diff options
author | Malcolm Priestley <tvboxspy@gmail.com> | 2010-08-28 17:07:37 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-10-20 23:04:53 -0400 |
commit | 1ae2c5893d091bdfa382cbcfa3e09461f3a6c884 (patch) | |
tree | 4d020cf4841c852eb8f1d97ea1b774ab42ad96ec | |
parent | f78729b40a01a72b189a0618e1cf58facb68c129 (diff) |
V4L/DVB: Support for Sharp IX2505V (marked B0017) DVB-S silicon tuner
Tuner used in Sharp BS2F7VZ7395 dvbs module.
When ix2505v tuner is attached to stv0288 form this module.
Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/dvb/frontends/Kconfig | 7 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/ix2505v.c | 324 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/ix2505v.h | 64 |
4 files changed, 396 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig index b5f6a04f9c12..d83632c06872 100644 --- a/drivers/media/dvb/frontends/Kconfig +++ b/drivers/media/dvb/frontends/Kconfig | |||
@@ -607,6 +607,13 @@ config DVB_TDA665x | |||
607 | Currently supported tuners: | 607 | Currently supported tuners: |
608 | * Panasonic ENV57H12D5 (ET-50DT) | 608 | * Panasonic ENV57H12D5 (ET-50DT) |
609 | 609 | ||
610 | config DVB_IX2505V | ||
611 | tristate "Sharp IX2505V silicon tuner" | ||
612 | depends on DVB_CORE && I2C | ||
613 | default m if DVB_FE_CUSTOMISE | ||
614 | help | ||
615 | A DVB-S tuner module. Say Y when you want to support this frontend. | ||
616 | |||
610 | comment "Tools to develop new frontends" | 617 | comment "Tools to develop new frontends" |
611 | 618 | ||
612 | config DVB_DUMMY_FE | 619 | config DVB_DUMMY_FE |
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile index 874e8ada4d1d..9b59e411d5b4 100644 --- a/drivers/media/dvb/frontends/Makefile +++ b/drivers/media/dvb/frontends/Makefile | |||
@@ -82,3 +82,4 @@ obj-$(CONFIG_DVB_ISL6423) += isl6423.o | |||
82 | obj-$(CONFIG_DVB_EC100) += ec100.o | 82 | obj-$(CONFIG_DVB_EC100) += ec100.o |
83 | obj-$(CONFIG_DVB_DS3000) += ds3000.o | 83 | obj-$(CONFIG_DVB_DS3000) += ds3000.o |
84 | obj-$(CONFIG_DVB_MB86A16) += mb86a16.o | 84 | obj-$(CONFIG_DVB_MB86A16) += mb86a16.o |
85 | obj-$(CONFIG_DVB_IX2505V) += ix2505v.o | ||
diff --git a/drivers/media/dvb/frontends/ix2505v.c b/drivers/media/dvb/frontends/ix2505v.c new file mode 100644 index 000000000000..e9fe6da6d162 --- /dev/null +++ b/drivers/media/dvb/frontends/ix2505v.c | |||
@@ -0,0 +1,324 @@ | |||
1 | /** | ||
2 | * Driver for Sharp IX2505V (marked B0017) DVB-S silicon tuner | ||
3 | * | ||
4 | * Copyright (C) 2010 Malcolm Priestley | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License Version 2, as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/dvb/frontend.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/types.h> | ||
25 | |||
26 | #include "ix2505v.h" | ||
27 | |||
28 | static int ix2505v_debug; | ||
29 | #define dprintk(level, args...) \ | ||
30 | do { if (ix2505v_debug & level) printk(KERN_DEBUG "ix2505v: " args); \ | ||
31 | } while (0) | ||
32 | |||
33 | #define deb_info(args...) dprintk(0x01, args) | ||
34 | #define deb_i2c(args...) dprintk(0x02, args) | ||
35 | |||
36 | struct ix2505v_state { | ||
37 | struct i2c_adapter *i2c; | ||
38 | const struct ix2505v_config *config; | ||
39 | u32 frequency; | ||
40 | }; | ||
41 | |||
42 | /** | ||
43 | * Data read format of the Sharp IX2505V B0017 | ||
44 | * | ||
45 | * byte1: 1 | 1 | 0 | 0 | 0 | MA1 | MA0 | 1 | ||
46 | * byte2: POR | FL | RD2 | RD1 | RD0 | X | X | X | ||
47 | * | ||
48 | * byte1 = address | ||
49 | * byte2; | ||
50 | * POR = Power on Reset (VCC H=<2.2v L=>2.2v) | ||
51 | * FL = Phase Lock (H=lock L=unlock) | ||
52 | * RD0-2 = Reserved internal operations | ||
53 | * | ||
54 | * Only POR can be used to check the tuner is present | ||
55 | * | ||
56 | * Caution: after byte2 the I2C reverts to write mode continuing to read | ||
57 | * may corrupt tuning data. | ||
58 | * | ||
59 | */ | ||
60 | |||
61 | static int ix2505v_read_status_reg(struct ix2505v_state *state) | ||
62 | { | ||
63 | u8 addr = state->config->tuner_address; | ||
64 | u8 b2[] = {0}; | ||
65 | int ret; | ||
66 | |||
67 | struct i2c_msg msg[1] = { | ||
68 | { .addr = addr, .flags = I2C_M_RD, .buf = b2, .len = 1 } | ||
69 | }; | ||
70 | |||
71 | ret = i2c_transfer(state->i2c, msg, 1); | ||
72 | deb_i2c("Read %s ", __func__); | ||
73 | |||
74 | return (ret = 1) ? (int) b2[0] : -1; | ||
75 | } | ||
76 | |||
77 | static int ix2505v_write(struct ix2505v_state *state, u8 buf[], u8 count) | ||
78 | { | ||
79 | struct i2c_msg msg[1] = { | ||
80 | { .addr = state->config->tuner_address, .flags = 0, | ||
81 | .buf = buf, .len = count }, | ||
82 | }; | ||
83 | |||
84 | int ret; | ||
85 | |||
86 | ret = i2c_transfer(state->i2c, msg, 1); | ||
87 | |||
88 | if (ret != 1) { | ||
89 | deb_i2c("%s: i2c error, ret=%d\n", __func__, ret); | ||
90 | return -EIO; | ||
91 | } | ||
92 | |||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | static int ix2505v_release(struct dvb_frontend *fe) | ||
97 | { | ||
98 | struct ix2505v_state *state = fe->tuner_priv; | ||
99 | |||
100 | fe->tuner_priv = NULL; | ||
101 | kfree(state); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Data write format of the Sharp IX2505V B0017 | ||
108 | * | ||
109 | * byte1: 1 | 1 | 0 | 0 | 0 | 0(MA1)| 0(MA0)| 0 | ||
110 | * byte2: 0 | BG1 | BG2 | N8 | N7 | N6 | N5 | N4 | ||
111 | * byte3: N3 | N2 | N1 | A5 | A4 | A3 | A2 | A1 | ||
112 | * byte4: 1 | 1(C1) | 1(C0) | PD5 | PD4 | TM | 0(RTS)| 1(REF) | ||
113 | * byte5: BA2 | BA1 | BA0 | PSC | PD3 |PD2/TS2|DIV/TS1|PD0/TS0 | ||
114 | * | ||
115 | * byte1 = address | ||
116 | * | ||
117 | * Write order | ||
118 | * 1) byte1 -> byte2 -> byte3 -> byte4 -> byte5 | ||
119 | * 2) byte1 -> byte4 -> byte5 -> byte2 -> byte3 | ||
120 | * 3) byte1 -> byte2 -> byte3 -> byte4 | ||
121 | * 4) byte1 -> byte4 -> byte5 -> byte2 | ||
122 | * 5) byte1 -> byte2 -> byte3 | ||
123 | * 6) byte1 -> byte4 -> byte5 | ||
124 | * 7) byte1 -> byte2 | ||
125 | * 8) byte1 -> byte4 | ||
126 | * | ||
127 | * Recommended Setup | ||
128 | * 1 -> 8 -> 6 | ||
129 | */ | ||
130 | |||
131 | static int ix2505v_set_params(struct dvb_frontend *fe, | ||
132 | struct dvb_frontend_parameters *params) | ||
133 | { | ||
134 | struct ix2505v_state *state = fe->tuner_priv; | ||
135 | u32 frequency = params->frequency; | ||
136 | u32 b_w = (params->u.qpsk.symbol_rate * 27) / 32000; | ||
137 | u32 div_factor, N , A, x; | ||
138 | int ret = 0, len; | ||
139 | u8 gain, cc, ref, psc, local_osc, lpf; | ||
140 | u8 data[4] = {0}; | ||
141 | |||
142 | if ((frequency < fe->ops.info.frequency_min) | ||
143 | || (frequency > fe->ops.info.frequency_max)) | ||
144 | return -EINVAL; | ||
145 | |||
146 | if (state->config->tuner_gain) | ||
147 | gain = (state->config->tuner_gain < 4) | ||
148 | ? state->config->tuner_gain : 0; | ||
149 | else | ||
150 | gain = 0x0; | ||
151 | |||
152 | if (state->config->tuner_chargepump) | ||
153 | cc = state->config->tuner_chargepump; | ||
154 | else | ||
155 | cc = 0x3; | ||
156 | |||
157 | ref = 8; /* REF =1 */ | ||
158 | psc = 32; /* PSC = 0 */ | ||
159 | |||
160 | div_factor = (frequency * ref) / 40; /* local osc = 4Mhz */ | ||
161 | x = div_factor / psc; | ||
162 | N = x/100; | ||
163 | A = ((x - (N * 100)) * psc) / 100; | ||
164 | |||
165 | data[0] = ((gain & 0x3) << 5) | (N >> 3); | ||
166 | data[1] = (N << 5) | (A & 0x1f); | ||
167 | data[2] = 0x81 | ((cc & 0x3) << 5) ; /*PD5,PD4 & TM = 0|C1,C0|REF=1*/ | ||
168 | |||
169 | deb_info("Frq=%d x=%d N=%d A=%d \n", frequency, x, N, A); | ||
170 | |||
171 | if (frequency <= 1065000) | ||
172 | local_osc = (6 << 5) | 2; | ||
173 | else if (frequency <= 1170000) | ||
174 | local_osc = (7 << 5) | 2; | ||
175 | else if (frequency <= 1300000) | ||
176 | local_osc = (1 << 5); | ||
177 | else if (frequency <= 1445000) | ||
178 | local_osc = (2 << 5); | ||
179 | else if (frequency <= 1607000) | ||
180 | local_osc = (3 << 5); | ||
181 | else if (frequency <= 1778000) | ||
182 | local_osc = (4 << 5); | ||
183 | else if (frequency <= 1942000) | ||
184 | local_osc = (5 << 5); | ||
185 | else /*frequency up to 2150000*/ | ||
186 | local_osc = (6 << 5); | ||
187 | |||
188 | data[3] = local_osc; /* all other bits set 0 */ | ||
189 | |||
190 | |||
191 | if (b_w <= 10000) | ||
192 | lpf = 0xc; | ||
193 | else if (b_w <= 12000) | ||
194 | lpf = 0x2; | ||
195 | else if (b_w <= 14000) | ||
196 | lpf = 0xa; | ||
197 | else if (b_w <= 16000) | ||
198 | lpf = 0x6; | ||
199 | else if (b_w <= 18000) | ||
200 | lpf = 0xe; | ||
201 | else if (b_w <= 20000) | ||
202 | lpf = 0x1; | ||
203 | else if (b_w <= 22000) | ||
204 | lpf = 0x9; | ||
205 | else if (b_w <= 24000) | ||
206 | lpf = 0x5; | ||
207 | else if (b_w <= 26000) | ||
208 | lpf = 0xd; | ||
209 | else if (b_w <= 28000) | ||
210 | lpf = 0x3; | ||
211 | else | ||
212 | lpf = 0xb; | ||
213 | |||
214 | deb_info("Osc=%x b_w=%x lpf=%x\n", local_osc, b_w, lpf); | ||
215 | deb_info("Data 0=[%x%x%x%x] \n", data[0], data[1], data[2], data[3]); | ||
216 | |||
217 | if (fe->ops.i2c_gate_ctrl) | ||
218 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
219 | |||
220 | len = sizeof(data); | ||
221 | |||
222 | ret |= ix2505v_write(state, data, len); | ||
223 | |||
224 | data[2] |= 0x4; /* set TM = 1 other bits same */ | ||
225 | |||
226 | len = 1; | ||
227 | ret |= ix2505v_write(state, &data[2], len); /* write byte 4 only */ | ||
228 | |||
229 | |||
230 | msleep(10); | ||
231 | |||
232 | data[2] |= ((lpf >> 2) & 0x3) << 3; /* lpf */ | ||
233 | data[3] |= (lpf & 0x3) << 2; | ||
234 | |||
235 | deb_info("Data 2=[%x%x] \n", data[2], data[3]); | ||
236 | |||
237 | len = 2; | ||
238 | ret |= ix2505v_write(state, &data[2], len); /* write byte 4 & 5 */ | ||
239 | |||
240 | if (fe->ops.i2c_gate_ctrl) | ||
241 | fe->ops.i2c_gate_ctrl(fe, 0); | ||
242 | |||
243 | if (state->config->min_delay_ms) | ||
244 | msleep(state->config->min_delay_ms); | ||
245 | |||
246 | state->frequency = frequency; | ||
247 | |||
248 | return ret; | ||
249 | } | ||
250 | |||
251 | static int ix2505v_get_frequency(struct dvb_frontend *fe, u32 *frequency) | ||
252 | { | ||
253 | struct ix2505v_state *state = fe->tuner_priv; | ||
254 | |||
255 | *frequency = state->frequency; | ||
256 | |||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | static struct dvb_tuner_ops ix2505v_tuner_ops = { | ||
261 | .info = { | ||
262 | .name = "Sharp IX2505V (B0017)", | ||
263 | .frequency_min = 950000, | ||
264 | .frequency_max = 2175000 | ||
265 | }, | ||
266 | .release = ix2505v_release, | ||
267 | .set_params = ix2505v_set_params, | ||
268 | .get_frequency = ix2505v_get_frequency, | ||
269 | }; | ||
270 | |||
271 | struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe, | ||
272 | const struct ix2505v_config *config, | ||
273 | struct i2c_adapter *i2c) | ||
274 | { | ||
275 | struct ix2505v_state *state = NULL; | ||
276 | int ret; | ||
277 | |||
278 | if (NULL == config) { | ||
279 | deb_i2c("%s: no config ", __func__); | ||
280 | goto error; | ||
281 | } | ||
282 | |||
283 | state = kzalloc(sizeof(struct ix2505v_state), GFP_KERNEL); | ||
284 | if (NULL == state) | ||
285 | return NULL; | ||
286 | |||
287 | state->config = config; | ||
288 | state->i2c = i2c; | ||
289 | |||
290 | if (state->config->tuner_write_only) { | ||
291 | if (fe->ops.i2c_gate_ctrl) | ||
292 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
293 | |||
294 | ret = ix2505v_read_status_reg(state); | ||
295 | |||
296 | if (ret & 0x80) { | ||
297 | deb_i2c("%s: No IX2505V found\n", __func__); | ||
298 | goto error; | ||
299 | } | ||
300 | |||
301 | if (fe->ops.i2c_gate_ctrl) | ||
302 | fe->ops.i2c_gate_ctrl(fe, 0); | ||
303 | } | ||
304 | |||
305 | fe->tuner_priv = state; | ||
306 | |||
307 | memcpy(&fe->ops.tuner_ops, &ix2505v_tuner_ops, | ||
308 | sizeof(struct dvb_tuner_ops)); | ||
309 | deb_i2c("%s: initialization (%s addr=0x%02x) ok\n", | ||
310 | __func__, fe->ops.tuner_ops.info.name, config->tuner_address); | ||
311 | |||
312 | return fe; | ||
313 | |||
314 | error: | ||
315 | ix2505v_release(fe); | ||
316 | return NULL; | ||
317 | } | ||
318 | EXPORT_SYMBOL(ix2505v_attach); | ||
319 | |||
320 | module_param_named(debug, ix2505v_debug, int, 0644); | ||
321 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); | ||
322 | MODULE_DESCRIPTION("DVB IX2505V tuner driver"); | ||
323 | MODULE_AUTHOR("Malcolm Priestley"); | ||
324 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/dvb/frontends/ix2505v.h b/drivers/media/dvb/frontends/ix2505v.h new file mode 100644 index 000000000000..67e89d616d50 --- /dev/null +++ b/drivers/media/dvb/frontends/ix2505v.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /** | ||
2 | * Driver for Sharp IX2505V (marked B0017) DVB-S silicon tuner | ||
3 | * | ||
4 | * Copyright (C) 2010 Malcolm Priestley | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License Version 2, as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | */ | ||
19 | |||
20 | #ifndef DVB_IX2505V_H | ||
21 | #define DVB_IX2505V_H | ||
22 | |||
23 | #include <linux/i2c.h> | ||
24 | #include "dvb_frontend.h" | ||
25 | |||
26 | /** | ||
27 | * Attach a ix2505v tuner to the supplied frontend structure. | ||
28 | * | ||
29 | * @param fe Frontend to attach to. | ||
30 | * @param config ix2505v_config structure | ||
31 | * @return FE pointer on success, NULL on failure. | ||
32 | */ | ||
33 | |||
34 | struct ix2505v_config { | ||
35 | u8 tuner_address; | ||
36 | |||
37 | /*Baseband AMP gain control 0/1=0dB(default) 2=-2bB 3=-4dB */ | ||
38 | u8 tuner_gain; | ||
39 | |||
40 | /*Charge pump output +/- 0=120 1=260 2=555 3=1200(default) */ | ||
41 | u8 tuner_chargepump; | ||
42 | |||
43 | /* delay after tune */ | ||
44 | int min_delay_ms; | ||
45 | |||
46 | /* disables reads*/ | ||
47 | u8 tuner_write_only; | ||
48 | |||
49 | }; | ||
50 | |||
51 | #if defined(CONFIG_DVB_IX2505V) || \ | ||
52 | (defined(CONFIG_DVB_IX2505V_MODULE) && defined(MODULE)) | ||
53 | extern struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe, | ||
54 | const struct ix2505v_config *config, struct i2c_adapter *i2c); | ||
55 | #else | ||
56 | static inline struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe, | ||
57 | const struct ix2505v_config *config, struct i2c_adapter *i2c) | ||
58 | { | ||
59 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
60 | return NULL; | ||
61 | } | ||
62 | #endif | ||
63 | |||
64 | #endif /* DVB_IX2505V_H */ | ||