13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
23 #include <linux/i2c.h>
27 #define CMD_GET_FUNC 1
28 #define CMD_SET_DELAY 2
29 #define CMD_GET_STATUS 3
32 #define CMD_I2C_IO_BEGIN (1<<0)
33 #define CMD_I2C_IO_END (1<<1)
38 static unsigned short delay = 10;
41 "(default is 10us for 100kHz max)");
52 #define STATUS_ADDRESS_ACK 1
53 #define STATUS_ADDRESS_NAK 2
61 dev_dbg(&adapter->
dev,
"master xfer %d messages:\n", num);
63 for (i = 0 ; i < num ; i++) {
75 " %d: %s (flags %d) %d bytes to 0x%02x\n",
82 if (usb_read(adapter, cmd,
86 "failure reading data\n");
91 if (usb_write(adapter, cmd,
95 "failure writing data\n");
102 dev_err(&adapter->
dev,
"failure reading status\n");
106 dev_dbg(&adapter->
dev,
" status = %d\n", status);
119 if (usb_read(adapter,
CMD_GET_FUNC, 0, 0, &func,
sizeof(func)) !=
121 dev_err(&adapter->
dev,
"failure reading functionality\n");
130 .master_xfer = usb_xfer,
131 .functionality = usb_func,
144 { USB_DEVICE(0x0403, 0xc631) },
145 { USB_DEVICE(0x1c40, 0x0534) },
146 { USB_DEVICE(0x1964, 0x0001) },
170 static int usb_write(
struct i2c_adapter *adapter,
int cmd,
171 int value,
int index,
void *data,
int len)
194 dev_dbg(&interface->dev,
"probing usb device\n");
199 dev_err(&interface->dev,
"Out of memory\n");
207 usb_set_intfdata(interface, dev);
211 "version %x.%02x found at bus %03d address %03d\n",
212 version >> 8, version & 0xff,
218 dev->
adapter.algo = &usb_algorithm;
221 "i2c-tiny-usb at bus %03d device %03d",
226 "failure setting delay to %dus\n",
delay);
243 i2c_tiny_usb_free(dev);
248 static void i2c_tiny_usb_disconnect(
struct usb_interface *interface)
253 usb_set_intfdata(interface,
NULL);
254 i2c_tiny_usb_free(dev);
256 dev_dbg(&interface->dev,
"disconnected\n");
259 static struct usb_driver i2c_tiny_usb_driver = {
260 .name =
"i2c-tiny-usb",
261 .probe = i2c_tiny_usb_probe,
262 .disconnect = i2c_tiny_usb_disconnect,
263 .id_table = i2c_tiny_usb_table,