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>
32 #include "dvb_demux.h"
35 #include "dvb_frontend.h"
37 #include "va1j5jf8007t.h"
38 #include "va1j5jf8007s.h"
40 #define DRIVER_NAME "earth-pt1"
42 #define PT1_PAGE_SHIFT 12
43 #define PT1_PAGE_SIZE (1 << PT1_PAGE_SHIFT)
44 #define PT1_NR_UPACKETS 1024
45 #define PT1_NR_BUFS 511
47 struct pt1_buffer_page
{
48 __le32 upackets
[PT1_NR_UPACKETS
];
51 struct pt1_table_page
{
53 __le32 buf_pfns
[PT1_NR_BUFS
];
57 struct pt1_buffer_page
*page
;
62 struct pt1_table_page
*page
;
64 struct pt1_buffer bufs
[PT1_NR_BUFS
];
67 #define PT1_NR_ADAPS 4
74 struct i2c_adapter i2c_adap
;
76 struct pt1_adapter
*adaps
[PT1_NR_ADAPS
];
77 struct pt1_table
*tables
;
78 struct task_struct
*kthread
;
89 struct dvb_adapter adap
;
90 struct dvb_demux demux
;
94 struct dvb_frontend
*fe
;
95 int (*orig_set_voltage
)(struct dvb_frontend
*fe
,
96 fe_sec_voltage_t voltage
);
99 #define pt1_printk(level, pt1, format, arg...) \
100 dev_printk(level, &(pt1)->pdev->dev, format, ##arg)
102 static void pt1_write_reg(struct pt1
*pt1
, int reg
, u32 data
)
104 writel(data
, pt1
->regs
+ reg
* 4);
107 static u32
pt1_read_reg(struct pt1
*pt1
, int reg
)
109 return readl(pt1
->regs
+ reg
* 4);
112 static int pt1_nr_tables
= 64;
113 module_param_named(nr_tables
, pt1_nr_tables
, int, 0);
115 static void pt1_increment_table_count(struct pt1
*pt1
)
117 pt1_write_reg(pt1
, 0, 0x00000020);
120 static void pt1_init_table_count(struct pt1
*pt1
)
122 pt1_write_reg(pt1
, 0, 0x00000010);
125 static void pt1_register_tables(struct pt1
*pt1
, u32 first_pfn
)
127 pt1_write_reg(pt1
, 5, first_pfn
);
128 pt1_write_reg(pt1
, 0, 0x0c000040);
131 static void pt1_unregister_tables(struct pt1
*pt1
)
133 pt1_write_reg(pt1
, 0, 0x08080000);
136 static int pt1_sync(struct pt1
*pt1
)
139 for (i
= 0; i
< 57; i
++) {
140 if (pt1_read_reg(pt1
, 0) & 0x20000000)
142 pt1_write_reg(pt1
, 0, 0x00000008);
144 pt1_printk(KERN_ERR
, pt1
, "could not sync\n");
148 static u64
pt1_identify(struct pt1
*pt1
)
153 for (i
= 0; i
< 57; i
++) {
154 id
|= (u64
)(pt1_read_reg(pt1
, 0) >> 30 & 1) << i
;
155 pt1_write_reg(pt1
, 0, 0x00000008);
160 static int pt1_unlock(struct pt1
*pt1
)
163 pt1_write_reg(pt1
, 0, 0x00000008);
164 for (i
= 0; i
< 3; i
++) {
165 if (pt1_read_reg(pt1
, 0) & 0x80000000)
167 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
169 pt1_printk(KERN_ERR
, pt1
, "could not unlock\n");
173 static int pt1_reset_pci(struct pt1
*pt1
)
176 pt1_write_reg(pt1
, 0, 0x01010000);
177 pt1_write_reg(pt1
, 0, 0x01000000);
178 for (i
= 0; i
< 10; i
++) {
179 if (pt1_read_reg(pt1
, 0) & 0x00000001)
181 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
183 pt1_printk(KERN_ERR
, pt1
, "could not reset PCI\n");
187 static int pt1_reset_ram(struct pt1
*pt1
)
190 pt1_write_reg(pt1
, 0, 0x02020000);
191 pt1_write_reg(pt1
, 0, 0x02000000);
192 for (i
= 0; i
< 10; i
++) {
193 if (pt1_read_reg(pt1
, 0) & 0x00000002)
195 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
197 pt1_printk(KERN_ERR
, pt1
, "could not reset RAM\n");
201 static int pt1_do_enable_ram(struct pt1
*pt1
)
205 status
= pt1_read_reg(pt1
, 0) & 0x00000004;
206 pt1_write_reg(pt1
, 0, 0x00000002);
207 for (i
= 0; i
< 10; i
++) {
208 for (j
= 0; j
< 1024; j
++) {
209 if ((pt1_read_reg(pt1
, 0) & 0x00000004) != status
)
212 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
214 pt1_printk(KERN_ERR
, pt1
, "could not enable RAM\n");
218 static int pt1_enable_ram(struct pt1
*pt1
)
221 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
222 for (i
= 0; i
< 10; i
++) {
223 ret
= pt1_do_enable_ram(pt1
);
230 static void pt1_disable_ram(struct pt1
*pt1
)
232 pt1_write_reg(pt1
, 0, 0x0b0b0000);
235 static void pt1_set_stream(struct pt1
*pt1
, int index
, int enabled
)
237 pt1_write_reg(pt1
, 2, 1 << (index
+ 8) | enabled
<< index
);
240 static void pt1_init_streams(struct pt1
*pt1
)
243 for (i
= 0; i
< PT1_NR_ADAPS
; i
++)
244 pt1_set_stream(pt1
, i
, 0);
247 static int pt1_filter(struct pt1
*pt1
, struct pt1_buffer_page
*page
)
252 struct pt1_adapter
*adap
;
256 if (!page
->upackets
[PT1_NR_UPACKETS
- 1])
259 for (i
= 0; i
< PT1_NR_UPACKETS
; i
++) {
260 upacket
= le32_to_cpu(page
->upackets
[i
]);
261 index
= (upacket
>> 29) - 1;
262 if (index
< 0 || index
>= PT1_NR_ADAPS
)
265 adap
= pt1
->adaps
[index
];
266 if (upacket
>> 25 & 1)
267 adap
->upacket_count
= 0;
268 else if (!adap
->upacket_count
)
272 offset
= adap
->packet_count
* 188 + adap
->upacket_count
* 3;
273 buf
[offset
] = upacket
>> 16;
274 buf
[offset
+ 1] = upacket
>> 8;
275 if (adap
->upacket_count
!= 62)
276 buf
[offset
+ 2] = upacket
;
278 if (++adap
->upacket_count
>= 63) {
279 adap
->upacket_count
= 0;
280 if (++adap
->packet_count
>= 21) {
281 dvb_dmx_swfilter_packets(&adap
->demux
, buf
, 21);
282 adap
->packet_count
= 0;
287 page
->upackets
[PT1_NR_UPACKETS
- 1] = 0;
291 static int pt1_thread(void *data
)
296 struct pt1_buffer_page
*page
;
304 while (!kthread_should_stop()) {
307 page
= pt1
->tables
[table_index
].bufs
[buf_index
].page
;
308 if (!pt1_filter(pt1
, page
)) {
309 schedule_timeout_interruptible((HZ
+ 999) / 1000);
313 if (++buf_index
>= PT1_NR_BUFS
) {
314 pt1_increment_table_count(pt1
);
316 if (++table_index
>= pt1_nr_tables
)
324 static void pt1_free_page(struct pt1
*pt1
, void *page
, dma_addr_t addr
)
326 dma_free_coherent(&pt1
->pdev
->dev
, PT1_PAGE_SIZE
, page
, addr
);
329 static void *pt1_alloc_page(struct pt1
*pt1
, dma_addr_t
*addrp
, u32
*pfnp
)
334 page
= dma_alloc_coherent(&pt1
->pdev
->dev
, PT1_PAGE_SIZE
, &addr
,
339 BUG_ON(addr
& (PT1_PAGE_SIZE
- 1));
340 BUG_ON(addr
>> PT1_PAGE_SHIFT
>> 31 >> 1);
343 *pfnp
= addr
>> PT1_PAGE_SHIFT
;
347 static void pt1_cleanup_buffer(struct pt1
*pt1
, struct pt1_buffer
*buf
)
349 pt1_free_page(pt1
, buf
->page
, buf
->addr
);
353 pt1_init_buffer(struct pt1
*pt1
, struct pt1_buffer
*buf
, u32
*pfnp
)
355 struct pt1_buffer_page
*page
;
358 page
= pt1_alloc_page(pt1
, &addr
, pfnp
);
362 page
->upackets
[PT1_NR_UPACKETS
- 1] = 0;
369 static void pt1_cleanup_table(struct pt1
*pt1
, struct pt1_table
*table
)
373 for (i
= 0; i
< PT1_NR_BUFS
; i
++)
374 pt1_cleanup_buffer(pt1
, &table
->bufs
[i
]);
376 pt1_free_page(pt1
, table
->page
, table
->addr
);
380 pt1_init_table(struct pt1
*pt1
, struct pt1_table
*table
, u32
*pfnp
)
382 struct pt1_table_page
*page
;
387 page
= pt1_alloc_page(pt1
, &addr
, pfnp
);
391 for (i
= 0; i
< PT1_NR_BUFS
; i
++) {
392 ret
= pt1_init_buffer(pt1
, &table
->bufs
[i
], &buf_pfn
);
396 page
->buf_pfns
[i
] = cpu_to_le32(buf_pfn
);
399 pt1_increment_table_count(pt1
);
406 pt1_cleanup_buffer(pt1
, &table
->bufs
[i
]);
408 pt1_free_page(pt1
, page
, addr
);
412 static void pt1_cleanup_tables(struct pt1
*pt1
)
414 struct pt1_table
*tables
;
417 tables
= pt1
->tables
;
418 pt1_unregister_tables(pt1
);
420 for (i
= 0; i
< pt1_nr_tables
; i
++)
421 pt1_cleanup_table(pt1
, &tables
[i
]);
426 static int pt1_init_tables(struct pt1
*pt1
)
428 struct pt1_table
*tables
;
432 tables
= vmalloc(sizeof(struct pt1_table
) * pt1_nr_tables
);
436 pt1_init_table_count(pt1
);
440 ret
= pt1_init_table(pt1
, &tables
[0], &first_pfn
);
446 while (i
< pt1_nr_tables
) {
447 ret
= pt1_init_table(pt1
, &tables
[i
], &pfn
);
450 tables
[i
- 1].page
->next_pfn
= cpu_to_le32(pfn
);
454 tables
[pt1_nr_tables
- 1].page
->next_pfn
= cpu_to_le32(first_pfn
);
456 pt1_register_tables(pt1
, first_pfn
);
457 pt1
->tables
= tables
;
462 pt1_cleanup_table(pt1
, &tables
[i
]);
468 static int pt1_start_feed(struct dvb_demux_feed
*feed
)
470 struct pt1_adapter
*adap
;
471 adap
= container_of(feed
->demux
, struct pt1_adapter
, demux
);
473 pt1_set_stream(adap
->pt1
, adap
->index
, 1);
477 static int pt1_stop_feed(struct dvb_demux_feed
*feed
)
479 struct pt1_adapter
*adap
;
480 adap
= container_of(feed
->demux
, struct pt1_adapter
, demux
);
482 pt1_set_stream(adap
->pt1
, adap
->index
, 0);
487 pt1_set_power(struct pt1
*pt1
, int power
, int lnb
, int reset
)
489 pt1_write_reg(pt1
, 1, power
| lnb
<< 1 | !reset
<< 3);
492 static int pt1_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
494 struct pt1_adapter
*adap
;
497 adap
= container_of(fe
->dvb
, struct pt1_adapter
, adap
);
500 case SEC_VOLTAGE_13
: /* actually 11V */
503 case SEC_VOLTAGE_18
: /* actually 15V */
506 case SEC_VOLTAGE_OFF
:
513 pt1_set_power(adap
->pt1
, 1, lnb
, 0);
515 if (adap
->orig_set_voltage
)
516 return adap
->orig_set_voltage(fe
, voltage
);
521 static void pt1_free_adapter(struct pt1_adapter
*adap
)
523 dvb_unregister_frontend(adap
->fe
);
524 dvb_net_release(&adap
->net
);
525 adap
->demux
.dmx
.close(&adap
->demux
.dmx
);
526 dvb_dmxdev_release(&adap
->dmxdev
);
527 dvb_dmx_release(&adap
->demux
);
528 dvb_unregister_adapter(&adap
->adap
);
529 free_page((unsigned long)adap
->buf
);
533 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
535 static struct pt1_adapter
*
536 pt1_alloc_adapter(struct pt1
*pt1
, struct dvb_frontend
*fe
)
538 struct pt1_adapter
*adap
;
540 struct dvb_adapter
*dvb_adap
;
541 struct dvb_demux
*demux
;
542 struct dmxdev
*dmxdev
;
545 adap
= kzalloc(sizeof(struct pt1_adapter
), GFP_KERNEL
);
553 adap
->orig_set_voltage
= fe
->ops
.set_voltage
;
554 fe
->ops
.set_voltage
= pt1_set_voltage
;
556 buf
= (u8
*)__get_free_page(GFP_KERNEL
);
563 adap
->upacket_count
= 0;
564 adap
->packet_count
= 0;
566 dvb_adap
= &adap
->adap
;
567 dvb_adap
->priv
= adap
;
568 ret
= dvb_register_adapter(dvb_adap
, DRIVER_NAME
, THIS_MODULE
,
569 &pt1
->pdev
->dev
, adapter_nr
);
573 demux
= &adap
->demux
;
574 demux
->dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
576 demux
->feednum
= 256;
577 demux
->filternum
= 256;
578 demux
->start_feed
= pt1_start_feed
;
579 demux
->stop_feed
= pt1_stop_feed
;
580 demux
->write_to_decoder
= NULL
;
581 ret
= dvb_dmx_init(demux
);
583 goto err_unregister_adapter
;
585 dmxdev
= &adap
->dmxdev
;
586 dmxdev
->filternum
= 256;
587 dmxdev
->demux
= &demux
->dmx
;
588 dmxdev
->capabilities
= 0;
589 ret
= dvb_dmxdev_init(dmxdev
, dvb_adap
);
591 goto err_dmx_release
;
593 dvb_net_init(dvb_adap
, &adap
->net
, &demux
->dmx
);
595 ret
= dvb_register_frontend(dvb_adap
, fe
);
597 goto err_net_release
;
603 dvb_net_release(&adap
->net
);
604 adap
->demux
.dmx
.close(&adap
->demux
.dmx
);
605 dvb_dmxdev_release(&adap
->dmxdev
);
607 dvb_dmx_release(demux
);
608 err_unregister_adapter
:
609 dvb_unregister_adapter(dvb_adap
);
611 free_page((unsigned long)buf
);
618 static void pt1_cleanup_adapters(struct pt1
*pt1
)
621 for (i
= 0; i
< PT1_NR_ADAPS
; i
++)
622 pt1_free_adapter(pt1
->adaps
[i
]);
626 struct va1j5jf8007s_config va1j5jf8007s_config
;
627 struct va1j5jf8007t_config va1j5jf8007t_config
;
630 static const struct pt1_config pt1_configs
[2] = {
632 { .demod_address
= 0x1b },
633 { .demod_address
= 0x1a },
635 { .demod_address
= 0x19 },
636 { .demod_address
= 0x18 },
640 static int pt1_init_adapters(struct pt1
*pt1
)
643 struct i2c_adapter
*i2c_adap
;
644 const struct pt1_config
*config
;
645 struct dvb_frontend
*fe
[4];
646 struct pt1_adapter
*adap
;
652 i2c_adap
= &pt1
->i2c_adap
;
654 config
= &pt1_configs
[i
/ 2];
656 fe
[i
] = va1j5jf8007s_attach(&config
->va1j5jf8007s_config
,
659 ret
= -ENODEV
; /* This does not sound nice... */
664 fe
[i
] = va1j5jf8007t_attach(&config
->va1j5jf8007t_config
,
672 ret
= va1j5jf8007s_prepare(fe
[i
- 2]);
676 ret
= va1j5jf8007t_prepare(fe
[i
- 1]);
683 adap
= pt1_alloc_adapter(pt1
, fe
[j
]);
687 pt1
->adaps
[j
] = adap
;
694 fe
[i
]->ops
.release(fe
[i
]);
697 pt1_free_adapter(pt1
->adaps
[j
]);
702 static void pt1_i2c_emit(struct pt1
*pt1
, int addr
, int busy
, int read_enable
,
703 int clock
, int data
, int next_addr
)
705 pt1_write_reg(pt1
, 4, addr
<< 18 | busy
<< 13 | read_enable
<< 12 |
706 !clock
<< 11 | !data
<< 10 | next_addr
);
709 static void pt1_i2c_write_bit(struct pt1
*pt1
, int addr
, int *addrp
, int data
)
711 pt1_i2c_emit(pt1
, addr
, 1, 0, 0, data
, addr
+ 1);
712 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, data
, addr
+ 2);
713 pt1_i2c_emit(pt1
, addr
+ 2, 1, 0, 0, data
, addr
+ 3);
717 static void pt1_i2c_read_bit(struct pt1
*pt1
, int addr
, int *addrp
)
719 pt1_i2c_emit(pt1
, addr
, 1, 0, 0, 1, addr
+ 1);
720 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 1, addr
+ 2);
721 pt1_i2c_emit(pt1
, addr
+ 2, 1, 1, 1, 1, addr
+ 3);
722 pt1_i2c_emit(pt1
, addr
+ 3, 1, 0, 0, 1, addr
+ 4);
726 static void pt1_i2c_write_byte(struct pt1
*pt1
, int addr
, int *addrp
, int data
)
729 for (i
= 0; i
< 8; i
++)
730 pt1_i2c_write_bit(pt1
, addr
, &addr
, data
>> (7 - i
) & 1);
731 pt1_i2c_write_bit(pt1
, addr
, &addr
, 1);
735 static void pt1_i2c_read_byte(struct pt1
*pt1
, int addr
, int *addrp
, int last
)
738 for (i
= 0; i
< 8; i
++)
739 pt1_i2c_read_bit(pt1
, addr
, &addr
);
740 pt1_i2c_write_bit(pt1
, addr
, &addr
, last
);
744 static void pt1_i2c_prepare(struct pt1
*pt1
, int addr
, int *addrp
)
746 pt1_i2c_emit(pt1
, addr
, 1, 0, 1, 1, addr
+ 1);
747 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 0, addr
+ 2);
748 pt1_i2c_emit(pt1
, addr
+ 2, 1, 0, 0, 0, addr
+ 3);
753 pt1_i2c_write_msg(struct pt1
*pt1
, int addr
, int *addrp
, struct i2c_msg
*msg
)
756 pt1_i2c_prepare(pt1
, addr
, &addr
);
757 pt1_i2c_write_byte(pt1
, addr
, &addr
, msg
->addr
<< 1);
758 for (i
= 0; i
< msg
->len
; i
++)
759 pt1_i2c_write_byte(pt1
, addr
, &addr
, msg
->buf
[i
]);
764 pt1_i2c_read_msg(struct pt1
*pt1
, int addr
, int *addrp
, struct i2c_msg
*msg
)
767 pt1_i2c_prepare(pt1
, addr
, &addr
);
768 pt1_i2c_write_byte(pt1
, addr
, &addr
, msg
->addr
<< 1 | 1);
769 for (i
= 0; i
< msg
->len
; i
++)
770 pt1_i2c_read_byte(pt1
, addr
, &addr
, i
== msg
->len
- 1);
774 static int pt1_i2c_end(struct pt1
*pt1
, int addr
)
776 pt1_i2c_emit(pt1
, addr
, 1, 0, 0, 0, addr
+ 1);
777 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 0, addr
+ 2);
778 pt1_i2c_emit(pt1
, addr
+ 2, 1, 0, 1, 1, 0);
780 pt1_write_reg(pt1
, 0, 0x00000004);
782 if (signal_pending(current
))
784 schedule_timeout_interruptible((HZ
+ 999) / 1000);
785 } while (pt1_read_reg(pt1
, 0) & 0x00000080);
789 static void pt1_i2c_begin(struct pt1
*pt1
, int *addrp
)
794 pt1_i2c_emit(pt1
, addr
, 0, 0, 1, 1, addr
/* itself */);
797 if (!pt1
->i2c_running
) {
798 pt1_i2c_emit(pt1
, addr
, 1, 0, 1, 1, addr
+ 1);
799 pt1_i2c_emit(pt1
, addr
+ 1, 1, 0, 1, 0, addr
+ 2);
801 pt1
->i2c_running
= 1;
806 static int pt1_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msgs
, int num
)
810 struct i2c_msg
*msg
, *next_msg
;
815 pt1
= i2c_get_adapdata(adap
);
817 for (i
= 0; i
< num
; i
++) {
819 if (msg
->flags
& I2C_M_RD
)
823 next_msg
= &msgs
[i
+ 1];
827 if (next_msg
&& next_msg
->flags
& I2C_M_RD
) {
834 pt1_i2c_begin(pt1
, &addr
);
835 pt1_i2c_write_msg(pt1
, addr
, &addr
, msg
);
836 pt1_i2c_read_msg(pt1
, addr
, &addr
, next_msg
);
837 ret
= pt1_i2c_end(pt1
, addr
);
841 word
= pt1_read_reg(pt1
, 2);
843 next_msg
->buf
[len
] = word
;
847 pt1_i2c_begin(pt1
, &addr
);
848 pt1_i2c_write_msg(pt1
, addr
, &addr
, msg
);
849 ret
= pt1_i2c_end(pt1
, addr
);
858 static u32
pt1_i2c_func(struct i2c_adapter
*adap
)
863 static const struct i2c_algorithm pt1_i2c_algo
= {
864 .master_xfer
= pt1_i2c_xfer
,
865 .functionality
= pt1_i2c_func
,
868 static void pt1_i2c_wait(struct pt1
*pt1
)
871 for (i
= 0; i
< 128; i
++)
872 pt1_i2c_emit(pt1
, 0, 0, 0, 1, 1, 0);
875 static void pt1_i2c_init(struct pt1
*pt1
)
878 for (i
= 0; i
< 1024; i
++)
879 pt1_i2c_emit(pt1
, i
, 0, 0, 1, 1, 0);
882 static void __devexit
pt1_remove(struct pci_dev
*pdev
)
887 pt1
= pci_get_drvdata(pdev
);
890 kthread_stop(pt1
->kthread
);
891 pt1_cleanup_tables(pt1
);
892 pt1_cleanup_adapters(pt1
);
893 pt1_disable_ram(pt1
);
894 pt1_set_power(pt1
, 0, 0, 1);
895 i2c_del_adapter(&pt1
->i2c_adap
);
896 pci_set_drvdata(pdev
, NULL
);
898 pci_iounmap(pdev
, regs
);
899 pci_release_regions(pdev
);
900 pci_disable_device(pdev
);
904 pt1_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
909 struct i2c_adapter
*i2c_adap
;
910 struct task_struct
*kthread
;
912 ret
= pci_enable_device(pdev
);
916 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
918 goto err_pci_disable_device
;
920 pci_set_master(pdev
);
922 ret
= pci_request_regions(pdev
, DRIVER_NAME
);
924 goto err_pci_disable_device
;
926 regs
= pci_iomap(pdev
, 0, 0);
929 goto err_pci_release_regions
;
932 pt1
= kzalloc(sizeof(struct pt1
), GFP_KERNEL
);
935 goto err_pci_iounmap
;
940 pci_set_drvdata(pdev
, pt1
);
942 i2c_adap
= &pt1
->i2c_adap
;
943 i2c_adap
->class = I2C_CLASS_TV_DIGITAL
;
944 i2c_adap
->algo
= &pt1_i2c_algo
;
945 i2c_adap
->algo_data
= NULL
;
946 i2c_adap
->dev
.parent
= &pdev
->dev
;
947 i2c_set_adapdata(i2c_adap
, pt1
);
948 ret
= i2c_add_adapter(i2c_adap
);
952 pt1_set_power(pt1
, 0, 0, 1);
959 goto err_i2c_del_adapter
;
963 ret
= pt1_unlock(pt1
);
965 goto err_i2c_del_adapter
;
967 ret
= pt1_reset_pci(pt1
);
969 goto err_i2c_del_adapter
;
971 ret
= pt1_reset_ram(pt1
);
973 goto err_i2c_del_adapter
;
975 ret
= pt1_enable_ram(pt1
);
977 goto err_i2c_del_adapter
;
979 pt1_init_streams(pt1
);
981 pt1_set_power(pt1
, 1, 0, 1);
982 schedule_timeout_uninterruptible((HZ
+ 49) / 50);
984 pt1_set_power(pt1
, 1, 0, 0);
985 schedule_timeout_uninterruptible((HZ
+ 999) / 1000);
987 ret
= pt1_init_adapters(pt1
);
989 goto err_pt1_disable_ram
;
991 ret
= pt1_init_tables(pt1
);
993 goto err_pt1_cleanup_adapters
;
995 kthread
= kthread_run(pt1_thread
, pt1
, "pt1");
996 if (IS_ERR(kthread
)) {
997 ret
= PTR_ERR(kthread
);
998 goto err_pt1_cleanup_tables
;
1001 pt1
->kthread
= kthread
;
1004 err_pt1_cleanup_tables
:
1005 pt1_cleanup_tables(pt1
);
1006 err_pt1_cleanup_adapters
:
1007 pt1_cleanup_adapters(pt1
);
1008 err_pt1_disable_ram
:
1009 pt1_disable_ram(pt1
);
1010 pt1_set_power(pt1
, 0, 0, 1);
1011 err_i2c_del_adapter
:
1012 i2c_del_adapter(i2c_adap
);
1014 pci_set_drvdata(pdev
, NULL
);
1017 pci_iounmap(pdev
, regs
);
1018 err_pci_release_regions
:
1019 pci_release_regions(pdev
);
1020 err_pci_disable_device
:
1021 pci_disable_device(pdev
);
1027 static struct pci_device_id pt1_id_table
[] = {
1028 { PCI_DEVICE(0x10ee, 0x211a) },
1031 MODULE_DEVICE_TABLE(pci
, pt1_id_table
);
1033 static struct pci_driver pt1_driver
= {
1034 .name
= DRIVER_NAME
,
1036 .remove
= __devexit_p(pt1_remove
),
1037 .id_table
= pt1_id_table
,
1041 static int __init
pt1_init(void)
1043 return pci_register_driver(&pt1_driver
);
1047 static void __exit
pt1_cleanup(void)
1049 pci_unregister_driver(&pt1_driver
);
1052 module_init(pt1_init
);
1053 module_exit(pt1_cleanup
);
1055 MODULE_AUTHOR("Takahito HIRANO <hiranotaka@zng.info>");
1056 MODULE_DESCRIPTION("Earthsoft PT1 Driver");
1057 MODULE_LICENSE("GPL");