Commit | Line | Data |
---|---|---|
f01312d8 LP |
1 | /* |
2 | * Nano River Technologies viperboard driver | |
3 | * | |
4 | * This is the core driver for the viperboard. There are cell drivers | |
5 | * available for I2C, ADC and both GPIOs. SPI is not yet supported. | |
6 | * The drivers do not support all features the board exposes. See user | |
7 | * manual of the viperboard. | |
8 | * | |
9 | * (C) 2012 by Lemonage GmbH | |
10 | * Author: Lars Poeschel <poeschel@lemonage.de> | |
11 | * All rights reserved. | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or modify it | |
14 | * under the terms of the GNU General Public License as published by the | |
15 | * Free Software Foundation; either version 2 of the License, or (at your | |
16 | * option) any later version. | |
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 | ||
33 | static const struct usb_device_id vprbrd_table[] = { | |
34 | { USB_DEVICE(0x2058, 0x1005) }, /* Nano River Technologies */ | |
35 | { } /* Terminating entry */ | |
36 | }; | |
37 | ||
38 | MODULE_DEVICE_TABLE(usb, vprbrd_table); | |
39 | ||
40 | static struct mfd_cell vprbrd_devs[] = { | |
9d5b72de LP |
41 | { |
42 | .name = "viperboard-gpio", | |
43 | }, | |
174a13aa LP |
44 | { |
45 | .name = "viperboard-i2c", | |
46 | }, | |
ffd8a6e7 LP |
47 | { |
48 | .name = "viperboard-adc", | |
49 | }, | |
f01312d8 LP |
50 | }; |
51 | ||
52 | static 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 | unsigned char buf[1]; | |
60 | ||
61 | /* allocate memory for our device state and initialize it */ | |
62 | vb = kzalloc(sizeof(*vb), GFP_KERNEL); | |
63 | if (vb == NULL) { | |
64 | dev_err(&interface->dev, "Out of memory\n"); | |
65 | return -ENOMEM; | |
66 | } | |
67 | ||
68 | mutex_init(&vb->lock); | |
69 | ||
70 | vb->usb_dev = usb_get_dev(interface_to_usbdev(interface)); | |
71 | ||
72 | /* save our data pointer in this interface device */ | |
73 | usb_set_intfdata(interface, vb); | |
74 | dev_set_drvdata(&vb->pdev.dev, vb); | |
75 | ||
76 | /* get version information, major first, minor then */ | |
77 | pipe = usb_rcvctrlpipe(vb->usb_dev, 0); | |
78 | ret = usb_control_msg(vb->usb_dev, pipe, VPRBRD_USB_REQUEST_MAJOR, | |
79 | VPRBRD_USB_TYPE_IN, 0x0000, 0x0000, buf, 1, | |
80 | VPRBRD_USB_TIMEOUT_MS); | |
81 | if (ret == 1) | |
82 | version = buf[0]; | |
83 | ||
84 | ret = usb_control_msg(vb->usb_dev, pipe, VPRBRD_USB_REQUEST_MINOR, | |
85 | VPRBRD_USB_TYPE_IN, 0x0000, 0x0000, buf, 1, | |
86 | VPRBRD_USB_TIMEOUT_MS); | |
87 | if (ret == 1) { | |
88 | version <<= 8; | |
89 | version = version | buf[0]; | |
90 | } | |
91 | ||
92 | dev_info(&interface->dev, | |
93 | "version %x.%02x found at bus %03d address %03d\n", | |
94 | version >> 8, version & 0xff, | |
95 | vb->usb_dev->bus->busnum, vb->usb_dev->devnum); | |
96 | ||
97 | ret = mfd_add_devices(&interface->dev, -1, vprbrd_devs, | |
98 | ARRAY_SIZE(vprbrd_devs), NULL, 0, NULL); | |
99 | if (ret != 0) { | |
100 | dev_err(&interface->dev, "Failed to add mfd devices to core."); | |
101 | goto error; | |
102 | } | |
103 | ||
104 | return 0; | |
105 | ||
106 | error: | |
107 | if (vb) { | |
108 | usb_put_dev(vb->usb_dev); | |
109 | kfree(vb); | |
110 | } | |
111 | ||
112 | return ret; | |
113 | } | |
114 | ||
115 | static void vprbrd_disconnect(struct usb_interface *interface) | |
116 | { | |
117 | struct vprbrd *vb = usb_get_intfdata(interface); | |
118 | ||
119 | mfd_remove_devices(&interface->dev); | |
120 | usb_set_intfdata(interface, NULL); | |
121 | usb_put_dev(vb->usb_dev); | |
122 | kfree(vb); | |
123 | ||
124 | dev_dbg(&interface->dev, "disconnected\n"); | |
125 | } | |
126 | ||
127 | static struct usb_driver vprbrd_driver = { | |
128 | .name = "viperboard", | |
129 | .probe = vprbrd_probe, | |
130 | .disconnect = vprbrd_disconnect, | |
131 | .id_table = vprbrd_table, | |
132 | }; | |
133 | ||
134 | module_usb_driver(vprbrd_driver); | |
135 | ||
136 | MODULE_DESCRIPTION("Nano River Technologies viperboard mfd core driver"); | |
137 | MODULE_AUTHOR("Lars Poeschel <poeschel@lemonage.de>"); | |
138 | MODULE_LICENSE("GPL"); |