13 #include <linux/kernel.h>
14 #include <linux/errno.h>
16 #include <linux/slab.h>
17 #include <linux/module.h>
18 #include <linux/string.h>
23 #define DRIVER_DESC "USB 7 Segment Driver"
25 #define VENDOR_ID 0x0fc5
26 #define PRODUCT_ID 0x1227
37 static char *display_textmodes[] = {
"raw",
"hex",
"ascii",
NULL};
62 if (count > 0 && buf[count-1] ==
'\n')
68 static void update_display_powered(
struct usb_sevsegdev *mydev)
73 rc = usb_autopm_get_interface(mydev->
intf);
83 usb_sndctrlpipe(mydev->
udev, 0),
87 (0x00 * 0x100) + (mydev->
powered ? 1 : 0),
92 dev_dbg(&mydev->
udev->dev,
"power retval = %d\n", rc);
95 usb_autopm_put_interface(mydev->
intf);
108 usb_sndctrlpipe(mydev->
udev, 0),
118 dev_dbg(&mydev->
udev->dev,
"mode retval = %d\n", rc);
131 buffer = kzalloc(
MAXLEN, mf);
142 usb_sndctrlpipe(mydev->
udev, 0),
152 dev_dbg(&mydev->
udev->dev,
"write retval = %d\n", rc);
157 for (i = 0; i <
sizeof(mydev->
decimals); i++)
158 decimals |= mydev->
decimals[i] << i;
161 usb_sndctrlpipe(mydev->
udev, 0),
165 (0 * 0x100) + decimals,
171 dev_dbg(&mydev->
udev->dev,
"decimal retval = %d\n", rc);
174 #define MYDEV_ATTR_SIMPLE_UNSIGNED(name, update_fcn) \
175 static ssize_t show_attr_##name(struct device *dev, \
176 struct device_attribute *attr, char *buf) \
178 struct usb_interface *intf = to_usb_interface(dev); \
179 struct usb_sevsegdev *mydev = usb_get_intfdata(intf); \
181 return sprintf(buf, "%u\n", mydev->name); \
184 static ssize_t set_attr_##name(struct device *dev, \
185 struct device_attribute *attr, const char *buf, size_t count) \
187 struct usb_interface *intf = to_usb_interface(dev); \
188 struct usb_sevsegdev *mydev = usb_get_intfdata(intf); \
190 mydev->name = simple_strtoul(buf, NULL, 10); \
195 static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show_attr_##name, set_attr_##name);
213 if (end >
sizeof(mydev->
text))
236 for (i = 0; i <
sizeof(mydev->
decimals); i++) {
237 pos =
sizeof(mydev->
decimals) - 1 - i;
246 buf[
sizeof(mydev->
decimals)] =
'\n';
261 for (i = 0; i <
end; i++)
262 if (buf[i] !=
'0' && buf[i] !=
'1')
266 for (i = 0; i <
end; i++)
286 for (i = 0; display_textmodes[
i]; i++) {
289 strcat(buf, display_textmodes[i]);
293 strcat(buf, display_textmodes[i]);
310 for (i = 0; display_textmodes[
i]; i++) {
329 &dev_attr_powered.attr,
331 &dev_attr_textmode.attr,
332 &dev_attr_decimals.attr,
333 &dev_attr_mode_msb.attr,
334 &dev_attr_mode_lsb.attr,
345 struct usb_device *
udev = interface_to_usbdev(interface);
351 dev_err(&interface->dev,
"Out of memory\n");
357 usb_set_intfdata(interface, mydev);
372 dev_info(&interface->dev,
"USB 7 Segment device now attached\n");
376 usb_set_intfdata(interface, NULL);
383 static void sevseg_disconnect(
struct usb_interface *interface)
387 mydev = usb_get_intfdata(interface);
389 usb_set_intfdata(interface, NULL);
392 dev_info(&interface->dev,
"USB 7 Segment now disconnected\n");
399 mydev = usb_get_intfdata(intf);
409 mydev = usb_get_intfdata(intf);
411 update_display_mode(mydev);
412 update_display_visual(mydev,
GFP_NOIO);
421 mydev = usb_get_intfdata(intf);
423 update_display_mode(mydev);
424 update_display_visual(mydev,
GFP_NOIO);
429 static struct usb_driver sevseg_driver = {
431 .probe = sevseg_probe,
432 .disconnect = sevseg_disconnect,
433 .suspend = sevseg_suspend,
434 .resume = sevseg_resume,
435 .reset_resume = sevseg_reset_resume,
436 .id_table = id_table,
437 .supports_autosuspend = 1,