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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/threads.h>
26 #include <linux/sched.h>
27 #include <linux/ioport.h>
28 #include <linux/pci.h>
29 #include <linux/delay.h>
31 #include <media/lirc_dev.h>
33 static int poll_main(void);
34 static int atir_init_start(void);
36 static void write_index(unsigned char index, unsigned int value);
37 static unsigned int read_index(unsigned char index);
39 static void do_i2c_start(void);
40 static void do_i2c_stop(void);
42 static void seems_wr_byte(unsigned char al);
43 static unsigned char seems_rd_byte(void);
45 static unsigned int read_index(unsigned char al);
46 static void write_index(unsigned char ah, unsigned int edx);
48 static void cycle_delay(int cycle);
50 static void do_set_bits(unsigned char bl);
51 static unsigned char do_get_bits(void);
53 #define DATA_PCI_OFF 0x7FFC00
56 #define DRIVER_NAME "lirc_bt829"
59 #define dprintk(fmt, args...) \
62 printk(KERN_DEBUG DRIVER_NAME ": "fmt, ## args); \
65 static int atir_minor;
66 static unsigned long pci_addr_phys;
67 static unsigned char *pci_addr_lin;
69 static struct lirc_driver atir_driver;
71 static struct pci_dev *do_pci_probe(void)
73 struct pci_dev *my_dev;
74 my_dev = pci_get_device(PCI_VENDOR_ID_ATI,
75 PCI_DEVICE_ID_ATI_264VT, NULL);
77 pr_err("Using device: %s\n", pci_name(my_dev));
79 if (my_dev->resource[0].flags & IORESOURCE_MEM) {
80 pci_addr_phys = my_dev->resource[0].start;
81 pr_info("memory at 0x%08X\n",
82 (unsigned int)pci_addr_phys);
84 if (pci_addr_phys == 0) {
85 pr_err("no memory resource ?\n");
89 pr_err("pci_probe failed\n");
95 static int atir_add_to_buf(void *data, struct lirc_buffer *buf)
100 key = (status >> 8) & 0xFF;
102 dprintk("reading key %02X\n", key);
103 lirc_buffer_write(buf, &key);
109 static int atir_set_use_inc(void *data)
111 dprintk("driver is opened\n");
115 static void atir_set_use_dec(void *data)
117 dprintk("driver is closed\n");
120 int init_module(void)
122 struct pci_dev *pdev;
124 pdev = do_pci_probe();
128 if (!atir_init_start())
131 strcpy(atir_driver.name, "ATIR");
132 atir_driver.minor = -1;
133 atir_driver.code_length = 8;
134 atir_driver.sample_rate = 10;
135 atir_driver.data = NULL;
136 atir_driver.add_to_buf = atir_add_to_buf;
137 atir_driver.set_use_inc = atir_set_use_inc;
138 atir_driver.set_use_dec = atir_set_use_dec;
139 atir_driver.dev = &pdev->dev;
140 atir_driver.owner = THIS_MODULE;
142 atir_minor = lirc_register_driver(&atir_driver);
143 if (atir_minor < 0) {
144 pr_err("failed to register driver!\n");
147 dprintk("driver is registered on minor %d\n", atir_minor);
153 void cleanup_module(void)
155 lirc_unregister_driver(atir_minor);
159 static int atir_init_start(void)
161 pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400);
163 pr_info("pci mem must be mapped\n");
169 static void cycle_delay(int cycle)
171 udelay(WAIT_CYCLE*cycle);
175 static int poll_main(void)
177 unsigned char status_high, status_low;
188 status_low = seems_rd_byte();
189 status_high = seems_rd_byte();
193 return (status_high << 8) | status_low;
196 static void do_i2c_start(void)
208 static void do_i2c_stop(void)
211 bits = do_get_bits() & 0xFD;
226 static void seems_wr_byte(unsigned char value)
232 for (i = 0; i < 8; i++) {
266 static unsigned char seems_rd_byte(void)
270 unsigned char bits_2, bits_1;
272 bits_1 = do_get_bits() | 2;
276 for (i = 0; i < 8; i++) {
285 bits_2 = do_get_bits();
312 static void do_set_bits(unsigned char new_bits)
315 reg_val = read_index(0x34);
317 reg_val &= 0xFFFFFFDF;
320 reg_val &= 0xFFFFFFFE;
324 write_index(0x34, reg_val);
326 reg_val = read_index(0x31);
328 reg_val |= 0x1000000;
330 reg_val &= 0xFEFFFFFF;
332 reg_val |= 0x8000000;
333 write_index(0x31, reg_val);
336 static unsigned char do_get_bits(void)
341 reg_val = read_index(0x34);
343 reg_val &= 0xFFFFFFDF;
344 write_index(0x34, reg_val);
346 reg_val = read_index(0x34);
353 reg_val = read_index(0x31);
354 if (reg_val & 0x1000000)
362 static unsigned int read_index(unsigned char index)
366 /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
367 addr = pci_addr_lin + ((index & 0xFF) << 2);
372 static void write_index(unsigned char index, unsigned int reg_val)
375 addr = pci_addr_lin + ((index & 0xFF) << 2);
376 writel(reg_val, addr);
379 MODULE_AUTHOR("Froenchenko Leonid");
380 MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
381 MODULE_LICENSE("GPL");
383 module_param(debug, bool, S_IRUGO | S_IWUSR);
384 MODULE_PARM_DESC(debug, "Debug enabled or not");