2 * driver for Earthsoft PT1
4 * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info>
6 * based on pt1dvr - http://pt1dvr.sourceforge.jp/
7 * by Tomoaki Ishikawa <tomy@users.sourceforge.jp>
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.
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.
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.
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/vmalloc.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/freezer.h>
30 #include <linux/vmalloc.h>
33 #include "dvb_demux.h"
36 #include "dvb_frontend.h"
38 #include "va1j5jf8007t.h"
39 #include "va1j5jf8007s.h"
41 #define DRIVER_NAME "earth-pt1"
43 #define PT1_PAGE_SHIFT 12
44 #define PT1_PAGE_SIZE (1 << PT1_PAGE_SHIFT)
45 #define PT1_NR_UPACKETS 1024
46 #define PT1_NR_BUFS 511
48 struct pt1_buffer_page
{
49 __le32 upackets
[PT1_NR_UPACKETS
];
52 struct pt1_table_page
{
54 __le32 buf_pfns
[PT1_NR_BUFS
];
58 struct pt1_buffer_page
*page
;
63 struct pt1_table_page
*page
;
65 struct pt1_buffer bufs
[PT1_NR_BUFS
];
68 #define PT1_NR_ADAPS 4
75 struct i2c_adapter i2c_adap
;
77 struct pt1_adapter
*adaps
[PT1_NR_ADAPS
];
78 struct pt1_table
*tables
;
79 struct task_struct
*kthread
;
90 struct dvb_adapter adap
;
91 struct dvb_demux demux
;
95 struct dvb_frontend
*fe
;
96 int (*orig_set_voltage
)(struct dvb_frontend
*fe
,
97 fe_sec_voltage_t voltage
);
100 #define pt1_printk(level, pt1, format, arg...) \
101 dev_printk(level, &(pt1)->pdev->dev, format, ##arg)
103 static void pt1_write_reg(struct pt1
*pt1
, int reg
, u32 data
)
105 writel(data
, pt1
->regs
+ reg
* 4);
108 static u32
pt1_read_reg(struct pt1
*pt1
, int reg
)
110 return readl(pt1
->regs
+ reg
* 4);
113 static int pt1_nr_tables
= 64;
114 module_param_named(nr_tables
, pt1_nr_tables
, int, 0);
116 static void pt1_increment_table_count(struct pt1
*pt1
)
118 pt1_write_reg(pt1
, 0, 0x00000020);
121 static void pt1_init_table_count(struct pt1
*pt1
)
123 pt1_write_reg(pt1
, 0, 0x00000010);
126 static void pt1_register_tables(struct pt1
*pt1
, u32 first_pfn
)
128 pt1_write_reg(pt1
, 5, first_pfn
);
129 pt1_write_reg(pt1
, 0, 0x0c000040);
132 static void pt1_unregister_tables(struct pt1
*pt1
)
134 pt1_write_reg(pt1
, 0, 0x08080000);
137 static int pt1_sync(struct pt1
*pt1
)
140 for (i
= 0; i
< 57; i
++) {
141 if (pt1_read_reg(pt1
, 0) & 0x20000000)
143 pt1_write_reg(pt1
, 0, 0x00000008);
145 pt1_printk(KERN_ERR
, pt1
, "could not sync\n");
149 static u64
pt1_identify(struct pt1
*pt1
)
154 for (i
= 0; i
< 57; i
++) {
155 id
|= (u64
)(pt1_read_reg(pt1
, 0) >> 30 & 1) << i
;
156 pt1_write_reg(pt1
, 0, 0x00000008);
161 static int pt1_unlock(struct pt1
*pt1
)
164 pt1_write_reg(pt1
, 0, 0x00000008);
165 for (i
= 0; i
< 3; i
++) {
166 if (pt1_read_reg(pt1
, 0) & 0x80000000)
168 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
170 pt1_printk(KERN_ERR
, pt1
, "could not unlock\n");
174 static int pt1_reset_pci(struct pt1
*pt1
)
177 pt1_write_reg(pt1
, 0, 0x01010000);
178 pt1_write_reg(pt1
, 0, 0x01000000);
179 for (i
= 0; i
< 10; i
++) {
180 if (pt1_read_reg(pt1
, 0) & 0x00000001)
182 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
184 pt1_printk(KERN_ERR
, pt1
, "could not reset PCI\n");
188 static int pt1_reset_ram(struct pt1
*pt1
)
191 pt1_write_reg(pt1
, 0, 0x02020000);
192 pt1_write_reg(pt1
, 0, 0x02000000);
193 for (i
= 0; i
< 10; i
++) {
194 if (pt1_read_reg(pt1
, 0) & 0x00000002)
196 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
198 pt1_printk(KERN_ERR
, pt1
, "could not reset RAM\n");
202 static int pt1_do_enable_ram(struct pt1
*pt1
)
206 status
= pt1_read_reg(pt1
, 0) & 0x00000004;
207 pt1_write_reg(pt1
, 0, 0x00000002);
208 for (i
= 0; i
< 10; i
++) {
209 for (j
= 0; j
< 1024; j
++) {
210 if ((pt1_read_reg(pt1
, 0) & 0x00000004) != status
)
213 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
215 pt1_printk(KERN_ERR
, pt1
, "could not enable RAM\n");
219 static int pt1_enable_ram(struct pt1
*pt1
)
222 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
223 for (i
= 0; i
< 10; i
++) {
224 ret
= pt1_do_enable_ram(pt1
);
231 static void pt1_disable_ram(struct pt1
*pt1
)
233 pt1_write_reg(pt1
, 0, 0x0b0b0000);
236 static void pt1_set_stream(struct pt1
*pt1
, int index
, int enabled
)
238 pt1_write_reg(pt1
, 2, 1 << (index
+ 8) | enabled
<< index
);
241 static void pt1_init_streams(struct pt1
*pt1
)
244 for (i
= 0; i
< PT1_NR_ADAPS
; i
++)
245 pt1_set_stream(pt1
, i
, 0);
248 static int pt1_filter(struct pt1
*pt1
, struct pt1_buffer_page
*page
)
253 struct pt1_adapter
*adap
;
257 if (!page
->upackets
[PT1_NR_UPACKETS
- 1])
260 for (i
= 0; i
< PT1_NR_UPACKETS
; i
++) {
261 upacket
= le32_to_cpu(page
->upackets
[i
]);
262 index
= (upacket
>> 29) - 1;
263 if (index
< 0 || index
>= PT1_NR_ADAPS
)
266 adap
= pt1
->adaps
[index
];
267 if (upacket
>> 25 & 1)
268 adap
->upacket_count
= 0;
269 else if (!adap
->upacket_count
)
273 offset
= adap
->packet_count
* 188 + adap
->upacket_count
* 3;
274 buf
[offset
] = upacket
>> 16;
275 buf
[offset
+ 1] = upacket
>> 8;
276 if (adap
->upacket_count
!= 62)
277 buf
[offset
+ 2] = upacket
;
279 if (++adap
->upacket_count
>= 63) {
280 adap
->upacket_count
= 0;
281 if (++adap
->packet_count
>= 21) {
282 dvb_dmx_swfilter_packets(&adap
->demux
, buf
, 21);
283 adap
->packet_count
= 0;
288 page
->upackets
[PT1_NR_UPACKETS
- 1] = 0;
292 static int pt1_thread(void *data
)
297 struct pt1_buffer_page
*page
;
305 while (!kthread_should_stop()) {
308 page
= pt1
->tables
[table_index
].bufs
[buf_index
].page
;
309 if (!pt1_filter(pt1
, page
)) {
310 schedule_timeout_interruptible((HZ
+ 999) / 1000);
314 if (++buf_index
>= PT1_NR_BUFS
) {
315 pt1_increment_table_count(pt1
);
317 if (++table_index
>= pt1_nr_tables
)
325 static void pt1_free_page(struct pt1
*pt1
, void *page
, dma_addr_t addr
)
327 dma_free_coherent(&pt1
->pdev
->dev
, PT1_PAGE_SIZE
, page
, addr
);
330 static void *pt1_alloc_page(struct pt1
*pt1
, dma_addr_t
*addrp
, u32
*pfnp
)
335 page
= dma_alloc_coherent(&pt1
->pdev
->dev
, PT1_PAGE_SIZE
, &addr
,
340 BUG_ON(addr
& (PT1_PAGE_SIZE
- 1));
341 BUG_ON(addr
>> PT1_PAGE_SHIFT
>> 31 >> 1);
344 *pfnp
= addr
>> PT1_PAGE_SHIFT
;
348 static void pt1_cleanup_buffer(struct pt1
*pt1
, struct pt1_buffer
*buf
)
350 pt1_free_page(pt1
, buf
->page
, buf
->addr
);
354 pt1_init_buffer(struct pt1
*pt1
, struct pt1_buffer
*buf
, u32
*pfnp
)
356 struct pt1_buffer_page
*page
;
359 page
= pt1_alloc_page(pt1
, &addr
, pfnp
);
363 page
->upackets
[PT1_NR_UPACKETS
- 1] = 0;
370 static void pt1_cleanup_table(struct pt1
*pt1
, struct pt1_table
*table
)
374 for (i
= 0; i
< PT1_NR_BUFS
; i
++)
375 pt1_cleanup_buffer(pt1
, &table
->bufs
[i
]);
377 pt1_free_page(pt1
, table
->page
, table
->addr
);
381 pt1_init_table(struct pt1
*pt1
, struct pt1_table
*table
, u32
*pfnp
)
383 struct pt1_table_page
*page
;
388 page
= pt1_alloc_page(pt1
, &addr
, pfnp
);
392 for (i
= 0; i
< PT1_NR_BUFS
; i
++) {
393 ret
= pt1_init_buffer(pt1
, &table
->bufs
[i
], &buf_pfn
);
397 page
->buf_pfns
[i
] = cpu_to_le32(buf_pfn
);
400 pt1_increment_table_count(pt1
);
407 pt1_cleanup_buffer(pt1
, &table
->bufs
[i
]);
409 pt1_free_page(pt1
, page
, addr
);
413 static void pt1_cleanup_tables(struct pt1
*pt1
)
415 struct pt1_table
*tables
;
418 tables
= pt1
->tables
;
419 pt1_unregister_tables(pt1
);
421 for (i
= 0; i
< pt1_nr_tables
; i
++)
422 pt1_cleanup_table(pt1
, &tables
[i
]);
427 static int pt1_init_tables(struct pt1
*pt1
)
429 struct pt1_table
*tables
;
433 tables
= vmalloc(sizeof(struct pt1_table
) * pt1_nr_tables
);
437 pt1_init_table_count(pt1
);
441 ret
= pt1_init_table(pt1
, &tables
[0], &first_pfn
);
447 while (i
< pt1_nr_tables
) {
448 ret
= pt1_init_table(pt1
, &tables
[i
], &pfn
);
451 tables
[i
- 1].page
->next_pfn
= cpu_to_le32(pfn
);
455 tables
[pt1_nr_tables
- 1].page
->next_pfn
= cpu_to_le32(first_pfn
);
457 pt1_register_tables(pt1
, first_pfn
);
458 pt1
->tables
= tables
;
463 pt1_cleanup_table(pt1
, &tables
[i
]);
469 static int pt1_start_feed(struct dvb_demux_feed
*feed
)
471 struct pt1_adapter
*adap
;
472 adap
= container_of(feed
->demux
, struct pt1_adapter
, demux
);
474 pt1_set_stream(adap
->pt1
, adap
->index
, 1);
478 static int pt1_stop_feed(struct dvb_demux_feed
*feed
)
480 struct pt1_adapter
*adap
;
481 adap
= container_of(feed
->demux
, struct pt1_adapter
, demux
);
483 pt1_set_stream(adap
->pt1
, adap
->index
, 0);
488 pt1_set_power(struct pt1
*pt1
, int power
, int lnb
, int reset
)
490 pt1_write_reg(pt1
, 1, power
| lnb
<< 1 | !reset
<< 3);
493 static int pt1_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
495 struct pt1_adapter
*adap
;
498 adap
= container_of(fe
->dvb
, struct pt1_adapter
, adap
);
501 case SEC_VOLTAGE_13
: /* actually 11V */
504 case SEC_VOLTAGE_18
: /* actually 15V */
507 case SEC_VOLTAGE_OFF
:
514 pt1_set_power(adap
->pt1
, 1, lnb
, 0);
516 if (adap
->orig_set_voltage
)
517 return adap
->orig_set_voltage(fe
, voltage
);
522 static void pt1_free_adapter(struct pt1_adapter
*adap
)
524 dvb_unregister_frontend(adap
->fe
);
525 dvb_net_release(&adap
->net
);
526 adap
->demux
.dmx
.close(&adap
->demux
.dmx
);
527 dvb_dmxdev_release(&adap
->dmxdev
);
528 dvb_dmx_release(&adap
->demux
);
529 dvb_unregister_adapter(&adap
->adap
);
530 free_page((unsigned long)adap
->buf
);
534 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
536 static struct pt1_adapter
*
537 pt1_alloc_adapter(struct pt1
*pt1
, struct dvb_frontend
*fe
)
539 struct pt1_adapter
*adap
;
541 struct dvb_adapter
*dvb_adap
;
542 struct dvb_demux
*demux
;
543 struct dmxdev
*dmxdev
;
546 adap
= kzalloc(sizeof(struct pt1_adapter
), GFP_KERNEL
);
554 adap
->orig_set_voltage
= fe
->ops
.set_voltage
;
555 fe
->ops
.set_voltage
= pt1_set_voltage
;
557 buf
= (u8
*)__get_free_page(GFP_KERNEL
);
564 adap
->upacket_count
= 0;
565 adap
->packet_count
= 0;
567 dvb_adap
= &adap
->adap
;
568 dvb_adap
->priv
= adap
;
569 ret
= dvb_register_adapter(dvb_adap
, DRIVER_NAME
, THIS_MODULE
,
570 &pt1
->pdev
->dev
, adapter_nr
);
574 demux
= &adap
->demux
;
575 demux
->dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
577 demux
->feednum
= 256;
578 demux
->filternum
= 256;
579 demux
->start_feed
= pt1_start_feed
;
580 demux
->stop_feed
= pt1_stop_feed
;
581 demux
->write_to_decoder
= NULL
;
582 ret
= dvb_dmx_init(demux
);
584 goto err_unregister_adapter
;
586 dmxdev
= &adap
->dmxdev
;
587 dmxdev
->filternum
= 256;
588 dmxdev
->demux
= &demux
->dmx
;
589 dmxdev
->capabilities
= 0;
590 ret
= dvb_dmxdev_init(dmxdev
, dvb_adap
);
592 goto err_dmx_release
;
594 dvb_net_init(dvb_adap
, &adap
->net
, &demux
->dmx
);
596 ret
= dvb_register_frontend(dvb_adap
, fe
);
598 goto err_net_release
;
604 dvb_net_release(&adap
->net
);
605 adap
->demux
.dmx
.close(&adap
->demux
.dmx
);
606 dvb_dmxdev_release(&adap
->dmxdev
);
608 dvb_dmx_release(demux
);
609 err_unregister_adapter
:
610 dvb_unregister_adapter(dvb_adap
);
612 free_page((unsigned long)buf
);
619 static void pt1_cleanup_adapters(struct pt1
*pt1
)
622 for (i
= 0; i
< PT1_NR_ADAPS
; i
++)
623 pt1_free_adapter(pt1
->adaps
[i
]);
627 struct va1j5jf8007s_config va1j5jf8007s_config
;
628 struct va1j5jf8007t_config va1j5jf8007t_config
;
631 static const struct pt1_config pt1_configs
[2] = {
633 { .demod_address
= 0x1b },
634 { .demod_address
= 0x1a },
636 { .demod_address
= 0x19 },
637 { .demod_address
= 0x18 },
641 static int pt1_init_adapters(struct pt1
*pt1
)
644 struct i2c_adapter
*i2c_adap
;
645 const struct pt1_config
*config
;
646 struct dvb_frontend
*fe
[4];
647 struct pt1_adapter
*adap
;
653 i2c_adap
= &pt1
->i2c_adap
;
655 config
= &pt1_configs
[i
/ 2];
657 fe
[i
] = va1j5jf8007s_attach(&config
->va1j5jf8007s_config
,
660 ret
= -ENODEV
; /* This does not sound nice... */
665 fe
[i
] = va1j5jf8007t_attach(&config
->va1j5jf8007t_config
,
673 ret
= va1j5jf8007s_prepare(fe
[i
- 2]);
677 ret
= va1j5jf8007t_prepare(fe
[i
- 1]);
684 adap
= pt1_alloc_adapter(pt1
, fe
[j
]);
688 pt1
->adaps
[j
] = adap
;
695 fe
[i
]->ops
.release(fe
[i
]);
698 pt1_free_adapter(pt1
->adaps
[j
]);
703 static void pt1_i2c_emit(struct pt1
*pt1
, int addr
, int busy
, int read_enable
,
704 int clock
, int data
, int next_addr
)
706 pt1_write_reg(pt1
, 4, addr
<< 18 | busy
<< 13 | read_enable
<< 12 |
707 !clock
<< 11 | !data
<< 10 | next_addr
);
710 static void pt1_i2c_write_bit(struct pt1
*pt1
, int addr
, int *addrp
, int data
)
712 pt1_i2c_emit(pt1
, addr
, 1, 0, 0, data
, addr
+ 1);
713 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, data
, addr
+ 2);
714 pt1_i2c_emit(pt1
, addr
+ 2, 1, 0, 0, data
, addr
+ 3);
718 static void pt1_i2c_read_bit(struct pt1
*pt1
, int addr
, int *addrp
)
720 pt1_i2c_emit(pt1
, addr
, 1, 0, 0, 1, addr
+ 1);
721 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 1, addr
+ 2);
722 pt1_i2c_emit(pt1
, addr
+ 2, 1, 1, 1, 1, addr
+ 3);
723 pt1_i2c_emit(pt1
, addr
+ 3, 1, 0, 0, 1, addr
+ 4);
727 static void pt1_i2c_write_byte(struct pt1
*pt1
, int addr
, int *addrp
, int data
)
730 for (i
= 0; i
< 8; i
++)
731 pt1_i2c_write_bit(pt1
, addr
, &addr
, data
>> (7 - i
) & 1);
732 pt1_i2c_write_bit(pt1
, addr
, &addr
, 1);
736 static void pt1_i2c_read_byte(struct pt1
*pt1
, int addr
, int *addrp
, int last
)
739 for (i
= 0; i
< 8; i
++)
740 pt1_i2c_read_bit(pt1
, addr
, &addr
);
741 pt1_i2c_write_bit(pt1
, addr
, &addr
, last
);
745 static void pt1_i2c_prepare(struct pt1
*pt1
, int addr
, int *addrp
)
747 pt1_i2c_emit(pt1
, addr
, 1, 0, 1, 1, addr
+ 1);
748 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 0, addr
+ 2);
749 pt1_i2c_emit(pt1
, addr
+ 2, 1, 0, 0, 0, addr
+ 3);
754 pt1_i2c_write_msg(struct pt1
*pt1
, int addr
, int *addrp
, struct i2c_msg
*msg
)
757 pt1_i2c_prepare(pt1
, addr
, &addr
);
758 pt1_i2c_write_byte(pt1
, addr
, &addr
, msg
->addr
<< 1);
759 for (i
= 0; i
< msg
->len
; i
++)
760 pt1_i2c_write_byte(pt1
, addr
, &addr
, msg
->buf
[i
]);
765 pt1_i2c_read_msg(struct pt1
*pt1
, int addr
, int *addrp
, struct i2c_msg
*msg
)
768 pt1_i2c_prepare(pt1
, addr
, &addr
);
769 pt1_i2c_write_byte(pt1
, addr
, &addr
, msg
->addr
<< 1 | 1);
770 for (i
= 0; i
< msg
->len
; i
++)
771 pt1_i2c_read_byte(pt1
, addr
, &addr
, i
== msg
->len
- 1);
775 static int pt1_i2c_end(struct pt1
*pt1
, int addr
)
777 pt1_i2c_emit(pt1
, addr
, 1, 0, 0, 0, addr
+ 1);
778 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 0, addr
+ 2);
779 pt1_i2c_emit(pt1
, addr
+ 2, 1, 0, 1, 1, 0);
781 pt1_write_reg(pt1
, 0, 0x00000004);
783 if (signal_pending(current
))
785 schedule_timeout_interruptible((HZ
+ 999) / 1000);
786 } while (pt1_read_reg(pt1
, 0) & 0x00000080);
790 static void pt1_i2c_begin(struct pt1
*pt1
, int *addrp
)
795 pt1_i2c_emit(pt1
, addr
, 0, 0, 1, 1, addr
/* itself */);
798 if (!pt1
->i2c_running
) {
799 pt1_i2c_emit(pt1
, addr
, 1, 0, 1, 1, addr
+ 1);
800 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 0, addr
+ 2);
802 pt1
->i2c_running
= 1;
807 static int pt1_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msgs
, int num
)
811 struct i2c_msg
*msg
, *next_msg
;
816 pt1
= i2c_get_adapdata(adap
);
818 for (i
= 0; i
< num
; i
++) {
820 if (msg
->flags
& I2C_M_RD
)
824 next_msg
= &msgs
[i
+ 1];
828 if (next_msg
&& next_msg
->flags
& I2C_M_RD
) {
835 pt1_i2c_begin(pt1
, &addr
);
836 pt1_i2c_write_msg(pt1
, addr
, &addr
, msg
);
837 pt1_i2c_read_msg(pt1
, addr
, &addr
, next_msg
);
838 ret
= pt1_i2c_end(pt1
, addr
);
842 word
= pt1_read_reg(pt1
, 2);
844 next_msg
->buf
[len
] = word
;
848 pt1_i2c_begin(pt1
, &addr
);
849 pt1_i2c_write_msg(pt1
, addr
, &addr
, msg
);
850 ret
= pt1_i2c_end(pt1
, addr
);
859 static u32
pt1_i2c_func(struct i2c_adapter
*adap
)
864 static const struct i2c_algorithm pt1_i2c_algo
= {
865 .master_xfer
= pt1_i2c_xfer
,
866 .functionality
= pt1_i2c_func
,
869 static void pt1_i2c_wait(struct pt1
*pt1
)
872 for (i
= 0; i
< 128; i
++)
873 pt1_i2c_emit(pt1
, 0, 0, 0, 1, 1, 0);
876 static void pt1_i2c_init(struct pt1
*pt1
)
879 for (i
= 0; i
< 1024; i
++)
880 pt1_i2c_emit(pt1
, i
, 0, 0, 1, 1, 0);
883 static void __devexit
pt1_remove(struct pci_dev
*pdev
)
888 pt1
= pci_get_drvdata(pdev
);
891 kthread_stop(pt1
->kthread
);
892 pt1_cleanup_tables(pt1
);
893 pt1_cleanup_adapters(pt1
);
894 pt1_disable_ram(pt1
);
895 pt1_set_power(pt1
, 0, 0, 1);
896 i2c_del_adapter(&pt1
->i2c_adap
);
897 pci_set_drvdata(pdev
, NULL
);
899 pci_iounmap(pdev
, regs
);
900 pci_release_regions(pdev
);
901 pci_disable_device(pdev
);
905 pt1_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
910 struct i2c_adapter
*i2c_adap
;
911 struct task_struct
*kthread
;
913 ret
= pci_enable_device(pdev
);
917 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
919 goto err_pci_disable_device
;
921 pci_set_master(pdev
);
923 ret
= pci_request_regions(pdev
, DRIVER_NAME
);
925 goto err_pci_disable_device
;
927 regs
= pci_iomap(pdev
, 0, 0);
930 goto err_pci_release_regions
;
933 pt1
= kzalloc(sizeof(struct pt1
), GFP_KERNEL
);
936 goto err_pci_iounmap
;
941 pci_set_drvdata(pdev
, pt1
);
943 i2c_adap
= &pt1
->i2c_adap
;
944 i2c_adap
->class = I2C_CLASS_TV_DIGITAL
;
945 i2c_adap
->algo
= &pt1_i2c_algo
;
946 i2c_adap
->algo_data
= NULL
;
947 i2c_adap
->dev
.parent
= &pdev
->dev
;
948 i2c_set_adapdata(i2c_adap
, pt1
);
949 ret
= i2c_add_adapter(i2c_adap
);
953 pt1_set_power(pt1
, 0, 0, 1);
960 goto err_i2c_del_adapter
;
964 ret
= pt1_unlock(pt1
);
966 goto err_i2c_del_adapter
;
968 ret
= pt1_reset_pci(pt1
);
970 goto err_i2c_del_adapter
;
972 ret
= pt1_reset_ram(pt1
);
974 goto err_i2c_del_adapter
;
976 ret
= pt1_enable_ram(pt1
);
978 goto err_i2c_del_adapter
;
980 pt1_init_streams(pt1
);
982 pt1_set_power(pt1
, 1, 0, 1);
983 schedule_timeout_uninterruptible((HZ
+ 49) / 50);
985 pt1_set_power(pt1
, 1, 0, 0);
986 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
988 ret
= pt1_init_adapters(pt1
);
990 goto err_pt1_disable_ram
;
992 ret
= pt1_init_tables(pt1
);
994 goto err_pt1_cleanup_adapters
;
996 kthread
= kthread_run(pt1_thread
, pt1
, "pt1");
997 if (IS_ERR(kthread
)) {
998 ret
= PTR_ERR(kthread
);
999 goto err_pt1_cleanup_tables
;
1002 pt1
->kthread
= kthread
;
1005 err_pt1_cleanup_tables
:
1006 pt1_cleanup_tables(pt1
);
1007 err_pt1_cleanup_adapters
:
1008 pt1_cleanup_adapters(pt1
);
1009 err_pt1_disable_ram
:
1010 pt1_disable_ram(pt1
);
1011 pt1_set_power(pt1
, 0, 0, 1);
1012 err_i2c_del_adapter
:
1013 i2c_del_adapter(i2c_adap
);
1015 pci_set_drvdata(pdev
, NULL
);
1018 pci_iounmap(pdev
, regs
);
1019 err_pci_release_regions
:
1020 pci_release_regions(pdev
);
1021 err_pci_disable_device
:
1022 pci_disable_device(pdev
);
1028 static struct pci_device_id pt1_id_table
[] = {
1029 { PCI_DEVICE(0x10ee, 0x211a) },
1032 MODULE_DEVICE_TABLE(pci
, pt1_id_table
);
1034 static struct pci_driver pt1_driver
= {
1035 .name
= DRIVER_NAME
,
1037 .remove
= __devexit_p(pt1_remove
),
1038 .id_table
= pt1_id_table
,
1042 static int __init
pt1_init(void)
1044 return pci_register_driver(&pt1_driver
);
1048 static void __exit
pt1_cleanup(void)
1050 pci_unregister_driver(&pt1_driver
);
1053 module_init(pt1_init
);
1054 module_exit(pt1_cleanup
);
1056 MODULE_AUTHOR("Takahito HIRANO <hiranotaka@zng.info>");
1057 MODULE_DESCRIPTION("Earthsoft PT1 Driver");
1058 MODULE_LICENSE("GPL");