summaryrefslogtreecommitdiff
path: root/linux/drivers/media/dvb/frontends/alps_tdlb7.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/drivers/media/dvb/frontends/alps_tdlb7.c')
-rw-r--r--linux/drivers/media/dvb/frontends/alps_tdlb7.c284
1 files changed, 147 insertions, 137 deletions
diff --git a/linux/drivers/media/dvb/frontends/alps_tdlb7.c b/linux/drivers/media/dvb/frontends/alps_tdlb7.c
index 8a94b2a83..bf9f8382f 100644
--- a/linux/drivers/media/dvb/frontends/alps_tdlb7.c
+++ b/linux/drivers/media/dvb/frontends/alps_tdlb7.c
@@ -20,31 +20,25 @@
*/
-
/*
- This driver needs a copy of the firmware file 'Sc_main.mc' from the Haupauge
- windows driver in the '/usr/lib/DVB/driver/frontends' directory.
- You can also pass the complete file name with the module parameter 'firmware_file'.
-
+ This driver needs a copy of the firmware file from the Haupauge
+ Windoze driver.
+
+ Copy 'Sc_main.mc' to '/usr/lib/hotplug/firmware/dvb-fe-tdlb7.fw'.
*/
+#define SP887X_DEFAULT_FIRMWARE "dvb-fe-tdlb7.fw"
-
-#define __KERNEL_SYSCALLS__
-#include <linux/module.h>
#include <linux/init.h>
-#include <linux/vmalloc.h>
-#include <linux/fs.h>
-#include <linux/unistd.h>
+#include <linux/module.h>
+#include <linux/firmware.h>
#include <linux/delay.h>
#include "dvb_frontend.h"
#include "dvb_functions.h"
-#ifndef CONFIG_ALPS_TDLB7_FIRMWARE_LOCATION
-#define CONFIG_ALPS_TDLB7_FIRMWARE_LOCATION "/usr/lib/DVB/driver/frontends/Sc_main.mc"
-#endif
+/* fixme: add this to i2c-id.h */
+#define I2C_DRIVERID_TDLB7 I2C_DRIVERID_EXP3
-static char * firmware_file = CONFIG_ALPS_TDLB7_FIRMWARE_LOCATION;
static int debug = 0;
#define dprintk if (debug) printk
@@ -55,9 +49,6 @@ static int debug = 0;
/* starting point for firmware in file 'Sc_main.mc' */
#define SP8870_FIRMWARE_OFFSET 0x0A
-
-static int errno;
-
static struct dvb_frontend_info tdlb7_info = {
.name = "Alps TDLB7",
.type = FE_OFDM,
@@ -72,13 +63,18 @@ static struct dvb_frontend_info tdlb7_info = {
FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER
};
-static int sp8870_writereg (struct dvb_i2c_bus *i2c, u16 reg, u16 data)
+struct tdlb7_state {
+ struct i2c_adapter *i2c;
+ struct dvb_adapter *dvb;
+};
+
+static int sp8870_writereg (struct i2c_adapter *i2c, u16 reg, u16 data)
{
u8 buf [] = { reg >> 8, reg & 0xff, data >> 8, data & 0xff };
struct i2c_msg msg = { .addr = 0x71, .flags = 0, .buf = buf, .len = 4 };
int err;
- if ((err = i2c->xfer (i2c, &msg, 1)) != 1) {
+ if ((err = i2c_transfer (i2c, &msg, 1)) != 1) {
dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data);
return -EREMOTEIO;
}
@@ -86,8 +82,7 @@ static int sp8870_writereg (struct dvb_i2c_bus *i2c, u16 reg, u16 data)
return 0;
}
-
-static u16 sp8870_readreg (struct dvb_i2c_bus *i2c, u16 reg)
+static u16 sp8870_readreg (struct i2c_adapter *i2c, u16 reg)
{
int ret;
u8 b0 [] = { reg >> 8 , reg & 0xff };
@@ -95,7 +90,7 @@ static u16 sp8870_readreg (struct dvb_i2c_bus *i2c, u16 reg)
struct i2c_msg msg [] = { { .addr = 0x71, .flags = 0, .buf = b0, .len = 2 },
{ .addr = 0x71, .flags = I2C_M_RD, .buf = b1, .len = 2 } };
- ret = i2c->xfer (i2c, msg, 2);
+ ret = i2c_transfer (i2c, msg, 2);
if (ret != 2) {
dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret);
@@ -105,13 +100,12 @@ static u16 sp8870_readreg (struct dvb_i2c_bus *i2c, u16 reg)
return (b1[0] << 8 | b1[1]);
}
-
-static int sp5659_write (struct dvb_i2c_bus *i2c, u8 data [4])
+static int sp5659_write (struct i2c_adapter *i2c, u8 data [4])
{
int ret;
struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = data, .len = 4 };
- ret = i2c->xfer (i2c, &msg, 1);
+ ret = i2c_transfer (i2c, &msg, 1);
if (ret != 1)
printk("%s: i/o error (ret == %i)\n", __FUNCTION__, ret);
@@ -119,8 +113,7 @@ static int sp5659_write (struct dvb_i2c_bus *i2c, u8 data [4])
return (ret != 1) ? -1 : 0;
}
-
-static void sp5659_set_tv_freq (struct dvb_i2c_bus *i2c, u32 freq)
+static void sp5659_set_tv_freq (struct i2c_adapter *i2c, u32 freq)
{
u32 div = (freq + 36200000) / 166666;
u8 buf [4];
@@ -142,60 +135,20 @@ static void sp5659_set_tv_freq (struct dvb_i2c_bus *i2c, u32 freq)
sp8870_writereg(i2c, 0x206, 0x000);
}
-
-static int sp8870_read_firmware_file (const char *fn, char **fp)
-{
- int fd;
- loff_t filesize;
- char *dp;
-
- fd = open(fn, 0, 0);
- if (fd == -1) {
- printk("%s: unable to open '%s'.\n", __FUNCTION__, fn);
- return -EIO;
- }
-
- filesize = lseek(fd, 0L, 2);
- if (filesize <= 0 || filesize < SP8870_FIRMWARE_OFFSET + SP8870_FIRMWARE_SIZE) {
- printk("%s: firmware filesize to small '%s'\n", __FUNCTION__, fn);
- sys_close(fd);
- return -EIO;
- }
-
- *fp= dp = vmalloc(SP8870_FIRMWARE_SIZE);
- if (dp == NULL) {
- printk("%s: out of memory loading '%s'.\n", __FUNCTION__, fn);
- sys_close(fd);
- return -EIO;
- }
-
- lseek(fd, SP8870_FIRMWARE_OFFSET, 0);
- if (read(fd, dp, SP8870_FIRMWARE_SIZE) != SP8870_FIRMWARE_SIZE) {
- printk("%s: failed to read '%s'.\n",__FUNCTION__, fn);
- vfree(dp);
- sys_close(fd);
- return -EIO;
- }
-
- sys_close(fd);
- *fp = dp;
-
- return 0;
-}
-
-
-static int sp8870_firmware_upload (struct dvb_i2c_bus *i2c)
+static int sp8870_firmware_upload (struct i2c_adapter *i2c, const struct firmware *fw)
{
struct i2c_msg msg;
- char *fw_buf = NULL;
+ char *fw_buf = fw->data;
int fw_pos;
u8 tx_buf[255];
int tx_len;
int err = 0;
- mm_segment_t fs = get_fs();
dprintk ("%s: ...\n", __FUNCTION__);
+ if (fw->size < SP8870_FIRMWARE_SIZE)
+ return -ENODEV;
+
// system controller stop
sp8870_writereg(i2c, 0x0F00, 0x0000);
@@ -205,15 +158,6 @@ static int sp8870_firmware_upload (struct dvb_i2c_bus *i2c)
// instruction RAM MWR
sp8870_writereg(i2c, 0x8F0A, ((SP8870_FIRMWARE_SIZE / 2) >> 16));
- // reading firmware file to buffer
- set_fs(get_ds());
- err = sp8870_read_firmware_file(firmware_file, (char**) &fw_buf);
- set_fs(fs);
- if (err != 0) {
- printk("%s: reading firmware file failed!\n", __FUNCTION__);
- return err;
- }
-
// do firmware upload
fw_pos = 0;
while (fw_pos < SP8870_FIRMWARE_SIZE){
@@ -226,23 +170,19 @@ static int sp8870_firmware_upload (struct dvb_i2c_bus *i2c)
msg.flags = 0;
msg.buf = tx_buf;
msg.len = tx_len + 2;
- if ((err = i2c->xfer (i2c, &msg, 1)) != 1) {
+ if ((err = i2c_transfer (i2c, &msg, 1)) != 1) {
printk("%s: firmware upload failed!\n", __FUNCTION__);
printk ("%s: i2c error (err == %i)\n", __FUNCTION__, err);
- vfree(fw_buf);
return err;
}
fw_pos += tx_len;
}
- vfree(fw_buf);
-
dprintk ("%s: done!\n", __FUNCTION__);
return 0;
};
-
-static void sp8870_microcontroller_stop (struct dvb_i2c_bus *i2c)
+static void sp8870_microcontroller_stop (struct i2c_adapter *i2c)
{
sp8870_writereg(i2c, 0x0F08, 0x000);
sp8870_writereg(i2c, 0x0F09, 0x000);
@@ -251,8 +191,7 @@ static void sp8870_microcontroller_stop (struct dvb_i2c_bus *i2c)
sp8870_writereg(i2c, 0x0F00, 0x000);
}
-
-static void sp8870_microcontroller_start (struct dvb_i2c_bus *i2c)
+static void sp8870_microcontroller_start (struct i2c_adapter *i2c)
{
sp8870_writereg(i2c, 0x0F08, 0x000);
sp8870_writereg(i2c, 0x0F09, 0x000);
@@ -264,8 +203,7 @@ static void sp8870_microcontroller_start (struct dvb_i2c_bus *i2c)
sp8870_readreg(i2c, 0x0D01);
}
-
-static int sp8870_init (struct dvb_i2c_bus *i2c)
+static int sp8870_init (struct i2c_adapter *i2c)
{
dprintk ("%s\n", __FUNCTION__);
@@ -291,8 +229,7 @@ static int sp8870_init (struct dvb_i2c_bus *i2c)
return 0;
}
-
-static int sp8870_read_status (struct dvb_i2c_bus *i2c, fe_status_t * fe_status)
+static int sp8870_read_status (struct i2c_adapter *i2c, fe_status_t * fe_status)
{
int status;
int signal;
@@ -317,8 +254,7 @@ static int sp8870_read_status (struct dvb_i2c_bus *i2c, fe_status_t * fe_status
return 0;
}
-
-static int sp8870_read_ber (struct dvb_i2c_bus *i2c, u32 * ber)
+static int sp8870_read_ber (struct i2c_adapter *i2c, u32 * ber)
{
int ret;
u32 tmp;
@@ -345,8 +281,7 @@ static int sp8870_read_ber (struct dvb_i2c_bus *i2c, u32 * ber)
return 0;
}
-
-static int sp8870_read_signal_strength (struct dvb_i2c_bus *i2c, u16 * signal)
+static int sp8870_read_signal_strength (struct i2c_adapter *i2c, u16 * signal)
{
int ret;
u16 tmp;
@@ -371,15 +306,13 @@ static int sp8870_read_signal_strength (struct dvb_i2c_bus *i2c, u16 * signal)
return 0;
}
-
-static int sp8870_read_snr(struct dvb_i2c_bus *i2c, u32* snr)
+static int sp8870_read_snr(struct i2c_adapter *i2c, u32* snr)
{
*snr = 0;
return -EOPNOTSUPP;
}
-
-static int sp8870_read_uncorrected_blocks (struct dvb_i2c_bus *i2c, u32* ublocks)
+static int sp8870_read_uncorrected_blocks (struct i2c_adapter *i2c, u32* ublocks)
{
int ret;
@@ -397,13 +330,11 @@ static int sp8870_read_uncorrected_blocks (struct dvb_i2c_bus *i2c, u32* ublocks
return 0;
}
-
-static int sp8870_read_data_valid_signal(struct dvb_i2c_bus *i2c)
+static int sp8870_read_data_valid_signal(struct i2c_adapter *i2c)
{
return (sp8870_readreg(i2c, 0x0D02) > 0);
}
-
static
int configure_reg0xc05 (struct dvb_frontend_parameters *p, u16 *reg0xc05)
{
@@ -476,8 +407,7 @@ int configure_reg0xc05 (struct dvb_frontend_parameters *p, u16 *reg0xc05)
return 0;
}
-
-static int sp8870_set_frontend_parameters (struct dvb_i2c_bus *i2c,
+static int sp8870_set_frontend_parameters (struct i2c_adapter *i2c,
struct dvb_frontend_parameters *p)
{
int err;
@@ -529,7 +459,6 @@ static int sp8870_set_frontend_parameters (struct dvb_i2c_bus *i2c,
return 0;
}
-
// number of trials to recover from lockup
#define MAXTRIALS 5
// maximum checks for data valid signal
@@ -540,7 +469,7 @@ static int lockups = 0;
// only for debugging: counter for channel switches
static int switches = 0;
-static int sp8870_set_frontend (struct dvb_i2c_bus *i2c, struct dvb_frontend_parameters *p)
+static int sp8870_set_frontend (struct i2c_adapter *i2c, struct dvb_frontend_parameters *p)
{
/*
The firmware of the sp8870 sometimes locks up after setting frontend parameters.
@@ -595,24 +524,22 @@ static int sp8870_set_frontend (struct dvb_i2c_bus *i2c, struct dvb_frontend_par
return 0;
}
-
-static int sp8870_sleep(struct dvb_i2c_bus *i2c)
+static int sp8870_sleep(struct i2c_adapter *i2c)
{
// tristate TS output and disable interface pins
return sp8870_writereg(i2c, 0xC18, 0x000);
}
-
-static int sp8870_wake_up(struct dvb_i2c_bus *i2c)
+static int sp8870_wake_up(struct i2c_adapter *i2c)
{
// enable TS output and interface pins
return sp8870_writereg(i2c, 0xC18, 0x00D);
}
-
static int tdlb7_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg)
{
- struct dvb_i2c_bus *i2c = fe->i2c;
+ struct tdlb7_state *state = (struct tdlb7_state *) fe->data;
+ struct i2c_adapter *i2c = state->i2c;
switch (cmd) {
case FE_GET_INFO:
@@ -667,61 +594,144 @@ static int tdlb7_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg)
return 0;
}
+static struct i2c_client client_template;
-static int tdlb7_attach (struct dvb_i2c_bus *i2c, void **data)
+static int attach_adapter(struct i2c_adapter *adapter)
{
- u8 b0 [] = { 0x02 , 0x00 };
+ struct i2c_client *client;
+ struct tdlb7_state *state;
+ const struct firmware *fw;
+ int ret;
+
+ u8 b0 [] = { 0x02 , 0x00 };
u8 b1 [] = { 0, 0 };
struct i2c_msg msg [] = { { .addr = 0x71, .flags = 0, .buf = b0, .len = 2 },
{ .addr = 0x71, .flags = I2C_M_RD, .buf = b1, .len = 2 } };
- dprintk ("%s\n", __FUNCTION__);
+ dprintk ("%s\n", __FUNCTION__);
+
+ if (NULL == (client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
+ return -ENOMEM;
+ }
- if (i2c->xfer (i2c, msg, 2) != 2)
+ if (NULL == (state = kmalloc(sizeof(struct tdlb7_state), GFP_KERNEL))) {
+ kfree(client);
+ return -ENOMEM;
+ }
+ state->i2c = adapter;
+
+ if (i2c_transfer (adapter, msg, 2) != 2) {
+ kfree(state);
+ kfree(client);
return -ENODEV;
+ }
- sp8870_firmware_upload(i2c);
+ memcpy(client, &client_template, sizeof(struct i2c_client));
+ client->adapter = adapter;
+ i2c_set_clientdata(client, (void*)state);
- return dvb_register_frontend (tdlb7_ioctl, i2c, NULL, &tdlb7_info);
-}
+ ret = i2c_attach_client(client);
+ if (ret) {
+ kfree(client);
+ kfree(state);
+ return ret;
+ }
+ /* request the firmware, this will block until someone uploads it */
+ printk("tdlb7: waiting for firmware upload...\n");
+ ret = request_firmware(&fw, SP887X_DEFAULT_FIRMWARE, &client->dev);
+ if (ret) {
+ printk("tdlb7: no firmware upload (timeout or file not found?)\n");
+ goto out;
+ }
-static void tdlb7_detach (struct dvb_i2c_bus *i2c, void *data)
+ ret = sp8870_firmware_upload(adapter, fw);
+ if (ret) {
+ printk("tdlb7: writing firmware to device failed\n");
+ goto out;
+ }
+
+ ret = dvb_register_frontend_new (tdlb7_ioctl, state->dvb, (void*) state, &tdlb7_info);
+ if (ret) {
+ printk("tdlb7: registering frontend to dvb-core failed.\n");
+ goto out;
+ }
+
+ return 0;
+out:
+ release_firmware(fw);
+ i2c_detach_client(client);
+ kfree(client);
+ kfree(state);
+ return ret;
+}
+
+static int detach_client(struct i2c_client *client)
{
+ struct tdlb7_state *state = (struct tdlb7_state*)i2c_get_clientdata(client);
+
dprintk ("%s\n", __FUNCTION__);
- dvb_unregister_frontend (tdlb7_ioctl, i2c);
+ dvb_unregister_frontend_new (tdlb7_ioctl, state->dvb);
+ i2c_detach_client(client);
+ BUG_ON(state->dvb);
+ kfree(client);
+ kfree(state);
+ return 0;
}
-
-static int __init init_tdlb7 (void)
+static int command (struct i2c_client *client, unsigned int cmd, void *arg)
{
+ struct tdlb7_state *state = (struct tdlb7_state*)i2c_get_clientdata(client);
+
dprintk ("%s\n", __FUNCTION__);
- return dvb_register_i2c_device (THIS_MODULE, tdlb7_attach, tdlb7_detach);
+ switch (cmd) {
+ case FE_REGISTER:
+ state->dvb = (struct dvb_adapter*)arg;
+ break;
+ case FE_UNREGISTER:
+ state->dvb = NULL;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+ return 0;
}
+static struct i2c_driver driver = {
+ .owner = THIS_MODULE,
+ .name = "tdlb7",
+ .id = I2C_DRIVERID_TDLB7,
+ .flags = I2C_DF_NOTIFY,
+ .attach_adapter = attach_adapter,
+ .detach_client = detach_client,
+ .command = command,
+};
-static void __exit exit_tdlb7 (void)
-{
- dprintk ("%s\n", __FUNCTION__);
+static struct i2c_client client_template = {
+ I2C_DEVNAME("tdlb7"),
+ .flags = I2C_CLIENT_ALLOW_USE,
+ .driver = &driver,
+};
- dvb_unregister_i2c_device (tdlb7_attach);
+static int __init init_tdlb7(void)
+{
+ return i2c_add_driver(&driver);
}
+static void __exit exit_tdlb7(void)
+{
+ if (i2c_del_driver(&driver))
+ printk("tdlb7: driver deregistration failed\n");
+}
module_init(init_tdlb7);
module_exit(exit_tdlb7);
-
MODULE_PARM(debug,"i");
MODULE_PARM_DESC(debug, "enable verbose debug messages");
-MODULE_PARM(firmware_file,"s");
-MODULE_PARM_DESC(firmware_file, "where to find the firmware file");
-
MODULE_DESCRIPTION("TDLB7 DVB-T Frontend");
MODULE_AUTHOR("Juergen Peitz");
MODULE_LICENSE("GPL");
-
-