Skip to contentSkip to conversation

usb: new driver for Cypress CY7C63xxx mirco controllers

PATCH Oliver Bock 4 participants 8 messages Jun 9, 2006 – Jun 18, 2006 USB

lore
Share & tools
lore
#0 lore raw

From: Oliver Bock <[email protected]>

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.

---

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

drivers/usb/Makefile renamed from drivers/usb/Makefile.orig +1 -0
@@ -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/
drivers/usb/misc/Kconfig renamed from drivers/usb/misc/Kconfig.orig +14 -0
@@ -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
drivers/usb/misc/Makefile renamed from drivers/usb/misc/Makefile.orig +1 -0
@@ -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
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +244 -0

244 lines not on this page · raw message

#1 lore raw

Hi!

Sorry, now the review begins...

drivers/usb/misc/cy7c63.c line 67

Quoted 3 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +3 -0
+/* 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.

Quoted 40 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +40 -0
+#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);			\
+										\

drivers/usb/misc/cy7c63.c line 160

Quoted 10 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +10 -0
+	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..

drivers/usb/misc/cy7c63.c line 163

Quoted 2 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +2 -0
+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.

drivers/usb/misc/cy7c63.c line 186

Quoted 3 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +3 -0
+	/* 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

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
Quoted 1 line · Pavel Machek

Sorry, now the review begins...

No problem at all.

Quoted 5 lines

drivers/usb/misc/cy7c63.c line 67

Quoted 3 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +3 -0
+/* 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.

Quoted 46 lines
Quoted 46 lines
(quoted diff) +2 -0
+#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) { \

drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +43 -0
+										\
+	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);				\
+}										\
Quoted 8 lines

drivers/usb/misc/cy7c63.c line 160

Quoted 4 lines

+static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num, set_port##num); +

drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +2 -0
+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?

Quoted 2 lines

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...

Quoted 5 lines

drivers/usb/misc/cy7c63.c line 186

Quoted 3 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +3 -0
+	/* 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

#3 lore raw

Hi!

Quoted 7 lines
Quoted 2 lines

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?

Quoted 3 lines

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 :-).

Quoted 7 lines
Quoted 5 lines

drivers/usb/misc/cy7c63.c line 186

Quoted 3 lines
drivers/usb/misc/cy7c63.c renamed from drivers/usb/misc/cy7c63.c.orig +3 -0
+	/* 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

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#4 lore raw
Quoted 11 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 2 lines

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

#5 lore raw

From: Oliver Bock <[email protected]>

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.

---

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.

drivers/usb/Makefile renamed from drivers/usb/Makefile.orig +1 -0
@@ -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/
drivers/usb/misc/Kconfig renamed from drivers/usb/misc/Kconfig.orig +14 -0
@@ -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
drivers/usb/misc/Makefile renamed from drivers/usb/misc/Makefile.orig +1 -0
@@ -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
drivers/usb/misc/cypress_cy7c63.c renamed from drivers/usb/misc/cypress_cy7c63.c.orig +279 -0

279 lines not on this page · raw message

#6 lore raw
In reply to Pavel Machek

Hi Pavel,

Quoted 6 lines
Quoted 4 lines

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?

Quoted 8 lines
Quoted 1 line

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

#7 lore raw
Quoted 12 lines · Oliver Bock

Hi Pavel,

Quoted 6 lines
Quoted 4 lines

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...

Quoted 7 lines

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.

Quoted 8 lines
Quoted 1 line

(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

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