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

Merge tag 'i2c-for-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c updates from Wolfram Sang:
"I2C Core:
- prevent double-free of an fwnode if it is a software node
- use recent helpers instead of custom ACPI or outdated OF ones
- add a more elaborate description of a message flag

Cleanups and refactorings:
- lpi2c, riic, st, stm32f7: general improvements
- riic: support more flexible IRQ configurations
- tegra: fix documentation

Improvements:
- lpi2c: improve register polling and add atomic transfer
- imx: use guarded spinlocks

New hardware support:
- Samsung Exynos 2200
- Renesas RZ/T2H (R9A09G077), RZ/N2H (R9A09G087)

DT binding:
- rk3x: enable power domains
- nxp: support clock property"

* tag 'i2c-for-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
i2c: core: Fix double-free of fwnode in i2c_unregister_device()
i2c: lpi2c: implement xfer_atomic callback
i2c: lpi2c: use readl_poll_timeout() for register polling
dt-bindings: i2c: i2c-rk3x: Allow use of a power-domain
dt-bindings: i2c: exynos5: add samsung,exynos2200-hsi2c compatible
i2c: lpi2c: convert to use secs_to_jiffies()
i2c: st: Use min() to improve code
i2c: imx: use guard to take spinlock
i2c: stm32f7: Use str_on_off() helper
dt-bindings: i2c: nxp,pnx-i2c: allow clocks property
i2c: riic: Add support for RZ/T2H SoC
i2c: riic: Move generic compatible string to end of array
i2c: riic: Pass IRQ desc array as part of OF data
dt-bindings: i2c: renesas,riic: Document RZ/T2H and RZ/N2H support
dt-bindings: i2c: renesas,riic: Move ref for i2c-controller.yaml to the end
i2c: tegra: Add missing kernel-doc for dma_dev member
i2c: Clarify behavior of I2C_M_RD flag
i2c: mux: pca954x: Use dev_fwnode()
i2c: acpi: Replace custom code with device_match_acpi_handle()

+333 -165
+1
Documentation/devicetree/bindings/i2c/i2c-exynos5.yaml
··· 36 36 - items: 37 37 - enum: 38 38 - google,gs101-hsi2c 39 + - samsung,exynos2200-hsi2c 39 40 - samsung,exynos850-hsi2c 40 41 - const: samsung,exynosautov9-hsi2c 41 42 - const: samsung,exynos5-hsi2c # Exynos5250 and Exynos5420
+3
Documentation/devicetree/bindings/i2c/i2c-rk3x.yaml
··· 105 105 (t(f) in the I2C specification). If not specified we will use the SCL 106 106 value since they are the same in nearly all cases. 107 107 108 + power-domains: 109 + maxItems: 1 110 + 108 111 required: 109 112 - compatible 110 113 - reg
+3
Documentation/devicetree/bindings/i2c/nxp,pnx-i2c.yaml
··· 22 22 interrupts: 23 23 maxItems: 1 24 24 25 + clocks: 26 + maxItems: 1 27 + 25 28 clock-frequency: 26 29 default: 100000 27 30
+71 -34
Documentation/devicetree/bindings/i2c/renesas,riic.yaml
··· 10 10 - Chris Brandt <chris.brandt@renesas.com> 11 11 - Wolfram Sang <wsa+renesas@sang-engineering.com> 12 12 13 - allOf: 14 - - $ref: /schemas/i2c/i2c-controller.yaml# 15 - 16 13 properties: 17 14 compatible: 18 15 oneOf: ··· 29 32 - renesas,riic-r9a09g056 # RZ/V2N 30 33 - const: renesas,riic-r9a09g057 # RZ/V2H(P) 31 34 32 - - const: renesas,riic-r9a09g057 # RZ/V2H(P) 35 + - enum: 36 + - renesas,riic-r9a09g057 # RZ/V2H(P) 37 + - renesas,riic-r9a09g077 # RZ/T2H 38 + 39 + - items: 40 + - const: renesas,riic-r9a09g087 # RZ/N2H 41 + - const: renesas,riic-r9a09g077 # RZ/T2H 33 42 34 43 reg: 35 44 maxItems: 1 36 45 37 46 interrupts: 38 - items: 39 - - description: Transmit End Interrupt 40 - - description: Receive Data Full Interrupt 41 - - description: Transmit Data Empty Interrupt 42 - - description: Stop Condition Detection Interrupt 43 - - description: Start Condition Detection Interrupt 44 - - description: NACK Reception Interrupt 45 - - description: Arbitration-Lost Interrupt 46 - - description: Timeout Interrupt 47 + oneOf: 48 + - items: 49 + - description: Transmit End Interrupt 50 + - description: Receive Data Full Interrupt 51 + - description: Transmit Data Empty Interrupt 52 + - description: Stop Condition Detection Interrupt 53 + - description: Start Condition Detection Interrupt 54 + - description: NACK Reception Interrupt 55 + - description: Arbitration-Lost Interrupt 56 + - description: Timeout Interrupt 57 + - items: 58 + - description: Transfer Error Or Event Generation 59 + - description: Receive Data Full Interrupt 60 + - description: Transmit Data Empty Interrupt 61 + - description: Transmit End Interrupt 47 62 48 63 interrupt-names: 49 - items: 50 - - const: tei 51 - - const: ri 52 - - const: ti 53 - - const: spi 54 - - const: sti 55 - - const: naki 56 - - const: ali 57 - - const: tmoi 64 + oneOf: 65 + - items: 66 + - const: tei 67 + - const: ri 68 + - const: ti 69 + - const: spi 70 + - const: sti 71 + - const: naki 72 + - const: ali 73 + - const: tmoi 74 + - items: 75 + - const: eei 76 + - const: rxi 77 + - const: txi 78 + - const: tei 58 79 59 80 clock-frequency: 60 81 description: ··· 99 84 - '#address-cells' 100 85 - '#size-cells' 101 86 102 - if: 103 - properties: 104 - compatible: 105 - contains: 106 - enum: 107 - - renesas,riic-r9a07g043 108 - - renesas,riic-r9a07g044 109 - - renesas,riic-r9a07g054 110 - - renesas,riic-r9a09g057 111 - then: 112 - required: 113 - - resets 87 + allOf: 88 + - $ref: /schemas/i2c/i2c-controller.yaml# 89 + 90 + - if: 91 + properties: 92 + compatible: 93 + contains: 94 + const: renesas,riic-r9a09g077 95 + then: 96 + properties: 97 + interrupts: 98 + maxItems: 4 99 + interrupt-names: 100 + maxItems: 4 101 + resets: false 102 + else: 103 + properties: 104 + interrupts: 105 + minItems: 8 106 + interrupt-names: 107 + minItems: 8 108 + 109 + - if: 110 + properties: 111 + compatible: 112 + contains: 113 + enum: 114 + - renesas,riic-r9a07g043 115 + - renesas,riic-r9a07g044 116 + - renesas,riic-r9a07g054 117 + - renesas,riic-r9a09g057 118 + then: 119 + required: 120 + - resets 114 121 115 122 unevaluatedProperties: false 116 123
+173 -83
drivers/i2c/busses/i2c-imx-lpi2c.c
··· 16 16 #include <linux/init.h> 17 17 #include <linux/interrupt.h> 18 18 #include <linux/io.h> 19 + #include <linux/iopoll.h> 19 20 #include <linux/kernel.h> 20 21 #include <linux/module.h> 21 22 #include <linux/of.h> ··· 188 187 struct i2c_client *target; 189 188 }; 190 189 190 + #define lpi2c_imx_read_msr_poll_timeout(atomic, val, cond) \ 191 + (atomic ? readl_poll_timeout_atomic(lpi2c_imx->base + LPI2C_MSR, val, \ 192 + cond, 0, 500000) : \ 193 + readl_poll_timeout(lpi2c_imx->base + LPI2C_MSR, val, cond, \ 194 + 0, 500000)) 195 + 191 196 static void lpi2c_imx_intctrl(struct lpi2c_imx_struct *lpi2c_imx, 192 197 unsigned int enable) 193 198 { 194 199 writel(enable, lpi2c_imx->base + LPI2C_MIER); 195 200 } 196 201 197 - static int lpi2c_imx_bus_busy(struct lpi2c_imx_struct *lpi2c_imx) 202 + static int lpi2c_imx_bus_busy(struct lpi2c_imx_struct *lpi2c_imx, bool atomic) 198 203 { 199 - unsigned long orig_jiffies = jiffies; 200 204 unsigned int temp; 205 + int err; 201 206 202 - while (1) { 203 - temp = readl(lpi2c_imx->base + LPI2C_MSR); 207 + err = lpi2c_imx_read_msr_poll_timeout(atomic, temp, 208 + temp & (MSR_ALF | MSR_BBF | MSR_MBF)); 204 209 205 - /* check for arbitration lost, clear if set */ 206 - if (temp & MSR_ALF) { 207 - writel(temp, lpi2c_imx->base + LPI2C_MSR); 208 - return -EAGAIN; 209 - } 210 + /* check for arbitration lost, clear if set */ 211 + if (temp & MSR_ALF) { 212 + writel(temp, lpi2c_imx->base + LPI2C_MSR); 213 + return -EAGAIN; 214 + } 210 215 211 - if (temp & (MSR_BBF | MSR_MBF)) 212 - break; 213 - 214 - if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { 215 - dev_dbg(&lpi2c_imx->adapter.dev, "bus not work\n"); 216 - if (lpi2c_imx->adapter.bus_recovery_info) 217 - i2c_recover_bus(&lpi2c_imx->adapter); 218 - return -ETIMEDOUT; 219 - } 220 - schedule(); 216 + /* check for bus not busy */ 217 + if (err) { 218 + dev_dbg(&lpi2c_imx->adapter.dev, "bus not work\n"); 219 + if (lpi2c_imx->adapter.bus_recovery_info) 220 + i2c_recover_bus(&lpi2c_imx->adapter); 221 + return -ETIMEDOUT; 221 222 } 222 223 223 224 return 0; 225 + } 226 + 227 + static u32 lpi2c_imx_txfifo_cnt(struct lpi2c_imx_struct *lpi2c_imx) 228 + { 229 + return readl(lpi2c_imx->base + LPI2C_MFSR) & 0xff; 224 230 } 225 231 226 232 static void lpi2c_imx_set_mode(struct lpi2c_imx_struct *lpi2c_imx) ··· 250 242 } 251 243 252 244 static int lpi2c_imx_start(struct lpi2c_imx_struct *lpi2c_imx, 253 - struct i2c_msg *msgs) 245 + struct i2c_msg *msgs, bool atomic) 254 246 { 255 247 unsigned int temp; 256 248 ··· 262 254 temp = i2c_8bit_addr_from_msg(msgs) | (GEN_START << 8); 263 255 writel(temp, lpi2c_imx->base + LPI2C_MTDR); 264 256 265 - return lpi2c_imx_bus_busy(lpi2c_imx); 257 + return lpi2c_imx_bus_busy(lpi2c_imx, atomic); 266 258 } 267 259 268 - static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx) 260 + static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx, bool atomic) 269 261 { 270 - unsigned long orig_jiffies = jiffies; 271 262 unsigned int temp; 263 + int err; 272 264 273 265 writel(GEN_STOP << 8, lpi2c_imx->base + LPI2C_MTDR); 274 266 275 - do { 276 - temp = readl(lpi2c_imx->base + LPI2C_MSR); 277 - if (temp & MSR_SDF) 278 - break; 267 + err = lpi2c_imx_read_msr_poll_timeout(atomic, temp, temp & MSR_SDF); 279 268 280 - if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { 281 - dev_dbg(&lpi2c_imx->adapter.dev, "stop timeout\n"); 282 - if (lpi2c_imx->adapter.bus_recovery_info) 283 - i2c_recover_bus(&lpi2c_imx->adapter); 284 - break; 285 - } 286 - schedule(); 287 - 288 - } while (1); 269 + if (err) { 270 + dev_dbg(&lpi2c_imx->adapter.dev, "stop timeout\n"); 271 + if (lpi2c_imx->adapter.bus_recovery_info) 272 + i2c_recover_bus(&lpi2c_imx->adapter); 273 + } 289 274 } 290 275 291 276 /* CLKLO = I2C_CLK_RATIO * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI/2 */ ··· 392 391 return time_left ? 0 : -ETIMEDOUT; 393 392 } 394 393 395 - static int lpi2c_imx_txfifo_empty(struct lpi2c_imx_struct *lpi2c_imx) 394 + static int lpi2c_imx_txfifo_empty(struct lpi2c_imx_struct *lpi2c_imx, bool atomic) 396 395 { 397 - unsigned long orig_jiffies = jiffies; 398 - u32 txcnt; 396 + unsigned int temp; 397 + int err; 399 398 400 - do { 401 - txcnt = readl(lpi2c_imx->base + LPI2C_MFSR) & 0xff; 399 + err = lpi2c_imx_read_msr_poll_timeout(atomic, temp, 400 + (temp & MSR_NDF) || !lpi2c_imx_txfifo_cnt(lpi2c_imx)); 402 401 403 - if (readl(lpi2c_imx->base + LPI2C_MSR) & MSR_NDF) { 404 - dev_dbg(&lpi2c_imx->adapter.dev, "NDF detected\n"); 405 - return -EIO; 406 - } 402 + if (temp & MSR_NDF) { 403 + dev_dbg(&lpi2c_imx->adapter.dev, "NDF detected\n"); 404 + return -EIO; 405 + } 407 406 408 - if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { 409 - dev_dbg(&lpi2c_imx->adapter.dev, "txfifo empty timeout\n"); 410 - if (lpi2c_imx->adapter.bus_recovery_info) 411 - i2c_recover_bus(&lpi2c_imx->adapter); 412 - return -ETIMEDOUT; 413 - } 414 - schedule(); 415 - 416 - } while (txcnt); 407 + if (err) { 408 + dev_dbg(&lpi2c_imx->adapter.dev, "txfifo empty timeout\n"); 409 + if (lpi2c_imx->adapter.bus_recovery_info) 410 + i2c_recover_bus(&lpi2c_imx->adapter); 411 + return -ETIMEDOUT; 412 + } 417 413 418 414 return 0; 419 415 } ··· 434 436 writel(temp << 16, lpi2c_imx->base + LPI2C_MFCR); 435 437 } 436 438 437 - static void lpi2c_imx_write_txfifo(struct lpi2c_imx_struct *lpi2c_imx) 439 + static bool lpi2c_imx_write_txfifo(struct lpi2c_imx_struct *lpi2c_imx, bool atomic) 438 440 { 439 441 unsigned int data, txcnt; 440 442 ··· 449 451 txcnt++; 450 452 } 451 453 452 - if (lpi2c_imx->delivered < lpi2c_imx->msglen) 453 - lpi2c_imx_intctrl(lpi2c_imx, MIER_TDIE | MIER_NDIE); 454 - else 454 + if (lpi2c_imx->delivered < lpi2c_imx->msglen) { 455 + if (!atomic) 456 + lpi2c_imx_intctrl(lpi2c_imx, MIER_TDIE | MIER_NDIE); 457 + return false; 458 + } 459 + 460 + if (!atomic) 455 461 complete(&lpi2c_imx->complete); 462 + 463 + return true; 456 464 } 457 465 458 - static void lpi2c_imx_read_rxfifo(struct lpi2c_imx_struct *lpi2c_imx) 466 + static bool lpi2c_imx_read_rxfifo(struct lpi2c_imx_struct *lpi2c_imx, bool atomic) 459 467 { 460 468 unsigned int blocklen, remaining; 461 469 unsigned int temp, data; ··· 486 482 remaining = lpi2c_imx->msglen - lpi2c_imx->delivered; 487 483 488 484 if (!remaining) { 489 - complete(&lpi2c_imx->complete); 490 - return; 485 + if (!atomic) 486 + complete(&lpi2c_imx->complete); 487 + return true; 491 488 } 492 489 493 490 /* not finished, still waiting for rx data */ ··· 506 501 writel(temp, lpi2c_imx->base + LPI2C_MTDR); 507 502 } 508 503 509 - lpi2c_imx_intctrl(lpi2c_imx, MIER_RDIE); 504 + if (!atomic) 505 + lpi2c_imx_intctrl(lpi2c_imx, MIER_RDIE); 506 + 507 + return false; 510 508 } 511 509 512 510 static void lpi2c_imx_write(struct lpi2c_imx_struct *lpi2c_imx, ··· 517 509 { 518 510 lpi2c_imx->tx_buf = msgs->buf; 519 511 lpi2c_imx_set_tx_watermark(lpi2c_imx); 520 - lpi2c_imx_write_txfifo(lpi2c_imx); 512 + lpi2c_imx_write_txfifo(lpi2c_imx, false); 521 513 } 522 514 523 - static void lpi2c_imx_read(struct lpi2c_imx_struct *lpi2c_imx, 524 - struct i2c_msg *msgs) 515 + static int lpi2c_imx_write_atomic(struct lpi2c_imx_struct *lpi2c_imx, 516 + struct i2c_msg *msgs) 517 + { 518 + u32 temp; 519 + int err; 520 + 521 + lpi2c_imx->tx_buf = msgs->buf; 522 + 523 + err = lpi2c_imx_read_msr_poll_timeout(true, temp, 524 + (temp & MSR_NDF) || 525 + lpi2c_imx_write_txfifo(lpi2c_imx, true)); 526 + 527 + if (temp & MSR_NDF) 528 + return -EIO; 529 + 530 + return err; 531 + } 532 + 533 + static void lpi2c_imx_read_init(struct lpi2c_imx_struct *lpi2c_imx, 534 + struct i2c_msg *msgs) 525 535 { 526 536 unsigned int temp; 527 537 ··· 550 524 temp = msgs->len > CHUNK_DATA ? CHUNK_DATA - 1 : msgs->len - 1; 551 525 temp |= (RECV_DATA << 8); 552 526 writel(temp, lpi2c_imx->base + LPI2C_MTDR); 527 + } 553 528 554 - lpi2c_imx_intctrl(lpi2c_imx, MIER_RDIE | MIER_NDIE); 529 + static bool lpi2c_imx_read_chunk_atomic(struct lpi2c_imx_struct *lpi2c_imx) 530 + { 531 + u32 rxcnt; 532 + 533 + rxcnt = (readl(lpi2c_imx->base + LPI2C_MFSR) >> 16) & 0xFF; 534 + if (!rxcnt) 535 + return false; 536 + 537 + if (!lpi2c_imx_read_rxfifo(lpi2c_imx, true)) 538 + return false; 539 + 540 + return true; 541 + } 542 + 543 + static int lpi2c_imx_read_atomic(struct lpi2c_imx_struct *lpi2c_imx, 544 + struct i2c_msg *msgs) 545 + { 546 + u32 temp; 547 + int tmo_us; 548 + 549 + tmo_us = 1000000; 550 + do { 551 + if (lpi2c_imx_read_chunk_atomic(lpi2c_imx)) 552 + return 0; 553 + 554 + temp = readl(lpi2c_imx->base + LPI2C_MSR); 555 + 556 + if (temp & MSR_NDF) 557 + return -EIO; 558 + 559 + udelay(100); 560 + tmo_us -= 100; 561 + } while (tmo_us > 0); 562 + 563 + return -ETIMEDOUT; 555 564 } 556 565 557 566 static bool is_use_dma(struct lpi2c_imx_struct *lpi2c_imx, struct i2c_msg *msg) ··· 606 545 { 607 546 reinit_completion(&lpi2c_imx->complete); 608 547 609 - if (msg->flags & I2C_M_RD) 610 - lpi2c_imx_read(lpi2c_imx, msg); 611 - else 548 + if (msg->flags & I2C_M_RD) { 549 + lpi2c_imx_read_init(lpi2c_imx, msg); 550 + lpi2c_imx_intctrl(lpi2c_imx, MIER_RDIE | MIER_NDIE); 551 + } else { 612 552 lpi2c_imx_write(lpi2c_imx, msg); 553 + } 613 554 614 555 return lpi2c_imx_pio_msg_complete(lpi2c_imx); 556 + } 557 + 558 + static int lpi2c_imx_pio_xfer_atomic(struct lpi2c_imx_struct *lpi2c_imx, 559 + struct i2c_msg *msg) 560 + { 561 + if (msg->flags & I2C_M_RD) { 562 + lpi2c_imx_read_init(lpi2c_imx, msg); 563 + return lpi2c_imx_read_atomic(lpi2c_imx, msg); 564 + } 565 + 566 + return lpi2c_imx_write_atomic(lpi2c_imx, msg); 615 567 } 616 568 617 569 static int lpi2c_imx_dma_timeout_calculate(struct lpi2c_imx_struct *lpi2c_imx) ··· 637 563 time += 1; 638 564 639 565 /* Double calculated time */ 640 - return msecs_to_jiffies(time * MSEC_PER_SEC); 566 + return secs_to_jiffies(time); 641 567 } 642 568 643 569 static int lpi2c_imx_alloc_rx_cmd_buf(struct lpi2c_imx_struct *lpi2c_imx) ··· 1021 947 return ret; 1022 948 } 1023 949 1024 - static int lpi2c_imx_xfer(struct i2c_adapter *adapter, 1025 - struct i2c_msg *msgs, int num) 950 + static int lpi2c_imx_xfer_common(struct i2c_adapter *adapter, 951 + struct i2c_msg *msgs, int num, bool atomic) 1026 952 { 1027 953 struct lpi2c_imx_struct *lpi2c_imx = i2c_get_adapdata(adapter); 1028 954 unsigned int temp; ··· 1033 959 return result; 1034 960 1035 961 for (i = 0; i < num; i++) { 1036 - result = lpi2c_imx_start(lpi2c_imx, &msgs[i]); 962 + result = lpi2c_imx_start(lpi2c_imx, &msgs[i], atomic); 1037 963 if (result) 1038 964 goto disable; 1039 965 ··· 1045 971 lpi2c_imx->tx_buf = NULL; 1046 972 lpi2c_imx->delivered = 0; 1047 973 lpi2c_imx->msglen = msgs[i].len; 1048 - init_completion(&lpi2c_imx->complete); 1049 974 1050 - if (is_use_dma(lpi2c_imx, &msgs[i])) { 1051 - result = lpi2c_imx_dma_xfer(lpi2c_imx, &msgs[i]); 1052 - if (result && lpi2c_imx->dma->using_pio_mode) 1053 - result = lpi2c_imx_pio_xfer(lpi2c_imx, &msgs[i]); 975 + if (atomic) { 976 + result = lpi2c_imx_pio_xfer_atomic(lpi2c_imx, &msgs[i]); 1054 977 } else { 1055 - result = lpi2c_imx_pio_xfer(lpi2c_imx, &msgs[i]); 978 + init_completion(&lpi2c_imx->complete); 979 + 980 + if (is_use_dma(lpi2c_imx, &msgs[i])) { 981 + result = lpi2c_imx_dma_xfer(lpi2c_imx, &msgs[i]); 982 + if (result && lpi2c_imx->dma->using_pio_mode) 983 + result = lpi2c_imx_pio_xfer(lpi2c_imx, &msgs[i]); 984 + } else { 985 + result = lpi2c_imx_pio_xfer(lpi2c_imx, &msgs[i]); 986 + } 1056 987 } 1057 988 1058 989 if (result) 1059 990 goto stop; 1060 991 1061 992 if (!(msgs[i].flags & I2C_M_RD)) { 1062 - result = lpi2c_imx_txfifo_empty(lpi2c_imx); 993 + result = lpi2c_imx_txfifo_empty(lpi2c_imx, atomic); 1063 994 if (result) 1064 995 goto stop; 1065 996 } 1066 997 } 1067 998 1068 999 stop: 1069 - lpi2c_imx_stop(lpi2c_imx); 1000 + lpi2c_imx_stop(lpi2c_imx, atomic); 1070 1001 1071 1002 temp = readl(lpi2c_imx->base + LPI2C_MSR); 1072 1003 if ((temp & MSR_NDF) && !result) ··· 1085 1006 (result < 0) ? result : num); 1086 1007 1087 1008 return (result < 0) ? result : num; 1009 + } 1010 + 1011 + static int lpi2c_imx_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) 1012 + { 1013 + return lpi2c_imx_xfer_common(adapter, msgs, num, false); 1014 + } 1015 + 1016 + static int lpi2c_imx_xfer_atomic(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) 1017 + { 1018 + return lpi2c_imx_xfer_common(adapter, msgs, num, true); 1088 1019 } 1089 1020 1090 1021 static irqreturn_t lpi2c_imx_target_isr(struct lpi2c_imx_struct *lpi2c_imx, ··· 1159 1070 if (temp & MSR_NDF) 1160 1071 complete(&lpi2c_imx->complete); 1161 1072 else if (temp & MSR_RDF) 1162 - lpi2c_imx_read_rxfifo(lpi2c_imx); 1073 + lpi2c_imx_read_rxfifo(lpi2c_imx, false); 1163 1074 else if (temp & MSR_TDF) 1164 - lpi2c_imx_write_txfifo(lpi2c_imx); 1075 + lpi2c_imx_write_txfifo(lpi2c_imx, false); 1165 1076 1166 1077 return IRQ_HANDLED; 1167 1078 } ··· 1358 1269 1359 1270 static const struct i2c_algorithm lpi2c_imx_algo = { 1360 1271 .xfer = lpi2c_imx_xfer, 1272 + .xfer_atomic = lpi2c_imx_xfer_atomic, 1361 1273 .functionality = lpi2c_imx_func, 1362 1274 .reg_target = lpi2c_imx_register_target, 1363 1275 .unreg_target = lpi2c_imx_unregister_target,
+16 -21
drivers/i2c/busses/i2c-imx.c
··· 23 23 24 24 #include <linux/acpi.h> 25 25 #include <linux/clk.h> 26 + #include <linux/cleanup.h> 26 27 #include <linux/completion.h> 27 28 #include <linux/delay.h> 28 29 #include <linux/dma-mapping.h> ··· 892 891 struct imx_i2c_struct *i2c_imx = container_of(t, struct imx_i2c_struct, 893 892 slave_timer); 894 893 unsigned int ctl, status; 895 - unsigned long flags; 896 894 897 - spin_lock_irqsave(&i2c_imx->slave_lock, flags); 895 + guard(spinlock_irqsave)(&i2c_imx->slave_lock); 896 + 898 897 status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); 899 898 ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 900 899 i2c_imx_slave_handle(i2c_imx, status, ctl); 901 - spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); 900 + 902 901 return HRTIMER_NORESTART; 903 902 } 904 903 ··· 1127 1126 { 1128 1127 struct imx_i2c_struct *i2c_imx = dev_id; 1129 1128 unsigned int ctl, status; 1130 - unsigned long flags; 1131 1129 1132 - spin_lock_irqsave(&i2c_imx->slave_lock, flags); 1133 - status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); 1134 - ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 1130 + scoped_guard(spinlock_irqsave, &i2c_imx->slave_lock) { 1131 + status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); 1132 + ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); 1135 1133 1136 - if (status & I2SR_IIF) { 1134 + if (!(status & I2SR_IIF)) 1135 + return IRQ_NONE; 1136 + 1137 1137 i2c_imx_clear_irq(i2c_imx, I2SR_IIF); 1138 - if (i2c_imx->slave) { 1139 - if (!(ctl & I2CR_MSTA)) { 1140 - irqreturn_t ret; 1141 1138 1142 - ret = i2c_imx_slave_handle(i2c_imx, 1143 - status, ctl); 1144 - spin_unlock_irqrestore(&i2c_imx->slave_lock, 1145 - flags); 1146 - return ret; 1147 - } 1139 + if (i2c_imx->slave) { 1140 + if (!(ctl & I2CR_MSTA)) 1141 + return i2c_imx_slave_handle(i2c_imx, 1142 + status, ctl); 1143 + 1148 1144 i2c_imx_slave_finish_op(i2c_imx); 1149 1145 } 1150 - spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); 1151 - return i2c_imx_master_isr(i2c_imx, status); 1152 1146 } 1153 - spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); 1154 1147 1155 - return IRQ_NONE; 1148 + return i2c_imx_master_isr(i2c_imx, status); 1156 1149 } 1157 1150 1158 1151 static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
+46 -8
drivers/i2c/busses/i2c-riic.c
··· 79 79 #define ICIER_SPIE BIT(3) 80 80 81 81 #define ICSR2_NACKF BIT(4) 82 + #define ICSR2_STOP BIT(3) 82 83 83 84 #define ICBR_RESERVED GENMASK(7, 5) /* Should be 1 on writes */ 84 85 ··· 103 102 104 103 struct riic_of_data { 105 104 const u8 *regs; 105 + const struct riic_irq_desc *irqs; 106 + u8 num_irqs; 106 107 bool fast_mode_plus; 107 108 }; 108 109 ··· 327 324 return IRQ_HANDLED; 328 325 } 329 326 327 + static irqreturn_t riic_eei_isr(int irq, void *data) 328 + { 329 + u8 icsr2 = riic_readb(data, RIIC_ICSR2); 330 + 331 + if (icsr2 & ICSR2_NACKF) 332 + return riic_tend_isr(irq, data); 333 + 334 + if (icsr2 & ICSR2_STOP) 335 + return riic_stop_isr(irq, data); 336 + 337 + return IRQ_NONE; 338 + } 339 + 330 340 static u32 riic_func(struct i2c_adapter *adap) 331 341 { 332 342 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; ··· 511 495 { .res_num = 5, .isr = riic_tend_isr, .name = "riic-nack" }, 512 496 }; 513 497 498 + static const struct riic_irq_desc riic_rzt2h_irqs[] = { 499 + { .res_num = 0, .isr = riic_eei_isr, .name = "riic-eei" }, 500 + { .res_num = 1, .isr = riic_rdrf_isr, .name = "riic-rxi" }, 501 + { .res_num = 2, .isr = riic_tdre_isr, .name = "riic-txi" }, 502 + { .res_num = 3, .isr = riic_tend_isr, .name = "riic-tei" }, 503 + }; 504 + 514 505 static int riic_i2c_probe(struct platform_device *pdev) 515 506 { 516 507 struct device *dev = &pdev->dev; ··· 543 520 return dev_err_probe(dev, PTR_ERR(riic->rstc), 544 521 "failed to acquire deasserted reset\n"); 545 522 546 - for (i = 0; i < ARRAY_SIZE(riic_irqs); i++) { 523 + riic->info = of_device_get_match_data(dev); 524 + 525 + for (i = 0; i < riic->info->num_irqs; i++) { 526 + const struct riic_irq_desc *irq_desc; 547 527 int irq; 548 528 549 - irq = platform_get_irq(pdev, riic_irqs[i].res_num); 529 + irq_desc = &riic->info->irqs[i]; 530 + irq = platform_get_irq(pdev, irq_desc->res_num); 550 531 if (irq < 0) 551 532 return irq; 552 533 553 - ret = devm_request_irq(dev, irq, riic_irqs[i].isr, 554 - 0, riic_irqs[i].name, riic); 534 + ret = devm_request_irq(dev, irq, irq_desc->isr, 0, irq_desc->name, riic); 555 535 if (ret) 556 536 return dev_err_probe(dev, ret, "failed to request irq %s\n", 557 - riic_irqs[i].name); 537 + irq_desc->name); 558 538 } 559 539 560 - riic->info = of_device_get_match_data(dev); 561 540 562 541 adap = &riic->adapter; 563 542 i2c_set_adapdata(adap, riic); ··· 631 606 632 607 static const struct riic_of_data riic_rz_a_info = { 633 608 .regs = riic_rz_a_regs, 609 + .irqs = riic_irqs, 610 + .num_irqs = ARRAY_SIZE(riic_irqs), 634 611 .fast_mode_plus = true, 635 612 }; 636 613 637 614 static const struct riic_of_data riic_rz_a1h_info = { 638 615 .regs = riic_rz_a_regs, 616 + .irqs = riic_irqs, 617 + .num_irqs = ARRAY_SIZE(riic_irqs), 639 618 }; 640 619 641 620 static const u8 riic_rz_v2h_regs[RIIC_REG_END] = { ··· 659 630 660 631 static const struct riic_of_data riic_rz_v2h_info = { 661 632 .regs = riic_rz_v2h_regs, 633 + .irqs = riic_irqs, 634 + .num_irqs = ARRAY_SIZE(riic_irqs), 662 635 .fast_mode_plus = true, 636 + }; 637 + 638 + static const struct riic_of_data riic_rz_t2h_info = { 639 + .regs = riic_rz_v2h_regs, 640 + .irqs = riic_rzt2h_irqs, 641 + .num_irqs = ARRAY_SIZE(riic_rzt2h_irqs), 663 642 }; 664 643 665 644 static int riic_i2c_suspend(struct device *dev) ··· 720 683 }; 721 684 722 685 static const struct of_device_id riic_i2c_dt_ids[] = { 723 - { .compatible = "renesas,riic-rz", .data = &riic_rz_a_info }, 724 686 { .compatible = "renesas,riic-r7s72100", .data = &riic_rz_a1h_info, }, 725 687 { .compatible = "renesas,riic-r9a09g057", .data = &riic_rz_v2h_info }, 726 - { /* Sentinel */ }, 688 + { .compatible = "renesas,riic-r9a09g077", .data = &riic_rz_t2h_info }, 689 + { .compatible = "renesas,riic-rz", .data = &riic_rz_a_info }, 690 + { /* Sentinel */ } 727 691 }; 728 692 729 693 static struct platform_driver riic_i2c_driver = {
+6 -13
drivers/i2c/busses/i2c-st.c
··· 13 13 #include <linux/i2c.h> 14 14 #include <linux/interrupt.h> 15 15 #include <linux/io.h> 16 + #include <linux/minmax.h> 16 17 #include <linux/module.h> 17 18 #include <linux/of_address.h> 18 19 #include <linux/of_irq.h> ··· 423 422 tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT); 424 423 tx_fstat &= SSC_TX_FSTAT_STATUS; 425 424 426 - if (c->count < (SSC_TXFIFO_SIZE - tx_fstat)) 427 - i = c->count; 428 - else 429 - i = SSC_TXFIFO_SIZE - tx_fstat; 430 - 431 - for (; i > 0; i--, c->count--, c->buf++) 425 + for (i = min(c->count, SSC_TXFIFO_SIZE - tx_fstat); 426 + i > 0; i--, c->count--, c->buf++) 432 427 st_i2c_write_tx_fifo(i2c_dev, *c->buf); 433 428 } 434 429 ··· 436 439 * This functions fills the Tx FIFO with fixed pattern when 437 440 * in read mode to trigger clock. 438 441 */ 439 - static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max) 442 + static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, u32 max) 440 443 { 441 444 struct st_i2c_client *c = &i2c_dev->client; 442 445 u32 tx_fstat, sta; ··· 449 452 tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT); 450 453 tx_fstat &= SSC_TX_FSTAT_STATUS; 451 454 452 - if (max < (SSC_TXFIFO_SIZE - tx_fstat)) 453 - i = max; 454 - else 455 - i = SSC_TXFIFO_SIZE - tx_fstat; 456 - 457 - for (; i > 0; i--, c->xfered++) 455 + for (i = min(max, SSC_TXFIFO_SIZE - tx_fstat); 456 + i > 0; i--, c->xfered++) 458 457 st_i2c_write_tx_fifo(i2c_dev, 0xff); 459 458 } 460 459
+2 -1
drivers/i2c/busses/i2c-stm32f7.c
··· 34 34 #include <linux/regmap.h> 35 35 #include <linux/reset.h> 36 36 #include <linux/slab.h> 37 + #include <linux/string_choices.h> 37 38 38 39 #include "i2c-stm32.h" 39 40 ··· 723 722 dev_dbg(i2c_dev->dev, "I2C Rise(%i) and Fall(%i) Time\n", 724 723 setup->rise_time, setup->fall_time); 725 724 dev_dbg(i2c_dev->dev, "I2C Analog Filter(%s), DNF(%i)\n", 726 - (i2c_dev->analog_filter ? "On" : "Off"), i2c_dev->dnf); 725 + str_on_off(i2c_dev->analog_filter), i2c_dev->dnf); 727 726 728 727 i2c_dev->bus_rate = setup->speed_freq; 729 728
+1
drivers/i2c/busses/i2c-tegra.c
··· 253 253 * @dma_phys: handle to DMA resources 254 254 * @dma_buf: pointer to allocated DMA buffer 255 255 * @dma_buf_size: DMA buffer size 256 + * @dma_dev: DMA device used for transfers 256 257 * @dma_mode: indicates active DMA transfer 257 258 * @dma_complete: DMA completion notifier 258 259 * @atomic_mode: indicates active atomic transfer
+1 -1
drivers/i2c/i2c-core-acpi.c
··· 250 250 251 251 if (adapter) { 252 252 /* The adapter must match the one in I2cSerialBus() connector */ 253 - if (ACPI_HANDLE(&adapter->dev) != lookup.adapter_handle) 253 + if (!device_match_acpi_handle(&adapter->dev, lookup.adapter_handle)) 254 254 return -ENODEV; 255 255 } else { 256 256 struct acpi_device *adapter_adev;
+7 -1
drivers/i2c/i2c-core-base.c
··· 1066 1066 of_node_clear_flag(to_of_node(fwnode), OF_POPULATED); 1067 1067 else if (is_acpi_device_node(fwnode)) 1068 1068 acpi_device_clear_enumerated(to_acpi_device_node(fwnode)); 1069 - fwnode_handle_put(fwnode); 1069 + 1070 + /* 1071 + * If the primary fwnode is a software node it is free-ed by 1072 + * device_remove_software_node() below, avoid double-free. 1073 + */ 1074 + if (!is_software_node(fwnode)) 1075 + fwnode_handle_put(fwnode); 1070 1076 1071 1077 device_remove_software_node(&client->dev); 1072 1078 device_unregister(&client->dev);
+1 -2
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 442 442 443 443 raw_spin_lock_init(&data->lock); 444 444 445 - data->irq = irq_domain_create_linear(of_fwnode_handle(client->dev.of_node), 446 - data->chip->nchans, 445 + data->irq = irq_domain_create_linear(dev_fwnode(&client->dev), data->chip->nchans, 447 446 &irq_domain_simple_ops, data); 448 447 if (!data->irq) 449 448 return -ENODEV;
+2 -1
include/uapi/linux/i2c.h
··· 21 21 * 22 22 * @flags: 23 23 * Supported by all adapters: 24 - * %I2C_M_RD: read data (from slave to master). Guaranteed to be 0x0001! 24 + * %I2C_M_RD: read data (from slave to master). Guaranteed to be 0x0001! If 25 + * not set, the transaction is interpreted as write. 25 26 * 26 27 * Optional: 27 28 * %I2C_M_DMA_SAFE: the buffer of this message is DMA safe. Makes only sense