1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/types.h>
25#include <linux/mutex.h>
26
27#include <linux/mfd/core.h>
28#include <linux/mfd/viperboard.h>
29
30#include <linux/usb.h>
31
32
33static const struct usb_device_id vprbrd_table[] = {
34 { USB_DEVICE(0x2058, 0x1005) },
35 { }
36};
37
38MODULE_DEVICE_TABLE(usb, vprbrd_table);
39
40static const struct mfd_cell vprbrd_devs[] = {
41 {
42 .name = "viperboard-gpio",
43 },
44 {
45 .name = "viperboard-i2c",
46 },
47 {
48 .name = "viperboard-adc",
49 },
50};
51
52static int vprbrd_probe(struct usb_interface *interface,
53 const struct usb_device_id *id)
54{
55 struct vprbrd *vb;
56
57 u16 version = 0;
58 int pipe, ret;
59
60
61 vb = kzalloc(sizeof(*vb), GFP_KERNEL);
62 if (!vb)
63 return -ENOMEM;
64
65 mutex_init(&vb->lock);
66
67 vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));
68
69
70 usb_set_intfdata(interface, vb);
71 dev_set_drvdata(&vb->pdev.dev, vb);
72
73
74 pipe = usb_rcvctrlpipe(vb->usb_dev, 0);
75 ret = usb_control_msg(vb->usb_dev, pipe, VPRBRD_USB_REQUEST_MAJOR,
76 VPRBRD_USB_TYPE_IN, 0x0000, 0x0000, vb->buf, 1,
77 VPRBRD_USB_TIMEOUT_MS);
78 if (ret == 1)
79 version = vb->buf[0];
80
81 ret = usb_control_msg(vb->usb_dev, pipe, VPRBRD_USB_REQUEST_MINOR,
82 VPRBRD_USB_TYPE_IN, 0x0000, 0x0000, vb->buf, 1,
83 VPRBRD_USB_TIMEOUT_MS);
84 if (ret == 1) {
85 version <<= 8;
86 version = version | vb->buf[0];
87 }
88
89 dev_info(&interface->dev,
90 "version %x.%02x found at bus %03d address %03d\n",
91 version >> 8, version & 0xff,
92 vb->usb_dev->bus->busnum, vb->usb_dev->devnum);
93
94 ret = mfd_add_hotplug_devices(&interface->dev, vprbrd_devs,
95 ARRAY_SIZE(vprbrd_devs));
96 if (ret != 0) {
97 dev_err(&interface->dev, "Failed to add mfd devices to core.");
98 goto error;
99 }
100
101 return 0;
102
103error:
104 if (vb) {
105 usb_put_dev(vb->usb_dev);
106 kfree(vb);
107 }
108
109 return ret;
110}
111
112static void vprbrd_disconnect(struct usb_interface *interface)
113{
114 struct vprbrd *vb = usb_get_intfdata(interface);
115
116 mfd_remove_devices(&interface->dev);
117 usb_set_intfdata(interface, NULL);
118 usb_put_dev(vb->usb_dev);
119 kfree(vb);
120
121 dev_dbg(&interface->dev, "disconnected\n");
122}
123
124static struct usb_driver vprbrd_driver = {
125 .name = "viperboard",
126 .probe = vprbrd_probe,
127 .disconnect = vprbrd_disconnect,
128 .id_table = vprbrd_table,
129};
130
131module_usb_driver(vprbrd_driver);
132
133MODULE_DESCRIPTION("Nano River Technologies viperboard mfd core driver");
134MODULE_AUTHOR("Lars Poeschel <poeschel@lemonage.de>");
135MODULE_LICENSE("GPL");
136