blob: daba2c2d6835d26993db40fab40746d9f8cce249 [file] [log] [blame]
Marek Vasut16637b42022-04-10 06:27:14 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Driver for Microchip USB251xB USB 2.0 Hi-Speed Hub Controller
4 * Configuration via SMBus.
5 *
6 * Copyright (c) 2017 SKIDATA AG
7 *
8 * This work is based on the USB3503 driver by Dongjin Kim and
9 * a not-accepted patch by Fabien Lahoudere, see:
10 * https://patchwork.kernel.org/patch/9257715/
11 */
12
Marek Vasut16637b42022-04-10 06:27:14 +020013#include <asm/gpio.h>
14#include <dm.h>
15#include <dm/device_compat.h>
16#include <errno.h>
17#include <i2c.h>
18#include <linux/delay.h>
19#include <linux/utf.h>
20#include <power/regulator.h>
21
22/* Internal Register Set Addresses & Default Values acc. to DS00001692C */
23#define USB251XB_ADDR_VENDOR_ID_LSB 0x00
24#define USB251XB_ADDR_VENDOR_ID_MSB 0x01
25#define USB251XB_DEF_VENDOR_ID 0x0424
26
27#define USB251XB_ADDR_PRODUCT_ID_LSB 0x02
28#define USB251XB_ADDR_PRODUCT_ID_MSB 0x03
29
30#define USB251XB_ADDR_DEVICE_ID_LSB 0x04
31#define USB251XB_ADDR_DEVICE_ID_MSB 0x05
32#define USB251XB_DEF_DEVICE_ID 0x0BB3
33
34#define USB251XB_ADDR_CONFIG_DATA_1 0x06
35#define USB251XB_DEF_CONFIG_DATA_1 0x9B
36#define USB251XB_ADDR_CONFIG_DATA_2 0x07
37#define USB251XB_DEF_CONFIG_DATA_2 0x20
38#define USB251XB_ADDR_CONFIG_DATA_3 0x08
39#define USB251XB_DEF_CONFIG_DATA_3 0x02
40
41#define USB251XB_ADDR_NON_REMOVABLE_DEVICES 0x09
42#define USB251XB_DEF_NON_REMOVABLE_DEVICES 0x00
43
44#define USB251XB_ADDR_PORT_DISABLE_SELF 0x0A
45#define USB251XB_DEF_PORT_DISABLE_SELF 0x00
46#define USB251XB_ADDR_PORT_DISABLE_BUS 0x0B
47#define USB251XB_DEF_PORT_DISABLE_BUS 0x00
48
49#define USB251XB_ADDR_MAX_POWER_SELF 0x0C
50#define USB251XB_DEF_MAX_POWER_SELF 0x01
51#define USB251XB_ADDR_MAX_POWER_BUS 0x0D
52#define USB251XB_DEF_MAX_POWER_BUS 0x32
53
54#define USB251XB_ADDR_MAX_CURRENT_SELF 0x0E
55#define USB251XB_DEF_MAX_CURRENT_SELF 0x01
56#define USB251XB_ADDR_MAX_CURRENT_BUS 0x0F
57#define USB251XB_DEF_MAX_CURRENT_BUS 0x32
58
59#define USB251XB_ADDR_POWER_ON_TIME 0x10
60#define USB251XB_DEF_POWER_ON_TIME 0x32
61
62#define USB251XB_ADDR_LANGUAGE_ID_HIGH 0x11
63#define USB251XB_ADDR_LANGUAGE_ID_LOW 0x12
64#define USB251XB_DEF_LANGUAGE_ID 0x0000
65
66#define USB251XB_STRING_BUFSIZE 62
67#define USB251XB_ADDR_MANUFACTURER_STRING_LEN 0x13
68#define USB251XB_ADDR_MANUFACTURER_STRING 0x16
69#define USB251XB_DEF_MANUFACTURER_STRING "Microchip"
70
71#define USB251XB_ADDR_PRODUCT_STRING_LEN 0x14
72#define USB251XB_ADDR_PRODUCT_STRING 0x54
73
74#define USB251XB_ADDR_SERIAL_STRING_LEN 0x15
75#define USB251XB_ADDR_SERIAL_STRING 0x92
76#define USB251XB_DEF_SERIAL_STRING ""
77
78#define USB251XB_ADDR_BATTERY_CHARGING_ENABLE 0xD0
79#define USB251XB_DEF_BATTERY_CHARGING_ENABLE 0x00
80
81#define USB251XB_ADDR_BOOST_UP 0xF6
82#define USB251XB_DEF_BOOST_UP 0x00
83#define USB251XB_ADDR_BOOST_57 0xF7
84#define USB251XB_DEF_BOOST_57 0x00
85#define USB251XB_ADDR_BOOST_14 0xF8
86#define USB251XB_DEF_BOOST_14 0x00
87
88#define USB251XB_ADDR_PORT_SWAP 0xFA
89#define USB251XB_DEF_PORT_SWAP 0x00
90
91#define USB251XB_ADDR_PORT_MAP_12 0xFB
92#define USB251XB_DEF_PORT_MAP_12 0x00
93#define USB251XB_ADDR_PORT_MAP_34 0xFC
94#define USB251XB_DEF_PORT_MAP_34 0x00 /* USB251{3B/i,4B/i,7/i} only */
95#define USB251XB_ADDR_PORT_MAP_56 0xFD
96#define USB251XB_DEF_PORT_MAP_56 0x00 /* USB2517/i only */
97#define USB251XB_ADDR_PORT_MAP_7 0xFE
98#define USB251XB_DEF_PORT_MAP_7 0x00 /* USB2517/i only */
99
100#define USB251XB_ADDR_STATUS_COMMAND 0xFF
101#define USB251XB_STATUS_COMMAND_SMBUS_DOWN 0x04
102#define USB251XB_STATUS_COMMAND_RESET 0x02
103#define USB251XB_STATUS_COMMAND_ATTACH 0x01
104
105#define USB251XB_I2C_REG_SZ 0x100
106#define USB251XB_I2C_WRITE_SZ 0x10
107
108#define DRIVER_NAME "usb251xb"
109#define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller"
110
111struct usb251xb {
112 struct device *dev;
113 struct i2c_client *i2c;
114 struct udevice *vdd;
115 u8 skip_config;
116 struct gpio_desc gpio_reset;
117 u32 vendor_id;
118 u32 product_id;
119 u32 device_id;
120 u8 conf_data1;
121 u8 conf_data2;
122 u8 conf_data3;
123 u8 non_rem_dev;
124 u8 port_disable_sp;
125 u8 port_disable_bp;
126 u8 max_power_sp;
127 u8 max_power_bp;
128 u8 max_current_sp;
129 u8 max_current_bp;
130 u8 power_on_time;
131 u32 lang_id;
132 u8 manufacturer_len;
133 u8 product_len;
134 u8 serial_len;
135 s16 manufacturer[USB251XB_STRING_BUFSIZE];
136 s16 product[USB251XB_STRING_BUFSIZE];
137 s16 serial[USB251XB_STRING_BUFSIZE];
138 u8 bat_charge_en;
139 u32 boost_up;
140 u8 boost_57;
141 u8 boost_14;
142 u8 port_swap;
143 u8 port_map12;
144 u8 port_map34;
145 u8 port_map56;
146 u8 port_map7;
147 u8 status;
148};
149
150struct usb251xb_data {
151 u16 product_id;
152 u8 port_cnt;
153 bool led_support;
154 bool bat_support;
155 char product_str[USB251XB_STRING_BUFSIZE / 2]; /* ASCII string */
156};
157
158static const struct usb251xb_data usb2422_data = {
159 .product_id = 0x2422,
160 .port_cnt = 2,
161 .led_support = false,
162 .bat_support = true,
163 .product_str = "USB2422",
164};
165
166static const struct usb251xb_data usb2512b_data = {
167 .product_id = 0x2512,
168 .port_cnt = 2,
169 .led_support = false,
170 .bat_support = true,
171 .product_str = "USB2512B",
172};
173
174static const struct usb251xb_data usb2512bi_data = {
175 .product_id = 0x2512,
176 .port_cnt = 2,
177 .led_support = false,
178 .bat_support = true,
179 .product_str = "USB2512Bi",
180};
181
182static const struct usb251xb_data usb2513b_data = {
183 .product_id = 0x2513,
184 .port_cnt = 3,
185 .led_support = false,
186 .bat_support = true,
187 .product_str = "USB2513B",
188};
189
190static const struct usb251xb_data usb2513bi_data = {
191 .product_id = 0x2513,
192 .port_cnt = 3,
193 .led_support = false,
194 .bat_support = true,
195 .product_str = "USB2513Bi",
196};
197
198static const struct usb251xb_data usb2514b_data = {
199 .product_id = 0x2514,
200 .port_cnt = 4,
201 .led_support = false,
202 .bat_support = true,
203 .product_str = "USB2514B",
204};
205
206static const struct usb251xb_data usb2514bi_data = {
207 .product_id = 0x2514,
208 .port_cnt = 4,
209 .led_support = false,
210 .bat_support = true,
211 .product_str = "USB2514Bi",
212};
213
214static const struct usb251xb_data usb2517_data = {
215 .product_id = 0x2517,
216 .port_cnt = 7,
217 .led_support = true,
218 .bat_support = false,
219 .product_str = "USB2517",
220};
221
222static const struct usb251xb_data usb2517i_data = {
223 .product_id = 0x2517,
224 .port_cnt = 7,
225 .led_support = true,
226 .bat_support = false,
227 .product_str = "USB2517i",
228};
229
230static void usb251xb_reset(struct usb251xb *hub)
231{
232 dm_gpio_set_value(&hub->gpio_reset, 1);
233 udelay(10); /* >=1us RESET_N asserted */
234 dm_gpio_set_value(&hub->gpio_reset, 0);
235
236 /* wait for hub recovery/stabilization */
237 udelay(750); /* >=500us after RESET_N deasserted */
238}
239
240static int usb251xb_connect(struct udevice *dev)
241{
242 struct usb251xb *hub = dev_get_priv(dev);
243 char i2c_wb[USB251XB_I2C_REG_SZ];
244 int err, i;
245
246 memset(i2c_wb, 0, USB251XB_I2C_REG_SZ);
247
248 if (hub->skip_config) {
249 dev_info(dev, "Skip hub configuration, only attach.\n");
250 i2c_wb[0] = 0x01;
251 i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH;
252
253 usb251xb_reset(hub);
254
255 err = dm_i2c_write(dev, USB251XB_ADDR_STATUS_COMMAND, i2c_wb, 2);
256 if (err) {
257 dev_err(dev, "attaching hub failed: %d\n", err);
258 return err;
259 }
260 return 0;
261 }
262
263 i2c_wb[USB251XB_ADDR_VENDOR_ID_MSB] = (hub->vendor_id >> 8) & 0xFF;
264 i2c_wb[USB251XB_ADDR_VENDOR_ID_LSB] = hub->vendor_id & 0xFF;
265 i2c_wb[USB251XB_ADDR_PRODUCT_ID_MSB] = (hub->product_id >> 8) & 0xFF;
266 i2c_wb[USB251XB_ADDR_PRODUCT_ID_LSB] = hub->product_id & 0xFF;
267 i2c_wb[USB251XB_ADDR_DEVICE_ID_MSB] = (hub->device_id >> 8) & 0xFF;
268 i2c_wb[USB251XB_ADDR_DEVICE_ID_LSB] = hub->device_id & 0xFF;
269 i2c_wb[USB251XB_ADDR_CONFIG_DATA_1] = hub->conf_data1;
270 i2c_wb[USB251XB_ADDR_CONFIG_DATA_2] = hub->conf_data2;
271 i2c_wb[USB251XB_ADDR_CONFIG_DATA_3] = hub->conf_data3;
272 i2c_wb[USB251XB_ADDR_NON_REMOVABLE_DEVICES] = hub->non_rem_dev;
273 i2c_wb[USB251XB_ADDR_PORT_DISABLE_SELF] = hub->port_disable_sp;
274 i2c_wb[USB251XB_ADDR_PORT_DISABLE_BUS] = hub->port_disable_bp;
275 i2c_wb[USB251XB_ADDR_MAX_POWER_SELF] = hub->max_power_sp;
276 i2c_wb[USB251XB_ADDR_MAX_POWER_BUS] = hub->max_power_bp;
277 i2c_wb[USB251XB_ADDR_MAX_CURRENT_SELF] = hub->max_current_sp;
278 i2c_wb[USB251XB_ADDR_MAX_CURRENT_BUS] = hub->max_current_bp;
279 i2c_wb[USB251XB_ADDR_POWER_ON_TIME] = hub->power_on_time;
280 i2c_wb[USB251XB_ADDR_LANGUAGE_ID_HIGH] = (hub->lang_id >> 8) & 0xFF;
281 i2c_wb[USB251XB_ADDR_LANGUAGE_ID_LOW] = hub->lang_id & 0xFF;
282 i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING_LEN] = hub->manufacturer_len;
283 i2c_wb[USB251XB_ADDR_PRODUCT_STRING_LEN] = hub->product_len;
284 i2c_wb[USB251XB_ADDR_SERIAL_STRING_LEN] = hub->serial_len;
285 memcpy(&i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING], hub->manufacturer,
286 USB251XB_STRING_BUFSIZE);
287 memcpy(&i2c_wb[USB251XB_ADDR_SERIAL_STRING], hub->serial,
288 USB251XB_STRING_BUFSIZE);
289 memcpy(&i2c_wb[USB251XB_ADDR_PRODUCT_STRING], hub->product,
290 USB251XB_STRING_BUFSIZE);
291 i2c_wb[USB251XB_ADDR_BATTERY_CHARGING_ENABLE] = hub->bat_charge_en;
292 i2c_wb[USB251XB_ADDR_BOOST_UP] = hub->boost_up;
293 i2c_wb[USB251XB_ADDR_BOOST_57] = hub->boost_57;
294 i2c_wb[USB251XB_ADDR_BOOST_14] = hub->boost_14;
295 i2c_wb[USB251XB_ADDR_PORT_SWAP] = hub->port_swap;
296 i2c_wb[USB251XB_ADDR_PORT_MAP_12] = hub->port_map12;
297 i2c_wb[USB251XB_ADDR_PORT_MAP_34] = hub->port_map34;
298 i2c_wb[USB251XB_ADDR_PORT_MAP_56] = hub->port_map56;
299 i2c_wb[USB251XB_ADDR_PORT_MAP_7] = hub->port_map7;
300 i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH;
301
302 usb251xb_reset(hub);
303
304 /* write registers */
305 for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) {
306 int offset = i * USB251XB_I2C_WRITE_SZ;
307 char wbuf[USB251XB_I2C_WRITE_SZ + 1];
308
309 /* The first data byte transferred tells the hub how many data
310 * bytes will follow (byte count).
311 */
312 wbuf[0] = USB251XB_I2C_WRITE_SZ;
313 memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ);
314
315 dev_dbg(dev, "writing %d byte block %d to 0x%02X\n",
316 USB251XB_I2C_WRITE_SZ, i, offset);
317
318 err = dm_i2c_write(dev, offset, wbuf, USB251XB_I2C_WRITE_SZ + 1);
319 if (err)
320 goto out_err;
321 }
322
323 dev_info(dev, "Hub configuration was successful.\n");
324 return 0;
325
326out_err:
327 dev_err(dev, "configuring block %d failed: %d\n", i, err);
328 return err;
329}
330
331static int usb251xb_probe(struct udevice *dev)
332{
333 struct usb251xb *hub = dev_get_priv(dev);
334 int err;
335
Marek Vasuta0ec4762023-02-28 02:55:18 +0100336 if (CONFIG_IS_ENABLED(DM_REGULATOR) && hub->vdd) {
Marek Vasut16637b42022-04-10 06:27:14 +0200337 err = regulator_set_enable(hub->vdd, true);
338 if (err)
339 return err;
340 }
341
342 err = usb251xb_connect(dev);
343 if (err) {
344 dev_err(dev, "Failed to connect hub (%d)\n", err);
345 return err;
346 }
347
348 dev_info(dev, "Hub probed successfully\n");
349
350 return 0;
351}
352
353static void usb251xb_get_ports_field(struct udevice *dev,
354 const char *prop_name, u8 port_cnt,
355 bool ds_only, u8 *fld)
356{
357 u32 i, port;
358 int ret;
359
360 for (i = 0; i < port_cnt; i++) {
361 ret = dev_read_u32_index(dev, prop_name, i, &port);
362 if (ret)
363 continue;
364 if (port >= ds_only ? 1 : 0 && port <= port_cnt)
365 *fld |= BIT(port);
366 else
367 dev_warn(dev, "port %u doesn't exist\n", port);
368 }
369}
370
371static int usb251xb_of_to_plat(struct udevice *dev)
372{
373 struct usb251xb_data *data =
374 (struct usb251xb_data *)dev_get_driver_data(dev);
375 struct usb251xb *hub = dev_get_priv(dev);
376 char str[USB251XB_STRING_BUFSIZE / 2];
377 const char *cproperty_char;
378 u32 property_u32 = 0;
379 int len, err;
380
381 if (dev_read_bool(dev, "skip-config"))
382 hub->skip_config = 1;
383 else
384 hub->skip_config = 0;
385
386 err = gpio_request_by_name(dev, "reset-gpios", 0, &hub->gpio_reset,
387 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
388 if (err && err != -ENOENT) {
389 dev_err(dev, "unable to request GPIO reset pin (%d)\n", err);
390 return err;
391 }
392
Marek Vasuta0ec4762023-02-28 02:55:18 +0100393 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
Marek Vasut16637b42022-04-10 06:27:14 +0200394 err = device_get_supply_regulator(dev, "vdd-supply",
395 &hub->vdd);
396 if (err && err != -ENOENT) {
397 dev_err(dev, "Warning: cannot get power supply\n");
398 return err;
399 }
400 }
401
Stefan Herbrechtsmeiercbd45092022-06-14 15:21:31 +0200402 hub->vendor_id = dev_read_u16_default(dev, "vendor-id",
403 USB251XB_DEF_VENDOR_ID);
Marek Vasut16637b42022-04-10 06:27:14 +0200404
Stefan Herbrechtsmeiercbd45092022-06-14 15:21:31 +0200405 hub->product_id = dev_read_u16_default(dev, "product-id",
406 data->product_id);
Marek Vasut16637b42022-04-10 06:27:14 +0200407
Stefan Herbrechtsmeiercbd45092022-06-14 15:21:31 +0200408 hub->device_id = dev_read_u16_default(dev, "device-id",
409 USB251XB_DEF_DEVICE_ID);
Marek Vasut16637b42022-04-10 06:27:14 +0200410
411 hub->conf_data1 = USB251XB_DEF_CONFIG_DATA_1;
412 if (dev_read_bool(dev, "self-powered")) {
413 hub->conf_data1 |= BIT(7);
414
415 /* Configure Over-Current sens when self-powered */
416 hub->conf_data1 &= ~BIT(2);
417 if (dev_read_bool(dev, "ganged-sensing"))
418 hub->conf_data1 &= ~BIT(1);
419 else if (dev_read_bool(dev, "individual-sensing"))
420 hub->conf_data1 |= BIT(1);
421 } else if (dev_read_bool(dev, "bus-powered")) {
422 hub->conf_data1 &= ~BIT(7);
423
424 /* Disable Over-Current sense when bus-powered */
425 hub->conf_data1 |= BIT(2);
426 }
427
428 if (dev_read_bool(dev, "disable-hi-speed"))
429 hub->conf_data1 |= BIT(5);
430
431 if (dev_read_bool(dev, "multi-tt"))
432 hub->conf_data1 |= BIT(4);
433 else if (dev_read_bool(dev, "single-tt"))
434 hub->conf_data1 &= ~BIT(4);
435
436 if (dev_read_bool(dev, "disable-eop"))
437 hub->conf_data1 |= BIT(3);
438
439 if (dev_read_bool(dev, "individual-port-switching"))
440 hub->conf_data1 |= BIT(0);
441 else if (dev_read_bool(dev, "ganged-port-switching"))
442 hub->conf_data1 &= ~BIT(0);
443
444 hub->conf_data2 = USB251XB_DEF_CONFIG_DATA_2;
445 if (dev_read_bool(dev, "dynamic-power-switching"))
446 hub->conf_data2 |= BIT(7);
447
448 if (!dev_read_u32(dev, "oc-delay-us", &property_u32)) {
449 if (property_u32 == 100) {
450 /* 100 us*/
451 hub->conf_data2 &= ~BIT(5);
452 hub->conf_data2 &= ~BIT(4);
453 } else if (property_u32 == 4000) {
454 /* 4 ms */
455 hub->conf_data2 &= ~BIT(5);
456 hub->conf_data2 |= BIT(4);
457 } else if (property_u32 == 16000) {
458 /* 16 ms */
459 hub->conf_data2 |= BIT(5);
460 hub->conf_data2 |= BIT(4);
461 } else {
462 /* 8 ms (DEFAULT) */
463 hub->conf_data2 |= BIT(5);
464 hub->conf_data2 &= ~BIT(4);
465 }
466 }
467
468 if (dev_read_bool(dev, "compound-device"))
469 hub->conf_data2 |= BIT(3);
470
471 hub->conf_data3 = USB251XB_DEF_CONFIG_DATA_3;
472 if (dev_read_bool(dev, "port-mapping-mode"))
473 hub->conf_data3 |= BIT(3);
474
475 if (data->led_support && dev_read_bool(dev, "led-usb-mode"))
476 hub->conf_data3 &= ~BIT(1);
477
478 if (dev_read_bool(dev, "string-support"))
479 hub->conf_data3 |= BIT(0);
480
481 hub->non_rem_dev = USB251XB_DEF_NON_REMOVABLE_DEVICES;
482 usb251xb_get_ports_field(dev, "non-removable-ports", data->port_cnt,
483 true, &hub->non_rem_dev);
484
485 hub->port_disable_sp = USB251XB_DEF_PORT_DISABLE_SELF;
486 usb251xb_get_ports_field(dev, "sp-disabled-ports", data->port_cnt,
487 true, &hub->port_disable_sp);
488
489 hub->port_disable_bp = USB251XB_DEF_PORT_DISABLE_BUS;
490 usb251xb_get_ports_field(dev, "bp-disabled-ports", data->port_cnt,
491 true, &hub->port_disable_bp);
492
493 hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF;
494 if (!dev_read_u32(dev, "sp-max-total-current-microamp", &property_u32))
495 hub->max_power_sp = min_t(u8, property_u32 / 2000, 50);
496
497 hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS;
498 if (!dev_read_u32(dev, "bp-max-total-current-microamp", &property_u32))
499 hub->max_power_bp = min_t(u8, property_u32 / 2000, 255);
500
501 hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF;
502 if (!dev_read_u32(dev, "sp-max-removable-current-microamp",
503 &property_u32))
504 hub->max_current_sp = min_t(u8, property_u32 / 2000, 50);
505
506 hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS;
507 if (!dev_read_u32(dev, "bp-max-removable-current-microamp",
508 &property_u32))
509 hub->max_current_bp = min_t(u8, property_u32 / 2000, 255);
510
511 hub->power_on_time = USB251XB_DEF_POWER_ON_TIME;
512 if (!dev_read_u32(dev, "power-on-time-ms", &property_u32))
513 hub->power_on_time = min_t(u8, property_u32 / 2, 255);
514
Stefan Herbrechtsmeiercbd45092022-06-14 15:21:31 +0200515 hub->lang_id = dev_read_u16_default(dev, "language-id",
516 USB251XB_DEF_LANGUAGE_ID);
Marek Vasut16637b42022-04-10 06:27:14 +0200517
Stefan Herbrechtsmeiercbd45092022-06-14 15:21:31 +0200518 hub->boost_up = dev_read_u8_default(dev, "boost-up",
519 USB251XB_DEF_BOOST_UP);
Marek Vasut16637b42022-04-10 06:27:14 +0200520
521 cproperty_char = dev_read_string(dev, "manufacturer");
522 strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
523 sizeof(str));
524 hub->manufacturer_len = strlen(str) & 0xFF;
525 memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE);
526 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
527 len = utf8_to_utf16le(str, hub->manufacturer, len);
528
529 cproperty_char = dev_read_string(dev, "product");
530 strlcpy(str, cproperty_char ? : data->product_str, sizeof(str));
531 hub->product_len = strlen(str) & 0xFF;
532 memset(hub->product, 0, USB251XB_STRING_BUFSIZE);
533 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
534 len = utf8_to_utf16le(str, hub->product, len);
535
536 cproperty_char = dev_read_string(dev, "serial");
537 strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
538 sizeof(str));
539 hub->serial_len = strlen(str) & 0xFF;
540 memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
541 len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
542 len = utf8_to_utf16le(str, hub->serial, len);
543
544 /*
545 * The datasheet documents the register as 'Port Swap' but in real the
546 * register controls the USB DP/DM signal swapping for each port.
547 */
548 hub->port_swap = USB251XB_DEF_PORT_SWAP;
549 usb251xb_get_ports_field(dev, "swap-dx-lanes", data->port_cnt,
550 false, &hub->port_swap);
551
552 /* The following parameters are currently not exposed to devicetree, but
553 * may be as soon as needed.
554 */
555 hub->bat_charge_en = USB251XB_DEF_BATTERY_CHARGING_ENABLE;
556 hub->boost_57 = USB251XB_DEF_BOOST_57;
557 hub->boost_14 = USB251XB_DEF_BOOST_14;
558 hub->port_map12 = USB251XB_DEF_PORT_MAP_12;
559 hub->port_map34 = USB251XB_DEF_PORT_MAP_34;
560 hub->port_map56 = USB251XB_DEF_PORT_MAP_56;
561 hub->port_map7 = USB251XB_DEF_PORT_MAP_7;
562
563 return 0;
564}
565
566static const struct udevice_id usb251xb_of_match[] = {
567 {
568 .compatible = "microchip,usb2422",
569 .data = (ulong)&usb2422_data,
570 }, {
571 .compatible = "microchip,usb2512b",
572 .data = (ulong)&usb2512b_data,
573 }, {
574 .compatible = "microchip,usb2512bi",
575 .data = (ulong)&usb2512bi_data,
576 }, {
577 .compatible = "microchip,usb2513b",
578 .data = (ulong)&usb2513b_data,
579 }, {
580 .compatible = "microchip,usb2513bi",
581 .data = (ulong)&usb2513bi_data,
582 }, {
583 .compatible = "microchip,usb2514b",
584 .data = (ulong)&usb2514b_data,
585 }, {
586 .compatible = "microchip,usb2514bi",
587 .data = (ulong)&usb2514bi_data,
588 }, {
589 .compatible = "microchip,usb2517",
590 .data = (ulong)&usb2517_data,
591 }, {
592 .compatible = "microchip,usb2517i",
593 .data = (ulong)&usb2517i_data,
594 }
595};
596
597U_BOOT_DRIVER(usb251xb) = {
598 .name = "usb251xb",
599 .id = UCLASS_MISC,
600 .of_match = usb251xb_of_match,
601 .of_to_plat = usb251xb_of_to_plat,
602 .probe = usb251xb_probe,
603 .priv_auto = sizeof(struct usb251xb),
604};