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

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

Pull i2c updates from Wolfram Sang:
"Here is the pull request from the i2c subsystem. It got a little
delayed because I needed to wait for a dependency to be included
(commit b424080a9e08: "reset: Add optional resets and stubs"). Plus,
I had some email problems. All done now, the highlights are:

- drivers can now deprecate their use of i2c classes. That shouldn't
be used on embedded platforms anyhow and was often blindly
copy&pasted. This mechanism gives users time to switch away and
ultimately boot faster once the use of classes for those drivers is
gone for good.

- new drivers for QUP, Cadence, efm32

- tracepoint support for I2C and SMBus

- bigger cleanups for the mv64xxx, nomadik, and designware drivers

And the usual bugfixes, cleanups, feature additions. Most stuff has
been in linux-next for a while. Just some hot fixes and new drivers
were added a bit more recently."

* 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (63 commits)
i2c: cadence: fix Kconfig dependency
i2c: Add driver for Cadence I2C controller
i2c: cadence: Document device tree bindings
Documentation: i2c: improve section about flags mangling the protocol
i2c: qup: use proper type fro clk_freq
i2c: qup: off by ones in qup_i2c_probe()
i2c: efm32: fix binding doc
MAINTAINERS: update I2C web resources
i2c: qup: New bus driver for the Qualcomm QUP I2C controller
i2c: qup: Add device tree bindings information
i2c: i2c-xiic: deprecate class based instantiation
i2c: i2c-sirf: deprecate class based instantiation
i2c: i2c-mv64xxx: deprecate class based instantiation
i2c: i2c-designware-platdrv: deprecate class based instantiation
i2c: i2c-davinci: deprecate class based instantiation
i2c: i2c-bcm2835: deprecate class based instantiation
i2c: mv64xxx: Fix reset controller handling
i2c: omap: fix usage of IS_ERR_VALUE with pm_runtime_get_sync
i2c: efm32: new bus driver
i2c: exynos5: remove unnecessary cast of void pointer
...

+3293 -502
+2
Documentation/devicetree/bindings/i2c/i2c-at91.txt
··· 12 12 - clocks: phandles to input clocks. 13 13 14 14 Optional properties: 15 + - clock-frequency: Desired I2C bus frequency in Hz, otherwise defaults to 100000 15 16 - Child nodes conforming to i2c bus binding 16 17 17 18 Examples : ··· 24 23 #address-cells = <1>; 25 24 #size-cells = <0>; 26 25 clocks = <&twi0_clk>; 26 + clock-frequency = <400000>; 27 27 28 28 24c512@50 { 29 29 compatible = "24c512";
+24
Documentation/devicetree/bindings/i2c/i2c-cadence.txt
··· 1 + Binding for the Cadence I2C controller 2 + 3 + Required properties: 4 + - reg: Physical base address and size of the controller's register area. 5 + - compatible: Compatibility string. Must be 'cdns,i2c-r1p10'. 6 + - clocks: Input clock specifier. Refer to common clock bindings. 7 + - interrupts: Interrupt specifier. Refer to interrupt bindings. 8 + - #address-cells: Should be 1. 9 + - #size-cells: Should be 0. 10 + 11 + Optional properties: 12 + - clock-frequency: Desired operating frequency, in Hz, of the bus. 13 + - clock-names: Input clock name, should be 'pclk'. 14 + 15 + Example: 16 + i2c@e0004000 { 17 + compatible = "cdns,i2c-r1p10"; 18 + clocks = <&clkc 38>; 19 + interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>; 20 + reg = <0xe0004000 0x1000>; 21 + clock-frequency = <400000>; 22 + #address-cells = <1>; 23 + #size-cells = <0>; 24 + };
+8
Documentation/devicetree/bindings/i2c/i2c-designware.txt
··· 14 14 - i2c-sda-hold-time-ns : should contain the SDA hold time in nanoseconds. 15 15 This option is only supported in hardware blocks version 1.11a or newer. 16 16 17 + - i2c-scl-falling-time : should contain the SCL falling time in nanoseconds. 18 + This value which is by default 300ns is used to compute the tLOW period. 19 + 20 + - i2c-sda-falling-time : should contain the SDA falling time in nanoseconds. 21 + This value which is by default 300ns is used to compute the tHIGH period. 22 + 17 23 Example : 18 24 19 25 i2c@f0000 { ··· 40 34 interrupts = <12 1>; 41 35 clock-frequency = <400000>; 42 36 i2c-sda-hold-time-ns = <300>; 37 + i2c-sda-falling-time-ns = <300>; 38 + i2c-scl-falling-time-ns = <300>; 43 39 };
+34
Documentation/devicetree/bindings/i2c/i2c-efm32.txt
··· 1 + * Energymicro efm32 i2c controller 2 + 3 + Required properties : 4 + 5 + - reg : Offset and length of the register set for the device 6 + - compatible : should be "energymicro,efm32-i2c" 7 + - interrupts : the interrupt number 8 + - clocks : reference to the module clock 9 + 10 + Recommended properties : 11 + 12 + - clock-frequency : maximal I2C bus clock frequency in Hz. 13 + - efm32,location : Decides the location of the USART I/O pins. 14 + Allowed range : [0 .. 6] 15 + 16 + Example: 17 + i2c0: i2c@4000a000 { 18 + #address-cells = <1>; 19 + #size-cells = <0>; 20 + compatible = "energymicro,efm32-i2c"; 21 + reg = <0x4000a000 0x400>; 22 + interrupts = <9>; 23 + clocks = <&cmu clk_HFPERCLKI2C0>; 24 + clock-frequency = <100000>; 25 + status = "ok"; 26 + efm32,location = <3>; 27 + 28 + eeprom@50 { 29 + compatible = "microchip,24c02"; 30 + reg = <0x50>; 31 + pagesize = <16>; 32 + }; 33 + }; 34 +
+14 -6
Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
··· 4 4 Required properties : 5 5 6 6 - reg : Offset and length of the register set for the device 7 - - compatible : Should be "marvell,mv64xxx-i2c" or "allwinner,sun4i-i2c" 8 - or "marvell,mv78230-i2c" or "marvell,mv78230-a0-i2c" 9 - Note: Only use "marvell,mv78230-a0-i2c" for a very rare, 10 - initial version of the SoC which had broken offload 11 - support. Linux auto-detects this and sets it 12 - appropriately. 7 + - compatible : Should be either: 8 + - "allwinner,sun4i-i2c" 9 + - "allwinner,sun6i-a31-i2c" 10 + - "marvell,mv64xxx-i2c" 11 + - "marvell,mv78230-i2c" 12 + - "marvell,mv78230-a0-i2c" 13 + * Note: Only use "marvell,mv78230-a0-i2c" for a 14 + very rare, initial version of the SoC which 15 + had broken offload support. Linux 16 + auto-detects this and sets it appropriately. 13 17 - interrupts : The interrupt number 14 18 15 19 Optional properties : 16 20 17 21 - clock-frequency : Desired I2C bus clock frequency in Hz. If not set the 18 22 default frequency is 100kHz 23 + 24 + - resets : phandle to the parent reset controller. Mandatory 25 + whenever you're using the "allwinner,sun6i-a31-i2c" 26 + compatible. 19 27 20 28 Examples: 21 29
+10 -4
Documentation/devicetree/bindings/i2c/i2c-rcar.txt
··· 6 6 "renesas,i2c-r8a7778" 7 7 "renesas,i2c-r8a7779" 8 8 "renesas,i2c-r8a7790" 9 + "renesas,i2c-r8a7791" 9 10 - reg: physical base address of the controller and length of memory mapped 10 11 region. 11 12 - interrupts: interrupt specifier. ··· 14 13 Optional properties: 15 14 - clock-frequency: desired I2C bus clock frequency in Hz. The absence of this 16 15 propoerty indicates the default frequency 100 kHz. 16 + - clocks: clock specifier. 17 17 18 18 Examples : 19 19 20 - i2c0: i2c@e6500000 { 21 - compatible = "renesas,i2c-rcar-h2"; 22 - reg = <0 0xe6500000 0 0x428>; 23 - interrupts = <0 174 0x4>; 20 + i2c0: i2c@e6508000 { 21 + #address-cells = <1>; 22 + #size-cells = <0>; 23 + compatible = "renesas,i2c-r8a7791"; 24 + reg = <0 0xe6508000 0 0x40>; 25 + interrupts = <0 287 IRQ_TYPE_LEVEL_HIGH>; 26 + clocks = <&mstp9_clks R8A7791_CLK_I2C0>; 27 + clock-frequency = <400000>; 24 28 };
+40
Documentation/devicetree/bindings/i2c/qcom,i2c-qup.txt
··· 1 + Qualcomm Universal Peripheral (QUP) I2C controller 2 + 3 + Required properties: 4 + - compatible: Should be: 5 + * "qcom,i2c-qup-v1.1.1" for 8660, 8960 and 8064. 6 + * "qcom,i2c-qup-v2.1.1" for 8974 v1. 7 + * "qcom,i2c-qup-v2.2.1" for 8974 v2 and later. 8 + - reg: Should contain QUP register address and length. 9 + - interrupts: Should contain I2C interrupt. 10 + 11 + - clocks: A list of phandles + clock-specifiers, one for each entry in 12 + clock-names. 13 + - clock-names: Should contain: 14 + * "core" for the core clock 15 + * "iface" for the AHB clock 16 + 17 + - #address-cells: Should be <1> Address cells for i2c device address 18 + - #size-cells: Should be <0> as i2c addresses have no size component 19 + 20 + Optional properties: 21 + - clock-frequency: Should specify the desired i2c bus clock frequency in Hz, 22 + defaults to 100kHz if omitted. 23 + 24 + Child nodes should conform to i2c bus binding. 25 + 26 + Example: 27 + 28 + i2c@f9924000 { 29 + compatible = "qcom,i2c-qup-v2.2.1"; 30 + reg = <0xf9924000 0x1000>; 31 + interrupts = <0 96 0>; 32 + 33 + clocks = <&gcc GCC_BLSP1_QUP2_I2C_APPS_CLK>, <&gcc GCC_BLSP1_AHB_CLK>; 34 + clock-names = "core", "iface"; 35 + 36 + clock-frequency = <355000>; 37 + 38 + #address-cells = <1>; 39 + #size-cells = <0>; 40 + };
+1
Documentation/i2c/busses/i2c-i801
··· 26 26 * Intel Wellsburg (PCH) 27 27 * Intel Coleto Creek (PCH) 28 28 * Intel Wildcat Point-LP (PCH) 29 + * Intel BayTrail (SOC) 29 30 Datasheets: Publicly available at the Intel website 30 31 31 32 On Intel Patsburg and later chipsets, both the normal host SMBus controller
+1 -1
Documentation/i2c/functionality
··· 46 46 and write_block_data commands 47 47 I2C_FUNC_SMBUS_I2C_BLOCK Handles the SMBus read_i2c_block_data 48 48 and write_i2c_block_data commands 49 - I2C_FUNC_SMBUS_EMUL Handles all SMBus commands than can be 49 + I2C_FUNC_SMBUS_EMUL Handles all SMBus commands that can be 50 50 emulated by a real I2C adapter (using 51 51 the transparent emulation layer) 52 52
+20 -15
Documentation/i2c/i2c-protocol
··· 6 6 S (1 bit) : Start bit 7 7 P (1 bit) : Stop bit 8 8 Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. 9 - A, NA (1 bit) : Accept and reverse accept bit. 10 - Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to 9 + A, NA (1 bit) : Accept and reverse accept bit. 10 + Addr (7 bits): I2C 7 bit address. Note that this can be expanded as usual to 11 11 get a 10 bit I2C address. 12 12 Comm (8 bits): Command byte, a data byte which often selects a register on 13 13 the device. ··· 49 49 Modified transactions 50 50 ===================== 51 51 52 - The following modifications to the I2C protocol can also be generated, 53 - with the exception of I2C_M_NOSTART these are usually only needed to 54 - work around device issues: 52 + The following modifications to the I2C protocol can also be generated by 53 + setting these flags for i2c messages. With the exception of I2C_M_NOSTART, they 54 + are usually only needed to work around device issues: 55 55 56 - Flag I2C_M_NOSTART: 56 + I2C_M_IGNORE_NAK: 57 + Normally message is interrupted immediately if there is [NA] from the 58 + client. Setting this flag treats any [NA] as [A], and all of 59 + message is sent. 60 + These messages may still fail to SCL lo->hi timeout. 61 + 62 + I2C_M_NO_RD_ACK: 63 + In a read message, master A/NA bit is skipped. 64 + 65 + I2C_M_NOSTART: 57 66 In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some 58 67 point. For example, setting I2C_M_NOSTART on the second partial message 59 68 generates something like: ··· 76 67 I2C device but may also be used between direction changes by some 77 68 rare devices. 78 69 79 - Flags I2C_M_REV_DIR_ADDR 70 + I2C_M_REV_DIR_ADDR: 80 71 This toggles the Rd/Wr flag. That is, if you want to do a write, but 81 72 need to emit an Rd instead of a Wr, or vice versa, you set this 82 73 flag. For example: 83 74 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P 84 75 85 - Flags I2C_M_IGNORE_NAK 86 - Normally message is interrupted immediately if there is [NA] from the 87 - client. Setting this flag treats any [NA] as [A], and all of 88 - message is sent. 89 - These messages may still fail to SCL lo->hi timeout. 90 - 91 - Flags I2C_M_NO_RD_ACK 92 - In a read message, master A/NA bit is skipped. 76 + I2C_M_STOP: 77 + Force a stop condition (P) after the message. Some I2C related protocols 78 + like SCCB require that. Normally, you really don't want to get interrupted 79 + between the messages of one transfer.
+3 -1
MAINTAINERS
··· 1427 1427 N: zynq 1428 1428 N: xilinx 1429 1429 F: drivers/clocksource/cadence_ttc_timer.c 1430 + F: drivers/i2c/busses/i2c-cadence.c 1430 1431 F: drivers/mmc/host/sdhci-of-arasan.c 1431 1432 1432 1433 ARM SMMU DRIVER ··· 4309 4308 I2C SUBSYSTEM 4310 4309 M: Wolfram Sang <wsa@the-dreams.de> 4311 4310 L: linux-i2c@vger.kernel.org 4312 - W: http://i2c.wiki.kernel.org/ 4311 + W: https://i2c.wiki.kernel.org/ 4312 + Q: https://patchwork.ozlabs.org/project/linux-i2c/list/ 4313 4313 T: git git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git 4314 4314 S: Maintained 4315 4315 F: Documentation/i2c/
+19 -124
arch/blackfin/include/asm/bfin_twi.h
··· 9 9 #ifndef __ASM_BFIN_TWI_H__ 10 10 #define __ASM_BFIN_TWI_H__ 11 11 12 - #include <linux/types.h> 13 - #include <linux/i2c.h> 14 - 15 - /* 16 - * All Blackfin system MMRs are padded to 32bits even if the register 17 - * itself is only 16bits. So use a helper macro to streamline this. 18 - */ 19 - #define __BFP(m) u16 m; u16 __pad_##m 20 - 21 - /* 22 - * bfin twi registers layout 23 - */ 24 - struct bfin_twi_regs { 25 - __BFP(clkdiv); 26 - __BFP(control); 27 - __BFP(slave_ctl); 28 - __BFP(slave_stat); 29 - __BFP(slave_addr); 30 - __BFP(master_ctl); 31 - __BFP(master_stat); 32 - __BFP(master_addr); 33 - __BFP(int_stat); 34 - __BFP(int_mask); 35 - __BFP(fifo_ctl); 36 - __BFP(fifo_stat); 37 - u32 __pad[20]; 38 - __BFP(xmt_data8); 39 - __BFP(xmt_data16); 40 - __BFP(rcv_data8); 41 - __BFP(rcv_data16); 42 - }; 43 - 44 - #undef __BFP 45 - 46 - struct bfin_twi_iface { 47 - int irq; 48 - spinlock_t lock; 49 - char read_write; 50 - u8 command; 51 - u8 *transPtr; 52 - int readNum; 53 - int writeNum; 54 - int cur_mode; 55 - int manual_stop; 56 - int result; 57 - struct i2c_adapter adap; 58 - struct completion complete; 59 - struct i2c_msg *pmsg; 60 - int msg_num; 61 - int cur_msg; 62 - u16 saved_clkdiv; 63 - u16 saved_control; 64 - struct bfin_twi_regs __iomem *regs_base; 65 - }; 12 + #include <asm/blackfin.h> 66 13 67 14 #define DEFINE_TWI_REG(reg_name, reg) \ 68 15 static inline u16 read_##reg_name(struct bfin_twi_iface *iface) \ ··· 18 71 { bfin_write16(&iface->regs_base->reg, v); } 19 72 20 73 DEFINE_TWI_REG(CLKDIV, clkdiv) 21 - DEFINE_TWI_REG(CONTROL, control) 22 74 DEFINE_TWI_REG(SLAVE_CTL, slave_ctl) 23 75 DEFINE_TWI_REG(SLAVE_STAT, slave_stat) 24 76 DEFINE_TWI_REG(SLAVE_ADDR, slave_addr) ··· 26 80 DEFINE_TWI_REG(MASTER_ADDR, master_addr) 27 81 DEFINE_TWI_REG(INT_STAT, int_stat) 28 82 DEFINE_TWI_REG(INT_MASK, int_mask) 29 - DEFINE_TWI_REG(FIFO_CTL, fifo_ctl) 30 83 DEFINE_TWI_REG(FIFO_STAT, fifo_stat) 31 84 DEFINE_TWI_REG(XMT_DATA8, xmt_data8) 32 85 DEFINE_TWI_REG(XMT_DATA16, xmt_data16) ··· 58 113 } 59 114 #endif 60 115 116 + static inline u16 read_FIFO_CTL(struct bfin_twi_iface *iface) 117 + { 118 + return bfin_read16(&iface->regs_base->fifo_ctl); 119 + } 61 120 62 - /* ******************** TWO-WIRE INTERFACE (TWI) MASKS ***********************/ 63 - /* TWI_CLKDIV Macros (Use: *pTWI_CLKDIV = CLKLOW(x)|CLKHI(y); ) */ 64 - #define CLKLOW(x) ((x) & 0xFF) /* Periods Clock Is Held Low */ 65 - #define CLKHI(y) (((y)&0xFF)<<0x8) /* Periods Before New Clock Low */ 121 + static inline void write_FIFO_CTL(struct bfin_twi_iface *iface, u16 v) 122 + { 123 + bfin_write16(&iface->regs_base->fifo_ctl, v); 124 + SSYNC(); 125 + } 66 126 67 - /* TWI_PRESCALE Masks */ 68 - #define PRESCALE 0x007F /* SCLKs Per Internal Time Reference (10MHz) */ 69 - #define TWI_ENA 0x0080 /* TWI Enable */ 70 - #define SCCB 0x0200 /* SCCB Compatibility Enable */ 127 + static inline u16 read_CONTROL(struct bfin_twi_iface *iface) 128 + { 129 + return bfin_read16(&iface->regs_base->control); 130 + } 71 131 72 - /* TWI_SLAVE_CTL Masks */ 73 - #define SEN 0x0001 /* Slave Enable */ 74 - #define SADD_LEN 0x0002 /* Slave Address Length */ 75 - #define STDVAL 0x0004 /* Slave Transmit Data Valid */ 76 - #define NAK 0x0008 /* NAK/ACK* Generated At Conclusion Of Transfer */ 77 - #define GEN 0x0010 /* General Call Address Matching Enabled */ 78 - 79 - /* TWI_SLAVE_STAT Masks */ 80 - #define SDIR 0x0001 /* Slave Transfer Direction (Transmit/Receive*) */ 81 - #define GCALL 0x0002 /* General Call Indicator */ 82 - 83 - /* TWI_MASTER_CTL Masks */ 84 - #define MEN 0x0001 /* Master Mode Enable */ 85 - #define MADD_LEN 0x0002 /* Master Address Length */ 86 - #define MDIR 0x0004 /* Master Transmit Direction (RX/TX*) */ 87 - #define FAST 0x0008 /* Use Fast Mode Timing Specs */ 88 - #define STOP 0x0010 /* Issue Stop Condition */ 89 - #define RSTART 0x0020 /* Repeat Start or Stop* At End Of Transfer */ 90 - #define DCNT 0x3FC0 /* Data Bytes To Transfer */ 91 - #define SDAOVR 0x4000 /* Serial Data Override */ 92 - #define SCLOVR 0x8000 /* Serial Clock Override */ 93 - 94 - /* TWI_MASTER_STAT Masks */ 95 - #define MPROG 0x0001 /* Master Transfer In Progress */ 96 - #define LOSTARB 0x0002 /* Lost Arbitration Indicator (Xfer Aborted) */ 97 - #define ANAK 0x0004 /* Address Not Acknowledged */ 98 - #define DNAK 0x0008 /* Data Not Acknowledged */ 99 - #define BUFRDERR 0x0010 /* Buffer Read Error */ 100 - #define BUFWRERR 0x0020 /* Buffer Write Error */ 101 - #define SDASEN 0x0040 /* Serial Data Sense */ 102 - #define SCLSEN 0x0080 /* Serial Clock Sense */ 103 - #define BUSBUSY 0x0100 /* Bus Busy Indicator */ 104 - 105 - /* TWI_INT_SRC and TWI_INT_ENABLE Masks */ 106 - #define SINIT 0x0001 /* Slave Transfer Initiated */ 107 - #define SCOMP 0x0002 /* Slave Transfer Complete */ 108 - #define SERR 0x0004 /* Slave Transfer Error */ 109 - #define SOVF 0x0008 /* Slave Overflow */ 110 - #define MCOMP 0x0010 /* Master Transfer Complete */ 111 - #define MERR 0x0020 /* Master Transfer Error */ 112 - #define XMTSERV 0x0040 /* Transmit FIFO Service */ 113 - #define RCVSERV 0x0080 /* Receive FIFO Service */ 114 - 115 - /* TWI_FIFO_CTRL Masks */ 116 - #define XMTFLUSH 0x0001 /* Transmit Buffer Flush */ 117 - #define RCVFLUSH 0x0002 /* Receive Buffer Flush */ 118 - #define XMTINTLEN 0x0004 /* Transmit Buffer Interrupt Length */ 119 - #define RCVINTLEN 0x0008 /* Receive Buffer Interrupt Length */ 120 - 121 - /* TWI_FIFO_STAT Masks */ 122 - #define XMTSTAT 0x0003 /* Transmit FIFO Status */ 123 - #define XMT_EMPTY 0x0000 /* Transmit FIFO Empty */ 124 - #define XMT_HALF 0x0001 /* Transmit FIFO Has 1 Byte To Write */ 125 - #define XMT_FULL 0x0003 /* Transmit FIFO Full (2 Bytes To Write) */ 126 - 127 - #define RCVSTAT 0x000C /* Receive FIFO Status */ 128 - #define RCV_EMPTY 0x0000 /* Receive FIFO Empty */ 129 - #define RCV_HALF 0x0004 /* Receive FIFO Has 1 Byte To Read */ 130 - #define RCV_FULL 0x000C /* Receive FIFO Full (2 Bytes To Read) */ 131 - 132 + static inline void write_CONTROL(struct bfin_twi_iface *iface, u16 v) 133 + { 134 + SSYNC(); 135 + bfin_write16(&iface->regs_base->control, v); 136 + } 132 137 #endif
+1
arch/blackfin/kernel/debug-mmrs.c
··· 10 10 #include <linux/fs.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/module.h> 13 + #include <linux/i2c/bfin_twi.h> 13 14 14 15 #include <asm/blackfin.h> 15 16 #include <asm/gpio.h>
+26 -1
drivers/i2c/busses/Kconfig
··· 110 110 Wellsburg (PCH) 111 111 Coleto Creek (PCH) 112 112 Wildcat Point-LP (PCH) 113 + BayTrail (SOC) 113 114 114 115 This driver can also be built as a module. If so, the module 115 116 will be called i2c-i801. ··· 376 375 help 377 376 The unit of the TWI clock is kHz. 378 377 378 + config I2C_CADENCE 379 + tristate "Cadence I2C Controller" 380 + depends on ARCH_ZYNQ 381 + help 382 + Say yes here to select Cadence I2C Host Controller. This controller is 383 + e.g. used by Xilinx Zynq. 384 + 379 385 config I2C_CBUS_GPIO 380 386 tristate "CBUS I2C driver" 381 387 depends on GPIOLIB ··· 439 431 440 432 This driver can also be built as a module. If so, the module 441 433 will be called i2c-designware-pci. 434 + 435 + config I2C_EFM32 436 + tristate "EFM32 I2C controller" 437 + depends on ARCH_EFM32 || COMPILE_TEST 438 + help 439 + This driver supports the i2c block found in Energy Micro's EFM32 440 + SoCs. 442 441 443 442 config I2C_EG20T 444 443 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) I2C" ··· 542 527 543 528 config I2C_MV64XXX 544 529 tristate "Marvell mv64xxx I2C Controller" 545 - depends on (MV64X60 || PLAT_ORION || ARCH_SUNXI) 530 + depends on MV64X60 || PLAT_ORION || ARCH_SUNXI 546 531 help 547 532 If you say yes to this option, support will be included for the 548 533 built-in I2C interface on the Marvell 64xxx line of host bridges. ··· 662 647 Support I2C slave mode communications on the PXA I2C bus. This 663 648 is necessary for systems where the PXA may be a target on the 664 649 I2C bus. 650 + 651 + config I2C_QUP 652 + tristate "Qualcomm QUP based I2C controller" 653 + depends on ARCH_QCOM 654 + help 655 + If you say yes to this option, support will be included for the 656 + built-in I2C interface on the Qualcomm SoCs. 657 + 658 + This driver can also be built as a module. If so, the module 659 + will be called i2c-qup. 665 660 666 661 config I2C_RIIC 667 662 tristate "Renesas RIIC adapter"
+3
drivers/i2c/busses/Makefile
··· 33 33 obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 34 34 obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o 35 35 obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o 36 + obj-$(CONFIG_I2C_CADENCE) += i2c-cadence.o 36 37 obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o 37 38 obj-$(CONFIG_I2C_CPM) += i2c-cpm.o 38 39 obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o ··· 42 41 i2c-designware-platform-objs := i2c-designware-platdrv.o 43 42 obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o 44 43 i2c-designware-pci-objs := i2c-designware-pcidrv.o 44 + obj-$(CONFIG_I2C_EFM32) += i2c-efm32.o 45 45 obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o 46 46 obj-$(CONFIG_I2C_EXYNOS5) += i2c-exynos5.o 47 47 obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o ··· 65 63 obj-$(CONFIG_I2C_PUV3) += i2c-puv3.o 66 64 obj-$(CONFIG_I2C_PXA) += i2c-pxa.o 67 65 obj-$(CONFIG_I2C_PXA_PCI) += i2c-pxa-pci.o 66 + obj-$(CONFIG_I2C_QUP) += i2c-qup.o 68 67 obj-$(CONFIG_I2C_RIIC) += i2c-riic.o 69 68 obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 70 69 obj-$(CONFIG_I2C_S6000) += i2c-s6000.o
+1 -1
drivers/i2c/busses/i2c-ali1535.c
··· 494 494 .algo = &smbus_algorithm, 495 495 }; 496 496 497 - static DEFINE_PCI_DEVICE_TABLE(ali1535_ids) = { 497 + static const struct pci_device_id ali1535_ids[] = { 498 498 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 499 499 { }, 500 500 };
+1 -1
drivers/i2c/busses/i2c-ali1563.c
··· 416 416 ali1563_shutdown(dev); 417 417 } 418 418 419 - static DEFINE_PCI_DEVICE_TABLE(ali1563_id_table) = { 419 + static const struct pci_device_id ali1563_id_table[] = { 420 420 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) }, 421 421 {}, 422 422 };
+1 -1
drivers/i2c/busses/i2c-ali15x3.c
··· 476 476 .algo = &smbus_algorithm, 477 477 }; 478 478 479 - static DEFINE_PCI_DEVICE_TABLE(ali15x3_ids) = { 479 + static const struct pci_device_id ali15x3_ids[] = { 480 480 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 481 481 { 0, } 482 482 };
+1 -1
drivers/i2c/busses/i2c-amd756.c
··· 307 307 "nVidia nForce", "AMD8111", 308 308 }; 309 309 310 - static DEFINE_PCI_DEVICE_TABLE(amd756_ids) = { 310 + static const struct pci_device_id amd756_ids[] = { 311 311 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B), 312 312 .driver_data = AMD756 }, 313 313 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413),
+1 -1
drivers/i2c/busses/i2c-amd8111.c
··· 414 414 }; 415 415 416 416 417 - static DEFINE_PCI_DEVICE_TABLE(amd8111_ids) = { 417 + static const struct pci_device_id amd8111_ids[] = { 418 418 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) }, 419 419 { 0, } 420 420 };
+9 -3
drivers/i2c/busses/i2c-at91.c
··· 32 32 #include <linux/slab.h> 33 33 #include <linux/platform_data/dma-atmel.h> 34 34 35 - #define TWI_CLK_HZ 100000 /* max 400 Kbits/s */ 35 + #define DEFAULT_TWI_CLK_HZ 100000 /* max 400 Kbits/s */ 36 36 #define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ 37 37 #define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */ 38 38 ··· 711 711 struct resource *mem; 712 712 int rc; 713 713 u32 phy_addr; 714 + u32 bus_clk_rate; 714 715 715 716 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 716 717 if (!dev) ··· 757 756 dev->use_dma = true; 758 757 } 759 758 760 - at91_calc_twi_clock(dev, TWI_CLK_HZ); 759 + rc = of_property_read_u32(dev->dev->of_node, "clock-frequency", 760 + &bus_clk_rate); 761 + if (rc) 762 + bus_clk_rate = DEFAULT_TWI_CLK_HZ; 763 + 764 + at91_calc_twi_clock(dev, bus_clk_rate); 761 765 at91_init_twi_bus(dev); 762 766 763 767 snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91"); 764 768 i2c_set_adapdata(&dev->adapter, dev); 765 769 dev->adapter.owner = THIS_MODULE; 766 - dev->adapter.class = I2C_CLASS_HWMON; 770 + dev->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 767 771 dev->adapter.algo = &at91_twi_algorithm; 768 772 dev->adapter.dev.parent = dev->dev; 769 773 dev->adapter.nr = pdev->id;
+5 -21
drivers/i2c/busses/i2c-bcm2835.c
··· 219 219 static int bcm2835_i2c_probe(struct platform_device *pdev) 220 220 { 221 221 struct bcm2835_i2c_dev *i2c_dev; 222 - struct resource *mem, *requested, *irq; 222 + struct resource *mem, *irq; 223 223 u32 bus_clk_rate, divider; 224 224 int ret; 225 225 struct i2c_adapter *adap; ··· 234 234 init_completion(&i2c_dev->completion); 235 235 236 236 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 237 - if (!mem) { 238 - dev_err(&pdev->dev, "No mem resource\n"); 239 - return -ENODEV; 240 - } 241 - 242 - requested = devm_request_mem_region(&pdev->dev, mem->start, 243 - resource_size(mem), 244 - dev_name(&pdev->dev)); 245 - if (!requested) { 246 - dev_err(&pdev->dev, "Could not claim register region\n"); 247 - return -EBUSY; 248 - } 249 - 250 - i2c_dev->regs = devm_ioremap(&pdev->dev, mem->start, 251 - resource_size(mem)); 252 - if (!i2c_dev->regs) { 253 - dev_err(&pdev->dev, "Could not map registers\n"); 254 - return -ENOMEM; 255 - } 237 + i2c_dev->regs = devm_ioremap_resource(&pdev->dev, mem); 238 + if (IS_ERR(i2c_dev->regs)) 239 + return PTR_ERR(i2c_dev->regs); 256 240 257 241 i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 258 242 if (IS_ERR(i2c_dev->clk)) { ··· 279 295 adap = &i2c_dev->adapter; 280 296 i2c_set_adapdata(adap, i2c_dev); 281 297 adap->owner = THIS_MODULE; 282 - adap->class = I2C_CLASS_HWMON; 298 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 283 299 strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name)); 284 300 adap->algo = &bcm2835_i2c_algo; 285 301 adap->dev.parent = &pdev->dev;
+3 -17
drivers/i2c/busses/i2c-bfin-twi.c
··· 21 21 #include <linux/interrupt.h> 22 22 #include <linux/platform_device.h> 23 23 #include <linux/delay.h> 24 + #include <linux/i2c/bfin_twi.h> 24 25 25 - #include <asm/blackfin.h> 26 - #include <asm/portmux.h> 27 26 #include <asm/irq.h> 27 + #include <asm/portmux.h> 28 28 #include <asm/bfin_twi.h> 29 29 30 30 /* SMBus mode*/ ··· 65 65 /* Transmit next data */ 66 66 while (iface->writeNum > 0 && 67 67 (read_FIFO_STAT(iface) & XMTSTAT) != XMT_FULL) { 68 - SSYNC(); 69 68 write_XMT_DATA8(iface, *(iface->transPtr++)); 70 69 iface->writeNum--; 71 70 } ··· 247 248 /* Clear interrupt status */ 248 249 write_INT_STAT(iface, twi_int_status); 249 250 bfin_twi_handle_interrupt(iface, twi_int_status); 250 - SSYNC(); 251 251 } 252 252 spin_unlock_irqrestore(&iface->lock, flags); 253 253 return IRQ_HANDLED; ··· 292 294 * discarded before start a new operation. 293 295 */ 294 296 write_FIFO_CTL(iface, 0x3); 295 - SSYNC(); 296 297 write_FIFO_CTL(iface, 0); 297 - SSYNC(); 298 298 299 299 if (pmsg->flags & I2C_M_RD) 300 300 iface->read_write = I2C_SMBUS_READ; ··· 302 306 if (iface->writeNum > 0) { 303 307 write_XMT_DATA8(iface, *(iface->transPtr++)); 304 308 iface->writeNum--; 305 - SSYNC(); 306 309 } 307 310 } 308 311 ··· 310 315 311 316 /* Interrupt mask . Enable XMT, RCV interrupt */ 312 317 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV); 313 - SSYNC(); 314 318 315 319 if (pmsg->len <= 255) 316 320 write_MASTER_CTL(iface, pmsg->len << 6); ··· 323 329 (iface->msg_num > 1 ? RSTART : 0) | 324 330 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | 325 331 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 326 - SSYNC(); 327 332 328 333 while (!iface->result) { 329 334 if (!wait_for_completion_timeout(&iface->complete, ··· 446 453 * start a new operation. 447 454 */ 448 455 write_FIFO_CTL(iface, 0x3); 449 - SSYNC(); 450 456 write_FIFO_CTL(iface, 0); 451 457 452 458 /* clear int stat */ ··· 453 461 454 462 /* Set Transmit device address */ 455 463 write_MASTER_ADDR(iface, addr); 456 - SSYNC(); 457 464 458 465 switch (iface->cur_mode) { 459 466 case TWI_I2C_MODE_STANDARDSUB: ··· 460 469 write_INT_MASK(iface, MCOMP | MERR | 461 470 ((iface->read_write == I2C_SMBUS_READ) ? 462 471 RCVSERV : XMTSERV)); 463 - SSYNC(); 464 472 465 473 if (iface->writeNum + 1 <= 255) 466 474 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6); ··· 474 484 case TWI_I2C_MODE_COMBINED: 475 485 write_XMT_DATA8(iface, iface->command); 476 486 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV); 477 - SSYNC(); 478 487 479 488 if (iface->writeNum > 0) 480 489 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6); ··· 520 531 write_INT_MASK(iface, MCOMP | MERR | 521 532 ((iface->read_write == I2C_SMBUS_READ) ? 522 533 RCVSERV : XMTSERV)); 523 - SSYNC(); 524 534 525 535 /* Master enable */ 526 536 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | ··· 527 539 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 528 540 break; 529 541 } 530 - SSYNC(); 531 542 532 543 while (!iface->result) { 533 544 if (!wait_for_completion_timeout(&iface->complete, ··· 656 669 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name)); 657 670 p_adap->algo = &bfin_twi_algorithm; 658 671 p_adap->algo_data = iface; 659 - p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 672 + p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 660 673 p_adap->dev.parent = &pdev->dev; 661 674 p_adap->timeout = 5 * HZ; 662 675 p_adap->retries = 3; ··· 691 704 692 705 /* Enable TWI */ 693 706 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA); 694 - SSYNC(); 695 707 696 708 rc = i2c_add_numbered_adapter(p_adap); 697 709 if (rc < 0) {
+905
drivers/i2c/busses/i2c-cadence.c
··· 1 + /* 2 + * I2C bus driver for the Cadence I2C controller. 3 + * 4 + * Copyright (C) 2009 - 2014 Xilinx, Inc. 5 + * 6 + * This program is free software; you can redistribute it 7 + * and/or modify it under the terms of the GNU General Public 8 + * License as published by the Free Software Foundation; 9 + * either version 2 of the License, or (at your option) any 10 + * later version. 11 + */ 12 + 13 + #include <linux/clk.h> 14 + #include <linux/delay.h> 15 + #include <linux/i2c.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/io.h> 18 + #include <linux/module.h> 19 + #include <linux/platform_device.h> 20 + 21 + /* Register offsets for the I2C device. */ 22 + #define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */ 23 + #define CDNS_I2C_SR_OFFSET 0x04 /* Status Register, RO */ 24 + #define CDNS_I2C_ADDR_OFFSET 0x08 /* I2C Address Register, RW */ 25 + #define CDNS_I2C_DATA_OFFSET 0x0C /* I2C Data Register, RW */ 26 + #define CDNS_I2C_ISR_OFFSET 0x10 /* IRQ Status Register, RW */ 27 + #define CDNS_I2C_XFER_SIZE_OFFSET 0x14 /* Transfer Size Register, RW */ 28 + #define CDNS_I2C_TIME_OUT_OFFSET 0x1C /* Time Out Register, RW */ 29 + #define CDNS_I2C_IER_OFFSET 0x24 /* IRQ Enable Register, WO */ 30 + #define CDNS_I2C_IDR_OFFSET 0x28 /* IRQ Disable Register, WO */ 31 + 32 + /* Control Register Bit mask definitions */ 33 + #define CDNS_I2C_CR_HOLD BIT(4) /* Hold Bus bit */ 34 + #define CDNS_I2C_CR_ACK_EN BIT(3) 35 + #define CDNS_I2C_CR_NEA BIT(2) 36 + #define CDNS_I2C_CR_MS BIT(1) 37 + /* Read or Write Master transfer 0 = Transmitter, 1 = Receiver */ 38 + #define CDNS_I2C_CR_RW BIT(0) 39 + /* 1 = Auto init FIFO to zeroes */ 40 + #define CDNS_I2C_CR_CLR_FIFO BIT(6) 41 + #define CDNS_I2C_CR_DIVA_SHIFT 14 42 + #define CDNS_I2C_CR_DIVA_MASK (3 << CDNS_I2C_CR_DIVA_SHIFT) 43 + #define CDNS_I2C_CR_DIVB_SHIFT 8 44 + #define CDNS_I2C_CR_DIVB_MASK (0x3f << CDNS_I2C_CR_DIVB_SHIFT) 45 + 46 + /* Status Register Bit mask definitions */ 47 + #define CDNS_I2C_SR_BA BIT(8) 48 + #define CDNS_I2C_SR_RXDV BIT(5) 49 + 50 + /* 51 + * I2C Address Register Bit mask definitions 52 + * Normal addressing mode uses [6:0] bits. Extended addressing mode uses [9:0] 53 + * bits. A write access to this register always initiates a transfer if the I2C 54 + * is in master mode. 55 + */ 56 + #define CDNS_I2C_ADDR_MASK 0x000003FF /* I2C Address Mask */ 57 + 58 + /* 59 + * I2C Interrupt Registers Bit mask definitions 60 + * All the four interrupt registers (Status/Mask/Enable/Disable) have the same 61 + * bit definitions. 62 + */ 63 + #define CDNS_I2C_IXR_ARB_LOST BIT(9) 64 + #define CDNS_I2C_IXR_RX_UNF BIT(7) 65 + #define CDNS_I2C_IXR_TX_OVF BIT(6) 66 + #define CDNS_I2C_IXR_RX_OVF BIT(5) 67 + #define CDNS_I2C_IXR_SLV_RDY BIT(4) 68 + #define CDNS_I2C_IXR_TO BIT(3) 69 + #define CDNS_I2C_IXR_NACK BIT(2) 70 + #define CDNS_I2C_IXR_DATA BIT(1) 71 + #define CDNS_I2C_IXR_COMP BIT(0) 72 + 73 + #define CDNS_I2C_IXR_ALL_INTR_MASK (CDNS_I2C_IXR_ARB_LOST | \ 74 + CDNS_I2C_IXR_RX_UNF | \ 75 + CDNS_I2C_IXR_TX_OVF | \ 76 + CDNS_I2C_IXR_RX_OVF | \ 77 + CDNS_I2C_IXR_SLV_RDY | \ 78 + CDNS_I2C_IXR_TO | \ 79 + CDNS_I2C_IXR_NACK | \ 80 + CDNS_I2C_IXR_DATA | \ 81 + CDNS_I2C_IXR_COMP) 82 + 83 + #define CDNS_I2C_IXR_ERR_INTR_MASK (CDNS_I2C_IXR_ARB_LOST | \ 84 + CDNS_I2C_IXR_RX_UNF | \ 85 + CDNS_I2C_IXR_TX_OVF | \ 86 + CDNS_I2C_IXR_RX_OVF | \ 87 + CDNS_I2C_IXR_NACK) 88 + 89 + #define CDNS_I2C_ENABLED_INTR_MASK (CDNS_I2C_IXR_ARB_LOST | \ 90 + CDNS_I2C_IXR_RX_UNF | \ 91 + CDNS_I2C_IXR_TX_OVF | \ 92 + CDNS_I2C_IXR_RX_OVF | \ 93 + CDNS_I2C_IXR_NACK | \ 94 + CDNS_I2C_IXR_DATA | \ 95 + CDNS_I2C_IXR_COMP) 96 + 97 + #define CDNS_I2C_TIMEOUT msecs_to_jiffies(1000) 98 + 99 + #define CDNS_I2C_FIFO_DEPTH 16 100 + /* FIFO depth at which the DATA interrupt occurs */ 101 + #define CDNS_I2C_DATA_INTR_DEPTH (CDNS_I2C_FIFO_DEPTH - 2) 102 + #define CDNS_I2C_MAX_TRANSFER_SIZE 255 103 + /* Transfer size in multiples of data interrupt depth */ 104 + #define CDNS_I2C_TRANSFER_SIZE (CDNS_I2C_MAX_TRANSFER_SIZE - 3) 105 + 106 + #define DRIVER_NAME "cdns-i2c" 107 + 108 + #define CDNS_I2C_SPEED_MAX 400000 109 + #define CDNS_I2C_SPEED_DEFAULT 100000 110 + 111 + #define CDNS_I2C_DIVA_MAX 4 112 + #define CDNS_I2C_DIVB_MAX 64 113 + 114 + #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) 115 + #define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset) 116 + 117 + /** 118 + * struct cdns_i2c - I2C device private data structure 119 + * @membase: Base address of the I2C device 120 + * @adap: I2C adapter instance 121 + * @p_msg: Message pointer 122 + * @err_status: Error status in Interrupt Status Register 123 + * @xfer_done: Transfer complete status 124 + * @p_send_buf: Pointer to transmit buffer 125 + * @p_recv_buf: Pointer to receive buffer 126 + * @suspended: Flag holding the device's PM status 127 + * @send_count: Number of bytes still expected to send 128 + * @recv_count: Number of bytes still expected to receive 129 + * @irq: IRQ number 130 + * @input_clk: Input clock to I2C controller 131 + * @i2c_clk: Maximum I2C clock speed 132 + * @bus_hold_flag: Flag used in repeated start for clearing HOLD bit 133 + * @clk: Pointer to struct clk 134 + * @clk_rate_change_nb: Notifier block for clock rate changes 135 + */ 136 + struct cdns_i2c { 137 + void __iomem *membase; 138 + struct i2c_adapter adap; 139 + struct i2c_msg *p_msg; 140 + int err_status; 141 + struct completion xfer_done; 142 + unsigned char *p_send_buf; 143 + unsigned char *p_recv_buf; 144 + u8 suspended; 145 + unsigned int send_count; 146 + unsigned int recv_count; 147 + int irq; 148 + unsigned long input_clk; 149 + unsigned int i2c_clk; 150 + unsigned int bus_hold_flag; 151 + struct clk *clk; 152 + struct notifier_block clk_rate_change_nb; 153 + }; 154 + 155 + #define to_cdns_i2c(_nb) container_of(_nb, struct cdns_i2c, \ 156 + clk_rate_change_nb) 157 + 158 + /** 159 + * cdns_i2c_clear_bus_hold() - Clear bus hold bit 160 + * @id: Pointer to driver data struct 161 + * 162 + * Helper to clear the controller's bus hold bit. 163 + */ 164 + static void cdns_i2c_clear_bus_hold(struct cdns_i2c *id) 165 + { 166 + u32 reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 167 + if (reg & CDNS_I2C_CR_HOLD) 168 + cdns_i2c_writereg(reg & ~CDNS_I2C_CR_HOLD, CDNS_I2C_CR_OFFSET); 169 + } 170 + 171 + /** 172 + * cdns_i2c_isr - Interrupt handler for the I2C device 173 + * @irq: irq number for the I2C device 174 + * @ptr: void pointer to cdns_i2c structure 175 + * 176 + * This function handles the data interrupt, transfer complete interrupt and 177 + * the error interrupts of the I2C device. 178 + * 179 + * Return: IRQ_HANDLED always 180 + */ 181 + static irqreturn_t cdns_i2c_isr(int irq, void *ptr) 182 + { 183 + unsigned int isr_status, avail_bytes; 184 + unsigned int bytes_to_recv, bytes_to_send; 185 + struct cdns_i2c *id = ptr; 186 + /* Signal completion only after everything is updated */ 187 + int done_flag = 0; 188 + irqreturn_t status = IRQ_NONE; 189 + 190 + isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); 191 + 192 + /* Handling nack and arbitration lost interrupt */ 193 + if (isr_status & (CDNS_I2C_IXR_NACK | CDNS_I2C_IXR_ARB_LOST)) { 194 + done_flag = 1; 195 + status = IRQ_HANDLED; 196 + } 197 + 198 + /* Handling Data interrupt */ 199 + if ((isr_status & CDNS_I2C_IXR_DATA) && 200 + (id->recv_count >= CDNS_I2C_DATA_INTR_DEPTH)) { 201 + /* Always read data interrupt threshold bytes */ 202 + bytes_to_recv = CDNS_I2C_DATA_INTR_DEPTH; 203 + id->recv_count -= CDNS_I2C_DATA_INTR_DEPTH; 204 + avail_bytes = cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET); 205 + 206 + /* 207 + * if the tranfer size register value is zero, then 208 + * check for the remaining bytes and update the 209 + * transfer size register. 210 + */ 211 + if (!avail_bytes) { 212 + if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) 213 + cdns_i2c_writereg(CDNS_I2C_TRANSFER_SIZE, 214 + CDNS_I2C_XFER_SIZE_OFFSET); 215 + else 216 + cdns_i2c_writereg(id->recv_count, 217 + CDNS_I2C_XFER_SIZE_OFFSET); 218 + } 219 + 220 + /* Process the data received */ 221 + while (bytes_to_recv--) 222 + *(id->p_recv_buf)++ = 223 + cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET); 224 + 225 + if (!id->bus_hold_flag && 226 + (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) 227 + cdns_i2c_clear_bus_hold(id); 228 + 229 + status = IRQ_HANDLED; 230 + } 231 + 232 + /* Handling Transfer Complete interrupt */ 233 + if (isr_status & CDNS_I2C_IXR_COMP) { 234 + if (!id->p_recv_buf) { 235 + /* 236 + * If the device is sending data If there is further 237 + * data to be sent. Calculate the available space 238 + * in FIFO and fill the FIFO with that many bytes. 239 + */ 240 + if (id->send_count) { 241 + avail_bytes = CDNS_I2C_FIFO_DEPTH - 242 + cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET); 243 + if (id->send_count > avail_bytes) 244 + bytes_to_send = avail_bytes; 245 + else 246 + bytes_to_send = id->send_count; 247 + 248 + while (bytes_to_send--) { 249 + cdns_i2c_writereg( 250 + (*(id->p_send_buf)++), 251 + CDNS_I2C_DATA_OFFSET); 252 + id->send_count--; 253 + } 254 + } else { 255 + /* 256 + * Signal the completion of transaction and 257 + * clear the hold bus bit if there are no 258 + * further messages to be processed. 259 + */ 260 + done_flag = 1; 261 + } 262 + if (!id->send_count && !id->bus_hold_flag) 263 + cdns_i2c_clear_bus_hold(id); 264 + } else { 265 + if (!id->bus_hold_flag) 266 + cdns_i2c_clear_bus_hold(id); 267 + /* 268 + * If the device is receiving data, then signal 269 + * the completion of transaction and read the data 270 + * present in the FIFO. Signal the completion of 271 + * transaction. 272 + */ 273 + while (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & 274 + CDNS_I2C_SR_RXDV) { 275 + *(id->p_recv_buf)++ = 276 + cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET); 277 + id->recv_count--; 278 + } 279 + done_flag = 1; 280 + } 281 + 282 + status = IRQ_HANDLED; 283 + } 284 + 285 + /* Update the status for errors */ 286 + id->err_status = isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; 287 + if (id->err_status) 288 + status = IRQ_HANDLED; 289 + 290 + cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET); 291 + 292 + if (done_flag) 293 + complete(&id->xfer_done); 294 + 295 + return status; 296 + } 297 + 298 + /** 299 + * cdns_i2c_mrecv - Prepare and start a master receive operation 300 + * @id: pointer to the i2c device structure 301 + */ 302 + static void cdns_i2c_mrecv(struct cdns_i2c *id) 303 + { 304 + unsigned int ctrl_reg; 305 + unsigned int isr_status; 306 + 307 + id->p_recv_buf = id->p_msg->buf; 308 + id->recv_count = id->p_msg->len; 309 + 310 + /* Put the controller in master receive mode and clear the FIFO */ 311 + ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 312 + ctrl_reg |= CDNS_I2C_CR_RW | CDNS_I2C_CR_CLR_FIFO; 313 + 314 + if (id->p_msg->flags & I2C_M_RECV_LEN) 315 + id->recv_count = I2C_SMBUS_BLOCK_MAX + 1; 316 + 317 + /* 318 + * Check for the message size against FIFO depth and set the 319 + * 'hold bus' bit if it is greater than FIFO depth. 320 + */ 321 + if (id->recv_count > CDNS_I2C_FIFO_DEPTH) 322 + ctrl_reg |= CDNS_I2C_CR_HOLD; 323 + 324 + cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET); 325 + 326 + /* Clear the interrupts in interrupt status register */ 327 + isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); 328 + cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET); 329 + 330 + /* 331 + * The no. of bytes to receive is checked against the limit of 332 + * max transfer size. Set transfer size register with no of bytes 333 + * receive if it is less than transfer size and transfer size if 334 + * it is more. Enable the interrupts. 335 + */ 336 + if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) 337 + cdns_i2c_writereg(CDNS_I2C_TRANSFER_SIZE, 338 + CDNS_I2C_XFER_SIZE_OFFSET); 339 + else 340 + cdns_i2c_writereg(id->recv_count, CDNS_I2C_XFER_SIZE_OFFSET); 341 + /* Clear the bus hold flag if bytes to receive is less than FIFO size */ 342 + if (!id->bus_hold_flag && 343 + ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && 344 + (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) 345 + cdns_i2c_clear_bus_hold(id); 346 + /* Set the slave address in address register - triggers operation */ 347 + cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, 348 + CDNS_I2C_ADDR_OFFSET); 349 + cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); 350 + } 351 + 352 + /** 353 + * cdns_i2c_msend - Prepare and start a master send operation 354 + * @id: pointer to the i2c device 355 + */ 356 + static void cdns_i2c_msend(struct cdns_i2c *id) 357 + { 358 + unsigned int avail_bytes; 359 + unsigned int bytes_to_send; 360 + unsigned int ctrl_reg; 361 + unsigned int isr_status; 362 + 363 + id->p_recv_buf = NULL; 364 + id->p_send_buf = id->p_msg->buf; 365 + id->send_count = id->p_msg->len; 366 + 367 + /* Set the controller in Master transmit mode and clear the FIFO. */ 368 + ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 369 + ctrl_reg &= ~CDNS_I2C_CR_RW; 370 + ctrl_reg |= CDNS_I2C_CR_CLR_FIFO; 371 + 372 + /* 373 + * Check for the message size against FIFO depth and set the 374 + * 'hold bus' bit if it is greater than FIFO depth. 375 + */ 376 + if (id->send_count > CDNS_I2C_FIFO_DEPTH) 377 + ctrl_reg |= CDNS_I2C_CR_HOLD; 378 + cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET); 379 + 380 + /* Clear the interrupts in interrupt status register. */ 381 + isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); 382 + cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET); 383 + 384 + /* 385 + * Calculate the space available in FIFO. Check the message length 386 + * against the space available, and fill the FIFO accordingly. 387 + * Enable the interrupts. 388 + */ 389 + avail_bytes = CDNS_I2C_FIFO_DEPTH - 390 + cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET); 391 + 392 + if (id->send_count > avail_bytes) 393 + bytes_to_send = avail_bytes; 394 + else 395 + bytes_to_send = id->send_count; 396 + 397 + while (bytes_to_send--) { 398 + cdns_i2c_writereg((*(id->p_send_buf)++), CDNS_I2C_DATA_OFFSET); 399 + id->send_count--; 400 + } 401 + 402 + /* 403 + * Clear the bus hold flag if there is no more data 404 + * and if it is the last message. 405 + */ 406 + if (!id->bus_hold_flag && !id->send_count) 407 + cdns_i2c_clear_bus_hold(id); 408 + /* Set the slave address in address register - triggers operation. */ 409 + cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, 410 + CDNS_I2C_ADDR_OFFSET); 411 + 412 + cdns_i2c_writereg(CDNS_I2C_ENABLED_INTR_MASK, CDNS_I2C_IER_OFFSET); 413 + } 414 + 415 + /** 416 + * cdns_i2c_master_reset - Reset the interface 417 + * @adap: pointer to the i2c adapter driver instance 418 + * 419 + * This function cleanup the fifos, clear the hold bit and status 420 + * and disable the interrupts. 421 + */ 422 + static void cdns_i2c_master_reset(struct i2c_adapter *adap) 423 + { 424 + struct cdns_i2c *id = adap->algo_data; 425 + u32 regval; 426 + 427 + /* Disable the interrupts */ 428 + cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK, CDNS_I2C_IDR_OFFSET); 429 + /* Clear the hold bit and fifos */ 430 + regval = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 431 + regval &= ~CDNS_I2C_CR_HOLD; 432 + regval |= CDNS_I2C_CR_CLR_FIFO; 433 + cdns_i2c_writereg(regval, CDNS_I2C_CR_OFFSET); 434 + /* Update the transfercount register to zero */ 435 + cdns_i2c_writereg(0, CDNS_I2C_XFER_SIZE_OFFSET); 436 + /* Clear the interupt status register */ 437 + regval = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); 438 + cdns_i2c_writereg(regval, CDNS_I2C_ISR_OFFSET); 439 + /* Clear the status register */ 440 + regval = cdns_i2c_readreg(CDNS_I2C_SR_OFFSET); 441 + cdns_i2c_writereg(regval, CDNS_I2C_SR_OFFSET); 442 + } 443 + 444 + static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, 445 + struct i2c_adapter *adap) 446 + { 447 + int ret; 448 + u32 reg; 449 + 450 + id->p_msg = msg; 451 + id->err_status = 0; 452 + reinit_completion(&id->xfer_done); 453 + 454 + /* Check for the TEN Bit mode on each msg */ 455 + reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 456 + if (msg->flags & I2C_M_TEN) { 457 + if (reg & CDNS_I2C_CR_NEA) 458 + cdns_i2c_writereg(reg & ~CDNS_I2C_CR_NEA, 459 + CDNS_I2C_CR_OFFSET); 460 + } else { 461 + if (!(reg & CDNS_I2C_CR_NEA)) 462 + cdns_i2c_writereg(reg | CDNS_I2C_CR_NEA, 463 + CDNS_I2C_CR_OFFSET); 464 + } 465 + 466 + /* Check for the R/W flag on each msg */ 467 + if (msg->flags & I2C_M_RD) 468 + cdns_i2c_mrecv(id); 469 + else 470 + cdns_i2c_msend(id); 471 + 472 + /* Wait for the signal of completion */ 473 + ret = wait_for_completion_timeout(&id->xfer_done, adap->timeout); 474 + if (!ret) { 475 + cdns_i2c_master_reset(adap); 476 + dev_err(id->adap.dev.parent, 477 + "timeout waiting on completion\n"); 478 + return -ETIMEDOUT; 479 + } 480 + 481 + cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK, 482 + CDNS_I2C_IDR_OFFSET); 483 + 484 + /* If it is bus arbitration error, try again */ 485 + if (id->err_status & CDNS_I2C_IXR_ARB_LOST) 486 + return -EAGAIN; 487 + 488 + return 0; 489 + } 490 + 491 + /** 492 + * cdns_i2c_master_xfer - The main i2c transfer function 493 + * @adap: pointer to the i2c adapter driver instance 494 + * @msgs: pointer to the i2c message structure 495 + * @num: the number of messages to transfer 496 + * 497 + * Initiates the send/recv activity based on the transfer message received. 498 + * 499 + * Return: number of msgs processed on success, negative error otherwise 500 + */ 501 + static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, 502 + int num) 503 + { 504 + int ret, count; 505 + u32 reg; 506 + struct cdns_i2c *id = adap->algo_data; 507 + 508 + /* Check if the bus is free */ 509 + if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA) 510 + return -EAGAIN; 511 + 512 + /* 513 + * Set the flag to one when multiple messages are to be 514 + * processed with a repeated start. 515 + */ 516 + if (num > 1) { 517 + id->bus_hold_flag = 1; 518 + reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 519 + reg |= CDNS_I2C_CR_HOLD; 520 + cdns_i2c_writereg(reg, CDNS_I2C_CR_OFFSET); 521 + } else { 522 + id->bus_hold_flag = 0; 523 + } 524 + 525 + /* Process the msg one by one */ 526 + for (count = 0; count < num; count++, msgs++) { 527 + if (count == (num - 1)) 528 + id->bus_hold_flag = 0; 529 + 530 + ret = cdns_i2c_process_msg(id, msgs, adap); 531 + if (ret) 532 + return ret; 533 + 534 + /* Report the other error interrupts to application */ 535 + if (id->err_status) { 536 + cdns_i2c_master_reset(adap); 537 + 538 + if (id->err_status & CDNS_I2C_IXR_NACK) 539 + return -ENXIO; 540 + 541 + return -EIO; 542 + } 543 + } 544 + 545 + return num; 546 + } 547 + 548 + /** 549 + * cdns_i2c_func - Returns the supported features of the I2C driver 550 + * @adap: pointer to the i2c adapter structure 551 + * 552 + * Return: 32 bit value, each bit corresponding to a feature 553 + */ 554 + static u32 cdns_i2c_func(struct i2c_adapter *adap) 555 + { 556 + return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | 557 + (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK) | 558 + I2C_FUNC_SMBUS_BLOCK_DATA; 559 + } 560 + 561 + static const struct i2c_algorithm cdns_i2c_algo = { 562 + .master_xfer = cdns_i2c_master_xfer, 563 + .functionality = cdns_i2c_func, 564 + }; 565 + 566 + /** 567 + * cdns_i2c_calc_divs - Calculate clock dividers 568 + * @f: I2C clock frequency 569 + * @input_clk: Input clock frequency 570 + * @a: First divider (return value) 571 + * @b: Second divider (return value) 572 + * 573 + * f is used as input and output variable. As input it is used as target I2C 574 + * frequency. On function exit f holds the actually resulting I2C frequency. 575 + * 576 + * Return: 0 on success, negative errno otherwise. 577 + */ 578 + static int cdns_i2c_calc_divs(unsigned long *f, unsigned long input_clk, 579 + unsigned int *a, unsigned int *b) 580 + { 581 + unsigned long fscl = *f, best_fscl = *f, actual_fscl, temp; 582 + unsigned int div_a, div_b, calc_div_a = 0, calc_div_b = 0; 583 + unsigned int last_error, current_error; 584 + 585 + /* calculate (divisor_a+1) x (divisor_b+1) */ 586 + temp = input_clk / (22 * fscl); 587 + 588 + /* 589 + * If the calculated value is negative or 0, the fscl input is out of 590 + * range. Return error. 591 + */ 592 + if (!temp || (temp > (CDNS_I2C_DIVA_MAX * CDNS_I2C_DIVB_MAX))) 593 + return -EINVAL; 594 + 595 + last_error = -1; 596 + for (div_a = 0; div_a < CDNS_I2C_DIVA_MAX; div_a++) { 597 + div_b = DIV_ROUND_UP(input_clk, 22 * fscl * (div_a + 1)); 598 + 599 + if ((div_b < 1) || (div_b > CDNS_I2C_DIVB_MAX)) 600 + continue; 601 + div_b--; 602 + 603 + actual_fscl = input_clk / (22 * (div_a + 1) * (div_b + 1)); 604 + 605 + if (actual_fscl > fscl) 606 + continue; 607 + 608 + current_error = ((actual_fscl > fscl) ? (actual_fscl - fscl) : 609 + (fscl - actual_fscl)); 610 + 611 + if (last_error > current_error) { 612 + calc_div_a = div_a; 613 + calc_div_b = div_b; 614 + best_fscl = actual_fscl; 615 + last_error = current_error; 616 + } 617 + } 618 + 619 + *a = calc_div_a; 620 + *b = calc_div_b; 621 + *f = best_fscl; 622 + 623 + return 0; 624 + } 625 + 626 + /** 627 + * cdns_i2c_setclk - This function sets the serial clock rate for the I2C device 628 + * @clk_in: I2C clock input frequency in Hz 629 + * @id: Pointer to the I2C device structure 630 + * 631 + * The device must be idle rather than busy transferring data before setting 632 + * these device options. 633 + * The data rate is set by values in the control register. 634 + * The formula for determining the correct register values is 635 + * Fscl = Fpclk/(22 x (divisor_a+1) x (divisor_b+1)) 636 + * See the hardware data sheet for a full explanation of setting the serial 637 + * clock rate. The clock can not be faster than the input clock divide by 22. 638 + * The two most common clock rates are 100KHz and 400KHz. 639 + * 640 + * Return: 0 on success, negative error otherwise 641 + */ 642 + static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id) 643 + { 644 + unsigned int div_a, div_b; 645 + unsigned int ctrl_reg; 646 + int ret = 0; 647 + unsigned long fscl = id->i2c_clk; 648 + 649 + ret = cdns_i2c_calc_divs(&fscl, clk_in, &div_a, &div_b); 650 + if (ret) 651 + return ret; 652 + 653 + ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); 654 + ctrl_reg &= ~(CDNS_I2C_CR_DIVA_MASK | CDNS_I2C_CR_DIVB_MASK); 655 + ctrl_reg |= ((div_a << CDNS_I2C_CR_DIVA_SHIFT) | 656 + (div_b << CDNS_I2C_CR_DIVB_SHIFT)); 657 + cdns_i2c_writereg(ctrl_reg, CDNS_I2C_CR_OFFSET); 658 + 659 + return 0; 660 + } 661 + 662 + /** 663 + * cdns_i2c_clk_notifier_cb - Clock rate change callback 664 + * @nb: Pointer to notifier block 665 + * @event: Notification reason 666 + * @data: Pointer to notification data object 667 + * 668 + * This function is called when the cdns_i2c input clock frequency changes. 669 + * The callback checks whether a valid bus frequency can be generated after the 670 + * change. If so, the change is acknowledged, otherwise the change is aborted. 671 + * New dividers are written to the HW in the pre- or post change notification 672 + * depending on the scaling direction. 673 + * 674 + * Return: NOTIFY_STOP if the rate change should be aborted, NOTIFY_OK 675 + * to acknowedge the change, NOTIFY_DONE if the notification is 676 + * considered irrelevant. 677 + */ 678 + static int cdns_i2c_clk_notifier_cb(struct notifier_block *nb, unsigned long 679 + event, void *data) 680 + { 681 + struct clk_notifier_data *ndata = data; 682 + struct cdns_i2c *id = to_cdns_i2c(nb); 683 + 684 + if (id->suspended) 685 + return NOTIFY_OK; 686 + 687 + switch (event) { 688 + case PRE_RATE_CHANGE: 689 + { 690 + unsigned long input_clk = ndata->new_rate; 691 + unsigned long fscl = id->i2c_clk; 692 + unsigned int div_a, div_b; 693 + int ret; 694 + 695 + ret = cdns_i2c_calc_divs(&fscl, input_clk, &div_a, &div_b); 696 + if (ret) { 697 + dev_warn(id->adap.dev.parent, 698 + "clock rate change rejected\n"); 699 + return NOTIFY_STOP; 700 + } 701 + 702 + /* scale up */ 703 + if (ndata->new_rate > ndata->old_rate) 704 + cdns_i2c_setclk(ndata->new_rate, id); 705 + 706 + return NOTIFY_OK; 707 + } 708 + case POST_RATE_CHANGE: 709 + id->input_clk = ndata->new_rate; 710 + /* scale down */ 711 + if (ndata->new_rate < ndata->old_rate) 712 + cdns_i2c_setclk(ndata->new_rate, id); 713 + return NOTIFY_OK; 714 + case ABORT_RATE_CHANGE: 715 + /* scale up */ 716 + if (ndata->new_rate > ndata->old_rate) 717 + cdns_i2c_setclk(ndata->old_rate, id); 718 + return NOTIFY_OK; 719 + default: 720 + return NOTIFY_DONE; 721 + } 722 + } 723 + 724 + /** 725 + * cdns_i2c_suspend - Suspend method for the driver 726 + * @_dev: Address of the platform_device structure 727 + * 728 + * Put the driver into low power mode. 729 + * 730 + * Return: 0 always 731 + */ 732 + static int __maybe_unused cdns_i2c_suspend(struct device *_dev) 733 + { 734 + struct platform_device *pdev = container_of(_dev, 735 + struct platform_device, dev); 736 + struct cdns_i2c *xi2c = platform_get_drvdata(pdev); 737 + 738 + clk_disable(xi2c->clk); 739 + xi2c->suspended = 1; 740 + 741 + return 0; 742 + } 743 + 744 + /** 745 + * cdns_i2c_resume - Resume from suspend 746 + * @_dev: Address of the platform_device structure 747 + * 748 + * Resume operation after suspend. 749 + * 750 + * Return: 0 on success and error value on error 751 + */ 752 + static int __maybe_unused cdns_i2c_resume(struct device *_dev) 753 + { 754 + struct platform_device *pdev = container_of(_dev, 755 + struct platform_device, dev); 756 + struct cdns_i2c *xi2c = platform_get_drvdata(pdev); 757 + int ret; 758 + 759 + ret = clk_enable(xi2c->clk); 760 + if (ret) { 761 + dev_err(_dev, "Cannot enable clock.\n"); 762 + return ret; 763 + } 764 + 765 + xi2c->suspended = 0; 766 + 767 + return 0; 768 + } 769 + 770 + static SIMPLE_DEV_PM_OPS(cdns_i2c_dev_pm_ops, cdns_i2c_suspend, 771 + cdns_i2c_resume); 772 + 773 + /** 774 + * cdns_i2c_probe - Platform registration call 775 + * @pdev: Handle to the platform device structure 776 + * 777 + * This function does all the memory allocation and registration for the i2c 778 + * device. User can modify the address mode to 10 bit address mode using the 779 + * ioctl call with option I2C_TENBIT. 780 + * 781 + * Return: 0 on success, negative error otherwise 782 + */ 783 + static int cdns_i2c_probe(struct platform_device *pdev) 784 + { 785 + struct resource *r_mem; 786 + struct cdns_i2c *id; 787 + int ret; 788 + 789 + id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); 790 + if (!id) 791 + return -ENOMEM; 792 + 793 + platform_set_drvdata(pdev, id); 794 + 795 + r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 796 + id->membase = devm_ioremap_resource(&pdev->dev, r_mem); 797 + if (IS_ERR(id->membase)) 798 + return PTR_ERR(id->membase); 799 + 800 + id->irq = platform_get_irq(pdev, 0); 801 + 802 + id->adap.dev.of_node = pdev->dev.of_node; 803 + id->adap.algo = &cdns_i2c_algo; 804 + id->adap.timeout = CDNS_I2C_TIMEOUT; 805 + id->adap.retries = 3; /* Default retry value. */ 806 + id->adap.algo_data = id; 807 + id->adap.dev.parent = &pdev->dev; 808 + init_completion(&id->xfer_done); 809 + snprintf(id->adap.name, sizeof(id->adap.name), 810 + "Cadence I2C at %08lx", (unsigned long)r_mem->start); 811 + 812 + id->clk = devm_clk_get(&pdev->dev, NULL); 813 + if (IS_ERR(id->clk)) { 814 + dev_err(&pdev->dev, "input clock not found.\n"); 815 + return PTR_ERR(id->clk); 816 + } 817 + ret = clk_prepare_enable(id->clk); 818 + if (ret) { 819 + dev_err(&pdev->dev, "Unable to enable clock.\n"); 820 + return ret; 821 + } 822 + id->clk_rate_change_nb.notifier_call = cdns_i2c_clk_notifier_cb; 823 + if (clk_notifier_register(id->clk, &id->clk_rate_change_nb)) 824 + dev_warn(&pdev->dev, "Unable to register clock notifier.\n"); 825 + id->input_clk = clk_get_rate(id->clk); 826 + 827 + ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", 828 + &id->i2c_clk); 829 + if (ret || (id->i2c_clk > CDNS_I2C_SPEED_MAX)) 830 + id->i2c_clk = CDNS_I2C_SPEED_DEFAULT; 831 + 832 + cdns_i2c_writereg(CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS, 833 + CDNS_I2C_CR_OFFSET); 834 + 835 + ret = cdns_i2c_setclk(id->input_clk, id); 836 + if (ret) { 837 + dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk); 838 + ret = -EINVAL; 839 + goto err_clk_dis; 840 + } 841 + 842 + ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0, 843 + DRIVER_NAME, id); 844 + if (ret) { 845 + dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); 846 + goto err_clk_dis; 847 + } 848 + 849 + ret = i2c_add_adapter(&id->adap); 850 + if (ret < 0) { 851 + dev_err(&pdev->dev, "reg adap failed: %d\n", ret); 852 + goto err_clk_dis; 853 + } 854 + 855 + dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n", 856 + id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); 857 + 858 + return 0; 859 + 860 + err_clk_dis: 861 + clk_disable_unprepare(id->clk); 862 + return ret; 863 + } 864 + 865 + /** 866 + * cdns_i2c_remove - Unregister the device after releasing the resources 867 + * @pdev: Handle to the platform device structure 868 + * 869 + * This function frees all the resources allocated to the device. 870 + * 871 + * Return: 0 always 872 + */ 873 + static int cdns_i2c_remove(struct platform_device *pdev) 874 + { 875 + struct cdns_i2c *id = platform_get_drvdata(pdev); 876 + 877 + i2c_del_adapter(&id->adap); 878 + clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); 879 + clk_disable_unprepare(id->clk); 880 + 881 + return 0; 882 + } 883 + 884 + static const struct of_device_id cdns_i2c_of_match[] = { 885 + { .compatible = "cdns,i2c-r1p10", }, 886 + { /* end of table */ } 887 + }; 888 + MODULE_DEVICE_TABLE(of, cdns_i2c_of_match); 889 + 890 + static struct platform_driver cdns_i2c_drv = { 891 + .driver = { 892 + .name = DRIVER_NAME, 893 + .owner = THIS_MODULE, 894 + .of_match_table = cdns_i2c_of_match, 895 + .pm = &cdns_i2c_dev_pm_ops, 896 + }, 897 + .probe = cdns_i2c_probe, 898 + .remove = cdns_i2c_remove, 899 + }; 900 + 901 + module_platform_driver(cdns_i2c_drv); 902 + 903 + MODULE_AUTHOR("Xilinx Inc."); 904 + MODULE_DESCRIPTION("Cadence I2C bus driver"); 905 + MODULE_LICENSE("GPL");
+1 -1
drivers/i2c/busses/i2c-davinci.c
··· 712 712 adap = &dev->adapter; 713 713 i2c_set_adapdata(adap, dev); 714 714 adap->owner = THIS_MODULE; 715 - adap->class = I2C_CLASS_HWMON; 715 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 716 716 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name)); 717 717 adap->algo = &i2c_davinci_algo; 718 718 adap->dev.parent = &pdev->dev;
+16 -11
drivers/i2c/busses/i2c-designware-core.c
··· 218 218 * 219 219 * If your hardware is free from tHD;STA issue, try this one. 220 220 */ 221 - return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset; 221 + return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset; 222 222 else 223 223 /* 224 224 * Conditional expression: ··· 234 234 * The reason why we need to take into account "tf" here, 235 235 * is the same as described in i2c_dw_scl_lcnt(). 236 236 */ 237 - return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset; 237 + return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000 238 + - 3 + offset; 238 239 } 239 240 240 241 static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) ··· 251 250 * account the fall time of SCL signal (tf). Default tf value 252 251 * should be 0.3 us, for safety. 253 252 */ 254 - return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; 253 + return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset; 255 254 } 256 255 257 256 static void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable) ··· 288 287 u32 input_clock_khz; 289 288 u32 hcnt, lcnt; 290 289 u32 reg; 290 + u32 sda_falling_time, scl_falling_time; 291 291 292 292 input_clock_khz = dev->get_clk_rate_khz(dev); 293 293 ··· 310 308 311 309 /* set standard and fast speed deviders for high/low periods */ 312 310 311 + sda_falling_time = dev->sda_falling_time ?: 300; /* ns */ 312 + scl_falling_time = dev->scl_falling_time ?: 300; /* ns */ 313 + 313 314 /* Standard-mode */ 314 315 hcnt = i2c_dw_scl_hcnt(input_clock_khz, 315 - 40, /* tHD;STA = tHIGH = 4.0 us */ 316 - 3, /* tf = 0.3 us */ 316 + 4000, /* tHD;STA = tHIGH = 4.0 us */ 317 + sda_falling_time, 317 318 0, /* 0: DW default, 1: Ideal */ 318 319 0); /* No offset */ 319 320 lcnt = i2c_dw_scl_lcnt(input_clock_khz, 320 - 47, /* tLOW = 4.7 us */ 321 - 3, /* tf = 0.3 us */ 321 + 4700, /* tLOW = 4.7 us */ 322 + scl_falling_time, 322 323 0); /* No offset */ 323 324 324 325 /* Allow platforms to specify the ideal HCNT and LCNT values */ ··· 335 330 336 331 /* Fast-mode */ 337 332 hcnt = i2c_dw_scl_hcnt(input_clock_khz, 338 - 6, /* tHD;STA = tHIGH = 0.6 us */ 339 - 3, /* tf = 0.3 us */ 333 + 600, /* tHD;STA = tHIGH = 0.6 us */ 334 + sda_falling_time, 340 335 0, /* 0: DW default, 1: Ideal */ 341 336 0); /* No offset */ 342 337 lcnt = i2c_dw_scl_lcnt(input_clock_khz, 343 - 13, /* tLOW = 1.3 us */ 344 - 3, /* tf = 0.3 us */ 338 + 1300, /* tLOW = 1.3 us */ 339 + scl_falling_time, 345 340 0); /* No offset */ 346 341 347 342 if (dev->fs_hcnt && dev->fs_lcnt) {
+2
drivers/i2c/busses/i2c-designware-core.h
··· 99 99 unsigned int rx_fifo_depth; 100 100 int rx_outstanding; 101 101 u32 sda_hold_time; 102 + u32 sda_falling_time; 103 + u32 scl_falling_time; 102 104 u16 ss_hcnt; 103 105 u16 ss_lcnt; 104 106 u16 fs_hcnt;
+66 -59
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 54 54 medfield_3, 55 55 medfield_4, 56 56 medfield_5, 57 + 58 + baytrail, 59 + }; 60 + 61 + struct dw_scl_sda_cfg { 62 + u32 ss_hcnt; 63 + u32 fs_hcnt; 64 + u32 ss_lcnt; 65 + u32 fs_lcnt; 66 + u32 sda_hold; 57 67 }; 58 68 59 69 struct dw_pci_controller { ··· 72 62 u32 tx_fifo_depth; 73 63 u32 rx_fifo_depth; 74 64 u32 clk_khz; 65 + u32 functionality; 66 + struct dw_scl_sda_cfg *scl_sda_cfg; 75 67 }; 76 68 77 69 #define INTEL_MID_STD_CFG (DW_IC_CON_MASTER | \ 78 70 DW_IC_CON_SLAVE_DISABLE | \ 79 71 DW_IC_CON_RESTART_EN) 72 + 73 + #define DW_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \ 74 + I2C_FUNC_SMBUS_BYTE | \ 75 + I2C_FUNC_SMBUS_BYTE_DATA | \ 76 + I2C_FUNC_SMBUS_WORD_DATA | \ 77 + I2C_FUNC_SMBUS_I2C_BLOCK) 78 + 79 + /* BayTrail HCNT/LCNT/SDA hold time */ 80 + static struct dw_scl_sda_cfg byt_config = { 81 + .ss_hcnt = 0x200, 82 + .fs_hcnt = 0x55, 83 + .ss_lcnt = 0x200, 84 + .fs_lcnt = 0x99, 85 + .sda_hold = 0x6, 86 + }; 80 87 81 88 static struct dw_pci_controller dw_pci_controllers[] = { 82 89 [moorestown_0] = { ··· 159 132 .rx_fifo_depth = 32, 160 133 .clk_khz = 25000, 161 134 }, 135 + [baytrail] = { 136 + .bus_num = -1, 137 + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, 138 + .tx_fifo_depth = 32, 139 + .rx_fifo_depth = 32, 140 + .clk_khz = 100000, 141 + .functionality = I2C_FUNC_10BIT_ADDR, 142 + .scl_sda_cfg = &byt_config, 143 + }, 162 144 }; 163 145 static struct i2c_algorithm i2c_dw_algo = { 164 146 .master_xfer = i2c_dw_xfer, 165 147 .functionality = i2c_dw_func, 166 148 }; 167 149 150 + #ifdef CONFIG_PM 168 151 static int i2c_dw_pci_suspend(struct device *dev) 169 152 { 170 153 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); 171 - struct dw_i2c_dev *i2c = pci_get_drvdata(pdev); 172 - int err; 173 154 174 - 175 - i2c_dw_disable(i2c); 176 - 177 - err = pci_save_state(pdev); 178 - if (err) { 179 - dev_err(&pdev->dev, "pci_save_state failed\n"); 180 - return err; 181 - } 182 - 183 - err = pci_set_power_state(pdev, PCI_D3hot); 184 - if (err) { 185 - dev_err(&pdev->dev, "pci_set_power_state failed\n"); 186 - return err; 187 - } 188 - 155 + i2c_dw_disable(pci_get_drvdata(pdev)); 189 156 return 0; 190 157 } 191 158 192 159 static int i2c_dw_pci_resume(struct device *dev) 193 160 { 194 161 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); 195 - struct dw_i2c_dev *i2c = pci_get_drvdata(pdev); 196 - int err; 197 - u32 enabled; 198 162 199 - enabled = i2c_dw_is_enabled(i2c); 200 - if (enabled) 201 - return 0; 202 - 203 - err = pci_set_power_state(pdev, PCI_D0); 204 - if (err) { 205 - dev_err(&pdev->dev, "pci_set_power_state() failed\n"); 206 - return err; 207 - } 208 - 209 - pci_restore_state(pdev); 210 - 211 - i2c_dw_init(i2c); 212 - return 0; 163 + return i2c_dw_init(pci_get_drvdata(pdev)); 213 164 } 165 + #endif 214 166 215 - static int i2c_dw_pci_runtime_idle(struct device *dev) 216 - { 217 - int err = pm_schedule_suspend(dev, 500); 218 - dev_dbg(dev, "runtime_idle called\n"); 219 - 220 - if (err != 0) 221 - return 0; 222 - return -EBUSY; 223 - } 224 - 225 - static const struct dev_pm_ops i2c_dw_pm_ops = { 226 - .resume = i2c_dw_pci_resume, 227 - .suspend = i2c_dw_pci_suspend, 228 - SET_RUNTIME_PM_OPS(i2c_dw_pci_suspend, i2c_dw_pci_resume, 229 - i2c_dw_pci_runtime_idle) 230 - }; 167 + static UNIVERSAL_DEV_PM_OPS(i2c_dw_pm_ops, i2c_dw_pci_suspend, 168 + i2c_dw_pci_resume, NULL); 231 169 232 170 static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) 233 171 { ··· 206 214 struct i2c_adapter *adap; 207 215 int r; 208 216 struct dw_pci_controller *controller; 217 + struct dw_scl_sda_cfg *cfg; 209 218 210 219 if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) { 211 220 dev_err(&pdev->dev, "%s: invalid driver data %ld\n", __func__, ··· 240 247 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; 241 248 dev->base = pcim_iomap_table(pdev)[0]; 242 249 dev->dev = &pdev->dev; 243 - dev->functionality = 244 - I2C_FUNC_I2C | 245 - I2C_FUNC_SMBUS_BYTE | 246 - I2C_FUNC_SMBUS_BYTE_DATA | 247 - I2C_FUNC_SMBUS_WORD_DATA | 248 - I2C_FUNC_SMBUS_I2C_BLOCK; 250 + dev->functionality = controller->functionality | 251 + DW_DEFAULT_FUNCTIONALITY; 252 + 249 253 dev->master_cfg = controller->bus_cfg; 254 + if (controller->scl_sda_cfg) { 255 + cfg = controller->scl_sda_cfg; 256 + dev->ss_hcnt = cfg->ss_hcnt; 257 + dev->fs_hcnt = cfg->fs_hcnt; 258 + dev->ss_lcnt = cfg->ss_lcnt; 259 + dev->fs_lcnt = cfg->fs_lcnt; 260 + dev->sda_hold_time = cfg->sda_hold; 261 + } 250 262 251 263 pci_set_drvdata(pdev, dev); 252 264 ··· 268 270 adap->algo = &i2c_dw_algo; 269 271 adap->dev.parent = &pdev->dev; 270 272 adap->nr = controller->bus_num; 271 - snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d", 272 - adap->nr); 273 + 274 + snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci"); 273 275 274 276 r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, IRQF_SHARED, 275 277 adap->name, dev); ··· 288 290 289 291 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 290 292 pm_runtime_use_autosuspend(&pdev->dev); 293 + pm_runtime_put_autosuspend(&pdev->dev); 291 294 pm_runtime_allow(&pdev->dev); 292 295 293 296 return 0; ··· 308 309 /* work with hotplug and coldplug */ 309 310 MODULE_ALIAS("i2c_designware-pci"); 310 311 311 - static DEFINE_PCI_DEVICE_TABLE(i2_designware_pci_ids) = { 312 + static const struct pci_device_id i2_designware_pci_ids[] = { 312 313 /* Moorestown */ 313 314 { PCI_VDEVICE(INTEL, 0x0802), moorestown_0 }, 314 315 { PCI_VDEVICE(INTEL, 0x0803), moorestown_1 }, ··· 320 321 { PCI_VDEVICE(INTEL, 0x082C), medfield_0 }, 321 322 { PCI_VDEVICE(INTEL, 0x082D), medfield_1 }, 322 323 { PCI_VDEVICE(INTEL, 0x082E), medfield_2 }, 324 + /* Baytrail */ 325 + { PCI_VDEVICE(INTEL, 0x0F41), baytrail }, 326 + { PCI_VDEVICE(INTEL, 0x0F42), baytrail }, 327 + { PCI_VDEVICE(INTEL, 0x0F43), baytrail }, 328 + { PCI_VDEVICE(INTEL, 0x0F44), baytrail }, 329 + { PCI_VDEVICE(INTEL, 0x0F45), baytrail }, 330 + { PCI_VDEVICE(INTEL, 0x0F46), baytrail }, 331 + { PCI_VDEVICE(INTEL, 0x0F47), baytrail }, 323 332 { 0,} 324 333 }; 325 334 MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids);
+8 -1
drivers/i2c/busses/i2c-designware-platdrv.c
··· 159 159 "i2c-sda-hold-time-ns", &ht); 160 160 dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000, 161 161 1000000); 162 + 163 + of_property_read_u32(pdev->dev.of_node, 164 + "i2c-sda-falling-time-ns", 165 + &dev->sda_falling_time); 166 + of_property_read_u32(pdev->dev.of_node, 167 + "i2c-scl-falling-time-ns", 168 + &dev->scl_falling_time); 162 169 } 163 170 164 171 dev->functionality = ··· 202 195 adap = &dev->adapter; 203 196 i2c_set_adapdata(adap, dev); 204 197 adap->owner = THIS_MODULE; 205 - adap->class = I2C_CLASS_HWMON; 198 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 206 199 strlcpy(adap->name, "Synopsys DesignWare I2C adapter", 207 200 sizeof(adap->name)); 208 201 adap->algo = &i2c_dw_algo;
+481
drivers/i2c/busses/i2c-efm32.c
··· 1 + /* 2 + * Copyright (C) 2014 Uwe Kleine-Koenig for Pengutronix 3 + * 4 + * This program is free software; you can redistribute it and/or modify it under 5 + * the terms of the GNU General Public License version 2 as published by the 6 + * Free Software Foundation. 7 + */ 8 + #include <linux/module.h> 9 + #include <linux/platform_device.h> 10 + #include <linux/i2c.h> 11 + #include <linux/io.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/err.h> 14 + #include <linux/clk.h> 15 + 16 + #define DRIVER_NAME "efm32-i2c" 17 + 18 + #define MASK_VAL(mask, val) ((val << __ffs(mask)) & mask) 19 + 20 + #define REG_CTRL 0x00 21 + #define REG_CTRL_EN 0x00001 22 + #define REG_CTRL_SLAVE 0x00002 23 + #define REG_CTRL_AUTOACK 0x00004 24 + #define REG_CTRL_AUTOSE 0x00008 25 + #define REG_CTRL_AUTOSN 0x00010 26 + #define REG_CTRL_ARBDIS 0x00020 27 + #define REG_CTRL_GCAMEN 0x00040 28 + #define REG_CTRL_CLHR__MASK 0x00300 29 + #define REG_CTRL_BITO__MASK 0x03000 30 + #define REG_CTRL_BITO_OFF 0x00000 31 + #define REG_CTRL_BITO_40PCC 0x01000 32 + #define REG_CTRL_BITO_80PCC 0x02000 33 + #define REG_CTRL_BITO_160PCC 0x03000 34 + #define REG_CTRL_GIBITO 0x08000 35 + #define REG_CTRL_CLTO__MASK 0x70000 36 + #define REG_CTRL_CLTO_OFF 0x00000 37 + 38 + #define REG_CMD 0x04 39 + #define REG_CMD_START 0x00001 40 + #define REG_CMD_STOP 0x00002 41 + #define REG_CMD_ACK 0x00004 42 + #define REG_CMD_NACK 0x00008 43 + #define REG_CMD_CONT 0x00010 44 + #define REG_CMD_ABORT 0x00020 45 + #define REG_CMD_CLEARTX 0x00040 46 + #define REG_CMD_CLEARPC 0x00080 47 + 48 + #define REG_STATE 0x08 49 + #define REG_STATE_BUSY 0x00001 50 + #define REG_STATE_MASTER 0x00002 51 + #define REG_STATE_TRANSMITTER 0x00004 52 + #define REG_STATE_NACKED 0x00008 53 + #define REG_STATE_BUSHOLD 0x00010 54 + #define REG_STATE_STATE__MASK 0x000e0 55 + #define REG_STATE_STATE_IDLE 0x00000 56 + #define REG_STATE_STATE_WAIT 0x00020 57 + #define REG_STATE_STATE_START 0x00040 58 + #define REG_STATE_STATE_ADDR 0x00060 59 + #define REG_STATE_STATE_ADDRACK 0x00080 60 + #define REG_STATE_STATE_DATA 0x000a0 61 + #define REG_STATE_STATE_DATAACK 0x000c0 62 + 63 + #define REG_STATUS 0x0c 64 + #define REG_STATUS_PSTART 0x00001 65 + #define REG_STATUS_PSTOP 0x00002 66 + #define REG_STATUS_PACK 0x00004 67 + #define REG_STATUS_PNACK 0x00008 68 + #define REG_STATUS_PCONT 0x00010 69 + #define REG_STATUS_PABORT 0x00020 70 + #define REG_STATUS_TXC 0x00040 71 + #define REG_STATUS_TXBL 0x00080 72 + #define REG_STATUS_RXDATAV 0x00100 73 + 74 + #define REG_CLKDIV 0x10 75 + #define REG_CLKDIV_DIV__MASK 0x001ff 76 + #define REG_CLKDIV_DIV(div) MASK_VAL(REG_CLKDIV_DIV__MASK, (div)) 77 + 78 + #define REG_SADDR 0x14 79 + #define REG_SADDRMASK 0x18 80 + #define REG_RXDATA 0x1c 81 + #define REG_RXDATAP 0x20 82 + #define REG_TXDATA 0x24 83 + #define REG_IF 0x28 84 + #define REG_IF_START 0x00001 85 + #define REG_IF_RSTART 0x00002 86 + #define REG_IF_ADDR 0x00004 87 + #define REG_IF_TXC 0x00008 88 + #define REG_IF_TXBL 0x00010 89 + #define REG_IF_RXDATAV 0x00020 90 + #define REG_IF_ACK 0x00040 91 + #define REG_IF_NACK 0x00080 92 + #define REG_IF_MSTOP 0x00100 93 + #define REG_IF_ARBLOST 0x00200 94 + #define REG_IF_BUSERR 0x00400 95 + #define REG_IF_BUSHOLD 0x00800 96 + #define REG_IF_TXOF 0x01000 97 + #define REG_IF_RXUF 0x02000 98 + #define REG_IF_BITO 0x04000 99 + #define REG_IF_CLTO 0x08000 100 + #define REG_IF_SSTOP 0x10000 101 + 102 + #define REG_IFS 0x2c 103 + #define REG_IFC 0x30 104 + #define REG_IFC__MASK 0x1ffcf 105 + 106 + #define REG_IEN 0x34 107 + 108 + #define REG_ROUTE 0x38 109 + #define REG_ROUTE_SDAPEN 0x00001 110 + #define REG_ROUTE_SCLPEN 0x00002 111 + #define REG_ROUTE_LOCATION__MASK 0x00700 112 + #define REG_ROUTE_LOCATION(n) MASK_VAL(REG_ROUTE_LOCATION__MASK, (n)) 113 + 114 + struct efm32_i2c_ddata { 115 + struct i2c_adapter adapter; 116 + 117 + struct clk *clk; 118 + void __iomem *base; 119 + unsigned int irq; 120 + u8 location; 121 + unsigned long frequency; 122 + 123 + /* transfer data */ 124 + struct completion done; 125 + struct i2c_msg *msgs; 126 + size_t num_msgs; 127 + size_t current_word, current_msg; 128 + int retval; 129 + }; 130 + 131 + static u32 efm32_i2c_read32(struct efm32_i2c_ddata *ddata, unsigned offset) 132 + { 133 + return readl(ddata->base + offset); 134 + } 135 + 136 + static void efm32_i2c_write32(struct efm32_i2c_ddata *ddata, 137 + unsigned offset, u32 value) 138 + { 139 + writel(value, ddata->base + offset); 140 + } 141 + 142 + static void efm32_i2c_send_next_msg(struct efm32_i2c_ddata *ddata) 143 + { 144 + struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg]; 145 + 146 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_START); 147 + efm32_i2c_write32(ddata, REG_TXDATA, cur_msg->addr << 1 | 148 + (cur_msg->flags & I2C_M_RD ? 1 : 0)); 149 + } 150 + 151 + static void efm32_i2c_send_next_byte(struct efm32_i2c_ddata *ddata) 152 + { 153 + struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg]; 154 + 155 + if (ddata->current_word >= cur_msg->len) { 156 + /* cur_msg completely transferred */ 157 + ddata->current_word = 0; 158 + ddata->current_msg += 1; 159 + 160 + if (ddata->current_msg >= ddata->num_msgs) { 161 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP); 162 + complete(&ddata->done); 163 + } else { 164 + efm32_i2c_send_next_msg(ddata); 165 + } 166 + } else { 167 + efm32_i2c_write32(ddata, REG_TXDATA, 168 + cur_msg->buf[ddata->current_word++]); 169 + } 170 + } 171 + 172 + static void efm32_i2c_recv_next_byte(struct efm32_i2c_ddata *ddata) 173 + { 174 + struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg]; 175 + 176 + cur_msg->buf[ddata->current_word] = efm32_i2c_read32(ddata, REG_RXDATA); 177 + ddata->current_word += 1; 178 + if (ddata->current_word >= cur_msg->len) { 179 + /* cur_msg completely transferred */ 180 + ddata->current_word = 0; 181 + ddata->current_msg += 1; 182 + 183 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_NACK); 184 + 185 + if (ddata->current_msg >= ddata->num_msgs) { 186 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP); 187 + complete(&ddata->done); 188 + } else { 189 + efm32_i2c_send_next_msg(ddata); 190 + } 191 + } else { 192 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_ACK); 193 + } 194 + } 195 + 196 + static irqreturn_t efm32_i2c_irq(int irq, void *dev_id) 197 + { 198 + struct efm32_i2c_ddata *ddata = dev_id; 199 + struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg]; 200 + u32 irqflag = efm32_i2c_read32(ddata, REG_IF); 201 + u32 state = efm32_i2c_read32(ddata, REG_STATE); 202 + 203 + efm32_i2c_write32(ddata, REG_IFC, irqflag & REG_IFC__MASK); 204 + 205 + switch (state & REG_STATE_STATE__MASK) { 206 + case REG_STATE_STATE_IDLE: 207 + /* arbitration lost? */ 208 + ddata->retval = -EAGAIN; 209 + complete(&ddata->done); 210 + break; 211 + case REG_STATE_STATE_WAIT: 212 + /* 213 + * huh, this shouldn't happen. 214 + * Reset hardware state and get out 215 + */ 216 + ddata->retval = -EIO; 217 + efm32_i2c_write32(ddata, REG_CMD, 218 + REG_CMD_STOP | REG_CMD_ABORT | 219 + REG_CMD_CLEARTX | REG_CMD_CLEARPC); 220 + complete(&ddata->done); 221 + break; 222 + case REG_STATE_STATE_START: 223 + /* "caller" is expected to send an address */ 224 + break; 225 + case REG_STATE_STATE_ADDR: 226 + /* wait for Ack or NAck of slave */ 227 + break; 228 + case REG_STATE_STATE_ADDRACK: 229 + if (state & REG_STATE_NACKED) { 230 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP); 231 + ddata->retval = -ENXIO; 232 + complete(&ddata->done); 233 + } else if (cur_msg->flags & I2C_M_RD) { 234 + /* wait for slave to send first data byte */ 235 + } else { 236 + efm32_i2c_send_next_byte(ddata); 237 + } 238 + break; 239 + case REG_STATE_STATE_DATA: 240 + if (cur_msg->flags & I2C_M_RD) { 241 + efm32_i2c_recv_next_byte(ddata); 242 + } else { 243 + /* wait for Ack or Nack of slave */ 244 + } 245 + break; 246 + case REG_STATE_STATE_DATAACK: 247 + if (state & REG_STATE_NACKED) { 248 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_STOP); 249 + complete(&ddata->done); 250 + } else { 251 + efm32_i2c_send_next_byte(ddata); 252 + } 253 + } 254 + 255 + return IRQ_HANDLED; 256 + } 257 + 258 + static int efm32_i2c_master_xfer(struct i2c_adapter *adap, 259 + struct i2c_msg *msgs, int num) 260 + { 261 + struct efm32_i2c_ddata *ddata = i2c_get_adapdata(adap); 262 + int ret; 263 + 264 + if (ddata->msgs) 265 + return -EBUSY; 266 + 267 + ddata->msgs = msgs; 268 + ddata->num_msgs = num; 269 + ddata->current_word = 0; 270 + ddata->current_msg = 0; 271 + ddata->retval = -EIO; 272 + 273 + reinit_completion(&ddata->done); 274 + 275 + dev_dbg(&ddata->adapter.dev, "state: %08x, status: %08x\n", 276 + efm32_i2c_read32(ddata, REG_STATE), 277 + efm32_i2c_read32(ddata, REG_STATUS)); 278 + 279 + efm32_i2c_send_next_msg(ddata); 280 + 281 + wait_for_completion(&ddata->done); 282 + 283 + if (ddata->current_msg >= ddata->num_msgs) 284 + ret = ddata->num_msgs; 285 + else 286 + ret = ddata->retval; 287 + 288 + return ret; 289 + } 290 + 291 + static u32 efm32_i2c_functionality(struct i2c_adapter *adap) 292 + { 293 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 294 + } 295 + 296 + static const struct i2c_algorithm efm32_i2c_algo = { 297 + .master_xfer = efm32_i2c_master_xfer, 298 + .functionality = efm32_i2c_functionality, 299 + }; 300 + 301 + static u32 efm32_i2c_get_configured_location(struct efm32_i2c_ddata *ddata) 302 + { 303 + u32 reg = efm32_i2c_read32(ddata, REG_ROUTE); 304 + 305 + return (reg & REG_ROUTE_LOCATION__MASK) >> 306 + __ffs(REG_ROUTE_LOCATION__MASK); 307 + } 308 + 309 + static int efm32_i2c_probe(struct platform_device *pdev) 310 + { 311 + struct efm32_i2c_ddata *ddata; 312 + struct resource *res; 313 + unsigned long rate; 314 + struct device_node *np = pdev->dev.of_node; 315 + u32 location, frequency; 316 + int ret; 317 + u32 clkdiv; 318 + 319 + if (!np) 320 + return -EINVAL; 321 + 322 + ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); 323 + if (!ddata) { 324 + dev_dbg(&pdev->dev, "failed to allocate private data\n"); 325 + return -ENOMEM; 326 + } 327 + platform_set_drvdata(pdev, ddata); 328 + 329 + init_completion(&ddata->done); 330 + strlcpy(ddata->adapter.name, pdev->name, sizeof(ddata->adapter.name)); 331 + ddata->adapter.owner = THIS_MODULE; 332 + ddata->adapter.algo = &efm32_i2c_algo; 333 + ddata->adapter.dev.parent = &pdev->dev; 334 + ddata->adapter.dev.of_node = pdev->dev.of_node; 335 + i2c_set_adapdata(&ddata->adapter, ddata); 336 + 337 + ddata->clk = devm_clk_get(&pdev->dev, NULL); 338 + if (IS_ERR(ddata->clk)) { 339 + ret = PTR_ERR(ddata->clk); 340 + dev_err(&pdev->dev, "failed to get clock: %d\n", ret); 341 + return ret; 342 + } 343 + 344 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 345 + if (!res) { 346 + dev_err(&pdev->dev, "failed to determine base address\n"); 347 + return -ENODEV; 348 + } 349 + 350 + if (resource_size(res) < 0x42) { 351 + dev_err(&pdev->dev, "memory resource too small\n"); 352 + return -EINVAL; 353 + } 354 + 355 + ddata->base = devm_ioremap_resource(&pdev->dev, res); 356 + if (IS_ERR(ddata->base)) 357 + return PTR_ERR(ddata->base); 358 + 359 + ret = platform_get_irq(pdev, 0); 360 + if (ret <= 0) { 361 + dev_err(&pdev->dev, "failed to get irq (%d)\n", ret); 362 + if (!ret) 363 + ret = -EINVAL; 364 + return ret; 365 + } 366 + 367 + ddata->irq = ret; 368 + 369 + ret = clk_prepare_enable(ddata->clk); 370 + if (ret < 0) { 371 + dev_err(&pdev->dev, "failed to enable clock (%d)\n", ret); 372 + return ret; 373 + } 374 + 375 + ret = of_property_read_u32(np, "efm32,location", &location); 376 + if (!ret) { 377 + dev_dbg(&pdev->dev, "using location %u\n", location); 378 + } else { 379 + /* default to location configured in hardware */ 380 + location = efm32_i2c_get_configured_location(ddata); 381 + 382 + dev_info(&pdev->dev, "fall back to location %u\n", location); 383 + } 384 + 385 + ddata->location = location; 386 + 387 + ret = of_property_read_u32(np, "clock-frequency", &frequency); 388 + if (!ret) { 389 + dev_dbg(&pdev->dev, "using frequency %u\n", frequency); 390 + } else { 391 + frequency = 100000; 392 + dev_info(&pdev->dev, "defaulting to 100 kHz\n"); 393 + } 394 + ddata->frequency = frequency; 395 + 396 + rate = clk_get_rate(ddata->clk); 397 + if (!rate) { 398 + dev_err(&pdev->dev, "there is no input clock available\n"); 399 + ret = -EINVAL; 400 + goto err_disable_clk; 401 + } 402 + clkdiv = DIV_ROUND_UP(rate, 8 * ddata->frequency) - 1; 403 + if (clkdiv >= 0x200) { 404 + dev_err(&pdev->dev, 405 + "input clock too fast (%lu) to divide down to bus freq (%lu)", 406 + rate, ddata->frequency); 407 + ret = -EINVAL; 408 + goto err_disable_clk; 409 + } 410 + 411 + dev_dbg(&pdev->dev, "input clock = %lu, bus freq = %lu, clkdiv = %lu\n", 412 + rate, ddata->frequency, (unsigned long)clkdiv); 413 + efm32_i2c_write32(ddata, REG_CLKDIV, REG_CLKDIV_DIV(clkdiv)); 414 + 415 + efm32_i2c_write32(ddata, REG_ROUTE, REG_ROUTE_SDAPEN | 416 + REG_ROUTE_SCLPEN | 417 + REG_ROUTE_LOCATION(ddata->location)); 418 + 419 + efm32_i2c_write32(ddata, REG_CTRL, REG_CTRL_EN | 420 + REG_CTRL_BITO_160PCC | 0 * REG_CTRL_GIBITO); 421 + 422 + efm32_i2c_write32(ddata, REG_IFC, REG_IFC__MASK); 423 + efm32_i2c_write32(ddata, REG_IEN, REG_IF_TXC | REG_IF_ACK | REG_IF_NACK 424 + | REG_IF_ARBLOST | REG_IF_BUSERR | REG_IF_RXDATAV); 425 + 426 + /* to make bus idle */ 427 + efm32_i2c_write32(ddata, REG_CMD, REG_CMD_ABORT); 428 + 429 + ret = request_irq(ddata->irq, efm32_i2c_irq, 0, DRIVER_NAME, ddata); 430 + if (ret < 0) { 431 + dev_err(&pdev->dev, "failed to request irq (%d)\n", ret); 432 + return ret; 433 + } 434 + 435 + ret = i2c_add_adapter(&ddata->adapter); 436 + if (ret) { 437 + dev_err(&pdev->dev, "failed to add i2c adapter (%d)\n", ret); 438 + free_irq(ddata->irq, ddata); 439 + 440 + err_disable_clk: 441 + clk_disable_unprepare(ddata->clk); 442 + } 443 + return ret; 444 + } 445 + 446 + static int efm32_i2c_remove(struct platform_device *pdev) 447 + { 448 + struct efm32_i2c_ddata *ddata = platform_get_drvdata(pdev); 449 + 450 + i2c_del_adapter(&ddata->adapter); 451 + free_irq(ddata->irq, ddata); 452 + clk_disable_unprepare(ddata->clk); 453 + 454 + return 0; 455 + } 456 + 457 + static const struct of_device_id efm32_i2c_dt_ids[] = { 458 + { 459 + .compatible = "energymicro,efm32-i2c", 460 + }, { 461 + /* sentinel */ 462 + } 463 + }; 464 + MODULE_DEVICE_TABLE(of, efm32_i2c_dt_ids); 465 + 466 + static struct platform_driver efm32_i2c_driver = { 467 + .probe = efm32_i2c_probe, 468 + .remove = efm32_i2c_remove, 469 + 470 + .driver = { 471 + .name = DRIVER_NAME, 472 + .owner = THIS_MODULE, 473 + .of_match_table = efm32_i2c_dt_ids, 474 + }, 475 + }; 476 + module_platform_driver(efm32_i2c_driver); 477 + 478 + MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>"); 479 + MODULE_DESCRIPTION("EFM32 i2c driver"); 480 + MODULE_LICENSE("GPL v2"); 481 + MODULE_ALIAS("platform:" DRIVER_NAME);
+1 -1
drivers/i2c/busses/i2c-eg20t.c
··· 186 186 #define PCI_DEVICE_ID_ML7223_I2C 0x8010 187 187 #define PCI_DEVICE_ID_ML7831_I2C 0x8817 188 188 189 - static DEFINE_PCI_DEVICE_TABLE(pch_pcidev_id) = { 189 + static const struct pci_device_id pch_pcidev_id[] = { 190 190 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, }, 191 191 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, }, 192 192 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, },
+3 -1
drivers/i2c/busses/i2c-exynos5.c
··· 566 566 static int exynos5_i2c_xfer(struct i2c_adapter *adap, 567 567 struct i2c_msg *msgs, int num) 568 568 { 569 - struct exynos5_i2c *i2c = (struct exynos5_i2c *)adap->algo_data; 569 + struct exynos5_i2c *i2c = adap->algo_data; 570 570 int i = 0, ret = 0, stop = 0; 571 571 572 572 if (i2c->suspended) { ··· 715 715 return 0; 716 716 } 717 717 718 + #ifdef CONFIG_PM_SLEEP 718 719 static int exynos5_i2c_suspend_noirq(struct device *dev) 719 720 { 720 721 struct platform_device *pdev = to_platform_device(dev); ··· 746 745 747 746 return 0; 748 747 } 748 + #endif 749 749 750 750 static SIMPLE_DEV_PM_OPS(exynos5_i2c_dev_pm_ops, exynos5_i2c_suspend_noirq, 751 751 exynos5_i2c_resume_noirq);
+3
drivers/i2c/busses/i2c-gpio.c
··· 94 94 *sda_pin = of_get_gpio(np, 0); 95 95 *scl_pin = of_get_gpio(np, 1); 96 96 97 + if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER) 98 + return -EPROBE_DEFER; 99 + 97 100 if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { 98 101 pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n", 99 102 np->full_name, *sda_pin, *scl_pin);
+1 -1
drivers/i2c/busses/i2c-hydra.c
··· 104 104 .algo_data = &hydra_bit_data, 105 105 }; 106 106 107 - static DEFINE_PCI_DEVICE_TABLE(hydra_ids) = { 107 + static const struct pci_device_id hydra_ids[] = { 108 108 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, 109 109 { 0, } 110 110 };
+4 -1
drivers/i2c/busses/i2c-i801.c
··· 60 60 Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes 61 61 Coleto Creek (PCH) 0x23b0 32 hard yes yes yes 62 62 Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes 63 + BayTrail (SOC) 0x0f12 32 hard yes yes yes 63 64 64 65 Features supported by this driver: 65 66 Software PEC no ··· 162 161 STATUS_ERROR_FLAGS) 163 162 164 163 /* Older devices have their ID defined in <linux/pci_ids.h> */ 164 + #define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12 165 165 #define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22 166 166 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22 167 167 /* Patsburg also has three 'Integrated Device Function' SMBus controllers */ ··· 791 789 .functionality = i801_func, 792 790 }; 793 791 794 - static DEFINE_PCI_DEVICE_TABLE(i801_ids) = { 792 + static const struct pci_device_id i801_ids[] = { 795 793 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, 796 794 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, 797 795 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) }, ··· 824 822 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) }, 825 823 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) }, 826 824 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) }, 825 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) }, 827 826 { 0, } 828 827 }; 829 828
+1 -1
drivers/i2c/busses/i2c-ismt.c
··· 182 182 /** 183 183 * ismt_ids - PCI device IDs supported by this driver 184 184 */ 185 - static DEFINE_PCI_DEVICE_TABLE(ismt_ids) = { 185 + static const struct pci_device_id ismt_ids[] = { 186 186 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) }, 187 187 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) }, 188 188 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) },
+50 -33
drivers/i2c/busses/i2c-mv64xxx.c
··· 17 17 #include <linux/interrupt.h> 18 18 #include <linux/mv643xx_i2c.h> 19 19 #include <linux/platform_device.h> 20 + #include <linux/reset.h> 20 21 #include <linux/io.h> 21 22 #include <linux/of.h> 22 23 #include <linux/of_device.h> ··· 98 97 enum { 99 98 MV64XXX_I2C_ACTION_INVALID, 100 99 MV64XXX_I2C_ACTION_CONTINUE, 101 - MV64XXX_I2C_ACTION_SEND_START, 102 100 MV64XXX_I2C_ACTION_SEND_RESTART, 103 101 MV64XXX_I2C_ACTION_OFFLOAD_RESTART, 104 102 MV64XXX_I2C_ACTION_SEND_ADDR_1, ··· 148 148 bool offload_enabled; 149 149 /* 5us delay in order to avoid repeated start timing violation */ 150 150 bool errata_delay; 151 + struct reset_control *rstc; 152 + bool irq_clear_inverted; 151 153 }; 152 154 153 155 static struct mv64xxx_i2c_regs mv64xxx_i2c_regs_mv64xxx = { ··· 178 176 { 179 177 u32 dir = 0; 180 178 181 - drv_data->msg = msg; 182 - drv_data->byte_posn = 0; 183 - drv_data->bytes_left = msg->len; 184 - drv_data->aborting = 0; 185 - drv_data->rc = 0; 186 179 drv_data->cntl_bits = MV64XXX_I2C_REG_CONTROL_ACK | 187 180 MV64XXX_I2C_REG_CONTROL_INTEN | MV64XXX_I2C_REG_CONTROL_TWSIEN; 188 181 ··· 203 206 if (!drv_data->offload_enabled) 204 207 return -EOPNOTSUPP; 205 208 206 - drv_data->msg = msg; 207 - drv_data->byte_posn = 0; 208 - drv_data->bytes_left = msg->len; 209 - drv_data->aborting = 0; 210 - drv_data->rc = 0; 211 209 /* Only regular transactions can be offloaded */ 212 210 if ((msg->flags & ~(I2C_M_TEN | I2C_M_RD)) != 0) 213 211 return -EINVAL; ··· 411 419 } 412 420 } 413 421 422 + static void mv64xxx_i2c_send_start(struct mv64xxx_i2c_data *drv_data) 423 + { 424 + drv_data->msg = drv_data->msgs; 425 + drv_data->byte_posn = 0; 426 + drv_data->bytes_left = drv_data->msg->len; 427 + drv_data->aborting = 0; 428 + drv_data->rc = 0; 429 + 430 + /* Can we offload this msg ? */ 431 + if (mv64xxx_i2c_offload_msg(drv_data) < 0) { 432 + /* No, switch to standard path */ 433 + mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs); 434 + writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START, 435 + drv_data->reg_base + drv_data->reg_offsets.control); 436 + } 437 + } 438 + 414 439 static void 415 440 mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) 416 441 { ··· 444 435 445 436 drv_data->msgs++; 446 437 drv_data->num_msgs--; 447 - if (mv64xxx_i2c_offload_msg(drv_data) < 0) { 448 - drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START; 449 - writel(drv_data->cntl_bits, 450 - drv_data->reg_base + drv_data->reg_offsets.control); 438 + mv64xxx_i2c_send_start(drv_data); 451 439 452 - /* Setup for the next message */ 453 - mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs); 454 - } 455 440 if (drv_data->errata_delay) 456 441 udelay(5); 457 442 ··· 460 457 case MV64XXX_I2C_ACTION_CONTINUE: 461 458 writel(drv_data->cntl_bits, 462 459 drv_data->reg_base + drv_data->reg_offsets.control); 463 - break; 464 - 465 - case MV64XXX_I2C_ACTION_SEND_START: 466 - /* Can we offload this msg ? */ 467 - if (mv64xxx_i2c_offload_msg(drv_data) < 0) { 468 - /* No, switch to standard path */ 469 - mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs); 470 - writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START, 471 - drv_data->reg_base + drv_data->reg_offsets.control); 472 - } 473 460 break; 474 461 475 462 case MV64XXX_I2C_ACTION_SEND_ADDR_1: ··· 559 566 status = readl(drv_data->reg_base + drv_data->reg_offsets.status); 560 567 mv64xxx_i2c_fsm(drv_data, status); 561 568 mv64xxx_i2c_do_action(drv_data); 569 + 570 + if (drv_data->irq_clear_inverted) 571 + writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_IFLG, 572 + drv_data->reg_base + drv_data->reg_offsets.control); 573 + 562 574 rc = IRQ_HANDLED; 563 575 } 564 576 spin_unlock_irqrestore(&drv_data->lock, flags); ··· 624 626 625 627 spin_lock_irqsave(&drv_data->lock, flags); 626 628 627 - drv_data->action = MV64XXX_I2C_ACTION_SEND_START; 628 629 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND; 629 630 630 631 drv_data->send_stop = is_last; 631 632 drv_data->block = 1; 632 - mv64xxx_i2c_do_action(drv_data); 633 + mv64xxx_i2c_send_start(drv_data); 633 634 spin_unlock_irqrestore(&drv_data->lock, flags); 634 635 635 636 mv64xxx_i2c_wait_for_completion(drv_data); ··· 682 685 */ 683 686 static const struct of_device_id mv64xxx_i2c_of_match_table[] = { 684 687 { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 688 + { .compatible = "allwinner,sun6i-a31-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 685 689 { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 686 690 { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 687 691 { .compatible = "marvell,mv78230-a0-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, ··· 757 759 } 758 760 drv_data->irq = irq_of_parse_and_map(np, 0); 759 761 762 + drv_data->rstc = devm_reset_control_get_optional(dev, NULL); 763 + if (IS_ERR(drv_data->rstc)) { 764 + if (PTR_ERR(drv_data->rstc) == -EPROBE_DEFER) { 765 + rc = -EPROBE_DEFER; 766 + goto out; 767 + } 768 + } else { 769 + reset_control_deassert(drv_data->rstc); 770 + } 771 + 760 772 /* Its not yet defined how timeouts will be specified in device tree. 761 773 * So hard code the value to 1 second. 762 774 */ ··· 791 783 drv_data->offload_enabled = false; 792 784 drv_data->errata_delay = true; 793 785 } 786 + 787 + if (of_device_is_compatible(np, "allwinner,sun6i-a31-i2c")) 788 + drv_data->irq_clear_inverted = true; 789 + 794 790 out: 795 791 return rc; 796 792 #endif ··· 857 845 } 858 846 if (drv_data->irq < 0) { 859 847 rc = -ENXIO; 860 - goto exit_clk; 848 + goto exit_reset; 861 849 } 862 850 863 851 drv_data->adapter.dev.parent = &pd->dev; 864 852 drv_data->adapter.algo = &mv64xxx_i2c_algo; 865 853 drv_data->adapter.owner = THIS_MODULE; 866 - drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 854 + drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 867 855 drv_data->adapter.nr = pd->id; 868 856 drv_data->adapter.dev.of_node = pd->dev.of_node; 869 857 platform_set_drvdata(pd, drv_data); ··· 877 865 dev_err(&drv_data->adapter.dev, 878 866 "mv64xxx: Can't register intr handler irq%d: %d\n", 879 867 drv_data->irq, rc); 880 - goto exit_clk; 868 + goto exit_reset; 881 869 } else if ((rc = i2c_add_numbered_adapter(&drv_data->adapter)) != 0) { 882 870 dev_err(&drv_data->adapter.dev, 883 871 "mv64xxx: Can't add i2c adapter, rc: %d\n", -rc); ··· 888 876 889 877 exit_free_irq: 890 878 free_irq(drv_data->irq, drv_data); 879 + exit_reset: 880 + if (!IS_ERR_OR_NULL(drv_data->rstc)) 881 + reset_control_assert(drv_data->rstc); 891 882 exit_clk: 892 883 #if defined(CONFIG_HAVE_CLK) 893 884 /* Not all platforms have a clk */ ··· 909 894 910 895 i2c_del_adapter(&drv_data->adapter); 911 896 free_irq(drv_data->irq, drv_data); 897 + if (!IS_ERR_OR_NULL(drv_data->rstc)) 898 + reset_control_assert(drv_data->rstc); 912 899 #if defined(CONFIG_HAVE_CLK) 913 900 /* Not all platforms have a clk */ 914 901 if (!IS_ERR(drv_data->clk)) {
+6 -12
drivers/i2c/busses/i2c-mxs.c
··· 806 806 struct mxs_i2c_dev *i2c; 807 807 struct i2c_adapter *adap; 808 808 struct resource *res; 809 - resource_size_t res_size; 810 809 int err, irq; 811 810 812 811 i2c = devm_kzalloc(dev, sizeof(struct mxs_i2c_dev), GFP_KERNEL); ··· 818 819 } 819 820 820 821 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 822 + i2c->regs = devm_ioremap_resource(&pdev->dev, res); 823 + if (IS_ERR(i2c->regs)) 824 + return PTR_ERR(i2c->regs); 825 + 821 826 irq = platform_get_irq(pdev, 0); 822 - 823 - if (!res || irq < 0) 824 - return -ENOENT; 825 - 826 - res_size = resource_size(res); 827 - if (!devm_request_mem_region(dev, res->start, res_size, res->name)) 828 - return -EBUSY; 829 - 830 - i2c->regs = devm_ioremap_nocache(dev, res->start, res_size); 831 - if (!i2c->regs) 832 - return -EBUSY; 827 + if (irq < 0) 828 + return irq; 833 829 834 830 err = devm_request_irq(dev, irq, mxs_i2c_isr, 0, dev_name(dev), i2c); 835 831 if (err)
+1 -1
drivers/i2c/busses/i2c-nforce2.c
··· 306 306 }; 307 307 308 308 309 - static DEFINE_PCI_DEVICE_TABLE(nforce2_ids) = { 309 + static const struct pci_device_id nforce2_ids[] = { 310 310 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, 311 311 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) }, 312 312 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) },
+107 -148
drivers/i2c/busses/i2c-nomadik.c
··· 111 111 }; 112 112 113 113 /** 114 - * struct nmk_i2c_controller - client specific controller configuration 115 - * @clk_freq: clock frequency for the operation mode 116 - * @tft: Tx FIFO Threshold in bytes 117 - * @rft: Rx FIFO Threshold in bytes 118 - * @timeout Slave response timeout(ms) 119 - * @sm: speed mode 120 - */ 121 - struct nmk_i2c_controller { 122 - u32 clk_freq; 123 - unsigned char tft; 124 - unsigned char rft; 125 - int timeout; 126 - enum i2c_freq_mode sm; 127 - }; 128 - 129 - /** 130 114 * struct i2c_vendor_data - per-vendor variations 131 115 * @has_mtdws: variant has the MTDWS bit 132 116 * @fifodepth: variant FIFO depth ··· 158 174 * @irq: interrupt line for the controller. 159 175 * @virtbase: virtual io memory area. 160 176 * @clk: hardware i2c block clock. 161 - * @cfg: machine provided controller configuration. 162 177 * @cli: holder of client specific data. 178 + * @clk_freq: clock frequency for the operation mode 179 + * @tft: Tx FIFO Threshold in bytes 180 + * @rft: Rx FIFO Threshold in bytes 181 + * @timeout Slave response timeout (ms) 182 + * @sm: speed mode 163 183 * @stop: stop condition. 164 184 * @xfer_complete: acknowledge completion for a I2C message. 165 185 * @result: controller propogated result. 166 - * @busy: Busy doing transfer. 167 186 */ 168 187 struct nmk_i2c_dev { 169 188 struct i2c_vendor_data *vendor; ··· 175 188 int irq; 176 189 void __iomem *virtbase; 177 190 struct clk *clk; 178 - struct nmk_i2c_controller cfg; 179 191 struct i2c_nmk_client cli; 192 + u32 clk_freq; 193 + unsigned char tft; 194 + unsigned char rft; 195 + int timeout; 196 + enum i2c_freq_mode sm; 180 197 int stop; 181 198 struct completion xfer_complete; 182 199 int result; 183 - bool busy; 184 200 }; 185 201 186 202 /* controller's abort causes */ ··· 376 386 * slsu = cycles / (1000000000 / f) + 1 377 387 */ 378 388 ns = DIV_ROUND_UP_ULL(1000000000ULL, i2c_clk); 379 - switch (dev->cfg.sm) { 389 + switch (dev->sm) { 380 390 case I2C_FREQ_MODE_FAST: 381 391 case I2C_FREQ_MODE_FAST_PLUS: 382 392 slsu = DIV_ROUND_UP(100, ns); /* Fast */ ··· 399 409 * 2 whereas it is 3 for fast and fastplus mode of 400 410 * operation. TODO - high speed support. 401 411 */ 402 - div = (dev->cfg.clk_freq > 100000) ? 3 : 2; 412 + div = (dev->clk_freq > 100000) ? 3 : 2; 403 413 404 414 /* 405 415 * generate the mask for baud rate counters. The controller ··· 409 419 * so set brcr1 to 0. 410 420 */ 411 421 brcr1 = 0 << 16; 412 - brcr2 = (i2c_clk/(dev->cfg.clk_freq * div)) & 0xffff; 422 + brcr2 = (i2c_clk/(dev->clk_freq * div)) & 0xffff; 413 423 414 424 /* set the baud rate counter register */ 415 425 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); ··· 420 430 * TODO - support for fast mode plus (up to 1Mb/s) 421 431 * and high speed (up to 3.4 Mb/s) 422 432 */ 423 - if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { 433 + if (dev->sm > I2C_FREQ_MODE_FAST) { 424 434 dev_err(&dev->adev->dev, 425 435 "do not support this mode defaulting to std. mode\n"); 426 436 brcr2 = i2c_clk/(100000 * 2) & 0xffff; ··· 428 438 writel(I2C_FREQ_MODE_STANDARD << 4, 429 439 dev->virtbase + I2C_CR); 430 440 } 431 - writel(dev->cfg.sm << 4, dev->virtbase + I2C_CR); 441 + writel(dev->sm << 4, dev->virtbase + I2C_CR); 432 442 433 443 /* set the Tx and Rx FIFO threshold */ 434 - writel(dev->cfg.tft, dev->virtbase + I2C_TFTR); 435 - writel(dev->cfg.rft, dev->virtbase + I2C_RFTR); 444 + writel(dev->tft, dev->virtbase + I2C_TFTR); 445 + writel(dev->rft, dev->virtbase + I2C_RFTR); 436 446 } 437 447 438 448 /** ··· 664 674 static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, 665 675 struct i2c_msg msgs[], int num_msgs) 666 676 { 667 - int status; 677 + int status = 0; 668 678 int i; 669 679 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); 670 680 int j; 671 681 672 - dev->busy = true; 673 - 674 682 pm_runtime_get_sync(&dev->adev->dev); 675 - 676 - status = clk_prepare_enable(dev->clk); 677 - if (status) { 678 - dev_err(&dev->adev->dev, "can't prepare_enable clock\n"); 679 - goto out_clk; 680 - } 681 - 682 - /* Optionaly enable pins to be muxed in and configured */ 683 - pinctrl_pm_select_default_state(&dev->adev->dev); 684 - 685 - status = init_hw(dev); 686 - if (status) 687 - goto out; 688 683 689 684 /* Attempt three times to send the message queue */ 690 685 for (j = 0; j < 3; j++) { ··· 691 716 break; 692 717 } 693 718 694 - out: 695 - clk_disable_unprepare(dev->clk); 696 - out_clk: 697 - /* Optionally let pins go into idle state */ 698 - pinctrl_pm_select_idle_state(&dev->adev->dev); 699 - 700 719 pm_runtime_put_sync(&dev->adev->dev); 701 - 702 - dev->busy = false; 703 720 704 721 /* return the no. messages processed */ 705 722 if (status) ··· 876 909 return IRQ_HANDLED; 877 910 } 878 911 879 - 880 - #ifdef CONFIG_PM 881 - static int nmk_i2c_suspend(struct device *dev) 912 + #ifdef CONFIG_PM_SLEEP 913 + static int nmk_i2c_suspend_late(struct device *dev) 882 914 { 883 - struct amba_device *adev = to_amba_device(dev); 884 - struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 885 - 886 - if (nmk_i2c->busy) 887 - return -EBUSY; 888 - 889 915 pinctrl_pm_select_sleep_state(dev); 890 916 891 917 return 0; 892 918 } 893 919 894 - static int nmk_i2c_resume(struct device *dev) 920 + static int nmk_i2c_resume_early(struct device *dev) 895 921 { 896 922 /* First go to the default state */ 897 923 pinctrl_pm_select_default_state(dev); ··· 893 933 894 934 return 0; 895 935 } 896 - #else 897 - #define nmk_i2c_suspend NULL 898 - #define nmk_i2c_resume NULL 899 936 #endif 900 937 901 - /* 902 - * We use noirq so that we suspend late and resume before the wakeup interrupt 903 - * to ensure that we do the !pm_runtime_suspended() check in resume before 904 - * there has been a regular pm runtime resume (via pm_runtime_get_sync()). 905 - */ 938 + #ifdef CONFIG_PM 939 + static int nmk_i2c_runtime_suspend(struct device *dev) 940 + { 941 + struct amba_device *adev = to_amba_device(dev); 942 + struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 943 + 944 + clk_disable_unprepare(nmk_i2c->clk); 945 + pinctrl_pm_select_idle_state(dev); 946 + return 0; 947 + } 948 + 949 + static int nmk_i2c_runtime_resume(struct device *dev) 950 + { 951 + struct amba_device *adev = to_amba_device(dev); 952 + struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 953 + int ret; 954 + 955 + ret = clk_prepare_enable(nmk_i2c->clk); 956 + if (ret) { 957 + dev_err(dev, "can't prepare_enable clock\n"); 958 + return ret; 959 + } 960 + 961 + pinctrl_pm_select_default_state(dev); 962 + 963 + ret = init_hw(nmk_i2c); 964 + if (ret) { 965 + clk_disable_unprepare(nmk_i2c->clk); 966 + pinctrl_pm_select_idle_state(dev); 967 + } 968 + 969 + return ret; 970 + } 971 + #endif 972 + 906 973 static const struct dev_pm_ops nmk_i2c_pm = { 907 - .suspend_noirq = nmk_i2c_suspend, 908 - .resume_noirq = nmk_i2c_resume, 974 + SET_LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early) 975 + SET_PM_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend, 976 + nmk_i2c_runtime_resume, 977 + NULL) 909 978 }; 910 979 911 980 static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) ··· 947 958 .functionality = nmk_i2c_functionality 948 959 }; 949 960 950 - static struct nmk_i2c_controller u8500_i2c = { 951 - .tft = 1, /* Tx FIFO threshold */ 952 - .rft = 8, /* Rx FIFO threshold */ 953 - .clk_freq = 400000, /* fast mode operation */ 954 - .timeout = 200, /* Slave response timeout(ms) */ 955 - .sm = I2C_FREQ_MODE_FAST, 956 - }; 957 - 958 961 static void nmk_i2c_of_probe(struct device_node *np, 959 - struct nmk_i2c_controller *pdata) 962 + struct nmk_i2c_dev *nmk) 960 963 { 961 - of_property_read_u32(np, "clock-frequency", &pdata->clk_freq); 964 + /* Default to 100 kHz if no frequency is given in the node */ 965 + if (of_property_read_u32(np, "clock-frequency", &nmk->clk_freq)) 966 + nmk->clk_freq = 100000; 962 967 963 968 /* This driver only supports 'standard' and 'fast' modes of operation. */ 964 - if (pdata->clk_freq <= 100000) 965 - pdata->sm = I2C_FREQ_MODE_STANDARD; 969 + if (nmk->clk_freq <= 100000) 970 + nmk->sm = I2C_FREQ_MODE_STANDARD; 966 971 else 967 - pdata->sm = I2C_FREQ_MODE_FAST; 972 + nmk->sm = I2C_FREQ_MODE_FAST; 973 + nmk->tft = 1; /* Tx FIFO threshold */ 974 + nmk->rft = 8; /* Rx FIFO threshold */ 975 + nmk->timeout = 200; /* Slave response timeout(ms) */ 968 976 } 969 977 970 978 static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) 971 979 { 972 980 int ret = 0; 973 - struct nmk_i2c_controller *pdata = dev_get_platdata(&adev->dev); 974 981 struct device_node *np = adev->dev.of_node; 975 982 struct nmk_i2c_dev *dev; 976 983 struct i2c_adapter *adap; 977 984 struct i2c_vendor_data *vendor = id->data; 978 985 u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1; 979 986 980 - if (!pdata) { 981 - if (np) { 982 - pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL); 983 - if (!pdata) { 984 - ret = -ENOMEM; 985 - goto err_no_mem; 986 - } 987 - /* Provide the default configuration as a base. */ 988 - memcpy(pdata, &u8500_i2c, sizeof(struct nmk_i2c_controller)); 989 - nmk_i2c_of_probe(np, pdata); 990 - } else 991 - /* No i2c configuration found, using the default. */ 992 - pdata = &u8500_i2c; 993 - } 994 - 995 - if (pdata->tft > max_fifo_threshold) { 996 - dev_warn(&adev->dev, "requested TX FIFO threshold %u, adjusted down to %u\n", 997 - pdata->tft, max_fifo_threshold); 998 - pdata->tft = max_fifo_threshold; 999 - } 1000 - 1001 - if (pdata->rft > max_fifo_threshold) { 1002 - dev_warn(&adev->dev, "requested RX FIFO threshold %u, adjusted down to %u\n", 1003 - pdata->rft, max_fifo_threshold); 1004 - pdata->rft = max_fifo_threshold; 1005 - } 1006 - 1007 - dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); 987 + dev = devm_kzalloc(&adev->dev, sizeof(struct nmk_i2c_dev), GFP_KERNEL); 1008 988 if (!dev) { 1009 989 dev_err(&adev->dev, "cannot allocate memory\n"); 1010 990 ret = -ENOMEM; 1011 991 goto err_no_mem; 1012 992 } 1013 993 dev->vendor = vendor; 1014 - dev->busy = false; 1015 994 dev->adev = adev; 995 + nmk_i2c_of_probe(np, dev); 996 + 997 + if (dev->tft > max_fifo_threshold) { 998 + dev_warn(&adev->dev, "requested TX FIFO threshold %u, adjusted down to %u\n", 999 + dev->tft, max_fifo_threshold); 1000 + dev->tft = max_fifo_threshold; 1001 + } 1002 + 1003 + if (dev->rft > max_fifo_threshold) { 1004 + dev_warn(&adev->dev, "requested RX FIFO threshold %u, adjusted down to %u\n", 1005 + dev->rft, max_fifo_threshold); 1006 + dev->rft = max_fifo_threshold; 1007 + } 1008 + 1016 1009 amba_set_drvdata(adev, dev); 1017 1010 1018 - /* Select default pin state */ 1019 - pinctrl_pm_select_default_state(&adev->dev); 1020 - /* If possible, let's go to idle until the first transfer */ 1021 - pinctrl_pm_select_idle_state(&adev->dev); 1022 - 1023 - dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 1024 - if (!dev->virtbase) { 1011 + dev->virtbase = devm_ioremap(&adev->dev, adev->res.start, 1012 + resource_size(&adev->res)); 1013 + if (IS_ERR(dev->virtbase)) { 1025 1014 ret = -ENOMEM; 1026 - goto err_no_ioremap; 1015 + goto err_no_mem; 1027 1016 } 1028 1017 1029 1018 dev->irq = adev->irq[0]; 1030 - ret = request_irq(dev->irq, i2c_irq_handler, 0, 1019 + ret = devm_request_irq(&adev->dev, dev->irq, i2c_irq_handler, 0, 1031 1020 DRIVER_NAME, dev); 1032 1021 if (ret) { 1033 1022 dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq); 1034 - goto err_irq; 1023 + goto err_no_mem; 1035 1024 } 1036 1025 1037 1026 pm_suspend_ignore_children(&adev->dev, true); 1038 1027 1039 - dev->clk = clk_get(&adev->dev, NULL); 1028 + dev->clk = devm_clk_get(&adev->dev, NULL); 1040 1029 if (IS_ERR(dev->clk)) { 1041 1030 dev_err(&adev->dev, "could not get i2c clock\n"); 1042 1031 ret = PTR_ERR(dev->clk); 1043 - goto err_no_clk; 1032 + goto err_no_mem; 1044 1033 } 1034 + 1035 + ret = clk_prepare_enable(dev->clk); 1036 + if (ret) { 1037 + dev_err(&adev->dev, "can't prepare_enable clock\n"); 1038 + goto err_no_mem; 1039 + } 1040 + 1041 + init_hw(dev); 1045 1042 1046 1043 adap = &dev->adap; 1047 1044 adap->dev.of_node = np; 1048 1045 adap->dev.parent = &adev->dev; 1049 1046 adap->owner = THIS_MODULE; 1050 - adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1047 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 1051 1048 adap->algo = &nmk_i2c_algo; 1052 - adap->timeout = msecs_to_jiffies(pdata->timeout); 1049 + adap->timeout = msecs_to_jiffies(dev->timeout); 1053 1050 snprintf(adap->name, sizeof(adap->name), 1054 1051 "Nomadik I2C at %pR", &adev->res); 1055 - 1056 - /* fetch the controller configuration from machine */ 1057 - dev->cfg.clk_freq = pdata->clk_freq; 1058 - dev->cfg.tft = pdata->tft; 1059 - dev->cfg.rft = pdata->rft; 1060 - dev->cfg.sm = pdata->sm; 1061 1052 1062 1053 i2c_set_adapdata(adap, dev); 1063 1054 ··· 1048 1079 ret = i2c_add_adapter(adap); 1049 1080 if (ret) { 1050 1081 dev_err(&adev->dev, "failed to add adapter\n"); 1051 - goto err_add_adap; 1082 + goto err_no_adap; 1052 1083 } 1053 1084 1054 1085 pm_runtime_put(&adev->dev); 1055 1086 1056 1087 return 0; 1057 1088 1058 - err_add_adap: 1059 - clk_put(dev->clk); 1060 - err_no_clk: 1061 - free_irq(dev->irq, dev); 1062 - err_irq: 1063 - iounmap(dev->virtbase); 1064 - err_no_ioremap: 1065 - kfree(dev); 1089 + err_no_adap: 1090 + clk_disable_unprepare(dev->clk); 1066 1091 err_no_mem: 1067 1092 1068 1093 return ret; ··· 1073 1110 clear_all_interrupts(dev); 1074 1111 /* disable the controller */ 1075 1112 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); 1076 - free_irq(dev->irq, dev); 1077 - iounmap(dev->virtbase); 1113 + clk_disable_unprepare(dev->clk); 1078 1114 if (res) 1079 1115 release_mem_region(res->start, resource_size(res)); 1080 - clk_put(dev->clk); 1081 - pm_runtime_disable(&adev->dev); 1082 - kfree(dev); 1083 1116 1084 1117 return 0; 1085 1118 }
+1 -1
drivers/i2c/busses/i2c-ocores.c
··· 246 246 static struct i2c_adapter ocores_adapter = { 247 247 .owner = THIS_MODULE, 248 248 .name = "i2c-ocores", 249 - .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 249 + .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED, 250 250 .algo = &ocores_algorithm, 251 251 }; 252 252
+4 -4
drivers/i2c/busses/i2c-omap.c
··· 636 636 int r; 637 637 638 638 r = pm_runtime_get_sync(dev->dev); 639 - if (IS_ERR_VALUE(r)) 639 + if (r < 0) 640 640 goto out; 641 641 642 642 r = omap_i2c_wait_for_bb(dev); ··· 1155 1155 pm_runtime_use_autosuspend(dev->dev); 1156 1156 1157 1157 r = pm_runtime_get_sync(dev->dev); 1158 - if (IS_ERR_VALUE(r)) 1158 + if (r < 0) 1159 1159 goto err_free_mem; 1160 1160 1161 1161 /* ··· 1238 1238 adap = &dev->adapter; 1239 1239 i2c_set_adapdata(adap, dev); 1240 1240 adap->owner = THIS_MODULE; 1241 - adap->class = I2C_CLASS_HWMON; 1241 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 1242 1242 strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); 1243 1243 adap->algo = &omap_i2c_algo; 1244 1244 adap->dev.parent = &pdev->dev; ··· 1276 1276 1277 1277 i2c_del_adapter(&dev->adapter); 1278 1278 ret = pm_runtime_get_sync(&pdev->dev); 1279 - if (IS_ERR_VALUE(ret)) 1279 + if (ret < 0) 1280 1280 return ret; 1281 1281 1282 1282 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
+1 -1
drivers/i2c/busses/i2c-pasemi.c
··· 401 401 kfree(smbus); 402 402 } 403 403 404 - static DEFINE_PCI_DEVICE_TABLE(pasemi_smb_ids) = { 404 + static const struct pci_device_id pasemi_smb_ids[] = { 405 405 { PCI_DEVICE(0x1959, 0xa003) }, 406 406 { 0, } 407 407 };
+1 -1
drivers/i2c/busses/i2c-piix4.c
··· 540 540 .functionality = piix4_func, 541 541 }; 542 542 543 - static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = { 543 + static const struct pci_device_id piix4_ids[] = { 544 544 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, 545 545 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, 546 546 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
+1 -1
drivers/i2c/busses/i2c-pxa-pci.c
··· 148 148 kfree(sds); 149 149 } 150 150 151 - static DEFINE_PCI_DEVICE_TABLE(ce4100_i2c_devices) = { 151 + static const struct pci_device_id ce4100_i2c_devices[] = { 152 152 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)}, 153 153 { }, 154 154 };
+768
drivers/i2c/busses/i2c-qup.c
··· 1 + /* 2 + * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. 3 + * Copyright (c) 2014, Sony Mobile Communications AB. 4 + * 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 and 8 + * only version 2 as published by the Free Software Foundation. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/delay.h> 19 + #include <linux/err.h> 20 + #include <linux/i2c.h> 21 + #include <linux/interrupt.h> 22 + #include <linux/io.h> 23 + #include <linux/module.h> 24 + #include <linux/of.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/pm_runtime.h> 27 + 28 + /* QUP Registers */ 29 + #define QUP_CONFIG 0x000 30 + #define QUP_STATE 0x004 31 + #define QUP_IO_MODE 0x008 32 + #define QUP_SW_RESET 0x00c 33 + #define QUP_OPERATIONAL 0x018 34 + #define QUP_ERROR_FLAGS 0x01c 35 + #define QUP_ERROR_FLAGS_EN 0x020 36 + #define QUP_HW_VERSION 0x030 37 + #define QUP_MX_OUTPUT_CNT 0x100 38 + #define QUP_OUT_FIFO_BASE 0x110 39 + #define QUP_MX_WRITE_CNT 0x150 40 + #define QUP_MX_INPUT_CNT 0x200 41 + #define QUP_MX_READ_CNT 0x208 42 + #define QUP_IN_FIFO_BASE 0x218 43 + #define QUP_I2C_CLK_CTL 0x400 44 + #define QUP_I2C_STATUS 0x404 45 + 46 + /* QUP States and reset values */ 47 + #define QUP_RESET_STATE 0 48 + #define QUP_RUN_STATE 1 49 + #define QUP_PAUSE_STATE 3 50 + #define QUP_STATE_MASK 3 51 + 52 + #define QUP_STATE_VALID BIT(2) 53 + #define QUP_I2C_MAST_GEN BIT(4) 54 + 55 + #define QUP_OPERATIONAL_RESET 0x000ff0 56 + #define QUP_I2C_STATUS_RESET 0xfffffc 57 + 58 + /* QUP OPERATIONAL FLAGS */ 59 + #define QUP_I2C_NACK_FLAG BIT(3) 60 + #define QUP_OUT_NOT_EMPTY BIT(4) 61 + #define QUP_IN_NOT_EMPTY BIT(5) 62 + #define QUP_OUT_FULL BIT(6) 63 + #define QUP_OUT_SVC_FLAG BIT(8) 64 + #define QUP_IN_SVC_FLAG BIT(9) 65 + #define QUP_MX_OUTPUT_DONE BIT(10) 66 + #define QUP_MX_INPUT_DONE BIT(11) 67 + 68 + /* I2C mini core related values */ 69 + #define QUP_CLOCK_AUTO_GATE BIT(13) 70 + #define I2C_MINI_CORE (2 << 8) 71 + #define I2C_N_VAL 15 72 + /* Most significant word offset in FIFO port */ 73 + #define QUP_MSW_SHIFT (I2C_N_VAL + 1) 74 + 75 + /* Packing/Unpacking words in FIFOs, and IO modes */ 76 + #define QUP_OUTPUT_BLK_MODE (1 << 10) 77 + #define QUP_INPUT_BLK_MODE (1 << 12) 78 + #define QUP_UNPACK_EN BIT(14) 79 + #define QUP_PACK_EN BIT(15) 80 + 81 + #define QUP_REPACK_EN (QUP_UNPACK_EN | QUP_PACK_EN) 82 + 83 + #define QUP_OUTPUT_BLOCK_SIZE(x)(((x) >> 0) & 0x03) 84 + #define QUP_OUTPUT_FIFO_SIZE(x) (((x) >> 2) & 0x07) 85 + #define QUP_INPUT_BLOCK_SIZE(x) (((x) >> 5) & 0x03) 86 + #define QUP_INPUT_FIFO_SIZE(x) (((x) >> 7) & 0x07) 87 + 88 + /* QUP tags */ 89 + #define QUP_TAG_START (1 << 8) 90 + #define QUP_TAG_DATA (2 << 8) 91 + #define QUP_TAG_STOP (3 << 8) 92 + #define QUP_TAG_REC (4 << 8) 93 + 94 + /* Status, Error flags */ 95 + #define I2C_STATUS_WR_BUFFER_FULL BIT(0) 96 + #define I2C_STATUS_BUS_ACTIVE BIT(8) 97 + #define I2C_STATUS_ERROR_MASK 0x38000fc 98 + #define QUP_STATUS_ERROR_FLAGS 0x7c 99 + 100 + #define QUP_READ_LIMIT 256 101 + 102 + struct qup_i2c_dev { 103 + struct device *dev; 104 + void __iomem *base; 105 + int irq; 106 + struct clk *clk; 107 + struct clk *pclk; 108 + struct i2c_adapter adap; 109 + 110 + int clk_ctl; 111 + int out_fifo_sz; 112 + int in_fifo_sz; 113 + int out_blk_sz; 114 + int in_blk_sz; 115 + 116 + unsigned long one_byte_t; 117 + 118 + struct i2c_msg *msg; 119 + /* Current posion in user message buffer */ 120 + int pos; 121 + /* I2C protocol errors */ 122 + u32 bus_err; 123 + /* QUP core errors */ 124 + u32 qup_err; 125 + 126 + struct completion xfer; 127 + }; 128 + 129 + static irqreturn_t qup_i2c_interrupt(int irq, void *dev) 130 + { 131 + struct qup_i2c_dev *qup = dev; 132 + u32 bus_err; 133 + u32 qup_err; 134 + u32 opflags; 135 + 136 + bus_err = readl(qup->base + QUP_I2C_STATUS); 137 + qup_err = readl(qup->base + QUP_ERROR_FLAGS); 138 + opflags = readl(qup->base + QUP_OPERATIONAL); 139 + 140 + if (!qup->msg) { 141 + /* Clear Error interrupt */ 142 + writel(QUP_RESET_STATE, qup->base + QUP_STATE); 143 + return IRQ_HANDLED; 144 + } 145 + 146 + bus_err &= I2C_STATUS_ERROR_MASK; 147 + qup_err &= QUP_STATUS_ERROR_FLAGS; 148 + 149 + if (qup_err) { 150 + /* Clear Error interrupt */ 151 + writel(qup_err, qup->base + QUP_ERROR_FLAGS); 152 + goto done; 153 + } 154 + 155 + if (bus_err) { 156 + /* Clear Error interrupt */ 157 + writel(QUP_RESET_STATE, qup->base + QUP_STATE); 158 + goto done; 159 + } 160 + 161 + if (opflags & QUP_IN_SVC_FLAG) 162 + writel(QUP_IN_SVC_FLAG, qup->base + QUP_OPERATIONAL); 163 + 164 + if (opflags & QUP_OUT_SVC_FLAG) 165 + writel(QUP_OUT_SVC_FLAG, qup->base + QUP_OPERATIONAL); 166 + 167 + done: 168 + qup->qup_err = qup_err; 169 + qup->bus_err = bus_err; 170 + complete(&qup->xfer); 171 + return IRQ_HANDLED; 172 + } 173 + 174 + static int qup_i2c_poll_state_mask(struct qup_i2c_dev *qup, 175 + u32 req_state, u32 req_mask) 176 + { 177 + int retries = 1; 178 + u32 state; 179 + 180 + /* 181 + * State transition takes 3 AHB clocks cycles + 3 I2C master clock 182 + * cycles. So retry once after a 1uS delay. 183 + */ 184 + do { 185 + state = readl(qup->base + QUP_STATE); 186 + 187 + if (state & QUP_STATE_VALID && 188 + (state & req_mask) == req_state) 189 + return 0; 190 + 191 + udelay(1); 192 + } while (retries--); 193 + 194 + return -ETIMEDOUT; 195 + } 196 + 197 + static int qup_i2c_poll_state(struct qup_i2c_dev *qup, u32 req_state) 198 + { 199 + return qup_i2c_poll_state_mask(qup, req_state, QUP_STATE_MASK); 200 + } 201 + 202 + static int qup_i2c_poll_state_valid(struct qup_i2c_dev *qup) 203 + { 204 + return qup_i2c_poll_state_mask(qup, 0, 0); 205 + } 206 + 207 + static int qup_i2c_poll_state_i2c_master(struct qup_i2c_dev *qup) 208 + { 209 + return qup_i2c_poll_state_mask(qup, QUP_I2C_MAST_GEN, QUP_I2C_MAST_GEN); 210 + } 211 + 212 + static int qup_i2c_change_state(struct qup_i2c_dev *qup, u32 state) 213 + { 214 + if (qup_i2c_poll_state_valid(qup) != 0) 215 + return -EIO; 216 + 217 + writel(state, qup->base + QUP_STATE); 218 + 219 + if (qup_i2c_poll_state(qup, state) != 0) 220 + return -EIO; 221 + return 0; 222 + } 223 + 224 + static int qup_i2c_wait_writeready(struct qup_i2c_dev *qup) 225 + { 226 + unsigned long timeout; 227 + u32 opflags; 228 + u32 status; 229 + 230 + timeout = jiffies + HZ; 231 + 232 + for (;;) { 233 + opflags = readl(qup->base + QUP_OPERATIONAL); 234 + status = readl(qup->base + QUP_I2C_STATUS); 235 + 236 + if (!(opflags & QUP_OUT_NOT_EMPTY) && 237 + !(status & I2C_STATUS_BUS_ACTIVE)) 238 + return 0; 239 + 240 + if (time_after(jiffies, timeout)) 241 + return -ETIMEDOUT; 242 + 243 + usleep_range(qup->one_byte_t, qup->one_byte_t * 2); 244 + } 245 + } 246 + 247 + static void qup_i2c_set_write_mode(struct qup_i2c_dev *qup, struct i2c_msg *msg) 248 + { 249 + /* Number of entries to shift out, including the start */ 250 + int total = msg->len + 1; 251 + 252 + if (total < qup->out_fifo_sz) { 253 + /* FIFO mode */ 254 + writel(QUP_REPACK_EN, qup->base + QUP_IO_MODE); 255 + writel(total, qup->base + QUP_MX_WRITE_CNT); 256 + } else { 257 + /* BLOCK mode (transfer data on chunks) */ 258 + writel(QUP_OUTPUT_BLK_MODE | QUP_REPACK_EN, 259 + qup->base + QUP_IO_MODE); 260 + writel(total, qup->base + QUP_MX_OUTPUT_CNT); 261 + } 262 + } 263 + 264 + static void qup_i2c_issue_write(struct qup_i2c_dev *qup, struct i2c_msg *msg) 265 + { 266 + u32 addr = msg->addr << 1; 267 + u32 qup_tag; 268 + u32 opflags; 269 + int idx; 270 + u32 val; 271 + 272 + if (qup->pos == 0) { 273 + val = QUP_TAG_START | addr; 274 + idx = 1; 275 + } else { 276 + val = 0; 277 + idx = 0; 278 + } 279 + 280 + while (qup->pos < msg->len) { 281 + /* Check that there's space in the FIFO for our pair */ 282 + opflags = readl(qup->base + QUP_OPERATIONAL); 283 + if (opflags & QUP_OUT_FULL) 284 + break; 285 + 286 + if (qup->pos == msg->len - 1) 287 + qup_tag = QUP_TAG_STOP; 288 + else 289 + qup_tag = QUP_TAG_DATA; 290 + 291 + if (idx & 1) 292 + val |= (qup_tag | msg->buf[qup->pos]) << QUP_MSW_SHIFT; 293 + else 294 + val = qup_tag | msg->buf[qup->pos]; 295 + 296 + /* Write out the pair and the last odd value */ 297 + if (idx & 1 || qup->pos == msg->len - 1) 298 + writel(val, qup->base + QUP_OUT_FIFO_BASE); 299 + 300 + qup->pos++; 301 + idx++; 302 + } 303 + } 304 + 305 + static int qup_i2c_write_one(struct qup_i2c_dev *qup, struct i2c_msg *msg) 306 + { 307 + unsigned long left; 308 + int ret; 309 + 310 + qup->msg = msg; 311 + qup->pos = 0; 312 + 313 + enable_irq(qup->irq); 314 + 315 + qup_i2c_set_write_mode(qup, msg); 316 + 317 + ret = qup_i2c_change_state(qup, QUP_RUN_STATE); 318 + if (ret) 319 + goto err; 320 + 321 + writel(qup->clk_ctl, qup->base + QUP_I2C_CLK_CTL); 322 + 323 + do { 324 + ret = qup_i2c_change_state(qup, QUP_PAUSE_STATE); 325 + if (ret) 326 + goto err; 327 + 328 + qup_i2c_issue_write(qup, msg); 329 + 330 + ret = qup_i2c_change_state(qup, QUP_RUN_STATE); 331 + if (ret) 332 + goto err; 333 + 334 + left = wait_for_completion_timeout(&qup->xfer, HZ); 335 + if (!left) { 336 + writel(1, qup->base + QUP_SW_RESET); 337 + ret = -ETIMEDOUT; 338 + goto err; 339 + } 340 + 341 + if (qup->bus_err || qup->qup_err) { 342 + if (qup->bus_err & QUP_I2C_NACK_FLAG) 343 + dev_err(qup->dev, "NACK from %x\n", msg->addr); 344 + ret = -EIO; 345 + goto err; 346 + } 347 + } while (qup->pos < msg->len); 348 + 349 + /* Wait for the outstanding data in the fifo to drain */ 350 + ret = qup_i2c_wait_writeready(qup); 351 + 352 + err: 353 + disable_irq(qup->irq); 354 + qup->msg = NULL; 355 + 356 + return ret; 357 + } 358 + 359 + static void qup_i2c_set_read_mode(struct qup_i2c_dev *qup, int len) 360 + { 361 + if (len < qup->in_fifo_sz) { 362 + /* FIFO mode */ 363 + writel(QUP_REPACK_EN, qup->base + QUP_IO_MODE); 364 + writel(len, qup->base + QUP_MX_READ_CNT); 365 + } else { 366 + /* BLOCK mode (transfer data on chunks) */ 367 + writel(QUP_INPUT_BLK_MODE | QUP_REPACK_EN, 368 + qup->base + QUP_IO_MODE); 369 + writel(len, qup->base + QUP_MX_INPUT_CNT); 370 + } 371 + } 372 + 373 + static void qup_i2c_issue_read(struct qup_i2c_dev *qup, struct i2c_msg *msg) 374 + { 375 + u32 addr, len, val; 376 + 377 + addr = (msg->addr << 1) | 1; 378 + 379 + /* 0 is used to specify a length 256 (QUP_READ_LIMIT) */ 380 + len = (msg->len == QUP_READ_LIMIT) ? 0 : msg->len; 381 + 382 + val = ((QUP_TAG_REC | len) << QUP_MSW_SHIFT) | QUP_TAG_START | addr; 383 + writel(val, qup->base + QUP_OUT_FIFO_BASE); 384 + } 385 + 386 + 387 + static void qup_i2c_read_fifo(struct qup_i2c_dev *qup, struct i2c_msg *msg) 388 + { 389 + u32 opflags; 390 + u32 val = 0; 391 + int idx; 392 + 393 + for (idx = 0; qup->pos < msg->len; idx++) { 394 + if ((idx & 1) == 0) { 395 + /* Check that FIFO have data */ 396 + opflags = readl(qup->base + QUP_OPERATIONAL); 397 + if (!(opflags & QUP_IN_NOT_EMPTY)) 398 + break; 399 + 400 + /* Reading 2 words at time */ 401 + val = readl(qup->base + QUP_IN_FIFO_BASE); 402 + 403 + msg->buf[qup->pos++] = val & 0xFF; 404 + } else { 405 + msg->buf[qup->pos++] = val >> QUP_MSW_SHIFT; 406 + } 407 + } 408 + } 409 + 410 + static int qup_i2c_read_one(struct qup_i2c_dev *qup, struct i2c_msg *msg) 411 + { 412 + unsigned long left; 413 + int ret; 414 + 415 + /* 416 + * The QUP block will issue a NACK and STOP on the bus when reaching 417 + * the end of the read, the length of the read is specified as one byte 418 + * which limits the possible read to 256 (QUP_READ_LIMIT) bytes. 419 + */ 420 + if (msg->len > QUP_READ_LIMIT) { 421 + dev_err(qup->dev, "HW not capable of reads over %d bytes\n", 422 + QUP_READ_LIMIT); 423 + return -EINVAL; 424 + } 425 + 426 + qup->msg = msg; 427 + qup->pos = 0; 428 + 429 + enable_irq(qup->irq); 430 + 431 + qup_i2c_set_read_mode(qup, msg->len); 432 + 433 + ret = qup_i2c_change_state(qup, QUP_RUN_STATE); 434 + if (ret) 435 + goto err; 436 + 437 + writel(qup->clk_ctl, qup->base + QUP_I2C_CLK_CTL); 438 + 439 + ret = qup_i2c_change_state(qup, QUP_PAUSE_STATE); 440 + if (ret) 441 + goto err; 442 + 443 + qup_i2c_issue_read(qup, msg); 444 + 445 + ret = qup_i2c_change_state(qup, QUP_RUN_STATE); 446 + if (ret) 447 + goto err; 448 + 449 + do { 450 + left = wait_for_completion_timeout(&qup->xfer, HZ); 451 + if (!left) { 452 + writel(1, qup->base + QUP_SW_RESET); 453 + ret = -ETIMEDOUT; 454 + goto err; 455 + } 456 + 457 + if (qup->bus_err || qup->qup_err) { 458 + if (qup->bus_err & QUP_I2C_NACK_FLAG) 459 + dev_err(qup->dev, "NACK from %x\n", msg->addr); 460 + ret = -EIO; 461 + goto err; 462 + } 463 + 464 + qup_i2c_read_fifo(qup, msg); 465 + } while (qup->pos < msg->len); 466 + 467 + err: 468 + disable_irq(qup->irq); 469 + qup->msg = NULL; 470 + 471 + return ret; 472 + } 473 + 474 + static int qup_i2c_xfer(struct i2c_adapter *adap, 475 + struct i2c_msg msgs[], 476 + int num) 477 + { 478 + struct qup_i2c_dev *qup = i2c_get_adapdata(adap); 479 + int ret, idx; 480 + 481 + ret = pm_runtime_get_sync(qup->dev); 482 + if (ret) 483 + goto out; 484 + 485 + writel(1, qup->base + QUP_SW_RESET); 486 + ret = qup_i2c_poll_state(qup, QUP_RESET_STATE); 487 + if (ret) 488 + goto out; 489 + 490 + /* Configure QUP as I2C mini core */ 491 + writel(I2C_MINI_CORE | I2C_N_VAL, qup->base + QUP_CONFIG); 492 + 493 + for (idx = 0; idx < num; idx++) { 494 + if (msgs[idx].len == 0) { 495 + ret = -EINVAL; 496 + goto out; 497 + } 498 + 499 + if (qup_i2c_poll_state_i2c_master(qup)) { 500 + ret = -EIO; 501 + goto out; 502 + } 503 + 504 + if (msgs[idx].flags & I2C_M_RD) 505 + ret = qup_i2c_read_one(qup, &msgs[idx]); 506 + else 507 + ret = qup_i2c_write_one(qup, &msgs[idx]); 508 + 509 + if (ret) 510 + break; 511 + 512 + ret = qup_i2c_change_state(qup, QUP_RESET_STATE); 513 + if (ret) 514 + break; 515 + } 516 + 517 + if (ret == 0) 518 + ret = num; 519 + out: 520 + 521 + pm_runtime_mark_last_busy(qup->dev); 522 + pm_runtime_put_autosuspend(qup->dev); 523 + 524 + return ret; 525 + } 526 + 527 + static u32 qup_i2c_func(struct i2c_adapter *adap) 528 + { 529 + return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); 530 + } 531 + 532 + static const struct i2c_algorithm qup_i2c_algo = { 533 + .master_xfer = qup_i2c_xfer, 534 + .functionality = qup_i2c_func, 535 + }; 536 + 537 + static void qup_i2c_enable_clocks(struct qup_i2c_dev *qup) 538 + { 539 + clk_prepare_enable(qup->clk); 540 + clk_prepare_enable(qup->pclk); 541 + } 542 + 543 + static void qup_i2c_disable_clocks(struct qup_i2c_dev *qup) 544 + { 545 + u32 config; 546 + 547 + qup_i2c_change_state(qup, QUP_RESET_STATE); 548 + clk_disable_unprepare(qup->clk); 549 + config = readl(qup->base + QUP_CONFIG); 550 + config |= QUP_CLOCK_AUTO_GATE; 551 + writel(config, qup->base + QUP_CONFIG); 552 + clk_disable_unprepare(qup->pclk); 553 + } 554 + 555 + static int qup_i2c_probe(struct platform_device *pdev) 556 + { 557 + static const int blk_sizes[] = {4, 16, 32}; 558 + struct device_node *node = pdev->dev.of_node; 559 + struct qup_i2c_dev *qup; 560 + unsigned long one_bit_t; 561 + struct resource *res; 562 + u32 io_mode, hw_ver, size; 563 + int ret, fs_div, hs_div; 564 + int src_clk_freq; 565 + u32 clk_freq = 100000; 566 + 567 + qup = devm_kzalloc(&pdev->dev, sizeof(*qup), GFP_KERNEL); 568 + if (!qup) 569 + return -ENOMEM; 570 + 571 + qup->dev = &pdev->dev; 572 + init_completion(&qup->xfer); 573 + platform_set_drvdata(pdev, qup); 574 + 575 + of_property_read_u32(node, "clock-frequency", &clk_freq); 576 + 577 + /* We support frequencies up to FAST Mode (400KHz) */ 578 + if (!clk_freq || clk_freq > 400000) { 579 + dev_err(qup->dev, "clock frequency not supported %d\n", 580 + clk_freq); 581 + return -EINVAL; 582 + } 583 + 584 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 585 + qup->base = devm_ioremap_resource(qup->dev, res); 586 + if (IS_ERR(qup->base)) 587 + return PTR_ERR(qup->base); 588 + 589 + qup->irq = platform_get_irq(pdev, 0); 590 + if (qup->irq < 0) { 591 + dev_err(qup->dev, "No IRQ defined\n"); 592 + return qup->irq; 593 + } 594 + 595 + qup->clk = devm_clk_get(qup->dev, "core"); 596 + if (IS_ERR(qup->clk)) { 597 + dev_err(qup->dev, "Could not get core clock\n"); 598 + return PTR_ERR(qup->clk); 599 + } 600 + 601 + qup->pclk = devm_clk_get(qup->dev, "iface"); 602 + if (IS_ERR(qup->pclk)) { 603 + dev_err(qup->dev, "Could not get iface clock\n"); 604 + return PTR_ERR(qup->pclk); 605 + } 606 + 607 + qup_i2c_enable_clocks(qup); 608 + 609 + /* 610 + * Bootloaders might leave a pending interrupt on certain QUP's, 611 + * so we reset the core before registering for interrupts. 612 + */ 613 + writel(1, qup->base + QUP_SW_RESET); 614 + ret = qup_i2c_poll_state_valid(qup); 615 + if (ret) 616 + goto fail; 617 + 618 + ret = devm_request_irq(qup->dev, qup->irq, qup_i2c_interrupt, 619 + IRQF_TRIGGER_HIGH, "i2c_qup", qup); 620 + if (ret) { 621 + dev_err(qup->dev, "Request %d IRQ failed\n", qup->irq); 622 + goto fail; 623 + } 624 + disable_irq(qup->irq); 625 + 626 + hw_ver = readl(qup->base + QUP_HW_VERSION); 627 + dev_dbg(qup->dev, "Revision %x\n", hw_ver); 628 + 629 + io_mode = readl(qup->base + QUP_IO_MODE); 630 + 631 + /* 632 + * The block/fifo size w.r.t. 'actual data' is 1/2 due to 'tag' 633 + * associated with each byte written/received 634 + */ 635 + size = QUP_OUTPUT_BLOCK_SIZE(io_mode); 636 + if (size >= ARRAY_SIZE(blk_sizes)) 637 + return -EIO; 638 + qup->out_blk_sz = blk_sizes[size] / 2; 639 + 640 + size = QUP_INPUT_BLOCK_SIZE(io_mode); 641 + if (size >= ARRAY_SIZE(blk_sizes)) 642 + return -EIO; 643 + qup->in_blk_sz = blk_sizes[size] / 2; 644 + 645 + size = QUP_OUTPUT_FIFO_SIZE(io_mode); 646 + qup->out_fifo_sz = qup->out_blk_sz * (2 << size); 647 + 648 + size = QUP_INPUT_FIFO_SIZE(io_mode); 649 + qup->in_fifo_sz = qup->in_blk_sz * (2 << size); 650 + 651 + src_clk_freq = clk_get_rate(qup->clk); 652 + fs_div = ((src_clk_freq / clk_freq) / 2) - 3; 653 + hs_div = 3; 654 + qup->clk_ctl = (hs_div << 8) | (fs_div & 0xff); 655 + 656 + /* 657 + * Time it takes for a byte to be clocked out on the bus. 658 + * Each byte takes 9 clock cycles (8 bits + 1 ack). 659 + */ 660 + one_bit_t = (USEC_PER_SEC / clk_freq) + 1; 661 + qup->one_byte_t = one_bit_t * 9; 662 + 663 + dev_dbg(qup->dev, "IN:block:%d, fifo:%d, OUT:block:%d, fifo:%d\n", 664 + qup->in_blk_sz, qup->in_fifo_sz, 665 + qup->out_blk_sz, qup->out_fifo_sz); 666 + 667 + i2c_set_adapdata(&qup->adap, qup); 668 + qup->adap.algo = &qup_i2c_algo; 669 + qup->adap.dev.parent = qup->dev; 670 + qup->adap.dev.of_node = pdev->dev.of_node; 671 + strlcpy(qup->adap.name, "QUP I2C adapter", sizeof(qup->adap.name)); 672 + 673 + ret = i2c_add_adapter(&qup->adap); 674 + if (ret) 675 + goto fail; 676 + 677 + pm_runtime_set_autosuspend_delay(qup->dev, MSEC_PER_SEC); 678 + pm_runtime_use_autosuspend(qup->dev); 679 + pm_runtime_set_active(qup->dev); 680 + pm_runtime_enable(qup->dev); 681 + return 0; 682 + 683 + fail: 684 + qup_i2c_disable_clocks(qup); 685 + return ret; 686 + } 687 + 688 + static int qup_i2c_remove(struct platform_device *pdev) 689 + { 690 + struct qup_i2c_dev *qup = platform_get_drvdata(pdev); 691 + 692 + disable_irq(qup->irq); 693 + qup_i2c_disable_clocks(qup); 694 + i2c_del_adapter(&qup->adap); 695 + pm_runtime_disable(qup->dev); 696 + pm_runtime_set_suspended(qup->dev); 697 + return 0; 698 + } 699 + 700 + #ifdef CONFIG_PM 701 + static int qup_i2c_pm_suspend_runtime(struct device *device) 702 + { 703 + struct qup_i2c_dev *qup = dev_get_drvdata(device); 704 + 705 + dev_dbg(device, "pm_runtime: suspending...\n"); 706 + qup_i2c_disable_clocks(qup); 707 + return 0; 708 + } 709 + 710 + static int qup_i2c_pm_resume_runtime(struct device *device) 711 + { 712 + struct qup_i2c_dev *qup = dev_get_drvdata(device); 713 + 714 + dev_dbg(device, "pm_runtime: resuming...\n"); 715 + qup_i2c_enable_clocks(qup); 716 + return 0; 717 + } 718 + #endif 719 + 720 + #ifdef CONFIG_PM_SLEEP 721 + static int qup_i2c_suspend(struct device *device) 722 + { 723 + qup_i2c_pm_suspend_runtime(device); 724 + return 0; 725 + } 726 + 727 + static int qup_i2c_resume(struct device *device) 728 + { 729 + qup_i2c_pm_resume_runtime(device); 730 + pm_runtime_mark_last_busy(device); 731 + pm_request_autosuspend(device); 732 + return 0; 733 + } 734 + #endif 735 + 736 + static const struct dev_pm_ops qup_i2c_qup_pm_ops = { 737 + SET_SYSTEM_SLEEP_PM_OPS( 738 + qup_i2c_suspend, 739 + qup_i2c_resume) 740 + SET_RUNTIME_PM_OPS( 741 + qup_i2c_pm_suspend_runtime, 742 + qup_i2c_pm_resume_runtime, 743 + NULL) 744 + }; 745 + 746 + static const struct of_device_id qup_i2c_dt_match[] = { 747 + { .compatible = "qcom,i2c-qup-v1.1.1" }, 748 + { .compatible = "qcom,i2c-qup-v2.1.1" }, 749 + { .compatible = "qcom,i2c-qup-v2.2.1" }, 750 + {} 751 + }; 752 + MODULE_DEVICE_TABLE(of, qup_i2c_dt_match); 753 + 754 + static struct platform_driver qup_i2c_driver = { 755 + .probe = qup_i2c_probe, 756 + .remove = qup_i2c_remove, 757 + .driver = { 758 + .name = "i2c_qup", 759 + .owner = THIS_MODULE, 760 + .pm = &qup_i2c_qup_pm_ops, 761 + .of_match_table = qup_i2c_dt_match, 762 + }, 763 + }; 764 + 765 + module_platform_driver(qup_i2c_driver); 766 + 767 + MODULE_LICENSE("GPL v2"); 768 + MODULE_ALIAS("platform:i2c_qup");
+2 -1
drivers/i2c/busses/i2c-rcar.c
··· 638 638 { .compatible = "renesas,i2c-r8a7778", .data = (void *)I2C_RCAR_GEN1 }, 639 639 { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_GEN1 }, 640 640 { .compatible = "renesas,i2c-r8a7790", .data = (void *)I2C_RCAR_GEN2 }, 641 + { .compatible = "renesas,i2c-r8a7791", .data = (void *)I2C_RCAR_GEN2 }, 641 642 {}, 642 643 }; 643 644 MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids); ··· 692 691 adap = &priv->adap; 693 692 adap->nr = pdev->id; 694 693 adap->algo = &rcar_i2c_algo; 695 - adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 694 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 696 695 adap->retries = 3; 697 696 adap->dev.parent = dev; 698 697 adap->dev.of_node = dev->of_node;
+34 -5
drivers/i2c/busses/i2c-s3c2410.c
··· 601 601 return IRQ_HANDLED; 602 602 } 603 603 604 + /* 605 + * Disable the bus so that we won't get any interrupts from now on, or try 606 + * to drive any lines. This is the default state when we don't have 607 + * anything to send/receive. 608 + * 609 + * If there is an event on the bus, or we have a pre-existing event at 610 + * kernel boot time, we may not notice the event and the I2C controller 611 + * will lock the bus with the I2C clock line low indefinitely. 612 + */ 613 + static inline void s3c24xx_i2c_disable_bus(struct s3c24xx_i2c *i2c) 614 + { 615 + unsigned long tmp; 616 + 617 + /* Stop driving the I2C pins */ 618 + tmp = readl(i2c->regs + S3C2410_IICSTAT); 619 + tmp &= ~S3C2410_IICSTAT_TXRXEN; 620 + writel(tmp, i2c->regs + S3C2410_IICSTAT); 621 + 622 + /* We don't expect any interrupts now, and don't want send acks */ 623 + tmp = readl(i2c->regs + S3C2410_IICCON); 624 + tmp &= ~(S3C2410_IICCON_IRQEN | S3C2410_IICCON_IRQPEND | 625 + S3C2410_IICCON_ACKEN); 626 + writel(tmp, i2c->regs + S3C2410_IICCON); 627 + } 628 + 604 629 605 630 /* s3c24xx_i2c_set_master 606 631 * ··· 760 735 761 736 s3c24xx_i2c_wait_idle(i2c); 762 737 738 + s3c24xx_i2c_disable_bus(i2c); 739 + 763 740 out: 741 + i2c->state = STATE_IDLE; 742 + 764 743 return ret; 765 744 } 766 745 ··· 1033 1004 1034 1005 static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) 1035 1006 { 1036 - unsigned long iicon = S3C2410_IICCON_IRQEN | S3C2410_IICCON_ACKEN; 1037 1007 struct s3c2410_platform_i2c *pdata; 1038 1008 unsigned int freq; 1039 1009 ··· 1046 1018 1047 1019 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); 1048 1020 1049 - writel(iicon, i2c->regs + S3C2410_IICCON); 1021 + writel(0, i2c->regs + S3C2410_IICCON); 1022 + writel(0, i2c->regs + S3C2410_IICSTAT); 1050 1023 1051 1024 /* we need to work out the divisors for the clock... */ 1052 1025 1053 1026 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) { 1054 - writel(0, i2c->regs + S3C2410_IICCON); 1055 1027 dev_err(i2c->dev, "cannot meet bus frequency required\n"); 1056 1028 return -EINVAL; 1057 1029 } ··· 1059 1031 /* todo - check that the i2c lines aren't being dragged anywhere */ 1060 1032 1061 1033 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); 1062 - dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); 1034 + dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02x\n", 1035 + readl(i2c->regs + S3C2410_IICCON)); 1063 1036 1064 1037 return 0; 1065 1038 } ··· 1135 1106 i2c->adap.owner = THIS_MODULE; 1136 1107 i2c->adap.algo = &s3c24xx_i2c_algorithm; 1137 1108 i2c->adap.retries = 2; 1138 - i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1109 + i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED; 1139 1110 i2c->tx_setup = 50; 1140 1111 1141 1112 init_waitqueue_head(&i2c->wait);
+1 -1
drivers/i2c/busses/i2c-sirf.c
··· 312 312 goto out; 313 313 } 314 314 adap = &siic->adapter; 315 - adap->class = I2C_CLASS_HWMON; 315 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 316 316 317 317 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 318 318 siic->base = devm_ioremap_resource(&pdev->dev, mem_res);
+1 -1
drivers/i2c/busses/i2c-sis5595.c
··· 369 369 .algo = &smbus_algorithm, 370 370 }; 371 371 372 - static DEFINE_PCI_DEVICE_TABLE(sis5595_ids) = { 372 + static const struct pci_device_id sis5595_ids[] = { 373 373 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 374 374 { 0, } 375 375 };
+1 -1
drivers/i2c/busses/i2c-sis630.c
··· 510 510 .retries = 3 511 511 }; 512 512 513 - static DEFINE_PCI_DEVICE_TABLE(sis630_ids) = { 513 + static const struct pci_device_id sis630_ids[] = { 514 514 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 515 515 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, 516 516 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_964) },
+1 -1
drivers/i2c/busses/i2c-sis96x.c
··· 244 244 .algo = &smbus_algorithm, 245 245 }; 246 246 247 - static DEFINE_PCI_DEVICE_TABLE(sis96x_ids) = { 247 + static const struct pci_device_id sis96x_ids[] = { 248 248 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) }, 249 249 { 0, } 250 250 };
+1 -1
drivers/i2c/busses/i2c-st.c
··· 574 574 writel_relaxed(it, i2c_dev->base + SSC_IEN); 575 575 576 576 st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG); 577 - c->result = -EIO; 577 + c->result = -EAGAIN; 578 578 break; 579 579 580 580 default:
+1 -1
drivers/i2c/busses/i2c-stu300.c
··· 911 911 adap = &dev->adapter; 912 912 adap->owner = THIS_MODULE; 913 913 /* DDC class but actually often used for more generic I2C */ 914 - adap->class = I2C_CLASS_DDC; 914 + adap->class = I2C_CLASS_DDC | I2C_CLASS_DEPRECATED; 915 915 strlcpy(adap->name, "ST Microelectronics DDC I2C adapter", 916 916 sizeof(adap->name)); 917 917 adap->nr = bus_nr;
+1 -1
drivers/i2c/busses/i2c-tegra.c
··· 794 794 795 795 i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); 796 796 i2c_dev->adapter.owner = THIS_MODULE; 797 - i2c_dev->adapter.class = I2C_CLASS_HWMON; 797 + i2c_dev->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_DEPRECATED; 798 798 strlcpy(i2c_dev->adapter.name, "Tegra I2C adapter", 799 799 sizeof(i2c_dev->adapter.name)); 800 800 i2c_dev->adapter.algo = &tegra_i2c_algo;
+1 -1
drivers/i2c/busses/i2c-via.c
··· 88 88 }; 89 89 90 90 91 - static DEFINE_PCI_DEVICE_TABLE(vt586b_ids) = { 91 + static const struct pci_device_id vt586b_ids[] = { 92 92 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) }, 93 93 { 0, } 94 94 };
+1 -1
drivers/i2c/busses/i2c-viapro.c
··· 442 442 return error; 443 443 } 444 444 445 - static DEFINE_PCI_DEVICE_TABLE(vt596_ids) = { 445 + static const struct pci_device_id vt596_ids[] = { 446 446 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3), 447 447 .driver_data = SMBBA1 }, 448 448 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3),
+1 -1
drivers/i2c/busses/i2c-xiic.c
··· 684 684 static struct i2c_adapter xiic_adapter = { 685 685 .owner = THIS_MODULE, 686 686 .name = DRIVER_NAME, 687 - .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 687 + .class = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED, 688 688 .algo = &xiic_algorithm, 689 689 }; 690 690
+1 -1
drivers/i2c/busses/scx200_acb.c
··· 556 556 .remove = scx200_remove, 557 557 }; 558 558 559 - static DEFINE_PCI_DEVICE_TABLE(scx200_isa) = { 559 + static const struct pci_device_id scx200_isa[] = { 560 560 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) }, 561 561 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) }, 562 562 { 0, }
+64 -3
drivers/i2c/i2c-core.c
··· 48 48 #include <linux/rwsem.h> 49 49 #include <linux/pm_runtime.h> 50 50 #include <linux/acpi.h> 51 + #include <linux/jump_label.h> 51 52 #include <asm/uaccess.h> 52 53 53 54 #include "i2c-core.h" 54 55 56 + #define CREATE_TRACE_POINTS 57 + #include <trace/events/i2c.h> 55 58 56 59 /* core_lock protects i2c_adapter_idr, and guarantees 57 60 that device detection, deletion of detected devices, and attach_adapter ··· 64 61 65 62 static struct device_type i2c_client_type; 66 63 static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); 64 + 65 + static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE; 66 + 67 + void i2c_transfer_trace_reg(void) 68 + { 69 + static_key_slow_inc(&i2c_trace_msg); 70 + } 71 + 72 + void i2c_transfer_trace_unreg(void) 73 + { 74 + static_key_slow_dec(&i2c_trace_msg); 75 + } 67 76 68 77 /* ------------------------------------------------------------------------- */ 69 78 ··· 1701 1686 class_compat_unregister(i2c_adapter_compat_class); 1702 1687 #endif 1703 1688 bus_unregister(&i2c_bus_type); 1689 + tracepoint_synchronize_unregister(); 1704 1690 } 1705 1691 1706 1692 /* We must initialize early, because some subsystems register i2c drivers ··· 1732 1716 unsigned long orig_jiffies; 1733 1717 int ret, try; 1734 1718 1719 + /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets 1720 + * enabled. This is an efficient way of keeping the for-loop from 1721 + * being executed when not needed. 1722 + */ 1723 + if (static_key_false(&i2c_trace_msg)) { 1724 + int i; 1725 + for (i = 0; i < num; i++) 1726 + if (msgs[i].flags & I2C_M_RD) 1727 + trace_i2c_read(adap, &msgs[i], i); 1728 + else 1729 + trace_i2c_write(adap, &msgs[i], i); 1730 + } 1731 + 1735 1732 /* Retry automatically on arbitration loss */ 1736 1733 orig_jiffies = jiffies; 1737 1734 for (ret = 0, try = 0; try <= adap->retries; try++) { ··· 1753 1724 break; 1754 1725 if (time_after(jiffies, orig_jiffies + adap->timeout)) 1755 1726 break; 1727 + } 1728 + 1729 + if (static_key_false(&i2c_trace_msg)) { 1730 + int i; 1731 + for (i = 0; i < ret; i++) 1732 + if (msgs[i].flags & I2C_M_RD) 1733 + trace_i2c_reply(adap, &msgs[i], i); 1734 + trace_i2c_result(adap, i, ret); 1756 1735 } 1757 1736 1758 1737 return ret; ··· 1978 1941 struct i2c_client *client; 1979 1942 1980 1943 /* Detection succeeded, instantiate the device */ 1944 + if (adapter->class & I2C_CLASS_DEPRECATED) 1945 + dev_warn(&adapter->dev, 1946 + "This adapter will soon drop class based instantiation of devices. " 1947 + "Please make sure client 0x%02x gets instantiated by other means. " 1948 + "Check 'Documentation/i2c/instantiating-devices' for details.\n", 1949 + info.addr); 1950 + 1981 1951 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n", 1982 1952 info.type, info.addr); 1983 1953 client = i2c_new_device(adapter, &info); ··· 2565 2521 int try; 2566 2522 s32 res; 2567 2523 2524 + /* If enabled, the following two tracepoints are conditional on 2525 + * read_write and protocol. 2526 + */ 2527 + trace_smbus_write(adapter, addr, flags, read_write, 2528 + command, protocol, data); 2529 + trace_smbus_read(adapter, addr, flags, read_write, 2530 + command, protocol); 2531 + 2568 2532 flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB; 2569 2533 2570 2534 if (adapter->algo->smbus_xfer) { ··· 2593 2541 i2c_unlock_adapter(adapter); 2594 2542 2595 2543 if (res != -EOPNOTSUPP || !adapter->algo->master_xfer) 2596 - return res; 2544 + goto trace; 2597 2545 /* 2598 2546 * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't 2599 2547 * implement native support for the SMBus operation. 2600 2548 */ 2601 2549 } 2602 2550 2603 - return i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2604 - command, protocol, data); 2551 + res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2552 + command, protocol, data); 2553 + 2554 + trace: 2555 + /* If enabled, the reply tracepoint is conditional on read_write. */ 2556 + trace_smbus_reply(adapter, addr, flags, read_write, 2557 + command, protocol, data); 2558 + trace_smbus_result(adapter, addr, flags, read_write, 2559 + command, protocol, res); 2560 + 2561 + return res; 2605 2562 } 2606 2563 EXPORT_SYMBOL(i2c_smbus_xfer); 2607 2564
+1
include/linux/i2c.h
··· 487 487 #define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ 488 488 #define I2C_CLASS_DDC (1<<3) /* DDC bus on graphics adapters */ 489 489 #define I2C_CLASS_SPD (1<<7) /* Memory modules */ 490 + #define I2C_CLASS_DEPRECATED (1<<8) /* Warn users that adapter will stop using classes */ 490 491 491 492 /* Internal numbers to terminate lists */ 492 493 #define I2C_CLIENT_END 0xfffeU
+145
include/linux/i2c/bfin_twi.h
··· 1 + /* 2 + * i2c-bfin-twi.h - interface to ADI TWI controller 3 + * 4 + * Copyright 2005-2014 Analog Devices Inc. 5 + * 6 + * Licensed under the GPL-2 or later. 7 + */ 8 + 9 + #ifndef __I2C_BFIN_TWI_H__ 10 + #define __I2C_BFIN_TWI_H__ 11 + 12 + #include <linux/types.h> 13 + #include <linux/i2c.h> 14 + 15 + /* 16 + * ADI twi registers layout 17 + */ 18 + struct bfin_twi_regs { 19 + u16 clkdiv; 20 + u16 dummy1; 21 + u16 control; 22 + u16 dummy2; 23 + u16 slave_ctl; 24 + u16 dummy3; 25 + u16 slave_stat; 26 + u16 dummy4; 27 + u16 slave_addr; 28 + u16 dummy5; 29 + u16 master_ctl; 30 + u16 dummy6; 31 + u16 master_stat; 32 + u16 dummy7; 33 + u16 master_addr; 34 + u16 dummy8; 35 + u16 int_stat; 36 + u16 dummy9; 37 + u16 int_mask; 38 + u16 dummy10; 39 + u16 fifo_ctl; 40 + u16 dummy11; 41 + u16 fifo_stat; 42 + u16 dummy12; 43 + u32 __pad[20]; 44 + u16 xmt_data8; 45 + u16 dummy13; 46 + u16 xmt_data16; 47 + u16 dummy14; 48 + u16 rcv_data8; 49 + u16 dummy15; 50 + u16 rcv_data16; 51 + u16 dummy16; 52 + }; 53 + 54 + struct bfin_twi_iface { 55 + int irq; 56 + spinlock_t lock; 57 + char read_write; 58 + u8 command; 59 + u8 *transPtr; 60 + int readNum; 61 + int writeNum; 62 + int cur_mode; 63 + int manual_stop; 64 + int result; 65 + struct i2c_adapter adap; 66 + struct completion complete; 67 + struct i2c_msg *pmsg; 68 + int msg_num; 69 + int cur_msg; 70 + u16 saved_clkdiv; 71 + u16 saved_control; 72 + struct bfin_twi_regs __iomem *regs_base; 73 + }; 74 + 75 + /* ******************** TWO-WIRE INTERFACE (TWI) MASKS ********************/ 76 + /* TWI_CLKDIV Macros (Use: *pTWI_CLKDIV = CLKLOW(x)|CLKHI(y); ) */ 77 + #define CLKLOW(x) ((x) & 0xFF) /* Periods Clock Is Held Low */ 78 + #define CLKHI(y) (((y)&0xFF)<<0x8) /* Periods Before New Clock Low */ 79 + 80 + /* TWI_PRESCALE Masks */ 81 + #define PRESCALE 0x007F /* SCLKs Per Internal Time Reference (10MHz) */ 82 + #define TWI_ENA 0x0080 /* TWI Enable */ 83 + #define SCCB 0x0200 /* SCCB Compatibility Enable */ 84 + 85 + /* TWI_SLAVE_CTL Masks */ 86 + #define SEN 0x0001 /* Slave Enable */ 87 + #define SADD_LEN 0x0002 /* Slave Address Length */ 88 + #define STDVAL 0x0004 /* Slave Transmit Data Valid */ 89 + #define NAK 0x0008 /* NAK Generated At Conclusion Of Transfer */ 90 + #define GEN 0x0010 /* General Call Address Matching Enabled */ 91 + 92 + /* TWI_SLAVE_STAT Masks */ 93 + #define SDIR 0x0001 /* Slave Transfer Direction (RX/TX*) */ 94 + #define GCALL 0x0002 /* General Call Indicator */ 95 + 96 + /* TWI_MASTER_CTL Masks */ 97 + #define MEN 0x0001 /* Master Mode Enable */ 98 + #define MADD_LEN 0x0002 /* Master Address Length */ 99 + #define MDIR 0x0004 /* Master Transmit Direction (RX/TX*) */ 100 + #define FAST 0x0008 /* Use Fast Mode Timing Specs */ 101 + #define STOP 0x0010 /* Issue Stop Condition */ 102 + #define RSTART 0x0020 /* Repeat Start or Stop* At End Of Transfer */ 103 + #define DCNT 0x3FC0 /* Data Bytes To Transfer */ 104 + #define SDAOVR 0x4000 /* Serial Data Override */ 105 + #define SCLOVR 0x8000 /* Serial Clock Override */ 106 + 107 + /* TWI_MASTER_STAT Masks */ 108 + #define MPROG 0x0001 /* Master Transfer In Progress */ 109 + #define LOSTARB 0x0002 /* Lost Arbitration Indicator (Xfer Aborted) */ 110 + #define ANAK 0x0004 /* Address Not Acknowledged */ 111 + #define DNAK 0x0008 /* Data Not Acknowledged */ 112 + #define BUFRDERR 0x0010 /* Buffer Read Error */ 113 + #define BUFWRERR 0x0020 /* Buffer Write Error */ 114 + #define SDASEN 0x0040 /* Serial Data Sense */ 115 + #define SCLSEN 0x0080 /* Serial Clock Sense */ 116 + #define BUSBUSY 0x0100 /* Bus Busy Indicator */ 117 + 118 + /* TWI_INT_SRC and TWI_INT_ENABLE Masks */ 119 + #define SINIT 0x0001 /* Slave Transfer Initiated */ 120 + #define SCOMP 0x0002 /* Slave Transfer Complete */ 121 + #define SERR 0x0004 /* Slave Transfer Error */ 122 + #define SOVF 0x0008 /* Slave Overflow */ 123 + #define MCOMP 0x0010 /* Master Transfer Complete */ 124 + #define MERR 0x0020 /* Master Transfer Error */ 125 + #define XMTSERV 0x0040 /* Transmit FIFO Service */ 126 + #define RCVSERV 0x0080 /* Receive FIFO Service */ 127 + 128 + /* TWI_FIFO_CTRL Masks */ 129 + #define XMTFLUSH 0x0001 /* Transmit Buffer Flush */ 130 + #define RCVFLUSH 0x0002 /* Receive Buffer Flush */ 131 + #define XMTINTLEN 0x0004 /* Transmit Buffer Interrupt Length */ 132 + #define RCVINTLEN 0x0008 /* Receive Buffer Interrupt Length */ 133 + 134 + /* TWI_FIFO_STAT Masks */ 135 + #define XMTSTAT 0x0003 /* Transmit FIFO Status */ 136 + #define XMT_EMPTY 0x0000 /* Transmit FIFO Empty */ 137 + #define XMT_HALF 0x0001 /* Transmit FIFO Has 1 Byte To Write */ 138 + #define XMT_FULL 0x0003 /* Transmit FIFO Full (2 Bytes To Write) */ 139 + 140 + #define RCVSTAT 0x000C /* Receive FIFO Status */ 141 + #define RCV_EMPTY 0x0000 /* Receive FIFO Empty */ 142 + #define RCV_HALF 0x0004 /* Receive FIFO Has 1 Byte To Read */ 143 + #define RCV_FULL 0x000C /* Receive FIFO Full (2 Bytes To Read) */ 144 + 145 + #endif
+4 -5
include/linux/platform_data/i2c-s3c2410.h
··· 1 - /* arch/arm/plat-s3c/include/plat/iic.h 2 - * 1 + /* 3 2 * Copyright 2004-2009 Simtec Electronics 4 3 * Ben Dooks <ben@simtec.co.uk> 5 4 * ··· 9 10 * published by the Free Software Foundation. 10 11 */ 11 12 12 - #ifndef __ASM_ARCH_IIC_H 13 - #define __ASM_ARCH_IIC_H __FILE__ 13 + #ifndef __I2C_S3C2410_H 14 + #define __I2C_S3C2410_H __FILE__ 14 15 15 16 #define S3C_IICFLG_FILTER (1<<0) /* enable s3c2440 filter */ 16 17 ··· 75 76 76 77 extern struct s3c2410_platform_i2c default_i2c_data; 77 78 78 - #endif /* __ASM_ARCH_IIC_H */ 79 + #endif /* __I2C_S3C2410_H */
+372
include/trace/events/i2c.h
··· 1 + /* I2C and SMBUS message transfer tracepoints 2 + * 3 + * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved. 4 + * Written by David Howells (dhowells@redhat.com) 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public Licence 8 + * as published by the Free Software Foundation; either version 9 + * 2 of the Licence, or (at your option) any later version. 10 + */ 11 + #undef TRACE_SYSTEM 12 + #define TRACE_SYSTEM i2c 13 + 14 + #if !defined(_TRACE_I2C_H) || defined(TRACE_HEADER_MULTI_READ) 15 + #define _TRACE_I2C_H 16 + 17 + #include <linux/i2c.h> 18 + #include <linux/tracepoint.h> 19 + 20 + /* 21 + * drivers/i2c/i2c-core.c 22 + */ 23 + extern void i2c_transfer_trace_reg(void); 24 + extern void i2c_transfer_trace_unreg(void); 25 + 26 + /* 27 + * __i2c_transfer() write request 28 + */ 29 + TRACE_EVENT_FN(i2c_write, 30 + TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg, 31 + int num), 32 + TP_ARGS(adap, msg, num), 33 + TP_STRUCT__entry( 34 + __field(int, adapter_nr ) 35 + __field(__u16, msg_nr ) 36 + __field(__u16, addr ) 37 + __field(__u16, flags ) 38 + __field(__u16, len ) 39 + __dynamic_array(__u8, buf, msg->len) ), 40 + TP_fast_assign( 41 + __entry->adapter_nr = adap->nr; 42 + __entry->msg_nr = num; 43 + __entry->addr = msg->addr; 44 + __entry->flags = msg->flags; 45 + __entry->len = msg->len; 46 + memcpy(__get_dynamic_array(buf), msg->buf, msg->len); 47 + ), 48 + TP_printk("i2c-%d #%u a=%03x f=%04x l=%u [%*phD]", 49 + __entry->adapter_nr, 50 + __entry->msg_nr, 51 + __entry->addr, 52 + __entry->flags, 53 + __entry->len, 54 + __entry->len, __get_dynamic_array(buf) 55 + ), 56 + i2c_transfer_trace_reg, 57 + i2c_transfer_trace_unreg); 58 + 59 + /* 60 + * __i2c_transfer() read request 61 + */ 62 + TRACE_EVENT_FN(i2c_read, 63 + TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg, 64 + int num), 65 + TP_ARGS(adap, msg, num), 66 + TP_STRUCT__entry( 67 + __field(int, adapter_nr ) 68 + __field(__u16, msg_nr ) 69 + __field(__u16, addr ) 70 + __field(__u16, flags ) 71 + __field(__u16, len ) 72 + ), 73 + TP_fast_assign( 74 + __entry->adapter_nr = adap->nr; 75 + __entry->msg_nr = num; 76 + __entry->addr = msg->addr; 77 + __entry->flags = msg->flags; 78 + __entry->len = msg->len; 79 + ), 80 + TP_printk("i2c-%d #%u a=%03x f=%04x l=%u", 81 + __entry->adapter_nr, 82 + __entry->msg_nr, 83 + __entry->addr, 84 + __entry->flags, 85 + __entry->len 86 + ), 87 + i2c_transfer_trace_reg, 88 + i2c_transfer_trace_unreg); 89 + 90 + /* 91 + * __i2c_transfer() read reply 92 + */ 93 + TRACE_EVENT_FN(i2c_reply, 94 + TP_PROTO(const struct i2c_adapter *adap, const struct i2c_msg *msg, 95 + int num), 96 + TP_ARGS(adap, msg, num), 97 + TP_STRUCT__entry( 98 + __field(int, adapter_nr ) 99 + __field(__u16, msg_nr ) 100 + __field(__u16, addr ) 101 + __field(__u16, flags ) 102 + __field(__u16, len ) 103 + __dynamic_array(__u8, buf, msg->len) ), 104 + TP_fast_assign( 105 + __entry->adapter_nr = adap->nr; 106 + __entry->msg_nr = num; 107 + __entry->addr = msg->addr; 108 + __entry->flags = msg->flags; 109 + __entry->len = msg->len; 110 + memcpy(__get_dynamic_array(buf), msg->buf, msg->len); 111 + ), 112 + TP_printk("i2c-%d #%u a=%03x f=%04x l=%u [%*phD]", 113 + __entry->adapter_nr, 114 + __entry->msg_nr, 115 + __entry->addr, 116 + __entry->flags, 117 + __entry->len, 118 + __entry->len, __get_dynamic_array(buf) 119 + ), 120 + i2c_transfer_trace_reg, 121 + i2c_transfer_trace_unreg); 122 + 123 + /* 124 + * __i2c_transfer() result 125 + */ 126 + TRACE_EVENT_FN(i2c_result, 127 + TP_PROTO(const struct i2c_adapter *adap, int num, int ret), 128 + TP_ARGS(adap, num, ret), 129 + TP_STRUCT__entry( 130 + __field(int, adapter_nr ) 131 + __field(__u16, nr_msgs ) 132 + __field(__s16, ret ) 133 + ), 134 + TP_fast_assign( 135 + __entry->adapter_nr = adap->nr; 136 + __entry->nr_msgs = num; 137 + __entry->ret = ret; 138 + ), 139 + TP_printk("i2c-%d n=%u ret=%d", 140 + __entry->adapter_nr, 141 + __entry->nr_msgs, 142 + __entry->ret 143 + ), 144 + i2c_transfer_trace_reg, 145 + i2c_transfer_trace_unreg); 146 + 147 + /* 148 + * i2c_smbus_xfer() write data or procedure call request 149 + */ 150 + TRACE_EVENT_CONDITION(smbus_write, 151 + TP_PROTO(const struct i2c_adapter *adap, 152 + u16 addr, unsigned short flags, 153 + char read_write, u8 command, int protocol, 154 + const union i2c_smbus_data *data), 155 + TP_ARGS(adap, addr, flags, read_write, command, protocol, data), 156 + TP_CONDITION(read_write == I2C_SMBUS_WRITE || 157 + protocol == I2C_SMBUS_PROC_CALL || 158 + protocol == I2C_SMBUS_BLOCK_PROC_CALL), 159 + TP_STRUCT__entry( 160 + __field(int, adapter_nr ) 161 + __field(__u16, addr ) 162 + __field(__u16, flags ) 163 + __field(__u8, command ) 164 + __field(__u8, len ) 165 + __field(__u32, protocol ) 166 + __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ), 167 + TP_fast_assign( 168 + __entry->adapter_nr = adap->nr; 169 + __entry->addr = addr; 170 + __entry->flags = flags; 171 + __entry->command = command; 172 + __entry->protocol = protocol; 173 + 174 + switch (protocol) { 175 + case I2C_SMBUS_BYTE_DATA: 176 + __entry->len = 1; 177 + goto copy; 178 + case I2C_SMBUS_WORD_DATA: 179 + case I2C_SMBUS_PROC_CALL: 180 + __entry->len = 2; 181 + goto copy; 182 + case I2C_SMBUS_BLOCK_DATA: 183 + case I2C_SMBUS_BLOCK_PROC_CALL: 184 + case I2C_SMBUS_I2C_BLOCK_DATA: 185 + __entry->len = data->block[0] + 1; 186 + copy: 187 + memcpy(__entry->buf, data->block, __entry->len); 188 + break; 189 + case I2C_SMBUS_QUICK: 190 + case I2C_SMBUS_BYTE: 191 + case I2C_SMBUS_I2C_BLOCK_BROKEN: 192 + default: 193 + __entry->len = 0; 194 + } 195 + ), 196 + TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]", 197 + __entry->adapter_nr, 198 + __entry->addr, 199 + __entry->flags, 200 + __entry->command, 201 + __print_symbolic(__entry->protocol, 202 + { I2C_SMBUS_QUICK, "QUICK" }, 203 + { I2C_SMBUS_BYTE, "BYTE" }, 204 + { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" }, 205 + { I2C_SMBUS_WORD_DATA, "WORD_DATA" }, 206 + { I2C_SMBUS_PROC_CALL, "PROC_CALL" }, 207 + { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" }, 208 + { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" }, 209 + { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" }, 210 + { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }), 211 + __entry->len, 212 + __entry->len, __entry->buf 213 + )); 214 + 215 + /* 216 + * i2c_smbus_xfer() read data request 217 + */ 218 + TRACE_EVENT_CONDITION(smbus_read, 219 + TP_PROTO(const struct i2c_adapter *adap, 220 + u16 addr, unsigned short flags, 221 + char read_write, u8 command, int protocol), 222 + TP_ARGS(adap, addr, flags, read_write, command, protocol), 223 + TP_CONDITION(!(read_write == I2C_SMBUS_WRITE || 224 + protocol == I2C_SMBUS_PROC_CALL || 225 + protocol == I2C_SMBUS_BLOCK_PROC_CALL)), 226 + TP_STRUCT__entry( 227 + __field(int, adapter_nr ) 228 + __field(__u16, flags ) 229 + __field(__u16, addr ) 230 + __field(__u8, command ) 231 + __field(__u32, protocol ) 232 + __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ), 233 + TP_fast_assign( 234 + __entry->adapter_nr = adap->nr; 235 + __entry->addr = addr; 236 + __entry->flags = flags; 237 + __entry->command = command; 238 + __entry->protocol = protocol; 239 + ), 240 + TP_printk("i2c-%d a=%03x f=%04x c=%x %s", 241 + __entry->adapter_nr, 242 + __entry->addr, 243 + __entry->flags, 244 + __entry->command, 245 + __print_symbolic(__entry->protocol, 246 + { I2C_SMBUS_QUICK, "QUICK" }, 247 + { I2C_SMBUS_BYTE, "BYTE" }, 248 + { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" }, 249 + { I2C_SMBUS_WORD_DATA, "WORD_DATA" }, 250 + { I2C_SMBUS_PROC_CALL, "PROC_CALL" }, 251 + { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" }, 252 + { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" }, 253 + { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" }, 254 + { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }) 255 + )); 256 + 257 + /* 258 + * i2c_smbus_xfer() read data or procedure call reply 259 + */ 260 + TRACE_EVENT_CONDITION(smbus_reply, 261 + TP_PROTO(const struct i2c_adapter *adap, 262 + u16 addr, unsigned short flags, 263 + char read_write, u8 command, int protocol, 264 + const union i2c_smbus_data *data), 265 + TP_ARGS(adap, addr, flags, read_write, command, protocol, data), 266 + TP_CONDITION(read_write == I2C_SMBUS_READ), 267 + TP_STRUCT__entry( 268 + __field(int, adapter_nr ) 269 + __field(__u16, addr ) 270 + __field(__u16, flags ) 271 + __field(__u8, command ) 272 + __field(__u8, len ) 273 + __field(__u32, protocol ) 274 + __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ), 275 + TP_fast_assign( 276 + __entry->adapter_nr = adap->nr; 277 + __entry->addr = addr; 278 + __entry->flags = flags; 279 + __entry->command = command; 280 + __entry->protocol = protocol; 281 + 282 + switch (protocol) { 283 + case I2C_SMBUS_BYTE: 284 + case I2C_SMBUS_BYTE_DATA: 285 + __entry->len = 1; 286 + goto copy; 287 + case I2C_SMBUS_WORD_DATA: 288 + case I2C_SMBUS_PROC_CALL: 289 + __entry->len = 2; 290 + goto copy; 291 + case I2C_SMBUS_BLOCK_DATA: 292 + case I2C_SMBUS_BLOCK_PROC_CALL: 293 + case I2C_SMBUS_I2C_BLOCK_DATA: 294 + __entry->len = data->block[0] + 1; 295 + copy: 296 + memcpy(__entry->buf, data->block, __entry->len); 297 + break; 298 + case I2C_SMBUS_QUICK: 299 + case I2C_SMBUS_I2C_BLOCK_BROKEN: 300 + default: 301 + __entry->len = 0; 302 + } 303 + ), 304 + TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]", 305 + __entry->adapter_nr, 306 + __entry->addr, 307 + __entry->flags, 308 + __entry->command, 309 + __print_symbolic(__entry->protocol, 310 + { I2C_SMBUS_QUICK, "QUICK" }, 311 + { I2C_SMBUS_BYTE, "BYTE" }, 312 + { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" }, 313 + { I2C_SMBUS_WORD_DATA, "WORD_DATA" }, 314 + { I2C_SMBUS_PROC_CALL, "PROC_CALL" }, 315 + { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" }, 316 + { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" }, 317 + { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" }, 318 + { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }), 319 + __entry->len, 320 + __entry->len, __entry->buf 321 + )); 322 + 323 + /* 324 + * i2c_smbus_xfer() result 325 + */ 326 + TRACE_EVENT(smbus_result, 327 + TP_PROTO(const struct i2c_adapter *adap, 328 + u16 addr, unsigned short flags, 329 + char read_write, u8 command, int protocol, 330 + int res), 331 + TP_ARGS(adap, addr, flags, read_write, command, protocol, res), 332 + TP_STRUCT__entry( 333 + __field(int, adapter_nr ) 334 + __field(__u16, addr ) 335 + __field(__u16, flags ) 336 + __field(__u8, read_write ) 337 + __field(__u8, command ) 338 + __field(__s16, res ) 339 + __field(__u32, protocol ) 340 + ), 341 + TP_fast_assign( 342 + __entry->adapter_nr = adap->nr; 343 + __entry->addr = addr; 344 + __entry->flags = flags; 345 + __entry->read_write = read_write; 346 + __entry->command = command; 347 + __entry->protocol = protocol; 348 + __entry->res = res; 349 + ), 350 + TP_printk("i2c-%d a=%03x f=%04x c=%x %s %s res=%d", 351 + __entry->adapter_nr, 352 + __entry->addr, 353 + __entry->flags, 354 + __entry->command, 355 + __print_symbolic(__entry->protocol, 356 + { I2C_SMBUS_QUICK, "QUICK" }, 357 + { I2C_SMBUS_BYTE, "BYTE" }, 358 + { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" }, 359 + { I2C_SMBUS_WORD_DATA, "WORD_DATA" }, 360 + { I2C_SMBUS_PROC_CALL, "PROC_CALL" }, 361 + { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" }, 362 + { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" }, 363 + { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" }, 364 + { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }), 365 + __entry->read_write == I2C_SMBUS_WRITE ? "wr" : "rd", 366 + __entry->res 367 + )); 368 + 369 + #endif /* _TRACE_I2C_H */ 370 + 371 + /* This part must be outside protection */ 372 + #include <trace/define_trace.h>