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/version.h>
22 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
23 #error "This driver needs kernel version 2.4.0 or higher"
26 #include <linux/autoconf.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/threads.h>
30 #include <linux/sched.h>
31 #include <linux/ioport.h>
32 #include <linux/pci.h>
33 #include <linux/delay.h>
35 #include "drivers/kcompat.h"
36 #include "drivers/lirc_dev/lirc_dev.h"
38 static int poll_main(void);
39 static int atir_init_start(void);
41 static void write_index(unsigned char index
, unsigned int value
);
42 static unsigned int read_index(unsigned char index
);
44 static void do_i2c_start(void);
45 static void do_i2c_stop(void);
47 static void seems_wr_byte(unsigned char al
);
48 static unsigned char seems_rd_byte(void);
50 static unsigned int read_index(unsigned char al
);
51 static void write_index(unsigned char ah
, unsigned int edx
);
53 static void cycle_delay(int cycle
);
55 static void do_set_bits(unsigned char bl
);
56 static unsigned char do_get_bits(void);
58 #define DATA_PCI_OFF 0x7FFC00
62 #define dprintk(fmt, args...) \
65 printk(KERN_DEBUG fmt, ## args); \
68 static int atir_minor
;
69 static unsigned long pci_addr_phys
;
70 static unsigned char *pci_addr_lin
;
72 static struct lirc_plugin atir_plugin
;
74 static struct pci_dev
*do_pci_probe(void)
76 struct pci_dev
*my_dev
;
78 /* unnecessary with recent kernels */
80 printk(KERN_ERR
"ATIR: no pci in this kernel\n");
82 my_dev
= pci_get_device(PCI_VENDOR_ID_ATI
,
83 PCI_DEVICE_ID_ATI_264VT
, NULL
);
85 printk(KERN_ERR
"ATIR: Using device: %s\n",
88 if (my_dev
->resource
[0].flags
& IORESOURCE_MEM
) {
89 pci_addr_phys
= my_dev
->resource
[0].start
;
90 printk(KERN_INFO
"ATIR memory at 0x%08X \n",
91 (unsigned int)pci_addr_phys
);
93 if (pci_addr_phys
== 0) {
94 printk(KERN_ERR
"ATIR no memory resource ?\n");
98 printk(KERN_ERR
"ATIR: pci_prob failed\n");
104 static int atir_add_to_buf(void *data
, struct lirc_buffer
*buf
)
108 status
= poll_main();
109 key
= (status
>> 8) & 0xFF;
111 dprintk("ATIR reading key %02X\n", key
);
112 lirc_buffer_write_1(buf
, &key
);
118 static int atir_set_use_inc(void *data
)
121 dprintk("ATIR driver is opened\n");
125 static void atir_set_use_dec(void *data
)
128 dprintk("ATIR driver is closed\n");
131 int init_module(void)
133 struct pci_dev
*pdev
;
135 pdev
= do_pci_probe();
139 if (!atir_init_start())
142 strcpy(atir_plugin
.name
, "ATIR");
143 atir_plugin
.minor
= -1;
144 atir_plugin
.code_length
= 8;
145 atir_plugin
.sample_rate
= 10;
146 atir_plugin
.data
= 0;
147 atir_plugin
.add_to_buf
= atir_add_to_buf
;
148 atir_plugin
.set_use_inc
= atir_set_use_inc
;
149 atir_plugin
.set_use_dec
= atir_set_use_dec
;
150 #ifdef LIRC_HAVE_SYSFS
151 atir_plugin
.dev
= &pdev
->dev
;
153 atir_plugin
.owner
= THIS_MODULE
;
155 atir_minor
= lirc_register_plugin(&atir_plugin
);
156 dprintk("ATIR driver is registered on minor %d\n", atir_minor
);
162 void cleanup_module(void)
164 lirc_unregister_plugin(atir_minor
);
168 static int atir_init_start(void)
170 pci_addr_lin
= ioremap(pci_addr_phys
+ DATA_PCI_OFF
, 0x400);
171 if (pci_addr_lin
== 0) {
172 printk(KERN_INFO
"atir: pci mem must be mapped\n");
178 static void cycle_delay(int cycle
)
180 udelay(WAIT_CYCLE
*cycle
);
184 static int poll_main()
186 unsigned char status_high
, status_low
;
197 status_low
= seems_rd_byte();
198 status_high
= seems_rd_byte();
202 return (status_high
<< 8) | status_low
;
205 static void do_i2c_start(void)
217 static void do_i2c_stop(void)
220 bits
= do_get_bits() & 0xFD;
235 static void seems_wr_byte(unsigned char value
)
241 for (i
= 0; i
< 8; i
++) {
275 static unsigned char seems_rd_byte(void)
279 unsigned char bits_2
, bits_1
;
281 bits_1
= do_get_bits() | 2;
285 for (i
= 0; i
< 8; i
++) {
294 bits_2
= do_get_bits();
321 static void do_set_bits(unsigned char new_bits
)
324 reg_val
= read_index(0x34);
326 reg_val
&= 0xFFFFFFDF;
329 reg_val
&= 0xFFFFFFFE;
333 write_index(0x34, reg_val
);
335 reg_val
= read_index(0x31);
337 reg_val
|= 0x1000000;
339 reg_val
&= 0xFEFFFFFF;
341 reg_val
|= 0x8000000;
342 write_index(0x31, reg_val
);
345 static unsigned char do_get_bits(void)
350 reg_val
= read_index(0x34);
352 reg_val
&= 0xFFFFFFDF;
353 write_index(0x34, reg_val
);
355 reg_val
= read_index(0x34);
362 reg_val
= read_index(0x31);
363 if (reg_val
& 0x1000000) {
371 static unsigned int read_index(unsigned char index
)
375 /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
376 addr
= pci_addr_lin
+ ((index
& 0xFF) << 2);
381 static void write_index(unsigned char index
, unsigned int reg_val
)
384 addr
= pci_addr_lin
+ ((index
& 0xFF) << 2);
385 writel(reg_val
, addr
);
388 MODULE_AUTHOR("Froenchenko Leonid");
389 MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
390 MODULE_LICENSE("GPL");
392 module_param(debug
, bool, 0644);
393 MODULE_PARM_DESC(debug
, "Debug enabled or not");
398 * Overrides for Emacs so that we follow Linus's tabbing style.
399 * ---------------------------------------------------------------------------