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

Merge branch 'i2c/for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c updates from Wolfram Sang:

- the I2C core gained helpers to assist drivers in handling their
suspended state, and drivers were converted to use it

- two new fault-injectors for stress-testing

- bigger refactoring and feature improvements for the ocores,
sh_mobile, and tegra drivers

- platform_data removal for the at24 EEPROM driver

- ... and various improvements and bugfixes all over the subsystem

* 'i2c/for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (69 commits)
i2c: Allow recovery of the initial IRQ by an I2C client device.
i2c: ocores: turn incomplete kdoc into a comment
i2c: designware: Do not allow i2c_dw_xfer() calls while suspended
i2c: tegra: Only display error messages if DMA setup fails
i2c: gpio: fault-injector: add 'inject_panic' injector
i2c: gpio: fault-injector: add 'lose_arbitration' injector
i2c: tegra: remove multi-master support
i2c: tegra: remove master fifo support on tegra186
i2c: tegra: change phrasing, "fallbacking" to "falling back"
i2c: expand minor range when registering chrdev region
i2c: aspeed: Add multi-master use case support
i2c: core-smbus: don't trace smbus_reply data on errors
i2c: ocores: Add support for bus clock via platform data
i2c: ocores: Add support for IO mapper registers.
i2c: ocores: checkpatch fixes
i2c: ocores: add SPDX tag
i2c: ocores: add polling interface
i2c: ocores: do not handle IRQ if IF is not set
i2c: ocores: stop transfer on timeout
i2c: tegra: add i2c interface timing support
...

+1562 -662
+3
Documentation/devicetree/bindings/eeprom/at24.txt
··· 75 75 76 76 - address-width: number of address bits (one of 8, 16). 77 77 78 + - num-addresses: total number of i2c slave addresses this device takes 79 + 78 80 Example: 79 81 80 82 eeprom@52 { ··· 84 82 reg = <0x52>; 85 83 pagesize = <32>; 86 84 wp-gpios = <&gpio1 3 0>; 85 + num-addresses = <8>; 87 86 };
+1
Documentation/devicetree/bindings/i2c/i2c-mtk.txt
··· 10 10 "mediatek,mt6589-i2c": for MediaTek MT6589 11 11 "mediatek,mt7622-i2c": for MediaTek MT7622 12 12 "mediatek,mt7623-i2c", "mediatek,mt6577-i2c": for MediaTek MT7623 13 + "mediatek,mt7629-i2c", "mediatek,mt2712-i2c": for MediaTek MT7629 13 14 "mediatek,mt8173-i2c": for MediaTek MT8173 14 15 - reg: physical base address of the controller and dma base, length of memory 15 16 mapped region.
+20
Documentation/devicetree/bindings/i2c/i2c-xscale.txt
··· 1 + i2c Controller on XScale platforms such as IOP3xx and IXP4xx 2 + 3 + Required properties: 4 + - compatible : Must be one of 5 + "intel,iop3xx-i2c" 6 + "intel,ixp4xx-i2c"; 7 + - reg 8 + - #address-cells = <1>; 9 + - #size-cells = <0>; 10 + 11 + Optional properties: 12 + - Child nodes conforming to i2c bus binding 13 + 14 + Example: 15 + 16 + i2c@c8011000 { 17 + compatible = "intel,ixp4xx-i2c"; 18 + reg = <0xc8011000 0x18>; 19 + interrupts = <33 IRQ_TYPE_LEVEL_LOW>; 20 + };
+4
Documentation/i2c/fault-codes
··· 112 112 case is when the length of an SMBus block data response 113 113 (from the SMBus slave) is outside the range 1-32 bytes. 114 114 115 + ESHUTDOWN 116 + Returned when a transfer was requested using an adapter 117 + which is already suspended. 118 + 115 119 ETIMEDOUT 116 120 This is returned by drivers when an operation took too much 117 121 time, and was aborted before it completed.
+58 -3
Documentation/i2c/gpio-fault-injection
··· 1 + ========================= 1 2 Linux I2C fault injection 2 3 ========================= 3 4 ··· 13 12 mounted at /sys/kernel/debug. There will be a separate subdirectory per GPIO 14 13 driven I2C bus. Each subdirectory will contain files to trigger the fault 15 14 injection. They will be described now along with their intended use-cases. 15 + 16 + Wire states 17 + =========== 16 18 17 19 "scl" 18 20 ----- ··· 38 34 core (see 'struct bus_recovery_info'). However, the bus recovery will not 39 35 succeed because SDA is still pinned low until you manually release it again 40 36 with "echo 1 > sda". A test with an automatic release can be done with the 41 - following class of fault injectors. 37 + "incomplete transfers" class of fault injectors. 42 38 43 - Introduction to incomplete transfers 44 - ------------------------------------ 39 + Incomplete transfers 40 + ==================== 45 41 46 42 The following fault injectors create situations where SDA will be held low by a 47 43 device. Bus recovery should be able to fix these situations. But please note: ··· 83 79 additional STOP conditions to ensure the bus has been released. Otherwise 84 80 random data will be written to a device! 85 81 82 + Lost arbitration 83 + ================ 84 + 85 + Here, we want to simulate the condition where the master under test loses the 86 + bus arbitration against another master in a multi-master setup. 87 + 88 + "lose_arbitration" 89 + ------------------ 90 + 91 + This file is write only and you need to write the duration of the arbitration 92 + intereference (in µs, maximum is 100ms). The calling process will then sleep 93 + and wait for the next bus clock. The process is interruptible, though. 94 + 95 + Arbitration lost is achieved by waiting for SCL going down by the master under 96 + test and then pulling SDA low for some time. So, the I2C address sent out 97 + should be corrupted and that should be detected properly. That means that the 98 + address sent out should have a lot of '1' bits to be able to detect corruption. 99 + There doesn't need to be a device at this address because arbitration lost 100 + should be detected beforehand. Also note, that SCL going down is monitored 101 + using interrupts, so the interrupt latency might cause the first bits to be not 102 + corrupted. A good starting point for using this fault injector on an otherwise 103 + idle bus is: 104 + 105 + # echo 200 > lose_arbitration & 106 + # i2cget -y <bus_to_test> 0x3f 107 + 108 + Panic during transfer 109 + ===================== 110 + 111 + This fault injector will create a Kernel panic once the master under test 112 + started a transfer. This usually means that the state machine of the bus master 113 + driver will be ungracefully interrupted and the bus may end up in an unusual 114 + state. Use this to check if your shutdown/reboot/boot code can handle this 115 + scenario. 116 + 117 + "inject_panic" 118 + -------------- 119 + 120 + This file is write only and you need to write the delay between the detected 121 + start of a transmission and the induced Kernel panic (in µs, maximum is 100ms). 122 + The calling process will then sleep and wait for the next bus clock. The 123 + process is interruptible, though. 124 + 125 + Start of a transfer is detected by waiting for SCL going down by the master 126 + under test. A good starting point for using this fault injector is: 127 + 128 + # echo 0 > inject_panic & 129 + # i2cget -y <bus_to_test> <some_address> 130 + 131 + Note that there doesn't need to be a device listening to the address you are 132 + using. Results may vary depending on that, though.
-1
MAINTAINERS
··· 2554 2554 S: Maintained 2555 2555 F: Documentation/devicetree/bindings/eeprom/at24.txt 2556 2556 F: drivers/misc/eeprom/at24.c 2557 - F: include/linux/platform_data/at24.h 2558 2557 2559 2558 ATA OVER ETHERNET (AOE) DRIVER 2560 2559 M: "Ed L. Cashin" <ed.cashin@acm.org>
+10 -8
arch/arm/mach-omap1/board-nokia770.c
··· 10 10 #include <linux/clkdev.h> 11 11 #include <linux/irq.h> 12 12 #include <linux/gpio.h> 13 + #include <linux/gpio/machine.h> 13 14 #include <linux/kernel.h> 14 15 #include <linux/init.h> 15 16 #include <linux/mutex.h> ··· 26 25 #include <linux/platform_data/keypad-omap.h> 27 26 #include <linux/platform_data/lcd-mipid.h> 28 27 #include <linux/platform_data/gpio-omap.h> 29 - #include <linux/platform_data/i2c-cbus-gpio.h> 30 28 31 29 #include <asm/mach-types.h> 32 30 #include <asm/mach/arch.h> ··· 217 217 #endif 218 218 219 219 #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO) 220 - static struct i2c_cbus_platform_data nokia770_cbus_data = { 221 - .clk_gpio = OMAP_MPUIO(9), 222 - .dat_gpio = OMAP_MPUIO(10), 223 - .sel_gpio = OMAP_MPUIO(11), 220 + static struct gpiod_lookup_table nokia770_cbus_gpio_table = { 221 + .dev_id = "i2c-cbus-gpio.2", 222 + .table = { 223 + GPIO_LOOKUP_IDX("mpuio", 9, NULL, 0, 0), /* clk */ 224 + GPIO_LOOKUP_IDX("mpuio", 10, NULL, 1, 0), /* dat */ 225 + GPIO_LOOKUP_IDX("mpuio", 11, NULL, 2, 0), /* sel */ 226 + { }, 227 + }, 224 228 }; 225 229 226 230 static struct platform_device nokia770_cbus_device = { 227 231 .name = "i2c-cbus-gpio", 228 232 .id = 2, 229 - .dev = { 230 - .platform_data = &nokia770_cbus_data, 231 - }, 232 233 }; 233 234 234 235 static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = { ··· 258 257 nokia770_i2c_board_info_2[1].irq = gpio_to_irq(tahvo_irq_gpio); 259 258 i2c_register_board_info(2, nokia770_i2c_board_info_2, 260 259 ARRAY_SIZE(nokia770_i2c_board_info_2)); 260 + gpiod_add_lookup_table(&nokia770_cbus_gpio_table); 261 261 platform_device_register(&nokia770_cbus_device); 262 262 } 263 263 #else /* CONFIG_I2C_CBUS_GPIO */
+8 -17
drivers/i2c/algos/i2c-algo-bit.c
··· 1 - /* ------------------------------------------------------------------------- 2 - * i2c-algo-bit.c i2c driver algorithms for bit-shift adapters 3 - * ------------------------------------------------------------------------- 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * i2c-algo-bit.c: i2c driver algorithms for bit-shift adapters 4 + * 4 5 * Copyright (C) 1995-2000 Simon G. Vogl 5 - 6 - This program is free software; you can redistribute it and/or modify 7 - it under the terms of the GNU General Public License as published by 8 - the Free Software Foundation; either version 2 of the License, or 9 - (at your option) any later version. 10 - 11 - This program is distributed in the hope that it will be useful, 12 - but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - GNU General Public License for more details. 15 - * ------------------------------------------------------------------------- */ 16 - 17 - /* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki 18 - <kmalkki@cc.hut.fi> and Jean Delvare <jdelvare@suse.de> */ 6 + * 7 + * With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki 8 + * <kmalkki@cc.hut.fi> and Jean Delvare <jdelvare@suse.de> 9 + */ 19 10 20 11 #include <linux/kernel.h> 21 12 #include <linux/module.h>
+93 -27
drivers/i2c/busses/i2c-aspeed.c
··· 117 117 118 118 enum aspeed_i2c_master_state { 119 119 ASPEED_I2C_MASTER_INACTIVE, 120 + ASPEED_I2C_MASTER_PENDING, 120 121 ASPEED_I2C_MASTER_START, 121 122 ASPEED_I2C_MASTER_TX_FIRST, 122 123 ASPEED_I2C_MASTER_TX, ··· 127 126 }; 128 127 129 128 enum aspeed_i2c_slave_state { 130 - ASPEED_I2C_SLAVE_STOP, 129 + ASPEED_I2C_SLAVE_INACTIVE, 131 130 ASPEED_I2C_SLAVE_START, 132 131 ASPEED_I2C_SLAVE_READ_REQUESTED, 133 132 ASPEED_I2C_SLAVE_READ_PROCESSED, 134 133 ASPEED_I2C_SLAVE_WRITE_REQUESTED, 135 134 ASPEED_I2C_SLAVE_WRITE_RECEIVED, 135 + ASPEED_I2C_SLAVE_STOP, 136 136 }; 137 137 138 138 struct aspeed_i2c_bus { ··· 158 156 int cmd_err; 159 157 /* Protected only by i2c_lock_bus */ 160 158 int master_xfer_result; 159 + /* Multi-master */ 160 + bool multi_master; 161 161 #if IS_ENABLED(CONFIG_I2C_SLAVE) 162 162 struct i2c_client *slave; 163 163 enum aspeed_i2c_slave_state slave_state; ··· 255 251 } 256 252 257 253 /* Slave is not currently active, irq was for someone else. */ 258 - if (bus->slave_state == ASPEED_I2C_SLAVE_STOP) 254 + if (bus->slave_state == ASPEED_I2C_SLAVE_INACTIVE) 259 255 return irq_handled; 260 256 261 257 dev_dbg(bus->dev, "slave irq status 0x%08x, cmd 0x%08x\n", ··· 281 277 irq_handled |= ASPEED_I2CD_INTR_NORMAL_STOP; 282 278 bus->slave_state = ASPEED_I2C_SLAVE_STOP; 283 279 } 284 - if (irq_status & ASPEED_I2CD_INTR_TX_NAK) { 280 + if (irq_status & ASPEED_I2CD_INTR_TX_NAK && 281 + bus->slave_state == ASPEED_I2C_SLAVE_READ_PROCESSED) { 285 282 irq_handled |= ASPEED_I2CD_INTR_TX_NAK; 286 283 bus->slave_state = ASPEED_I2C_SLAVE_STOP; 287 284 } 288 - if (irq_status & ASPEED_I2CD_INTR_TX_ACK) 289 - irq_handled |= ASPEED_I2CD_INTR_TX_ACK; 290 285 291 286 switch (bus->slave_state) { 292 287 case ASPEED_I2C_SLAVE_READ_REQUESTED: 293 - if (irq_status & ASPEED_I2CD_INTR_TX_ACK) 288 + if (unlikely(irq_status & ASPEED_I2CD_INTR_TX_ACK)) 294 289 dev_err(bus->dev, "Unexpected ACK on read request.\n"); 295 290 bus->slave_state = ASPEED_I2C_SLAVE_READ_PROCESSED; 296 291 i2c_slave_event(slave, I2C_SLAVE_READ_REQUESTED, &value); ··· 297 294 writel(ASPEED_I2CD_S_TX_CMD, bus->base + ASPEED_I2C_CMD_REG); 298 295 break; 299 296 case ASPEED_I2C_SLAVE_READ_PROCESSED: 300 - if (!(irq_status & ASPEED_I2CD_INTR_TX_ACK)) 297 + if (unlikely(!(irq_status & ASPEED_I2CD_INTR_TX_ACK))) { 301 298 dev_err(bus->dev, 302 299 "Expected ACK after processed read.\n"); 300 + break; 301 + } 302 + irq_handled |= ASPEED_I2CD_INTR_TX_ACK; 303 303 i2c_slave_event(slave, I2C_SLAVE_READ_PROCESSED, &value); 304 304 writel(value, bus->base + ASPEED_I2C_BYTE_BUF_REG); 305 305 writel(ASPEED_I2CD_S_TX_CMD, bus->base + ASPEED_I2C_CMD_REG); ··· 316 310 break; 317 311 case ASPEED_I2C_SLAVE_STOP: 318 312 i2c_slave_event(slave, I2C_SLAVE_STOP, &value); 313 + bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; 314 + break; 315 + case ASPEED_I2C_SLAVE_START: 316 + /* Slave was just started. Waiting for the next event. */; 319 317 break; 320 318 default: 321 - dev_err(bus->dev, "unhandled slave_state: %d\n", 319 + dev_err(bus->dev, "unknown slave_state: %d\n", 322 320 bus->slave_state); 321 + bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; 323 322 break; 324 323 } 325 324 ··· 340 329 u8 slave_addr = i2c_8bit_addr_from_msg(msg); 341 330 342 331 bus->master_state = ASPEED_I2C_MASTER_START; 332 + 333 + #if IS_ENABLED(CONFIG_I2C_SLAVE) 334 + /* 335 + * If it's requested in the middle of a slave session, set the master 336 + * state to 'pending' then H/W will continue handling this master 337 + * command when the bus comes back to the idle state. 338 + */ 339 + if (bus->slave_state != ASPEED_I2C_SLAVE_INACTIVE) 340 + bus->master_state = ASPEED_I2C_MASTER_PENDING; 341 + #endif /* CONFIG_I2C_SLAVE */ 342 + 343 343 bus->buf_index = 0; 344 344 345 345 if (msg->flags & I2C_M_RD) { ··· 406 384 bus->master_state = ASPEED_I2C_MASTER_INACTIVE; 407 385 irq_handled |= ASPEED_I2CD_INTR_BUS_RECOVER_DONE; 408 386 goto out_complete; 409 - } else { 410 - /* Master is not currently active, irq was for someone else. */ 411 - if (bus->master_state == ASPEED_I2C_MASTER_INACTIVE) 412 - goto out_no_complete; 413 387 } 414 388 415 389 /* ··· 417 399 if (ret) { 418 400 dev_dbg(bus->dev, "received error interrupt: 0x%08x\n", 419 401 irq_status); 420 - bus->cmd_err = ret; 421 - bus->master_state = ASPEED_I2C_MASTER_INACTIVE; 422 402 irq_handled |= (irq_status & ASPEED_I2CD_INTR_MASTER_ERRORS); 423 - goto out_complete; 403 + if (bus->master_state != ASPEED_I2C_MASTER_INACTIVE) { 404 + bus->cmd_err = ret; 405 + bus->master_state = ASPEED_I2C_MASTER_INACTIVE; 406 + goto out_complete; 407 + } 424 408 } 409 + 410 + #if IS_ENABLED(CONFIG_I2C_SLAVE) 411 + /* 412 + * A pending master command will be started by H/W when the bus comes 413 + * back to idle state after completing a slave operation so change the 414 + * master state from 'pending' to 'start' at here if slave is inactive. 415 + */ 416 + if (bus->master_state == ASPEED_I2C_MASTER_PENDING) { 417 + if (bus->slave_state != ASPEED_I2C_SLAVE_INACTIVE) 418 + goto out_no_complete; 419 + 420 + bus->master_state = ASPEED_I2C_MASTER_START; 421 + } 422 + #endif /* CONFIG_I2C_SLAVE */ 423 + 424 + /* Master is not currently active, irq was for someone else. */ 425 + if (bus->master_state == ASPEED_I2C_MASTER_INACTIVE || 426 + bus->master_state == ASPEED_I2C_MASTER_PENDING) 427 + goto out_no_complete; 425 428 426 429 /* We are in an invalid state; reset bus to a known state. */ 427 430 if (!bus->msgs) { ··· 462 423 * then update the state and handle the new state below. 463 424 */ 464 425 if (bus->master_state == ASPEED_I2C_MASTER_START) { 426 + #if IS_ENABLED(CONFIG_I2C_SLAVE) 427 + /* 428 + * If a peer master starts a xfer immediately after it queues a 429 + * master command, change its state to 'pending' then H/W will 430 + * continue the queued master xfer just after completing the 431 + * slave mode session. 432 + */ 433 + if (unlikely(irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH)) { 434 + bus->master_state = ASPEED_I2C_MASTER_PENDING; 435 + dev_dbg(bus->dev, 436 + "master goes pending due to a slave start\n"); 437 + goto out_no_complete; 438 + } 439 + #endif /* CONFIG_I2C_SLAVE */ 465 440 if (unlikely(!(irq_status & ASPEED_I2CD_INTR_TX_ACK))) { 466 441 if (unlikely(!(irq_status & ASPEED_I2CD_INTR_TX_NAK))) { 467 442 bus->cmd_err = -ENXIO; ··· 619 566 * interrupt bits. Each case needs to be handled using corresponding 620 567 * handlers depending on the current state. 621 568 */ 622 - if (bus->master_state != ASPEED_I2C_MASTER_INACTIVE) { 569 + if (bus->master_state != ASPEED_I2C_MASTER_INACTIVE && 570 + bus->master_state != ASPEED_I2C_MASTER_PENDING) { 623 571 irq_handled = aspeed_i2c_master_irq(bus, irq_remaining); 624 572 irq_remaining &= ~irq_handled; 625 573 if (irq_remaining) ··· 655 601 { 656 602 struct aspeed_i2c_bus *bus = i2c_get_adapdata(adap); 657 603 unsigned long time_left, flags; 658 - int ret = 0; 659 604 660 605 spin_lock_irqsave(&bus->lock, flags); 661 606 bus->cmd_err = 0; 662 607 663 - /* If bus is busy, attempt recovery. We assume a single master 664 - * environment. 665 - */ 666 - if (readl(bus->base + ASPEED_I2C_CMD_REG) & ASPEED_I2CD_BUS_BUSY_STS) { 608 + /* If bus is busy in a single master environment, attempt recovery. */ 609 + if (!bus->multi_master && 610 + (readl(bus->base + ASPEED_I2C_CMD_REG) & 611 + ASPEED_I2CD_BUS_BUSY_STS)) { 612 + int ret; 613 + 667 614 spin_unlock_irqrestore(&bus->lock, flags); 668 615 ret = aspeed_i2c_recover_bus(bus); 669 616 if (ret) ··· 684 629 time_left = wait_for_completion_timeout(&bus->cmd_complete, 685 630 bus->adap.timeout); 686 631 687 - if (time_left == 0) 632 + if (time_left == 0) { 633 + /* 634 + * If timed out and bus is still busy in a multi master 635 + * environment, attempt recovery at here. 636 + */ 637 + if (bus->multi_master && 638 + (readl(bus->base + ASPEED_I2C_CMD_REG) & 639 + ASPEED_I2CD_BUS_BUSY_STS)) 640 + aspeed_i2c_recover_bus(bus); 641 + 688 642 return -ETIMEDOUT; 689 - else 690 - return bus->master_xfer_result; 643 + } 644 + 645 + return bus->master_xfer_result; 691 646 } 692 647 693 648 static u32 aspeed_i2c_functionality(struct i2c_adapter *adap) ··· 737 672 __aspeed_i2c_reg_slave(bus, client->addr); 738 673 739 674 bus->slave = client; 740 - bus->slave_state = ASPEED_I2C_SLAVE_STOP; 675 + bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE; 741 676 spin_unlock_irqrestore(&bus->lock, flags); 742 677 743 678 return 0; ··· 892 827 if (ret < 0) 893 828 return ret; 894 829 895 - if (!of_property_read_bool(pdev->dev.of_node, "multi-master")) 830 + if (of_property_read_bool(pdev->dev.of_node, "multi-master")) 831 + bus->multi_master = true; 832 + else 896 833 fun_ctrl_reg |= ASPEED_I2CD_MULTI_MASTER_DIS; 897 834 898 835 /* Enable Master Mode */ ··· 997 930 init_completion(&bus->cmd_complete); 998 931 bus->adap.owner = THIS_MODULE; 999 932 bus->adap.retries = 0; 1000 - bus->adap.timeout = 5 * HZ; 1001 933 bus->adap.algo = &aspeed_i2c_algo; 1002 934 bus->adap.dev.parent = &pdev->dev; 1003 935 bus->adap.dev.of_node = pdev->dev.of_node;
+2 -11
drivers/i2c/busses/i2c-brcmstb.c
··· 170 170 struct bsc_regs *bsc_regmap; 171 171 struct i2c_adapter adapter; 172 172 struct completion done; 173 - bool is_suspended; 174 173 u32 clk_freq_hz; 175 174 int data_regsz; 176 175 }; ··· 466 467 int xfersz = brcmstb_i2c_get_xfersz(dev); 467 468 u32 cond, cond_per_msg; 468 469 469 - if (dev->is_suspended) 470 - return -EBUSY; 471 - 472 470 /* Loop through all messages */ 473 471 for (i = 0; i < num; i++) { 474 472 pmsg = &msgs[i]; ··· 685 689 { 686 690 struct brcmstb_i2c_dev *i2c_dev = dev_get_drvdata(dev); 687 691 688 - i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER); 689 - i2c_dev->is_suspended = true; 690 - i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER); 691 - 692 + i2c_mark_adapter_suspended(&i2c_dev->adapter); 692 693 return 0; 693 694 } 694 695 ··· 693 700 { 694 701 struct brcmstb_i2c_dev *i2c_dev = dev_get_drvdata(dev); 695 702 696 - i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER); 697 703 brcmstb_i2c_set_bsc_reg_defaults(i2c_dev); 698 - i2c_dev->is_suspended = false; 699 - i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER); 704 + i2c_mark_adapter_resumed(&i2c_dev->adapter); 700 705 701 706 return 0; 702 707 }
+30 -50
drivers/i2c/busses/i2c-cbus-gpio.c
··· 18 18 19 19 #include <linux/io.h> 20 20 #include <linux/i2c.h> 21 - #include <linux/gpio.h> 22 21 #include <linux/slab.h> 23 22 #include <linux/delay.h> 24 23 #include <linux/errno.h> 25 24 #include <linux/kernel.h> 26 25 #include <linux/module.h> 27 - #include <linux/of_gpio.h> 26 + #include <linux/gpio/consumer.h> 28 27 #include <linux/interrupt.h> 29 28 #include <linux/platform_device.h> 30 - #include <linux/platform_data/i2c-cbus-gpio.h> 31 29 32 30 /* 33 31 * Bit counts are derived from Nokia implementation. These should be checked ··· 37 39 struct cbus_host { 38 40 spinlock_t lock; /* host lock */ 39 41 struct device *dev; 40 - int clk_gpio; 41 - int dat_gpio; 42 - int sel_gpio; 42 + struct gpio_desc *clk; 43 + struct gpio_desc *dat; 44 + struct gpio_desc *sel; 43 45 }; 44 46 45 47 /** ··· 49 51 */ 50 52 static void cbus_send_bit(struct cbus_host *host, unsigned bit) 51 53 { 52 - gpio_set_value(host->dat_gpio, bit ? 1 : 0); 53 - gpio_set_value(host->clk_gpio, 1); 54 - gpio_set_value(host->clk_gpio, 0); 54 + gpiod_set_value(host->dat, bit ? 1 : 0); 55 + gpiod_set_value(host->clk, 1); 56 + gpiod_set_value(host->clk, 0); 55 57 } 56 58 57 59 /** ··· 76 78 { 77 79 int ret; 78 80 79 - gpio_set_value(host->clk_gpio, 1); 80 - ret = gpio_get_value(host->dat_gpio); 81 - gpio_set_value(host->clk_gpio, 0); 81 + gpiod_set_value(host->clk, 1); 82 + ret = gpiod_get_value(host->dat); 83 + gpiod_set_value(host->clk, 0); 82 84 return ret; 83 85 } 84 86 ··· 121 123 spin_lock_irqsave(&host->lock, flags); 122 124 123 125 /* Reset state and start of transfer, SEL stays down during transfer */ 124 - gpio_set_value(host->sel_gpio, 0); 126 + gpiod_set_value(host->sel, 0); 125 127 126 128 /* Set the DAT pin to output */ 127 - gpio_direction_output(host->dat_gpio, 1); 129 + gpiod_direction_output(host->dat, 1); 128 130 129 131 /* Send the device address */ 130 132 cbus_send_data(host, dev, CBUS_ADDR_BITS); ··· 139 141 cbus_send_data(host, data, 16); 140 142 ret = 0; 141 143 } else { 142 - ret = gpio_direction_input(host->dat_gpio); 144 + ret = gpiod_direction_input(host->dat); 143 145 if (ret) { 144 146 dev_dbg(host->dev, "failed setting direction\n"); 145 147 goto out; 146 148 } 147 - gpio_set_value(host->clk_gpio, 1); 149 + gpiod_set_value(host->clk, 1); 148 150 149 151 ret = cbus_receive_word(host); 150 152 if (ret < 0) { ··· 154 156 } 155 157 156 158 /* Indicate end of transfer, SEL goes up until next transfer */ 157 - gpio_set_value(host->sel_gpio, 1); 158 - gpio_set_value(host->clk_gpio, 1); 159 - gpio_set_value(host->clk_gpio, 0); 159 + gpiod_set_value(host->sel, 1); 160 + gpiod_set_value(host->clk, 1); 161 + gpiod_set_value(host->clk, 0); 160 162 161 163 out: 162 164 spin_unlock_irqrestore(&host->lock, flags); ··· 212 214 { 213 215 struct i2c_adapter *adapter; 214 216 struct cbus_host *chost; 215 - int ret; 216 217 217 218 adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), 218 219 GFP_KERNEL); ··· 222 225 if (!chost) 223 226 return -ENOMEM; 224 227 225 - if (pdev->dev.of_node) { 226 - struct device_node *dnode = pdev->dev.of_node; 227 - if (of_gpio_count(dnode) != 3) 228 - return -ENODEV; 229 - chost->clk_gpio = of_get_gpio(dnode, 0); 230 - chost->dat_gpio = of_get_gpio(dnode, 1); 231 - chost->sel_gpio = of_get_gpio(dnode, 2); 232 - } else if (dev_get_platdata(&pdev->dev)) { 233 - struct i2c_cbus_platform_data *pdata = 234 - dev_get_platdata(&pdev->dev); 235 - chost->clk_gpio = pdata->clk_gpio; 236 - chost->dat_gpio = pdata->dat_gpio; 237 - chost->sel_gpio = pdata->sel_gpio; 238 - } else { 228 + if (gpiod_count(&pdev->dev, NULL) != 3) 239 229 return -ENODEV; 240 - } 230 + chost->clk = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_LOW); 231 + if (IS_ERR(chost->clk)) 232 + return PTR_ERR(chost->clk); 233 + chost->dat = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_IN); 234 + if (IS_ERR(chost->dat)) 235 + return PTR_ERR(chost->dat); 236 + chost->sel = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_OUT_HIGH); 237 + if (IS_ERR(chost->sel)) 238 + return PTR_ERR(chost->sel); 239 + gpiod_set_consumer_name(chost->clk, "CBUS clk"); 240 + gpiod_set_consumer_name(chost->dat, "CBUS dat"); 241 + gpiod_set_consumer_name(chost->sel, "CBUS sel"); 241 242 242 243 adapter->owner = THIS_MODULE; 243 244 adapter->class = I2C_CLASS_HWMON; ··· 248 253 249 254 spin_lock_init(&chost->lock); 250 255 chost->dev = &pdev->dev; 251 - 252 - ret = devm_gpio_request_one(&pdev->dev, chost->clk_gpio, 253 - GPIOF_OUT_INIT_LOW, "CBUS clk"); 254 - if (ret) 255 - return ret; 256 - 257 - ret = devm_gpio_request_one(&pdev->dev, chost->dat_gpio, GPIOF_IN, 258 - "CBUS data"); 259 - if (ret) 260 - return ret; 261 - 262 - ret = devm_gpio_request_one(&pdev->dev, chost->sel_gpio, 263 - GPIOF_OUT_INIT_HIGH, "CBUS sel"); 264 - if (ret) 265 - return ret; 266 256 267 257 i2c_set_adapdata(adapter, chost); 268 258 platform_set_drvdata(pdev, adapter);
+2
drivers/i2c/busses/i2c-designware-core.h
··· 215 215 * @disable_int: function to disable all interrupts 216 216 * @init: function to initialize the I2C hardware 217 217 * @mode: operation mode - DW_IC_MASTER or DW_IC_SLAVE 218 + * @suspended: set to true if the controller is suspended 218 219 * 219 220 * HCNT and LCNT parameters can be used if the platform knows more accurate 220 221 * values than the one computed based only on the input clock frequency. ··· 271 270 int (*set_sda_hold_time)(struct dw_i2c_dev *dev); 272 271 int mode; 273 272 struct i2c_bus_recovery_info rinfo; 273 + bool suspended; 274 274 }; 275 275 276 276 #define ACCESS_SWAP 0x00000001
+6
drivers/i2c/busses/i2c-designware-master.c
··· 426 426 427 427 pm_runtime_get_sync(dev->dev); 428 428 429 + if (dev->suspended) { 430 + dev_err(dev->dev, "Error %s call while suspended\n", __func__); 431 + ret = -ESHUTDOWN; 432 + goto done_nolock; 433 + } 434 + 429 435 reinit_completion(&dev->cmd_complete); 430 436 dev->msgs = msgs; 431 437 dev->msgs_num = num;
+6 -1
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 176 176 struct pci_dev *pdev = to_pci_dev(dev); 177 177 struct dw_i2c_dev *i_dev = pci_get_drvdata(pdev); 178 178 179 + i_dev->suspended = true; 179 180 i_dev->disable(i_dev); 180 181 181 182 return 0; ··· 186 185 { 187 186 struct pci_dev *pdev = to_pci_dev(dev); 188 187 struct dw_i2c_dev *i_dev = pci_get_drvdata(pdev); 188 + int ret; 189 189 190 - return i_dev->init(i_dev); 190 + ret = i_dev->init(i_dev); 191 + i_dev->suspended = false; 192 + 193 + return ret; 191 194 } 192 195 #endif 193 196
+3
drivers/i2c/busses/i2c-designware-platdrv.c
··· 454 454 { 455 455 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); 456 456 457 + i_dev->suspended = true; 458 + 457 459 if (i_dev->shared_with_punit) 458 460 return 0; 459 461 ··· 473 471 i2c_dw_prepare_clk(i_dev, true); 474 472 475 473 i_dev->init(i_dev); 474 + i_dev->suspended = false; 476 475 477 476 return 0; 478 477 }
+2 -9
drivers/i2c/busses/i2c-exynos5.c
··· 183 183 184 184 struct exynos5_i2c { 185 185 struct i2c_adapter adap; 186 - unsigned int suspended:1; 187 186 188 187 struct i2c_msg *msg; 189 188 struct completion msg_complete; ··· 714 715 struct exynos5_i2c *i2c = adap->algo_data; 715 716 int i, ret; 716 717 717 - if (i2c->suspended) { 718 - dev_err(i2c->dev, "HS-I2C is not initialized.\n"); 719 - return -EIO; 720 - } 721 - 722 718 ret = clk_enable(i2c->clk); 723 719 if (ret) 724 720 return ret; ··· 841 847 { 842 848 struct exynos5_i2c *i2c = dev_get_drvdata(dev); 843 849 844 - i2c->suspended = 1; 845 - 850 + i2c_mark_adapter_suspended(&i2c->adap); 846 851 clk_unprepare(i2c->clk); 847 852 848 853 return 0; ··· 864 871 865 872 exynos5_i2c_init(i2c); 866 873 clk_disable(i2c->clk); 867 - i2c->suspended = 0; 874 + i2c_mark_adapter_resumed(&i2c->adap); 868 875 869 876 return 0; 870 877 }
+117 -21
drivers/i2c/busses/i2c-gpio.c
··· 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 9 */ 10 + #include <linux/completion.h> 10 11 #include <linux/debugfs.h> 11 12 #include <linux/delay.h> 12 - #include <linux/i2c.h> 13 - #include <linux/i2c-algo-bit.h> 14 - #include <linux/platform_data/i2c-gpio.h> 15 - #include <linux/init.h> 16 - #include <linux/module.h> 17 - #include <linux/slab.h> 18 - #include <linux/platform_device.h> 19 13 #include <linux/gpio/consumer.h> 14 + #include <linux/i2c-algo-bit.h> 15 + #include <linux/i2c.h> 16 + #include <linux/init.h> 17 + #include <linux/interrupt.h> 18 + #include <linux/module.h> 20 19 #include <linux/of.h> 20 + #include <linux/platform_data/i2c-gpio.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/slab.h> 21 23 22 24 struct i2c_gpio_private_data { 23 25 struct gpio_desc *sda; ··· 29 27 struct i2c_gpio_platform_data pdata; 30 28 #ifdef CONFIG_I2C_GPIO_FAULT_INJECTOR 31 29 struct dentry *debug_dir; 30 + /* these must be protected by bus lock */ 31 + struct completion scl_irq_completion; 32 + u64 scl_irq_data; 32 33 #endif 33 34 }; 34 35 ··· 167 162 } 168 163 DEFINE_DEBUGFS_ATTRIBUTE(fops_incomplete_write_byte, NULL, fops_incomplete_write_byte_set, "%llu\n"); 169 164 165 + static int i2c_gpio_fi_act_on_scl_irq(struct i2c_gpio_private_data *priv, 166 + irqreturn_t handler(int, void*)) 167 + { 168 + int ret, irq = gpiod_to_irq(priv->scl); 169 + 170 + if (irq < 0) 171 + return irq; 172 + 173 + i2c_lock_bus(&priv->adap, I2C_LOCK_ROOT_ADAPTER); 174 + 175 + ret = gpiod_direction_input(priv->scl); 176 + if (ret) 177 + goto unlock; 178 + 179 + reinit_completion(&priv->scl_irq_completion); 180 + 181 + ret = request_irq(irq, handler, IRQF_TRIGGER_FALLING, 182 + "i2c_gpio_fault_injector_scl_irq", priv); 183 + if (ret) 184 + goto output; 185 + 186 + wait_for_completion_interruptible(&priv->scl_irq_completion); 187 + 188 + free_irq(irq, priv); 189 + output: 190 + ret = gpiod_direction_output(priv->scl, 1) ?: ret; 191 + unlock: 192 + i2c_unlock_bus(&priv->adap, I2C_LOCK_ROOT_ADAPTER); 193 + 194 + return ret; 195 + } 196 + 197 + static irqreturn_t lose_arbitration_irq(int irq, void *dev_id) 198 + { 199 + struct i2c_gpio_private_data *priv = dev_id; 200 + 201 + setsda(&priv->bit_data, 0); 202 + udelay(priv->scl_irq_data); 203 + setsda(&priv->bit_data, 1); 204 + 205 + complete(&priv->scl_irq_completion); 206 + 207 + return IRQ_HANDLED; 208 + } 209 + 210 + static int fops_lose_arbitration_set(void *data, u64 duration) 211 + { 212 + struct i2c_gpio_private_data *priv = data; 213 + 214 + if (duration > 100 * 1000) 215 + return -EINVAL; 216 + 217 + priv->scl_irq_data = duration; 218 + /* 219 + * Interrupt on falling SCL. This ensures that the master under test has 220 + * really started the transfer. Interrupt on falling SDA did only 221 + * exercise 'bus busy' detection on some HW but not 'arbitration lost'. 222 + * Note that the interrupt latency may cause the first bits to be 223 + * transmitted correctly. 224 + */ 225 + return i2c_gpio_fi_act_on_scl_irq(priv, lose_arbitration_irq); 226 + } 227 + DEFINE_DEBUGFS_ATTRIBUTE(fops_lose_arbitration, NULL, fops_lose_arbitration_set, "%llu\n"); 228 + 229 + static irqreturn_t inject_panic_irq(int irq, void *dev_id) 230 + { 231 + struct i2c_gpio_private_data *priv = dev_id; 232 + 233 + udelay(priv->scl_irq_data); 234 + panic("I2C fault injector induced panic"); 235 + 236 + return IRQ_HANDLED; 237 + } 238 + 239 + static int fops_inject_panic_set(void *data, u64 duration) 240 + { 241 + struct i2c_gpio_private_data *priv = data; 242 + 243 + if (duration > 100 * 1000) 244 + return -EINVAL; 245 + 246 + priv->scl_irq_data = duration; 247 + /* 248 + * Interrupt on falling SCL. This ensures that the master under test has 249 + * really started the transfer. 250 + */ 251 + return i2c_gpio_fi_act_on_scl_irq(priv, inject_panic_irq); 252 + } 253 + DEFINE_DEBUGFS_ATTRIBUTE(fops_inject_panic, NULL, fops_inject_panic_set, "%llu\n"); 254 + 170 255 static void i2c_gpio_fault_injector_init(struct platform_device *pdev) 171 256 { 172 257 struct i2c_gpio_private_data *priv = platform_get_drvdata(pdev); ··· 276 181 if (!priv->debug_dir) 277 182 return; 278 183 279 - debugfs_create_file_unsafe("scl", 0600, priv->debug_dir, priv, &fops_scl); 280 - debugfs_create_file_unsafe("sda", 0600, priv->debug_dir, priv, &fops_sda); 184 + init_completion(&priv->scl_irq_completion); 185 + 281 186 debugfs_create_file_unsafe("incomplete_address_phase", 0200, priv->debug_dir, 282 187 priv, &fops_incomplete_addr_phase); 283 188 debugfs_create_file_unsafe("incomplete_write_byte", 0200, priv->debug_dir, 284 189 priv, &fops_incomplete_write_byte); 190 + if (priv->bit_data.getscl) { 191 + debugfs_create_file_unsafe("inject_panic", 0200, priv->debug_dir, 192 + priv, &fops_inject_panic); 193 + debugfs_create_file_unsafe("lose_arbitration", 0200, priv->debug_dir, 194 + priv, &fops_lose_arbitration); 195 + } 196 + debugfs_create_file_unsafe("scl", 0600, priv->debug_dir, priv, &fops_scl); 197 + debugfs_create_file_unsafe("sda", 0600, priv->debug_dir, priv, &fops_sda); 285 198 } 286 199 287 200 static void i2c_gpio_fault_injector_exit(struct platform_device *pdev) ··· 389 286 390 287 /* 391 288 * First get the GPIO pins; if it fails, we'll defer the probe. 392 - * If the SDA line is marked from platform data or device tree as 393 - * "open drain" it means something outside of our control is making 394 - * this line being handled as open drain, and we should just handle 395 - * it as any other output. Else we enforce open drain as this is 396 - * required for an I2C bus. 289 + * If the SCL/SDA lines are marked "open drain" by platform data or 290 + * device tree then this means that something outside of our control is 291 + * marking these lines to be handled as open drain, and we should just 292 + * handle them as we handle any other output. Else we enforce open 293 + * drain as this is required for an I2C bus. 397 294 */ 398 295 if (pdata->sda_is_open_drain) 399 296 gflags = GPIOD_OUT_HIGH; ··· 403 300 if (IS_ERR(priv->sda)) 404 301 return PTR_ERR(priv->sda); 405 302 406 - /* 407 - * If the SCL line is marked from platform data or device tree as 408 - * "open drain" it means something outside of our control is making 409 - * this line being handled as open drain, and we should just handle 410 - * it as any other output. Else we enforce open drain as this is 411 - * required for an I2C bus. 412 - */ 413 303 if (pdata->scl_is_open_drain) 414 304 gflags = GPIOD_OUT_HIGH; 415 305 else
+22 -15
drivers/i2c/busses/i2c-imx.c
··· 273 273 } 274 274 275 275 /* Functions for DMA support */ 276 - static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, 277 - dma_addr_t phy_addr) 276 + static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, 277 + dma_addr_t phy_addr) 278 278 { 279 279 struct imx_i2c_dma *dma; 280 280 struct dma_slave_config dma_sconfig; ··· 283 283 284 284 dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); 285 285 if (!dma) 286 - return; 286 + return -ENOMEM; 287 287 288 - dma->chan_tx = dma_request_slave_channel(dev, "tx"); 289 - if (!dma->chan_tx) { 290 - dev_dbg(dev, "can't request DMA tx channel\n"); 288 + dma->chan_tx = dma_request_chan(dev, "tx"); 289 + if (IS_ERR(dma->chan_tx)) { 290 + ret = PTR_ERR(dma->chan_tx); 291 + if (ret != -ENODEV && ret != -EPROBE_DEFER) 292 + dev_err(dev, "can't request DMA tx channel (%d)\n", ret); 291 293 goto fail_al; 292 294 } 293 295 ··· 300 298 dma_sconfig.direction = DMA_MEM_TO_DEV; 301 299 ret = dmaengine_slave_config(dma->chan_tx, &dma_sconfig); 302 300 if (ret < 0) { 303 - dev_dbg(dev, "can't configure tx channel\n"); 301 + dev_err(dev, "can't configure tx channel (%d)\n", ret); 304 302 goto fail_tx; 305 303 } 306 304 307 - dma->chan_rx = dma_request_slave_channel(dev, "rx"); 308 - if (!dma->chan_rx) { 309 - dev_dbg(dev, "can't request DMA rx channel\n"); 305 + dma->chan_rx = dma_request_chan(dev, "rx"); 306 + if (IS_ERR(dma->chan_rx)) { 307 + ret = PTR_ERR(dma->chan_rx); 308 + if (ret != -ENODEV && ret != -EPROBE_DEFER) 309 + dev_err(dev, "can't request DMA rx channel (%d)\n", ret); 310 310 goto fail_tx; 311 311 } 312 312 ··· 319 315 dma_sconfig.direction = DMA_DEV_TO_MEM; 320 316 ret = dmaengine_slave_config(dma->chan_rx, &dma_sconfig); 321 317 if (ret < 0) { 322 - dev_dbg(dev, "can't configure rx channel\n"); 318 + dev_err(dev, "can't configure rx channel (%d)\n", ret); 323 319 goto fail_rx; 324 320 } 325 321 ··· 328 324 dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", 329 325 dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); 330 326 331 - return; 327 + return 0; 332 328 333 329 fail_rx: 334 330 dma_release_channel(dma->chan_rx); ··· 336 332 dma_release_channel(dma->chan_tx); 337 333 fail_al: 338 334 devm_kfree(dev, dma); 339 - dev_info(dev, "can't use DMA, using PIO instead.\n"); 335 + /* return successfully if there is no dma support */ 336 + return ret == -ENODEV ? 0 : ret; 340 337 } 341 338 342 339 static void i2c_imx_dma_callback(void *arg) ··· 1165 1160 dev_dbg(&i2c_imx->adapter.dev, "device resources: %pR\n", res); 1166 1161 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", 1167 1162 i2c_imx->adapter.name); 1168 - dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); 1169 1163 1170 1164 /* Init DMA config if supported */ 1171 - i2c_imx_dma_request(i2c_imx, phy_addr); 1165 + ret = i2c_imx_dma_request(i2c_imx, phy_addr); 1166 + if (ret < 0) 1167 + goto clk_notifier_unregister; 1172 1168 1169 + dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); 1173 1170 return 0; /* Return OK */ 1174 1171 1175 1172 clk_notifier_unregister:
+8
drivers/i2c/busses/i2c-iop3xx.c
··· 471 471 new_adapter->owner = THIS_MODULE; 472 472 new_adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 473 473 new_adapter->dev.parent = &pdev->dev; 474 + new_adapter->dev.of_node = pdev->dev.of_node; 474 475 new_adapter->nr = pdev->id; 475 476 476 477 /* ··· 509 508 return ret; 510 509 } 511 510 511 + static const struct of_device_id i2c_iop3xx_match[] = { 512 + { .compatible = "intel,iop3xx-i2c", }, 513 + { .compatible = "intel,ixp4xx-i2c", }, 514 + {}, 515 + }; 516 + MODULE_DEVICE_TABLE(of, i2c_iop3xx_match); 512 517 513 518 static struct platform_driver iop3xx_i2c_driver = { 514 519 .probe = iop3xx_i2c_probe, 515 520 .remove = iop3xx_i2c_remove, 516 521 .driver = { 517 522 .name = "IOP3xx-I2C", 523 + .of_match_table = i2c_iop3xx_match, 518 524 }, 519 525 }; 520 526
+2 -4
drivers/i2c/busses/i2c-mt65xx.c
··· 456 456 457 457 control_reg = readw(i2c->base + OFFSET_CONTROL) & 458 458 ~(I2C_CONTROL_DIR_CHANGE | I2C_CONTROL_RS); 459 - if ((i2c->speed_hz > 400000) || (left_num >= 1)) 459 + if ((i2c->speed_hz > MAX_FS_MODE_SPEED) || (left_num >= 1)) 460 460 control_reg |= I2C_CONTROL_RS; 461 461 462 462 if (i2c->op == I2C_MASTER_WRRD) ··· 465 465 writew(control_reg, i2c->base + OFFSET_CONTROL); 466 466 467 467 /* set start condition */ 468 - if (i2c->speed_hz <= 100000) 468 + if (i2c->speed_hz <= I2C_DEFAULT_SPEED) 469 469 writew(I2C_ST_START_CON, i2c->base + OFFSET_EXT_CONF); 470 470 else 471 471 writew(I2C_FS_START_CON, i2c->base + OFFSET_EXT_CONF); ··· 641 641 mtk_i2c_init_hw(i2c); 642 642 return -ETIMEDOUT; 643 643 } 644 - 645 - completion_done(&i2c->msg_complete); 646 644 647 645 if (i2c->irq_stat & (I2C_HS_NACKERR | I2C_ACKERR)) { 648 646 dev_dbg(i2c->dev, "addr: %x, transfer ACK error\n", msgs->addr);
+260 -48
drivers/i2c/busses/i2c-ocores.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * i2c-ocores.c: I2C bus driver for OpenCores I2C controller 3 4 * (https://opencores.org/project/i2c/overview) ··· 7 6 * 8 7 * Support for the GRLIB port of the controller by 9 8 * Andreas Larsson <andreas@gaisler.com> 10 - * 11 - * This file is licensed under the terms of the GNU General Public License 12 - * version 2. This program is licensed "as is" without any warranty of any 13 - * kind, whether express or implied. 14 9 */ 15 10 16 11 #include <linux/clk.h> 12 + #include <linux/delay.h> 17 13 #include <linux/err.h> 18 14 #include <linux/kernel.h> 19 15 #include <linux/module.h> ··· 23 25 #include <linux/slab.h> 24 26 #include <linux/io.h> 25 27 #include <linux/log2.h> 28 + #include <linux/spinlock.h> 29 + #include <linux/jiffies.h> 26 30 31 + #define OCORES_FLAG_POLL BIT(0) 32 + 33 + /* 34 + * 'process_lock' exists because ocores_process() and ocores_process_timeout() 35 + * can't run in parallel. 36 + */ 27 37 struct ocores_i2c { 28 38 void __iomem *base; 39 + int iobase; 29 40 u32 reg_shift; 30 41 u32 reg_io_width; 42 + unsigned long flags; 31 43 wait_queue_head_t wait; 32 44 struct i2c_adapter adap; 33 45 struct i2c_msg *msg; 34 46 int pos; 35 47 int nmsgs; 36 48 int state; /* see STATE_ */ 49 + spinlock_t process_lock; 37 50 struct clk *clk; 38 51 int ip_clock_khz; 39 52 int bus_clock_khz; ··· 136 127 return ioread32be(i2c->base + (reg << i2c->reg_shift)); 137 128 } 138 129 130 + static void oc_setreg_io_8(struct ocores_i2c *i2c, int reg, u8 value) 131 + { 132 + outb(value, i2c->iobase + reg); 133 + } 134 + 135 + static inline u8 oc_getreg_io_8(struct ocores_i2c *i2c, int reg) 136 + { 137 + return inb(i2c->iobase + reg); 138 + } 139 + 139 140 static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) 140 141 { 141 142 i2c->setreg(i2c, reg, value); ··· 156 137 return i2c->getreg(i2c, reg); 157 138 } 158 139 159 - static void ocores_process(struct ocores_i2c *i2c) 140 + static void ocores_process(struct ocores_i2c *i2c, u8 stat) 160 141 { 161 142 struct i2c_msg *msg = i2c->msg; 162 - u8 stat = oc_getreg(i2c, OCI2C_STATUS); 143 + unsigned long flags; 144 + 145 + /* 146 + * If we spin here is because we are in timeout, so we are going 147 + * to be in STATE_ERROR. See ocores_process_timeout() 148 + */ 149 + spin_lock_irqsave(&i2c->process_lock, flags); 163 150 164 151 if ((i2c->state == STATE_DONE) || (i2c->state == STATE_ERROR)) { 165 152 /* stop has been sent */ 166 153 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK); 167 154 wake_up(&i2c->wait); 168 - return; 155 + goto out; 169 156 } 170 157 171 158 /* error? */ 172 159 if (stat & OCI2C_STAT_ARBLOST) { 173 160 i2c->state = STATE_ERROR; 174 161 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 175 - return; 162 + goto out; 176 163 } 177 164 178 165 if ((i2c->state == STATE_START) || (i2c->state == STATE_WRITE)) { ··· 188 163 if (stat & OCI2C_STAT_NACK) { 189 164 i2c->state = STATE_ERROR; 190 165 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 191 - return; 166 + goto out; 192 167 } 193 - } else 168 + } else { 194 169 msg->buf[i2c->pos++] = oc_getreg(i2c, OCI2C_DATA); 170 + } 195 171 196 172 /* end of msg? */ 197 173 if (i2c->pos == msg->len) { ··· 209 183 i2c->state = STATE_START; 210 184 211 185 oc_setreg(i2c, OCI2C_DATA, addr); 212 - oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 213 - return; 214 - } else 215 - i2c->state = (msg->flags & I2C_M_RD) 216 - ? STATE_READ : STATE_WRITE; 186 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 187 + goto out; 188 + } 189 + i2c->state = (msg->flags & I2C_M_RD) 190 + ? STATE_READ : STATE_WRITE; 217 191 } else { 218 192 i2c->state = STATE_DONE; 219 193 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 220 - return; 194 + goto out; 221 195 } 222 196 } 223 197 ··· 228 202 oc_setreg(i2c, OCI2C_DATA, msg->buf[i2c->pos++]); 229 203 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_WRITE); 230 204 } 205 + 206 + out: 207 + spin_unlock_irqrestore(&i2c->process_lock, flags); 231 208 } 232 209 233 210 static irqreturn_t ocores_isr(int irq, void *dev_id) 234 211 { 235 212 struct ocores_i2c *i2c = dev_id; 213 + u8 stat = oc_getreg(i2c, OCI2C_STATUS); 236 214 237 - ocores_process(i2c); 215 + if (!(stat & OCI2C_STAT_IF)) 216 + return IRQ_NONE; 217 + 218 + ocores_process(i2c, stat); 238 219 239 220 return IRQ_HANDLED; 240 221 } 241 222 242 - static int ocores_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 223 + /** 224 + * Process timeout event 225 + * @i2c: ocores I2C device instance 226 + */ 227 + static void ocores_process_timeout(struct ocores_i2c *i2c) 243 228 { 244 - struct ocores_i2c *i2c = i2c_get_adapdata(adap); 229 + unsigned long flags; 230 + 231 + spin_lock_irqsave(&i2c->process_lock, flags); 232 + i2c->state = STATE_ERROR; 233 + oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_STOP); 234 + spin_unlock_irqrestore(&i2c->process_lock, flags); 235 + } 236 + 237 + /** 238 + * Wait until something change in a given register 239 + * @i2c: ocores I2C device instance 240 + * @reg: register to query 241 + * @mask: bitmask to apply on register value 242 + * @val: expected result 243 + * @timeout: timeout in jiffies 244 + * 245 + * Timeout is necessary to avoid to stay here forever when the chip 246 + * does not answer correctly. 247 + * 248 + * Return: 0 on success, -ETIMEDOUT on timeout 249 + */ 250 + static int ocores_wait(struct ocores_i2c *i2c, 251 + int reg, u8 mask, u8 val, 252 + const unsigned long timeout) 253 + { 254 + unsigned long j; 255 + 256 + j = jiffies + timeout; 257 + while (1) { 258 + u8 status = oc_getreg(i2c, reg); 259 + 260 + if ((status & mask) == val) 261 + break; 262 + 263 + if (time_after(jiffies, j)) 264 + return -ETIMEDOUT; 265 + } 266 + return 0; 267 + } 268 + 269 + /** 270 + * Wait until is possible to process some data 271 + * @i2c: ocores I2C device instance 272 + * 273 + * Used when the device is in polling mode (interrupts disabled). 274 + * 275 + * Return: 0 on success, -ETIMEDOUT on timeout 276 + */ 277 + static int ocores_poll_wait(struct ocores_i2c *i2c) 278 + { 279 + u8 mask; 280 + int err; 281 + 282 + if (i2c->state == STATE_DONE || i2c->state == STATE_ERROR) { 283 + /* transfer is over */ 284 + mask = OCI2C_STAT_BUSY; 285 + } else { 286 + /* on going transfer */ 287 + mask = OCI2C_STAT_TIP; 288 + /* 289 + * We wait for the data to be transferred (8bit), 290 + * then we start polling on the ACK/NACK bit 291 + */ 292 + udelay((8 * 1000) / i2c->bus_clock_khz); 293 + } 294 + 295 + /* 296 + * once we are here we expect to get the expected result immediately 297 + * so if after 1ms we timeout then something is broken. 298 + */ 299 + err = ocores_wait(i2c, OCI2C_STATUS, mask, 0, msecs_to_jiffies(1)); 300 + if (err) 301 + dev_warn(i2c->adap.dev.parent, 302 + "%s: STATUS timeout, bit 0x%x did not clear in 1ms\n", 303 + __func__, mask); 304 + return err; 305 + } 306 + 307 + /** 308 + * It handles an IRQ-less transfer 309 + * @i2c: ocores I2C device instance 310 + * 311 + * Even if IRQ are disabled, the I2C OpenCore IP behavior is exactly the same 312 + * (only that IRQ are not produced). This means that we can re-use entirely 313 + * ocores_isr(), we just add our polling code around it. 314 + * 315 + * It can run in atomic context 316 + */ 317 + static void ocores_process_polling(struct ocores_i2c *i2c) 318 + { 319 + while (1) { 320 + irqreturn_t ret; 321 + int err; 322 + 323 + err = ocores_poll_wait(i2c); 324 + if (err) { 325 + i2c->state = STATE_ERROR; 326 + break; /* timeout */ 327 + } 328 + 329 + ret = ocores_isr(-1, i2c); 330 + if (ret == IRQ_NONE) 331 + break; /* all messages have been transferred */ 332 + } 333 + } 334 + 335 + static int ocores_xfer_core(struct ocores_i2c *i2c, 336 + struct i2c_msg *msgs, int num, 337 + bool polling) 338 + { 339 + int ret; 340 + u8 ctrl; 341 + 342 + ctrl = oc_getreg(i2c, OCI2C_CONTROL); 343 + if (polling) 344 + oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~OCI2C_CTRL_IEN); 345 + else 346 + oc_setreg(i2c, OCI2C_CONTROL, ctrl | OCI2C_CTRL_IEN); 245 347 246 348 i2c->msg = msgs; 247 349 i2c->pos = 0; ··· 379 225 oc_setreg(i2c, OCI2C_DATA, i2c_8bit_addr_from_msg(i2c->msg)); 380 226 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START); 381 227 382 - if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) || 383 - (i2c->state == STATE_DONE), HZ)) 384 - return (i2c->state == STATE_DONE) ? num : -EIO; 385 - else 386 - return -ETIMEDOUT; 228 + if (polling) { 229 + ocores_process_polling(i2c); 230 + } else { 231 + ret = wait_event_timeout(i2c->wait, 232 + (i2c->state == STATE_ERROR) || 233 + (i2c->state == STATE_DONE), HZ); 234 + if (ret == 0) { 235 + ocores_process_timeout(i2c); 236 + return -ETIMEDOUT; 237 + } 238 + } 239 + 240 + return (i2c->state == STATE_DONE) ? num : -EIO; 241 + } 242 + 243 + static int ocores_xfer_polling(struct i2c_adapter *adap, 244 + struct i2c_msg *msgs, int num) 245 + { 246 + return ocores_xfer_core(i2c_get_adapdata(adap), msgs, num, true); 247 + } 248 + 249 + static int ocores_xfer(struct i2c_adapter *adap, 250 + struct i2c_msg *msgs, int num) 251 + { 252 + struct ocores_i2c *i2c = i2c_get_adapdata(adap); 253 + 254 + if (i2c->flags & OCORES_FLAG_POLL) 255 + return ocores_xfer_polling(adap, msgs, num); 256 + return ocores_xfer_core(i2c, msgs, num, false); 387 257 } 388 258 389 259 static int ocores_init(struct device *dev, struct ocores_i2c *i2c) ··· 417 239 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); 418 240 419 241 /* make sure the device is disabled */ 420 - oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN)); 242 + ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN); 243 + oc_setreg(i2c, OCI2C_CONTROL, ctrl); 421 244 422 245 prescale = (i2c->ip_clock_khz / (5 * i2c->bus_clock_khz)) - 1; 423 246 prescale = clamp(prescale, 0, 0xffff); ··· 436 257 437 258 /* Init the device */ 438 259 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_IACK); 439 - oc_setreg(i2c, OCI2C_CONTROL, ctrl | OCI2C_CTRL_IEN | OCI2C_CTRL_EN); 260 + oc_setreg(i2c, OCI2C_CONTROL, ctrl | OCI2C_CTRL_EN); 440 261 441 262 return 0; 442 263 } ··· 473 294 MODULE_DEVICE_TABLE(of, ocores_i2c_match); 474 295 475 296 #ifdef CONFIG_OF 476 - /* Read and write functions for the GRLIB port of the controller. Registers are 297 + /* 298 + * Read and write functions for the GRLIB port of the controller. Registers are 477 299 * 32-bit big endian and the PRELOW and PREHIGH registers are merged into one 478 - * register. The subsequent registers has their offset decreased accordingly. */ 300 + * register. The subsequent registers have their offsets decreased accordingly. 301 + */ 479 302 static u8 oc_getreg_grlib(struct ocores_i2c *i2c, int reg) 480 303 { 481 304 u32 rd; 482 305 int rreg = reg; 306 + 483 307 if (reg != OCI2C_PRELOW) 484 308 rreg--; 485 309 rd = ioread32be(i2c->base + (rreg << i2c->reg_shift)); ··· 496 314 { 497 315 u32 curr, wr; 498 316 int rreg = reg; 317 + 499 318 if (reg != OCI2C_PRELOW) 500 319 rreg--; 501 320 if (reg == OCI2C_PRELOW || reg == OCI2C_PREHIGH) { ··· 585 402 return 0; 586 403 } 587 404 #else 588 - #define ocores_i2c_of_probe(pdev,i2c) -ENODEV 405 + #define ocores_i2c_of_probe(pdev, i2c) -ENODEV 589 406 #endif 590 407 591 408 static int ocores_i2c_probe(struct platform_device *pdev) ··· 597 414 int ret; 598 415 int i; 599 416 600 - irq = platform_get_irq(pdev, 0); 601 - if (irq < 0) 602 - return irq; 603 - 604 417 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 605 418 if (!i2c) 606 419 return -ENOMEM; 607 420 421 + spin_lock_init(&i2c->process_lock); 422 + 608 423 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 609 - i2c->base = devm_ioremap_resource(&pdev->dev, res); 610 - if (IS_ERR(i2c->base)) 611 - return PTR_ERR(i2c->base); 424 + if (res) { 425 + i2c->base = devm_ioremap_resource(&pdev->dev, res); 426 + if (IS_ERR(i2c->base)) 427 + return PTR_ERR(i2c->base); 428 + } else { 429 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 430 + if (!res) 431 + return -EINVAL; 432 + i2c->iobase = res->start; 433 + if (!devm_request_region(&pdev->dev, res->start, 434 + resource_size(res), 435 + pdev->name)) { 436 + dev_err(&pdev->dev, "Can't get I/O resource.\n"); 437 + return -EBUSY; 438 + } 439 + i2c->setreg = oc_setreg_io_8; 440 + i2c->getreg = oc_getreg_io_8; 441 + } 612 442 613 443 pdata = dev_get_platdata(&pdev->dev); 614 444 if (pdata) { 615 445 i2c->reg_shift = pdata->reg_shift; 616 446 i2c->reg_io_width = pdata->reg_io_width; 617 447 i2c->ip_clock_khz = pdata->clock_khz; 618 - i2c->bus_clock_khz = 100; 448 + if (pdata->bus_khz) 449 + i2c->bus_clock_khz = pdata->bus_khz; 450 + else 451 + i2c->bus_clock_khz = 100; 619 452 } else { 620 453 ret = ocores_i2c_of_probe(pdev, i2c); 621 454 if (ret) ··· 669 470 } 670 471 } 671 472 473 + init_waitqueue_head(&i2c->wait); 474 + 475 + irq = platform_get_irq(pdev, 0); 476 + if (irq == -ENXIO) { 477 + i2c->flags |= OCORES_FLAG_POLL; 478 + } else { 479 + if (irq < 0) 480 + return irq; 481 + } 482 + 483 + if (!(i2c->flags & OCORES_FLAG_POLL)) { 484 + ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0, 485 + pdev->name, i2c); 486 + if (ret) { 487 + dev_err(&pdev->dev, "Cannot claim IRQ\n"); 488 + goto err_clk; 489 + } 490 + } 491 + 672 492 ret = ocores_init(&pdev->dev, i2c); 673 493 if (ret) 674 494 goto err_clk; 675 - 676 - init_waitqueue_head(&i2c->wait); 677 - ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0, 678 - pdev->name, i2c); 679 - if (ret) { 680 - dev_err(&pdev->dev, "Cannot claim IRQ\n"); 681 - goto err_clk; 682 - } 683 495 684 496 /* hook up driver to tree */ 685 497 platform_set_drvdata(pdev, i2c); ··· 720 510 static int ocores_i2c_remove(struct platform_device *pdev) 721 511 { 722 512 struct ocores_i2c *i2c = platform_get_drvdata(pdev); 513 + u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); 723 514 724 515 /* disable i2c logic */ 725 - oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL) 726 - & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN)); 516 + ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN); 517 + oc_setreg(i2c, OCI2C_CONTROL, ctrl); 727 518 728 519 /* remove adapter & data */ 729 520 i2c_del_adapter(&i2c->adap); ··· 742 531 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); 743 532 744 533 /* make sure the device is disabled */ 745 - oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN)); 534 + ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN); 535 + oc_setreg(i2c, OCI2C_CONTROL, ctrl); 746 536 747 537 if (!IS_ERR(i2c->clk)) 748 538 clk_disable_unprepare(i2c->clk);
+35 -14
drivers/i2c/busses/i2c-rcar.c
··· 2 2 /* 3 3 * Driver for the Renesas R-Car I2C unit 4 4 * 5 - * Copyright (C) 2014-15 Wolfram Sang <wsa@sang-engineering.com> 6 - * Copyright (C) 2011-2015 Renesas Electronics Corporation 5 + * Copyright (C) 2014-19 Wolfram Sang <wsa@sang-engineering.com> 6 + * Copyright (C) 2011-2019 Renesas Electronics Corporation 7 7 * 8 8 * Copyright (C) 2012-14 Renesas Solutions Corp. 9 9 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> ··· 39 39 #define ICSAR 0x1C /* slave address */ 40 40 #define ICMAR 0x20 /* master address */ 41 41 #define ICRXTX 0x24 /* data port */ 42 - #define ICDMAER 0x3c /* DMA enable */ 43 - #define ICFBSCR 0x38 /* first bit setup cycle */ 42 + #define ICFBSCR 0x38 /* first bit setup cycle (Gen3) */ 43 + #define ICDMAER 0x3c /* DMA enable (Gen3) */ 44 44 45 45 /* ICSCR */ 46 46 #define SDBS (1 << 3) /* slave data buffer select */ ··· 83 83 #define TMDMAE (1 << 0) /* DMA Master Transmitted Enable */ 84 84 85 85 /* ICFBSCR */ 86 - #define TCYC06 0x04 /* 6*Tcyc delay 1st bit between SDA and SCL */ 87 86 #define TCYC17 0x0f /* 17*Tcyc delay 1st bit between SDA and SCL */ 88 87 89 88 ··· 211 212 rcar_i2c_write(priv, ICMSR, 0); 212 213 /* start clock */ 213 214 rcar_i2c_write(priv, ICCCR, priv->icccr); 215 + 216 + if (priv->devtype == I2C_RCAR_GEN3) 217 + rcar_i2c_write(priv, ICFBSCR, TCYC17); 218 + 214 219 } 215 220 216 221 static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) ··· 358 355 rcar_i2c_prepare_msg(priv); 359 356 } 360 357 361 - /* 362 - * interrupt functions 363 - */ 364 358 static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv) 365 359 { 366 360 struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE ··· 365 365 366 366 /* Disable DMA Master Received/Transmitted */ 367 367 rcar_i2c_write(priv, ICDMAER, 0); 368 - 369 - /* Reset default delay */ 370 - rcar_i2c_write(priv, ICFBSCR, TCYC06); 371 368 372 369 dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg), 373 370 sg_dma_len(&priv->sg), priv->dma_direction); ··· 460 463 rcar_i2c_cleanup_dma(priv); 461 464 return; 462 465 } 463 - 464 - /* Set delay for DMA operations */ 465 - rcar_i2c_write(priv, ICFBSCR, TCYC17); 466 466 467 467 /* Enable DMA Master Received/Transmitted */ 468 468 if (read) ··· 1011 1017 return 0; 1012 1018 } 1013 1019 1020 + #ifdef CONFIG_PM_SLEEP 1021 + static int rcar_i2c_suspend(struct device *dev) 1022 + { 1023 + struct rcar_i2c_priv *priv = dev_get_drvdata(dev); 1024 + 1025 + i2c_mark_adapter_suspended(&priv->adap); 1026 + return 0; 1027 + } 1028 + 1029 + static int rcar_i2c_resume(struct device *dev) 1030 + { 1031 + struct rcar_i2c_priv *priv = dev_get_drvdata(dev); 1032 + 1033 + i2c_mark_adapter_resumed(&priv->adap); 1034 + return 0; 1035 + } 1036 + 1037 + static const struct dev_pm_ops rcar_i2c_pm_ops = { 1038 + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(rcar_i2c_suspend, rcar_i2c_resume) 1039 + }; 1040 + 1041 + #define DEV_PM_OPS (&rcar_i2c_pm_ops) 1042 + #else 1043 + #define DEV_PM_OPS NULL 1044 + #endif /* CONFIG_PM_SLEEP */ 1045 + 1014 1046 static struct platform_driver rcar_i2c_driver = { 1015 1047 .driver = { 1016 1048 .name = "i2c-rcar", 1017 1049 .of_match_table = rcar_i2c_dt_ids, 1050 + .pm = DEV_PM_OPS, 1018 1051 }, 1019 1052 .probe = rcar_i2c_probe, 1020 1053 .remove = rcar_i2c_remove,
+2 -6
drivers/i2c/busses/i2c-s3c2410.c
··· 104 104 struct s3c24xx_i2c { 105 105 wait_queue_head_t wait; 106 106 kernel_ulong_t quirks; 107 - unsigned int suspended:1; 108 107 109 108 struct i2c_msg *msg; 110 109 unsigned int msg_num; ··· 702 703 unsigned long timeout; 703 704 int ret; 704 705 705 - if (i2c->suspended) 706 - return -EIO; 707 - 708 706 ret = s3c24xx_i2c_set_master(i2c); 709 707 if (ret != 0) { 710 708 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); ··· 1242 1246 { 1243 1247 struct s3c24xx_i2c *i2c = dev_get_drvdata(dev); 1244 1248 1245 - i2c->suspended = 1; 1249 + i2c_mark_adapter_suspended(&i2c->adap); 1246 1250 1247 1251 if (!IS_ERR(i2c->sysreg)) 1248 1252 regmap_read(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, &i2c->sys_i2c_cfg); ··· 1263 1267 return ret; 1264 1268 s3c24xx_i2c_init(i2c); 1265 1269 clk_disable(i2c->clk); 1266 - i2c->suspended = 0; 1270 + i2c_mark_adapter_resumed(&i2c->adap); 1267 1271 1268 1272 return 0; 1269 1273 }
+43 -76
drivers/i2c/busses/i2c-sh_mobile.c
··· 2 2 /* 3 3 * SuperH Mobile I2C Controller 4 4 * 5 - * Copyright (C) 2014 Wolfram Sang <wsa@sang-engineering.com> 6 - * 5 + * Copyright (C) 2014-19 Wolfram Sang <wsa@sang-engineering.com> 7 6 * Copyright (C) 2008 Magnus Damm 8 7 * 9 8 * Portions of the code based on out-of-tree driver i2c-sh7343.c ··· 302 303 return sh_mobile_i2c_check_timing(pd); 303 304 } 304 305 305 - static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, 306 - enum sh_mobile_i2c_op op, unsigned char data) 306 + static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, enum sh_mobile_i2c_op op) 307 307 { 308 308 unsigned char ret = 0; 309 309 unsigned long flags; 310 310 311 - dev_dbg(pd->dev, "op %d, data in 0x%02x\n", op, data); 311 + dev_dbg(pd->dev, "op %d\n", op); 312 312 313 313 spin_lock_irqsave(&pd->lock, flags); 314 314 ··· 315 317 case OP_START: /* issue start and trigger DTE interrupt */ 316 318 iic_wr(pd, ICCR, ICCR_ICE | ICCR_TRS | ICCR_BBSY); 317 319 break; 318 - case OP_TX_FIRST: /* disable DTE interrupt and write data */ 320 + case OP_TX_FIRST: /* disable DTE interrupt and write client address */ 319 321 iic_wr(pd, ICIC, ICIC_WAITE | ICIC_ALE | ICIC_TACKE); 320 - iic_wr(pd, ICDR, data); 322 + iic_wr(pd, ICDR, i2c_8bit_addr_from_msg(pd->msg)); 321 323 break; 322 324 case OP_TX: /* write data */ 323 - iic_wr(pd, ICDR, data); 325 + iic_wr(pd, ICDR, pd->msg->buf[pd->pos]); 324 326 break; 325 327 case OP_TX_STOP: /* issue a stop (or rep_start) */ 326 328 iic_wr(pd, ICCR, pd->send_stop ? ICCR_ICE | ICCR_TRS ··· 351 353 return ret; 352 354 } 353 355 354 - static bool sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd) 355 - { 356 - return pd->pos == -1; 357 - } 358 - 359 - static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd, 360 - unsigned char *buf) 361 - { 362 - switch (pd->pos) { 363 - case -1: 364 - *buf = i2c_8bit_addr_from_msg(pd->msg); 365 - break; 366 - default: 367 - *buf = pd->msg->buf[pd->pos]; 368 - } 369 - } 370 - 371 356 static int sh_mobile_i2c_isr_tx(struct sh_mobile_i2c_data *pd) 372 357 { 373 - unsigned char data; 374 - 375 358 if (pd->pos == pd->msg->len) { 376 - i2c_op(pd, OP_TX_STOP, 0); 359 + i2c_op(pd, OP_TX_STOP); 377 360 return 1; 378 361 } 379 362 380 - sh_mobile_i2c_get_data(pd, &data); 381 - i2c_op(pd, sh_mobile_i2c_is_first_byte(pd) ? OP_TX_FIRST : OP_TX, data); 363 + if (pd->pos == -1) 364 + i2c_op(pd, OP_TX_FIRST); 365 + else 366 + i2c_op(pd, OP_TX); 382 367 383 368 pd->pos++; 384 369 return 0; ··· 372 391 unsigned char data; 373 392 int real_pos; 374 393 375 - do { 376 - if (pd->pos <= -1) { 377 - sh_mobile_i2c_get_data(pd, &data); 394 + /* switch from TX (address) to RX (data) adds two interrupts */ 395 + real_pos = pd->pos - 2; 378 396 379 - if (sh_mobile_i2c_is_first_byte(pd)) 380 - i2c_op(pd, OP_TX_FIRST, data); 381 - else 382 - i2c_op(pd, OP_TX, data); 383 - break; 397 + if (pd->pos == -1) { 398 + i2c_op(pd, OP_TX_FIRST); 399 + } else if (pd->pos == 0) { 400 + i2c_op(pd, OP_TX_TO_RX); 401 + } else if (pd->pos == pd->msg->len) { 402 + if (pd->stop_after_dma) { 403 + /* Simulate PIO end condition after DMA transfer */ 404 + i2c_op(pd, OP_RX_STOP); 405 + pd->pos++; 406 + goto done; 384 407 } 385 408 386 - if (pd->pos == 0) { 387 - i2c_op(pd, OP_TX_TO_RX, 0); 388 - break; 389 - } 409 + if (real_pos < 0) 410 + i2c_op(pd, OP_RX_STOP); 411 + else 412 + data = i2c_op(pd, OP_RX_STOP_DATA); 413 + } else if (real_pos >= 0) { 414 + data = i2c_op(pd, OP_RX); 415 + } 390 416 391 - real_pos = pd->pos - 2; 392 - 393 - if (pd->pos == pd->msg->len) { 394 - if (pd->stop_after_dma) { 395 - /* Simulate PIO end condition after DMA transfer */ 396 - i2c_op(pd, OP_RX_STOP, 0); 397 - pd->pos++; 398 - break; 399 - } 400 - 401 - if (real_pos < 0) { 402 - i2c_op(pd, OP_RX_STOP, 0); 403 - break; 404 - } 405 - data = i2c_op(pd, OP_RX_STOP_DATA, 0); 406 - } else if (real_pos >= 0) { 407 - data = i2c_op(pd, OP_RX, 0); 408 - } 409 - 410 - if (real_pos >= 0) 411 - pd->msg->buf[real_pos] = data; 412 - } while (0); 413 - 417 + if (real_pos >= 0) 418 + pd->msg->buf[real_pos] = data; 419 + done: 414 420 pd->pos++; 415 421 return pd->pos == (pd->msg->len + 2); 416 422 } ··· 666 698 start_ch(pd, msg, do_start); 667 699 668 700 if (do_start) 669 - i2c_op(pd, OP_START, 0); 701 + i2c_op(pd, OP_START); 670 702 671 703 /* The interrupt handler takes care of the rest... */ 672 704 timeout = wait_event_timeout(pd->wait, ··· 717 749 }; 718 750 719 751 /* 720 - * r8a7740 chip has lasting errata on I2C I/O pad reset. 721 - * this is work-around for it. 752 + * r8a7740 has an errata regarding I2C I/O pad reset needing this workaround. 722 753 */ 723 754 static int sh_mobile_i2c_r8a7740_workaround(struct sh_mobile_i2c_data *pd) 724 755 { ··· 769 802 { .compatible = "renesas,iic-r8a7740", .data = &r8a7740_dt_config }, 770 803 { .compatible = "renesas,iic-r8a774c0", .data = &fast_clock_dt_config }, 771 804 { .compatible = "renesas,iic-r8a7790", .data = &v2_freq_calc_dt_config }, 772 - { .compatible = "renesas,iic-r8a7791", .data = &fast_clock_dt_config }, 773 - { .compatible = "renesas,iic-r8a7792", .data = &fast_clock_dt_config }, 774 - { .compatible = "renesas,iic-r8a7793", .data = &fast_clock_dt_config }, 775 - { .compatible = "renesas,iic-r8a7794", .data = &fast_clock_dt_config }, 776 - { .compatible = "renesas,rcar-gen2-iic", .data = &fast_clock_dt_config }, 777 - { .compatible = "renesas,iic-r8a7795", .data = &fast_clock_dt_config }, 778 - { .compatible = "renesas,rcar-gen3-iic", .data = &fast_clock_dt_config }, 779 - { .compatible = "renesas,iic-r8a77990", .data = &fast_clock_dt_config }, 805 + { .compatible = "renesas,iic-r8a7791", .data = &v2_freq_calc_dt_config }, 806 + { .compatible = "renesas,iic-r8a7792", .data = &v2_freq_calc_dt_config }, 807 + { .compatible = "renesas,iic-r8a7793", .data = &v2_freq_calc_dt_config }, 808 + { .compatible = "renesas,iic-r8a7794", .data = &v2_freq_calc_dt_config }, 809 + { .compatible = "renesas,iic-r8a7795", .data = &v2_freq_calc_dt_config }, 810 + { .compatible = "renesas,iic-r8a77990", .data = &v2_freq_calc_dt_config }, 780 811 { .compatible = "renesas,iic-sh73a0", .data = &fast_clock_dt_config }, 812 + { .compatible = "renesas,rcar-gen2-iic", .data = &v2_freq_calc_dt_config }, 813 + { .compatible = "renesas,rcar-gen3-iic", .data = &v2_freq_calc_dt_config }, 781 814 { .compatible = "renesas,rmobile-iic", .data = &default_dt_config }, 782 815 {}, 783 816 };
+12 -22
drivers/i2c/busses/i2c-sprd.c
··· 86 86 u32 count; 87 87 int irq; 88 88 int err; 89 - bool is_suspended; 90 89 }; 91 90 92 91 static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count) ··· 282 283 { 283 284 struct sprd_i2c *i2c_dev = i2c_adap->algo_data; 284 285 int im, ret; 285 - 286 - if (i2c_dev->is_suspended) 287 - return -EBUSY; 288 286 289 287 ret = pm_runtime_get_sync(i2c_dev->dev); 290 288 if (ret < 0) ··· 582 586 return 0; 583 587 } 584 588 585 - static int __maybe_unused sprd_i2c_suspend_noirq(struct device *pdev) 589 + static int __maybe_unused sprd_i2c_suspend_noirq(struct device *dev) 586 590 { 587 - struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 591 + struct sprd_i2c *i2c_dev = dev_get_drvdata(dev); 588 592 589 - i2c_lock_bus(&i2c_dev->adap, I2C_LOCK_ROOT_ADAPTER); 590 - i2c_dev->is_suspended = true; 591 - i2c_unlock_bus(&i2c_dev->adap, I2C_LOCK_ROOT_ADAPTER); 592 - 593 - return pm_runtime_force_suspend(pdev); 593 + i2c_mark_adapter_suspended(&i2c_dev->adap); 594 + return pm_runtime_force_suspend(dev); 594 595 } 595 596 596 - static int __maybe_unused sprd_i2c_resume_noirq(struct device *pdev) 597 + static int __maybe_unused sprd_i2c_resume_noirq(struct device *dev) 597 598 { 598 - struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 599 + struct sprd_i2c *i2c_dev = dev_get_drvdata(dev); 599 600 600 - i2c_lock_bus(&i2c_dev->adap, I2C_LOCK_ROOT_ADAPTER); 601 - i2c_dev->is_suspended = false; 602 - i2c_unlock_bus(&i2c_dev->adap, I2C_LOCK_ROOT_ADAPTER); 603 - 604 - return pm_runtime_force_resume(pdev); 601 + i2c_mark_adapter_resumed(&i2c_dev->adap); 602 + return pm_runtime_force_resume(dev); 605 603 } 606 604 607 - static int __maybe_unused sprd_i2c_runtime_suspend(struct device *pdev) 605 + static int __maybe_unused sprd_i2c_runtime_suspend(struct device *dev) 608 606 { 609 - struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 607 + struct sprd_i2c *i2c_dev = dev_get_drvdata(dev); 610 608 611 609 clk_disable_unprepare(i2c_dev->clk); 612 610 613 611 return 0; 614 612 } 615 613 616 - static int __maybe_unused sprd_i2c_runtime_resume(struct device *pdev) 614 + static int __maybe_unused sprd_i2c_runtime_resume(struct device *dev) 617 615 { 618 - struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); 616 + struct sprd_i2c *i2c_dev = dev_get_drvdata(dev); 619 617 int ret; 620 618 621 619 ret = clk_prepare_enable(i2c_dev->clk);
-5
drivers/i2c/busses/i2c-synquacer.c
··· 144 144 u32 timeout_ms; 145 145 enum i2c_state state; 146 146 struct i2c_adapter adapter; 147 - 148 - bool is_suspended; 149 147 }; 150 148 151 149 static inline int is_lastmsg(struct synquacer_i2c *i2c) ··· 313 315 unsigned char bsr; 314 316 unsigned long timeout; 315 317 int ret; 316 - 317 - if (i2c->is_suspended) 318 - return -EBUSY; 319 318 320 319 synquacer_i2c_hw_init(i2c); 321 320 bsr = readb(i2c->base + SYNQUACER_I2C_REG_BSR);
+648 -94
drivers/i2c/busses/i2c-tegra.c
··· 6 6 * Author: Colin Cross <ccross@android.com> 7 7 */ 8 8 9 - #include <linux/kernel.h> 10 - #include <linux/init.h> 11 - #include <linux/platform_device.h> 12 9 #include <linux/clk.h> 10 + #include <linux/delay.h> 11 + #include <linux/dmaengine.h> 12 + #include <linux/dma-mapping.h> 13 13 #include <linux/err.h> 14 14 #include <linux/i2c.h> 15 - #include <linux/io.h> 15 + #include <linux/init.h> 16 16 #include <linux/interrupt.h> 17 - #include <linux/delay.h> 18 - #include <linux/slab.h> 19 - #include <linux/of_device.h> 20 - #include <linux/module.h> 21 - #include <linux/reset.h> 22 - #include <linux/pinctrl/consumer.h> 23 - #include <linux/pm_runtime.h> 17 + #include <linux/io.h> 24 18 #include <linux/iopoll.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 21 + #include <linux/of_device.h> 22 + #include <linux/pinctrl/consumer.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/pm_runtime.h> 25 + #include <linux/reset.h> 25 26 26 - #include <asm/unaligned.h> 27 - 28 - #define TEGRA_I2C_TIMEOUT (msecs_to_jiffies(1000)) 29 27 #define BYTES_PER_FIFO_WORD 4 30 28 31 29 #define I2C_CNFG 0x000 ··· 43 45 #define I2C_FIFO_CONTROL 0x05c 44 46 #define I2C_FIFO_CONTROL_TX_FLUSH BIT(1) 45 47 #define I2C_FIFO_CONTROL_RX_FLUSH BIT(0) 46 - #define I2C_FIFO_CONTROL_TX_TRIG_SHIFT 5 47 - #define I2C_FIFO_CONTROL_RX_TRIG_SHIFT 2 48 + #define I2C_FIFO_CONTROL_TX_TRIG(x) (((x) - 1) << 5) 49 + #define I2C_FIFO_CONTROL_RX_TRIG(x) (((x) - 1) << 2) 48 50 #define I2C_FIFO_STATUS 0x060 49 51 #define I2C_FIFO_STATUS_TX_MASK 0xF0 50 52 #define I2C_FIFO_STATUS_TX_SHIFT 4 ··· 52 54 #define I2C_FIFO_STATUS_RX_SHIFT 0 53 55 #define I2C_INT_MASK 0x064 54 56 #define I2C_INT_STATUS 0x068 57 + #define I2C_INT_BUS_CLR_DONE BIT(11) 55 58 #define I2C_INT_PACKET_XFER_COMPLETE BIT(7) 56 59 #define I2C_INT_ALL_PACKETS_XFER_COMPLETE BIT(6) 57 60 #define I2C_INT_TX_FIFO_OVERFLOW BIT(5) ··· 95 96 #define I2C_HEADER_MASTER_ADDR_SHIFT 12 96 97 #define I2C_HEADER_SLAVE_ADDR_SHIFT 1 97 98 99 + #define I2C_BUS_CLEAR_CNFG 0x084 100 + #define I2C_BC_SCLK_THRESHOLD 9 101 + #define I2C_BC_SCLK_THRESHOLD_SHIFT 16 102 + #define I2C_BC_STOP_COND BIT(2) 103 + #define I2C_BC_TERMINATE BIT(1) 104 + #define I2C_BC_ENABLE BIT(0) 105 + #define I2C_BUS_CLEAR_STATUS 0x088 106 + #define I2C_BC_STATUS BIT(0) 107 + 98 108 #define I2C_CONFIG_LOAD 0x08C 99 109 #define I2C_MSTR_CONFIG_LOAD BIT(0) 100 110 #define I2C_SLV_CONFIG_LOAD BIT(1) ··· 125 117 #define I2C_MST_FIFO_STATUS_RX_SHIFT 0 126 118 #define I2C_MST_FIFO_STATUS_TX_MASK 0xff0000 127 119 #define I2C_MST_FIFO_STATUS_TX_SHIFT 16 120 + 121 + #define I2C_INTERFACE_TIMING_0 0x94 122 + #define I2C_THIGH_SHIFT 8 123 + #define I2C_INTERFACE_TIMING_1 0x98 124 + 125 + #define I2C_STANDARD_MODE 100000 126 + #define I2C_FAST_MODE 400000 127 + #define I2C_FAST_PLUS_MODE 1000000 128 + #define I2C_HS_MODE 3500000 129 + 130 + /* Packet header size in bytes */ 131 + #define I2C_PACKET_HEADER_SIZE 12 132 + 133 + /* 134 + * Upto I2C_PIO_MODE_MAX_LEN bytes, controller will use PIO mode, 135 + * above this, controller will use DMA to fill FIFO. 136 + * MAX PIO len is 20 bytes excluding packet header. 137 + */ 138 + #define I2C_PIO_MODE_MAX_LEN 32 128 139 129 140 /* 130 141 * msg_end_type: The bus control which need to be send at end of transfer. ··· 169 142 * @has_config_load_reg: Has the config load register to load the new 170 143 * configuration. 171 144 * @clk_divisor_hs_mode: Clock divisor in HS mode. 172 - * @clk_divisor_std_fast_mode: Clock divisor in standard/fast mode. It is 145 + * @clk_divisor_std_mode: Clock divisor in standard mode. It is 146 + * applicable if there is no fast clock source i.e. single clock 147 + * source. 148 + * @clk_divisor_fast_mode: Clock divisor in fast mode. It is 173 149 * applicable if there is no fast clock source i.e. single clock 174 150 * source. 175 151 * @clk_divisor_fast_plus_mode: Clock divisor in fast mode plus. It is ··· 187 157 * be transferred in one go. 188 158 * @quirks: i2c adapter quirks for limiting write/read transfer size and not 189 159 * allowing 0 length transfers. 160 + * @supports_bus_clear: Bus Clear support to recover from bus hang during 161 + * SDA stuck low from device for some unknown reasons. 162 + * @has_apb_dma: Support of APBDMA on corresponding Tegra chip. 163 + * @tlow_std_mode: Low period of the clock in standard mode. 164 + * @thigh_std_mode: High period of the clock in standard mode. 165 + * @tlow_fast_fastplus_mode: Low period of the clock in fast/fast-plus modes. 166 + * @thigh_fast_fastplus_mode: High period of the clock in fast/fast-plus modes. 167 + * @setup_hold_time_std_mode: Setup and hold time for start and stop conditions 168 + * in standard mode. 169 + * @setup_hold_time_fast_fast_plus_mode: Setup and hold time for start and stop 170 + * conditions in fast/fast-plus modes. 171 + * @setup_hold_time_hs_mode: Setup and hold time for start and stop conditions 172 + * in HS mode. 173 + * @has_interface_timing_reg: Has interface timing register to program the tuned 174 + * timing settings. 190 175 */ 191 176 struct tegra_i2c_hw_feature { 192 177 bool has_continue_xfer_support; ··· 209 164 bool has_single_clk_source; 210 165 bool has_config_load_reg; 211 166 int clk_divisor_hs_mode; 212 - int clk_divisor_std_fast_mode; 167 + int clk_divisor_std_mode; 168 + int clk_divisor_fast_mode; 213 169 u16 clk_divisor_fast_plus_mode; 214 170 bool has_multi_master_mode; 215 171 bool has_slcg_override_reg; 216 172 bool has_mst_fifo; 217 173 const struct i2c_adapter_quirks *quirks; 174 + bool supports_bus_clear; 175 + bool has_apb_dma; 176 + u8 tlow_std_mode; 177 + u8 thigh_std_mode; 178 + u8 tlow_fast_fastplus_mode; 179 + u8 thigh_fast_fastplus_mode; 180 + u32 setup_hold_time_std_mode; 181 + u32 setup_hold_time_fast_fast_plus_mode; 182 + u32 setup_hold_time_hs_mode; 183 + bool has_interface_timing_reg; 218 184 }; 219 185 220 186 /** ··· 237 181 * @fast_clk: clock reference for fast clock of I2C controller 238 182 * @rst: reset control for the I2C controller 239 183 * @base: ioremapped registers cookie 184 + * @base_phys: physical base address of the I2C controller 240 185 * @cont_id: I2C controller ID, used for packet header 241 186 * @irq: IRQ number of transfer complete interrupt 242 187 * @irq_disabled: used to track whether or not the interrupt is enabled ··· 251 194 * @clk_divisor_non_hs_mode: clock divider for non-high-speed modes 252 195 * @is_multimaster_mode: track if I2C controller is in multi-master mode 253 196 * @xfer_lock: lock to serialize transfer submission and processing 197 + * @tx_dma_chan: DMA transmit channel 198 + * @rx_dma_chan: DMA receive channel 199 + * @dma_phys: handle to DMA resources 200 + * @dma_buf: pointer to allocated DMA buffer 201 + * @dma_buf_size: DMA buffer size 202 + * @is_curr_dma_xfer: indicates active DMA transfer 203 + * @dma_complete: DMA completion notifier 254 204 */ 255 205 struct tegra_i2c_dev { 256 206 struct device *dev; ··· 267 203 struct clk *fast_clk; 268 204 struct reset_control *rst; 269 205 void __iomem *base; 206 + phys_addr_t base_phys; 270 207 int cont_id; 271 208 int irq; 272 209 bool irq_disabled; ··· 281 216 u16 clk_divisor_non_hs_mode; 282 217 bool is_multimaster_mode; 283 218 spinlock_t xfer_lock; 219 + struct dma_chan *tx_dma_chan; 220 + struct dma_chan *rx_dma_chan; 221 + dma_addr_t dma_phys; 222 + u32 *dma_buf; 223 + unsigned int dma_buf_size; 224 + bool is_curr_dma_xfer; 225 + struct completion dma_complete; 284 226 }; 285 227 286 228 static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, ··· 354 282 355 283 int_mask = i2c_readl(i2c_dev, I2C_INT_MASK) | mask; 356 284 i2c_writel(i2c_dev, int_mask, I2C_INT_MASK); 285 + } 286 + 287 + static void tegra_i2c_dma_complete(void *args) 288 + { 289 + struct tegra_i2c_dev *i2c_dev = args; 290 + 291 + complete(&i2c_dev->dma_complete); 292 + } 293 + 294 + static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len) 295 + { 296 + struct dma_async_tx_descriptor *dma_desc; 297 + enum dma_transfer_direction dir; 298 + struct dma_chan *chan; 299 + 300 + dev_dbg(i2c_dev->dev, "starting DMA for length: %zu\n", len); 301 + reinit_completion(&i2c_dev->dma_complete); 302 + dir = i2c_dev->msg_read ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; 303 + chan = i2c_dev->msg_read ? i2c_dev->rx_dma_chan : i2c_dev->tx_dma_chan; 304 + dma_desc = dmaengine_prep_slave_single(chan, i2c_dev->dma_phys, 305 + len, dir, DMA_PREP_INTERRUPT | 306 + DMA_CTRL_ACK); 307 + if (!dma_desc) { 308 + dev_err(i2c_dev->dev, "failed to get DMA descriptor\n"); 309 + return -EINVAL; 310 + } 311 + 312 + dma_desc->callback = tegra_i2c_dma_complete; 313 + dma_desc->callback_param = i2c_dev; 314 + dmaengine_submit(dma_desc); 315 + dma_async_issue_pending(chan); 316 + return 0; 317 + } 318 + 319 + static void tegra_i2c_release_dma(struct tegra_i2c_dev *i2c_dev) 320 + { 321 + if (i2c_dev->dma_buf) { 322 + dma_free_coherent(i2c_dev->dev, i2c_dev->dma_buf_size, 323 + i2c_dev->dma_buf, i2c_dev->dma_phys); 324 + i2c_dev->dma_buf = NULL; 325 + } 326 + 327 + if (i2c_dev->tx_dma_chan) { 328 + dma_release_channel(i2c_dev->tx_dma_chan); 329 + i2c_dev->tx_dma_chan = NULL; 330 + } 331 + 332 + if (i2c_dev->rx_dma_chan) { 333 + dma_release_channel(i2c_dev->rx_dma_chan); 334 + i2c_dev->rx_dma_chan = NULL; 335 + } 336 + } 337 + 338 + static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) 339 + { 340 + struct dma_chan *chan; 341 + u32 *dma_buf; 342 + dma_addr_t dma_phys; 343 + int err; 344 + 345 + if (!i2c_dev->hw->has_apb_dma) 346 + return 0; 347 + 348 + if (!IS_ENABLED(CONFIG_TEGRA20_APB_DMA)) { 349 + dev_dbg(i2c_dev->dev, "Support for APB DMA not enabled!\n"); 350 + return 0; 351 + } 352 + 353 + chan = dma_request_slave_channel_reason(i2c_dev->dev, "rx"); 354 + if (IS_ERR(chan)) { 355 + err = PTR_ERR(chan); 356 + goto err_out; 357 + } 358 + 359 + i2c_dev->rx_dma_chan = chan; 360 + 361 + chan = dma_request_slave_channel_reason(i2c_dev->dev, "tx"); 362 + if (IS_ERR(chan)) { 363 + err = PTR_ERR(chan); 364 + goto err_out; 365 + } 366 + 367 + i2c_dev->tx_dma_chan = chan; 368 + 369 + dma_buf = dma_alloc_coherent(i2c_dev->dev, i2c_dev->dma_buf_size, 370 + &dma_phys, GFP_KERNEL | __GFP_NOWARN); 371 + if (!dma_buf) { 372 + dev_err(i2c_dev->dev, "failed to allocate the DMA buffer\n"); 373 + err = -ENOMEM; 374 + goto err_out; 375 + } 376 + 377 + i2c_dev->dma_buf = dma_buf; 378 + i2c_dev->dma_phys = dma_phys; 379 + return 0; 380 + 381 + err_out: 382 + tegra_i2c_release_dma(i2c_dev); 383 + if (err != -EPROBE_DEFER) { 384 + dev_err(i2c_dev->dev, "cannot use DMA: %d\n", err); 385 + dev_err(i2c_dev->dev, "falling back to PIO\n"); 386 + return 0; 387 + } 388 + 389 + return err; 357 390 } 358 391 359 392 static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) ··· 695 518 return 0; 696 519 } 697 520 698 - static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) 521 + static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev, bool clk_reinit) 699 522 { 700 523 u32 val; 701 524 int err; 702 - u32 clk_divisor; 525 + u32 clk_divisor, clk_multiplier; 526 + u32 tsu_thd = 0; 527 + u8 tlow, thigh; 703 528 704 529 err = pm_runtime_get_sync(i2c_dev->dev); 705 530 if (err < 0) { ··· 731 552 I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT; 732 553 i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); 733 554 555 + if (i2c_dev->bus_clk_rate > I2C_STANDARD_MODE && 556 + i2c_dev->bus_clk_rate <= I2C_FAST_PLUS_MODE) { 557 + tlow = i2c_dev->hw->tlow_fast_fastplus_mode; 558 + thigh = i2c_dev->hw->thigh_fast_fastplus_mode; 559 + tsu_thd = i2c_dev->hw->setup_hold_time_fast_fast_plus_mode; 560 + } else { 561 + tlow = i2c_dev->hw->tlow_std_mode; 562 + thigh = i2c_dev->hw->thigh_std_mode; 563 + tsu_thd = i2c_dev->hw->setup_hold_time_std_mode; 564 + } 565 + 566 + if (i2c_dev->hw->has_interface_timing_reg) { 567 + val = (thigh << I2C_THIGH_SHIFT) | tlow; 568 + i2c_writel(i2c_dev, val, I2C_INTERFACE_TIMING_0); 569 + } 570 + 571 + /* 572 + * configure setup and hold times only when tsu_thd is non-zero. 573 + * otherwise, preserve the chip default values 574 + */ 575 + if (i2c_dev->hw->has_interface_timing_reg && tsu_thd) 576 + i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1); 577 + 578 + if (!clk_reinit) { 579 + clk_multiplier = (tlow + thigh + 2); 580 + clk_multiplier *= (i2c_dev->clk_divisor_non_hs_mode + 1); 581 + err = clk_set_rate(i2c_dev->div_clk, 582 + i2c_dev->bus_clk_rate * clk_multiplier); 583 + if (err) { 584 + dev_err(i2c_dev->dev, 585 + "failed changing clock rate: %d\n", err); 586 + goto err; 587 + } 588 + } 589 + 734 590 if (!i2c_dev->is_dvc) { 735 591 u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG); 736 592 ··· 773 559 i2c_writel(i2c_dev, sl_cfg, I2C_SL_CNFG); 774 560 i2c_writel(i2c_dev, 0xfc, I2C_SL_ADDR1); 775 561 i2c_writel(i2c_dev, 0x00, I2C_SL_ADDR2); 776 - } 777 - 778 - if (i2c_dev->hw->has_mst_fifo) { 779 - val = I2C_MST_FIFO_CONTROL_TX_TRIG(8) | 780 - I2C_MST_FIFO_CONTROL_RX_TRIG(1); 781 - i2c_writel(i2c_dev, val, I2C_MST_FIFO_CONTROL); 782 - } else { 783 - val = 7 << I2C_FIFO_CONTROL_TX_TRIG_SHIFT | 784 - 0 << I2C_FIFO_CONTROL_RX_TRIG_SHIFT; 785 - i2c_writel(i2c_dev, val, I2C_FIFO_CONTROL); 786 562 } 787 563 788 564 err = tegra_i2c_flush_fifos(i2c_dev); ··· 847 643 goto err; 848 644 } 849 645 850 - if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { 851 - if (i2c_dev->msg_buf_remaining) 852 - tegra_i2c_empty_rx_fifo(i2c_dev); 853 - else 854 - BUG(); 855 - } 646 + /* 647 + * I2C transfer is terminated during the bus clear so skip 648 + * processing the other interrupts. 649 + */ 650 + if (i2c_dev->hw->supports_bus_clear && (status & I2C_INT_BUS_CLR_DONE)) 651 + goto err; 856 652 857 - if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) { 858 - if (i2c_dev->msg_buf_remaining) 859 - tegra_i2c_fill_tx_fifo(i2c_dev); 860 - else 861 - tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ); 653 + if (!i2c_dev->is_curr_dma_xfer) { 654 + if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { 655 + if (i2c_dev->msg_buf_remaining) 656 + tegra_i2c_empty_rx_fifo(i2c_dev); 657 + else 658 + BUG(); 659 + } 660 + 661 + if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) { 662 + if (i2c_dev->msg_buf_remaining) 663 + tegra_i2c_fill_tx_fifo(i2c_dev); 664 + else 665 + tegra_i2c_mask_irq(i2c_dev, 666 + I2C_INT_TX_FIFO_DATA_REQ); 667 + } 862 668 } 863 669 864 670 i2c_writel(i2c_dev, status, I2C_INT_STATUS); 865 671 if (i2c_dev->is_dvc) 866 672 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); 867 673 674 + /* 675 + * During message read XFER_COMPLETE interrupt is triggered prior to 676 + * DMA completion and during message write XFER_COMPLETE interrupt is 677 + * triggered after DMA completion. 678 + * PACKETS_XFER_COMPLETE indicates completion of all bytes of transfer. 679 + * so forcing msg_buf_remaining to 0 in DMA mode. 680 + */ 868 681 if (status & I2C_INT_PACKET_XFER_COMPLETE) { 682 + if (i2c_dev->is_curr_dma_xfer) 683 + i2c_dev->msg_buf_remaining = 0; 869 684 BUG_ON(i2c_dev->msg_buf_remaining); 870 685 complete(&i2c_dev->msg_complete); 871 686 } ··· 894 671 tegra_i2c_mask_irq(i2c_dev, I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST | 895 672 I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | 896 673 I2C_INT_RX_FIFO_DATA_REQ); 674 + if (i2c_dev->hw->supports_bus_clear) 675 + tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); 897 676 i2c_writel(i2c_dev, status, I2C_INT_STATUS); 898 677 if (i2c_dev->is_dvc) 899 678 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); 679 + 680 + if (i2c_dev->is_curr_dma_xfer) { 681 + if (i2c_dev->msg_read) 682 + dmaengine_terminate_async(i2c_dev->rx_dma_chan); 683 + else 684 + dmaengine_terminate_async(i2c_dev->tx_dma_chan); 685 + 686 + complete(&i2c_dev->dma_complete); 687 + } 900 688 901 689 complete(&i2c_dev->msg_complete); 902 690 done: 903 691 spin_unlock(&i2c_dev->xfer_lock); 904 692 return IRQ_HANDLED; 693 + } 694 + 695 + static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev, 696 + size_t len) 697 + { 698 + u32 val, reg; 699 + u8 dma_burst; 700 + struct dma_slave_config slv_config = {0}; 701 + struct dma_chan *chan; 702 + int ret; 703 + unsigned long reg_offset; 704 + 705 + if (i2c_dev->hw->has_mst_fifo) 706 + reg = I2C_MST_FIFO_CONTROL; 707 + else 708 + reg = I2C_FIFO_CONTROL; 709 + 710 + if (i2c_dev->is_curr_dma_xfer) { 711 + if (len & 0xF) 712 + dma_burst = 1; 713 + else if (len & 0x10) 714 + dma_burst = 4; 715 + else 716 + dma_burst = 8; 717 + 718 + if (i2c_dev->msg_read) { 719 + chan = i2c_dev->rx_dma_chan; 720 + reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_RX_FIFO); 721 + slv_config.src_addr = i2c_dev->base_phys + reg_offset; 722 + slv_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 723 + slv_config.src_maxburst = dma_burst; 724 + 725 + if (i2c_dev->hw->has_mst_fifo) 726 + val = I2C_MST_FIFO_CONTROL_RX_TRIG(dma_burst); 727 + else 728 + val = I2C_FIFO_CONTROL_RX_TRIG(dma_burst); 729 + } else { 730 + chan = i2c_dev->tx_dma_chan; 731 + reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_TX_FIFO); 732 + slv_config.dst_addr = i2c_dev->base_phys + reg_offset; 733 + slv_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 734 + slv_config.dst_maxburst = dma_burst; 735 + 736 + if (i2c_dev->hw->has_mst_fifo) 737 + val = I2C_MST_FIFO_CONTROL_TX_TRIG(dma_burst); 738 + else 739 + val = I2C_FIFO_CONTROL_TX_TRIG(dma_burst); 740 + } 741 + 742 + slv_config.device_fc = true; 743 + ret = dmaengine_slave_config(chan, &slv_config); 744 + if (ret < 0) { 745 + dev_err(i2c_dev->dev, "DMA slave config failed: %d\n", 746 + ret); 747 + dev_err(i2c_dev->dev, "falling back to PIO\n"); 748 + tegra_i2c_release_dma(i2c_dev); 749 + i2c_dev->is_curr_dma_xfer = false; 750 + } else { 751 + goto out; 752 + } 753 + } 754 + 755 + if (i2c_dev->hw->has_mst_fifo) 756 + val = I2C_MST_FIFO_CONTROL_TX_TRIG(8) | 757 + I2C_MST_FIFO_CONTROL_RX_TRIG(1); 758 + else 759 + val = I2C_FIFO_CONTROL_TX_TRIG(8) | 760 + I2C_FIFO_CONTROL_RX_TRIG(1); 761 + out: 762 + i2c_writel(i2c_dev, val, reg); 763 + } 764 + 765 + static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) 766 + { 767 + struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); 768 + int err; 769 + unsigned long time_left; 770 + u32 reg; 771 + 772 + reinit_completion(&i2c_dev->msg_complete); 773 + reg = (I2C_BC_SCLK_THRESHOLD << I2C_BC_SCLK_THRESHOLD_SHIFT) | 774 + I2C_BC_STOP_COND | I2C_BC_TERMINATE; 775 + i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); 776 + if (i2c_dev->hw->has_config_load_reg) { 777 + err = tegra_i2c_wait_for_config_load(i2c_dev); 778 + if (err) 779 + return err; 780 + } 781 + 782 + reg |= I2C_BC_ENABLE; 783 + i2c_writel(i2c_dev, reg, I2C_BUS_CLEAR_CNFG); 784 + tegra_i2c_unmask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE); 785 + 786 + time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, 787 + msecs_to_jiffies(50)); 788 + if (time_left == 0) { 789 + dev_err(i2c_dev->dev, "timed out for bus clear\n"); 790 + return -ETIMEDOUT; 791 + } 792 + 793 + reg = i2c_readl(i2c_dev, I2C_BUS_CLEAR_STATUS); 794 + if (!(reg & I2C_BC_STATUS)) { 795 + dev_err(i2c_dev->dev, 796 + "un-recovered arbitration lost\n"); 797 + return -EIO; 798 + } 799 + 800 + return -EAGAIN; 905 801 } 906 802 907 803 static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, ··· 1030 688 u32 int_mask; 1031 689 unsigned long time_left; 1032 690 unsigned long flags; 691 + size_t xfer_size; 692 + u32 *buffer = NULL; 693 + int err = 0; 694 + bool dma; 695 + u16 xfer_time = 100; 1033 696 1034 697 tegra_i2c_flush_fifos(i2c_dev); 1035 698 ··· 1044 697 i2c_dev->msg_read = (msg->flags & I2C_M_RD); 1045 698 reinit_completion(&i2c_dev->msg_complete); 1046 699 700 + if (i2c_dev->msg_read) 701 + xfer_size = msg->len; 702 + else 703 + xfer_size = msg->len + I2C_PACKET_HEADER_SIZE; 704 + 705 + xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD); 706 + i2c_dev->is_curr_dma_xfer = (xfer_size > I2C_PIO_MODE_MAX_LEN) && 707 + i2c_dev->dma_buf; 708 + tegra_i2c_config_fifo_trig(i2c_dev, xfer_size); 709 + dma = i2c_dev->is_curr_dma_xfer; 710 + /* 711 + * Transfer time in mSec = Total bits / transfer rate 712 + * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits 713 + */ 714 + xfer_time += DIV_ROUND_CLOSEST(((xfer_size * 9) + 2) * MSEC_PER_SEC, 715 + i2c_dev->bus_clk_rate); 1047 716 spin_lock_irqsave(&i2c_dev->xfer_lock, flags); 1048 717 1049 718 int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; 1050 719 tegra_i2c_unmask_irq(i2c_dev, int_mask); 720 + if (dma) { 721 + if (i2c_dev->msg_read) { 722 + dma_sync_single_for_device(i2c_dev->dev, 723 + i2c_dev->dma_phys, 724 + xfer_size, 725 + DMA_FROM_DEVICE); 726 + err = tegra_i2c_dma_submit(i2c_dev, xfer_size); 727 + if (err < 0) { 728 + dev_err(i2c_dev->dev, 729 + "starting RX DMA failed, err %d\n", 730 + err); 731 + goto unlock; 732 + } 733 + 734 + } else { 735 + dma_sync_single_for_cpu(i2c_dev->dev, 736 + i2c_dev->dma_phys, 737 + xfer_size, 738 + DMA_TO_DEVICE); 739 + buffer = i2c_dev->dma_buf; 740 + } 741 + } 1051 742 1052 743 packet_header = (0 << PACKET_HEADER0_HEADER_SIZE_SHIFT) | 1053 744 PACKET_HEADER0_PROTOCOL_I2C | 1054 745 (i2c_dev->cont_id << PACKET_HEADER0_CONT_ID_SHIFT) | 1055 746 (1 << PACKET_HEADER0_PACKET_ID_SHIFT); 1056 - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 747 + if (dma && !i2c_dev->msg_read) 748 + *buffer++ = packet_header; 749 + else 750 + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 1057 751 1058 752 packet_header = msg->len - 1; 1059 - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 753 + if (dma && !i2c_dev->msg_read) 754 + *buffer++ = packet_header; 755 + else 756 + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 1060 757 1061 758 packet_header = I2C_HEADER_IE_ENABLE; 1062 759 if (end_state == MSG_END_CONTINUE) ··· 1117 726 packet_header |= I2C_HEADER_CONT_ON_NAK; 1118 727 if (msg->flags & I2C_M_RD) 1119 728 packet_header |= I2C_HEADER_READ; 1120 - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 729 + if (dma && !i2c_dev->msg_read) 730 + *buffer++ = packet_header; 731 + else 732 + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 1121 733 1122 - if (!(msg->flags & I2C_M_RD)) 1123 - tegra_i2c_fill_tx_fifo(i2c_dev); 734 + if (!i2c_dev->msg_read) { 735 + if (dma) { 736 + memcpy(buffer, msg->buf, msg->len); 737 + dma_sync_single_for_device(i2c_dev->dev, 738 + i2c_dev->dma_phys, 739 + xfer_size, 740 + DMA_TO_DEVICE); 741 + err = tegra_i2c_dma_submit(i2c_dev, xfer_size); 742 + if (err < 0) { 743 + dev_err(i2c_dev->dev, 744 + "starting TX DMA failed, err %d\n", 745 + err); 746 + goto unlock; 747 + } 748 + } else { 749 + tegra_i2c_fill_tx_fifo(i2c_dev); 750 + } 751 + } 1124 752 1125 753 if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) 1126 754 int_mask |= I2C_INT_PACKET_XFER_COMPLETE; 1127 - if (msg->flags & I2C_M_RD) 1128 - int_mask |= I2C_INT_RX_FIFO_DATA_REQ; 1129 - else if (i2c_dev->msg_buf_remaining) 1130 - int_mask |= I2C_INT_TX_FIFO_DATA_REQ; 755 + if (!dma) { 756 + if (msg->flags & I2C_M_RD) 757 + int_mask |= I2C_INT_RX_FIFO_DATA_REQ; 758 + else if (i2c_dev->msg_buf_remaining) 759 + int_mask |= I2C_INT_TX_FIFO_DATA_REQ; 760 + } 1131 761 1132 762 tegra_i2c_unmask_irq(i2c_dev, int_mask); 1133 - spin_unlock_irqrestore(&i2c_dev->xfer_lock, flags); 1134 763 dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", 1135 764 i2c_readl(i2c_dev, I2C_INT_MASK)); 1136 765 766 + unlock: 767 + spin_unlock_irqrestore(&i2c_dev->xfer_lock, flags); 768 + 769 + if (dma) { 770 + if (err) 771 + return err; 772 + 773 + time_left = wait_for_completion_timeout( 774 + &i2c_dev->dma_complete, 775 + msecs_to_jiffies(xfer_time)); 776 + if (time_left == 0) { 777 + dev_err(i2c_dev->dev, "DMA transfer timeout\n"); 778 + dmaengine_terminate_sync(i2c_dev->msg_read ? 779 + i2c_dev->rx_dma_chan : 780 + i2c_dev->tx_dma_chan); 781 + tegra_i2c_init(i2c_dev, true); 782 + return -ETIMEDOUT; 783 + } 784 + 785 + if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) { 786 + dma_sync_single_for_cpu(i2c_dev->dev, 787 + i2c_dev->dma_phys, 788 + xfer_size, 789 + DMA_FROM_DEVICE); 790 + memcpy(i2c_dev->msg_buf, i2c_dev->dma_buf, 791 + msg->len); 792 + } 793 + 794 + if (i2c_dev->msg_err != I2C_ERR_NONE) 795 + dmaengine_synchronize(i2c_dev->msg_read ? 796 + i2c_dev->rx_dma_chan : 797 + i2c_dev->tx_dma_chan); 798 + } 799 + 1137 800 time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, 1138 - TEGRA_I2C_TIMEOUT); 801 + msecs_to_jiffies(xfer_time)); 1139 802 tegra_i2c_mask_irq(i2c_dev, int_mask); 1140 803 1141 804 if (time_left == 0) { 1142 805 dev_err(i2c_dev->dev, "i2c transfer timed out\n"); 1143 806 1144 - tegra_i2c_init(i2c_dev); 807 + tegra_i2c_init(i2c_dev, true); 1145 808 return -ETIMEDOUT; 1146 809 } 1147 810 ··· 1203 758 time_left, completion_done(&i2c_dev->msg_complete), 1204 759 i2c_dev->msg_err); 1205 760 761 + i2c_dev->is_curr_dma_xfer = false; 1206 762 if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) 1207 763 return 0; 1208 764 1209 - tegra_i2c_init(i2c_dev); 765 + tegra_i2c_init(i2c_dev, true); 766 + /* start recovery upon arbitration loss in single master mode */ 767 + if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) { 768 + if (!i2c_dev->is_multimaster_mode) 769 + return i2c_recover_bus(&i2c_dev->adapter); 770 + return -EAGAIN; 771 + } 772 + 1210 773 if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { 1211 774 if (msg->flags & I2C_M_IGNORE_NAK) 1212 775 return 0; ··· 1289 836 /* payload size is only 12 bit */ 1290 837 static const struct i2c_adapter_quirks tegra_i2c_quirks = { 1291 838 .flags = I2C_AQ_NO_ZERO_LEN, 1292 - .max_read_len = 4096, 1293 - .max_write_len = 4096, 839 + .max_read_len = SZ_4K, 840 + .max_write_len = SZ_4K - I2C_PACKET_HEADER_SIZE, 1294 841 }; 1295 842 1296 843 static const struct i2c_adapter_quirks tegra194_i2c_quirks = { 1297 844 .flags = I2C_AQ_NO_ZERO_LEN, 845 + .max_write_len = SZ_64K - I2C_PACKET_HEADER_SIZE, 846 + }; 847 + 848 + static struct i2c_bus_recovery_info tegra_i2c_recovery_info = { 849 + .recover_bus = tegra_i2c_issue_bus_clear, 1298 850 }; 1299 851 1300 852 static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { ··· 1307 849 .has_per_pkt_xfer_complete_irq = false, 1308 850 .has_single_clk_source = false, 1309 851 .clk_divisor_hs_mode = 3, 1310 - .clk_divisor_std_fast_mode = 0, 852 + .clk_divisor_std_mode = 0, 853 + .clk_divisor_fast_mode = 0, 1311 854 .clk_divisor_fast_plus_mode = 0, 1312 855 .has_config_load_reg = false, 1313 856 .has_multi_master_mode = false, 1314 857 .has_slcg_override_reg = false, 1315 858 .has_mst_fifo = false, 1316 859 .quirks = &tegra_i2c_quirks, 860 + .supports_bus_clear = false, 861 + .has_apb_dma = true, 862 + .tlow_std_mode = 0x4, 863 + .thigh_std_mode = 0x2, 864 + .tlow_fast_fastplus_mode = 0x4, 865 + .thigh_fast_fastplus_mode = 0x2, 866 + .setup_hold_time_std_mode = 0x0, 867 + .setup_hold_time_fast_fast_plus_mode = 0x0, 868 + .setup_hold_time_hs_mode = 0x0, 869 + .has_interface_timing_reg = false, 1317 870 }; 1318 871 1319 872 static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { ··· 1332 863 .has_per_pkt_xfer_complete_irq = false, 1333 864 .has_single_clk_source = false, 1334 865 .clk_divisor_hs_mode = 3, 1335 - .clk_divisor_std_fast_mode = 0, 866 + .clk_divisor_std_mode = 0, 867 + .clk_divisor_fast_mode = 0, 1336 868 .clk_divisor_fast_plus_mode = 0, 1337 869 .has_config_load_reg = false, 1338 870 .has_multi_master_mode = false, 1339 871 .has_slcg_override_reg = false, 1340 872 .has_mst_fifo = false, 1341 873 .quirks = &tegra_i2c_quirks, 874 + .supports_bus_clear = false, 875 + .has_apb_dma = true, 876 + .tlow_std_mode = 0x4, 877 + .thigh_std_mode = 0x2, 878 + .tlow_fast_fastplus_mode = 0x4, 879 + .thigh_fast_fastplus_mode = 0x2, 880 + .setup_hold_time_std_mode = 0x0, 881 + .setup_hold_time_fast_fast_plus_mode = 0x0, 882 + .setup_hold_time_hs_mode = 0x0, 883 + .has_interface_timing_reg = false, 1342 884 }; 1343 885 1344 886 static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { ··· 1357 877 .has_per_pkt_xfer_complete_irq = true, 1358 878 .has_single_clk_source = true, 1359 879 .clk_divisor_hs_mode = 1, 1360 - .clk_divisor_std_fast_mode = 0x19, 880 + .clk_divisor_std_mode = 0x19, 881 + .clk_divisor_fast_mode = 0x19, 1361 882 .clk_divisor_fast_plus_mode = 0x10, 1362 883 .has_config_load_reg = false, 1363 884 .has_multi_master_mode = false, 1364 885 .has_slcg_override_reg = false, 1365 886 .has_mst_fifo = false, 1366 887 .quirks = &tegra_i2c_quirks, 888 + .supports_bus_clear = true, 889 + .has_apb_dma = true, 890 + .tlow_std_mode = 0x4, 891 + .thigh_std_mode = 0x2, 892 + .tlow_fast_fastplus_mode = 0x4, 893 + .thigh_fast_fastplus_mode = 0x2, 894 + .setup_hold_time_std_mode = 0x0, 895 + .setup_hold_time_fast_fast_plus_mode = 0x0, 896 + .setup_hold_time_hs_mode = 0x0, 897 + .has_interface_timing_reg = false, 1367 898 }; 1368 899 1369 900 static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { ··· 1382 891 .has_per_pkt_xfer_complete_irq = true, 1383 892 .has_single_clk_source = true, 1384 893 .clk_divisor_hs_mode = 1, 1385 - .clk_divisor_std_fast_mode = 0x19, 894 + .clk_divisor_std_mode = 0x19, 895 + .clk_divisor_fast_mode = 0x19, 1386 896 .clk_divisor_fast_plus_mode = 0x10, 1387 897 .has_config_load_reg = true, 1388 898 .has_multi_master_mode = false, 1389 899 .has_slcg_override_reg = true, 1390 900 .has_mst_fifo = false, 1391 901 .quirks = &tegra_i2c_quirks, 902 + .supports_bus_clear = true, 903 + .has_apb_dma = true, 904 + .tlow_std_mode = 0x4, 905 + .thigh_std_mode = 0x2, 906 + .tlow_fast_fastplus_mode = 0x4, 907 + .thigh_fast_fastplus_mode = 0x2, 908 + .setup_hold_time_std_mode = 0x0, 909 + .setup_hold_time_fast_fast_plus_mode = 0x0, 910 + .setup_hold_time_hs_mode = 0x0, 911 + .has_interface_timing_reg = true, 1392 912 }; 1393 913 1394 914 static const struct tegra_i2c_hw_feature tegra210_i2c_hw = { ··· 1407 905 .has_per_pkt_xfer_complete_irq = true, 1408 906 .has_single_clk_source = true, 1409 907 .clk_divisor_hs_mode = 1, 1410 - .clk_divisor_std_fast_mode = 0x19, 908 + .clk_divisor_std_mode = 0x19, 909 + .clk_divisor_fast_mode = 0x19, 1411 910 .clk_divisor_fast_plus_mode = 0x10, 1412 911 .has_config_load_reg = true, 1413 - .has_multi_master_mode = true, 912 + .has_multi_master_mode = false, 1414 913 .has_slcg_override_reg = true, 1415 914 .has_mst_fifo = false, 1416 915 .quirks = &tegra_i2c_quirks, 916 + .supports_bus_clear = true, 917 + .has_apb_dma = true, 918 + .tlow_std_mode = 0x4, 919 + .thigh_std_mode = 0x2, 920 + .tlow_fast_fastplus_mode = 0x4, 921 + .thigh_fast_fastplus_mode = 0x2, 922 + .setup_hold_time_std_mode = 0, 923 + .setup_hold_time_fast_fast_plus_mode = 0, 924 + .setup_hold_time_hs_mode = 0, 925 + .has_interface_timing_reg = true, 926 + }; 927 + 928 + static const struct tegra_i2c_hw_feature tegra186_i2c_hw = { 929 + .has_continue_xfer_support = true, 930 + .has_per_pkt_xfer_complete_irq = true, 931 + .has_single_clk_source = true, 932 + .clk_divisor_hs_mode = 1, 933 + .clk_divisor_std_mode = 0x16, 934 + .clk_divisor_fast_mode = 0x19, 935 + .clk_divisor_fast_plus_mode = 0x10, 936 + .has_config_load_reg = true, 937 + .has_multi_master_mode = false, 938 + .has_slcg_override_reg = true, 939 + .has_mst_fifo = false, 940 + .quirks = &tegra_i2c_quirks, 941 + .supports_bus_clear = true, 942 + .has_apb_dma = false, 943 + .tlow_std_mode = 0x4, 944 + .thigh_std_mode = 0x3, 945 + .tlow_fast_fastplus_mode = 0x4, 946 + .thigh_fast_fastplus_mode = 0x2, 947 + .setup_hold_time_std_mode = 0, 948 + .setup_hold_time_fast_fast_plus_mode = 0, 949 + .setup_hold_time_hs_mode = 0, 950 + .has_interface_timing_reg = true, 1417 951 }; 1418 952 1419 953 static const struct tegra_i2c_hw_feature tegra194_i2c_hw = { ··· 1457 919 .has_per_pkt_xfer_complete_irq = true, 1458 920 .has_single_clk_source = true, 1459 921 .clk_divisor_hs_mode = 1, 1460 - .clk_divisor_std_fast_mode = 0x19, 1461 - .clk_divisor_fast_plus_mode = 0x10, 922 + .clk_divisor_std_mode = 0x4f, 923 + .clk_divisor_fast_mode = 0x3c, 924 + .clk_divisor_fast_plus_mode = 0x16, 1462 925 .has_config_load_reg = true, 1463 926 .has_multi_master_mode = true, 1464 927 .has_slcg_override_reg = true, 1465 928 .has_mst_fifo = true, 1466 929 .quirks = &tegra194_i2c_quirks, 930 + .supports_bus_clear = true, 931 + .has_apb_dma = false, 932 + .tlow_std_mode = 0x8, 933 + .thigh_std_mode = 0x7, 934 + .tlow_fast_fastplus_mode = 0x2, 935 + .thigh_fast_fastplus_mode = 0x2, 936 + .setup_hold_time_std_mode = 0x08080808, 937 + .setup_hold_time_fast_fast_plus_mode = 0x02020202, 938 + .setup_hold_time_hs_mode = 0x090909, 939 + .has_interface_timing_reg = true, 1467 940 }; 1468 941 1469 942 /* Match table for of_platform binding */ 1470 943 static const struct of_device_id tegra_i2c_of_match[] = { 1471 944 { .compatible = "nvidia,tegra194-i2c", .data = &tegra194_i2c_hw, }, 945 + { .compatible = "nvidia,tegra186-i2c", .data = &tegra186_i2c_hw, }, 1472 946 { .compatible = "nvidia,tegra210-i2c", .data = &tegra210_i2c_hw, }, 1473 947 { .compatible = "nvidia,tegra124-i2c", .data = &tegra124_i2c_hw, }, 1474 948 { .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, }, ··· 1498 948 struct clk *div_clk; 1499 949 struct clk *fast_clk; 1500 950 void __iomem *base; 951 + phys_addr_t base_phys; 1501 952 int irq; 1502 953 int ret = 0; 1503 - int clk_multiplier = I2C_CLK_MULTIPLIER_STD_FAST_MODE; 1504 954 1505 955 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 956 + base_phys = res->start; 1506 957 base = devm_ioremap_resource(&pdev->dev, res); 1507 958 if (IS_ERR(base)) 1508 959 return PTR_ERR(base); ··· 1526 975 return -ENOMEM; 1527 976 1528 977 i2c_dev->base = base; 978 + i2c_dev->base_phys = base_phys; 1529 979 i2c_dev->div_clk = div_clk; 1530 980 i2c_dev->adapter.algo = &tegra_i2c_algo; 981 + i2c_dev->adapter.retries = 1; 982 + i2c_dev->adapter.timeout = 6 * HZ; 1531 983 i2c_dev->irq = irq; 1532 984 i2c_dev->cont_id = pdev->id; 1533 985 i2c_dev->dev = &pdev->dev; ··· 1547 993 i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, 1548 994 "nvidia,tegra20-i2c-dvc"); 1549 995 i2c_dev->adapter.quirks = i2c_dev->hw->quirks; 996 + i2c_dev->dma_buf_size = i2c_dev->adapter.quirks->max_write_len + 997 + I2C_PACKET_HEADER_SIZE; 1550 998 init_completion(&i2c_dev->msg_complete); 999 + init_completion(&i2c_dev->dma_complete); 1551 1000 spin_lock_init(&i2c_dev->xfer_lock); 1552 1001 1553 1002 if (!i2c_dev->hw->has_single_clk_source) { ··· 1572 1015 } 1573 1016 } 1574 1017 1575 - i2c_dev->clk_divisor_non_hs_mode = 1576 - i2c_dev->hw->clk_divisor_std_fast_mode; 1577 - if (i2c_dev->hw->clk_divisor_fast_plus_mode && 1578 - (i2c_dev->bus_clk_rate == 1000000)) 1018 + if (i2c_dev->bus_clk_rate > I2C_FAST_MODE && 1019 + i2c_dev->bus_clk_rate <= I2C_FAST_PLUS_MODE) 1579 1020 i2c_dev->clk_divisor_non_hs_mode = 1580 - i2c_dev->hw->clk_divisor_fast_plus_mode; 1581 - 1582 - clk_multiplier *= (i2c_dev->clk_divisor_non_hs_mode + 1); 1583 - ret = clk_set_rate(i2c_dev->div_clk, 1584 - i2c_dev->bus_clk_rate * clk_multiplier); 1585 - if (ret) { 1586 - dev_err(i2c_dev->dev, "Clock rate change failed %d\n", ret); 1587 - goto unprepare_fast_clk; 1588 - } 1021 + i2c_dev->hw->clk_divisor_fast_plus_mode; 1022 + else if (i2c_dev->bus_clk_rate > I2C_STANDARD_MODE && 1023 + i2c_dev->bus_clk_rate <= I2C_FAST_MODE) 1024 + i2c_dev->clk_divisor_non_hs_mode = 1025 + i2c_dev->hw->clk_divisor_fast_mode; 1026 + else 1027 + i2c_dev->clk_divisor_non_hs_mode = 1028 + i2c_dev->hw->clk_divisor_std_mode; 1589 1029 1590 1030 ret = clk_prepare(i2c_dev->div_clk); 1591 1031 if (ret < 0) { ··· 1608 1054 } 1609 1055 } 1610 1056 1611 - ret = tegra_i2c_init(i2c_dev); 1057 + if (i2c_dev->hw->supports_bus_clear) 1058 + i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info; 1059 + 1060 + ret = tegra_i2c_init_dma(i2c_dev); 1061 + if (ret < 0) 1062 + goto disable_div_clk; 1063 + 1064 + ret = tegra_i2c_init(i2c_dev, false); 1612 1065 if (ret) { 1613 1066 dev_err(&pdev->dev, "Failed to initialize i2c controller\n"); 1614 - goto disable_div_clk; 1067 + goto release_dma; 1615 1068 } 1616 1069 1617 1070 ret = devm_request_irq(&pdev->dev, i2c_dev->irq, 1618 1071 tegra_i2c_isr, 0, dev_name(&pdev->dev), i2c_dev); 1619 1072 if (ret) { 1620 1073 dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); 1621 - goto disable_div_clk; 1074 + goto release_dma; 1622 1075 } 1623 1076 1624 1077 i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); ··· 1639 1078 1640 1079 ret = i2c_add_numbered_adapter(&i2c_dev->adapter); 1641 1080 if (ret) 1642 - goto disable_div_clk; 1081 + goto release_dma; 1643 1082 1644 1083 return 0; 1084 + 1085 + release_dma: 1086 + tegra_i2c_release_dma(i2c_dev); 1645 1087 1646 1088 disable_div_clk: 1647 1089 if (i2c_dev->is_multimaster_mode) ··· 1682 1118 if (!i2c_dev->hw->has_single_clk_source) 1683 1119 clk_unprepare(i2c_dev->fast_clk); 1684 1120 1121 + tegra_i2c_release_dma(i2c_dev); 1685 1122 return 0; 1686 1123 } 1687 1124 ··· 1706 1141 }, 1707 1142 }; 1708 1143 1709 - static int __init tegra_i2c_init_driver(void) 1710 - { 1711 - return platform_driver_register(&tegra_i2c_driver); 1712 - } 1713 - 1714 - static void __exit tegra_i2c_exit_driver(void) 1715 - { 1716 - platform_driver_unregister(&tegra_i2c_driver); 1717 - } 1718 - 1719 - subsys_initcall(tegra_i2c_init_driver); 1720 - module_exit(tegra_i2c_exit_driver); 1144 + module_platform_driver(tegra_i2c_driver); 1721 1145 1722 1146 MODULE_DESCRIPTION("nVidia Tegra2 I2C Bus Controller driver"); 1723 1147 MODULE_AUTHOR("Colin Cross");
+2 -6
drivers/i2c/busses/i2c-zx2967.c
··· 66 66 int msg_rd; 67 67 u8 *cur_trans; 68 68 u8 access_cnt; 69 - bool is_suspended; 70 69 int error; 71 70 }; 72 71 ··· 312 313 int ret; 313 314 int i; 314 315 315 - if (i2c->is_suspended) 316 - return -EBUSY; 317 - 318 316 zx2967_set_addr(i2c, msgs->addr); 319 317 320 318 for (i = 0; i < num; i++) { ··· 466 470 { 467 471 struct zx2967_i2c *i2c = dev_get_drvdata(dev); 468 472 469 - i2c->is_suspended = true; 473 + i2c_mark_adapter_suspended(&i2c->adap); 470 474 clk_disable_unprepare(i2c->clk); 471 475 472 476 return 0; ··· 476 480 { 477 481 struct zx2967_i2c *i2c = dev_get_drvdata(dev); 478 482 479 - i2c->is_suspended = false; 480 483 clk_prepare_enable(i2c->clk); 484 + i2c_mark_adapter_resumed(&i2c->adap); 481 485 482 486 return 0; 483 487 }
+8 -4
drivers/i2c/i2c-core-base.c
··· 430 430 dev_pm_clear_wake_irq(&client->dev); 431 431 device_init_wakeup(&client->dev, false); 432 432 433 - client->irq = 0; 433 + client->irq = client->init_irq; 434 434 435 435 return status; 436 436 } ··· 741 741 client->flags = info->flags; 742 742 client->addr = info->addr; 743 743 744 - client->irq = info->irq; 745 - if (!client->irq) 746 - client->irq = i2c_dev_irq_from_resources(info->resources, 744 + client->init_irq = info->irq; 745 + if (!client->init_irq) 746 + client->init_irq = i2c_dev_irq_from_resources(info->resources, 747 747 info->num_resources); 748 + client->irq = client->init_irq; 748 749 749 750 strlcpy(client->name, info->type, sizeof(client->name)); 750 751 ··· 1233 1232 if (!adap->lock_ops) 1234 1233 adap->lock_ops = &i2c_adapter_lock_ops; 1235 1234 1235 + adap->locked_flags = 0; 1236 1236 rt_mutex_init(&adap->bus_lock); 1237 1237 rt_mutex_init(&adap->mux_lock); 1238 1238 mutex_init(&adap->userspace_clients_lock); ··· 1867 1865 1868 1866 if (WARN_ON(!msgs || num < 1)) 1869 1867 return -EINVAL; 1868 + if (WARN_ON(test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags))) 1869 + return -ESHUTDOWN; 1870 1870 1871 1871 if (adap->quirks && i2c_check_for_quirks(adap, msgs, num)) 1872 1872 return -EOPNOTSUPP;
+13 -1
drivers/i2c/i2c-core-of.c
··· 121 121 return dev->of_node == data; 122 122 } 123 123 124 + static int of_dev_or_parent_node_match(struct device *dev, void *data) 125 + { 126 + if (dev->of_node == data) 127 + return 1; 128 + 129 + if (dev->parent) 130 + return dev->parent->of_node == data; 131 + 132 + return 0; 133 + } 134 + 124 135 /* must call put_device() when done with returned i2c_client device */ 125 136 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) 126 137 { ··· 156 145 struct device *dev; 157 146 struct i2c_adapter *adapter; 158 147 159 - dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match); 148 + dev = bus_find_device(&i2c_bus_type, NULL, node, 149 + of_dev_or_parent_node_match); 160 150 if (!dev) 161 151 return NULL; 162 152
+1 -1
drivers/i2c/i2c-core-smbus.c
··· 585 585 trace: 586 586 /* If enabled, the reply tracepoint is conditional on read_write. */ 587 587 trace_smbus_reply(adapter, addr, flags, read_write, 588 - command, protocol, data); 588 + command, protocol, data, res); 589 589 trace_smbus_result(adapter, addr, flags, read_write, 590 590 command, protocol, res); 591 591
+1 -1
drivers/i2c/i2c-dev.c
··· 52 52 struct cdev cdev; 53 53 }; 54 54 55 - #define I2C_MINORS MINORMASK 55 + #define I2C_MINORS (MINORMASK + 1) 56 56 static LIST_HEAD(i2c_dev_list); 57 57 static DEFINE_SPINLOCK(i2c_dev_list_lock); 58 58
+80 -89
drivers/misc/eeprom/at24.c
··· 22 22 #include <linux/i2c.h> 23 23 #include <linux/nvmem-provider.h> 24 24 #include <linux/regmap.h> 25 - #include <linux/platform_data/at24.h> 26 25 #include <linux/pm_runtime.h> 27 26 #include <linux/gpio/consumer.h> 27 + 28 + /* Address pointer is 16 bit. */ 29 + #define AT24_FLAG_ADDR16 BIT(7) 30 + /* sysfs-entry will be read-only. */ 31 + #define AT24_FLAG_READONLY BIT(6) 32 + /* sysfs-entry will be world-readable. */ 33 + #define AT24_FLAG_IRUGO BIT(5) 34 + /* Take always 8 addresses (24c00). */ 35 + #define AT24_FLAG_TAKE8ADDR BIT(4) 36 + /* Factory-programmed serial number. */ 37 + #define AT24_FLAG_SERIAL BIT(3) 38 + /* Factory-programmed mac address. */ 39 + #define AT24_FLAG_MAC BIT(2) 40 + /* Does not auto-rollover reads to the next slave address. */ 41 + #define AT24_FLAG_NO_RDROL BIT(1) 28 42 29 43 /* 30 44 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. ··· 121 107 MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)"); 122 108 123 109 struct at24_chip_data { 124 - /* 125 - * these fields mirror their equivalents in 126 - * struct at24_platform_data 127 - */ 128 110 u32 byte_len; 129 111 u8 flags; 130 112 }; ··· 481 471 return 0; 482 472 } 483 473 484 - static void at24_properties_to_pdata(struct device *dev, 485 - struct at24_platform_data *chip) 486 - { 487 - int err; 488 - u32 val; 489 - 490 - if (device_property_present(dev, "read-only")) 491 - chip->flags |= AT24_FLAG_READONLY; 492 - if (device_property_present(dev, "no-read-rollover")) 493 - chip->flags |= AT24_FLAG_NO_RDROL; 494 - 495 - err = device_property_read_u32(dev, "address-width", &val); 496 - if (!err) { 497 - switch (val) { 498 - case 8: 499 - if (chip->flags & AT24_FLAG_ADDR16) 500 - dev_warn(dev, "Override address width to be 8, while default is 16\n"); 501 - chip->flags &= ~AT24_FLAG_ADDR16; 502 - break; 503 - case 16: 504 - chip->flags |= AT24_FLAG_ADDR16; 505 - break; 506 - default: 507 - dev_warn(dev, "Bad \"address-width\" property: %u\n", 508 - val); 509 - } 510 - } 511 - 512 - err = device_property_read_u32(dev, "size", &val); 513 - if (!err) 514 - chip->byte_len = val; 515 - 516 - err = device_property_read_u32(dev, "pagesize", &val); 517 - if (!err) { 518 - chip->page_size = val; 519 - } else { 520 - /* 521 - * This is slow, but we can't know all eeproms, so we better 522 - * play safe. Specifying custom eeprom-types via platform_data 523 - * is recommended anyhow. 524 - */ 525 - chip->page_size = 1; 526 - } 527 - } 528 - 529 - static int at24_get_pdata(struct device *dev, struct at24_platform_data *pdata) 474 + static const struct at24_chip_data *at24_get_chip_data(struct device *dev) 530 475 { 531 476 struct device_node *of_node = dev->of_node; 532 477 const struct at24_chip_data *cdata; 533 478 const struct i2c_device_id *id; 534 - struct at24_platform_data *pd; 535 - 536 - pd = dev_get_platdata(dev); 537 - if (pd) { 538 - memcpy(pdata, pd, sizeof(*pdata)); 539 - return 0; 540 - } 541 479 542 480 id = i2c_match_id(at24_ids, to_i2c_client(dev)); 543 481 ··· 502 544 cdata = acpi_device_get_match_data(dev); 503 545 504 546 if (!cdata) 505 - return -ENODEV; 547 + return ERR_PTR(-ENODEV); 506 548 507 - pdata->byte_len = cdata->byte_len; 508 - pdata->flags = cdata->flags; 509 - at24_properties_to_pdata(dev, pdata); 510 - 511 - return 0; 549 + return cdata; 512 550 } 513 551 514 552 static void at24_remove_dummy_clients(struct at24_data *at24) ··· 573 619 { 574 620 struct regmap_config regmap_config = { }; 575 621 struct nvmem_config nvmem_config = { }; 576 - struct at24_platform_data pdata = { }; 622 + u32 byte_len, page_size, flags, addrw; 623 + const struct at24_chip_data *cdata; 577 624 struct device *dev = &client->dev; 578 625 bool i2c_fn_i2c, i2c_fn_block; 579 626 unsigned int i, num_addresses; ··· 589 634 i2c_fn_block = i2c_check_functionality(client->adapter, 590 635 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK); 591 636 592 - err = at24_get_pdata(dev, &pdata); 637 + cdata = at24_get_chip_data(dev); 638 + if (IS_ERR(cdata)) 639 + return PTR_ERR(cdata); 640 + 641 + err = device_property_read_u32(dev, "pagesize", &page_size); 593 642 if (err) 594 - return err; 643 + /* 644 + * This is slow, but we can't know all eeproms, so we better 645 + * play safe. Specifying custom eeprom-types via platform_data 646 + * is recommended anyhow. 647 + */ 648 + page_size = 1; 649 + 650 + flags = cdata->flags; 651 + if (device_property_present(dev, "read-only")) 652 + flags |= AT24_FLAG_READONLY; 653 + if (device_property_present(dev, "no-read-rollover")) 654 + flags |= AT24_FLAG_NO_RDROL; 655 + 656 + err = device_property_read_u32(dev, "address-width", &addrw); 657 + if (!err) { 658 + switch (addrw) { 659 + case 8: 660 + if (flags & AT24_FLAG_ADDR16) 661 + dev_warn(dev, 662 + "Override address width to be 8, while default is 16\n"); 663 + flags &= ~AT24_FLAG_ADDR16; 664 + break; 665 + case 16: 666 + flags |= AT24_FLAG_ADDR16; 667 + break; 668 + default: 669 + dev_warn(dev, "Bad \"address-width\" property: %u\n", 670 + addrw); 671 + } 672 + } 673 + 674 + err = device_property_read_u32(dev, "size", &byte_len); 675 + if (err) 676 + byte_len = cdata->byte_len; 595 677 596 678 if (!i2c_fn_i2c && !i2c_fn_block) 597 - pdata.page_size = 1; 679 + page_size = 1; 598 680 599 - if (!pdata.page_size) { 681 + if (!page_size) { 600 682 dev_err(dev, "page_size must not be 0!\n"); 601 683 return -EINVAL; 602 684 } 603 685 604 - if (!is_power_of_2(pdata.page_size)) 686 + if (!is_power_of_2(page_size)) 605 687 dev_warn(dev, "page_size looks suspicious (no power of 2)!\n"); 606 688 607 - if (pdata.flags & AT24_FLAG_TAKE8ADDR) 608 - num_addresses = 8; 609 - else 610 - num_addresses = DIV_ROUND_UP(pdata.byte_len, 611 - (pdata.flags & AT24_FLAG_ADDR16) ? 65536 : 256); 689 + err = device_property_read_u32(dev, "num-addresses", &num_addresses); 690 + if (err) { 691 + if (flags & AT24_FLAG_TAKE8ADDR) 692 + num_addresses = 8; 693 + else 694 + num_addresses = DIV_ROUND_UP(byte_len, 695 + (flags & AT24_FLAG_ADDR16) ? 65536 : 256); 696 + } 612 697 613 - if ((pdata.flags & AT24_FLAG_SERIAL) && (pdata.flags & AT24_FLAG_MAC)) { 698 + if ((flags & AT24_FLAG_SERIAL) && (flags & AT24_FLAG_MAC)) { 614 699 dev_err(dev, 615 700 "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); 616 701 return -EINVAL; 617 702 } 618 703 619 704 regmap_config.val_bits = 8; 620 - regmap_config.reg_bits = (pdata.flags & AT24_FLAG_ADDR16) ? 16 : 8; 705 + regmap_config.reg_bits = (flags & AT24_FLAG_ADDR16) ? 16 : 8; 621 706 regmap_config.disable_locking = true; 622 707 623 708 regmap = devm_regmap_init_i2c(client, &regmap_config); ··· 670 675 return -ENOMEM; 671 676 672 677 mutex_init(&at24->lock); 673 - at24->byte_len = pdata.byte_len; 674 - at24->page_size = pdata.page_size; 675 - at24->flags = pdata.flags; 678 + at24->byte_len = byte_len; 679 + at24->page_size = page_size; 680 + at24->flags = flags; 676 681 at24->num_addresses = num_addresses; 677 - at24->offset_adj = at24_get_offset_adj(pdata.flags, pdata.byte_len); 682 + at24->offset_adj = at24_get_offset_adj(flags, byte_len); 678 683 at24->client[0].client = client; 679 684 at24->client[0].regmap = regmap; 680 685 ··· 682 687 if (IS_ERR(at24->wp_gpio)) 683 688 return PTR_ERR(at24->wp_gpio); 684 689 685 - writable = !(pdata.flags & AT24_FLAG_READONLY); 690 + writable = !(flags & AT24_FLAG_READONLY); 686 691 if (writable) { 687 692 at24->write_max = min_t(unsigned int, 688 - pdata.page_size, at24_io_limit); 693 + page_size, at24_io_limit); 689 694 if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX) 690 695 at24->write_max = I2C_SMBUS_BLOCK_MAX; 691 696 } ··· 728 733 nvmem_config.priv = at24; 729 734 nvmem_config.stride = 1; 730 735 nvmem_config.word_size = 1; 731 - nvmem_config.size = pdata.byte_len; 736 + nvmem_config.size = byte_len; 732 737 733 738 at24->nvmem = devm_nvmem_register(dev, &nvmem_config); 734 739 if (IS_ERR(at24->nvmem)) { ··· 737 742 } 738 743 739 744 dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", 740 - pdata.byte_len, client->name, 745 + byte_len, client->name, 741 746 writable ? "writable" : "read-only", at24->write_max); 742 - 743 - /* export data to kernel code */ 744 - if (pdata.setup) 745 - pdata.setup(at24->nvmem, pdata.context); 746 747 747 748 return 0; 748 749
-11
include/linux/acpi.h
··· 1061 1061 } 1062 1062 #endif 1063 1063 1064 - #if defined(CONFIG_ACPI) && IS_ENABLED(CONFIG_I2C) 1065 - bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 1066 - struct acpi_resource_i2c_serialbus **i2c); 1067 - #else 1068 - static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 1069 - struct acpi_resource_i2c_serialbus **i2c) 1070 - { 1071 - return false; 1072 - } 1073 - #endif 1074 - 1075 1064 /* Device properties */ 1076 1065 1077 1066 #ifdef CONFIG_ACPI
+10 -23
include/linux/i2c-algo-bit.h
··· 1 - /* ------------------------------------------------------------------------- */ 2 - /* i2c-algo-bit.h i2c driver algorithms for bit-shift adapters */ 3 - /* ------------------------------------------------------------------------- */ 4 - /* Copyright (C) 1995-99 Simon G. Vogl 5 - 6 - This program is free software; you can redistribute it and/or modify 7 - it under the terms of the GNU General Public License as published by 8 - the Free Software Foundation; either version 2 of the License, or 9 - (at your option) any later version. 10 - 11 - This program is distributed in the hope that it will be useful, 12 - but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - GNU General Public License for more details. 15 - 16 - You should have received a copy of the GNU General Public License 17 - along with this program; if not, write to the Free Software 18 - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 - MA 02110-1301 USA. */ 20 - /* ------------------------------------------------------------------------- */ 21 - 22 - /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even 23 - Frodo Looijaard <frodol@dds.nl> */ 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + /* 3 + * i2c-algo-bit.h: i2c driver algorithms for bit-shift adapters 4 + * 5 + * Copyright (C) 1995-99 Simon G. Vogl 6 + * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even 7 + * Frodo Looijaard <frodol@dds.nl> 8 + */ 24 9 25 10 #ifndef _LINUX_I2C_ALGO_BIT_H 26 11 #define _LINUX_I2C_ALGO_BIT_H 12 + 13 + #include <linux/i2c.h> 27 14 28 15 /* --- Defines for bit-adapters --------------------------------------- */ 29 16 /*
+45
include/linux/i2c.h
··· 333 333 char name[I2C_NAME_SIZE]; 334 334 struct i2c_adapter *adapter; /* the adapter we sit on */ 335 335 struct device dev; /* the device structure */ 336 + int init_irq; /* irq set at initialization */ 336 337 int irq; /* irq issued by device */ 337 338 struct list_head detected; 338 339 #if IS_ENABLED(CONFIG_I2C_SLAVE) ··· 681 680 int timeout; /* in jiffies */ 682 681 int retries; 683 682 struct device dev; /* the adapter device */ 683 + unsigned long locked_flags; /* owned by the I2C core */ 684 + #define I2C_ALF_IS_SUSPENDED 0 684 685 685 686 int nr; 686 687 char name[48]; ··· 763 760 i2c_unlock_bus(struct i2c_adapter *adapter, unsigned int flags) 764 761 { 765 762 adapter->lock_ops->unlock_bus(adapter, flags); 763 + } 764 + 765 + /** 766 + * i2c_mark_adapter_suspended - Report suspended state of the adapter to the core 767 + * @adap: Adapter to mark as suspended 768 + * 769 + * When using this helper to mark an adapter as suspended, the core will reject 770 + * further transfers to this adapter. The usage of this helper is optional but 771 + * recommended for devices having distinct handlers for system suspend and 772 + * runtime suspend. More complex devices are free to implement custom solutions 773 + * to reject transfers when suspended. 774 + */ 775 + static inline void i2c_mark_adapter_suspended(struct i2c_adapter *adap) 776 + { 777 + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); 778 + set_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags); 779 + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); 780 + } 781 + 782 + /** 783 + * i2c_mark_adapter_resumed - Report resumed state of the adapter to the core 784 + * @adap: Adapter to mark as resumed 785 + * 786 + * When using this helper to mark an adapter as resumed, the core will allow 787 + * further transfers to this adapter. See also further notes to 788 + * @i2c_mark_adapter_suspended(). 789 + */ 790 + static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap) 791 + { 792 + i2c_lock_bus(adap, I2C_LOCK_ROOT_ADAPTER); 793 + clear_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags); 794 + i2c_unlock_bus(adap, I2C_LOCK_ROOT_ADAPTER); 766 795 } 767 796 768 797 /*flags for the client struct: */ ··· 968 933 969 934 #endif /* CONFIG_OF */ 970 935 936 + struct acpi_resource; 937 + struct acpi_resource_i2c_serialbus; 938 + 971 939 #if IS_ENABLED(CONFIG_ACPI) 940 + bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 941 + struct acpi_resource_i2c_serialbus **i2c); 972 942 u32 i2c_acpi_find_bus_speed(struct device *dev); 973 943 struct i2c_client *i2c_acpi_new_device(struct device *dev, int index, 974 944 struct i2c_board_info *info); 975 945 #else 946 + static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 947 + struct acpi_resource_i2c_serialbus **i2c) 948 + { 949 + return false; 950 + } 976 951 static inline u32 i2c_acpi_find_bus_speed(struct device *dev) 977 952 { 978 953 return 0;
-60
include/linux/platform_data/at24.h
··· 1 - /* 2 - * at24.h - platform_data for the at24 (generic eeprom) driver 3 - * (C) Copyright 2008 by Pengutronix 4 - * (C) Copyright 2012 by Wolfram Sang 5 - * same license as the driver 6 - */ 7 - 8 - #ifndef _LINUX_AT24_H 9 - #define _LINUX_AT24_H 10 - 11 - #include <linux/types.h> 12 - #include <linux/nvmem-consumer.h> 13 - #include <linux/bitops.h> 14 - 15 - /** 16 - * struct at24_platform_data - data to set up at24 (generic eeprom) driver 17 - * @byte_len: size of eeprom in byte 18 - * @page_size: number of byte which can be written in one go 19 - * @flags: tunable options, check AT24_FLAG_* defines 20 - * @setup: an optional callback invoked after eeprom is probed; enables kernel 21 - code to access eeprom via nvmem, see example 22 - * @context: optional parameter passed to setup() 23 - * 24 - * If you set up a custom eeprom type, please double-check the parameters. 25 - * Especially page_size needs extra care, as you risk data loss if your value 26 - * is bigger than what the chip actually supports! 27 - * 28 - * An example in pseudo code for a setup() callback: 29 - * 30 - * void get_mac_addr(struct nvmem_device *nvmem, void *context) 31 - * { 32 - * u8 *mac_addr = ethernet_pdata->mac_addr; 33 - * off_t offset = context; 34 - * 35 - * // Read MAC addr from EEPROM 36 - * if (nvmem_device_read(nvmem, offset, ETH_ALEN, mac_addr) == ETH_ALEN) 37 - * pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr); 38 - * } 39 - * 40 - * This function pointer and context can now be set up in at24_platform_data. 41 - */ 42 - 43 - struct at24_platform_data { 44 - u32 byte_len; /* size (sum of all addr) */ 45 - u16 page_size; /* for writes */ 46 - u8 flags; 47 - #define AT24_FLAG_ADDR16 BIT(7) /* address pointer is 16 bit */ 48 - #define AT24_FLAG_READONLY BIT(6) /* sysfs-entry will be read-only */ 49 - #define AT24_FLAG_IRUGO BIT(5) /* sysfs-entry will be world-readable */ 50 - #define AT24_FLAG_TAKE8ADDR BIT(4) /* take always 8 addresses (24c00) */ 51 - #define AT24_FLAG_SERIAL BIT(3) /* factory-programmed serial number */ 52 - #define AT24_FLAG_MAC BIT(2) /* factory-programmed mac address */ 53 - #define AT24_FLAG_NO_RDROL BIT(1) /* does not auto-rollover reads to */ 54 - /* the next slave address */ 55 - 56 - void (*setup)(struct nvmem_device *nvmem, void *context); 57 - void *context; 58 - }; 59 - 60 - #endif /* _LINUX_AT24_H */
-27
include/linux/platform_data/i2c-cbus-gpio.h
··· 1 - /* 2 - * i2c-cbus-gpio.h - CBUS I2C platform_data definition 3 - * 4 - * Copyright (C) 2004-2009 Nokia Corporation 5 - * 6 - * Written by Felipe Balbi and Aaro Koskinen. 7 - * 8 - * This file is subject to the terms and conditions of the GNU General 9 - * Public License. See the file "COPYING" in the main directory of this 10 - * archive for more details. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - */ 17 - 18 - #ifndef __INCLUDE_LINUX_I2C_CBUS_GPIO_H 19 - #define __INCLUDE_LINUX_I2C_CBUS_GPIO_H 20 - 21 - struct i2c_cbus_platform_data { 22 - int dat_gpio; 23 - int clk_gpio; 24 - int sel_gpio; 25 - }; 26 - 27 - #endif /* __INCLUDE_LINUX_I2C_CBUS_GPIO_H */
+2 -4
include/linux/platform_data/i2c-ocores.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 1 2 /* 2 3 * i2c-ocores.h - definitions for the i2c-ocores interface 3 4 * 4 5 * Peter Korsgaard <peter@korsgaard.com> 5 - * 6 - * This file is licensed under the terms of the GNU General Public License 7 - * version 2. This program is licensed "as is" without any warranty of any 8 - * kind, whether express or implied. 9 6 */ 10 7 11 8 #ifndef _LINUX_I2C_OCORES_H ··· 12 15 u32 reg_shift; /* register offset shift value */ 13 16 u32 reg_io_width; /* register io read/write width */ 14 17 u32 clock_khz; /* input clock in kHz */ 18 + u32 bus_khz; /* bus clock in kHz */ 15 19 bool big_endian; /* registers are big endian */ 16 20 u8 num_devices; /* number of devices in the devices list */ 17 21 struct i2c_board_info const *devices; /* devices connected to the bus */
+3 -3
include/trace/events/smbus.h
··· 138 138 TP_PROTO(const struct i2c_adapter *adap, 139 139 u16 addr, unsigned short flags, 140 140 char read_write, u8 command, int protocol, 141 - const union i2c_smbus_data *data), 142 - TP_ARGS(adap, addr, flags, read_write, command, protocol, data), 143 - TP_CONDITION(read_write == I2C_SMBUS_READ), 141 + const union i2c_smbus_data *data, int res), 142 + TP_ARGS(adap, addr, flags, read_write, command, protocol, data, res), 143 + TP_CONDITION(res >= 0 && read_write == I2C_SMBUS_READ), 144 144 TP_STRUCT__entry( 145 145 __field(int, adapter_nr ) 146 146 __field(__u16, addr )