diff options
-rw-r--r-- | drivers/media/dvb/Kconfig | 4 | ||||
-rw-r--r-- | drivers/media/dvb/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/Kconfig | 12 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/Makefile | 5 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/pt1.c | 1056 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/va1j5jf8007s.c | 658 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/va1j5jf8007s.h | 40 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/va1j5jf8007t.c | 468 | ||||
-rw-r--r-- | drivers/media/dvb/pt1/va1j5jf8007t.h | 40 |
9 files changed, 2284 insertions, 1 deletions
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig index 1d0e4b1ef10c..35d0817126e9 100644 --- a/drivers/media/dvb/Kconfig +++ b/drivers/media/dvb/Kconfig | |||
@@ -68,6 +68,10 @@ comment "Supported FireWire (IEEE 1394) Adapters" | |||
68 | depends on DVB_CORE && IEEE1394 | 68 | depends on DVB_CORE && IEEE1394 |
69 | source "drivers/media/dvb/firewire/Kconfig" | 69 | source "drivers/media/dvb/firewire/Kconfig" |
70 | 70 | ||
71 | comment "Supported Earthsoft PT1 Adapters" | ||
72 | depends on DVB_CORE && PCI && I2C | ||
73 | source "drivers/media/dvb/pt1/Kconfig" | ||
74 | |||
71 | comment "Supported DVB Frontends" | 75 | comment "Supported DVB Frontends" |
72 | depends on DVB_CORE | 76 | depends on DVB_CORE |
73 | source "drivers/media/dvb/frontends/Kconfig" | 77 | source "drivers/media/dvb/frontends/Kconfig" |
diff --git a/drivers/media/dvb/Makefile b/drivers/media/dvb/Makefile index 6092a5bb5a7d..16d262ddb45d 100644 --- a/drivers/media/dvb/Makefile +++ b/drivers/media/dvb/Makefile | |||
@@ -2,6 +2,6 @@ | |||
2 | # Makefile for the kernel multimedia device drivers. | 2 | # Makefile for the kernel multimedia device drivers. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dvb-usb/ pluto2/ siano/ dm1105/ | 5 | obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dvb-usb/ pluto2/ siano/ dm1105/ pt1/ |
6 | 6 | ||
7 | obj-$(CONFIG_DVB_FIREDTV) += firewire/ | 7 | obj-$(CONFIG_DVB_FIREDTV) += firewire/ |
diff --git a/drivers/media/dvb/pt1/Kconfig b/drivers/media/dvb/pt1/Kconfig new file mode 100644 index 000000000000..24501d5bf70d --- /dev/null +++ b/drivers/media/dvb/pt1/Kconfig | |||
@@ -0,0 +1,12 @@ | |||
1 | config DVB_PT1 | ||
2 | tristate "PT1 cards" | ||
3 | depends on DVB_CORE && PCI && I2C | ||
4 | help | ||
5 | Support for Earthsoft PT1 PCI cards. | ||
6 | |||
7 | Since these cards have no MPEG decoder onboard, they transmit | ||
8 | only compressed MPEG data over the PCI bus, so you need | ||
9 | an external software decoder to watch TV on your computer. | ||
10 | |||
11 | Say Y or M if you own such a device and want to use it. | ||
12 | |||
diff --git a/drivers/media/dvb/pt1/Makefile b/drivers/media/dvb/pt1/Makefile new file mode 100644 index 000000000000..a66da17bbe31 --- /dev/null +++ b/drivers/media/dvb/pt1/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | earth-pt1-objs := pt1.o va1j5jf8007s.o va1j5jf8007t.o | ||
2 | |||
3 | obj-$(CONFIG_DVB_PT1) += earth-pt1.o | ||
4 | |||
5 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core -Idrivers/media/dvb/frontends | ||
diff --git a/drivers/media/dvb/pt1/pt1.c b/drivers/media/dvb/pt1/pt1.c new file mode 100644 index 000000000000..ef0f7d235e2a --- /dev/null +++ b/drivers/media/dvb/pt1/pt1.c | |||
@@ -0,0 +1,1056 @@ | |||
1 | /* | ||
2 | * driver for Earthsoft PT1 | ||
3 | * | ||
4 | * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> | ||
5 | * | ||
6 | * based on pt1dvr - http://pt1dvr.sourceforge.jp/ | ||
7 | * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/pci.h> | ||
27 | #include <linux/kthread.h> | ||
28 | #include <linux/freezer.h> | ||
29 | |||
30 | #include "dvbdev.h" | ||
31 | #include "dvb_demux.h" | ||
32 | #include "dmxdev.h" | ||
33 | #include "dvb_net.h" | ||
34 | #include "dvb_frontend.h" | ||
35 | |||
36 | #include "va1j5jf8007t.h" | ||
37 | #include "va1j5jf8007s.h" | ||
38 | |||
39 | #define DRIVER_NAME "earth-pt1" | ||
40 | |||
41 | #define PT1_PAGE_SHIFT 12 | ||
42 | #define PT1_PAGE_SIZE (1 << PT1_PAGE_SHIFT) | ||
43 | #define PT1_NR_UPACKETS 1024 | ||
44 | #define PT1_NR_BUFS 511 | ||
45 | |||
46 | struct pt1_buffer_page { | ||
47 | __le32 upackets[PT1_NR_UPACKETS]; | ||
48 | }; | ||
49 | |||
50 | struct pt1_table_page { | ||
51 | __le32 next_pfn; | ||
52 | __le32 buf_pfns[PT1_NR_BUFS]; | ||
53 | }; | ||
54 | |||
55 | struct pt1_buffer { | ||
56 | struct pt1_buffer_page *page; | ||
57 | dma_addr_t addr; | ||
58 | }; | ||
59 | |||
60 | struct pt1_table { | ||
61 | struct pt1_table_page *page; | ||
62 | dma_addr_t addr; | ||
63 | struct pt1_buffer bufs[PT1_NR_BUFS]; | ||
64 | }; | ||
65 | |||
66 | #define PT1_NR_ADAPS 4 | ||
67 | |||
68 | struct pt1_adapter; | ||
69 | |||
70 | struct pt1 { | ||
71 | struct pci_dev *pdev; | ||
72 | void __iomem *regs; | ||
73 | struct i2c_adapter i2c_adap; | ||
74 | int i2c_running; | ||
75 | struct pt1_adapter *adaps[PT1_NR_ADAPS]; | ||
76 | struct pt1_table *tables; | ||
77 | struct task_struct *kthread; | ||
78 | }; | ||
79 | |||
80 | struct pt1_adapter { | ||
81 | struct pt1 *pt1; | ||
82 | int index; | ||
83 | |||
84 | u8 *buf; | ||
85 | int upacket_count; | ||
86 | int packet_count; | ||
87 | |||
88 | struct dvb_adapter adap; | ||
89 | struct dvb_demux demux; | ||
90 | int users; | ||
91 | struct dmxdev dmxdev; | ||
92 | struct dvb_net net; | ||
93 | struct dvb_frontend *fe; | ||
94 | int (*orig_set_voltage)(struct dvb_frontend *fe, | ||
95 | fe_sec_voltage_t voltage); | ||
96 | }; | ||
97 | |||
98 | #define pt1_printk(level, pt1, format, arg...) \ | ||
99 | dev_printk(level, &(pt1)->pdev->dev, format, ##arg) | ||
100 | |||
101 | static void pt1_write_reg(struct pt1 *pt1, int reg, u32 data) | ||
102 | { | ||
103 | writel(data, pt1->regs + reg * 4); | ||
104 | } | ||
105 | |||
106 | static u32 pt1_read_reg(struct pt1 *pt1, int reg) | ||
107 | { | ||
108 | return readl(pt1->regs + reg * 4); | ||
109 | } | ||
110 | |||
111 | static int pt1_nr_tables = 64; | ||
112 | module_param_named(nr_tables, pt1_nr_tables, int, 0); | ||
113 | |||
114 | static void pt1_increment_table_count(struct pt1 *pt1) | ||
115 | { | ||
116 | pt1_write_reg(pt1, 0, 0x00000020); | ||
117 | } | ||
118 | |||
119 | static void pt1_init_table_count(struct pt1 *pt1) | ||
120 | { | ||
121 | pt1_write_reg(pt1, 0, 0x00000010); | ||
122 | } | ||
123 | |||
124 | static void pt1_register_tables(struct pt1 *pt1, u32 first_pfn) | ||
125 | { | ||
126 | pt1_write_reg(pt1, 5, first_pfn); | ||
127 | pt1_write_reg(pt1, 0, 0x0c000040); | ||
128 | } | ||
129 | |||
130 | static void pt1_unregister_tables(struct pt1 *pt1) | ||
131 | { | ||
132 | pt1_write_reg(pt1, 0, 0x08080000); | ||
133 | } | ||
134 | |||
135 | static int pt1_sync(struct pt1 *pt1) | ||
136 | { | ||
137 | int i; | ||
138 | for (i = 0; i < 57; i++) { | ||
139 | if (pt1_read_reg(pt1, 0) & 0x20000000) | ||
140 | return 0; | ||
141 | pt1_write_reg(pt1, 0, 0x00000008); | ||
142 | } | ||
143 | pt1_printk(KERN_ERR, pt1, "could not sync\n"); | ||
144 | return -EIO; | ||
145 | } | ||
146 | |||
147 | static u64 pt1_identify(struct pt1 *pt1) | ||
148 | { | ||
149 | int i; | ||
150 | u64 id; | ||
151 | id = 0; | ||
152 | for (i = 0; i < 57; i++) { | ||
153 | id |= (u64)(pt1_read_reg(pt1, 0) >> 30 & 1) << i; | ||
154 | pt1_write_reg(pt1, 0, 0x00000008); | ||
155 | } | ||
156 | return id; | ||
157 | } | ||
158 | |||
159 | static int pt1_unlock(struct pt1 *pt1) | ||
160 | { | ||
161 | int i; | ||
162 | pt1_write_reg(pt1, 0, 0x00000008); | ||
163 | for (i = 0; i < 3; i++) { | ||
164 | if (pt1_read_reg(pt1, 0) & 0x80000000) | ||
165 | return 0; | ||
166 | schedule_timeout_uninterruptible((HZ + 999) / 1000); | ||
167 | } | ||
168 | pt1_printk(KERN_ERR, pt1, "could not unlock\n"); | ||
169 | return -EIO; | ||
170 | } | ||
171 | |||
172 | static int pt1_reset_pci(struct pt1 *pt1) | ||
173 | { | ||
174 | int i; | ||
175 | pt1_write_reg(pt1, 0, 0x01010000); | ||
176 | pt1_write_reg(pt1, 0, 0x01000000); | ||
177 | for (i = 0; i < 10; i++) { | ||
178 | if (pt1_read_reg(pt1, 0) & 0x00000001) | ||
179 | return 0; | ||
180 | schedule_timeout_uninterruptible((HZ + 999) / 1000); | ||
181 | } | ||
182 | pt1_printk(KERN_ERR, pt1, "could not reset PCI\n"); | ||
183 | return -EIO; | ||
184 | } | ||
185 | |||
186 | static int pt1_reset_ram(struct pt1 *pt1) | ||
187 | { | ||
188 | int i; | ||
189 | pt1_write_reg(pt1, 0, 0x02020000); | ||
190 | pt1_write_reg(pt1, 0, 0x02000000); | ||
191 | for (i = 0; i < 10; i++) { | ||
192 | if (pt1_read_reg(pt1, 0) & 0x00000002) | ||
193 | return 0; | ||
194 | schedule_timeout_uninterruptible((HZ + 999) / 1000); | ||
195 | } | ||
196 | pt1_printk(KERN_ERR, pt1, "could not reset RAM\n"); | ||
197 | return -EIO; | ||
198 | } | ||
199 | |||
200 | static int pt1_do_enable_ram(struct pt1 *pt1) | ||
201 | { | ||
202 | int i, j; | ||
203 | u32 status; | ||
204 | status = pt1_read_reg(pt1, 0) & 0x00000004; | ||
205 | pt1_write_reg(pt1, 0, 0x00000002); | ||
206 | for (i = 0; i < 10; i++) { | ||
207 | for (j = 0; j < 1024; j++) { | ||
208 | if ((pt1_read_reg(pt1, 0) & 0x00000004) != status) | ||
209 | return 0; | ||
210 | } | ||
211 | schedule_timeout_uninterruptible((HZ + 999) / 1000); | ||
212 | } | ||
213 | pt1_printk(KERN_ERR, pt1, "could not enable RAM\n"); | ||
214 | return -EIO; | ||
215 | } | ||
216 | |||
217 | static int pt1_enable_ram(struct pt1 *pt1) | ||
218 | { | ||
219 | int i, ret; | ||
220 | schedule_timeout_uninterruptible((HZ + 999) / 1000); | ||
221 | for (i = 0; i < 10; i++) { | ||
222 | ret = pt1_do_enable_ram(pt1); | ||
223 | if (ret < 0) | ||
224 | return ret; | ||
225 | } | ||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | static void pt1_disable_ram(struct pt1 *pt1) | ||
230 | { | ||
231 | pt1_write_reg(pt1, 0, 0x0b0b0000); | ||
232 | } | ||
233 | |||
234 | static void pt1_set_stream(struct pt1 *pt1, int index, int enabled) | ||
235 | { | ||
236 | pt1_write_reg(pt1, 2, 1 << (index + 8) | enabled << index); | ||
237 | } | ||
238 | |||
239 | static void pt1_init_streams(struct pt1 *pt1) | ||
240 | { | ||
241 | int i; | ||
242 | for (i = 0; i < PT1_NR_ADAPS; i++) | ||
243 | pt1_set_stream(pt1, i, 0); | ||
244 | } | ||
245 | |||
246 | static int pt1_filter(struct pt1 *pt1, struct pt1_buffer_page *page) | ||
247 | { | ||
248 | u32 upacket; | ||
249 | int i; | ||
250 | int index; | ||
251 | struct pt1_adapter *adap; | ||
252 | int offset; | ||
253 | u8 *buf; | ||
254 | |||
255 | if (!page->upackets[PT1_NR_UPACKETS - 1]) | ||
256 | return 0; | ||
257 | |||
258 | for (i = 0; i < PT1_NR_UPACKETS; i++) { | ||
259 | upacket = le32_to_cpu(page->upackets[i]); | ||
260 | index = (upacket >> 29) - 1; | ||
261 | if (index < 0 || index >= PT1_NR_ADAPS) | ||
262 | continue; | ||
263 | |||
264 | adap = pt1->adaps[index]; | ||
265 | if (upacket >> 25 & 1) | ||
266 | adap->upacket_count = 0; | ||
267 | else if (!adap->upacket_count) | ||
268 | continue; | ||
269 | |||
270 | buf = adap->buf; | ||
271 | offset = adap->packet_count * 188 + adap->upacket_count * 3; | ||
272 | buf[offset] = upacket >> 16; | ||
273 | buf[offset + 1] = upacket >> 8; | ||
274 | if (adap->upacket_count != 62) | ||
275 | buf[offset + 2] = upacket; | ||
276 | |||
277 | if (++adap->upacket_count >= 63) { | ||
278 | adap->upacket_count = 0; | ||
279 | if (++adap->packet_count >= 21) { | ||
280 | dvb_dmx_swfilter_packets(&adap->demux, buf, 21); | ||
281 | adap->packet_count = 0; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | page->upackets[PT1_NR_UPACKETS - 1] = 0; | ||
287 | return 1; | ||
288 | } | ||
289 | |||
290 | static int pt1_thread(void *data) | ||
291 | { | ||
292 | struct pt1 *pt1; | ||
293 | int table_index; | ||
294 | int buf_index; | ||
295 | struct pt1_buffer_page *page; | ||
296 | |||
297 | pt1 = data; | ||
298 | set_freezable(); | ||
299 | |||
300 | table_index = 0; | ||
301 | buf_index = 0; | ||
302 | |||
303 | while (!kthread_should_stop()) { | ||
304 | try_to_freeze(); | ||
305 | |||
306 | page = pt1->tables[table_index].bufs[buf_index].page; | ||
307 | if (!pt1_filter(pt1, page)) { | ||
308 | schedule_timeout_interruptible((HZ + 999) / 1000); | ||
309 | continue; | ||
310 | } | ||
311 | |||
312 | if (++buf_index >= PT1_NR_BUFS) { | ||
313 | pt1_increment_table_count(pt1); | ||
314 | buf_index = 0; | ||
315 | if (++table_index >= pt1_nr_tables) | ||
316 | table_index = 0; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | static void pt1_free_page(struct pt1 *pt1, void *page, dma_addr_t addr) | ||
324 | { | ||
325 | dma_free_coherent(&pt1->pdev->dev, PT1_PAGE_SIZE, page, addr); | ||
326 | } | ||
327 | |||
328 | static void *pt1_alloc_page(struct pt1 *pt1, dma_addr_t *addrp, u32 *pfnp) | ||
329 | { | ||
330 | void *page; | ||
331 | dma_addr_t addr; | ||
332 | |||
333 | page = dma_alloc_coherent(&pt1->pdev->dev, PT1_PAGE_SIZE, &addr, | ||
334 | GFP_KERNEL); | ||
335 | if (page == NULL) | ||
336 | return NULL; | ||
337 | |||
338 | BUG_ON(addr & (PT1_PAGE_SIZE - 1)); | ||
339 | BUG_ON(addr >> PT1_PAGE_SHIFT >> 31 >> 1); | ||
340 | |||
341 | *addrp = addr; | ||
342 | *pfnp = addr >> PT1_PAGE_SHIFT; | ||
343 | return page; | ||
344 | } | ||
345 | |||
346 | static void pt1_cleanup_buffer(struct pt1 *pt1, struct pt1_buffer *buf) | ||
347 | { | ||
348 | pt1_free_page(pt1, buf->page, buf->addr); | ||
349 | } | ||
350 | |||
351 | static int | ||
352 | pt1_init_buffer(struct pt1 *pt1, struct pt1_buffer *buf, u32 *pfnp) | ||
353 | { | ||
354 | struct pt1_buffer_page *page; | ||
355 | dma_addr_t addr; | ||
356 | |||
357 | page = pt1_alloc_page(pt1, &addr, pfnp); | ||
358 | if (page == NULL) | ||
359 | return -ENOMEM; | ||
360 | |||
361 | page->upackets[PT1_NR_UPACKETS - 1] = 0; | ||
362 | |||
363 | buf->page = page; | ||
364 | buf->addr = addr; | ||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static void pt1_cleanup_table(struct pt1 *pt1, struct pt1_table *table) | ||
369 | { | ||
370 | int i; | ||
371 | |||
372 | for (i = 0; i < PT1_NR_BUFS; i++) | ||
373 | pt1_cleanup_buffer(pt1, &table->bufs[i]); | ||
374 | |||
375 | pt1_free_page(pt1, table->page, table->addr); | ||
376 | } | ||
377 | |||
378 | static int | ||
379 | pt1_init_table(struct pt1 *pt1, struct pt1_table *table, u32 *pfnp) | ||
380 | { | ||
381 | struct pt1_table_page *page; | ||
382 | dma_addr_t addr; | ||
383 | int i, ret; | ||
384 | u32 buf_pfn; | ||
385 | |||
386 | page = pt1_alloc_page(pt1, &addr, pfnp); | ||
387 | if (page == NULL) | ||
388 | return -ENOMEM; | ||
389 | |||
390 | for (i = 0; i < PT1_NR_BUFS; i++) { | ||
391 | ret = pt1_init_buffer(pt1, &table->bufs[i], &buf_pfn); | ||
392 | if (ret < 0) | ||
393 | goto err; | ||
394 | |||
395 | page->buf_pfns[i] = cpu_to_le32(buf_pfn); | ||
396 | } | ||
397 | |||
398 | pt1_increment_table_count(pt1); | ||
399 | table->page = page; | ||
400 | table->addr = addr; | ||
401 | return 0; | ||
402 | |||
403 | err: | ||
404 | while (i--) | ||
405 | pt1_cleanup_buffer(pt1, &table->bufs[i]); | ||
406 | |||
407 | pt1_free_page(pt1, page, addr); | ||
408 | return ret; | ||
409 | } | ||
410 | |||
411 | static void pt1_cleanup_tables(struct pt1 *pt1) | ||
412 | { | ||
413 | struct pt1_table *tables; | ||
414 | int i; | ||
415 | |||
416 | tables = pt1->tables; | ||
417 | pt1_unregister_tables(pt1); | ||
418 | |||
419 | for (i = 0; i < pt1_nr_tables; i++) | ||
420 | pt1_cleanup_table(pt1, &tables[i]); | ||
421 | |||
422 | vfree(tables); | ||
423 | } | ||
424 | |||
425 | static int pt1_init_tables(struct pt1 *pt1) | ||
426 | { | ||
427 | struct pt1_table *tables; | ||
428 | int i, ret; | ||
429 | u32 first_pfn, pfn; | ||
430 | |||
431 | tables = vmalloc(sizeof(struct pt1_table) * pt1_nr_tables); | ||
432 | if (tables == NULL) | ||
433 | return -ENOMEM; | ||
434 | |||
435 | pt1_init_table_count(pt1); | ||
436 | |||
437 | i = 0; | ||
438 | if (pt1_nr_tables) { | ||
439 | ret = pt1_init_table(pt1, &tables[0], &first_pfn); | ||
440 | if (ret) | ||
441 | goto err; | ||
442 | i++; | ||
443 | } | ||
444 | |||
445 | while (i < pt1_nr_tables) { | ||
446 | ret = pt1_init_table(pt1, &tables[i], &pfn); | ||
447 | if (ret) | ||
448 | goto err; | ||
449 | tables[i - 1].page->next_pfn = cpu_to_le32(pfn); | ||
450 | i++; | ||
451 | } | ||
452 | |||
453 | tables[pt1_nr_tables - 1].page->next_pfn = cpu_to_le32(first_pfn); | ||
454 | |||
455 | pt1_register_tables(pt1, first_pfn); | ||
456 | pt1->tables = tables; | ||
457 | return 0; | ||
458 | |||
459 | err: | ||
460 | while (i--) | ||
461 | pt1_cleanup_table(pt1, &tables[i]); | ||
462 | |||
463 | vfree(tables); | ||
464 | return ret; | ||
465 | } | ||
466 | |||
467 | static int pt1_start_feed(struct dvb_demux_feed *feed) | ||
468 | { | ||
469 | struct pt1_adapter *adap; | ||
470 | adap = container_of(feed->demux, struct pt1_adapter, demux); | ||
471 | if (!adap->users++) | ||
472 | pt1_set_stream(adap->pt1, adap->index, 1); | ||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | static int pt1_stop_feed(struct dvb_demux_feed *feed) | ||
477 | { | ||
478 | struct pt1_adapter *adap; | ||
479 | adap = container_of(feed->demux, struct pt1_adapter, demux); | ||
480 | if (!--adap->users) | ||
481 | pt1_set_stream(adap->pt1, adap->index, 0); | ||
482 | return 0; | ||
483 | } | ||
484 | |||
485 | static void | ||
486 | pt1_set_power(struct pt1 *pt1, int power, int lnb, int reset) | ||
487 | { | ||
488 | pt1_write_reg(pt1, 1, power | lnb << 1 | !reset << 3); | ||
489 | } | ||
490 | |||
491 | static int pt1_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) | ||
492 | { | ||
493 | struct pt1_adapter *adap; | ||
494 | int lnb; | ||
495 | |||
496 | adap = container_of(fe->dvb, struct pt1_adapter, adap); | ||
497 | |||
498 | switch (voltage) { | ||
499 | case SEC_VOLTAGE_13: /* actually 11V */ | ||
500 | lnb = 2; | ||
501 | break; | ||
502 | case SEC_VOLTAGE_18: /* actually 15V */ | ||
503 | lnb = 3; | ||
504 | break; | ||
505 | case SEC_VOLTAGE_OFF: | ||
506 | lnb = 0; | ||
507 | break; | ||
508 | default: | ||
509 | return -EINVAL; | ||
510 | } | ||
511 | |||
512 | pt1_set_power(adap->pt1, 1, lnb, 0); | ||
513 | |||
514 | if (adap->orig_set_voltage) | ||
515 | return adap->orig_set_voltage(fe, voltage); | ||
516 | else | ||
517 | return 0; | ||
518 | } | ||
519 | |||
520 | static void pt1_free_adapter(struct pt1_adapter *adap) | ||
521 | { | ||
522 | dvb_unregister_frontend(adap->fe); | ||
523 | dvb_net_release(&adap->net); | ||
524 | adap->demux.dmx.close(&adap->demux.dmx); | ||
525 | dvb_dmxdev_release(&adap->dmxdev); | ||
526 | dvb_dmx_release(&adap->demux); | ||
527 | dvb_unregister_adapter(&adap->adap); | ||
528 | free_page((unsigned long)adap->buf); | ||
529 | kfree(adap); | ||
530 | } | ||
531 | |||
532 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
533 | |||
534 | static struct pt1_adapter * | ||
535 | pt1_alloc_adapter(struct pt1 *pt1, struct dvb_frontend *fe) | ||
536 | { | ||
537 | struct pt1_adapter *adap; | ||
538 | void *buf; | ||
539 | struct dvb_adapter *dvb_adap; | ||
540 | struct dvb_demux *demux; | ||
541 | struct dmxdev *dmxdev; | ||
542 | int ret; | ||
543 | |||
544 | adap = kzalloc(sizeof(struct pt1_adapter), GFP_KERNEL); | ||
545 | if (!adap) { | ||
546 | ret = -ENOMEM; | ||
547 | goto err; | ||
548 | } | ||
549 | |||
550 | adap->pt1 = pt1; | ||
551 | |||
552 | adap->orig_set_voltage = fe->ops.set_voltage; | ||
553 | fe->ops.set_voltage = pt1_set_voltage; | ||
554 | |||
555 | buf = (u8 *)__get_free_page(GFP_KERNEL); | ||
556 | if (!buf) { | ||
557 | ret = -ENOMEM; | ||
558 | goto err_kfree; | ||
559 | } | ||
560 | |||
561 | adap->buf = buf; | ||
562 | adap->upacket_count = 0; | ||
563 | adap->packet_count = 0; | ||
564 | |||
565 | dvb_adap = &adap->adap; | ||
566 | dvb_adap->priv = adap; | ||
567 | ret = dvb_register_adapter(dvb_adap, DRIVER_NAME, THIS_MODULE, | ||
568 | &pt1->pdev->dev, adapter_nr); | ||
569 | if (ret < 0) | ||
570 | goto err_free_page; | ||
571 | |||
572 | demux = &adap->demux; | ||
573 | demux->dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING; | ||
574 | demux->priv = adap; | ||
575 | demux->feednum = 256; | ||
576 | demux->filternum = 256; | ||
577 | demux->start_feed = pt1_start_feed; | ||
578 | demux->stop_feed = pt1_stop_feed; | ||
579 | demux->write_to_decoder = NULL; | ||
580 | ret = dvb_dmx_init(demux); | ||
581 | if (ret < 0) | ||
582 | goto err_unregister_adapter; | ||
583 | |||
584 | dmxdev = &adap->dmxdev; | ||
585 | dmxdev->filternum = 256; | ||
586 | dmxdev->demux = &demux->dmx; | ||
587 | dmxdev->capabilities = 0; | ||
588 | ret = dvb_dmxdev_init(dmxdev, dvb_adap); | ||
589 | if (ret < 0) | ||
590 | goto err_dmx_release; | ||
591 | |||
592 | dvb_net_init(dvb_adap, &adap->net, &demux->dmx); | ||
593 | |||
594 | ret = dvb_register_frontend(dvb_adap, fe); | ||
595 | if (ret < 0) | ||
596 | goto err_net_release; | ||
597 | adap->fe = fe; | ||
598 | |||
599 | return adap; | ||
600 | |||
601 | err_net_release: | ||
602 | dvb_net_release(&adap->net); | ||
603 | adap->demux.dmx.close(&adap->demux.dmx); | ||
604 | dvb_dmxdev_release(&adap->dmxdev); | ||
605 | err_dmx_release: | ||
606 | dvb_dmx_release(demux); | ||
607 | err_unregister_adapter: | ||
608 | dvb_unregister_adapter(dvb_adap); | ||
609 | err_free_page: | ||
610 | free_page((unsigned long)buf); | ||
611 | err_kfree: | ||
612 | kfree(adap); | ||
613 | err: | ||
614 | return ERR_PTR(ret); | ||
615 | } | ||
616 | |||
617 | static void pt1_cleanup_adapters(struct pt1 *pt1) | ||
618 | { | ||
619 | int i; | ||
620 | for (i = 0; i < PT1_NR_ADAPS; i++) | ||
621 | pt1_free_adapter(pt1->adaps[i]); | ||
622 | } | ||
623 | |||
624 | struct pt1_config { | ||
625 | struct va1j5jf8007s_config va1j5jf8007s_config; | ||
626 | struct va1j5jf8007t_config va1j5jf8007t_config; | ||
627 | }; | ||
628 | |||
629 | static const struct pt1_config pt1_configs[2] = { | ||
630 | { | ||
631 | { .demod_address = 0x1b }, | ||
632 | { .demod_address = 0x1a }, | ||
633 | }, { | ||
634 | { .demod_address = 0x19 }, | ||
635 | { .demod_address = 0x18 }, | ||
636 | }, | ||
637 | }; | ||
638 | |||
639 | static int pt1_init_adapters(struct pt1 *pt1) | ||
640 | { | ||
641 | int i, j; | ||
642 | struct i2c_adapter *i2c_adap; | ||
643 | const struct pt1_config *config; | ||
644 | struct dvb_frontend *fe[4]; | ||
645 | struct pt1_adapter *adap; | ||
646 | int ret; | ||
647 | |||
648 | i = 0; | ||
649 | j = 0; | ||
650 | |||
651 | i2c_adap = &pt1->i2c_adap; | ||
652 | do { | ||
653 | config = &pt1_configs[i / 2]; | ||
654 | |||
655 | fe[i] = va1j5jf8007s_attach(&config->va1j5jf8007s_config, | ||
656 | i2c_adap); | ||
657 | if (!fe[i]) { | ||
658 | ret = -ENODEV; /* This does not sound nice... */ | ||
659 | goto err; | ||
660 | } | ||
661 | i++; | ||
662 | |||
663 | fe[i] = va1j5jf8007t_attach(&config->va1j5jf8007t_config, | ||
664 | i2c_adap); | ||
665 | if (!fe[i]) { | ||
666 | ret = -ENODEV; | ||
667 | goto err; | ||
668 | } | ||
669 | i++; | ||
670 | |||
671 | ret = va1j5jf8007s_prepare(fe[i - 2]); | ||
672 | if (ret < 0) | ||
673 | goto err; | ||
674 | |||
675 | ret = va1j5jf8007t_prepare(fe[i - 1]); | ||
676 | if (ret < 0) | ||
677 | goto err; | ||
678 | |||
679 | } while (i < 4); | ||
680 | |||
681 | do { | ||
682 | adap = pt1_alloc_adapter(pt1, fe[j]); | ||
683 | if (IS_ERR(adap)) | ||
684 | goto err; | ||
685 | adap->index = j; | ||
686 | pt1->adaps[j] = adap; | ||
687 | } while (++j < 4); | ||
688 | |||
689 | return 0; | ||
690 | |||
691 | err: | ||
692 | while (i-- > j) | ||
693 | fe[i]->ops.release(fe[i]); | ||
694 | |||
695 | while (j--) | ||
696 | pt1_free_adapter(pt1->adaps[j]); | ||
697 | |||
698 | return ret; | ||
699 | } | ||
700 | |||
701 | static void pt1_i2c_emit(struct pt1 *pt1, int addr, int busy, int read_enable, | ||
702 | int clock, int data, int next_addr) | ||
703 | { | ||
704 | pt1_write_reg(pt1, 4, addr << 18 | busy << 13 | read_enable << 12 | | ||
705 | !clock << 11 | !data << 10 | next_addr); | ||
706 | } | ||
707 | |||
708 | static void pt1_i2c_write_bit(struct pt1 *pt1, int addr, int *addrp, int data) | ||
709 | { | ||
710 | pt1_i2c_emit(pt1, addr, 1, 0, 0, data, addr + 1); | ||
711 | pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, data, addr + 2); | ||
712 | pt1_i2c_emit(pt1, addr + 2, 1, 0, 0, data, addr + 3); | ||
713 | *addrp = addr + 3; | ||
714 | } | ||
715 | |||
716 | static void pt1_i2c_read_bit(struct pt1 *pt1, int addr, int *addrp) | ||
717 | { | ||
718 | pt1_i2c_emit(pt1, addr, 1, 0, 0, 1, addr + 1); | ||
719 | pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 1, addr + 2); | ||
720 | pt1_i2c_emit(pt1, addr + 2, 1, 1, 1, 1, addr + 3); | ||
721 | pt1_i2c_emit(pt1, addr + 3, 1, 0, 0, 1, addr + 4); | ||
722 | *addrp = addr + 4; | ||
723 | } | ||
724 | |||
725 | static void pt1_i2c_write_byte(struct pt1 *pt1, int addr, int *addrp, int data) | ||
726 | { | ||
727 | int i; | ||
728 | for (i = 0; i < 8; i++) | ||
729 | pt1_i2c_write_bit(pt1, addr, &addr, data >> (7 - i) & 1); | ||
730 | pt1_i2c_write_bit(pt1, addr, &addr, 1); | ||
731 | *addrp = addr; | ||
732 | } | ||
733 | |||
734 | static void pt1_i2c_read_byte(struct pt1 *pt1, int addr, int *addrp, int last) | ||
735 | { | ||
736 | int i; | ||
737 | for (i = 0; i < 8; i++) | ||
738 | pt1_i2c_read_bit(pt1, addr, &addr); | ||
739 | pt1_i2c_write_bit(pt1, addr, &addr, last); | ||
740 | *addrp = addr; | ||
741 | } | ||
742 | |||
743 | static void pt1_i2c_prepare(struct pt1 *pt1, int addr, int *addrp) | ||
744 | { | ||
745 | pt1_i2c_emit(pt1, addr, 1, 0, 1, 1, addr + 1); | ||
746 | pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 0, addr + 2); | ||
747 | pt1_i2c_emit(pt1, addr + 2, 1, 0, 0, 0, addr + 3); | ||
748 | *addrp = addr + 3; | ||
749 | } | ||
750 | |||
751 | static void | ||
752 | pt1_i2c_write_msg(struct pt1 *pt1, int addr, int *addrp, struct i2c_msg *msg) | ||
753 | { | ||
754 | int i; | ||
755 | pt1_i2c_prepare(pt1, addr, &addr); | ||
756 | pt1_i2c_write_byte(pt1, addr, &addr, msg->addr << 1); | ||
757 | for (i = 0; i < msg->len; i++) | ||
758 | pt1_i2c_write_byte(pt1, addr, &addr, msg->buf[i]); | ||
759 | *addrp = addr; | ||
760 | } | ||
761 | |||
762 | static void | ||
763 | pt1_i2c_read_msg(struct pt1 *pt1, int addr, int *addrp, struct i2c_msg *msg) | ||
764 | { | ||
765 | int i; | ||
766 | pt1_i2c_prepare(pt1, addr, &addr); | ||
767 | pt1_i2c_write_byte(pt1, addr, &addr, msg->addr << 1 | 1); | ||
768 | for (i = 0; i < msg->len; i++) | ||
769 | pt1_i2c_read_byte(pt1, addr, &addr, i == msg->len - 1); | ||
770 | *addrp = addr; | ||
771 | } | ||
772 | |||
773 | static int pt1_i2c_end(struct pt1 *pt1, int addr) | ||
774 | { | ||
775 | pt1_i2c_emit(pt1, addr, 1, 0, 0, 0, addr + 1); | ||
776 | pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 0, addr + 2); | ||
777 | pt1_i2c_emit(pt1, addr + 2, 1, 0, 1, 1, 0); | ||
778 | |||
779 | pt1_write_reg(pt1, 0, 0x00000004); | ||
780 | do { | ||
781 | if (signal_pending(current)) | ||
782 | return -EINTR; | ||
783 | schedule_timeout_interruptible((HZ + 999) / 1000); | ||
784 | } while (pt1_read_reg(pt1, 0) & 0x00000080); | ||
785 | return 0; | ||
786 | } | ||
787 | |||
788 | static void pt1_i2c_begin(struct pt1 *pt1, int *addrp) | ||
789 | { | ||
790 | int addr; | ||
791 | addr = 0; | ||
792 | |||
793 | pt1_i2c_emit(pt1, addr, 0, 0, 1, 1, addr /* itself */); | ||
794 | addr = addr + 1; | ||
795 | |||
796 | if (!pt1->i2c_running) { | ||
797 | pt1_i2c_emit(pt1, addr, 1, 0, 1, 1, addr + 1); | ||
798 | pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 0, addr + 2); | ||
799 | addr = addr + 2; | ||
800 | pt1->i2c_running = 1; | ||
801 | } | ||
802 | *addrp = addr; | ||
803 | } | ||
804 | |||
805 | static int pt1_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | ||
806 | { | ||
807 | struct pt1 *pt1; | ||
808 | int i; | ||
809 | struct i2c_msg *msg, *next_msg; | ||
810 | int addr, ret; | ||
811 | u16 len; | ||
812 | u32 word; | ||
813 | |||
814 | pt1 = i2c_get_adapdata(adap); | ||
815 | |||
816 | for (i = 0; i < num; i++) { | ||
817 | msg = &msgs[i]; | ||
818 | if (msg->flags & I2C_M_RD) | ||
819 | return -ENOTSUPP; | ||
820 | |||
821 | if (i + 1 < num) | ||
822 | next_msg = &msgs[i + 1]; | ||
823 | else | ||
824 | next_msg = NULL; | ||
825 | |||
826 | if (next_msg && next_msg->flags & I2C_M_RD) { | ||
827 | i++; | ||
828 | |||
829 | len = next_msg->len; | ||
830 | if (len > 4) | ||
831 | return -ENOTSUPP; | ||
832 | |||
833 | pt1_i2c_begin(pt1, &addr); | ||
834 | pt1_i2c_write_msg(pt1, addr, &addr, msg); | ||
835 | pt1_i2c_read_msg(pt1, addr, &addr, next_msg); | ||
836 | ret = pt1_i2c_end(pt1, addr); | ||
837 | if (ret < 0) | ||
838 | return ret; | ||
839 | |||
840 | word = pt1_read_reg(pt1, 2); | ||
841 | while (len--) { | ||
842 | next_msg->buf[len] = word; | ||
843 | word >>= 8; | ||
844 | } | ||
845 | } else { | ||
846 | pt1_i2c_begin(pt1, &addr); | ||
847 | pt1_i2c_write_msg(pt1, addr, &addr, msg); | ||
848 | ret = pt1_i2c_end(pt1, addr); | ||
849 | if (ret < 0) | ||
850 | return ret; | ||
851 | } | ||
852 | } | ||
853 | |||
854 | return num; | ||
855 | } | ||
856 | |||
857 | static u32 pt1_i2c_func(struct i2c_adapter *adap) | ||
858 | { | ||
859 | return I2C_FUNC_I2C; | ||
860 | } | ||
861 | |||
862 | static const struct i2c_algorithm pt1_i2c_algo = { | ||
863 | .master_xfer = pt1_i2c_xfer, | ||
864 | .functionality = pt1_i2c_func, | ||
865 | }; | ||
866 | |||
867 | static void pt1_i2c_wait(struct pt1 *pt1) | ||
868 | { | ||
869 | int i; | ||
870 | for (i = 0; i < 128; i++) | ||
871 | pt1_i2c_emit(pt1, 0, 0, 0, 1, 1, 0); | ||
872 | } | ||
873 | |||
874 | static void pt1_i2c_init(struct pt1 *pt1) | ||
875 | { | ||
876 | int i; | ||
877 | for (i = 0; i < 1024; i++) | ||
878 | pt1_i2c_emit(pt1, i, 0, 0, 1, 1, 0); | ||
879 | } | ||
880 | |||
881 | static void __devexit pt1_remove(struct pci_dev *pdev) | ||
882 | { | ||
883 | struct pt1 *pt1; | ||
884 | void __iomem *regs; | ||
885 | |||
886 | pt1 = pci_get_drvdata(pdev); | ||
887 | regs = pt1->regs; | ||
888 | |||
889 | kthread_stop(pt1->kthread); | ||
890 | pt1_cleanup_tables(pt1); | ||
891 | pt1_cleanup_adapters(pt1); | ||
892 | pt1_disable_ram(pt1); | ||
893 | pt1_set_power(pt1, 0, 0, 1); | ||
894 | i2c_del_adapter(&pt1->i2c_adap); | ||
895 | pci_set_drvdata(pdev, NULL); | ||
896 | kfree(pt1); | ||
897 | pci_iounmap(pdev, regs); | ||
898 | pci_release_regions(pdev); | ||
899 | pci_disable_device(pdev); | ||
900 | } | ||
901 | |||
902 | static int __devinit | ||
903 | pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
904 | { | ||
905 | int ret; | ||
906 | void __iomem *regs; | ||
907 | struct pt1 *pt1; | ||
908 | struct i2c_adapter *i2c_adap; | ||
909 | struct task_struct *kthread; | ||
910 | |||
911 | ret = pci_enable_device(pdev); | ||
912 | if (ret < 0) | ||
913 | goto err; | ||
914 | |||
915 | ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | ||
916 | if (ret < 0) | ||
917 | goto err_pci_disable_device; | ||
918 | |||
919 | pci_set_master(pdev); | ||
920 | |||
921 | ret = pci_request_regions(pdev, DRIVER_NAME); | ||
922 | if (ret < 0) | ||
923 | goto err_pci_disable_device; | ||
924 | |||
925 | regs = pci_iomap(pdev, 0, 0); | ||
926 | if (!regs) { | ||
927 | ret = -EIO; | ||
928 | goto err_pci_release_regions; | ||
929 | } | ||
930 | |||
931 | pt1 = kzalloc(sizeof(struct pt1), GFP_KERNEL); | ||
932 | if (!pt1) { | ||
933 | ret = -ENOMEM; | ||
934 | goto err_pci_iounmap; | ||
935 | } | ||
936 | |||
937 | pt1->pdev = pdev; | ||
938 | pt1->regs = regs; | ||
939 | pci_set_drvdata(pdev, pt1); | ||
940 | |||
941 | i2c_adap = &pt1->i2c_adap; | ||
942 | i2c_adap->class = I2C_CLASS_TV_DIGITAL; | ||
943 | i2c_adap->algo = &pt1_i2c_algo; | ||
944 | i2c_adap->algo_data = NULL; | ||
945 | i2c_adap->dev.parent = &pdev->dev; | ||
946 | i2c_set_adapdata(i2c_adap, pt1); | ||
947 | ret = i2c_add_adapter(i2c_adap); | ||
948 | if (ret < 0) | ||
949 | goto err_kfree; | ||
950 | |||
951 | pt1_set_power(pt1, 0, 0, 1); | ||
952 | |||
953 | pt1_i2c_init(pt1); | ||
954 | pt1_i2c_wait(pt1); | ||
955 | |||
956 | ret = pt1_sync(pt1); | ||
957 | if (ret < 0) | ||
958 | goto err_i2c_del_adapter; | ||
959 | |||
960 | pt1_identify(pt1); | ||
961 | |||
962 | ret = pt1_unlock(pt1); | ||
963 | if (ret < 0) | ||
964 | goto err_i2c_del_adapter; | ||
965 | |||
966 | ret = pt1_reset_pci(pt1); | ||
967 | if (ret < 0) | ||
968 | goto err_i2c_del_adapter; | ||
969 | |||
970 | ret = pt1_reset_ram(pt1); | ||
971 | if (ret < 0) | ||
972 | goto err_i2c_del_adapter; | ||
973 | |||
974 | ret = pt1_enable_ram(pt1); | ||
975 | if (ret < 0) | ||
976 | goto err_i2c_del_adapter; | ||
977 | |||
978 | pt1_init_streams(pt1); | ||
979 | |||
980 | pt1_set_power(pt1, 1, 0, 1); | ||
981 | schedule_timeout_uninterruptible((HZ + 49) / 50); | ||
982 | |||
983 | pt1_set_power(pt1, 1, 0, 0); | ||
984 | schedule_timeout_uninterruptible((HZ + 999) / 1000); | ||
985 | |||
986 | ret = pt1_init_adapters(pt1); | ||
987 | if (ret < 0) | ||
988 | goto err_pt1_disable_ram; | ||
989 | |||
990 | ret = pt1_init_tables(pt1); | ||
991 | if (ret < 0) | ||
992 | goto err_pt1_cleanup_adapters; | ||
993 | |||
994 | kthread = kthread_run(pt1_thread, pt1, "pt1"); | ||
995 | if (IS_ERR(kthread)) { | ||
996 | ret = PTR_ERR(kthread); | ||
997 | goto err_pt1_cleanup_tables; | ||
998 | } | ||
999 | |||
1000 | pt1->kthread = kthread; | ||
1001 | return 0; | ||
1002 | |||
1003 | err_pt1_cleanup_tables: | ||
1004 | pt1_cleanup_tables(pt1); | ||
1005 | err_pt1_cleanup_adapters: | ||
1006 | pt1_cleanup_adapters(pt1); | ||
1007 | err_pt1_disable_ram: | ||
1008 | pt1_disable_ram(pt1); | ||
1009 | pt1_set_power(pt1, 0, 0, 1); | ||
1010 | err_i2c_del_adapter: | ||
1011 | i2c_del_adapter(i2c_adap); | ||
1012 | err_kfree: | ||
1013 | pci_set_drvdata(pdev, NULL); | ||
1014 | kfree(pt1); | ||
1015 | err_pci_iounmap: | ||
1016 | pci_iounmap(pdev, regs); | ||
1017 | err_pci_release_regions: | ||
1018 | pci_release_regions(pdev); | ||
1019 | err_pci_disable_device: | ||
1020 | pci_disable_device(pdev); | ||
1021 | err: | ||
1022 | return ret; | ||
1023 | |||
1024 | } | ||
1025 | |||
1026 | static struct pci_device_id pt1_id_table[] = { | ||
1027 | { PCI_DEVICE(0x10ee, 0x211a) }, | ||
1028 | { }, | ||
1029 | }; | ||
1030 | MODULE_DEVICE_TABLE(pci, pt1_id_table); | ||
1031 | |||
1032 | static struct pci_driver pt1_driver = { | ||
1033 | .name = DRIVER_NAME, | ||
1034 | .probe = pt1_probe, | ||
1035 | .remove = __devexit_p(pt1_remove), | ||
1036 | .id_table = pt1_id_table, | ||
1037 | }; | ||
1038 | |||
1039 | |||
1040 | static int __init pt1_init(void) | ||
1041 | { | ||
1042 | return pci_register_driver(&pt1_driver); | ||
1043 | } | ||
1044 | |||
1045 | |||
1046 | static void __exit pt1_cleanup(void) | ||
1047 | { | ||
1048 | pci_unregister_driver(&pt1_driver); | ||
1049 | } | ||
1050 | |||
1051 | module_init(pt1_init); | ||
1052 | module_exit(pt1_cleanup); | ||
1053 | |||
1054 | MODULE_AUTHOR("Takahito HIRANO <hiranotaka@zng.info>"); | ||
1055 | MODULE_DESCRIPTION("Earthsoft PT1 Driver"); | ||
1056 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/dvb/pt1/va1j5jf8007s.c b/drivers/media/dvb/pt1/va1j5jf8007s.c new file mode 100644 index 000000000000..2db940f8635f --- /dev/null +++ b/drivers/media/dvb/pt1/va1j5jf8007s.c | |||
@@ -0,0 +1,658 @@ | |||
1 | /* | ||
2 | * ISDB-S driver for VA1J5JF8007 | ||
3 | * | ||
4 | * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> | ||
5 | * | ||
6 | * based on pt1dvr - http://pt1dvr.sourceforge.jp/ | ||
7 | * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include "dvb_frontend.h" | ||
29 | #include "va1j5jf8007s.h" | ||
30 | |||
31 | enum va1j5jf8007s_tune_state { | ||
32 | VA1J5JF8007S_IDLE, | ||
33 | VA1J5JF8007S_SET_FREQUENCY_1, | ||
34 | VA1J5JF8007S_SET_FREQUENCY_2, | ||
35 | VA1J5JF8007S_SET_FREQUENCY_3, | ||
36 | VA1J5JF8007S_CHECK_FREQUENCY, | ||
37 | VA1J5JF8007S_SET_MODULATION, | ||
38 | VA1J5JF8007S_CHECK_MODULATION, | ||
39 | VA1J5JF8007S_SET_TS_ID, | ||
40 | VA1J5JF8007S_CHECK_TS_ID, | ||
41 | VA1J5JF8007S_TRACK, | ||
42 | }; | ||
43 | |||
44 | struct va1j5jf8007s_state { | ||
45 | const struct va1j5jf8007s_config *config; | ||
46 | struct i2c_adapter *adap; | ||
47 | struct dvb_frontend fe; | ||
48 | enum va1j5jf8007s_tune_state tune_state; | ||
49 | }; | ||
50 | |||
51 | static int va1j5jf8007s_get_frontend_algo(struct dvb_frontend *fe) | ||
52 | { | ||
53 | return DVBFE_ALGO_HW; | ||
54 | } | ||
55 | |||
56 | static int | ||
57 | va1j5jf8007s_read_status(struct dvb_frontend *fe, fe_status_t *status) | ||
58 | { | ||
59 | struct va1j5jf8007s_state *state; | ||
60 | |||
61 | state = fe->demodulator_priv; | ||
62 | |||
63 | switch (state->tune_state) { | ||
64 | case VA1J5JF8007S_IDLE: | ||
65 | case VA1J5JF8007S_SET_FREQUENCY_1: | ||
66 | case VA1J5JF8007S_SET_FREQUENCY_2: | ||
67 | case VA1J5JF8007S_SET_FREQUENCY_3: | ||
68 | case VA1J5JF8007S_CHECK_FREQUENCY: | ||
69 | *status = 0; | ||
70 | return 0; | ||
71 | |||
72 | |||
73 | case VA1J5JF8007S_SET_MODULATION: | ||
74 | case VA1J5JF8007S_CHECK_MODULATION: | ||
75 | *status |= FE_HAS_SIGNAL; | ||
76 | return 0; | ||
77 | |||
78 | case VA1J5JF8007S_SET_TS_ID: | ||
79 | case VA1J5JF8007S_CHECK_TS_ID: | ||
80 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER; | ||
81 | return 0; | ||
82 | |||
83 | case VA1J5JF8007S_TRACK: | ||
84 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; | ||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | BUG(); | ||
89 | } | ||
90 | |||
91 | struct va1j5jf8007s_cb_map { | ||
92 | u32 frequency; | ||
93 | u8 cb; | ||
94 | }; | ||
95 | |||
96 | static const struct va1j5jf8007s_cb_map va1j5jf8007s_cb_maps[] = { | ||
97 | { 986000, 0xb2 }, | ||
98 | { 1072000, 0xd2 }, | ||
99 | { 1154000, 0xe2 }, | ||
100 | { 1291000, 0x20 }, | ||
101 | { 1447000, 0x40 }, | ||
102 | { 1615000, 0x60 }, | ||
103 | { 1791000, 0x80 }, | ||
104 | { 1972000, 0xa0 }, | ||
105 | }; | ||
106 | |||
107 | static u8 va1j5jf8007s_lookup_cb(u32 frequency) | ||
108 | { | ||
109 | int i; | ||
110 | const struct va1j5jf8007s_cb_map *map; | ||
111 | |||
112 | for (i = 0; i < ARRAY_SIZE(va1j5jf8007s_cb_maps); i++) { | ||
113 | map = &va1j5jf8007s_cb_maps[i]; | ||
114 | if (frequency < map->frequency) | ||
115 | return map->cb; | ||
116 | } | ||
117 | return 0xc0; | ||
118 | } | ||
119 | |||
120 | static int va1j5jf8007s_set_frequency_1(struct va1j5jf8007s_state *state) | ||
121 | { | ||
122 | u32 frequency; | ||
123 | u16 word; | ||
124 | u8 buf[6]; | ||
125 | struct i2c_msg msg; | ||
126 | |||
127 | frequency = state->fe.dtv_property_cache.frequency; | ||
128 | |||
129 | word = (frequency + 500) / 1000; | ||
130 | if (frequency < 1072000) | ||
131 | word = (word << 1 & ~0x1f) | (word & 0x0f); | ||
132 | |||
133 | buf[0] = 0xfe; | ||
134 | buf[1] = 0xc0; | ||
135 | buf[2] = 0x40 | word >> 8; | ||
136 | buf[3] = word; | ||
137 | buf[4] = 0xe0; | ||
138 | buf[5] = va1j5jf8007s_lookup_cb(frequency); | ||
139 | |||
140 | msg.addr = state->config->demod_address; | ||
141 | msg.flags = 0; | ||
142 | msg.len = sizeof(buf); | ||
143 | msg.buf = buf; | ||
144 | |||
145 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
146 | return -EREMOTEIO; | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static int va1j5jf8007s_set_frequency_2(struct va1j5jf8007s_state *state) | ||
152 | { | ||
153 | u8 buf[3]; | ||
154 | struct i2c_msg msg; | ||
155 | |||
156 | buf[0] = 0xfe; | ||
157 | buf[1] = 0xc0; | ||
158 | buf[2] = 0xe4; | ||
159 | |||
160 | msg.addr = state->config->demod_address; | ||
161 | msg.flags = 0; | ||
162 | msg.len = sizeof(buf); | ||
163 | msg.buf = buf; | ||
164 | |||
165 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
166 | return -EREMOTEIO; | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static int va1j5jf8007s_set_frequency_3(struct va1j5jf8007s_state *state) | ||
172 | { | ||
173 | u32 frequency; | ||
174 | u8 buf[4]; | ||
175 | struct i2c_msg msg; | ||
176 | |||
177 | frequency = state->fe.dtv_property_cache.frequency; | ||
178 | |||
179 | buf[0] = 0xfe; | ||
180 | buf[1] = 0xc0; | ||
181 | buf[2] = 0xf4; | ||
182 | buf[3] = va1j5jf8007s_lookup_cb(frequency) | 0x4; | ||
183 | |||
184 | msg.addr = state->config->demod_address; | ||
185 | msg.flags = 0; | ||
186 | msg.len = sizeof(buf); | ||
187 | msg.buf = buf; | ||
188 | |||
189 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
190 | return -EREMOTEIO; | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static int | ||
196 | va1j5jf8007s_check_frequency(struct va1j5jf8007s_state *state, int *lock) | ||
197 | { | ||
198 | u8 addr; | ||
199 | u8 write_buf[2], read_buf[1]; | ||
200 | struct i2c_msg msgs[2]; | ||
201 | |||
202 | addr = state->config->demod_address; | ||
203 | |||
204 | write_buf[0] = 0xfe; | ||
205 | write_buf[1] = 0xc1; | ||
206 | |||
207 | msgs[0].addr = addr; | ||
208 | msgs[0].flags = 0; | ||
209 | msgs[0].len = sizeof(write_buf); | ||
210 | msgs[0].buf = write_buf; | ||
211 | |||
212 | msgs[1].addr = addr; | ||
213 | msgs[1].flags = I2C_M_RD; | ||
214 | msgs[1].len = sizeof(read_buf); | ||
215 | msgs[1].buf = read_buf; | ||
216 | |||
217 | if (i2c_transfer(state->adap, msgs, 2) != 2) | ||
218 | return -EREMOTEIO; | ||
219 | |||
220 | *lock = read_buf[0] & 0x40; | ||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | static int va1j5jf8007s_set_modulation(struct va1j5jf8007s_state *state) | ||
225 | { | ||
226 | u8 buf[2]; | ||
227 | struct i2c_msg msg; | ||
228 | |||
229 | buf[0] = 0x03; | ||
230 | buf[1] = 0x01; | ||
231 | |||
232 | msg.addr = state->config->demod_address; | ||
233 | msg.flags = 0; | ||
234 | msg.len = sizeof(buf); | ||
235 | msg.buf = buf; | ||
236 | |||
237 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
238 | return -EREMOTEIO; | ||
239 | |||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | static int | ||
244 | va1j5jf8007s_check_modulation(struct va1j5jf8007s_state *state, int *lock) | ||
245 | { | ||
246 | u8 addr; | ||
247 | u8 write_buf[1], read_buf[1]; | ||
248 | struct i2c_msg msgs[2]; | ||
249 | |||
250 | addr = state->config->demod_address; | ||
251 | |||
252 | write_buf[0] = 0xc3; | ||
253 | |||
254 | msgs[0].addr = addr; | ||
255 | msgs[0].flags = 0; | ||
256 | msgs[0].len = sizeof(write_buf); | ||
257 | msgs[0].buf = write_buf; | ||
258 | |||
259 | msgs[1].addr = addr; | ||
260 | msgs[1].flags = I2C_M_RD; | ||
261 | msgs[1].len = sizeof(read_buf); | ||
262 | msgs[1].buf = read_buf; | ||
263 | |||
264 | if (i2c_transfer(state->adap, msgs, 2) != 2) | ||
265 | return -EREMOTEIO; | ||
266 | |||
267 | *lock = !(read_buf[0] & 0x10); | ||
268 | return 0; | ||
269 | } | ||
270 | |||
271 | static int | ||
272 | va1j5jf8007s_set_ts_id(struct va1j5jf8007s_state *state) | ||
273 | { | ||
274 | u32 ts_id; | ||
275 | u8 buf[3]; | ||
276 | struct i2c_msg msg; | ||
277 | |||
278 | ts_id = state->fe.dtv_property_cache.isdbs_ts_id; | ||
279 | if (!ts_id) | ||
280 | return 0; | ||
281 | |||
282 | buf[0] = 0x8f; | ||
283 | buf[1] = ts_id >> 8; | ||
284 | buf[2] = ts_id; | ||
285 | |||
286 | msg.addr = state->config->demod_address; | ||
287 | msg.flags = 0; | ||
288 | msg.len = sizeof(buf); | ||
289 | msg.buf = buf; | ||
290 | |||
291 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
292 | return -EREMOTEIO; | ||
293 | |||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | static int | ||
298 | va1j5jf8007s_check_ts_id(struct va1j5jf8007s_state *state, int *lock) | ||
299 | { | ||
300 | u8 addr; | ||
301 | u8 write_buf[1], read_buf[2]; | ||
302 | struct i2c_msg msgs[2]; | ||
303 | u32 ts_id; | ||
304 | |||
305 | ts_id = state->fe.dtv_property_cache.isdbs_ts_id; | ||
306 | if (!ts_id) { | ||
307 | *lock = 1; | ||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | addr = state->config->demod_address; | ||
312 | |||
313 | write_buf[0] = 0xe6; | ||
314 | |||
315 | msgs[0].addr = addr; | ||
316 | msgs[0].flags = 0; | ||
317 | msgs[0].len = sizeof(write_buf); | ||
318 | msgs[0].buf = write_buf; | ||
319 | |||
320 | msgs[1].addr = addr; | ||
321 | msgs[1].flags = I2C_M_RD; | ||
322 | msgs[1].len = sizeof(read_buf); | ||
323 | msgs[1].buf = read_buf; | ||
324 | |||
325 | if (i2c_transfer(state->adap, msgs, 2) != 2) | ||
326 | return -EREMOTEIO; | ||
327 | |||
328 | *lock = (read_buf[0] << 8 | read_buf[1]) == ts_id; | ||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static int | ||
333 | va1j5jf8007s_tune(struct dvb_frontend *fe, | ||
334 | struct dvb_frontend_parameters *params, | ||
335 | unsigned int mode_flags, unsigned int *delay, | ||
336 | fe_status_t *status) | ||
337 | { | ||
338 | struct va1j5jf8007s_state *state; | ||
339 | int ret; | ||
340 | int lock; | ||
341 | |||
342 | state = fe->demodulator_priv; | ||
343 | |||
344 | if (params != NULL) | ||
345 | state->tune_state = VA1J5JF8007S_SET_FREQUENCY_1; | ||
346 | |||
347 | switch (state->tune_state) { | ||
348 | case VA1J5JF8007S_IDLE: | ||
349 | *delay = 3 * HZ; | ||
350 | *status = 0; | ||
351 | return 0; | ||
352 | |||
353 | case VA1J5JF8007S_SET_FREQUENCY_1: | ||
354 | ret = va1j5jf8007s_set_frequency_1(state); | ||
355 | if (ret < 0) | ||
356 | return ret; | ||
357 | |||
358 | state->tune_state = VA1J5JF8007S_SET_FREQUENCY_2; | ||
359 | *delay = 0; | ||
360 | *status = 0; | ||
361 | return 0; | ||
362 | |||
363 | case VA1J5JF8007S_SET_FREQUENCY_2: | ||
364 | ret = va1j5jf8007s_set_frequency_2(state); | ||
365 | if (ret < 0) | ||
366 | return ret; | ||
367 | |||
368 | state->tune_state = VA1J5JF8007S_SET_FREQUENCY_3; | ||
369 | *delay = (HZ + 99) / 100; | ||
370 | *status = 0; | ||
371 | return 0; | ||
372 | |||
373 | case VA1J5JF8007S_SET_FREQUENCY_3: | ||
374 | ret = va1j5jf8007s_set_frequency_3(state); | ||
375 | if (ret < 0) | ||
376 | return ret; | ||
377 | |||
378 | state->tune_state = VA1J5JF8007S_CHECK_FREQUENCY; | ||
379 | *delay = 0; | ||
380 | *status = 0; | ||
381 | return 0; | ||
382 | |||
383 | case VA1J5JF8007S_CHECK_FREQUENCY: | ||
384 | ret = va1j5jf8007s_check_frequency(state, &lock); | ||
385 | if (ret < 0) | ||
386 | return ret; | ||
387 | |||
388 | if (!lock) { | ||
389 | *delay = (HZ + 999) / 1000; | ||
390 | *status = 0; | ||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | state->tune_state = VA1J5JF8007S_SET_MODULATION; | ||
395 | *delay = 0; | ||
396 | *status = FE_HAS_SIGNAL; | ||
397 | return 0; | ||
398 | |||
399 | case VA1J5JF8007S_SET_MODULATION: | ||
400 | ret = va1j5jf8007s_set_modulation(state); | ||
401 | if (ret < 0) | ||
402 | return ret; | ||
403 | |||
404 | state->tune_state = VA1J5JF8007S_CHECK_MODULATION; | ||
405 | *delay = 0; | ||
406 | *status = FE_HAS_SIGNAL; | ||
407 | return 0; | ||
408 | |||
409 | case VA1J5JF8007S_CHECK_MODULATION: | ||
410 | ret = va1j5jf8007s_check_modulation(state, &lock); | ||
411 | if (ret < 0) | ||
412 | return ret; | ||
413 | |||
414 | if (!lock) { | ||
415 | *delay = (HZ + 49) / 50; | ||
416 | *status = FE_HAS_SIGNAL; | ||
417 | return 0; | ||
418 | } | ||
419 | |||
420 | state->tune_state = VA1J5JF8007S_SET_TS_ID; | ||
421 | *delay = 0; | ||
422 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER; | ||
423 | return 0; | ||
424 | |||
425 | case VA1J5JF8007S_SET_TS_ID: | ||
426 | ret = va1j5jf8007s_set_ts_id(state); | ||
427 | if (ret < 0) | ||
428 | return ret; | ||
429 | |||
430 | state->tune_state = VA1J5JF8007S_CHECK_TS_ID; | ||
431 | return 0; | ||
432 | |||
433 | case VA1J5JF8007S_CHECK_TS_ID: | ||
434 | ret = va1j5jf8007s_check_ts_id(state, &lock); | ||
435 | if (ret < 0) | ||
436 | return ret; | ||
437 | |||
438 | if (!lock) { | ||
439 | *delay = (HZ + 99) / 100; | ||
440 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER; | ||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | state->tune_state = VA1J5JF8007S_TRACK; | ||
445 | /* fall through */ | ||
446 | |||
447 | case VA1J5JF8007S_TRACK: | ||
448 | *delay = 3 * HZ; | ||
449 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | BUG(); | ||
454 | } | ||
455 | |||
456 | static int va1j5jf8007s_init_frequency(struct va1j5jf8007s_state *state) | ||
457 | { | ||
458 | u8 buf[4]; | ||
459 | struct i2c_msg msg; | ||
460 | |||
461 | buf[0] = 0xfe; | ||
462 | buf[1] = 0xc0; | ||
463 | buf[2] = 0xf0; | ||
464 | buf[3] = 0x04; | ||
465 | |||
466 | msg.addr = state->config->demod_address; | ||
467 | msg.flags = 0; | ||
468 | msg.len = sizeof(buf); | ||
469 | msg.buf = buf; | ||
470 | |||
471 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
472 | return -EREMOTEIO; | ||
473 | |||
474 | return 0; | ||
475 | } | ||
476 | |||
477 | static int va1j5jf8007s_set_sleep(struct va1j5jf8007s_state *state, int sleep) | ||
478 | { | ||
479 | u8 buf[2]; | ||
480 | struct i2c_msg msg; | ||
481 | |||
482 | buf[0] = 0x17; | ||
483 | buf[1] = sleep ? 0x01 : 0x00; | ||
484 | |||
485 | msg.addr = state->config->demod_address; | ||
486 | msg.flags = 0; | ||
487 | msg.len = sizeof(buf); | ||
488 | msg.buf = buf; | ||
489 | |||
490 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
491 | return -EREMOTEIO; | ||
492 | |||
493 | return 0; | ||
494 | } | ||
495 | |||
496 | static int va1j5jf8007s_sleep(struct dvb_frontend *fe) | ||
497 | { | ||
498 | struct va1j5jf8007s_state *state; | ||
499 | int ret; | ||
500 | |||
501 | state = fe->demodulator_priv; | ||
502 | |||
503 | ret = va1j5jf8007s_init_frequency(state); | ||
504 | if (ret < 0) | ||
505 | return ret; | ||
506 | |||
507 | return va1j5jf8007s_set_sleep(state, 1); | ||
508 | } | ||
509 | |||
510 | static int va1j5jf8007s_init(struct dvb_frontend *fe) | ||
511 | { | ||
512 | struct va1j5jf8007s_state *state; | ||
513 | |||
514 | state = fe->demodulator_priv; | ||
515 | state->tune_state = VA1J5JF8007S_IDLE; | ||
516 | |||
517 | return va1j5jf8007s_set_sleep(state, 0); | ||
518 | } | ||
519 | |||
520 | static void va1j5jf8007s_release(struct dvb_frontend *fe) | ||
521 | { | ||
522 | struct va1j5jf8007s_state *state; | ||
523 | state = fe->demodulator_priv; | ||
524 | kfree(state); | ||
525 | } | ||
526 | |||
527 | static struct dvb_frontend_ops va1j5jf8007s_ops = { | ||
528 | .info = { | ||
529 | .name = "VA1J5JF8007 ISDB-S", | ||
530 | .type = FE_QPSK, | ||
531 | .frequency_min = 950000, | ||
532 | .frequency_max = 2150000, | ||
533 | .frequency_stepsize = 1000, | ||
534 | .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_AUTO | | ||
535 | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | | ||
536 | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO, | ||
537 | }, | ||
538 | |||
539 | .get_frontend_algo = va1j5jf8007s_get_frontend_algo, | ||
540 | .read_status = va1j5jf8007s_read_status, | ||
541 | .tune = va1j5jf8007s_tune, | ||
542 | .sleep = va1j5jf8007s_sleep, | ||
543 | .init = va1j5jf8007s_init, | ||
544 | .release = va1j5jf8007s_release, | ||
545 | }; | ||
546 | |||
547 | static int va1j5jf8007s_prepare_1(struct va1j5jf8007s_state *state) | ||
548 | { | ||
549 | u8 addr; | ||
550 | u8 write_buf[1], read_buf[1]; | ||
551 | struct i2c_msg msgs[2]; | ||
552 | |||
553 | addr = state->config->demod_address; | ||
554 | |||
555 | write_buf[0] = 0x07; | ||
556 | |||
557 | msgs[0].addr = addr; | ||
558 | msgs[0].flags = 0; | ||
559 | msgs[0].len = sizeof(write_buf); | ||
560 | msgs[0].buf = write_buf; | ||
561 | |||
562 | msgs[1].addr = addr; | ||
563 | msgs[1].flags = I2C_M_RD; | ||
564 | msgs[1].len = sizeof(read_buf); | ||
565 | msgs[1].buf = read_buf; | ||
566 | |||
567 | if (i2c_transfer(state->adap, msgs, 2) != 2) | ||
568 | return -EREMOTEIO; | ||
569 | |||
570 | if (read_buf[0] != 0x41) | ||
571 | return -EIO; | ||
572 | |||
573 | return 0; | ||
574 | } | ||
575 | |||
576 | static const u8 va1j5jf8007s_prepare_bufs[][2] = { | ||
577 | {0x04, 0x02}, {0x0d, 0x55}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01}, | ||
578 | {0x1c, 0x0a}, {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0}, | ||
579 | {0x52, 0x89}, {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69}, | ||
580 | {0x87, 0x04}, {0x8e, 0x02}, {0xa3, 0xf7}, {0xa5, 0xc0}, | ||
581 | }; | ||
582 | |||
583 | static int va1j5jf8007s_prepare_2(struct va1j5jf8007s_state *state) | ||
584 | { | ||
585 | u8 addr; | ||
586 | u8 buf[2]; | ||
587 | struct i2c_msg msg; | ||
588 | int i; | ||
589 | |||
590 | addr = state->config->demod_address; | ||
591 | |||
592 | msg.addr = addr; | ||
593 | msg.flags = 0; | ||
594 | msg.len = 2; | ||
595 | msg.buf = buf; | ||
596 | for (i = 0; i < ARRAY_SIZE(va1j5jf8007s_prepare_bufs); i++) { | ||
597 | memcpy(buf, va1j5jf8007s_prepare_bufs[i], sizeof(buf)); | ||
598 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
599 | return -EREMOTEIO; | ||
600 | } | ||
601 | |||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | /* must be called after va1j5jf8007t_attach */ | ||
606 | int va1j5jf8007s_prepare(struct dvb_frontend *fe) | ||
607 | { | ||
608 | struct va1j5jf8007s_state *state; | ||
609 | int ret; | ||
610 | |||
611 | state = fe->demodulator_priv; | ||
612 | |||
613 | ret = va1j5jf8007s_prepare_1(state); | ||
614 | if (ret < 0) | ||
615 | return ret; | ||
616 | |||
617 | ret = va1j5jf8007s_prepare_2(state); | ||
618 | if (ret < 0) | ||
619 | return ret; | ||
620 | |||
621 | return va1j5jf8007s_init_frequency(state); | ||
622 | } | ||
623 | |||
624 | struct dvb_frontend * | ||
625 | va1j5jf8007s_attach(const struct va1j5jf8007s_config *config, | ||
626 | struct i2c_adapter *adap) | ||
627 | { | ||
628 | struct va1j5jf8007s_state *state; | ||
629 | struct dvb_frontend *fe; | ||
630 | u8 buf[2]; | ||
631 | struct i2c_msg msg; | ||
632 | |||
633 | state = kzalloc(sizeof(struct va1j5jf8007s_state), GFP_KERNEL); | ||
634 | if (!state) | ||
635 | return NULL; | ||
636 | |||
637 | state->config = config; | ||
638 | state->adap = adap; | ||
639 | |||
640 | fe = &state->fe; | ||
641 | memcpy(&fe->ops, &va1j5jf8007s_ops, sizeof(struct dvb_frontend_ops)); | ||
642 | fe->demodulator_priv = state; | ||
643 | |||
644 | buf[0] = 0x01; | ||
645 | buf[1] = 0x80; | ||
646 | |||
647 | msg.addr = state->config->demod_address; | ||
648 | msg.flags = 0; | ||
649 | msg.len = sizeof(buf); | ||
650 | msg.buf = buf; | ||
651 | |||
652 | if (i2c_transfer(state->adap, &msg, 1) != 1) { | ||
653 | kfree(state); | ||
654 | return NULL; | ||
655 | } | ||
656 | |||
657 | return fe; | ||
658 | } | ||
diff --git a/drivers/media/dvb/pt1/va1j5jf8007s.h b/drivers/media/dvb/pt1/va1j5jf8007s.h new file mode 100644 index 000000000000..aa228a816353 --- /dev/null +++ b/drivers/media/dvb/pt1/va1j5jf8007s.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * ISDB-S driver for VA1J5JF8007 | ||
3 | * | ||
4 | * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> | ||
5 | * | ||
6 | * based on pt1dvr - http://pt1dvr.sourceforge.jp/ | ||
7 | * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef VA1J5JF8007S_H | ||
25 | #define VA1J5JF8007S_H | ||
26 | |||
27 | struct va1j5jf8007s_config { | ||
28 | u8 demod_address; | ||
29 | }; | ||
30 | |||
31 | struct i2c_adapter; | ||
32 | |||
33 | struct dvb_frontend * | ||
34 | va1j5jf8007s_attach(const struct va1j5jf8007s_config *config, | ||
35 | struct i2c_adapter *adap); | ||
36 | |||
37 | /* must be called after va1j5jf8007t_attach */ | ||
38 | int va1j5jf8007s_prepare(struct dvb_frontend *fe); | ||
39 | |||
40 | #endif | ||
diff --git a/drivers/media/dvb/pt1/va1j5jf8007t.c b/drivers/media/dvb/pt1/va1j5jf8007t.c new file mode 100644 index 000000000000..71117f4ca7e6 --- /dev/null +++ b/drivers/media/dvb/pt1/va1j5jf8007t.c | |||
@@ -0,0 +1,468 @@ | |||
1 | /* | ||
2 | * ISDB-T driver for VA1J5JF8007 | ||
3 | * | ||
4 | * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> | ||
5 | * | ||
6 | * based on pt1dvr - http://pt1dvr.sourceforge.jp/ | ||
7 | * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include "dvb_frontend.h" | ||
29 | #include "dvb_math.h" | ||
30 | #include "va1j5jf8007t.h" | ||
31 | |||
32 | enum va1j5jf8007t_tune_state { | ||
33 | VA1J5JF8007T_IDLE, | ||
34 | VA1J5JF8007T_SET_FREQUENCY, | ||
35 | VA1J5JF8007T_CHECK_FREQUENCY, | ||
36 | VA1J5JF8007T_SET_MODULATION, | ||
37 | VA1J5JF8007T_CHECK_MODULATION, | ||
38 | VA1J5JF8007T_TRACK, | ||
39 | VA1J5JF8007T_ABORT, | ||
40 | }; | ||
41 | |||
42 | struct va1j5jf8007t_state { | ||
43 | const struct va1j5jf8007t_config *config; | ||
44 | struct i2c_adapter *adap; | ||
45 | struct dvb_frontend fe; | ||
46 | enum va1j5jf8007t_tune_state tune_state; | ||
47 | }; | ||
48 | |||
49 | static int va1j5jf8007t_get_frontend_algo(struct dvb_frontend *fe) | ||
50 | { | ||
51 | return DVBFE_ALGO_HW; | ||
52 | } | ||
53 | |||
54 | static int | ||
55 | va1j5jf8007t_read_status(struct dvb_frontend *fe, fe_status_t *status) | ||
56 | { | ||
57 | struct va1j5jf8007t_state *state; | ||
58 | |||
59 | state = fe->demodulator_priv; | ||
60 | |||
61 | switch (state->tune_state) { | ||
62 | case VA1J5JF8007T_IDLE: | ||
63 | case VA1J5JF8007T_SET_FREQUENCY: | ||
64 | case VA1J5JF8007T_CHECK_FREQUENCY: | ||
65 | *status = 0; | ||
66 | return 0; | ||
67 | |||
68 | |||
69 | case VA1J5JF8007T_SET_MODULATION: | ||
70 | case VA1J5JF8007T_CHECK_MODULATION: | ||
71 | case VA1J5JF8007T_ABORT: | ||
72 | *status |= FE_HAS_SIGNAL; | ||
73 | return 0; | ||
74 | |||
75 | case VA1J5JF8007T_TRACK: | ||
76 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | BUG(); | ||
81 | } | ||
82 | |||
83 | struct va1j5jf8007t_cb_map { | ||
84 | u32 frequency; | ||
85 | u8 cb; | ||
86 | }; | ||
87 | |||
88 | static const struct va1j5jf8007t_cb_map va1j5jf8007t_cb_maps[] = { | ||
89 | { 90000000, 0x80 }, | ||
90 | { 140000000, 0x81 }, | ||
91 | { 170000000, 0xa1 }, | ||
92 | { 220000000, 0x62 }, | ||
93 | { 330000000, 0xa2 }, | ||
94 | { 402000000, 0xe2 }, | ||
95 | { 450000000, 0x64 }, | ||
96 | { 550000000, 0x84 }, | ||
97 | { 600000000, 0xa4 }, | ||
98 | { 700000000, 0xc4 }, | ||
99 | }; | ||
100 | |||
101 | static u8 va1j5jf8007t_lookup_cb(u32 frequency) | ||
102 | { | ||
103 | int i; | ||
104 | const struct va1j5jf8007t_cb_map *map; | ||
105 | |||
106 | for (i = 0; i < ARRAY_SIZE(va1j5jf8007t_cb_maps); i++) { | ||
107 | map = &va1j5jf8007t_cb_maps[i]; | ||
108 | if (frequency < map->frequency) | ||
109 | return map->cb; | ||
110 | } | ||
111 | return 0xe4; | ||
112 | } | ||
113 | |||
114 | static int va1j5jf8007t_set_frequency(struct va1j5jf8007t_state *state) | ||
115 | { | ||
116 | u32 frequency; | ||
117 | u16 word; | ||
118 | u8 buf[6]; | ||
119 | struct i2c_msg msg; | ||
120 | |||
121 | frequency = state->fe.dtv_property_cache.frequency; | ||
122 | |||
123 | word = (frequency + 71428) / 142857 + 399; | ||
124 | buf[0] = 0xfe; | ||
125 | buf[1] = 0xc2; | ||
126 | buf[2] = word >> 8; | ||
127 | buf[3] = word; | ||
128 | buf[4] = 0x80; | ||
129 | buf[5] = va1j5jf8007t_lookup_cb(frequency); | ||
130 | |||
131 | msg.addr = state->config->demod_address; | ||
132 | msg.flags = 0; | ||
133 | msg.len = sizeof(buf); | ||
134 | msg.buf = buf; | ||
135 | |||
136 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
137 | return -EREMOTEIO; | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static int | ||
143 | va1j5jf8007t_check_frequency(struct va1j5jf8007t_state *state, int *lock) | ||
144 | { | ||
145 | u8 addr; | ||
146 | u8 write_buf[2], read_buf[1]; | ||
147 | struct i2c_msg msgs[2]; | ||
148 | |||
149 | addr = state->config->demod_address; | ||
150 | |||
151 | write_buf[0] = 0xfe; | ||
152 | write_buf[1] = 0xc3; | ||
153 | |||
154 | msgs[0].addr = addr; | ||
155 | msgs[0].flags = 0; | ||
156 | msgs[0].len = sizeof(write_buf); | ||
157 | msgs[0].buf = write_buf; | ||
158 | |||
159 | msgs[1].addr = addr; | ||
160 | msgs[1].flags = I2C_M_RD; | ||
161 | msgs[1].len = sizeof(read_buf); | ||
162 | msgs[1].buf = read_buf; | ||
163 | |||
164 | if (i2c_transfer(state->adap, msgs, 2) != 2) | ||
165 | return -EREMOTEIO; | ||
166 | |||
167 | *lock = read_buf[0] & 0x40; | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static int va1j5jf8007t_set_modulation(struct va1j5jf8007t_state *state) | ||
172 | { | ||
173 | u8 buf[2]; | ||
174 | struct i2c_msg msg; | ||
175 | |||
176 | buf[0] = 0x01; | ||
177 | buf[1] = 0x40; | ||
178 | |||
179 | msg.addr = state->config->demod_address; | ||
180 | msg.flags = 0; | ||
181 | msg.len = sizeof(buf); | ||
182 | msg.buf = buf; | ||
183 | |||
184 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
185 | return -EREMOTEIO; | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static int va1j5jf8007t_check_modulation(struct va1j5jf8007t_state *state, | ||
191 | int *lock, int *retry) | ||
192 | { | ||
193 | u8 addr; | ||
194 | u8 write_buf[1], read_buf[1]; | ||
195 | struct i2c_msg msgs[2]; | ||
196 | |||
197 | addr = state->config->demod_address; | ||
198 | |||
199 | write_buf[0] = 0x80; | ||
200 | |||
201 | msgs[0].addr = addr; | ||
202 | msgs[0].flags = 0; | ||
203 | msgs[0].len = sizeof(write_buf); | ||
204 | msgs[0].buf = write_buf; | ||
205 | |||
206 | msgs[1].addr = addr; | ||
207 | msgs[1].flags = I2C_M_RD; | ||
208 | msgs[1].len = sizeof(read_buf); | ||
209 | msgs[1].buf = read_buf; | ||
210 | |||
211 | if (i2c_transfer(state->adap, msgs, 2) != 2) | ||
212 | return -EREMOTEIO; | ||
213 | |||
214 | *lock = !(read_buf[0] & 0x10); | ||
215 | *retry = read_buf[0] & 0x80; | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static int | ||
220 | va1j5jf8007t_tune(struct dvb_frontend *fe, | ||
221 | struct dvb_frontend_parameters *params, | ||
222 | unsigned int mode_flags, unsigned int *delay, | ||
223 | fe_status_t *status) | ||
224 | { | ||
225 | struct va1j5jf8007t_state *state; | ||
226 | int ret; | ||
227 | int lock, retry; | ||
228 | |||
229 | state = fe->demodulator_priv; | ||
230 | |||
231 | if (params != NULL) | ||
232 | state->tune_state = VA1J5JF8007T_SET_FREQUENCY; | ||
233 | |||
234 | switch (state->tune_state) { | ||
235 | case VA1J5JF8007T_IDLE: | ||
236 | *delay = 3 * HZ; | ||
237 | *status = 0; | ||
238 | return 0; | ||
239 | |||
240 | case VA1J5JF8007T_SET_FREQUENCY: | ||
241 | ret = va1j5jf8007t_set_frequency(state); | ||
242 | if (ret < 0) | ||
243 | return ret; | ||
244 | |||
245 | state->tune_state = VA1J5JF8007T_CHECK_FREQUENCY; | ||
246 | *delay = 0; | ||
247 | *status = 0; | ||
248 | return 0; | ||
249 | |||
250 | case VA1J5JF8007T_CHECK_FREQUENCY: | ||
251 | ret = va1j5jf8007t_check_frequency(state, &lock); | ||
252 | if (ret < 0) | ||
253 | return ret; | ||
254 | |||
255 | if (!lock) { | ||
256 | *delay = (HZ + 999) / 1000; | ||
257 | *status = 0; | ||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | state->tune_state = VA1J5JF8007T_SET_MODULATION; | ||
262 | *delay = 0; | ||
263 | *status = FE_HAS_SIGNAL; | ||
264 | return 0; | ||
265 | |||
266 | case VA1J5JF8007T_SET_MODULATION: | ||
267 | ret = va1j5jf8007t_set_modulation(state); | ||
268 | if (ret < 0) | ||
269 | return ret; | ||
270 | |||
271 | state->tune_state = VA1J5JF8007T_CHECK_MODULATION; | ||
272 | *delay = 0; | ||
273 | *status = FE_HAS_SIGNAL; | ||
274 | return 0; | ||
275 | |||
276 | case VA1J5JF8007T_CHECK_MODULATION: | ||
277 | ret = va1j5jf8007t_check_modulation(state, &lock, &retry); | ||
278 | if (ret < 0) | ||
279 | return ret; | ||
280 | |||
281 | if (!lock) { | ||
282 | if (!retry) { | ||
283 | state->tune_state = VA1J5JF8007T_ABORT; | ||
284 | *delay = 3 * HZ; | ||
285 | *status = FE_HAS_SIGNAL; | ||
286 | return 0; | ||
287 | } | ||
288 | *delay = (HZ + 999) / 1000; | ||
289 | *status = FE_HAS_SIGNAL; | ||
290 | return 0; | ||
291 | } | ||
292 | |||
293 | state->tune_state = VA1J5JF8007T_TRACK; | ||
294 | /* fall through */ | ||
295 | |||
296 | case VA1J5JF8007T_TRACK: | ||
297 | *delay = 3 * HZ; | ||
298 | *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; | ||
299 | return 0; | ||
300 | |||
301 | case VA1J5JF8007T_ABORT: | ||
302 | *delay = 3 * HZ; | ||
303 | *status = FE_HAS_SIGNAL; | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | BUG(); | ||
308 | } | ||
309 | |||
310 | static int va1j5jf8007t_init_frequency(struct va1j5jf8007t_state *state) | ||
311 | { | ||
312 | u8 buf[7]; | ||
313 | struct i2c_msg msg; | ||
314 | |||
315 | buf[0] = 0xfe; | ||
316 | buf[1] = 0xc2; | ||
317 | buf[2] = 0x01; | ||
318 | buf[3] = 0x8f; | ||
319 | buf[4] = 0xc1; | ||
320 | buf[5] = 0x80; | ||
321 | buf[6] = 0x80; | ||
322 | |||
323 | msg.addr = state->config->demod_address; | ||
324 | msg.flags = 0; | ||
325 | msg.len = sizeof(buf); | ||
326 | msg.buf = buf; | ||
327 | |||
328 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
329 | return -EREMOTEIO; | ||
330 | |||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | static int va1j5jf8007t_set_sleep(struct va1j5jf8007t_state *state, int sleep) | ||
335 | { | ||
336 | u8 buf[2]; | ||
337 | struct i2c_msg msg; | ||
338 | |||
339 | buf[0] = 0x03; | ||
340 | buf[1] = sleep ? 0x90 : 0x80; | ||
341 | |||
342 | msg.addr = state->config->demod_address; | ||
343 | msg.flags = 0; | ||
344 | msg.len = sizeof(buf); | ||
345 | msg.buf = buf; | ||
346 | |||
347 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
348 | return -EREMOTEIO; | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int va1j5jf8007t_sleep(struct dvb_frontend *fe) | ||
354 | { | ||
355 | struct va1j5jf8007t_state *state; | ||
356 | int ret; | ||
357 | |||
358 | state = fe->demodulator_priv; | ||
359 | |||
360 | ret = va1j5jf8007t_init_frequency(state); | ||
361 | if (ret < 0) | ||
362 | return ret; | ||
363 | |||
364 | return va1j5jf8007t_set_sleep(state, 1); | ||
365 | } | ||
366 | |||
367 | static int va1j5jf8007t_init(struct dvb_frontend *fe) | ||
368 | { | ||
369 | struct va1j5jf8007t_state *state; | ||
370 | |||
371 | state = fe->demodulator_priv; | ||
372 | state->tune_state = VA1J5JF8007T_IDLE; | ||
373 | |||
374 | return va1j5jf8007t_set_sleep(state, 0); | ||
375 | } | ||
376 | |||
377 | static void va1j5jf8007t_release(struct dvb_frontend *fe) | ||
378 | { | ||
379 | struct va1j5jf8007t_state *state; | ||
380 | state = fe->demodulator_priv; | ||
381 | kfree(state); | ||
382 | } | ||
383 | |||
384 | static struct dvb_frontend_ops va1j5jf8007t_ops = { | ||
385 | .info = { | ||
386 | .name = "VA1J5JF8007 ISDB-T", | ||
387 | .type = FE_OFDM, | ||
388 | .frequency_min = 90000000, | ||
389 | .frequency_max = 770000000, | ||
390 | .frequency_stepsize = 142857, | ||
391 | .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_AUTO | | ||
392 | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | | ||
393 | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO, | ||
394 | }, | ||
395 | |||
396 | .get_frontend_algo = va1j5jf8007t_get_frontend_algo, | ||
397 | .read_status = va1j5jf8007t_read_status, | ||
398 | .tune = va1j5jf8007t_tune, | ||
399 | .sleep = va1j5jf8007t_sleep, | ||
400 | .init = va1j5jf8007t_init, | ||
401 | .release = va1j5jf8007t_release, | ||
402 | }; | ||
403 | |||
404 | static const u8 va1j5jf8007t_prepare_bufs[][2] = { | ||
405 | {0x03, 0x90}, {0x14, 0x8f}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2}, | ||
406 | {0x22, 0x83}, {0x31, 0x0d}, {0x32, 0xe0}, {0x39, 0xd3}, {0x3a, 0x00}, | ||
407 | {0x5c, 0x40}, {0x5f, 0x80}, {0x75, 0x02}, {0x76, 0x4e}, {0x77, 0x03}, | ||
408 | {0xef, 0x01} | ||
409 | }; | ||
410 | |||
411 | int va1j5jf8007t_prepare(struct dvb_frontend *fe) | ||
412 | { | ||
413 | struct va1j5jf8007t_state *state; | ||
414 | u8 buf[2]; | ||
415 | struct i2c_msg msg; | ||
416 | int i; | ||
417 | |||
418 | state = fe->demodulator_priv; | ||
419 | |||
420 | msg.addr = state->config->demod_address; | ||
421 | msg.flags = 0; | ||
422 | msg.len = sizeof(buf); | ||
423 | msg.buf = buf; | ||
424 | |||
425 | for (i = 0; i < ARRAY_SIZE(va1j5jf8007t_prepare_bufs); i++) { | ||
426 | memcpy(buf, va1j5jf8007t_prepare_bufs[i], sizeof(buf)); | ||
427 | if (i2c_transfer(state->adap, &msg, 1) != 1) | ||
428 | return -EREMOTEIO; | ||
429 | } | ||
430 | |||
431 | return va1j5jf8007t_init_frequency(state); | ||
432 | } | ||
433 | |||
434 | struct dvb_frontend * | ||
435 | va1j5jf8007t_attach(const struct va1j5jf8007t_config *config, | ||
436 | struct i2c_adapter *adap) | ||
437 | { | ||
438 | struct va1j5jf8007t_state *state; | ||
439 | struct dvb_frontend *fe; | ||
440 | u8 buf[2]; | ||
441 | struct i2c_msg msg; | ||
442 | |||
443 | state = kzalloc(sizeof(struct va1j5jf8007t_state), GFP_KERNEL); | ||
444 | if (!state) | ||
445 | return NULL; | ||
446 | |||
447 | state->config = config; | ||
448 | state->adap = adap; | ||
449 | |||
450 | fe = &state->fe; | ||
451 | memcpy(&fe->ops, &va1j5jf8007t_ops, sizeof(struct dvb_frontend_ops)); | ||
452 | fe->demodulator_priv = state; | ||
453 | |||
454 | buf[0] = 0x01; | ||
455 | buf[1] = 0x80; | ||
456 | |||
457 | msg.addr = state->config->demod_address; | ||
458 | msg.flags = 0; | ||
459 | msg.len = sizeof(buf); | ||
460 | msg.buf = buf; | ||
461 | |||
462 | if (i2c_transfer(state->adap, &msg, 1) != 1) { | ||
463 | kfree(state); | ||
464 | return NULL; | ||
465 | } | ||
466 | |||
467 | return fe; | ||
468 | } | ||
diff --git a/drivers/media/dvb/pt1/va1j5jf8007t.h b/drivers/media/dvb/pt1/va1j5jf8007t.h new file mode 100644 index 000000000000..ed49906f7769 --- /dev/null +++ b/drivers/media/dvb/pt1/va1j5jf8007t.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * ISDB-T driver for VA1J5JF8007 | ||
3 | * | ||
4 | * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> | ||
5 | * | ||
6 | * based on pt1dvr - http://pt1dvr.sourceforge.jp/ | ||
7 | * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef VA1J5JF8007T_H | ||
25 | #define VA1J5JF8007T_H | ||
26 | |||
27 | struct va1j5jf8007t_config { | ||
28 | u8 demod_address; | ||
29 | }; | ||
30 | |||
31 | struct i2c_adapter; | ||
32 | |||
33 | struct dvb_frontend * | ||
34 | va1j5jf8007t_attach(const struct va1j5jf8007t_config *config, | ||
35 | struct i2c_adapter *adap); | ||
36 | |||
37 | /* must be called after va1j5jf8007s_attach */ | ||
38 | int va1j5jf8007t_prepare(struct dvb_frontend *fe); | ||
39 | |||
40 | #endif | ||