public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
@ 2006-06-08 20:57 Oliver Bock
  2006-06-09 10:45 ` Pavel Machek
  0 siblings, 1 reply; 12+ messages in thread
From: Oliver Bock @ 2006-06-08 20:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: greg, alan

[-- Attachment #1: Type: text/plain, Size: 12825 bytes --]

From: Oliver Bock <o.bock@fh-wolfenbuettel.de>

This is a new driver for the Cypress CY7C63xxx mirco controller series. It 
currently supports the pre-programmed CYC63001A-PC by AK Modul-Bus GmbH.
It's based on a kernel 2.4 driver (cyport) by Marcus Maul which I ported to kernel 2.6 
using sysfs. I intend to support more controllers of this family (and more features) as
soon as I get hold of the required IDs etc. Please see the source code's header for
more information.

Signed-off-by: Oliver Bock <o.bock@fh-wolfenbuettel.de>

---

Please CC me as I'm not yet subscribed to LKML. Any comments are welcome.
Special thanks to Greg K-H for his helpful support!

diff against 2.6.16.19

--- linux-2.6.16.19/drivers/usb/Makefile.orig   2006-05-31 02:31:44.000000000 +0200
+++ linux-2.6.16.19/drivers/usb/Makefile        2006-06-04 21:03:24.000000000 +0200
@@ -62,6 +62,7 @@ obj-$(CONFIG_USB_MICROTEK)    += image/
 obj-$(CONFIG_USB_SERIAL)       += serial/
 
 obj-$(CONFIG_USB_AUERSWALD)    += misc/
+obj-$(CONFIG_USB_CY7C63)       += misc/
 obj-$(CONFIG_USB_CYTHERM)      += misc/
 obj-$(CONFIG_USB_EMI26)                += misc/
 obj-$(CONFIG_USB_EMI62)                += misc/
--- linux-2.6.16.19/drivers/usb/misc/Kconfig.orig       2006-05-31 02:31:44.000000000 +0200
+++ linux-2.6.16.19/drivers/usb/misc/Kconfig    2006-06-04 21:02:21.000000000 +0200
@@ -88,6 +88,20 @@ config USB_LED
          To compile this driver as a module, choose M here: the
          module will be called usbled.
 
+config USB_CY7C63
+       tristate "Cypress CY7C63xxx USB driver support"
+       depends on USB
+       help
+         Say Y here if you want to connect a Cypress CY7C63xxx
+         micro controller to your computer's USB port. This driver
+         supports the pre-programmed devices (incl. firmware) by
+         AK Modul-Bus Computer GmbH.
+
+         Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html
+
+         To compile this driver as a module, choose M here: the
+         module will be called cy7c63.
+
 config USB_CYTHERM
        tristate "Cypress USB thermometer driver support"
        depends on USB
--- linux-2.6.16.19/drivers/usb/misc/Makefile.orig      2006-05-31 02:31:44.000000000 +0200
+++ linux-2.6.16.19/drivers/usb/misc/Makefile   2006-06-04 21:02:52.000000000 +0200
@@ -4,6 +4,7 @@
 #
 
 obj-$(CONFIG_USB_AUERSWALD)    += auerswald.o
+obj-$(CONFIG_USB_CY7C63)       += cy7c63.o
 obj-$(CONFIG_USB_CYTHERM)      += cytherm.o
 obj-$(CONFIG_USB_EMI26)                += emi26.o
 obj-$(CONFIG_USB_EMI62)                += emi62.o
--- linux-2.6.16.19/drivers/usb/misc/cy7c63.c.orig      1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.16.19/drivers/usb/misc/cy7c63.c   2006-06-04 23:45:54.000000000 +0200
@@ -0,0 +1,244 @@
+/*
+* cy7c63.c
+*
+* Copyright (c) 2006 Oliver Bock (bock@fh-wolfenbuettel.de)
+*
+*      This driver is based on the Cypress Thermometer USB Driver by
+*      Marcus Maul and the 2.0 version of Greg Kroah-Hartman's
+*      USB Skeleton driver.
+*
+*      Is is a generic driver for the Cypress CY7C63000 family.
+*      For the time being it enables you to toggle the single I/O ports
+*      of the device.
+*
+*      Supported vendors:      AK Modul-Bus Computer GmbH
+*      Supported devices:      CY7C63001A-PC (to be continued...)
+*      Supported functions:    Read/Write Ports (to be continued...)
+*
+*      Chipsets families:      CY7C63000, CY7C63001, CY7C63100, CY7C63101
+*
+*
+*      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, version 2.
+*/
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+
+#define DRIVER_AUTHOR          "Oliver Bock (bock@fh-wolfenbuettel.de)"
+#define DRIVER_DESC            "Cypress CY7C63xxx USB driver"
+
+#define CY7C63_VENDOR_ID       0xa2c
+#define CY7C63_PRODUCT_ID      0x8
+
+#define CY7C63_READ_PORT       0x4
+#define CY7C63_WRITE_PORT      0x5
+#define CY7C63_READ_RAM                0x2
+#define CY7C63_WRITE_RAM       0x3
+#define CY7C63_READ_ROM                0x1
+
+#define CY7C63_READ_PORT_ID0   0
+#define CY7C63_WRITE_PORT_ID0  0
+#define CY7C63_READ_PORT_ID1   0x2
+#define CY7C63_WRITE_PORT_ID1  1
+
+#define CY7C63_MAX_REQSIZE     8
+
+
+/* table of devices that work with this driver */
+static struct usb_device_id cy7c63_table [] = {
+       { USB_DEVICE(CY7C63_VENDOR_ID, CY7C63_PRODUCT_ID) },
+       { }
+};
+MODULE_DEVICE_TABLE(usb, cy7c63_table);
+
+/* structure to hold all of our device specific stuff */
+struct cy7c63 {
+       struct usb_device *     udev;
+       char                    port0;
+       char                    port1;
+};
+
+/* used to send usb control messages to device */
+int vendor_command(struct cy7c63 *dev, unsigned char request,
+                        unsigned char address, unsigned char data) {
+
+       int retval = 0;
+       unsigned int pipe;
+       unsigned char *iobuf;
+
+       /* allocate some memory for the i/o buffer*/
+       iobuf = kzalloc(CY7C63_MAX_REQSIZE, GFP_KERNEL);
+       if (!iobuf) {
+               dev_err(&dev->udev->dev, "Out of memory!\n");
+               retval = -ENOMEM;
+               goto error;
+       }
+
+       dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data);
+
+       /* prepare usb control message and send it upstream */
+       pipe = usb_rcvctrlpipe(dev->udev, 0);
+       retval = usb_control_msg(dev->udev, pipe, request,
+                               USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+                               address, data, iobuf, CY7C63_MAX_REQSIZE,
+                               USB_CTRL_GET_TIMEOUT);
+
+       /* store returned data (more READs to be added!) */
+       switch (request) {
+               case CY7C63_READ_PORT:
+                       if (address == CY7C63_READ_PORT_ID0) {
+                               dev->port0 = iobuf[1];
+                               dev_dbg(&dev->udev->dev,
+                                       "READ_PORT0 returned: %d\n",dev->port0);
+                       }
+                       else if (address == CY7C63_READ_PORT_ID1) {
+                               dev->port1 = iobuf[1];
+                               dev_dbg(&dev->udev->dev,
+                                       "READ_PORT1 returned: %d\n",dev->port1);
+                       }
+                       break;
+       }
+
+       kfree(iobuf);
+error:
+       return retval;
+}
+
+#define get_set_port(num,read_id,write_id) \
+static ssize_t set_port##num(struct device *dev, struct device_attribute *attr,        \
+                                       const char *buf, size_t count) {        \
+                                                                               \
+       int value;                                                              \
+       int result = 0;                                                         \
+                                                                               \
+       struct usb_interface *intf = to_usb_interface(dev);                     \
+       struct cy7c63 *cyp = usb_get_intfdata(intf);                            \
+                                                                               \
+       dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", num);                 \
+                                                                               \
+       /* validate input data */                                               \
+       if (sscanf(buf, "%d", &value) < 1) {                                    \
+               result = -EINVAL;                                               \
+               goto error;                                                     \
+       }                                                                       \
+       if (value>255 || value<0) {                                             \
+               result = -EINVAL;                                               \
+               goto error;                                                     \
+       }                                                                       \
+                                                                               \
+       result = vendor_command(cyp, CY7C63_WRITE_PORT, write_id,               \
+                                        (unsigned char)value);                 \
+                                                                               \
+       dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n",result);    \
+error:                                                                         \
+       return result < 0 ? result : count;                                     \
+}                                                                              \
+                                                                               \
+static ssize_t get_port##num(struct device *dev,                               \
+                                struct device_attribute *attr, char *buf) {    \
+                                                                               \
+       int result = 0;                                                         \
+                                                                               \
+       struct usb_interface *intf = to_usb_interface(dev);                     \
+       struct cy7c63 *cyp = usb_get_intfdata(intf);                            \
+                                                                               \
+       dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", num);                  \
+                                                                               \
+       result = vendor_command(cyp, CY7C63_READ_PORT, read_id, 0);             \
+                                                                               \
+       dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);   \
+                                                                               \
+       return sprintf(buf, "%d", cyp->port##num);                              \
+}                                                                              \
+static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num, set_port##num);
+
+get_set_port(0, CY7C63_READ_PORT_ID0, CY7C63_WRITE_PORT_ID0);
+get_set_port(1, CY7C63_READ_PORT_ID1, CY7C63_WRITE_PORT_ID1);
+
+static int cy7c63_probe(struct usb_interface *interface,
+                       const struct usb_device_id *id) {
+
+       struct cy7c63 *dev = NULL;
+       int retval = -ENOMEM;
+
+       /* allocate memory for our device state and initialize it */
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (dev == NULL) {
+               dev_err(&dev->udev->dev, "Out of memory!\n");
+               goto error;
+       }
+
+       dev->udev = usb_get_dev(interface_to_usbdev(interface));
+
+       /* save our data pointer in this interface device */
+       usb_set_intfdata(interface, dev);
+
+       /* create device attribute files */
+       device_create_file(&interface->dev, &dev_attr_port0);
+       device_create_file(&interface->dev, &dev_attr_port1);
+
+       /* let the user know what node this device is now attached to */
+       dev_info(&interface->dev,
+               "Cypress CY7C63xxx device now attached\n");
+
+       retval = 0;
+error:
+       return retval;
+}
+
+static void cy7c63_disconnect(struct usb_interface *interface) {
+
+       struct cy7c63 *dev;
+
+       dev = usb_get_intfdata(interface);
+       usb_set_intfdata(interface, NULL);
+
+       /* remove device attribute files */
+       device_remove_file(&interface->dev, &dev_attr_port0);
+       device_remove_file(&interface->dev, &dev_attr_port1);
+
+       usb_put_dev(dev->udev);
+
+       dev_info(&interface->dev,
+               "Cypress CY7C63xxx device now disconnected\n");
+
+       kfree(dev);
+}
+
+static struct usb_driver cy7c63_driver = {
+       .name = "cy7c63",
+       .probe = cy7c63_probe,
+       .disconnect = cy7c63_disconnect,
+       .id_table = cy7c63_table,
+};
+
+static int __init cy7c63_init(void) {
+
+       int result;
+
+       /* register this driver with the USB subsystem */
+       result = usb_register(&cy7c63_driver);
+       if (result) {
+               err("Function usb_register failed! Error number: %d\n", result);
+       }
+
+       return result;
+}
+
+static void __exit cy7c63_exit(void) {
+
+       /* deregister this driver with the USB subsystem */
+       usb_deregister(&cy7c63_driver);
+}
+
+module_init(cy7c63_init);
+module_exit(cy7c63_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+
+MODULE_LICENSE("GPL");

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-08 20:57 [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers Oliver Bock
@ 2006-06-09 10:45 ` Pavel Machek
  2006-06-09 22:50   ` Greg KH
  0 siblings, 1 reply; 12+ messages in thread
From: Pavel Machek @ 2006-06-09 10:45 UTC (permalink / raw)
  To: Oliver Bock; +Cc: linux-kernel, greg, alan

On Čt 08-06-06 22:57:18, Oliver Bock wrote:
> From: Oliver Bock <o.bock@fh-wolfenbuettel.de>
> 
> This is a new driver for the Cypress CY7C63xxx mirco controller series. It 
> currently supports the pre-programmed CYC63001A-PC by AK Modul-Bus GmbH.
> It's based on a kernel 2.4 driver (cyport) by Marcus Maul which I ported to kernel 2.6 
> using sysfs. I intend to support more controllers of this family (and more features) as
> soon as I get hold of the required IDs etc. Please see the source code's header for
> more information.

I see "a" letters here tabs should have been. You probably need to
resend...


> Please CC me as I'm not yet subscribed to LKML. Any comments are welcome.
> Special thanks to Greg K-H for his helpful support!
> 
> diff against 2.6.16.19

Ugh, and new drivers should really go against 2.6.17-rcX.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
@ 2006-06-09 22:42 Oliver Bock
  2006-06-09 22:49 ` Pavel Machek
  0 siblings, 1 reply; 12+ messages in thread
From: Oliver Bock @ 2006-06-09 22:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: pavel, akpm

From: Oliver Bock <o.bock@fh-wolfenbuettel.de>

This is a new driver for the Cypress CY7C63xxx mirco controller series. It 
currently supports the pre-programmed CYC63001A-PC by AK Modul-Bus GmbH.
It's based on a kernel 2.4 driver (cyport) by Marcus Maul which I ported to kernel 2.6 
using sysfs. I intend to support more controllers of this family (and more features) as
soon as I get hold of the required IDs etc. Please see the source code's header for
more information.

Signed-off-by: Oliver Bock <o.bock@fh-wolfenbuettel.de>

---

Please CC me as I'm not yet subscribed to LKML. Any comments are welcome.
Special thanks to Greg K-H and Pavel Machek for their helpful support!

diff against 2.6.17-rc6

--- linux-2.6.17-rc6/drivers/usb/Makefile.orig	2006-06-09 23:59:57.000000000 +0200
+++ linux-2.6.17-rc6/drivers/usb/Makefile	2006-06-10 00:13:15.626507000 +0200
@@ -48,6 +48,7 @@ obj-$(CONFIG_USB_MICROTEK)	+= image/
 obj-$(CONFIG_USB_SERIAL)	+= serial/
 
 obj-$(CONFIG_USB_AUERSWALD)	+= misc/
+obj-$(CONFIG_USB_CY7C63)	+= misc/
 obj-$(CONFIG_USB_CYTHERM)	+= misc/
 obj-$(CONFIG_USB_EMI26)		+= misc/
 obj-$(CONFIG_USB_EMI62)		+= misc/
--- linux-2.6.17-rc6/drivers/usb/misc/Kconfig.orig	2006-03-28 08:49:02.000000000 +0200
+++ linux-2.6.17-rc6/drivers/usb/misc/Kconfig	2006-06-10 00:16:07.093223000 +0200
@@ -88,6 +88,20 @@ config USB_LED
 	  To compile this driver as a module, choose M here: the
 	  module will be called usbled.
 
+config USB_CY7C63
+	tristate "Cypress CY7C63xxx USB driver support"
+	depends on USB
+	help
+	  Say Y here if you want to connect a Cypress CY7C63xxx
+	  micro controller to your computer's USB port. This driver
+	  supports the pre-programmed devices (incl. firmware) by
+	  AK Modul-Bus Computer GmbH.
+
+	  Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called cy7c63.
+
 config USB_CYTHERM
 	tristate "Cypress USB thermometer driver support"
 	depends on USB
--- linux-2.6.17-rc6/drivers/usb/misc/Makefile.orig	2006-03-28 08:49:02.000000000 +0200
+++ linux-2.6.17-rc6/drivers/usb/misc/Makefile	2006-06-10 00:14:32.419306250 +0200
@@ -4,6 +4,7 @@
 #
 
 obj-$(CONFIG_USB_AUERSWALD)	+= auerswald.o
+obj-$(CONFIG_USB_CY7C63)	+= cy7c63.o
 obj-$(CONFIG_USB_CYTHERM)	+= cytherm.o
 obj-$(CONFIG_USB_EMI26)		+= emi26.o
 obj-$(CONFIG_USB_EMI62)		+= emi62.o
--- linux-2.6.17-rc6/drivers/usb/misc/cy7c63.c.orig	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.17-rc6/drivers/usb/misc/cy7c63.c	2006-06-04 23:45:54.000000000 +0200
@@ -0,0 +1,244 @@
+/*
+* cy7c63.c
+*
+* Copyright (c) 2006 Oliver Bock (bock@fh-wolfenbuettel.de)
+*
+*	This driver is based on the Cypress Thermometer USB Driver by
+*	Marcus Maul and the 2.0 version of Greg Kroah-Hartman's
+*	USB Skeleton driver.
+*
+*	Is is a generic driver for the Cypress CY7C63000 family.
+*	For the time being it enables you to toggle the single I/O ports
+*	of the device.
+*
+*	Supported vendors:	AK Modul-Bus Computer GmbH
+*	Supported devices:	CY7C63001A-PC (to be continued...)
+*	Supported functions:	Read/Write Ports (to be continued...)
+*
+*	Chipsets families:	CY7C63000, CY7C63001, CY7C63100, CY7C63101
+*
+*
+*	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, version 2.
+*/
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+
+#define DRIVER_AUTHOR		"Oliver Bock (bock@fh-wolfenbuettel.de)"
+#define DRIVER_DESC		"Cypress CY7C63xxx USB driver"
+
+#define CY7C63_VENDOR_ID	0xa2c
+#define CY7C63_PRODUCT_ID	0x8
+
+#define CY7C63_READ_PORT	0x4
+#define CY7C63_WRITE_PORT	0x5
+#define CY7C63_READ_RAM		0x2
+#define CY7C63_WRITE_RAM	0x3
+#define CY7C63_READ_ROM		0x1
+
+#define CY7C63_READ_PORT_ID0	0
+#define CY7C63_WRITE_PORT_ID0	0
+#define CY7C63_READ_PORT_ID1	0x2
+#define CY7C63_WRITE_PORT_ID1	1
+
+#define CY7C63_MAX_REQSIZE	8
+
+
+/* table of devices that work with this driver */
+static struct usb_device_id cy7c63_table [] = {
+	{ USB_DEVICE(CY7C63_VENDOR_ID, CY7C63_PRODUCT_ID) },
+	{ }
+};
+MODULE_DEVICE_TABLE(usb, cy7c63_table);
+
+/* structure to hold all of our device specific stuff */
+struct cy7c63 {
+	struct usb_device *	udev;
+	char 			port0;
+	char			port1;
+};
+
+/* used to send usb control messages to device */
+int vendor_command(struct cy7c63 *dev, unsigned char request,
+			 unsigned char address, unsigned char data) {
+
+	int retval = 0;
+	unsigned int pipe;
+	unsigned char *iobuf;
+
+	/* allocate some memory for the i/o buffer*/
+	iobuf = kzalloc(CY7C63_MAX_REQSIZE, GFP_KERNEL);
+	if (!iobuf) {
+		dev_err(&dev->udev->dev, "Out of memory!\n");
+		retval = -ENOMEM;
+		goto error;
+	}
+
+	dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data);
+
+	/* prepare usb control message and send it upstream */
+	pipe = usb_rcvctrlpipe(dev->udev, 0);
+	retval = usb_control_msg(dev->udev, pipe, request,
+				USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+				address, data, iobuf, CY7C63_MAX_REQSIZE,
+				USB_CTRL_GET_TIMEOUT);
+
+	/* store returned data (more READs to be added!) */
+	switch (request) {
+		case CY7C63_READ_PORT:
+			if (address == CY7C63_READ_PORT_ID0) {
+				dev->port0 = iobuf[1];
+				dev_dbg(&dev->udev->dev,
+					"READ_PORT0 returned: %d\n",dev->port0);
+			}
+			else if (address == CY7C63_READ_PORT_ID1) {
+				dev->port1 = iobuf[1];
+				dev_dbg(&dev->udev->dev,
+					"READ_PORT1 returned: %d\n",dev->port1);
+			}
+			break;
+	}
+
+	kfree(iobuf);
+error:
+	return retval;
+}
+
+#define get_set_port(num,read_id,write_id) \
+static ssize_t set_port##num(struct device *dev, struct device_attribute *attr,	\
+					const char *buf, size_t count) {	\
+										\
+	int value;								\
+	int result = 0;								\
+										\
+	struct usb_interface *intf = to_usb_interface(dev);			\
+	struct cy7c63 *cyp = usb_get_intfdata(intf);				\
+										\
+	dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", num);			\
+										\
+	/* validate input data */						\
+	if (sscanf(buf, "%d", &value) < 1) {					\
+		result = -EINVAL;						\
+		goto error;							\
+	}									\
+	if (value>255 || value<0) {						\
+		result = -EINVAL;						\
+		goto error;							\
+	}									\
+										\
+	result = vendor_command(cyp, CY7C63_WRITE_PORT, write_id,		\
+					 (unsigned char)value);			\
+										\
+	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n",result);	\
+error:										\
+	return result < 0 ? result : count;					\
+}										\
+										\
+static ssize_t get_port##num(struct device *dev,				\
+				 struct device_attribute *attr, char *buf) {	\
+										\
+	int result = 0;								\
+										\
+	struct usb_interface *intf = to_usb_interface(dev);			\
+	struct cy7c63 *cyp = usb_get_intfdata(intf);				\
+										\
+	dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", num);			\
+										\
+	result = vendor_command(cyp, CY7C63_READ_PORT, read_id, 0);		\
+										\
+	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);	\
+										\
+	return sprintf(buf, "%d", cyp->port##num);				\
+}										\
+static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num, set_port##num);
+
+get_set_port(0, CY7C63_READ_PORT_ID0, CY7C63_WRITE_PORT_ID0);
+get_set_port(1, CY7C63_READ_PORT_ID1, CY7C63_WRITE_PORT_ID1);
+
+static int cy7c63_probe(struct usb_interface *interface,
+			const struct usb_device_id *id) {
+
+	struct cy7c63 *dev = NULL;
+	int retval = -ENOMEM;
+
+	/* allocate memory for our device state and initialize it */
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (dev == NULL) {
+		dev_err(&dev->udev->dev, "Out of memory!\n");
+		goto error;
+	}
+
+	dev->udev = usb_get_dev(interface_to_usbdev(interface));
+
+	/* save our data pointer in this interface device */
+	usb_set_intfdata(interface, dev);
+
+	/* create device attribute files */
+	device_create_file(&interface->dev, &dev_attr_port0);
+	device_create_file(&interface->dev, &dev_attr_port1);
+
+	/* let the user know what node this device is now attached to */
+	dev_info(&interface->dev,
+		"Cypress CY7C63xxx device now attached\n");
+
+	retval = 0;
+error:
+	return retval;
+}
+
+static void cy7c63_disconnect(struct usb_interface *interface) {
+
+	struct cy7c63 *dev;
+
+	dev = usb_get_intfdata(interface);
+	usb_set_intfdata(interface, NULL);
+
+	/* remove device attribute files */
+	device_remove_file(&interface->dev, &dev_attr_port0);
+	device_remove_file(&interface->dev, &dev_attr_port1);
+
+	usb_put_dev(dev->udev);
+
+	dev_info(&interface->dev,
+		"Cypress CY7C63xxx device now disconnected\n");
+
+	kfree(dev);
+}
+
+static struct usb_driver cy7c63_driver = {
+	.name = "cy7c63",
+	.probe = cy7c63_probe,
+	.disconnect = cy7c63_disconnect,
+	.id_table = cy7c63_table,
+};
+
+static int __init cy7c63_init(void) {
+
+	int result;
+
+	/* register this driver with the USB subsystem */
+	result = usb_register(&cy7c63_driver);
+	if (result) {
+		err("Function usb_register failed! Error number: %d\n", result);
+	}
+
+	return result;
+}
+
+static void __exit cy7c63_exit(void) {
+
+	/* deregister this driver with the USB subsystem */
+	usb_deregister(&cy7c63_driver);
+}
+
+module_init(cy7c63_init);
+module_exit(cy7c63_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+
+MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-09 22:42 Oliver Bock
@ 2006-06-09 22:49 ` Pavel Machek
  2006-06-12 17:34   ` Oliver Bock
  0 siblings, 1 reply; 12+ messages in thread
From: Pavel Machek @ 2006-06-09 22:49 UTC (permalink / raw)
  To: Oliver Bock; +Cc: linux-kernel, akpm

Hi!

Sorry, now the review begins...

> +/* used to send usb control messages to device */
> +int vendor_command(struct cy7c63 *dev, unsigned char request,
> +			 unsigned char address, unsigned char data) {

Codingstyle: { goes to new line.


> +#define get_set_port(num,read_id,write_id) \
> +static ssize_t set_port##num(struct device *dev, struct device_attribute *attr,	\
> +					const char *buf, size_t count) {	\
> +										\
> +	int value;								\
> +	int result = 0;								\
> +										\
> +	struct usb_interface *intf = to_usb_interface(dev);			\
> +	struct cy7c63 *cyp = usb_get_intfdata(intf);				\
> +										\
> +	dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", num);			\
> +										\
> +	/* validate input data */						\
> +	if (sscanf(buf, "%d", &value) < 1) {					\
> +		result = -EINVAL;						\
> +		goto error;							\
> +	}									\
> +	if (value>255 || value<0) {						\
> +		result = -EINVAL;						\
> +		goto error;							\
> +	}									\
> +										\
> +	result = vendor_command(cyp, CY7C63_WRITE_PORT, write_id,		\
> +					 (unsigned char)value);			\
> +										\
> +	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n",result);	\
> +error:										\
> +	return result < 0 ? result : count;					\
> +}										\
> +										\
> +static ssize_t get_port##num(struct device *dev,				\
> +				 struct device_attribute *attr, char *buf) {	\
> +										\
> +	int result = 0;								\
> +										\
> +	struct usb_interface *intf = to_usb_interface(dev);			\
> +	struct cy7c63 *cyp = usb_get_intfdata(intf);				\
> +										\
> +	dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", num);			\
> +										\
> +	result = vendor_command(cyp, CY7C63_READ_PORT, read_id, 0);		\
> +										\
> +	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);	\
> +										\
> +	return sprintf(buf, "%d", cyp->port##num);				\
> +}										\
> +static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num, set_port##num);
> +
> +get_set_port(0, CY7C63_READ_PORT_ID0, CY7C63_WRITE_PORT_ID0);
> +get_set_port(1, CY7C63_READ_PORT_ID1, CY7C63_WRITE_PORT_ID1);

You get "best abuse of the macros" prize. Can you just use functions,
and pass num as aditional argument? Then just wrap the long functions
in small ones... converting cyp->port0/1 into array will be handy..


> +static int cy7c63_probe(struct usb_interface *interface,
> +			const struct usb_device_id *id) {

{ on new line, please...

BTW could we get come better name for the driver? cy7c63 looks like
password of very paranoid sysadmin.

> +	/* let the user know what node this device is now attached to */
> +	dev_info(&interface->dev,
> +		"Cypress CY7C63xxx device now attached\n");

In cases like this we aling " one character to the right.

Otherwise it looks okay.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-09 10:45 ` Pavel Machek
@ 2006-06-09 22:50   ` Greg KH
  2006-06-10 12:56     ` Oliver Bock
  0 siblings, 1 reply; 12+ messages in thread
From: Greg KH @ 2006-06-09 22:50 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Oliver Bock, linux-kernel, alan

On Fri, Jun 09, 2006 at 12:45:41PM +0200, Pavel Machek wrote:
> On ??t 08-06-06 22:57:18, Oliver Bock wrote:
> > From: Oliver Bock <o.bock@fh-wolfenbuettel.de>
> > 
> > This is a new driver for the Cypress CY7C63xxx mirco controller series. It 
> > currently supports the pre-programmed CYC63001A-PC by AK Modul-Bus GmbH.
> > It's based on a kernel 2.4 driver (cyport) by Marcus Maul which I ported to kernel 2.6 
> > using sysfs. I intend to support more controllers of this family (and more features) as
> > soon as I get hold of the required IDs etc. Please see the source code's header for
> > more information.
> 
> I see "a" letters here tabs should have been. You probably need to
> resend...

It's just mime, my tools can handle it, I hope...

> > Please CC me as I'm not yet subscribed to LKML. Any comments are welcome.
> > Special thanks to Greg K-H for his helpful support!
> > 
> > diff against 2.6.16.19
> 
> Ugh, and new drivers should really go against 2.6.17-rcX.

Stand-alone drivers should work ok, I'll test this one and see...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-09 22:50   ` Greg KH
@ 2006-06-10 12:56     ` Oliver Bock
  0 siblings, 0 replies; 12+ messages in thread
From: Oliver Bock @ 2006-06-10 12:56 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, alan

Hi Greg,
I submitted the patch again a few hours ago. Now the tabs are still there 
where they belong and it's a diff against 2.6.17-rc6.

Have a look at: http://lkml.org/lkml/2006/6/9/398

Thanks, Oliver

On Saturday 10 June 2006 00:50, Greg KH wrote:
> On Fri, Jun 09, 2006 at 12:45:41PM +0200, Pavel Machek wrote:
> > On ??t 08-06-06 22:57:18, Oliver Bock wrote:
> > > From: Oliver Bock <o.bock@fh-wolfenbuettel.de>
> > >
> > > This is a new driver for the Cypress CY7C63xxx mirco controller series.
> > > It currently supports the pre-programmed CYC63001A-PC by AK Modul-Bus
> > > GmbH. It's based on a kernel 2.4 driver (cyport) by Marcus Maul which I
> > > ported to kernel 2.6 using sysfs. I intend to support more controllers
> > > of this family (and more features) as soon as I get hold of the
> > > required IDs etc. Please see the source code's header for more
> > > information.
> >
> > I see "a" letters here tabs should have been. You probably need to
> > resend...
>
> It's just mime, my tools can handle it, I hope...
>
> > > Please CC me as I'm not yet subscribed to LKML. Any comments are
> > > welcome. Special thanks to Greg K-H for his helpful support!
> > >
> > > diff against 2.6.16.19
> >
> > Ugh, and new drivers should really go against 2.6.17-rcX.
>
> Stand-alone drivers should work ok, I'll test this one and see...
>
> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-09 22:49 ` Pavel Machek
@ 2006-06-12 17:34   ` Oliver Bock
  2006-06-13 19:23     ` Pavel Machek
  0 siblings, 1 reply; 12+ messages in thread
From: Oliver Bock @ 2006-06-12 17:34 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, Greg KH

On Saturday 10 June 2006 00:49, Pavel Machek wrote:
> Sorry, now the review begins...

No problem at all.

> > +/* used to send usb control messages to device */
> > +int vendor_command(struct cy7c63 *dev, unsigned char request,
> > +			 unsigned char address, unsigned char data) {
>
> Codingstyle: { goes to new line.

Ok, I missed that one and remembered only the if-styling. I'll change it and 
I'm glad to see that as it's according to my style.

> > +#define get_set_port(num,read_id,write_id) \
> > +static ssize_t set_port##num(struct device *dev, struct device_attribute
> > *attr,	\ +					const char *buf, size_t count) {	\
> > +										\
> > +	int value;								\
> > +	int result = 0;								\
> > +										\
> > +	struct usb_interface *intf = to_usb_interface(dev);			\
> > +	struct cy7c63 *cyp = usb_get_intfdata(intf);				\
> > +										\
> > +	dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", num);			\
> > +										\
> > +	/* validate input data */						\
> > +	if (sscanf(buf, "%d", &value) < 1) {					\
> > +		result = -EINVAL;						\
> > +		goto error;							\
> > +	}									\
> > +	if (value>255 || value<0) {						\
> > +		result = -EINVAL;						\
> > +		goto error;							\
> > +	}									\
> > +										\
> > +	result = vendor_command(cyp, CY7C63_WRITE_PORT, write_id,		\
> > +					 (unsigned char)value);			\
> > +										\
> > +	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n",result);	\
> > +error:										\
> > +	return result < 0 ? result : count;					\
> > +}										\
> > +										\
> > +static ssize_t get_port##num(struct device *dev,				\
> > +				 struct device_attribute *attr, char *buf) {	\
> > +										\
> > +	int result = 0;								\
> > +										\
> > +	struct usb_interface *intf = to_usb_interface(dev);			\
> > +	struct cy7c63 *cyp = usb_get_intfdata(intf);				\
> > +										\
> > +	dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", num);			\
> > +										\
> > +	result = vendor_command(cyp, CY7C63_READ_PORT, read_id, 0);		\
> > +										\
> > +	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);	\
> > +										\
> > +	return sprintf(buf, "%d", cyp->port##num);				\
> > +}										\
> > +static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num,
> > set_port##num); +
> > +get_set_port(0, CY7C63_READ_PORT_ID0, CY7C63_WRITE_PORT_ID0);
> > +get_set_port(1, CY7C63_READ_PORT_ID1, CY7C63_WRITE_PORT_ID1);
>
> You get "best abuse of the macros" prize. Can you just use functions,
> and pass num as aditional argument? Then just wrap the long functions
> in small ones... converting cyp->port0/1 into array will be handy..

Well, thanks but I think I've to "share the price" with at least one other:
drivers/usb/misc/phidgetservo.c

I agree that this is no excuse for bad style, but I was just trying to keep 
the code compliant with the kernel coding conventions - my personal style 
looks a bit different anyway. I tried to avoid any formatting issues by 
looking at other drivers and the one mentioned above was recommended to me 
when I did the porting from ioctls to sysfs. Due to this I assumed that this 
might be a common way you guys try to avoid redundant code...

To be sure (and because he's the author of the USB skeleton I also used) I 
asked Greg K-H for an initial review of my code before I sent it to the list, 
and he didn't complain a bit about this marco. So is there any common rule 
for this?

> BTW could we get come better name for the driver? cy7c63 looks like
> password of very paranoid sysadmin.

Hm, the chipset family is just called like that and there're at least three 
other Cypress related drivers (cypress, cypress_m8 and cytherm) with generic 
names. I think this name shows clearly what kind of device it supports, 
doesn't it?

Apart from that there are again other drivers (ark3116.c, cp2101.c) which do 
it the same way, and I assumed that this might be some sort of naming 
convention...

> > +	/* let the user know what node this device is now attached to */
> > +	dev_info(&interface->dev,
> > +		"Cypress CY7C63xxx device now attached\n");
>
> In cases like this we aling " one character to the right.

You mean the whole string (line) one character to the right, correct?


Regards,
Oliver

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-12 17:34   ` Oliver Bock
@ 2006-06-13 19:23     ` Pavel Machek
  2006-06-13 21:16       ` Greg KH
  2006-06-13 21:30       ` Oliver Bock
  0 siblings, 2 replies; 12+ messages in thread
From: Pavel Machek @ 2006-06-13 19:23 UTC (permalink / raw)
  To: Oliver Bock; +Cc: linux-kernel, Greg KH

Hi!

> > BTW could we get come better name for the driver? cy7c63 looks like
> > password of very paranoid sysadmin.
> 
> Hm, the chipset family is just called like that and there're at least three 
> other Cypress related drivers (cypress, cypress_m8 and cytherm) with generic 
> names. I think this name shows clearly what kind of device it supports, 
> doesn't it?

cypress_63 might be unique and still easier to pronounce?

> Apart from that there are again other drivers (ark3116.c, cp2101.c) which do 
> it the same way, and I assumed that this might be some sort of naming 
> convention...

Well, at least it is not ark2a116.c :-).

> > > +	/* let the user know what node this device is now attached to */
> > > +	dev_info(&interface->dev,
> > > +		"Cypress CY7C63xxx device now attached\n");
> >
> > In cases like this we aling " one character to the right.
> 
> You mean the whole string (line) one character to the right, correct?

Yes. It should be

foo(BAR,
    BAZ).

(You have it at few more places).
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-13 19:23     ` Pavel Machek
@ 2006-06-13 21:16       ` Greg KH
  2006-06-18 15:52         ` Oliver Bock
  2006-06-13 21:30       ` Oliver Bock
  1 sibling, 1 reply; 12+ messages in thread
From: Greg KH @ 2006-06-13 21:16 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Oliver Bock, linux-kernel

On Tue, Jun 13, 2006 at 09:23:04PM +0200, Pavel Machek wrote:
> Hi!
> 
> > > BTW could we get come better name for the driver? cy7c63 looks like
> > > password of very paranoid sysadmin.
> > 
> > Hm, the chipset family is just called like that and there're at least three 
> > other Cypress related drivers (cypress, cypress_m8 and cytherm) with generic 
> > names. I think this name shows clearly what kind of device it supports, 
> > doesn't it?
> 
> cypress_63 might be unique and still easier to pronounce?

Who cares what the thing is called.  It only has to be unique in the
whole kernel driver namespace, and it will be automatically loaded by
the tools when the device is plugged in, so it will never be typed in by
hand (except by developers, and they are used to looney names like
this.)

Oliver wrote it, so he gets to name it :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-13 19:23     ` Pavel Machek
  2006-06-13 21:16       ` Greg KH
@ 2006-06-13 21:30       ` Oliver Bock
  2006-06-13 22:18         ` Pavel Machek
  1 sibling, 1 reply; 12+ messages in thread
From: Oliver Bock @ 2006-06-13 21:30 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, Greg KH

Hi Pavel,

> > Hm, the chipset family is just called like that and there're at least
> > three other Cypress related drivers (cypress, cypress_m8 and cytherm)
> > with generic names. I think this name shows clearly what kind of device
> > it supports, doesn't it?
>
> cypress_63 might be unique and still easier to pronounce?

Hm, what about something related to the vendor "AK Modul-Bus Computer GmbH"?
I think my driver might (!) only work for their firmware implementations...

cypress_akmb
cypress_akmodbus
cypress_akmodulbus

The third would be my favourite. Are there any length restrictions for 
driver/files names? Is it a problem to use parts of company names for this 
purpose (I saw lego, rio, auerswald, etc.) or does one need to ask them for 
permission in this case?

> > You mean the whole string (line) one character to the right, correct?
>
> Yes. It should be
>
> foo(BAR,
>     BAZ).
>
> (You have it at few more places).

I changed it. I had the rule "only tabs for indentation" on my mind and tried 
to choose the closest ;-) Now I first use tabs followed by spaces for 
fine-tuning (if needed).

What about the macro discussion?
If there's any convention I'm happy to follow it...


Thanks,
Oliver


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-13 21:30       ` Oliver Bock
@ 2006-06-13 22:18         ` Pavel Machek
  0 siblings, 0 replies; 12+ messages in thread
From: Pavel Machek @ 2006-06-13 22:18 UTC (permalink / raw)
  To: Oliver Bock; +Cc: linux-kernel, Greg KH

On Út 13-06-06 23:30:24, Oliver Bock wrote:
> Hi Pavel,
> 
> > > Hm, the chipset family is just called like that and there're at least
> > > three other Cypress related drivers (cypress, cypress_m8 and cytherm)
> > > with generic names. I think this name shows clearly what kind of device
> > > it supports, doesn't it?
> >
> > cypress_63 might be unique and still easier to pronounce?
> 
> Hm, what about something related to the vendor "AK Modul-Bus Computer GmbH"?
> I think my driver might (!) only work for their firmware implementations...
> 
> cypress_akmb
> cypress_akmodbus
> cypress_akmodulbus
> 
> The third would be my favourite. Are there any length restrictions for 
> driver/files names? Is it a problem to use parts of company names
> for this

No length limit; cypress_akmodulbus is quite long, but probably okay.

> > (You have it at few more places).
> 
> I changed it. I had the rule "only tabs for indentation" on my mind and tried 
> to choose the closest ;-) Now I first use tabs followed by spaces for 
> fine-tuning (if needed).
> 
> What about the macro discussion?
> If there's any convention I'm happy to follow it...

I'd prefer to do it using functions... it should be feasible. Only
repeated code will be function calls with different arguments.

								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers
  2006-06-13 21:16       ` Greg KH
@ 2006-06-18 15:52         ` Oliver Bock
  0 siblings, 0 replies; 12+ messages in thread
From: Oliver Bock @ 2006-06-18 15:52 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, Pavel Machek

From: Oliver Bock <o.bock@fh-wolfenbuettel.de>

This is a new driver for the Cypress CY7C63xxx mirco controller series. It 
currently supports the pre-programmed CYC63001A-PC by AK Modul-Bus GmbH.
It's based on a kernel 2.4 driver (cyport) by Marcus Maul which I ported to
kernel 2.6 using sysfs. I intend to support more controllers of this family
(and more features) as soon as I get hold of the required IDs etc. Please see
the source code's header for more information.

Signed-off-by: Oliver Bock <o.bock@fh-wolfenbuettel.de>

---

Please CC me as I'm not yet subscribed to LKML. Any comments are welcome.
Special thanks to Greg K-H and Pavel Machek for their helpful support!

I polished the formatting and indentation (source looks perfectly fine although the
patch shows too few spaces in wrapped function headers) and also redesigned
the code using the usual approach instead of a marco. The module name
changed also to look not too cryptic. I considered naming it cypress_akmodbus
but that name would limit future extensions of the driver, thus I dropped that
idea again. In my opinion this is the final patch of this initial version.

diff against 2.6.17 as there's no prepatch version yet.


--- linux-2.6.17/drivers/usb/Makefile.orig	2006-06-18 03:49:35.000000000 +0200
+++ linux-2.6.17/drivers/usb/Makefile	2006-06-18 17:17:43.292942750 +0200
@@ -48,6 +48,7 @@ obj-$(CONFIG_USB_MICROTEK)	+= image/
 obj-$(CONFIG_USB_SERIAL)	+= serial/
 
 obj-$(CONFIG_USB_AUERSWALD)	+= misc/
+obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/
 obj-$(CONFIG_USB_CYTHERM)	+= misc/
 obj-$(CONFIG_USB_EMI26)		+= misc/
 obj-$(CONFIG_USB_EMI62)		+= misc/
--- linux-2.6.17/drivers/usb/misc/Kconfig.orig	2006-06-18 03:49:35.000000000 +0200
+++ linux-2.6.17/drivers/usb/misc/Kconfig	2006-06-18 17:15:09.475329750 +0200
@@ -88,6 +88,20 @@ config USB_LED
 	  To compile this driver as a module, choose M here: the
 	  module will be called usbled.
 
+config USB_CYPRESS_CY7C63
+	tristate "Cypress CY7C63xxx USB driver support"
+	depends on USB
+	help
+	  Say Y here if you want to connect a Cypress CY7C63xxx
+	  micro controller to your computer's USB port. Currently this
+	  driver supports the pre-programmed devices (incl. firmware)
+	  by AK Modul-Bus Computer GmbH.
+
+	  Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called cypress_cy7c63.
+
 config USB_CYTHERM
 	tristate "Cypress USB thermometer driver support"
 	depends on USB
--- linux-2.6.17/drivers/usb/misc/Makefile.orig	2006-06-18 03:49:35.000000000 +0200
+++ linux-2.6.17/drivers/usb/misc/Makefile	2006-06-18 17:16:49.833601750 +0200
@@ -4,6 +4,7 @@
 #
 
 obj-$(CONFIG_USB_AUERSWALD)	+= auerswald.o
+obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
 obj-$(CONFIG_USB_CYTHERM)	+= cytherm.o
 obj-$(CONFIG_USB_EMI26)		+= emi26.o
 obj-$(CONFIG_USB_EMI62)		+= emi62.o
--- linux-2.6.17/drivers/usb/misc/cypress_cy7c63.c.orig	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.17/drivers/usb/misc/cypress_cy7c63.c	2006-06-18 14:47:33.000000000 +0200
@@ -0,0 +1,279 @@
+/*
+* cypress_cy7c63.c
+*
+* Copyright (c) 2006 Oliver Bock (o.bock@fh-wolfenbuettel.de)
+*
+*	This driver is based on the Cypress USB Driver by Marcus Maul
+*	(cyport) and the 2.0 version of Greg Kroah-Hartman's
+*	USB Skeleton driver.
+*
+*	This is a generic driver for the Cypress CY7C63xxx family.
+*	For the time being it enables you to read from and write to
+*	the single I/O ports of the device.
+*
+*	Supported vendors:	AK Modul-Bus Computer GmbH
+*	Supported devices:	CY7C63001A-PC (to be continued...)
+*	Supported functions:	Read/Write Ports (to be continued...)
+*
+*
+*	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, version 2.
+*/
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+
+#define DRIVER_AUTHOR		"Oliver Bock (o.bock@fh-wolfenbuettel.de)"
+#define DRIVER_DESC		"Cypress CY7C63xxx USB driver"
+
+#define CYPRESS_VENDOR_ID	0xa2c
+#define CYPRESS_PRODUCT_ID	0x8
+
+#define CYPRESS_READ_PORT	0x4
+#define CYPRESS_WRITE_PORT	0x5
+
+#define CYPRESS_READ_RAM	0x2
+#define CYPRESS_WRITE_RAM	0x3
+#define CYPRESS_READ_ROM	0x1
+
+#define CYPRESS_READ_PORT_ID0	0
+#define CYPRESS_WRITE_PORT_ID0	0
+#define CYPRESS_READ_PORT_ID1	0x2
+#define CYPRESS_WRITE_PORT_ID1	1
+
+#define CYPRESS_MAX_REQSIZE	8
+
+
+/* table of devices that work with this driver */
+static struct usb_device_id cypress_table [] = {
+	{ USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) },
+	{ }
+};
+MODULE_DEVICE_TABLE(usb, cypress_table);
+
+/* structure to hold all of our device specific stuff */
+struct cypress {
+	struct usb_device *	udev;
+	unsigned char		port[2];
+};
+
+/* used to send usb control messages to device */
+int vendor_command(struct cypress *dev, unsigned char request,
+		   unsigned char address, unsigned char data)
+{
+	int retval = 0;
+	unsigned int pipe;
+	unsigned char *iobuf;
+
+	/* allocate some memory for the i/o buffer*/
+	iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL);
+	if (!iobuf) {
+		dev_err(&dev->udev->dev, "Out of memory!\n");
+		retval = -ENOMEM;
+		goto error;
+	}
+
+	dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data);
+
+	/* prepare usb control message and send it upstream */
+	pipe = usb_rcvctrlpipe(dev->udev, 0);
+	retval = usb_control_msg(dev->udev, pipe, request,
+				 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+				 address, data, iobuf, CYPRESS_MAX_REQSIZE,
+				 USB_CTRL_GET_TIMEOUT);
+
+	/* store returned data (more READs to be added) */
+	switch (request) {
+		case CYPRESS_READ_PORT:
+			if (address == CYPRESS_READ_PORT_ID0) {
+				dev->port[0] = iobuf[1];
+				dev_dbg(&dev->udev->dev,
+					"READ_PORT0 returned: %d\n",
+					dev->port[0]);
+			}
+			else if (address == CYPRESS_READ_PORT_ID1) {
+				dev->port[1] = iobuf[1];
+				dev_dbg(&dev->udev->dev,
+					"READ_PORT1 returned: %d\n",
+					dev->port[1]);
+			}
+			break;
+	}
+
+	kfree(iobuf);
+error:
+	return retval;
+}
+
+/* write port value */
+static ssize_t write_port(struct device *dev, struct device_attribute *attr,
+			  const char *buf, size_t count,
+			  int port_num, int write_id)
+{
+	int value = -1;
+	int result = 0;
+
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct cypress *cyp = usb_get_intfdata(intf);
+
+	dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", port_num);
+
+	/* validate input data */
+	if (sscanf(buf, "%d", &value) < 1) {
+		result = -EINVAL;
+		goto error;
+	}
+	if (value < 0 || value > 255) {
+		result = -EINVAL;
+		goto error;
+	}
+
+	result = vendor_command(cyp, CYPRESS_WRITE_PORT, write_id,
+				(unsigned char)value);
+
+	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);
+error:
+	return result < 0 ? result : count;
+}
+
+/* attribute callback handler (write) */
+static ssize_t set_port0_handler(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t count)
+{
+	return write_port(dev, attr, buf, count, 0, CYPRESS_WRITE_PORT_ID0);
+}
+
+/* attribute callback handler (write) */
+static ssize_t set_port1_handler(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t count)
+{
+	return write_port(dev, attr, buf, count, 1, CYPRESS_WRITE_PORT_ID1);
+}
+
+/* read port value */
+static ssize_t read_port(struct device *dev, struct device_attribute *attr,
+			 char *buf, int port_num, int read_id)
+{
+	int result = 0;
+
+	struct usb_interface *intf = to_usb_interface(dev);
+	struct cypress *cyp = usb_get_intfdata(intf);
+
+	dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", port_num);
+
+	result = vendor_command(cyp, CYPRESS_READ_PORT, read_id, 0);
+
+	dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result);
+
+	return sprintf(buf, "%d", cyp->port[port_num]);
+}
+
+/* attribute callback handler (read) */
+static ssize_t get_port0_handler(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	return read_port(dev, attr, buf, 0, CYPRESS_READ_PORT_ID0);
+}
+
+/* attribute callback handler (read) */
+static ssize_t get_port1_handler(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1);
+}
+
+static DEVICE_ATTR(port0, S_IWUGO | S_IRUGO,
+		   get_port0_handler, set_port0_handler);
+
+static DEVICE_ATTR(port1, S_IWUGO | S_IRUGO,
+		   get_port1_handler, set_port1_handler);
+
+
+static int cypress_probe(struct usb_interface *interface,
+			 const struct usb_device_id *id)
+{
+	struct cypress *dev = NULL;
+	int retval = -ENOMEM;
+
+	/* allocate memory for our device state and initialize it */
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (dev == NULL) {
+		dev_err(&dev->udev->dev, "Out of memory!\n");
+		goto error;
+	}
+
+	dev->udev = usb_get_dev(interface_to_usbdev(interface));
+
+	/* save our data pointer in this interface device */
+	usb_set_intfdata(interface, dev);
+
+	/* create device attribute files */
+	device_create_file(&interface->dev, &dev_attr_port0);
+	device_create_file(&interface->dev, &dev_attr_port1);
+
+	/* let the user know that the device is now attached */
+	dev_info(&interface->dev,
+		 "Cypress CY7C63xxx device now attached\n");
+
+	retval = 0;
+error:
+	return retval;
+}
+
+static void cypress_disconnect(struct usb_interface *interface)
+{
+	struct cypress *dev;
+
+	dev = usb_get_intfdata(interface);
+	usb_set_intfdata(interface, NULL);
+
+	/* remove device attribute files */
+	device_remove_file(&interface->dev, &dev_attr_port0);
+	device_remove_file(&interface->dev, &dev_attr_port1);
+
+	usb_put_dev(dev->udev);
+
+	dev_info(&interface->dev,
+		 "Cypress CY7C63xxx device now disconnected\n");
+
+	kfree(dev);
+}
+
+static struct usb_driver cypress_driver = {
+	.name = "cypress_cy7c63",
+	.probe = cypress_probe,
+	.disconnect = cypress_disconnect,
+	.id_table = cypress_table,
+};
+
+static int __init cypress_init(void)
+{
+	int result;
+
+	/* register this driver with the USB subsystem */
+	result = usb_register(&cypress_driver);
+	if (result) {
+		err("Function usb_register failed! Error number: %d\n", result);
+	}
+
+	return result;
+}
+
+static void __exit cypress_exit(void)
+{
+	/* deregister this driver with the USB subsystem */
+	usb_deregister(&cypress_driver);
+}
+
+module_init(cypress_init);
+module_exit(cypress_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+
+MODULE_LICENSE("GPL");



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-06-18 15:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-08 20:57 [PATCH 1/1] usb: new driver for Cypress CY7C63xxx mirco controllers Oliver Bock
2006-06-09 10:45 ` Pavel Machek
2006-06-09 22:50   ` Greg KH
2006-06-10 12:56     ` Oliver Bock
  -- strict thread matches above, loose matches on Subject: below --
2006-06-09 22:42 Oliver Bock
2006-06-09 22:49 ` Pavel Machek
2006-06-12 17:34   ` Oliver Bock
2006-06-13 19:23     ` Pavel Machek
2006-06-13 21:16       ` Greg KH
2006-06-18 15:52         ` Oliver Bock
2006-06-13 21:30       ` Oliver Bock
2006-06-13 22:18         ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox