diff options
author | Oliver Bock <o.bock@fh-wolfenbuettel.de> | 2006-06-22 13:04:47 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-07-12 19:03:21 -0400 |
commit | 9189bfc2df0fd87e0e537fe7ad4cf3b66a440fe4 (patch) | |
tree | 2ae07311531ff2ce51d9e93de7fc10953efae335 /drivers/usb | |
parent | 58a5b0a6346b71bf01f0d49cfcc91d3225a373aa (diff) |
[PATCH] USB: rename Cypress CY7C63xxx driver to proper name and fix up some tiny things
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/misc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/usb/misc/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/misc/cy7c63.c | 244 | ||||
-rw-r--r-- | drivers/usb/misc/cypress_cy7c63.c | 279 |
5 files changed, 286 insertions, 251 deletions
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index c7123bf71c58..4710eb02ed64 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -48,7 +48,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/ | |||
48 | obj-$(CONFIG_USB_SERIAL) += serial/ | 48 | obj-$(CONFIG_USB_SERIAL) += serial/ |
49 | 49 | ||
50 | obj-$(CONFIG_USB_AUERSWALD) += misc/ | 50 | obj-$(CONFIG_USB_AUERSWALD) += misc/ |
51 | obj-$(CONFIG_USB_CY7C63) += misc/ | 51 | obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ |
52 | obj-$(CONFIG_USB_CYTHERM) += misc/ | 52 | obj-$(CONFIG_USB_CYTHERM) += misc/ |
53 | obj-$(CONFIG_USB_EMI26) += misc/ | 53 | obj-$(CONFIG_USB_EMI26) += misc/ |
54 | obj-$(CONFIG_USB_EMI62) += misc/ | 54 | obj-$(CONFIG_USB_EMI62) += misc/ |
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index daa486dde8cf..88928a4be805 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig | |||
@@ -88,19 +88,19 @@ config USB_LED | |||
88 | To compile this driver as a module, choose M here: the | 88 | To compile this driver as a module, choose M here: the |
89 | module will be called usbled. | 89 | module will be called usbled. |
90 | 90 | ||
91 | config USB_CY7C63 | 91 | config USB_CYPRESS_CY7C63 |
92 | tristate "Cypress CY7C63xxx USB driver support" | 92 | tristate "Cypress CY7C63xxx USB driver support" |
93 | depends on USB | 93 | depends on USB |
94 | help | 94 | help |
95 | Say Y here if you want to connect a Cypress CY7C63xxx | 95 | Say Y here if you want to connect a Cypress CY7C63xxx |
96 | micro controller to your computer's USB port. This driver | 96 | micro controller to your computer's USB port. Currently this |
97 | supports the pre-programmed devices (incl. firmware) by | 97 | driver supports the pre-programmed devices (incl. firmware) |
98 | AK Modul-Bus Computer GmbH. | 98 | by AK Modul-Bus Computer GmbH. |
99 | 99 | ||
100 | Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html | 100 | Please see: http://www.ak-modul-bus.de/stat/mikrocontroller.html |
101 | 101 | ||
102 | To compile this driver as a module, choose M here: the | 102 | To compile this driver as a module, choose M here: the |
103 | module will be called cy7c63. | 103 | module will be called cypress_cy7c63. |
104 | 104 | ||
105 | config USB_CYTHERM | 105 | config USB_CYTHERM |
106 | tristate "Cypress USB thermometer driver support" | 106 | tristate "Cypress USB thermometer driver support" |
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile index f25a97227297..2927260c5812 100644 --- a/drivers/usb/misc/Makefile +++ b/drivers/usb/misc/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | obj-$(CONFIG_USB_AUERSWALD) += auerswald.o | 6 | obj-$(CONFIG_USB_AUERSWALD) += auerswald.o |
7 | obj-$(CONFIG_USB_CY7C63) += cy7c63.o | 7 | obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o |
8 | obj-$(CONFIG_USB_CYTHERM) += cytherm.o | 8 | obj-$(CONFIG_USB_CYTHERM) += cytherm.o |
9 | obj-$(CONFIG_USB_EMI26) += emi26.o | 9 | obj-$(CONFIG_USB_EMI26) += emi26.o |
10 | obj-$(CONFIG_USB_EMI62) += emi62.o | 10 | obj-$(CONFIG_USB_EMI62) += emi62.o |
diff --git a/drivers/usb/misc/cy7c63.c b/drivers/usb/misc/cy7c63.c deleted file mode 100644 index 8a1c10b89b76..000000000000 --- a/drivers/usb/misc/cy7c63.c +++ /dev/null | |||
@@ -1,244 +0,0 @@ | |||
1 | /* | ||
2 | * cy7c63.c | ||
3 | * | ||
4 | * Copyright (c) 2006 Oliver Bock (bock@fh-wolfenbuettel.de) | ||
5 | * | ||
6 | * This driver is based on the Cypress Thermometer USB Driver by | ||
7 | * Marcus Maul and the 2.0 version of Greg Kroah-Hartman's | ||
8 | * USB Skeleton driver. | ||
9 | * | ||
10 | * Is is a generic driver for the Cypress CY7C63000 family. | ||
11 | * For the time being it enables you to toggle the single I/O ports | ||
12 | * of the device. | ||
13 | * | ||
14 | * Supported vendors: AK Modul-Bus Computer GmbH | ||
15 | * Supported devices: CY7C63001A-PC (to be continued...) | ||
16 | * Supported functions: Read/Write Ports (to be continued...) | ||
17 | * | ||
18 | * Chipsets families: CY7C63000, CY7C63001, CY7C63100, CY7C63101 | ||
19 | * | ||
20 | * | ||
21 | * This program is free software; you can redistribute it and/or | ||
22 | * modify it under the terms of the GNU General Public License as | ||
23 | * published by the Free Software Foundation, version 2. | ||
24 | */ | ||
25 | |||
26 | #include <linux/init.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/usb.h> | ||
30 | |||
31 | #define DRIVER_AUTHOR "Oliver Bock (bock@fh-wolfenbuettel.de)" | ||
32 | #define DRIVER_DESC "Cypress CY7C63xxx USB driver" | ||
33 | |||
34 | #define CY7C63_VENDOR_ID 0xa2c | ||
35 | #define CY7C63_PRODUCT_ID 0x8 | ||
36 | |||
37 | #define CY7C63_READ_PORT 0x4 | ||
38 | #define CY7C63_WRITE_PORT 0x5 | ||
39 | #define CY7C63_READ_RAM 0x2 | ||
40 | #define CY7C63_WRITE_RAM 0x3 | ||
41 | #define CY7C63_READ_ROM 0x1 | ||
42 | |||
43 | #define CY7C63_READ_PORT_ID0 0 | ||
44 | #define CY7C63_WRITE_PORT_ID0 0 | ||
45 | #define CY7C63_READ_PORT_ID1 0x2 | ||
46 | #define CY7C63_WRITE_PORT_ID1 1 | ||
47 | |||
48 | #define CY7C63_MAX_REQSIZE 8 | ||
49 | |||
50 | |||
51 | /* table of devices that work with this driver */ | ||
52 | static struct usb_device_id cy7c63_table [] = { | ||
53 | { USB_DEVICE(CY7C63_VENDOR_ID, CY7C63_PRODUCT_ID) }, | ||
54 | { } | ||
55 | }; | ||
56 | MODULE_DEVICE_TABLE(usb, cy7c63_table); | ||
57 | |||
58 | /* structure to hold all of our device specific stuff */ | ||
59 | struct cy7c63 { | ||
60 | struct usb_device * udev; | ||
61 | char port0; | ||
62 | char port1; | ||
63 | }; | ||
64 | |||
65 | /* used to send usb control messages to device */ | ||
66 | int vendor_command(struct cy7c63 *dev, unsigned char request, | ||
67 | unsigned char address, unsigned char data) { | ||
68 | |||
69 | int retval = 0; | ||
70 | unsigned int pipe; | ||
71 | unsigned char *iobuf; | ||
72 | |||
73 | /* allocate some memory for the i/o buffer*/ | ||
74 | iobuf = kzalloc(CY7C63_MAX_REQSIZE, GFP_KERNEL); | ||
75 | if (!iobuf) { | ||
76 | dev_err(&dev->udev->dev, "Out of memory!\n"); | ||
77 | retval = -ENOMEM; | ||
78 | goto error; | ||
79 | } | ||
80 | |||
81 | dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data); | ||
82 | |||
83 | /* prepare usb control message and send it upstream */ | ||
84 | pipe = usb_rcvctrlpipe(dev->udev, 0); | ||
85 | retval = usb_control_msg(dev->udev, pipe, request, | ||
86 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, | ||
87 | address, data, iobuf, CY7C63_MAX_REQSIZE, | ||
88 | USB_CTRL_GET_TIMEOUT); | ||
89 | |||
90 | /* store returned data (more READs to be added!) */ | ||
91 | switch (request) { | ||
92 | case CY7C63_READ_PORT: | ||
93 | if (address == CY7C63_READ_PORT_ID0) { | ||
94 | dev->port0 = iobuf[1]; | ||
95 | dev_dbg(&dev->udev->dev, | ||
96 | "READ_PORT0 returned: %d\n",dev->port0); | ||
97 | } | ||
98 | else if (address == CY7C63_READ_PORT_ID1) { | ||
99 | dev->port1 = iobuf[1]; | ||
100 | dev_dbg(&dev->udev->dev, | ||
101 | "READ_PORT1 returned: %d\n",dev->port1); | ||
102 | } | ||
103 | break; | ||
104 | } | ||
105 | |||
106 | kfree(iobuf); | ||
107 | error: | ||
108 | return retval; | ||
109 | } | ||
110 | |||
111 | #define get_set_port(num,read_id,write_id) \ | ||
112 | static ssize_t set_port##num(struct device *dev, struct device_attribute *attr, \ | ||
113 | const char *buf, size_t count) { \ | ||
114 | \ | ||
115 | int value; \ | ||
116 | int result = 0; \ | ||
117 | \ | ||
118 | struct usb_interface *intf = to_usb_interface(dev); \ | ||
119 | struct cy7c63 *cyp = usb_get_intfdata(intf); \ | ||
120 | \ | ||
121 | dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", num); \ | ||
122 | \ | ||
123 | /* validate input data */ \ | ||
124 | if (sscanf(buf, "%d", &value) < 1) { \ | ||
125 | result = -EINVAL; \ | ||
126 | goto error; \ | ||
127 | } \ | ||
128 | if (value>255 || value<0) { \ | ||
129 | result = -EINVAL; \ | ||
130 | goto error; \ | ||
131 | } \ | ||
132 | \ | ||
133 | result = vendor_command(cyp, CY7C63_WRITE_PORT, write_id, \ | ||
134 | (unsigned char)value); \ | ||
135 | \ | ||
136 | dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n",result); \ | ||
137 | error: \ | ||
138 | return result < 0 ? result : count; \ | ||
139 | } \ | ||
140 | \ | ||
141 | static ssize_t get_port##num(struct device *dev, \ | ||
142 | struct device_attribute *attr, char *buf) { \ | ||
143 | \ | ||
144 | int result = 0; \ | ||
145 | \ | ||
146 | struct usb_interface *intf = to_usb_interface(dev); \ | ||
147 | struct cy7c63 *cyp = usb_get_intfdata(intf); \ | ||
148 | \ | ||
149 | dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", num); \ | ||
150 | \ | ||
151 | result = vendor_command(cyp, CY7C63_READ_PORT, read_id, 0); \ | ||
152 | \ | ||
153 | dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result); \ | ||
154 | \ | ||
155 | return sprintf(buf, "%d", cyp->port##num); \ | ||
156 | } \ | ||
157 | static DEVICE_ATTR(port##num, S_IWUGO | S_IRUGO, get_port##num, set_port##num); | ||
158 | |||
159 | get_set_port(0, CY7C63_READ_PORT_ID0, CY7C63_WRITE_PORT_ID0); | ||
160 | get_set_port(1, CY7C63_READ_PORT_ID1, CY7C63_WRITE_PORT_ID1); | ||
161 | |||
162 | static int cy7c63_probe(struct usb_interface *interface, | ||
163 | const struct usb_device_id *id) { | ||
164 | |||
165 | struct cy7c63 *dev = NULL; | ||
166 | int retval = -ENOMEM; | ||
167 | |||
168 | /* allocate memory for our device state and initialize it */ | ||
169 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
170 | if (dev == NULL) { | ||
171 | dev_err(&dev->udev->dev, "Out of memory!\n"); | ||
172 | goto error; | ||
173 | } | ||
174 | |||
175 | dev->udev = usb_get_dev(interface_to_usbdev(interface)); | ||
176 | |||
177 | /* save our data pointer in this interface device */ | ||
178 | usb_set_intfdata(interface, dev); | ||
179 | |||
180 | /* create device attribute files */ | ||
181 | device_create_file(&interface->dev, &dev_attr_port0); | ||
182 | device_create_file(&interface->dev, &dev_attr_port1); | ||
183 | |||
184 | /* let the user know what node this device is now attached to */ | ||
185 | dev_info(&interface->dev, | ||
186 | "Cypress CY7C63xxx device now attached\n"); | ||
187 | |||
188 | retval = 0; | ||
189 | error: | ||
190 | return retval; | ||
191 | } | ||
192 | |||
193 | static void cy7c63_disconnect(struct usb_interface *interface) { | ||
194 | |||
195 | struct cy7c63 *dev; | ||
196 | |||
197 | dev = usb_get_intfdata(interface); | ||
198 | usb_set_intfdata(interface, NULL); | ||
199 | |||
200 | /* remove device attribute files */ | ||
201 | device_remove_file(&interface->dev, &dev_attr_port0); | ||
202 | device_remove_file(&interface->dev, &dev_attr_port1); | ||
203 | |||
204 | usb_put_dev(dev->udev); | ||
205 | |||
206 | dev_info(&interface->dev, | ||
207 | "Cypress CY7C63xxx device now disconnected\n"); | ||
208 | |||
209 | kfree(dev); | ||
210 | } | ||
211 | |||
212 | static struct usb_driver cy7c63_driver = { | ||
213 | .name = "cy7c63", | ||
214 | .probe = cy7c63_probe, | ||
215 | .disconnect = cy7c63_disconnect, | ||
216 | .id_table = cy7c63_table, | ||
217 | }; | ||
218 | |||
219 | static int __init cy7c63_init(void) { | ||
220 | |||
221 | int result; | ||
222 | |||
223 | /* register this driver with the USB subsystem */ | ||
224 | result = usb_register(&cy7c63_driver); | ||
225 | if (result) { | ||
226 | err("Function usb_register failed! Error number: %d\n", result); | ||
227 | } | ||
228 | |||
229 | return result; | ||
230 | } | ||
231 | |||
232 | static void __exit cy7c63_exit(void) { | ||
233 | |||
234 | /* deregister this driver with the USB subsystem */ | ||
235 | usb_deregister(&cy7c63_driver); | ||
236 | } | ||
237 | |||
238 | module_init(cy7c63_init); | ||
239 | module_exit(cy7c63_exit); | ||
240 | |||
241 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
242 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
243 | |||
244 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c new file mode 100644 index 000000000000..e091d327bd9e --- /dev/null +++ b/drivers/usb/misc/cypress_cy7c63.c | |||
@@ -0,0 +1,279 @@ | |||
1 | /* | ||
2 | * cypress_cy7c63.c | ||
3 | * | ||
4 | * Copyright (c) 2006 Oliver Bock (o.bock@fh-wolfenbuettel.de) | ||
5 | * | ||
6 | * This driver is based on the Cypress USB Driver by Marcus Maul | ||
7 | * (cyport) and the 2.0 version of Greg Kroah-Hartman's | ||
8 | * USB Skeleton driver. | ||
9 | * | ||
10 | * This is a generic driver for the Cypress CY7C63xxx family. | ||
11 | * For the time being it enables you to read from and write to | ||
12 | * the single I/O ports of the device. | ||
13 | * | ||
14 | * Supported vendors: AK Modul-Bus Computer GmbH | ||
15 | * Supported devices: CY7C63001A-PC (to be continued...) | ||
16 | * Supported functions: Read/Write Ports (to be continued...) | ||
17 | * | ||
18 | * | ||
19 | * This program is free software; you can redistribute it and/or | ||
20 | * modify it under the terms of the GNU General Public License as | ||
21 | * published by the Free Software Foundation, version 2. | ||
22 | */ | ||
23 | |||
24 | #include <linux/init.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/usb.h> | ||
28 | |||
29 | #define DRIVER_AUTHOR "Oliver Bock (o.bock@fh-wolfenbuettel.de)" | ||
30 | #define DRIVER_DESC "Cypress CY7C63xxx USB driver" | ||
31 | |||
32 | #define CYPRESS_VENDOR_ID 0xa2c | ||
33 | #define CYPRESS_PRODUCT_ID 0x8 | ||
34 | |||
35 | #define CYPRESS_READ_PORT 0x4 | ||
36 | #define CYPRESS_WRITE_PORT 0x5 | ||
37 | |||
38 | #define CYPRESS_READ_RAM 0x2 | ||
39 | #define CYPRESS_WRITE_RAM 0x3 | ||
40 | #define CYPRESS_READ_ROM 0x1 | ||
41 | |||
42 | #define CYPRESS_READ_PORT_ID0 0 | ||
43 | #define CYPRESS_WRITE_PORT_ID0 0 | ||
44 | #define CYPRESS_READ_PORT_ID1 0x2 | ||
45 | #define CYPRESS_WRITE_PORT_ID1 1 | ||
46 | |||
47 | #define CYPRESS_MAX_REQSIZE 8 | ||
48 | |||
49 | |||
50 | /* table of devices that work with this driver */ | ||
51 | static struct usb_device_id cypress_table [] = { | ||
52 | { USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) }, | ||
53 | { } | ||
54 | }; | ||
55 | MODULE_DEVICE_TABLE(usb, cypress_table); | ||
56 | |||
57 | /* structure to hold all of our device specific stuff */ | ||
58 | struct cypress { | ||
59 | struct usb_device * udev; | ||
60 | unsigned char port[2]; | ||
61 | }; | ||
62 | |||
63 | /* used to send usb control messages to device */ | ||
64 | static int vendor_command(struct cypress *dev, unsigned char request, | ||
65 | unsigned char address, unsigned char data) | ||
66 | { | ||
67 | int retval = 0; | ||
68 | unsigned int pipe; | ||
69 | unsigned char *iobuf; | ||
70 | |||
71 | /* allocate some memory for the i/o buffer*/ | ||
72 | iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL); | ||
73 | if (!iobuf) { | ||
74 | dev_err(&dev->udev->dev, "Out of memory!\n"); | ||
75 | retval = -ENOMEM; | ||
76 | goto error; | ||
77 | } | ||
78 | |||
79 | dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data); | ||
80 | |||
81 | /* prepare usb control message and send it upstream */ | ||
82 | pipe = usb_rcvctrlpipe(dev->udev, 0); | ||
83 | retval = usb_control_msg(dev->udev, pipe, request, | ||
84 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, | ||
85 | address, data, iobuf, CYPRESS_MAX_REQSIZE, | ||
86 | USB_CTRL_GET_TIMEOUT); | ||
87 | |||
88 | /* store returned data (more READs to be added) */ | ||
89 | switch (request) { | ||
90 | case CYPRESS_READ_PORT: | ||
91 | if (address == CYPRESS_READ_PORT_ID0) { | ||
92 | dev->port[0] = iobuf[1]; | ||
93 | dev_dbg(&dev->udev->dev, | ||
94 | "READ_PORT0 returned: %d\n", | ||
95 | dev->port[0]); | ||
96 | } | ||
97 | else if (address == CYPRESS_READ_PORT_ID1) { | ||
98 | dev->port[1] = iobuf[1]; | ||
99 | dev_dbg(&dev->udev->dev, | ||
100 | "READ_PORT1 returned: %d\n", | ||
101 | dev->port[1]); | ||
102 | } | ||
103 | break; | ||
104 | } | ||
105 | |||
106 | kfree(iobuf); | ||
107 | error: | ||
108 | return retval; | ||
109 | } | ||
110 | |||
111 | /* write port value */ | ||
112 | static ssize_t write_port(struct device *dev, struct device_attribute *attr, | ||
113 | const char *buf, size_t count, | ||
114 | int port_num, int write_id) | ||
115 | { | ||
116 | int value = -1; | ||
117 | int result = 0; | ||
118 | |||
119 | struct usb_interface *intf = to_usb_interface(dev); | ||
120 | struct cypress *cyp = usb_get_intfdata(intf); | ||
121 | |||
122 | dev_dbg(&cyp->udev->dev, "WRITE_PORT%d called\n", port_num); | ||
123 | |||
124 | /* validate input data */ | ||
125 | if (sscanf(buf, "%d", &value) < 1) { | ||
126 | result = -EINVAL; | ||
127 | goto error; | ||
128 | } | ||
129 | if (value < 0 || value > 255) { | ||
130 | result = -EINVAL; | ||
131 | goto error; | ||
132 | } | ||
133 | |||
134 | result = vendor_command(cyp, CYPRESS_WRITE_PORT, write_id, | ||
135 | (unsigned char)value); | ||
136 | |||
137 | dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result); | ||
138 | error: | ||
139 | return result < 0 ? result : count; | ||
140 | } | ||
141 | |||
142 | /* attribute callback handler (write) */ | ||
143 | static ssize_t set_port0_handler(struct device *dev, | ||
144 | struct device_attribute *attr, | ||
145 | const char *buf, size_t count) | ||
146 | { | ||
147 | return write_port(dev, attr, buf, count, 0, CYPRESS_WRITE_PORT_ID0); | ||
148 | } | ||
149 | |||
150 | /* attribute callback handler (write) */ | ||
151 | static ssize_t set_port1_handler(struct device *dev, | ||
152 | struct device_attribute *attr, | ||
153 | const char *buf, size_t count) | ||
154 | { | ||
155 | return write_port(dev, attr, buf, count, 1, CYPRESS_WRITE_PORT_ID1); | ||
156 | } | ||
157 | |||
158 | /* read port value */ | ||
159 | static ssize_t read_port(struct device *dev, struct device_attribute *attr, | ||
160 | char *buf, int port_num, int read_id) | ||
161 | { | ||
162 | int result = 0; | ||
163 | |||
164 | struct usb_interface *intf = to_usb_interface(dev); | ||
165 | struct cypress *cyp = usb_get_intfdata(intf); | ||
166 | |||
167 | dev_dbg(&cyp->udev->dev, "READ_PORT%d called\n", port_num); | ||
168 | |||
169 | result = vendor_command(cyp, CYPRESS_READ_PORT, read_id, 0); | ||
170 | |||
171 | dev_dbg(&cyp->udev->dev, "Result of vendor_command: %d\n\n", result); | ||
172 | |||
173 | return sprintf(buf, "%d", cyp->port[port_num]); | ||
174 | } | ||
175 | |||
176 | /* attribute callback handler (read) */ | ||
177 | static ssize_t get_port0_handler(struct device *dev, | ||
178 | struct device_attribute *attr, char *buf) | ||
179 | { | ||
180 | return read_port(dev, attr, buf, 0, CYPRESS_READ_PORT_ID0); | ||
181 | } | ||
182 | |||
183 | /* attribute callback handler (read) */ | ||
184 | static ssize_t get_port1_handler(struct device *dev, | ||
185 | struct device_attribute *attr, char *buf) | ||
186 | { | ||
187 | return read_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1); | ||
188 | } | ||
189 | |||
190 | static DEVICE_ATTR(port0, S_IWUGO | S_IRUGO, | ||
191 | get_port0_handler, set_port0_handler); | ||
192 | |||
193 | static DEVICE_ATTR(port1, S_IWUGO | S_IRUGO, | ||
194 | get_port1_handler, set_port1_handler); | ||
195 | |||
196 | |||
197 | static int cypress_probe(struct usb_interface *interface, | ||
198 | const struct usb_device_id *id) | ||
199 | { | ||
200 | struct cypress *dev = NULL; | ||
201 | int retval = -ENOMEM; | ||
202 | |||
203 | /* allocate memory for our device state and initialize it */ | ||
204 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
205 | if (dev == NULL) { | ||
206 | dev_err(&dev->udev->dev, "Out of memory!\n"); | ||
207 | goto error; | ||
208 | } | ||
209 | |||
210 | dev->udev = usb_get_dev(interface_to_usbdev(interface)); | ||
211 | |||
212 | /* save our data pointer in this interface device */ | ||
213 | usb_set_intfdata(interface, dev); | ||
214 | |||
215 | /* create device attribute files */ | ||
216 | device_create_file(&interface->dev, &dev_attr_port0); | ||
217 | device_create_file(&interface->dev, &dev_attr_port1); | ||
218 | |||
219 | /* let the user know that the device is now attached */ | ||
220 | dev_info(&interface->dev, | ||
221 | "Cypress CY7C63xxx device now attached\n"); | ||
222 | |||
223 | retval = 0; | ||
224 | error: | ||
225 | return retval; | ||
226 | } | ||
227 | |||
228 | static void cypress_disconnect(struct usb_interface *interface) | ||
229 | { | ||
230 | struct cypress *dev; | ||
231 | |||
232 | dev = usb_get_intfdata(interface); | ||
233 | usb_set_intfdata(interface, NULL); | ||
234 | |||
235 | /* remove device attribute files */ | ||
236 | device_remove_file(&interface->dev, &dev_attr_port0); | ||
237 | device_remove_file(&interface->dev, &dev_attr_port1); | ||
238 | |||
239 | usb_put_dev(dev->udev); | ||
240 | |||
241 | dev_info(&interface->dev, | ||
242 | "Cypress CY7C63xxx device now disconnected\n"); | ||
243 | |||
244 | kfree(dev); | ||
245 | } | ||
246 | |||
247 | static struct usb_driver cypress_driver = { | ||
248 | .name = "cypress_cy7c63", | ||
249 | .probe = cypress_probe, | ||
250 | .disconnect = cypress_disconnect, | ||
251 | .id_table = cypress_table, | ||
252 | }; | ||
253 | |||
254 | static int __init cypress_init(void) | ||
255 | { | ||
256 | int result; | ||
257 | |||
258 | /* register this driver with the USB subsystem */ | ||
259 | result = usb_register(&cypress_driver); | ||
260 | if (result) { | ||
261 | err("Function usb_register failed! Error number: %d\n", result); | ||
262 | } | ||
263 | |||
264 | return result; | ||
265 | } | ||
266 | |||
267 | static void __exit cypress_exit(void) | ||
268 | { | ||
269 | /* deregister this driver with the USB subsystem */ | ||
270 | usb_deregister(&cypress_driver); | ||
271 | } | ||
272 | |||
273 | module_init(cypress_init); | ||
274 | module_exit(cypress_exit); | ||
275 | |||
276 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
277 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
278 | |||
279 | MODULE_LICENSE("GPL"); | ||