Ak Modul-bus Driver



Ak Modul-bus DriverAk modul-bus driver licence

In case you would like to purchase the J-Link EDU from Europe, please contact the appropriate distributor in your country or the online shop at AK-Modul-Bus. For purchase from countries outside Europe, J-Link EDU is sold via distribution or at the Digi-Key website. Customers, please check out our website shop-us.segger.com. 2-Way IP/RS-232 Driver: -Select Manufacturer- ADA Advantage AK-Modul-Bus AMX Anthem Electronics Inc. Apart APEX Apple Inc. Aprilaire Aquameta Aquavision Arcam Assa Abloy Asterisk Atlona Audio Authority AudioControl Autonomic Controls AutoPatch Avocation Systems B&K B&W Bachmann Bang&Olufsen Beale Xpress Belkin Benq Biamp BlueStream Bose BSS.

Ak Modul-bus Driver Portal

1// SPDX-License-Identifier: GPL-2.0
2/*
3* cypress_cy7c63.c
4*
5* Copyright (c) 2006-2007 Oliver Bock (bock@tfh-berlin.de)
6*
7* This driver is based on the Cypress USB Driver by Marcus Maul
8* (cyport) and the 2.0 version of Greg Kroah-Hartman's
9* USB Skeleton driver.
10*
11* This is a generic driver for the Cypress CY7C63xxx family.
12* For the time being it enables you to read from and write to
13* the single I/O ports of the device.
14*
15* Supported vendors: AK Modul-Bus Computer GmbH
16* (Firmware 'Port-Chip')
17*
18* Supported devices: CY7C63001A-PC
19* CY7C63001C-PXC
20* CY7C63001C-SXC
21*
22* Supported functions: Read/Write Ports
23*
24*
25* For up-to-date information please visit:
26* http://www.obock.de/kernel/cypress
27*/
28
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/slab.h>
32#include <linux/usb.h>
33
34#define DRIVER_AUTHOR 'Oliver Bock (bock@tfh-berlin.de)'
35#define DRIVER_DESC 'Cypress CY7C63xxx USB driver'
36
37#define CYPRESS_VENDOR_ID 0xa2c
38#define CYPRESS_PRODUCT_ID 0x8
39
40#define CYPRESS_READ_PORT 0x4
41#define CYPRESS_WRITE_PORT 0x5
42
43#define CYPRESS_READ_RAM 0x2
44#define CYPRESS_WRITE_RAM 0x3
45#define CYPRESS_READ_ROM 0x1
46
47#define CYPRESS_READ_PORT_ID0 0
48#define CYPRESS_WRITE_PORT_ID0 0
49#define CYPRESS_READ_PORT_ID1 0x2
50#define CYPRESS_WRITE_PORT_ID1 1
51
52#define CYPRESS_MAX_REQSIZE 8
53
54
55/* table of devices that work with this driver */
56staticconststructusb_device_idcypress_table[] = {
57 { USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) },
58 { }
59};
60MODULE_DEVICE_TABLE(usb, cypress_table);
61
62/* structure to hold all of our device specific stuff */
63structcypress {
64structusb_device * udev;
65unsignedcharport[2];
66};
67
68/* used to send usb control messages to device */
69staticintvendor_command(structcypress *dev, unsignedcharrequest,
70unsignedcharaddress, unsignedchardata)
71{
72intretval = 0;
73unsignedintpipe;
74unsignedchar *iobuf;
75
76/* allocate some memory for the i/o buffer*/
77iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL);
78if (!iobuf) {
79retval = -ENOMEM;
80gotoerror;
81 }
82
83dev_dbg(&dev->udev->dev, 'Sending usb_control_msg (data: %d)n', data);
84
85/* prepare usb control message and send it upstream */
86pipe = usb_rcvctrlpipe(dev->udev, 0);
87retval = usb_control_msg(dev->udev, pipe, request,
88USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
89address, data, iobuf, CYPRESS_MAX_REQSIZE,
90USB_CTRL_GET_TIMEOUT);
91
92/* store returned data (more READs to be added) */
93switch (request) {
94caseCYPRESS_READ_PORT:
95if (address CYPRESS_READ_PORT_ID0) {
96dev->port[0] = iobuf[1];
97dev_dbg(&dev->udev->dev,
98'READ_PORT0 returned: %dn',
99dev->port[0]);
100 }
101elseif (address CYPRESS_READ_PORT_ID1) {
102dev->port[1] = iobuf[1];
103dev_dbg(&dev->udev->dev,
104'READ_PORT1 returned: %dn',
105dev->port[1]);
106 }
107break;
108 }
109
110kfree(iobuf);
111error:
112returnretval;
113}
114
115/* write port value */
116staticssize_twrite_port(structdevice *dev, structdevice_attribute *attr,
117constchar *buf, size_tcount,
118intport_num, intwrite_id)
119{
120intvalue = -1;
121intresult = 0;
122
123structusb_interface *intf = to_usb_interface(dev);
124structcypress *cyp = usb_get_intfdata(intf);
125
126dev_dbg(&cyp->udev->dev, 'WRITE_PORT%d calledn', port_num);
127
128/* validate input data */
129if (sscanf(buf, '%d', &value) < 1) {
130result = -EINVAL;
131gotoerror;
132 }
133if (value < 0 || value > 255) {
134result = -EINVAL;
135gotoerror;
136 }
137
138result = vendor_command(cyp, CYPRESS_WRITE_PORT, write_id,
139 (unsignedchar)value);
140
141dev_dbg(&cyp->udev->dev, 'Result of vendor_command: %dnn', result);
142error:
143returnresult < 0 ? result : count;
144}
145
146/* attribute callback handler (write) */
147staticssize_tport0_store(structdevice *dev,
148structdevice_attribute *attr,
149constchar *buf, size_tcount)
150{
151returnwrite_port(dev, attr, buf, count, 0, CYPRESS_WRITE_PORT_ID0);
152}
153
154/* attribute callback handler (write) */
155staticssize_tport1_store(structdevice *dev,
156structdevice_attribute *attr,
157constchar *buf, size_tcount)
158{
159returnwrite_port(dev, attr, buf, count, 1, CYPRESS_WRITE_PORT_ID1);
160}
161
162/* read port value */
163staticssize_tread_port(structdevice *dev, structdevice_attribute *attr,
164char *buf, intport_num, intread_id)
165{
166intresult = 0;
167
168structusb_interface *intf = to_usb_interface(dev);
169structcypress *cyp = usb_get_intfdata(intf);
170
171dev_dbg(&cyp->udev->dev, 'READ_PORT%d calledn', port_num);
172
173result = vendor_command(cyp, CYPRESS_READ_PORT, read_id, 0);
174
175dev_dbg(&cyp->udev->dev, 'Result of vendor_command: %dnn', result);
176
177returnsprintf(buf, '%d', cyp->port[port_num]);
178}
179
180/* attribute callback handler (read) */
181staticssize_tport0_show(structdevice *dev,
182structdevice_attribute *attr, char *buf)
183{
184returnread_port(dev, attr, buf, 0, CYPRESS_READ_PORT_ID0);
185}
186
187/* attribute callback handler (read) */
188staticssize_tport1_show(structdevice *dev,
189structdevice_attribute *attr, char *buf)
190{
191returnread_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1);
192}
193
194staticDEVICE_ATTR_RW(port0);
195
196staticDEVICE_ATTR_RW(port1);
197
198
199staticintcypress_probe(structusb_interface *interface,
200conststructusb_device_id *id)
201{
202structcypress *dev = NULL;
203intretval = -ENOMEM;
204
205/* allocate memory for our device state and initialize it */
206dev = kzalloc(sizeof(*dev), GFP_KERNEL);
207if (!dev)
208gotoerror_mem;
209
210dev->udev = usb_get_dev(interface_to_usbdev(interface));
211
212/* save our data pointer in this interface device */
213usb_set_intfdata(interface, dev);
214
215/* create device attribute files */
216retval = device_create_file(&interface->dev, &dev_attr_port0);
217if (retval)
218gotoerror;
219retval = device_create_file(&interface->dev, &dev_attr_port1);
220if (retval)
221gotoerror;
222
223/* let the user know that the device is now attached */
224dev_info(&interface->dev,
225'Cypress CY7C63xxx device now attachedn');
226return0;
227
228error:
229device_remove_file(&interface->dev, &dev_attr_port0);
230device_remove_file(&interface->dev, &dev_attr_port1);
231usb_set_intfdata(interface, NULL);
232usb_put_dev(dev->udev);
233kfree(dev);
234
235error_mem:
236returnretval;
237}
238
239staticvoidcypress_disconnect(structusb_interface *interface)
240{
241structcypress *dev;
242
243dev = usb_get_intfdata(interface);
244
245/* remove device attribute files */
246device_remove_file(&interface->dev, &dev_attr_port0);
247device_remove_file(&interface->dev, &dev_attr_port1);
248/* the intfdata can be set to NULL only after the
249 * device files have been removed */
250usb_set_intfdata(interface, NULL);
251
252usb_put_dev(dev->udev);
253
254dev_info(&interface->dev,
255'Cypress CY7C63xxx device now disconnectedn');
256
257kfree(dev);
258}
259
260staticstructusb_drivercypress_driver = {
261 .name = 'cypress_cy7c63',
262 .probe = cypress_probe,
263 .disconnect = cypress_disconnect,
264 .id_table = cypress_table,
265};
266
267module_usb_driver(cypress_driver);
268
269MODULE_AUTHOR(DRIVER_AUTHOR);
270MODULE_DESCRIPTION(DRIVER_DESC);
271
272MODULE_LICENSE('GPL');
273