Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 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/ |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/delay.h> |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 14 | #include <linux/gpio/consumer.h> |
Serge Semin | 6e3c8be | 2019-04-24 17:49:14 +0300 | [diff] [blame] | 15 | #include <linux/gpio/driver.h> |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 16 | #include <linux/i2c.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/nls.h> |
| 19 | #include <linux/of_device.h> |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 20 | #include <linux/slab.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 | #define USB251XB_DEF_PRODUCT_ID_12 0x2512 /* USB2512B/12Bi */ |
| 30 | #define USB251XB_DEF_PRODUCT_ID_13 0x2513 /* USB2513B/13Bi */ |
| 31 | #define USB251XB_DEF_PRODUCT_ID_14 0x2514 /* USB2514B/14Bi */ |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 32 | #define USB251XB_DEF_PRODUCT_ID_17 0x2517 /* USB2517/17i */ |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 33 | |
| 34 | #define USB251XB_ADDR_DEVICE_ID_LSB 0x04 |
| 35 | #define USB251XB_ADDR_DEVICE_ID_MSB 0x05 |
| 36 | #define USB251XB_DEF_DEVICE_ID 0x0BB3 |
| 37 | |
| 38 | #define USB251XB_ADDR_CONFIG_DATA_1 0x06 |
| 39 | #define USB251XB_DEF_CONFIG_DATA_1 0x9B |
| 40 | #define USB251XB_ADDR_CONFIG_DATA_2 0x07 |
| 41 | #define USB251XB_DEF_CONFIG_DATA_2 0x20 |
| 42 | #define USB251XB_ADDR_CONFIG_DATA_3 0x08 |
| 43 | #define USB251XB_DEF_CONFIG_DATA_3 0x02 |
| 44 | |
| 45 | #define USB251XB_ADDR_NON_REMOVABLE_DEVICES 0x09 |
| 46 | #define USB251XB_DEF_NON_REMOVABLE_DEVICES 0x00 |
| 47 | |
| 48 | #define USB251XB_ADDR_PORT_DISABLE_SELF 0x0A |
| 49 | #define USB251XB_DEF_PORT_DISABLE_SELF 0x00 |
| 50 | #define USB251XB_ADDR_PORT_DISABLE_BUS 0x0B |
| 51 | #define USB251XB_DEF_PORT_DISABLE_BUS 0x00 |
| 52 | |
| 53 | #define USB251XB_ADDR_MAX_POWER_SELF 0x0C |
| 54 | #define USB251XB_DEF_MAX_POWER_SELF 0x01 |
| 55 | #define USB251XB_ADDR_MAX_POWER_BUS 0x0D |
| 56 | #define USB251XB_DEF_MAX_POWER_BUS 0x32 |
| 57 | |
| 58 | #define USB251XB_ADDR_MAX_CURRENT_SELF 0x0E |
| 59 | #define USB251XB_DEF_MAX_CURRENT_SELF 0x01 |
| 60 | #define USB251XB_ADDR_MAX_CURRENT_BUS 0x0F |
| 61 | #define USB251XB_DEF_MAX_CURRENT_BUS 0x32 |
| 62 | |
| 63 | #define USB251XB_ADDR_POWER_ON_TIME 0x10 |
| 64 | #define USB251XB_DEF_POWER_ON_TIME 0x32 |
| 65 | |
| 66 | #define USB251XB_ADDR_LANGUAGE_ID_HIGH 0x11 |
| 67 | #define USB251XB_ADDR_LANGUAGE_ID_LOW 0x12 |
| 68 | #define USB251XB_DEF_LANGUAGE_ID 0x0000 |
| 69 | |
| 70 | #define USB251XB_STRING_BUFSIZE 62 |
| 71 | #define USB251XB_ADDR_MANUFACTURER_STRING_LEN 0x13 |
| 72 | #define USB251XB_ADDR_MANUFACTURER_STRING 0x16 |
| 73 | #define USB251XB_DEF_MANUFACTURER_STRING "Microchip" |
| 74 | |
| 75 | #define USB251XB_ADDR_PRODUCT_STRING_LEN 0x14 |
| 76 | #define USB251XB_ADDR_PRODUCT_STRING 0x54 |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 77 | #define USB251XB_DEF_PRODUCT_STRING "USB251xB/xBi/7i" |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 78 | |
| 79 | #define USB251XB_ADDR_SERIAL_STRING_LEN 0x15 |
| 80 | #define USB251XB_ADDR_SERIAL_STRING 0x92 |
| 81 | #define USB251XB_DEF_SERIAL_STRING "" |
| 82 | |
| 83 | #define USB251XB_ADDR_BATTERY_CHARGING_ENABLE 0xD0 |
| 84 | #define USB251XB_DEF_BATTERY_CHARGING_ENABLE 0x00 |
| 85 | |
| 86 | #define USB251XB_ADDR_BOOST_UP 0xF6 |
| 87 | #define USB251XB_DEF_BOOST_UP 0x00 |
Serge Semin | ccdddc0 | 2017-10-22 23:38:07 +0300 | [diff] [blame] | 88 | #define USB251XB_ADDR_BOOST_57 0xF7 |
| 89 | #define USB251XB_DEF_BOOST_57 0x00 |
| 90 | #define USB251XB_ADDR_BOOST_14 0xF8 |
| 91 | #define USB251XB_DEF_BOOST_14 0x00 |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 92 | |
| 93 | #define USB251XB_ADDR_PORT_SWAP 0xFA |
| 94 | #define USB251XB_DEF_PORT_SWAP 0x00 |
| 95 | |
| 96 | #define USB251XB_ADDR_PORT_MAP_12 0xFB |
| 97 | #define USB251XB_DEF_PORT_MAP_12 0x00 |
| 98 | #define USB251XB_ADDR_PORT_MAP_34 0xFC |
Serge Semin | db234b9 | 2017-10-22 23:38:06 +0300 | [diff] [blame] | 99 | #define USB251XB_DEF_PORT_MAP_34 0x00 /* USB251{3B/i,4B/i,7/i} only */ |
| 100 | #define USB251XB_ADDR_PORT_MAP_56 0xFD |
| 101 | #define USB251XB_DEF_PORT_MAP_56 0x00 /* USB2517/i only */ |
| 102 | #define USB251XB_ADDR_PORT_MAP_7 0xFE |
| 103 | #define USB251XB_DEF_PORT_MAP_7 0x00 /* USB2517/i only */ |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 104 | |
| 105 | #define USB251XB_ADDR_STATUS_COMMAND 0xFF |
| 106 | #define USB251XB_STATUS_COMMAND_SMBUS_DOWN 0x04 |
| 107 | #define USB251XB_STATUS_COMMAND_RESET 0x02 |
| 108 | #define USB251XB_STATUS_COMMAND_ATTACH 0x01 |
| 109 | |
| 110 | #define USB251XB_I2C_REG_SZ 0x100 |
| 111 | #define USB251XB_I2C_WRITE_SZ 0x10 |
| 112 | |
| 113 | #define DRIVER_NAME "usb251xb" |
| 114 | #define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller" |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 115 | |
| 116 | struct usb251xb { |
| 117 | struct device *dev; |
| 118 | struct i2c_client *i2c; |
| 119 | u8 skip_config; |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 120 | struct gpio_desc *gpio_reset; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 121 | u16 vendor_id; |
| 122 | u16 product_id; |
| 123 | u16 device_id; |
| 124 | u8 conf_data1; |
| 125 | u8 conf_data2; |
| 126 | u8 conf_data3; |
| 127 | u8 non_rem_dev; |
| 128 | u8 port_disable_sp; |
| 129 | u8 port_disable_bp; |
| 130 | u8 max_power_sp; |
| 131 | u8 max_power_bp; |
| 132 | u8 max_current_sp; |
| 133 | u8 max_current_bp; |
| 134 | u8 power_on_time; |
| 135 | u16 lang_id; |
| 136 | u8 manufacturer_len; |
| 137 | u8 product_len; |
| 138 | u8 serial_len; |
| 139 | char manufacturer[USB251XB_STRING_BUFSIZE]; |
| 140 | char product[USB251XB_STRING_BUFSIZE]; |
| 141 | char serial[USB251XB_STRING_BUFSIZE]; |
| 142 | u8 bat_charge_en; |
| 143 | u8 boost_up; |
Serge Semin | ccdddc0 | 2017-10-22 23:38:07 +0300 | [diff] [blame] | 144 | u8 boost_57; |
| 145 | u8 boost_14; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 146 | u8 port_swap; |
| 147 | u8 port_map12; |
| 148 | u8 port_map34; |
Serge Semin | db234b9 | 2017-10-22 23:38:06 +0300 | [diff] [blame] | 149 | u8 port_map56; |
| 150 | u8 port_map7; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 151 | u8 status; |
| 152 | }; |
| 153 | |
| 154 | struct usb251xb_data { |
| 155 | u16 product_id; |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 156 | u8 port_cnt; |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 157 | bool led_support; |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 158 | bool bat_support; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 159 | char product_str[USB251XB_STRING_BUFSIZE / 2]; /* ASCII string */ |
| 160 | }; |
| 161 | |
| 162 | static const struct usb251xb_data usb2512b_data = { |
| 163 | .product_id = 0x2512, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 164 | .port_cnt = 2, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 165 | .led_support = false, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 166 | .bat_support = true, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 167 | .product_str = "USB2512B", |
| 168 | }; |
| 169 | |
| 170 | static const struct usb251xb_data usb2512bi_data = { |
| 171 | .product_id = 0x2512, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 172 | .port_cnt = 2, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 173 | .led_support = false, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 174 | .bat_support = true, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 175 | .product_str = "USB2512Bi", |
| 176 | }; |
| 177 | |
| 178 | static const struct usb251xb_data usb2513b_data = { |
| 179 | .product_id = 0x2513, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 180 | .port_cnt = 3, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 181 | .led_support = false, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 182 | .bat_support = true, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 183 | .product_str = "USB2513B", |
| 184 | }; |
| 185 | |
| 186 | static const struct usb251xb_data usb2513bi_data = { |
| 187 | .product_id = 0x2513, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 188 | .port_cnt = 3, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 189 | .led_support = false, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 190 | .bat_support = true, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 191 | .product_str = "USB2513Bi", |
| 192 | }; |
| 193 | |
| 194 | static const struct usb251xb_data usb2514b_data = { |
| 195 | .product_id = 0x2514, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 196 | .port_cnt = 4, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 197 | .led_support = false, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 198 | .bat_support = true, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 199 | .product_str = "USB2514B", |
| 200 | }; |
| 201 | |
| 202 | static const struct usb251xb_data usb2514bi_data = { |
| 203 | .product_id = 0x2514, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 204 | .port_cnt = 4, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 205 | .led_support = false, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 206 | .bat_support = true, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 207 | .product_str = "USB2514Bi", |
| 208 | }; |
| 209 | |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 210 | static const struct usb251xb_data usb2517_data = { |
| 211 | .product_id = 0x2517, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 212 | .port_cnt = 7, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 213 | .led_support = true, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 214 | .bat_support = false, |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 215 | .product_str = "USB2517", |
| 216 | }; |
| 217 | |
| 218 | static const struct usb251xb_data usb2517i_data = { |
| 219 | .product_id = 0x2517, |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 220 | .port_cnt = 7, |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 221 | .led_support = true, |
Serge Semin | dd99d10 | 2017-10-22 23:38:08 +0300 | [diff] [blame] | 222 | .bat_support = false, |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 223 | .product_str = "USB2517i", |
| 224 | }; |
| 225 | |
Serge Semin | 95e060e | 2019-04-27 12:06:44 +0300 | [diff] [blame^] | 226 | #ifdef CONFIG_GPIOLIB |
Serge Semin | 6e3c8be | 2019-04-24 17:49:14 +0300 | [diff] [blame] | 227 | static int usb251xb_check_dev_children(struct device *dev, void *child) |
| 228 | { |
| 229 | if (dev->type == &i2c_adapter_type) { |
| 230 | return device_for_each_child(dev, child, |
| 231 | usb251xb_check_dev_children); |
| 232 | } |
| 233 | |
| 234 | return (dev == child); |
| 235 | } |
| 236 | |
| 237 | static int usb251x_check_gpio_chip(struct usb251xb *hub) |
| 238 | { |
| 239 | struct gpio_chip *gc = gpiod_to_chip(hub->gpio_reset); |
| 240 | struct i2c_adapter *adap = hub->i2c->adapter; |
| 241 | int ret; |
| 242 | |
| 243 | if (!hub->gpio_reset) |
| 244 | return 0; |
| 245 | |
| 246 | if (!gc) |
| 247 | return -EINVAL; |
| 248 | |
| 249 | ret = usb251xb_check_dev_children(&adap->dev, gc->parent); |
| 250 | if (ret) { |
| 251 | dev_err(hub->dev, "Reset GPIO chip is at the same i2c-bus\n"); |
| 252 | return -EINVAL; |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | } |
Serge Semin | 95e060e | 2019-04-27 12:06:44 +0300 | [diff] [blame^] | 257 | #else |
| 258 | static int usb251x_check_gpio_chip(struct usb251xb *hub) |
| 259 | { |
| 260 | return 0; |
| 261 | } |
| 262 | #endif |
Serge Semin | 6e3c8be | 2019-04-24 17:49:14 +0300 | [diff] [blame] | 263 | |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 264 | static void usb251xb_reset(struct usb251xb *hub, int state) |
| 265 | { |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 266 | if (!hub->gpio_reset) |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 267 | return; |
| 268 | |
Serge Semin | 6e3c8be | 2019-04-24 17:49:14 +0300 | [diff] [blame] | 269 | i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); |
| 270 | |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 271 | gpiod_set_value_cansleep(hub->gpio_reset, state); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 272 | |
| 273 | /* wait for hub recovery/stabilization */ |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 274 | if (!state) |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 275 | usleep_range(500, 750); /* >=500us at power on */ |
| 276 | else |
| 277 | usleep_range(1, 10); /* >=1us at power down */ |
Serge Semin | 6e3c8be | 2019-04-24 17:49:14 +0300 | [diff] [blame] | 278 | |
| 279 | i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static int usb251xb_connect(struct usb251xb *hub) |
| 283 | { |
| 284 | struct device *dev = hub->dev; |
| 285 | int err, i; |
| 286 | char i2c_wb[USB251XB_I2C_REG_SZ]; |
| 287 | |
| 288 | memset(i2c_wb, 0, USB251XB_I2C_REG_SZ); |
| 289 | |
| 290 | if (hub->skip_config) { |
| 291 | dev_info(dev, "Skip hub configuration, only attach.\n"); |
| 292 | i2c_wb[0] = 0x01; |
| 293 | i2c_wb[1] = USB251XB_STATUS_COMMAND_ATTACH; |
| 294 | |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 295 | usb251xb_reset(hub, 0); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 296 | |
| 297 | err = i2c_smbus_write_i2c_block_data(hub->i2c, |
| 298 | USB251XB_ADDR_STATUS_COMMAND, 2, i2c_wb); |
| 299 | if (err) { |
| 300 | dev_err(dev, "attaching hub failed: %d\n", err); |
| 301 | return err; |
| 302 | } |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | i2c_wb[USB251XB_ADDR_VENDOR_ID_MSB] = (hub->vendor_id >> 8) & 0xFF; |
| 307 | i2c_wb[USB251XB_ADDR_VENDOR_ID_LSB] = hub->vendor_id & 0xFF; |
| 308 | i2c_wb[USB251XB_ADDR_PRODUCT_ID_MSB] = (hub->product_id >> 8) & 0xFF; |
| 309 | i2c_wb[USB251XB_ADDR_PRODUCT_ID_LSB] = hub->product_id & 0xFF; |
| 310 | i2c_wb[USB251XB_ADDR_DEVICE_ID_MSB] = (hub->device_id >> 8) & 0xFF; |
| 311 | i2c_wb[USB251XB_ADDR_DEVICE_ID_LSB] = hub->device_id & 0xFF; |
| 312 | i2c_wb[USB251XB_ADDR_CONFIG_DATA_1] = hub->conf_data1; |
| 313 | i2c_wb[USB251XB_ADDR_CONFIG_DATA_2] = hub->conf_data2; |
| 314 | i2c_wb[USB251XB_ADDR_CONFIG_DATA_3] = hub->conf_data3; |
| 315 | i2c_wb[USB251XB_ADDR_NON_REMOVABLE_DEVICES] = hub->non_rem_dev; |
| 316 | i2c_wb[USB251XB_ADDR_PORT_DISABLE_SELF] = hub->port_disable_sp; |
| 317 | i2c_wb[USB251XB_ADDR_PORT_DISABLE_BUS] = hub->port_disable_bp; |
| 318 | i2c_wb[USB251XB_ADDR_MAX_POWER_SELF] = hub->max_power_sp; |
| 319 | i2c_wb[USB251XB_ADDR_MAX_POWER_BUS] = hub->max_power_bp; |
| 320 | i2c_wb[USB251XB_ADDR_MAX_CURRENT_SELF] = hub->max_current_sp; |
| 321 | i2c_wb[USB251XB_ADDR_MAX_CURRENT_BUS] = hub->max_current_bp; |
| 322 | i2c_wb[USB251XB_ADDR_POWER_ON_TIME] = hub->power_on_time; |
| 323 | i2c_wb[USB251XB_ADDR_LANGUAGE_ID_HIGH] = (hub->lang_id >> 8) & 0xFF; |
| 324 | i2c_wb[USB251XB_ADDR_LANGUAGE_ID_LOW] = hub->lang_id & 0xFF; |
| 325 | i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING_LEN] = hub->manufacturer_len; |
| 326 | i2c_wb[USB251XB_ADDR_PRODUCT_STRING_LEN] = hub->product_len; |
| 327 | i2c_wb[USB251XB_ADDR_SERIAL_STRING_LEN] = hub->serial_len; |
| 328 | memcpy(&i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING], hub->manufacturer, |
| 329 | USB251XB_STRING_BUFSIZE); |
| 330 | memcpy(&i2c_wb[USB251XB_ADDR_SERIAL_STRING], hub->serial, |
| 331 | USB251XB_STRING_BUFSIZE); |
| 332 | memcpy(&i2c_wb[USB251XB_ADDR_PRODUCT_STRING], hub->product, |
| 333 | USB251XB_STRING_BUFSIZE); |
| 334 | i2c_wb[USB251XB_ADDR_BATTERY_CHARGING_ENABLE] = hub->bat_charge_en; |
| 335 | i2c_wb[USB251XB_ADDR_BOOST_UP] = hub->boost_up; |
Serge Semin | ccdddc0 | 2017-10-22 23:38:07 +0300 | [diff] [blame] | 336 | i2c_wb[USB251XB_ADDR_BOOST_57] = hub->boost_57; |
| 337 | i2c_wb[USB251XB_ADDR_BOOST_14] = hub->boost_14; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 338 | i2c_wb[USB251XB_ADDR_PORT_SWAP] = hub->port_swap; |
| 339 | i2c_wb[USB251XB_ADDR_PORT_MAP_12] = hub->port_map12; |
| 340 | i2c_wb[USB251XB_ADDR_PORT_MAP_34] = hub->port_map34; |
Serge Semin | db234b9 | 2017-10-22 23:38:06 +0300 | [diff] [blame] | 341 | i2c_wb[USB251XB_ADDR_PORT_MAP_56] = hub->port_map56; |
| 342 | i2c_wb[USB251XB_ADDR_PORT_MAP_7] = hub->port_map7; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 343 | i2c_wb[USB251XB_ADDR_STATUS_COMMAND] = USB251XB_STATUS_COMMAND_ATTACH; |
| 344 | |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 345 | usb251xb_reset(hub, 0); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 346 | |
| 347 | /* write registers */ |
| 348 | for (i = 0; i < (USB251XB_I2C_REG_SZ / USB251XB_I2C_WRITE_SZ); i++) { |
| 349 | int offset = i * USB251XB_I2C_WRITE_SZ; |
| 350 | char wbuf[USB251XB_I2C_WRITE_SZ + 1]; |
| 351 | |
| 352 | /* The first data byte transferred tells the hub how many data |
| 353 | * bytes will follow (byte count). |
| 354 | */ |
| 355 | wbuf[0] = USB251XB_I2C_WRITE_SZ; |
| 356 | memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ); |
| 357 | |
| 358 | dev_dbg(dev, "writing %d byte block %d to 0x%02X\n", |
| 359 | USB251XB_I2C_WRITE_SZ, i, offset); |
| 360 | |
| 361 | err = i2c_smbus_write_i2c_block_data(hub->i2c, offset, |
| 362 | USB251XB_I2C_WRITE_SZ + 1, |
| 363 | wbuf); |
| 364 | if (err) |
| 365 | goto out_err; |
| 366 | } |
| 367 | |
| 368 | dev_info(dev, "Hub configuration was successful.\n"); |
| 369 | return 0; |
| 370 | |
| 371 | out_err: |
| 372 | dev_err(dev, "configuring block %d failed: %d\n", i, err); |
| 373 | return err; |
| 374 | } |
| 375 | |
| 376 | #ifdef CONFIG_OF |
| 377 | static int usb251xb_get_ofdata(struct usb251xb *hub, |
| 378 | struct usb251xb_data *data) |
| 379 | { |
| 380 | struct device *dev = hub->dev; |
| 381 | struct device_node *np = dev->of_node; |
| 382 | int len, err, i; |
Marco Felsch | 02a50b8 | 2019-01-16 15:20:37 +0100 | [diff] [blame] | 383 | u32 port, property_u32 = 0; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 384 | const u32 *cproperty_u32; |
| 385 | const char *cproperty_char; |
| 386 | char str[USB251XB_STRING_BUFSIZE / 2]; |
Marco Felsch | 02a50b8 | 2019-01-16 15:20:37 +0100 | [diff] [blame] | 387 | struct property *prop; |
| 388 | const __be32 *p; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 389 | |
| 390 | if (!np) { |
| 391 | dev_err(dev, "failed to get ofdata\n"); |
| 392 | return -ENODEV; |
| 393 | } |
| 394 | |
| 395 | if (of_get_property(np, "skip-config", NULL)) |
| 396 | hub->skip_config = 1; |
| 397 | else |
| 398 | hub->skip_config = 0; |
| 399 | |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 400 | hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); |
| 401 | if (PTR_ERR(hub->gpio_reset) == -EPROBE_DEFER) { |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 402 | return -EPROBE_DEFER; |
Serge Semin | 69a0c69 | 2017-10-22 23:38:12 +0300 | [diff] [blame] | 403 | } else if (IS_ERR(hub->gpio_reset)) { |
| 404 | err = PTR_ERR(hub->gpio_reset); |
| 405 | dev_err(dev, "unable to request GPIO reset pin (%d)\n", err); |
| 406 | return err; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1)) |
| 410 | hub->vendor_id = USB251XB_DEF_VENDOR_ID; |
| 411 | |
| 412 | if (of_property_read_u16_array(np, "product-id", |
| 413 | &hub->product_id, 1)) |
| 414 | hub->product_id = data->product_id; |
| 415 | |
| 416 | if (of_property_read_u16_array(np, "device-id", &hub->device_id, 1)) |
| 417 | hub->device_id = USB251XB_DEF_DEVICE_ID; |
| 418 | |
| 419 | hub->conf_data1 = USB251XB_DEF_CONFIG_DATA_1; |
| 420 | if (of_get_property(np, "self-powered", NULL)) { |
| 421 | hub->conf_data1 |= BIT(7); |
| 422 | |
| 423 | /* Configure Over-Current sens when self-powered */ |
| 424 | hub->conf_data1 &= ~BIT(2); |
| 425 | if (of_get_property(np, "ganged-sensing", NULL)) |
| 426 | hub->conf_data1 &= ~BIT(1); |
| 427 | else if (of_get_property(np, "individual-sensing", NULL)) |
| 428 | hub->conf_data1 |= BIT(1); |
| 429 | } else if (of_get_property(np, "bus-powered", NULL)) { |
| 430 | hub->conf_data1 &= ~BIT(7); |
| 431 | |
| 432 | /* Disable Over-Current sense when bus-powered */ |
| 433 | hub->conf_data1 |= BIT(2); |
| 434 | } |
| 435 | |
| 436 | if (of_get_property(np, "disable-hi-speed", NULL)) |
| 437 | hub->conf_data1 |= BIT(5); |
| 438 | |
| 439 | if (of_get_property(np, "multi-tt", NULL)) |
| 440 | hub->conf_data1 |= BIT(4); |
| 441 | else if (of_get_property(np, "single-tt", NULL)) |
| 442 | hub->conf_data1 &= ~BIT(4); |
| 443 | |
| 444 | if (of_get_property(np, "disable-eop", NULL)) |
| 445 | hub->conf_data1 |= BIT(3); |
| 446 | |
| 447 | if (of_get_property(np, "individual-port-switching", NULL)) |
| 448 | hub->conf_data1 |= BIT(0); |
| 449 | else if (of_get_property(np, "ganged-port-switching", NULL)) |
| 450 | hub->conf_data1 &= ~BIT(0); |
| 451 | |
| 452 | hub->conf_data2 = USB251XB_DEF_CONFIG_DATA_2; |
| 453 | if (of_get_property(np, "dynamic-power-switching", NULL)) |
| 454 | hub->conf_data2 |= BIT(7); |
| 455 | |
Serge Semin | 287c2bb | 2017-10-22 23:38:10 +0300 | [diff] [blame] | 456 | if (!of_property_read_u32(np, "oc-delay-us", &property_u32)) { |
| 457 | if (property_u32 == 100) { |
Richard Leitner | 7f7d8ba | 2017-03-06 09:24:21 +0100 | [diff] [blame] | 458 | /* 100 us*/ |
| 459 | hub->conf_data2 &= ~BIT(5); |
| 460 | hub->conf_data2 &= ~BIT(4); |
Serge Semin | 287c2bb | 2017-10-22 23:38:10 +0300 | [diff] [blame] | 461 | } else if (property_u32 == 4000) { |
Richard Leitner | 7f7d8ba | 2017-03-06 09:24:21 +0100 | [diff] [blame] | 462 | /* 4 ms */ |
| 463 | hub->conf_data2 &= ~BIT(5); |
| 464 | hub->conf_data2 |= BIT(4); |
Serge Semin | 287c2bb | 2017-10-22 23:38:10 +0300 | [diff] [blame] | 465 | } else if (property_u32 == 16000) { |
Richard Leitner | 7f7d8ba | 2017-03-06 09:24:21 +0100 | [diff] [blame] | 466 | /* 16 ms */ |
| 467 | hub->conf_data2 |= BIT(5); |
| 468 | hub->conf_data2 |= BIT(4); |
| 469 | } else { |
| 470 | /* 8 ms (DEFAULT) */ |
| 471 | hub->conf_data2 |= BIT(5); |
| 472 | hub->conf_data2 &= ~BIT(4); |
| 473 | } |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | if (of_get_property(np, "compound-device", NULL)) |
| 477 | hub->conf_data2 |= BIT(3); |
| 478 | |
| 479 | hub->conf_data3 = USB251XB_DEF_CONFIG_DATA_3; |
| 480 | if (of_get_property(np, "port-mapping-mode", NULL)) |
| 481 | hub->conf_data3 |= BIT(3); |
| 482 | |
Serge Semin | 2818e13 | 2017-10-22 23:38:09 +0300 | [diff] [blame] | 483 | if (data->led_support && of_get_property(np, "led-usb-mode", NULL)) |
| 484 | hub->conf_data3 &= ~BIT(1); |
| 485 | |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 486 | if (of_get_property(np, "string-support", NULL)) |
| 487 | hub->conf_data3 |= BIT(0); |
| 488 | |
| 489 | hub->non_rem_dev = USB251XB_DEF_NON_REMOVABLE_DEVICES; |
| 490 | cproperty_u32 = of_get_property(np, "non-removable-ports", &len); |
| 491 | if (cproperty_u32 && (len / sizeof(u32)) > 0) { |
| 492 | for (i = 0; i < len / sizeof(u32); i++) { |
| 493 | u32 port = be32_to_cpu(cproperty_u32[i]); |
| 494 | |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 495 | if ((port >= 1) && (port <= data->port_cnt)) |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 496 | hub->non_rem_dev |= BIT(port); |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 497 | else |
| 498 | dev_warn(dev, "NRD port %u doesn't exist\n", |
| 499 | port); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | hub->port_disable_sp = USB251XB_DEF_PORT_DISABLE_SELF; |
| 504 | cproperty_u32 = of_get_property(np, "sp-disabled-ports", &len); |
| 505 | if (cproperty_u32 && (len / sizeof(u32)) > 0) { |
| 506 | for (i = 0; i < len / sizeof(u32); i++) { |
| 507 | u32 port = be32_to_cpu(cproperty_u32[i]); |
| 508 | |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 509 | if ((port >= 1) && (port <= data->port_cnt)) |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 510 | hub->port_disable_sp |= BIT(port); |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 511 | else |
| 512 | dev_warn(dev, "PDS port %u doesn't exist\n", |
| 513 | port); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | hub->port_disable_bp = USB251XB_DEF_PORT_DISABLE_BUS; |
| 518 | cproperty_u32 = of_get_property(np, "bp-disabled-ports", &len); |
| 519 | if (cproperty_u32 && (len / sizeof(u32)) > 0) { |
| 520 | for (i = 0; i < len / sizeof(u32); i++) { |
| 521 | u32 port = be32_to_cpu(cproperty_u32[i]); |
| 522 | |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 523 | if ((port >= 1) && (port <= data->port_cnt)) |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 524 | hub->port_disable_bp |= BIT(port); |
Serge Semin | 3848112 | 2017-10-22 23:38:05 +0300 | [diff] [blame] | 525 | else |
| 526 | dev_warn(dev, "PDB port %u doesn't exist\n", |
| 527 | port); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Serge Semin | 4ed466a | 2017-10-22 23:38:11 +0300 | [diff] [blame] | 531 | hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF; |
| 532 | if (!of_property_read_u32(np, "sp-max-total-current-microamp", |
| 533 | &property_u32)) |
| 534 | hub->max_power_sp = min_t(u8, property_u32 / 2000, 50); |
| 535 | |
| 536 | hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS; |
| 537 | if (!of_property_read_u32(np, "bp-max-total-current-microamp", |
| 538 | &property_u32)) |
| 539 | hub->max_power_bp = min_t(u8, property_u32 / 2000, 255); |
| 540 | |
| 541 | hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF; |
| 542 | if (!of_property_read_u32(np, "sp-max-removable-current-microamp", |
| 543 | &property_u32)) |
| 544 | hub->max_current_sp = min_t(u8, property_u32 / 2000, 50); |
| 545 | |
| 546 | hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS; |
| 547 | if (!of_property_read_u32(np, "bp-max-removable-current-microamp", |
| 548 | &property_u32)) |
| 549 | hub->max_current_bp = min_t(u8, property_u32 / 2000, 255); |
| 550 | |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 551 | hub->power_on_time = USB251XB_DEF_POWER_ON_TIME; |
Serge Semin | 287c2bb | 2017-10-22 23:38:10 +0300 | [diff] [blame] | 552 | if (!of_property_read_u32(np, "power-on-time-ms", &property_u32)) |
| 553 | hub->power_on_time = min_t(u8, property_u32 / 2, 255); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 554 | |
| 555 | if (of_property_read_u16_array(np, "language-id", &hub->lang_id, 1)) |
| 556 | hub->lang_id = USB251XB_DEF_LANGUAGE_ID; |
| 557 | |
| 558 | cproperty_char = of_get_property(np, "manufacturer", NULL); |
| 559 | strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING, |
| 560 | sizeof(str)); |
| 561 | hub->manufacturer_len = strlen(str) & 0xFF; |
| 562 | memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE); |
| 563 | len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str)); |
| 564 | len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN, |
| 565 | (wchar_t *)hub->manufacturer, |
| 566 | USB251XB_STRING_BUFSIZE); |
| 567 | |
| 568 | cproperty_char = of_get_property(np, "product", NULL); |
| 569 | strlcpy(str, cproperty_char ? : data->product_str, sizeof(str)); |
| 570 | hub->product_len = strlen(str) & 0xFF; |
| 571 | memset(hub->product, 0, USB251XB_STRING_BUFSIZE); |
| 572 | len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str)); |
| 573 | len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN, |
| 574 | (wchar_t *)hub->product, |
| 575 | USB251XB_STRING_BUFSIZE); |
| 576 | |
| 577 | cproperty_char = of_get_property(np, "serial", NULL); |
| 578 | strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING, |
| 579 | sizeof(str)); |
| 580 | hub->serial_len = strlen(str) & 0xFF; |
| 581 | memset(hub->serial, 0, USB251XB_STRING_BUFSIZE); |
| 582 | len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str)); |
| 583 | len = utf8s_to_utf16s(str, len, UTF16_LITTLE_ENDIAN, |
| 584 | (wchar_t *)hub->serial, |
| 585 | USB251XB_STRING_BUFSIZE); |
| 586 | |
Marco Felsch | 02a50b8 | 2019-01-16 15:20:37 +0100 | [diff] [blame] | 587 | /* |
| 588 | * The datasheet documents the register as 'Port Swap' but in real the |
| 589 | * register controls the USB DP/DM signal swapping for each port. |
| 590 | */ |
| 591 | hub->port_swap = USB251XB_DEF_PORT_SWAP; |
| 592 | of_property_for_each_u32(np, "swap-dx-lanes", prop, p, port) { |
Gustavo A. R. Silva | 22feda4 | 2019-03-18 09:50:24 -0500 | [diff] [blame] | 593 | if (port <= data->port_cnt) |
Marco Felsch | 02a50b8 | 2019-01-16 15:20:37 +0100 | [diff] [blame] | 594 | hub->port_swap |= BIT(port); |
| 595 | } |
| 596 | |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 597 | /* The following parameters are currently not exposed to devicetree, but |
| 598 | * may be as soon as needed. |
| 599 | */ |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 600 | hub->bat_charge_en = USB251XB_DEF_BATTERY_CHARGING_ENABLE; |
| 601 | hub->boost_up = USB251XB_DEF_BOOST_UP; |
Serge Semin | ccdddc0 | 2017-10-22 23:38:07 +0300 | [diff] [blame] | 602 | hub->boost_57 = USB251XB_DEF_BOOST_57; |
| 603 | hub->boost_14 = USB251XB_DEF_BOOST_14; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 604 | hub->port_map12 = USB251XB_DEF_PORT_MAP_12; |
| 605 | hub->port_map34 = USB251XB_DEF_PORT_MAP_34; |
Serge Semin | db234b9 | 2017-10-22 23:38:06 +0300 | [diff] [blame] | 606 | hub->port_map56 = USB251XB_DEF_PORT_MAP_56; |
| 607 | hub->port_map7 = USB251XB_DEF_PORT_MAP_7; |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static const struct of_device_id usb251xb_of_match[] = { |
| 613 | { |
| 614 | .compatible = "microchip,usb2512b", |
| 615 | .data = &usb2512b_data, |
| 616 | }, { |
| 617 | .compatible = "microchip,usb2512bi", |
| 618 | .data = &usb2512bi_data, |
| 619 | }, { |
| 620 | .compatible = "microchip,usb2513b", |
| 621 | .data = &usb2513b_data, |
| 622 | }, { |
| 623 | .compatible = "microchip,usb2513bi", |
| 624 | .data = &usb2513bi_data, |
| 625 | }, { |
| 626 | .compatible = "microchip,usb2514b", |
| 627 | .data = &usb2514b_data, |
| 628 | }, { |
| 629 | .compatible = "microchip,usb2514bi", |
| 630 | .data = &usb2514bi_data, |
| 631 | }, { |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 632 | .compatible = "microchip,usb2517", |
| 633 | .data = &usb2517_data, |
| 634 | }, { |
| 635 | .compatible = "microchip,usb2517i", |
| 636 | .data = &usb2517i_data, |
| 637 | }, { |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 638 | /* sentinel */ |
| 639 | } |
| 640 | }; |
| 641 | MODULE_DEVICE_TABLE(of, usb251xb_of_match); |
| 642 | #else /* CONFIG_OF */ |
| 643 | static int usb251xb_get_ofdata(struct usb251xb *hub, |
| 644 | struct usb251xb_data *data) |
| 645 | { |
| 646 | return 0; |
| 647 | } |
| 648 | #endif /* CONFIG_OF */ |
| 649 | |
| 650 | static int usb251xb_probe(struct usb251xb *hub) |
| 651 | { |
| 652 | struct device *dev = hub->dev; |
| 653 | struct device_node *np = dev->of_node; |
| 654 | const struct of_device_id *of_id = of_match_device(usb251xb_of_match, |
| 655 | dev); |
| 656 | int err; |
| 657 | |
Aditya Pakki | 41f00e6 | 2019-03-20 10:27:11 -0500 | [diff] [blame] | 658 | if (np && of_id) { |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 659 | err = usb251xb_get_ofdata(hub, |
| 660 | (struct usb251xb_data *)of_id->data); |
| 661 | if (err) { |
| 662 | dev_err(dev, "failed to get ofdata: %d\n", err); |
| 663 | return err; |
| 664 | } |
| 665 | } |
| 666 | |
Serge Semin | 6e3c8be | 2019-04-24 17:49:14 +0300 | [diff] [blame] | 667 | /* |
| 668 | * usb251x SMBus-slave SCL lane is muxed with CFG_SEL0 pin. So if anyone |
| 669 | * tries to work with the bus at the moment the hub reset is released, |
| 670 | * it may cause an invalid config being latched by usb251x. Particularly |
| 671 | * one of the config modes makes the hub loading a default registers |
| 672 | * value without SMBus-slave interface activation. If the hub |
| 673 | * accidentally gets this mode, this will cause the driver SMBus- |
| 674 | * functions failure. Normally we could just lock the SMBus-segment the |
| 675 | * hub i2c-interface resides for the device-specific reset timing. But |
| 676 | * the GPIO controller, which is used to handle the hub reset, might be |
| 677 | * placed at the same i2c-bus segment. In this case an error should be |
| 678 | * returned since we can't safely use the GPIO controller to clear the |
| 679 | * reset state (it may affect the hub configuration) and we can't lock |
| 680 | * the i2c-bus segment (it will cause a deadlock). |
| 681 | */ |
| 682 | err = usb251x_check_gpio_chip(hub); |
| 683 | if (err) |
| 684 | return err; |
| 685 | |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 686 | err = usb251xb_connect(hub); |
| 687 | if (err) { |
| 688 | dev_err(dev, "Failed to connect hub (%d)\n", err); |
| 689 | return err; |
| 690 | } |
| 691 | |
| 692 | dev_info(dev, "Hub probed successfully\n"); |
| 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | static int usb251xb_i2c_probe(struct i2c_client *i2c, |
| 698 | const struct i2c_device_id *id) |
| 699 | { |
| 700 | struct usb251xb *hub; |
| 701 | |
| 702 | hub = devm_kzalloc(&i2c->dev, sizeof(struct usb251xb), GFP_KERNEL); |
| 703 | if (!hub) |
| 704 | return -ENOMEM; |
| 705 | |
| 706 | i2c_set_clientdata(i2c, hub); |
| 707 | hub->dev = &i2c->dev; |
| 708 | hub->i2c = i2c; |
| 709 | |
| 710 | return usb251xb_probe(hub); |
| 711 | } |
| 712 | |
| 713 | static const struct i2c_device_id usb251xb_id[] = { |
| 714 | { "usb2512b", 0 }, |
| 715 | { "usb2512bi", 0 }, |
| 716 | { "usb2513b", 0 }, |
| 717 | { "usb2513bi", 0 }, |
| 718 | { "usb2514b", 0 }, |
| 719 | { "usb2514bi", 0 }, |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 720 | { "usb2517", 0 }, |
| 721 | { "usb2517i", 0 }, |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 722 | { /* sentinel */ } |
| 723 | }; |
| 724 | MODULE_DEVICE_TABLE(i2c, usb251xb_id); |
| 725 | |
| 726 | static struct i2c_driver usb251xb_i2c_driver = { |
| 727 | .driver = { |
| 728 | .name = DRIVER_NAME, |
| 729 | .of_match_table = of_match_ptr(usb251xb_of_match), |
| 730 | }, |
| 731 | .probe = usb251xb_i2c_probe, |
| 732 | .id_table = usb251xb_id, |
| 733 | }; |
| 734 | |
| 735 | module_i2c_driver(usb251xb_i2c_driver); |
| 736 | |
| 737 | MODULE_AUTHOR("Richard Leitner <richard.leitner@skidata.com>"); |
Serge Semin | 7fcf558 | 2017-10-22 23:38:04 +0300 | [diff] [blame] | 738 | MODULE_DESCRIPTION("USB251x/xBi USB 2.0 Hub Controller Driver"); |
Richard Leitner | 3ec72a2 | 2017-02-10 09:19:27 +0100 | [diff] [blame] | 739 | MODULE_LICENSE("GPL"); |