diff options
Diffstat (limited to 'drivers/media/video/tea5767.c')
-rw-r--r-- | drivers/media/video/tea5767.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c index 4c9c4e01331a..5a08ec2f99fb 100644 --- a/drivers/media/video/tea5767.c +++ b/drivers/media/video/tea5767.c | |||
@@ -20,6 +20,10 @@ | |||
20 | /* from tuner-core.c */ | 20 | /* from tuner-core.c */ |
21 | extern int tuner_debug; | 21 | extern int tuner_debug; |
22 | 22 | ||
23 | struct tea5767_priv { | ||
24 | struct tuner_i2c_props i2c_props; | ||
25 | }; | ||
26 | |||
23 | /*****************************************************************************/ | 27 | /*****************************************************************************/ |
24 | 28 | ||
25 | /****************************** | 29 | /****************************** |
@@ -129,10 +133,8 @@ enum tea5767_xtal_freq { | |||
129 | 133 | ||
130 | /*****************************************************************************/ | 134 | /*****************************************************************************/ |
131 | 135 | ||
132 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) | 136 | static void set_tv_freq(struct tuner *t, unsigned int freq) |
133 | { | 137 | { |
134 | struct tuner *t = i2c_get_clientdata(c); | ||
135 | |||
136 | tuner_warn("This tuner doesn't support TV freq.\n"); | 138 | tuner_warn("This tuner doesn't support TV freq.\n"); |
137 | } | 139 | } |
138 | 140 | ||
@@ -190,9 +192,9 @@ static void tea5767_status_dump(unsigned char *buffer) | |||
190 | } | 192 | } |
191 | 193 | ||
192 | /* Freq should be specifyed at 62.5 Hz */ | 194 | /* Freq should be specifyed at 62.5 Hz */ |
193 | static void set_radio_freq(struct i2c_client *c, unsigned int frq) | 195 | static void set_radio_freq(struct tuner *t, unsigned int frq) |
194 | { | 196 | { |
195 | struct tuner *t = i2c_get_clientdata(c); | 197 | struct tea5767_priv *priv = t->priv; |
196 | unsigned char buffer[5]; | 198 | unsigned char buffer[5]; |
197 | unsigned div; | 199 | unsigned div; |
198 | int rc; | 200 | int rc; |
@@ -246,38 +248,38 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq) | |||
246 | buffer[0] = (div >> 8) & 0x3f; | 248 | buffer[0] = (div >> 8) & 0x3f; |
247 | buffer[1] = div & 0xff; | 249 | buffer[1] = div & 0xff; |
248 | 250 | ||
249 | if (5 != (rc = i2c_master_send(c, buffer, 5))) | 251 | if (5 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 5))) |
250 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 252 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
251 | 253 | ||
252 | if (tuner_debug) { | 254 | if (tuner_debug) { |
253 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) | 255 | if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) |
254 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 256 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
255 | else | 257 | else |
256 | tea5767_status_dump(buffer); | 258 | tea5767_status_dump(buffer); |
257 | } | 259 | } |
258 | } | 260 | } |
259 | 261 | ||
260 | static int tea5767_signal(struct i2c_client *c) | 262 | static int tea5767_signal(struct tuner *t) |
261 | { | 263 | { |
262 | unsigned char buffer[5]; | 264 | unsigned char buffer[5]; |
263 | int rc; | 265 | int rc; |
264 | struct tuner *t = i2c_get_clientdata(c); | 266 | struct tea5767_priv *priv = t->priv; |
265 | 267 | ||
266 | memset(buffer, 0, sizeof(buffer)); | 268 | memset(buffer, 0, sizeof(buffer)); |
267 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) | 269 | if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) |
268 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 270 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
269 | 271 | ||
270 | return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); | 272 | return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); |
271 | } | 273 | } |
272 | 274 | ||
273 | static int tea5767_stereo(struct i2c_client *c) | 275 | static int tea5767_stereo(struct tuner *t) |
274 | { | 276 | { |
275 | unsigned char buffer[5]; | 277 | unsigned char buffer[5]; |
276 | int rc; | 278 | int rc; |
277 | struct tuner *t = i2c_get_clientdata(c); | 279 | struct tea5767_priv *priv = t->priv; |
278 | 280 | ||
279 | memset(buffer, 0, sizeof(buffer)); | 281 | memset(buffer, 0, sizeof(buffer)); |
280 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) | 282 | if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) |
281 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 283 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
282 | 284 | ||
283 | rc = buffer[2] & TEA5767_STEREO_MASK; | 285 | rc = buffer[2] & TEA5767_STEREO_MASK; |
@@ -287,10 +289,10 @@ static int tea5767_stereo(struct i2c_client *c) | |||
287 | return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); | 289 | return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); |
288 | } | 290 | } |
289 | 291 | ||
290 | static void tea5767_standby(struct i2c_client *c) | 292 | static void tea5767_standby(struct tuner *t) |
291 | { | 293 | { |
292 | unsigned char buffer[5]; | 294 | unsigned char buffer[5]; |
293 | struct tuner *t = i2c_get_clientdata(c); | 295 | struct tea5767_priv *priv = t->priv; |
294 | unsigned div, rc; | 296 | unsigned div, rc; |
295 | 297 | ||
296 | div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */ | 298 | div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */ |
@@ -301,17 +303,17 @@ static void tea5767_standby(struct i2c_client *c) | |||
301 | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY; | 303 | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY; |
302 | buffer[4] = 0; | 304 | buffer[4] = 0; |
303 | 305 | ||
304 | if (5 != (rc = i2c_master_send(c, buffer, 5))) | 306 | if (5 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 5))) |
305 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 307 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
306 | } | 308 | } |
307 | 309 | ||
308 | int tea5767_autodetection(struct i2c_client *c) | 310 | int tea5767_autodetection(struct tuner *t) |
309 | { | 311 | { |
312 | struct tuner_i2c_props i2c = { .adap = t->i2c.adapter, .addr = t->i2c.addr }; | ||
310 | unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 313 | unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
311 | int rc; | 314 | int rc; |
312 | struct tuner *t = i2c_get_clientdata(c); | ||
313 | 315 | ||
314 | if ((rc = i2c_master_recv(c, buffer, 7))< 5) { | 316 | if ((rc = tuner_i2c_xfer_send(&i2c, buffer, 7))< 5) { |
315 | tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); | 317 | tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); |
316 | return EINVAL; | 318 | return EINVAL; |
317 | } | 319 | } |
@@ -343,20 +345,35 @@ int tea5767_autodetection(struct i2c_client *c) | |||
343 | return 0; | 345 | return 0; |
344 | } | 346 | } |
345 | 347 | ||
348 | static void tea5767_release(struct tuner *t) | ||
349 | { | ||
350 | kfree(t->priv); | ||
351 | t->priv = NULL; | ||
352 | } | ||
353 | |||
346 | static struct tuner_operations tea5767_tuner_ops = { | 354 | static struct tuner_operations tea5767_tuner_ops = { |
347 | .set_tv_freq = set_tv_freq, | 355 | .set_tv_freq = set_tv_freq, |
348 | .set_radio_freq = set_radio_freq, | 356 | .set_radio_freq = set_radio_freq, |
349 | .has_signal = tea5767_signal, | 357 | .has_signal = tea5767_signal, |
350 | .is_stereo = tea5767_stereo, | 358 | .is_stereo = tea5767_stereo, |
351 | .standby = tea5767_standby, | 359 | .standby = tea5767_standby, |
360 | .release = tea5767_release, | ||
352 | }; | 361 | }; |
353 | 362 | ||
354 | int tea5767_tuner_init(struct i2c_client *c) | 363 | int tea5767_tuner_init(struct tuner *t) |
355 | { | 364 | { |
356 | struct tuner *t = i2c_get_clientdata(c); | 365 | struct tea5767_priv *priv = NULL; |
366 | |||
367 | priv = kzalloc(sizeof(struct tea5767_priv), GFP_KERNEL); | ||
368 | if (priv == NULL) | ||
369 | return -ENOMEM; | ||
370 | t->priv = priv; | ||
371 | |||
372 | priv->i2c_props.addr = t->i2c.addr; | ||
373 | priv->i2c_props.adap = t->i2c.adapter; | ||
357 | 374 | ||
358 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio"); | 375 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio"); |
359 | strlcpy(c->name, "tea5767", sizeof(c->name)); | 376 | strlcpy(t->i2c.name, "tea5767", sizeof(t->i2c.name)); |
360 | 377 | ||
361 | memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations)); | 378 | memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations)); |
362 | 379 | ||