From: Jarod Wilson <jwilson@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jarod Wilson <jwilson@redhat.com>,
Jarod Wilson <jarod@redhat.com>, Janne Grunau <j@jannau.net>,
Christoph Bartelmus <lirc@bartelmus.de>
Subject: [PATCH 16/18] lirc driver for the IR interface on BT829-based hardware
Date: Tue, 9 Sep 2008 00:06:01 -0400 [thread overview]
Message-ID: <1220933164-10160-17-git-send-email-jwilson@redhat.com> (raw)
In-Reply-To: <1220933164-10160-16-git-send-email-jwilson@redhat.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Janne Grunau <j@jannau.net>
CC: Christoph Bartelmus <lirc@bartelmus.de>
---
drivers/input/lirc/Kconfig | 7 +
drivers/input/lirc/Makefile | 1 +
drivers/input/lirc/lirc_bt829.c | 388 +++++++++++++++++++++++++++++++++++++++
3 files changed, 396 insertions(+), 0 deletions(-)
create mode 100644 drivers/input/lirc/lirc_bt829.c
diff --git a/drivers/input/lirc/Kconfig b/drivers/input/lirc/Kconfig
index b2bdbfb..2af6278 100644
--- a/drivers/input/lirc/Kconfig
+++ b/drivers/input/lirc/Kconfig
@@ -25,6 +25,13 @@ config LIRC_ATIUSB
help
Driver for the ATI USB RF remote receiver
+config LIRC_BT829
+ tristate "BT829 based hardware"
+ default n
+ depends on LIRC_DEV
+ help
+ Driver for the IR interface on BT829-based hardware
+
config LIRC_CMDIR
tristate "CommandIR USB Transceiver"
default n
diff --git a/drivers/input/lirc/Makefile b/drivers/input/lirc/Makefile
index 761cb47..c5f71fa 100644
--- a/drivers/input/lirc/Makefile
+++ b/drivers/input/lirc/Makefile
@@ -7,6 +7,7 @@ EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)
obj-$(CONFIG_LIRC_DEV) += lirc_dev.o
obj-$(CONFIG_LIRC_ATIUSB) += lirc_atiusb.o
+obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
obj-$(CONFIG_LIRC_CMDIR) += lirc_cmdir.o
obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o
obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
diff --git a/drivers/input/lirc/lirc_bt829.c b/drivers/input/lirc/lirc_bt829.c
new file mode 100644
index 0000000..01cbdfe
--- /dev/null
+++ b/drivers/input/lirc/lirc_bt829.c
@@ -0,0 +1,388 @@
+/*
+ * Remote control driver for the TV-card based on bt829
+ *
+ * by Leonid Froenchenko <lfroen@galileo.co.il>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <linux/version.h>
+
+#include <linux/autoconf.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/threads.h>
+#include <linux/sched.h>
+#include <linux/ioport.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+
+#include "lirc_dev.h"
+
+static int poll_main(void);
+static int atir_init_start(void);
+
+static void write_index(unsigned char index, unsigned int value);
+static unsigned int read_index(unsigned char index);
+
+static void do_i2c_start(void);
+static void do_i2c_stop(void);
+
+static void seems_wr_byte(unsigned char al);
+static unsigned char seems_rd_byte(void);
+
+static unsigned int read_index(unsigned char al);
+static void write_index(unsigned char ah, unsigned int edx);
+
+static void cycle_delay(int cycle);
+
+static void do_set_bits(unsigned char bl);
+static unsigned char do_get_bits(void);
+
+#define DATA_PCI_OFF 0x7FFC00
+#define WAIT_CYCLE 20
+
+static int debug;
+#define dprintk(fmt, args...) \
+ do { \
+ if (debug) \
+ printk(KERN_DEBUG fmt, ## args); \
+ } while (0)
+
+static int atir_minor;
+static unsigned long pci_addr_phys;
+static unsigned char *pci_addr_lin;
+
+static struct lirc_plugin atir_plugin;
+
+static struct pci_dev *do_pci_probe(void)
+{
+ struct pci_dev *my_dev;
+ my_dev = pci_get_device(PCI_VENDOR_ID_ATI,
+ PCI_DEVICE_ID_ATI_264VT, NULL);
+ if (my_dev) {
+ printk(KERN_ERR "ATIR: Using device: %s\n",
+ pci_name(my_dev));
+ pci_addr_phys = 0;
+ if (my_dev->resource[0].flags & IORESOURCE_MEM) {
+ pci_addr_phys = my_dev->resource[0].start;
+ printk(KERN_INFO "ATIR memory at 0x%08X \n",
+ (unsigned int)pci_addr_phys);
+ }
+ if (pci_addr_phys == 0) {
+ printk(KERN_ERR "ATIR no memory resource ?\n");
+ return NULL;
+ }
+ } else {
+ printk(KERN_ERR "ATIR: pci_prob failed\n");
+ return NULL;
+ }
+ return my_dev;
+}
+
+static int atir_add_to_buf(void *data, struct lirc_buffer *buf)
+{
+ unsigned char key;
+ int status;
+ status = poll_main();
+ key = (status >> 8) & 0xFF;
+ if (status & 0xFF) {
+ dprintk("ATIR reading key %02X\n", key);
+ lirc_buffer_write_1(buf, &key);
+ return 0;
+ }
+ return -ENODATA;
+}
+
+static int atir_set_use_inc(void *data)
+{
+ dprintk("ATIR driver is opened\n");
+ return 0;
+}
+
+static void atir_set_use_dec(void *data)
+{
+ dprintk("ATIR driver is closed\n");
+}
+
+int init_module(void)
+{
+ struct pci_dev *pdev;
+
+ pdev = do_pci_probe();
+ if (pdev == NULL)
+ return 1;
+
+ if (!atir_init_start())
+ return 1;
+
+ strcpy(atir_plugin.name, "ATIR");
+ atir_plugin.minor = -1;
+ atir_plugin.code_length = 8;
+ atir_plugin.sample_rate = 10;
+ atir_plugin.data = 0;
+ atir_plugin.add_to_buf = atir_add_to_buf;
+ atir_plugin.set_use_inc = atir_set_use_inc;
+ atir_plugin.set_use_dec = atir_set_use_dec;
+ atir_plugin.dev = &pdev->dev;
+ atir_plugin.owner = THIS_MODULE;
+
+ atir_minor = lirc_register_plugin(&atir_plugin);
+ dprintk("ATIR driver is registered on minor %d\n", atir_minor);
+
+ return 0;
+}
+
+
+void cleanup_module(void)
+{
+ lirc_unregister_plugin(atir_minor);
+}
+
+
+static int atir_init_start(void)
+{
+ pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400);
+ if (pci_addr_lin == 0) {
+ printk(KERN_INFO "atir: pci mem must be mapped\n");
+ return 0;
+ }
+ return 1;
+}
+
+static void cycle_delay(int cycle)
+{
+ udelay(WAIT_CYCLE*cycle);
+}
+
+
+static int poll_main()
+{
+ unsigned char status_high, status_low;
+
+ do_i2c_start();
+
+ seems_wr_byte(0xAA);
+ seems_wr_byte(0x01);
+
+ do_i2c_start();
+
+ seems_wr_byte(0xAB);
+
+ status_low = seems_rd_byte();
+ status_high = seems_rd_byte();
+
+ do_i2c_stop();
+
+ return (status_high << 8) | status_low;
+}
+
+static void do_i2c_start(void)
+{
+ do_set_bits(3);
+ cycle_delay(4);
+
+ do_set_bits(1);
+ cycle_delay(7);
+
+ do_set_bits(0);
+ cycle_delay(2);
+}
+
+static void do_i2c_stop(void)
+{
+ unsigned char bits;
+ bits = do_get_bits() & 0xFD;
+ do_set_bits(bits);
+ cycle_delay(1);
+
+ bits |= 1;
+ do_set_bits(bits);
+ cycle_delay(2);
+
+ bits |= 2;
+ do_set_bits(bits);
+ bits = 3;
+ do_set_bits(bits);
+ cycle_delay(2);
+}
+
+static void seems_wr_byte(unsigned char value)
+{
+ int i;
+ unsigned char reg;
+
+ reg = do_get_bits();
+ for (i = 0; i < 8; i++) {
+ if (value & 0x80)
+ reg |= 0x02;
+ else
+ reg &= 0xFD;
+
+ do_set_bits(reg);
+ cycle_delay(1);
+
+ reg |= 1;
+ do_set_bits(reg);
+ cycle_delay(1);
+
+ reg &= 0xFE;
+ do_set_bits(reg);
+ cycle_delay(1);
+ value <<= 1;
+ }
+ cycle_delay(2);
+
+ reg |= 2;
+ do_set_bits(reg);
+
+ reg |= 1;
+ do_set_bits(reg);
+
+ cycle_delay(1);
+ do_get_bits();
+
+ reg &= 0xFE;
+ do_set_bits(reg);
+ cycle_delay(3);
+}
+
+static unsigned char seems_rd_byte(void)
+{
+ int i;
+ int rd_byte;
+ unsigned char bits_2, bits_1;
+
+ bits_1 = do_get_bits() | 2;
+ do_set_bits(bits_1);
+
+ rd_byte = 0;
+ for (i = 0; i < 8; i++) {
+ bits_1 &= 0xFE;
+ do_set_bits(bits_1);
+ cycle_delay(2);
+
+ bits_1 |= 1;
+ do_set_bits(bits_1);
+ cycle_delay(1);
+
+ bits_2 = do_get_bits();
+ if (bits_2 & 2)
+ rd_byte |= 1;
+
+ rd_byte <<= 1;
+ }
+
+ bits_1 = 0;
+ if (bits_2 == 0)
+ bits_1 |= 2;
+
+ do_set_bits(bits_1);
+ cycle_delay(2);
+
+ bits_1 |= 1;
+ do_set_bits(bits_1);
+ cycle_delay(3);
+
+ bits_1 &= 0xFE;
+ do_set_bits(bits_1);
+ cycle_delay(2);
+
+ rd_byte >>= 1;
+ rd_byte &= 0xFF;
+ return rd_byte;
+}
+
+static void do_set_bits(unsigned char new_bits)
+{
+ int reg_val;
+ reg_val = read_index(0x34);
+ if (new_bits & 2) {
+ reg_val &= 0xFFFFFFDF;
+ reg_val |= 1;
+ } else {
+ reg_val &= 0xFFFFFFFE;
+ reg_val |= 0x20;
+ }
+ reg_val |= 0x10;
+ write_index(0x34, reg_val);
+
+ reg_val = read_index(0x31);
+ if (new_bits & 1)
+ reg_val |= 0x1000000;
+ else
+ reg_val &= 0xFEFFFFFF;
+
+ reg_val |= 0x8000000;
+ write_index(0x31, reg_val);
+}
+
+static unsigned char do_get_bits(void)
+{
+ unsigned char bits;
+ int reg_val;
+
+ reg_val = read_index(0x34);
+ reg_val |= 0x10;
+ reg_val &= 0xFFFFFFDF;
+ write_index(0x34, reg_val);
+
+ reg_val = read_index(0x34);
+ bits = 0;
+ if (reg_val & 8)
+ bits |= 2;
+ else
+ bits &= 0xFD;
+
+ reg_val = read_index(0x31);
+ if (reg_val & 0x1000000)
+ bits |= 1;
+ else
+ bits &= 0xFE;
+
+ return bits;
+}
+
+static unsigned int read_index(unsigned char index)
+{
+ unsigned char *addr;
+ unsigned int value;
+ /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
+ addr = pci_addr_lin + ((index & 0xFF) << 2);
+ value = readl(addr);
+ return value;
+}
+
+static void write_index(unsigned char index, unsigned int reg_val)
+{
+ unsigned char *addr;
+ addr = pci_addr_lin + ((index & 0xFF) << 2);
+ writel(reg_val, addr);
+}
+
+MODULE_AUTHOR("Froenchenko Leonid");
+MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
+MODULE_LICENSE("GPL");
+
+module_param(debug, bool, 0644);
+MODULE_PARM_DESC(debug, "Debug enabled or not");
+
+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
--
1.6.0.1
next prev parent reply other threads:[~2008-09-09 4:13 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-09 4:05 [PATCH 0/18] linux infrared remote control drivers Jarod Wilson
2008-09-09 4:05 ` [PATCH 01/18] lirc core device driver infrastructure Jarod Wilson
2008-09-09 4:05 ` [PATCH 02/18] lirc serial port receiver/transmitter device driver Jarod Wilson
2008-09-09 4:05 ` [PATCH 03/18] lirc driver for 1st-gen Media Center Ed. USB IR transceivers Jarod Wilson
2008-09-09 4:05 ` [PATCH 04/18] lirc driver for 2nd-gen and later " Jarod Wilson
2008-09-09 4:05 ` [PATCH 05/18] lirc driver for i2c-based IR receivers Jarod Wilson
2008-09-09 4:05 ` [PATCH 06/18] lirc driver for the ATI USB RF remote receiver Jarod Wilson
2008-09-09 4:05 ` [PATCH 07/18] lirc driver for the CommandIR USB Transceiver Jarod Wilson
2008-09-09 4:05 ` [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers Jarod Wilson
2008-09-09 4:05 ` [PATCH 09/18] lirc driver for the Streamzap PC Receiver Jarod Wilson
2008-09-09 4:05 ` [PATCH 10/18] lirc driver for Igor Cesko's USB IR receiver Jarod Wilson
2008-09-09 4:05 ` [PATCH 11/18] lirc driver for the Technotrend " Jarod Wilson
2008-09-09 4:05 ` [PATCH 12/18] lirc driver for the Sasem OnAir and Dign HV5 receivers Jarod Wilson
2008-09-09 4:05 ` [PATCH 13/18] lirc driver for ITE8709 CIR port receiver Jarod Wilson
2008-09-09 4:05 ` [PATCH 14/18] lirc driver for the ITE IT87xx CIR Port receivers Jarod Wilson
2008-09-09 4:06 ` [PATCH 15/18] lirc driver for the SIR IrDA port Jarod Wilson
2008-09-09 4:06 ` Jarod Wilson [this message]
2008-09-09 4:06 ` [PATCH 17/18] lirc driver for homebrew parallel port receivers Jarod Wilson
2008-09-09 4:06 ` [PATCH 18/18] lirc driver for the zilog/haupauge IR transceiver Jarod Wilson
2008-09-09 4:06 ` Jarod Wilson
2008-09-11 15:22 ` [PATCH 09/18] lirc driver for the Streamzap PC Receiver Jonathan Corbet
2008-09-10 21:02 ` [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers Jonathan Corbet
2008-09-10 21:23 ` Janne Grunau
2008-09-11 3:22 ` Jarod Wilson
2008-09-22 21:47 ` Jarod Wilson
2008-09-24 20:21 ` Jarod Wilson
2008-09-10 17:09 ` [PATCH 07/18] lirc driver for the CommandIR USB Transceiver Jonathan Corbet
2008-09-11 18:24 ` Christoph Bartelmus
[not found] ` <1221159005.13683.34.camel@minimatt>
2008-09-11 19:03 ` Jarod Wilson
2008-09-11 19:14 ` Janne Grunau
2008-09-25 15:21 ` Jarod Wilson
2008-09-10 9:58 ` [PATCH 06/18] lirc driver for the ATI USB RF remote receiver Ville Syrjälä
2008-09-10 13:05 ` Jarod Wilson
2008-09-10 13:14 ` Christoph Hellwig
2008-09-10 13:37 ` Jon Smirl
2008-09-10 14:30 ` Dmitry Torokhov
2008-09-10 13:44 ` Janne Grunau
2008-09-10 14:13 ` Jarod Wilson
2008-09-10 14:19 ` Christoph Hellwig
2008-09-10 14:08 ` Ville Syrjälä
2008-09-10 14:37 ` Dmitry Torokhov
2008-09-09 4:13 ` [PATCH 05/18] lirc driver for i2c-based IR receivers Jarod Wilson
2008-09-10 15:42 ` Jonathan Corbet
2008-09-09 23:30 ` [PATCH 04/18] lirc driver for 2nd-gen and later Media Center Ed. USB IR transceivers Jonathan Corbet
2008-09-10 0:36 ` Janne Grunau
2008-09-11 9:21 ` Adrian Bunk
2008-09-09 19:21 ` [PATCH 03/18] lirc driver for 1st-gen " Jonathan Corbet
2008-09-09 23:59 ` Janne Grunau
2008-09-10 1:39 ` Jarod Wilson
2008-09-10 0:04 ` Janne Grunau
2008-09-09 16:14 ` [PATCH 02/18] lirc serial port receiver/transmitter device driver Jonathan Corbet
2008-09-09 19:51 ` Stefan Lippers-Hollmann
2008-09-09 19:56 ` Jarod Wilson
2008-09-10 17:40 ` Jarod Wilson
2008-09-09 7:40 ` [PATCH 01/18] lirc core device driver infrastructure Sebastian Siewior
2008-09-09 9:53 ` Janne Grunau
2008-09-09 12:33 ` Sebastian Siewior
2008-09-09 13:10 ` Janne Grunau
2008-09-11 16:41 ` Christoph Bartelmus
2008-09-09 11:13 ` Alan Cox
2008-09-09 13:27 ` Stefan Richter
2008-09-09 17:03 ` Jarod Wilson
2008-09-11 18:30 ` Christoph Bartelmus
2008-09-11 19:09 ` Jarod Wilson
2008-09-13 7:21 ` Christoph Bartelmus
2008-09-09 9:46 ` Andi Kleen
2008-09-09 11:35 ` Janne Grunau
2008-09-09 13:03 ` Andi Kleen
2008-09-09 13:20 ` Janne Grunau
2008-09-12 16:46 ` Greg KH
2008-09-09 13:01 ` Christoph Hellwig
2008-09-10 12:24 ` Janne Grunau
2008-09-10 12:29 ` Christoph Hellwig
2008-09-10 12:45 ` Janne Grunau
2008-09-11 18:03 ` Christoph Bartelmus
2008-09-11 19:18 ` Janne Grunau
2008-09-12 0:16 ` Janne Grunau
2008-09-12 8:33 ` Christoph Hellwig
2008-09-12 14:51 ` Jarod Wilson
2008-09-09 15:33 ` Jonathan Corbet
2008-09-12 0:12 ` Janne Grunau
2008-09-10 13:08 ` Dmitry Torokhov
2008-09-11 8:47 ` Gerd Hoffmann
2008-09-11 21:28 ` Maxim Levitsky
2008-09-13 7:20 ` Christoph Bartelmus
2008-09-12 4:44 ` Dmitry Torokhov
2008-09-09 4:36 ` [PATCH 0/18] linux infrared remote control drivers Chris Wedgwood
2008-09-09 7:06 ` Alexey Dobriyan
2008-09-09 8:32 ` Janne Grunau
2008-09-09 12:46 ` Christoph Hellwig
2008-09-09 15:23 ` Jarod Wilson
2008-09-09 18:27 ` Lennart Sorensen
2008-09-09 18:34 ` Jarod Wilson
2008-09-09 15:34 ` Jon Smirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1220933164-10160-17-git-send-email-jwilson@redhat.com \
--to=jwilson@redhat.com \
--cc=j@jannau.net \
--cc=jarod@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lirc@bartelmus.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome