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