Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'i3c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull ic3 updates from Boris Brezillon:

- Drop support for 10-bit I2C addresses

- Add support for limited bus mode

- Fix the Cadence DT binding doc

- Use struct_size() to allocate a DEFSLVS packet

* tag 'i3c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
i3c: master: Use struct_size() helper
dt-bindings: i3c: cdns: Use correct cells for I2C device
i3c: dw: add limited bus mode support
i3c: add mixed limited bus mode
i3c: fix i2c and i3c scl rate by bus mode
dt-bindings: i3c: Document dropped support for I2C 10 bit devices
i3c: Drop support for I2C 10 bit addresing

+71 -44
+1 -1
Documentation/devicetree/bindings/i3c/cdns,i3c-master.txt
··· 38 38 39 39 nunchuk: nunchuk@52 { 40 40 compatible = "nintendo,nunchuk"; 41 - reg = <0x52 0x80000010 0>; 41 + reg = <0x52 0x0 0x10>; 42 42 }; 43 43 };
+3 -1
Documentation/devicetree/bindings/i3c/i3c.txt
··· 39 39 New constraint on existing properties: 40 40 -------------------------------------- 41 41 - reg: contains 3 cells 42 - + first cell : still encoding the I2C address 42 + + first cell : still encoding the I2C address. 10 bit addressing is not 43 + supported. Devices with 10 bit address can't be properly passed through 44 + DEFSLVS command. 43 45 44 46 + second cell: shall be 0 45 47
+59 -23
drivers/i3c/master.c
··· 91 91 up_read(&bus->lock); 92 92 } 93 93 94 + static struct i3c_master_controller * 95 + i3c_bus_to_i3c_master(struct i3c_bus *i3cbus) 96 + { 97 + return container_of(i3cbus, struct i3c_master_controller, bus); 98 + } 99 + 94 100 static struct i3c_master_controller *dev_to_i3cmaster(struct device *dev) 95 101 { 96 102 return container_of(dev, struct i3c_master_controller, dev); ··· 470 464 static const char * const i3c_bus_mode_strings[] = { 471 465 [I3C_BUS_MODE_PURE] = "pure", 472 466 [I3C_BUS_MODE_MIXED_FAST] = "mixed-fast", 467 + [I3C_BUS_MODE_MIXED_LIMITED] = "mixed-limited", 473 468 [I3C_BUS_MODE_MIXED_SLOW] = "mixed-slow", 474 469 }; 475 470 ··· 572 565 .groups = i3c_masterdev_groups, 573 566 }; 574 567 575 - int i3c_bus_set_mode(struct i3c_bus *i3cbus, enum i3c_bus_mode mode) 568 + int i3c_bus_set_mode(struct i3c_bus *i3cbus, enum i3c_bus_mode mode, 569 + unsigned long max_i2c_scl_rate) 576 570 { 571 + struct i3c_master_controller *master = i3c_bus_to_i3c_master(i3cbus); 572 + 577 573 i3cbus->mode = mode; 578 574 579 - if (!i3cbus->scl_rate.i3c) 580 - i3cbus->scl_rate.i3c = I3C_BUS_TYP_I3C_SCL_RATE; 581 - 582 - if (!i3cbus->scl_rate.i2c) { 583 - if (i3cbus->mode == I3C_BUS_MODE_MIXED_SLOW) 584 - i3cbus->scl_rate.i2c = I3C_BUS_I2C_FM_SCL_RATE; 585 - else 586 - i3cbus->scl_rate.i2c = I3C_BUS_I2C_FM_PLUS_SCL_RATE; 575 + switch (i3cbus->mode) { 576 + case I3C_BUS_MODE_PURE: 577 + if (!i3cbus->scl_rate.i3c) 578 + i3cbus->scl_rate.i3c = I3C_BUS_TYP_I3C_SCL_RATE; 579 + break; 580 + case I3C_BUS_MODE_MIXED_FAST: 581 + case I3C_BUS_MODE_MIXED_LIMITED: 582 + if (!i3cbus->scl_rate.i3c) 583 + i3cbus->scl_rate.i3c = I3C_BUS_TYP_I3C_SCL_RATE; 584 + if (!i3cbus->scl_rate.i2c) 585 + i3cbus->scl_rate.i2c = max_i2c_scl_rate; 586 + break; 587 + case I3C_BUS_MODE_MIXED_SLOW: 588 + if (!i3cbus->scl_rate.i2c) 589 + i3cbus->scl_rate.i2c = max_i2c_scl_rate; 590 + if (!i3cbus->scl_rate.i3c || 591 + i3cbus->scl_rate.i3c > i3cbus->scl_rate.i2c) 592 + i3cbus->scl_rate.i3c = i3cbus->scl_rate.i2c; 593 + break; 594 + default: 595 + return -EINVAL; 587 596 } 597 + 598 + dev_dbg(&master->dev, "i2c-scl = %ld Hz i3c-scl = %ld Hz\n", 599 + i3cbus->scl_rate.i2c, i3cbus->scl_rate.i3c); 588 600 589 601 /* 590 602 * I3C/I2C frequency may have been overridden, check that user-provided ··· 950 924 ndevs++; 951 925 952 926 defslvs = i3c_ccc_cmd_dest_init(&dest, I3C_BROADCAST_ADDR, 953 - sizeof(*defslvs) + 954 - ((ndevs - 1) * 955 - sizeof(struct i3c_ccc_dev_desc))); 927 + struct_size(defslvs, slaves, 928 + ndevs - 1)); 956 929 if (!defslvs) 957 930 return -ENOMEM; 958 931 ··· 1988 1963 if (ret) 1989 1964 return ret; 1990 1965 1966 + /* 1967 + * The I3C Specification does not clearly say I2C devices with 10-bit 1968 + * address are supported. These devices can't be passed properly through 1969 + * DEFSLVS command. 1970 + */ 1971 + if (boardinfo->base.flags & I2C_CLIENT_TEN) { 1972 + dev_err(&master->dev, "I2C device with 10 bit address not supported."); 1973 + return -ENOTSUPP; 1974 + } 1975 + 1991 1976 /* LVR is encoded in reg[2]. */ 1992 1977 boardinfo->lvr = reg[2]; 1993 - 1994 - if (boardinfo->lvr & I3C_LVR_I2C_FM_MODE) 1995 - master->bus.scl_rate.i2c = I3C_BUS_I2C_FM_SCL_RATE; 1996 1978 1997 1979 list_add_tail(&boardinfo->node, &master->boardinfo.i2c); 1998 1980 of_node_get(node); ··· 2143 2111 return ret ? ret : nxfers; 2144 2112 } 2145 2113 2146 - static u32 i3c_master_i2c_functionalities(struct i2c_adapter *adap) 2114 + static u32 i3c_master_i2c_funcs(struct i2c_adapter *adapter) 2147 2115 { 2148 - struct i3c_master_controller *master = i2c_adapter_to_i3c_master(adap); 2149 - 2150 - return master->ops->i2c_funcs(master); 2116 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; 2151 2117 } 2152 2118 2153 2119 static const struct i2c_algorithm i3c_master_i2c_algo = { 2154 2120 .master_xfer = i3c_master_i2c_adapter_xfer, 2155 - .functionality = i3c_master_i2c_functionalities, 2121 + .functionality = i3c_master_i2c_funcs, 2156 2122 }; 2157 2123 2158 2124 static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master) ··· 2409 2379 static int i3c_master_check_ops(const struct i3c_master_controller_ops *ops) 2410 2380 { 2411 2381 if (!ops || !ops->bus_init || !ops->priv_xfers || 2412 - !ops->send_ccc_cmd || !ops->do_daa || !ops->i2c_xfers || 2413 - !ops->i2c_funcs) 2382 + !ops->send_ccc_cmd || !ops->do_daa || !ops->i2c_xfers) 2414 2383 return -EINVAL; 2415 2384 2416 2385 if (ops->request_ibi && ··· 2446 2417 const struct i3c_master_controller_ops *ops, 2447 2418 bool secondary) 2448 2419 { 2420 + unsigned long i2c_scl_rate = I3C_BUS_I2C_FM_PLUS_SCL_RATE; 2449 2421 struct i3c_bus *i3cbus = i3c_master_get_bus(master); 2450 2422 enum i3c_bus_mode mode = I3C_BUS_MODE_PURE; 2451 2423 struct i2c_dev_boardinfo *i2cbi; ··· 2488 2458 mode = I3C_BUS_MODE_MIXED_FAST; 2489 2459 break; 2490 2460 case I3C_LVR_I2C_INDEX(1): 2461 + if (mode < I3C_BUS_MODE_MIXED_LIMITED) 2462 + mode = I3C_BUS_MODE_MIXED_LIMITED; 2463 + break; 2491 2464 case I3C_LVR_I2C_INDEX(2): 2492 2465 if (mode < I3C_BUS_MODE_MIXED_SLOW) 2493 2466 mode = I3C_BUS_MODE_MIXED_SLOW; ··· 2499 2466 ret = -EINVAL; 2500 2467 goto err_put_dev; 2501 2468 } 2469 + 2470 + if (i2cbi->lvr & I3C_LVR_I2C_FM_MODE) 2471 + i2c_scl_rate = I3C_BUS_I2C_FM_SCL_RATE; 2502 2472 } 2503 2473 2504 - ret = i3c_bus_set_mode(i3cbus, mode); 2474 + ret = i3c_bus_set_mode(i3cbus, mode, i2c_scl_rate); 2505 2475 if (ret) 2506 2476 goto err_put_dev; 2507 2477
+1 -6
drivers/i3c/master/dw-i3c-master.c
··· 599 599 600 600 switch (bus->mode) { 601 601 case I3C_BUS_MODE_MIXED_FAST: 602 + case I3C_BUS_MODE_MIXED_LIMITED: 602 603 ret = dw_i2c_clk_cfg(master); 603 604 if (ret) 604 605 return ret; ··· 1061 1060 kfree(data); 1062 1061 } 1063 1062 1064 - static u32 dw_i3c_master_i2c_funcs(struct i3c_master_controller *m) 1065 - { 1066 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 1067 - } 1068 - 1069 1063 static irqreturn_t dw_i3c_master_irq_handler(int irq, void *dev_id) 1070 1064 { 1071 1065 struct dw_i3c_master *master = dev_id; ··· 1095 1099 .attach_i2c_dev = dw_i3c_master_attach_i2c_dev, 1096 1100 .detach_i2c_dev = dw_i3c_master_detach_i2c_dev, 1097 1101 .i2c_xfers = dw_i3c_master_i2c_xfers, 1098 - .i2c_funcs = dw_i3c_master_i2c_funcs, 1099 1102 }; 1100 1103 1101 1104 static int dw_i3c_probe(struct platform_device *pdev)
+1 -9
drivers/i3c/master/i3c-master-cdns.c
··· 864 864 return ret; 865 865 } 866 866 867 - static u32 cdns_i3c_master_i2c_funcs(struct i3c_master_controller *m) 868 - { 869 - return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR; 870 - } 871 - 872 867 struct cdns_i3c_i2c_dev_data { 873 868 u16 id; 874 869 s16 ibi; ··· 1005 1010 master->free_rr_slots &= ~BIT(slot); 1006 1011 i2c_dev_set_master_data(dev, data); 1007 1012 1008 - writel(prepare_rr0_dev_address(dev->boardinfo->base.addr) | 1009 - (dev->boardinfo->base.flags & I2C_CLIENT_TEN ? 1010 - DEV_ID_RR0_LVR_EXT_ADDR : 0), 1013 + writel(prepare_rr0_dev_address(dev->boardinfo->base.addr), 1011 1014 master->regs + DEV_ID_RR0(data->id)); 1012 1015 writel(dev->boardinfo->lvr, master->regs + DEV_ID_RR2(data->id)); 1013 1016 writel(readl(master->regs + DEVS_CTRL) | ··· 1511 1518 .send_ccc_cmd = cdns_i3c_master_send_ccc_cmd, 1512 1519 .priv_xfers = cdns_i3c_master_priv_xfers, 1513 1520 .i2c_xfers = cdns_i3c_master_i2c_xfers, 1514 - .i2c_funcs = cdns_i3c_master_i2c_funcs, 1515 1521 .enable_ibi = cdns_i3c_master_enable_ibi, 1516 1522 .disable_ibi = cdns_i3c_master_disable_ibi, 1517 1523 .request_ibi = cdns_i3c_master_request_ibi,
+6 -4
include/linux/i3c/master.h
··· 48 48 #define I3C_LVR_I2C_INDEX(x) ((x) << 5) 49 49 #define I3C_LVR_I2C_FM_MODE BIT(4) 50 50 51 - #define I2C_MAX_ADDR GENMASK(9, 0) 51 + #define I2C_MAX_ADDR GENMASK(6, 0) 52 52 53 53 /** 54 54 * struct i2c_dev_boardinfo - I2C device board information ··· 250 250 * the bus. The only impact in this mode is that the 251 251 * high SCL pulse has to stay below 50ns to trick I2C 252 252 * devices when transmitting I3C frames 253 + * @I3C_BUS_MODE_MIXED_LIMITED: I2C devices without 50ns spike filter are 254 + * present on the bus. However they allow 255 + * compliance up to the maximum SDR SCL clock 256 + * frequency. 253 257 * @I3C_BUS_MODE_MIXED_SLOW: I2C devices without 50ns spike filter are present 254 258 * on the bus 255 259 */ 256 260 enum i3c_bus_mode { 257 261 I3C_BUS_MODE_PURE, 258 262 I3C_BUS_MODE_MIXED_FAST, 263 + I3C_BUS_MODE_MIXED_LIMITED, 259 264 I3C_BUS_MODE_MIXED_SLOW, 260 265 }; 261 266 ··· 395 390 * and i2c_put_dma_safe_msg_buf() helpers provided by the I2C 396 391 * framework. 397 392 * This method is mandatory. 398 - * @i2c_funcs: expose the supported I2C functionalities. 399 - * This method is mandatory. 400 393 * @request_ibi: attach an IBI handler to an I3C device. This implies defining 401 394 * an IBI handler and the constraints of the IBI (maximum payload 402 395 * length and number of pre-allocated slots). ··· 440 437 void (*detach_i2c_dev)(struct i2c_dev_desc *dev); 441 438 int (*i2c_xfers)(struct i2c_dev_desc *dev, 442 439 const struct i2c_msg *xfers, int nxfers); 443 - u32 (*i2c_funcs)(struct i3c_master_controller *master); 444 440 int (*request_ibi)(struct i3c_dev_desc *dev, 445 441 const struct i3c_ibi_setup *req); 446 442 void (*free_ibi)(struct i3c_dev_desc *dev);