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

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

Pull i3c updates from Alexandre Belloni:
"The silvaco driver gets support for the integration of the IP in the
Nuvoton npcm845 SoC. There is also a fix for a possible NULL pointer
dereference that can happen with early IBIs. Summary:

Core:

- Fix a possible NULL pointer dereference due to IBI coming when the
target driver is not yet probed.

Drivers:

- mipi-i3c-hci: Use I2C DMA-safe api

- svc: add Nuvoton npcm845 support"

* tag 'i3c/for-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
i3c: Add NULL pointer check in i3c_master_queue_ibi()
i3c: master: Drop duplicate check before calling OF APIs
i3c: master: svc: Fix implicit fallthrough in svc_i3c_master_ibi_work()
i3c: master: svc: Fix missing STOP for master request
i3c: master: svc: Use readsb helper for reading MDB
i3c: master: svc: Fix missing the IBI rules
i3c: master: svc: Fix i3c_master_get_free_addr return check
i3c: master: svc: Fix npcm845 DAA process corruption
i3c: master: svc: Fix npcm845 invalid slvstart event
i3c: master: svc: Fix npcm845 FIFO empty issue
i3c: master: svc: Add support for Nuvoton npcm845 i3c
dt-bindings: i3c: silvaco: Add npcm845 compatible string
dt-bindings: i3c: dw: Add power-domains
i3c: master: svc: Flush FIFO before sending Dynamic Address Assignment(DAA)
i3c: mipi-i3c-hci: Use I2C DMA-safe api
i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
MAINTAINERS: Add Frank Li to Silvaco I3C
MAINTAINERS: Remove Conor Culhane from Silvaco I3C

+154 -36
+4
CREDITS
··· 855 855 E: john@phrozen.org 856 856 D: MediaTek MT7623 Gigabit ethernet support 857 857 858 + N: Conor Culhane 859 + E: conor.culhane@silvaco.com 860 + D: Silvaco I3C master driver 861 + 858 862 N: Laurence Culhane 859 863 E: loz@holmes.demon.co.uk 860 864 D: Wrote the initial alpha SLIP code
+3 -1
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml
··· 14 14 15 15 properties: 16 16 compatible: 17 - const: silvaco,i3c-master-v1 17 + enum: 18 + - nuvoton,npcm845-i3c 19 + - silvaco,i3c-master-v1 18 20 19 21 reg: 20 22 maxItems: 1
+3
Documentation/devicetree/bindings/i3c/snps,dw-i3c-master.yaml
··· 34 34 interrupts: 35 35 maxItems: 1 36 36 37 + power-domains: 38 + maxItems: 1 39 + 37 40 required: 38 41 - compatible 39 42 - reg
+3 -1
MAINTAINERS
··· 11265 11265 11266 11266 I3C SUBSYSTEM 11267 11267 M: Alexandre Belloni <alexandre.belloni@bootlin.com> 11268 + R: Frank Li <Frank.Li@nxp.com> 11268 11269 L: linux-i3c@lists.infradead.org (moderated for non-subscribers) 11269 11270 S: Maintained 11270 11271 C: irc://chat.freenode.net/linux-i3c ··· 22107 22106 22108 22107 SILVACO I3C DUAL-ROLE MASTER 22109 22108 M: Miquel Raynal <miquel.raynal@bootlin.com> 22110 - M: Conor Culhane <conor.culhane@silvaco.com> 22109 + M: Frank Li <Frank.Li@nxp.com> 22111 22110 L: linux-i3c@lists.infradead.org (moderated for non-subscribers) 22111 + L: imx@lists.linux.dev 22112 22112 S: Maintained 22113 22113 F: Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml 22114 22114 F: drivers/i3c/master/svc-i3c-master.c
+9 -12
drivers/i3c/master.c
··· 2276 2276 u32 reg[3]; 2277 2277 int ret; 2278 2278 2279 - if (!master || !node) 2279 + if (!master) 2280 2280 return -EINVAL; 2281 2281 2282 2282 ret = of_property_read_u32_array(node, "reg", reg, ARRAY_SIZE(reg)); ··· 2369 2369 { 2370 2370 /* Fall back to no spike filters and FM bus mode. */ 2371 2371 u8 lvr = I3C_LVR_I2C_INDEX(2) | I3C_LVR_I2C_FM_MODE; 2372 + u32 reg[3]; 2372 2373 2373 - if (client->dev.of_node) { 2374 - u32 reg[3]; 2375 - 2376 - if (!of_property_read_u32_array(client->dev.of_node, "reg", 2377 - reg, ARRAY_SIZE(reg))) 2378 - lvr = reg[2]; 2379 - } 2374 + if (!of_property_read_u32_array(client->dev.of_node, "reg", reg, ARRAY_SIZE(reg))) 2375 + lvr = reg[2]; 2380 2376 2381 2377 return lvr; 2382 2378 } ··· 2482 2486 struct i2c_adapter *adap = i3c_master_to_i2c_adapter(master); 2483 2487 struct i2c_dev_desc *i2cdev; 2484 2488 struct i2c_dev_boardinfo *i2cboardinfo; 2485 - int ret, id = -ENODEV; 2489 + int ret, id; 2486 2490 2487 2491 adap->dev.parent = master->dev.parent; 2488 2492 adap->owner = master->dev.parent->driver->owner; ··· 2493 2497 adap->timeout = 1000; 2494 2498 adap->retries = 3; 2495 2499 2496 - if (master->dev.of_node) 2497 - id = of_alias_get_id(master->dev.of_node, "i2c"); 2498 - 2500 + id = of_alias_get_id(master->dev.of_node, "i2c"); 2499 2501 if (id >= 0) { 2500 2502 adap->nr = id; 2501 2503 ret = i2c_add_numbered_adapter(adap); ··· 2555 2561 */ 2556 2562 void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot) 2557 2563 { 2564 + if (!dev->ibi || !slot) 2565 + return; 2566 + 2558 2567 atomic_inc(&dev->ibi->pending_ibis); 2559 2568 queue_work(dev->ibi->wq, &slot->work); 2560 2569 }
+1 -1
drivers/i3c/master/dw-i3c-master.c
··· 1079 1079 } 1080 1080 1081 1081 static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev, 1082 - const struct i2c_msg *i2c_xfers, 1082 + struct i2c_msg *i2c_xfers, 1083 1083 int i2c_nxfers) 1084 1084 { 1085 1085 struct dw_i3c_i2c_dev_data *data = i2c_dev_get_master_data(dev);
+1 -1
drivers/i3c/master/i3c-master-cdns.c
··· 813 813 } 814 814 815 815 static int cdns_i3c_master_i2c_xfers(struct i2c_dev_desc *dev, 816 - const struct i2c_msg *xfers, int nxfers) 816 + struct i2c_msg *xfers, int nxfers) 817 817 { 818 818 struct i3c_master_controller *m = i2c_dev_get_master(dev); 819 819 struct cdns_i3c_master *master = to_cdns_i3c_master(m);
+4 -6
drivers/i3c/master/mipi-i3c-hci/core.c
··· 367 367 } 368 368 369 369 static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, 370 - const struct i2c_msg *i2c_xfers, int nxfers) 370 + struct i2c_msg *i2c_xfers, int nxfers) 371 371 { 372 372 struct i3c_master_controller *m = i2c_dev_get_master(dev); 373 373 struct i3c_hci *hci = to_i3c_hci(m); ··· 382 382 return -ENOMEM; 383 383 384 384 for (i = 0; i < nxfers; i++) { 385 - xfer[i].data = i2c_xfers[i].buf; 385 + xfer[i].data = i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1); 386 386 xfer[i].data_len = i2c_xfers[i].len; 387 387 xfer[i].rnw = i2c_xfers[i].flags & I2C_M_RD; 388 388 hci->cmd->prep_i2c_xfer(hci, dev, &xfer[i]); 389 389 xfer[i].cmd_desc[0] |= CMD_0_ROC; 390 - ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]); 391 - if (ret) 392 - goto out; 393 390 } 394 391 last = i - 1; 395 392 xfer[last].cmd_desc[0] |= CMD_0_TOC; ··· 409 412 410 413 out: 411 414 for (i = 0; i < nxfers; i++) 412 - i3c_hci_free_safe_xfer_buf(hci, &xfer[i]); 415 + i2c_put_dma_safe_msg_buf(xfer[i].data, &i2c_xfers[i], 416 + ret ? false : true); 413 417 414 418 hci_free_xfer(xfer, nxfers); 415 419 return ret;
+125 -13
drivers/i3c/master/svc-i3c-master.c
··· 32 32 #define SVC_I3C_MCONFIG_ODBAUD(x) FIELD_PREP(GENMASK(23, 16), (x)) 33 33 #define SVC_I3C_MCONFIG_ODHPP(x) FIELD_PREP(BIT(24), (x)) 34 34 #define SVC_I3C_MCONFIG_SKEW(x) FIELD_PREP(GENMASK(27, 25), (x)) 35 + #define SVC_I3C_MCONFIG_SKEW_MASK GENMASK(27, 25) 35 36 #define SVC_I3C_MCONFIG_I2CBAUD(x) FIELD_PREP(GENMASK(31, 28), (x)) 36 37 37 38 #define SVC_I3C_MCTRL 0x084 ··· 59 58 #define SVC_I3C_MSTATUS 0x088 60 59 #define SVC_I3C_MSTATUS_STATE(x) FIELD_GET(GENMASK(2, 0), (x)) 61 60 #define SVC_I3C_MSTATUS_STATE_DAA(x) (SVC_I3C_MSTATUS_STATE(x) == 5) 61 + #define SVC_I3C_MSTATUS_STATE_SLVREQ(x) (SVC_I3C_MSTATUS_STATE(x) == 1) 62 62 #define SVC_I3C_MSTATUS_STATE_IDLE(x) (SVC_I3C_MSTATUS_STATE(x) == 0) 63 63 #define SVC_I3C_MSTATUS_BETWEEN(x) FIELD_GET(BIT(4), (x)) 64 64 #define SVC_I3C_MSTATUS_NACKED(x) FIELD_GET(BIT(5), (x)) ··· 115 113 #define SVC_I3C_MWDATAHE 0x0BC 116 114 #define SVC_I3C_MRDATAB 0x0C0 117 115 #define SVC_I3C_MRDATAH 0x0C8 116 + #define SVC_I3C_MWDATAB1 0x0CC 118 117 #define SVC_I3C_MWMSG_SDR 0x0D0 119 118 #define SVC_I3C_MRMSG_SDR 0x0D4 120 119 #define SVC_I3C_MWMSG_DDR 0x0D8 ··· 135 132 136 133 #define SVC_I3C_EVENT_IBI GENMASK(7, 0) 137 134 #define SVC_I3C_EVENT_HOTJOIN BIT(31) 135 + 136 + /* 137 + * SVC_I3C_QUIRK_FIFO_EMPTY: 138 + * I3C HW stalls the write transfer if the transmit FIFO becomes empty, 139 + * when new data is written to FIFO, I3C HW resumes the transfer but 140 + * the first transmitted data bit may have the wrong value. 141 + * Workaround: 142 + * Fill the FIFO in advance to prevent FIFO from becoming empty. 143 + */ 144 + #define SVC_I3C_QUIRK_FIFO_EMPTY BIT(0) 145 + /* 146 + * SVC_I3C_QUIRK_FLASE_SLVSTART: 147 + * I3C HW may generate an invalid SlvStart event when emitting a STOP. 148 + * If it is a true SlvStart, the MSTATUS state is SLVREQ. 149 + */ 150 + #define SVC_I3C_QUIRK_FALSE_SLVSTART BIT(1) 151 + /* 152 + * SVC_I3C_QUIRK_DAA_CORRUPT: 153 + * When MCONFIG.SKEW=0 and MCONFIG.ODHPP=0, the ENTDAA transaction gets 154 + * corrupted and results in a no repeated-start condition at the end of 155 + * address assignment. 156 + * Workaround: 157 + * Set MCONFIG.SKEW to 1 before initiating the DAA process. After the DAA 158 + * process is completed, return MCONFIG.SKEW to its previous value. 159 + */ 160 + #define SVC_I3C_QUIRK_DAA_CORRUPT BIT(2) 138 161 139 162 struct svc_i3c_cmd { 140 163 u8 addr; ··· 185 156 struct svc_i3c_regs_save { 186 157 u32 mconfig; 187 158 u32 mdynaddr; 159 + }; 160 + 161 + struct svc_i3c_drvdata { 162 + u32 quirks; 188 163 }; 189 164 190 165 /** ··· 216 183 * @ibi.tbq_slot: To be queued IBI slot 217 184 * @ibi.lock: IBI lock 218 185 * @lock: Transfer lock, protect between IBI work thread and callbacks from master 186 + * @drvdata: Driver data 219 187 * @enabled_events: Bit masks for enable events (IBI, HotJoin). 220 188 * @mctrl_config: Configuration value in SVC_I3C_MCTRL for setting speed back. 221 189 */ ··· 248 214 spinlock_t lock; 249 215 } ibi; 250 216 struct mutex lock; 217 + const struct svc_i3c_drvdata *drvdata; 251 218 u32 enabled_events; 252 219 u32 mctrl_config; 253 220 }; ··· 264 229 int ibi; 265 230 struct i3c_generic_ibi_pool *ibi_pool; 266 231 }; 232 + 233 + static inline bool svc_has_quirk(struct svc_i3c_master *master, u32 quirk) 234 + { 235 + return (master->drvdata->quirks & quirk); 236 + } 237 + 238 + static inline bool svc_has_daa_corrupt(struct svc_i3c_master *master) 239 + { 240 + return ((master->drvdata->quirks & SVC_I3C_QUIRK_DAA_CORRUPT) && 241 + !(master->mctrl_config & 242 + (SVC_I3C_MCONFIG_SKEW_MASK | SVC_I3C_MCONFIG_ODHPP(1)))); 243 + } 267 244 268 245 static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask) 269 246 { ··· 425 378 slot->len < SVC_I3C_FIFO_SIZE) { 426 379 mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL); 427 380 count = SVC_I3C_MDATACTRL_RXCOUNT(mdatactrl); 428 - readsl(master->regs + SVC_I3C_MRDATAB, buf, count); 381 + readsb(master->regs + SVC_I3C_MRDATAB, buf, count); 429 382 slot->len += count; 430 383 buf += count; 431 384 } ··· 592 545 queue_work(master->base.wq, &master->hj_work); 593 546 break; 594 547 case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST: 548 + svc_i3c_master_emit_stop(master); 549 + break; 595 550 default: 596 551 break; 597 552 } ··· 612 563 613 564 /* Clear the interrupt status */ 614 565 writel(SVC_I3C_MINT_SLVSTART, master->regs + SVC_I3C_MSTATUS); 566 + 567 + /* Ignore the false event */ 568 + if (svc_has_quirk(master, SVC_I3C_QUIRK_FALSE_SLVSTART) && 569 + !SVC_I3C_MSTATUS_STATE_SLVREQ(active)) 570 + return IRQ_HANDLED; 615 571 616 572 svc_i3c_master_disable_interrupts(master); 617 573 ··· 942 888 u8 *addrs, unsigned int *count) 943 889 { 944 890 u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0; 945 - unsigned int dev_nb = 0, last_addr = 0; 891 + unsigned int dev_nb = 0, last_addr = 0, dyn_addr = 0; 946 892 u32 reg; 947 893 int ret, i; 894 + 895 + svc_i3c_master_flush_fifo(master); 948 896 949 897 while (true) { 950 898 /* clean SVC_I3C_MINT_IBIWON w1c bits */ ··· 986 930 987 931 if (SVC_I3C_MSTATUS_RXPEND(reg)) { 988 932 u8 data[6]; 933 + 934 + /* 935 + * One slave sends its ID to request for address assignment, 936 + * prefilling the dynamic address can reduce SCL clock stalls 937 + * and also fix the SVC_I3C_QUIRK_FIFO_EMPTY quirk. 938 + * 939 + * Ideally, prefilling before the processDAA command is better. 940 + * However, it requires an additional check to write the dyn_addr 941 + * at the right time because the driver needs to write the processDAA 942 + * command twice for one assignment. 943 + * Prefilling here is safe and efficient because the FIFO starts 944 + * filling within a few hundred nanoseconds, which is significantly 945 + * faster compared to the 64 SCL clock cycles. 946 + */ 947 + ret = i3c_master_get_free_addr(&master->base, last_addr + 1); 948 + if (ret < 0) 949 + break; 950 + 951 + dyn_addr = ret; 952 + writel(dyn_addr, master->regs + SVC_I3C_MWDATAB); 989 953 990 954 /* 991 955 * We only care about the 48-bit provisioned ID yet to ··· 1085 1009 if (ret) 1086 1010 break; 1087 1011 1088 - /* Give the slave device a suitable dynamic address */ 1089 - ret = i3c_master_get_free_addr(&master->base, last_addr + 1); 1090 - if (ret < 0) 1091 - break; 1092 - 1093 - addrs[dev_nb] = ret; 1012 + addrs[dev_nb] = dyn_addr; 1094 1013 dev_dbg(master->dev, "DAA: device %d assigned to 0x%02x\n", 1095 1014 dev_nb, addrs[dev_nb]); 1096 - 1097 - writel(addrs[dev_nb], master->regs + SVC_I3C_MWDATAB); 1098 1015 last_addr = addrs[dev_nb++]; 1099 1016 } 1100 1017 1101 1018 /* Need manual issue STOP except for Complete condition */ 1102 1019 svc_i3c_master_emit_stop(master); 1020 + svc_i3c_master_flush_fifo(master); 1021 + 1103 1022 return ret; 1104 1023 } 1105 1024 ··· 1108 1037 1109 1038 /* Create the IBIRULES register for both cases */ 1110 1039 i3c_bus_for_each_i3cdev(&master->base.bus, dev) { 1111 - if (I3C_BCR_DEVICE_ROLE(dev->info.bcr) == I3C_BCR_I3C_MASTER) 1040 + if (!(dev->info.bcr & I3C_BCR_IBI_REQ_CAP)) 1112 1041 continue; 1113 1042 1114 1043 if (dev->info.bcr & I3C_BCR_IBI_PAYLOAD) { ··· 1167 1096 } 1168 1097 1169 1098 spin_lock_irqsave(&master->xferqueue.lock, flags); 1099 + 1100 + if (svc_has_daa_corrupt(master)) 1101 + writel(master->mctrl_config | SVC_I3C_MCONFIG_SKEW(1), 1102 + master->regs + SVC_I3C_MCONFIG); 1103 + 1170 1104 ret = svc_i3c_master_do_daa_locked(master, addrs, &dev_nb); 1105 + 1106 + if (svc_has_daa_corrupt(master)) 1107 + writel(master->mctrl_config, master->regs + SVC_I3C_MCONFIG); 1108 + 1171 1109 spin_unlock_irqrestore(&master->xferqueue.lock, flags); 1172 1110 1173 1111 svc_i3c_master_clear_merrwarn(master); ··· 1300 1220 SVC_I3C_MCTRL_RDTERM(*actual_len), 1301 1221 master->regs + SVC_I3C_MCTRL); 1302 1222 1223 + /* 1224 + * The entire transaction can consist of multiple write transfers. 1225 + * Prefilling before EmitStartAddr causes the data to be emitted 1226 + * immediately, becoming part of the previous transfer. 1227 + * The only way to work around this hardware issue is to let the 1228 + * FIFO start filling as soon as possible after EmitStartAddr. 1229 + */ 1230 + if (svc_has_quirk(master, SVC_I3C_QUIRK_FIFO_EMPTY) && !rnw && xfer_len) { 1231 + u32 end = xfer_len > SVC_I3C_FIFO_SIZE ? 0 : SVC_I3C_MWDATAB_END; 1232 + u32 len = min_t(u32, xfer_len, SVC_I3C_FIFO_SIZE); 1233 + 1234 + writesb(master->regs + SVC_I3C_MWDATAB1, out, len - 1); 1235 + /* Mark END bit if this is the last byte */ 1236 + writel(out[len - 1] | end, master->regs + SVC_I3C_MWDATAB); 1237 + xfer_len -= len; 1238 + out += len; 1239 + } 1240 + 1303 1241 ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, 1304 1242 SVC_I3C_MSTATUS_MCTRLDONE(reg), 0, 1000); 1305 1243 if (ret) ··· 1406 1308 emit_stop: 1407 1309 svc_i3c_master_emit_stop(master); 1408 1310 svc_i3c_master_clear_merrwarn(master); 1311 + svc_i3c_master_flush_fifo(master); 1409 1312 1410 1313 return ret; 1411 1314 } ··· 1683 1584 } 1684 1585 1685 1586 static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev, 1686 - const struct i2c_msg *xfers, 1587 + struct i2c_msg *xfers, 1687 1588 int nxfers) 1688 1589 { 1689 1590 struct i3c_master_controller *m = i2c_dev_get_master(dev); ··· 1916 1817 if (!master) 1917 1818 return -ENOMEM; 1918 1819 1820 + master->drvdata = of_device_get_match_data(dev); 1821 + if (!master->drvdata) 1822 + return -EINVAL; 1823 + 1919 1824 master->regs = devm_platform_ioremap_resource(pdev, 0); 1920 1825 if (IS_ERR(master->regs)) 1921 1826 return PTR_ERR(master->regs); ··· 2061 1958 svc_i3c_runtime_resume, NULL) 2062 1959 }; 2063 1960 1961 + static const struct svc_i3c_drvdata npcm845_drvdata = { 1962 + .quirks = SVC_I3C_QUIRK_FIFO_EMPTY | 1963 + SVC_I3C_QUIRK_FALSE_SLVSTART | 1964 + SVC_I3C_QUIRK_DAA_CORRUPT, 1965 + }; 1966 + 1967 + static const struct svc_i3c_drvdata svc_default_drvdata = {}; 1968 + 2064 1969 static const struct of_device_id svc_i3c_master_of_match_tbl[] = { 2065 - { .compatible = "silvaco,i3c-master-v1"}, 1970 + { .compatible = "nuvoton,npcm845-i3c", .data = &npcm845_drvdata }, 1971 + { .compatible = "silvaco,i3c-master-v1", .data = &svc_default_drvdata }, 2066 1972 { /* sentinel */ }, 2067 1973 }; 2068 1974 MODULE_DEVICE_TABLE(of, svc_i3c_master_of_match_tbl);
+1 -1
include/linux/i3c/master.h
··· 475 475 int (*attach_i2c_dev)(struct i2c_dev_desc *dev); 476 476 void (*detach_i2c_dev)(struct i2c_dev_desc *dev); 477 477 int (*i2c_xfers)(struct i2c_dev_desc *dev, 478 - const struct i2c_msg *xfers, int nxfers); 478 + struct i2c_msg *xfers, int nxfers); 479 479 int (*request_ibi)(struct i3c_dev_desc *dev, 480 480 const struct i3c_ibi_setup *req); 481 481 void (*free_ibi)(struct i3c_dev_desc *dev);