ARC: [plat-eznps] spinlock aware for MTM
[linux/fpc-iii.git] / drivers / usb / misc / usb251xb.c
blob91f66d68bcb7b55bd000e18ad551d8b6bc27ff7c
1 /*
2 * Driver for Microchip USB251xB USB 2.0 Hi-Speed Hub Controller
3 * Configuration via SMBus.
5 * Copyright (c) 2017 SKIDATA AG
7 * This work is based on the USB3503 driver by Dongjin Kim and
8 * a not-accepted patch by Fabien Lahoudere, see:
9 * https://patchwork.kernel.org/patch/9257715/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
22 #include <linux/delay.h>
23 #include <linux/gpio.h>
24 #include <linux/i2c.h>
25 #include <linux/module.h>
26 #include <linux/nls.h>
27 #include <linux/of_device.h>
28 #include <linux/of_gpio.h>
29 #include <linux/slab.h>
31 /* Internal Register Set Addresses & Default Values acc. to DS00001692C */
32 #define USB251XB_ADDR_VENDOR_ID_LSB 0x00
33 #define USB251XB_ADDR_VENDOR_ID_MSB 0x01
34 #define USB251XB_DEF_VENDOR_ID 0x0424
36 #define USB251XB_ADDR_PRODUCT_ID_LSB 0x02
37 #define USB251XB_ADDR_PRODUCT_ID_MSB 0x03
38 #define USB251XB_DEF_PRODUCT_ID_12 0x2512 /* USB2512B/12Bi */
39 #define USB251XB_DEF_PRODUCT_ID_13 0x2513 /* USB2513B/13Bi */
40 #define USB251XB_DEF_PRODUCT_ID_14 0x2514 /* USB2514B/14Bi */
42 #define USB251XB_ADDR_DEVICE_ID_LSB 0x04
43 #define USB251XB_ADDR_DEVICE_ID_MSB 0x05
44 #define USB251XB_DEF_DEVICE_ID 0x0BB3
46 #define USB251XB_ADDR_CONFIG_DATA_1 0x06
47 #define USB251XB_DEF_CONFIG_DATA_1 0x9B
48 #define USB251XB_ADDR_CONFIG_DATA_2 0x07
49 #define USB251XB_DEF_CONFIG_DATA_2 0x20
50 #define USB251XB_ADDR_CONFIG_DATA_3 0x08
51 #define USB251XB_DEF_CONFIG_DATA_3 0x02
53 #define USB251XB_ADDR_NON_REMOVABLE_DEVICES 0x09
54 #define USB251XB_DEF_NON_REMOVABLE_DEVICES 0x00
56 #define USB251XB_ADDR_PORT_DISABLE_SELF 0x0A
57 #define USB251XB_DEF_PORT_DISABLE_SELF 0x00
58 #define USB251XB_ADDR_PORT_DISABLE_BUS 0x0B
59 #define USB251XB_DEF_PORT_DISABLE_BUS 0x00
61 #define USB251XB_ADDR_MAX_POWER_SELF 0x0C
62 #define USB251XB_DEF_MAX_POWER_SELF 0x01
63 #define USB251XB_ADDR_MAX_POWER_BUS 0x0D
64 #define USB251XB_DEF_MAX_POWER_BUS 0x32
66 #define USB251XB_ADDR_MAX_CURRENT_SELF 0x0E
67 #define USB251XB_DEF_MAX_CURRENT_SELF 0x01
68 #define USB251XB_ADDR_MAX_CURRENT_BUS 0x0F
69 #define USB251XB_DEF_MAX_CURRENT_BUS 0x32
71 #define USB251XB_ADDR_POWER_ON_TIME 0x10
72 #define USB251XB_DEF_POWER_ON_TIME 0x32
74 #define USB251XB_ADDR_LANGUAGE_ID_HIGH 0x11
75 #define USB251XB_ADDR_LANGUAGE_ID_LOW 0x12
76 #define USB251XB_DEF_LANGUAGE_ID 0x0000
78 #define USB251XB_STRING_BUFSIZE 62
79 #define USB251XB_ADDR_MANUFACTURER_STRING_LEN 0x13
80 #define USB251XB_ADDR_MANUFACTURER_STRING 0x16
81 #define USB251XB_DEF_MANUFACTURER_STRING "Microchip"
83 #define USB251XB_ADDR_PRODUCT_STRING_LEN 0x14
84 #define USB251XB_ADDR_PRODUCT_STRING 0x54
85 #define USB251XB_DEF_PRODUCT_STRING "USB251xB/xBi"
87 #define USB251XB_ADDR_SERIAL_STRING_LEN 0x15
88 #define USB251XB_ADDR_SERIAL_STRING 0x92
89 #define USB251XB_DEF_SERIAL_STRING ""
91 #define USB251XB_ADDR_BATTERY_CHARGING_ENABLE 0xD0
92 #define USB251XB_DEF_BATTERY_CHARGING_ENABLE 0x00
94 #define USB251XB_ADDR_BOOST_UP 0xF6
95 #define USB251XB_DEF_BOOST_UP 0x00
96 #define USB251XB_ADDR_BOOST_X 0xF8
97 #define USB251XB_DEF_BOOST_X 0x00
99 #define USB251XB_ADDR_PORT_SWAP 0xFA
100 #define USB251XB_DEF_PORT_SWAP 0x00
102 #define USB251XB_ADDR_PORT_MAP_12 0xFB
103 #define USB251XB_DEF_PORT_MAP_12 0x00
104 #define USB251XB_ADDR_PORT_MAP_34 0xFC
105 #define USB251XB_DEF_PORT_MAP_34 0x00 /* USB2513B/i & USB2514B/i only */
107 #define USB251XB_ADDR_STATUS_COMMAND 0xFF
108 #define USB251XB_STATUS_COMMAND_SMBUS_DOWN 0x04
109 #define USB251XB_STATUS_COMMAND_RESET 0x02
110 #define USB251XB_STATUS_COMMAND_ATTACH 0x01
112 #define USB251XB_I2C_REG_SZ 0x100
113 #define USB251XB_I2C_WRITE_SZ 0x10
115 #define DRIVER_NAME "usb251xb"
116 #define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller"
117 #define DRIVER_VERSION "1.0"
119 struct usb251xb {
120 struct device *dev;
121 struct i2c_client *i2c;
122 u8 skip_config;
123 int gpio_reset;
124 u16 vendor_id;
125 u16 product_id;
126 u16 device_id;
127 u8 conf_data1;
128 u8 conf_data2;
129 u8 conf_data3;
130 u8 non_rem_dev;
131 u8 port_disable_sp;
132 u8 port_disable_bp;
133 u8 max_power_sp;
134 u8 max_power_bp;
135 u8 max_current_sp;
136 u8 max_current_bp;
137 u8 power_on_time;
138 u16 lang_id;
139 u8 manufacturer_len;
140 u8 product_len;
141 u8 serial_len;
142 char manufacturer[USB251XB_STRING_BUFSIZE];
143 char product[USB251XB_STRING_BUFSIZE];
144 char serial[USB251XB_STRING_BUFSIZE];
145 u8 bat_charge_en;
146 u8 boost_up;
147 u8 boost_x;
148 u8 port_swap;
149 u8 port_map12;
150 u8 port_map34;
151 u8 status;
154 struct usb251xb_data {
155 u16 product_id;
156 char product_str[USB251XB_STRING_BUFSIZE / 2]; /* ASCII string */
159 static const struct usb251xb_data usb2512b_data = {
160 .product_id = 0x2512,
161 .product_str = "USB2512B",
164 static const struct usb251xb_data usb2512bi_data = {
165 .product_id = 0x2512,
166 .product_str = "USB2512Bi",
169 static const struct usb251xb_data usb2513b_data = {
170 .product_id = 0x2513,
171 .product_str = "USB2513B",
174 static const struct usb251xb_data usb2513bi_data = {
175 .product_id = 0x2513,
176 .product_str = "USB2513Bi",
179 static const struct usb251xb_data usb2514b_data = {
180 .product_id = 0x2514,
181 .product_str = "USB2514B",
184 static const struct usb251xb_data usb2514bi_data = {
185 .product_id = 0x2514,
186 .product_str = "USB2514Bi",
189 static void usb251xb_reset(struct usb251xb *hub, int state)
191 if (!gpio_is_valid(hub->gpio_reset))
192 return;
194 gpio_set_value_cansleep(hub->gpio_reset, state);
196 /* wait for hub recovery/stabilization */
197 if (state)
198 usleep_range(500, 750); /* >=500us at power on */
199 else
200 usleep_range(1, 10); /* >=1us at power down */
203 static int usb251xb_connect(struct usb251xb *hub)
205 struct device *dev = hub->dev;
206 int err, i;
207 char i2c_wb[USB251XB_I2C_REG_SZ];
209 memset(i2c_wb, 0, USB251XB_I2C_REG_SZ);
211 if (hub->skip_config) {
212 dev_info(dev, "Skip hub configuration, only attach.\n");
213 i2c_wb[0] = 0x01;
214 i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH;
216 usb251xb_reset(hub, 1);
218 err = i2c_smbus_write_i2c_block_data(hub->i2c,
219 USB251XB_ADDR_STATUS_COMMAND, 2, i2c_wb);
220 if (err) {
221 dev_err(dev, "attaching hub failed: %d\n", err);
222 return err;
224 return 0;
227 i2c_wb[USB251XB_ADDR_VENDOR_ID_MSB] = (hub->vendor_id >> 8) & 0xFF;
228 i2c_wb[USB251XB_ADDR_VENDOR_ID_LSB] = hub->vendor_id & 0xFF;
229 i2c_wb[USB251XB_ADDR_PRODUCT_ID_MSB] = (hub->product_id >> 8) & 0xFF;
230 i2c_wb[USB251XB_ADDR_PRODUCT_ID_LSB] = hub->product_id & 0xFF;
231 i2c_wb[USB251XB_ADDR_DEVICE_ID_MSB] = (hub->device_id >> 8) & 0xFF;
232 i2c_wb[USB251XB_ADDR_DEVICE_ID_LSB] = hub->device_id & 0xFF;
233 i2c_wb[USB251XB_ADDR_CONFIG_DATA_1] = hub->conf_data1;
234 i2c_wb[USB251XB_ADDR_CONFIG_DATA_2] = hub->conf_data2;
235 i2c_wb[USB251XB_ADDR_CONFIG_DATA_3] = hub->conf_data3;
236 i2c_wb[USB251XB_ADDR_NON_REMOVABLE_DEVICES] = hub->non_rem_dev;
237 i2c_wb[USB251XB_ADDR_PORT_DISABLE_SELF] = hub->port_disable_sp;
238 i2c_wb[USB251XB_ADDR_PORT_DISABLE_BUS] = hub->port_disable_bp;
239 i2c_wb[USB251XB_ADDR_MAX_POWER_SELF] = hub->max_power_sp;
240 i2c_wb[USB251XB_ADDR_MAX_POWER_BUS] = hub->max_power_bp;
241 i2c_wb[USB251XB_ADDR_MAX_CURRENT_SELF] = hub->max_current_sp;
242 i2c_wb[USB251XB_ADDR_MAX_CURRENT_BUS] = hub->max_current_bp;
243 i2c_wb[USB251XB_ADDR_POWER_ON_TIME] = hub->power_on_time;
244 i2c_wb[USB251XB_ADDR_LANGUAGE_ID_HIGH] = (hub->lang_id >> 8) & 0xFF;
245 i2c_wb[USB251XB_ADDR_LANGUAGE_ID_LOW] = hub->lang_id & 0xFF;
246 i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING_LEN] = hub->manufacturer_len;
247 i2c_wb[USB251XB_ADDR_PRODUCT_STRING_LEN] = hub->product_len;
248 i2c_wb[USB251XB_ADDR_SERIAL_STRING_LEN] = hub->serial_len;
249 memcpy(&i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING], hub->manufacturer,
250 USB251XB_STRING_BUFSIZE);
251 memcpy(&i2c_wb[USB251XB_ADDR_SERIAL_STRING], hub->serial,
252 USB251XB_STRING_BUFSIZE);
253 memcpy(&i2c_wb[USB251XB_ADDR_PRODUCT_STRING], hub->product,
254 USB251XB_STRING_BUFSIZE);
255 i2c_wb[USB251XB_ADDR_BATTERY_CHARGING_ENABLE] = hub->bat_charge_en;
256 i2c_wb[USB251XB_ADDR_BOOST_UP] = hub->boost_up;
257 i2c_wb[USB251XB_ADDR_BOOST_X] = hub->boost_x;
258 i2c_wb[USB251XB_ADDR_PORT_SWAP] = hub->port_swap;
259 i2c_wb[USB251XB_ADDR_PORT_MAP_12] = hub->port_map12;
260 i2c_wb[USB251XB_ADDR_PORT_MAP_34] = hub->port_map34;
261 i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH;
263 usb251xb_reset(hub, 1);
265 /* write registers */
266 for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) {
267 int offset = i * USB251XB_I2C_WRITE_SZ;
268 char wbuf[USB251XB_I2C_WRITE_SZ + 1];
270 /* The first data byte transferred tells the hub how many data
271 * bytes will follow (byte count).
273 wbuf[0] = USB251XB_I2C_WRITE_SZ;
274 memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ);
276 dev_dbg(dev, "writing %d byte block %d to 0x%02X\n",
277 USB251XB_I2C_WRITE_SZ, i, offset);
279 err = i2c_smbus_write_i2c_block_data(hub->i2c, offset,
280 USB251XB_I2C_WRITE_SZ + 1,
281 wbuf);
282 if (err)
283 goto out_err;
286 dev_info(dev, "Hub configuration was successful.\n");
287 return 0;
289 out_err:
290 dev_err(dev, "configuring block %d failed: %d\n", i, err);
291 return err;
294 #ifdef CONFIG_OF
295 static int usb251xb_get_ofdata(struct usb251xb *hub,
296 struct usb251xb_data *data)
298 struct device *dev = hub->dev;
299 struct device_node *np = dev->of_node;
300 int len, err, i;
301 u32 *property_u32 = NULL;
302 const u32 *cproperty_u32;
303 const char *cproperty_char;
304 char str[USB251XB_STRING_BUFSIZE / 2];
306 if (!np) {
307 dev_err(dev, "failed to get ofdata\n");
308 return -ENODEV;
311 if (of_get_property(np, "skip-config", NULL))
312 hub->skip_config = 1;
313 else
314 hub->skip_config = 0;
316 hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
317 if (hub->gpio_reset == -EPROBE_DEFER)
318 return -EPROBE_DEFER;
319 if (gpio_is_valid(hub->gpio_reset)) {
320 err = devm_gpio_request_one(dev, hub->gpio_reset,
321 GPIOF_OUT_INIT_LOW,
322 "usb251xb reset");
323 if (err) {
324 dev_err(dev,
325 "unable to request GPIO %d as reset pin (%d)\n",
326 hub->gpio_reset, err);
327 return err;
331 if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1))
332 hub->vendor_id = USB251XB_DEF_VENDOR_ID;
334 if (of_property_read_u16_array(np, "product-id",
335 &hub->product_id, 1))
336 hub->product_id = data->product_id;
338 if (of_property_read_u16_array(np, "device-id", &hub->device_id, 1))
339 hub->device_id = USB251XB_DEF_DEVICE_ID;
341 hub->conf_data1 = USB251XB_DEF_CONFIG_DATA_1;
342 if (of_get_property(np, "self-powered", NULL)) {
343 hub->conf_data1 |= BIT(7);
345 /* Configure Over-Current sens when self-powered */
346 hub->conf_data1 &= ~BIT(2);
347 if (of_get_property(np, "ganged-sensing", NULL))
348 hub->conf_data1 &= ~BIT(1);
349 else if (of_get_property(np, "individual-sensing", NULL))
350 hub->conf_data1 |= BIT(1);
351 } else if (of_get_property(np, "bus-powered", NULL)) {
352 hub->conf_data1 &= ~BIT(7);
354 /* Disable Over-Current sense when bus-powered */
355 hub->conf_data1 |= BIT(2);
358 if (of_get_property(np, "disable-hi-speed", NULL))
359 hub->conf_data1 |= BIT(5);
361 if (of_get_property(np, "multi-tt", NULL))
362 hub->conf_data1 |= BIT(4);
363 else if (of_get_property(np, "single-tt", NULL))
364 hub->conf_data1 &= ~BIT(4);
366 if (of_get_property(np, "disable-eop", NULL))
367 hub->conf_data1 |= BIT(3);
369 if (of_get_property(np, "individual-port-switching", NULL))
370 hub->conf_data1 |= BIT(0);
371 else if (of_get_property(np, "ganged-port-switching", NULL))
372 hub->conf_data1 &= ~BIT(0);
374 hub->conf_data2 = USB251XB_DEF_CONFIG_DATA_2;
375 if (of_get_property(np, "dynamic-power-switching", NULL))
376 hub->conf_data2 |= BIT(7);
378 if (!of_property_read_u32(np, "oc-delay-us", property_u32)) {
379 if (*property_u32 == 100) {
380 /* 100 us*/
381 hub->conf_data2 &= ~BIT(5);
382 hub->conf_data2 &= ~BIT(4);
383 } else if (*property_u32 == 4000) {
384 /* 4 ms */
385 hub->conf_data2 &= ~BIT(5);
386 hub->conf_data2 |= BIT(4);
387 } else if (*property_u32 == 16000) {
388 /* 16 ms */
389 hub->conf_data2 |= BIT(5);
390 hub->conf_data2 |= BIT(4);
391 } else {
392 /* 8 ms (DEFAULT) */
393 hub->conf_data2 |= BIT(5);
394 hub->conf_data2 &= ~BIT(4);
398 if (of_get_property(np, "compound-device", NULL))
399 hub->conf_data2 |= BIT(3);
401 hub->conf_data3 = USB251XB_DEF_CONFIG_DATA_3;
402 if (of_get_property(np, "port-mapping-mode", NULL))
403 hub->conf_data3 |= BIT(3);
405 if (of_get_property(np, "string-support", NULL))
406 hub->conf_data3 |= BIT(0);
408 hub->non_rem_dev = USB251XB_DEF_NON_REMOVABLE_DEVICES;
409 cproperty_u32 = of_get_property(np, "non-removable-ports", &len);
410 if (cproperty_u32 && (len / sizeof(u32)) > 0) {
411 for (i = 0; i < len / sizeof(u32); i++) {
412 u32 port = be32_to_cpu(cproperty_u32[i]);
414 if ((port >= 1) && (port <= 4))
415 hub->non_rem_dev |= BIT(port);
419 hub->port_disable_sp = USB251XB_DEF_PORT_DISABLE_SELF;
420 cproperty_u32 = of_get_property(np, "sp-disabled-ports", &len);
421 if (cproperty_u32 && (len / sizeof(u32)) > 0) {
422 for (i = 0; i < len / sizeof(u32); i++) {
423 u32 port = be32_to_cpu(cproperty_u32[i]);
425 if ((port >= 1) && (port <= 4))
426 hub->port_disable_sp |= BIT(port);
430 hub->port_disable_bp = USB251XB_DEF_PORT_DISABLE_BUS;
431 cproperty_u32 = of_get_property(np, "bp-disabled-ports", &len);
432 if (cproperty_u32 && (len / sizeof(u32)) > 0) {
433 for (i = 0; i < len / sizeof(u32); i++) {
434 u32 port = be32_to_cpu(cproperty_u32[i]);
436 if ((port >= 1) && (port <= 4))
437 hub->port_disable_bp |= BIT(port);
441 hub->power_on_time = USB251XB_DEF_POWER_ON_TIME;
442 if (!of_property_read_u32(np, "power-on-time-ms", property_u32))
443 hub->power_on_time = min_t(u8, *property_u32 / 2, 255);
445 if (of_property_read_u16_array(np, "language-id", &hub->lang_id, 1))
446 hub->lang_id = USB251XB_DEF_LANGUAGE_ID;
448 cproperty_char = of_get_property(np, "manufacturer", NULL);
449 strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
450 sizeof(str));
451 hub->manufacturer_len = strlen(str) & 0xFF;
452 memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE);
453 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
454 len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN,
455 (wchar_t *)hub->manufacturer,
456 USB251XB_STRING_BUFSIZE);
458 cproperty_char = of_get_property(np, "product", NULL);
459 strlcpy(str, cproperty_char ? : data->product_str, sizeof(str));
460 hub->product_len = strlen(str) & 0xFF;
461 memset(hub->product, 0, USB251XB_STRING_BUFSIZE);
462 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
463 len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN,
464 (wchar_t *)hub->product,
465 USB251XB_STRING_BUFSIZE);
467 cproperty_char = of_get_property(np, "serial", NULL);
468 strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
469 sizeof(str));
470 hub->serial_len = strlen(str) & 0xFF;
471 memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
472 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
473 len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN,
474 (wchar_t *)hub->serial,
475 USB251XB_STRING_BUFSIZE);
477 /* The following parameters are currently not exposed to devicetree, but
478 * may be as soon as needed.
480 hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF;
481 hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS;
482 hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF;
483 hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS;
484 hub->bat_charge_en = USB251XB_DEF_BATTERY_CHARGING_ENABLE;
485 hub->boost_up = USB251XB_DEF_BOOST_UP;
486 hub->boost_x = USB251XB_DEF_BOOST_X;
487 hub->port_swap = USB251XB_DEF_PORT_SWAP;
488 hub->port_map12 = USB251XB_DEF_PORT_MAP_12;
489 hub->port_map34 = USB251XB_DEF_PORT_MAP_34;
491 return 0;
494 static const struct of_device_id usb251xb_of_match[] = {
496 .compatible = "microchip,usb2512b",
497 .data = &usb2512b_data,
498 }, {
499 .compatible = "microchip,usb2512bi",
500 .data = &usb2512bi_data,
501 }, {
502 .compatible = "microchip,usb2513b",
503 .data = &usb2513b_data,
504 }, {
505 .compatible = "microchip,usb2513bi",
506 .data = &usb2513bi_data,
507 }, {
508 .compatible = "microchip,usb2514b",
509 .data = &usb2514b_data,
510 }, {
511 .compatible = "microchip,usb2514bi",
512 .data = &usb2514bi_data,
513 }, {
514 /* sentinel */
517 MODULE_DEVICE_TABLE(of, usb251xb_of_match);
518 #else /* CONFIG_OF */
519 static int usb251xb_get_ofdata(struct usb251xb *hub,
520 struct usb251xb_data *data)
522 return 0;
524 #endif /* CONFIG_OF */
526 static int usb251xb_probe(struct usb251xb *hub)
528 struct device *dev = hub->dev;
529 struct device_node *np = dev->of_node;
530 const struct of_device_id *of_id = of_match_device(usb251xb_of_match,
531 dev);
532 int err;
534 if (np) {
535 err = usb251xb_get_ofdata(hub,
536 (struct usb251xb_data *)of_id->data);
537 if (err) {
538 dev_err(dev, "failed to get ofdata: %d\n", err);
539 return err;
543 err = usb251xb_connect(hub);
544 if (err) {
545 dev_err(dev, "Failed to connect hub (%d)\n", err);
546 return err;
549 dev_info(dev, "Hub probed successfully\n");
551 return 0;
554 static int usb251xb_i2c_probe(struct i2c_client *i2c,
555 const struct i2c_device_id *id)
557 struct usb251xb *hub;
559 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb251xb), GFP_KERNEL);
560 if (!hub)
561 return -ENOMEM;
563 i2c_set_clientdata(i2c, hub);
564 hub->dev = &i2c->dev;
565 hub->i2c = i2c;
567 return usb251xb_probe(hub);
570 static const struct i2c_device_id usb251xb_id[] = {
571 { "usb2512b", 0 },
572 { "usb2512bi", 0 },
573 { "usb2513b", 0 },
574 { "usb2513bi", 0 },
575 { "usb2514b", 0 },
576 { "usb2514bi", 0 },
577 { /* sentinel */ }
579 MODULE_DEVICE_TABLE(i2c, usb251xb_id);
581 static struct i2c_driver usb251xb_i2c_driver = {
582 .driver = {
583 .name = DRIVER_NAME,
584 .of_match_table = of_match_ptr(usb251xb_of_match),
586 .probe = usb251xb_i2c_probe,
587 .id_table = usb251xb_id,
590 module_i2c_driver(usb251xb_i2c_driver);
592 MODULE_AUTHOR("Richard Leitner <richard.leitner@skidata.com>");
593 MODULE_DESCRIPTION("USB251xB/xBi USB 2.0 Hub Controller Driver");
594 MODULE_LICENSE("GPL");