Lines Matching +full:usb +full:- +full:version
1 // SPDX-License-Identifier: GPL-2.0-only
3 * driver for the i2c-tiny-usb adapter - 1.0
6 * Copyright (C) 2006-2007 Till Harbaum (Till@Harbaum.org)
15 /* include interfaces to usb layer */
16 #include <linux/usb.h>
21 /* commands via USB, must match command ids in the firmware */
31 /* i2c bit delay, default is 10us -> 100kHz max
45 /* ----- begin of i2c layer ---------------------------------------------- */
59 return -ENOMEM; in usb_xfer()
67 if (i == num-1) in usb_xfer()
72 dev_dbg(&adapter->dev, in usb_xfer()
74 i, pmsg->flags & I2C_M_RD ? "read" : "write", in usb_xfer()
75 pmsg->flags, pmsg->len, pmsg->addr); in usb_xfer()
78 if (pmsg->flags & I2C_M_RD) { in usb_xfer()
81 pmsg->flags, pmsg->addr, in usb_xfer()
82 pmsg->buf, pmsg->len) != pmsg->len) { in usb_xfer()
83 dev_err(&adapter->dev, in usb_xfer()
85 ret = -EIO; in usb_xfer()
91 pmsg->flags, pmsg->addr, in usb_xfer()
92 pmsg->buf, pmsg->len) != pmsg->len) { in usb_xfer()
93 dev_err(&adapter->dev, in usb_xfer()
95 ret = -EIO; in usb_xfer()
102 dev_err(&adapter->dev, "failure reading status\n"); in usb_xfer()
103 ret = -EIO; in usb_xfer()
107 dev_dbg(&adapter->dev, " status = %d\n", *pstatus); in usb_xfer()
109 ret = -ENXIO; in usb_xfer()
130 dev_err(&adapter->dev, "failure reading functionality\n"); in usb_func()
147 /* ----- end of i2c layer ------------------------------------------------ */
149 /* ----- begin of usb layer ---------------------------------------------- */
152 * Initially the usb i2c interface uses a vid/pid pair donated by
162 MODULE_DEVICE_TABLE(usb, i2c_tiny_usb_table);
166 struct usb_device *usb_dev; /* the usb device for this device */
174 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data; in usb_read()
179 return -ENOMEM; in usb_read()
182 ret = usb_control_msg(dev->usb_dev, usb_rcvctrlpipe(dev->usb_dev, 0), in usb_read()
194 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data; in usb_write()
199 return -ENOMEM; in usb_write()
202 ret = usb_control_msg(dev->usb_dev, usb_sndctrlpipe(dev->usb_dev, 0), in usb_write()
212 usb_put_dev(dev->usb_dev); in i2c_tiny_usb_free()
220 int retval = -ENOMEM; in i2c_tiny_usb_probe()
221 u16 version; in i2c_tiny_usb_probe() local
223 if (interface->intf_assoc && in i2c_tiny_usb_probe()
224 interface->intf_assoc->bFunctionClass != USB_CLASS_VENDOR_SPEC) in i2c_tiny_usb_probe()
225 return -ENODEV; in i2c_tiny_usb_probe()
227 dev_dbg(&interface->dev, "probing usb device\n"); in i2c_tiny_usb_probe()
234 dev->usb_dev = usb_get_dev(interface_to_usbdev(interface)); in i2c_tiny_usb_probe()
235 dev->interface = interface; in i2c_tiny_usb_probe()
240 version = le16_to_cpu(dev->usb_dev->descriptor.bcdDevice); in i2c_tiny_usb_probe()
241 dev_info(&interface->dev, in i2c_tiny_usb_probe()
242 "version %x.%02x found at bus %03d address %03d\n", in i2c_tiny_usb_probe()
243 version >> 8, version & 0xff, in i2c_tiny_usb_probe()
244 dev->usb_dev->bus->busnum, dev->usb_dev->devnum); in i2c_tiny_usb_probe()
247 dev->adapter.owner = THIS_MODULE; in i2c_tiny_usb_probe()
248 dev->adapter.class = I2C_CLASS_HWMON; in i2c_tiny_usb_probe()
249 dev->adapter.algo = &usb_algorithm; in i2c_tiny_usb_probe()
250 dev->adapter.algo_data = dev; in i2c_tiny_usb_probe()
251 snprintf(dev->adapter.name, sizeof(dev->adapter.name), in i2c_tiny_usb_probe()
252 "i2c-tiny-usb at bus %03d device %03d", in i2c_tiny_usb_probe()
253 dev->usb_dev->bus->busnum, dev->usb_dev->devnum); in i2c_tiny_usb_probe()
255 if (usb_write(&dev->adapter, CMD_SET_DELAY, delay, 0, NULL, 0) != 0) { in i2c_tiny_usb_probe()
256 dev_err(&dev->adapter.dev, in i2c_tiny_usb_probe()
258 retval = -EIO; in i2c_tiny_usb_probe()
262 dev->adapter.dev.parent = &dev->interface->dev; in i2c_tiny_usb_probe()
265 i2c_add_adapter(&dev->adapter); in i2c_tiny_usb_probe()
268 dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n"); in i2c_tiny_usb_probe()
283 i2c_del_adapter(&dev->adapter); in i2c_tiny_usb_disconnect()
287 dev_dbg(&interface->dev, "disconnected\n"); in i2c_tiny_usb_disconnect()
291 .name = "i2c-tiny-usb",
299 /* ----- end of usb layer ------------------------------------------------ */
302 MODULE_DESCRIPTION("i2c-tiny-usb driver v1.0");