/* table of devices that work with this driver */ staticconststruct 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; unsignedchar port[2];
};
/* used to send usb control messages to device */ staticint vendor_command(struct cypress *dev, unsignedchar request, unsignedchar address, unsignedchar data)
{ int retval = 0; unsignedint pipe; unsignedchar *iobuf;
/* allocate some memory for the i/o buffer*/
iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL); if (!iobuf) {
retval = -ENOMEM; goto error;
}
/* 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); /* we must not process garbage */ if (retval < 2) goto err_buf;
/* 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]);
} elseif (address == CYPRESS_READ_PORT_ID1) {
dev->port[1] = iobuf[1];
dev_dbg(&dev->udev->dev, "READ_PORT1 returned: %d\n",
dev->port[1]);
} break;
}
err_buf:
kfree(iobuf);
error: return retval;
}
/* write port value */ static ssize_t write_port(struct device *dev, struct device_attribute *attr, constchar *buf, size_t count, int port_num, int write_id)
{ int value = -1; int result = 0;
/* 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;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.