Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <errno.h> |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 9 | #include <i2c.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
| 12 | #include <dm/device-internal.h> |
| 13 | #include <dm/lists.h> |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 14 | #include <dm/pinctrl.h> |
Simon Glass | bcee8d6 | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 15 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 16 | #include <asm/gpio.h> |
| 17 | #endif |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame^] | 18 | #include <linux/delay.h> |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 19 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 20 | #define I2C_MAX_OFFSET_LEN 4 |
| 21 | |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 22 | enum { |
| 23 | PIN_SDA = 0, |
| 24 | PIN_SCL, |
| 25 | PIN_COUNT, |
| 26 | }; |
| 27 | |
Simon Glass | 7d7db22 | 2015-07-02 18:15:39 -0600 | [diff] [blame] | 28 | /* Useful debugging function */ |
| 29 | void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs) |
| 30 | { |
| 31 | int i; |
| 32 | |
| 33 | for (i = 0; i < nmsgs; i++) { |
| 34 | struct i2c_msg *m = &msg[i]; |
| 35 | |
| 36 | printf(" %s %x len=%x", m->flags & I2C_M_RD ? "R" : "W", |
| 37 | msg->addr, msg->len); |
| 38 | if (!(m->flags & I2C_M_RD)) |
| 39 | printf(": %x", m->buf[0]); |
| 40 | printf("\n"); |
| 41 | } |
| 42 | } |
| 43 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 44 | /** |
| 45 | * i2c_setup_offset() - Set up a new message with a chip offset |
| 46 | * |
| 47 | * @chip: Chip to use |
| 48 | * @offset: Byte offset within chip |
| 49 | * @offset_buf: Place to put byte offset |
| 50 | * @msg: Message buffer |
| 51 | * @return 0 if OK, -EADDRNOTAVAIL if the offset length is 0. In that case the |
| 52 | * message is still set up but will not contain an offset. |
| 53 | */ |
| 54 | static int i2c_setup_offset(struct dm_i2c_chip *chip, uint offset, |
| 55 | uint8_t offset_buf[], struct i2c_msg *msg) |
| 56 | { |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 57 | int offset_len = chip->offset_len; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 58 | |
| 59 | msg->addr = chip->chip_addr; |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 60 | if (chip->chip_addr_offset_mask) |
| 61 | msg->addr |= (offset >> (8 * offset_len)) & |
| 62 | chip->chip_addr_offset_mask; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 63 | msg->flags = chip->flags & DM_I2C_CHIP_10BIT ? I2C_M_TEN : 0; |
| 64 | msg->len = chip->offset_len; |
| 65 | msg->buf = offset_buf; |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 66 | if (!offset_len) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 67 | return -EADDRNOTAVAIL; |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 68 | assert(offset_len <= I2C_MAX_OFFSET_LEN); |
| 69 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 70 | while (offset_len--) |
| 71 | *offset_buf++ = offset >> (8 * offset_len); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static int i2c_read_bytewise(struct udevice *dev, uint offset, |
| 77 | uint8_t *buffer, int len) |
| 78 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 79 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 80 | struct udevice *bus = dev_get_parent(dev); |
| 81 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 82 | struct i2c_msg msg[2], *ptr; |
| 83 | uint8_t offset_buf[I2C_MAX_OFFSET_LEN]; |
| 84 | int ret; |
| 85 | int i; |
| 86 | |
| 87 | for (i = 0; i < len; i++) { |
| 88 | if (i2c_setup_offset(chip, offset + i, offset_buf, msg)) |
| 89 | return -EINVAL; |
| 90 | ptr = msg + 1; |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 91 | ptr->addr = msg->addr; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 92 | ptr->flags = msg->flags | I2C_M_RD; |
| 93 | ptr->len = 1; |
| 94 | ptr->buf = &buffer[i]; |
| 95 | ptr++; |
| 96 | |
| 97 | ret = ops->xfer(bus, msg, ptr - msg); |
| 98 | if (ret) |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int i2c_write_bytewise(struct udevice *dev, uint offset, |
| 106 | const uint8_t *buffer, int len) |
| 107 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 108 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 109 | struct udevice *bus = dev_get_parent(dev); |
| 110 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 111 | struct i2c_msg msg[1]; |
| 112 | uint8_t buf[I2C_MAX_OFFSET_LEN + 1]; |
| 113 | int ret; |
| 114 | int i; |
| 115 | |
| 116 | for (i = 0; i < len; i++) { |
| 117 | if (i2c_setup_offset(chip, offset + i, buf, msg)) |
| 118 | return -EINVAL; |
| 119 | buf[msg->len++] = buffer[i]; |
| 120 | |
| 121 | ret = ops->xfer(bus, msg, 1); |
| 122 | if (ret) |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
Simon Glass | f9a4c2d | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 129 | int dm_i2c_read(struct udevice *dev, uint offset, uint8_t *buffer, int len) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 130 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 131 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 132 | struct udevice *bus = dev_get_parent(dev); |
| 133 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 134 | struct i2c_msg msg[2], *ptr; |
| 135 | uint8_t offset_buf[I2C_MAX_OFFSET_LEN]; |
| 136 | int msg_count; |
| 137 | |
| 138 | if (!ops->xfer) |
| 139 | return -ENOSYS; |
| 140 | if (chip->flags & DM_I2C_CHIP_RD_ADDRESS) |
| 141 | return i2c_read_bytewise(dev, offset, buffer, len); |
| 142 | ptr = msg; |
| 143 | if (!i2c_setup_offset(chip, offset, offset_buf, ptr)) |
| 144 | ptr++; |
| 145 | |
| 146 | if (len) { |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 147 | ptr->addr = msg->addr; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 148 | ptr->flags = chip->flags & DM_I2C_CHIP_10BIT ? I2C_M_TEN : 0; |
| 149 | ptr->flags |= I2C_M_RD; |
| 150 | ptr->len = len; |
| 151 | ptr->buf = buffer; |
| 152 | ptr++; |
| 153 | } |
| 154 | msg_count = ptr - msg; |
| 155 | |
| 156 | return ops->xfer(bus, msg, msg_count); |
| 157 | } |
| 158 | |
Simon Glass | f9a4c2d | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 159 | int dm_i2c_write(struct udevice *dev, uint offset, const uint8_t *buffer, |
| 160 | int len) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 161 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 162 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 163 | struct udevice *bus = dev_get_parent(dev); |
| 164 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 165 | struct i2c_msg msg[1]; |
| 166 | |
| 167 | if (!ops->xfer) |
| 168 | return -ENOSYS; |
| 169 | |
| 170 | if (chip->flags & DM_I2C_CHIP_WR_ADDRESS) |
| 171 | return i2c_write_bytewise(dev, offset, buffer, len); |
| 172 | /* |
| 173 | * The simple approach would be to send two messages here: one to |
| 174 | * set the offset and one to write the bytes. However some drivers |
| 175 | * will not be expecting this, and some chips won't like how the |
| 176 | * driver presents this on the I2C bus. |
| 177 | * |
| 178 | * The API does not support separate offset and data. We could extend |
| 179 | * it with a flag indicating that there is data in the next message |
| 180 | * that needs to be processed in the same transaction. We could |
| 181 | * instead add an additional buffer to each message. For now, handle |
| 182 | * this in the uclass since it isn't clear what the impact on drivers |
| 183 | * would be with this extra complication. Unfortunately this means |
| 184 | * copying the message. |
| 185 | * |
| 186 | * Use the stack for small messages, malloc() for larger ones. We |
| 187 | * need to allow space for the offset (up to 4 bytes) and the message |
| 188 | * itself. |
| 189 | */ |
| 190 | if (len < 64) { |
| 191 | uint8_t buf[I2C_MAX_OFFSET_LEN + len]; |
| 192 | |
| 193 | i2c_setup_offset(chip, offset, buf, msg); |
| 194 | msg->len += len; |
| 195 | memcpy(buf + chip->offset_len, buffer, len); |
| 196 | |
| 197 | return ops->xfer(bus, msg, 1); |
| 198 | } else { |
| 199 | uint8_t *buf; |
| 200 | int ret; |
| 201 | |
| 202 | buf = malloc(I2C_MAX_OFFSET_LEN + len); |
| 203 | if (!buf) |
| 204 | return -ENOMEM; |
| 205 | i2c_setup_offset(chip, offset, buf, msg); |
| 206 | msg->len += len; |
| 207 | memcpy(buf + chip->offset_len, buffer, len); |
| 208 | |
| 209 | ret = ops->xfer(bus, msg, 1); |
| 210 | free(buf); |
| 211 | return ret; |
| 212 | } |
| 213 | } |
| 214 | |
Simon Glass | df358c6 | 2015-07-02 18:15:42 -0600 | [diff] [blame] | 215 | int dm_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs) |
| 216 | { |
| 217 | struct udevice *bus = dev_get_parent(dev); |
| 218 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 219 | |
| 220 | if (!ops->xfer) |
| 221 | return -ENOSYS; |
| 222 | |
| 223 | return ops->xfer(bus, msg, nmsgs); |
| 224 | } |
| 225 | |
Simon Glass | ba3864f | 2015-04-20 12:37:14 -0600 | [diff] [blame] | 226 | int dm_i2c_reg_read(struct udevice *dev, uint offset) |
| 227 | { |
| 228 | uint8_t val; |
| 229 | int ret; |
| 230 | |
| 231 | ret = dm_i2c_read(dev, offset, &val, 1); |
| 232 | if (ret < 0) |
| 233 | return ret; |
| 234 | |
| 235 | return val; |
| 236 | } |
| 237 | |
| 238 | int dm_i2c_reg_write(struct udevice *dev, uint offset, uint value) |
| 239 | { |
| 240 | uint8_t val = value; |
| 241 | |
| 242 | return dm_i2c_write(dev, offset, &val, 1); |
| 243 | } |
| 244 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 245 | /** |
| 246 | * i2c_probe_chip() - probe for a chip on a bus |
| 247 | * |
| 248 | * @bus: Bus to probe |
| 249 | * @chip_addr: Chip address to probe |
| 250 | * @flags: Flags for the chip |
| 251 | * @return 0 if found, -ENOSYS if the driver is invalid, -EREMOTEIO if the chip |
| 252 | * does not respond to probe |
| 253 | */ |
| 254 | static int i2c_probe_chip(struct udevice *bus, uint chip_addr, |
| 255 | enum dm_i2c_chip_flags chip_flags) |
| 256 | { |
| 257 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 258 | struct i2c_msg msg[1]; |
| 259 | int ret; |
| 260 | |
| 261 | if (ops->probe_chip) { |
| 262 | ret = ops->probe_chip(bus, chip_addr, chip_flags); |
| 263 | if (!ret || ret != -ENOSYS) |
| 264 | return ret; |
| 265 | } |
| 266 | |
| 267 | if (!ops->xfer) |
| 268 | return -ENOSYS; |
| 269 | |
| 270 | /* Probe with a zero-length message */ |
| 271 | msg->addr = chip_addr; |
| 272 | msg->flags = chip_flags & DM_I2C_CHIP_10BIT ? I2C_M_TEN : 0; |
| 273 | msg->len = 0; |
| 274 | msg->buf = NULL; |
| 275 | |
| 276 | return ops->xfer(bus, msg, 1); |
| 277 | } |
| 278 | |
Simon Glass | 25ab4b0 | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 279 | static int i2c_bind_driver(struct udevice *bus, uint chip_addr, uint offset_len, |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 280 | struct udevice **devp) |
| 281 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 282 | struct dm_i2c_chip *chip; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 283 | char name[30], *str; |
| 284 | struct udevice *dev; |
| 285 | int ret; |
| 286 | |
| 287 | snprintf(name, sizeof(name), "generic_%x", chip_addr); |
| 288 | str = strdup(name); |
Simon Glass | 5c2d23b | 2015-02-18 14:10:28 -0700 | [diff] [blame] | 289 | if (!str) |
| 290 | return -ENOMEM; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 291 | ret = device_bind_driver(bus, "i2c_generic_chip_drv", str, &dev); |
| 292 | debug("%s: device_bind_driver: ret=%d\n", __func__, ret); |
| 293 | if (ret) |
| 294 | goto err_bind; |
| 295 | |
| 296 | /* Tell the device what we know about it */ |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 297 | chip = dev_get_parent_platdata(dev); |
| 298 | chip->chip_addr = chip_addr; |
| 299 | chip->offset_len = offset_len; |
| 300 | ret = device_probe(dev); |
| 301 | debug("%s: device_probe: ret=%d\n", __func__, ret); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 302 | if (ret) |
| 303 | goto err_probe; |
| 304 | |
| 305 | *devp = dev; |
| 306 | return 0; |
| 307 | |
| 308 | err_probe: |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 309 | /* |
| 310 | * If the device failed to probe, unbind it. There is nothing there |
| 311 | * on the bus so we don't want to leave it lying around |
| 312 | */ |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 313 | device_unbind(dev); |
| 314 | err_bind: |
| 315 | free(str); |
| 316 | return ret; |
| 317 | } |
| 318 | |
Simon Glass | 25ab4b0 | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 319 | int i2c_get_chip(struct udevice *bus, uint chip_addr, uint offset_len, |
| 320 | struct udevice **devp) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 321 | { |
| 322 | struct udevice *dev; |
| 323 | |
| 324 | debug("%s: Searching bus '%s' for address %02x: ", __func__, |
| 325 | bus->name, chip_addr); |
| 326 | for (device_find_first_child(bus, &dev); dev; |
| 327 | device_find_next_child(&dev)) { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 328 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 329 | int ret; |
| 330 | |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 331 | if (chip->chip_addr == (chip_addr & |
| 332 | ~chip->chip_addr_offset_mask)) { |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 333 | ret = device_probe(dev); |
| 334 | debug("found, ret=%d\n", ret); |
| 335 | if (ret) |
| 336 | return ret; |
| 337 | *devp = dev; |
| 338 | return 0; |
| 339 | } |
| 340 | } |
| 341 | debug("not found\n"); |
Simon Glass | 25ab4b0 | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 342 | return i2c_bind_driver(bus, chip_addr, offset_len, devp); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Simon Glass | 25ab4b0 | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 345 | int i2c_get_chip_for_busnum(int busnum, int chip_addr, uint offset_len, |
| 346 | struct udevice **devp) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 347 | { |
| 348 | struct udevice *bus; |
| 349 | int ret; |
| 350 | |
| 351 | ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus); |
| 352 | if (ret) { |
| 353 | debug("Cannot find I2C bus %d\n", busnum); |
| 354 | return ret; |
| 355 | } |
Jean-Jacques Hiblot | f32a800 | 2018-12-07 14:50:38 +0100 | [diff] [blame] | 356 | |
| 357 | /* detect the presence of the chip on the bus */ |
| 358 | ret = i2c_probe_chip(bus, chip_addr, 0); |
| 359 | debug("%s: bus='%s', address %02x, ret=%d\n", __func__, bus->name, |
| 360 | chip_addr, ret); |
| 361 | if (ret) { |
| 362 | debug("Cannot detect I2C chip %02x on bus %d\n", chip_addr, |
| 363 | busnum); |
| 364 | return ret; |
| 365 | } |
| 366 | |
Simon Glass | 25ab4b0 | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 367 | ret = i2c_get_chip(bus, chip_addr, offset_len, devp); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 368 | if (ret) { |
| 369 | debug("Cannot find I2C chip %02x on bus %d\n", chip_addr, |
| 370 | busnum); |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
Simon Glass | f9a4c2d | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 377 | int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags, |
| 378 | struct udevice **devp) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 379 | { |
| 380 | int ret; |
| 381 | |
| 382 | *devp = NULL; |
| 383 | |
| 384 | /* First probe that chip */ |
| 385 | ret = i2c_probe_chip(bus, chip_addr, chip_flags); |
| 386 | debug("%s: bus='%s', address %02x, ret=%d\n", __func__, bus->name, |
| 387 | chip_addr, ret); |
| 388 | if (ret) |
| 389 | return ret; |
| 390 | |
| 391 | /* The chip was found, see if we have a driver, and probe it */ |
Simon Glass | 25ab4b0 | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 392 | ret = i2c_get_chip(bus, chip_addr, 1, devp); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 393 | debug("%s: i2c_get_chip: ret=%d\n", __func__, ret); |
| 394 | |
| 395 | return ret; |
| 396 | } |
| 397 | |
Simon Glass | ca88b9b | 2015-02-05 21:41:32 -0700 | [diff] [blame] | 398 | int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 399 | { |
| 400 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 401 | struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 402 | int ret; |
| 403 | |
| 404 | /* |
| 405 | * If we have a method, call it. If not then the driver probably wants |
| 406 | * to deal with speed changes on the next transfer. It can easily read |
| 407 | * the current speed from this uclass |
| 408 | */ |
| 409 | if (ops->set_bus_speed) { |
| 410 | ret = ops->set_bus_speed(bus, speed); |
| 411 | if (ret) |
| 412 | return ret; |
| 413 | } |
| 414 | i2c->speed_hz = speed; |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
Simon Glass | ca88b9b | 2015-02-05 21:41:32 -0700 | [diff] [blame] | 419 | int dm_i2c_get_bus_speed(struct udevice *bus) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 420 | { |
| 421 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 422 | struct dm_i2c_bus *i2c = dev_get_uclass_priv(bus); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 423 | |
| 424 | if (!ops->get_bus_speed) |
| 425 | return i2c->speed_hz; |
| 426 | |
| 427 | return ops->get_bus_speed(bus); |
| 428 | } |
| 429 | |
| 430 | int i2c_set_chip_flags(struct udevice *dev, uint flags) |
| 431 | { |
| 432 | struct udevice *bus = dev->parent; |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 433 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 434 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 435 | int ret; |
| 436 | |
| 437 | if (ops->set_flags) { |
| 438 | ret = ops->set_flags(dev, flags); |
| 439 | if (ret) |
| 440 | return ret; |
| 441 | } |
| 442 | chip->flags = flags; |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | int i2c_get_chip_flags(struct udevice *dev, uint *flagsp) |
| 448 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 449 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 450 | |
| 451 | *flagsp = chip->flags; |
| 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | int i2c_set_chip_offset_len(struct udevice *dev, uint offset_len) |
| 457 | { |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 458 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 459 | |
| 460 | if (offset_len > I2C_MAX_OFFSET_LEN) |
| 461 | return -EINVAL; |
| 462 | chip->offset_len = offset_len; |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Simon Glass | 0150180 | 2015-05-04 11:30:58 -0600 | [diff] [blame] | 467 | int i2c_get_chip_offset_len(struct udevice *dev) |
| 468 | { |
| 469 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
| 470 | |
| 471 | return chip->offset_len; |
| 472 | } |
| 473 | |
Robert Beckett | 8596852 | 2019-10-28 17:44:57 +0000 | [diff] [blame] | 474 | int i2c_set_chip_addr_offset_mask(struct udevice *dev, uint mask) |
| 475 | { |
| 476 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
| 477 | |
| 478 | chip->chip_addr_offset_mask = mask; |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | uint i2c_get_chip_addr_offset_mask(struct udevice *dev) |
| 484 | { |
| 485 | struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); |
| 486 | |
| 487 | return chip->chip_addr_offset_mask; |
| 488 | } |
| 489 | |
Simon Glass | bcee8d6 | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 490 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 491 | static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit) |
| 492 | { |
| 493 | if (bit) |
| 494 | dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); |
| 495 | else |
| 496 | dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | |
| 497 | GPIOD_ACTIVE_LOW | |
| 498 | GPIOD_IS_OUT_ACTIVE); |
| 499 | } |
| 500 | |
| 501 | static int i2c_gpio_get_pin(struct gpio_desc *pin) |
| 502 | { |
| 503 | return dm_gpio_get_value(pin); |
| 504 | } |
| 505 | |
Marek Vasut | 7231522 | 2020-02-07 16:57:50 +0100 | [diff] [blame] | 506 | int i2c_deblock_gpio_loop(struct gpio_desc *sda_pin, |
| 507 | struct gpio_desc *scl_pin, |
| 508 | unsigned int scl_count, |
Marek Vasut | a191728 | 2020-02-07 16:57:51 +0100 | [diff] [blame] | 509 | unsigned int start_count, |
Marek Vasut | 7231522 | 2020-02-07 16:57:50 +0100 | [diff] [blame] | 510 | unsigned int delay) |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 511 | { |
Marek Vasut | a191728 | 2020-02-07 16:57:51 +0100 | [diff] [blame] | 512 | int i, ret = -EREMOTEIO; |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 513 | |
| 514 | i2c_gpio_set_pin(sda_pin, 1); |
| 515 | i2c_gpio_set_pin(scl_pin, 1); |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 516 | udelay(delay); |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 517 | |
| 518 | /* Toggle SCL until slave release SDA */ |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 519 | while (scl_count-- >= 0) { |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 520 | i2c_gpio_set_pin(scl_pin, 1); |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 521 | udelay(delay); |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 522 | i2c_gpio_set_pin(scl_pin, 0); |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 523 | udelay(delay); |
Marek Vasut | a191728 | 2020-02-07 16:57:51 +0100 | [diff] [blame] | 524 | if (i2c_gpio_get_pin(sda_pin)) { |
| 525 | ret = 0; |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 526 | break; |
Marek Vasut | a191728 | 2020-02-07 16:57:51 +0100 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
| 530 | if (!ret && start_count) { |
| 531 | for (i = 0; i < start_count; i++) { |
| 532 | /* Send start condition */ |
| 533 | udelay(delay); |
| 534 | i2c_gpio_set_pin(sda_pin, 1); |
| 535 | udelay(delay); |
| 536 | i2c_gpio_set_pin(scl_pin, 1); |
| 537 | udelay(delay); |
| 538 | i2c_gpio_set_pin(sda_pin, 0); |
| 539 | udelay(delay); |
| 540 | i2c_gpio_set_pin(scl_pin, 0); |
| 541 | } |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /* Then, send I2C stop */ |
| 545 | i2c_gpio_set_pin(sda_pin, 0); |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 546 | udelay(delay); |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 547 | |
| 548 | i2c_gpio_set_pin(scl_pin, 1); |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 549 | udelay(delay); |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 550 | |
| 551 | i2c_gpio_set_pin(sda_pin, 1); |
Marek Vasut | 1f746a2 | 2020-02-07 16:57:49 +0100 | [diff] [blame] | 552 | udelay(delay); |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 553 | |
| 554 | if (!i2c_gpio_get_pin(sda_pin) || !i2c_gpio_get_pin(scl_pin)) |
| 555 | ret = -EREMOTEIO; |
| 556 | |
| 557 | return ret; |
| 558 | } |
| 559 | |
| 560 | static int i2c_deblock_gpio(struct udevice *bus) |
| 561 | { |
| 562 | struct gpio_desc gpios[PIN_COUNT]; |
| 563 | int ret, ret0; |
| 564 | |
| 565 | ret = gpio_request_list_by_name(bus, "gpios", gpios, |
| 566 | ARRAY_SIZE(gpios), GPIOD_IS_IN); |
| 567 | if (ret != ARRAY_SIZE(gpios)) { |
| 568 | debug("%s: I2C Node '%s' has no 'gpios' property %s\n", |
| 569 | __func__, dev_read_name(bus), bus->name); |
| 570 | if (ret >= 0) { |
| 571 | gpio_free_list(bus, gpios, ret); |
| 572 | ret = -ENOENT; |
| 573 | } |
| 574 | goto out; |
| 575 | } |
| 576 | |
| 577 | ret = pinctrl_select_state(bus, "gpio"); |
| 578 | if (ret) { |
| 579 | debug("%s: I2C Node '%s' has no 'gpio' pinctrl state. %s\n", |
| 580 | __func__, dev_read_name(bus), bus->name); |
| 581 | goto out_no_pinctrl; |
| 582 | } |
| 583 | |
Marek Vasut | a191728 | 2020-02-07 16:57:51 +0100 | [diff] [blame] | 584 | ret0 = i2c_deblock_gpio_loop(&gpios[PIN_SDA], &gpios[PIN_SCL], 9, 0, 5); |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 585 | |
| 586 | ret = pinctrl_select_state(bus, "default"); |
| 587 | if (ret) { |
| 588 | debug("%s: I2C Node '%s' has no 'default' pinctrl state. %s\n", |
| 589 | __func__, dev_read_name(bus), bus->name); |
| 590 | } |
| 591 | |
| 592 | ret = !ret ? ret0 : ret; |
| 593 | |
| 594 | out_no_pinctrl: |
| 595 | gpio_free_list(bus, gpios, ARRAY_SIZE(gpios)); |
| 596 | out: |
| 597 | return ret; |
| 598 | } |
| 599 | #else |
| 600 | static int i2c_deblock_gpio(struct udevice *bus) |
| 601 | { |
| 602 | return -ENOSYS; |
| 603 | } |
Simon Glass | bcee8d6 | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 604 | #endif /* DM_GPIO */ |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 605 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 606 | int i2c_deblock(struct udevice *bus) |
| 607 | { |
| 608 | struct dm_i2c_ops *ops = i2c_get_ops(bus); |
| 609 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 610 | if (!ops->deblock) |
Alexander Kochetkov | aa54192 | 2018-03-27 17:52:27 +0300 | [diff] [blame] | 611 | return i2c_deblock_gpio(bus); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 612 | |
| 613 | return ops->deblock(bus); |
| 614 | } |
| 615 | |
Adam Ford | afa8cdd | 2018-08-20 20:24:34 -0500 | [diff] [blame] | 616 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 1704308 | 2017-05-18 20:09:30 -0600 | [diff] [blame] | 617 | int i2c_chip_ofdata_to_platdata(struct udevice *dev, struct dm_i2c_chip *chip) |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 618 | { |
Simon Glass | 1704308 | 2017-05-18 20:09:30 -0600 | [diff] [blame] | 619 | int addr; |
| 620 | |
| 621 | chip->offset_len = dev_read_u32_default(dev, "u-boot,i2c-offset-len", |
| 622 | 1); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 623 | chip->flags = 0; |
Simon Glass | 1704308 | 2017-05-18 20:09:30 -0600 | [diff] [blame] | 624 | addr = dev_read_u32_default(dev, "reg", -1); |
| 625 | if (addr == -1) { |
| 626 | debug("%s: I2C Node '%s' has no 'reg' property %s\n", __func__, |
| 627 | dev_read_name(dev), dev->name); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 628 | return -EINVAL; |
| 629 | } |
Simon Glass | 1704308 | 2017-05-18 20:09:30 -0600 | [diff] [blame] | 630 | chip->chip_addr = addr; |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 631 | |
| 632 | return 0; |
| 633 | } |
Mugunthan V N | 5142ac7 | 2016-07-18 15:10:58 +0530 | [diff] [blame] | 634 | #endif |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 635 | |
Lukasz Majewski | a40fe21 | 2019-04-04 12:35:34 +0200 | [diff] [blame] | 636 | static int i2c_pre_probe(struct udevice *dev) |
| 637 | { |
| 638 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 639 | struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev); |
| 640 | unsigned int max = 0; |
| 641 | ofnode node; |
| 642 | int ret; |
| 643 | |
| 644 | i2c->max_transaction_bytes = 0; |
| 645 | dev_for_each_subnode(node, dev) { |
| 646 | ret = ofnode_read_u32(node, |
| 647 | "u-boot,i2c-transaction-bytes", |
| 648 | &max); |
| 649 | if (!ret && max > i2c->max_transaction_bytes) |
| 650 | i2c->max_transaction_bytes = max; |
| 651 | } |
| 652 | |
| 653 | debug("%s: I2C bus: %s max transaction bytes: %d\n", __func__, |
| 654 | dev->name, i2c->max_transaction_bytes); |
| 655 | #endif |
| 656 | return 0; |
| 657 | } |
| 658 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 659 | static int i2c_post_probe(struct udevice *dev) |
| 660 | { |
Adam Ford | afa8cdd | 2018-08-20 20:24:34 -0500 | [diff] [blame] | 661 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 662 | struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 663 | |
Simon Glass | f3d4615 | 2020-01-23 11:48:22 -0700 | [diff] [blame] | 664 | i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency", |
| 665 | I2C_SPEED_STANDARD_RATE); |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 666 | |
Simon Glass | ca88b9b | 2015-02-05 21:41:32 -0700 | [diff] [blame] | 667 | return dm_i2c_set_bus_speed(dev, i2c->speed_hz); |
Mugunthan V N | 5142ac7 | 2016-07-18 15:10:58 +0530 | [diff] [blame] | 668 | #else |
| 669 | return 0; |
| 670 | #endif |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 673 | static int i2c_child_post_bind(struct udevice *dev) |
| 674 | { |
Adam Ford | afa8cdd | 2018-08-20 20:24:34 -0500 | [diff] [blame] | 675 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 676 | struct dm_i2c_chip *plat = dev_get_parent_platdata(dev); |
| 677 | |
Simon Glass | 1704308 | 2017-05-18 20:09:30 -0600 | [diff] [blame] | 678 | if (!dev_of_valid(dev)) |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 679 | return 0; |
Simon Glass | 1704308 | 2017-05-18 20:09:30 -0600 | [diff] [blame] | 680 | return i2c_chip_ofdata_to_platdata(dev, plat); |
Mugunthan V N | 5142ac7 | 2016-07-18 15:10:58 +0530 | [diff] [blame] | 681 | #else |
| 682 | return 0; |
| 683 | #endif |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Michal Simek | 6bfacc8 | 2019-01-31 16:31:01 +0100 | [diff] [blame] | 686 | struct i2c_priv { |
| 687 | int max_id; |
| 688 | }; |
| 689 | |
Michal Simek | 6160722 | 2019-01-31 16:31:02 +0100 | [diff] [blame] | 690 | static int i2c_post_bind(struct udevice *dev) |
| 691 | { |
| 692 | struct uclass *class = dev->uclass; |
| 693 | struct i2c_priv *priv = class->priv; |
| 694 | int ret = 0; |
| 695 | |
| 696 | /* Just for sure */ |
| 697 | if (!priv) |
| 698 | return -ENOMEM; |
| 699 | |
| 700 | debug("%s: %s, req_seq=%d\n", __func__, dev->name, dev->req_seq); |
| 701 | |
| 702 | /* if there is no alias ID, use the first free */ |
| 703 | if (dev->req_seq == -1) |
| 704 | dev->req_seq = ++priv->max_id; |
| 705 | |
| 706 | debug("%s: %s, new req_seq=%d\n", __func__, dev->name, dev->req_seq); |
| 707 | |
| 708 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 709 | ret = dm_scan_fdt_dev(dev); |
| 710 | #endif |
| 711 | return ret; |
| 712 | } |
| 713 | |
Michal Simek | 6bfacc8 | 2019-01-31 16:31:01 +0100 | [diff] [blame] | 714 | int i2c_uclass_init(struct uclass *class) |
| 715 | { |
| 716 | struct i2c_priv *priv = class->priv; |
| 717 | |
| 718 | /* Just for sure */ |
| 719 | if (!priv) |
| 720 | return -ENOMEM; |
| 721 | |
| 722 | /* Get the last allocated alias. */ |
Simon Glass | f3d4615 | 2020-01-23 11:48:22 -0700 | [diff] [blame] | 723 | if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) |
| 724 | priv->max_id = dev_read_alias_highest_id("i2c"); |
| 725 | else |
| 726 | priv->max_id = -1; |
Michal Simek | 6bfacc8 | 2019-01-31 16:31:01 +0100 | [diff] [blame] | 727 | |
| 728 | debug("%s: highest alias id is %d\n", __func__, priv->max_id); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 733 | UCLASS_DRIVER(i2c) = { |
| 734 | .id = UCLASS_I2C, |
| 735 | .name = "i2c", |
Simon Glass | 9cc36a2 | 2015-01-25 08:27:05 -0700 | [diff] [blame] | 736 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
Michal Simek | 6160722 | 2019-01-31 16:31:02 +0100 | [diff] [blame] | 737 | .post_bind = i2c_post_bind, |
Michal Simek | 6bfacc8 | 2019-01-31 16:31:01 +0100 | [diff] [blame] | 738 | .init = i2c_uclass_init, |
| 739 | .priv_auto_alloc_size = sizeof(struct i2c_priv), |
Lukasz Majewski | a40fe21 | 2019-04-04 12:35:34 +0200 | [diff] [blame] | 740 | .pre_probe = i2c_pre_probe, |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 741 | .post_probe = i2c_post_probe, |
Simon Glass | e6f66ec | 2015-01-25 08:27:13 -0700 | [diff] [blame] | 742 | .per_device_auto_alloc_size = sizeof(struct dm_i2c_bus), |
| 743 | .per_child_platdata_auto_alloc_size = sizeof(struct dm_i2c_chip), |
| 744 | .child_post_bind = i2c_child_post_bind, |
Simon Glass | c6202d8 | 2014-12-10 08:55:47 -0700 | [diff] [blame] | 745 | }; |
| 746 | |
| 747 | UCLASS_DRIVER(i2c_generic) = { |
| 748 | .id = UCLASS_I2C_GENERIC, |
| 749 | .name = "i2c_generic", |
| 750 | }; |
| 751 | |
| 752 | U_BOOT_DRIVER(i2c_generic_chip_drv) = { |
| 753 | .name = "i2c_generic_chip_drv", |
| 754 | .id = UCLASS_I2C_GENERIC, |
| 755 | }; |