Skip to contentSkip to conversation

linux infrared remote control drivers

PATCH In review Jarod Wilson 21 participants 94 messages Sep 9, 2008 – Sep 25, 2008 1 message not in the archive Input drivers

lore
Share & tools
lore
#0 lore raw

cover linux infrared remote control drivers

The following patch series adds 17 new drivers for assorted infrared and/or RF remote control receivers and/or transmitters. These drivers have long lived out-of-tree at http://www.lirc.org/, packaged as 3rd-party modules by many distributions, and more recently, patched into the kernels of at least Fedora and Ubuntu. The primary maintainer of lirc, Christoph Bartelmus simply hasn't had the time to send these bits upstream, and a few months back, gave me the go-ahead to take on the task.

Most drivers are fairly widely tested, certainly within the MythTV community, which relies upon this code quite a bit. However, note that in preparation for this submission, a fair number of code changes have been made only recently that may or may not have yet made it back into lirc cvs, and thus might not be as widely tested. Any bugs found were probably introduced by either myself or Janne Grunau, the primary folks working on the latest round of whacking checkpatch.pl complaints to prepare for this submission.

Speaking of checkpatch... When I first added the lirc driver patch to the Fedora kernels (oy, way back in August of 2007), there were tens of thousands of lines of checkpatch warnings and errors. Through the efforts of myself, Janne, Eric Sandeen, and misc contributions from others, I'm now quite tickled to see the following:

--

$ scripts/checkpatch.pl /data/patches/lirc-for-upstream-combined.patch
total: 0 errors, 0 warnings, 17877 lines checked

/data/patches/lirc-for-upstream-combined.patch has no obvious style problems and is ready for submission.
--

Earlier rounds of checkpatch cleanups have already been fed back into lirc cvs, and Christoph has given me commit access there, so as to filter the latest changes back in as well. For the time being, lirc cvs will continue to be the canonical upstream for the lirc drivers, and all the earlier kernel compat bits get stripped out via an export script[1], though the script is still under a bit of development... I'll be taking point on maintaining the git tree[2] and synchronizing changes back and forth with cvs, at least until such time as everything is in the kernel, and nobody has need for out-of-tree drivers anymore, at which time the drivers will be dropped from the main lirc tarball.

Not all drivers have been tested with this codebase and certainly not all devices they support, but its a solid place to start with these in-kernel. Patches are against 2.6.27-rc5-git9 or so, and have been tested running the same, at least in the cases where hardware was available. These patches are also in the latest nightly Fedora rawhide kernel, for those who want instant gratification[3]. Note that you also need the lirc userspace to really do any meaningful testing...

CC Christoph Bartelmus <[email protected]>
CC Eric Sandeen <[email protected]>
CC Mario Limonciello <[email protected]>

[1] http://people.redhat.com/jwilson/lirc/, in a tarball atm
[2] http://git.wilsonet.com/linux-2.6-lirc.git/ (s/http/git/ to clone)
[3] http://kojipkgs.fedoraproject.org/packages/kernel/2.6.27/0.314.rc5.git9.fc10/
is the latest build, at least as of this submission

Combined diffstat:

 MAINTAINERS                           |    9 +
 drivers/input/Kconfig                 |    2 +
 drivers/input/Makefile                |    2 +
 drivers/input/lirc/Kconfig            |  142 ++++
 drivers/input/lirc/Makefile           |   25 +
 drivers/input/lirc/commandir.c        |  982 +++++++++++++++++++++++
 drivers/input/lirc/commandir.h        |   68 ++
 drivers/input/lirc/lirc.h             |  103 +++
 drivers/input/lirc/lirc_atiusb.c      | 1321 +++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_bt829.c       |  388 +++++++++
 drivers/input/lirc/lirc_cmdir.c       |  596 ++++++++++++++
 drivers/input/lirc/lirc_cmdir.h       |   25 +
 drivers/input/lirc/lirc_dev.c         |  809 +++++++++++++++++++
 drivers/input/lirc/lirc_dev.h         |  262 ++++++
 drivers/input/lirc/lirc_i2c.c         |  639 +++++++++++++++
 drivers/input/lirc/lirc_igorplugusb.c |  619 +++++++++++++++
 drivers/input/lirc/lirc_imon.c        | 1280 ++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_it87.c        |  999 +++++++++++++++++++++++
 drivers/input/lirc/lirc_it87.h        |  116 +++
 drivers/input/lirc/lirc_ite8709.c     |  545 +++++++++++++
 drivers/input/lirc/lirc_mceusb.c      |  890 +++++++++++++++++++++
 drivers/input/lirc/lirc_mceusb2.c     | 1119 ++++++++++++++++++++++++++
 drivers/input/lirc/lirc_parallel.c    |  728 +++++++++++++++++
 drivers/input/lirc/lirc_parallel.h    |   26 +
 drivers/input/lirc/lirc_sasem.c       |  969 +++++++++++++++++++++++
 drivers/input/lirc/lirc_serial.c      | 1312 +++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_sir.c         | 1302 ++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_streamzap.c   |  795 +++++++++++++++++++
 drivers/input/lirc/lirc_ttusbir.c     |  400 ++++++++++
 drivers/input/lirc/lirc_zilog.c       | 1395 +++++++++++++++++++++++++++++++++
 30 files changed, 17868 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/Kconfig
 create mode 100644 drivers/input/lirc/Makefile
 create mode 100644 drivers/input/lirc/commandir.c
 create mode 100644 drivers/input/lirc/commandir.h
 create mode 100644 drivers/input/lirc/lirc.h
 create mode 100644 drivers/input/lirc/lirc_atiusb.c
 create mode 100644 drivers/input/lirc/lirc_bt829.c
 create mode 100644 drivers/input/lirc/lirc_cmdir.c
 create mode 100644 drivers/input/lirc/lirc_cmdir.h
 create mode 100644 drivers/input/lirc/lirc_dev.c
 create mode 100644 drivers/input/lirc/lirc_dev.h
 create mode 100644 drivers/input/lirc/lirc_i2c.c
 create mode 100644 drivers/input/lirc/lirc_igorplugusb.c
 create mode 100644 drivers/input/lirc/lirc_imon.c
 create mode 100644 drivers/input/lirc/lirc_it87.c
 create mode 100644 drivers/input/lirc/lirc_it87.h
 create mode 100644 drivers/input/lirc/lirc_ite8709.c
 create mode 100644 drivers/input/lirc/lirc_mceusb.c
 create mode 100644 drivers/input/lirc/lirc_mceusb2.c
 create mode 100644 drivers/input/lirc/lirc_parallel.c
 create mode 100644 drivers/input/lirc/lirc_parallel.h
 create mode 100644 drivers/input/lirc/lirc_sasem.c
 create mode 100644 drivers/input/lirc/lirc_serial.c
 create mode 100644 drivers/input/lirc/lirc_sir.c
 create mode 100644 drivers/input/lirc/lirc_streamzap.c
 create mode 100644 drivers/input/lirc/lirc_ttusbir.c
 create mode 100644 drivers/input/lirc/lirc_zilog.c
#1 lore raw

PATCH 1/18 lirc core device driver infrastructure

-Add Kconfig and Makefile bits
-Add device driver interface and headers

The initial Kconfig and Makefile bits were done by Mario Limonciello for the Ubuntu kernel, but have been tweaked a bit since then. Any errors are probably my doing.

CC Christoph Bartelmus <[email protected]>
CC Mario Limonciello <[email protected]>
---
 MAINTAINERS                   |    9 +
 drivers/input/Kconfig         |    2 +
 drivers/input/Makefile        |    2 +
 drivers/input/lirc/Kconfig    |   21 +
 drivers/input/lirc/Makefile   |    8 +
 drivers/input/lirc/lirc.h     |  103 ++++++
 drivers/input/lirc/lirc_dev.c |  809 +++++++++++++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_dev.h |  262 +++++++++++++
 8 files changed, 1216 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/Kconfig
 create mode 100644 drivers/input/lirc/Makefile
 create mode 100644 drivers/input/lirc/lirc.h
 create mode 100644 drivers/input/lirc/lirc_dev.c
 create mode 100644 drivers/input/lirc/lirc_dev.h
drivers/input/Kconfig +2 -0
index 5f9d860..2ba0904 100644
@@ -170,6 +170,8 @@ source "drivers/input/tablet/Kconfig"
 
 source "drivers/input/touchscreen/Kconfig"
 
+source "drivers/input/lirc/Kconfig"
+
 source "drivers/input/misc/Kconfig"
 
 endif
drivers/input/Makefile +2 -0
index 98c4f9a..4dcb852 100644
@@ -25,3 +25,5 @@ obj-$(CONFIG_INPUT_MISC)	+= misc/
 obj-$(CONFIG_INPUT_APMPOWER)	+= apm-power.o
 
 obj-$(CONFIG_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
+
+obj-$(CONFIG_INPUT_LIRC)	+= lirc/
drivers/input/lirc/Kconfig new file +21 -0
new file mode 100644
index 0000000..2a04d9b
@@ -0,0 +1,21 @@
+#
+# LIRC driver(s) configuration
+#
+menuconfig INPUT_LIRC
+	bool "Linux Infrared Remote Control IR receiver/transmitter drivers"
+	default n
+	help
+	  Say Y here, and all supported Linux Infrared Remote Control IR and
+	  RF receiver and transmitter drivers will be displayed. When paired
+	  with a remote control and the lirc daemon, the receiver drivers
+	  allow control of your Linux system via remote control.
+
+if INPUT_LIRC
+
+config LIRC_DEV
+	tristate "LIRC device loadable module support"
+	default n
+	help
+	  LIRC device loadable module support, required for most LIRC drivers
+
+endif
drivers/input/lirc/Makefile new file +8 -0
new file mode 100644
index 0000000..cdb4c45
@@ -0,0 +1,8 @@
+# Makefile for the lirc drivers.
+#
+
+# Each configuration option enables a list of files.
+
+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)
+
+obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
drivers/input/lirc/lirc.h new file +103 -0

103 lines not on this page · raw message

drivers/input/lirc/lirc_dev.c new file +809 -0

809 lines not on this page · raw message

drivers/input/lirc/lirc_dev.h new file +262 -0

262 lines not on this page · raw message

MAINTAINERS +9 -0
index af27945..f3f7f03 100644
@@ -2580,6 +2580,15 @@ W:	http://www.pasemi.com/
 L:	[email protected]
 S:	Supported
 
+LINUX INFRARED REMOTE CONTROL DRIVERS (LIRC)
+P:	Jarod Wilson
+M:	[email protected]
+P:	Christoph Bartelmus
+M:	[email protected]
+W:	http://www.lirc.org/
+L:	[email protected]
+S:	Maintained
+
 LLC (802.2)
 P:	Arnaldo Carvalho de Melo
 M:	[email protected]
Signature · 1 line
1.6.0.1
#2 lore raw

PATCH 2/18 lirc serial port receiver/transmitter device driver

---
 drivers/input/lirc/Kconfig       |    7 +
 drivers/input/lirc/Makefile      |    1 +
 drivers/input/lirc/lirc_serial.c | 1312 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1320 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_serial.c
drivers/input/lirc/Kconfig +7 -0
index 2a04d9b..73403b9 100644
@@ -18,4 +18,11 @@ config LIRC_DEV
 	help
 	  LIRC device loadable module support, required for most LIRC drivers
 
+config LIRC_SERIAL
+	tristate "Homebrew Serial Port Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for Homebrew Serial Port Receivers
+
 endif
drivers/input/lirc/Makefile +1 -0
index cdb4c45..7d76128 100644
@@ -6,3 +6,4 @@
 EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)
 
 obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
+obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
drivers/input/lirc/lirc_serial.c new file +1312 -0

1,312 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#3 lore raw

PATCH 3/18 lirc driver for 1st-gen Media Center Ed. USB IR transceivers

Works a treat with the lirc_mceusb receiver hooked to my own mythtv frontend, feeding it signals from a Logitech Harmony 880 remote.

---
 drivers/input/lirc/Kconfig       |    7 +
 drivers/input/lirc/Makefile      |    1 +
 drivers/input/lirc/lirc_mceusb.c |  890 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 898 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_mceusb.c
drivers/input/lirc/Kconfig +7 -0
index 73403b9..7dbf1a5 100644
@@ -18,6 +18,13 @@ config LIRC_DEV
 	help
 	  LIRC device loadable module support, required for most LIRC drivers
 
+config LIRC_MCEUSB
+	tristate "Microsoft Media Center Ed. Receiver, v1"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Microsoft Media Center Ed. Receiver, v1
+
 config LIRC_SERIAL
 	tristate "Homebrew Serial Port Receiver"
 	default n
drivers/input/lirc/Makefile +1 -0
index 7d76128..fafdd25 100644
@@ -6,4 +6,5 @@
 EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)
 
 obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
+obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
drivers/input/lirc/lirc_mceusb.c new file +890 -0

890 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#4 lore raw

PATCH 4/18 lirc driver for 2nd-gen and later Media Center Ed. USB IR transceivers

Successfully tested with the mce v2 receiver and remote that shipped with my Hauppauge HVR-1500 expresscard tuner.

---
 drivers/input/lirc/Kconfig        |    7 +
 drivers/input/lirc/Makefile       |    1 +
 drivers/input/lirc/lirc_mceusb2.c | 1119 +++++++++++++++++++++++++++++++++++++
 3 files changed, 1127 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_mceusb2.c
drivers/input/lirc/Kconfig +7 -0
index 7dbf1a5..0a0b059 100644
@@ -25,6 +25,13 @@ config LIRC_MCEUSB
 	help
 	  Driver for the Microsoft Media Center Ed. Receiver, v1
 
+config LIRC_MCEUSB2
+	tristate "Microsoft Media Center Ed. Receiver, v2"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Microsoft Media Center Ed. Receiver, v2
+
 config LIRC_SERIAL
 	tristate "Homebrew Serial Port Receiver"
 	default n
drivers/input/lirc/Makefile +1 -0
index fafdd25..f6accb9 100644
@@ -7,4 +7,5 @@ EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)
 
 obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
+obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
drivers/input/lirc/lirc_mceusb2.c new file +1119 -0

1,119 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#5 lore raw

PATCH 5/18 lirc driver for i2c-based IR receivers

Successfully tested with the IR interface on a Hauppauge PVR-250 and the flimsly little grey remote that shipped with it.

---
 drivers/input/lirc/Kconfig    |    8 +
 drivers/input/lirc/Makefile   |    1 +
 drivers/input/lirc/lirc_i2c.c |  639 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 648 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_i2c.c
drivers/input/lirc/Kconfig +8 -0
index 0a0b059..ba30d2e 100644
@@ -18,6 +18,14 @@ config LIRC_DEV
 	help
 	  LIRC device loadable module support, required for most LIRC drivers
 
+config LIRC_I2C
+	tristate "I2C Based IR Receivers"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for I2C-based IR receivers, such as those commonly
+	  found onboard Hauppauge PVR-150/250/350 video capture cards
+
 config LIRC_MCEUSB
 	tristate "Microsoft Media Center Ed. Receiver, v1"
 	default n
drivers/input/lirc/Makefile +1 -0
index f6accb9..99765d9 100644
@@ -6,6 +6,7 @@
 EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)
 
 obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
+obj-$(CONFIG_LIRC_I2C)		+= lirc_i2c.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
drivers/input/lirc/lirc_i2c.c new file +639 -0

639 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#6 lore raw

PATCH 6/18 lirc driver for the ATI USB RF remote receiver

---
 drivers/input/lirc/Kconfig       |    7 +
 drivers/input/lirc/Makefile      |    1 +
 drivers/input/lirc/lirc_atiusb.c | 1321 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1329 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_atiusb.c
drivers/input/lirc/Kconfig +7 -0
index ba30d2e..e17b39a 100644
@@ -18,6 +18,13 @@ config LIRC_DEV
 	help
 	  LIRC device loadable module support, required for most LIRC drivers
 
+config LIRC_ATIUSB
+	tristate "ATI RF USB Receiver support"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the ATI USB RF remote receiver
+
 config LIRC_I2C
 	tristate "I2C Based IR Receivers"
 	default n
drivers/input/lirc/Makefile +1 -0
index 99765d9..ba8d445 100644
@@ -6,6 +6,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_I2C)		+= lirc_i2c.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
drivers/input/lirc/lirc_atiusb.c new file +1321 -0

1,321 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#7 lore raw

PATCH 7/18 lirc driver for the CommandIR USB Transceiver

---
 drivers/input/lirc/Kconfig      |    7 +
 drivers/input/lirc/Makefile     |    1 +
 drivers/input/lirc/commandir.c  |  982 +++++++++++++++++++++++++++++++++++++++
 drivers/input/lirc/commandir.h  |   68 +++
 drivers/input/lirc/lirc_cmdir.c |  596 ++++++++++++++++++++++++
 drivers/input/lirc/lirc_cmdir.h |   25 +
 6 files changed, 1679 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/commandir.c
 create mode 100644 drivers/input/lirc/commandir.h
 create mode 100644 drivers/input/lirc/lirc_cmdir.c
 create mode 100644 drivers/input/lirc/lirc_cmdir.h
drivers/input/lirc/Kconfig +7 -0
index e17b39a..67802fe 100644
@@ -25,6 +25,13 @@ config LIRC_ATIUSB
 	help
 	  Driver for the ATI USB RF remote receiver
 
+config LIRC_CMDIR
+	tristate "CommandIR USB Transceiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the CommandIR USB Transceiver
+
 config LIRC_I2C
 	tristate "I2C Based IR Receivers"
 	default n
drivers/input/lirc/Makefile +1 -0
index ba8d445..86df97d 100644
@@ -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_CMDIR)	+= lirc_cmdir.o
 obj-$(CONFIG_LIRC_I2C)		+= lirc_i2c.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
drivers/input/lirc/commandir.c new file +982 -0

982 lines not on this page · raw message

drivers/input/lirc/commandir.h new file +68 -0

68 lines not on this page · raw message

drivers/input/lirc/lirc_cmdir.c new file +596 -0

596 lines not on this page · raw message

drivers/input/lirc/lirc_cmdir.h new file +25 -0
new file mode 100644
index 0000000..f2400c3
@@ -0,0 +1,25 @@
+/*
+ *   lirc_cmdir.h
+ */
+
+#ifndef LIRC_CMDIR_H
+#define LIRC_CMDIR_H
+
+#define ON          1
+#define OFF         0
+
+/* transmitter channel control */
+#define MAX_CHANNELS     32
+
+/* CommandIR control codes */
+#define MCU_CTRL_SIZE   3
+#define FREQ_HEADER     2
+#define TX_HEADER       7
+#define TX_HEADER_NEW	8
+
+extern int cmdir_write(unsigned char *buffer, int count,
+		       void *callback_fct, int u);
+extern ssize_t cmdir_read(unsigned char *buffer, size_t count);
+extern int set_tx_channels(unsigned int next_tx);
+
+#endif
Signature · 1 line
1.6.0.1
#8 lore raw

PATCH 8/18 lirc driver for the Soundgraph IMON IR Receivers

Successfully tested earlier tonight, see:

	https://bugzilla.redhat.com/show_bug.cgi?id=459523
---
 drivers/input/lirc/Kconfig     |    7 +
 drivers/input/lirc/Makefile    |    1 +
 drivers/input/lirc/lirc_imon.c | 1280 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1288 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_imon.c
drivers/input/lirc/Kconfig +7 -0
index 67802fe..7e37b2d 100644
@@ -40,6 +40,13 @@ config LIRC_I2C
 	  Driver for I2C-based IR receivers, such as those commonly
 	  found onboard Hauppauge PVR-150/250/350 video capture cards
 
+config LIRC_IMON
+	tristate "Soundgraph IMON Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Soundgraph IMON IR Receiver
+
 config LIRC_MCEUSB
 	tristate "Microsoft Media Center Ed. Receiver, v1"
 	default n
drivers/input/lirc/Makefile +1 -0
index 86df97d..f39fa06 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
 obj-$(CONFIG_LIRC_ATIUSB)	+= lirc_atiusb.o
 obj-$(CONFIG_LIRC_CMDIR)	+= lirc_cmdir.o
 obj-$(CONFIG_LIRC_I2C)		+= lirc_i2c.o
+obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
drivers/input/lirc/lirc_imon.c new file +1280 -0

1,280 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#9 lore raw

PATCH 9/18 lirc driver for the Streamzap PC Receiver

---
 drivers/input/lirc/Kconfig          |    7 +
 drivers/input/lirc/Makefile         |    1 +
 drivers/input/lirc/lirc_streamzap.c |  795 +++++++++++++++++++++++++++++++++++
 3 files changed, 803 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_streamzap.c
drivers/input/lirc/Kconfig +7 -0
index 7e37b2d..c105ac6 100644
@@ -68,4 +68,11 @@ config LIRC_SERIAL
 	help
 	  Driver for Homebrew Serial Port Receivers
 
+config LIRC_STREAMZAP
+	tristate "Streamzap PC Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Streamzap PC Receiver
+
 endif
drivers/input/lirc/Makefile +1 -0
index f39fa06..b348110 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
+obj-$(CONFIG_LIRC_STREAMZAP)	+= lirc_streamzap.o
drivers/input/lirc/lirc_streamzap.c new file +795 -0

795 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#10 lore raw

PATCH 10/18 lirc driver for Igor Cesko's USB IR receiver

---
 drivers/input/lirc/Kconfig            |    7 +
 drivers/input/lirc/Makefile           |    1 +
 drivers/input/lirc/lirc_igorplugusb.c |  619 +++++++++++++++++++++++++++++++++
 3 files changed, 627 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_igorplugusb.c
drivers/input/lirc/Kconfig +7 -0
index c105ac6..8579f96 100644
@@ -40,6 +40,13 @@ config LIRC_I2C
 	  Driver for I2C-based IR receivers, such as those commonly
 	  found onboard Hauppauge PVR-150/250/350 video capture cards
 
+config LIRC_IGORPLUGUSB
+	tristate "Igor Cesko's USB IR Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for Igor Cesko's USB IR Receiver
+
 config LIRC_IMON
 	tristate "Soundgraph IMON Receiver"
 	default n
drivers/input/lirc/Makefile +1 -0
index b348110..68f8da2 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
 obj-$(CONFIG_LIRC_ATIUSB)	+= lirc_atiusb.o
 obj-$(CONFIG_LIRC_CMDIR)	+= lirc_cmdir.o
 obj-$(CONFIG_LIRC_I2C)		+= lirc_i2c.o
+obj-$(CONFIG_LIRC_IGORPLUGUSB)	+= lirc_igorplugusb.o
 obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
drivers/input/lirc/lirc_igorplugusb.c new file +619 -0

619 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#11 lore raw

PATCH 11/18 lirc driver for the Technotrend USB IR receiver

---
 drivers/input/lirc/Kconfig        |    6 +
 drivers/input/lirc/Makefile       |    1 +
 drivers/input/lirc/lirc_ttusbir.c |  400 +++++++++++++++++++++++++++++++++++++
 3 files changed, 407 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_ttusbir.c
drivers/input/lirc/Kconfig +6 -0
index 8579f96..7e924fe 100644
@@ -82,4 +82,10 @@ config LIRC_STREAMZAP
 	help
 	  Driver for the Streamzap PC Receiver
 
+config LIRC_TTUSBIR
+	tristate "Technotrend USB IR Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Technotrend USB IR Receiver
 endif
drivers/input/lirc/Makefile +1 -0
index 68f8da2..2ee00d1 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
 obj-$(CONFIG_LIRC_STREAMZAP)	+= lirc_streamzap.o
+obj-$(CONFIG_LIRC_TTUSBIR)	+= lirc_ttusbir.o
drivers/input/lirc/lirc_ttusbir.c new file +400 -0

400 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#12 lore raw

PATCH 12/18 lirc driver for the Sasem OnAir and Dign HV5 receivers

---
 drivers/input/lirc/Kconfig      |    7 +
 drivers/input/lirc/Makefile     |    1 +
 drivers/input/lirc/lirc_sasem.c |  969 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 977 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_sasem.c
drivers/input/lirc/Kconfig +7 -0
index 7e924fe..2731c40 100644
@@ -68,6 +68,13 @@ config LIRC_MCEUSB2
 	help
 	  Driver for the Microsoft Media Center Ed. Receiver, v2
 
+config LIRC_SASEM
+	tristate "Sasem USB IR Remote"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module
+
 config LIRC_SERIAL
 	tristate "Homebrew Serial Port Receiver"
 	default n
drivers/input/lirc/Makefile +1 -0
index 2ee00d1..1b2793d 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_LIRC_IGORPLUGUSB)	+= lirc_igorplugusb.o
 obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
+obj-$(CONFIG_LIRC_SASEM)	+= lirc_sasem.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
 obj-$(CONFIG_LIRC_STREAMZAP)	+= lirc_streamzap.o
 obj-$(CONFIG_LIRC_TTUSBIR)	+= lirc_ttusbir.o
drivers/input/lirc/lirc_sasem.c new file +969 -0

969 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#13 lore raw

PATCH 13/18 lirc driver for ITE8709 CIR port receiver

---
 drivers/input/lirc/Kconfig        |    7 +
 drivers/input/lirc/Makefile       |    1 +
 drivers/input/lirc/lirc_ite8709.c |  545 +++++++++++++++++++++++++++++++++++++
 3 files changed, 553 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_ite8709.c
drivers/input/lirc/Kconfig +7 -0
index 2731c40..9783639 100644
@@ -54,6 +54,13 @@ config LIRC_IMON
 	help
 	  Driver for the Soundgraph IMON IR Receiver
 
+config LIRC_ITE8709
+	tristate "ITE8709 CIR Port Receiver"
+	default n
+	depends on LIRC_DEV && PNP
+	help
+	  Driver for the ITE8709 IR Receiver
+
 config LIRC_MCEUSB
 	tristate "Microsoft Media Center Ed. Receiver, v1"
 	default n
drivers/input/lirc/Makefile +1 -0
index 1b2793d..1da7c5b 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_LIRC_CMDIR)	+= lirc_cmdir.o
 obj-$(CONFIG_LIRC_I2C)		+= lirc_i2c.o
 obj-$(CONFIG_LIRC_IGORPLUGUSB)	+= lirc_igorplugusb.o
 obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
+obj-$(CONFIG_LIRC_ITE8709)	+= lirc_ite8709.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SASEM)	+= lirc_sasem.o
drivers/input/lirc/lirc_ite8709.c new file +545 -0

545 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#14 lore raw

PATCH 14/18 lirc driver for the ITE IT87xx CIR Port receivers

---
 drivers/input/lirc/Kconfig     |    7 +
 drivers/input/lirc/Makefile    |    1 +
 drivers/input/lirc/lirc_it87.c |  999 ++++++++++++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_it87.h |  116 +++++
 4 files changed, 1123 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_it87.c
 create mode 100644 drivers/input/lirc/lirc_it87.h
drivers/input/lirc/Kconfig +7 -0
index 9783639..42e9bc3 100644
@@ -54,6 +54,13 @@ config LIRC_IMON
 	help
 	  Driver for the Soundgraph IMON IR Receiver
 
+config LIRC_IT87
+	tristate "ITE IT87XX CIR Port Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the ITE IT87xx IR Receiver
+
 config LIRC_ITE8709
 	tristate "ITE8709 CIR Port Receiver"
 	default n
drivers/input/lirc/Makefile +1 -0
index 1da7c5b..4ee32f3 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_LIRC_CMDIR)	+= lirc_cmdir.o
 obj-$(CONFIG_LIRC_I2C)		+= lirc_i2c.o
 obj-$(CONFIG_LIRC_IGORPLUGUSB)	+= lirc_igorplugusb.o
 obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
+obj-$(CONFIG_LIRC_IT87)		+= lirc_it87.o
 obj-$(CONFIG_LIRC_ITE8709)	+= lirc_ite8709.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
drivers/input/lirc/lirc_it87.c new file +999 -0

999 lines not on this page · raw message

drivers/input/lirc/lirc_it87.h new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#15 lore raw

PATCH 15/18 lirc driver for the SIR IrDA port

---
 drivers/input/lirc/Kconfig    |    7 +
 drivers/input/lirc/Makefile   |    1 +
 drivers/input/lirc/lirc_sir.c | 1302 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1310 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_sir.c
drivers/input/lirc/Kconfig +7 -0
index 42e9bc3..b2bdbfb 100644
@@ -96,6 +96,13 @@ config LIRC_SERIAL
 	help
 	  Driver for Homebrew Serial Port Receivers
 
+config LIRC_SIR
+	tristate "Built-in SIR IrDA port"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the SIR IrDA port
+
 config LIRC_STREAMZAP
 	tristate "Streamzap PC Receiver"
 	default n
drivers/input/lirc/Makefile +1 -0
index 4ee32f3..761cb47 100644
@@ -17,5 +17,6 @@ obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
 obj-$(CONFIG_LIRC_SASEM)	+= lirc_sasem.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
+obj-$(CONFIG_LIRC_SIR)		+= lirc_sir.o
 obj-$(CONFIG_LIRC_STREAMZAP)	+= lirc_streamzap.o
 obj-$(CONFIG_LIRC_TTUSBIR)	+= lirc_ttusbir.o
drivers/input/lirc/lirc_sir.c new file +1302 -0

1,302 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#16 lore raw

PATCH 16/18 lirc driver for the IR interface on BT829-based hardware

---
 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
drivers/input/lirc/Kconfig +7 -0
index b2bdbfb..2af6278 100644
@@ -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
drivers/input/lirc/Makefile +1 -0
index 761cb47..c5f71fa 100644
@@ -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
drivers/input/lirc/lirc_bt829.c new file +388 -0

388 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#17 lore raw

PATCH 17/18 lirc driver for homebrew parallel port receivers

---
 drivers/input/lirc/Kconfig         |    7 +
 drivers/input/lirc/Makefile        |    1 +
 drivers/input/lirc/lirc_parallel.c |  728 ++++++++++++++++++++++++++++++++++++
 drivers/input/lirc/lirc_parallel.h |   26 ++
 4 files changed, 762 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_parallel.c
 create mode 100644 drivers/input/lirc/lirc_parallel.h
drivers/input/lirc/Kconfig +7 -0
index 2af6278..fb8ba38 100644
@@ -89,6 +89,13 @@ config LIRC_MCEUSB2
 	help
 	  Driver for the Microsoft Media Center Ed. Receiver, v2
 
+config LIRC_PARALLEL
+	tristate "Homebrew Parallel Port Receiver"
+	default n
+	depends on LIRC_DEV && !SMP
+	help
+	  Driver for Homebrew Parallel Port Receivers
+
 config LIRC_SASEM
 	tristate "Sasem USB IR Remote"
 	default n
drivers/input/lirc/Makefile +1 -0
index c5f71fa..3a1469c 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_LIRC_IT87)		+= lirc_it87.o
 obj-$(CONFIG_LIRC_ITE8709)	+= lirc_ite8709.o
 obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
 obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
+obj-$(CONFIG_LIRC_PARALLEL)	+= lirc_parallel.o
 obj-$(CONFIG_LIRC_SASEM)	+= lirc_sasem.o
 obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
 obj-$(CONFIG_LIRC_SIR)		+= lirc_sir.o
drivers/input/lirc/lirc_parallel.c new file +728 -0

728 lines not on this page · raw message

drivers/input/lirc/lirc_parallel.h new file +26 -0
new file mode 100644
index 0000000..4bed6af
@@ -0,0 +1,26 @@
+/* lirc_parallel.h */
+
+#ifndef _LIRC_PARALLEL_H
+#define _LIRC_PARALLEL_H
+
+#include <linux/lp.h>
+
+#define LIRC_PORT_LEN 3
+
+#define LIRC_LP_BASE    0
+#define LIRC_LP_STATUS  1
+#define LIRC_LP_CONTROL 2
+
+#define LIRC_PORT_DATA           LIRC_LP_BASE    /* base */
+#define LIRC_PORT_TIMER        LIRC_LP_STATUS    /* status port */
+#define LIRC_PORT_TIMER_BIT          LP_PBUSY    /* busy signal */
+#define LIRC_PORT_SIGNAL       LIRC_LP_STATUS    /* status port */
+#define LIRC_PORT_SIGNAL_BIT          LP_PACK    /* ack signal */
+#define LIRC_PORT_IRQ         LIRC_LP_CONTROL    /* control port */
+
+#define LIRC_SFH506_DELAY 0             /* delay t_phl in usecs */
+
+#define LIRC_PARALLEL_MAX_TRANSMITTERS 8
+#define LIRC_PARALLEL_TRANSMITTER_MASK ((1<<LIRC_PARALLEL_MAX_TRANSMITTERS) - 1)
+
+#endif
Signature · 1 line
1.6.0.1
#18 lore raw

PATCH 18/18 lirc driver for the zilog/haupauge IR transceiver

Hopefully, I get this summary more or less correct...

A number of Hauppauge devices contain both an IR receiver and an IR transmitter. The RX side is rather similar to those handled by the lirc_i2c driver, but the TX side is quite different. Devices with both have to be handled a bit carefully...

The TX side is serviced by a zilog processor, running some zilog firmware, but is interfaced with via a software db/table apparently written by a Hauppauge sub-contractor. This is provided via a binary blob, loaded via a request_firmware() call, and the binary blob was generated via i2c sniffing, so general consensus between myself, Janne, Steve and Mike was that there shouldn't be any reason it can't be redistributed, but Mark (the original author) and Christoph had concerns about redistribution, so this originally lived outside of lirc cvs as lirc_pvr150.c. Either way, the "firmware" lives out of tree at the moment anyhow...

See http://www.blushingpenguin.com/mark/blog/?p=24 for more details.

CC Christoph Bartelmus <[email protected]>
CC Mike Krufky <[email protected]>
CC Steven Toth <[email protected]>
CC Mark Weaver <[email protected]>
---
 drivers/input/lirc/Kconfig      |    9 +
 drivers/input/lirc/Makefile     |    1 +
 drivers/input/lirc/lirc_zilog.c | 1395 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 1405 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/lirc/lirc_zilog.c
drivers/input/lirc/Kconfig +9 -0
index fb8ba38..47183ee 100644
@@ -130,4 +130,13 @@ config LIRC_TTUSBIR
 	depends on LIRC_DEV
 	help
 	  Driver for the Technotrend USB IR Receiver
+
+config LIRC_ZILOG
+	tristate "Zilog/Hauppauge IR Transmitter"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Zilog/Hauppauge IR Transmitter, found on
+	  PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards
+
 endif
drivers/input/lirc/Makefile +1 -0
index 3a1469c..411db5e 100644
@@ -22,3 +22,4 @@ obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
 obj-$(CONFIG_LIRC_SIR)		+= lirc_sir.o
 obj-$(CONFIG_LIRC_STREAMZAP)	+= lirc_streamzap.o
 obj-$(CONFIG_LIRC_TTUSBIR)	+= lirc_ttusbir.o
+obj-$(CONFIG_LIRC_ZILOG)	+= lirc_zilog.o
drivers/input/lirc/lirc_zilog.c new file +1395 -0

1,395 lines not on this page · raw message

Signature · 1 line
1.6.0.1
#19 lore raw

PATCH 18/18 lirc driver for the zilog/haupauge IR transceiver

---

drivers/input/Kconfig +2 -0
index 5f9d860..2ba0904 100644
@@ -170,6 +170,8 @@ source "drivers/input/tablet/Kconfig"
 
 source "drivers/input/touchscreen/Kconfig"
 
+source "drivers/input/lirc/Kconfig"
+
 source "drivers/input/misc/Kconfig"
 
 endif
drivers/input/Makefile +2 -0
index 98c4f9a..4dcb852 100644
@@ -25,3 +25,5 @@ obj-$(CONFIG_INPUT_MISC)	+= misc/
 obj-$(CONFIG_INPUT_APMPOWER)	+= apm-power.o
 
 obj-$(CONFIG_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
+
+obj-$(CONFIG_INPUT_LIRC)	+= lirc/
drivers/input/lirc/Kconfig new file +142 -0

142 lines not on this page · raw message

drivers/input/lirc/Makefile new file +25 -0
new file mode 100644
index 0000000..411db5e
@@ -0,0 +1,25 @@
+# Makefile for the lirc drivers.
+#
+
+# Each configuration option enables a list of files.
+
+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
+obj-$(CONFIG_LIRC_IMON)		+= lirc_imon.o
+obj-$(CONFIG_LIRC_IT87)		+= lirc_it87.o
+obj-$(CONFIG_LIRC_ITE8709)	+= lirc_ite8709.o
+obj-$(CONFIG_LIRC_MCEUSB)	+= lirc_mceusb.o
+obj-$(CONFIG_LIRC_MCEUSB2)	+= lirc_mceusb2.o
+obj-$(CONFIG_LIRC_PARALLEL)	+= lirc_parallel.o
+obj-$(CONFIG_LIRC_SASEM)	+= lirc_sasem.o
+obj-$(CONFIG_LIRC_SERIAL)	+= lirc_serial.o
+obj-$(CONFIG_LIRC_SIR)		+= lirc_sir.o
+obj-$(CONFIG_LIRC_STREAMZAP)	+= lirc_streamzap.o
+obj-$(CONFIG_LIRC_TTUSBIR)	+= lirc_ttusbir.o
+obj-$(CONFIG_LIRC_ZILOG)	+= lirc_zilog.o
drivers/input/lirc/commandir.c new file +982 -0

982 lines not on this page · raw message

drivers/input/lirc/commandir.h new file +68 -0

68 lines not on this page · raw message

drivers/input/lirc/lirc.h new file +103 -0

103 lines not on this page · raw message

drivers/input/lirc/lirc_atiusb.c new file +1321 -0

1,321 lines not on this page · raw message

drivers/input/lirc/lirc_bt829.c new file +388 -0

346 lines not on this page · raw message

drivers/input/lirc/lirc_cmdir.c new file +596 -0

596 lines not on this page · raw message

drivers/input/lirc/lirc_cmdir.h new file +25 -0
new file mode 100644
index 0000000..f2400c3

Lines of this file are not shown. View the raw message.

drivers/input/lirc/lirc_dev.c new file +809 -0

809 lines not on this page · raw message

drivers/input/lirc/lirc_dev.h new file +262 -0

262 lines not on this page · raw message

drivers/input/lirc/lirc_i2c.c new file +639 -0

639 lines not on this page · raw message

drivers/input/lirc/lirc_igorplugusb.c new file +619 -0

619 lines not on this page · raw message

drivers/input/lirc/lirc_imon.c new file +1280 -0

1,280 lines not on this page · raw message

drivers/input/lirc/lirc_it87.c new file +999 -0

999 lines not on this page · raw message

drivers/input/lirc/lirc_it87.h new file +116 -0

116 lines not on this page · raw message

drivers/input/lirc/lirc_ite8709.c new file +545 -0

545 lines not on this page · raw message

drivers/input/lirc/lirc_mceusb.c new file +890 -0

890 lines not on this page · raw message

drivers/input/lirc/lirc_mceusb2.c new file +1119 -0

1,119 lines not on this page · raw message

drivers/input/lirc/lirc_parallel.c new file +728 -0

728 lines not on this page · raw message

drivers/input/lirc/lirc_parallel.h new file +26 -0
new file mode 100644
index 0000000..4bed6af

Lines of this file are not shown. View the raw message.

drivers/input/lirc/lirc_sasem.c new file +969 -0

969 lines not on this page · raw message

drivers/input/lirc/lirc_serial.c new file +1312 -0

1,312 lines not on this page · raw message

drivers/input/lirc/lirc_sir.c new file +1302 -0

1,302 lines not on this page · raw message

drivers/input/lirc/lirc_streamzap.c new file +795 -0

795 lines not on this page · raw message

drivers/input/lirc/lirc_ttusbir.c new file +400 -0

400 lines not on this page · raw message

drivers/input/lirc/lirc_zilog.c new file +1395 -0

1,395 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#20 lore raw

Re: [PATCH 09/18] lirc driver for the Streamzap PC Receiver

In reply to Jarod Wilson

[Yes, you said I shouldn't do more reviews of the posted code, but the following was already pretty much written. I really only found one thing in this driver, and I suspect it may not have been addressed yet.

This was set to be the last anyway, I'm pretty much out of time for now.]

jon

I'm curious about the following function:

drivers/input/lirc/lirc_streamzap.c line 182

Quoted 6 lines
drivers/input/lirc/lirc_streamzap.c new file +6 -0
+static void stop_timer(struct usb_streamzap *sz)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&sz->timer_lock, flags);
+	if (sz->timer_running) {

What happens if the timer fires right here?

drivers/input/lirc/lirc_streamzap.c line 187

Quoted 5 lines
drivers/input/lirc/lirc_streamzap.c new file +5 -0
+		sz->timer_running = 0;
+		del_timer_sync(&sz->delay_timer);
+	}
+	spin_unlock_irqrestore(&sz->timer_lock, flags);
+}

The timer acquires the lock too, so this looks a bit like a deadlock to me. Probably del_timer_sync() should be called without the lock?

#21 lore raw

Re: [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers

In reply to Jarod Wilson

drivers/input/lirc/lirc_imon.c line 74

Quoted 3 lines
drivers/input/lirc/lirc_imon.c new file +3 -0
+#define SUCCESS		0
+#define	TRUE		1
+#define FALSE		0

(See my grumble in previous reviews...:)

drivers/input/lirc/lirc_imon.c line 149

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+#define LOCK_CONTEXT	mutex_lock(&context->lock)
+#define UNLOCK_CONTEXT	mutex_unlock(&context->lock)

Here too.

drivers/input/lirc/lirc_imon.c line 214

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+/* to prevent races between open() and disconnect() */
+static DECLARE_MUTEX(disconnect_sem);

This should be a real mutex, I think.

drivers/input/lirc/lirc_imon.c line 219

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+/* lcd or vfd? */
+static int is_lcd;

The driver can only do one or the other? You can't have both in the system? And somehow the user is supposed to configure it at load time to do the right thing?

Quoted 15 lines
drivers/input/lirc/lirc_imon.c new file +15 -0
+/**
+ * Sends a packet to the VFD.
+ */
+static inline int send_packet(struct imon_context *context)
+{
+	unsigned int pipe;
+	int interval = 0;
+	int retval = SUCCESS;
+	struct usb_ctrlrequest *control_req = NULL;
+
+	/* Check if we need to use control or interrupt urb */
+	if (!context->tx_control) {
+		pipe = usb_sndintpipe(context->dev,
+				      context->tx_endpoint->bEndpointAddress);
+		interval = context->tx_endpoint->bInterval;

drivers/input/lirc/lirc_imon.c line 382

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+
+		usb_fill_int_urb(context->tx_urb, context->dev, pipe,
+				 context->usb_tx_buf,
+				 sizeof(context->usb_tx_buf),
+				 usb_tx_callback, context, interval);
+
+		context->tx_urb->actual_length = 0;
+	} else {
+		/* fill request into kmalloc'ed space: */
+		control_req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);

Why GFP_NOIO?

Quoted 24 lines
drivers/input/lirc/lirc_imon.c new file +24 -0
+		if (control_req == NULL)
+			return -ENOMEM;
+
+		/* setup packet is '21 09 0200 0001 0008' */
+		control_req->bRequestType = 0x21;
+		control_req->bRequest = 0x09;
+		control_req->wValue = cpu_to_le16(0x0002);
+		control_req->wIndex = cpu_to_le16(0x0100);
+		control_req->wLength = cpu_to_le16(0x0800);
+
+		/* control pipe is endpoint 0x00 */
+		pipe = usb_sndctrlpipe(context->dev, 0);
+
+		/* build the control urb */
+		usb_fill_control_urb(context->tx_urb, context->dev, pipe,
+				     (unsigned char *)control_req,
+				     context->usb_tx_buf,
+				     sizeof(context->usb_tx_buf),
+				     usb_tx_callback, context);
+		context->tx_urb->actual_length = 0;
+	}
+
+	init_completion(&context->tx.finished);
+	atomic_set(&(context->tx.busy), 1);

drivers/input/lirc/lirc_imon.c line 416

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+
+	retval =  usb_submit_urb(context->tx_urb, GFP_KERNEL);
+	if (retval != SUCCESS) {
+		atomic_set(&(context->tx.busy), 0);
+		err("%s: error submitting urb(%d)", __func__, retval);
+	} else {
+		/* Wait for tranmission to complete(or abort) */
+		UNLOCK_CONTEXT;
+		wait_for_completion(&context->tx.finished);
+		LOCK_CONTEXT;

Should that be an interruptible (or killable) wait?

Quoted 12 lines
drivers/input/lirc/lirc_imon.c new file +12 -0
+static ssize_t show_associate_remote(struct device *d,
+				     struct device_attribute *attr,
+				     char *buf)
+{
+	struct imon_context *context = dev_get_drvdata(d);
+
+	if (!context)
+		return -ENODEV;
+
+	if (context->ir_isassociating) {
+		strcpy(buf, "The device it associating press some button "
+			    "on the remote.\n");

drivers/input/lirc/lirc_imon.c line 492

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+	} else if (context->ir_isopen) {
+		strcpy(buf, "Device is open and ready to associate.\n"
+			    "Echo something into this file to start "
+			    "the process.\n");
+	} else {
+		strcpy(buf, "Device is closed, you need to open it to "
+			    "associate the remote(you can use irw).\n");
+	}
+	return strlen(buf);
+}

I *guess* that's one value per file, but it's still not quite the sysfs norm. How about one-word status codes which can be made more verbose by user space? (That's an API change, of course...)

Quoted 11 lines
drivers/input/lirc/lirc_imon.c new file +11 -0
+static ssize_t store_associate_remote(struct device *d,
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct imon_context *context;
+
+	context = dev_get_drvdata(d);
+
+	if (!context)
+		return -ENODEV;
+

drivers/input/lirc/lirc_imon.c line 514

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+	if (!context->ir_isopen)
+		return -EINVAL;
+
+	if (context->ir_isopen) {
+		context->ir_isassociating = TRUE;
+		send_associate_24g(context);
+	}
+
+	return count;
+}

No need to take the mutex here?

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+/**
+ * Called by lirc_dev when the application opens /dev/lirc
+ */
+static int ir_open(void *data)
+{
+	int retval = SUCCESS;
+	struct imon_context *context;
+
+	/* prevent races with disconnect */
+	down(&disconnect_sem);

drivers/input/lirc/lirc_imon.c line 716

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+
+	context = (struct imon_context *) data;
+
+	LOCK_CONTEXT;
+
+	if (context->ir_isopen) {
+		err("%s: IR port is already open", __func__);
+		retval = -EBUSY;
+		goto exit;
+	}

I wonder if the single-open semantics are really doing what the author intended? It is unsufficient to prevent concurrent calls elsewhere.

Quoted 17 lines
drivers/input/lirc/lirc_imon.c new file +17 -0
+	/* initial IR protocol decode variables */
+	context->rx.count = 0;
+	context->rx.initial_space = 1;
+	context->rx.prev_bit = 0;
+
+	usb_fill_int_urb(context->rx_urb, context->dev,
+		usb_rcvintpipe(context->dev,
+				context->rx_endpoint->bEndpointAddress),
+		context->usb_rx_buf, sizeof(context->usb_rx_buf),
+		usb_rx_callback, context, context->rx_endpoint->bInterval);
+
+	retval = usb_submit_urb(context->rx_urb, GFP_KERNEL);
+
+	if (retval)
+		err("%s: usb_submit_urb failed for ir_open(%d)",
+		    __func__, retval);
+	else {

drivers/input/lirc/lirc_imon.c line 744

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+		context->ir_isopen = TRUE;
+		info("IR port opened");
+	}
+
+exit:
+	UNLOCK_CONTEXT;
+
+	up(&disconnect_sem);
+	return SUCCESS;
+}

This discards "retval", which could hold an error status - the function returns "SUCCESS" even if ->ir_isopen is not set.

Quoted 20 lines
drivers/input/lirc/lirc_imon.c new file +20 -0
+/**
+ * Callback function for USB core API: disonnect
+ */
+static void imon_disconnect(struct usb_interface *interface)
+{
+	struct imon_context *context;
+
+	/* prevent races with ir_open()/vfd_open() */
+	down(&disconnect_sem);
+
+	context = usb_get_intfdata(interface);
+	LOCK_CONTEXT;
+
+	info("%s: iMON device disconnected", __func__);
+
+	/* sysfs_remove_group is safe to call even if sysfs_create_group
+	 * hasn't been called */
+	sysfs_remove_group(&interface->dev.kobj,
+			   &imon_attribute_group);
+	usb_set_intfdata(interface, NULL);

drivers/input/lirc/lirc_imon.c line 1235

Quoted 10 lines
drivers/input/lirc/lirc_imon.c new file +10 -0
+	context->dev_present = FALSE;
+
+	/* Stop reception */
+	usb_kill_urb(context->rx_urb);
+
+	/* Abort ongoing write */
+	if (atomic_read(&context->tx.busy)) {
+		usb_kill_urb(context->tx_urb);
+		wait_for_completion(&context->tx.finished);
+	}

What if this races with another thread waiting for the completion? It seems like it should be completed with complete_all(), but that wasn't the case.

#22 lore raw

Re: [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers

Quoted 11 lines · On Wednesday 10 September 2008 23:02:29 Jonathan Corbet wrote:

drivers/input/lirc/lirc_imon.c line 74

Quoted 3 lines
drivers/input/lirc/lirc_imon.c new file +3 -0
+#define SUCCESS		0
+#define	TRUE		1
+#define FALSE		0

(See my grumble in previous reviews...:)

drivers/input/lirc/lirc_imon.c line 149

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+#define LOCK_CONTEXT	mutex_lock(&context->lock)
+#define UNLOCK_CONTEXT	mutex_unlock(&context->lock)

Here too.

Quoted 4 lines

drivers/input/lirc/lirc_imon.c line 214

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+/* to prevent races between open() and disconnect() */
+static DECLARE_MUTEX(disconnect_sem);

This should be a real mutex, I think.

All three already resolved. I think it would wise to stop the review of this patch set until we repost or review based on Jarod's git repository (http://git.wilsonet.com/linux-2.6-lirc.git/).

Thanks for the reviews so far.

Janne

#23 lore raw

Re: [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers

Quoted 12 lines · On Wednesday 10 September 2008 17:23:51 Janne Grunau wrote:
Quoted 11 lines · On Wednesday 10 September 2008 23:02:29 Jonathan Corbet wrote:

drivers/input/lirc/lirc_imon.c line 74

Quoted 3 lines
drivers/input/lirc/lirc_imon.c new file +3 -0
+#define SUCCESS		0
+#define	TRUE		1
+#define FALSE		0

(See my grumble in previous reviews...:)

drivers/input/lirc/lirc_imon.c line 149

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+#define LOCK_CONTEXT	mutex_lock(&context->lock)
+#define UNLOCK_CONTEXT	mutex_unlock(&context->lock)

Here too.

Quoted 8 lines
Quoted 4 lines

drivers/input/lirc/lirc_imon.c line 214

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+/* to prevent races between open() and disconnect() */
+static DECLARE_MUTEX(disconnect_sem);

This should be a real mutex, I think.

All three already resolved. I think it would wise to stop the review of this patch set until we repost or review based on Jarod's git repository (http://git.wilsonet.com/linux-2.6-lirc.git/).

Yeah, I'd say for any driver that hasn't yet been reviewed, if anyone wants to continue reviewing, it might be best to poke the version in that git tree, as a number of issues common across multiple drivers have already (hopefully) been whacked. We'll definitely put together an updated patch set in the near future, but at the moment, we're still working through all the bits that have received feedback so far.

Quoted 1 line

Thanks for the reviews so far.

Indeed, very much appreciated!

Signature · 2 lines
Jarod Wilson
[email protected]
#24 lore raw

Re: [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers

In reply to Jonathan Corbet
Quoted 10 lines · On Wednesday 10 September 2008 17:02:29 Jonathan Corbet wrote:

drivers/input/lirc/lirc_imon.c line 74

Quoted 3 lines
drivers/input/lirc/lirc_imon.c new file +3 -0
+#define SUCCESS		0
+#define	TRUE		1
+#define FALSE		0

(See my grumble in previous reviews...:)

drivers/input/lirc/lirc_imon.c line 149

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+#define LOCK_CONTEXT	mutex_lock(&context->lock)
+#define UNLOCK_CONTEXT	mutex_unlock(&context->lock)

Here too.

All gone.

Quoted 4 lines

drivers/input/lirc/lirc_imon.c line 214

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+/* to prevent races between open() and disconnect() */
+static DECLARE_MUTEX(disconnect_sem);

This should be a real mutex, I think.

Done.

Quoted 6 lines

drivers/input/lirc/lirc_imon.c line 219

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+/* lcd or vfd? */
+static int is_lcd;

The driver can only do one or the other? You can't have both in the system? And somehow the user is supposed to configure it at load time to do the right thing?

Should be autodetected by default now, based on usb device ID, but can still be overridden by a module para 'display_type'. Not sure exactly what would happen if the user had more than one, but I don't know why they would in the first place...

Quoted 1 line
Quoted 1 line

+static inline int send_packet(struct imon_context *context)

[...]

Quoted 4 lines

drivers/input/lirc/lirc_imon.c line 382

Quoted 2 lines
drivers/input/lirc/lirc_imon.c new file +2 -0
+		/* fill request into kmalloc'ed space: */
+		control_req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);

Why GFP_NOIO?

Original author probably thought it was necessary. Certainly doesn't look like it is to me, I'll make that just GFP_KERNEL.

Quoted 7 lines

drivers/input/lirc/lirc_imon.c line 416

Quoted 5 lines
drivers/input/lirc/lirc_imon.c new file +5 -0
+	} else {
+		/* Wait for tranmission to complete(or abort) */
+		UNLOCK_CONTEXT;
+		wait_for_completion(&context->tx.finished);
+		LOCK_CONTEXT;

Should that be an interruptible (or killable) wait?

Don't see why it couldn't be. Done.

Quoted 18 lines
Quoted 18 lines
drivers/input/lirc/lirc_imon.c new file +18 -0
+static ssize_t show_associate_remote(struct device *d,
+				     struct device_attribute *attr,
+				     char *buf)
+{
+	struct imon_context *context = dev_get_drvdata(d);
+
+	if (!context)
+		return -ENODEV;
+
+	if (context->ir_isassociating) {
+		strcpy(buf, "The device it associating press some button "
+			    "on the remote.\n");
+	} else if (context->ir_isopen) {
+		strcpy(buf, "Device is open and ready to associate.\n"
+			    "Echo something into this file to start "
+			    "the process.\n");
+	} else {
+		strcpy(buf, "Device is closed, you need to open it to "
Quoted 8 lines

drivers/input/lirc/lirc_imon.c line 492

Quoted 4 lines
drivers/input/lirc/lirc_imon.c new file +4 -0
+			    "associate the remote(you can use irw).\n");
+	}
+	return strlen(buf);
+}

I *guess* that's one value per file, but it's still not quite the sysfs norm. How about one-word status codes which can be made more verbose by user space? (That's an API change, of course...)

Yuk. There really is no user space. But chances of someone stumbling upon these directions in sysfs are pretty slim. Reducing to single-word, and logging a url pointer to the lirc.org page on setting these up. Sound sane enough?

Quoted 15 lines
Quoted 15 lines
drivers/input/lirc/lirc_imon.c new file +15 -0
+static ssize_t store_associate_remote(struct device *d,
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct imon_context *context;
+
+	context = dev_get_drvdata(d);
+
+	if (!context)
+		return -ENODEV;
+
+	if (!context->ir_isopen)
+		return -EINVAL;
+
+	if (context->ir_isopen) {
Quoted 8 lines

drivers/input/lirc/lirc_imon.c line 514

Quoted 6 lines
drivers/input/lirc/lirc_imon.c new file +6 -0
+		context->ir_isassociating = TRUE;
+		send_associate_24g(context);
+	}
+
+	return count;
+}

No need to take the mutex here?

Added mutex here and in show_associate_remote() for good measure.

Quoted 15 lines
Quoted 15 lines
drivers/input/lirc/lirc_imon.c new file +15 -0
+/**
+ * Called by lirc_dev when the application opens /dev/lirc
+ */
+static int ir_open(void *data)
+{
+	int retval = SUCCESS;
+	struct imon_context *context;
+
+	/* prevent races with disconnect */
+	down(&disconnect_sem);
+
+	context = (struct imon_context *) data;
+
+	LOCK_CONTEXT;
+
Quoted 8 lines

drivers/input/lirc/lirc_imon.c line 716

Quoted 5 lines
drivers/input/lirc/lirc_imon.c new file +5 -0
+	if (context->ir_isopen) {
+		err("%s: IR port is already open", __func__);
+		retval = -EBUSY;
+		goto exit;
+	}

I wonder if the single-open semantics are really doing what the author intended? It is unsufficient to prevent concurrent calls elsewhere.

I think we're good to go with disconnect_sem being converted to an actual mutex, no?

Quoted 9 lines

drivers/input/lirc/lirc_imon.c line 744

Quoted 6 lines
drivers/input/lirc/lirc_imon.c new file +6 -0
+exit:
+	UNLOCK_CONTEXT;
+
+	up(&disconnect_sem);
+	return SUCCESS;
+}

This discards "retval", which could hold an error status - the function returns "SUCCESS" even if ->ir_isopen is not set.

Gah. That's fugly. Fixed.

Quoted 1 line
Quoted 1 line

+static void imon_disconnect(struct usb_interface *interface)

[...]

Quoted 9 lines

drivers/input/lirc/lirc_imon.c line 1235

Quoted 5 lines
drivers/input/lirc/lirc_imon.c new file +5 -0
+	/* Abort ongoing write */
+	if (atomic_read(&context->tx.busy)) {
+		usb_kill_urb(context->tx_urb);
+		wait_for_completion(&context->tx.finished);
+	}

What if this races with another thread waiting for the completion? It seems like it should be completed with complete_all(), but that wasn't the case.

Agreed. At this point, we're disconnecting, no point in waiting on anyone else.

I've attempted to remedy everything, compile-tested and briefly run-time tested the changes, and have pushed 'em all into my git tree. My shiny new iMon Knob receiver and remote are reasonably happy still (less some lockdep spew that I have to figure out what to do with still), but I have no vfd or lcd to test with, unfortunately.

Signature · 2 lines
Jarod Wilson
[email protected]
#25 lore raw

Re: [PATCH 08/18] lirc driver for the Soundgraph IMON IR Receivers

Quoted 24 lines · On Monday 22 September 2008 17:47:56 Jarod Wilson wrote:
Quoted 15 lines
Quoted 15 lines
drivers/input/lirc/lirc_imon.c new file +15 -0
+/**
+ * Called by lirc_dev when the application opens /dev/lirc
+ */
+static int ir_open(void *data)
+{
+   int retval = SUCCESS;
+   struct imon_context *context;
+
+   /* prevent races with disconnect */
+   down(&disconnect_sem);
+
+   context = (struct imon_context *) data;
+
+   LOCK_CONTEXT;
+
Quoted 8 lines
Quoted 5 lines

+   if (context->ir_isopen) {
+           err("%s: IR port is already open", __func__); +           retval = -EBUSY;
+           goto exit;
+   }

I wonder if the single-open semantics are really doing what the author intended?  It is unsufficient to prevent concurrent calls elsewhere.

Quoted 2 lines

I think we're good to go with disconnect_sem being converted to an actual mutex, no?

No. The lock here is worthless, as is the check for context->ir_isopen, as this function *only* gets called with the driver_lock held in lirc_dev, and lirc_dev won't call this if the device is already open. I've simply dropped the context lock, as its not needed at all (and in fact, triggered lockdep spew).

Signature · 2 lines
Jarod Wilson
[email protected]
#26 lore raw

Re: [PATCH 07/18] lirc driver for the CommandIR USB Transceiver

In reply to Jarod Wilson

This driver has real locking problems. Parts of it depend on the BKL, but I would have a hard time arguing for the addition of new BKL users in this century. The assumption that ->open() is called under the BKL no longer holds. It's really time to put a proper lock here.

This driver also needs a lot of "static" keywords thrown in.

drivers/input/lirc/commandir.c line 49

Quoted 6 lines
drivers/input/lirc/commandir.c new file +6 -0
+/* circular packet queue */
+unsigned char ourbuffers[QUEUELENGTH][64];
+int waitusecs[QUEUELENGTH];
+int ourbufferlengths[QUEUELENGTH];
+int nexttosend;
+int nexttofill;

So this driver only handles a single device?

drivers/input/lirc/commandir.c line 68

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+/* Structure to hold all of our device specific stuff */
+struct usb_skel {
+	struct usb_device *udev; /* the usb device for this device */
+	struct usb_interface *interface; /* the interface for this device */
+	unsigned char *bulk_in_buffer; /* the buffer to receive data */
+	size_t bulk_in_size; /* the size of the receive buffer */
+	__u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
+	__u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
+	struct kref kref;
+};

As with a previous driver, a more descriptive name than "usb_skel" would be nice.

As far as I can tell, the kref here is just extra overhead. Why not just free the structure in cmdir_release()?

drivers/input/lirc/commandir.c line 106

Quoted 3 lines
drivers/input/lirc/commandir.c new file +3 -0
+#define CMDIR_VAR_LEN 68
+static char cmdir_var[] =
+"COMMANDIRx:\n TX Enabled: 1, 2, 3, 4\n RX: commandirx\n LCD: commandirx";

This struck me as a little weird, so I went and looked at where it is used:

Quoted 8 lines
drivers/input/lirc/commandir.c new file +8 -0
+static void update_cmdir_string(int device_num)
+{
+	int next_comma = 0;
+	int next_pos = 25;
+	unsigned int multiplier;
+	int i;
+
+	/* cmdir_var[] = "COMMANDIRx:\n"

drivers/input/lirc/commandir.c line 370

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+	 * 		 " TX Enabled: 1, 2, 3, 4\n"
+	 * 		 " RX: commandirx\n"
+	 * 		 " LCD: commandirx\n" */
+
+	cmdir_var[9] = ASCII0+device_num;
+	cmdir_var[50] = ASCII0+rx_device;
+	cmdir_var[67] = ASCII0+lcd_device;
+
+	for (i = 25; i < 35; i++)
+		cmdir_var[i] = ' ';

[...]

I don't get it. Something is wrong with sprintf()?

Quoted 3 lines
drivers/input/lirc/commandir.c new file +3 -0
+static int cmdir_probe(struct usb_interface *interface,
+		       const struct usb_device_id *id)
+{

[...]

drivers/input/lirc/commandir.c line 232

Quoted 4 lines
drivers/input/lirc/commandir.c new file +4 -0
+	/* check whether minor already includes base */
+	minor = interface->minor;
+	if (minor >= USB_CMDIR_MINOR_BASE)
+		minor = minor-USB_CMDIR_MINOR_BASE;

This kind of stuff looks like a recipe for confusion. Why not just deal with the minor number as it is?

drivers/input/lirc/commandir.c line 254

Quoted 7 lines
drivers/input/lirc/commandir.c new file +7 -0
+static void cmdir_disconnect(struct usb_interface *interface)
+{
+	struct usb_skel *dev;
+	int minor = interface->minor;
+
+	/* prevent cmdir_open() from racing cmdir_disconnect() */
+	lock_kernel();

As noted before, that won't work.

Quoted 4 lines
drivers/input/lirc/commandir.c new file +4 -0
+static int cmdir_check(int device_num)
+{
+	struct usb_interface *interface;
+

drivers/input/lirc/commandir.c line 321

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+	interface = usb_find_interface(&cmdir_driver,
+				       USB_CMDIR_MINOR_BASE+device_num);
+	if (!interface) {
+		/* also check without adding base, for devfs */
+		interface = usb_find_interface(&cmdir_driver, rx_device);
+		if (!interface)
+			return -ENODEV;
+	}
+	return 0;
+}

For devfs?? Again, this messing around with the minor number looks like trouble.

drivers/input/lirc/commandir.c line 329

Quoted 7 lines
drivers/input/lirc/commandir.c new file +7 -0
+static void init_cmdir_var(int device_num)
+{
+	int i;
+	unsigned int multiplier = 1;
+
+	for (i = 0; i < device_num; i++)
+		multiplier = multiplier*0x10;

I bet that could be implemented without a loop.

Quoted 11 lines
drivers/input/lirc/commandir.c new file +10 -0
+	transmitters |= multiplier * 0x0F;
+	next_transmitters = transmitters;
+	info("commandir%d reset", device_num);
+	return;
+}
 
+static ssize_t cmdir_file_read(struct file *file, char *buffer,
+			       size_t count, loff_t *ppos)
+{
+	int retval = 0;
+	int minor = 0;

drivers/input/lirc/commandir.c line 426

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+	struct usb_skel *dev;
+
+	dev = (struct usb_skel *)file->private_data;
+	minor = dev->interface->minor;
+	if (minor >= USB_CMDIR_MINOR_BASE)
+		minor = minor - USB_CMDIR_MINOR_BASE;
+
+	if (((int)*ppos) == 0) {
+		update_cmdir_string(minor);
+		if (copy_to_user(buffer, cmdir_var, CMDIR_VAR_LEN))

So it ignores the count the user asked for and stuffs the full length down there anyway?

Quoted 13 lines
drivers/input/lirc/commandir.c new file +13 -0
+			retval = -EFAULT;
+		else
+			retval = CMDIR_VAR_LEN;
+		return retval;
+	} else
+		return 0;
+}
+
+/*  Read data from CommandIR  */
+ssize_t cmdir_read(unsigned char *buffer, size_t count)
+{
+	struct usb_skel *dev;
+	int length, retval = 0;

drivers/input/lirc/commandir.c line 449

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+
+	struct usb_interface *interface;
+	interface = usb_find_interface(&cmdir_driver,
+			USB_CMDIR_MINOR_BASE+rx_device);
+	if (!interface) {
+		/* also check without adding base, for devfs */
+		interface = usb_find_interface(&cmdir_driver, rx_device);
+		if (!interface)
+			return -ENODEV;
+	}

Again, devfs compatibility is probably not needed anymore.

Quoted 17 lines
drivers/input/lirc/commandir.c new file +17 -0
+	dev = usb_get_intfdata(interface);
+	if (!dev)
+		return -ENODEV;
+	retval = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev,
+						dev->bulk_in_endpointAddr),
+		 dev->bulk_in_buffer, min(dev->bulk_in_size, count),
+		 &length, HZ*10);
+	if (!retval) {
+		if (!memcpy(buffer, dev->bulk_in_buffer, length))
+			retval = -EFAULT;
+		else {
+			/* current status of the TX buffer */
+			curTXFill = buffer[2];
+			retval = length;
+		}
+	}
+	/* suppress errors */

drivers/input/lirc/commandir.c line 476

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+	/*
+	else {
+		err("Read from device failed, error %d",retval);
+	}
+	*/
+	/* printk(KERN_INFO "CommandIR Reporting TX buffer at %d bytes. \n",
+	 * 	  curTXFill); */
+	return retval;
+}
+EXPORT_SYMBOL(cmdir_read);

Who is the consumer of these exports? (OK, I found it later).

Quoted 36 lines
drivers/input/lirc/commandir.c new file +36 -0
+static ssize_t cmdir_file_write(struct file *file, const char *buffer,
+				size_t count, loff_t *ppos)
+{
+	int retval;
+	int i;
+	int equalsign = 0;
+	int changeType = 0;
+	unsigned char ctrl_buffer[MCU_CTRL_SIZE];
+	char *local_buffer;
+	int minor;
+
+	/* set as default - if non-specific error,
+	 * won't keep calling this function */
+	retval = count;
+	local_buffer = kmalloc(count, GFP_KERNEL);
+
+	/* verify that we actually have some data to write */
+	if (count == 0) {
+		err("Write request of 0 bytes");
+		goto exit;
+	}
+	if (count > 64) {
+		err("Input too long");
+		goto exit;
+	}
+
+	/* copy the data from userspace into our local buffer */
+	if (copy_from_user(local_buffer, buffer, count)) {
+		retval = -EFAULT;
+		goto exit;
+	}
+
+	/* parse code */
+	changeType = cNothing;
+	equalsign = 0;
+	for (i = 0; i < MCU_CTRL_SIZE; i++)

drivers/input/lirc/commandir.c line 523

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+		ctrl_buffer[i] = 'j';
+
+	for (i = 0; i < count; i++) {
+		switch (local_buffer[i]) {
+		case 'X':
+		case 'x':
+			if ((i > 0) && ((local_buffer[i - 1] == 'R')
+			    || (local_buffer[i - 1] == 'r')))
+				changeType = cRX;
+			break;

So we have a command parser built into this driver. It looks like somebody wanted to avoid ioctl() at all costs. But ioctl() exists for a reason, and this looks like a good use for it to me. Of course, now this is a user-space API which will be hard to change, but I think consideration should be given to doing just that.

Quoted 25 lines
drivers/input/lirc/commandir.c new file +25 -0
+		case 'S':
+		case 's':
+			if ((i > 1) && ((local_buffer[i - 1] == 'E')
+			    || (local_buffer[i - 1] == 'e'))) {
+				if ((local_buffer[i-2] == 'R')
+				    || (local_buffer[i-2] == 'r'))
+					changeType = cRESET;
+			}
+			break;
+		case 'L':
+		case 'l':
+			if ((i > 0) && ((local_buffer[i - 1] == 'F')
+			    || (local_buffer[i - 1] == 'f')))
+				changeType = cFLASH;
+			break;
+		case 'C':
+		case 'c':
+			if ((i > 0) && ((local_buffer[i - 1] == 'L')
+			    || (local_buffer[i - 1] == 'l')))
+				changeType = cLCD;
+			break;
+		case '=':
+			if (changeType != cNothing)
+				equalsign = i;
+			break;

drivers/input/lirc/commandir.c line 558

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+		case '0':
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+			if (equalsign > 0) {
+				minor = local_buffer[i] - ASCII0;

This code never checks minor for validity, it just assumes that the device exists - and that the current process has the right to mess with it.

[...]

drivers/input/lirc/commandir.c line 621

Quoted 6 lines
drivers/input/lirc/commandir.c new file +6 -0
+		default:
+			if ((equalsign > 0) && (local_buffer[i] > 32)) {
+				err("Non-numerical argument");
+				goto exit;
+			}
+			break;

And here it ignores junk if an "=" has not been seen yet.

drivers/input/lirc/commandir.c line 640

Quoted 6 lines
drivers/input/lirc/commandir.c new file +6 -0
+int cmdir_write(unsigned char *buffer, int count,
+		void *callback_fct, int usecdelay)
+{
+	/* Always add to queue, then send queue number
+	 * no locks
+	 * mbodkin, Sept 8, 2005 */

Why no locks? This code is messing with a global buffer.

drivers/input/lirc/commandir.c line 755

Quoted 4 lines
drivers/input/lirc/commandir.c new file +4 -0
+int wait_to_tx(int usecs)
+{
+	/* don't return until last_time + usecs has been reached
+	 * for non-zero last_tx's. */

I will confess that I have no clue what this function is really trying to do. I also note, though, that the only call to it is commented out. So it should maybe just go away?

Quoted 12 lines
drivers/input/lirc/commandir.c new file +12 -0
+int write_core(unsigned char *buffer, int count,
+	       void *callback_fct, int device_num)
+{
+	struct usb_skel *dev;
+	int retval = count;
+
+	struct usb_interface *interface;
+	struct urb *urb = NULL;
+	char *buf = NULL;
+	interface = usb_find_interface(&cmdir_driver,
+			USB_CMDIR_MINOR_BASE + device_num);
+	if (!interface) {

drivers/input/lirc/commandir.c line 907

Quoted 10 lines
drivers/input/lirc/commandir.c new file +10 -0
+		/* also check without adding base, for devfs */
+		interface = usb_find_interface(&cmdir_driver, device_num);
+		if (!interface)
+			return -ENODEV;
+	}
+	dev = usb_get_intfdata(interface);
+	if (!dev)
+		return -ENODEV;
+	/* create a urb, and a buffer for it, and copy the data to the urb */
+	urb = usb_alloc_urb(0, GFP_ATOMIC);	/* Now -=Atomic=- */

Why GFP_ATOMIC? Somehow the comment fails to shed much light.

drivers/input/lirc/commandir.h line 5

Quoted 11 lines
drivers/input/lirc/commandir.h new file +5 -0
new file mode 100644
index 0000000..bed703d
@@ -0,0 +1,68 @@
+/*
+ *  commandir.h
+ */
+
+#define ASCII0      48

'0' was too clear?

Quoted 11 lines
drivers/input/lirc/lirc_cmdir.c new file +4 -0
new file mode 100644
index 0000000..1faa8e3
@@ -0,0 +1,596 @@
 
+#ifndef MAX_UDELAY_MS
+#define MAX_UDELAY_US 5000
+#else
+#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)

drivers/input/lirc/lirc_cmdir.c line 93

Quoted 10 lines
drivers/input/lirc/lirc_cmdir.c new file +10 -0
+#endif
+
+static inline void safe_udelay(unsigned long usecs)
+{
+	while (usecs > MAX_UDELAY_US) {
+		udelay(MAX_UDELAY_US);
+		usecs -= MAX_UDELAY_US;
+	}
+	udelay(usecs);
+}

This looks like mdelay() in disguise? Perhaps something that sleeps would be even better (haven't looked at the calling context yet)?

drivers/input/lirc/lirc_cmdir.c line 153

Quoted 5 lines
drivers/input/lirc/lirc_cmdir.c new file +5 -0
+static int write_to_usb(unsigned char *buffer, int count, int time_elapsed)
+{
+	int write_return;
+
+	write_return = cmdir_write(buffer, count, NULL, time_elapsed);

Ah, this is why those functions are exported? Is there any reason not to just link the whole mess together into a single module?

Quoted 4 lines
drivers/input/lirc/lirc_cmdir.c new file +4 -0
+static int cmdir_convert_RX(unsigned char *orig_rxbuffer)
+{
+	unsigned char tmp_char_buffer[80];
+	unsigned int tmp_int_buffer[20];

drivers/input/lirc/lirc_cmdir.c line 199

Quoted 10 lines
drivers/input/lirc/lirc_cmdir.c new file +10 -0
+	unsigned int final_data_buffer[20];
+	unsigned int num_data_values = 0;
+	unsigned char num_data_bytes = 0;
+	unsigned int orig_index = 0;
+	int i;
+
+	for (i = 0; i < 80; i++)
+		tmp_char_buffer[i] = 0;
+	for (i = 0; i < 20; i++)
+		tmp_int_buffer[i] = 0;

Looks like memset() to me.

Quoted 16 lines
drivers/input/lirc/lirc_cmdir.c new file +16 -0
+	/*
+	 * get number of data bytes that follow the control bytes
+	 * (NOT including them)
+	 */
+	num_data_bytes = orig_rxbuffer[1];
+
+	/* check if num_bytes is multiple of 3; if not, error */
+	if (num_data_bytes % 3 > 0)
+		return -1;
+	if (num_data_bytes > 60)
+		return -3;
+	if (num_data_bytes < 3)
+		return -2;
+
+	/*
+	 * get number of ints to be returned; num_data_bytes does

drivers/input/lirc/lirc_cmdir.c line 226

Quoted 10 lines
drivers/input/lirc/lirc_cmdir.c new file +10 -0
+	 * NOT include control bytes
+	 */
+	num_data_values = num_data_bytes/3;
+
+	for (i = 0; i < num_data_values; i++) {
+		tmp_char_buffer[i*4] = orig_rxbuffer[(i+1)*3];
+		tmp_char_buffer[i*4+1] = orig_rxbuffer[(i+1)*3+1];
+		tmp_char_buffer[i*4+2] = 0;
+		tmp_char_buffer[i*4+3] = 0;
+	}

Hmm... num_data_bytes can be 60, so num_data values can be 20, so i*4+3 can be 83, you've just overflowed the buffer.

drivers/input/lirc/lirc_cmdir.c line 230

Quoted 3 lines
drivers/input/lirc/lirc_cmdir.c new file +3 -0
+	/* convert to int array */
+	memcpy((unsigned char *)tmp_int_buffer, tmp_char_buffer,
+						(num_data_values*4));

Hmm...I think there ought to be a better way. Even before considering endian problems.

Quoted 17 lines
drivers/input/lirc/lirc_cmdir.c new file +17 -0
+static ssize_t lirc_write(struct file *file, const char *buf,
+			 size_t n, loff_t *ppos)
+{
+	int i, count;
+	unsigned int mod_signal_length = 0;
+	unsigned int time_elapse = 0;
+	unsigned int total_time_elapsed = 0;
+	unsigned int num_bytes_already_sent = 0;
+	unsigned int hibyte = 0;
+	unsigned int lobyte = 0;
+	int cmdir_cnt = 0;
+	unsigned int wait_this = 0;
+	struct timeval start_time;
+	struct timeval end_time;
+	unsigned int real_time_elapsed = 0;
+
+	/* save the time we started the write: */

drivers/input/lirc/lirc_cmdir.c line 366

Quoted 10 lines
drivers/input/lirc/lirc_cmdir.c new file +10 -0
+	do_gettimeofday(&start_time);
+
+	if (n % sizeof(int))
+		return -EINVAL;
+
+	count = n / sizeof(int);
+	if (count > WBUF_LEN || count % 2 == 0)
+		return -EINVAL;
+	if (copy_from_user(wbuf, buf, n))
+		return -EFAULT;

That's a global buffer - what's protecting it from concurrent access?

[...]

Quoted 14 lines
drivers/input/lirc/lirc_cmdir.c new file +14 -0
+	 * we need to _manually delay ourselves_ to remain backwards
+	 * compatible with LIRC and prevent our queue buffer from overflowing.
+	 * Queuing in this driver is about instant, and send_start for example
+	 * will fill it up quickly and prevent send_stop from taking immediate
+	 * effect.
+	 */
+	dprintk("Total elapsed time is: %d. \n", total_time_elapsed);
+	do_gettimeofday(&end_time);
+	/*
+	 * udelay for the difference between endtime and
+	 * start + total_time_elapsed
+	 */
+	if (start_time.tv_usec < end_time.tv_usec)
+		real_time_elapsed = (end_time.tv_usec - start_time.tv_usec);

drivers/input/lirc/lirc_cmdir.c line 440

Quoted 10 lines
drivers/input/lirc/lirc_cmdir.c new file +10 -0
+	else
+		real_time_elapsed = ((end_time.tv_usec +  1000000) -
+							start_time.tv_usec);
+	dprintk("Real time elapsed was %u.\n", real_time_elapsed);
+	if (real_time_elapsed < (total_time_elapsed - 1000))
+		wait_this = total_time_elapsed - real_time_elapsed - 1000;
+
+#if 0 /* enable this for backwards compatibility */
+	safe_udelay(wait_this);
+#endif

I assume that compatibility is not needed now? In that case, this code (and safe_udelay()) can go away.

jon

#27 lore raw

Re: [PATCH 07/18] lirc driver for the CommandIR USB Transceiver

Hi,

there is a user-space driver that is going to replace the kernel driver for the CommandIR driver. I don't think there is a reason anymore to get this driver into the kernel.
Added, Matthew.

Christoph

A message that is not in the archive (sent off-list or not yet received): 1221159005.13683.34.camel@minimatt

#29 lore raw

Re: [PATCH 07/18] lirc driver for the CommandIR USB Transceiver

Quoted 8 lines · On Thursday 11 September 2008 14:50:05 Matthew Bodkin wrote:

Hi Christoph, All -

True, I added a 'commandir' userspace driver a couple months ago that replaces the kernel 'lirc_cmdir' driver.

However the userspace driver remains unreleased in CVS so until there is a new LIRC release, I think the include the old kernel driver will have to be included.

I thought I remembered something about a userspace driver... Don't worry about whether or not its released in an lirc tarball though. The code headed to the kernel is cvs head based already.

I take it the userspace driver is the commandir.{c,h} bits vs. the old lirc_cmdir.{c,h} bits being the old driver. D'oh. Its been sitting right under my nose... So yeah, we'll drop the lirc_cmdir bits, and roll with just the commandir bits.

Side bar: wish I'd had more time to read over *all* the code, rather than focusing so much on just the checkpatch cleanups, but I think it was better to get this out here and get some momentum built up anyhow...

Quoted 1 line

Demo hardware is available for testing if anyone wants.

That would be most excellent. I'd definitely love to get some, will drop you a line off-list.

Quoted 9 lines · Christoph Bartelmus
Quoted 8 lines

Hi,

there is a user-space driver that is going to replace the kernel driver for the CommandIR driver. I don't think there is a reason anymore to get this driver into the kernel.
Added, Matthew.

Christoph

Signature · 2 lines
Jarod Wilson
[email protected]
#30 lore raw

Re: [PATCH 07/18] lirc driver for the CommandIR USB Transceiver

In reply to a message not in the archive

Hi,

Quoted 7 lines · On Thursday 11 September 2008 20:50:05 Matthew Bodkin wrote:

True, I added a 'commandir' userspace driver a couple months ago that replaces the kernel 'lirc_cmdir' driver.

However the userspace driver remains unreleased in CVS so until there is a new LIRC release, I think the include the old kernel driver will have to be included.

It doesn't make sense to spend considerible effort cleaning the driver up for kernel inclusion if a user space driver exist in licr cvs.

Janne

#31 lore raw

Re: [PATCH 07/18] lirc driver for the CommandIR USB Transceiver

In reply to Jonathan Corbet
Quoted 4 lines · Jonathan Corbet

This driver has real locking problems. Parts of it depend on the BKL, but I would have a hard time arguing for the addition of new BKL users in this century. The assumption that ->open() is called under the BKL no longer holds. It's really time to put a proper lock here.

The kernel-space drivers for CommandIR devices are being dropped entirely, in favor of the new userspace driver for it, which is included in the lirc 0.8.4pre1 userspace.

Signature · 2 lines
Jarod Wilson
[email protected]
#32 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

In reply to Jarod Wilson

drivers/input/lirc/Kconfig config LIRC_DEV · line 27

Quoted 7 lines · Jarod Wilson
drivers/input/lirc/Kconfig +7 -0
+config LIRC_ATIUSB
+	tristate "ATI RF USB Receiver support"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the ATI USB RF remote receiver
+

We already have proper input drivers for these devices (ati_remote and ati_remote2).

Signature · 3 lines
Ville Syrjälä
[email protected]
http://www.sci.fi/~syrjala/
#33 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

Quoted 11 lines · On Wednesday 10 September 2008 05:58:32 Ville Syrjälä wrote:

drivers/input/lirc/Kconfig config LIRC_DEV · line 27

Quoted 7 lines · Jarod Wilson
drivers/input/lirc/Kconfig +7 -0
+config LIRC_ATIUSB
+	tristate "ATI RF USB Receiver support"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the ATI USB RF remote receiver
+

We already have proper input drivers for these devices (ati_remote and ati_remote2).

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

http://evuraan.blogspot.com/2008/01/how-to-use-ati-remote-wonder-ii-
remote.html

Signature · 2 lines
Jarod Wilson
[email protected]
#34 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

Quoted 5 lines · Jarod Wilson

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

Bad idea to have two drivers for the same piece of hardware. And this gets straight back into the why should lirc be different from the input layer point raised earlies. I think we really shouldn't keep lirc as a separate subsystem, but make sure all the drivers are written to the input layer. To make the migration easier for exiting users we could add a /dev/lirc driver ontop of the input layer, similar to how the ps2 mouse and joystick drivers sit ontop of the input core.

#35 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Jarod Wilson

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

Quoted 7 lines

Bad idea to have two drivers for the same piece of hardware. And this
gets straight back into the why should lirc be different from the input layer point raised earlies. I think we really shouldn't keep lirc as a separate subsystem, but make sure all the drivers are written to the input layer. To make the migration easier for exiting users we could add a /dev/lirc driver ontop of the input layer, similar to how the ps2 mouse and joystick drivers sit ontop of the input core.

There have been concerns on the lirc list that integrating with the input core would mean that the kernel has to translate from the lirc timing data to key strokes. Keyboards do their translation in user space, lirc can do the same, right? User space app receives lirc event and then calls a translation library function.

A second issue is that some IR drivers are completely in user space. Is there a mechanism for these user space drivers to send events down into the input layer? These events would then get queued with the other kernel generated events and be delivered to consuming apps in order.

Quoted 8 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Jon Smirl
[email protected]
maintainer
#36 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

Quoted 6 lines · Jon Smirl

A second issue is that some IR drivers are completely in user space. Is there a mechanism for these user space drivers to send events down into the input layer? These events would then get queued with the other kernel generated events and be delivered to consuming apps in order.

Uinput driver (/dev/uinput, drivers/input/misc/uinput.c) can be used to inject events into kernel for subsequent distribution through normal interfaces (console, evdev, etc).

Signature · 1 line
Dmitry
#37 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

In reply to Christoph Hellwig
Quoted 8 lines · On Wednesday 10 September 2008 15:14:32 Christoph Hellwig wrote:
Quoted 6 lines · Jarod Wilson

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

Quoted 5 lines

Bad idea to have two drivers for the same piece of hardware. And this gets straight back into the why should lirc be different from the input layer point raised earlies. I think we really shouldn't keep lirc as a separate subsystem, but make sure all the drivers are written to the input layer.

Some drivers don't report events but deliver the signal to the lirc daemon. The daemon decodes the signal. Decoding of several IR protocols and mapping of each possible remote to events are things much easier done in userspace.
Aslo LIRC is not only about IR input but also output.

See following mail from Christoph Bertelmus for more details.
http://sourceforge.net/mailarchive/message.php?msg_id=AAryKgq9UOB%40bartelmus.de

Quoted 2 lines

To make the migration easier for exiting
users we could add a /dev/lirc driver ontop of the input layer,

This shouldn't be necessary since the lirc daemon can already read from input devices.

Janne

#38 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

Quoted 21 lines · On Wednesday 10 September 2008 09:44:17 Janne Grunau wrote:
Quoted 8 lines · On Wednesday 10 September 2008 15:14:32 Christoph Hellwig wrote:
Quoted 6 lines · Jarod Wilson

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

Quoted 5 lines

Bad idea to have two drivers for the same piece of hardware. And this gets straight back into the why should lirc be different from the input layer point raised earlies. I think we really shouldn't keep lirc as a separate subsystem, but make sure all the drivers are written to the input layer.

Some drivers don't report events but deliver the signal to the lirc daemon. The daemon decodes the signal. Decoding of several IR protocols and mapping of each possible remote to events are things much easier done in userspace.
Aslo LIRC is not only about IR input but also output.

Quoted 3 lines

See following mail from Christoph Bertelmus for more details.
http://sourceforge.net/mailarchive/message.php?msg_id=AAryKgq9UOB%40bartelm
us.de

Yeah, I think that pretty well covers the issues.

Quoted 5 lines
Quoted 2 lines

To make the migration easier for exiting
users we could add a /dev/lirc driver ontop of the input layer,

This shouldn't be necessary since the lirc daemon can already read from input devices.

Okay, so what I'm hearing and thinking is that we should at drop lirc_atiusb from consideration for inclusion, and instead extend ati_remote{,2} as/if necessary to be able to let the lirc daemon use it via the provided input device, so people can get the best of both worlds (it behaves like a keyboard if so configured, talks to lircd if so configured).

Signature · 2 lines
Jarod Wilson
[email protected]
#39 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

In reply to Janne Grunau
Quoted 15 lines · Janne Grunau
Quoted 8 lines · On Wednesday 10 September 2008 15:14:32 Christoph Hellwig wrote:
Quoted 6 lines · Jarod Wilson

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

Quoted 5 lines

Bad idea to have two drivers for the same piece of hardware. And this gets straight back into the why should lirc be different from the input layer point raised earlies. I think we really shouldn't keep lirc as a separate subsystem, but make sure all the drivers are written to the input layer.

Quoted 4 lines

Some drivers don't report events but deliver the signal to the lirc daemon. The daemon decodes the signal. Decoding of several IR protocols and mapping of each possible remote to events are things much easier done in userspace.

Mixing these two in the same interface seems like a really bad idea. The input layer is the right interface for devices that directly produce events. If you want to decode them in userspace you need a different interface for the daemon. Not sure why you really want to do this in userspace, though.

Quoted 1 line

Aslo LIRC is not only about IR input but also output.

The input layer also does some outputs, like the pc speaker :)

#40 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

In reply to Jarod Wilson
Quoted 13 lines · Jarod Wilson
Quoted 11 lines · On Wednesday 10 September 2008 05:58:32 Ville Syrjälä wrote:

drivers/input/lirc/Kconfig config LIRC_DEV · line 27

Quoted 7 lines · Jarod Wilson
drivers/input/lirc/Kconfig +7 -0
+config LIRC_ATIUSB
+	tristate "ATI RF USB Receiver support"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the ATI USB RF remote receiver
+

We already have proper input drivers for these devices (ati_remote and ati_remote2).

Quoted 8 lines

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

http://evuraan.blogspot.com/2008/01/how-to-use-ati-remote-wonder-ii-
remote.html

The X11 limitations are unfortunate but they can be worked around with keymap support in the kernel driver. ati_remote2 keymap patch is somewhere on it's way upstream as we speak. Not sure about ati_remote though.

Furthermore if lirc can already handle input from event devices then the lirc_atiusb drivers are simply not needed.

Signature · 3 lines
Ville Syrjälä
[email protected]
http://www.sci.fi/~syrjala/
maintainer
#41 lore raw

Re: [PATCH 06/18] lirc driver for the ATI USB RF remote receiver

Quoted 20 lines · Ville Syrjälä
Quoted 19 lines · Jarod Wilson
Quoted 11 lines · On Wednesday 10 September 2008 05:58:32 Ville Syrjälä wrote:

drivers/input/lirc/Kconfig config LIRC_DEV · line 27

Quoted 7 lines · Jarod Wilson
drivers/input/lirc/Kconfig +7 -0
+config LIRC_ATIUSB
+	tristate "ATI RF USB Receiver support"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the ATI USB RF remote receiver
+

We already have proper input drivers for these devices (ati_remote and ati_remote2).

True, though I think some users still prefer using them with the lirc drivers for assorted reasons. Configuring something like mythtv to work with the ati_remote{,2} driver appears to be a bit more complex (or at least non- standard vs. several other popular remotes) and not as functional vs. configuring mythtv w/lirc_atiusb.

Quoted 5 lines
Quoted 2 lines

http://evuraan.blogspot.com/2008/01/how-to-use-ati-remote-wonder-ii-
remote.html

The X11 limitations are unfortunate but they can be worked around with keymap support in the kernel driver.

X's evdev support is also maturing and hopefully hotplug support will be implemented soon.

Quoted 3 lines

ati_remote2 keymap patch is somewhere
on it's way upstream as we speak. Not sure about ati_remote though.

Yeah, its in my "next" branch, waiting for .28 to open.

Quoted 12 lines

Furthermore if lirc can already handle input from event devices then the lirc_atiusb drivers are simply not needed.

Signature · 8 lines
Ville Syrjälä
[email protected]
http://www.sci.fi/~syrjala/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Dmitry
#42 lore raw

Re: [PATCH 05/18] lirc driver for i2c-based IR receivers

In reply to Jarod Wilson
Quoted 5 lines · On Tuesday 09 September 2008 00:05:50 Jarod Wilson wrote:

Successfully tested with the IR interface on a Hauppauge PVR-250 and the flimsly little grey remote that shipped with it.

Knew I had to screw up at least one thing. That should be [email protected], not jannua.net.

Signature · 2 lines
Jarod Wilson
[email protected]
#43 lore raw

Re: [PATCH 05/18] lirc driver for i2c-based IR receivers

In reply to Jarod Wilson

drivers/input/lirc/Kconfig config LIRC_DEV · line 27

Quoted 7 lines
drivers/input/lirc/Kconfig +7 -0
+config LIRC_I2C
+	tristate "I2C Based IR Receivers"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for I2C-based IR receivers, such as those commonly
+	  found onboard Hauppauge PVR-150/250/350 video capture cards

This driver offers relatively few things to gripe about. But I'm not one to shrink from a challenge...

Quoted 1 line

+#include <linux/semaphore.h>

It looks like this driver is semaphore-free? Actually, it looks kind of lock-free in general. That's probably my biggest concern; what is protecting against concurrent operations on the device?

Quoted 13 lines
drivers/input/lirc/lirc_i2c.c new file +13 -0
+static int add_to_buf_pcf8574(void *data, struct lirc_buffer *buf)
+{
+	struct IR *ir = data;
+	int rc;
+	unsigned char all, mask;
+	unsigned char key;
+
+	/* compute all valid bits (key code + pressed/release flag) */
+	all = ir->bits | ir->flag;
+
+	/* save IR writable mask bits */
+	mask = i2c_smbus_read_byte(&ir->c) & ~all;
+

drivers/input/lirc/lirc_i2c.c line 144

Quoted 10 lines
drivers/input/lirc/lirc_i2c.c new file +10 -0
+	/* send bit mask */
+	rc = i2c_smbus_write_byte(&ir->c, (0xff & all) | mask);
+
+	/* receive scan code */
+	rc = i2c_smbus_read_byte(&ir->c);
+
+	if (rc == -1) {
+		dprintk("%s read error\n", ir->c.name);
+		return -EIO;
+	}

This ignores the return value from the first i2c_smbus_read_byte() and i2c_smbus_write_byte() calls. Beyond that, i2c_smbus_read_byte() can return -EANYTHING, so I think the check should be "rc < 0", no? Tests against -1 are common in this driver, I'll not point them all out.

Quoted 3 lines
drivers/input/lirc/lirc_i2c.c new file +3 -0
+static int ir_attach(struct i2c_adapter *adap, int addr,
+		     unsigned short flags, int kind)
+{

...

drivers/input/lirc/lirc_i2c.c line 465

Quoted 4 lines
drivers/input/lirc/lirc_i2c.c new file +4 -0
+	ir->l.minor = lirc_register_plugin(&ir->l);
+
+	return 0;
+}

The lirc_register_plugin() call can fail, the result should be checked.

drivers/input/lirc/lirc_i2c.c line 612

Quoted 11 lines
drivers/input/lirc/lirc_i2c.c new file +11 -0
+#ifdef MODULE
+
+int init_module(void)
+{
+	request_module("bttv");
+	request_module("rivatv");
+	request_module("ivtv");
+	request_module("cx8800");
+	i2c_add_driver(&driver);
+	return 0;
+}

Why are all these modules being loaded here? That would seem like a job for udev.

jon

#44 lore raw

Re: [PATCH 04/18] lirc driver for 2nd-gen and later Media Center Ed. USB IR transceivers

In reply to Jarod Wilson
Quoted 8 lines · On Tue, 9 Sep 2008 00:05:49 -0400 Jarod Wilson <[email protected]> wrote:

+/*
+ * LIRC driver for Philips eHome USB Infrared Transceiver
+ * and the Microsoft MCE 2005 Remote Control
+ *
+ * (C) by Martin A. Blatter <[email protected]>
+ *
+ * Transmitter support and reception code cleanup.
+ * (C) by Daniel Melander <[email protected]>

As I understand it, proper assertions of copyright need the word "copyright" and a year; the "(C)" trigraph doesn't have any legal meaning.

Quoted 4 lines

+ * This driver will only work reliably with kernel version 2.6.10
+ * or higher, probably because of differences in USB device enumeration
+ * in the kernel code. Device initialization fails most of the time
+ * with earlier kernel versions.

My guess is that this will not be a major impediment to mainline inclusion; this comment can probably go.

drivers/input/lirc/lirc_mceusb2.c line 97

Quoted 3 lines
drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+/* lock irctl structure */
+#define IRLOCK		mutex_lock(&ir->lock)
+#define IRUNLOCK	mutex_unlock(&ir->lock)

Might I request that these go away? They can only obfuscate the code.

drivers/input/lirc/lirc_mceusb2.c line 244

Quoted 7 lines
drivers/input/lirc/lirc_mceusb2.c new file +7 -0
+/* init strings */
+static char init1[] = {0x00, 0xff, 0xaa, 0xff, 0x0b};
+static char init2[] = {0xff, 0x18};
+
+static char pin_init1[] = { 0x9f, 0x07};
+static char pin_init2[] = { 0x9f, 0x13};
+static char pin_init3[] = { 0x9f, 0x0d};

Documentation here would be nice; what do these magic numbers do?

drivers/input/lirc/lirc_mceusb2.c line 287

Quoted 4 lines
drivers/input/lirc/lirc_mceusb2.c new file +4 -0
+/* request incoming or send outgoing usb packet - used to initialize remote */
+static void request_packet_async(struct irctl *ir,
+				 struct usb_endpoint_descriptor *ep,
+				 unsigned char *data, int size, int urb_type)

What is the locking regime for this function? As far as I can tell, it's called with no locking at all, even though it's manipulating the irctl structure.

Quoted 1 line

+{

...

drivers/input/lirc/lirc_mceusb2.c line 307

Quoted 9 lines
drivers/input/lirc/lirc_mceusb2.c new file +9 -0
+				if (urb_type == PHILUSB_OUTBOUND) {
+					/* outbound data */
+					usb_fill_int_urb(async_urb, ir->usbdev,
+						usb_sndintpipe(ir->usbdev,
+							ep->bEndpointAddress),
+					async_buf,
+					size,
+					(usb_complete_t) usb_async_callback,
+					ir, ep->bInterval);

This kind of formatting suggests that, just maybe, the control structures in this function have been nested too deeply.

Quoted 17 lines
drivers/input/lirc/lirc_mceusb2.c new file +17 -0
+static int unregister_from_lirc(struct irctl *ir)
+{
+	struct lirc_plugin *p = ir->p;
+	int devnum;
+	int rtn;
+
+	devnum = ir->devnum;
+	dprintk(DRIVER_NAME "[%d]: unregister from lirc called\n", devnum);
+
+	rtn = lirc_unregister_plugin(p->minor);
+	if (rtn > 0) {
+		printk(DRIVER_NAME "[%d]: error in lirc_unregister minor: %d\n"
+			"Trying again...\n", devnum, p->minor);
+		if (rtn == -EBUSY) {
+			printk(DRIVER_NAME
+				"[%d]: device is opened, will unregister"
+				" on close\n", devnum);

drivers/input/lirc/lirc_mceusb2.c line 371

Quoted 10 lines
drivers/input/lirc/lirc_mceusb2.c new file +10 -0
+			return -EAGAIN;
+		}
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(HZ);
+
+		rtn = lirc_unregister_plugin(p->minor);
+		if (rtn > 0)
+			printk(DRIVER_NAME "[%d]: lirc_unregister failed\n",
+			devnum);
+	}

Looking at lirc_unregister_plugin(), I don't see any cause of failure that could be expected to go away one second later. But this code has the look of something somebody actually needed once upon a time. Am I missing something? It seems there should be a better way.

Quoted 25 lines
drivers/input/lirc/lirc_mceusb2.c new file +25 -0
+static int set_use_inc(void *data)
+{
+	struct irctl *ir = data;
+
+	if (!ir) {
+		printk(DRIVER_NAME "[?]: set_use_inc called with no context\n");
+		return -EIO;
+	}
+	dprintk(DRIVER_NAME "[%d]: set use inc\n", ir->devnum);
+
+	if (!ir->flags.connected) {
+		if (!ir->usbdev)
+			return -ENOENT;
+		ir->flags.connected = 1;
+	}
+
+	return SUCCESS;
+}
+
+static void set_use_dec(void *data)
+{
+	struct irctl *ir = data;
+
+	if (!ir) {
+		printk(DRIVER_NAME "[?]: set_use_dec called with no context\n");

drivers/input/lirc/lirc_mceusb2.c line 421

Quoted 10 lines
drivers/input/lirc/lirc_mceusb2.c new file +10 -0
+		return;
+	}
+	dprintk(DRIVER_NAME "[%d]: set use dec\n", ir->devnum);
+
+	if (ir->flags.connected) {
+		IRLOCK;
+		ir->flags.connected = 0;
+		IRUNLOCK;
+	}
+}

One function sets ir->flags.connected under lock, the other does not. Is that what was intended?

Also, set_use_inc() is returning a normal zero-or-negative-error status to an outside caller. It shouldn't return a locally-defined symbol like SUCCESS. I'd just use "return 0;".

drivers/input/lirc/lirc_mceusb2.c line 566

Quoted 9 lines
drivers/input/lirc/lirc_mceusb2.c new file +9 -0
+static ssize_t lirc_write(struct file *file, const char *buf,
+			  size_t n, loff_t *ppos)
+{
+	int i, count = 0, cmdcount = 0;
+	struct irctl *ir = NULL;
+	int wbuf[LIRCBUF_SIZE]; /* Workbuffer with values from lirc */
+	unsigned char cmdbuf[MCE_CMDBUF_SIZE]; /* MCE command buffer */
+	unsigned long signal_duration = 0; /* Singnal length in us */
+	struct timeval start_time, end_time;

That looks like roughly 1400 bytes on the stack - on a 32-bit system.

[...]

drivers/input/lirc/lirc_mceusb2.c line 639

Quoted 3 lines
drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+	/* delay with the closest number of ticks */
+	set_current_state(TASK_INTERRUPTIBLE);
+	schedule_timeout(usecs_to_jiffies(signal_duration));

Why do you need to delay here? And wouldn't something like msleep() be a better way to do it?

lirc_write() seems short on locking.

drivers/input/lirc/lirc_mceusb2.c line 650

Quoted 7 lines
drivers/input/lirc/lirc_mceusb2.c new file +7 -0
+static void set_transmitter_mask(struct irctl *ir, unsigned int mask)
+{
+	if (ir->flags.transmitter_mask_inverted)
+		ir->transmitter_mask = (mask != 0x03 ? mask ^ 0x03 : mask) << 1;
+	else
+		ir->transmitter_mask = mask;
+}

What this short function is doing is not entirely obvious to me.

drivers/input/lirc/lirc_mceusb2.c line 658

Quoted 6 lines
drivers/input/lirc/lirc_mceusb2.c new file +6 -0
+/* Sets the send carrier frequency */
+static int set_send_carrier(struct irctl *ir, int carrier)
+{
+	int clk = 10000000;
+	int prescaler = 0, divisor = 0;
+	unsigned char cmdbuf[] = { 0x9F, 0x06, 0x01, 0x80 };

And this sequence of magic numbers does...?

Quoted 63 lines
drivers/input/lirc/lirc_mceusb2.c new file +63 -0
+static int lirc_ioctl(struct inode *node, struct file *filep,
+		      unsigned int cmd, unsigned long arg)
+{
+	int result;
+	unsigned int ivalue;
+	unsigned long lvalue;
+	struct irctl *ir = NULL;
+
+	/* Retrieve lirc_plugin data for the device */
+	ir = lirc_get_pdata(filep);
+	if (!ir && !ir->usb_ep_out)
+		return -EFAULT;
+
+
+	switch (cmd) {
+	case LIRC_SET_TRANSMITTER_MASK:
+
+		result = get_user(ivalue, (unsigned int *) arg);
+		if (result)
+			return result;
+		switch (ivalue) {
+		case 0x01: /* Transmitter 1     => 0x04 */
+		case 0x02: /* Transmitter 2     => 0x02 */
+		case 0x03: /* Transmitter 1 & 2 => 0x06 */
+			set_transmitter_mask(ir, ivalue);
+			break;
+
+		default: /* Unsupported transmitter mask */
+			return MCE_MAX_CHANNELS;
+		}
+
+		dprintk(DRIVER_NAME ": SET_TRANSMITTERS mask=%d\n", ivalue);
+		break;
+
+	case LIRC_GET_SEND_MODE:
+
+		result = put_user(LIRC_SEND2MODE(LIRC_CAN_SEND_PULSE &
+						 LIRC_CAN_SEND_MASK),
+				  (unsigned long *) arg);
+
+		if (result)
+			return result;
+		break;
+
+	case LIRC_SET_SEND_MODE:
+
+		result = get_user(lvalue, (unsigned long *) arg);
+
+		if (result)
+			return result;
+		if (lvalue != (LIRC_MODE_PULSE&LIRC_CAN_SEND_MASK))
+			return -EINVAL;
+		break;
+
+	case LIRC_SET_SEND_CARRIER:
+
+		result = get_user(ivalue, (unsigned int *) arg);
+		if (result)
+			return result;
+
+		set_send_carrier(ir, ivalue);
+		break;
+

drivers/input/lirc/lirc_mceusb2.c line 772

Quoted 10 lines
drivers/input/lirc/lirc_mceusb2.c new file +10 -0
+	default:
+		return -ENOIOCTLCMD;
+	}
+
+	return 0;
+}
+
+static struct file_operations lirc_fops = {
+	.write	= lirc_write,
+};

My first reaction here was that .ioctl=lirc_ioctl is missing. But, of course, it's the plugin ioctl() function instead. I still think that needs some cleaning up.

Quoted 3 lines
drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+static int usb_remote_probe(struct usb_interface *intf,
+				const struct usb_device_id *id)
+{

[...]

Quoted 11 lines
drivers/input/lirc/lirc_mceusb2.c new file +11 -0
+mem_failure_switch:
+
+	/* free allocated memory incase of failure */
+	switch (mem_failure) {
+	case 9:
+		usb_free_urb(ir->urb_in);
+	case 7:
+		usb_buffer_free(dev, maxp, ir->buf_in, ir->dma_in);
+	case 5:
+		lirc_buffer_free(rbuf);
+	case 4:

drivers/input/lirc/lirc_mceusb2.c line 945

Quoted 10 lines
drivers/input/lirc/lirc_mceusb2.c new file +10 -0
+		kfree(rbuf);
+	case 3:
+		kfree(plugin);
+	case 2:
+		kfree(ir);
+	case 1:
+		printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
+			devnum, mem_failure);
+		return -ENOMEM;
+	}

Usually this kind of error recovery is handled at the end of the function with a series of cascading goto labels. To find it wedged into the middle of this (very long) function as a switch is a bit disorienting. Normal execution will just route around the whole thing via the (missing) default branch. I think it would be better to put it at the end and use the normal conventions that everybody knows how to read.

drivers/input/lirc/lirc_mceusb2.c line 955

Quoted 9 lines
drivers/input/lirc/lirc_mceusb2.c new file +9 -0
+	plugin->minor = minor;
+	ir->p = plugin;
+	ir->devnum = devnum;
+	ir->usbdev = dev;
+	ir->len_in = maxp;
+	ir->flags.connected = 0;
+	ir->flags.pinnacle = is_pinnacle;
+	ir->flags.transmitter_mask_inverted =
+		usb_match_id(intf, transmitter_mask_list) ? 0 : 1;

At this point, the plugin is already registered, but you're still initializing it. Are you sure there's no potential for a race here?

drivers/input/lirc/lirc_mceusb2.c line 1085

Quoted 3 lines
drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+#ifdef MODULE
+static int __init usb_remote_init(void)
+{

I'm curious: you don't need to initialize if not compiled as a module?

drivers/input/lirc/lirc_mceusb2.c line 1093

Quoted 8 lines
drivers/input/lirc/lirc_mceusb2.c new file +8 -0
+	int i;
+
+	printk(KERN_INFO "\n");
+	printk(KERN_INFO DRIVER_NAME ": " DRIVER_DESC " " DRIVER_VERSION "\n");
+	printk(KERN_INFO DRIVER_NAME ": " DRIVER_AUTHOR "\n");
+	dprintk(DRIVER_NAME ": debug mode enabled\n");
+
+	request_module("lirc_dev");

You're calling functions from lirc_dev.c, so modprobe will not load this module until lirc_dev is already there. There's no point in trying to load it explicitly with request_module().

drivers/input/lirc/lirc_mceusb2.c line 1102

Quoted 8 lines
drivers/input/lirc/lirc_mceusb2.c new file +8 -0
+	i = usb_register(&usb_remote_driver);
+	if (i < 0) {
+		printk(DRIVER_NAME ": usb register failed, result = %d\n", i);
+		return -ENODEV;
+	}
+
+	return SUCCESS;
+}

"return 0;" please.

jon

#45 lore raw

Re: [PATCH 04/18] lirc driver for 2nd-gen and later Media Center Ed. USB IR transceivers

Quoted 12 lines · On Wednesday 10 September 2008 01:30:57 Jonathan Corbet wrote:

On Tue, 9 Sep 2008 00:05:49 -0400

Quoted 8 lines · Jarod Wilson

+/*
+ * LIRC driver for Philips eHome USB Infrared Transceiver
+ * and the Microsoft MCE 2005 Remote Control
+ *
+ * (C) by Martin A. Blatter <[email protected]>
+ *
+ * Transmitter support and reception code cleanup.
+ * (C) by Daniel Melander <[email protected]>

Quoted 3 lines

As I understand it, proper assertions of copyright need the word "copyright" and a year; the "(C)" trigraph doesn't have any legal meaning.

Depends on the country. I won't touch copyright notices or attributions.

Quoted 7 lines
Quoted 4 lines

+ * This driver will only work reliably with kernel version 2.6.10
+ * or higher, probably because of differences in USB device enumeration + * in the kernel code. Device initialization fails most of the time + * with earlier kernel versions.

My guess is that this will not be a major impediment to mainline inclusion; this comment can probably go.

Already removed.

Quoted 6 lines

drivers/input/lirc/lirc_mceusb2.c line 97

Quoted 3 lines
drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+/* lock irctl structure */
+#define IRLOCK		mutex_lock(&ir->lock)
+#define IRUNLOCK	mutex_unlock(&ir->lock)

Might I request that these go away? They can only obfuscate the code.

yes, I will manually expand similar macros in the other drivers too.

Quoted 3 lines

Also, set_use_inc() is returning a normal zero-or-negative-error status to an outside caller. It shouldn't return a locally-defined symbol like SUCCESS. I'd just use "return 0;".

fixed

Quoted 6 lines

drivers/input/lirc/lirc_mceusb2.c line 1085

Quoted 3 lines
drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+#ifdef MODULE
+static int __init usb_remote_init(void)
+{

I'm curious: you don't need to initialize if not compiled as a module?

Already fixed in all drivers, relict from out of tree lirc.

Quoted 4 lines
Quoted 4 lines
drivers/input/lirc/lirc_mceusb2.c new file +4 -0
+	int i;
+
+	printk(KERN_INFO "\n");
+	printk(KERN_INFO DRIVER_NAME ": " DRIVER_DESC " " DRIVER_VERSION
Quoted 8 lines

drivers/input/lirc/lirc_mceusb2.c line 1093

Quoted 4 lines

"\n"); + printk(KERN_INFO DRIVER_NAME ": " DRIVER_AUTHOR "\n");

drivers/input/lirc/lirc_mceusb2.c new file +3 -0
+	dprintk(DRIVER_NAME ": debug mode enabled\n");
+
+	request_module("lirc_dev");

You're calling functions from lirc_dev.c, so modprobe will not load this module until lirc_dev is already there. There's no point in trying to load it explicitly with request_module().

True, request_module("lirc_dev"); removed from all drivers.

Quoted 10 lines

drivers/input/lirc/lirc_mceusb2.c line 1102

Quoted 8 lines
drivers/input/lirc/lirc_mceusb2.c new file +8 -0
+	i = usb_register(&usb_remote_driver);
+	if (i < 0) {
+		printk(DRIVER_NAME ": usb register failed, result = %d\n", i);
+		return -ENODEV;
+	}
+
+	return SUCCESS;
+}

"return 0;" please.

fixed for all drivers

Janne

#46 lore raw

Re: [PATCH 04/18] lirc driver for 2nd-gen and later Media Center Ed. USB IR transceivers

In reply to Jonathan Corbet
Quoted 12 lines · Jonathan Corbet
Quoted 8 lines · On Tue, 9 Sep 2008 00:05:49 -0400 Jarod Wilson <[email protected]> wrote:

+/*
+ * LIRC driver for Philips eHome USB Infrared Transceiver
+ * and the Microsoft MCE 2005 Remote Control
+ *
+ * (C) by Martin A. Blatter <[email protected]>
+ *
+ * Transmitter support and reception code cleanup.
+ * (C) by Daniel Melander <[email protected]>

Quoted 3 lines

As I understand it, proper assertions of copyright need the word "copyright" and a year; the "(C)" trigraph doesn't have any legal meaning.
...

As far as I understand it your statement is only true if you are in the USA and travel back in time by at least 20 years, and otherwise no proper assertion is required at all.

Anything I miss?

Quoted 1 line

jon

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#47 lore raw

Re: [PATCH 03/18] lirc driver for 1st-gen Media Center Ed. USB IR transceivers

In reply to Jarod Wilson

drivers/input/lirc/Kconfig config LIRC_DEV · line 26

Quoted 6 lines
drivers/input/lirc/Kconfig +6 -0
+config LIRC_MCEUSB
+	tristate "Microsoft Media Center Ed. Receiver, v1"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for the Microsoft Media Center Ed. Receiver, v1

A little more verbosity in these help texts might be nice.

Quoted 11 lines

+ * 2003_11_11 - Restructured to minimalize code interpretation in the
+ * driver. The normal use case will be with lirc.
+ *
+ * 2004_01_01 - Removed all code interpretation. Generate mode2 data
+ * for passing off to lirc. Cleanup
+ *
+ * 2004_01_04 - Removed devfs handle. Put in a temporary workaround
+ * for a known issue where repeats generate two
+ * sequential spaces (last_was_repeat_gap)
+ *
+ * 2004_02_17 - Changed top level api to no longer use fops, and

Quoted 8 lines
+ *	      instead use new interface for polling via
+ *	      lirc_thread. Restructure data read/mode2 generation to
+ *	      a single pass, reducing number of buffers. Rev to .2
+ *
+ * 2004_02_27 - Last of fixups to plugin->add_to_buf API. Properly
+ *	      handle broken fragments from the receiver. Up the
+ *	      sample rate and remove any pacing from
+ *	      fetch_more_data. Fixes all known issues.

General convention is that this sort of changelog information belongs in the SCM, not in the code. That's doubly true for the USB skeleton driver info.

Quoted 1 line

+#include <linux/smp_lock.h>

It doesn't look like this include is needed.

drivers/input/lirc/lirc_mceusb.c line 139

Quoted 2 lines
drivers/input/lirc/lirc_mceusb.c new file +2 -0
+/* Structure to hold all of our device specific stuff */
+struct usb_skel {

Perhaps renaming this structure to something more directly descriptive would make sense?

drivers/input/lirc/lirc_mceusb.c line 142

Quoted 3 lines
drivers/input/lirc/lirc_mceusb.c new file +3 -0
+	struct usb_device *udev; /* save off the usb device pointer */
+	struct usb_interface *interface; /* the interface for this device */
+	unsigned char minor;	 /* the starting minor number for this device */

Minor numbers don't necessarily fit in an unsigned char.

Quoted 10 lines
drivers/input/lirc/lirc_mceusb.c new file +10 -0
+	unsigned char num_ports; /* the number of ports this device has */
+	char num_interrupt_in;	 /* number of interrupt in endpoints */
+	char num_bulk_in;	 /* number of bulk in endpoints */
+	char num_bulk_out;	 /* number of bulk out endpoints */
+
+	unsigned char *bulk_in_buffer;	/* the buffer to receive data */
+	int bulk_in_size;		/* the size of the receive buffer */
+	__u8 bulk_in_endpointAddr;	/* the address of bulk in endpoint */
+
+	unsigned char *bulk_out_buffer;	/* the buffer to send data */

drivers/input/lirc/lirc_mceusb.c line 162

Quoted 10 lines
drivers/input/lirc/lirc_mceusb.c new file +10 -0
+	int bulk_out_size;		/* the size of the send buffer */
+	struct urb *write_urb;		/* the urb used to send data */
+	__u8 bulk_out_endpointAddr;	/* the address of bulk out endpoint */
+
+	atomic_t write_busy;		/* true iff write urb is busy */
+	struct completion write_finished; /* wait for the write to finish */
+
+	wait_queue_head_t wait_q; /* for timeouts */
+	int open_count;		/* number of times this port has been opened */
+	struct mutex sem;	/* locks this structure */

"sem" is not a semaphore; it should probably have a different name.

drivers/input/lirc/lirc_mceusb.c line 258

Quoted 11 lines
drivers/input/lirc/lirc_mceusb.c new file +11 -0
+static void mceusb_setup(struct usb_device *udev)
+{
+	char data[8];
+	int res;
+
+	memset(data, 0, 8);
+
+	/* Get Status */
+	res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+			      USB_REQ_GET_STATUS, USB_DIR_IN,
+			      0, 0, data, 2, HZ * 3);

res is set many times in this function, but it is never checked. It seems to me like the addition of some error handling would be a good idea.

...

drivers/input/lirc/lirc_mceusb.c line 288

Quoted 5 lines
drivers/input/lirc/lirc_mceusb.c new file +5 -0
+	/* These two are sent by the windows driver, but stall for
+	 * me. I dont have an analyzer on the linux side so i can't
+	 * see what is actually different and why the device takes
+	 * issue with them
+	 */

Hmm...how was that information obtained? If this driver was reverse-engineered, it would be good to know just what process was followed.

Quoted 2 lines
drivers/input/lirc/lirc_mceusb.c new file +2 -0
+static int msir_fetch_more_data(struct usb_skel *dev, int dont_block)
+{

...

drivers/input/lirc/lirc_mceusb.c line 405

Quoted 8 lines
drivers/input/lirc/lirc_mceusb.c new file +8 -0
+			/* retry a few times on overruns; map all
+			   other errors to -EIO */
+			if (retval) {
+				if (retval == -EOVERFLOW && retries < 5) {
+					retries++;
+					interruptible_sleep_on_timeout(
+						&dev->wait_q, HZ);
+					continue;

As others have noted, I think, getting new sleep_on() calls into the kernel is kind of a hard sell.

Quoted 9 lines
drivers/input/lirc/lirc_mceusb.c new file +9 -0
+/**
+ *	mceusb_probe
+ *
+ *	Called by the usb core when a new device is connected that it
+ *	thinks this driver might be interested in.
+ */
+static int mceusb_probe(struct usb_interface *interface,
+			const struct usb_device_id *id)
+{

...

drivers/input/lirc/lirc_mceusb.c line 642

Quoted 3 lines
drivers/input/lirc/lirc_mceusb.c new file +3 -0
+
+	/* select a "subminor" number (part of a minor number) */
+	down(&minor_table_mutex);

So...this driver has a mutex called "sem" and a semaphore called "minor_table_mutex". I suspect that minor_table_mutex should, in fact, be a mutex.

...

drivers/input/lirc/lirc_mceusb.c line 799

Quoted 7 lines
drivers/input/lirc/lirc_mceusb.c new file +7 -0
+error:
+	mceusb_delete(dev);
+	dev = NULL;
+	dprintk("%s: retval = %x", __func__, retval);
+	up(&minor_table_mutex);
+	return retval;
+}

This will leak the memory allocated for dev. It also leaves the entry in minor_table pointing to a nonfunctional device.

jon

#48 lore raw

Re: [PATCH 03/18] lirc driver for 1st-gen Media Center Ed. USB IR transceivers

Quoted 21 lines · On Tuesday 09 September 2008 21:21:40 Jonathan Corbet wrote:
Quoted 12 lines

+ * 2003_11_11 - Restructured to minimalize code interpretation in
the + * driver. The normal use case will be with lirc.
+ *
+ * 2004_01_01 - Removed all code interpretation. Generate mode2
data + * for passing off to lirc. Cleanup
+ *
+ * 2004_01_04 - Removed devfs handle. Put in a temporary
workaround + * for a known issue where repeats generate two
+ * sequential spaces (last_was_repeat_gap)
+ *
+ * 2004_02_17 - Changed top level api to no longer use fops, and

Quoted 8 lines
+ *	      instead use new interface for polling via
+ *	      lirc_thread. Restructure data read/mode2 generation to
+ *	      a single pass, reducing number of buffers. Rev to .2
+ *
+ * 2004_02_27 - Last of fixups to plugin->add_to_buf API. Properly
+ *	      handle broken fragments from the receiver. Up the
+ *	      sample rate and remove any pacing from
+ *	      fetch_more_data. Fixes all known issues.
Quoted 3 lines

General convention is that this sort of changelog information belongs in the SCM, not in the code. That's doubly true for the USB skeleton driver info.

I don't really care and I agree that the SCM is the preferred place for the information. The only problem is that the info is in a different SCM (lirc cvs repository).

I've removed the changelogs from all files as long as no names wre mentioned.

Quoted 3 lines
Quoted 1 line

+#include <linux/smp_lock.h>

It doesn't look like this include is needed.

removed

Quoted 5 lines

drivers/input/lirc/lirc_mceusb.c line 139

Quoted 2 lines
drivers/input/lirc/lirc_mceusb.c new file +2 -0
+/* Structure to hold all of our device specific stuff */
+struct usb_skel {

Perhaps renaming this structure to something more directly descriptive would make sense?

renamed to mceusb_device

Quoted 21 lines
Quoted 4 lines
(quoted diff) +2 -0
+	struct usb_device *udev; /* save off the usb device pointer */
+	struct usb_interface *interface; /* the interface for this device

*/ + unsigned char minor; /* the starting minor number for this
device */

Minor numbers don't necessarily fit in an unsigned char.

Quoted 14 lines
(quoted diff) +1 -0
+	unsigned char num_ports; /* the number of ports this device has

*/ + char num_interrupt_in; /* number of interrupt in endpoints */

drivers/input/lirc/lirc_mceusb.c new file +11 -0
+	char num_bulk_in;	 /* number of bulk in endpoints */
+	char num_bulk_out;	 /* number of bulk out endpoints */
+
+	unsigned char *bulk_in_buffer;	/* the buffer to receive data */
+	int bulk_in_size;		/* the size of the receive buffer */
+	__u8 bulk_in_endpointAddr;	/* the address of bulk in endpoint */
+
+	unsigned char *bulk_out_buffer;	/* the buffer to send data */
+	int bulk_out_size;		/* the size of the send buffer */
+	struct urb *write_urb;		/* the urb used to send data */
+	__u8 bulk_out_endpointAddr;	/* the address of bulk out endpoint

*/ +

Quoted 8 lines

drivers/input/lirc/lirc_mceusb.c line 162

Quoted 6 lines
(quoted diff) +2 -0
+	atomic_t write_busy;		/* true iff write urb is busy */
+	struct completion write_finished; /* wait for the write to finish

*/ +

drivers/input/lirc/lirc_mceusb.c new file +3 -0
+	wait_queue_head_t wait_q; /* for timeouts */
+	int open_count;		/* number of times this port has been opened */
+	struct mutex sem;	/* locks this structure */

"sem" is not a semaphore; it should probably have a different name.

renamed to lock

Quoted 7 lines
Quoted 7 lines
drivers/input/lirc/lirc_mceusb.c new file +7 -0
+static void mceusb_setup(struct usb_device *udev)
+{
+	char data[8];
+	int res;
+
+	memset(data, 0, 8);
+
Quoted 8 lines

drivers/input/lirc/lirc_mceusb.c line 258

Quoted 4 lines
drivers/input/lirc/lirc_mceusb.c new file +4 -0
+	/* Get Status */
+	res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+			      USB_REQ_GET_STATUS, USB_DIR_IN,
+			      0, 0, data, 2, HZ * 3);

res is set many times in this function, but it is never checked. It seems to me like the addition of some error handling would be a good idea.

sigh, It would be a good idea, not sure if I'm motivated enough to add that to a driver I can't test and I know almost nothing about.

Quoted 9 lines

drivers/input/lirc/lirc_mceusb.c line 288

Quoted 5 lines
drivers/input/lirc/lirc_mceusb.c new file +5 -0
+	/* These two are sent by the windows driver, but stall for
+	 * me. I dont have an analyzer on the linux side so i can't
+	 * see what is actually different and why the device takes
+	 * issue with them
+	 */

Hmm...how was that information obtained? If this driver was reverse-engineered, it would be good to know just what process was followed.

That's probably a question for the original author, Dan. CC added. I'm just cleaning them up for kernel inclusion.

Quoted 5 lines
Quoted 2 lines

+static int msir_fetch_more_data(struct usb_skel *dev, int dont_block) +{

...

Quoted 11 lines

drivers/input/lirc/lirc_mceusb.c line 405

Quoted 8 lines
drivers/input/lirc/lirc_mceusb.c new file +8 -0
+			/* retry a few times on overruns; map all
+			   other errors to -EIO */
+			if (retval) {
+				if (retval == -EOVERFLOW && retries < 5) {
+					retries++;
+					interruptible_sleep_on_timeout(
+						&dev->wait_q, HZ);
+					continue;

As others have noted, I think, getting new sleep_on() calls into the kernel is kind of a hard sell.

there are more, I'll fix them all before the next patchset get posted.

Quoted 9 lines

...

drivers/input/lirc/lirc_mceusb.c line 642

Quoted 3 lines
drivers/input/lirc/lirc_mceusb.c new file +3 -0
+
+	/* select a "subminor" number (part of a minor number) */
+	down(&minor_table_mutex);

So...this driver has a mutex called "sem" and a semaphore called "minor_table_mutex". I suspect that minor_table_mutex should, in fact, be a mutex.

yes, the declaration looks like this:
static DECLARE_MUTEX(...);

which gives us a single holder semaphore. the static in front of DECLARE_MUTEX() fools checkpatch. changed to to DEFINE_MUTEX, also in two other drivers.

Quoted 13 lines

...

drivers/input/lirc/lirc_mceusb.c line 799

Quoted 7 lines
drivers/input/lirc/lirc_mceusb.c new file +7 -0
+error:
+	mceusb_delete(dev);
+	dev = NULL;
+	dprintk("%s: retval = %x", __func__, retval);
+	up(&minor_table_mutex);
+	return retval;
+}

This will leak the memory allocated for dev. It also leaves the entry in minor_table pointing to a nonfunctional device.

fixed.

Thanks for the review.

Janne

#49 lore raw

Re: [PATCH 03/18] lirc driver for 1st-gen Media Center Ed. USB IR transceivers

Quoted 16 lines · On Tuesday 09 September 2008 19:59:32 Janne Grunau wrote:
Quoted 7 lines
Quoted 7 lines
drivers/input/lirc/lirc_mceusb.c new file +7 -0
+static void mceusb_setup(struct usb_device *udev)
+{
+   char data[8];
+   int res;
+
+   memset(data, 0, 8);
+
Quoted 8 lines
Quoted 4 lines

+   /* Get Status */
+   res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), +                         USB_REQ_GET_STATUS, USB_DIR_IN, +                         0, 0, data, 2, HZ * 3);

res is set many times in this function, but it is never checked.  It seems to me like the addition of some error handling would be a good idea.

Quoted 2 lines

sigh, It would be a good idea, not sure if I'm motivated enough to add that to a driver I can't test and I know almost nothing about.

I'll take a look, I've at least got the hardware to test with.

Signature · 2 lines
Jarod Wilson
[email protected]
#50 lore raw

Re: [PATCH 03/18] lirc driver for 1st-gen Media Center Ed. USB IR transceivers

In reply to Jonathan Corbet
Quoted 10 lines · On Tuesday 09 September 2008 21:21:40 Jonathan Corbet wrote:

drivers/input/lirc/lirc_mceusb.c line 799

Quoted 7 lines
drivers/input/lirc/lirc_mceusb.c new file +7 -0
+error:
+     mceusb_delete(dev);
+     dev = NULL;
+     dprintk("%s: retval = %x", __func__, retval);
+     up(&minor_table_mutex);
+     return retval;
+}

This will leak the memory allocated for dev.  It also leaves the entry in minor_table pointing to a nonfunctional device.

Argh, I replied too quickly.

kfree(dev) and minor_table cleanup are in mceusb_delete()

Janne

#51 lore raw

Re: [PATCH 02/18] lirc serial port receiver/transmitter device driver

In reply to Jarod Wilson

drivers/input/lirc/Kconfig config LIRC_DEV · line 26

Quoted 6 lines
drivers/input/lirc/Kconfig +6 -0
+config LIRC_SERIAL
+	tristate "Homebrew Serial Port Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for Homebrew Serial Port Receivers

What receivers might these be? Do any actually exist?

drivers/input/lirc/lirc_serial.c line 126

Quoted 13 lines
drivers/input/lirc/lirc_serial.c new file +13 -0
+#ifdef LIRC_SERIAL_IRDEO
+static int type = LIRC_IRDEO;
+#elif defined(LIRC_SERIAL_IRDEO_REMOTE)
+static int type = LIRC_IRDEO_REMOTE;
+#elif defined(LIRC_SERIAL_ANIMAX)
+static int type = LIRC_ANIMAX;
+#elif defined(LIRC_SERIAL_IGOR)
+static int type = LIRC_IGOR;
+#elif defined(LIRC_SERIAL_NSLU2)
+static int type = LIRC_NSLU2;
+#else
+static int type = LIRC_HOMEBREW;
+#endif

So where do all these LIRC_SERIAL_* macros come from? I can't really tell what this bunch of ifdeffery is doing or how one might influence it.

Quoted 8 lines
drivers/input/lirc/lirc_serial.c new file +8 -0
+
+static struct lirc_serial hardware[] = {
+	/* home-brew receiver/transmitter */
+	{
+		UART_MSR_DCD,
+		UART_MSR_DDCD,
+		UART_MCR_RTS|UART_MCR_OUT2|UART_MCR_DTR,
+		UART_MCR_RTS|UART_MCR_OUT2,

drivers/input/lirc/lirc_serial.c line 196

Quoted 10 lines
drivers/input/lirc/lirc_serial.c new file +10 -0
+		send_pulse_homebrew,
+		send_space_homebrew,
+		(
+#ifdef LIRC_SERIAL_TRANSMITTER
+		 LIRC_CAN_SET_SEND_DUTY_CYCLE|
+		 LIRC_CAN_SET_SEND_CARRIER|
+		 LIRC_CAN_SEND_PULSE|
+#endif
+		 LIRC_CAN_REC_MODE2)
+	},

It would be really nice to use the .field=value structure initialization conventions here.

Quoted 23 lines
drivers/input/lirc/lirc_serial.c new file +23 -0
+#if defined(__i386__)
+/*
+  From:
+  Linux I/O port programming mini-HOWTO
+  Author: Riku Saikkonen <[email protected]>
+  v, 28 December 1997
+
+  [...]
+  Actually, a port I/O instruction on most ports in the 0-0x3ff range
+  takes almost exactly 1 microsecond, so if you're, for example,using
+  the parallel port directly, just do additional inb()s from that port
+  to delay.
+  [...]
+*/
+/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from
+ * comment above plus trimming to match actual measured frequency.
+ * This will be sensitive to cpu speed, though hopefully most of the 1.5us
+ * is spent in the uart access.  Still - for reference test machine was a
+ * 1.13GHz Athlon system - Steve
+ */
+
+/* changed from 400 to 450 as this works better on slower machines;
+   faster machines will use the rdtsc code anyway */

drivers/input/lirc/lirc_serial.c line 350

Quoted 10 lines
drivers/input/lirc/lirc_serial.c new file +10 -0
+
+#define LIRC_SERIAL_TRANSMITTER_LATENCY 450
+
+#else
+
+/* does anybody have information on other platforms ? */
+/* 256 = 1<<8 */
+#define LIRC_SERIAL_TRANSMITTER_LATENCY 256
+
+#endif  /* __i386__ */

This is a little scary. Maybe hrtimers would be a better way of handling your timing issues?

drivers/input/lirc/lirc_serial.c line 362

Quoted 11 lines
drivers/input/lirc/lirc_serial.c new file +11 -0
+static inline unsigned int sinp(int offset)
+{
+#if defined(LIRC_ALLOW_MMAPPED_IO)
+	if (iommap != 0) {
+		/* the register is memory-mapped */
+		offset <<= ioshift;
+		return readb(io + offset);
+	}
+#endif
+	return inb(io + offset);
+}

This all looks like a reimplementation of ioport_map() and the associated ioread*() and iowrite*() functions...?

Quoted 16 lines
drivers/input/lirc/lirc_serial.c new file +16 -0
+#ifdef USE_RDTSC
+/* Version that uses Pentium rdtsc instruction to measure clocks */
+
+/* This version does sub-microsecond timing using rdtsc instruction,
+ * and does away with the fudged LIRC_SERIAL_TRANSMITTER_LATENCY
+ * Implicitly i586 architecture...  - Steve
+ */
+
+static inline long send_pulse_homebrew_softcarrier(unsigned long length) 
+{
+	int flag;
+	unsigned long target, start, now;
+
+	/* Get going quick as we can */
+	rdtscl(start); on();
+	/* Convert length from microseconds to clocks */

drivers/input/lirc/lirc_serial.c line 555

Quoted 10 lines
drivers/input/lirc/lirc_serial.c new file +10 -0
+	length *= conv_us_to_clocks;
+	/* And loop till time is up - flipping at right intervals */
+	now = start;
+	target = pulse_width;
+	flag = 1;
+	while ((now-start) < length) {
+		/* Delay till flip time */
+		do {
+			rdtscl(now);
+		} while ((now-start) < target);

This looks like a hard busy wait, without even an occasional, polite, cpu_relax() call. There's got to be a better way?

The i2c code has the result of a lot of bit-banging work, I wonder if there's something there which could be helpful here.

drivers/input/lirc/lirc_serial.c line 699

Quoted 12 lines
drivers/input/lirc/lirc_serial.c new file +12 -0
+static irqreturn_t irq_handler(int i, void *blah)
+{
+	struct timeval tv;
+	int status, counter, dcd;
+	long deltv;
+	int data;
+	static int last_dcd = -1;
+
+	if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
+		/* not our interrupt */
+		return IRQ_RETVAL(IRQ_NONE);
+	}

That should just be IRQ_NONE, no?

drivers/input/lirc/lirc_serial.c line 791

Quoted 4 lines
drivers/input/lirc/lirc_serial.c new file +4 -0
+static void hardware_init_port(void)
+{
+	unsigned long flags;
+	local_irq_save(flags);

That won't help you if an interrupt is handled by another processor. This needs proper locking, methinks.

Nothing in this function does anything to assure itself that the port actually exists and is the right kind of hardware. Maybe that can't really be done with this kind of device?

Quoted 2 lines
(quoted diff) +2 -0
+static int init_port(void)
+{

...

drivers/input/lirc/lirc_serial.c line 889

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+	if (sense == -1) {
+		/* wait 1/2 sec for the power supply */
+
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(HZ/2);

msleep(), maybe?

Quoted 33 lines
drivers/input/lirc/lirc_serial.c new file +28 -0
+static int set_use_inc(void *data)
+{
+	int result;
+	unsigned long flags;
+
+	/* Init read buffer. */
+	if (lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN) < 0)
+		return -ENOMEM;
+
+	/* initialize timestamp */
+	do_gettimeofday(&lasttv);
+
+	result = request_irq(irq, irq_handler,
+			   IRQF_DISABLED | (share_irq ? IRQF_SHARED : 0),
+			   LIRC_DRIVER_NAME, (void *)&hardware);
+
+	switch (result) {
+	case -EBUSY:
+		printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", irq);
+		lirc_buffer_free(&rbuf);
+		return -EBUSY;
+	case -EINVAL:
+		printk(KERN_ERR LIRC_DRIVER_NAME
+		       ": Bad irq number or handler\n");
+		lirc_buffer_free(&rbuf);
+		return -EINVAL;
+	default:
+		dprintk("Interrupt %d, port %04x obtained\n", irq,

io);

drivers/input/lirc/lirc_serial.c new file +4 -0
+		break;
+	};
+
+	local_irq_save(flags);

drivers/input/lirc/lirc_serial.c line 953

Quoted 10 lines
drivers/input/lirc/lirc_serial.c new file +10 -0
+
+	/* Set DLAB 0. */
+	soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
+
+	soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
+
+	local_irq_restore(flags);
+
+	return 0;
+}

OK, so set_use_inc() really is just an open() function. It still seems like a strange duplication.

Again, local_irq_save() seems insufficient here. You need a lock to serialize access to the hardware.

jon

#52 lore raw

Re: [PATCH 02/18] lirc serial port receiver/transmitter device driver

Hi

Quoted 8 lines · Jonathan Corbet

drivers/input/lirc/Kconfig config LIRC_DEV · line 26

Quoted 6 lines
drivers/input/lirc/Kconfig +6 -0
+config LIRC_SERIAL
+	tristate "Homebrew Serial Port Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for Homebrew Serial Port Receivers

What receivers might these be? Do any actually exist?

[...]

This might actually be the most common setup, as it is very easy to build[1] with minimal soldering skills and has also been used by various vendors (older models of the TechniSat SkyStar2 DVB-S budget card, to name just one example; it is only slowly being replaced by alternative means, as serial ports are becoming rare on newer systems.

Regards
Stefan Lippers-Hollmann

[1] http://www.lirc.org/receivers.html

#53 lore raw

Re: [PATCH 02/18] lirc serial port receiver/transmitter device driver

Quoted 20 lines · On Tuesday 09 September 2008 15:51:12 Stefan Lippers-Hollmann wrote:

Hi

Quoted 8 lines · Jonathan Corbet

drivers/input/lirc/Kconfig config LIRC_DEV · line 26

Quoted 6 lines
drivers/input/lirc/Kconfig +6 -0
+config LIRC_SERIAL
+	tristate "Homebrew Serial Port Receiver"
+	default n
+	depends on LIRC_DEV
+	help
+	  Driver for Homebrew Serial Port Receivers

What receivers might these be? Do any actually exist?

[...]

This might actually be the most common setup, as it is very easy to build[1] with minimal soldering skills and has also been used by various vendors (older models of the TechniSat SkyStar2 DVB-S budget card, to name just one example; it is only slowly being replaced by alternative means, as serial ports are becoming rare on newer systems.

Quoted 4 lines

Regards
Stefan Lippers-Hollmann

[1] http://www.lirc.org/receivers.html

One frequently-used source of pre-built serial receivers (and transmitters) here in the US is http://irblaster.info/.

Hey, that actually just reminded me... I think I *do* have a serial IR receiver laying about somewhere that came w/one of my TechniSat SkyStar HD-5000 cards... Thank you, Stefan! ;)

Signature · 2 lines
Jarod Wilson
[email protected]
#54 lore raw

Re: [PATCH 02/18] lirc serial port receiver/transmitter device driver

In reply to Jonathan Corbet
Quoted 8 lines · On Tuesday 09 September 2008 12:14:22 Jonathan Corbet wrote:
Quoted 8 lines
drivers/input/lirc/lirc_serial.c new file +8 -0
+#ifdef LIRC_SERIAL_IRDEO
+static int type = LIRC_IRDEO;
+#elif defined(LIRC_SERIAL_IRDEO_REMOTE)
+static int type = LIRC_IRDEO_REMOTE;
+#elif defined(LIRC_SERIAL_ANIMAX)
+static int type = LIRC_ANIMAX;
+#elif defined(LIRC_SERIAL_IGOR)
+static int type = LIRC_IGOR;
Quoted 8 lines

drivers/input/lirc/lirc_serial.c line 126

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+#elif defined(LIRC_SERIAL_NSLU2)
+static int type = LIRC_NSLU2;
+#else
+static int type = LIRC_HOMEBREW;
+#endif

So where do all these LIRC_SERIAL_* macros come from? I can't really tell what this bunch of ifdeffery is doing or how one might influence it.

Bleah. I believe these get passed in when building lirc userspace and drivers together, when manually selected the specific type of serial receiver you have in lirc's menu-driven configuration tool thingy...

In other words, they do us absolutely no good here. We just build for the default type (LIRC_HOMEBREW), and users can override the type as necessary via the 'type' module parameter. I'll nuke that chunk.

Quoted 13 lines
Quoted 13 lines
drivers/input/lirc/lirc_serial.c new file +13 -0
+
+static struct lirc_serial hardware[] = {
+	/* home-brew receiver/transmitter */
+	{
+		UART_MSR_DCD,
+		UART_MSR_DDCD,
+		UART_MCR_RTS|UART_MCR_OUT2|UART_MCR_DTR,
+		UART_MCR_RTS|UART_MCR_OUT2,
+		send_pulse_homebrew,
+		send_space_homebrew,
+		(
+#ifdef LIRC_SERIAL_TRANSMITTER
+		 LIRC_CAN_SET_SEND_DUTY_CYCLE|
Quoted 8 lines

drivers/input/lirc/lirc_serial.c line 196

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+		 LIRC_CAN_SET_SEND_CARRIER|
+		 LIRC_CAN_SEND_PULSE|
+#endif
+		 LIRC_CAN_REC_MODE2)
+	},

It would be really nice to use the .field=value structure initialization conventions here.

Indeed. Done.

Quoted 28 lines
Quoted 28 lines
drivers/input/lirc/lirc_serial.c new file +17 -0
+#if defined(__i386__)
+/*
+  From:
+  Linux I/O port programming mini-HOWTO
+  Author: Riku Saikkonen <[email protected]>
+  v, 28 December 1997
+
+  [...]
+  Actually, a port I/O instruction on most ports in the 0-0x3ff range
+  takes almost exactly 1 microsecond, so if you're, for example,using
+  the parallel port directly, just do additional inb()s from that port
+  to delay.
+  [...]
+*/
+/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from
+ * comment above plus trimming to match actual measured frequency.
+ * This will be sensitive to cpu speed, though hopefully most of the

1.5us + * is spent in the uart access. Still - for reference test machine was a + * 1.13GHz Athlon system - Steve
+ */

drivers/input/lirc/lirc_serial.c new file +8 -0
+
+/* changed from 400 to 450 as this works better on slower machines;
+   faster machines will use the rdtsc code anyway */
+
+#define LIRC_SERIAL_TRANSMITTER_LATENCY 450
+
+#else
+
Quoted 8 lines

drivers/input/lirc/lirc_serial.c line 350

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+/* does anybody have information on other platforms ? */
+/* 256 = 1<<8 */
+#define LIRC_SERIAL_TRANSMITTER_LATENCY 256
+
+#endif  /* __i386__ */

This is a little scary. Maybe hrtimers would be a better way of handling your timing issues?

Sounds plausible, will look into it. Of course, this partially hinges on the USE_RDTSC bits, more comments just a little ways down...

Quoted 6 lines
Quoted 6 lines
drivers/input/lirc/lirc_serial.c new file +6 -0
+static inline unsigned int sinp(int offset)
+{
+#if defined(LIRC_ALLOW_MMAPPED_IO)
+	if (iommap != 0) {
+		/* the register is memory-mapped */
+		offset <<= ioshift;
Quoted 8 lines

drivers/input/lirc/lirc_serial.c line 362

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+		return readb(io + offset);
+	}
+#endif
+	return inb(io + offset);
+}

This all looks like a reimplementation of ioport_map() and the associated ioread*() and iowrite*() functions...?

Probably. Will see about using those instead.

Quoted 30 lines
Quoted 16 lines
drivers/input/lirc/lirc_serial.c new file +16 -0
+#ifdef USE_RDTSC
+/* Version that uses Pentium rdtsc instruction to measure clocks */
+
+/* This version does sub-microsecond timing using rdtsc instruction,
+ * and does away with the fudged LIRC_SERIAL_TRANSMITTER_LATENCY
+ * Implicitly i586 architecture...  - Steve
+ */
+
+static inline long send_pulse_homebrew_softcarrier(unsigned long length)
+{
+	int flag;
+	unsigned long target, start, now;
+
+	/* Get going quick as we can */
+	rdtscl(start); on();
+	/* Convert length from microseconds to clocks */

drivers/input/lirc/lirc_serial.c line 555

Quoted 10 lines
drivers/input/lirc/lirc_serial.c new file +10 -0
+	length *= conv_us_to_clocks;
+	/* And loop till time is up - flipping at right intervals */
+	now = start;
+	target = pulse_width;
+	flag = 1;
+	while ((now-start) < length) {
+		/* Delay till flip time */
+		do {
+			rdtscl(now);
+		} while ((now-start) < target);

This looks like a hard busy wait, without even an occasional, polite, cpu_relax() call. There's got to be a better way?

Quoted 2 lines

The i2c code has the result of a lot of bit-banging work, I wonder if there's something there which could be helpful here.

Hrm... So at some point in the past, there was an "#if defined(rdtscl)" in the lirc_serial.c code that triggered USE_RDTSC being defined. At the moment, there's nothing defining it (I probably overzealously nuked it during clean- up), so we're not even touching the above code. However, this is supposed to be the "better" code path wrt producing a reliable waveform, at least on platforms with rdtscl... Will have to do some investigating... This actually affects whether or not we bother with hrtimers as suggested above too, as LIRC_SERIAL_TRANSMITTER_LATENCY is not used at all in the USE_RDTSC case.

Quoted 6 lines
Quoted 6 lines
drivers/input/lirc/lirc_serial.c new file +6 -0
+static irqreturn_t irq_handler(int i, void *blah)
+{
+	struct timeval tv;
+	int status, counter, dcd;
+	long deltv;
+	int data;
Quoted 8 lines

drivers/input/lirc/lirc_serial.c line 699

Quoted 6 lines
drivers/input/lirc/lirc_serial.c new file +6 -0
+	static int last_dcd = -1;
+
+	if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
+		/* not our interrupt */
+		return IRQ_RETVAL(IRQ_NONE);
+	}

That should just be IRQ_NONE, no?

Yeah, looks like it. Done.

Quoted 7 lines

drivers/input/lirc/lirc_serial.c line 791

Quoted 4 lines
drivers/input/lirc/lirc_serial.c new file +4 -0
+static void hardware_init_port(void)
+{
+	unsigned long flags;
+	local_irq_save(flags);

That won't help you if an interrupt is handled by another processor. This needs proper locking, methinks.

Yeah, working on implementing locking right now.

Quoted 3 lines

Nothing in this function does anything to assure itself that the port actually exists and is the right kind of hardware. Maybe that can't really be done with this kind of device?

We should probably try to make sure the port actually exists, but I don't think there's a whole lot (if anything) we can do as far as verifying the device itself.

Quoted 5 lines
Quoted 2 lines
(quoted diff) +2 -0
+static int init_port(void)
+{

...

Quoted 7 lines

drivers/input/lirc/lirc_serial.c line 889

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+	if (sense == -1) {
+		/* wait 1/2 sec for the power supply */
+
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule_timeout(HZ/2);

msleep(), maybe?

Yeah, looks like it.

Quoted 38 lines
Quoted 38 lines
drivers/input/lirc/lirc_serial.c new file +28 -0
+static int set_use_inc(void *data)
+{
+	int result;
+	unsigned long flags;
+
+	/* Init read buffer. */
+	if (lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN) < 0)
+		return -ENOMEM;
+
+	/* initialize timestamp */
+	do_gettimeofday(&lasttv);
+
+	result = request_irq(irq, irq_handler,
+			   IRQF_DISABLED | (share_irq ? IRQF_SHARED : 0),
+			   LIRC_DRIVER_NAME, (void *)&hardware);
+
+	switch (result) {
+	case -EBUSY:
+		printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", irq);
+		lirc_buffer_free(&rbuf);
+		return -EBUSY;
+	case -EINVAL:
+		printk(KERN_ERR LIRC_DRIVER_NAME
+		       ": Bad irq number or handler\n");
+		lirc_buffer_free(&rbuf);
+		return -EINVAL;
+	default:
+		dprintk("Interrupt %d, port %04x obtained\n", irq,

io);

drivers/input/lirc/lirc_serial.c new file +9 -0
+		break;
+	};
+
+	local_irq_save(flags);
+
+	/* Set DLAB 0. */
+	soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
+
+	soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
Quoted 8 lines

drivers/input/lirc/lirc_serial.c line 910

Quoted 5 lines
drivers/input/lirc/lirc_serial.c new file +5 -0
+
+	local_irq_restore(flags);
+
+	return 0;
+}

OK, so set_use_inc() really is just an open() function. It still seems like a strange duplication.

Going to let the duplication be for the moment, since I don't know the history behind why there's duplication, and there are enough other mountains to climb first... :)

Quoted 2 lines

Again, local_irq_save() seems insufficient here. You need a lock to serialize access to the hardware.

Will do.

Signature · 2 lines
Jarod Wilson
[email protected]
#55 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Jarod Wilson

drivers/input/lirc/Makefile line 6

Quoted 12 lines
drivers/input/lirc/Makefile new file +6 -0
new file mode 100644
index 0000000..cdb4c45
@@ -0,0 +1,8 @@
+# Makefile for the lirc drivers.
+#
+
+# Each configuration option enables a list of files.
+
+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)

Do you rely on this specific major? Since your daemon opens /dev/lirc0 you don't need a fixed major do you? LIRC_SERIAL_TRANSMITTER is used in patch 2 and just to enable a module options. Since it is always the case, please remove it.
I haven't found the source of $src. It is probably a relic.

drivers/input/lirc/lirc_dev.c line 4

Quoted 11 lines
drivers/input/lirc/Makefile new file +1 -0
+obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
drivers/input/lirc/lirc_dev.c new file +4 -0
new file mode 100644
index 0000000..c8f325c
@@ -0,0 +1,809 @@
+/*
+ * LIRC base driver
+ *
+ * (L) by Artur Lipowski <[email protected]>

Is that L here on purpose?

Quoted 8 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+ *
+ *  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

drivers/input/lirc/lirc_dev.c line 22

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+ *  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>

You souldn't need this one

drivers/input/lirc/lirc_dev.c line 24

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+#include <linux/autoconf.h>

this as well.

drivers/input/lirc/lirc_dev.c line 32

Quoted 8 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/errno.h>
+#include <linux/ioctl.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/smp_lock.h>

if you need this than you use the BKL back. As far as I remember the ioctl() handler in kernel core no longer takes the BKL and I don't see any locking in irctl_ioctl().

drivers/input/lirc/lirc_dev.c line 36

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+#include <linux/completion.h>
+#include <linux/uaccess.h>
+#include <linux/errno.h>
+#include <linux/semaphore.h>

haven't found any call of down(). Do you really need this?

drivers/input/lirc/lirc_dev.c line 37

Quoted 1 line
drivers/input/lirc/lirc_dev.c new file +1 -0
+#define __KERNEL_SYSCALLS__

this define shouldn't be here, should it?

Quoted 35 lines
drivers/input/lirc/lirc_dev.c new file +35 -0
+#include <linux/unistd.h>
+#include <linux/kthread.h>
+
+/* SysFS header */
+#include <linux/device.h>
+
+#include "lirc.h"
+#include "lirc_dev.h"
+
+static int debug;
+#define dprintk(fmt, args...)					\
+	do {							\
+		if (debug)					\
+			printk(KERN_DEBUG fmt, ## args);	\
+	} while (0)
+
+#define IRCTL_DEV_NAME    "BaseRemoteCtl"
+#define SUCCESS           0
+#define NOPLUG            -1
+#define LOGHEAD           "lirc_dev (%s[%d]): "
+
+struct irctl {
+	struct lirc_plugin p;
+	int attached;
+	int open;
+
+	struct mutex buffer_lock;
+	struct lirc_buffer *buf;
+
+	struct task_struct *task;
+	long jiffies_to_wait;
+
+};
+
+static DEFINE_MUTEX(plugin_lock);

drivers/input/lirc/lirc_dev.c line 82

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+
+static struct irctl irctls[MAX_IRCTL_DEVICES];
+static struct file_operations fops;
+
+/* Only used for sysfs but defined to void otherwise */
+static struct class *lirc_class;
+
+/*  helper function
+ *  initializes the irctl structure
+ */

For all comments above functions:
- Please use the default comment style.
- don't comment obvious things
- please use kernel doc if
- please comment the prototypes but the actual function.

drivers/input/lirc/lirc_dev.c line 83

Quoted 1 line
drivers/input/lirc/lirc_dev.c new file +1 -0
+static inline void init_irctl(struct irctl *ir)

this inline can go in my opinion. The others here as well. It is not *that* performance critical.

Quoted 198 lines
drivers/input/lirc/lirc_dev.c new file +198 -0
+{
+	memset(&ir->p, 0, sizeof(struct lirc_plugin));
+	mutex_init(&ir->buffer_lock);
+	ir->p.minor = NOPLUG;
+
+	ir->task = NULL;
+	ir->jiffies_to_wait = 0;
+
+	ir->open = 0;
+	ir->attached = 0;
+}
+
+static void cleanup(struct irctl *ir)
+{
+	dprintk(LOGHEAD "cleaning up\n", ir->p.name, ir->p.minor);
+
+	device_destroy(lirc_class, MKDEV(IRCTL_DEV_MAJOR, ir->p.minor));
+
+	if (ir->buf != ir->p.rbuf) {
+		lirc_buffer_free(ir->buf);
+		kfree(ir->buf);
+	}
+	ir->buf = NULL;
+
+	init_irctl(ir);
+}
+
+/*  helper function
+ *  reads key codes from plugin and puts them into buffer
+ *  buffer free space is checked and locking performed
+ *  returns 0 on success
+ */
+static inline int add_to_buf(struct irctl *ir)
+{
+	if (lirc_buffer_full(ir->buf)) {
+		dprintk(LOGHEAD "buffer overflow\n",
+			ir->p.name, ir->p.minor);
+		return -EOVERFLOW;
+	}
+
+	if (ir->p.add_to_buf) {
+		int res = -ENODATA;
+		int got_data = 0;
+
+		/* service the device as long as it is returning
+		 * data and we have space
+		 */
+		while (!lirc_buffer_full(ir->buf)) {
+			res = ir->p.add_to_buf(ir->p.data, ir->buf);
+			if (res == SUCCESS)
+				got_data++;
+			else
+				break;
+		}
+
+		if (res == -ENODEV)
+			kthread_stop(ir->task);
+
+		return got_data ? SUCCESS : res;
+	}
+
+	return SUCCESS;
+}
+
+/* main function of the polling thread
+ */
+static int lirc_thread(void *irctl)
+{
+	struct irctl *ir = irctl;
+
+	/* This thread doesn't need any user-level access,
+	 * so get rid of all our resources
+	 */
+
+	dprintk(LOGHEAD "poll thread started\n", ir->p.name, ir->p.minor);
+
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}
+			if (kthread_should_stop())
+				break;
+			if (!add_to_buf(ir))
+				wake_up_interruptible(&ir->buf->wait_poll);
+		} else {
+			/* if device not opened so we can sleep half a second */
+			set_current_state(TASK_INTERRUPTIBLE);
+			schedule_timeout(HZ/2);
+		}
+	} while (!kthread_should_stop());
+
+	dprintk(LOGHEAD "poll thread ended\n", ir->p.name, ir->p.minor);
+
+	return 0;
+}
+
+int lirc_register_plugin(struct lirc_plugin *p)
+{
+	struct irctl *ir;
+	int minor;
+	int bytes_in_key;
+	int err;
+	DECLARE_COMPLETION(tn);
+
+	if (!p) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "plugin pointer must be not NULL!\n");
+		err = -EBADRQC;
+		goto out;
+	}
+
+	if (MAX_IRCTL_DEVICES <= p->minor) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "\"minor\" must be between 0 and %d (%d)!\n",
+		       MAX_IRCTL_DEVICES-1, p->minor);
+		err = -EBADRQC;
+		goto out;
+	}
+
+	if (1 > p->code_length || (BUFLEN * 8) < p->code_length) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "code length in bits for minor (%d) "
+		       "must be less than %d!\n",
+		       p->minor, BUFLEN * 8);
+		err = -EBADRQC;
+		goto out;
+	}
+
+	printk(KERN_INFO "lirc_dev: lirc_register_plugin: sample_rate: %d\n",
+		p->sample_rate);
+	if (p->sample_rate) {
+		if (2 > p->sample_rate || HZ < p->sample_rate) {
+			printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+			       "sample_rate must be between 2 and %d!\n", HZ);
+			err = -EBADRQC;
+			goto out;
+		}
+		if (!p->add_to_buf) {
+			printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+			       "add_to_buf cannot be NULL when "
+			       "sample_rate is set\n");
+			err = -EBADRQC;
+			goto out;
+		}
+	} else if (!(p->fops && p->fops->read)
+		   && !p->get_queue && !p->rbuf) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "fops->read, get_queue and rbuf "
+		       "cannot all be NULL!\n");
+		err = -EBADRQC;
+		goto out;
+	} else if (!p->get_queue && !p->rbuf) {
+		if (!(p->fops && p->fops->read && p->fops->poll)
+		    || (!p->fops->ioctl && !p->ioctl)) {
+			printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+			       "neither read, poll nor ioctl can be NULL!\n");
+			err = -EBADRQC;
+			goto out;
+		}
+	}
+
+	if (p->owner == NULL) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+				    "no module owner registered\n");
+		err = -EBADRQC;
+		goto out;
+	}
+
+	mutex_lock(&plugin_lock);
+
+	minor = p->minor;
+
+	if (0 > minor) {
+		/* find first free slot for plugin */
+		for (minor = 0; minor < MAX_IRCTL_DEVICES; minor++)
+			if (irctls[minor].p.minor == NOPLUG)
+				break;
+		if (MAX_IRCTL_DEVICES == minor) {
+			printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+			       "no free slots for plugins!\n");
+			err = -ENOMEM;
+			goto out_lock;
+		}
+	} else if (irctls[minor].p.minor != NOPLUG) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "minor (%d) just registered!\n", minor);
+		err = -EBUSY;
+		goto out_lock;
+	}
+
+	ir = &irctls[minor];
+
+	if (p->sample_rate) {

drivers/input/lirc/lirc_dev.c line 291

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+		ir->jiffies_to_wait = HZ / p->sample_rate;
+	} else {
+		/* it means - wait for external event in task queue */
+		ir->jiffies_to_wait = 0;
+	}
+
+	/* some safety check 8-) */
+	p->name[sizeof(p->name)-1] = '\0';
+
+	bytes_in_key = p->code_length/8 + (p->code_length%8 ? 1 : 0);

did you actually pass checkpatch.pl ?

Quoted 49 lines
drivers/input/lirc/lirc_dev.c new file +49 -0
+
+	if (p->rbuf) {
+		ir->buf = p->rbuf;
+	} else {
+		ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
+		if (!ir->buf) {
+			err = -ENOMEM;
+			goto out_lock;
+		}
+		if (lirc_buffer_init(ir->buf, bytes_in_key,
+				     BUFLEN/bytes_in_key) != 0) {
+			kfree(ir->buf);
+			err = -ENOMEM;
+			goto out_lock;
+		}
+	}
+
+	if (p->features == 0)
+		p->features = (p->code_length > 8) ?
+			LIRC_CAN_REC_LIRCCODE : LIRC_CAN_REC_CODE;
+
+	ir->p = *p;
+	ir->p.minor = minor;
+
+	device_create(lirc_class, ir->p.dev,
+		      MKDEV(IRCTL_DEV_MAJOR, ir->p.minor), NULL,
+		      "lirc%u", ir->p.minor);
+
+	if (p->sample_rate || p->get_queue) {
+		/* try to fire up polling thread */
+		ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev");
+		if (IS_ERR(ir->task)) {
+			printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+			       "cannot run poll thread for minor = %d\n",
+			       p->minor);
+			err = -ECHILD;
+			goto out_sysfs;
+		}
+	}
+	ir->attached = 1;
+	mutex_unlock(&plugin_lock);
+
+/*
+ * Recent kernels should handle this autmatically by increasing/decreasing
+ * use count when a dependant module is loaded/unloaded.
+ */
+	dprintk("lirc_dev: plugin %s registered at minor number = %d\n",
+		ir->p.name, ir->p.minor);
+	p->minor = minor;

drivers/input/lirc/lirc_dev.c line 350

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	return minor;
+
+out_sysfs:
+	device_destroy(lirc_class, MKDEV(IRCTL_DEV_MAJOR, ir->p.minor));
+out_lock:
+	mutex_unlock(&plugin_lock);
+out:
+	return err;
+}
+EXPORT_SYMBOL(lirc_register_plugin);

Is EXPORT_SYMBOL_GPL() possible?

Quoted 404 lines
drivers/input/lirc/lirc_dev.c new file +404 -0
+
+int lirc_unregister_plugin(int minor)
+{
+	struct irctl *ir;
+	DECLARE_COMPLETION(tn);
+	DECLARE_COMPLETION(tn2);
+
+	if (minor < 0 || minor >= MAX_IRCTL_DEVICES) {
+		printk(KERN_ERR "lirc_dev: lirc_unregister_plugin: "
+		       "\"minor\" must be between 0 and %d!\n",
+		       MAX_IRCTL_DEVICES-1);
+		return -EBADRQC;
+	}
+
+	ir = &irctls[minor];
+
+	mutex_lock(&plugin_lock);
+
+	if (ir->p.minor != minor) {
+		printk(KERN_ERR "lirc_dev: lirc_unregister_plugin: "
+		       "minor (%d) device not registered!", minor);
+		mutex_unlock(&plugin_lock);
+		return -ENOENT;
+	}
+
+	/* end up polling thread */
+	if (ir->task) {
+		wake_up_process(ir->task);
+		kthread_stop(ir->task);
+	}
+
+	dprintk("lirc_dev: plugin %s unregistered from minor number = %d\n",
+		ir->p.name, ir->p.minor);
+
+	ir->attached = 0;
+	if (ir->open) {
+		dprintk(LOGHEAD "releasing opened plugin\n",
+			ir->p.name, ir->p.minor);
+		wake_up_interruptible(&ir->buf->wait_poll);
+		mutex_lock(&ir->buffer_lock);
+		ir->p.set_use_dec(ir->p.data);
+		module_put(ir->p.owner);
+		mutex_unlock(&ir->buffer_lock);
+	} else
+		cleanup(ir);
+	mutex_unlock(&plugin_lock);
+
+/*
+ * Recent kernels should handle this autmatically by increasing/decreasing
+ * use count when a dependant module is loaded/unloaded.
+ */
+
+	return SUCCESS;
+}
+EXPORT_SYMBOL(lirc_unregister_plugin);
+
+/*
+ *
+ */
+static int irctl_open(struct inode *inode, struct file *file)
+{
+	struct irctl *ir;
+	int retval;
+
+	if (MINOR(inode->i_rdev) >= MAX_IRCTL_DEVICES) {
+		dprintk("lirc_dev [%d]: open result = -ENODEV\n",
+			MINOR(inode->i_rdev));
+		return -ENODEV;
+	}
+
+	ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "open called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has an open function use it instead */
+	if (ir->p.fops && ir->p.fops->open)
+		return ir->p.fops->open(inode, file);
+
+	if (mutex_lock_interruptible(&plugin_lock))
+		return -ERESTARTSYS;
+
+	if (ir->p.minor == NOPLUG) {
+		mutex_unlock(&plugin_lock);
+		dprintk(LOGHEAD "open result = -ENODEV\n",
+			ir->p.name, ir->p.minor);
+		return -ENODEV;
+	}
+
+	if (ir->open) {
+		mutex_unlock(&plugin_lock);
+		dprintk(LOGHEAD "open result = -EBUSY\n",
+			ir->p.name, ir->p.minor);
+		return -EBUSY;
+	}
+
+	/* there is no need for locking here because ir->open is 0
+	 * and lirc_thread isn't using buffer
+	 * plugins which use irq's should allocate them on set_use_inc,
+	 * so there should be no problem with those either.
+	 */
+	ir->buf->head = ir->buf->tail;
+	ir->buf->fill = 0;
+
+	if (ir->p.owner != NULL && try_module_get(ir->p.owner)) {
+		++ir->open;
+		retval = ir->p.set_use_inc(ir->p.data);
+
+		if (retval != SUCCESS) {
+			module_put(ir->p.owner);
+			--ir->open;
+		}
+	} else {
+		if (ir->p.owner == NULL)
+			dprintk(LOGHEAD "no module owner!!!\n",
+				ir->p.name, ir->p.minor);
+
+		retval = -ENODEV;
+	}
+
+	dprintk(LOGHEAD "open result = %d\n", ir->p.name, ir->p.minor, retval);
+	mutex_unlock(&plugin_lock);
+
+	return retval;
+}
+
+/*
+ *
+ */
+static int irctl_close(struct inode *inode, struct file *file)
+{
+	struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "close called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a close function use it instead */
+	if (ir->p.fops && ir->p.fops->release)
+		return ir->p.fops->release(inode, file);
+
+	if (mutex_lock_interruptible(&plugin_lock))
+		return -ERESTARTSYS;
+
+	--ir->open;
+	if (ir->attached) {
+		ir->p.set_use_dec(ir->p.data);
+		module_put(ir->p.owner);
+	} else {
+		cleanup(ir);
+	}
+
+	mutex_unlock(&plugin_lock);
+
+	return SUCCESS;
+}
+
+/*
+ *
+ */
+static unsigned int irctl_poll(struct file *file, poll_table *wait)
+{
+	struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
+	unsigned int ret;
+
+	dprintk(LOGHEAD "poll called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a poll function use it instead */
+	if (ir->p.fops && ir->p.fops->poll)
+		return ir->p.fops->poll(file, wait);
+
+	mutex_lock(&ir->buffer_lock);
+	if (!ir->attached) {
+		mutex_unlock(&ir->buffer_lock);
+		return POLLERR;
+	}
+
+	poll_wait(file, &ir->buf->wait_poll, wait);
+
+	dprintk(LOGHEAD "poll result = %s\n",
+		ir->p.name, ir->p.minor,
+		lirc_buffer_empty(ir->buf) ? "0" : "POLLIN|POLLRDNORM");
+
+	ret = lirc_buffer_empty(ir->buf) ? 0 : (POLLIN|POLLRDNORM);
+
+	mutex_unlock(&ir->buffer_lock);
+	return ret;
+}
+
+/*
+ *
+ */
+static int irctl_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg)
+{
+	unsigned long mode;
+	int result;
+	struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "ioctl called (0x%x)\n",
+		ir->p.name, ir->p.minor, cmd);
+
+	/* if the plugin has a ioctl function use it instead */
+	if (ir->p.fops && ir->p.fops->ioctl)
+		return ir->p.fops->ioctl(inode, file, cmd, arg);
+
+	if (ir->p.minor == NOPLUG || !ir->attached) {
+		dprintk(LOGHEAD "ioctl result = -ENODEV\n",
+			ir->p.name, ir->p.minor);
+		return -ENODEV;
+	}
+
+	/* Give the plugin a chance to handle the ioctl */
+	if (ir->p.ioctl) {
+		result = ir->p.ioctl(inode, file, cmd, arg);
+		if (result != -ENOIOCTLCMD)
+			return result;
+	}
+	/* The plugin can't handle cmd */
+	result = SUCCESS;
+
+	switch (cmd) {
+	case LIRC_GET_FEATURES:
+		result = put_user(ir->p.features, (unsigned long *)arg);
+		break;
+	case LIRC_GET_REC_MODE:
+		if (!(ir->p.features&LIRC_CAN_REC_MASK))
+			return -ENOSYS;
+
+		result = put_user(LIRC_REC2MODE
+				  (ir->p.features&LIRC_CAN_REC_MASK),
+				  (unsigned long *)arg);
+		break;
+	case LIRC_SET_REC_MODE:
+		if (!(ir->p.features&LIRC_CAN_REC_MASK))
+			return -ENOSYS;
+
+		result = get_user(mode, (unsigned long *)arg);
+		if (!result && !(LIRC_MODE2REC(mode) & ir->p.features))
+			result = -EINVAL;
+		/*
+		 * FIXME: We should actually set the mode somehow but
+		 * for now, lirc_serial doesn't support mode changing either
+		 */
+		break;
+	case LIRC_GET_LENGTH:
+		result = put_user((unsigned long)ir->p.code_length,
+				  (unsigned long *)arg);
+		break;
+	default:
+		result = -ENOIOCTLCMD;
+	}
+
+	dprintk(LOGHEAD "ioctl result = %d\n",
+		ir->p.name, ir->p.minor, result);
+
+	return result;
+}
+
+/*
+ *
+ */
+static ssize_t irctl_read(struct file *file,
+			  char *buffer,
+			  size_t length,
+			  loff_t *ppos)
+{
+	struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
+	unsigned char buf[ir->buf->chunk_size];
+	int ret = 0, written = 0;
+	DECLARE_WAITQUEUE(wait, current);
+
+	dprintk(LOGHEAD "read called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a specific read function use it instead */
+	if (ir->p.fops && ir->p.fops->read)
+		return ir->p.fops->read(file, buffer, length, ppos);
+
+	if (mutex_lock_interruptible(&ir->buffer_lock))
+		return -ERESTARTSYS;
+	if (!ir->attached) {
+		mutex_unlock(&ir->buffer_lock);
+		return -ENODEV;
+	}
+
+	if (length % ir->buf->chunk_size) {
+		dprintk(LOGHEAD "read result = -EINVAL\n",
+			ir->p.name, ir->p.minor);
+		mutex_unlock(&ir->buffer_lock);
+		return -EINVAL;
+	}
+
+	/*
+	 * we add ourselves to the task queue before buffer check
+	 * to avoid losing scan code (in case when queue is awaken somewhere
+	 * beetwen while condition checking and scheduling)
+	 */
+	add_wait_queue(&ir->buf->wait_poll, &wait);
+	set_current_state(TASK_INTERRUPTIBLE);
+
+	/*
+	 * while we did't provide 'length' bytes, device is opened in blocking
+	 * mode and 'copy_to_user' is happy, wait for data.
+	 */
+	while (written < length && ret == 0) {
+		if (lirc_buffer_empty(ir->buf)) {
+			/* According to the read(2) man page, 'written' can be
+			 * returned as less than 'length', instead of blocking
+			 * again, returning -EWOULDBLOCK, or returning
+			 * -ERESTARTSYS */
+			if (written)
+				break;
+			if (file->f_flags & O_NONBLOCK) {
+				ret = -EWOULDBLOCK;
+				break;
+			}
+			if (signal_pending(current)) {
+				ret = -ERESTARTSYS;
+				break;
+			}
+			schedule();
+			set_current_state(TASK_INTERRUPTIBLE);
+			if (!ir->attached) {
+				ret = -ENODEV;
+				break;
+			}
+		} else {
+			lirc_buffer_read_1(ir->buf, buf);
+			ret = copy_to_user((void *)buffer+written, buf,
+					   ir->buf->chunk_size);
+			written += ir->buf->chunk_size;
+		}
+	}
+
+	remove_wait_queue(&ir->buf->wait_poll, &wait);
+	set_current_state(TASK_RUNNING);
+	mutex_unlock(&ir->buffer_lock);
+
+	dprintk(LOGHEAD "read result = %s (%d)\n",
+		ir->p.name, ir->p.minor, ret ? "-EFAULT" : "OK", ret);
+
+	return ret ? ret : written;
+}
+
+
+void *lirc_get_pdata(struct file *file)
+{
+	void *data = NULL;
+
+	if (file && file->f_dentry && file->f_dentry->d_inode &&
+	    file->f_dentry->d_inode->i_rdev) {
+		struct irctl *ir;
+		ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
+		data = ir->p.data;
+	}
+
+	return data;
+}
+EXPORT_SYMBOL(lirc_get_pdata);
+
+
+static ssize_t irctl_write(struct file *file, const char *buffer,
+			   size_t length, loff_t *ppos)
+{
+	struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
+
+	dprintk(LOGHEAD "write called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a specific read function use it instead */
+	if (ir->p.fops && ir->p.fops->write)
+		return ir->p.fops->write(file, buffer, length, ppos);
+
+	if (!ir->attached)
+		return -ENODEV;
+
+	return -EINVAL;
+}
+
+
+static struct file_operations fops = {
+	.read		= irctl_read,
+	.write		= irctl_write,
+	.poll		= irctl_poll,
+	.ioctl		= irctl_ioctl,
+	.open		= irctl_open,
+	.release	= irctl_close
+};
+
+
+static int lirc_dev_init(void)
+{
+	int i;
+
+	for (i = 0; i < MAX_IRCTL_DEVICES; ++i)
+		init_irctl(&irctls[i]);
+
+	if (register_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME, &fops)) {
+		printk(KERN_ERR "lirc_dev: register_chrdev failed\n");
+		goto out;
+	}
+
+	lirc_class = class_create(THIS_MODULE, "lirc");
+	if (IS_ERR(lirc_class)) {
+		printk(KERN_ERR "lirc_dev: class_create failed\n");
+		goto out_unregister;
+	}
+

drivers/input/lirc/lirc_dev.c line 764

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	printk(KERN_INFO "lirc_dev: IR Remote Control driver registered, "
+	       "major %d \n", IRCTL_DEV_MAJOR);
+
+	return SUCCESS;
+
+out_unregister:
+	/* unregister_chrdev returns void now */
+	unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
+out:
+	return -1;

Ehm, the error code from register_chrdev() ?

drivers/input/lirc/lirc_dev.c line 767

Quoted 3 lines
drivers/input/lirc/lirc_dev.c new file +3 -0
+}
+
+/* ---------------------------------------------------------------------- */

I hate those

drivers/input/lirc/lirc_dev.c line 769

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+#ifdef MODULE

You don't need that one. subsys_initcall() does the right thing for you allready.

Quoted 30 lines
drivers/input/lirc/lirc_dev.c new file +30 -0
+
+/*
+ *
+ */
+int init_module(void)
+{
+	return lirc_dev_init();
+}
+
+/*
+ *
+ */
+void cleanup_module(void)
+{
+	/* unregister_chrdev returns void now */
+	unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
+	class_destroy(lirc_class);
+	dprintk("lirc_dev: module unloaded\n");
+}
+
+MODULE_DESCRIPTION("LIRC base driver module");
+MODULE_AUTHOR("Artur Lipowski");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(IRCTL_DEV_MAJOR);
+
+module_param(debug, bool, 0644);
+MODULE_PARM_DESC(debug, "Enable debugging messages");
+
+#else /* not a MODULE */
+subsys_initcall(lirc_dev_init);

drivers/input/lirc/lirc_dev.c line 809

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+
+#endif /* MODULE */
+
+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */

Please don't enforce formating that way.

Regards,
Sebastian

#56 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 8 lines · On Tuesday 09 September 2008 09:40:18 Sebastian Siewior wrote:
Quoted 8 lines
(quoted diff) +0 -0

b/drivers/input/lirc/Makefile new file mode 100644 index 0000000..cdb4c45

drivers/input/lirc/Makefile new file +2 -0
@@ -0,0 +1,8 @@
+# Makefile for the lirc drivers.
+#
Quoted 8 lines

drivers/input/lirc/Makefile

Quoted 5 lines
drivers/input/lirc/Makefile new file +4 -1
+
+# Each configuration option enables a list of files.
+
+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER
-I$(src)

LIRC_SERIAL_TRANSMITTER is used in patch 2 and just to enable a module options. Since it is always the case, please remove it.

Added CONFIG_LIRC_SERIAL_TRANSMITTER to Kconfig and removed this from the Makefile

Quoted 1 line

I haven't found the source of $src. It is probably a relic.

removed

Quoted 7 lines
Quoted 7 lines
drivers/input/lirc/Makefile new file +1 -0
+obj-$(CONFIG_LIRC_DEV)		+= lirc_dev.o
(quoted diff) +0 -0

b/drivers/input/lirc/lirc_dev.c new file mode 100644 index 0000000..c8f325c

drivers/input/lirc/lirc_dev.c new file +0 -0
@@ -0,0 +1,809 @@

...

Quoted 9 lines

drivers/input/lirc/lirc_dev.c line 22

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+#include <linux/version.h>

You souldn't need this one

drivers/input/lirc/lirc_dev.c line 24

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+#include <linux/autoconf.h>

this as well.

fixed, in all other files as well.

Quoted 3 lines
Quoted 1 line

+#include <linux/semaphore.h>

haven't found any call of down(). Do you really need this?

A relict. Lirc used many single holder semaphore and I forgot to remove the include after converting them to mutexes. I'll check the other files too.

Quoted 3 lines
Quoted 1 line

+#define __KERNEL_SYSCALLS__

this define shouldn't be here, should it?

Probably not, but it doesn't make a difference for the current kernel. The only other hit for this symbol is arch/xtensa/kernel/syscall.c 38:#undef __KERNEL_SYSCALLS__

...

Quoted 4 lines
Quoted 1 line

+static inline void init_irctl(struct irctl *ir)

this inline can go in my opinion. The others here as well. It is not *that* performance critical.

There is only one other inline. I doubt it makes a difference there but I won't change it without test. It does for the object size since the function is only called from one place.

...

Quoted 4 lines

drivers/input/lirc/lirc_dev.c line 291

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+	bytes_in_key = p->code_length/8 + (p->code_length%8 ? 1 : 0);

did you actually pass checkpatch.pl ?

yes, and while this is ugly I see no obvious CodingStyle violation.

is following better?

bytes_in_key = p->code_length/8;
if (p->code_length%8)

	bytes_in_key++;
Quoted 3 lines
Quoted 1 line

+EXPORT_SYMBOL(lirc_register_plugin);

Is EXPORT_SYMBOL_GPL() possible?

Afaik yes, all drivers using this symbol are in this patchset and under GPL. If it is desireable to to use EXPORT_SYMBOL_GPL() has someone else to decide. Christoph?

Quoted 10 lines
Quoted 8 lines

+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ *
-------------------------------------------------------------------
-------- + * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */

Please don't enforce formating that way.

Removed, from all other files as well.

Thanks for the review. We will address the misssing comments later

Janne

#57 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 5 lines · * Janne Grunau | 2008-09-09 11:53:48 [+0200]:
Quoted 4 lines

drivers/input/lirc/lirc_dev.c line 291

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+	bytes_in_key = p->code_length/8 + (p->code_length%8 ? 1 : 0);

did you actually pass checkpatch.pl ?

Quoted 8 lines

yes, and while this is ugly I see no obvious CodingStyle violation.

is following better?

bytes_in_key = p->code_length/8;
if (p->code_length%8)

	bytes_in_key++;

bytes_in_key = p->code_length / 8;
if (p->code_length % 8)

	bytes_in_key++;

I meant the missing spaces around / and %. Looking now at it, it seems that it behaves like DIV_ROUND_UP(). The magic of spaces :)

Quoted 2 lines

Janne

Sebastian

#58 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 14 lines · On Tuesday 09 September 2008 14:33:35 Sebastian Siewior wrote:
Quoted 5 lines · * Janne Grunau | 2008-09-09 11:53:48 [+0200]:
Quoted 4 lines

drivers/input/lirc/lirc_dev.c line 291

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+
+	bytes_in_key = p->code_length/8 + (p->code_length%8 ? 1 : 0);

did you actually pass checkpatch.pl ?

Quoted 7 lines

yes, and while this is ugly I see no obvious CodingStyle violation.

is following better?

bytes_in_key = p->code_length/8;
if (p->code_length%8)

	bytes_in_key++;
Quoted 6 lines

bytes_in_key = p->code_length / 8;
if (p->code_length % 8)

	bytes_in_key++;

I meant the missing spaces around / and %. Looking now at it, it seems that it behaves like DIV_ROUND_UP(). The magic of spaces :)

There is also BITS_TO_LONGS(x) which does the intended. I found it only since it uses DIV_ROUND_UP. Will use that. Thanks.

Janne

#59 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Janne Grunau

Hi Janne,

Quoted 1 line · Janne Grunau

On Tuesday 09 September 2008 09:40:18 Sebastian Siewior wrote:

[...]

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+EXPORT_SYMBOL(lirc_register_plugin);

Is EXPORT_SYMBOL_GPL() possible?

Afaik yes, all drivers using this symbol are in this patchset and under GPL. If it is desireable to to use EXPORT_SYMBOL_GPL() has someone else to decide. Christoph?

Please keep EXPORT_SYMBOL().

Christoph

#60 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Sebastian Siewior
Quoted 2 lines

Do you rely on this specific major? Since your daemon opens /dev/lirc0 you don't need a fixed major do you?

Needs to change anyway 60 is already assigned for local and experimental use.

Alan

#61 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Sebastian Siewior
Quoted 2 lines · Sebastian Siewior
Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +0 -0

...

Quoted 7 lines

drivers/input/lirc/lirc_dev.c line 32

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+#include <linux/ioctl.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/smp_lock.h>

if you need this than you use the BKL back. As far as I remember the ioctl() handler in kernel core no longer takes the BKL and I don't see any locking in irctl_ioctl().

Really? .open() has been changed to be called without the BKL held, but .ioctl() is still called with BKL protection. Currently, many .ioctl() implementations are replaced by .unlocked_ioctl() which take the BKL themselves if necessary or if it is not yet clear whether they would work without BKL protection.

...

Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 734

Quoted 8 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+static struct file_operations fops = {
+	.read		= irctl_read,
+	.write		= irctl_write,
+	.poll		= irctl_poll,
+	.ioctl		= irctl_ioctl,
+	.open		= irctl_open,
+	.release	= irctl_close
+};

This should be audited for the following aspects:

- Could there be a race condition between irctl_open() and lirc_dev_init()? If yes, try to rework them to eliminate the race, or as a last resort take the BKL in irctl_open().

- Does irctl_ioctl() require BKL protection, i.e. does it have to be serialized against itself and against irctl_open()? If not, replace it by .unlocked_ioctl. If yes, preferably convert it to .unlocked_ioctl too and add a local mutex for the necessary serialization.

(Added Cc: Jonathan Corbet to correct me if I'm wrong.)

Signature · 3 lines
Stefan Richter
-=====-==--- =--= -=--=
http://arcgraph.de/sr/
#62 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Sebastian Siewior
Quoted 7 lines · On Tuesday 09 September 2008 03:40:18 Sebastian Siewior wrote:
Quoted 7 lines
drivers/input/lirc/Makefile new file +1 -0
new file mode 100644
index 0000000..cdb4c45
@@ -0,0 +1,8 @@
+# Makefile for the lirc drivers.
Quoted 8 lines

drivers/input/lirc/Makefile line 6

Quoted 5 lines
drivers/input/lirc/Makefile new file +5 -0
+#
+
+# Each configuration option enables a list of files.
+
+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)

Do you rely on this specific major? Since your daemon opens /dev/lirc0 you don't need a fixed major do you?

Good question. Quite honestly, I'm not sure. Christoph?

Quoted 3 lines

LIRC_SERIAL_TRANSMITTER is used in patch 2 and just to enable a module options. Since it is always the case, please remove it.
I haven't found the source of $src. It is probably a relic.

Janne took care of these. Heck, he's already replied, I'll just leave out the parts he already replied to...

Quoted 8 lines

drivers/input/lirc/Makefile line 4

Quoted 6 lines
drivers/input/lirc/Makefile new file +5 -0
+++ b/drivers/input/lirc/lirc_dev.c
@@ -0,0 +1,809 @@
+/*
+ * LIRC base driver
+ *
+ * (L) by Artur Lipowski <[email protected]>

Is that L here on purpose?

Historical. I think it is supposed to signify that this was originally licensed and written by Artur, but simply removing "(L) " is fine (here and in lirc_dev.h).

Quoted 7 lines

drivers/input/lirc/Makefile line 5

Quoted 1 line
drivers/input/lirc/Makefile new file +1 -0
+#include <linux/smp_lock.h>

if you need this than you use the BKL back. As far as I remember the ioctl() handler in kernel core no longer takes the BKL and I don't see any locking in irctl_ioctl().

Quoted 6 lines

drivers/input/lirc/Makefile line 8

Quoted 3 lines
drivers/input/lirc/Makefile new file +3 -0
+/*  helper function
+ *  initializes the irctl structure
+ */

For all comments above functions:
- Please use the default comment style.

Apologies, I started on that, didn't finish, then forgot about it. Will do.

Quoted 3 lines

- don't comment obvious things
- please use kernel doc if
- please comment the prototypes but the actual function.

Working on this too.

Quoted 3 lines

drivers/input/lirc/Makefile line 9

Quoted 1 line
drivers/input/lirc/Makefile new file +1 -0
+	bytes_in_key = p->code_length/8 + (p->code_length%8 ? 1 : 0);

did you actually pass checkpatch.pl ?

Yeah, but now that you point that out, I'm not sure how... :)

Taken care of by simply using BITS_TO_LONG() instead.

Quoted 3 lines

drivers/input/lirc/Makefile line 10

Quoted 1 line
drivers/input/lirc/Makefile new file +1 -0
+EXPORT_SYMBOL(lirc_register_plugin);

Is EXPORT_SYMBOL_GPL() possible?

Should be, I'm definitely not aware of any non-GPL users.

Quoted 1 line

drivers/input/lirc/Makefile line 11

Quoted 1 line
drivers/input/lirc/Makefile new file +1 -0
+EXPORT_SYMBOL(lirc_unregister_plugin);

Ditto.

Quoted 4 lines
Quoted 2 lines
drivers/input/lirc/Makefile new file +1 -0
+/* ----------------------------------------------------------------------

*/

I hate those

Me too. Gone.

Signature · 2 lines
Jarod Wilson
[email protected]
#63 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Hi,

Quoted 1 line · Jarod Wilson

On Tuesday 09 September 2008 03:40:18 Sebastian Siewior wrote:

[...]

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)

Do you rely on this specific major? Since your daemon opens /dev/lirc0 you don't need a fixed major do you?

Good question. Quite honestly, I'm not sure. Christoph?

LIRC does not rely on a specific major. But to be honest, the last time I looked into this issue, was when devfs was bleeding-edge...

So, we need some advice here how to proceed. Should we try to register an official major number for LIRC? Should we try to have a minor number mapping, e.g.
/dev/lirc/serial/0 LIRC device on 1st UART serial port
...
/dev/lirc/serial/n LIRC device on n-th UART serial port /dev/lirc/parallel/0 LIRC device on 1st parallel port
...
/dev/lirc/parallel/n LIRC device on n-th parallel port /dev/lirc/usb/0 1st LIRC USB device
...

Christoph

#64 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 17 lines · On Thursday 11 September 2008 14:30:00 Christoph Bartelmus wrote:

Hi,

Quoted 1 line · Jarod Wilson

On Tuesday 09 September 2008 03:40:18 Sebastian Siewior wrote:

[...]

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)

Do you rely on this specific major? Since your daemon opens /dev/lirc0 you don't need a fixed major do you?

Good question. Quite honestly, I'm not sure. Christoph?

LIRC does not rely on a specific major. But to be honest, the last time I looked into this issue, was when devfs was bleeding-edge...

Quoted 11 lines

So, we need some advice here how to proceed. Should we try to register an official major number for LIRC? Should we try to have a minor number mapping, e.g.
/dev/lirc/serial/0 LIRC device on 1st UART serial port
...
/dev/lirc/serial/n LIRC device on n-th UART serial port /dev/lirc/parallel/0 LIRC device on 1st parallel port
...
/dev/lirc/parallel/n LIRC device on n-th parallel port /dev/lirc/usb/0 1st LIRC USB device
...

Janne took a crack at dynamic device allocation earlier today, committed into my git tree:

http://git.wilsonet.com/linux-2.6-
lirc.git/?a=commitdiff;h=ea74897bf7b03e2ed2401df3815637caa0702eab

Haven't yet tested it out, that's on tap for tonight...

Signature · 2 lines
Jarod Wilson
[email protected]
#65 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Hi Jarod,

Quoted 25 lines · Jarod Wilson
Quoted 12 lines · On Thursday 11 September 2008 14:30:00 Christoph Bartelmus wrote:
Quoted 7 lines · Jarod Wilson
Quoted 4 lines · On Tuesday 09 September 2008 03:40:18 Sebastian Siewior wrote:
Quoted 1 line

+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)

Do you rely on this specific major? Since your daemon opens /dev/lirc0 you don't need a fixed major do you?

Good question. Quite honestly, I'm not sure. Christoph?

LIRC does not rely on a specific major. But to be honest, the last time I looked into this issue, was when devfs was bleeding-edge...

Quoted 11 lines

So, we need some advice here how to proceed. Should we try to register an official major number for LIRC? Should we try to have a minor number mapping, e.g.
/dev/lirc/serial/0 LIRC device on 1st UART serial port
...
/dev/lirc/serial/n LIRC device on n-th UART serial port /dev/lirc/parallel/0 LIRC device on 1st parallel port
...
/dev/lirc/parallel/n LIRC device on n-th parallel port /dev/lirc/usb/0 1st LIRC USB device
...

Quoted 2 lines

Janne took a crack at dynamic device allocation earlier today, committed into my git tree:

The problem is this:
http://www.lirc.org/html/configure.html#multiple

Quoting the very last paragraph:
"The only situation where the described procedure will not work is when you have two devices that both use a kernel driver that can only handle one device at once like e.g. lirc_serial, lirc_sir or lirc_parallel. You can still make it work with a trick by compiling the affected driver multiple times using different names and different major numbers. You will find detailed instructions how to achieve this by searching the mailing list. Lifting this limitation is one of the todo items for future releases."

The limitation that lirc_serial can only handle one device at a time still exists and I think we should have a concept how to solve it before the drivers are merged into the kernel.

Christoph

#66 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Jarod Wilson

Jarod Wilson <[email protected]> writes:

Just some quick comments, no complete review

Quoted 1 line

+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER -I$(src)

Put the Ds into some include instead?

drivers/input/lirc/lirc_dev.c line 52

Quoted 7 lines
drivers/input/lirc/lirc_dev.c new file +7 -0
+
+static int debug;
+#define dprintk(fmt, args...)					\
+	do {							\
+		if (debug)					\
+			printk(KERN_DEBUG fmt, ## args);	\
+	} while (0)

There's some effort to replace that all with pr_printk

drivers/input/lirc/lirc_dev.c line 167

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	dprintk(LOGHEAD "poll thread started\n", ir->p.name, ir->p.minor);
+
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));

sleep_on is really discouraged, consider replacing it with wait_event()

drivers/input/lirc/lirc_dev.c line 176

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+			}
+			if (kthread_should_stop())
+				break;
+			if (!add_to_buf(ir))
+				wake_up_interruptible(&ir->buf->wait_poll);
+		} else {
+			/* if device not opened so we can sleep half a second */
+			set_current_state(TASK_INTERRUPTIBLE);
+			schedule_timeout(HZ/2);

This means you always wake up every half a second? That will not make the powertop users happy. When there's nothing to do it should just sleep.

The checks in plugin_register seem a bit extreme.
At least make that all WARN_ONs

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+
+	/* end up polling thread */
+	if (ir->task) {
+		wake_up_process(ir->task);
+		kthread_stop(ir->task);

drivers/input/lirc/lirc_dev.c line 389

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	}
+
+	dprintk("lirc_dev: plugin %s unregistered from minor number = %d\n",
+		ir->p.name, ir->p.minor);
+
+	ir->attached = 0;
+	if (ir->open) {
+		dprintk(LOGHEAD "releasing opened plugin\n",
+			ir->p.name, ir->p.minor);
+		wake_up_interruptible(&ir->buf->wait_poll);

This seems racy with some users who are lockless

drivers/input/lirc/lirc_dev.c line 401

Quoted 12 lines
drivers/input/lirc/lirc_dev.c new file +12 -0
+		mutex_lock(&ir->buffer_lock);
+		ir->p.set_use_dec(ir->p.data);
+		module_put(ir->p.owner);
+		mutex_unlock(&ir->buffer_lock);
+	} else
+		cleanup(ir);
+	mutex_unlock(&plugin_lock);
+
+/*
+ * Recent kernels should handle this autmatically by increasing/decreasing
+ * use count when a dependant module is loaded/unloaded.
+ */

All kernels are recent now.

Quoted 23 lines
drivers/input/lirc/lirc_dev.c new file +23 -0
+#ifdef MODULE
+
+/*
+ *
+ */
+int init_module(void)
+{
+	return lirc_dev_init();
+}
+
+/*
+ *
+ */
+void cleanup_module(void)
+{
+	/* unregister_chrdev returns void now */
+	unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
+	class_destroy(lirc_class);
+	dprintk("lirc_dev: module unloaded\n");
+}
+
+MODULE_DESCRIPTION("LIRC base driver module");
+MODULE_AUTHOR("Artur Lipowski");

drivers/input/lirc/lirc_dev.c line 801

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(IRCTL_DEV_MAJOR);
+
+module_param(debug, bool, 0644);
+MODULE_PARM_DESC(debug, "Enable debugging messages");
+
+#else /* not a MODULE */
+subsys_initcall(lirc_dev_init);
+
+#endif /* MODULE */

Always use the #ifdef MODULE path, it does DTRT when compiled in too. Remove the init_module wrapper, replace with module_init()

... not read further ...
-Andi

Signature · 1 line
[email protected]
#67 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 8 lines · On Tuesday 09 September 2008 11:46:48 Andi Kleen wrote:

Jarod Wilson <[email protected]> writes:

Just some quick comments, no complete review

Review

Quoted 2 lines
(quoted diff) +1 -1
+EXTRA_CFLAGS =-DIRCTL_DEV_MAJOR=61 -DLIRC_SERIAL_TRANSMITTER
-I$(src)

Put the Ds into some include instead?

LIRC_SERIAL_TRANSMITTER is already gone, not sure that should happen to IRCTL_DEV_MAJOR but it could go into lirc.h. moved

Quoted 9 lines

drivers/input/lirc/lirc_dev.c line 52

Quoted 7 lines
drivers/input/lirc/lirc_dev.c new file +7 -0
+
+static int debug;
+#define dprintk(fmt, args...)					\
+	do {							\
+		if (debug)					\
+			printk(KERN_DEBUG fmt, ## args);	\
+	} while (0)

There's some effort to replace that all with pr_printk

pr_printk is not found in include/ nor by google. please explain

Quoted 5 lines
Quoted 5 lines
(quoted diff) +1 -0
+	dprintk(LOGHEAD "poll thread started\n", ir->p.name,

ir->p.minor); +

drivers/input/lirc/lirc_dev.c new file +3 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 167

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));

sleep_on is really discouraged, consider replacing it with wait_event()

done

Quoted 5 lines
Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+			}
+			if (kthread_should_stop())
+				break;
+			if (!add_to_buf(ir))
+				wake_up_interruptible(&ir->buf->wait_poll);
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 176

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+		} else {
+			/* if device not opened so we can sleep half a second */
+			set_current_state(TASK_INTERRUPTIBLE);
+			schedule_timeout(HZ/2);

This means you always wake up every half a second? That will not make the powertop users happy. When there's nothing to do it should just sleep.

done

Quoted 21 lines

The checks in plugin_register seem a bit extreme.
At least make that all WARN_ONs

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+
+	/* end up polling thread */
+	if (ir->task) {
+		wake_up_process(ir->task);
+		kthread_stop(ir->task);
+	}
+
+	dprintk("lirc_dev: plugin %s unregistered from minor number =

%d\n", + ir->p.name, ir->p.minor);

drivers/input/lirc/lirc_dev.c line 389

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+
+	ir->attached = 0;
+	if (ir->open) {
+		dprintk(LOGHEAD "releasing opened plugin\n",
+			ir->p.name, ir->p.minor);
+		wake_up_interruptible(&ir->buf->wait_poll);

This seems racy with some users who are lockless

Quoted 15 lines
Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+		mutex_lock(&ir->buffer_lock);
+		ir->p.set_use_dec(ir->p.data);
+		module_put(ir->p.owner);
+		mutex_unlock(&ir->buffer_lock);
+	} else
+		cleanup(ir);
+	mutex_unlock(&plugin_lock);
+
+/*
+ * Recent kernels should handle this autmatically by
Quoted 3 lines

increasing/decreasing + * use count when a dependant module is loaded/unloaded.
+ */

All kernels are recent now.

removed

Quoted 28 lines
Quoted 28 lines
drivers/input/lirc/lirc_dev.c new file +28 -0
+#ifdef MODULE
+
+/*
+ *
+ */
+int init_module(void)
+{
+	return lirc_dev_init();
+}
+
+/*
+ *
+ */
+void cleanup_module(void)
+{
+	/* unregister_chrdev returns void now */
+	unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
+	class_destroy(lirc_class);
+	dprintk("lirc_dev: module unloaded\n");
+}
+
+MODULE_DESCRIPTION("LIRC base driver module");
+MODULE_AUTHOR("Artur Lipowski");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(IRCTL_DEV_MAJOR);
+
+module_param(debug, bool, 0644);
+MODULE_PARM_DESC(debug, "Enable debugging messages");
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 801

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+
+#else /* not a MODULE */
+subsys_initcall(lirc_dev_init);
+
+#endif /* MODULE */

Always use the #ifdef MODULE path, it does DTRT when compiled in too. Remove the init_module wrapper, replace with module_init()

done

thanks for the review. My changes are until Jarod pulls them in following tree git://git.jannau.net/linux-2.6-lirc.git

Janne

#68 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 1 line

pr_printk is not found in include/ nor by google. please explain

pr_debug() sorry.

-Andi

#69 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 3 lines · On Tuesday 09 September 2008 15:03:11 Andi Kleen wrote:
Quoted 1 line

pr_printk is not found in include/ nor by google. please explain

pr_debug() sorry.

pr_debug() does something else. that dprintk macro prints depending on a module parameter

Janne

#70 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 7 lines · Janne Grunau
Quoted 3 lines · On Tuesday 09 September 2008 15:03:11 Andi Kleen wrote:
Quoted 1 line

pr_printk is not found in include/ nor by google. please explain

pr_debug() sorry.

pr_debug() does something else. that dprintk macro prints depending on a module parameter

pr_debug() is what you want, 2.6.28 will turn it into a dynamic option to turn on and off at a per-module level.

Actually you should be using dev_dbg() instead, that's much better and will also work the same way on a per-module level.

thanks,

greg k-h

#71 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Jarod Wilson

drivers/input/lirc/Kconfig line 6

Quoted 3 lines
drivers/input/lirc/Kconfig new file +3 -0
+menuconfig INPUT_LIRC
+	bool "Linux Infrared Remote Control IR receiver/transmitter drivers"
+	default n

n is the default, no needed add a "default n" line for it.

Anyone configuring the kernel should know he's on Linux, so strike the Linux away :)

drivers/input/lirc/Kconfig line 19

Quoted 7 lines
drivers/input/lirc/Kconfig new file +7 -0
+if INPUT_LIRC
+
+config LIRC_DEV
+	tristate "LIRC device loadable module support"
+	default n
+	help
+	  LIRC device loadable module support, required for most LIRC drivers

Obviously this can be built in, so it should be named better. Also I don't think LIRC means anything to a user, so use Infrared Remote Control support or something similar instead.

I don't quite understand why this needs a different option from INPUT_LIRC.

Quoted 1 line

+#define __KERNEL_SYSCALLS__

No need for this in any semi-recent kernel.

drivers/input/lirc/lirc_dev.c line 42

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+#include <linux/unistd.h>
+#include <linux/kthread.h>
+
+/* SysFS header */
+#include <linux/device.h>

That comment is not quite correct, just remove it.

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+/*  helper function
+ *  initializes the irctl structure
+ */
+static inline void init_irctl(struct irctl *ir)
+{

drivers/input/lirc/lirc_dev.c line 94

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	memset(&ir->p, 0, sizeof(struct lirc_plugin));
+	mutex_init(&ir->buffer_lock);
+	ir->p.minor = NOPLUG;
+
+	ir->task = NULL;
+	ir->jiffies_to_wait = 0;
+
+	ir->open = 0;
+	ir->attached = 0;
+}

Please don't mark funtion inline unless there's a very good reason for it.

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+static void cleanup(struct irctl *ir)
+{
+	dprintk(LOGHEAD "cleaning up\n", ir->p.name, ir->p.minor);
+

drivers/input/lirc/lirc_dev.c line 109

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	device_destroy(lirc_class, MKDEV(IRCTL_DEV_MAJOR, ir->p.minor));
+
+	if (ir->buf != ir->p.rbuf) {
+		lirc_buffer_free(ir->buf);
+		kfree(ir->buf);
+	}
+	ir->buf = NULL;
+
+	init_irctl(ir);
+}

What's the init doing in a cleanup routine? Oh, you initialize it again becaus of the static array. I think the right approach is to dynamically allocate struct irctl.

Quoted 1 line

+static inline int add_to_buf(struct irctl *ir)

The inline thing also applies here and in various other placez.

Quoted 19 lines
drivers/input/lirc/lirc_dev.c new file +19 -0
+{
+	if (lirc_buffer_full(ir->buf)) {
+		dprintk(LOGHEAD "buffer overflow\n",
+			ir->p.name, ir->p.minor);
+		return -EOVERFLOW;
+	}
+
+	if (ir->p.add_to_buf) {
+		int res = -ENODATA;
+		int got_data = 0;
+
+		/* service the device as long as it is returning
+		 * data and we have space
+		 */
+		while (!lirc_buffer_full(ir->buf)) {
+			res = ir->p.add_to_buf(ir->p.data, ir->buf);
+			if (res == SUCCESS)
+				got_data++;
+			else

drivers/input/lirc/lirc_dev.c line 145

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+				break;
+		}
+
+		if (res == -ENODEV)
+			kthread_stop(ir->task);
+
+		return got_data ? SUCCESS : res;
+	}
+
+	return SUCCESS;

I guess success is a #define for 0? Just user 0 directly. Also the kthread_stop here looks odd. The normal way to use kthreads is to start them when bringing up an interface of some sorts, and call kthread_stop when the interface is brought down. Doing it in a routine like this screams "unclear lifetime rules".

drivers/input/lirc/lirc_dev.c line 168

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}

No sleep on, please. But this one should be trivial to fix anyway, by just changing this to a

	set_current_state(TASK_INTERRUPTIBLE);
	schedule();

and using wake_up_process in the wakeup path.

drivers/input/lirc/lirc_dev.c line 177

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+		} else {
+			/* if device not opened so we can sleep half a second */
+			set_current_state(TASK_INTERRUPTIBLE);
+			schedule_timeout(HZ/2);
+		}

Yikes. This should use some form of more fine-grained wakeus.

drivers/input/lirc/lirc_dev.c line 186

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+int lirc_register_plugin(struct lirc_plugin *p)
+{

Please add a kerneldoc comments for exported functions like this, instead of the comments in the header.

drivers/input/lirc/lirc_dev.c line 198

Quoted 12 lines
drivers/input/lirc/lirc_dev.c new file +12 -0
+	struct irctl *ir;
+	int minor;
+	int bytes_in_key;
+	int err;
+	DECLARE_COMPLETION(tn);
+
+	if (!p) {
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "plugin pointer must be not NULL!\n");
+		err = -EBADRQC;
+		goto out;
+	}

No need for this, a null pointer derference should be a clear enough warning for the writer of the broken pluging..

Quoted 1 line

+int lirc_unregister_plugin(int minor)

Why doesn't this one take a struct lirc_plugin pointer?

drivers/input/lirc/lirc_dev.c line 356

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+{
+	struct irctl *ir;
+	DECLARE_COMPLETION(tn);
+	DECLARE_COMPLETION(tn2);

both completion seems unused.

drivers/input/lirc/lirc_dev.c line 380

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+	/* end up polling thread */
+	if (ir->task) {
+		wake_up_process(ir->task);
+		kthread_stop(ir->task);
+	}

kthread_stop already wakes the thread up.

drivers/input/lirc/lirc_dev.c line 403

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+/*
+ * Recent kernels should handle this autmatically by increasing/decreasing
+ * use count when a dependant module is loaded/unloaded.
+ */
+
+	return SUCCESS;

The comment above looks superflous.

drivers/input/lirc/lirc_dev.c line 415

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+static int irctl_open(struct inode *inode, struct file *file)
+{
+	struct irctl *ir;
+	int retval;
+
+	if (MINOR(inode->i_rdev) >= MAX_IRCTL_DEVICES) {

iminor.

drivers/input/lirc/lirc_dev.c line 427

Quoted 3 lines
drivers/input/lirc/lirc_dev.c new file +3 -0
+	/* if the plugin has an open function use it instead */
+	if (ir->p.fops && ir->p.fops->open)
+		return ir->p.fops->open(inode, file);

in which case this 'plugin' should just install it's own fops. Thanks to cdev_add we can install fops at minor number granularity.

drivers/input/lirc/lirc_dev.c line 519

Quoted 12 lines
drivers/input/lirc/lirc_dev.c new file +12 -0
+static unsigned int irctl_poll(struct file *file, poll_table *wait)
+{
+	struct irctl *ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
+	unsigned int ret;
+
+	dprintk(LOGHEAD "poll called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a poll function use it instead */
+	if (ir->p.fops && ir->p.fops->poll)
+		return ir->p.fops->poll(file, wait);
+
+	mutex_lock(&ir->buffer_lock);

->poll ust not sleep.

Quoted 3 lines

+/*
+ *
+ */

???

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+
+void *lirc_get_pdata(struct file *file)
+{
+	void *data = NULL;
+

drivers/input/lirc/lirc_dev.c line 706

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	if (file && file->f_dentry && file->f_dentry->d_inode &&
+	    file->f_dentry->d_inode->i_rdev) {
+		struct irctl *ir;
+		ir = &irctls[MINOR(file->f_dentry->d_inode->i_rdev)];
+		data = ir->p.data;
+	}
+
+	return data;
+}
+EXPORT_SYMBOL(lirc_get_pdata);

Yikes. All these should never really be null. But once you have a struct file you should just use file->private_data.

drivers/input/lirc/lirc_dev.h line 20

Quoted 6 lines
drivers/input/lirc/lirc_dev.h new file +6 -0
+/* #define LIRC_BUFF_POWER_OF_2 */
+#ifdef LIRC_BUFF_POWER_OF_2
+#define mod(n, div) ((n) & ((div) - 1))
+#else
+#define mod(n, div) ((n) % (div))
+#endif

??

Quoted 23 lines
drivers/input/lirc/lirc_dev.h new file +23 -0
+static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
+{
+	buf->head = 0;
+	buf->tail = 0;
+	buf->fill = 0;
+}
+static inline int lirc_buffer_init(struct lirc_buffer *buf,
+				    unsigned int chunk_size,
+				    unsigned int size)
+{
+	/* Adjusting size to the next power of 2 would allow for
+	 * inconditional LIRC_BUFF_POWER_OF_2 optimization */
+	init_waitqueue_head(&buf->wait_poll);
+	spin_lock_init(&buf->lock);
+	_lirc_buffer_clear(buf);
+	buf->chunk_size = chunk_size;
+	buf->size = size;
+	buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
+	if (buf->data == NULL)
+		return -1;
+	memset(buf->data, 0, size*chunk_size);
+	return 0;
+}

drivers/input/lirc/lirc_dev.h line 68

Quoted 10 lines
drivers/input/lirc/lirc_dev.h new file +10 -0
+static inline void lirc_buffer_free(struct lirc_buffer *buf)
+{
+	kfree(buf->data);
+	buf->data = NULL;
+	buf->head = 0;
+	buf->tail = 0;
+	buf->fill = 0;
+	buf->chunk_size = 0;
+	buf->size = 0;
+}

Please move these out of line. And please document all the functions. Or switch to a kfifo or the existing tty buffering helpers.

drivers/input/lirc/lirc_dev.h line 90

Quoted 10 lines
drivers/input/lirc/lirc_dev.h new file +10 -0
+static inline void lirc_buffer_lock(struct lirc_buffer *buf,
+				    unsigned long *flags)
+{
+	spin_lock_irqsave(&buf->lock, *flags);
+}
+static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
+				      unsigned long *flags)
+{
+	spin_unlock_irqrestore(&buf->lock, *flags);
+}

Please don't do you own spinlock wrappers.

#72 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 13 lines · On Tuesday 09 September 2008 15:01:02 Christoph Hellwig wrote:

drivers/input/lirc/lirc_dev.c line 168

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}

No sleep on, please. But this one should be trivial to fix anyway, by just changing this to a

Quoted 4 lines
	set_current_state(TASK_INTERRUPTIBLE);
	schedule();

and using wake_up_process in the wakeup path.

No driver uses the get_queue callback. So I'm inclined to just remove it. Christoph, any objections?

Janne

#73 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 15 lines · Janne Grunau
Quoted 13 lines · On Tuesday 09 September 2008 15:01:02 Christoph Hellwig wrote:

drivers/input/lirc/lirc_dev.c line 168

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}

No sleep on, please. But this one should be trivial to fix anyway, by just changing this to a

Quoted 7 lines
Quoted 4 lines
	set_current_state(TASK_INTERRUPTIBLE);
	schedule();

and using wake_up_process in the wakeup path.

No driver uses the get_queue callback. So I'm inclined to just remove it. Christoph, any objections?

Sounds good.

#74 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 18 lines · On Wednesday 10 September 2008 14:29:43 Christoph Hellwig wrote:
Quoted 17 lines · Janne Grunau
Quoted 16 lines · On Tuesday 09 September 2008 15:01:02 Christoph Hellwig wrote:

drivers/input/lirc/lirc_dev.c line 168

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}

No sleep on, please. But this one should be trivial to fix anyway, by just changing this to a

	set_current_state(TASK_INTERRUPTIBLE);
	schedule();
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

and using wake_up_process in the wakeup path.

No driver uses the get_queue callback. So I'm inclined to just remove it. Christoph, any objections?

Sounds good.

Oh, just realized that there are two Christophs in TO an CC, I meant Christoph Bartelmus, the LIRC maintainer, sorry.

Janne

#75 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Janne Grunau

Hi Janne,

Quoted 15 lines · Janne Grunau
Quoted 13 lines · On Tuesday 09 September 2008 15:01:02 Christoph Hellwig wrote:

drivers/input/lirc/lirc_dev.c line 168

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}

No sleep on, please. But this one should be trivial to fix anyway, by just changing this to a

Quoted 7 lines
Quoted 4 lines
	set_current_state(TASK_INTERRUPTIBLE);
	schedule();

and using wake_up_process in the wakeup path.

No driver uses the get_queue callback. So I'm inclined to just remove it. Christoph, any objections?

lirc_gpio is using it.
I guess there will be no need to use lirc_gpio in future, but I'd like to keep this in CVS for people who still use it.

Christoph

#76 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 20 lines · On Thursday 11 September 2008 20:03:00 Christoph Bartelmus wrote:

Hi Janne,

Quoted 17 lines · Janne Grunau
Quoted 16 lines · On Tuesday 09 September 2008 15:01:02 Christoph Hellwig wrote:

drivers/input/lirc/lirc_dev.c line 168

Quoted 9 lines
drivers/input/lirc/lirc_dev.c new file +9 -0
+	do {
+		if (ir->open) {
+			if (ir->jiffies_to_wait) {
+				set_current_state(TASK_INTERRUPTIBLE);
+				schedule_timeout(ir->jiffies_to_wait);
+			} else {
+				interruptible_sleep_on(
+					ir->p.get_queue(ir->p.data));
+			}

No sleep on, please. But this one should be trivial to fix anyway, by just changing this to a

	set_current_state(TASK_INTERRUPTIBLE);
	schedule();
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

and using wake_up_process in the wakeup path.

No driver uses the get_queue callback. So I'm inclined to just remove it. Christoph, any objections?

lirc_gpio is using it.
I guess there will be no need to use lirc_gpio in future, but I'd like to keep this in CVS for people who still use it.

We don't have lirc_gpio in the kernel tree? And I guess there is no need to integrate into the kernel. I've removed it already.

Janne

Quoted 1 line

Christoph

#77 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Christoph Hellwig
Quoted 5 lines · On Tuesday 09 September 2008 15:01:02 Christoph Hellwig wrote:
Quoted 3 lines
(quoted diff) +2 -0
+menuconfig INPUT_LIRC
+	bool "Linux Infrared Remote Control IR receiver/transmitter

drivers" + default n

n is the default, no needed add a "default n" line for it.

removed

Quoted 4 lines
Quoted 4 lines
drivers/input/lirc/Kconfig new file +4 -0
+if INPUT_LIRC
+
+config LIRC_DEV
+	tristate "LIRC device loadable module support"
Quoted 8 lines
Quoted 4 lines
drivers/input/lirc/Kconfig new file +3 -0
+	default n
+	help
+	  LIRC device loadable module support, required for most LIRC

drivers

Obviously this can be built in, so it should be named better. Also I don't think LIRC means anything to a user, so use Infrared Remote Control support or something similar instead.

I'm pretty sure LIRC will be recognized by its current users, it is probably enough if it is in the help text though.

Quoted 3 lines
Quoted 1 line

+#define __KERNEL_SYSCALLS__

No need for this in any semi-recent kernel.

already gone

Quoted 7 lines

drivers/input/lirc/lirc_dev.c line 42

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+#include <linux/unistd.h>
+#include <linux/kthread.h>
+
+/* SysFS header */
+#include <linux/device.h>

That comment is not quite correct, just remove it.

removed

Quoted 10 lines
Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+/*  helper function
+ *  initializes the irctl structure
+ */
+static inline void init_irctl(struct irctl *ir)
+{
+	memset(&ir->p, 0, sizeof(struct lirc_plugin));
+	mutex_init(&ir->buffer_lock);
+	ir->p.minor = NOPLUG;
+
+	ir->task = NULL;
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 94

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+	ir->jiffies_to_wait = 0;
+
+	ir->open = 0;
+	ir->attached = 0;
+}

Please don't mark funtion inline unless there's a very good reason for it.

all inlines (65 in drivers/inpu/lirc) removed

Quoted 10 lines
Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+static void cleanup(struct irctl *ir)
+{
+	dprintk(LOGHEAD "cleaning up\n", ir->p.name, ir->p.minor);
+
+	device_destroy(lirc_class, MKDEV(IRCTL_DEV_MAJOR, ir->p.minor));
+
+	if (ir->buf != ir->p.rbuf) {
+		lirc_buffer_free(ir->buf);
+		kfree(ir->buf);
+	}
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 109

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+	ir->buf = NULL;
+
+	init_irctl(ir);
+}

What's the init doing in a cleanup routine? Oh, you initialize it again becaus of the static array. I think the right approach is to dynamically allocate struct irctl.

agree, it's done dynamically now

Quoted 23 lines
Quoted 23 lines
drivers/input/lirc/lirc_dev.c new file +23 -0
+{
+	if (lirc_buffer_full(ir->buf)) {
+		dprintk(LOGHEAD "buffer overflow\n",
+			ir->p.name, ir->p.minor);
+		return -EOVERFLOW;
+	}
+
+	if (ir->p.add_to_buf) {
+		int res = -ENODATA;
+		int got_data = 0;
+
+		/* service the device as long as it is returning
+		 * data and we have space
+		 */
+		while (!lirc_buffer_full(ir->buf)) {
+			res = ir->p.add_to_buf(ir->p.data, ir->buf);
+			if (res == SUCCESS)
+				got_data++;
+			else
+				break;
+		}
+
+		if (res == -ENODEV)
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 145

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+			kthread_stop(ir->task);
+
+		return got_data ? SUCCESS : res;
+	}
+
+	return SUCCESS;

I guess success is a #define for 0? Just user 0 directly.

yes, already removed. also removed custom TRUE/FALSE defines

Quoted 6 lines

Also the
kthread_stop here looks odd. The normal way to use kthreads is to start them when bringing up an interface of some sorts, and call kthread_stop when the interface is brought down. Doing it in a routine like this screams "unclear lifetime rules".

Quoted 7 lines

drivers/input/lirc/lirc_dev.c line 177

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+		} else {
+			/* if device not opened so we can sleep half a second */
+			set_current_state(TASK_INTERRUPTIBLE);
+			schedule_timeout(HZ/2);
+		}

Yikes. This should use some form of more fine-grained wakeus.

added a waitqueue and wait_event

Quoted 7 lines
Quoted 7 lines
drivers/input/lirc/lirc_dev.c new file +7 -0
+	struct irctl *ir;
+	int minor;
+	int bytes_in_key;
+	int err;
+	DECLARE_COMPLETION(tn);
+
+	if (!p) {
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 198

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+		printk(KERN_ERR "lirc_dev: lirc_register_plugin: "
+		       "plugin pointer must be not NULL!\n");
+		err = -EBADRQC;
+		goto out;
+	}

No need for this, a null pointer derference should be a clear enough warning for the writer of the broken pluging..

ok

Quoted 3 lines
Quoted 1 line

+int lirc_unregister_plugin(int minor)

Why doesn't this one take a struct lirc_plugin pointer?

I don't know, It doesn't really help though since the struct lirc_plugin is copied by value to irctl.p in lirc_register_plugin.

Quoted 6 lines

drivers/input/lirc/lirc_dev.c line 356

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+{
+	struct irctl *ir;
+	DECLARE_COMPLETION(tn);
+	DECLARE_COMPLETION(tn2);

both completion seems unused.

the one in lirc_register_plugin too, removed

Quoted 7 lines

drivers/input/lirc/lirc_dev.c line 380

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+	/* end up polling thread */
+	if (ir->task) {
+		wake_up_process(ir->task);
+		kthread_stop(ir->task);
+	}

kthread_stop already wakes the thread up.

removed

Quoted 9 lines

Review

Quoted 7 lines

+/*
+ * Recent kernels should handle this autmatically by increasing/decreasing + * use count when a dependant module is loaded/unloaded.
+ */

(quoted diff) +2 -0
+
+	return SUCCESS;

The comment above looks superflous.

already removed.

Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 415

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+static int irctl_open(struct inode *inode, struct file *file)
+{
+	struct irctl *ir;
+	int retval;
+
+	if (MINOR(inode->i_rdev) >= MAX_IRCTL_DEVICES) {

iminor.

replaced in all occurances

Quoted 6 lines

drivers/input/lirc/lirc_dev.c line 427

Quoted 3 lines
drivers/input/lirc/lirc_dev.c new file +3 -0
+	/* if the plugin has an open function use it instead */
+	if (ir->p.fops && ir->p.fops->open)
+		return ir->p.fops->open(inode, file);

in which case this 'plugin' should just install it's own fops. Thanks to cdev_add we can install fops at minor number granularity.

done

Quoted 7 lines
Quoted 7 lines

+static unsigned int irctl_poll(struct file *file, poll_table *wait) +{

(quoted diff) +1 -0
+	struct irctl *ir =

&irctls[MINOR(file->f_dentry->d_inode->i_rdev)]; + unsigned int
ret;

drivers/input/lirc/lirc_dev.c new file +2 -0
+
+	dprintk(LOGHEAD "poll called\n", ir->p.name, ir->p.minor);
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 519

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+
+	/* if the plugin has a poll function use it instead */
+	if (ir->p.fops && ir->p.fops->poll)
+		return ir->p.fops->poll(file, wait);
+
+	mutex_lock(&ir->buffer_lock);

->poll ust not sleep.

I don't see why poll has to hold the lock, removed

Quoted 6 lines

drivers/input/lirc/lirc_dev.h line 20

Quoted 6 lines
drivers/input/lirc/lirc_dev.h new file +6 -0
+/* #define LIRC_BUFF_POWER_OF_2 */
+#ifdef LIRC_BUFF_POWER_OF_2
+#define mod(n, div) ((n) & ((div) - 1))
+#else
+#define mod(n, div) ((n) % (div))
+#endif

removed

Quoted 29 lines
Quoted 29 lines
drivers/input/lirc/lirc_dev.h new file +29 -0
+static inline void _lirc_buffer_clear(struct lirc_buffer *buf)
+{
+	buf->head = 0;
+	buf->tail = 0;
+	buf->fill = 0;
+}
+static inline int lirc_buffer_init(struct lirc_buffer *buf,
+				    unsigned int chunk_size,
+				    unsigned int size)
+{
+	/* Adjusting size to the next power of 2 would allow for
+	 * inconditional LIRC_BUFF_POWER_OF_2 optimization */
+	init_waitqueue_head(&buf->wait_poll);
+	spin_lock_init(&buf->lock);
+	_lirc_buffer_clear(buf);
+	buf->chunk_size = chunk_size;
+	buf->size = size;
+	buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
+	if (buf->data == NULL)
+		return -1;
+	memset(buf->data, 0, size*chunk_size);
+	return 0;
+}
+static inline void lirc_buffer_free(struct lirc_buffer *buf)
+{
+	kfree(buf->data);
+	buf->data = NULL;
+	buf->head = 0;
+	buf->tail = 0;
Quoted 8 lines

drivers/input/lirc/lirc_dev.h line 68

Quoted 4 lines
drivers/input/lirc/lirc_dev.h new file +4 -0
+	buf->fill = 0;
+	buf->chunk_size = 0;
+	buf->size = 0;
+}

Please move these out of line. And please document all the functions. Or switch to a kfifo or the existing tty buffering helpers.

I'll look at it.

Quoted 4 lines
Quoted 4 lines
drivers/input/lirc/lirc_dev.h new file +4 -0
+static inline void lirc_buffer_lock(struct lirc_buffer *buf,
+				    unsigned long *flags)
+{
+	spin_lock_irqsave(&buf->lock, *flags);
Quoted 8 lines

drivers/input/lirc/lirc_dev.h line 90

Quoted 6 lines
drivers/input/lirc/lirc_dev.h new file +6 -0
+}
+static inline void lirc_buffer_unlock(struct lirc_buffer *buf,
+				      unsigned long *flags)
+{
+	spin_unlock_irqrestore(&buf->lock, *flags);
+}

Please don't do you own spinlock wrappers.

removed

Thanks for the review.

Janne

#78 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 2 lines · Janne Grunau

I'm pretty sure LIRC will be recognized by its current users, it is probably enough if it is in the help text though.

But we don't care just for your current users :) Kernel features / drivers do need good descriptions.

Quoted 9 lines
Quoted 7 lines

drivers/input/lirc/lirc_dev.c line 177

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+		} else {
+			/* if device not opened so we can sleep half a second */
+			set_current_state(TASK_INTERRUPTIBLE);
+			schedule_timeout(HZ/2);
+		}

Yikes. This should use some form of more fine-grained wakeus.

added a waitqueue and wait_event

I don't think you'll need a wait queue - you can just call wake_up_process on ir->task while the thread just sleeps in schedule().

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+int lirc_unregister_plugin(int minor)

Why doesn't this one take a struct lirc_plugin pointer?

I don't know, It doesn't really help though since the struct lirc_plugin is copied by value to irctl.p in lirc_register_plugin.

Well, the lifetime rules for these structures seems a litte odd. I would except this to work like:

struct lirc_plugin statically allocated by the driver, then passed into lirc_register_plugin, which dynamically allocates an irdev. The irdev would point to the plugin, not copy it.

And btw, any chance for an s/plugin/driver/g - that's the terminology we use everywhere else in the kernel.

#79 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 6 lines · On Friday 12 September 2008 04:33:32 Christoph Hellwig wrote:
Quoted 2 lines · Janne Grunau

I'm pretty sure LIRC will be recognized by its current users, it is probably enough if it is in the help text though.

But we don't care just for your current users :) Kernel features / drivers do need good descriptions.

I'll work on that, as well as some less terse help texts.

[...wait queue and lifetime bits snipped, Janne's handling 'em...]

Quoted 2 lines

And btw, any chance for an s/plugin/driver/g - that's the terminology we use everywhere else in the kernel.

Done. (will push after doing a quick sanity build-test to make sure I didn't miss anything)

Signature · 2 lines
Jarod Wilson
[email protected]
#80 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Jarod Wilson

I think it's most cool that this code is finally making its way toward the mainline. What I have is mostly nits...

Quoted 2 lines
(quoted diff) +2 -0
+int lirc_unregister_plugin(int minor)
+{

...

drivers/input/lirc/lirc_dev.c line 380

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+	/* end up polling thread */
+	if (ir->task) {
+		wake_up_process(ir->task);
+		kthread_stop(ir->task);
+	}

kthread_stop() will wake up the process, so there is no need to do it separately here. In fact, it almost looks like the separate wake_up_process() call could create an (unlikely) race where the thread would miss the fact that it's supposed to stop and sleep again. Fixing the sleep_on() call there to use something like wait_event() would help in that regard.

drivers/input/lirc/lirc_dev.c line 415

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+static int irctl_open(struct inode *inode, struct file *file)
+{
+	struct irctl *ir;
+	int retval;
+
+	if (MINOR(inode->i_rdev) >= MAX_IRCTL_DEVICES) {

All of these might be better as iminor(inode)

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+		dprintk("lirc_dev [%d]: open result = -ENODEV\n",
+			MINOR(inode->i_rdev));
+		return -ENODEV;
+	}
+

drivers/input/lirc/lirc_dev.c line 430

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "open called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has an open function use it instead */
+	if (ir->p.fops && ir->p.fops->open)
+		return ir->p.fops->open(inode, file);
+
+	if (mutex_lock_interruptible(&plugin_lock))
+		return -ERESTARTSYS;

So the plugin open() function is called outside of any lock. Note that open() no longer has BKL protection as of 2.6.27. This might all be OK, but I hope you're convinced of it.

...

drivers/input/lirc/lirc_dev.c line 456

Quoted 3 lines
drivers/input/lirc/lirc_dev.c new file +3 -0
+	if (ir->p.owner != NULL && try_module_get(ir->p.owner)) {
+		++ir->open;
+		retval = ir->p.set_use_inc(ir->p.data);

Why is there a set_use_inc() function separate from open()?

drivers/input/lirc/lirc_dev.c line 468

Quoted 11 lines
drivers/input/lirc/lirc_dev.c new file +11 -0
+		if (retval != SUCCESS) {
+			module_put(ir->p.owner);
+			--ir->open;
+		}
+	} else {
+		if (ir->p.owner == NULL)
+			dprintk(LOGHEAD "no module owner!!!\n",
+				ir->p.name, ir->p.minor);
+
+		retval = -ENODEV;
+	}

If "no owner" is a fatal condition, it seems better to check it when the plugin is registered. (Also, BTW, your variant of dprintk() is confusing to read - I was wondering where all the %'s were. I still wonder, actually. dev_printk() would be better.)

drivers/input/lirc/lirc_dev.c line 490

Quoted 12 lines
drivers/input/lirc/lirc_dev.c new file +12 -0
+static int irctl_close(struct inode *inode, struct file *file)
+{
+	struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "close called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a close function use it instead */
+	if (ir->p.fops && ir->p.fops->release)
+		return ir->p.fops->release(inode, file);
+
+	if (mutex_lock_interruptible(&plugin_lock))
+		return -ERESTARTSYS;

Should this be interruptible? You probably want the close call to get its job done. Maybe mutex_lock_killable() - and still do the cleanup on a signal?

Quoted 16 lines
drivers/input/lirc/lirc_dev.c new file +16 -0
+static int irctl_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg)
+{
+	unsigned long mode;
+	int result;
+	struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "ioctl called (0x%x)\n",
+		ir->p.name, ir->p.minor, cmd);
+
+	/* if the plugin has a ioctl function use it instead */
+	if (ir->p.fops && ir->p.fops->ioctl)
+		return ir->p.fops->ioctl(inode, file, cmd, arg);
+
+	if (ir->p.minor == NOPLUG || !ir->attached) {
+		dprintk(LOGHEAD "ioctl result = -ENODEV\n",

drivers/input/lirc/lirc_dev.c line 565

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+			ir->p.name, ir->p.minor);
+		return -ENODEV;
+	}
+
+	/* Give the plugin a chance to handle the ioctl */
+	if (ir->p.ioctl) {
+		result = ir->p.ioctl(inode, file, cmd, arg);
+		if (result != -ENOIOCTLCMD)
+			return result;
+	}

Why two ioctl() handlers? It seems better to just have one way for plugins to handle this call.

...

drivers/input/lirc/lirc_dev.c line 598

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+	default:
+		result = -ENOIOCTLCMD;

Hmm, I note with interest that unlocked_ioctl() remaps -ENOIOCTLCMD to -EINVAL, while regular, locked ioctl() (which this is) does not. Not sure what to make of that.

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+static ssize_t irctl_read(struct file *file,
+			  char *buffer,
+			  size_t length,
+			  loff_t *ppos)
+{

...

drivers/input/lirc/lirc_dev.c line 673

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+			schedule();
+			set_current_state(TASK_INTERRUPTIBLE);
+			if (!ir->attached) {
+				ret = -ENODEV;
+				break;
+			}

How can ir->attached go to zero? You checked it earlier and have been holding the mutex ever since.

drivers/input/lirc/lirc_dev.c line 718

Quoted 11 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+static ssize_t irctl_write(struct file *file, const char *buffer,
+			   size_t length, loff_t *ppos)
+{
+	struct irctl *ir =

&irctls[MINOR(file->f_dentry->d_inode->i_rdev)];

drivers/input/lirc/lirc_dev.c new file +3 -0
+	dprintk(LOGHEAD "write called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a specific read function use it instead

*/

drivers/input/lirc/lirc_dev.c new file +2 -0
+	if (ir->p.fops && ir->p.fops->write)
+		return ir->p.fops->write(file, buffer, length, ppos);

Looks like you're using the "specific write function" instead :)

drivers/input/lirc/lirc_dev.c line 734

Quoted 8 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+static struct file_operations fops = {
+	.read		= irctl_read,
+	.write		= irctl_write,
+	.poll		= irctl_poll,
+	.ioctl		= irctl_ioctl,
+	.open		= irctl_open,
+	.release	= irctl_close
+};

You should probably set .owner too.

Quoted 22 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+static int lirc_dev_init(void)
+{
+	int i;
+
+	for (i = 0; i < MAX_IRCTL_DEVICES; ++i)
+		init_irctl(&irctls[i]);
+
+	if (register_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME, &fops))

{

(quoted diff) +1 -0
+		printk(KERN_ERR "lirc_dev: register_chrdev

failed\n");

drivers/input/lirc/lirc_dev.c new file +10 -0
+		goto out;
+	}
+
+	lirc_class = class_create(THIS_MODULE, "lirc");
+	if (IS_ERR(lirc_class)) {
+		printk(KERN_ERR "lirc_dev: class_create failed\n");
+		goto out_unregister;
+	}
+
+	printk(KERN_INFO "lirc_dev: IR Remote Control driver

registered, "

drivers/input/lirc/lirc_dev.c line 765

Quoted 10 lines
drivers/input/lirc/lirc_dev.c new file +10 -0
+	       "major %d \n", IRCTL_DEV_MAJOR);
+
+	return SUCCESS;
+
+out_unregister:
+	/* unregister_chrdev returns void now */
+	unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
+out:
+	return -1;
+}

Do you want to fail completely if class_create() fails? What if somebody already opened one of your devices?

Quoted 7 lines
drivers/input/lirc/lirc_dev.h new file +7 -0
+static inline int lirc_buffer_init(struct lirc_buffer *buf,
+				    unsigned int chunk_size,
+				    unsigned int size)
+{
+	/* Adjusting size to the next power of 2 would allow for
+	 * inconditional LIRC_BUFF_POWER_OF_2 optimization */
+	init_waitqueue_head(&buf->wait_poll);

drivers/input/lirc/lirc_dev.h line 58

Quoted 10 lines
drivers/input/lirc/lirc_dev.h new file +10 -0
+	spin_lock_init(&buf->lock);
+	_lirc_buffer_clear(buf);
+	buf->chunk_size = chunk_size;
+	buf->size = size;
+	buf->data = kmalloc(size*chunk_size, GFP_KERNEL);
+	if (buf->data == NULL)
+		return -1;
+	memset(buf->data, 0, size*chunk_size);
+	return 0;
+}

All of these inlines probably shouldn't be.

jon

#81 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 2 lines · On Tuesday 09 September 2008 17:33:08 Jonathan Corbet wrote:

I think it's most cool that this code is finally making its way toward the mainline. What I have is mostly nits...

ignoring bits already handled in Christoph Hellwig's review

Quoted 11 lines
Quoted 11 lines
drivers/input/lirc/lirc_dev.c new file +11 -0
+		dprintk("lirc_dev [%d]: open result = -ENODEV\n",
+			MINOR(inode->i_rdev));
+		return -ENODEV;
+	}
+
+	ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "open called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has an open function use it instead */
+	if (ir->p.fops && ir->p.fops->open)
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 430

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+		return ir->p.fops->open(inode, file);
+
+	if (mutex_lock_interruptible(&plugin_lock))
+		return -ERESTARTSYS;

So the plugin open() function is called outside of any lock. Note that open() no longer has BKL protection as of 2.6.27. This might all be OK, but I hope you're convinced of it.

plugins fops are called directly now

Quoted 5 lines

drivers/input/lirc/lirc_dev.c line 456

Quoted 3 lines
drivers/input/lirc/lirc_dev.c new file +3 -0
+	if (ir->p.owner != NULL && try_module_get(ir->p.owner)) {
+		++ir->open;
+		retval = ir->p.set_use_inc(ir->p.data);

Why is there a set_use_inc() function separate from open()?

since not all plugins set p.fops? some of those functions in the drivers are even empty. I'll look at it.

Quoted 6 lines
Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+		if (retval != SUCCESS) {
+			module_put(ir->p.owner);
+			--ir->open;
+		}
+	} else {
+		if (ir->p.owner == NULL)
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 468

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+			dprintk(LOGHEAD "no module owner!!!\n",
+				ir->p.name, ir->p.minor);
+
+		retval = -ENODEV;
+	}

If "no owner" is a fatal condition, it seems better to check it when the plugin is registered.

maybe because it's not needed if the plugin has its own fops.open?

Quoted 3 lines

(Also, BTW, your variant of dprintk() is
confusing to read - I was wondering where all the %'s were. I still wonder, actually. dev_printk() would be better.)

the LOGHEAD define is confusing, I'll look into make more clear

Quoted 8 lines
Quoted 8 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+static int irctl_close(struct inode *inode, struct file *file)
+{
+	struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "close called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a close function use it instead */
+	if (ir->p.fops && ir->p.fops->release)
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 490

Quoted 4 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+		return ir->p.fops->release(inode, file);
+
+	if (mutex_lock_interruptible(&plugin_lock))
+		return -ERESTARTSYS;

Should this be interruptible? You probably want the close call to get its job done. Maybe mutex_lock_killable() - and still do the cleanup on a signal?

That's better than the current state.

Quoted 21 lines
Quoted 21 lines
drivers/input/lirc/lirc_dev.c new file +21 -0
+static int irctl_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg)
+{
+	unsigned long mode;
+	int result;
+	struct irctl *ir = &irctls[MINOR(inode->i_rdev)];
+
+	dprintk(LOGHEAD "ioctl called (0x%x)\n",
+		ir->p.name, ir->p.minor, cmd);
+
+	/* if the plugin has a ioctl function use it instead */
+	if (ir->p.fops && ir->p.fops->ioctl)
+		return ir->p.fops->ioctl(inode, file, cmd, arg);
+
+	if (ir->p.minor == NOPLUG || !ir->attached) {
+		dprintk(LOGHEAD "ioctl result = -ENODEV\n",
+			ir->p.name, ir->p.minor);
+		return -ENODEV;
+	}
+
+	/* Give the plugin a chance to handle the ioctl */
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 565

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+	if (ir->p.ioctl) {
+		result = ir->p.ioctl(inode, file, cmd, arg);
+		if (result != -ENOIOCTLCMD)
+			return result;
+	}

Why two ioctl() handlers? It seems better to just have one way for plugins to handle this call.

after a cursory look this is used if the plugin doesn't reimplement or want to overwrite the commands handled in irctl. I'll look if this can be handled better.

Quoted 6 lines

drivers/input/lirc/lirc_dev.c line 598

Quoted 2 lines
drivers/input/lirc/lirc_dev.c new file +2 -0
+	default:
+		result = -ENOIOCTLCMD;

Hmm, I note with interest that unlocked_ioctl() remaps -ENOIOCTLCMD to -EINVAL, while regular, locked ioctl() (which this is) does not. Not sure what to make of that.

changed this return value to -EINVAL

Quoted 8 lines
Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+static ssize_t irctl_read(struct file *file,
+			  char *buffer,
+			  size_t length,
+			  loff_t *ppos)
+{

...

Quoted 9 lines

drivers/input/lirc/lirc_dev.c line 673

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +6 -0
+			schedule();
+			set_current_state(TASK_INTERRUPTIBLE);
+			if (!ir->attached) {
+				ret = -ENODEV;
+				break;
+			}

How can ir->attached go to zero? You checked it earlier and have been holding the mutex ever since.

I don't think the lock has to be held while sleeping

Quoted 5 lines
Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +4 -0
+static ssize_t irctl_write(struct file *file, const char *buffer,
+			   size_t length, loff_t *ppos)
+{
+	struct irctl *ir =

&irctls[MINOR(file->f_dentry->d_inode->i_rdev)];

Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 718

Quoted 6 lines
drivers/input/lirc/lirc_dev.c new file +3 -0
+	dprintk(LOGHEAD "write called\n", ir->p.name, ir->p.minor);
+
+	/* if the plugin has a specific read function use it instead

*/

drivers/input/lirc/lirc_dev.c new file +2 -0
+	if (ir->p.fops && ir->p.fops->write)
+		return ir->p.fops->write(file, buffer, length, ppos);

Looks like you're using the "specific write function" instead :)

plugins fops will be used directly now, no need for this comment and code anymore ;)

Quoted 10 lines

drivers/input/lirc/lirc_dev.c line 734

Quoted 8 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+static struct file_operations fops = {
+	.read		= irctl_read,
+	.write		= irctl_write,
+	.poll		= irctl_poll,
+	.ioctl		= irctl_ioctl,
+	.open		= irctl_open,
+	.release	= irctl_close
+};

You should probably set .owner too.

done

Quoted 27 lines
Quoted 27 lines
drivers/input/lirc/lirc_dev.c new file +8 -0
+static int lirc_dev_init(void)
+{
+	int i;
+
+	for (i = 0; i < MAX_IRCTL_DEVICES; ++i)
+		init_irctl(&irctls[i]);
+
+	if (register_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME, &fops))

{

(quoted diff) +1 -0
+		printk(KERN_ERR "lirc_dev: register_chrdev

failed\n");

drivers/input/lirc/lirc_dev.c new file +10 -0
+		goto out;
+	}
+
+	lirc_class = class_create(THIS_MODULE, "lirc");
+	if (IS_ERR(lirc_class)) {
+		printk(KERN_ERR "lirc_dev: class_create failed\n");
+		goto out_unregister;
+	}
+
+	printk(KERN_INFO "lirc_dev: IR Remote Control driver

registered, "

drivers/input/lirc/lirc_dev.c new file +5 -0
+	       "major %d \n", IRCTL_DEV_MAJOR);
+
+	return SUCCESS;
+
+out_unregister:
Quoted 8 lines

drivers/input/lirc/lirc_dev.c line 765

Quoted 5 lines
drivers/input/lirc/lirc_dev.c new file +5 -0
+	/* unregister_chrdev returns void now */
+	unregister_chrdev(IRCTL_DEV_MAJOR, IRCTL_DEV_NAME);
+out:
+	return -1;
+}

Do you want to fail completely if class_create() fails? What if somebody already opened one of your devices?

order reversed and using alloc_chrdev_region so there is no device which could be opened. Also returning correct error values now.

Thanks for the review.

Janne

maintainer
#82 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Jarod Wilson

Hi Jarod,

Quoted 7 lines · Jarod Wilson
(quoted diff) +0 -2
-Add Kconfig and Makefile bits
-Add device driver interface and headers

The initial Kconfig and Makefile bits were done by Mario Limonciello for the Ubuntu kernel, but have been tweaked a bit since then. Any errors are probably my doing.

Couple of questions - what is missing in the current input core to properly support IR devices? How can we enhance it to not need new subsystem to handle such devices? We already have in-kernel support for some of the devices you are adding (ATI remotes, xbox, etc) so the situation is not ideal. Could we try to work it in ininput core and maybe provide LIRC device access through an input handler implementation so that applications do not have to implement 2 types of interfaces?

Signature · 1 line
Dmitry
#83 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 2 lines · Dmitry Torokhov

Couple of questions - what is missing in the current input core to properly support IR devices?

One issue is *sending* IR codes.
Another one is access to the raw IR signal (more on this below).

Probably 90% of the users are happy without that.

Quoted 4 lines

Could we try to work it in ininput core and
maybe provide LIRC device access through an input handler implementation so that applications do not have to implement 2 types of interfaces?

Not needed. Applications don't talk to the lirc device directly, they talk to the lircd daemon. The lircd daemon can handle linux input layer devices just fine. So moving drivers from lirc to the input layer can be done transparently to the applications.

Quite some time ago, back the days when I maintained video4linux, I've switched the tv card IR drivers from lirc to the input layer. Main reason for that was that having a in-kernel driver using an out-of-tree subsystem was a PITA. I think these days most (all?) TV card drivers use the input layer for the IR remotes frequently shipped with those cards.

Some more background, using the Hauppauge cards as example, which usually use rc5 coding with the remotes.

The older, bt878 based ones do decoding in hardware (i2c chip). You'll get the decoded rc5 keycode.

The newer, cx88 based ones just sample the raw IR signal and give you that. The decoding has to be done in software. The driver can program the sample rate and has to do the biphase decoding in software to get the rc5 keycodes. The driver gets that done just fine, and the remote shipped with the TV card works without problems.

The part which doesn't work is supporting *any* remote. The (newer) hardware gives you the raw IR signal, so it is possible to decode any IR signal in software. The missing bit is some way to send the raw IR samples to userspace (i.e. the lircd daemon) for decoding. lirc drivers do just that.

HTH,
Gerd

#84 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Quoted 38 lines · Gerd Hoffmann
Quoted 2 lines · Dmitry Torokhov

Couple of questions - what is missing in the current input core to properly support IR devices?

One issue is *sending* IR codes.
Another one is access to the raw IR signal (more on this below).

Probably 90% of the users are happy without that.

Quoted 4 lines

Could we try to work it in ininput core and
maybe provide LIRC device access through an input handler implementation so that applications do not have to implement 2 types of interfaces?

Not needed. Applications don't talk to the lirc device directly, they talk to the lircd daemon. The lircd daemon can handle linux input layer devices just fine. So moving drivers from lirc to the input layer can be done transparently to the applications.

Quite some time ago, back the days when I maintained video4linux, I've switched the tv card IR drivers from lirc to the input layer. Main reason for that was that having a in-kernel driver using an out-of-tree subsystem was a PITA. I think these days most (all?) TV card drivers use the input layer for the IR remotes frequently shipped with those cards.

Some more background, using the Hauppauge cards as example, which usually use rc5 coding with the remotes.

The older, bt878 based ones do decoding in hardware (i2c chip). You'll get the decoded rc5 keycode.

The newer, cx88 based ones just sample the raw IR signal and give you that. The decoding has to be done in software. The driver can program the sample rate and has to do the biphase decoding in software to get the rc5 keycodes. The driver gets that done just fine, and the remote shipped with the TV card works without problems.

Quoted 5 lines

The part which doesn't work is supporting *any* remote. The (newer) hardware gives you the raw IR signal, so it is possible to decode any IR signal in software. The missing bit is some way to send the raw IR samples to userspace (i.e. the lircd daemon) for decoding. lirc drivers do just that.

Hi,

Just my .02 cents,

I personally don't like the lircd daemon (*), I would like to have all input keycodes in input layer.
What do you, lirc developers think about making lircd a daemon that injects input events via uinput?

(*) the reason I don't like lircd is that not all applications support it.

Best regards,
Maxim Levitsky

Quoted 8 lines

HTH,
Gerd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#85 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

Hi Maxim,

on 12 Sep 08 at 00:28, Maxim Levitsky wrote:
[...]

Quoted 2 lines

What do you, lirc developers think about making lircd a daemon that injects input events via uinput?

I have already agreed to implement this in lircd.
The reason why I didn't until now is that there never was any reguest for such a feature from real users of LIRC. This is often suggested by people from an architectural viewpoint, because it's nice to have a unified interface through the input layer. But if you start using LIRC you usually realise quite fast that simple key events are not enough to build a remote controlled home entertainment system for example.
But if enough people want this feature, it will be in the next release.

Christoph

maintainer
#86 lore raw

Re: [PATCH 01/18] lirc core device driver infrastructure

In reply to Gerd Hoffmann

Hi Gerd,

Quoted 38 lines · Gerd Hoffmann
Quoted 2 lines · Dmitry Torokhov

Couple of questions - what is missing in the current input core to properly support IR devices?

One issue is *sending* IR codes.
Another one is access to the raw IR signal (more on this below).

Probably 90% of the users are happy without that.

Quoted 4 lines

Could we try to work it in ininput core and
maybe provide LIRC device access through an input handler implementation so that applications do not have to implement 2 types of interfaces?

Not needed. Applications don't talk to the lirc device directly, they talk to the lircd daemon. The lircd daemon can handle linux input layer devices just fine. So moving drivers from lirc to the input layer can be done transparently to the applications.

Quite some time ago, back the days when I maintained video4linux, I've switched the tv card IR drivers from lirc to the input layer. Main reason for that was that having a in-kernel driver using an out-of-tree subsystem was a PITA. I think these days most (all?) TV card drivers use the input layer for the IR remotes frequently shipped with those cards.

Some more background, using the Hauppauge cards as example, which usually use rc5 coding with the remotes.

The older, bt878 based ones do decoding in hardware (i2c chip). You'll get the decoded rc5 keycode.

The newer, cx88 based ones just sample the raw IR signal and give you that. The decoding has to be done in software. The driver can program the sample rate and has to do the biphase decoding in software to get the rc5 keycodes. The driver gets that done just fine, and the remote shipped with the TV card works without problems.

Quoted 6 lines

The part which doesn't work is supporting *any* remote. The (newer) hardware gives you the raw IR signal, so it is possible to decode any IR signal in software. The missing bit is some way to send the raw IR samples to userspace (i.e. the lircd daemon) for decoding. lirc drivers do just that.

I see. I guess what I would like to see it first to have "smart" devices that do decoding in hardware to be converted to input subsystem since lirc can use it and other programs can do that too. We should probably start using KEY_NUMERIC_* there to help userspace distinguishing RC keys from normal numeric/keypad keys.

For protocols that require decoding in userspace the best solution IMHO is to route them back via uinput so that applications would not need to keep implementing 2 interfaces, one for standard input devices and another for lirc.

I am not sure if input devices are the best for transmittign raw IR signal. It is pretty easy to add EV_MSC/IR_RAW event type to the input core... It would give you a timestamp and a 32 bit value... I guess I need to start looking at extending number of event devices in the system.

Signature · 1 line
Dmitry
#87 lore raw
In reply to Jarod Wilson
Quoted 2 lines · Jarod Wilson

The following patch series adds 17 new drivers for assorted infrared and/or RF remote control receivers and/or transmitters.

Why does most of this have to be in the kernel? Can a lot of this not be done from userspace?

#88 lore raw
In reply to Jarod Wilson
Quoted 5 lines · Jarod Wilson

The following patch series adds 17 new drivers for assorted infrared and/or RF remote control receivers and/or transmitters. These drivers have long lived out-of-tree at http://www.lirc.org/, packaged as 3rd-party modules by many distributions, and more recently, patched into the kernels of at least Fedora and Ubuntu.

Woo-hoo! One Vista-compatible (oh how it's called) remote control was waiting for this!

All version.h and autoconf.h inclusions aren't needed.

#ifdef MODULE is gross and very old. Don't need that. Just use

	static int __init x_init(void)
	{
		...
	}

	static void __exit x_exit(void)
	{
		...
	}
	module_init(x_init);
	module_exit(x_exit);
	MODULE_LICENSE
		...

It will work correctly in modular and built-in case.

Static number of devices is simple but how about adding them dynamically.

#89 lore raw
Quoted 2 lines · On Tuesday 09 September 2008 09:06:03 Alexey Dobriyan wrote:

All version.h and autoconf.h inclusions aren't needed.

I'll remove them.

Quoted 16 lines

#ifdef MODULE is gross and very old. Don't need that. Just use

	static int __init x_init(void)
	{
		...
	}

	static void __exit x_exit(void)
	{
		...
	}
	module_init(x_init);
	module_exit(x_exit);
	MODULE_LICENSE
		...
Quoted 1 line

It will work correctly in modular and built-in case.

Will do so.

Quoted 2 lines

Static number of devices is simple but how about adding them dynamically.

Will have a look

Janne

#90 lore raw
In reply to Jarod Wilson
Quoted 7 lines · Jarod Wilson

The following patch series adds 17 new drivers for assorted infrared and/or RF remote control receivers and/or transmitters. These drivers have long lived out-of-tree at http://www.lirc.org/, packaged as 3rd-party modules by many distributions, and more recently, patched into the kernels of at least Fedora and Ubuntu. The primary maintainer of lirc, Christoph Bartelmus simply hasn't had the time to send these bits upstream, and a few months back, gave me the go-ahead to take on the task.

Any reason this is a separate subsystem instead of just a bunch new drivers for the input subsystem?

Quoted 7 lines

Not all drivers have been tested with this codebase and certainly not all devices they support, but its a solid place to start with these in-kernel. Patches are against 2.6.27-rc5-git9 or so, and have been tested running the same, at least in the cases where hardware was available. These patches are also in the latest nightly Fedora rawhide kernel, for those who want instant gratification[3]. Note that you also need the lirc userspace to really do any meaningful testing...

Can you first only send the actually tested drivers? That way review an cleanup can focus on the core and those few and we might get them ready for 2.6.28. Other drivers can than be added when testing and review is done.

#91 lore raw
Quoted 10 lines · On Tuesday 09 September 2008 08:46:09 Christoph Hellwig wrote:
Quoted 8 lines · Jarod Wilson

The following patch series adds 17 new drivers for assorted infrared and/or RF remote control receivers and/or transmitters. These drivers have long lived out-of-tree at http://www.lirc.org/, packaged as 3rd-party modules by many distributions, and more recently, patched into the kernels of at least Fedora and Ubuntu. The primary maintainer of lirc, Christoph Bartelmus simply hasn't had the time to send these bits upstream, and a few months back, gave me the go-ahead to take on the task.

Quoted 2 lines

Any reason this is a separate subsystem instead of just a bunch new drivers for the input subsystem?

IR device handling is often a bit, shall we say, "special", for a number of devices... Some receivers decode the waveform and give us something sensible the input layer could use (and some IR receivers do work that way), while other receivers pass along raw IR codes, which we require the use of the lirc daemon to decode and convert into something sensible. To complicate the matter further, a number of devices are either output-only devices, or both input and output devices.

There's been talk about converting lirc drivers over to using evdev in the long run, but evdev would need a decent amount of extending to be able to support everything lircd does right now.

Quoted 8 lines
Quoted 7 lines

Not all drivers have been tested with this codebase and certainly not all devices they support, but its a solid place to start with these in-kernel. Patches are against 2.6.27-rc5-git9 or so, and have been tested running the same, at least in the cases where hardware was available. These patches are also in the latest nightly Fedora rawhide kernel, for those who want instant gratification[3]. Note that you also need the lirc userspace to really do any meaningful testing...

Quoted 4 lines

Can you first only send the actually tested drivers? That way review an cleanup can focus on the core and those few and we might get them ready for 2.6.28. Other drivers can than be added when testing and review is done.

I meant to include that the ordering of the patches was more or less from most-used/most-tested to least-used/least-tested, and a few of the patches do include Tested-by: lines in them. Basically, the first four or five drivers probably cover the majority of users, so getting them in first would provide the most bang-for-your-buck. But I can certainly re-send with only the tested drivers after we get through the first round of comments, if that's preferred over my approach of putting the higher-prio ones to the front of the ordering.

Signature · 2 lines
Jarod Wilson
[email protected]
#92 lore raw
Quoted 7 lines · Jarod Wilson

I meant to include that the ordering of the patches was more or less from most-used/most-tested to least-used/least-tested, and a few of the patches do include Tested-by: lines in them. Basically, the first four or five drivers probably cover the majority of users, so getting them in first would provide the most bang-for-your-buck. But I can certainly re-send with only the tested drivers after we get through the first round of comments, if that's preferred over my approach of putting the higher-prio ones to the front of the ordering.

The soundgraph imon driver is number 8, but it works great for me, and lots of cases include that one (at least silverstone cases). I think more than the first 4 or 5 are in very active use.

Signature · 1 line
Len Sorensen
#93 lore raw
Quoted 10 lines · On Tuesday 09 September 2008 14:27:10 Lennart Sorensen wrote:
Quoted 8 lines · Jarod Wilson

I meant to include that the ordering of the patches was more or less from most-used/most-tested to least-used/least-tested, and a few of the patches do include Tested-by: lines in them. Basically, the first four or five drivers probably cover the majority of users, so getting them in first would provide the most bang-for-your-buck. But I can certainly re-send with only the tested drivers after we get through the first round of comments, if that's preferred over my approach of putting the higher-prio ones to the front of the ordering.

Quoted 3 lines

The soundgraph imon driver is number 8, but it works great for me, and lots of cases include that one (at least silverstone cases). I think more than the first 4 or 5 are in very active use.

Yeah, I realized imon was much lower in the sort order after my reply there, which was a bad initial move by me, since its actually one of the ones that has definite positive testing feedback already. I believe quite a number of vendors of HTPC cases use imon lcd (or vfd) and ir combo devices.

Signature · 2 lines
Jarod Wilson
[email protected]
#94 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Jarod Wilson

The following patch series adds 17 new drivers for assorted infrared and/or RF remote control receivers and/or transmitters. These drivers have long lived out-of-tree at http://www.lirc.org/, packaged as 3rd-party modules by many distributions, and more recently, patched into the kernels of at least Fedora and Ubuntu. The primary maintainer of lirc, Christoph Bartelmus simply hasn't had the time to send these bits upstream, and a few months back, gave me the go-ahead to take on the task.

Quoted 2 lines

Any reason this is a separate subsystem instead of just a bunch new
drivers for the input subsystem?

I've been asking this one too. Can someone familiar with the guts of input give an assessment of integrating LIRC in with the rest of input? Don't we want these events handled via evdev so that ordering between IR, mouse, keyboard will be maintained?

Signature · 2 lines
Jon Smirl
[email protected]