diff options
Diffstat (limited to 'drivers/media/dvb/dvb-usb/dtv5100.c')
-rw-r--r-- | drivers/media/dvb/dvb-usb/dtv5100.c | 94 |
1 files changed, 59 insertions, 35 deletions
diff --git a/drivers/media/dvb/dvb-usb/dtv5100.c b/drivers/media/dvb/dvb-usb/dtv5100.c index f89d01755eab..7168a49cecf4 100644 --- a/drivers/media/dvb/dvb-usb/dtv5100.c +++ b/drivers/media/dvb/dvb-usb/dtv5100.c | |||
@@ -22,6 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include "dtv5100.h" | 24 | #include "dtv5100.h" |
25 | #include "zl10353.h" | ||
25 | #include "qt1010.h" | 26 | #include "qt1010.h" |
26 | 27 | ||
27 | /* debug */ | 28 | /* debug */ |
@@ -30,25 +31,44 @@ module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644); | |||
30 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); | 31 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); |
31 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | 32 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
32 | 33 | ||
33 | static int dtv5100_read_reg(struct dvb_usb_device *d, u8 addr, u8 reg, u8 *value) | 34 | static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr, |
35 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) | ||
34 | { | 36 | { |
35 | return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), | 37 | u8 request; |
36 | DTV5100_I2C_READ, USB_TYPE_VENDOR|USB_DIR_IN, | 38 | u8 type; |
37 | 0, (addr << 8) + reg, value, 1, | 39 | u16 value; |
38 | DTV5100_USB_TIMEOUT); | 40 | u16 index; |
39 | } | 41 | |
42 | switch (wlen) { | ||
43 | case 1: | ||
44 | /* write { reg }, read { value } */ | ||
45 | request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_READ : | ||
46 | DTV5100_TUNER_READ); | ||
47 | type = USB_TYPE_VENDOR|USB_DIR_IN; | ||
48 | value = 0; | ||
49 | break; | ||
50 | case 2: | ||
51 | /* write { reg, value } */ | ||
52 | request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_WRITE : | ||
53 | DTV5100_TUNER_WRITE); | ||
54 | type = USB_TYPE_VENDOR|USB_DIR_OUT; | ||
55 | value = wbuf[1]; | ||
56 | break; | ||
57 | default: | ||
58 | warn("wlen = %x, aborting.", wlen); | ||
59 | return -EINVAL; | ||
60 | } | ||
61 | index = (addr << 8) + wbuf[0]; | ||
40 | 62 | ||
41 | static int dtv5100_write_reg(struct dvb_usb_device *d, u8 addr, u8 reg, u8 value) | 63 | msleep(1); /* avoid I2C errors */ |
42 | { | 64 | return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request, |
43 | return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), | 65 | type, value, index, rbuf, rlen, |
44 | DTV5100_I2C_WRITE, USB_TYPE_VENDOR|USB_DIR_OUT, | ||
45 | value, (addr << 8) + reg, NULL, 0, | ||
46 | DTV5100_USB_TIMEOUT); | 66 | DTV5100_USB_TIMEOUT); |
47 | } | 67 | } |
48 | 68 | ||
49 | /* I2C */ | 69 | /* I2C */ |
50 | static int dtv5100_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], | 70 | static int dtv5100_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
51 | int num) | 71 | int num) |
52 | { | 72 | { |
53 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | 73 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
54 | int i; | 74 | int i; |
@@ -60,25 +80,16 @@ static int dtv5100_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], | |||
60 | return -EAGAIN; | 80 | return -EAGAIN; |
61 | 81 | ||
62 | for (i = 0; i < num; i++) { | 82 | for (i = 0; i < num; i++) { |
83 | /* write/read request */ | ||
63 | if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { | 84 | if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { |
64 | /* write/read request, 2 messages | 85 | if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf, |
65 | * msg = { | 86 | msg[i].len, msg[i+1].buf, |
66 | * { reg }, | 87 | msg[i+1].len) < 0) |
67 | * { val }, | ||
68 | * } | ||
69 | */ | ||
70 | if (dtv5100_read_reg(d, msg[i].addr, msg[i].buf[0], msg[i+1].buf) < 0) | ||
71 | break; | 88 | break; |
72 | i++; | 89 | i++; |
73 | } else { | 90 | } else if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf, |
74 | /* write request, 1 message | 91 | msg[i].len, NULL, 0) < 0) |
75 | * msg = { | ||
76 | * { reg, val }, | ||
77 | * } | ||
78 | */ | ||
79 | if (dtv5100_write_reg(d, msg[i].addr, msg[i].buf[0], msg[i].buf[1]) < 0) | ||
80 | break; | 92 | break; |
81 | } | ||
82 | } | 93 | } |
83 | 94 | ||
84 | mutex_unlock(&d->i2c_mutex); | 95 | mutex_unlock(&d->i2c_mutex); |
@@ -96,14 +107,27 @@ static struct i2c_algorithm dtv5100_i2c_algo = { | |||
96 | }; | 107 | }; |
97 | 108 | ||
98 | /* Callbacks for DVB USB */ | 109 | /* Callbacks for DVB USB */ |
110 | static struct zl10353_config dtv5100_zl10353_config = { | ||
111 | .demod_address = DTV5100_DEMOD_ADDR, | ||
112 | .no_tuner = 1, | ||
113 | .parallel_ts = 1, | ||
114 | }; | ||
115 | |||
99 | static int dtv5100_frontend_attach(struct dvb_usb_adapter *adap) | 116 | static int dtv5100_frontend_attach(struct dvb_usb_adapter *adap) |
100 | { | 117 | { |
101 | adap->fe = dtv5100_fe_attach(); | 118 | adap->fe = dvb_attach(zl10353_attach, &dtv5100_zl10353_config, |
119 | &adap->dev->i2c_adap); | ||
120 | if (adap->fe == NULL) | ||
121 | return -EIO; | ||
122 | |||
123 | /* disable i2c gate, or it won't work... is this safe? */ | ||
124 | adap->fe->ops.i2c_gate_ctrl = NULL; | ||
125 | |||
102 | return 0; | 126 | return 0; |
103 | } | 127 | } |
104 | 128 | ||
105 | static struct qt1010_config dtv5100_qt1010_config = { | 129 | static struct qt1010_config dtv5100_qt1010_config = { |
106 | .i2c_address = 0xc4 | 130 | .i2c_address = DTV5100_TUNER_ADDR |
107 | }; | 131 | }; |
108 | 132 | ||
109 | static int dtv5100_tuner_attach(struct dvb_usb_adapter *adap) | 133 | static int dtv5100_tuner_attach(struct dvb_usb_adapter *adap) |
@@ -122,12 +146,7 @@ static int dtv5100_probe(struct usb_interface *intf, | |||
122 | int i, ret; | 146 | int i, ret; |
123 | struct usb_device *udev = interface_to_usbdev(intf); | 147 | struct usb_device *udev = interface_to_usbdev(intf); |
124 | 148 | ||
125 | ret = dvb_usb_device_init(intf, &dtv5100_properties, | 149 | /* initialize non qt1010/zl10353 part? */ |
126 | THIS_MODULE, NULL, adapter_nr); | ||
127 | if (ret) | ||
128 | return ret; | ||
129 | |||
130 | /* initialize frontend & non qt1010 part? */ | ||
131 | for (i = 0; dtv5100_init[i].request; i++) | 150 | for (i = 0; dtv5100_init[i].request; i++) |
132 | { | 151 | { |
133 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | 152 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
@@ -140,6 +159,11 @@ static int dtv5100_probe(struct usb_interface *intf, | |||
140 | return ret; | 159 | return ret; |
141 | } | 160 | } |
142 | 161 | ||
162 | ret = dvb_usb_device_init(intf, &dtv5100_properties, | ||
163 | THIS_MODULE, NULL, adapter_nr); | ||
164 | if (ret) | ||
165 | return ret; | ||
166 | |||
143 | return 0; | 167 | return 0; |
144 | } | 168 | } |
145 | 169 | ||