Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[linux-dvb] [PATCH 3/4] Frontend conversion - mt352
Frontend conversion to kernel i2c, please check.
Kenneth
mt352.c | 180 ++++++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 127 insertions(+), 53 deletions(-)
Index: mt352.c
===================================================================
RCS file: /cvs/linuxtv/dvb-kernel/linux/drivers/media/dvb/frontends/mt352.c,v
retrieving revision 1.7
diff -u -r1.7 mt352.c
--- mt352.c 8 Jul 2004 17:05:42 -0000 1.7
+++ mt352.c 12 Jul 2004 17:09:13 -0000
@@ -36,14 +36,20 @@
#include "dvb_frontend.h"
#include "mt352.h"
+struct mt352_state {
+ struct i2c_adapter *i2c;
+ struct dvb_adapter *dvb;
+};
+
+// XXX - Get rid of card_type
static int force_card = -1;
-static u32 card_type = -1;
+static int card_type = 0;
#define mt352_write(ibuf, ilen) \
do { \
struct i2c_msg msg = { .addr = I2C_MT352_ADDR, .flags = 0, \
.buf = ibuf, .len = ilen }; \
- int err = i2c->xfer(i2c, &msg, 1); \
+ int err = i2c_transfer(i2c, &msg, 1); \
if (err != 1) { \
printk(KERN_WARNING \
"mt352_write() failed (err = %d)!\n", err); \
@@ -125,7 +131,7 @@
FE_CAN_MUTE_TS
};
-static int mt352_init_TUA6034(struct dvb_i2c_bus *i2c)
+static int mt352_init_TUA6034(struct i2c_adapter *i2c)
{
static u8 mt352_reset [] = { RESET, 0x80 };
static u8 mt352_clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
@@ -144,7 +150,7 @@
return 0;
}
-static int mt352_init_AVERMEDIA771(struct dvb_i2c_bus *i2c)
+static int mt352_init_AVERMEDIA771(struct i2c_adapter *i2c)
{
static u8 mt352_reset [] = { RESET, 0x80 };
static u8 mt352_clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
@@ -167,7 +173,7 @@
return 0;
}
-static int mt352_init_TDTC9251DH01C(struct dvb_i2c_bus *i2c)
+static int mt352_init_TDTC9251DH01C(struct i2c_adapter *i2c)
{
static u8 mt352_reset [] = { RESET, 0x80 };
static u8 mt352_clock_config [] = { CLOCK_CTL, 0x10, 0x2d };
@@ -286,7 +292,7 @@
}
-static int mt352_detect_avermedia_771(struct dvb_i2c_bus *i2c)
+static int mt352_detect_avermedia_771(struct i2c_adapter *i2c)
{
int i;
u8 reg;
@@ -311,7 +317,7 @@
{
reg = i + 0xFC;
msg[1].buf = id + i;
- if (i2c->xfer(i2c,msg,2) != 2)
+ if (i2c_transfer(i2c,msg,2) != 2)
{
return 0;
}
@@ -320,7 +326,7 @@
return *((u32 *) id) == *((u32 *) pciid);
}
-static int mt352_detect_tdtc9251dh01c(struct dvb_i2c_bus *i2c)
+static int mt352_detect_tdtc9251dh01c(struct i2c_adapter *i2c)
{
/* detection code must be written */
@@ -334,7 +340,7 @@
return(0);
}
-static int mt352_detect_tua6034(struct dvb_i2c_bus *i2c)
+static int mt352_detect_tua6034(struct i2c_adapter *i2c)
{
/* detection code must be written */
if (force_card == 0)
@@ -343,7 +349,7 @@
return(0);
}
-static int mt352_init(struct dvb_i2c_bus *i2c)
+static int mt352_init(struct i2c_adapter *i2c)
{
/**
* all register write sequence have the register address of the
@@ -362,7 +368,7 @@
return(MT352_INIT(i2c));
}
-static int mt352_sleep(struct dvb_i2c_bus *i2c)
+static int mt352_sleep(struct i2c_adapter *i2c)
{
static u8 mt352_softdown[] = { 0x89, 0x20, 0x08 };
@@ -371,7 +377,7 @@
return 0;
}
-static int mt352_set_parameters(struct dvb_i2c_bus *i2c,
+static int mt352_set_parameters(struct i2c_adapter *i2c,
struct dvb_frontend_parameters *param)
{
unsigned char buf[14];
@@ -529,7 +535,7 @@
return 0;
}
-static u8 mt352_read_register(struct dvb_i2c_bus *i2c, u8 reg)
+static u8 mt352_read_register(struct i2c_adapter *i2c, u8 reg)
{
int ret;
u8 b0 [] = { reg };
@@ -541,7 +547,7 @@
.flags = I2C_M_RD,
.buf = b1, .len = 1 } };
- ret = i2c->xfer (i2c, msg, 2);
+ ret = i2c_transfer(i2c, msg, 2);
if (ret != 2)
printk(KERN_WARNING
@@ -551,7 +557,7 @@
}
-static int mt352_get_parameters(struct dvb_i2c_bus *i2c,
+static int mt352_get_parameters(struct i2c_adapter *i2c,
struct dvb_frontend_parameters *param)
{
u16 tps;
@@ -668,7 +674,8 @@
static int mt352_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg)
{
- struct dvb_i2c_bus *i2c = fe->i2c;
+ struct mt352_state *state = fe->data;
+ struct i2c_adapter *i2c = state->i2c;
u8 r,snr;
fe_status_t *status;
u16 signal;
@@ -750,68 +757,135 @@
return 0;
}
+static struct i2c_client client_template;
-static int mt352_attach(struct dvb_i2c_bus *i2c, void **data)
+static int mt352_attach_adapter(struct i2c_adapter *i2c)
{
+ struct mt352_state *state;
+ struct i2c_client *client;
static u8 mt352_reset_attach [] = { 0x50, 0xC0 };
+ int ret;
/* set the proper MT352 frequency range */
mt352_info.frequency_min = FE_FREQ_MIN;
mt352_info.frequency_max = FE_FREQ_MAX;
mt352_info.frequency_stepsize = FE_FREQ_STEPSIZE;
- if (mt352_read_register(i2c, CHIP_ID) == ID_MT352)
+ if (mt352_read_register(i2c, CHIP_ID) != ID_MT352)
+ return -ENODEV;
+
+ if (!(state = kmalloc(sizeof(struct mt352_state), GFP_KERNEL)))
+ return -ENOMEM;
+
+ memset(state, 0, sizeof(struct mt352_state));
+ state->i2c = i2c;
+
+ if (mt352_detect_avermedia_771(i2c))
{
- if (mt352_detect_avermedia_771(i2c))
- {
- card_type = CARD_AVDVBT771;
- }
- else if (mt352_detect_tdtc9251dh01c(i2c))
- {
- card_type = CARD_TDTC9251DH01C;
- }
- else if (mt352_detect_tua6034(i2c))
- {
- card_type = CARD_TUA6034;
- }
- else
- {
- return -ENODEV;
- }
- /* Do a "hard" reset */
- mt352_write(mt352_reset_attach,sizeof(mt352_reset_attach));
- /* Don't waste power and (maybe) pci bandwidth */
- mt352_sleep(i2c);
- return dvb_register_frontend(mt352_ioctl, i2c, NULL,
- &mt352_info);
+ card_type = CARD_AVDVBT771;
+ }
+ else if (mt352_detect_tdtc9251dh01c(i2c))
+ {
+ card_type = CARD_TDTC9251DH01C;
+ }
+ else if (mt352_detect_tua6034(i2c))
+ {
+ card_type = CARD_TUA6034;
+ }
+ else
+ {
+ printk(KERN_ERR "mt352: You appear to have an unsupported"
+ " variant of the mt352 frontend.");
+ printk(KERN_ERR "mt352: Please report this to"
+ " linux-dvb@linuxtv.org");
+ kfree(state);
+ return -ENODEV;
}
- return -ENODEV;
-}
+ /* Do a "hard" reset */
+ mt352_write(mt352_reset_attach, sizeof(mt352_reset_attach));
+ if (!(client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL)))
+ return -ENOMEM;
-static void mt352_detach(struct dvb_i2c_bus *i2c, void *data)
-{
- mt352_sleep(i2c);
- dvb_unregister_frontend(mt352_ioctl, i2c);
+ memcpy(client, &client_template, sizeof(struct i2c_client));
+ client->adapter = i2c;
+ client->addr = 0; // XXX
+ i2c_set_clientdata(client, state);
+
+ if ((ret = i2c_attach_client(client))) {
+ kfree(client);
+ kfree(state);
+ return ret;
+ }
+
+ BUG_ON(state->dvb);
+
+ if ((ret = dvb_register_frontend_new(mt352_ioctl, state->dvb, state,
+ &mt352_info, THIS_MODULE)))
+ return ret;
+
+ return 0;
}
+static int mt352_detach_client(struct i2c_client *client)
+{
+ struct mt352_state *state = i2c_get_clientdata(client);
+
+ dvb_unregister_frontend_new (mt352_ioctl, state->dvb);
+ i2c_detach_client(client);
+ BUG_ON(state->dvb);
+ kfree(client);
+ kfree(state);
+ return 0;
+}
-static int __init init_mt352(void)
+static int mt352_command (struct i2c_client *client, unsigned int cmd, void *arg)
{
- return dvb_register_i2c_device(NULL, mt352_attach, mt352_detach);
+ struct mt352_state *state = i2c_get_clientdata(client);
+
+ switch (cmd) {
+ case FE_REGISTER:
+ state->dvb = arg;
+ break;
+ case FE_UNREGISTER:
+ state->dvb = NULL;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+ return 0;
}
+static struct i2c_driver driver = {
+ .owner = THIS_MODULE,
+ .name = "dvbfe_mt352",
+ .id = I2C_DRIVERID_DVBFE_MT352,
+ .flags = I2C_DF_NOTIFY,
+ .attach_adapter = mt352_attach_adapter,
+ .detach_client = mt352_detach_client,
+ .command = mt352_command,
+};
-static void __exit exit_mt352(void)
+static struct i2c_client client_template = {
+ I2C_DEVNAME("dvbfe_mt352"),
+ .flags = I2C_CLIENT_ALLOW_USE,
+ .driver = &driver,
+};
+
+static int __init mt352_module_init(void)
{
- dvb_unregister_i2c_device(mt352_attach);
+ return i2c_add_driver(&driver);
}
+static void __exit mt352_module_exit(void)
+{
+ if (i2c_del_driver(&driver))
+ printk(KERN_ERR "mt352: driver deregistration failed.\n");
+}
-module_init(init_mt352);
-module_exit(exit_mt352);
-
+module_init(mt352_module_init);
+module_exit(mt352_module_exit);
MODULE_DESCRIPTION("DVB-T MT352 Zarlink");
MODULE_AUTHOR("Holger Waechtler, Daniel Mack, Antonio Mancuso");
Home |
Main Index |
Thread Index