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 */ |
| 56 | staticconststructusb_device_idcypress_table[] = { |
| 57 | { USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) }, |
| 58 | { } |
| 59 | }; |
| 60 | MODULE_DEVICE_TABLE(usb, cypress_table); |
| 61 | |
| 62 | /* structure to hold all of our device specific stuff */ |
| 63 | structcypress { |
| 64 | structusb_device * udev; |
| 65 | unsignedcharport[2]; |
| 66 | }; |
| 67 | |
| 68 | /* used to send usb control messages to device */ |
| 69 | staticintvendor_command(structcypress *dev, unsignedcharrequest, |
| 70 | unsignedcharaddress, unsignedchardata) |
| 71 | { |
| 72 | intretval = 0; |
| 73 | unsignedintpipe; |
| 74 | unsignedchar *iobuf; |
| 75 | |
| 76 | /* allocate some memory for the i/o buffer*/ |
| 77 | iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL); |
| 78 | if (!iobuf) { |
| 79 | retval = -ENOMEM; |
| 80 | gotoerror; |
| 81 | } |
| 82 | |
| 83 | dev_dbg(&dev->udev->dev, 'Sending usb_control_msg (data: %d)n', data); |
| 84 | |
| 85 | /* prepare usb control message and send it upstream */ |
| 86 | pipe = usb_rcvctrlpipe(dev->udev, 0); |
| 87 | retval = usb_control_msg(dev->udev, pipe, request, |
| 88 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 89 | address, data, iobuf, CYPRESS_MAX_REQSIZE, |
| 90 | USB_CTRL_GET_TIMEOUT); |
| 91 | |
| 92 | /* store returned data (more READs to be added) */ |
| 93 | switch (request) { |
| 94 | caseCYPRESS_READ_PORT: |
| 95 | if (address CYPRESS_READ_PORT_ID0) { |
| 96 | dev->port[0] = iobuf[1]; |
| 97 | dev_dbg(&dev->udev->dev, |
| 98 | 'READ_PORT0 returned: %dn', |
| 99 | dev->port[0]); |
| 100 | } |
| 101 | elseif (address CYPRESS_READ_PORT_ID1) { |
| 102 | dev->port[1] = iobuf[1]; |
| 103 | dev_dbg(&dev->udev->dev, |
| 104 | 'READ_PORT1 returned: %dn', |
| 105 | dev->port[1]); |
| 106 | } |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | kfree(iobuf); |
| 111 | error: |
| 112 | returnretval; |
| 113 | } |
| 114 | |
| 115 | /* write port value */ |
| 116 | staticssize_twrite_port(structdevice *dev, structdevice_attribute *attr, |
| 117 | constchar *buf, size_tcount, |
| 118 | intport_num, intwrite_id) |
| 119 | { |
| 120 | intvalue = -1; |
| 121 | intresult = 0; |
| 122 | |
| 123 | structusb_interface *intf = to_usb_interface(dev); |
| 124 | structcypress *cyp = usb_get_intfdata(intf); |
| 125 | |
| 126 | dev_dbg(&cyp->udev->dev, 'WRITE_PORT%d calledn', port_num); |
| 127 | |
| 128 | /* validate input data */ |
| 129 | if (sscanf(buf, '%d', &value) < 1) { |
| 130 | result = -EINVAL; |
| 131 | gotoerror; |
| 132 | } |
| 133 | if (value < 0 || value > 255) { |
| 134 | result = -EINVAL; |
| 135 | gotoerror; |
| 136 | } |
| 137 | |
| 138 | result = vendor_command(cyp, CYPRESS_WRITE_PORT, write_id, |
| 139 | (unsignedchar)value); |
| 140 | |
| 141 | dev_dbg(&cyp->udev->dev, 'Result of vendor_command: %dnn', result); |
| 142 | error: |
| 143 | returnresult < 0 ? result : count; |
| 144 | } |
| 145 | |
| 146 | /* attribute callback handler (write) */ |
| 147 | staticssize_tport0_store(structdevice *dev, |
| 148 | structdevice_attribute *attr, |
| 149 | constchar *buf, size_tcount) |
| 150 | { |
| 151 | returnwrite_port(dev, attr, buf, count, 0, CYPRESS_WRITE_PORT_ID0); |
| 152 | } |
| 153 | |
| 154 | /* attribute callback handler (write) */ |
| 155 | staticssize_tport1_store(structdevice *dev, |
| 156 | structdevice_attribute *attr, |
| 157 | constchar *buf, size_tcount) |
| 158 | { |
| 159 | returnwrite_port(dev, attr, buf, count, 1, CYPRESS_WRITE_PORT_ID1); |
| 160 | } |
| 161 | |
| 162 | /* read port value */ |
| 163 | staticssize_tread_port(structdevice *dev, structdevice_attribute *attr, |
| 164 | char *buf, intport_num, intread_id) |
| 165 | { |
| 166 | intresult = 0; |
| 167 | |
| 168 | structusb_interface *intf = to_usb_interface(dev); |
| 169 | structcypress *cyp = usb_get_intfdata(intf); |
| 170 | |
| 171 | dev_dbg(&cyp->udev->dev, 'READ_PORT%d calledn', port_num); |
| 172 | |
| 173 | result = vendor_command(cyp, CYPRESS_READ_PORT, read_id, 0); |
| 174 | |
| 175 | dev_dbg(&cyp->udev->dev, 'Result of vendor_command: %dnn', result); |
| 176 | |
| 177 | returnsprintf(buf, '%d', cyp->port[port_num]); |
| 178 | } |
| 179 | |
| 180 | /* attribute callback handler (read) */ |
| 181 | staticssize_tport0_show(structdevice *dev, |
| 182 | structdevice_attribute *attr, char *buf) |
| 183 | { |
| 184 | returnread_port(dev, attr, buf, 0, CYPRESS_READ_PORT_ID0); |
| 185 | } |
| 186 | |
| 187 | /* attribute callback handler (read) */ |
| 188 | staticssize_tport1_show(structdevice *dev, |
| 189 | structdevice_attribute *attr, char *buf) |
| 190 | { |
| 191 | returnread_port(dev, attr, buf, 1, CYPRESS_READ_PORT_ID1); |
| 192 | } |
| 193 | |
| 194 | staticDEVICE_ATTR_RW(port0); |
| 195 | |
| 196 | staticDEVICE_ATTR_RW(port1); |
| 197 | |
| 198 | |
| 199 | staticintcypress_probe(structusb_interface *interface, |
| 200 | conststructusb_device_id *id) |
| 201 | { |
| 202 | structcypress *dev = NULL; |
| 203 | intretval = -ENOMEM; |
| 204 | |
| 205 | /* allocate memory for our device state and initialize it */ |
| 206 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 207 | if (!dev) |
| 208 | gotoerror_mem; |
| 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 | retval = device_create_file(&interface->dev, &dev_attr_port0); |
| 217 | if (retval) |
| 218 | gotoerror; |
| 219 | retval = device_create_file(&interface->dev, &dev_attr_port1); |
| 220 | if (retval) |
| 221 | gotoerror; |
| 222 | |
| 223 | /* let the user know that the device is now attached */ |
| 224 | dev_info(&interface->dev, |
| 225 | 'Cypress CY7C63xxx device now attachedn'); |
| 226 | return0; |
| 227 | |
| 228 | error: |
| 229 | device_remove_file(&interface->dev, &dev_attr_port0); |
| 230 | device_remove_file(&interface->dev, &dev_attr_port1); |
| 231 | usb_set_intfdata(interface, NULL); |
| 232 | usb_put_dev(dev->udev); |
| 233 | kfree(dev); |
| 234 | |
| 235 | error_mem: |
| 236 | returnretval; |
| 237 | } |
| 238 | |
| 239 | staticvoidcypress_disconnect(structusb_interface *interface) |
| 240 | { |
| 241 | structcypress *dev; |
| 242 | |
| 243 | dev = usb_get_intfdata(interface); |
| 244 | |
| 245 | /* remove device attribute files */ |
| 246 | device_remove_file(&interface->dev, &dev_attr_port0); |
| 247 | device_remove_file(&interface->dev, &dev_attr_port1); |
| 248 | /* the intfdata can be set to NULL only after the |
| 249 | * device files have been removed */ |
| 250 | usb_set_intfdata(interface, NULL); |
| 251 | |
| 252 | usb_put_dev(dev->udev); |
| 253 | |
| 254 | dev_info(&interface->dev, |
| 255 | 'Cypress CY7C63xxx device now disconnectedn'); |
| 256 | |
| 257 | kfree(dev); |
| 258 | } |
| 259 | |
| 260 | staticstructusb_drivercypress_driver = { |
| 261 | .name = 'cypress_cy7c63', |
| 262 | .probe = cypress_probe, |
| 263 | .disconnect = cypress_disconnect, |
| 264 | .id_table = cypress_table, |
| 265 | }; |
| 266 | |
| 267 | module_usb_driver(cypress_driver); |
| 268 | |
| 269 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 270 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 271 | |
| 272 | MODULE_LICENSE('GPL'); |
| 273 |


