Commit 099f88ee authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] radio-tea5764: add support for struct v4l2_device

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Cc: Fabio Belavenuto <belavenuto@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent bb732ccc
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <linux/i2c.h> /* I2C */ #include <linux/i2c.h> /* I2C */
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
#include <media/v4l2-device.h>
#define DRIVER_VERSION "0.0.2" #define DRIVER_VERSION "0.0.2"
...@@ -138,6 +139,7 @@ static int radio_nr = -1; ...@@ -138,6 +139,7 @@ static int radio_nr = -1;
static int use_xtal = RADIO_TEA5764_XTAL; static int use_xtal = RADIO_TEA5764_XTAL;
struct tea5764_device { struct tea5764_device {
struct v4l2_device v4l2_dev;
struct i2c_client *i2c_client; struct i2c_client *i2c_client;
struct video_device *videodev; struct video_device *videodev;
struct tea5764_regs regs; struct tea5764_regs regs;
...@@ -497,6 +499,7 @@ static int tea5764_i2c_probe(struct i2c_client *client, ...@@ -497,6 +499,7 @@ static int tea5764_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct tea5764_device *radio; struct tea5764_device *radio;
struct v4l2_device *v4l2_dev;
struct tea5764_regs *r; struct tea5764_regs *r;
int ret; int ret;
...@@ -505,31 +508,37 @@ static int tea5764_i2c_probe(struct i2c_client *client, ...@@ -505,31 +508,37 @@ static int tea5764_i2c_probe(struct i2c_client *client,
if (!radio) if (!radio)
return -ENOMEM; return -ENOMEM;
v4l2_dev = &radio->v4l2_dev;
ret = v4l2_device_register(&client->dev, v4l2_dev);
if (ret < 0) {
v4l2_err(v4l2_dev, "could not register v4l2_device\n");
goto errfr;
}
mutex_init(&radio->mutex); mutex_init(&radio->mutex);
radio->i2c_client = client; radio->i2c_client = client;
ret = tea5764_i2c_read(radio); ret = tea5764_i2c_read(radio);
if (ret) if (ret)
goto errfr; goto errunreg;
r = &radio->regs; r = &radio->regs;
PDEBUG("chipid = %04X, manid = %04X", r->chipid, r->manid); PDEBUG("chipid = %04X, manid = %04X", r->chipid, r->manid);
if (r->chipid != TEA5764_CHIPID || if (r->chipid != TEA5764_CHIPID ||
(r->manid & 0x0fff) != TEA5764_MANID) { (r->manid & 0x0fff) != TEA5764_MANID) {
PWARN("This chip is not a TEA5764!"); PWARN("This chip is not a TEA5764!");
ret = -EINVAL; ret = -EINVAL;
goto errfr; goto errunreg;
} }
radio->videodev = video_device_alloc(); radio->videodev = video_device_alloc();
if (!(radio->videodev)) { if (!(radio->videodev)) {
ret = -ENOMEM; ret = -ENOMEM;
goto errfr; goto errunreg;
} }
memcpy(radio->videodev, &tea5764_radio_template, *radio->videodev = tea5764_radio_template;
sizeof(tea5764_radio_template));
i2c_set_clientdata(client, radio); i2c_set_clientdata(client, radio);
video_set_drvdata(radio->videodev, radio); video_set_drvdata(radio->videodev, radio);
radio->videodev->lock = &radio->mutex; radio->videodev->lock = &radio->mutex;
radio->videodev->v4l2_dev = v4l2_dev;
/* initialize and power off the chip */ /* initialize and power off the chip */
tea5764_i2c_read(radio); tea5764_i2c_read(radio);
...@@ -547,6 +556,8 @@ static int tea5764_i2c_probe(struct i2c_client *client, ...@@ -547,6 +556,8 @@ static int tea5764_i2c_probe(struct i2c_client *client,
return 0; return 0;
errrel: errrel:
video_device_release(radio->videodev); video_device_release(radio->videodev);
errunreg:
v4l2_device_unregister(v4l2_dev);
errfr: errfr:
kfree(radio); kfree(radio);
return ret; return ret;
...@@ -560,6 +571,7 @@ static int tea5764_i2c_remove(struct i2c_client *client) ...@@ -560,6 +571,7 @@ static int tea5764_i2c_remove(struct i2c_client *client)
if (radio) { if (radio) {
tea5764_power_down(radio); tea5764_power_down(radio);
video_unregister_device(radio->videodev); video_unregister_device(radio->videodev);
v4l2_device_unregister(&radio->v4l2_dev);
kfree(radio); kfree(radio);
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment