Jerome Brock | 2 Oct 2004 07:05
Picon
Favicon

PATCH: [lirc_i2c] adding kcompat.h and removing most version code

Christoph,

The patch that follows is my first foray into getting
one of the drivers positioned for inclusion in the
kernel sources,  I started with the lirc_i2c driver.

I Added a kcompat.h and moved all version dependant
code from the lirc_i2c,c driver into this new file.  I
had to leave the bttv.h include line in the driver.

I tested this patch on stock 2.4.27 and 2.6.8.1
kernels.  It functioned just like the cvs sources
without the patch.

If it looks okay to you, please add to the cvs
sources.  If it's okay I will move onto lirc_dev.

Jerome

===================================================================

? lirc/drivers/lirc_i2c/kcompat.h
Index: lirc/drivers/lirc_i2c/Makefile.am
===================================================================
RCS file:
/cvsroot/lirc/lirc/drivers/lirc_i2c/Makefile.am,v
retrieving revision 1.6
diff -u -r1.6 Makefile.am
--- lirc/drivers/lirc_i2c/Makefile.am	25 Apr 2004
16:29:26 -0000	1.6
+++ lirc/drivers/lirc_i2c/Makefile.am	2 Oct 2004
04:41:02 -0000
 <at>  <at>  -5,7 +5,7  <at>  <at> 
 ## this is so that Automake includes the C compiling
definitions, and
 ## includes the source files in the distribution.
 EXTRA_PROGRAMS = automake_dummy
-automake_dummy_SOURCES = lirc_i2c.c
+automake_dummy_SOURCES = kcompat.h lirc_i2c.c

 ## there is no *just* object file support in
automake.  This is close enough
 module_DATA = lirc_i2c.o
Index: lirc/drivers/lirc_i2c/lirc_i2c.c
===================================================================
RCS file:
/cvsroot/lirc/lirc/drivers/lirc_i2c/lirc_i2c.c,v
retrieving revision 1.26
diff -u -r1.26 lirc_i2c.c
--- lirc/drivers/lirc_i2c/lirc_i2c.c	5 Sep 2004
16:48:48 -0000	1.26
+++ lirc/drivers/lirc_i2c/lirc_i2c.c	2 Oct 2004
04:41:02 -0000
 <at>  <at>  -11,6 +11,8  <at>  <at> 
  *      Ulrich Mueller <ulrich.mueller42@...>
  * modified for Asus TV-Box and Creative/VisionTek
BreakOut-Box by
  *      Stefan Jahn <stefan@...>
+ * modified for inclusion into kernel sources by
+ *      Jerome Brock <jbrock@...>
  *
  * parts are cut&pasted from the old lirc_haup.c
driver
  *
 <at>  <at>  -30,14 +32,8  <at>  <at> 
  *
  */

-#include <linux/version.h>
-#if LINUX_VERSION_CODE < 0x020200
-#error "--- Sorry, this driver needs kernel version
2.2.0 or higher. ---"
-#endif

-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include <linux/version.h>

 #include <linux/module.h>
 #include <linux/kmod.h>
 <at>  <at>  -49,20 +45,14  <at>  <at> 
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
-
-#ifndef I2C_CLIENT_END
-#error
"********************************************************"
-#error " Sorry, this driver needs the new I2C stack. 
          "
-#error " You can get it at
http://www2.lm-sensors.nu/~lm78/.    "
-#error
"********************************************************"
-#endif
-
 #include <linux/i2c-algo-bit.h>

 #include <asm/semaphore.h>

-#include "drivers/kcompat.h"
+#include "kcompat.h"
+
 #include "drivers/lirc_dev/lirc_dev.h"
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
 #include "../drivers/char/bttv.h"
 #else
 <at>  <at>  -264,12 +254,7  <at>  <at> 
 	/* lock bttv in memory while /dev/lirc is in use  */
 	/* this is completely broken code.
lirc_unregister_plugin()
 	   must be possible even when the device is open */
-#ifdef KERNEL_2_5
 	i2c_use_client(&ir->c);
-#else
-	if (ir->c.adapter->inc_use) 
-		ir->c.adapter->inc_use(ir->c.adapter);
-#endif

 	MOD_INC_USE_COUNT;
 	return 0;
 <at>  <at>  -279,12 +264,7  <at>  <at> 
 {
 	struct IR *ir = data;

-#ifdef KERNEL_2_5
 	i2c_release_client(&ir->c);
-#else
-	if (ir->c.adapter->dec_use) 
-		ir->c.adapter->dec_use(ir->c.adapter);
-#endif
 	MOD_DEC_USE_COUNT;
 }

 <at>  <at>  -332,11 +312,7  <at>  <at> 
 	
 	ir->c.adapter = adap;
 	ir->c.addr    = addr;
-#ifdef KERNEL_2_5
 	i2c_set_clientdata(&ir->c, ir);
-#else
-	ir->c.data    = ir;
-#endif
 	ir->l.data    = ir;
 	ir->l.minor   = minor;
 	ir->l.sample_rate = 10;
 <at>  <at>  -385,31 +361,17  <at>  <at> 
 	/* register device */
 	i2c_attach_client(&ir->c);
 	ir->l.minor = lirc_register_plugin(&ir->l);
-#ifdef KERNEL_2_5
 	i2c_use_client(&ir->c);
-#else
-	if (ir->c.adapter->inc_use) 
-		ir->c.adapter->inc_use(ir->c.adapter);
-#endif
 	
 	return 0;
 }

 static int ir_detach(struct i2c_client *client)
 {
-#ifdef KERNEL_2_5
 	struct IR *ir = i2c_get_clientdata(client);
-#else
-        struct IR *ir = client->data;
-#endif
 	
 	/* unregister device */
-#ifdef KERNEL_2_5
 	i2c_release_client(&ir->c);
-#else
-	if (ir->c.adapter->dec_use) 
-		ir->c.adapter->dec_use(ir->c.adapter);
-#endif
 	lirc_unregister_plugin(ir->l.minor);
 	i2c_detach_client(&ir->c);

 <at>  <at>  -523,7 +485,7  <at>  <at> 
 }

 MODULE_DESCRIPTION("Infrared receiver driver for
Hauppauge and Pixelview cards (i2c stack)");
-MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz,
Christoph Bartelmus, Ulrich Mueller, Stefan Jahn");
+MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz,
Christoph Bartelmus, Ulrich Mueller, Stefan Jahn,
Jerome Brock");
 MODULE_LICENSE("GPL");

 module_param(minor, int, 0444);
--- /dev/null	1969-12-31 19:00:00.000000000 -0500
+++ lirc/drivers/lirc_i2c/kcompat.h	2004-10-01
18:42:15.000000000 -0400
 <at>  <at>  -0,0 +1,81  <at>  <at> 
+/*
+ * kcompat header for i2c IR lirc plugin for
Hauppauge and Pixelview cards
+ *
+ * Copyright (c) 2004 Jerome Brock
<jbrock@...>
+ *
+ * parts are cut&pasted from the old lirc_i2c.c
driver
+ *
+ *  This program is free software; you can
redistribute it and/or modify
+ *  it under the terms of the GNU General Public
License as published by
+ *  the Free Software Foundation; either version 2 of
the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it
will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the
implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU
General Public License
+ *  along with this program; if not, write to the
Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef _LIRC_I2C_KCOMPAT_H
+#define _LIRC_I2C_KCOMPAT_H
+
+#include <linux/version.h>
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/**************************************************************************/
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 0)
+
+#error "--- Sorry, this driver needs kernel version
2.2.0 or higher. ---"
+#endif
+
+/**************************************************************************/
+#include <linux/i2c.h>
+
+#ifndef I2C_CLIENT_END
+#error
"********************************************************"
+#error " Sorry, this driver needs the new I2C stack. 
          "
+#error " You can get it at
http://www2.lm-sensors.nu/~lm78/.    "
+#error
"********************************************************"
+#endif
+
+#include <linux/module.h>
+#include "drivers/kcompat.h"
+
+/**************************************************************************/
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
+
+#undef i2c_use_client
+#define i2c_use_client(client_ptr) do { \
+	if ((client_ptr)->adapter->inc_use) \
+	
(client_ptr)->adapter->inc_use((client_ptr)->adapter);
\
+} while (0)
+
+#undef i2c_release_client
+#define i2c_release_client(client_ptr) do { \
+	if ((client_ptr)->adapter->dec_use) \
+	
(client_ptr)->adapter->dec_use((client_ptr)->adapter);
\
+} while (0)
+
+#undef i2c_get_clientdata
+#define i2c_get_clientdata(client) ((client)->data)
+
+
+#undef i2c_set_clientdata
+#define i2c_set_clientdata(client_ptr, new_data) do {
\
+	(client_ptr)->data = new_data; \
+} while (0)
+
+
+#endif
+
+/**************************************************************************/
+#endif				//_LIRC_I2C_KCOMPAT_H

		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl


Gmane