blob: 4e18600dc9b43e2603ec2c8f371545e63b75a404 [file] [log] [blame]
Richard Leitner3ec72a22017-02-10 09:19:27 +01001/*
2 * Driver for Microchip USB251xB USB 2.0 Hi-Speed Hub Controller
3 * Configuration via SMBus.
4 *
5 * Copyright (c) 2017 SKIDATA AG
6 *
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/
10 *
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.
15 *
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.
20 */
21
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>
30
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
35
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 */
41
42#define USB251XB_ADDR_DEVICE_ID_LSB 0x04
43#define USB251XB_ADDR_DEVICE_ID_MSB 0x05
44#define USB251XB_DEF_DEVICE_ID 0x0BB3
45
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
52
53#define USB251XB_ADDR_NON_REMOVABLE_DEVICES 0x09
54#define USB251XB_DEF_NON_REMOVABLE_DEVICES 0x00
55
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
60
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
65
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
70
71#define USB251XB_ADDR_POWER_ON_TIME 0x10
72#define USB251XB_DEF_POWER_ON_TIME 0x32
73
74#define USB251XB_ADDR_LANGUAGE_ID_HIGH 0x11
75#define USB251XB_ADDR_LANGUAGE_ID_LOW 0x12
76#define USB251XB_DEF_LANGUAGE_ID 0x0000
77
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"
82
83#define USB251XB_ADDR_PRODUCT_STRING_LEN 0x14
84#define USB251XB_ADDR_PRODUCT_STRING 0x54
85#define USB251XB_DEF_PRODUCT_STRING "USB251xB/xBi"
86
87#define USB251XB_ADDR_SERIAL_STRING_LEN 0x15
88#define USB251XB_ADDR_SERIAL_STRING 0x92
89#define USB251XB_DEF_SERIAL_STRING ""
90
91#define USB251XB_ADDR_BATTERY_CHARGING_ENABLE 0xD0
92#define USB251XB_DEF_BATTERY_CHARGING_ENABLE 0x00
93
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
98
99#define USB251XB_ADDR_PORT_SWAP 0xFA
100#define USB251XB_DEF_PORT_SWAP 0x00
101
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 */
106
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
111
112#define USB251XB_I2C_REG_SZ 0x100
113#define USB251XB_I2C_WRITE_SZ 0x10
114
115#define DRIVER_NAME "usb251xb"
116#define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller"
117#define DRIVER_VERSION "1.0"
118
119struct 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;
152};
153
154struct usb251xb_data {
155 u16 product_id;
156 char product_str[USB251XB_STRING_BUFSIZE / 2]; /* ASCII string */
157};
158
159static const struct usb251xb_data usb2512b_data = {
160 .product_id = 0x2512,
161 .product_str = "USB2512B",
162};
163
164static const struct usb251xb_data usb2512bi_data = {
165 .product_id = 0x2512,
166 .product_str = "USB2512Bi",
167};
168
169static const struct usb251xb_data usb2513b_data = {
170 .product_id = 0x2513,
171 .product_str = "USB2513B",
172};
173
174static const struct usb251xb_data usb2513bi_data = {
175 .product_id = 0x2513,
176 .product_str = "USB2513Bi",
177};
178
179static const struct usb251xb_data usb2514b_data = {
180 .product_id = 0x2514,
181 .product_str = "USB2514B",
182};
183
184static const struct usb251xb_data usb2514bi_data = {
185 .product_id = 0x2514,
186 .product_str = "USB2514Bi",
187};
188
189static void usb251xb_reset(struct usb251xb *hub, int state)
190{
191 if (!gpio_is_valid(hub->gpio_reset))
192 return;
193
194 gpio_set_value_cansleep(hub->gpio_reset, state);
195
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 */
201}
202
203static int usb251xb_connect(struct usb251xb *hub)
204{
205 struct device *dev = hub->dev;
206 int err, i;
207 char i2c_wb[USB251XB_I2C_REG_SZ];
208
209 memset(i2c_wb, 0, USB251XB_I2C_REG_SZ);
210
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;
215
216 usb251xb_reset(hub, 1);
217
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;
223 }
224 return 0;
225 }
226
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;
262
263 usb251xb_reset(hub, 1);
264
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];
269
270 /* The first data byte transferred tells the hub how many data
271 * bytes will follow (byte count).
272 */
273 wbuf[0] = USB251XB_I2C_WRITE_SZ;
274 memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ);
275
276 dev_dbg(dev, "writing %d byte block %d to 0x%02X\n",
277 USB251XB_I2C_WRITE_SZ, i, offset);
278
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;
284 }
285
286 dev_info(dev, "Hub configuration was successful.\n");
287 return 0;
288
289out_err:
290 dev_err(dev, "configuring block %d failed: %d\n", i, err);
291 return err;
292}
293
294#ifdef CONFIG_OF
295static int usb251xb_get_ofdata(struct usb251xb *hub,
296 struct usb251xb_data *data)
297{
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];
305
306 if (!np) {
307 dev_err(dev, "failed to get ofdata\n");
308 return -ENODEV;
309 }
310
311 if (of_get_property(np, "skip-config", NULL))
312 hub->skip_config = 1;
313 else
314 hub->skip_config = 0;
315
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;
328 }
329 }
330
331 if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1))
332 hub->vendor_id = USB251XB_DEF_VENDOR_ID;
333
334 if (of_property_read_u16_array(np, "product-id",
335 &hub->product_id, 1))
336 hub->product_id = data->product_id;
337
338 if (of_property_read_u16_array(np, "device-id", &hub->device_id, 1))
339 hub->device_id = USB251XB_DEF_DEVICE_ID;
340
341 hub->conf_data1 = USB251XB_DEF_CONFIG_DATA_1;
342 if (of_get_property(np, "self-powered", NULL)) {
343 hub->conf_data1 |= BIT(7);
344
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);
353
354 /* Disable Over-Current sense when bus-powered */
355 hub->conf_data1 |= BIT(2);
356 }
357
358 if (of_get_property(np, "disable-hi-speed", NULL))
359 hub->conf_data1 |= BIT(5);
360
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);
365
366 if (of_get_property(np, "disable-eop", NULL))
367 hub->conf_data1 |= BIT(3);
368
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);
373
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);
377
378 if (of_get_property(np, "oc-delay-100us", NULL)) {
379 hub->conf_data2 &= ~BIT(5);
380 hub->conf_data2 &= ~BIT(4);
381 } else if (of_get_property(np, "oc-delay-4ms", NULL)) {
382 hub->conf_data2 &= ~BIT(5);
383 hub->conf_data2 |= BIT(4);
384 } else if (of_get_property(np, "oc-delay-8ms", NULL)) {
385 hub->conf_data2 |= BIT(5);
386 hub->conf_data2 &= ~BIT(4);
387 } else if (of_get_property(np, "oc-delay-16ms", NULL)) {
388 hub->conf_data2 |= BIT(5);
389 hub->conf_data2 |= BIT(4);
390 }
391
392 if (of_get_property(np, "compound-device", NULL))
393 hub->conf_data2 |= BIT(3);
394
395 hub->conf_data3 = USB251XB_DEF_CONFIG_DATA_3;
396 if (of_get_property(np, "port-mapping-mode", NULL))
397 hub->conf_data3 |= BIT(3);
398
399 if (of_get_property(np, "string-support", NULL))
400 hub->conf_data3 |= BIT(0);
401
402 hub->non_rem_dev = USB251XB_DEF_NON_REMOVABLE_DEVICES;
403 cproperty_u32 = of_get_property(np, "non-removable-ports", &len);
404 if (cproperty_u32 && (len / sizeof(u32)) > 0) {
405 for (i = 0; i < len / sizeof(u32); i++) {
406 u32 port = be32_to_cpu(cproperty_u32[i]);
407
408 if ((port >= 1) && (port <= 4))
409 hub->non_rem_dev |= BIT(port);
410 }
411 }
412
413 hub->port_disable_sp = USB251XB_DEF_PORT_DISABLE_SELF;
414 cproperty_u32 = of_get_property(np, "sp-disabled-ports", &len);
415 if (cproperty_u32 && (len / sizeof(u32)) > 0) {
416 for (i = 0; i < len / sizeof(u32); i++) {
417 u32 port = be32_to_cpu(cproperty_u32[i]);
418
419 if ((port >= 1) && (port <= 4))
420 hub->port_disable_sp |= BIT(port);
421 }
422 }
423
424 hub->port_disable_bp = USB251XB_DEF_PORT_DISABLE_BUS;
425 cproperty_u32 = of_get_property(np, "bp-disabled-ports", &len);
426 if (cproperty_u32 && (len / sizeof(u32)) > 0) {
427 for (i = 0; i < len / sizeof(u32); i++) {
428 u32 port = be32_to_cpu(cproperty_u32[i]);
429
430 if ((port >= 1) && (port <= 4))
431 hub->port_disable_bp |= BIT(port);
432 }
433 }
434
435 hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF;
436 if (!of_property_read_u32(np, "max-sp-power", property_u32))
437 hub->max_power_sp = min_t(u8, be32_to_cpu(*property_u32) / 2,
438 250);
439
440 hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS;
441 if (!of_property_read_u32(np, "max-bp-power", property_u32))
442 hub->max_power_bp = min_t(u8, be32_to_cpu(*property_u32) / 2,
443 250);
444
445 hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF;
446 if (!of_property_read_u32(np, "max-sp-current", property_u32))
447 hub->max_current_sp = min_t(u8, be32_to_cpu(*property_u32) / 2,
448 250);
449
450 hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS;
451 if (!of_property_read_u32(np, "max-bp-current", property_u32))
452 hub->max_current_bp = min_t(u8, be32_to_cpu(*property_u32) / 2,
453 250);
454
455 hub->power_on_time = USB251XB_DEF_POWER_ON_TIME;
456 if (!of_property_read_u32(np, "power-on-time", property_u32))
457 hub->power_on_time = min_t(u8, be32_to_cpu(*property_u32) / 2,
458 255);
459
460 if (of_property_read_u16_array(np, "language-id", &hub->lang_id, 1))
461 hub->lang_id = USB251XB_DEF_LANGUAGE_ID;
462
463 cproperty_char = of_get_property(np, "manufacturer", NULL);
464 strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
465 sizeof(str));
466 hub->manufacturer_len = strlen(str) & 0xFF;
467 memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE);
468 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
469 len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN,
470 (wchar_t *)hub->manufacturer,
471 USB251XB_STRING_BUFSIZE);
472
473 cproperty_char = of_get_property(np, "product", NULL);
474 strlcpy(str, cproperty_char ? : data->product_str, sizeof(str));
475 hub->product_len = strlen(str) & 0xFF;
476 memset(hub->product, 0, USB251XB_STRING_BUFSIZE);
477 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
478 len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN,
479 (wchar_t *)hub->product,
480 USB251XB_STRING_BUFSIZE);
481
482 cproperty_char = of_get_property(np, "serial", NULL);
483 strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
484 sizeof(str));
485 hub->serial_len = strlen(str) & 0xFF;
486 memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
487 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
488 len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN,
489 (wchar_t *)hub->serial,
490 USB251XB_STRING_BUFSIZE);
491
492 /* The following parameters are currently not exposed to devicetree, but
493 * may be as soon as needed.
494 */
495 hub->bat_charge_en = USB251XB_DEF_BATTERY_CHARGING_ENABLE;
496 hub->boost_up = USB251XB_DEF_BOOST_UP;
497 hub->boost_x = USB251XB_DEF_BOOST_X;
498 hub->port_swap = USB251XB_DEF_PORT_SWAP;
499 hub->port_map12 = USB251XB_DEF_PORT_MAP_12;
500 hub->port_map34 = USB251XB_DEF_PORT_MAP_34;
501
502 return 0;
503}
504
505static const struct of_device_id usb251xb_of_match[] = {
506 {
507 .compatible = "microchip,usb2512b",
508 .data = &usb2512b_data,
509 }, {
510 .compatible = "microchip,usb2512bi",
511 .data = &usb2512bi_data,
512 }, {
513 .compatible = "microchip,usb2513b",
514 .data = &usb2513b_data,
515 }, {
516 .compatible = "microchip,usb2513bi",
517 .data = &usb2513bi_data,
518 }, {
519 .compatible = "microchip,usb2514b",
520 .data = &usb2514b_data,
521 }, {
522 .compatible = "microchip,usb2514bi",
523 .data = &usb2514bi_data,
524 }, {
525 /* sentinel */
526 }
527};
528MODULE_DEVICE_TABLE(of, usb251xb_of_match);
529#else /* CONFIG_OF */
530static int usb251xb_get_ofdata(struct usb251xb *hub,
531 struct usb251xb_data *data)
532{
533 return 0;
534}
535#endif /* CONFIG_OF */
536
537static int usb251xb_probe(struct usb251xb *hub)
538{
539 struct device *dev = hub->dev;
540 struct device_node *np = dev->of_node;
541 const struct of_device_id *of_id = of_match_device(usb251xb_of_match,
542 dev);
543 int err;
544
545 if (np) {
546 err = usb251xb_get_ofdata(hub,
547 (struct usb251xb_data *)of_id->data);
548 if (err) {
549 dev_err(dev, "failed to get ofdata: %d\n", err);
550 return err;
551 }
552 }
553
554 err = usb251xb_connect(hub);
555 if (err) {
556 dev_err(dev, "Failed to connect hub (%d)\n", err);
557 return err;
558 }
559
560 dev_info(dev, "Hub probed successfully\n");
561
562 return 0;
563}
564
565static int usb251xb_i2c_probe(struct i2c_client *i2c,
566 const struct i2c_device_id *id)
567{
568 struct usb251xb *hub;
569
570 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb251xb), GFP_KERNEL);
571 if (!hub)
572 return -ENOMEM;
573
574 i2c_set_clientdata(i2c, hub);
575 hub->dev = &i2c->dev;
576 hub->i2c = i2c;
577
578 return usb251xb_probe(hub);
579}
580
581static const struct i2c_device_id usb251xb_id[] = {
582 { "usb2512b", 0 },
583 { "usb2512bi", 0 },
584 { "usb2513b", 0 },
585 { "usb2513bi", 0 },
586 { "usb2514b", 0 },
587 { "usb2514bi", 0 },
588 { /* sentinel */ }
589};
590MODULE_DEVICE_TABLE(i2c, usb251xb_id);
591
592static struct i2c_driver usb251xb_i2c_driver = {
593 .driver = {
594 .name = DRIVER_NAME,
595 .of_match_table = of_match_ptr(usb251xb_of_match),
596 },
597 .probe = usb251xb_i2c_probe,
598 .id_table = usb251xb_id,
599};
600
601module_i2c_driver(usb251xb_i2c_driver);
602
603MODULE_AUTHOR("Richard Leitner <richard.leitner@skidata.com>");
604MODULE_DESCRIPTION("USB251xB/xBi USB 2.0 Hub Controller Driver");
605MODULE_LICENSE("GPL");