aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/tuners/tuner-i2c.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-04-29 17:53:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-29 17:53:40 -0400
commit2d5e3e8d28a7820de1eb7b18a7c15d645bb26992 (patch)
treee6af4574977947de83e670dad1f71505b249fe1c /drivers/media/common/tuners/tuner-i2c.h
parentb57ab7632b8fc1eef139bbbb7a89002be61f99e1 (diff)
parentaed6abd662c2903733bea7fcd3856c306e650680 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/v4l-dvb
* git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/v4l-dvb: (28 commits) V4L-DVB(7789a): cx18: fix symbol conflict with ivtv driver V4L/DVB (7789): tuner: remove static dependencies on analog tuner sub-modules V4L/DVB (7785): [2.6 patch] make mt9{m001,v022}_controls[] static V4L/DVB (7786): cx18: new driver for the Conexant CX23418 MPEG encoder chip V4L/DVB (7783): drivers/media/dvb/frontends/s5h1420.c: printk fix V4L/DVB (7782): pvrusb2: Driver is no longer experimental V4L/DVB (7781): pvrusb2-dvb: include dvb support by default and update Kconfig help text V4L/DVB (7780): pvrusb2: always enable support for OnAir Creator / HDTV USB2 V4L/DVB (7779): pvrusb2-dvb: quiet down noise in kernel log for feed debug Rename common tuner Kconfig names to use the same Fix V4L/DVB core help messages V4L/DVB (7769): Move other terrestrial tuners to common/tuners V4L/DVB (7768): reorganize some DVB-S Kconfig items V4L/DVB(7767): Move tuners to common/tuners V4L/DVB (7766): saa7134: add another PCI ID for Beholder M6 V4L/DVB (7765): Add support for Beholder BeholdTV H6 V4L/DVB (7763): ivtv: add tuner support for the AverMedia M116 V4L/DVB (7762): ivtv: fix tuner detection for PAL-N/Nc V4L/DVB (7761): ivtv: increase the DMA timeout from 100 to 300 ms V4L/DVB (7759): ivtv: increase version number to 1.2.1 ...
Diffstat (limited to 'drivers/media/common/tuners/tuner-i2c.h')
-rw-r--r--drivers/media/common/tuners/tuner-i2c.h173
1 files changed, 173 insertions, 0 deletions
diff --git a/drivers/media/common/tuners/tuner-i2c.h b/drivers/media/common/tuners/tuner-i2c.h
new file mode 100644
index 000000000000..3ad6c8e0b04c
--- /dev/null
+++ b/drivers/media/common/tuners/tuner-i2c.h
@@ -0,0 +1,173 @@
1/*
2 tuner-i2c.h - i2c interface for different tuners
3
4 Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __TUNER_I2C_H__
22#define __TUNER_I2C_H__
23
24#include <linux/i2c.h>
25
26struct tuner_i2c_props {
27 u8 addr;
28 struct i2c_adapter *adap;
29
30 /* used for tuner instance management */
31 int count;
32 char *name;
33};
34
35static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
36{
37 struct i2c_msg msg = { .addr = props->addr, .flags = 0,
38 .buf = buf, .len = len };
39 int ret = i2c_transfer(props->adap, &msg, 1);
40
41 return (ret == 1) ? len : ret;
42}
43
44static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len)
45{
46 struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
47 .buf = buf, .len = len };
48 int ret = i2c_transfer(props->adap, &msg, 1);
49
50 return (ret == 1) ? len : ret;
51}
52
53static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
54 char *obuf, int olen,
55 char *ibuf, int ilen)
56{
57 struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
58 .buf = obuf, .len = olen },
59 { .addr = props->addr, .flags = I2C_M_RD,
60 .buf = ibuf, .len = ilen } };
61 int ret = i2c_transfer(props->adap, msg, 2);
62
63 return (ret == 2) ? ilen : ret;
64}
65
66/* Callers must declare as a global for the module:
67 *
68 * static LIST_HEAD(hybrid_tuner_instance_list);
69 *
70 * hybrid_tuner_instance_list should be the third argument
71 * passed into hybrid_tuner_request_state().
72 *
73 * state structure must contain the following:
74 *
75 * struct list_head hybrid_tuner_instance_list;
76 * struct tuner_i2c_props i2c_props;
77 *
78 * hybrid_tuner_instance_list (both within state structure and globally)
79 * is only required if the driver is using hybrid_tuner_request_state
80 * and hybrid_tuner_release_state to manage state sharing between
81 * multiple instances of hybrid tuners.
82 */
83
84#define tuner_printk(kernlvl, i2cprops, fmt, arg...) do { \
85 printk(kernlvl "%s %d-%04x: " fmt, i2cprops.name, \
86 i2cprops.adap ? \
87 i2c_adapter_id(i2cprops.adap) : -1, \
88 i2cprops.addr, ##arg); \
89 } while (0)
90
91/* TO DO: convert all callers of these macros to pass in
92 * struct tuner_i2c_props, then remove the macro wrappers */
93
94#define __tuner_warn(i2cprops, fmt, arg...) do { \
95 tuner_printk(KERN_WARNING, i2cprops, fmt, ##arg); \
96 } while (0)
97
98#define __tuner_info(i2cprops, fmt, arg...) do { \
99 tuner_printk(KERN_INFO, i2cprops, fmt, ##arg); \
100 } while (0)
101
102#define __tuner_err(i2cprops, fmt, arg...) do { \
103 tuner_printk(KERN_ERR, i2cprops, fmt, ##arg); \
104 } while (0)
105
106#define __tuner_dbg(i2cprops, fmt, arg...) do { \
107 if ((debug)) \
108 tuner_printk(KERN_DEBUG, i2cprops, fmt, ##arg); \
109 } while (0)
110
111#define tuner_warn(fmt, arg...) __tuner_warn(priv->i2c_props, fmt, ##arg)
112#define tuner_info(fmt, arg...) __tuner_info(priv->i2c_props, fmt, ##arg)
113#define tuner_err(fmt, arg...) __tuner_err(priv->i2c_props, fmt, ##arg)
114#define tuner_dbg(fmt, arg...) __tuner_dbg(priv->i2c_props, fmt, ##arg)
115
116/****************************************************************************/
117
118/* The return value of hybrid_tuner_request_state indicates the number of
119 * instances using this tuner object.
120 *
121 * 0 - no instances, indicates an error - kzalloc must have failed
122 *
123 * 1 - one instance, indicates that the tuner object was created successfully
124 *
125 * 2 (or more) instances, indicates that an existing tuner object was found
126 */
127
128#define hybrid_tuner_request_state(type, state, list, i2cadap, i2caddr, devname)\
129({ \
130 int __ret = 0; \
131 list_for_each_entry(state, &list, hybrid_tuner_instance_list) { \
132 if (((i2cadap) && (state->i2c_props.adap)) && \
133 ((i2c_adapter_id(state->i2c_props.adap) == \
134 i2c_adapter_id(i2cadap)) && \
135 (i2caddr == state->i2c_props.addr))) { \
136 __tuner_info(state->i2c_props, \
137 "attaching existing instance\n"); \
138 state->i2c_props.count++; \
139 __ret = state->i2c_props.count; \
140 break; \
141 } \
142 } \
143 if (0 == __ret) { \
144 state = kzalloc(sizeof(type), GFP_KERNEL); \
145 if (NULL == state) \
146 goto __fail; \
147 state->i2c_props.addr = i2caddr; \
148 state->i2c_props.adap = i2cadap; \
149 state->i2c_props.name = devname; \
150 __tuner_info(state->i2c_props, \
151 "creating new instance\n"); \
152 list_add_tail(&state->hybrid_tuner_instance_list, &list);\
153 state->i2c_props.count++; \
154 __ret = state->i2c_props.count; \
155 } \
156__fail: \
157 __ret; \
158})
159
160#define hybrid_tuner_release_state(state) \
161({ \
162 int __ret; \
163 state->i2c_props.count--; \
164 __ret = state->i2c_props.count; \
165 if (!state->i2c_props.count) { \
166 __tuner_info(state->i2c_props, "destroying instance\n");\
167 list_del(&state->hybrid_tuner_instance_list); \
168 kfree(state); \
169 } \
170 __ret; \
171})
172
173#endif /* __TUNER_I2C_H__ */