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 phys_addr_t 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 %pa\n", &pci_addr_phys);
83 if (pci_addr_phys == 0) {
84 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;
125 pdev = do_pci_probe();
129 rc = pci_enable_device(pdev);
133 if (!atir_init_start()) {
138 strcpy(atir_driver.name, "ATIR");
139 atir_driver.minor = -1;
140 atir_driver.code_length = 8;
141 atir_driver.sample_rate = 10;
142 atir_driver.data = NULL;
143 atir_driver.add_to_buf = atir_add_to_buf;
144 atir_driver.set_use_inc = atir_set_use_inc;
145 atir_driver.set_use_dec = atir_set_use_dec;
146 atir_driver.dev = &pdev->dev;
147 atir_driver.owner = THIS_MODULE;
149 atir_minor = lirc_register_driver(&atir_driver);
150 if (atir_minor < 0) {
151 pr_err("failed to register driver!\n");
155 dprintk("driver is registered on minor %d\n", atir_minor);
160 iounmap(pci_addr_lin);
162 pci_disable_device(pdev);
169 void cleanup_module(void)
171 struct pci_dev *pdev = to_pci_dev(atir_driver.dev);
173 lirc_unregister_driver(atir_minor);
174 iounmap(pci_addr_lin);
175 pci_disable_device(pdev);
180 static int atir_init_start(void)
182 pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400);
184 pr_info("pci mem must be mapped\n");
190 static void cycle_delay(int cycle)
192 udelay(WAIT_CYCLE*cycle);
196 static int poll_main(void)
198 unsigned char status_high, status_low;
209 status_low = seems_rd_byte();
210 status_high = seems_rd_byte();
214 return (status_high << 8) | status_low;
217 static void do_i2c_start(void)
229 static void do_i2c_stop(void)
232 bits = do_get_bits() & 0xFD;
247 static void seems_wr_byte(unsigned char value)
253 for (i = 0; i < 8; i++) {
287 static unsigned char seems_rd_byte(void)
291 unsigned char bits_2, bits_1;
293 bits_1 = do_get_bits() | 2;
297 for (i = 0; i < 8; i++) {
306 bits_2 = do_get_bits();
333 static void do_set_bits(unsigned char new_bits)
336 reg_val = read_index(0x34);
338 reg_val &= 0xFFFFFFDF;
341 reg_val &= 0xFFFFFFFE;
345 write_index(0x34, reg_val);
347 reg_val = read_index(0x31);
349 reg_val |= 0x1000000;
351 reg_val &= 0xFEFFFFFF;
353 reg_val |= 0x8000000;
354 write_index(0x31, reg_val);
357 static unsigned char do_get_bits(void)
362 reg_val = read_index(0x34);
364 reg_val &= 0xFFFFFFDF;
365 write_index(0x34, reg_val);
367 reg_val = read_index(0x34);
374 reg_val = read_index(0x31);
375 if (reg_val & 0x1000000)
383 static unsigned int read_index(unsigned char index)
387 /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
388 addr = pci_addr_lin + ((index & 0xFF) << 2);
393 static void write_index(unsigned char index, unsigned int reg_val)
396 addr = pci_addr_lin + ((index & 0xFF) << 2);
397 writel(reg_val, addr);
400 MODULE_AUTHOR("Froenchenko Leonid");
401 MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
402 MODULE_LICENSE("GPL");
404 module_param(debug, bool, S_IRUGO | S_IWUSR);
405 MODULE_PARM_DESC(debug, "Debug enabled or not");