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

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

Pull i2c updates from Wolfram Sang:
"Features:

- new drivers: Renesas EMEV2, register based MUX, NXP LPC2xxx
- core: scans DT and assigns wakeup interrupts. no driver changes needed.
- core: some refcouting issues fixed and better API for that
- core: new helper function for best effort block read emulation
- slave framework: proper DT bindings and userspace instantiation
- some bigger work for xiic, pxa, omap drivers

.. and quite a number of smaller driver fixes, cleanups, improvements"

* 'i2c/for-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (65 commits)
i2c: mux: reg Change ioread endianness for readback
i2c: mux: reg: fix compilation warnings
i2c: mux: reg: simplify register size checking
i2c: muxes: fix leaked i2c adapter device node references
i2c: allow specifying separate wakeup interrupt in device tree
of/irq: export of_get_irq_byname()
i2c: xgene-slimpro: dma_mapping_error() doesn't return an error code
i2c: Replace I2C_CROS_EC_TUNNEL dependency
eeprom: at24: use i2c_smbus_read_i2c_block_data_or_emulated
i2c: core: Add support for best effort block read emulation
i2c: lpc2k: add driver
i2c: mux: Add register-based mux i2c-mux-reg
i2c: dt: describe generic bindings
i2c: slave: print warning if slave flag not set
i2c: support 10 bit and slave addresses in sysfs 'new_device'
i2c: take address space into account when checking for used addresses
i2c: apply DT flags when probing
i2c: make address check indpendent from client struct
i2c: rename address check functions
i2c: apply address offset for slaves, too
...

+2189 -524
+5 -1
Documentation/devicetree/bindings/i2c/i2c-cadence.txt
··· 2 2 3 3 Required properties: 4 4 - reg: Physical base address and size of the controller's register area. 5 - - compatible: Compatibility string. Must be 'cdns,i2c-r1p10'. 5 + - compatible: Should contain one of: 6 + * "cdns,i2c-r1p10" 7 + Note: Use this when cadence i2c controller version 1.0 is used. 8 + * "cdns,i2c-r1p14" 9 + Note: Use this when cadence i2c controller version 1.4 is used. 6 10 - clocks: Input clock specifier. Refer to common clock bindings. 7 11 - interrupts: Interrupt specifier. Refer to interrupt bindings. 8 12 - #address-cells: Should be 1.
+22
Documentation/devicetree/bindings/i2c/i2c-emev2.txt
··· 1 + Device tree configuration for Renesas EMEV2 IIC controller 2 + 3 + Required properties: 4 + - compatible : "renesas,iic-emev2" 5 + - reg : address start and address range size of device 6 + - interrupts : specifier for the IIC controller interrupt 7 + - clocks : phandle to the IP core SCLK 8 + - clock-names : must be "sclk" 9 + - #address-cells : should be <1> 10 + - #size-cells : should be <0> 11 + 12 + Example: 13 + 14 + iic0: i2c@e0070000 { 15 + #address-cells = <1>; 16 + #size-cells = <0>; 17 + compatible = "renesas,iic-emev2"; 18 + reg = <0xe0070000 0x28>; 19 + interrupts = <0 32 IRQ_TYPE_EDGE_RISING>; 20 + clocks = <&iic0_sclk>; 21 + clock-names = "sclk"; 22 + };
+33
Documentation/devicetree/bindings/i2c/i2c-lpc2k.txt
··· 1 + NXP I2C controller for LPC2xxx/178x/18xx/43xx 2 + 3 + Required properties: 4 + - compatible: must be "nxp,lpc1788-i2c" 5 + - reg: physical address and length of the device registers 6 + - interrupts: a single interrupt specifier 7 + - clocks: clock for the device 8 + - #address-cells: should be <1> 9 + - #size-cells: should be <0> 10 + 11 + Optional properties: 12 + - clock-frequency: the desired I2C bus clock frequency in Hz; in 13 + absence of this property the default value is used (100 kHz). 14 + 15 + Example: 16 + i2c0: i2c@400a1000 { 17 + compatible = "nxp,lpc1788-i2c"; 18 + reg = <0x400a1000 0x1000>; 19 + interrupts = <18>; 20 + clocks = <&ccu1 CLK_APB1_I2C0>; 21 + #address-cells = <1>; 22 + #size-cells = <0>; 23 + }; 24 + 25 + &i2c0 { 26 + clock-frequency = <400000>; 27 + 28 + lm75@48 { 29 + compatible = "nxp,lm75"; 30 + reg = <0x48>; 31 + }; 32 + }; 33 +
+74
Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt
··· 1 + Register-based I2C Bus Mux 2 + 3 + This binding describes an I2C bus multiplexer that uses a single register 4 + to route the I2C signals. 5 + 6 + Required properties: 7 + - compatible: i2c-mux-reg 8 + - i2c-parent: The phandle of the I2C bus that this multiplexer's master-side 9 + port is connected to. 10 + * Standard I2C mux properties. See mux.txt in this directory. 11 + * I2C child bus nodes. See mux.txt in this directory. 12 + 13 + Optional properties: 14 + - reg: this pair of <offset size> specifies the register to control the mux. 15 + The <offset size> depends on its parent node. It can be any memory-mapped 16 + address. The size must be either 1, 2, or 4 bytes. If reg is omitted, the 17 + resource of this device will be used. 18 + - little-endian: The existence indicates the register is in little endian. 19 + - big-endian: The existence indicates the register is in big endian. 20 + If both little-endian and big-endian are omitted, the endianness of the 21 + CPU will be used. 22 + - write-only: The existence indicates the register is write-only. 23 + - idle-state: value to set the muxer to when idle. When no value is 24 + given, it defaults to the last value used. 25 + 26 + Whenever an access is made to a device on a child bus, the value set 27 + in the revelant node's reg property will be output to the register. 28 + 29 + If an idle state is defined, using the idle-state (optional) property, 30 + whenever an access is not being made to a device on a child bus, the 31 + register will be set according to the idle value. 32 + 33 + If an idle state is not defined, the most recently used value will be 34 + left programmed into the register. 35 + 36 + Example of a mux on PCIe card, the host is a powerpc SoC (big endian): 37 + 38 + i2c-mux { 39 + /* the <offset size> depends on the address translation 40 + * of the parent device. If omitted, device resource 41 + * will be used instead. The size is to determine 42 + * whether iowrite32, iowrite16, or iowrite8 will be used. 43 + */ 44 + reg = <0x6028 0x4>; 45 + little-endian; /* little endian register on PCIe */ 46 + compatible = "i2c-mux-reg"; 47 + #address-cells = <1>; 48 + #size-cells = <0>; 49 + i2c-parent = <&i2c1>; 50 + i2c@0 { 51 + reg = <0>; 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + 55 + si5338: clock-generator@70 { 56 + compatible = "silabs,si5338"; 57 + reg = <0x70>; 58 + /* other stuff */ 59 + }; 60 + }; 61 + 62 + i2c@1 { 63 + /* data is written using iowrite32 */ 64 + reg = <1>; 65 + #address-cells = <1>; 66 + #size-cells = <0>; 67 + 68 + si5338: clock-generator@70 { 69 + compatible = "silabs,si5338"; 70 + reg = <0x70>; 71 + /* other stuff */ 72 + }; 73 + }; 74 + };
+45
Documentation/devicetree/bindings/i2c/i2c.txt
··· 1 + Generic device tree bindings for I2C busses 2 + =========================================== 3 + 4 + This document describes generic bindings which can be used to describe I2C 5 + busses in a device tree. 6 + 7 + Required properties 8 + ------------------- 9 + 10 + - #address-cells - should be <1>. Read more about addresses below. 11 + - #size-cells - should be <0>. 12 + - compatible - name of I2C bus controller following generic names 13 + recommended practice. 14 + 15 + For other required properties e.g. to describe register sets, 16 + clocks, etc. check the binding documentation of the specific driver. 17 + 18 + The cells properties above define that an address of children of an I2C bus 19 + are described by a single value. This is usually a 7 bit address. However, 20 + flags can be attached to the address. I2C_TEN_BIT_ADDRESS is used to mark a 10 21 + bit address. It is needed to avoid the ambiguity between e.g. a 7 bit address 22 + of 0x50 and a 10 bit address of 0x050 which, in theory, can be on the same bus. 23 + Another flag is I2C_OWN_SLAVE_ADDRESS to mark addresses on which we listen to 24 + be devices ourselves. 25 + 26 + Optional properties 27 + ------------------- 28 + 29 + These properties may not be supported by all drivers. However, if a driver 30 + wants to support one of the below features, it should adapt the bindings below. 31 + 32 + - clock-frequency - frequency of bus clock in Hz. 33 + - wakeup-source - device can be used as a wakeup source. 34 + 35 + - interrupts - interrupts used by the device. 36 + - interrupt-names - "irq" and "wakeup" names are recognized by I2C core, 37 + other names are left to individual drivers. 38 + 39 + Binding may contain optional "interrupts" property, describing interrupts 40 + used by the device. I2C core will assign "irq" interrupt (or the very first 41 + interrupt if not using interrupt names) as primary interrupt for the slave. 42 + 43 + Also, if device is marked as a wakeup source, I2C core will set up "wakeup" 44 + interrupt for the device. If "wakeup" interrupt name is not present in the 45 + binding, then primary interrupt will be used as wakeup interrupt.
Documentation/devicetree/bindings/i2c/ina209.txt Documentation/devicetree/bindings/hwmon/ina209.txt
Documentation/devicetree/bindings/i2c/ina2xx.txt Documentation/devicetree/bindings/hwmon/ina2xx.txt
Documentation/devicetree/bindings/i2c/max6697.txt Documentation/devicetree/bindings/hwmon/max6697.txt
Documentation/devicetree/bindings/i2c/ti,bq32k.txt Documentation/devicetree/bindings/rtc/ti,bq32k.txt
+2
Documentation/devicetree/bindings/i2c/trivial-devices.txt
··· 95 95 stm,m41t62 Serial real-time clock (RTC) with alarm 96 96 stm,m41t80 M41T80 - SERIAL ACCESS RTC WITH ALARMS 97 97 taos,tsl2550 Ambient Light Sensor with SMBUS/Two Wire Serial Interface 98 + ti,ads7828 8-Channels, 12-bit ADC 99 + ti,ads7830 8-Channels, 8-bit ADC 98 100 ti,tsc2003 I2C Touch-Screen Controller 99 101 ti,tmp102 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface 100 102 ti,tmp103 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface
+1
Documentation/i2c/busses/i2c-parport
··· 20 20 * (type=5) Analog Devices evaluation boards: ADM1025, ADM1030, ADM1031 21 21 * (type=6) Barco LPT->DVI (K5800236) adapter 22 22 * (type=7) One For All JP1 parallel port adapter 23 + * (type=8) VCT-jig 23 24 24 25 These devices use different pinout configurations, so you have to tell 25 26 the driver what you have, using the type module parameter. There is no
+6 -3
Documentation/i2c/slave-interface
··· 31 31 =========== 32 32 33 33 I2C slave backends behave like standard I2C clients. So, you can instantiate 34 - them as described in the document 'instantiating-devices'. A quick example for 35 - instantiating the slave-eeprom driver from userspace at address 0x64 on bus 1: 34 + them as described in the document 'instantiating-devices'. The only difference 35 + is that i2c slave backends have their own address space. So, you have to add 36 + 0x1000 to the address you would originally request. An example for 37 + instantiating the slave-eeprom driver from userspace at the 7 bit address 0x64 38 + on bus 1: 36 39 37 - # echo slave-24c02 0x64 > /sys/bus/i2c/devices/i2c-1/new_device 40 + # echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-1/new_device 38 41 39 42 Each backend should come with separate documentation to describe its specific 40 43 behaviour and setup.
+4
Documentation/i2c/ten-bit-addresses
··· 2 2 addresses, and an extended set of 10 bit addresses. The sets of addresses 3 3 do not intersect: the 7 bit address 0x10 is not the same as the 10 bit 4 4 address 0x10 (though a single device could respond to both of them). 5 + To avoid ambiguity, the user sees 10 bit addresses mapped to a different 6 + address space, namely 0xa000-0xa3ff. The leading 0xa (= 10) represents the 7 + 10 bit mode. This is used for creating device names in sysfs. It is also 8 + needed when instantiating 10 bit devices via the new_device file in sysfs. 5 9 6 10 I2C messages to and from 10-bit address devices have a different format. 7 11 See the I2C specification for the details.
+6
drivers/clk/shmobile/clk-emev2.c
··· 28 28 #define USIBU1_RSTCTRL 0x0ac 29 29 #define USIBU2_RSTCTRL 0x0b0 30 30 #define USIBU3_RSTCTRL 0x0b4 31 + #define IIC0_RSTCTRL 0x0dc 32 + #define IIC1_RSTCTRL 0x0e0 31 33 #define STI_RSTCTRL 0x124 32 34 #define STI_CLKSEL 0x688 33 35 ··· 68 66 emev2_smu_write(2, USIBU1_RSTCTRL); 69 67 emev2_smu_write(2, USIBU2_RSTCTRL); 70 68 emev2_smu_write(2, USIBU3_RSTCTRL); 69 + 70 + /* deassert reset for IIC0->IIC1 */ 71 + emev2_smu_write(1, IIC0_RSTCTRL); 72 + emev2_smu_write(1, IIC1_RSTCTRL); 71 73 } 72 74 73 75 static void __init emev2_smu_clkdiv_init(struct device_node *np)
+18 -1
drivers/i2c/busses/Kconfig
··· 526 526 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series. 527 527 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH. 528 528 529 + config I2C_EMEV2 530 + tristate "EMMA Mobile series I2C adapter" 531 + depends on HAVE_CLK 532 + help 533 + If you say yes to this option, support will be included for the 534 + I2C interface on the Renesas Electronics EM/EV family of processors. 535 + 529 536 config I2C_EXYNOS5 530 537 tristate "Exynos5 high-speed I2C driver" 531 538 depends on ARCH_EXYNOS && OF ··· 618 611 619 612 This driver can also be built as a module. If so, the module 620 613 will be called i2c-kempld. 614 + 615 + config I2C_LPC2K 616 + tristate "I2C bus support for NXP LPC2K/LPC178x/18xx/43xx" 617 + depends on OF && (ARCH_LPC18XX || COMPILE_TEST) 618 + help 619 + This driver supports the I2C interface found several NXP 620 + devices including LPC2xxx, LPC178x/7x and LPC18xx/43xx. 621 + 622 + This driver can also be built as a module. If so, the module 623 + will be called i2c-lpc2k. 621 624 622 625 config I2C_MESON 623 626 tristate "Amlogic Meson I2C controller" ··· 1140 1123 1141 1124 config I2C_CROS_EC_TUNNEL 1142 1125 tristate "ChromeOS EC tunnel I2C bus" 1143 - depends on CROS_EC_PROTO 1126 + depends on MFD_CROS_EC 1144 1127 help 1145 1128 If you say yes here you get an I2C bus that will tunnel i2c commands 1146 1129 through to the other side of the ChromeOS EC to the i2c bus
+2
drivers/i2c/busses/Makefile
··· 48 48 obj-$(CONFIG_I2C_DIGICOLOR) += i2c-digicolor.o 49 49 obj-$(CONFIG_I2C_EFM32) += i2c-efm32.o 50 50 obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o 51 + obj-$(CONFIG_I2C_EMEV2) += i2c-emev2.o 51 52 obj-$(CONFIG_I2C_EXYNOS5) += i2c-exynos5.o 52 53 obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 53 54 obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o ··· 59 58 obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 60 59 obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o 61 60 obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o 61 + obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o 62 62 obj-$(CONFIG_I2C_MESON) += i2c-meson.o 63 63 obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 64 64 obj-$(CONFIG_I2C_MT65XX) += i2c-mt65xx.o
+58 -11
drivers/i2c/busses/i2c-cadence.c
··· 17 17 #include <linux/io.h> 18 18 #include <linux/module.h> 19 19 #include <linux/platform_device.h> 20 + #include <linux/of.h> 20 21 21 22 /* Register offsets for the I2C device. */ 22 23 #define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */ ··· 114 113 115 114 #define CDNS_I2C_TIMEOUT_MAX 0xFF 116 115 116 + #define CDNS_I2C_BROKEN_HOLD_BIT BIT(0) 117 + 117 118 #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) 118 119 #define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset) 119 120 ··· 138 135 * @bus_hold_flag: Flag used in repeated start for clearing HOLD bit 139 136 * @clk: Pointer to struct clk 140 137 * @clk_rate_change_nb: Notifier block for clock rate changes 138 + * @quirks: flag for broken hold bit usage in r1p10 141 139 */ 142 140 struct cdns_i2c { 143 141 void __iomem *membase; ··· 158 154 unsigned int bus_hold_flag; 159 155 struct clk *clk; 160 156 struct notifier_block clk_rate_change_nb; 157 + u32 quirks; 158 + }; 159 + 160 + struct cdns_platform_data { 161 + u32 quirks; 161 162 }; 162 163 163 164 #define to_cdns_i2c(_nb) container_of(_nb, struct cdns_i2c, \ ··· 181 172 cdns_i2c_writereg(reg & ~CDNS_I2C_CR_HOLD, CDNS_I2C_CR_OFFSET); 182 173 } 183 174 175 + static inline bool cdns_is_holdquirk(struct cdns_i2c *id, bool hold_wrkaround) 176 + { 177 + return (hold_wrkaround && 178 + (id->curr_recv_count == CDNS_I2C_FIFO_DEPTH + 1)); 179 + } 180 + 184 181 /** 185 182 * cdns_i2c_isr - Interrupt handler for the I2C device 186 183 * @irq: irq number for the I2C device ··· 201 186 { 202 187 unsigned int isr_status, avail_bytes, updatetx; 203 188 unsigned int bytes_to_send; 189 + bool hold_quirk; 204 190 struct cdns_i2c *id = ptr; 205 191 /* Signal completion only after everything is updated */ 206 192 int done_flag = 0; ··· 224 208 if (id->recv_count > id->curr_recv_count) 225 209 updatetx = 1; 226 210 211 + hold_quirk = (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) && updatetx; 212 + 227 213 /* When receiving, handle data interrupt and completion interrupt */ 228 214 if (id->p_recv_buf && 229 215 ((isr_status & CDNS_I2C_IXR_COMP) || ··· 247 229 id->recv_count--; 248 230 id->curr_recv_count--; 249 231 250 - if (updatetx && 251 - (id->curr_recv_count == CDNS_I2C_FIFO_DEPTH + 1)) 232 + if (cdns_is_holdquirk(id, hold_quirk)) 252 233 break; 253 234 } 254 235 ··· 258 241 * maintain transfer size non-zero while performing a large 259 242 * receive operation. 260 243 */ 261 - if (updatetx && 262 - (id->curr_recv_count == CDNS_I2C_FIFO_DEPTH + 1)) { 244 + if (cdns_is_holdquirk(id, hold_quirk)) { 263 245 /* wait while fifo is full */ 264 246 while (cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET) != 265 247 (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH)) ··· 278 262 cdns_i2c_writereg(id->recv_count - 279 263 CDNS_I2C_FIFO_DEPTH, 280 264 CDNS_I2C_XFER_SIZE_OFFSET); 265 + id->curr_recv_count = id->recv_count; 266 + } 267 + } else if (id->recv_count && !hold_quirk && 268 + !id->curr_recv_count) { 269 + 270 + /* Set the slave address in address register*/ 271 + cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, 272 + CDNS_I2C_ADDR_OFFSET); 273 + 274 + if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) { 275 + cdns_i2c_writereg(CDNS_I2C_TRANSFER_SIZE, 276 + CDNS_I2C_XFER_SIZE_OFFSET); 277 + id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE; 278 + } else { 279 + cdns_i2c_writereg(id->recv_count, 280 + CDNS_I2C_XFER_SIZE_OFFSET); 281 281 id->curr_recv_count = id->recv_count; 282 282 } 283 283 } ··· 567 535 int ret, count; 568 536 u32 reg; 569 537 struct cdns_i2c *id = adap->algo_data; 538 + bool hold_quirk; 570 539 571 540 /* Check if the bus is free */ 572 541 if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA) 573 542 return -EAGAIN; 574 543 544 + hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); 575 545 /* 576 546 * Set the flag to one when multiple messages are to be 577 547 * processed with a repeated start. ··· 586 552 * followed by any other message, an error is returned 587 553 * indicating that this sequence is not supported. 588 554 */ 589 - for (count = 0; count < num - 1; count++) { 555 + for (count = 0; (count < num - 1 && hold_quirk); count++) { 590 556 if (msgs[count].flags & I2C_M_RD) { 591 557 dev_warn(adap->dev.parent, 592 558 "Can't do repeated start after a receive message\n"); ··· 849 815 static SIMPLE_DEV_PM_OPS(cdns_i2c_dev_pm_ops, cdns_i2c_suspend, 850 816 cdns_i2c_resume); 851 817 818 + static const struct cdns_platform_data r1p10_i2c_def = { 819 + .quirks = CDNS_I2C_BROKEN_HOLD_BIT, 820 + }; 821 + 822 + static const struct of_device_id cdns_i2c_of_match[] = { 823 + { .compatible = "cdns,i2c-r1p10", .data = &r1p10_i2c_def }, 824 + { .compatible = "cdns,i2c-r1p14",}, 825 + { /* end of table */ } 826 + }; 827 + MODULE_DEVICE_TABLE(of, cdns_i2c_of_match); 828 + 852 829 /** 853 830 * cdns_i2c_probe - Platform registration call 854 831 * @pdev: Handle to the platform device structure ··· 875 830 struct resource *r_mem; 876 831 struct cdns_i2c *id; 877 832 int ret; 833 + const struct of_device_id *match; 878 834 879 835 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); 880 836 if (!id) 881 837 return -ENOMEM; 882 838 883 839 platform_set_drvdata(pdev, id); 840 + 841 + match = of_match_node(cdns_i2c_of_match, pdev->dev.of_node); 842 + if (match && match->data) { 843 + const struct cdns_platform_data *data = match->data; 844 + id->quirks = data->quirks; 845 + } 884 846 885 847 r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 886 848 id->membase = devm_ioremap_resource(&pdev->dev, r_mem); ··· 896 844 897 845 id->irq = platform_get_irq(pdev, 0); 898 846 847 + id->adap.owner = THIS_MODULE; 899 848 id->adap.dev.of_node = pdev->dev.of_node; 900 849 id->adap.algo = &cdns_i2c_algo; 901 850 id->adap.timeout = CDNS_I2C_TIMEOUT; ··· 987 934 988 935 return 0; 989 936 } 990 - 991 - static const struct of_device_id cdns_i2c_of_match[] = { 992 - { .compatible = "cdns,i2c-r1p10", }, 993 - { /* end of table */ } 994 - }; 995 - MODULE_DEVICE_TABLE(of, cdns_i2c_of_match); 996 937 997 938 static struct platform_driver cdns_i2c_drv = { 998 939 .driver = {
+1 -2
drivers/i2c/busses/i2c-designware-core.c
··· 777 777 778 778 enabled = dw_readl(dev, DW_IC_ENABLE); 779 779 stat = dw_readl(dev, DW_IC_RAW_INTR_STAT); 780 - dev_dbg(dev->dev, "%s: %s enabled= 0x%x stat=0x%x\n", __func__, 781 - dev->adapter.name, enabled, stat); 780 + dev_dbg(dev->dev, "%s: enabled=%#x stat=%#x\n", __func__, enabled, stat); 782 781 if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY)) 783 782 return IRQ_NONE; 784 783
+2 -2
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 260 260 261 261 snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci"); 262 262 263 - r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, IRQF_SHARED, 264 - adap->name, dev); 263 + r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, 264 + IRQF_SHARED | IRQF_COND_SUSPEND, adap->name, dev); 265 265 if (r) { 266 266 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); 267 267 return r;
+332
drivers/i2c/busses/i2c-emev2.c
··· 1 + /* 2 + * I2C driver for the Renesas EMEV2 SoC 3 + * 4 + * Copyright (C) 2015 Wolfram Sang <wsa@sang-engineering.com> 5 + * Copyright 2013 Codethink Ltd. 6 + * Copyright 2010-2015 Renesas Electronics Corporation 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 10 + * as published by the Free Software Foundation. 11 + */ 12 + 13 + #include <linux/clk.h> 14 + #include <linux/completion.h> 15 + #include <linux/device.h> 16 + #include <linux/i2c.h> 17 + #include <linux/init.h> 18 + #include <linux/interrupt.h> 19 + #include <linux/io.h> 20 + #include <linux/kernel.h> 21 + #include <linux/module.h> 22 + #include <linux/of_device.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/sched.h> 25 + 26 + /* I2C Registers */ 27 + #define I2C_OFS_IICACT0 0x00 /* start */ 28 + #define I2C_OFS_IIC0 0x04 /* shift */ 29 + #define I2C_OFS_IICC0 0x08 /* control */ 30 + #define I2C_OFS_SVA0 0x0c /* slave address */ 31 + #define I2C_OFS_IICCL0 0x10 /* clock select */ 32 + #define I2C_OFS_IICX0 0x14 /* extension */ 33 + #define I2C_OFS_IICS0 0x18 /* status */ 34 + #define I2C_OFS_IICSE0 0x1c /* status For emulation */ 35 + #define I2C_OFS_IICF0 0x20 /* IIC flag */ 36 + 37 + /* I2C IICACT0 Masks */ 38 + #define I2C_BIT_IICE0 0x0001 39 + 40 + /* I2C IICC0 Masks */ 41 + #define I2C_BIT_LREL0 0x0040 42 + #define I2C_BIT_WREL0 0x0020 43 + #define I2C_BIT_SPIE0 0x0010 44 + #define I2C_BIT_WTIM0 0x0008 45 + #define I2C_BIT_ACKE0 0x0004 46 + #define I2C_BIT_STT0 0x0002 47 + #define I2C_BIT_SPT0 0x0001 48 + 49 + /* I2C IICCL0 Masks */ 50 + #define I2C_BIT_SMC0 0x0008 51 + #define I2C_BIT_DFC0 0x0004 52 + 53 + /* I2C IICSE0 Masks */ 54 + #define I2C_BIT_MSTS0 0x0080 55 + #define I2C_BIT_ALD0 0x0040 56 + #define I2C_BIT_EXC0 0x0020 57 + #define I2C_BIT_COI0 0x0010 58 + #define I2C_BIT_TRC0 0x0008 59 + #define I2C_BIT_ACKD0 0x0004 60 + #define I2C_BIT_STD0 0x0002 61 + #define I2C_BIT_SPD0 0x0001 62 + 63 + /* I2C IICF0 Masks */ 64 + #define I2C_BIT_STCF 0x0080 65 + #define I2C_BIT_IICBSY 0x0040 66 + #define I2C_BIT_STCEN 0x0002 67 + #define I2C_BIT_IICRSV 0x0001 68 + 69 + struct em_i2c_device { 70 + void __iomem *base; 71 + struct i2c_adapter adap; 72 + struct completion msg_done; 73 + struct clk *sclk; 74 + }; 75 + 76 + static inline void em_clear_set_bit(struct em_i2c_device *priv, u8 clear, u8 set, u8 reg) 77 + { 78 + writeb((readb(priv->base + reg) & ~clear) | set, priv->base + reg); 79 + } 80 + 81 + static int em_i2c_wait_for_event(struct em_i2c_device *priv) 82 + { 83 + unsigned long time_left; 84 + int status; 85 + 86 + reinit_completion(&priv->msg_done); 87 + 88 + time_left = wait_for_completion_timeout(&priv->msg_done, priv->adap.timeout); 89 + 90 + if (!time_left) 91 + return -ETIMEDOUT; 92 + 93 + status = readb(priv->base + I2C_OFS_IICSE0); 94 + return status & I2C_BIT_ALD0 ? -EAGAIN : status; 95 + } 96 + 97 + static void em_i2c_stop(struct em_i2c_device *priv) 98 + { 99 + /* Send Stop condition */ 100 + em_clear_set_bit(priv, 0, I2C_BIT_SPT0 | I2C_BIT_SPIE0, I2C_OFS_IICC0); 101 + 102 + /* Wait for stop condition */ 103 + em_i2c_wait_for_event(priv); 104 + } 105 + 106 + static void em_i2c_reset(struct i2c_adapter *adap) 107 + { 108 + struct em_i2c_device *priv = i2c_get_adapdata(adap); 109 + int retr; 110 + 111 + /* If I2C active */ 112 + if (readb(priv->base + I2C_OFS_IICACT0) & I2C_BIT_IICE0) { 113 + /* Disable I2C operation */ 114 + writeb(0, priv->base + I2C_OFS_IICACT0); 115 + 116 + retr = 1000; 117 + while (readb(priv->base + I2C_OFS_IICACT0) == 1 && retr) 118 + retr--; 119 + WARN_ON(retr == 0); 120 + } 121 + 122 + /* Transfer mode set */ 123 + writeb(I2C_BIT_DFC0, priv->base + I2C_OFS_IICCL0); 124 + 125 + /* Can Issue start without detecting a stop, Reservation disabled. */ 126 + writeb(I2C_BIT_STCEN | I2C_BIT_IICRSV, priv->base + I2C_OFS_IICF0); 127 + 128 + /* I2C enable, 9 bit interrupt mode */ 129 + writeb(I2C_BIT_WTIM0, priv->base + I2C_OFS_IICC0); 130 + 131 + /* Enable I2C operation */ 132 + writeb(I2C_BIT_IICE0, priv->base + I2C_OFS_IICACT0); 133 + 134 + retr = 1000; 135 + while (readb(priv->base + I2C_OFS_IICACT0) == 0 && retr) 136 + retr--; 137 + WARN_ON(retr == 0); 138 + } 139 + 140 + static int __em_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, 141 + int stop) 142 + { 143 + struct em_i2c_device *priv = i2c_get_adapdata(adap); 144 + int count, status, read = !!(msg->flags & I2C_M_RD); 145 + 146 + /* Send start condition */ 147 + em_clear_set_bit(priv, 0, I2C_BIT_ACKE0 | I2C_BIT_WTIM0, I2C_OFS_IICC0); 148 + em_clear_set_bit(priv, 0, I2C_BIT_STT0, I2C_OFS_IICC0); 149 + 150 + /* Send slave address and R/W type */ 151 + writeb((msg->addr << 1) | read, priv->base + I2C_OFS_IIC0); 152 + 153 + /* Wait for transaction */ 154 + status = em_i2c_wait_for_event(priv); 155 + if (status < 0) 156 + goto out_reset; 157 + 158 + /* Received NACK (result of setting slave address and R/W) */ 159 + if (!(status & I2C_BIT_ACKD0)) { 160 + em_i2c_stop(priv); 161 + goto out; 162 + } 163 + 164 + /* Extra setup for read transactions */ 165 + if (read) { 166 + /* 8 bit interrupt mode */ 167 + em_clear_set_bit(priv, I2C_BIT_WTIM0, I2C_BIT_ACKE0, I2C_OFS_IICC0); 168 + em_clear_set_bit(priv, I2C_BIT_WTIM0, I2C_BIT_WREL0, I2C_OFS_IICC0); 169 + 170 + /* Wait for transaction */ 171 + status = em_i2c_wait_for_event(priv); 172 + if (status < 0) 173 + goto out_reset; 174 + } 175 + 176 + /* Send / receive data */ 177 + for (count = 0; count < msg->len; count++) { 178 + if (read) { /* Read transaction */ 179 + msg->buf[count] = readb(priv->base + I2C_OFS_IIC0); 180 + em_clear_set_bit(priv, 0, I2C_BIT_WREL0, I2C_OFS_IICC0); 181 + 182 + } else { /* Write transaction */ 183 + /* Received NACK */ 184 + if (!(status & I2C_BIT_ACKD0)) { 185 + em_i2c_stop(priv); 186 + goto out; 187 + } 188 + 189 + /* Write data */ 190 + writeb(msg->buf[count], priv->base + I2C_OFS_IIC0); 191 + } 192 + 193 + /* Wait for R/W transaction */ 194 + status = em_i2c_wait_for_event(priv); 195 + if (status < 0) 196 + goto out_reset; 197 + } 198 + 199 + if (stop) 200 + em_i2c_stop(priv); 201 + 202 + return count; 203 + 204 + out_reset: 205 + em_i2c_reset(adap); 206 + out: 207 + return status < 0 ? status : -ENXIO; 208 + } 209 + 210 + static int em_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, 211 + int num) 212 + { 213 + struct em_i2c_device *priv = i2c_get_adapdata(adap); 214 + int ret, i; 215 + 216 + if (readb(priv->base + I2C_OFS_IICF0) & I2C_BIT_IICBSY) 217 + return -EAGAIN; 218 + 219 + for (i = 0; i < num; i++) { 220 + ret = __em_i2c_xfer(adap, &msgs[i], (i == (num - 1))); 221 + if (ret < 0) 222 + return ret; 223 + } 224 + 225 + /* I2C transfer completed */ 226 + return num; 227 + } 228 + 229 + static irqreturn_t em_i2c_irq_handler(int this_irq, void *dev_id) 230 + { 231 + struct em_i2c_device *priv = dev_id; 232 + 233 + complete(&priv->msg_done); 234 + return IRQ_HANDLED; 235 + } 236 + 237 + static u32 em_i2c_func(struct i2c_adapter *adap) 238 + { 239 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 240 + } 241 + 242 + static struct i2c_algorithm em_i2c_algo = { 243 + .master_xfer = em_i2c_xfer, 244 + .functionality = em_i2c_func, 245 + }; 246 + 247 + static int em_i2c_probe(struct platform_device *pdev) 248 + { 249 + struct em_i2c_device *priv; 250 + struct resource *r; 251 + int irq, ret; 252 + 253 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 254 + if (!priv) 255 + return -ENOMEM; 256 + 257 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 258 + priv->base = devm_ioremap_resource(&pdev->dev, r); 259 + if (IS_ERR(priv->base)) 260 + return PTR_ERR(priv->base); 261 + 262 + strlcpy(priv->adap.name, "EMEV2 I2C", sizeof(priv->adap.name)); 263 + 264 + priv->sclk = devm_clk_get(&pdev->dev, "sclk"); 265 + if (IS_ERR(priv->sclk)) 266 + return PTR_ERR(priv->sclk); 267 + 268 + clk_prepare_enable(priv->sclk); 269 + 270 + priv->adap.timeout = msecs_to_jiffies(100); 271 + priv->adap.retries = 5; 272 + priv->adap.dev.parent = &pdev->dev; 273 + priv->adap.algo = &em_i2c_algo; 274 + priv->adap.owner = THIS_MODULE; 275 + priv->adap.dev.of_node = pdev->dev.of_node; 276 + 277 + init_completion(&priv->msg_done); 278 + 279 + platform_set_drvdata(pdev, priv); 280 + i2c_set_adapdata(&priv->adap, priv); 281 + 282 + em_i2c_reset(&priv->adap); 283 + 284 + irq = platform_get_irq(pdev, 0); 285 + ret = devm_request_irq(&pdev->dev, irq, em_i2c_irq_handler, 0, 286 + "em_i2c", priv); 287 + if (ret) 288 + goto err_clk; 289 + 290 + ret = i2c_add_adapter(&priv->adap); 291 + 292 + if (ret) 293 + goto err_clk; 294 + 295 + dev_info(&pdev->dev, "Added i2c controller %d, irq %d\n", priv->adap.nr, irq); 296 + 297 + return 0; 298 + 299 + err_clk: 300 + clk_disable_unprepare(priv->sclk); 301 + return ret; 302 + } 303 + 304 + static int em_i2c_remove(struct platform_device *dev) 305 + { 306 + struct em_i2c_device *priv = platform_get_drvdata(dev); 307 + 308 + i2c_del_adapter(&priv->adap); 309 + clk_disable_unprepare(priv->sclk); 310 + 311 + return 0; 312 + } 313 + 314 + static const struct of_device_id em_i2c_ids[] = { 315 + { .compatible = "renesas,iic-emev2", }, 316 + { } 317 + }; 318 + 319 + static struct platform_driver em_i2c_driver = { 320 + .probe = em_i2c_probe, 321 + .remove = em_i2c_remove, 322 + .driver = { 323 + .name = "em-i2c", 324 + .of_match_table = em_i2c_ids, 325 + } 326 + }; 327 + module_platform_driver(em_i2c_driver); 328 + 329 + MODULE_DESCRIPTION("EMEV2 I2C bus driver"); 330 + MODULE_AUTHOR("Ian Molton and Wolfram Sang <wsa@sang-engineering.com>"); 331 + MODULE_LICENSE("GPL v2"); 332 + MODULE_DEVICE_TABLE(of, em_i2c_ids);
+513
drivers/i2c/busses/i2c-lpc2k.c
··· 1 + /* 2 + * Copyright (C) 2011 NXP Semiconductors 3 + * 4 + * Code portions referenced from the i2x-pxa and i2c-pnx drivers 5 + * 6 + * Make SMBus byte and word transactions work on LPC178x/7x 7 + * Copyright (c) 2012 8 + * Alexander Potashev, Emcraft Systems, aspotashev@emcraft.com 9 + * Anton Protopopov, Emcraft Systems, antonp@emcraft.com 10 + * 11 + * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com> 12 + * 13 + * This program is free software; you can redistribute it and/or modify 14 + * it under the terms of the GNU General Public License as published by 15 + * the Free Software Foundation; either version 2 of the License, or 16 + * (at your option) any later version. 17 + * 18 + */ 19 + 20 + #include <linux/clk.h> 21 + #include <linux/errno.h> 22 + #include <linux/i2c.h> 23 + #include <linux/interrupt.h> 24 + #include <linux/io.h> 25 + #include <linux/kernel.h> 26 + #include <linux/module.h> 27 + #include <linux/of.h> 28 + #include <linux/of_device.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/sched.h> 31 + #include <linux/time.h> 32 + 33 + /* LPC24xx register offsets and bits */ 34 + #define LPC24XX_I2CONSET 0x00 35 + #define LPC24XX_I2STAT 0x04 36 + #define LPC24XX_I2DAT 0x08 37 + #define LPC24XX_I2ADDR 0x0c 38 + #define LPC24XX_I2SCLH 0x10 39 + #define LPC24XX_I2SCLL 0x14 40 + #define LPC24XX_I2CONCLR 0x18 41 + 42 + #define LPC24XX_AA BIT(2) 43 + #define LPC24XX_SI BIT(3) 44 + #define LPC24XX_STO BIT(4) 45 + #define LPC24XX_STA BIT(5) 46 + #define LPC24XX_I2EN BIT(6) 47 + 48 + #define LPC24XX_STO_AA (LPC24XX_STO | LPC24XX_AA) 49 + #define LPC24XX_CLEAR_ALL (LPC24XX_AA | LPC24XX_SI | LPC24XX_STO | \ 50 + LPC24XX_STA | LPC24XX_I2EN) 51 + 52 + /* I2C SCL clock has different duty cycle depending on mode */ 53 + #define I2C_STD_MODE_DUTY 46 54 + #define I2C_FAST_MODE_DUTY 36 55 + #define I2C_FAST_MODE_PLUS_DUTY 38 56 + 57 + /* 58 + * 26 possible I2C status codes, but codes applicable only 59 + * to master are listed here and used in this driver 60 + */ 61 + enum { 62 + M_BUS_ERROR = 0x00, 63 + M_START = 0x08, 64 + M_REPSTART = 0x10, 65 + MX_ADDR_W_ACK = 0x18, 66 + MX_ADDR_W_NACK = 0x20, 67 + MX_DATA_W_ACK = 0x28, 68 + MX_DATA_W_NACK = 0x30, 69 + M_DATA_ARB_LOST = 0x38, 70 + MR_ADDR_R_ACK = 0x40, 71 + MR_ADDR_R_NACK = 0x48, 72 + MR_DATA_R_ACK = 0x50, 73 + MR_DATA_R_NACK = 0x58, 74 + M_I2C_IDLE = 0xf8, 75 + }; 76 + 77 + struct lpc2k_i2c { 78 + void __iomem *base; 79 + struct clk *clk; 80 + int irq; 81 + wait_queue_head_t wait; 82 + struct i2c_adapter adap; 83 + struct i2c_msg *msg; 84 + int msg_idx; 85 + int msg_status; 86 + int is_last; 87 + }; 88 + 89 + static void i2c_lpc2k_reset(struct lpc2k_i2c *i2c) 90 + { 91 + /* Will force clear all statuses */ 92 + writel(LPC24XX_CLEAR_ALL, i2c->base + LPC24XX_I2CONCLR); 93 + writel(0, i2c->base + LPC24XX_I2ADDR); 94 + writel(LPC24XX_I2EN, i2c->base + LPC24XX_I2CONSET); 95 + } 96 + 97 + static int i2c_lpc2k_clear_arb(struct lpc2k_i2c *i2c) 98 + { 99 + unsigned long timeout = jiffies + msecs_to_jiffies(1000); 100 + 101 + /* 102 + * If the transfer needs to abort for some reason, we'll try to 103 + * force a stop condition to clear any pending bus conditions 104 + */ 105 + writel(LPC24XX_STO, i2c->base + LPC24XX_I2CONSET); 106 + 107 + /* Wait for status change */ 108 + while (readl(i2c->base + LPC24XX_I2STAT) != M_I2C_IDLE) { 109 + if (time_after(jiffies, timeout)) { 110 + /* Bus was not idle, try to reset adapter */ 111 + i2c_lpc2k_reset(i2c); 112 + return -EBUSY; 113 + } 114 + 115 + cpu_relax(); 116 + } 117 + 118 + return 0; 119 + } 120 + 121 + static void i2c_lpc2k_pump_msg(struct lpc2k_i2c *i2c) 122 + { 123 + unsigned char data; 124 + u32 status; 125 + 126 + /* 127 + * I2C in the LPC2xxx series is basically a state machine. 128 + * Just run through the steps based on the current status. 129 + */ 130 + status = readl(i2c->base + LPC24XX_I2STAT); 131 + 132 + switch (status) { 133 + case M_START: 134 + case M_REPSTART: 135 + /* Start bit was just sent out, send out addr and dir */ 136 + data = i2c->msg->addr << 1; 137 + if (i2c->msg->flags & I2C_M_RD) 138 + data |= 1; 139 + 140 + writel(data, i2c->base + LPC24XX_I2DAT); 141 + writel(LPC24XX_STA, i2c->base + LPC24XX_I2CONCLR); 142 + break; 143 + 144 + case MX_ADDR_W_ACK: 145 + case MX_DATA_W_ACK: 146 + /* 147 + * Address or data was sent out with an ACK. If there is more 148 + * data to send, send it now 149 + */ 150 + if (i2c->msg_idx < i2c->msg->len) { 151 + writel(i2c->msg->buf[i2c->msg_idx], 152 + i2c->base + LPC24XX_I2DAT); 153 + } else if (i2c->is_last) { 154 + /* Last message, send stop */ 155 + writel(LPC24XX_STO_AA, i2c->base + LPC24XX_I2CONSET); 156 + writel(LPC24XX_SI, i2c->base + LPC24XX_I2CONCLR); 157 + i2c->msg_status = 0; 158 + disable_irq_nosync(i2c->irq); 159 + } else { 160 + i2c->msg_status = 0; 161 + disable_irq_nosync(i2c->irq); 162 + } 163 + 164 + i2c->msg_idx++; 165 + break; 166 + 167 + case MR_ADDR_R_ACK: 168 + /* Receive first byte from slave */ 169 + if (i2c->msg->len == 1) { 170 + /* Last byte, return NACK */ 171 + writel(LPC24XX_AA, i2c->base + LPC24XX_I2CONCLR); 172 + } else { 173 + /* Not last byte, return ACK */ 174 + writel(LPC24XX_AA, i2c->base + LPC24XX_I2CONSET); 175 + } 176 + 177 + writel(LPC24XX_STA, i2c->base + LPC24XX_I2CONCLR); 178 + break; 179 + 180 + case MR_DATA_R_NACK: 181 + /* 182 + * The I2C shows NACK status on reads, so we need to accept 183 + * the NACK as an ACK here. This should be ok, as the real 184 + * BACK would of been caught on the address write. 185 + */ 186 + case MR_DATA_R_ACK: 187 + /* Data was received */ 188 + if (i2c->msg_idx < i2c->msg->len) { 189 + i2c->msg->buf[i2c->msg_idx] = 190 + readl(i2c->base + LPC24XX_I2DAT); 191 + } 192 + 193 + /* If transfer is done, send STOP */ 194 + if (i2c->msg_idx >= i2c->msg->len - 1 && i2c->is_last) { 195 + writel(LPC24XX_STO_AA, i2c->base + LPC24XX_I2CONSET); 196 + writel(LPC24XX_SI, i2c->base + LPC24XX_I2CONCLR); 197 + i2c->msg_status = 0; 198 + } 199 + 200 + /* Message is done */ 201 + if (i2c->msg_idx >= i2c->msg->len - 1) { 202 + i2c->msg_status = 0; 203 + disable_irq_nosync(i2c->irq); 204 + } 205 + 206 + /* 207 + * One pre-last data input, send NACK to tell the slave that 208 + * this is going to be the last data byte to be transferred. 209 + */ 210 + if (i2c->msg_idx >= i2c->msg->len - 2) { 211 + /* One byte left to receive - NACK */ 212 + writel(LPC24XX_AA, i2c->base + LPC24XX_I2CONCLR); 213 + } else { 214 + /* More than one byte left to receive - ACK */ 215 + writel(LPC24XX_AA, i2c->base + LPC24XX_I2CONSET); 216 + } 217 + 218 + writel(LPC24XX_STA, i2c->base + LPC24XX_I2CONCLR); 219 + i2c->msg_idx++; 220 + break; 221 + 222 + case MX_ADDR_W_NACK: 223 + case MX_DATA_W_NACK: 224 + case MR_ADDR_R_NACK: 225 + /* NACK processing is done */ 226 + writel(LPC24XX_STO_AA, i2c->base + LPC24XX_I2CONSET); 227 + i2c->msg_status = -ENXIO; 228 + disable_irq_nosync(i2c->irq); 229 + break; 230 + 231 + case M_DATA_ARB_LOST: 232 + /* Arbitration lost */ 233 + i2c->msg_status = -EAGAIN; 234 + 235 + /* Release the I2C bus */ 236 + writel(LPC24XX_STA | LPC24XX_STO, i2c->base + LPC24XX_I2CONCLR); 237 + disable_irq_nosync(i2c->irq); 238 + break; 239 + 240 + default: 241 + /* Unexpected statuses */ 242 + i2c->msg_status = -EIO; 243 + disable_irq_nosync(i2c->irq); 244 + break; 245 + } 246 + 247 + /* Exit on failure or all bytes transferred */ 248 + if (i2c->msg_status != -EBUSY) 249 + wake_up(&i2c->wait); 250 + 251 + /* 252 + * If `msg_status` is zero, then `lpc2k_process_msg()` 253 + * is responsible for clearing the SI flag. 254 + */ 255 + if (i2c->msg_status != 0) 256 + writel(LPC24XX_SI, i2c->base + LPC24XX_I2CONCLR); 257 + } 258 + 259 + static int lpc2k_process_msg(struct lpc2k_i2c *i2c, int msgidx) 260 + { 261 + /* A new transfer is kicked off by initiating a start condition */ 262 + if (!msgidx) { 263 + writel(LPC24XX_STA, i2c->base + LPC24XX_I2CONSET); 264 + } else { 265 + /* 266 + * A multi-message I2C transfer continues where the 267 + * previous I2C transfer left off and uses the 268 + * current condition of the I2C adapter. 269 + */ 270 + if (unlikely(i2c->msg->flags & I2C_M_NOSTART)) { 271 + WARN_ON(i2c->msg->len == 0); 272 + 273 + if (!(i2c->msg->flags & I2C_M_RD)) { 274 + /* Start transmit of data */ 275 + writel(i2c->msg->buf[0], 276 + i2c->base + LPC24XX_I2DAT); 277 + i2c->msg_idx++; 278 + } 279 + } else { 280 + /* Start or repeated start */ 281 + writel(LPC24XX_STA, i2c->base + LPC24XX_I2CONSET); 282 + } 283 + 284 + writel(LPC24XX_SI, i2c->base + LPC24XX_I2CONCLR); 285 + } 286 + 287 + enable_irq(i2c->irq); 288 + 289 + /* Wait for transfer completion */ 290 + if (wait_event_timeout(i2c->wait, i2c->msg_status != -EBUSY, 291 + msecs_to_jiffies(1000)) == 0) { 292 + disable_irq_nosync(i2c->irq); 293 + 294 + return -ETIMEDOUT; 295 + } 296 + 297 + return i2c->msg_status; 298 + } 299 + 300 + static int i2c_lpc2k_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, 301 + int msg_num) 302 + { 303 + struct lpc2k_i2c *i2c = i2c_get_adapdata(adap); 304 + int ret, i; 305 + u32 stat; 306 + 307 + /* Check for bus idle condition */ 308 + stat = readl(i2c->base + LPC24XX_I2STAT); 309 + if (stat != M_I2C_IDLE) { 310 + /* Something is holding the bus, try to clear it */ 311 + return i2c_lpc2k_clear_arb(i2c); 312 + } 313 + 314 + /* Process a single message at a time */ 315 + for (i = 0; i < msg_num; i++) { 316 + /* Save message pointer and current message data index */ 317 + i2c->msg = &msgs[i]; 318 + i2c->msg_idx = 0; 319 + i2c->msg_status = -EBUSY; 320 + i2c->is_last = (i == (msg_num - 1)); 321 + 322 + ret = lpc2k_process_msg(i2c, i); 323 + if (ret) 324 + return ret; 325 + } 326 + 327 + return msg_num; 328 + } 329 + 330 + static irqreturn_t i2c_lpc2k_handler(int irq, void *dev_id) 331 + { 332 + struct lpc2k_i2c *i2c = dev_id; 333 + 334 + if (readl(i2c->base + LPC24XX_I2CONSET) & LPC24XX_SI) { 335 + i2c_lpc2k_pump_msg(i2c); 336 + return IRQ_HANDLED; 337 + } 338 + 339 + return IRQ_NONE; 340 + } 341 + 342 + static u32 i2c_lpc2k_functionality(struct i2c_adapter *adap) 343 + { 344 + /* Only emulated SMBus for now */ 345 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 346 + } 347 + 348 + static const struct i2c_algorithm i2c_lpc2k_algorithm = { 349 + .master_xfer = i2c_lpc2k_xfer, 350 + .functionality = i2c_lpc2k_functionality, 351 + }; 352 + 353 + static int i2c_lpc2k_probe(struct platform_device *pdev) 354 + { 355 + struct lpc2k_i2c *i2c; 356 + struct resource *res; 357 + u32 bus_clk_rate; 358 + u32 scl_high; 359 + u32 clkrate; 360 + int ret; 361 + 362 + i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 363 + if (!i2c) 364 + return -ENOMEM; 365 + 366 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 367 + i2c->base = devm_ioremap_resource(&pdev->dev, res); 368 + if (IS_ERR(i2c->base)) 369 + return PTR_ERR(i2c->base); 370 + 371 + i2c->irq = platform_get_irq(pdev, 0); 372 + if (i2c->irq < 0) { 373 + dev_err(&pdev->dev, "can't get interrupt resource\n"); 374 + return i2c->irq; 375 + } 376 + 377 + init_waitqueue_head(&i2c->wait); 378 + 379 + i2c->clk = devm_clk_get(&pdev->dev, NULL); 380 + if (IS_ERR(i2c->clk)) { 381 + dev_err(&pdev->dev, "error getting clock\n"); 382 + return PTR_ERR(i2c->clk); 383 + } 384 + 385 + ret = clk_prepare_enable(i2c->clk); 386 + if (ret) { 387 + dev_err(&pdev->dev, "unable to enable clock.\n"); 388 + return ret; 389 + } 390 + 391 + ret = devm_request_irq(&pdev->dev, i2c->irq, i2c_lpc2k_handler, 0, 392 + dev_name(&pdev->dev), i2c); 393 + if (ret < 0) { 394 + dev_err(&pdev->dev, "can't request interrupt.\n"); 395 + goto fail_clk; 396 + } 397 + 398 + disable_irq_nosync(i2c->irq); 399 + 400 + /* Place controller is a known state */ 401 + i2c_lpc2k_reset(i2c); 402 + 403 + ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", 404 + &bus_clk_rate); 405 + if (ret) 406 + bus_clk_rate = 100000; /* 100 kHz default clock rate */ 407 + 408 + clkrate = clk_get_rate(i2c->clk); 409 + if (clkrate == 0) { 410 + dev_err(&pdev->dev, "can't get I2C base clock\n"); 411 + ret = -EINVAL; 412 + goto fail_clk; 413 + } 414 + 415 + /* Setup I2C dividers to generate clock with proper duty cycle */ 416 + clkrate = clkrate / bus_clk_rate; 417 + if (bus_clk_rate <= 100000) 418 + scl_high = (clkrate * I2C_STD_MODE_DUTY) / 100; 419 + else if (bus_clk_rate <= 400000) 420 + scl_high = (clkrate * I2C_FAST_MODE_DUTY) / 100; 421 + else 422 + scl_high = (clkrate * I2C_FAST_MODE_PLUS_DUTY) / 100; 423 + 424 + writel(scl_high, i2c->base + LPC24XX_I2SCLH); 425 + writel(clkrate - scl_high, i2c->base + LPC24XX_I2SCLL); 426 + 427 + platform_set_drvdata(pdev, i2c); 428 + 429 + i2c_set_adapdata(&i2c->adap, i2c); 430 + i2c->adap.owner = THIS_MODULE; 431 + strlcpy(i2c->adap.name, "LPC2K I2C adapter", sizeof(i2c->adap.name)); 432 + i2c->adap.algo = &i2c_lpc2k_algorithm; 433 + i2c->adap.dev.parent = &pdev->dev; 434 + i2c->adap.dev.of_node = pdev->dev.of_node; 435 + 436 + ret = i2c_add_adapter(&i2c->adap); 437 + if (ret < 0) { 438 + dev_err(&pdev->dev, "failed to add adapter!\n"); 439 + goto fail_clk; 440 + } 441 + 442 + dev_info(&pdev->dev, "LPC2K I2C adapter\n"); 443 + 444 + return 0; 445 + 446 + fail_clk: 447 + clk_disable_unprepare(i2c->clk); 448 + return ret; 449 + } 450 + 451 + static int i2c_lpc2k_remove(struct platform_device *dev) 452 + { 453 + struct lpc2k_i2c *i2c = platform_get_drvdata(dev); 454 + 455 + i2c_del_adapter(&i2c->adap); 456 + clk_disable_unprepare(i2c->clk); 457 + 458 + return 0; 459 + } 460 + 461 + #ifdef CONFIG_PM 462 + static int i2c_lpc2k_suspend(struct device *dev) 463 + { 464 + struct platform_device *pdev = to_platform_device(dev); 465 + struct lpc2k_i2c *i2c = platform_get_drvdata(pdev); 466 + 467 + clk_disable(i2c->clk); 468 + 469 + return 0; 470 + } 471 + 472 + static int i2c_lpc2k_resume(struct device *dev) 473 + { 474 + struct platform_device *pdev = to_platform_device(dev); 475 + struct lpc2k_i2c *i2c = platform_get_drvdata(pdev); 476 + 477 + clk_enable(i2c->clk); 478 + i2c_lpc2k_reset(i2c); 479 + 480 + return 0; 481 + } 482 + 483 + static const struct dev_pm_ops i2c_lpc2k_dev_pm_ops = { 484 + .suspend_noirq = i2c_lpc2k_suspend, 485 + .resume_noirq = i2c_lpc2k_resume, 486 + }; 487 + 488 + #define I2C_LPC2K_DEV_PM_OPS (&i2c_lpc2k_dev_pm_ops) 489 + #else 490 + #define I2C_LPC2K_DEV_PM_OPS NULL 491 + #endif 492 + 493 + static const struct of_device_id lpc2k_i2c_match[] = { 494 + { .compatible = "nxp,lpc1788-i2c" }, 495 + {}, 496 + }; 497 + MODULE_DEVICE_TABLE(of, lpc2k_i2c_match); 498 + 499 + static struct platform_driver i2c_lpc2k_driver = { 500 + .probe = i2c_lpc2k_probe, 501 + .remove = i2c_lpc2k_remove, 502 + .driver = { 503 + .name = "lpc2k-i2c", 504 + .pm = I2C_LPC2K_DEV_PM_OPS, 505 + .of_match_table = lpc2k_i2c_match, 506 + }, 507 + }; 508 + module_platform_driver(i2c_lpc2k_driver); 509 + 510 + MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>"); 511 + MODULE_DESCRIPTION("I2C driver for LPC2xxx devices"); 512 + MODULE_LICENSE("GPL"); 513 + MODULE_ALIAS("platform:lpc2k-i2c");
+17 -4
drivers/i2c/busses/i2c-mt65xx.c
··· 59 59 #define I2C_DMA_START_EN 0x0001 60 60 #define I2C_DMA_INT_FLAG_NONE 0x0000 61 61 #define I2C_DMA_CLR_FLAG 0x0000 62 + #define I2C_DMA_HARD_RST 0x0002 62 63 63 64 #define I2C_DEFAULT_SPEED 100000 /* hz */ 64 65 #define MAX_FS_MODE_SPEED 400000 ··· 82 81 OFFSET_INT_FLAG = 0x0, 83 82 OFFSET_INT_EN = 0x04, 84 83 OFFSET_EN = 0x08, 84 + OFFSET_RST = 0x0c, 85 85 OFFSET_CON = 0x18, 86 86 OFFSET_TX_MEM_ADDR = 0x1c, 87 87 OFFSET_RX_MEM_ADDR = 0x20, ··· 264 262 I2C_CONTROL_CLK_EXT_EN | I2C_CONTROL_DMA_EN; 265 263 writew(control_reg, i2c->base + OFFSET_CONTROL); 266 264 writew(I2C_DELAY_LEN, i2c->base + OFFSET_DELAY_LEN); 265 + 266 + writel(I2C_DMA_HARD_RST, i2c->pdmabase + OFFSET_RST); 267 + udelay(50); 268 + writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_RST); 267 269 } 268 270 269 271 /* ··· 557 551 { 558 552 struct mtk_i2c *i2c = dev_id; 559 553 u16 restart_flag = 0; 554 + u16 intr_stat; 560 555 561 556 if (i2c->dev_comp->auto_restart) 562 557 restart_flag = I2C_RS_TRANSFER; 563 558 564 - i2c->irq_stat = readw(i2c->base + OFFSET_INTR_STAT); 565 - writew(restart_flag | I2C_HS_NACKERR | I2C_ACKERR 566 - | I2C_TRANSAC_COMP, i2c->base + OFFSET_INTR_STAT); 559 + intr_stat = readw(i2c->base + OFFSET_INTR_STAT); 560 + writew(intr_stat, i2c->base + OFFSET_INTR_STAT); 567 561 568 - complete(&i2c->msg_complete); 562 + /* 563 + * when occurs ack error, i2c controller generate two interrupts 564 + * first is the ack error interrupt, then the complete interrupt 565 + * i2c->irq_stat need keep the two interrupt value. 566 + */ 567 + i2c->irq_stat |= intr_stat; 568 + if (i2c->irq_stat & (I2C_TRANSAC_COMP | restart_flag)) 569 + complete(&i2c->msg_complete); 569 570 570 571 return IRQ_HANDLED; 571 572 }
+299 -301
drivers/i2c/busses/i2c-omap.c
··· 270 270 [OMAP_I2C_IP_V2_IRQENABLE_CLR] = 0x30, 271 271 }; 272 272 273 - static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, 273 + static inline void omap_i2c_write_reg(struct omap_i2c_dev *omap, 274 274 int reg, u16 val) 275 275 { 276 - writew_relaxed(val, i2c_dev->base + 277 - (i2c_dev->regs[reg] << i2c_dev->reg_shift)); 276 + writew_relaxed(val, omap->base + 277 + (omap->regs[reg] << omap->reg_shift)); 278 278 } 279 279 280 - static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) 280 + static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *omap, int reg) 281 281 { 282 - return readw_relaxed(i2c_dev->base + 283 - (i2c_dev->regs[reg] << i2c_dev->reg_shift)); 282 + return readw_relaxed(omap->base + 283 + (omap->regs[reg] << omap->reg_shift)); 284 284 } 285 285 286 - static void __omap_i2c_init(struct omap_i2c_dev *dev) 286 + static void __omap_i2c_init(struct omap_i2c_dev *omap) 287 287 { 288 288 289 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 289 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0); 290 290 291 291 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 292 - omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); 292 + omap_i2c_write_reg(omap, OMAP_I2C_PSC_REG, omap->pscstate); 293 293 294 294 /* SCL low and high time values */ 295 - omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); 296 - omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, dev->sclhstate); 297 - if (dev->rev >= OMAP_I2C_REV_ON_3430_3530) 298 - omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); 295 + omap_i2c_write_reg(omap, OMAP_I2C_SCLL_REG, omap->scllstate); 296 + omap_i2c_write_reg(omap, OMAP_I2C_SCLH_REG, omap->sclhstate); 297 + if (omap->rev >= OMAP_I2C_REV_ON_3430_3530) 298 + omap_i2c_write_reg(omap, OMAP_I2C_WE_REG, omap->westate); 299 299 300 300 /* Take the I2C module out of reset: */ 301 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 301 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 302 302 303 303 /* 304 304 * NOTE: right after setting CON_EN, STAT_BB could be 0 while the ··· 310 310 * Don't write to this register if the IE state is 0 as it can 311 311 * cause deadlock. 312 312 */ 313 - if (dev->iestate) 314 - omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); 313 + if (omap->iestate) 314 + omap_i2c_write_reg(omap, OMAP_I2C_IE_REG, omap->iestate); 315 315 } 316 316 317 - static int omap_i2c_reset(struct omap_i2c_dev *dev) 317 + static int omap_i2c_reset(struct omap_i2c_dev *omap) 318 318 { 319 319 unsigned long timeout; 320 320 u16 sysc; 321 321 322 - if (dev->rev >= OMAP_I2C_OMAP1_REV_2) { 323 - sysc = omap_i2c_read_reg(dev, OMAP_I2C_SYSC_REG); 322 + if (omap->rev >= OMAP_I2C_OMAP1_REV_2) { 323 + sysc = omap_i2c_read_reg(omap, OMAP_I2C_SYSC_REG); 324 324 325 325 /* Disable I2C controller before soft reset */ 326 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 327 - omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & 326 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 327 + omap_i2c_read_reg(omap, OMAP_I2C_CON_REG) & 328 328 ~(OMAP_I2C_CON_EN)); 329 329 330 - omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK); 330 + omap_i2c_write_reg(omap, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK); 331 331 /* For some reason we need to set the EN bit before the 332 332 * reset done bit gets set. */ 333 333 timeout = jiffies + OMAP_I2C_TIMEOUT; 334 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 335 - while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) & 334 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 335 + while (!(omap_i2c_read_reg(omap, OMAP_I2C_SYSS_REG) & 336 336 SYSS_RESETDONE_MASK)) { 337 337 if (time_after(jiffies, timeout)) { 338 - dev_warn(dev->dev, "timeout waiting " 338 + dev_warn(omap->dev, "timeout waiting " 339 339 "for controller reset\n"); 340 340 return -ETIMEDOUT; 341 341 } ··· 343 343 } 344 344 345 345 /* SYSC register is cleared by the reset; rewrite it */ 346 - omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, sysc); 346 + omap_i2c_write_reg(omap, OMAP_I2C_SYSC_REG, sysc); 347 347 348 - if (dev->rev > OMAP_I2C_REV_ON_3430_3530) { 348 + if (omap->rev > OMAP_I2C_REV_ON_3430_3530) { 349 349 /* Schedule I2C-bus monitoring on the next transfer */ 350 - dev->bb_valid = 0; 350 + omap->bb_valid = 0; 351 351 } 352 352 } 353 353 354 354 return 0; 355 355 } 356 356 357 - static int omap_i2c_init(struct omap_i2c_dev *dev) 357 + static int omap_i2c_init(struct omap_i2c_dev *omap) 358 358 { 359 359 u16 psc = 0, scll = 0, sclh = 0; 360 360 u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; ··· 362 362 unsigned long internal_clk = 0; 363 363 struct clk *fclk; 364 364 365 - if (dev->rev >= OMAP_I2C_REV_ON_3430_3530) { 365 + if (omap->rev >= OMAP_I2C_REV_ON_3430_3530) { 366 366 /* 367 367 * Enabling all wakup sources to stop I2C freezing on 368 368 * WFI instruction. 369 369 * REVISIT: Some wkup sources might not be needed. 370 370 */ 371 - dev->westate = OMAP_I2C_WE_ALL; 371 + omap->westate = OMAP_I2C_WE_ALL; 372 372 } 373 373 374 - if (dev->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) { 374 + if (omap->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) { 375 375 /* 376 376 * The I2C functional clock is the armxor_ck, so there's 377 377 * no need to get "armxor_ck" separately. Now, if OMAP2420 378 378 * always returns 12MHz for the functional clock, we can 379 379 * do this bit unconditionally. 380 380 */ 381 - fclk = clk_get(dev->dev, "fck"); 381 + fclk = clk_get(omap->dev, "fck"); 382 382 fclk_rate = clk_get_rate(fclk); 383 383 clk_put(fclk); 384 384 ··· 395 395 psc = fclk_rate / 12000000; 396 396 } 397 397 398 - if (!(dev->flags & OMAP_I2C_FLAG_SIMPLE_CLOCK)) { 398 + if (!(omap->flags & OMAP_I2C_FLAG_SIMPLE_CLOCK)) { 399 399 400 400 /* 401 401 * HSI2C controller internal clk rate should be 19.2 Mhz for ··· 403 403 * to get longer filter period for better noise suppression. 404 404 * The filter is iclk (fclk for HS) period. 405 405 */ 406 - if (dev->speed > 400 || 407 - dev->flags & OMAP_I2C_FLAG_FORCE_19200_INT_CLK) 406 + if (omap->speed > 400 || 407 + omap->flags & OMAP_I2C_FLAG_FORCE_19200_INT_CLK) 408 408 internal_clk = 19200; 409 - else if (dev->speed > 100) 409 + else if (omap->speed > 100) 410 410 internal_clk = 9600; 411 411 else 412 412 internal_clk = 4000; 413 - fclk = clk_get(dev->dev, "fck"); 413 + fclk = clk_get(omap->dev, "fck"); 414 414 fclk_rate = clk_get_rate(fclk) / 1000; 415 415 clk_put(fclk); 416 416 ··· 419 419 psc = psc - 1; 420 420 421 421 /* If configured for High Speed */ 422 - if (dev->speed > 400) { 422 + if (omap->speed > 400) { 423 423 unsigned long scl; 424 424 425 425 /* For first phase of HS mode */ ··· 428 428 fssclh = (scl / 3) - 5; 429 429 430 430 /* For second phase of HS mode */ 431 - scl = fclk_rate / dev->speed; 431 + scl = fclk_rate / omap->speed; 432 432 hsscll = scl - (scl / 3) - 7; 433 433 hssclh = (scl / 3) - 5; 434 - } else if (dev->speed > 100) { 434 + } else if (omap->speed > 100) { 435 435 unsigned long scl; 436 436 437 437 /* Fast mode */ 438 - scl = internal_clk / dev->speed; 438 + scl = internal_clk / omap->speed; 439 439 fsscll = scl - (scl / 3) - 7; 440 440 fssclh = (scl / 3) - 5; 441 441 } else { 442 442 /* Standard mode */ 443 - fsscll = internal_clk / (dev->speed * 2) - 7; 444 - fssclh = internal_clk / (dev->speed * 2) - 5; 443 + fsscll = internal_clk / (omap->speed * 2) - 7; 444 + fssclh = internal_clk / (omap->speed * 2) - 5; 445 445 } 446 446 scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll; 447 447 sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh; ··· 450 450 fclk_rate /= (psc + 1) * 1000; 451 451 if (psc > 2) 452 452 psc = 2; 453 - scll = fclk_rate / (dev->speed * 2) - 7 + psc; 454 - sclh = fclk_rate / (dev->speed * 2) - 7 + psc; 453 + scll = fclk_rate / (omap->speed * 2) - 7 + psc; 454 + sclh = fclk_rate / (omap->speed * 2) - 7 + psc; 455 455 } 456 456 457 - dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 457 + omap->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 458 458 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 459 - OMAP_I2C_IE_AL) | ((dev->fifo_size) ? 459 + OMAP_I2C_IE_AL) | ((omap->fifo_size) ? 460 460 (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); 461 461 462 - dev->pscstate = psc; 463 - dev->scllstate = scll; 464 - dev->sclhstate = sclh; 462 + omap->pscstate = psc; 463 + omap->scllstate = scll; 464 + omap->sclhstate = sclh; 465 465 466 - if (dev->rev <= OMAP_I2C_REV_ON_3430_3530) { 466 + if (omap->rev <= OMAP_I2C_REV_ON_3430_3530) { 467 467 /* Not implemented */ 468 - dev->bb_valid = 1; 468 + omap->bb_valid = 1; 469 469 } 470 470 471 - __omap_i2c_init(dev); 471 + __omap_i2c_init(omap); 472 472 473 473 return 0; 474 474 } ··· 476 476 /* 477 477 * Waiting on Bus Busy 478 478 */ 479 - static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev) 479 + static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap) 480 480 { 481 481 unsigned long timeout; 482 482 483 483 timeout = jiffies + OMAP_I2C_TIMEOUT; 484 - while (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { 484 + while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { 485 485 if (time_after(jiffies, timeout)) 486 - return i2c_recover_bus(&dev->adapter); 486 + return i2c_recover_bus(&omap->adapter); 487 487 msleep(1); 488 488 } 489 489 ··· 518 518 * 3. Any transfer started in the middle of another master's transfer 519 519 * results in unpredictable results and data corruption 520 520 */ 521 - static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *dev) 521 + static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap) 522 522 { 523 523 unsigned long bus_free_timeout = 0; 524 524 unsigned long timeout; 525 525 int bus_free = 0; 526 526 u16 stat, systest; 527 527 528 - if (dev->bb_valid) 528 + if (omap->bb_valid) 529 529 return 0; 530 530 531 531 timeout = jiffies + OMAP_I2C_TIMEOUT; 532 532 while (1) { 533 - stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); 533 + stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG); 534 534 /* 535 535 * We will see BB or BF event in a case IP had detected any 536 536 * activity on the I2C bus. Now IP correctly tracks the bus ··· 543 543 * Otherwise, we must look signals on the bus to make 544 544 * the right decision. 545 545 */ 546 - systest = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG); 546 + systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG); 547 547 if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) && 548 548 (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC)) { 549 549 if (!bus_free) { ··· 564 564 } 565 565 566 566 if (time_after(jiffies, timeout)) { 567 - dev_warn(dev->dev, "timeout waiting for bus ready\n"); 567 + dev_warn(omap->dev, "timeout waiting for bus ready\n"); 568 568 return -ETIMEDOUT; 569 569 } 570 570 571 571 msleep(1); 572 572 } 573 573 574 - dev->bb_valid = 1; 574 + omap->bb_valid = 1; 575 575 return 0; 576 576 } 577 577 578 - static void omap_i2c_resize_fifo(struct omap_i2c_dev *dev, u8 size, bool is_rx) 578 + static void omap_i2c_resize_fifo(struct omap_i2c_dev *omap, u8 size, bool is_rx) 579 579 { 580 580 u16 buf; 581 581 582 - if (dev->flags & OMAP_I2C_FLAG_NO_FIFO) 582 + if (omap->flags & OMAP_I2C_FLAG_NO_FIFO) 583 583 return; 584 584 585 585 /* ··· 589 589 * then we might use draining feature to transfer the remaining bytes. 590 590 */ 591 591 592 - dev->threshold = clamp(size, (u8) 1, dev->fifo_size); 592 + omap->threshold = clamp(size, (u8) 1, omap->fifo_size); 593 593 594 - buf = omap_i2c_read_reg(dev, OMAP_I2C_BUF_REG); 594 + buf = omap_i2c_read_reg(omap, OMAP_I2C_BUF_REG); 595 595 596 596 if (is_rx) { 597 597 /* Clear RX Threshold */ 598 598 buf &= ~(0x3f << 8); 599 - buf |= ((dev->threshold - 1) << 8) | OMAP_I2C_BUF_RXFIF_CLR; 599 + buf |= ((omap->threshold - 1) << 8) | OMAP_I2C_BUF_RXFIF_CLR; 600 600 } else { 601 601 /* Clear TX Threshold */ 602 602 buf &= ~0x3f; 603 - buf |= (dev->threshold - 1) | OMAP_I2C_BUF_TXFIF_CLR; 603 + buf |= (omap->threshold - 1) | OMAP_I2C_BUF_TXFIF_CLR; 604 604 } 605 605 606 - omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, buf); 606 + omap_i2c_write_reg(omap, OMAP_I2C_BUF_REG, buf); 607 607 608 - if (dev->rev < OMAP_I2C_REV_ON_3630) 609 - dev->b_hw = 1; /* Enable hardware fixes */ 608 + if (omap->rev < OMAP_I2C_REV_ON_3630) 609 + omap->b_hw = 1; /* Enable hardware fixes */ 610 610 611 611 /* calculate wakeup latency constraint for MPU */ 612 - if (dev->set_mpu_wkup_lat != NULL) 613 - dev->latency = (1000000 * dev->threshold) / 614 - (1000 * dev->speed / 8); 612 + if (omap->set_mpu_wkup_lat != NULL) 613 + omap->latency = (1000000 * omap->threshold) / 614 + (1000 * omap->speed / 8); 615 615 } 616 616 617 617 /* ··· 620 620 static int omap_i2c_xfer_msg(struct i2c_adapter *adap, 621 621 struct i2c_msg *msg, int stop) 622 622 { 623 - struct omap_i2c_dev *dev = i2c_get_adapdata(adap); 623 + struct omap_i2c_dev *omap = i2c_get_adapdata(adap); 624 624 unsigned long timeout; 625 625 u16 w; 626 626 627 - dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n", 627 + dev_dbg(omap->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n", 628 628 msg->addr, msg->len, msg->flags, stop); 629 629 630 630 if (msg->len == 0) 631 631 return -EINVAL; 632 632 633 - dev->receiver = !!(msg->flags & I2C_M_RD); 634 - omap_i2c_resize_fifo(dev, msg->len, dev->receiver); 633 + omap->receiver = !!(msg->flags & I2C_M_RD); 634 + omap_i2c_resize_fifo(omap, msg->len, omap->receiver); 635 635 636 - omap_i2c_write_reg(dev, OMAP_I2C_SA_REG, msg->addr); 636 + omap_i2c_write_reg(omap, OMAP_I2C_SA_REG, msg->addr); 637 637 638 638 /* REVISIT: Could the STB bit of I2C_CON be used with probing? */ 639 - dev->buf = msg->buf; 640 - dev->buf_len = msg->len; 639 + omap->buf = msg->buf; 640 + omap->buf_len = msg->len; 641 641 642 - /* make sure writes to dev->buf_len are ordered */ 642 + /* make sure writes to omap->buf_len are ordered */ 643 643 barrier(); 644 644 645 - omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len); 645 + omap_i2c_write_reg(omap, OMAP_I2C_CNT_REG, omap->buf_len); 646 646 647 647 /* Clear the FIFO Buffers */ 648 - w = omap_i2c_read_reg(dev, OMAP_I2C_BUF_REG); 648 + w = omap_i2c_read_reg(omap, OMAP_I2C_BUF_REG); 649 649 w |= OMAP_I2C_BUF_RXFIF_CLR | OMAP_I2C_BUF_TXFIF_CLR; 650 - omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, w); 650 + omap_i2c_write_reg(omap, OMAP_I2C_BUF_REG, w); 651 651 652 - reinit_completion(&dev->cmd_complete); 653 - dev->cmd_err = 0; 652 + reinit_completion(&omap->cmd_complete); 653 + omap->cmd_err = 0; 654 654 655 655 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT; 656 656 657 657 /* High speed configuration */ 658 - if (dev->speed > 400) 658 + if (omap->speed > 400) 659 659 w |= OMAP_I2C_CON_OPMODE_HS; 660 660 661 661 if (msg->flags & I2C_M_STOP) ··· 665 665 if (!(msg->flags & I2C_M_RD)) 666 666 w |= OMAP_I2C_CON_TRX; 667 667 668 - if (!dev->b_hw && stop) 668 + if (!omap->b_hw && stop) 669 669 w |= OMAP_I2C_CON_STP; 670 670 /* 671 671 * NOTE: STAT_BB bit could became 1 here if another master occupy 672 672 * the bus. IP successfully complete transfer when the bus will be 673 673 * free again (BB reset to 0). 674 674 */ 675 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 675 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, w); 676 676 677 677 /* 678 678 * Don't write stt and stp together on some hardware. 679 679 */ 680 - if (dev->b_hw && stop) { 680 + if (omap->b_hw && stop) { 681 681 unsigned long delay = jiffies + OMAP_I2C_TIMEOUT; 682 - u16 con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 682 + u16 con = omap_i2c_read_reg(omap, OMAP_I2C_CON_REG); 683 683 while (con & OMAP_I2C_CON_STT) { 684 - con = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 684 + con = omap_i2c_read_reg(omap, OMAP_I2C_CON_REG); 685 685 686 686 /* Let the user know if i2c is in a bad state */ 687 687 if (time_after(jiffies, delay)) { 688 - dev_err(dev->dev, "controller timed out " 688 + dev_err(omap->dev, "controller timed out " 689 689 "waiting for start condition to finish\n"); 690 690 return -ETIMEDOUT; 691 691 } ··· 694 694 695 695 w |= OMAP_I2C_CON_STP; 696 696 w &= ~OMAP_I2C_CON_STT; 697 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 697 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, w); 698 698 } 699 699 700 700 /* 701 701 * REVISIT: We should abort the transfer on signals, but the bus goes 702 702 * into arbitration and we're currently unable to recover from it. 703 703 */ 704 - timeout = wait_for_completion_timeout(&dev->cmd_complete, 704 + timeout = wait_for_completion_timeout(&omap->cmd_complete, 705 705 OMAP_I2C_TIMEOUT); 706 706 if (timeout == 0) { 707 - dev_err(dev->dev, "controller timed out\n"); 708 - omap_i2c_reset(dev); 709 - __omap_i2c_init(dev); 707 + dev_err(omap->dev, "controller timed out\n"); 708 + omap_i2c_reset(omap); 709 + __omap_i2c_init(omap); 710 710 return -ETIMEDOUT; 711 711 } 712 712 713 - if (likely(!dev->cmd_err)) 713 + if (likely(!omap->cmd_err)) 714 714 return 0; 715 715 716 716 /* We have an error */ 717 - if (dev->cmd_err & (OMAP_I2C_STAT_ROVR | OMAP_I2C_STAT_XUDF)) { 718 - omap_i2c_reset(dev); 719 - __omap_i2c_init(dev); 717 + if (omap->cmd_err & (OMAP_I2C_STAT_ROVR | OMAP_I2C_STAT_XUDF)) { 718 + omap_i2c_reset(omap); 719 + __omap_i2c_init(omap); 720 720 return -EIO; 721 721 } 722 722 723 - if (dev->cmd_err & OMAP_I2C_STAT_AL) 723 + if (omap->cmd_err & OMAP_I2C_STAT_AL) 724 724 return -EAGAIN; 725 725 726 - if (dev->cmd_err & OMAP_I2C_STAT_NACK) { 726 + if (omap->cmd_err & OMAP_I2C_STAT_NACK) { 727 727 if (msg->flags & I2C_M_IGNORE_NAK) 728 728 return 0; 729 729 730 - w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 730 + w = omap_i2c_read_reg(omap, OMAP_I2C_CON_REG); 731 731 w |= OMAP_I2C_CON_STP; 732 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 732 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, w); 733 733 return -EREMOTEIO; 734 734 } 735 735 return -EIO; ··· 743 743 static int 744 744 omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 745 745 { 746 - struct omap_i2c_dev *dev = i2c_get_adapdata(adap); 746 + struct omap_i2c_dev *omap = i2c_get_adapdata(adap); 747 747 int i; 748 748 int r; 749 749 750 - r = pm_runtime_get_sync(dev->dev); 750 + r = pm_runtime_get_sync(omap->dev); 751 751 if (r < 0) 752 752 goto out; 753 753 754 - r = omap_i2c_wait_for_bb_valid(dev); 754 + r = omap_i2c_wait_for_bb_valid(omap); 755 755 if (r < 0) 756 756 goto out; 757 757 758 - r = omap_i2c_wait_for_bb(dev); 758 + r = omap_i2c_wait_for_bb(omap); 759 759 if (r < 0) 760 760 goto out; 761 761 762 - if (dev->set_mpu_wkup_lat != NULL) 763 - dev->set_mpu_wkup_lat(dev->dev, dev->latency); 762 + if (omap->set_mpu_wkup_lat != NULL) 763 + omap->set_mpu_wkup_lat(omap->dev, omap->latency); 764 764 765 765 for (i = 0; i < num; i++) { 766 766 r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1))); ··· 771 771 if (r == 0) 772 772 r = num; 773 773 774 - omap_i2c_wait_for_bb(dev); 774 + omap_i2c_wait_for_bb(omap); 775 775 776 - if (dev->set_mpu_wkup_lat != NULL) 777 - dev->set_mpu_wkup_lat(dev->dev, -1); 776 + if (omap->set_mpu_wkup_lat != NULL) 777 + omap->set_mpu_wkup_lat(omap->dev, -1); 778 778 779 779 out: 780 - pm_runtime_mark_last_busy(dev->dev); 781 - pm_runtime_put_autosuspend(dev->dev); 780 + pm_runtime_mark_last_busy(omap->dev); 781 + pm_runtime_put_autosuspend(omap->dev); 782 782 return r; 783 783 } 784 784 ··· 790 790 } 791 791 792 792 static inline void 793 - omap_i2c_complete_cmd(struct omap_i2c_dev *dev, u16 err) 793 + omap_i2c_complete_cmd(struct omap_i2c_dev *omap, u16 err) 794 794 { 795 - dev->cmd_err |= err; 796 - complete(&dev->cmd_complete); 795 + omap->cmd_err |= err; 796 + complete(&omap->cmd_complete); 797 797 } 798 798 799 799 static inline void 800 - omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat) 800 + omap_i2c_ack_stat(struct omap_i2c_dev *omap, u16 stat) 801 801 { 802 - omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); 802 + omap_i2c_write_reg(omap, OMAP_I2C_STAT_REG, stat); 803 803 } 804 804 805 - static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat) 805 + static inline void i2c_omap_errata_i207(struct omap_i2c_dev *omap, u16 stat) 806 806 { 807 807 /* 808 808 * I2C Errata(Errata Nos. OMAP2: 1.67, OMAP3: 1.8) ··· 813 813 */ 814 814 if (stat & OMAP_I2C_STAT_RDR) { 815 815 /* Step 1: If RDR is set, clear it */ 816 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); 816 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR); 817 817 818 818 /* Step 2: */ 819 - if (!(omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) 819 + if (!(omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) 820 820 & OMAP_I2C_STAT_BB)) { 821 821 822 822 /* Step 3: */ 823 - if (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) 823 + if (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) 824 824 & OMAP_I2C_STAT_RDR) { 825 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); 826 - dev_dbg(dev->dev, "RDR when bus is busy.\n"); 825 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR); 826 + dev_dbg(omap->dev, "RDR when bus is busy.\n"); 827 827 } 828 828 829 829 } ··· 836 836 static irqreturn_t 837 837 omap_i2c_omap1_isr(int this_irq, void *dev_id) 838 838 { 839 - struct omap_i2c_dev *dev = dev_id; 839 + struct omap_i2c_dev *omap = dev_id; 840 840 u16 iv, w; 841 841 842 - if (pm_runtime_suspended(dev->dev)) 842 + if (pm_runtime_suspended(omap->dev)) 843 843 return IRQ_NONE; 844 844 845 - iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); 845 + iv = omap_i2c_read_reg(omap, OMAP_I2C_IV_REG); 846 846 switch (iv) { 847 847 case 0x00: /* None */ 848 848 break; 849 849 case 0x01: /* Arbitration lost */ 850 - dev_err(dev->dev, "Arbitration lost\n"); 851 - omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL); 850 + dev_err(omap->dev, "Arbitration lost\n"); 851 + omap_i2c_complete_cmd(omap, OMAP_I2C_STAT_AL); 852 852 break; 853 853 case 0x02: /* No acknowledgement */ 854 - omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK); 855 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP); 854 + omap_i2c_complete_cmd(omap, OMAP_I2C_STAT_NACK); 855 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP); 856 856 break; 857 857 case 0x03: /* Register access ready */ 858 - omap_i2c_complete_cmd(dev, 0); 858 + omap_i2c_complete_cmd(omap, 0); 859 859 break; 860 860 case 0x04: /* Receive data ready */ 861 - if (dev->buf_len) { 862 - w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); 863 - *dev->buf++ = w; 864 - dev->buf_len--; 865 - if (dev->buf_len) { 866 - *dev->buf++ = w >> 8; 867 - dev->buf_len--; 861 + if (omap->buf_len) { 862 + w = omap_i2c_read_reg(omap, OMAP_I2C_DATA_REG); 863 + *omap->buf++ = w; 864 + omap->buf_len--; 865 + if (omap->buf_len) { 866 + *omap->buf++ = w >> 8; 867 + omap->buf_len--; 868 868 } 869 869 } else 870 - dev_err(dev->dev, "RRDY IRQ while no data requested\n"); 870 + dev_err(omap->dev, "RRDY IRQ while no data requested\n"); 871 871 break; 872 872 case 0x05: /* Transmit data ready */ 873 - if (dev->buf_len) { 874 - w = *dev->buf++; 875 - dev->buf_len--; 876 - if (dev->buf_len) { 877 - w |= *dev->buf++ << 8; 878 - dev->buf_len--; 873 + if (omap->buf_len) { 874 + w = *omap->buf++; 875 + omap->buf_len--; 876 + if (omap->buf_len) { 877 + w |= *omap->buf++ << 8; 878 + omap->buf_len--; 879 879 } 880 - omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 880 + omap_i2c_write_reg(omap, OMAP_I2C_DATA_REG, w); 881 881 } else 882 - dev_err(dev->dev, "XRDY IRQ while no data to send\n"); 882 + dev_err(omap->dev, "XRDY IRQ while no data to send\n"); 883 883 break; 884 884 default: 885 885 return IRQ_NONE; ··· 896 896 * data to DATA_REG. Otherwise some data bytes can be lost while transferring 897 897 * them from the memory to the I2C interface. 898 898 */ 899 - static int errata_omap3_i462(struct omap_i2c_dev *dev) 899 + static int errata_omap3_i462(struct omap_i2c_dev *omap) 900 900 { 901 901 unsigned long timeout = 10000; 902 902 u16 stat; 903 903 904 904 do { 905 - stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); 905 + stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG); 906 906 if (stat & OMAP_I2C_STAT_XUDF) 907 907 break; 908 908 909 909 if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) { 910 - omap_i2c_ack_stat(dev, (OMAP_I2C_STAT_XRDY | 910 + omap_i2c_ack_stat(omap, (OMAP_I2C_STAT_XRDY | 911 911 OMAP_I2C_STAT_XDR)); 912 912 if (stat & OMAP_I2C_STAT_NACK) { 913 - dev->cmd_err |= OMAP_I2C_STAT_NACK; 914 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK); 913 + omap->cmd_err |= OMAP_I2C_STAT_NACK; 914 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_NACK); 915 915 } 916 916 917 917 if (stat & OMAP_I2C_STAT_AL) { 918 - dev_err(dev->dev, "Arbitration lost\n"); 919 - dev->cmd_err |= OMAP_I2C_STAT_AL; 920 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL); 918 + dev_err(omap->dev, "Arbitration lost\n"); 919 + omap->cmd_err |= OMAP_I2C_STAT_AL; 920 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_AL); 921 921 } 922 922 923 923 return -EIO; ··· 927 927 } while (--timeout); 928 928 929 929 if (!timeout) { 930 - dev_err(dev->dev, "timeout waiting on XUDF bit\n"); 930 + dev_err(omap->dev, "timeout waiting on XUDF bit\n"); 931 931 return 0; 932 932 } 933 933 934 934 return 0; 935 935 } 936 936 937 - static void omap_i2c_receive_data(struct omap_i2c_dev *dev, u8 num_bytes, 937 + static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes, 938 938 bool is_rdr) 939 939 { 940 940 u16 w; 941 941 942 942 while (num_bytes--) { 943 - w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG); 944 - *dev->buf++ = w; 945 - dev->buf_len--; 943 + w = omap_i2c_read_reg(omap, OMAP_I2C_DATA_REG); 944 + *omap->buf++ = w; 945 + omap->buf_len--; 946 946 947 947 /* 948 948 * Data reg in 2430, omap3 and 949 949 * omap4 is 8 bit wide 950 950 */ 951 - if (dev->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { 952 - *dev->buf++ = w >> 8; 953 - dev->buf_len--; 951 + if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { 952 + *omap->buf++ = w >> 8; 953 + omap->buf_len--; 954 954 } 955 955 } 956 956 } 957 957 958 - static int omap_i2c_transmit_data(struct omap_i2c_dev *dev, u8 num_bytes, 958 + static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes, 959 959 bool is_xdr) 960 960 { 961 961 u16 w; 962 962 963 963 while (num_bytes--) { 964 - w = *dev->buf++; 965 - dev->buf_len--; 964 + w = *omap->buf++; 965 + omap->buf_len--; 966 966 967 967 /* 968 968 * Data reg in 2430, omap3 and 969 969 * omap4 is 8 bit wide 970 970 */ 971 - if (dev->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { 972 - w |= *dev->buf++ << 8; 973 - dev->buf_len--; 971 + if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) { 972 + w |= *omap->buf++ << 8; 973 + omap->buf_len--; 974 974 } 975 975 976 - if (dev->errata & I2C_OMAP_ERRATA_I462) { 976 + if (omap->errata & I2C_OMAP_ERRATA_I462) { 977 977 int ret; 978 978 979 - ret = errata_omap3_i462(dev); 979 + ret = errata_omap3_i462(omap); 980 980 if (ret < 0) 981 981 return ret; 982 982 } 983 983 984 - omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 984 + omap_i2c_write_reg(omap, OMAP_I2C_DATA_REG, w); 985 985 } 986 986 987 987 return 0; ··· 990 990 static irqreturn_t 991 991 omap_i2c_isr(int irq, void *dev_id) 992 992 { 993 - struct omap_i2c_dev *dev = dev_id; 993 + struct omap_i2c_dev *omap = dev_id; 994 994 irqreturn_t ret = IRQ_HANDLED; 995 995 u16 mask; 996 996 u16 stat; 997 997 998 - spin_lock(&dev->lock); 999 - mask = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 1000 - stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); 998 + spin_lock(&omap->lock); 999 + mask = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG); 1000 + stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG); 1001 1001 1002 1002 if (stat & mask) 1003 1003 ret = IRQ_WAKE_THREAD; 1004 1004 1005 - spin_unlock(&dev->lock); 1005 + spin_unlock(&omap->lock); 1006 1006 1007 1007 return ret; 1008 1008 } ··· 1010 1010 static irqreturn_t 1011 1011 omap_i2c_isr_thread(int this_irq, void *dev_id) 1012 1012 { 1013 - struct omap_i2c_dev *dev = dev_id; 1013 + struct omap_i2c_dev *omap = dev_id; 1014 1014 unsigned long flags; 1015 1015 u16 bits; 1016 1016 u16 stat; 1017 1017 int err = 0, count = 0; 1018 1018 1019 - spin_lock_irqsave(&dev->lock, flags); 1019 + spin_lock_irqsave(&omap->lock, flags); 1020 1020 do { 1021 - bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); 1022 - stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); 1021 + bits = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG); 1022 + stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG); 1023 1023 stat &= bits; 1024 1024 1025 1025 /* If we're in receiver mode, ignore XDR/XRDY */ 1026 - if (dev->receiver) 1026 + if (omap->receiver) 1027 1027 stat &= ~(OMAP_I2C_STAT_XDR | OMAP_I2C_STAT_XRDY); 1028 1028 else 1029 1029 stat &= ~(OMAP_I2C_STAT_RDR | OMAP_I2C_STAT_RRDY); ··· 1033 1033 goto out; 1034 1034 } 1035 1035 1036 - dev_dbg(dev->dev, "IRQ (ISR = 0x%04x)\n", stat); 1036 + dev_dbg(omap->dev, "IRQ (ISR = 0x%04x)\n", stat); 1037 1037 if (count++ == 100) { 1038 - dev_warn(dev->dev, "Too much work in one IRQ\n"); 1038 + dev_warn(omap->dev, "Too much work in one IRQ\n"); 1039 1039 break; 1040 1040 } 1041 1041 1042 1042 if (stat & OMAP_I2C_STAT_NACK) { 1043 1043 err |= OMAP_I2C_STAT_NACK; 1044 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK); 1044 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_NACK); 1045 1045 } 1046 1046 1047 1047 if (stat & OMAP_I2C_STAT_AL) { 1048 - dev_err(dev->dev, "Arbitration lost\n"); 1048 + dev_err(omap->dev, "Arbitration lost\n"); 1049 1049 err |= OMAP_I2C_STAT_AL; 1050 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL); 1050 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_AL); 1051 1051 } 1052 1052 1053 1053 /* 1054 1054 * ProDB0017052: Clear ARDY bit twice 1055 1055 */ 1056 1056 if (stat & OMAP_I2C_STAT_ARDY) 1057 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_ARDY); 1057 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_ARDY); 1058 1058 1059 1059 if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK | 1060 1060 OMAP_I2C_STAT_AL)) { 1061 - omap_i2c_ack_stat(dev, (OMAP_I2C_STAT_RRDY | 1061 + omap_i2c_ack_stat(omap, (OMAP_I2C_STAT_RRDY | 1062 1062 OMAP_I2C_STAT_RDR | 1063 1063 OMAP_I2C_STAT_XRDY | 1064 1064 OMAP_I2C_STAT_XDR | ··· 1069 1069 if (stat & OMAP_I2C_STAT_RDR) { 1070 1070 u8 num_bytes = 1; 1071 1071 1072 - if (dev->fifo_size) 1073 - num_bytes = dev->buf_len; 1072 + if (omap->fifo_size) 1073 + num_bytes = omap->buf_len; 1074 1074 1075 - if (dev->errata & I2C_OMAP_ERRATA_I207) { 1076 - i2c_omap_errata_i207(dev, stat); 1077 - num_bytes = (omap_i2c_read_reg(dev, 1075 + if (omap->errata & I2C_OMAP_ERRATA_I207) { 1076 + i2c_omap_errata_i207(omap, stat); 1077 + num_bytes = (omap_i2c_read_reg(omap, 1078 1078 OMAP_I2C_BUFSTAT_REG) >> 8) & 0x3F; 1079 1079 } 1080 1080 1081 - omap_i2c_receive_data(dev, num_bytes, true); 1082 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); 1081 + omap_i2c_receive_data(omap, num_bytes, true); 1082 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR); 1083 1083 continue; 1084 1084 } 1085 1085 1086 1086 if (stat & OMAP_I2C_STAT_RRDY) { 1087 1087 u8 num_bytes = 1; 1088 1088 1089 - if (dev->threshold) 1090 - num_bytes = dev->threshold; 1089 + if (omap->threshold) 1090 + num_bytes = omap->threshold; 1091 1091 1092 - omap_i2c_receive_data(dev, num_bytes, false); 1093 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY); 1092 + omap_i2c_receive_data(omap, num_bytes, false); 1093 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RRDY); 1094 1094 continue; 1095 1095 } 1096 1096 ··· 1098 1098 u8 num_bytes = 1; 1099 1099 int ret; 1100 1100 1101 - if (dev->fifo_size) 1102 - num_bytes = dev->buf_len; 1101 + if (omap->fifo_size) 1102 + num_bytes = omap->buf_len; 1103 1103 1104 - ret = omap_i2c_transmit_data(dev, num_bytes, true); 1104 + ret = omap_i2c_transmit_data(omap, num_bytes, true); 1105 1105 if (ret < 0) 1106 1106 break; 1107 1107 1108 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XDR); 1108 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_XDR); 1109 1109 continue; 1110 1110 } 1111 1111 ··· 1113 1113 u8 num_bytes = 1; 1114 1114 int ret; 1115 1115 1116 - if (dev->threshold) 1117 - num_bytes = dev->threshold; 1116 + if (omap->threshold) 1117 + num_bytes = omap->threshold; 1118 1118 1119 - ret = omap_i2c_transmit_data(dev, num_bytes, false); 1119 + ret = omap_i2c_transmit_data(omap, num_bytes, false); 1120 1120 if (ret < 0) 1121 1121 break; 1122 1122 1123 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY); 1123 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_XRDY); 1124 1124 continue; 1125 1125 } 1126 1126 1127 1127 if (stat & OMAP_I2C_STAT_ROVR) { 1128 - dev_err(dev->dev, "Receive overrun\n"); 1128 + dev_err(omap->dev, "Receive overrun\n"); 1129 1129 err |= OMAP_I2C_STAT_ROVR; 1130 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_ROVR); 1130 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_ROVR); 1131 1131 break; 1132 1132 } 1133 1133 1134 1134 if (stat & OMAP_I2C_STAT_XUDF) { 1135 - dev_err(dev->dev, "Transmit underflow\n"); 1135 + dev_err(omap->dev, "Transmit underflow\n"); 1136 1136 err |= OMAP_I2C_STAT_XUDF; 1137 - omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XUDF); 1137 + omap_i2c_ack_stat(omap, OMAP_I2C_STAT_XUDF); 1138 1138 break; 1139 1139 } 1140 1140 } while (stat); 1141 1141 1142 - omap_i2c_complete_cmd(dev, err); 1142 + omap_i2c_complete_cmd(omap, err); 1143 1143 1144 1144 out: 1145 - spin_unlock_irqrestore(&dev->lock, flags); 1145 + spin_unlock_irqrestore(&omap->lock, flags); 1146 1146 1147 1147 return IRQ_HANDLED; 1148 1148 } ··· 1284 1284 static int 1285 1285 omap_i2c_probe(struct platform_device *pdev) 1286 1286 { 1287 - struct omap_i2c_dev *dev; 1287 + struct omap_i2c_dev *omap; 1288 1288 struct i2c_adapter *adap; 1289 1289 struct resource *mem; 1290 1290 const struct omap_i2c_bus_platform_data *pdata = ··· 1302 1302 return irq; 1303 1303 } 1304 1304 1305 - dev = devm_kzalloc(&pdev->dev, sizeof(struct omap_i2c_dev), GFP_KERNEL); 1306 - if (!dev) 1305 + omap = devm_kzalloc(&pdev->dev, sizeof(struct omap_i2c_dev), GFP_KERNEL); 1306 + if (!omap) 1307 1307 return -ENOMEM; 1308 1308 1309 1309 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1310 - dev->base = devm_ioremap_resource(&pdev->dev, mem); 1311 - if (IS_ERR(dev->base)) 1312 - return PTR_ERR(dev->base); 1310 + omap->base = devm_ioremap_resource(&pdev->dev, mem); 1311 + if (IS_ERR(omap->base)) 1312 + return PTR_ERR(omap->base); 1313 1313 1314 1314 match = of_match_device(of_match_ptr(omap_i2c_of_match), &pdev->dev); 1315 1315 if (match) { 1316 1316 u32 freq = 100000; /* default to 100000 Hz */ 1317 1317 1318 1318 pdata = match->data; 1319 - dev->flags = pdata->flags; 1319 + omap->flags = pdata->flags; 1320 1320 1321 1321 of_property_read_u32(node, "clock-frequency", &freq); 1322 1322 /* convert DT freq value in Hz into kHz for speed */ 1323 - dev->speed = freq / 1000; 1323 + omap->speed = freq / 1000; 1324 1324 } else if (pdata != NULL) { 1325 - dev->speed = pdata->clkrate; 1326 - dev->flags = pdata->flags; 1327 - dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat; 1325 + omap->speed = pdata->clkrate; 1326 + omap->flags = pdata->flags; 1327 + omap->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat; 1328 1328 } 1329 1329 1330 - dev->dev = &pdev->dev; 1331 - dev->irq = irq; 1330 + omap->dev = &pdev->dev; 1331 + omap->irq = irq; 1332 1332 1333 - spin_lock_init(&dev->lock); 1333 + spin_lock_init(&omap->lock); 1334 1334 1335 - platform_set_drvdata(pdev, dev); 1336 - init_completion(&dev->cmd_complete); 1335 + platform_set_drvdata(pdev, omap); 1336 + init_completion(&omap->cmd_complete); 1337 1337 1338 - dev->reg_shift = (dev->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3; 1338 + omap->reg_shift = (omap->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3; 1339 1339 1340 - pm_runtime_enable(dev->dev); 1341 - pm_runtime_set_autosuspend_delay(dev->dev, OMAP_I2C_PM_TIMEOUT); 1342 - pm_runtime_use_autosuspend(dev->dev); 1340 + pm_runtime_enable(omap->dev); 1341 + pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT); 1342 + pm_runtime_use_autosuspend(omap->dev); 1343 1343 1344 - r = pm_runtime_get_sync(dev->dev); 1344 + r = pm_runtime_get_sync(omap->dev); 1345 1345 if (r < 0) 1346 1346 goto err_free_mem; 1347 1347 ··· 1351 1351 * Also since the omap_i2c_read_reg uses reg_map_ip_* a 1352 1352 * readw_relaxed is done. 1353 1353 */ 1354 - rev = readw_relaxed(dev->base + 0x04); 1354 + rev = readw_relaxed(omap->base + 0x04); 1355 1355 1356 - dev->scheme = OMAP_I2C_SCHEME(rev); 1357 - switch (dev->scheme) { 1356 + omap->scheme = OMAP_I2C_SCHEME(rev); 1357 + switch (omap->scheme) { 1358 1358 case OMAP_I2C_SCHEME_0: 1359 - dev->regs = (u8 *)reg_map_ip_v1; 1360 - dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG); 1361 - minor = OMAP_I2C_REV_SCHEME_0_MAJOR(dev->rev); 1362 - major = OMAP_I2C_REV_SCHEME_0_MAJOR(dev->rev); 1359 + omap->regs = (u8 *)reg_map_ip_v1; 1360 + omap->rev = omap_i2c_read_reg(omap, OMAP_I2C_REV_REG); 1361 + minor = OMAP_I2C_REV_SCHEME_0_MAJOR(omap->rev); 1362 + major = OMAP_I2C_REV_SCHEME_0_MAJOR(omap->rev); 1363 1363 break; 1364 1364 case OMAP_I2C_SCHEME_1: 1365 1365 /* FALLTHROUGH */ 1366 1366 default: 1367 - dev->regs = (u8 *)reg_map_ip_v2; 1367 + omap->regs = (u8 *)reg_map_ip_v2; 1368 1368 rev = (rev << 16) | 1369 - omap_i2c_read_reg(dev, OMAP_I2C_IP_V2_REVNB_LO); 1369 + omap_i2c_read_reg(omap, OMAP_I2C_IP_V2_REVNB_LO); 1370 1370 minor = OMAP_I2C_REV_SCHEME_1_MINOR(rev); 1371 1371 major = OMAP_I2C_REV_SCHEME_1_MAJOR(rev); 1372 - dev->rev = rev; 1372 + omap->rev = rev; 1373 1373 } 1374 1374 1375 - dev->errata = 0; 1375 + omap->errata = 0; 1376 1376 1377 - if (dev->rev >= OMAP_I2C_REV_ON_2430 && 1378 - dev->rev < OMAP_I2C_REV_ON_4430_PLUS) 1379 - dev->errata |= I2C_OMAP_ERRATA_I207; 1377 + if (omap->rev >= OMAP_I2C_REV_ON_2430 && 1378 + omap->rev < OMAP_I2C_REV_ON_4430_PLUS) 1379 + omap->errata |= I2C_OMAP_ERRATA_I207; 1380 1380 1381 - if (dev->rev <= OMAP_I2C_REV_ON_3430_3530) 1382 - dev->errata |= I2C_OMAP_ERRATA_I462; 1381 + if (omap->rev <= OMAP_I2C_REV_ON_3430_3530) 1382 + omap->errata |= I2C_OMAP_ERRATA_I462; 1383 1383 1384 - if (!(dev->flags & OMAP_I2C_FLAG_NO_FIFO)) { 1384 + if (!(omap->flags & OMAP_I2C_FLAG_NO_FIFO)) { 1385 1385 u16 s; 1386 1386 1387 1387 /* Set up the fifo size - Get total size */ 1388 - s = (omap_i2c_read_reg(dev, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3; 1389 - dev->fifo_size = 0x8 << s; 1388 + s = (omap_i2c_read_reg(omap, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3; 1389 + omap->fifo_size = 0x8 << s; 1390 1390 1391 1391 /* 1392 1392 * Set up notification threshold as half the total available ··· 1394 1394 * call back latencies. 1395 1395 */ 1396 1396 1397 - dev->fifo_size = (dev->fifo_size / 2); 1397 + omap->fifo_size = (omap->fifo_size / 2); 1398 1398 1399 - if (dev->rev < OMAP_I2C_REV_ON_3630) 1400 - dev->b_hw = 1; /* Enable hardware fixes */ 1399 + if (omap->rev < OMAP_I2C_REV_ON_3630) 1400 + omap->b_hw = 1; /* Enable hardware fixes */ 1401 1401 1402 1402 /* calculate wakeup latency constraint for MPU */ 1403 - if (dev->set_mpu_wkup_lat != NULL) 1404 - dev->latency = (1000000 * dev->fifo_size) / 1405 - (1000 * dev->speed / 8); 1403 + if (omap->set_mpu_wkup_lat != NULL) 1404 + omap->latency = (1000000 * omap->fifo_size) / 1405 + (1000 * omap->speed / 8); 1406 1406 } 1407 1407 1408 1408 /* reset ASAP, clearing any IRQs */ 1409 - omap_i2c_init(dev); 1409 + omap_i2c_init(omap); 1410 1410 1411 - if (dev->rev < OMAP_I2C_OMAP1_REV_2) 1412 - r = devm_request_irq(&pdev->dev, dev->irq, omap_i2c_omap1_isr, 1413 - IRQF_NO_SUSPEND, pdev->name, dev); 1411 + if (omap->rev < OMAP_I2C_OMAP1_REV_2) 1412 + r = devm_request_irq(&pdev->dev, omap->irq, omap_i2c_omap1_isr, 1413 + IRQF_NO_SUSPEND, pdev->name, omap); 1414 1414 else 1415 - r = devm_request_threaded_irq(&pdev->dev, dev->irq, 1415 + r = devm_request_threaded_irq(&pdev->dev, omap->irq, 1416 1416 omap_i2c_isr, omap_i2c_isr_thread, 1417 1417 IRQF_NO_SUSPEND | IRQF_ONESHOT, 1418 - pdev->name, dev); 1418 + pdev->name, omap); 1419 1419 1420 1420 if (r) { 1421 - dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); 1421 + dev_err(omap->dev, "failure requesting irq %i\n", omap->irq); 1422 1422 goto err_unuse_clocks; 1423 1423 } 1424 1424 1425 - adap = &dev->adapter; 1426 - i2c_set_adapdata(adap, dev); 1425 + adap = &omap->adapter; 1426 + i2c_set_adapdata(adap, omap); 1427 1427 adap->owner = THIS_MODULE; 1428 1428 adap->class = I2C_CLASS_DEPRECATED; 1429 1429 strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); ··· 1436 1436 adap->nr = pdev->id; 1437 1437 r = i2c_add_numbered_adapter(adap); 1438 1438 if (r) { 1439 - dev_err(dev->dev, "failure adding adapter\n"); 1439 + dev_err(omap->dev, "failure adding adapter\n"); 1440 1440 goto err_unuse_clocks; 1441 1441 } 1442 1442 1443 - dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr, 1444 - major, minor, dev->speed); 1443 + dev_info(omap->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr, 1444 + major, minor, omap->speed); 1445 1445 1446 - pm_runtime_mark_last_busy(dev->dev); 1447 - pm_runtime_put_autosuspend(dev->dev); 1446 + pm_runtime_mark_last_busy(omap->dev); 1447 + pm_runtime_put_autosuspend(omap->dev); 1448 1448 1449 1449 return 0; 1450 1450 1451 1451 err_unuse_clocks: 1452 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 1453 - pm_runtime_put(dev->dev); 1452 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0); 1453 + pm_runtime_put(omap->dev); 1454 1454 pm_runtime_disable(&pdev->dev); 1455 1455 err_free_mem: 1456 1456 ··· 1459 1459 1460 1460 static int omap_i2c_remove(struct platform_device *pdev) 1461 1461 { 1462 - struct omap_i2c_dev *dev = platform_get_drvdata(pdev); 1462 + struct omap_i2c_dev *omap = platform_get_drvdata(pdev); 1463 1463 int ret; 1464 1464 1465 - i2c_del_adapter(&dev->adapter); 1465 + i2c_del_adapter(&omap->adapter); 1466 1466 ret = pm_runtime_get_sync(&pdev->dev); 1467 1467 if (ret < 0) 1468 1468 return ret; 1469 1469 1470 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 1471 - pm_runtime_put(&pdev->dev); 1470 + omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0); 1471 + pm_runtime_put_sync(&pdev->dev); 1472 1472 pm_runtime_disable(&pdev->dev); 1473 1473 return 0; 1474 1474 } ··· 1476 1476 #ifdef CONFIG_PM 1477 1477 static int omap_i2c_runtime_suspend(struct device *dev) 1478 1478 { 1479 - struct platform_device *pdev = to_platform_device(dev); 1480 - struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); 1479 + struct omap_i2c_dev *omap = dev_get_drvdata(dev); 1481 1480 1482 - _dev->iestate = omap_i2c_read_reg(_dev, OMAP_I2C_IE_REG); 1481 + omap->iestate = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG); 1483 1482 1484 - if (_dev->scheme == OMAP_I2C_SCHEME_0) 1485 - omap_i2c_write_reg(_dev, OMAP_I2C_IE_REG, 0); 1483 + if (omap->scheme == OMAP_I2C_SCHEME_0) 1484 + omap_i2c_write_reg(omap, OMAP_I2C_IE_REG, 0); 1486 1485 else 1487 - omap_i2c_write_reg(_dev, OMAP_I2C_IP_V2_IRQENABLE_CLR, 1486 + omap_i2c_write_reg(omap, OMAP_I2C_IP_V2_IRQENABLE_CLR, 1488 1487 OMAP_I2C_IP_V2_INTERRUPTS_MASK); 1489 1488 1490 - if (_dev->rev < OMAP_I2C_OMAP1_REV_2) { 1491 - omap_i2c_read_reg(_dev, OMAP_I2C_IV_REG); /* Read clears */ 1489 + if (omap->rev < OMAP_I2C_OMAP1_REV_2) { 1490 + omap_i2c_read_reg(omap, OMAP_I2C_IV_REG); /* Read clears */ 1492 1491 } else { 1493 - omap_i2c_write_reg(_dev, OMAP_I2C_STAT_REG, _dev->iestate); 1492 + omap_i2c_write_reg(omap, OMAP_I2C_STAT_REG, omap->iestate); 1494 1493 1495 1494 /* Flush posted write */ 1496 - omap_i2c_read_reg(_dev, OMAP_I2C_STAT_REG); 1495 + omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG); 1497 1496 } 1498 1497 1499 1498 pinctrl_pm_select_sleep_state(dev); ··· 1502 1503 1503 1504 static int omap_i2c_runtime_resume(struct device *dev) 1504 1505 { 1505 - struct platform_device *pdev = to_platform_device(dev); 1506 - struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); 1506 + struct omap_i2c_dev *omap = dev_get_drvdata(dev); 1507 1507 1508 1508 pinctrl_pm_select_default_state(dev); 1509 1509 1510 - if (!_dev->regs) 1510 + if (!omap->regs) 1511 1511 return 0; 1512 1512 1513 - __omap_i2c_init(_dev); 1513 + __omap_i2c_init(omap); 1514 1514 1515 1515 return 0; 1516 1516 }
+13 -12
drivers/i2c/busses/i2c-parport.c
··· 20 20 GNU General Public License for more details. 21 21 * ------------------------------------------------------------------------ */ 22 22 23 + #define pr_fmt(fmt) "i2c-parport: " fmt 24 + 23 25 #include <linux/kernel.h> 24 26 #include <linux/module.h> 25 27 #include <linux/init.h> ··· 178 176 break; 179 177 } 180 178 if (i == MAX_DEVICE) { 181 - pr_debug("i2c-parport: Not using parport%d.\n", port->number); 179 + pr_debug("Not using parport%d.\n", port->number); 182 180 return; 183 181 } 184 182 185 183 adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL); 186 - if (adapter == NULL) { 187 - printk(KERN_ERR "i2c-parport: Failed to kzalloc\n"); 184 + if (!adapter) 188 185 return; 189 - } 190 186 memset(&i2c_parport_cb, 0, sizeof(i2c_parport_cb)); 191 187 i2c_parport_cb.flags = PARPORT_FLAG_EXCL; 192 188 i2c_parport_cb.irq_func = i2c_parport_irq; 193 189 i2c_parport_cb.private = adapter; 194 190 195 - pr_debug("i2c-parport: attaching to %s\n", port->name); 191 + pr_debug("attaching to %s\n", port->name); 196 192 parport_disable_irq(port); 197 193 adapter->pdev = parport_register_dev_model(port, "i2c-parport", 198 194 &i2c_parport_cb, i); 199 195 if (!adapter->pdev) { 200 - printk(KERN_ERR "i2c-parport: Unable to register with parport\n"); 196 + pr_err("Unable to register with parport\n"); 201 197 goto err_free; 202 198 } 203 199 ··· 215 215 adapter->adapter.dev.parent = port->physport->dev; 216 216 217 217 if (parport_claim_or_block(adapter->pdev) < 0) { 218 - printk(KERN_ERR "i2c-parport: Could not claim parallel port\n"); 218 + dev_err(&adapter->pdev->dev, 219 + "Could not claim parallel port\n"); 219 220 goto err_unregister; 220 221 } 221 222 ··· 231 230 } 232 231 233 232 if (i2c_bit_add_bus(&adapter->adapter) < 0) { 234 - printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); 233 + dev_err(&adapter->pdev->dev, "Unable to register with I2C\n"); 235 234 goto err_unregister; 236 235 } 237 236 ··· 243 242 if (adapter->ara) 244 243 parport_enable_irq(port); 245 244 else 246 - printk(KERN_WARNING "i2c-parport: Failed to register " 247 - "ARA client\n"); 245 + dev_warn(&adapter->pdev->dev, 246 + "Failed to register ARA client\n"); 248 247 } 249 248 250 249 /* Add the new adapter to the list */ ··· 299 298 static int __init i2c_parport_init(void) 300 299 { 301 300 if (type < 0) { 302 - printk(KERN_WARNING "i2c-parport: adapter type unspecified\n"); 301 + pr_warn("adapter type unspecified\n"); 303 302 return -ENODEV; 304 303 } 305 304 306 305 if (type >= ARRAY_SIZE(adapter_parm)) { 307 - printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); 306 + pr_warn("invalid type (%d)\n", type); 308 307 return -ENODEV; 309 308 } 310 309
+8
drivers/i2c/busses/i2c-parport.h
··· 89 89 .getsda = { 0x80, PORT_STAT, 1 }, 90 90 .init = { 0x04, PORT_DATA, 1 }, 91 91 }, 92 + /* type 8: VCT-jig */ 93 + { 94 + .setsda = { 0x04, PORT_DATA, 1 }, 95 + .setscl = { 0x01, PORT_DATA, 1 }, 96 + .getsda = { 0x40, PORT_STAT, 0 }, 97 + .getscl = { 0x80, PORT_STAT, 1 }, 98 + }, 92 99 }; 93 100 94 101 static int type = -1; ··· 110 103 " 5 = ADM1025, ADM1030 and ADM1031 evaluation boards\n" 111 104 " 6 = Barco LPT->DVI (K5800236) adapter\n" 112 105 " 7 = One For All JP1 parallel port adapter\n" 106 + " 8 = VCT-jig\n" 113 107 );
+50 -62
drivers/i2c/busses/i2c-pxa.c
··· 132 132 unsigned int msg_idx; 133 133 unsigned int msg_ptr; 134 134 unsigned int slave_addr; 135 + unsigned int req_slave_addr; 135 136 136 137 struct i2c_adapter adap; 137 138 struct clk *clk; ··· 254 253 static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) 255 254 { 256 255 unsigned int i; 257 - printk(KERN_ERR "i2c: error: %s\n", why); 258 - printk(KERN_ERR "i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n", 256 + struct device *dev = &i2c->adap.dev; 257 + 258 + dev_err(dev, "slave_0x%x error: %s\n", 259 + i2c->req_slave_addr >> 1, why); 260 + dev_err(dev, "msg_num: %d msg_idx: %d msg_ptr: %d\n", 259 261 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); 260 - printk(KERN_ERR "i2c: ICR: %08x ISR: %08x\n", 261 - readl(_ICR(i2c)), readl(_ISR(i2c))); 262 - printk(KERN_DEBUG "i2c: log: "); 262 + dev_err(dev, "IBMR: %08x IDBR: %08x ICR: %08x ISR: %08x\n", 263 + readl(_IBMR(i2c)), readl(_IDBR(i2c)), readl(_ICR(i2c)), 264 + readl(_ISR(i2c))); 265 + dev_dbg(dev, "log: "); 263 266 for (i = 0; i < i2c->irqlogidx; i++) 264 - printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]); 265 - printk("\n"); 267 + pr_debug("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]); 268 + 269 + pr_debug("\n"); 266 270 } 267 271 268 272 #else /* ifdef DEBUG */ ··· 465 459 writel(I2C_ISR_INIT, _ISR(i2c)); 466 460 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c)); 467 461 468 - if (i2c->reg_isar) 462 + if (i2c->reg_isar && IS_ENABLED(CONFIG_I2C_PXA_SLAVE)) 469 463 writel(i2c->slave_addr, _ISAR(i2c)); 470 464 471 465 /* set control register values */ ··· 644 638 * Step 1: target slave address into IDBR 645 639 */ 646 640 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c)); 641 + i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg); 647 642 648 643 /* 649 644 * Step 2: initiate the write. ··· 752 745 ret = i2c->msg_idx; 753 746 754 747 out: 755 - if (timeout == 0) 748 + if (timeout == 0) { 756 749 i2c_pxa_scream_blue_murder(i2c, "timeout"); 750 + ret = I2C_RETRY; 751 + } 757 752 758 753 return ret; 759 754 } ··· 958 949 * Write the next address. 959 950 */ 960 951 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c)); 952 + i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg); 961 953 962 954 /* 963 955 * And trigger a repeated start, and send the byte. ··· 1124 1114 i2c->use_pio = 1; 1125 1115 if (of_get_property(np, "mrvl,i2c-fast-mode", NULL)) 1126 1116 i2c->fast_mode = 1; 1127 - *i2c_types = (u32)(of_id->data); 1117 + 1118 + *i2c_types = (enum pxa_i2c_types)(of_id->data); 1119 + 1128 1120 return 0; 1129 1121 } 1130 1122 ··· 1158 1146 struct resource *res = NULL; 1159 1147 int ret, irq; 1160 1148 1161 - i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL); 1162 - if (!i2c) { 1163 - ret = -ENOMEM; 1164 - goto emalloc; 1149 + i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); 1150 + if (!i2c) 1151 + return -ENOMEM; 1152 + 1153 + res = platform_get_resource(dev, IORESOURCE_MEM, 0); 1154 + i2c->reg_base = devm_ioremap_resource(&dev->dev, res); 1155 + if (IS_ERR(i2c->reg_base)) 1156 + return PTR_ERR(i2c->reg_base); 1157 + 1158 + irq = platform_get_irq(dev, 0); 1159 + if (irq < 0) { 1160 + dev_err(&dev->dev, "no irq resource: %d\n", irq); 1161 + return irq; 1165 1162 } 1166 1163 1167 1164 /* Default adapter num to device id; i2c_pxa_probe_dt can override. */ ··· 1180 1159 if (ret > 0) 1181 1160 ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); 1182 1161 if (ret < 0) 1183 - goto eclk; 1184 - 1185 - res = platform_get_resource(dev, IORESOURCE_MEM, 0); 1186 - irq = platform_get_irq(dev, 0); 1187 - if (res == NULL || irq < 0) { 1188 - ret = -ENODEV; 1189 - goto eclk; 1190 - } 1191 - 1192 - if (!request_mem_region(res->start, resource_size(res), res->name)) { 1193 - ret = -ENOMEM; 1194 - goto eclk; 1195 - } 1162 + return ret; 1196 1163 1197 1164 i2c->adap.owner = THIS_MODULE; 1198 1165 i2c->adap.retries = 5; ··· 1190 1181 1191 1182 strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); 1192 1183 1193 - i2c->clk = clk_get(&dev->dev, NULL); 1184 + i2c->clk = devm_clk_get(&dev->dev, NULL); 1194 1185 if (IS_ERR(i2c->clk)) { 1195 - ret = PTR_ERR(i2c->clk); 1196 - goto eclk; 1197 - } 1198 - 1199 - i2c->reg_base = ioremap(res->start, resource_size(res)); 1200 - if (!i2c->reg_base) { 1201 - ret = -EIO; 1202 - goto eremap; 1186 + dev_err(&dev->dev, "failed to get the clk: %ld\n", PTR_ERR(i2c->clk)); 1187 + return PTR_ERR(i2c->clk); 1203 1188 } 1204 1189 1205 1190 i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; ··· 1235 1232 i2c->adap.algo = &i2c_pxa_pio_algorithm; 1236 1233 } else { 1237 1234 i2c->adap.algo = &i2c_pxa_algorithm; 1238 - ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED, 1239 - dev_name(&dev->dev), i2c); 1240 - if (ret) 1235 + ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler, 1236 + IRQF_SHARED | IRQF_NO_SUSPEND, 1237 + dev_name(&dev->dev), i2c); 1238 + if (ret) { 1239 + dev_err(&dev->dev, "failed to request irq: %d\n", ret); 1241 1240 goto ereqirq; 1241 + } 1242 1242 } 1243 1243 1244 1244 i2c_pxa_reset(i2c); ··· 1254 1248 1255 1249 ret = i2c_add_numbered_adapter(&i2c->adap); 1256 1250 if (ret < 0) { 1257 - printk(KERN_INFO "I2C: Failed to add bus\n"); 1258 - goto eadapt; 1251 + dev_err(&dev->dev, "failed to add bus: %d\n", ret); 1252 + goto ereqirq; 1259 1253 } 1260 1254 1261 1255 platform_set_drvdata(dev, i2c); 1262 1256 1263 1257 #ifdef CONFIG_I2C_PXA_SLAVE 1264 - printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n", 1265 - dev_name(&i2c->adap.dev), i2c->slave_addr); 1258 + dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n", 1259 + i2c->slave_addr); 1266 1260 #else 1267 - printk(KERN_INFO "I2C: %s: PXA I2C adapter\n", 1268 - dev_name(&i2c->adap.dev)); 1261 + dev_info(&i2c->adap.dev, " PXA I2C adapter\n"); 1269 1262 #endif 1270 1263 return 0; 1271 1264 1272 - eadapt: 1273 - if (!i2c->use_pio) 1274 - free_irq(irq, i2c); 1275 1265 ereqirq: 1276 1266 clk_disable_unprepare(i2c->clk); 1277 - iounmap(i2c->reg_base); 1278 - eremap: 1279 - clk_put(i2c->clk); 1280 - eclk: 1281 - kfree(i2c); 1282 - emalloc: 1283 - release_mem_region(res->start, resource_size(res)); 1284 1267 return ret; 1285 1268 } 1286 1269 ··· 1278 1283 struct pxa_i2c *i2c = platform_get_drvdata(dev); 1279 1284 1280 1285 i2c_del_adapter(&i2c->adap); 1281 - if (!i2c->use_pio) 1282 - free_irq(i2c->irq, i2c); 1283 1286 1284 1287 clk_disable_unprepare(i2c->clk); 1285 - clk_put(i2c->clk); 1286 - 1287 - iounmap(i2c->reg_base); 1288 - release_mem_region(i2c->iobase, i2c->iosize); 1289 - kfree(i2c); 1290 1288 1291 1289 return 0; 1292 1290 }
+50 -2
drivers/i2c/busses/i2c-tegra.c
··· 100 100 #define I2C_HEADER_CONTINUE_XFER (1<<15) 101 101 #define I2C_HEADER_MASTER_ADDR_SHIFT 12 102 102 #define I2C_HEADER_SLAVE_ADDR_SHIFT 1 103 + 104 + #define I2C_CONFIG_LOAD 0x08C 105 + #define I2C_MSTR_CONFIG_LOAD (1 << 0) 106 + #define I2C_SLV_CONFIG_LOAD (1 << 1) 107 + #define I2C_TIMEOUT_CONFIG_LOAD (1 << 2) 108 + 103 109 /* 104 110 * msg_end_type: The bus control which need to be send at end of transfer. 105 111 * @MSG_END_STOP: Send stop pulse at end of transfer. ··· 127 121 * @has_single_clk_source: The i2c controller has single clock source. Tegra30 128 122 * and earlier Socs has two clock sources i.e. div-clk and 129 123 * fast-clk. 124 + * @has_config_load_reg: Has the config load register to load the new 125 + * configuration. 130 126 * @clk_divisor_hs_mode: Clock divisor in HS mode. 131 127 * @clk_divisor_std_fast_mode: Clock divisor in standard/fast mode. It is 132 128 * applicable if there is no fast clock source i.e. single clock ··· 139 131 bool has_continue_xfer_support; 140 132 bool has_per_pkt_xfer_complete_irq; 141 133 bool has_single_clk_source; 134 + bool has_config_load_reg; 142 135 int clk_divisor_hs_mode; 143 136 int clk_divisor_std_fast_mode; 137 + u16 clk_divisor_fast_plus_mode; 144 138 }; 145 139 146 140 /** ··· 182 172 size_t msg_buf_remaining; 183 173 int msg_read; 184 174 u32 bus_clk_rate; 175 + u16 clk_divisor_non_hs_mode; 185 176 bool is_suspended; 186 177 }; 187 178 ··· 421 410 u32 val; 422 411 int err = 0; 423 412 u32 clk_divisor; 413 + unsigned long timeout = jiffies + HZ; 424 414 425 415 err = tegra_i2c_clock_enable(i2c_dev); 426 416 if (err < 0) { ··· 443 431 444 432 /* Make sure clock divisor programmed correctly */ 445 433 clk_divisor = i2c_dev->hw->clk_divisor_hs_mode; 446 - clk_divisor |= i2c_dev->hw->clk_divisor_std_fast_mode << 434 + clk_divisor |= i2c_dev->clk_divisor_non_hs_mode << 447 435 I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT; 448 436 i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); 449 437 ··· 462 450 463 451 if (tegra_i2c_flush_fifos(i2c_dev)) 464 452 err = -ETIMEDOUT; 453 + 454 + if (i2c_dev->hw->has_config_load_reg) { 455 + i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); 456 + while (i2c_readl(i2c_dev, I2C_CONFIG_LOAD) != 0) { 457 + if (time_after(jiffies, timeout)) { 458 + dev_warn(i2c_dev->dev, 459 + "timeout waiting for config load\n"); 460 + return -ETIMEDOUT; 461 + } 462 + msleep(1); 463 + } 464 + } 465 465 466 466 tegra_i2c_clock_disable(i2c_dev); 467 467 ··· 705 681 .has_single_clk_source = false, 706 682 .clk_divisor_hs_mode = 3, 707 683 .clk_divisor_std_fast_mode = 0, 684 + .clk_divisor_fast_plus_mode = 0, 685 + .has_config_load_reg = false, 708 686 }; 709 687 710 688 static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { ··· 715 689 .has_single_clk_source = false, 716 690 .clk_divisor_hs_mode = 3, 717 691 .clk_divisor_std_fast_mode = 0, 692 + .clk_divisor_fast_plus_mode = 0, 693 + .has_config_load_reg = false, 718 694 }; 719 695 720 696 static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { ··· 725 697 .has_single_clk_source = true, 726 698 .clk_divisor_hs_mode = 1, 727 699 .clk_divisor_std_fast_mode = 0x19, 700 + .clk_divisor_fast_plus_mode = 0x10, 701 + .has_config_load_reg = false, 702 + }; 703 + 704 + static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { 705 + .has_continue_xfer_support = true, 706 + .has_per_pkt_xfer_complete_irq = true, 707 + .has_single_clk_source = true, 708 + .clk_divisor_hs_mode = 1, 709 + .clk_divisor_std_fast_mode = 0x19, 710 + .clk_divisor_fast_plus_mode = 0x10, 711 + .has_config_load_reg = true, 728 712 }; 729 713 730 714 /* Match table for of_platform binding */ 731 715 static const struct of_device_id tegra_i2c_of_match[] = { 716 + { .compatible = "nvidia,tegra124-i2c", .data = &tegra124_i2c_hw, }, 732 717 { .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, }, 733 718 { .compatible = "nvidia,tegra30-i2c", .data = &tegra30_i2c_hw, }, 734 719 { .compatible = "nvidia,tegra20-i2c", .data = &tegra20_i2c_hw, }, ··· 834 793 } 835 794 } 836 795 837 - clk_multiplier *= (i2c_dev->hw->clk_divisor_std_fast_mode + 1); 796 + i2c_dev->clk_divisor_non_hs_mode = 797 + i2c_dev->hw->clk_divisor_std_fast_mode; 798 + if (i2c_dev->hw->clk_divisor_fast_plus_mode && 799 + (i2c_dev->bus_clk_rate == 1000000)) 800 + i2c_dev->clk_divisor_non_hs_mode = 801 + i2c_dev->hw->clk_divisor_fast_plus_mode; 802 + 803 + clk_multiplier *= (i2c_dev->clk_divisor_non_hs_mode + 1); 838 804 ret = clk_set_rate(i2c_dev->div_clk, 839 805 i2c_dev->bus_clk_rate * clk_multiplier); 840 806 if (ret) {
+5 -5
drivers/i2c/busses/i2c-viperboard.c
··· 391 391 VPRBRD_USB_REQUEST_I2C_FREQ, VPRBRD_USB_TYPE_OUT, 392 392 0x0000, 0x0000, &vb_i2c->bus_freq_param, 1, 393 393 VPRBRD_USB_TIMEOUT_MS); 394 - if (ret != 1) { 395 - dev_err(&pdev->dev, 396 - "failure setting i2c_bus_freq to %d\n", i2c_bus_freq); 397 - return -EIO; 398 - } 394 + if (ret != 1) { 395 + dev_err(&pdev->dev, "failure setting i2c_bus_freq to %d\n", 396 + i2c_bus_freq); 397 + return -EIO; 398 + } 399 399 } else { 400 400 dev_err(&pdev->dev, 401 401 "invalid i2c_bus_freq setting:%d\n", i2c_bus_freq);
+4 -4
drivers/i2c/busses/i2c-xgene-slimpro.c
··· 198 198 int rc; 199 199 200 200 paddr = dma_map_single(ctx->dev, ctx->dma_buffer, readlen, DMA_FROM_DEVICE); 201 - rc = dma_mapping_error(ctx->dev, paddr); 202 - if (rc) { 201 + if (dma_mapping_error(ctx->dev, paddr)) { 203 202 dev_err(&ctx->adapter.dev, "Error in mapping dma buffer %p\n", 204 203 ctx->dma_buffer); 204 + rc = -ENOMEM; 205 205 goto err; 206 206 } 207 207 ··· 241 241 memcpy(ctx->dma_buffer, data, writelen); 242 242 paddr = dma_map_single(ctx->dev, ctx->dma_buffer, writelen, 243 243 DMA_TO_DEVICE); 244 - rc = dma_mapping_error(ctx->dev, paddr); 245 - if (rc) { 244 + if (dma_mapping_error(ctx->dev, paddr)) { 246 245 dev_err(&ctx->adapter.dev, "Error in mapping dma buffer %p\n", 247 246 ctx->dma_buffer); 247 + rc = -ENOMEM; 248 248 goto err; 249 249 } 250 250
+34 -40
drivers/i2c/busses/i2c-xiic.c
··· 283 283 /* Enable interrupts */ 284 284 xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); 285 285 286 - xiic_irq_clr_en(i2c, XIIC_INTR_AAS_MASK | XIIC_INTR_ARB_LOST_MASK); 286 + xiic_irq_clr_en(i2c, XIIC_INTR_ARB_LOST_MASK); 287 287 } 288 288 289 289 static void xiic_deinit(struct xiic_i2c *i2c) ··· 358 358 wake_up(&i2c->wait); 359 359 } 360 360 361 - static void xiic_process(struct xiic_i2c *i2c) 361 + static irqreturn_t xiic_process(int irq, void *dev_id) 362 362 { 363 + struct xiic_i2c *i2c = dev_id; 363 364 u32 pend, isr, ier; 364 365 u32 clr = 0; 365 366 ··· 369 368 * To find which interrupts are pending; AND interrupts pending with 370 369 * interrupts masked. 371 370 */ 371 + spin_lock(&i2c->lock); 372 372 isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); 373 373 ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); 374 374 pend = isr & ier; ··· 380 378 __func__, xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), 381 379 i2c->tx_msg, i2c->nmsgs); 382 380 383 - /* Do not processes a devices interrupts if the device has no 384 - * interrupts pending 385 - */ 386 - if (!pend) 387 - return; 388 381 389 382 /* Service requesting interrupt */ 390 383 if ((pend & XIIC_INTR_ARB_LOST_MASK) || ··· 399 402 */ 400 403 xiic_reinit(i2c); 401 404 405 + if (i2c->rx_msg) 406 + xiic_wakeup(i2c, STATE_ERROR); 402 407 if (i2c->tx_msg) 403 408 xiic_wakeup(i2c, STATE_ERROR); 404 - 405 - } else if (pend & XIIC_INTR_RX_FULL_MASK) { 409 + } 410 + if (pend & XIIC_INTR_RX_FULL_MASK) { 406 411 /* Receive register/FIFO is full */ 407 412 408 - clr = XIIC_INTR_RX_FULL_MASK; 413 + clr |= XIIC_INTR_RX_FULL_MASK; 409 414 if (!i2c->rx_msg) { 410 415 dev_dbg(i2c->adap.dev.parent, 411 416 "%s unexpexted RX IRQ\n", __func__); ··· 440 441 __xiic_start_xfer(i2c); 441 442 } 442 443 } 443 - } else if (pend & XIIC_INTR_BNB_MASK) { 444 + } 445 + if (pend & XIIC_INTR_BNB_MASK) { 444 446 /* IIC bus has transitioned to not busy */ 445 - clr = XIIC_INTR_BNB_MASK; 447 + clr |= XIIC_INTR_BNB_MASK; 446 448 447 449 /* The bus is not busy, disable BusNotBusy interrupt */ 448 450 xiic_irq_dis(i2c, XIIC_INTR_BNB_MASK); ··· 456 456 xiic_wakeup(i2c, STATE_DONE); 457 457 else 458 458 xiic_wakeup(i2c, STATE_ERROR); 459 - 460 - } else if (pend & (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK)) { 459 + } 460 + if (pend & (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK)) { 461 461 /* Transmit register/FIFO is empty or ½ empty */ 462 462 463 - clr = pend & 464 - (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK); 463 + clr |= (pend & 464 + (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK)); 465 465 466 466 if (!i2c->tx_msg) { 467 467 dev_dbg(i2c->adap.dev.parent, ··· 492 492 * make sure to disable tx half 493 493 */ 494 494 xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK); 495 - } else { 496 - /* got IRQ which is not acked */ 497 - dev_err(i2c->adap.dev.parent, "%s Got unexpected IRQ\n", 498 - __func__); 499 - clr = pend; 500 495 } 501 496 out: 502 497 dev_dbg(i2c->adap.dev.parent, "%s clr: 0x%x\n", __func__, clr); 503 498 504 499 xiic_setreg32(i2c, XIIC_IISR_OFFSET, clr); 500 + spin_unlock(&i2c->lock); 501 + return IRQ_HANDLED; 505 502 } 506 503 507 504 static int xiic_bus_busy(struct xiic_i2c *i2c) ··· 522 525 */ 523 526 err = xiic_bus_busy(i2c); 524 527 while (err && tries--) { 525 - mdelay(1); 528 + msleep(1); 526 529 err = xiic_bus_busy(i2c); 527 530 } 528 531 ··· 599 602 static irqreturn_t xiic_isr(int irq, void *dev_id) 600 603 { 601 604 struct xiic_i2c *i2c = dev_id; 602 - 603 - spin_lock(&i2c->lock); 604 - /* disable interrupts globally */ 605 - xiic_setreg32(i2c, XIIC_DGIER_OFFSET, 0); 605 + u32 pend, isr, ier; 606 + irqreturn_t ret = IRQ_NONE; 607 + /* Do not processes a devices interrupts if the device has no 608 + * interrupts pending 609 + */ 606 610 607 611 dev_dbg(i2c->adap.dev.parent, "%s entry\n", __func__); 608 612 609 - xiic_process(i2c); 613 + isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); 614 + ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); 615 + pend = isr & ier; 616 + if (pend) 617 + ret = IRQ_WAKE_THREAD; 610 618 611 - xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); 612 - spin_unlock(&i2c->lock); 613 - 614 - return IRQ_HANDLED; 619 + return ret; 615 620 } 616 621 617 622 static void __xiic_start_xfer(struct xiic_i2c *i2c) ··· 662 663 663 664 static void xiic_start_xfer(struct xiic_i2c *i2c) 664 665 { 665 - unsigned long flags; 666 - 667 - spin_lock_irqsave(&i2c->lock, flags); 668 - xiic_reinit(i2c); 669 - /* disable interrupts globally */ 670 - xiic_setreg32(i2c, XIIC_DGIER_OFFSET, 0); 671 - spin_unlock_irqrestore(&i2c->lock, flags); 672 666 673 667 __xiic_start_xfer(i2c); 674 - xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); 675 668 } 676 669 677 670 static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) ··· 746 755 spin_lock_init(&i2c->lock); 747 756 init_waitqueue_head(&i2c->wait); 748 757 749 - ret = devm_request_irq(&pdev->dev, irq, xiic_isr, 0, pdev->name, i2c); 758 + ret = devm_request_threaded_irq(&pdev->dev, irq, xiic_isr, 759 + xiic_process, IRQF_ONESHOT, 760 + pdev->name, i2c); 761 + 750 762 if (ret < 0) { 751 763 dev_err(&pdev->dev, "Cannot claim IRQ\n"); 752 764 return ret;
+194 -35
drivers/i2c/i2c-core.c
··· 27 27 I2C slave support (c) 2014 by Wolfram Sang <wsa@sang-engineering.com> 28 28 */ 29 29 30 + #include <dt-bindings/i2c/i2c.h> 30 31 #include <linux/module.h> 31 32 #include <linux/kernel.h> 32 33 #include <linux/delay.h> ··· 48 47 #include <linux/rwsem.h> 49 48 #include <linux/pm_runtime.h> 50 49 #include <linux/pm_domain.h> 50 + #include <linux/pm_wakeirq.h> 51 51 #include <linux/acpi.h> 52 52 #include <linux/jump_label.h> 53 53 #include <asm/uaccess.h> ··· 58 56 59 57 #define CREATE_TRACE_POINTS 60 58 #include <trace/events/i2c.h> 59 + 60 + #define I2C_ADDR_OFFSET_TEN_BIT 0xa000 61 + #define I2C_ADDR_OFFSET_SLAVE 0x1000 61 62 62 63 /* core_lock protects i2c_adapter_idr, and guarantees 63 64 that device detection, deletion of detected devices, and attach_adapter ··· 646 641 if (!client->irq) { 647 642 int irq = -ENOENT; 648 643 649 - if (dev->of_node) 650 - irq = of_irq_get(dev->of_node, 0); 651 - else if (ACPI_COMPANION(dev)) 644 + if (dev->of_node) { 645 + irq = of_irq_get_byname(dev->of_node, "irq"); 646 + if (irq == -EINVAL || irq == -ENODATA) 647 + irq = of_irq_get(dev->of_node, 0); 648 + } else if (ACPI_COMPANION(dev)) { 652 649 irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0); 653 - 650 + } 654 651 if (irq == -EPROBE_DEFER) 655 652 return irq; 656 653 if (irq < 0) ··· 665 658 if (!driver->probe || !driver->id_table) 666 659 return -ENODEV; 667 660 668 - if (!device_can_wakeup(&client->dev)) 669 - device_init_wakeup(&client->dev, 670 - client->flags & I2C_CLIENT_WAKE); 661 + if (client->flags & I2C_CLIENT_WAKE) { 662 + int wakeirq = -ENOENT; 663 + 664 + if (dev->of_node) { 665 + wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); 666 + if (wakeirq == -EPROBE_DEFER) 667 + return wakeirq; 668 + } 669 + 670 + device_init_wakeup(&client->dev, true); 671 + 672 + if (wakeirq > 0 && wakeirq != client->irq) 673 + status = dev_pm_set_dedicated_wake_irq(dev, wakeirq); 674 + else if (client->irq > 0) 675 + status = dev_pm_set_wake_irq(dev, wakeirq); 676 + else 677 + status = 0; 678 + 679 + if (status) 680 + dev_warn(&client->dev, "failed to set up wakeup irq"); 681 + } 682 + 671 683 dev_dbg(dev, "probe\n"); 672 684 673 685 status = of_clk_set_defaults(dev->of_node, false); 674 686 if (status < 0) 675 - return status; 687 + goto err_clear_wakeup_irq; 676 688 677 689 status = dev_pm_domain_attach(&client->dev, true); 678 690 if (status != -EPROBE_DEFER) { 679 691 status = driver->probe(client, i2c_match_id(driver->id_table, 680 692 client)); 681 693 if (status) 682 - dev_pm_domain_detach(&client->dev, true); 694 + goto err_detach_pm_domain; 683 695 } 684 696 697 + return 0; 698 + 699 + err_detach_pm_domain: 700 + dev_pm_domain_detach(&client->dev, true); 701 + err_clear_wakeup_irq: 702 + dev_pm_clear_wake_irq(&client->dev); 703 + device_init_wakeup(&client->dev, false); 685 704 return status; 686 705 } 687 706 ··· 727 694 } 728 695 729 696 dev_pm_domain_detach(&client->dev, true); 697 + 698 + dev_pm_clear_wake_irq(&client->dev); 699 + device_init_wakeup(&client->dev, false); 700 + 730 701 return status; 731 702 } 732 703 ··· 815 778 EXPORT_SYMBOL(i2c_verify_client); 816 779 817 780 781 + /* Return a unique address which takes the flags of the client into account */ 782 + static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client) 783 + { 784 + unsigned short addr = client->addr; 785 + 786 + /* For some client flags, add an arbitrary offset to avoid collisions */ 787 + if (client->flags & I2C_CLIENT_TEN) 788 + addr |= I2C_ADDR_OFFSET_TEN_BIT; 789 + 790 + if (client->flags & I2C_CLIENT_SLAVE) 791 + addr |= I2C_ADDR_OFFSET_SLAVE; 792 + 793 + return addr; 794 + } 795 + 818 796 /* This is a permissive address validity check, I2C address map constraints 819 797 * are purposely not enforced, except for the general call address. */ 820 - static int i2c_check_client_addr_validity(const struct i2c_client *client) 798 + static int i2c_check_addr_validity(unsigned addr, unsigned short flags) 821 799 { 822 - if (client->flags & I2C_CLIENT_TEN) { 800 + if (flags & I2C_CLIENT_TEN) { 823 801 /* 10-bit address, all values are valid */ 824 - if (client->addr > 0x3ff) 802 + if (addr > 0x3ff) 825 803 return -EINVAL; 826 804 } else { 827 805 /* 7-bit address, reject the general call address */ 828 - if (client->addr == 0x00 || client->addr > 0x7f) 806 + if (addr == 0x00 || addr > 0x7f) 829 807 return -EINVAL; 830 808 } 831 809 return 0; ··· 850 798 * device uses a reserved address, then it shouldn't be probed. 7-bit 851 799 * addressing is assumed, 10-bit address devices are rare and should be 852 800 * explicitly enumerated. */ 853 - static int i2c_check_addr_validity(unsigned short addr) 801 + static int i2c_check_7bit_addr_validity_strict(unsigned short addr) 854 802 { 855 803 /* 856 804 * Reserved addresses per I2C specification: ··· 872 820 struct i2c_client *client = i2c_verify_client(dev); 873 821 int addr = *(int *)addrp; 874 822 875 - if (client && client->addr == addr) 823 + if (client && i2c_encode_flags_to_addr(client) == addr) 876 824 return -EBUSY; 877 825 return 0; 878 826 } ··· 975 923 return; 976 924 } 977 925 978 - /* For 10-bit clients, add an arbitrary offset to avoid collisions */ 979 926 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), 980 - client->addr | ((client->flags & I2C_CLIENT_TEN) 981 - ? 0xa000 : 0)); 927 + i2c_encode_flags_to_addr(client)); 982 928 } 983 929 984 930 /** ··· 1018 968 1019 969 strlcpy(client->name, info->type, sizeof(client->name)); 1020 970 1021 - /* Check for address validity */ 1022 - status = i2c_check_client_addr_validity(client); 971 + status = i2c_check_addr_validity(client->addr, client->flags); 1023 972 if (status) { 1024 973 dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n", 1025 974 client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr); ··· 1026 977 } 1027 978 1028 979 /* Check for address business */ 1029 - status = i2c_check_addr_busy(adap, client->addr); 980 + status = i2c_check_addr_busy(adap, i2c_encode_flags_to_addr(client)); 1030 981 if (status) 1031 982 goto out_err; 1032 983 ··· 1191 1142 return -EINVAL; 1192 1143 } 1193 1144 1145 + if ((info.addr & I2C_ADDR_OFFSET_TEN_BIT) == I2C_ADDR_OFFSET_TEN_BIT) { 1146 + info.addr &= ~I2C_ADDR_OFFSET_TEN_BIT; 1147 + info.flags |= I2C_CLIENT_TEN; 1148 + } 1149 + 1150 + if (info.addr & I2C_ADDR_OFFSET_SLAVE) { 1151 + info.addr &= ~I2C_ADDR_OFFSET_SLAVE; 1152 + info.flags |= I2C_CLIENT_SLAVE; 1153 + } 1154 + 1194 1155 client = i2c_new_device(adap, &info); 1195 1156 if (!client) 1196 1157 return -EINVAL; ··· 1252 1193 i2c_adapter_depth(adap)); 1253 1194 list_for_each_entry_safe(client, next, &adap->userspace_clients, 1254 1195 detected) { 1255 - if (client->addr == addr) { 1196 + if (i2c_encode_flags_to_addr(client) == addr) { 1256 1197 dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", 1257 1198 "delete_device", client->name, client->addr); 1258 1199 ··· 1332 1273 struct i2c_client *result; 1333 1274 struct i2c_board_info info = {}; 1334 1275 struct dev_archdata dev_ad = {}; 1335 - const __be32 *addr; 1276 + const __be32 *addr_be; 1277 + u32 addr; 1336 1278 int len; 1337 1279 1338 1280 dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name); ··· 1344 1284 return ERR_PTR(-EINVAL); 1345 1285 } 1346 1286 1347 - addr = of_get_property(node, "reg", &len); 1348 - if (!addr || (len < sizeof(*addr))) { 1287 + addr_be = of_get_property(node, "reg", &len); 1288 + if (!addr_be || (len < sizeof(*addr_be))) { 1349 1289 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n", 1350 1290 node->full_name); 1351 1291 return ERR_PTR(-EINVAL); 1352 1292 } 1353 1293 1354 - info.addr = be32_to_cpup(addr); 1355 - if (info.addr > (1 << 10) - 1) { 1294 + addr = be32_to_cpup(addr_be); 1295 + if (addr & I2C_TEN_BIT_ADDRESS) { 1296 + addr &= ~I2C_TEN_BIT_ADDRESS; 1297 + info.flags |= I2C_CLIENT_TEN; 1298 + } 1299 + 1300 + if (addr & I2C_OWN_SLAVE_ADDRESS) { 1301 + addr &= ~I2C_OWN_SLAVE_ADDRESS; 1302 + info.flags |= I2C_CLIENT_SLAVE; 1303 + } 1304 + 1305 + if (i2c_check_addr_validity(addr, info.flags)) { 1356 1306 dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n", 1357 1307 info.addr, node->full_name); 1358 1308 return ERR_PTR(-EINVAL); 1359 1309 } 1360 1310 1311 + info.addr = addr; 1361 1312 info.of_node = of_node_get(node); 1362 1313 info.archdata = &dev_ad; 1363 1314 ··· 1442 1371 return adapter; 1443 1372 } 1444 1373 EXPORT_SYMBOL(of_find_i2c_adapter_by_node); 1374 + 1375 + /* must call i2c_put_adapter() when done with returned i2c_adapter device */ 1376 + struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node) 1377 + { 1378 + struct i2c_adapter *adapter; 1379 + 1380 + adapter = of_find_i2c_adapter_by_node(node); 1381 + if (!adapter) 1382 + return NULL; 1383 + 1384 + if (!try_module_get(adapter->owner)) { 1385 + put_device(&adapter->dev); 1386 + adapter = NULL; 1387 + } 1388 + 1389 + return adapter; 1390 + } 1391 + EXPORT_SYMBOL(of_get_i2c_adapter_by_node); 1445 1392 #else 1446 1393 static void of_i2c_register_devices(struct i2c_adapter *adap) { } 1447 1394 #endif /* CONFIG_OF */ ··· 2351 2262 int err; 2352 2263 2353 2264 /* Make sure the address is valid */ 2354 - err = i2c_check_addr_validity(addr); 2265 + err = i2c_check_7bit_addr_validity_strict(addr); 2355 2266 if (err) { 2356 2267 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", 2357 2268 addr); 2358 2269 return err; 2359 2270 } 2360 2271 2361 - /* Skip if already in use */ 2272 + /* Skip if already in use (7 bit, no need to encode flags) */ 2362 2273 if (i2c_check_addr_busy(adapter, addr)) 2363 2274 return 0; 2364 2275 ··· 2468 2379 2469 2380 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 2470 2381 /* Check address validity */ 2471 - if (i2c_check_addr_validity(addr_list[i]) < 0) { 2382 + if (i2c_check_7bit_addr_validity_strict(addr_list[i]) < 0) { 2472 2383 dev_warn(&adap->dev, "Invalid 7-bit address " 2473 2384 "0x%02x\n", addr_list[i]); 2474 2385 continue; 2475 2386 } 2476 2387 2477 - /* Check address availability */ 2388 + /* Check address availability (7 bit, no need to encode flags) */ 2478 2389 if (i2c_check_addr_busy(adap, addr_list[i])) { 2479 2390 dev_dbg(&adap->dev, "Address 0x%02x already in " 2480 2391 "use, not probing\n", addr_list[i]); ··· 2502 2413 2503 2414 mutex_lock(&core_lock); 2504 2415 adapter = idr_find(&i2c_adapter_idr, nr); 2505 - if (adapter && !try_module_get(adapter->owner)) 2416 + if (!adapter) 2417 + goto exit; 2418 + 2419 + if (try_module_get(adapter->owner)) 2420 + get_device(&adapter->dev); 2421 + else 2506 2422 adapter = NULL; 2507 2423 2424 + exit: 2508 2425 mutex_unlock(&core_lock); 2509 2426 return adapter; 2510 2427 } ··· 2518 2423 2519 2424 void i2c_put_adapter(struct i2c_adapter *adap) 2520 2425 { 2521 - if (adap) 2522 - module_put(adap->owner); 2426 + if (!adap) 2427 + return; 2428 + 2429 + put_device(&adap->dev); 2430 + module_put(adap->owner); 2523 2431 } 2524 2432 EXPORT_SYMBOL(i2c_put_adapter); 2525 2433 ··· 3040 2942 } 3041 2943 EXPORT_SYMBOL(i2c_smbus_xfer); 3042 2944 2945 + /** 2946 + * i2c_smbus_read_i2c_block_data_or_emulated - read block or emulate 2947 + * @client: Handle to slave device 2948 + * @command: Byte interpreted by slave 2949 + * @length: Size of data block; SMBus allows at most I2C_SMBUS_BLOCK_MAX bytes 2950 + * @values: Byte array into which data will be read; big enough to hold 2951 + * the data returned by the slave. SMBus allows at most 2952 + * I2C_SMBUS_BLOCK_MAX bytes. 2953 + * 2954 + * This executes the SMBus "block read" protocol if supported by the adapter. 2955 + * If block read is not supported, it emulates it using either word or byte 2956 + * read protocols depending on availability. 2957 + * 2958 + * The addresses of the I2C slave device that are accessed with this function 2959 + * must be mapped to a linear region, so that a block read will have the same 2960 + * effect as a byte read. Before using this function you must double-check 2961 + * if the I2C slave does support exchanging a block transfer with a byte 2962 + * transfer. 2963 + */ 2964 + s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, 2965 + u8 command, u8 length, u8 *values) 2966 + { 2967 + u8 i = 0; 2968 + int status; 2969 + 2970 + if (length > I2C_SMBUS_BLOCK_MAX) 2971 + length = I2C_SMBUS_BLOCK_MAX; 2972 + 2973 + if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) 2974 + return i2c_smbus_read_i2c_block_data(client, command, length, values); 2975 + 2976 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) 2977 + return -EOPNOTSUPP; 2978 + 2979 + if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) { 2980 + while ((i + 2) <= length) { 2981 + status = i2c_smbus_read_word_data(client, command + i); 2982 + if (status < 0) 2983 + return status; 2984 + values[i] = status & 0xff; 2985 + values[i + 1] = status >> 8; 2986 + i += 2; 2987 + } 2988 + } 2989 + 2990 + while (i < length) { 2991 + status = i2c_smbus_read_byte_data(client, command + i); 2992 + if (status < 0) 2993 + return status; 2994 + values[i] = status; 2995 + i++; 2996 + } 2997 + 2998 + return i; 2999 + } 3000 + EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated); 3001 + 3043 3002 #if IS_ENABLED(CONFIG_I2C_SLAVE) 3044 3003 int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb) 3045 3004 { ··· 3107 2952 return -EINVAL; 3108 2953 } 3109 2954 2955 + if (!(client->flags & I2C_CLIENT_SLAVE)) 2956 + dev_warn(&client->dev, "%s: client slave flag not set. You might see address collisions\n", 2957 + __func__); 2958 + 3110 2959 if (!(client->flags & I2C_CLIENT_TEN)) { 3111 2960 /* Enforce stricter address checking */ 3112 - ret = i2c_check_addr_validity(client->addr); 2961 + ret = i2c_check_7bit_addr_validity_strict(client->addr); 3113 2962 if (ret) { 3114 2963 dev_err(&client->dev, "%s: invalid address\n", __func__); 3115 2964 return ret;
-1
drivers/i2c/i2c-slave-eeprom.c
··· 157 157 static struct i2c_driver i2c_slave_eeprom_driver = { 158 158 .driver = { 159 159 .name = "i2c-slave-eeprom", 160 - .owner = THIS_MODULE, 161 160 }, 162 161 .probe = i2c_slave_eeprom_probe, 163 162 .remove = i2c_slave_eeprom_remove,
+11
drivers/i2c/muxes/Kconfig
··· 61 61 This driver can also be built as a module. If so, the module will be 62 62 called pinctrl-i2cmux. 63 63 64 + config I2C_MUX_REG 65 + tristate "Register-based I2C multiplexer" 66 + help 67 + If you say yes to this option, support will be included for a 68 + register based I2C multiplexer. This driver provides access to 69 + I2C busses connected through a MUX, which is controlled 70 + by a single register. 71 + 72 + This driver can also be built as a module. If so, the module 73 + will be called i2c-mux-reg. 74 + 64 75 endmenu
+1
drivers/i2c/muxes/Makefile
··· 7 7 obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o 8 8 obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o 9 9 obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o 10 + obj-$(CONFIG_I2C_MUX_REG) += i2c-mux-reg.o 10 11 11 12 ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
+2 -1
drivers/i2c/muxes/i2c-arb-gpio-challenge.c
··· 196 196 dev_err(dev, "Cannot parse i2c-parent\n"); 197 197 return -EINVAL; 198 198 } 199 - arb->parent = of_find_i2c_adapter_by_node(parent_np); 199 + arb->parent = of_get_i2c_adapter_by_node(parent_np); 200 + of_node_put(parent_np); 200 201 if (!arb->parent) { 201 202 dev_err(dev, "Cannot find parent bus\n"); 202 203 return -EPROBE_DEFER;
+1
drivers/i2c/muxes/i2c-mux-gpio.c
··· 76 76 return -ENODEV; 77 77 } 78 78 adapter = of_find_i2c_adapter_by_node(adapter_np); 79 + of_node_put(adapter_np); 79 80 if (!adapter) 80 81 return -EPROBE_DEFER; 81 82
-1
drivers/i2c/muxes/i2c-mux-pca9541.c
··· 386 386 static struct i2c_driver pca9541_driver = { 387 387 .driver = { 388 388 .name = "pca9541", 389 - .owner = THIS_MODULE, 390 389 }, 391 390 .probe = pca9541_probe, 392 391 .remove = pca9541_remove,
-1
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 300 300 .driver = { 301 301 .name = "pca954x", 302 302 .pm = &pca954x_pm, 303 - .owner = THIS_MODULE, 304 303 }, 305 304 .probe = pca954x_probe, 306 305 .remove = pca954x_remove,
+1
drivers/i2c/muxes/i2c-mux-pinctrl.c
··· 111 111 return -ENODEV; 112 112 } 113 113 adapter = of_find_i2c_adapter_by_node(adapter_np); 114 + of_node_put(adapter_np); 114 115 if (!adapter) { 115 116 dev_err(mux->dev, "Cannot find parent bus\n"); 116 117 return -EPROBE_DEFER;
+290
drivers/i2c/muxes/i2c-mux-reg.c
··· 1 + /* 2 + * I2C multiplexer using a single register 3 + * 4 + * Copyright 2015 Freescale Semiconductor 5 + * York Sun <yorksun@freescale.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License as published by the 9 + * Free Software Foundation; either version 2 of the License, or (at your 10 + * option) any later version. 11 + */ 12 + 13 + #include <linux/i2c.h> 14 + #include <linux/i2c-mux.h> 15 + #include <linux/init.h> 16 + #include <linux/io.h> 17 + #include <linux/module.h> 18 + #include <linux/of_address.h> 19 + #include <linux/platform_data/i2c-mux-reg.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/slab.h> 22 + 23 + struct regmux { 24 + struct i2c_adapter *parent; 25 + struct i2c_adapter **adap; /* child busses */ 26 + struct i2c_mux_reg_platform_data data; 27 + }; 28 + 29 + static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id) 30 + { 31 + if (!mux->data.reg) 32 + return -EINVAL; 33 + 34 + /* 35 + * Write to the register, followed by a read to ensure the write is 36 + * completed on a "posted" bus, for example PCI or write buffers. 37 + * The endianness of reading doesn't matter and the return data 38 + * is not used. 39 + */ 40 + switch (mux->data.reg_size) { 41 + case 4: 42 + if (mux->data.little_endian) 43 + iowrite32(chan_id, mux->data.reg); 44 + else 45 + iowrite32be(chan_id, mux->data.reg); 46 + if (!mux->data.write_only) 47 + ioread32(mux->data.reg); 48 + break; 49 + case 2: 50 + if (mux->data.little_endian) 51 + iowrite16(chan_id, mux->data.reg); 52 + else 53 + iowrite16be(chan_id, mux->data.reg); 54 + if (!mux->data.write_only) 55 + ioread16(mux->data.reg); 56 + break; 57 + case 1: 58 + iowrite8(chan_id, mux->data.reg); 59 + if (!mux->data.write_only) 60 + ioread8(mux->data.reg); 61 + break; 62 + } 63 + 64 + return 0; 65 + } 66 + 67 + static int i2c_mux_reg_select(struct i2c_adapter *adap, void *data, 68 + unsigned int chan) 69 + { 70 + struct regmux *mux = data; 71 + 72 + return i2c_mux_reg_set(mux, chan); 73 + } 74 + 75 + static int i2c_mux_reg_deselect(struct i2c_adapter *adap, void *data, 76 + unsigned int chan) 77 + { 78 + struct regmux *mux = data; 79 + 80 + if (mux->data.idle_in_use) 81 + return i2c_mux_reg_set(mux, mux->data.idle); 82 + 83 + return 0; 84 + } 85 + 86 + #ifdef CONFIG_OF 87 + static int i2c_mux_reg_probe_dt(struct regmux *mux, 88 + struct platform_device *pdev) 89 + { 90 + struct device_node *np = pdev->dev.of_node; 91 + struct device_node *adapter_np, *child; 92 + struct i2c_adapter *adapter; 93 + struct resource res; 94 + unsigned *values; 95 + int i = 0; 96 + 97 + if (!np) 98 + return -ENODEV; 99 + 100 + adapter_np = of_parse_phandle(np, "i2c-parent", 0); 101 + if (!adapter_np) { 102 + dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); 103 + return -ENODEV; 104 + } 105 + adapter = of_find_i2c_adapter_by_node(adapter_np); 106 + of_node_put(adapter_np); 107 + if (!adapter) 108 + return -EPROBE_DEFER; 109 + 110 + mux->parent = adapter; 111 + mux->data.parent = i2c_adapter_id(adapter); 112 + put_device(&adapter->dev); 113 + 114 + mux->data.n_values = of_get_child_count(np); 115 + if (of_find_property(np, "little-endian", NULL)) { 116 + mux->data.little_endian = true; 117 + } else if (of_find_property(np, "big-endian", NULL)) { 118 + mux->data.little_endian = false; 119 + } else { 120 + #if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : \ 121 + defined(__LITTLE_ENDIAN) 122 + mux->data.little_endian = true; 123 + #elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : \ 124 + defined(__BIG_ENDIAN) 125 + mux->data.little_endian = false; 126 + #else 127 + #error Endianness not defined? 128 + #endif 129 + } 130 + if (of_find_property(np, "write-only", NULL)) 131 + mux->data.write_only = true; 132 + else 133 + mux->data.write_only = false; 134 + 135 + values = devm_kzalloc(&pdev->dev, 136 + sizeof(*mux->data.values) * mux->data.n_values, 137 + GFP_KERNEL); 138 + if (!values) { 139 + dev_err(&pdev->dev, "Cannot allocate values array"); 140 + return -ENOMEM; 141 + } 142 + 143 + for_each_child_of_node(np, child) { 144 + of_property_read_u32(child, "reg", values + i); 145 + i++; 146 + } 147 + mux->data.values = values; 148 + 149 + if (!of_property_read_u32(np, "idle-state", &mux->data.idle)) 150 + mux->data.idle_in_use = true; 151 + 152 + /* map address from "reg" if exists */ 153 + if (of_address_to_resource(np, 0, &res)) { 154 + mux->data.reg_size = resource_size(&res); 155 + mux->data.reg = devm_ioremap_resource(&pdev->dev, &res); 156 + if (IS_ERR(mux->data.reg)) 157 + return PTR_ERR(mux->data.reg); 158 + } 159 + 160 + return 0; 161 + } 162 + #else 163 + static int i2c_mux_reg_probe_dt(struct regmux *mux, 164 + struct platform_device *pdev) 165 + { 166 + return 0; 167 + } 168 + #endif 169 + 170 + static int i2c_mux_reg_probe(struct platform_device *pdev) 171 + { 172 + struct regmux *mux; 173 + struct i2c_adapter *parent; 174 + struct resource *res; 175 + int (*deselect)(struct i2c_adapter *, void *, u32); 176 + unsigned int class; 177 + int i, ret, nr; 178 + 179 + mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); 180 + if (!mux) 181 + return -ENOMEM; 182 + 183 + platform_set_drvdata(pdev, mux); 184 + 185 + if (dev_get_platdata(&pdev->dev)) { 186 + memcpy(&mux->data, dev_get_platdata(&pdev->dev), 187 + sizeof(mux->data)); 188 + 189 + parent = i2c_get_adapter(mux->data.parent); 190 + if (!parent) 191 + return -EPROBE_DEFER; 192 + 193 + mux->parent = parent; 194 + } else { 195 + ret = i2c_mux_reg_probe_dt(mux, pdev); 196 + if (ret < 0) { 197 + dev_err(&pdev->dev, "Error parsing device tree"); 198 + return ret; 199 + } 200 + } 201 + 202 + if (!mux->data.reg) { 203 + dev_info(&pdev->dev, 204 + "Register not set, using platform resource\n"); 205 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 206 + mux->data.reg_size = resource_size(res); 207 + mux->data.reg = devm_ioremap_resource(&pdev->dev, res); 208 + if (IS_ERR(mux->data.reg)) 209 + return PTR_ERR(mux->data.reg); 210 + } 211 + 212 + if (mux->data.reg_size != 4 && mux->data.reg_size != 2 && 213 + mux->data.reg_size != 1) { 214 + dev_err(&pdev->dev, "Invalid register size\n"); 215 + return -EINVAL; 216 + } 217 + 218 + mux->adap = devm_kzalloc(&pdev->dev, 219 + sizeof(*mux->adap) * mux->data.n_values, 220 + GFP_KERNEL); 221 + if (!mux->adap) { 222 + dev_err(&pdev->dev, "Cannot allocate i2c_adapter structure"); 223 + return -ENOMEM; 224 + } 225 + 226 + if (mux->data.idle_in_use) 227 + deselect = i2c_mux_reg_deselect; 228 + else 229 + deselect = NULL; 230 + 231 + for (i = 0; i < mux->data.n_values; i++) { 232 + nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; 233 + class = mux->data.classes ? mux->data.classes[i] : 0; 234 + 235 + mux->adap[i] = i2c_add_mux_adapter(mux->parent, &pdev->dev, mux, 236 + nr, mux->data.values[i], 237 + class, i2c_mux_reg_select, 238 + deselect); 239 + if (!mux->adap[i]) { 240 + ret = -ENODEV; 241 + dev_err(&pdev->dev, "Failed to add adapter %d\n", i); 242 + goto add_adapter_failed; 243 + } 244 + } 245 + 246 + dev_dbg(&pdev->dev, "%d port mux on %s adapter\n", 247 + mux->data.n_values, mux->parent->name); 248 + 249 + return 0; 250 + 251 + add_adapter_failed: 252 + for (; i > 0; i--) 253 + i2c_del_mux_adapter(mux->adap[i - 1]); 254 + 255 + return ret; 256 + } 257 + 258 + static int i2c_mux_reg_remove(struct platform_device *pdev) 259 + { 260 + struct regmux *mux = platform_get_drvdata(pdev); 261 + int i; 262 + 263 + for (i = 0; i < mux->data.n_values; i++) 264 + i2c_del_mux_adapter(mux->adap[i]); 265 + 266 + i2c_put_adapter(mux->parent); 267 + 268 + return 0; 269 + } 270 + 271 + static const struct of_device_id i2c_mux_reg_of_match[] = { 272 + { .compatible = "i2c-mux-reg", }, 273 + {}, 274 + }; 275 + MODULE_DEVICE_TABLE(of, i2c_mux_reg_of_match); 276 + 277 + static struct platform_driver i2c_mux_reg_driver = { 278 + .probe = i2c_mux_reg_probe, 279 + .remove = i2c_mux_reg_remove, 280 + .driver = { 281 + .name = "i2c-mux-reg", 282 + }, 283 + }; 284 + 285 + module_platform_driver(i2c_mux_reg_driver); 286 + 287 + MODULE_DESCRIPTION("Register-based I2C multiplexer driver"); 288 + MODULE_AUTHOR("York Sun <yorksun@freescale.com>"); 289 + MODULE_LICENSE("GPL"); 290 + MODULE_ALIAS("platform:i2c-mux-reg");
+6 -31
drivers/misc/eeprom/at24.c
··· 186 186 if (count > io_limit) 187 187 count = io_limit; 188 188 189 - switch (at24->use_smbus) { 190 - case I2C_SMBUS_I2C_BLOCK_DATA: 189 + if (at24->use_smbus) { 191 190 /* Smaller eeproms can work given some SMBus extension calls */ 192 191 if (count > I2C_SMBUS_BLOCK_MAX) 193 192 count = I2C_SMBUS_BLOCK_MAX; 194 - break; 195 - case I2C_SMBUS_WORD_DATA: 196 - count = 2; 197 - break; 198 - case I2C_SMBUS_BYTE_DATA: 199 - count = 1; 200 - break; 201 - default: 193 + } else { 202 194 /* 203 195 * When we have a better choice than SMBus calls, use a 204 196 * combined I2C message. Write address; then read up to ··· 221 229 timeout = jiffies + msecs_to_jiffies(write_timeout); 222 230 do { 223 231 read_time = jiffies; 224 - switch (at24->use_smbus) { 225 - case I2C_SMBUS_I2C_BLOCK_DATA: 226 - status = i2c_smbus_read_i2c_block_data(client, offset, 227 - count, buf); 228 - break; 229 - case I2C_SMBUS_WORD_DATA: 230 - status = i2c_smbus_read_word_data(client, offset); 231 - if (status >= 0) { 232 - buf[0] = status & 0xff; 233 - buf[1] = status >> 8; 234 - status = count; 235 - } 236 - break; 237 - case I2C_SMBUS_BYTE_DATA: 238 - status = i2c_smbus_read_byte_data(client, offset); 239 - if (status >= 0) { 240 - buf[0] = status; 241 - status = count; 242 - } 243 - break; 244 - default: 232 + if (at24->use_smbus) { 233 + status = i2c_smbus_read_i2c_block_data_or_emulated(client, offset, 234 + count, buf); 235 + } else { 245 236 status = i2c_transfer(client->adapter, msg, 2); 246 237 if (status == 2) 247 238 status = count;
+1
drivers/misc/eeprom/max6875.c
··· 191 191 { "max6875", 0 }, 192 192 { } 193 193 }; 194 + MODULE_DEVICE_TABLE(i2c, max6875_id); 194 195 195 196 static struct i2c_driver max6875_driver = { 196 197 .driver = {
+1
drivers/of/irq.c
··· 432 432 433 433 return of_irq_get(dev, index); 434 434 } 435 + EXPORT_SYMBOL_GPL(of_irq_get_byname); 435 436 436 437 /** 437 438 * of_irq_count - Count the number of IRQs a node uses
+18
include/dt-bindings/i2c/i2c.h
··· 1 + /* 2 + * This header provides constants for I2C bindings 3 + * 4 + * Copyright (C) 2015 by Sang Engineering 5 + * Copyright (C) 2015 by Renesas Electronics Corporation 6 + * 7 + * Wolfram Sang <wsa@sang-engineering.com> 8 + * 9 + * GPLv2 only 10 + */ 11 + 12 + #ifndef _DT_BINDINGS_I2C_I2C_H 13 + #define _DT_BINDINGS_I2C_I2C_H 14 + 15 + #define I2C_TEN_BIT_ADDRESS (1 << 31) 16 + #define I2C_OWN_SLAVE_ADDRESS (1 << 30) 17 + 18 + #endif
+15 -4
include/linux/i2c.h
··· 121 121 extern s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, 122 122 u8 command, u8 length, 123 123 const u8 *values); 124 + extern s32 125 + i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, 126 + u8 command, u8 length, u8 *values); 124 127 #endif /* I2C */ 125 128 126 129 /** ··· 553 550 void i2c_unlock_adapter(struct i2c_adapter *); 554 551 555 552 /*flags for the client struct: */ 556 - #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ 557 - #define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ 553 + #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ 554 + #define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ 558 555 /* Must equal I2C_M_TEN below */ 559 - #define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */ 560 - #define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */ 556 + #define I2C_CLIENT_SLAVE 0x20 /* we are the slave */ 557 + #define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */ 558 + #define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */ 561 559 /* Must match I2C_M_STOP|IGNORE_NAK */ 562 560 563 561 /* i2c adapter classes (bitmask) */ ··· 642 638 /* must call put_device() when done with returned i2c_adapter device */ 643 639 extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); 644 640 641 + /* must call i2c_put_adapter() when done with returned i2c_adapter device */ 642 + struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node); 645 643 #else 646 644 647 645 static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) ··· 652 646 } 653 647 654 648 static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) 649 + { 650 + return NULL; 651 + } 652 + 653 + static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node) 655 654 { 656 655 return NULL; 657 656 }
+44
include/linux/platform_data/i2c-mux-reg.h
··· 1 + /* 2 + * I2C multiplexer using a single register 3 + * 4 + * Copyright 2015 Freescale Semiconductor 5 + * York Sun <yorksun@freescale.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License as published by the 9 + * Free Software Foundation; either version 2 of the License, or (at your 10 + * option) any later version. 11 + */ 12 + 13 + #ifndef __LINUX_PLATFORM_DATA_I2C_MUX_REG_H 14 + #define __LINUX_PLATFORM_DATA_I2C_MUX_REG_H 15 + 16 + /** 17 + * struct i2c_mux_reg_platform_data - Platform-dependent data for i2c-mux-reg 18 + * @parent: Parent I2C bus adapter number 19 + * @base_nr: Base I2C bus number to number adapters from or zero for dynamic 20 + * @values: Array of value for each channel 21 + * @n_values: Number of multiplexer channels 22 + * @little_endian: Indicating if the register is in little endian 23 + * @write_only: Reading the register is not allowed by hardware 24 + * @classes: Optional I2C auto-detection classes 25 + * @idle: Value to write to mux when idle 26 + * @idle_in_use: indicate if idle value is in use 27 + * @reg: Virtual address of the register to switch channel 28 + * @reg_size: register size in bytes 29 + */ 30 + struct i2c_mux_reg_platform_data { 31 + int parent; 32 + int base_nr; 33 + const unsigned int *values; 34 + int n_values; 35 + bool little_endian; 36 + bool write_only; 37 + const unsigned int *classes; 38 + u32 idle; 39 + bool idle_in_use; 40 + void __iomem *reg; 41 + resource_size_t reg_size; 42 + }; 43 + 44 + #endif /* __LINUX_PLATFORM_DATA_I2C_MUX_REG_H */