aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tuner-i2c.h
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2008-04-22 13:41:52 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 12:42:26 -0400
commit3c2a0865d06df23f755a7d36a1076965500e1228 (patch)
tree06541badffc9b5c9c170e2b0836b312d6d8a690c /drivers/media/video/tuner-i2c.h
parent2e43c953bfd31f0104f916b2f39e6d3d8b1a3099 (diff)
V4L/DVB (7134): tuner: create a macro for sharing state between hybrid tuner instances
Create a macro implementing a standard method to share state amongst multiple instances of a hybrid tuner object. Also, prepare tuner_foo printk macros for the removal of PREFIX Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/tuner-i2c.h')
-rw-r--r--drivers/media/video/tuner-i2c.h112
1 files changed, 96 insertions, 16 deletions
diff --git a/drivers/media/video/tuner-i2c.h b/drivers/media/video/tuner-i2c.h
index de52e8ffd347..8ec5b41d459f 100644
--- a/drivers/media/video/tuner-i2c.h
+++ b/drivers/media/video/tuner-i2c.h
@@ -26,6 +26,10 @@
26struct tuner_i2c_props { 26struct tuner_i2c_props {
27 u8 addr; 27 u8 addr;
28 struct i2c_adapter *adap; 28 struct i2c_adapter *adap;
29
30 /* used for tuner instance management */
31 int count;
32 char *name;
29}; 33};
30 34
31static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len) 35static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
@@ -59,29 +63,105 @@ static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
59 return (ret == 2) ? ilen : ret; 63 return (ret == 2) ? ilen : ret;
60} 64}
61 65
62#define tuner_warn(fmt, arg...) do { \ 66/* Callers must declare as a global for the module:
63 printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \ 67 *
64 i2c_adapter_id(priv->i2c_props.adap), \ 68 * static LIST_HEAD(hybrid_tuner_instance_list);
65 priv->i2c_props.addr, ##arg); \ 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 i2c_adapter_id(i2cprops.adap), \
87 i2cprops.addr, ##arg); \
66 } while (0) 88 } while (0)
67 89
68#define tuner_info(fmt, arg...) do { \ 90/* TO DO: convert all callers of these macros to pass in
69 printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \ 91 * struct tuner_i2c_props, then remove the macro wrappers */
70 i2c_adapter_id(priv->i2c_props.adap), \ 92
71 priv->i2c_props.addr , ##arg); \ 93#define __tuner_warn(i2cprops, fmt, arg...) do { \
94 tuner_printk(KERN_WARNING, i2cprops, fmt, ##arg); \
72 } while (0) 95 } while (0)
73 96
74#define tuner_err(fmt, arg...) do { \ 97#define __tuner_info(i2cprops, fmt, arg...) do { \
75 printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \ 98 tuner_printk(KERN_INFO, i2cprops, fmt, ##arg); \
76 i2c_adapter_id(priv->i2c_props.adap), \
77 priv->i2c_props.addr , ##arg); \
78 } while (0) 99 } while (0)
79 100
80#define tuner_dbg(fmt, arg...) do { \ 101#define __tuner_err(i2cprops, fmt, arg...) do { \
102 tuner_printk(KERN_ERR, i2cprops, fmt, ##arg); \
103 } while (0)
104
105#define __tuner_dbg(i2cprops, fmt, arg...) do { \
81 if ((debug)) \ 106 if ((debug)) \
82 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \ 107 tuner_printk(KERN_DEBUG, i2cprops, fmt, ##arg); \
83 i2c_adapter_id(priv->i2c_props.adap), \
84 priv->i2c_props.addr , ##arg); \
85 } while (0) 108 } while (0)
86 109
110#define tuner_warn(fmt, arg...) __tuner_warn(priv->i2c_props, fmt, ##arg)
111#define tuner_info(fmt, arg...) __tuner_info(priv->i2c_props, fmt, ##arg)
112#define tuner_err(fmt, arg...) __tuner_err(priv->i2c_props, fmt, ##arg)
113#define tuner_dbg(fmt, arg...) __tuner_dbg(priv->i2c_props, fmt, ##arg)
114
115/****************************************************************************/
116
117/* The return value of hybrid_tuner_request_state indicates the number of
118 * instances using this tuner object.
119 *
120 * 0 - no instances, indicates an error - kzalloc must have failed
121 *
122 * 1 - one instance, indicates that the tuner object was created successfully
123 *
124 * 2 (or more) instances, indicates that an existing tuner object was found
125 */
126
127#define hybrid_tuner_request_state(type, state, list, i2cadap, i2caddr, devname)\
128({ \
129 int __ret = 0; \
130 list_for_each_entry(state, &list, hybrid_tuner_instance_list) { \
131 if ((i2c_adapter_id(state->i2c_props.adap) == \
132 i2c_adapter_id(i2cadap)) && \
133 (state->i2c_props.addr == i2caddr)) { \
134 __tuner_info(state->i2c_props, \
135 "attaching existing instance\n"); \
136 state->i2c_props.count++; \
137 __ret = state->i2c_props.count; \
138 break; \
139 } \
140 } \
141 if (0 == __ret) { \
142 state = kzalloc(sizeof(type), GFP_KERNEL); \
143 if (NULL == state) \
144 goto __fail; \
145 state->i2c_props.addr = i2caddr; \
146 state->i2c_props.adap = i2cadap; \
147 state->i2c_props.name = devname; \
148 __tuner_info(state->i2c_props, \
149 "creating new instance\n"); \
150 list_add_tail(&state->hybrid_tuner_instance_list, &list);\
151 state->i2c_props.count++; \
152 __ret = state->i2c_props.count; \
153 } \
154__fail: \
155 __ret; \
156})
157
158#define hybrid_tuner_release_state(state) do { \
159 state->i2c_props.count--; \
160 if (!state->i2c_props.count) { \
161 __tuner_info(state->i2c_props, "destroying instance\n");\
162 list_del(&state->hybrid_tuner_instance_list); \
163 kfree(state); \
164 } \
165} while (0)
166
87#endif /* __TUNER_I2C_H__ */ 167#endif /* __TUNER_I2C_H__ */