2 * Remote control driver for the TV-card based on bt829
4 * by Leonid Froenchenko <lfroen@galileo.co.il>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/threads.h>
24 #include <linux/sched.h>
25 #include <linux/ioport.h>
26 #include <linux/pci.h>
27 #include <linux/delay.h>
29 #include <media/lirc_dev.h>
31 static int poll_main(void);
32 static int atir_init_start(void);
34 static void write_index(unsigned char index
, unsigned int value
);
35 static unsigned int read_index(unsigned char index
);
37 static void do_i2c_start(void);
38 static void do_i2c_stop(void);
40 static void seems_wr_byte(unsigned char al
);
41 static unsigned char seems_rd_byte(void);
43 static unsigned int read_index(unsigned char al
);
44 static void write_index(unsigned char ah
, unsigned int edx
);
46 static void cycle_delay(int cycle
);
48 static void do_set_bits(unsigned char bl
);
49 static unsigned char do_get_bits(void);
51 #define DATA_PCI_OFF 0x7FFC00
54 #define DRIVER_NAME "lirc_bt829"
57 #define dprintk(fmt, args...) \
60 printk(KERN_DEBUG DRIVER_NAME ": "fmt, ## args); \
63 static int atir_minor
;
64 static unsigned long pci_addr_phys
;
65 static unsigned char *pci_addr_lin
;
67 static struct lirc_driver atir_driver
;
69 static struct pci_dev
*do_pci_probe(void)
71 struct pci_dev
*my_dev
;
72 my_dev
= pci_get_device(PCI_VENDOR_ID_ATI
,
73 PCI_DEVICE_ID_ATI_264VT
, NULL
);
75 printk(KERN_ERR DRIVER_NAME
": Using device: %s\n",
78 if (my_dev
->resource
[0].flags
& IORESOURCE_MEM
) {
79 pci_addr_phys
= my_dev
->resource
[0].start
;
80 printk(KERN_INFO DRIVER_NAME
": memory at 0x%08X\n",
81 (unsigned int)pci_addr_phys
);
83 if (pci_addr_phys
== 0) {
84 printk(KERN_ERR DRIVER_NAME
": no memory resource ?\n");
88 printk(KERN_ERR DRIVER_NAME
": pci_probe failed\n");
94 static int atir_add_to_buf(void *data
, struct lirc_buffer
*buf
)
99 key
= (status
>> 8) & 0xFF;
101 dprintk("reading key %02X\n", key
);
102 lirc_buffer_write(buf
, &key
);
108 static int atir_set_use_inc(void *data
)
110 dprintk("driver is opened\n");
114 static void atir_set_use_dec(void *data
)
116 dprintk("driver is closed\n");
119 int init_module(void)
121 struct pci_dev
*pdev
;
123 pdev
= do_pci_probe();
127 if (!atir_init_start())
130 strcpy(atir_driver
.name
, "ATIR");
131 atir_driver
.minor
= -1;
132 atir_driver
.code_length
= 8;
133 atir_driver
.sample_rate
= 10;
134 atir_driver
.data
= 0;
135 atir_driver
.add_to_buf
= atir_add_to_buf
;
136 atir_driver
.set_use_inc
= atir_set_use_inc
;
137 atir_driver
.set_use_dec
= atir_set_use_dec
;
138 atir_driver
.dev
= &pdev
->dev
;
139 atir_driver
.owner
= THIS_MODULE
;
141 atir_minor
= lirc_register_driver(&atir_driver
);
142 if (atir_minor
< 0) {
143 printk(KERN_ERR DRIVER_NAME
": failed to register driver!\n");
146 dprintk("driver is registered on minor %d\n", atir_minor
);
152 void cleanup_module(void)
154 lirc_unregister_driver(atir_minor
);
158 static int atir_init_start(void)
160 pci_addr_lin
= ioremap(pci_addr_phys
+ DATA_PCI_OFF
, 0x400);
161 if (pci_addr_lin
== 0) {
162 printk(KERN_INFO DRIVER_NAME
": pci mem must be mapped\n");
168 static void cycle_delay(int cycle
)
170 udelay(WAIT_CYCLE
*cycle
);
174 static int poll_main()
176 unsigned char status_high
, status_low
;
187 status_low
= seems_rd_byte();
188 status_high
= seems_rd_byte();
192 return (status_high
<< 8) | status_low
;
195 static void do_i2c_start(void)
207 static void do_i2c_stop(void)
210 bits
= do_get_bits() & 0xFD;
225 static void seems_wr_byte(unsigned char value
)
231 for (i
= 0; i
< 8; i
++) {
265 static unsigned char seems_rd_byte(void)
269 unsigned char bits_2
, bits_1
;
271 bits_1
= do_get_bits() | 2;
275 for (i
= 0; i
< 8; i
++) {
284 bits_2
= do_get_bits();
311 static void do_set_bits(unsigned char new_bits
)
314 reg_val
= read_index(0x34);
316 reg_val
&= 0xFFFFFFDF;
319 reg_val
&= 0xFFFFFFFE;
323 write_index(0x34, reg_val
);
325 reg_val
= read_index(0x31);
327 reg_val
|= 0x1000000;
329 reg_val
&= 0xFEFFFFFF;
331 reg_val
|= 0x8000000;
332 write_index(0x31, reg_val
);
335 static unsigned char do_get_bits(void)
340 reg_val
= read_index(0x34);
342 reg_val
&= 0xFFFFFFDF;
343 write_index(0x34, reg_val
);
345 reg_val
= read_index(0x34);
352 reg_val
= read_index(0x31);
353 if (reg_val
& 0x1000000)
361 static unsigned int read_index(unsigned char index
)
365 /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
366 addr
= pci_addr_lin
+ ((index
& 0xFF) << 2);
371 static void write_index(unsigned char index
, unsigned int reg_val
)
374 addr
= pci_addr_lin
+ ((index
& 0xFF) << 2);
375 writel(reg_val
, addr
);
378 MODULE_AUTHOR("Froenchenko Leonid");
379 MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
380 MODULE_LICENSE("GPL");
382 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
383 MODULE_PARM_DESC(debug
, "Debug enabled or not");