Commit 79518daf authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (6457): msp3400: convert to bus-based I2C API

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 77566dd7
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include <linux/videodev.h> #include <linux/videodev.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <media/v4l2-i2c-drv-legacy.h>
#include <media/tvaudio.h> #include <media/tvaudio.h>
#include <media/msp3400.h> #include <media/msp3400.h>
#include <linux/kthread.h> #include <linux/kthread.h>
...@@ -783,7 +784,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) ...@@ -783,7 +784,6 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
static int msp_suspend(struct i2c_client *client, pm_message_t state) static int msp_suspend(struct i2c_client *client, pm_message_t state)
{ {
v4l_dbg(1, msp_debug, client, "suspend\n"); v4l_dbg(1, msp_debug, client, "suspend\n");
msp_reset(client); msp_reset(client);
return 0; return 0;
...@@ -791,7 +791,6 @@ static int msp_suspend(struct i2c_client *client, pm_message_t state) ...@@ -791,7 +791,6 @@ static int msp_suspend(struct i2c_client *client, pm_message_t state)
static int msp_resume(struct i2c_client *client) static int msp_resume(struct i2c_client *client)
{ {
v4l_dbg(1, msp_debug, client, "resume\n"); v4l_dbg(1, msp_debug, client, "resume\n");
msp_wake_thread(client); msp_wake_thread(client);
return 0; return 0;
...@@ -799,11 +798,8 @@ static int msp_resume(struct i2c_client *client) ...@@ -799,11 +798,8 @@ static int msp_resume(struct i2c_client *client)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static struct i2c_driver i2c_driver; static int msp_probe(struct i2c_client *client)
static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
{ {
struct i2c_client *client;
struct msp_state *state; struct msp_state *state;
int (*thread_func)(void *data) = NULL; int (*thread_func)(void *data) = NULL;
int msp_hard; int msp_hard;
...@@ -812,24 +808,15 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -812,24 +808,15 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
int msp_product, msp_prod_hi, msp_prod_lo; int msp_product, msp_prod_hi, msp_prod_lo;
int msp_rom; int msp_rom;
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client)
return -ENOMEM;
client->addr = address;
client->adapter = adapter;
client->driver = &i2c_driver;
snprintf(client->name, sizeof(client->name) - 1, "msp3400"); snprintf(client->name, sizeof(client->name) - 1, "msp3400");
if (msp_reset(client) == -1) { if (msp_reset(client) == -1) {
v4l_dbg(1, msp_debug, client, "msp3400 not found\n"); v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
kfree(client);
return 0; return 0;
} }
state = kzalloc(sizeof(*state), GFP_KERNEL); state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state) { if (!state) {
kfree(client);
return -ENOMEM; return -ENOMEM;
} }
...@@ -857,7 +844,6 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -857,7 +844,6 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) { if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n"); v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n");
kfree(state); kfree(state);
kfree(client);
return 0; return 0;
} }
...@@ -919,7 +905,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -919,7 +905,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
} }
/* hello world :-) */ /* hello world :-) */
v4l_info(client, "%s found @ 0x%x (%s)\n", client->name, address << 1, adapter->name); v4l_info(client, "%s found @ 0x%x (%s)\n", client->name, client->addr << 1, client->adapter->name);
v4l_info(client, "%s ", client->name); v4l_info(client, "%s ", client->name);
if (state->has_nicam && state->has_radio) if (state->has_nicam && state->has_radio)
printk("supports nicam and radio, "); printk("supports nicam and radio, ");
...@@ -954,24 +940,12 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind) ...@@ -954,24 +940,12 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
v4l_warn(client, "kernel_thread() failed\n"); v4l_warn(client, "kernel_thread() failed\n");
msp_wake_thread(client); msp_wake_thread(client);
} }
/* done */
i2c_attach_client(client);
return 0;
}
static int msp_probe(struct i2c_adapter *adapter)
{
if (adapter->class & I2C_CLASS_TV_ANALOG)
return i2c_probe(adapter, &addr_data, msp_attach);
return 0; return 0;
} }
static int msp_detach(struct i2c_client *client) static int msp_remove(struct i2c_client *client)
{ {
struct msp_state *state = i2c_get_clientdata(client); struct msp_state *state = i2c_get_clientdata(client);
int err;
/* shutdown control thread */ /* shutdown control thread */
if (state->kthread) { if (state->kthread) {
...@@ -980,43 +954,22 @@ static int msp_detach(struct i2c_client *client) ...@@ -980,43 +954,22 @@ static int msp_detach(struct i2c_client *client)
} }
msp_reset(client); msp_reset(client);
err = i2c_detach_client(client);
if (err) {
return err;
}
kfree(state); kfree(state);
kfree(client);
return 0; return 0;
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* i2c implementation */ static struct v4l2_i2c_driver_data v4l2_i2c_data = {
static struct i2c_driver i2c_driver = { .name = "msp3400",
.id = I2C_DRIVERID_MSP3400, .driverid = I2C_DRIVERID_MSP3400,
.attach_adapter = msp_probe, .command = msp_command,
.detach_client = msp_detach, .probe = msp_probe,
.remove = msp_remove,
.suspend = msp_suspend, .suspend = msp_suspend,
.resume = msp_resume, .resume = msp_resume,
.command = msp_command,
.driver = {
.name = "msp3400",
},
}; };
static int __init msp3400_init_module(void)
{
return i2c_add_driver(&i2c_driver);
}
static void __exit msp3400_cleanup_module(void)
{
i2c_del_driver(&i2c_driver);
}
module_init(msp3400_init_module);
module_exit(msp3400_cleanup_module);
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
......
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