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"
60 static int atir_minor;
61 static phys_addr_t pci_addr_phys;
62 static unsigned char __iomem *pci_addr_lin;
64 static struct lirc_driver atir_driver;
66 static struct pci_dev *do_pci_probe(void)
68 struct pci_dev *my_dev;
70 my_dev = pci_get_device(PCI_VENDOR_ID_ATI,
71 PCI_DEVICE_ID_ATI_264VT, NULL);
73 pr_err("Using device: %s\n", pci_name(my_dev));
75 if (my_dev->resource[0].flags & IORESOURCE_MEM) {
76 pci_addr_phys = my_dev->resource[0].start;
77 pr_info("memory at %pa\n", &pci_addr_phys);
79 if (pci_addr_phys == 0) {
80 pr_err("no memory resource ?\n");
85 pr_err("pci_probe failed\n");
91 static int atir_add_to_buf(void *data, struct lirc_buffer *buf)
97 key = (status >> 8) & 0xFF;
99 dev_dbg(atir_driver.dev, "reading key %02X\n", key);
100 lirc_buffer_write(buf, &key);
106 static int atir_set_use_inc(void *data)
108 dev_dbg(atir_driver.dev, "driver is opened\n");
112 static void atir_set_use_dec(void *data)
114 dev_dbg(atir_driver.dev, "driver is closed\n");
117 int init_module(void)
119 struct pci_dev *pdev;
122 pdev = do_pci_probe();
126 rc = pci_enable_device(pdev);
130 if (!atir_init_start()) {
135 strcpy(atir_driver.name, "ATIR");
136 atir_driver.minor = -1;
137 atir_driver.code_length = 8;
138 atir_driver.sample_rate = 10;
139 atir_driver.data = NULL;
140 atir_driver.add_to_buf = atir_add_to_buf;
141 atir_driver.set_use_inc = atir_set_use_inc;
142 atir_driver.set_use_dec = atir_set_use_dec;
143 atir_driver.dev = &pdev->dev;
144 atir_driver.owner = THIS_MODULE;
146 atir_minor = lirc_register_driver(&atir_driver);
147 if (atir_minor < 0) {
148 pr_err("failed to register driver!\n");
152 dev_dbg(atir_driver.dev, "driver is registered on minor %d\n",
158 iounmap(pci_addr_lin);
160 pci_disable_device(pdev);
166 void cleanup_module(void)
168 struct pci_dev *pdev = to_pci_dev(atir_driver.dev);
170 lirc_unregister_driver(atir_minor);
171 iounmap(pci_addr_lin);
172 pci_disable_device(pdev);
176 static int atir_init_start(void)
178 pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400);
180 pr_info("pci mem must be mapped\n");
186 static void cycle_delay(int cycle)
188 udelay(WAIT_CYCLE * cycle);
191 static int poll_main(void)
193 unsigned char status_high, status_low;
204 status_low = seems_rd_byte();
205 status_high = seems_rd_byte();
209 return (status_high << 8) | status_low;
212 static void do_i2c_start(void)
224 static void do_i2c_stop(void)
228 bits = do_get_bits() & 0xFD;
243 static void seems_wr_byte(unsigned char value)
249 for (i = 0; i < 8; i++) {
283 static unsigned char seems_rd_byte(void)
287 unsigned char bits_2, bits_1;
289 bits_1 = do_get_bits() | 2;
293 for (i = 0; i < 8; i++) {
302 bits_2 = do_get_bits();
329 static void do_set_bits(unsigned char new_bits)
333 reg_val = read_index(0x34);
335 reg_val &= 0xFFFFFFDF;
338 reg_val &= 0xFFFFFFFE;
342 write_index(0x34, reg_val);
344 reg_val = read_index(0x31);
346 reg_val |= 0x1000000;
348 reg_val &= 0xFEFFFFFF;
350 reg_val |= 0x8000000;
351 write_index(0x31, reg_val);
354 static unsigned char do_get_bits(void)
359 reg_val = read_index(0x34);
361 reg_val &= 0xFFFFFFDF;
362 write_index(0x34, reg_val);
364 reg_val = read_index(0x34);
371 reg_val = read_index(0x31);
372 if (reg_val & 0x1000000)
380 static unsigned int read_index(unsigned char index)
382 unsigned char __iomem *addr;
383 /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
384 addr = pci_addr_lin + ((index & 0xFF) << 2);
388 static void write_index(unsigned char index, unsigned int reg_val)
390 unsigned char __iomem *addr;
392 addr = pci_addr_lin + ((index & 0xFF) << 2);
393 writel(reg_val, addr);
396 MODULE_AUTHOR("Froenchenko Leonid");
397 MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
398 MODULE_LICENSE("GPL");
400 module_param(debug, bool, S_IRUGO | S_IWUSR);
401 MODULE_PARM_DESC(debug, "Debug enabled or not");