diff options
author | Kenneth Aafloy <devnull@localhost> | 2004-07-16 18:20:10 +0000 |
---|---|---|
committer | Kenneth Aafloy <devnull@localhost> | 2004-07-16 18:20:10 +0000 |
commit | 2ae9e8fdd009dc568f8447b64c6e93bd95c26981 (patch) | |
tree | 8de345bc16fcbe4e01f8531a69c376123975cc10 /linux/drivers/media/dvb/frontends/mt352.c | |
parent | 1e5206f141b6df2b23ae88ba45d305f9e4cc6975 (diff) | |
download | mediapointer-dvb-s2-2ae9e8fdd009dc568f8447b64c6e93bd95c26981.tar.gz mediapointer-dvb-s2-2ae9e8fdd009dc568f8447b64c6e93bd95c26981.tar.bz2 |
- Conversion to Kernel I2C layer.
- MODULE_PARM* -> module_param*
- Common name for I2C device and prefix for debug messages.
NOTE: This needs testing by someone who has one of these frontends.
Diffstat (limited to 'linux/drivers/media/dvb/frontends/mt352.c')
-rw-r--r-- | linux/drivers/media/dvb/frontends/mt352.c | 263 |
1 files changed, 170 insertions, 93 deletions
diff --git a/linux/drivers/media/dvb/frontends/mt352.c b/linux/drivers/media/dvb/frontends/mt352.c index ab5f8b7ac..ff5c1a8d2 100644 --- a/linux/drivers/media/dvb/frontends/mt352.c +++ b/linux/drivers/media/dvb/frontends/mt352.c @@ -36,14 +36,37 @@ #include "dvb_frontend.h" #include "mt352.h" +#define FRONTEND_NAME "dvbfe_mt352" + +#define dprintk(args...) \ + do { \ + if (debug) printk(KERN_DEBUG FRONTEND_NAME ": " args); \ + } while (0) + +static int debug; static int force_card = -1; -static u32 card_type = -1; +static int card_type = -1; + +module_param(debug, int, 0644); +MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); +//FIXME: Should be an array. +module_param(force_card, int, 0444); +MODULE_PARM_DESC(force_card, "Force card type.\n\t(0 == AVDVBT771, 1 == TUA6034, " + "2 == TDTC9251DH01C).\n\tDefault is that AVDVBT771 is attempted " + "to be autodetected,\n\tif you do not have this card, you must " + "specify the card type here."); + + +struct mt352_state { + struct i2c_adapter *i2c; + struct dvb_adapter *dvb; +}; #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); \ @@ -51,23 +74,8 @@ do { \ } \ } while (0) +// FIXME: static struct _tuner_info tuner_info [] = { - //TUA6034 tuner - { - .fe_frequency_min = 174000000, - .fe_frequency_max = 862000000, - .fe_frequency_stepsize = 166667, - .coderate_hp_shift = 9, - .coderate_lp_shift = 6, - .constellation_shift = 14, - .tx_mode_shift = 1, - .guard_interval_shift = 3, - .hierarchy_shift = 12, - .read_reg_flag = I2C_M_NOSTART, - .mt352_init = mt352_init_TUA6034, - .mt352_charge_pump = mt352_cp_TUA6034, - .mt352_band_select = mt352_bs_TUA6034 - }, //AVERMEDIA 771 board { .fe_frequency_min = 174000000, @@ -84,6 +92,22 @@ static struct _tuner_info tuner_info [] = { .mt352_charge_pump = mt352_cp_AVERMEDIA771, .mt352_band_select = mt352_bs_AVERMEDIA771 }, + //TUA6034 tuner + { + .fe_frequency_min = 174000000, + .fe_frequency_max = 862000000, + .fe_frequency_stepsize = 166667, + .coderate_hp_shift = 9, + .coderate_lp_shift = 6, + .constellation_shift = 14, + .tx_mode_shift = 1, + .guard_interval_shift = 3, + .hierarchy_shift = 12, + .read_reg_flag = I2C_M_NOSTART, + .mt352_init = mt352_init_TUA6034, + .mt352_charge_pump = mt352_cp_TUA6034, + .mt352_band_select = mt352_bs_TUA6034 + }, //TDTC9251DH01C tuner { .fe_frequency_min = 474000000, @@ -125,7 +149,7 @@ static struct dvb_frontend_info mt352_info = { 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 +168,7 @@ static int mt352_init_TUA6034(struct dvb_i2c_bus *i2c) 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 +191,7 @@ static int mt352_init_AVERMEDIA771(struct dvb_i2c_bus *i2c) 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 +310,7 @@ static unsigned char mt352_bs_TDTC9251DH01C(u32 freq) } -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 +335,7 @@ static int mt352_detect_avermedia_771(struct dvb_i2c_bus *i2c) { 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,30 +344,7 @@ static int mt352_detect_avermedia_771(struct dvb_i2c_bus *i2c) return *((u32 *) id) == *((u32 *) pciid); } -static int mt352_detect_tdtc9251dh01c(struct dvb_i2c_bus *i2c) -{ - /* detection code must be written */ - - /* for Airstar2 DVB-T checking the PCI ID */ - /* is not enought because the one reported from */ - /* lspci is the one of Skystar2 */ - - if (force_card == 2) - return(1); - else - return(0); -} - -static int mt352_detect_tua6034(struct dvb_i2c_bus *i2c) -{ - /* detection code must be written */ - if (force_card == 0) - return(1); - else - 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 +363,7 @@ static int mt352_init(struct dvb_i2c_bus *i2c) 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 +372,7 @@ static int mt352_sleep(struct dvb_i2c_bus *i2c) 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 +530,7 @@ static int mt352_set_parameters(struct dvb_i2c_bus *i2c, 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 +542,7 @@ static u8 mt352_read_register(struct dvb_i2c_bus *i2c, u8 reg) .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 +552,7 @@ static u8 mt352_read_register(struct dvb_i2c_bus *i2c, u8 reg) } -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 +669,8 @@ static int mt352_get_parameters(struct dvb_i2c_bus *i2c, 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,72 +752,147 @@ static int mt352_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) 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; + + dprintk("Trying to attach to adapter 0x%x:%s.\n", + i2c->id, i2c->name); /* 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_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); + 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)) { + card_type = CARD_AVDVBT771; + } else if (force_card < 0) { + dprintk("Avermedia 771 not detected, maybe you should try the " + "'force_card' module parameter?.\n"); + kfree(state); + return -ENODEV; } - return -ENODEV; -} + if (force_card > 0) { + if (card_type >= 0 && force_card != card_type) + printk(KERN_WARNING "dvbfe_mt352: Warning, overriding" + " detected card.\n"); + card_type = force_card; + } + if (card_type == CARD_AVDVBT771) + printk(KERN_INFO FRONTEND_NAME ": Setup for Avermedia 771.\n"); + else if (card_type == CARD_TUA6034) + printk(KERN_INFO FRONTEND_NAME ": Setup for TUA6034.\n"); + else if (card_type == CARD_TDTC9251DH01C) + printk(KERN_INFO FRONTEND_NAME ": Setup for TDTC9251DH01C.\n"); -static void mt352_detach(struct dvb_i2c_bus *i2c, void *data) -{ - mt352_sleep(i2c); - dvb_unregister_frontend(mt352_ioctl, i2c); + /* Do a "hard" reset */ + mt352_write(mt352_reset_attach, sizeof(mt352_reset_attach)); + + if ( !(client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL)) ) { + kfree(state); + return -ENOMEM; + } + + 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))) { + i2c_detach_client(client); + kfree(client); + kfree(state); + 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 = FRONTEND_NAME, + .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 = { + .name = FRONTEND_NAME, + .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"); MODULE_LICENSE("GPL"); -MODULE_PARM(force_card, "i"); -MODULE_PARM_DESC(force_card, "<0: TUA6034 -- 1:AVDVBT771 -- 2: TDTC9251DH01C>"); |