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

Merge branch 'i2c-embedded/for-next' of git://git.pengutronix.de/git/wsa/linux

Pull i2c-embedded changes from Wolfram Sang:
- CBUS driver (an I2C variant)
- continued rework of the omap driver
- s3c2410 gets lots of fixes and gains pinctrl support
- at91 gains DMA support
- the GPIO muxer gains devicetree probing
- typical fixes and additions all over

* 'i2c-embedded/for-next' of git://git.pengutronix.de/git/wsa/linux: (45 commits)
i2c: omap: Remove the OMAP_I2C_FLAG_RESET_REGS_POSTIDLE flag
i2c: at91: add dma support
i2c: at91: change struct members indentation
i2c: at91: fix compilation warning
i2c: mxs: Do not disable the I2C SMBus quick mode
i2c: mxs: Handle i2c DMA failure properly
i2c: s3c2410: Remove recently introduced performance overheads
i2c: ocores: Move grlib set/get functions into #ifdef CONFIG_OF block
i2c: s3c2410: Add fix for i2c suspend/resume
i2c: s3c2410: Fix code to free gpios
i2c: i2c-cbus-gpio: introduce driver
i2c: ocores: Add support for the GRLIB port of the controller and use function pointers for getreg and setreg functions
i2c: ocores: Add irq support for sparc
i2c: omap: Move the remove constraint
ARM: dts: cfa10049: Add the i2c muxer buses to the CFA-10049
i2c: s3c2410: do not special case HDMIPHY stuck bus detection
i2c: s3c2410: use exponential back off while polling for bus idle
i2c: s3c2410: do not generate STOP for QUIRK_HDMIPHY
i2c: s3c2410: grab adapter lock while changing i2c clock
i2c: s3c2410: Add support for pinctrl
...

+1483 -362
+27
Documentation/devicetree/bindings/i2c/i2c-cbus-gpio.txt
··· 1 + Device tree bindings for i2c-cbus-gpio driver 2 + 3 + Required properties: 4 + - compatible = "i2c-cbus-gpio"; 5 + - gpios: clk, dat, sel 6 + - #address-cells = <1>; 7 + - #size-cells = <0>; 8 + 9 + Optional properties: 10 + - child nodes conforming to i2c bus binding 11 + 12 + Example: 13 + 14 + i2c@0 { 15 + compatible = "i2c-cbus-gpio"; 16 + gpios = <&gpio 66 0 /* clk */ 17 + &gpio 65 0 /* dat */ 18 + &gpio 64 0 /* sel */ 19 + >; 20 + #address-cells = <1>; 21 + #size-cells = <0>; 22 + 23 + retu-mfd: retu@1 { 24 + compatible = "retu-mfd"; 25 + reg = <0x1>; 26 + }; 27 + };
+81
Documentation/devicetree/bindings/i2c/i2c-mux-gpio.txt
··· 1 + GPIO-based I2C Bus Mux 2 + 3 + This binding describes an I2C bus multiplexer that uses GPIOs to 4 + route the I2C signals. 5 + 6 + +-----+ +-----+ 7 + | dev | | dev | 8 + +------------+ +-----+ +-----+ 9 + | SoC | | | 10 + | | /--------+--------+ 11 + | +------+ | +------+ child bus A, on GPIO value set to 0 12 + | | I2C |-|--| Mux | 13 + | +------+ | +--+---+ child bus B, on GPIO value set to 1 14 + | | | \----------+--------+--------+ 15 + | +------+ | | | | | 16 + | | GPIO |-|-----+ +-----+ +-----+ +-----+ 17 + | +------+ | | dev | | dev | | dev | 18 + +------------+ +-----+ +-----+ +-----+ 19 + 20 + Required properties: 21 + - compatible: i2c-mux-gpio 22 + - i2c-parent: The phandle of the I2C bus that this multiplexer's master-side 23 + port is connected to. 24 + - mux-gpios: list of gpios used to control the muxer 25 + * Standard I2C mux properties. See mux.txt in this directory. 26 + * I2C child bus nodes. See mux.txt in this directory. 27 + 28 + Optional properties: 29 + - idle-state: value to set the muxer to when idle. When no value is 30 + given, it defaults to the last value used. 31 + 32 + For each i2c child node, an I2C child bus will be created. They will 33 + be numbered based on their order in the device tree. 34 + 35 + Whenever an access is made to a device on a child bus, the value set 36 + in the revelant node's reg property will be output using the list of 37 + GPIOs, the first in the list holding the least-significant value. 38 + 39 + If an idle state is defined, using the idle-state (optional) property, 40 + whenever an access is not being made to a device on a child bus, the 41 + GPIOs will be set according to the idle value. 42 + 43 + If an idle state is not defined, the most recently used value will be 44 + left programmed into hardware whenever no access is being made to a 45 + device on a child bus. 46 + 47 + Example: 48 + i2cmux { 49 + compatible = "i2c-mux-gpio"; 50 + #address-cells = <1>; 51 + #size-cells = <0>; 52 + mux-gpios = <&gpio1 22 0 &gpio1 23 0>; 53 + i2c-parent = <&i2c1>; 54 + 55 + i2c@1 { 56 + reg = <1>; 57 + #address-cells = <1>; 58 + #size-cells = <0>; 59 + 60 + ssd1307: oled@3c { 61 + compatible = "solomon,ssd1307fb-i2c"; 62 + reg = <0x3c>; 63 + pwms = <&pwm 4 3000>; 64 + reset-gpios = <&gpio2 7 1>; 65 + reset-active-low; 66 + }; 67 + }; 68 + 69 + i2c@3 { 70 + reg = <3>; 71 + #address-cells = <1>; 72 + #size-cells = <0>; 73 + 74 + pca9555: pca9555@20 { 75 + compatible = "nxp,pca9555"; 76 + gpio-controller; 77 + #gpio-cells = <2>; 78 + reg = <0x20>; 79 + }; 80 + }; 81 + };
+1 -1
Documentation/devicetree/bindings/i2c/i2c-ocores.txt
··· 1 1 Device tree configuration for i2c-ocores 2 2 3 3 Required properties: 4 - - compatible : "opencores,i2c-ocores" 4 + - compatible : "opencores,i2c-ocores" or "aeroflexgaisler,i2cmst" 5 5 - reg : bus address start and address range size of device 6 6 - interrupts : interrupt number 7 7 - clock-frequency : frequency of bus clock in Hz
+16 -4
Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt
··· 13 13 - interrupts: interrupt number to the cpu. 14 14 - samsung,i2c-sda-delay: Delay (in ns) applied to data line (SDA) edges. 15 15 16 + Required for all cases except "samsung,s3c2440-hdmiphy-i2c": 17 + - Samsung GPIO variant (deprecated): 18 + - gpios: The order of the gpios should be the following: <SDA, SCL>. 19 + The gpio specifier depends on the gpio controller. Required in all 20 + cases except for "samsung,s3c2440-hdmiphy-i2c" whose input/output 21 + lines are permanently wired to the respective clienta 22 + - Pinctrl variant (preferred, if available): 23 + - pinctrl-0: Pin control group to be used for this controller. 24 + - pinctrl-names: Should contain only one value - "default". 25 + 16 26 Optional properties: 17 - - gpios: The order of the gpios should be the following: <SDA, SCL>. 18 - The gpio specifier depends on the gpio controller. Required in all 19 - cases except for "samsung,s3c2440-hdmiphy-i2c" whose input/output 20 - lines are permanently wired to the respective client 21 27 - samsung,i2c-slave-addr: Slave address in multi-master enviroment. If not 22 28 specified, default value is 0. 23 29 - samsung,i2c-max-bus-freq: Desired frequency in Hz of the bus. If not ··· 37 31 interrupts = <345>; 38 32 samsung,i2c-sda-delay = <100>; 39 33 samsung,i2c-max-bus-freq = <100000>; 34 + /* Samsung GPIO variant begins here */ 40 35 gpios = <&gpd1 2 0 /* SDA */ 41 36 &gpd1 3 0 /* SCL */>; 37 + /* Samsung GPIO variant ends here */ 38 + /* Pinctrl variant begins here */ 39 + pinctrl-0 = <&i2c3_bus>; 40 + pinctrl-names = "default"; 41 + /* Pinctrl variant ends here */ 42 42 #address-cells = <1>; 43 43 #size-cells = <0>; 44 44
+24
arch/arm/boot/dts/imx28-cfa10049.dts
··· 92 92 status = "okay"; 93 93 }; 94 94 95 + i2cmux { 96 + compatible = "i2c-mux-gpio"; 97 + #address-cells = <1>; 98 + #size-cells = <0>; 99 + mux-gpios = <&gpio1 22 0 &gpio1 23 0>; 100 + i2c-parent = <&i2c1>; 101 + 102 + i2c@0 { 103 + reg = <0>; 104 + }; 105 + 106 + i2c@1 { 107 + reg = <1>; 108 + }; 109 + 110 + i2c@2 { 111 + reg = <2>; 112 + }; 113 + 114 + i2c@3 { 115 + reg = <3>; 116 + }; 117 + }; 118 + 95 119 usbphy1: usbphy@8007e000 { 96 120 status = "okay"; 97 121 };
+42
arch/arm/mach-omap2/board-n8x0.c
··· 16 16 #include <linux/gpio.h> 17 17 #include <linux/init.h> 18 18 #include <linux/io.h> 19 + #include <linux/irq.h> 19 20 #include <linux/stddef.h> 20 21 #include <linux/i2c.h> 21 22 #include <linux/spi/spi.h> 22 23 #include <linux/usb/musb.h> 24 + #include <linux/platform_data/i2c-cbus-gpio.h> 23 25 #include <linux/platform_data/spi-omap2-mcspi.h> 24 26 #include <linux/platform_data/mtd-onenand-omap2.h> 25 27 #include <linux/mfd/menelaus.h> ··· 41 39 #define TUSB6010_GPIO_INT 58 42 40 #define TUSB6010_GPIO_ENABLE 0 43 41 #define TUSB6010_DMACHAN 0x3f 42 + 43 + #if defined(CONFIG_I2C_CBUS_GPIO) || defined(CONFIG_I2C_CBUS_GPIO_MODULE) 44 + static struct i2c_cbus_platform_data n8x0_cbus_data = { 45 + .clk_gpio = 66, 46 + .dat_gpio = 65, 47 + .sel_gpio = 64, 48 + }; 49 + 50 + static struct platform_device n8x0_cbus_device = { 51 + .name = "i2c-cbus-gpio", 52 + .id = 3, 53 + .dev = { 54 + .platform_data = &n8x0_cbus_data, 55 + }, 56 + }; 57 + 58 + static struct i2c_board_info n8x0_i2c_board_info_3[] __initdata = { 59 + { 60 + I2C_BOARD_INFO("retu-mfd", 0x01), 61 + }, 62 + }; 63 + 64 + static void __init n8x0_cbus_init(void) 65 + { 66 + const int retu_irq_gpio = 108; 67 + 68 + if (gpio_request_one(retu_irq_gpio, GPIOF_IN, "Retu IRQ")) 69 + return; 70 + irq_set_irq_type(gpio_to_irq(retu_irq_gpio), IRQ_TYPE_EDGE_RISING); 71 + n8x0_i2c_board_info_3[0].irq = gpio_to_irq(retu_irq_gpio); 72 + i2c_register_board_info(3, n8x0_i2c_board_info_3, 73 + ARRAY_SIZE(n8x0_i2c_board_info_3)); 74 + platform_device_register(&n8x0_cbus_device); 75 + } 76 + #else /* CONFIG_I2C_CBUS_GPIO */ 77 + static void __init n8x0_cbus_init(void) 78 + { 79 + } 80 + #endif /* CONFIG_I2C_CBUS_GPIO */ 44 81 45 82 #if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_TUSB6010_MODULE) 46 83 /* ··· 719 678 gpmc_onenand_init(board_onenand_data); 720 679 n8x0_mmc_init(); 721 680 n8x0_usb_init(); 681 + n8x0_cbus_init(); 722 682 } 723 683 724 684 MACHINE_START(NOKIA_N800, "Nokia N800")
+19
arch/arm/mach-omap2/i2c.c
··· 120 120 return ports; 121 121 } 122 122 123 + /* 124 + * XXX This function is a temporary compatibility wrapper - only 125 + * needed until the I2C driver can be converted to call 126 + * omap_pm_set_max_dev_wakeup_lat() and handle a return code. 127 + */ 128 + static void omap_pm_set_max_mpu_wakeup_lat_compat(struct device *dev, long t) 129 + { 130 + omap_pm_set_max_mpu_wakeup_lat(dev, t); 131 + } 132 + 123 133 static const char name[] = "omap_i2c"; 124 134 125 135 int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata, ··· 167 157 dev_attr = (struct omap_i2c_dev_attr *)oh->dev_attr; 168 158 pdata->flags = dev_attr->flags; 169 159 160 + /* 161 + * When waiting for completion of a i2c transfer, we need to 162 + * set a wake up latency constraint for the MPU. This is to 163 + * ensure quick enough wakeup from idle, when transfer 164 + * completes. 165 + * Only omap3 has support for constraints 166 + */ 167 + if (cpu_is_omap34xx()) 168 + pdata->set_mpu_wkup_lat = omap_pm_set_max_mpu_wakeup_lat_compat; 170 169 pdev = omap_device_build(name, bus_id, oh, pdata, 171 170 sizeof(struct omap_i2c_bus_platform_data), 172 171 NULL, 0, 0);
+1 -2
arch/arm/mach-omap2/omap_hwmod_2430_data.c
··· 77 77 78 78 static struct omap_i2c_dev_attr i2c_dev_attr = { 79 79 .fifo_depth = 8, /* bytes */ 80 - .flags = OMAP_I2C_FLAG_APPLY_ERRATA_I207 | 81 - OMAP_I2C_FLAG_BUS_SHIFT_2 | 80 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_2 | 82 81 OMAP_I2C_FLAG_FORCE_19200_INT_CLK, 83 82 }; 84 83
+1 -2
arch/arm/mach-omap2/omap_hwmod_33xx_data.c
··· 1118 1118 }; 1119 1119 1120 1120 static struct omap_i2c_dev_attr i2c_dev_attr = { 1121 - .flags = OMAP_I2C_FLAG_BUS_SHIFT_NONE | 1122 - OMAP_I2C_FLAG_RESET_REGS_POSTIDLE, 1121 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_NONE, 1123 1122 }; 1124 1123 1125 1124 /* i2c1 */
+3 -9
arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
··· 794 794 /* I2C1 */ 795 795 static struct omap_i2c_dev_attr i2c1_dev_attr = { 796 796 .fifo_depth = 8, /* bytes */ 797 - .flags = OMAP_I2C_FLAG_APPLY_ERRATA_I207 | 798 - OMAP_I2C_FLAG_RESET_REGS_POSTIDLE | 799 - OMAP_I2C_FLAG_BUS_SHIFT_2, 797 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_2, 800 798 }; 801 799 802 800 static struct omap_hwmod omap3xxx_i2c1_hwmod = { ··· 819 821 /* I2C2 */ 820 822 static struct omap_i2c_dev_attr i2c2_dev_attr = { 821 823 .fifo_depth = 8, /* bytes */ 822 - .flags = OMAP_I2C_FLAG_APPLY_ERRATA_I207 | 823 - OMAP_I2C_FLAG_RESET_REGS_POSTIDLE | 824 - OMAP_I2C_FLAG_BUS_SHIFT_2, 824 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_2, 825 825 }; 826 826 827 827 static struct omap_hwmod omap3xxx_i2c2_hwmod = { ··· 844 848 /* I2C3 */ 845 849 static struct omap_i2c_dev_attr i2c3_dev_attr = { 846 850 .fifo_depth = 64, /* bytes */ 847 - .flags = OMAP_I2C_FLAG_APPLY_ERRATA_I207 | 848 - OMAP_I2C_FLAG_RESET_REGS_POSTIDLE | 849 - OMAP_I2C_FLAG_BUS_SHIFT_2, 851 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_2, 850 852 }; 851 853 852 854 static struct omap_hwmod_irq_info i2c3_mpu_irqs[] = {
+1 -2
arch/arm/mach-omap2/omap_hwmod_44xx_data.c
··· 1529 1529 }; 1530 1530 1531 1531 static struct omap_i2c_dev_attr i2c_dev_attr = { 1532 - .flags = OMAP_I2C_FLAG_BUS_SHIFT_NONE | 1533 - OMAP_I2C_FLAG_RESET_REGS_POSTIDLE, 1532 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_NONE, 1534 1533 }; 1535 1534 1536 1535 /* i2c1 */
+10
drivers/i2c/busses/Kconfig
··· 337 337 help 338 338 The unit of the TWI clock is kHz. 339 339 340 + config I2C_CBUS_GPIO 341 + tristate "CBUS I2C driver" 342 + depends on GENERIC_GPIO 343 + help 344 + Support for CBUS access using I2C API. Mostly relevant for Nokia 345 + Internet Tablets (770, N800 and N810). 346 + 347 + This driver can also be built as a module. If so, the module 348 + will be called i2c-cbus-gpio. 349 + 340 350 config I2C_CPM 341 351 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)" 342 352 depends on (CPM1 || CPM2) && OF_I2C
+1
drivers/i2c/busses/Makefile
··· 31 31 obj-$(CONFIG_I2C_AT91) += i2c-at91.o 32 32 obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 33 33 obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o 34 + obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o 34 35 obj-$(CONFIG_I2C_CPM) += i2c-cpm.o 35 36 obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o 36 37 obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o
+314 -24
drivers/i2c/busses/i2c-at91.c
··· 19 19 20 20 #include <linux/clk.h> 21 21 #include <linux/completion.h> 22 + #include <linux/dma-mapping.h> 23 + #include <linux/dmaengine.h> 22 24 #include <linux/err.h> 23 25 #include <linux/i2c.h> 24 26 #include <linux/interrupt.h> ··· 31 29 #include <linux/of_i2c.h> 32 30 #include <linux/platform_device.h> 33 31 #include <linux/slab.h> 32 + #include <linux/platform_data/dma-atmel.h> 34 33 35 34 #define TWI_CLK_HZ 100000 /* max 400 Kbits/s */ 36 35 #define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ 36 + #define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */ 37 37 38 38 /* AT91 TWI register definitions */ 39 39 #define AT91_TWI_CR 0x0000 /* Control Register */ ··· 70 66 #define AT91_TWI_THR 0x0034 /* Transmit Holding Register */ 71 67 72 68 struct at91_twi_pdata { 73 - unsigned clk_max_div; 74 - unsigned clk_offset; 75 - bool has_unre_flag; 69 + unsigned clk_max_div; 70 + unsigned clk_offset; 71 + bool has_unre_flag; 72 + bool has_dma_support; 73 + struct at_dma_slave dma_slave; 74 + }; 75 + 76 + struct at91_twi_dma { 77 + struct dma_chan *chan_rx; 78 + struct dma_chan *chan_tx; 79 + struct scatterlist sg; 80 + struct dma_async_tx_descriptor *data_desc; 81 + enum dma_data_direction direction; 82 + bool buf_mapped; 83 + bool xfer_in_progress; 76 84 }; 77 85 78 86 struct at91_twi_dev { 79 - struct device *dev; 80 - void __iomem *base; 81 - struct completion cmd_complete; 82 - struct clk *clk; 83 - u8 *buf; 84 - size_t buf_len; 85 - struct i2c_msg *msg; 86 - int irq; 87 - unsigned transfer_status; 88 - struct i2c_adapter adapter; 89 - unsigned twi_cwgr_reg; 90 - struct at91_twi_pdata *pdata; 87 + struct device *dev; 88 + void __iomem *base; 89 + struct completion cmd_complete; 90 + struct clk *clk; 91 + u8 *buf; 92 + size_t buf_len; 93 + struct i2c_msg *msg; 94 + int irq; 95 + unsigned imr; 96 + unsigned transfer_status; 97 + struct i2c_adapter adapter; 98 + unsigned twi_cwgr_reg; 99 + struct at91_twi_pdata *pdata; 100 + bool use_dma; 101 + struct at91_twi_dma dma; 91 102 }; 92 103 93 104 static unsigned at91_twi_read(struct at91_twi_dev *dev, unsigned reg) ··· 119 100 { 120 101 at91_twi_write(dev, AT91_TWI_IDR, 121 102 AT91_TWI_TXCOMP | AT91_TWI_RXRDY | AT91_TWI_TXRDY); 103 + } 104 + 105 + static void at91_twi_irq_save(struct at91_twi_dev *dev) 106 + { 107 + dev->imr = at91_twi_read(dev, AT91_TWI_IMR) & 0x7; 108 + at91_disable_twi_interrupts(dev); 109 + } 110 + 111 + static void at91_twi_irq_restore(struct at91_twi_dev *dev) 112 + { 113 + at91_twi_write(dev, AT91_TWI_IER, dev->imr); 122 114 } 123 115 124 116 static void at91_init_twi_bus(struct at91_twi_dev *dev) ··· 168 138 dev_dbg(dev->dev, "cdiv %d ckdiv %d\n", cdiv, ckdiv); 169 139 } 170 140 141 + static void at91_twi_dma_cleanup(struct at91_twi_dev *dev) 142 + { 143 + struct at91_twi_dma *dma = &dev->dma; 144 + 145 + at91_twi_irq_save(dev); 146 + 147 + if (dma->xfer_in_progress) { 148 + if (dma->direction == DMA_FROM_DEVICE) 149 + dmaengine_terminate_all(dma->chan_rx); 150 + else 151 + dmaengine_terminate_all(dma->chan_tx); 152 + dma->xfer_in_progress = false; 153 + } 154 + if (dma->buf_mapped) { 155 + dma_unmap_single(dev->dev, sg_dma_address(&dma->sg), 156 + dev->buf_len, dma->direction); 157 + dma->buf_mapped = false; 158 + } 159 + 160 + at91_twi_irq_restore(dev); 161 + } 162 + 171 163 static void at91_twi_write_next_byte(struct at91_twi_dev *dev) 172 164 { 173 165 if (dev->buf_len <= 0) ··· 204 152 dev_dbg(dev->dev, "wrote 0x%x, to go %d\n", *dev->buf, dev->buf_len); 205 153 206 154 ++dev->buf; 155 + } 156 + 157 + static void at91_twi_write_data_dma_callback(void *data) 158 + { 159 + struct at91_twi_dev *dev = (struct at91_twi_dev *)data; 160 + 161 + dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg), 162 + dev->buf_len, DMA_MEM_TO_DEV); 163 + 164 + at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); 165 + } 166 + 167 + static void at91_twi_write_data_dma(struct at91_twi_dev *dev) 168 + { 169 + dma_addr_t dma_addr; 170 + struct dma_async_tx_descriptor *txdesc; 171 + struct at91_twi_dma *dma = &dev->dma; 172 + struct dma_chan *chan_tx = dma->chan_tx; 173 + 174 + if (dev->buf_len <= 0) 175 + return; 176 + 177 + dma->direction = DMA_TO_DEVICE; 178 + 179 + at91_twi_irq_save(dev); 180 + dma_addr = dma_map_single(dev->dev, dev->buf, dev->buf_len, 181 + DMA_TO_DEVICE); 182 + if (dma_mapping_error(dev->dev, dma_addr)) { 183 + dev_err(dev->dev, "dma map failed\n"); 184 + return; 185 + } 186 + dma->buf_mapped = true; 187 + at91_twi_irq_restore(dev); 188 + sg_dma_len(&dma->sg) = dev->buf_len; 189 + sg_dma_address(&dma->sg) = dma_addr; 190 + 191 + txdesc = dmaengine_prep_slave_sg(chan_tx, &dma->sg, 1, DMA_MEM_TO_DEV, 192 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 193 + if (!txdesc) { 194 + dev_err(dev->dev, "dma prep slave sg failed\n"); 195 + goto error; 196 + } 197 + 198 + txdesc->callback = at91_twi_write_data_dma_callback; 199 + txdesc->callback_param = dev; 200 + 201 + dma->xfer_in_progress = true; 202 + dmaengine_submit(txdesc); 203 + dma_async_issue_pending(chan_tx); 204 + 205 + return; 206 + 207 + error: 208 + at91_twi_dma_cleanup(dev); 207 209 } 208 210 209 211 static void at91_twi_read_next_byte(struct at91_twi_dev *dev) ··· 283 177 dev_dbg(dev->dev, "read 0x%x, to go %d\n", *dev->buf, dev->buf_len); 284 178 285 179 ++dev->buf; 180 + } 181 + 182 + static void at91_twi_read_data_dma_callback(void *data) 183 + { 184 + struct at91_twi_dev *dev = (struct at91_twi_dev *)data; 185 + 186 + dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg), 187 + dev->buf_len, DMA_DEV_TO_MEM); 188 + 189 + /* The last two bytes have to be read without using dma */ 190 + dev->buf += dev->buf_len - 2; 191 + dev->buf_len = 2; 192 + at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_RXRDY); 193 + } 194 + 195 + static void at91_twi_read_data_dma(struct at91_twi_dev *dev) 196 + { 197 + dma_addr_t dma_addr; 198 + struct dma_async_tx_descriptor *rxdesc; 199 + struct at91_twi_dma *dma = &dev->dma; 200 + struct dma_chan *chan_rx = dma->chan_rx; 201 + 202 + dma->direction = DMA_FROM_DEVICE; 203 + 204 + /* Keep in mind that we won't use dma to read the last two bytes */ 205 + at91_twi_irq_save(dev); 206 + dma_addr = dma_map_single(dev->dev, dev->buf, dev->buf_len - 2, 207 + DMA_FROM_DEVICE); 208 + if (dma_mapping_error(dev->dev, dma_addr)) { 209 + dev_err(dev->dev, "dma map failed\n"); 210 + return; 211 + } 212 + dma->buf_mapped = true; 213 + at91_twi_irq_restore(dev); 214 + dma->sg.dma_address = dma_addr; 215 + sg_dma_len(&dma->sg) = dev->buf_len - 2; 216 + 217 + rxdesc = dmaengine_prep_slave_sg(chan_rx, &dma->sg, 1, DMA_DEV_TO_MEM, 218 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 219 + if (!rxdesc) { 220 + dev_err(dev->dev, "dma prep slave sg failed\n"); 221 + goto error; 222 + } 223 + 224 + rxdesc->callback = at91_twi_read_data_dma_callback; 225 + rxdesc->callback_param = dev; 226 + 227 + dma->xfer_in_progress = true; 228 + dmaengine_submit(rxdesc); 229 + dma_async_issue_pending(dma->chan_rx); 230 + 231 + return; 232 + 233 + error: 234 + at91_twi_dma_cleanup(dev); 286 235 } 287 236 288 237 static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) ··· 390 229 if (dev->buf_len <= 1 && !(dev->msg->flags & I2C_M_RECV_LEN)) 391 230 start_flags |= AT91_TWI_STOP; 392 231 at91_twi_write(dev, AT91_TWI_CR, start_flags); 393 - at91_twi_write(dev, AT91_TWI_IER, 232 + /* 233 + * When using dma, the last byte has to be read manually in 234 + * order to not send the stop command too late and then 235 + * to receive extra data. In practice, there are some issues 236 + * if you use the dma to read n-1 bytes because of latency. 237 + * Reading n-2 bytes with dma and the two last ones manually 238 + * seems to be the best solution. 239 + */ 240 + if (dev->use_dma && (dev->buf_len > AT91_I2C_DMA_THRESHOLD)) { 241 + at91_twi_read_data_dma(dev); 242 + /* 243 + * It is important to enable TXCOMP irq here because 244 + * doing it only when transferring the last two bytes 245 + * will mask NACK errors since TXCOMP is set when a 246 + * NACK occurs. 247 + */ 248 + at91_twi_write(dev, AT91_TWI_IER, 249 + AT91_TWI_TXCOMP); 250 + } else 251 + at91_twi_write(dev, AT91_TWI_IER, 394 252 AT91_TWI_TXCOMP | AT91_TWI_RXRDY); 395 253 } else { 396 - at91_twi_write_next_byte(dev); 397 - at91_twi_write(dev, AT91_TWI_IER, 398 - AT91_TWI_TXCOMP | AT91_TWI_TXRDY); 254 + if (dev->use_dma && (dev->buf_len > AT91_I2C_DMA_THRESHOLD)) { 255 + at91_twi_write_data_dma(dev); 256 + at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP); 257 + } else { 258 + at91_twi_write_next_byte(dev); 259 + at91_twi_write(dev, AT91_TWI_IER, 260 + AT91_TWI_TXCOMP | AT91_TWI_TXRDY); 261 + } 399 262 } 400 263 401 264 ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, ··· 427 242 if (ret == 0) { 428 243 dev_err(dev->dev, "controller timed out\n"); 429 244 at91_init_twi_bus(dev); 430 - return -ETIMEDOUT; 245 + ret = -ETIMEDOUT; 246 + goto error; 431 247 } 432 248 if (dev->transfer_status & AT91_TWI_NACK) { 433 249 dev_dbg(dev->dev, "received nack\n"); 434 - return -EREMOTEIO; 250 + ret = -EREMOTEIO; 251 + goto error; 435 252 } 436 253 if (dev->transfer_status & AT91_TWI_OVRE) { 437 254 dev_err(dev->dev, "overrun while reading\n"); 438 - return -EIO; 255 + ret = -EIO; 256 + goto error; 439 257 } 440 258 if (has_unre_flag && dev->transfer_status & AT91_TWI_UNRE) { 441 259 dev_err(dev->dev, "underrun while writing\n"); 442 - return -EIO; 260 + ret = -EIO; 261 + goto error; 443 262 } 444 263 dev_dbg(dev->dev, "transfer complete\n"); 445 264 446 265 return 0; 266 + 267 + error: 268 + at91_twi_dma_cleanup(dev); 269 + return ret; 447 270 } 448 271 449 272 static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num) ··· 522 329 .clk_max_div = 5, 523 330 .clk_offset = 3, 524 331 .has_unre_flag = true, 332 + .has_dma_support = false, 525 333 }; 526 334 527 335 static struct at91_twi_pdata at91sam9261_config = { 528 336 .clk_max_div = 5, 529 337 .clk_offset = 4, 530 338 .has_unre_flag = false, 339 + .has_dma_support = false, 531 340 }; 532 341 533 342 static struct at91_twi_pdata at91sam9260_config = { 534 343 .clk_max_div = 7, 535 344 .clk_offset = 4, 536 345 .has_unre_flag = false, 346 + .has_dma_support = false, 537 347 }; 538 348 539 349 static struct at91_twi_pdata at91sam9g20_config = { 540 350 .clk_max_div = 7, 541 351 .clk_offset = 4, 542 352 .has_unre_flag = false, 353 + .has_dma_support = false, 543 354 }; 544 355 545 356 static struct at91_twi_pdata at91sam9g10_config = { 546 357 .clk_max_div = 7, 547 358 .clk_offset = 4, 548 359 .has_unre_flag = false, 360 + .has_dma_support = false, 549 361 }; 550 362 551 363 static struct at91_twi_pdata at91sam9x5_config = { 552 364 .clk_max_div = 7, 553 365 .clk_offset = 4, 554 366 .has_unre_flag = false, 367 + .has_dma_support = true, 555 368 }; 556 369 557 370 static const struct platform_device_id at91_twi_devtypes[] = { ··· 604 405 #define atmel_twi_dt_ids NULL 605 406 #endif 606 407 408 + static bool __devinit filter(struct dma_chan *chan, void *slave) 409 + { 410 + struct at_dma_slave *sl = slave; 411 + 412 + if (sl->dma_dev == chan->device->dev) { 413 + chan->private = sl; 414 + return true; 415 + } else { 416 + return false; 417 + } 418 + } 419 + 420 + static int __devinit at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr) 421 + { 422 + int ret = 0; 423 + struct at_dma_slave *sdata; 424 + struct dma_slave_config slave_config; 425 + struct at91_twi_dma *dma = &dev->dma; 426 + 427 + sdata = &dev->pdata->dma_slave; 428 + 429 + memset(&slave_config, 0, sizeof(slave_config)); 430 + slave_config.src_addr = (dma_addr_t)phy_addr + AT91_TWI_RHR; 431 + slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 432 + slave_config.src_maxburst = 1; 433 + slave_config.dst_addr = (dma_addr_t)phy_addr + AT91_TWI_THR; 434 + slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 435 + slave_config.dst_maxburst = 1; 436 + slave_config.device_fc = false; 437 + 438 + if (sdata && sdata->dma_dev) { 439 + dma_cap_mask_t mask; 440 + 441 + dma_cap_zero(mask); 442 + dma_cap_set(DMA_SLAVE, mask); 443 + dma->chan_tx = dma_request_channel(mask, filter, sdata); 444 + if (!dma->chan_tx) { 445 + dev_err(dev->dev, "no DMA channel available for tx\n"); 446 + ret = -EBUSY; 447 + goto error; 448 + } 449 + dma->chan_rx = dma_request_channel(mask, filter, sdata); 450 + if (!dma->chan_rx) { 451 + dev_err(dev->dev, "no DMA channel available for rx\n"); 452 + ret = -EBUSY; 453 + goto error; 454 + } 455 + } else { 456 + ret = -EINVAL; 457 + goto error; 458 + } 459 + 460 + slave_config.direction = DMA_MEM_TO_DEV; 461 + if (dmaengine_slave_config(dma->chan_tx, &slave_config)) { 462 + dev_err(dev->dev, "failed to configure tx channel\n"); 463 + ret = -EINVAL; 464 + goto error; 465 + } 466 + 467 + slave_config.direction = DMA_DEV_TO_MEM; 468 + if (dmaengine_slave_config(dma->chan_rx, &slave_config)) { 469 + dev_err(dev->dev, "failed to configure rx channel\n"); 470 + ret = -EINVAL; 471 + goto error; 472 + } 473 + 474 + sg_init_table(&dma->sg, 1); 475 + dma->buf_mapped = false; 476 + dma->xfer_in_progress = false; 477 + 478 + dev_info(dev->dev, "using %s (tx) and %s (rx) for DMA transfers\n", 479 + dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); 480 + 481 + return ret; 482 + 483 + error: 484 + dev_info(dev->dev, "can't use DMA\n"); 485 + if (dma->chan_rx) 486 + dma_release_channel(dma->chan_rx); 487 + if (dma->chan_tx) 488 + dma_release_channel(dma->chan_tx); 489 + return ret; 490 + } 491 + 607 492 static struct at91_twi_pdata * __devinit at91_twi_get_driver_data( 608 493 struct platform_device *pdev) 609 494 { ··· 696 413 match = of_match_node(atmel_twi_dt_ids, pdev->dev.of_node); 697 414 if (!match) 698 415 return NULL; 699 - return match->data; 416 + return (struct at91_twi_pdata *)match->data; 700 417 } 701 418 return (struct at91_twi_pdata *) platform_get_device_id(pdev)->driver_data; 702 419 } ··· 706 423 struct at91_twi_dev *dev; 707 424 struct resource *mem; 708 425 int rc; 426 + u32 phy_addr; 709 427 710 428 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 711 429 if (!dev) ··· 717 433 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 718 434 if (!mem) 719 435 return -ENODEV; 436 + phy_addr = mem->start; 720 437 721 438 dev->pdata = at91_twi_get_driver_data(pdev); 722 439 if (!dev->pdata) ··· 746 461 return -ENODEV; 747 462 } 748 463 clk_prepare_enable(dev->clk); 464 + 465 + if (dev->pdata->has_dma_support) { 466 + if (at91_twi_configure_dma(dev, phy_addr) == 0) 467 + dev->use_dma = true; 468 + } 749 469 750 470 at91_calc_twi_clock(dev, TWI_CLK_HZ); 751 471 at91_init_twi_bus(dev);
+300
drivers/i2c/busses/i2c-cbus-gpio.c
··· 1 + /* 2 + * CBUS I2C driver for Nokia Internet Tablets. 3 + * 4 + * Copyright (C) 2004-2010 Nokia Corporation 5 + * 6 + * Based on code written by Juha Yrjölä, David Weinehall, Mikko Ylinen and 7 + * Felipe Balbi. Converted to I2C driver by Aaro Koskinen. 8 + * 9 + * This file is subject to the terms and conditions of the GNU General 10 + * Public License. See the file "COPYING" in the main directory of this 11 + * archive for more details. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + */ 18 + 19 + #include <linux/io.h> 20 + #include <linux/i2c.h> 21 + #include <linux/gpio.h> 22 + #include <linux/init.h> 23 + #include <linux/slab.h> 24 + #include <linux/delay.h> 25 + #include <linux/errno.h> 26 + #include <linux/kernel.h> 27 + #include <linux/module.h> 28 + #include <linux/of_gpio.h> 29 + #include <linux/interrupt.h> 30 + #include <linux/platform_device.h> 31 + #include <linux/platform_data/i2c-cbus-gpio.h> 32 + 33 + /* 34 + * Bit counts are derived from Nokia implementation. These should be checked 35 + * if other CBUS implementations appear. 36 + */ 37 + #define CBUS_ADDR_BITS 3 38 + #define CBUS_REG_BITS 5 39 + 40 + struct cbus_host { 41 + spinlock_t lock; /* host lock */ 42 + struct device *dev; 43 + int clk_gpio; 44 + int dat_gpio; 45 + int sel_gpio; 46 + }; 47 + 48 + /** 49 + * cbus_send_bit - sends one bit over the bus 50 + * @host: the host we're using 51 + * @bit: one bit of information to send 52 + */ 53 + static void cbus_send_bit(struct cbus_host *host, unsigned bit) 54 + { 55 + gpio_set_value(host->dat_gpio, bit ? 1 : 0); 56 + gpio_set_value(host->clk_gpio, 1); 57 + gpio_set_value(host->clk_gpio, 0); 58 + } 59 + 60 + /** 61 + * cbus_send_data - sends @len amount of data over the bus 62 + * @host: the host we're using 63 + * @data: the data to send 64 + * @len: size of the transfer 65 + */ 66 + static void cbus_send_data(struct cbus_host *host, unsigned data, unsigned len) 67 + { 68 + int i; 69 + 70 + for (i = len; i > 0; i--) 71 + cbus_send_bit(host, data & (1 << (i - 1))); 72 + } 73 + 74 + /** 75 + * cbus_receive_bit - receives one bit from the bus 76 + * @host: the host we're using 77 + */ 78 + static int cbus_receive_bit(struct cbus_host *host) 79 + { 80 + int ret; 81 + 82 + gpio_set_value(host->clk_gpio, 1); 83 + ret = gpio_get_value(host->dat_gpio); 84 + gpio_set_value(host->clk_gpio, 0); 85 + return ret; 86 + } 87 + 88 + /** 89 + * cbus_receive_word - receives 16-bit word from the bus 90 + * @host: the host we're using 91 + */ 92 + static int cbus_receive_word(struct cbus_host *host) 93 + { 94 + int ret = 0; 95 + int i; 96 + 97 + for (i = 16; i > 0; i--) { 98 + int bit = cbus_receive_bit(host); 99 + 100 + if (bit < 0) 101 + return bit; 102 + 103 + if (bit) 104 + ret |= 1 << (i - 1); 105 + } 106 + return ret; 107 + } 108 + 109 + /** 110 + * cbus_transfer - transfers data over the bus 111 + * @host: the host we're using 112 + * @rw: read/write flag 113 + * @dev: device address 114 + * @reg: register address 115 + * @data: if @rw == I2C_SBUS_WRITE data to send otherwise 0 116 + */ 117 + static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev, 118 + unsigned reg, unsigned data) 119 + { 120 + unsigned long flags; 121 + int ret; 122 + 123 + /* We don't want interrupts disturbing our transfer */ 124 + spin_lock_irqsave(&host->lock, flags); 125 + 126 + /* Reset state and start of transfer, SEL stays down during transfer */ 127 + gpio_set_value(host->sel_gpio, 0); 128 + 129 + /* Set the DAT pin to output */ 130 + gpio_direction_output(host->dat_gpio, 1); 131 + 132 + /* Send the device address */ 133 + cbus_send_data(host, dev, CBUS_ADDR_BITS); 134 + 135 + /* Send the rw flag */ 136 + cbus_send_bit(host, rw == I2C_SMBUS_READ); 137 + 138 + /* Send the register address */ 139 + cbus_send_data(host, reg, CBUS_REG_BITS); 140 + 141 + if (rw == I2C_SMBUS_WRITE) { 142 + cbus_send_data(host, data, 16); 143 + ret = 0; 144 + } else { 145 + ret = gpio_direction_input(host->dat_gpio); 146 + if (ret) { 147 + dev_dbg(host->dev, "failed setting direction\n"); 148 + goto out; 149 + } 150 + gpio_set_value(host->clk_gpio, 1); 151 + 152 + ret = cbus_receive_word(host); 153 + if (ret < 0) { 154 + dev_dbg(host->dev, "failed receiving data\n"); 155 + goto out; 156 + } 157 + } 158 + 159 + /* Indicate end of transfer, SEL goes up until next transfer */ 160 + gpio_set_value(host->sel_gpio, 1); 161 + gpio_set_value(host->clk_gpio, 1); 162 + gpio_set_value(host->clk_gpio, 0); 163 + 164 + out: 165 + spin_unlock_irqrestore(&host->lock, flags); 166 + 167 + return ret; 168 + } 169 + 170 + static int cbus_i2c_smbus_xfer(struct i2c_adapter *adapter, 171 + u16 addr, 172 + unsigned short flags, 173 + char read_write, 174 + u8 command, 175 + int size, 176 + union i2c_smbus_data *data) 177 + { 178 + struct cbus_host *chost = i2c_get_adapdata(adapter); 179 + int ret; 180 + 181 + if (size != I2C_SMBUS_WORD_DATA) 182 + return -EINVAL; 183 + 184 + ret = cbus_transfer(chost, read_write == I2C_SMBUS_READ, addr, 185 + command, data->word); 186 + if (ret < 0) 187 + return ret; 188 + 189 + if (read_write == I2C_SMBUS_READ) 190 + data->word = ret; 191 + 192 + return 0; 193 + } 194 + 195 + static u32 cbus_i2c_func(struct i2c_adapter *adapter) 196 + { 197 + return I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA; 198 + } 199 + 200 + static const struct i2c_algorithm cbus_i2c_algo = { 201 + .smbus_xfer = cbus_i2c_smbus_xfer, 202 + .functionality = cbus_i2c_func, 203 + }; 204 + 205 + static int cbus_i2c_remove(struct platform_device *pdev) 206 + { 207 + struct i2c_adapter *adapter = platform_get_drvdata(pdev); 208 + 209 + return i2c_del_adapter(adapter); 210 + } 211 + 212 + static int cbus_i2c_probe(struct platform_device *pdev) 213 + { 214 + struct i2c_adapter *adapter; 215 + struct cbus_host *chost; 216 + int ret; 217 + 218 + adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), 219 + GFP_KERNEL); 220 + if (!adapter) 221 + return -ENOMEM; 222 + 223 + chost = devm_kzalloc(&pdev->dev, sizeof(*chost), GFP_KERNEL); 224 + if (!chost) 225 + return -ENOMEM; 226 + 227 + if (pdev->dev.of_node) { 228 + struct device_node *dnode = pdev->dev.of_node; 229 + if (of_gpio_count(dnode) != 3) 230 + return -ENODEV; 231 + chost->clk_gpio = of_get_gpio(dnode, 0); 232 + chost->dat_gpio = of_get_gpio(dnode, 1); 233 + chost->sel_gpio = of_get_gpio(dnode, 2); 234 + } else if (pdev->dev.platform_data) { 235 + struct i2c_cbus_platform_data *pdata = pdev->dev.platform_data; 236 + chost->clk_gpio = pdata->clk_gpio; 237 + chost->dat_gpio = pdata->dat_gpio; 238 + chost->sel_gpio = pdata->sel_gpio; 239 + } else { 240 + return -ENODEV; 241 + } 242 + 243 + adapter->owner = THIS_MODULE; 244 + adapter->class = I2C_CLASS_HWMON; 245 + adapter->dev.parent = &pdev->dev; 246 + adapter->nr = pdev->id; 247 + adapter->timeout = HZ; 248 + adapter->algo = &cbus_i2c_algo; 249 + strlcpy(adapter->name, "CBUS I2C adapter", sizeof(adapter->name)); 250 + 251 + spin_lock_init(&chost->lock); 252 + chost->dev = &pdev->dev; 253 + 254 + ret = devm_gpio_request_one(&pdev->dev, chost->clk_gpio, 255 + GPIOF_OUT_INIT_LOW, "CBUS clk"); 256 + if (ret) 257 + return ret; 258 + 259 + ret = devm_gpio_request_one(&pdev->dev, chost->dat_gpio, GPIOF_IN, 260 + "CBUS data"); 261 + if (ret) 262 + return ret; 263 + 264 + ret = devm_gpio_request_one(&pdev->dev, chost->sel_gpio, 265 + GPIOF_OUT_INIT_HIGH, "CBUS sel"); 266 + if (ret) 267 + return ret; 268 + 269 + i2c_set_adapdata(adapter, chost); 270 + platform_set_drvdata(pdev, adapter); 271 + 272 + return i2c_add_numbered_adapter(adapter); 273 + } 274 + 275 + #if defined(CONFIG_OF) 276 + static const struct of_device_id i2c_cbus_dt_ids[] = { 277 + { .compatible = "i2c-cbus-gpio", }, 278 + { } 279 + }; 280 + MODULE_DEVICE_TABLE(of, i2c_cbus_dt_ids); 281 + #endif 282 + 283 + static struct platform_driver cbus_i2c_driver = { 284 + .probe = cbus_i2c_probe, 285 + .remove = cbus_i2c_remove, 286 + .driver = { 287 + .owner = THIS_MODULE, 288 + .name = "i2c-cbus-gpio", 289 + }, 290 + }; 291 + module_platform_driver(cbus_i2c_driver); 292 + 293 + MODULE_ALIAS("platform:i2c-cbus-gpio"); 294 + MODULE_DESCRIPTION("CBUS I2C driver"); 295 + MODULE_AUTHOR("Juha Yrjölä"); 296 + MODULE_AUTHOR("David Weinehall"); 297 + MODULE_AUTHOR("Mikko Ylinen"); 298 + MODULE_AUTHOR("Felipe Balbi"); 299 + MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>"); 300 + MODULE_LICENSE("GPL");
+5 -1
drivers/i2c/busses/i2c-gpio.c
··· 184 184 bit_data->data = pdata; 185 185 186 186 adap->owner = THIS_MODULE; 187 - snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 187 + if (pdev->dev.of_node) 188 + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); 189 + else 190 + snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 191 + 188 192 adap->algo_data = bit_data; 189 193 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 190 194 adap->dev.parent = &pdev->dev;
+1 -1
drivers/i2c/busses/i2c-mxs.c
··· 359 359 360 360 static u32 mxs_i2c_func(struct i2c_adapter *adap) 361 361 { 362 - return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); 362 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 363 363 } 364 364 365 365 static irqreturn_t mxs_i2c_isr(int this_irq, void *dev_id)
-14
drivers/i2c/busses/i2c-nomadik.c
··· 435 435 timeout = wait_for_completion_timeout( 436 436 &dev->xfer_complete, dev->adap.timeout); 437 437 438 - if (timeout < 0) { 439 - dev_err(&dev->adev->dev, 440 - "wait_for_completion_timeout " 441 - "returned %d waiting for event\n", timeout); 442 - status = timeout; 443 - } 444 - 445 438 if (timeout == 0) { 446 439 /* Controller timed out */ 447 440 dev_err(&dev->adev->dev, "read from slave 0x%x timed out\n", ··· 515 522 516 523 timeout = wait_for_completion_timeout( 517 524 &dev->xfer_complete, dev->adap.timeout); 518 - 519 - if (timeout < 0) { 520 - dev_err(&dev->adev->dev, 521 - "wait_for_completion_timeout " 522 - "returned %d waiting for event\n", timeout); 523 - status = timeout; 524 - } 525 525 526 526 if (timeout == 0) { 527 527 /* Controller timed out */
+129 -35
drivers/i2c/busses/i2c-ocores.c
··· 4 4 * 5 5 * Peter Korsgaard <jacmet@sunsite.dk> 6 6 * 7 + * Support for the GRLIB port of the controller by 8 + * Andreas Larsson <andreas@gaisler.com> 9 + * 7 10 * This file is licensed under the terms of the GNU General Public License 8 11 * version 2. This program is licensed "as is" without any warranty of any 9 12 * kind, whether express or implied. ··· 37 34 int nmsgs; 38 35 int state; /* see STATE_ */ 39 36 int clock_khz; 37 + void (*setreg)(struct ocores_i2c *i2c, int reg, u8 value); 38 + u8 (*getreg)(struct ocores_i2c *i2c, int reg); 40 39 }; 41 40 42 41 /* registers */ ··· 72 67 #define STATE_READ 3 73 68 #define STATE_ERROR 4 74 69 70 + #define TYPE_OCORES 0 71 + #define TYPE_GRLIB 1 72 + 73 + static void oc_setreg_8(struct ocores_i2c *i2c, int reg, u8 value) 74 + { 75 + iowrite8(value, i2c->base + (reg << i2c->reg_shift)); 76 + } 77 + 78 + static void oc_setreg_16(struct ocores_i2c *i2c, int reg, u8 value) 79 + { 80 + iowrite16(value, i2c->base + (reg << i2c->reg_shift)); 81 + } 82 + 83 + static void oc_setreg_32(struct ocores_i2c *i2c, int reg, u8 value) 84 + { 85 + iowrite32(value, i2c->base + (reg << i2c->reg_shift)); 86 + } 87 + 88 + static inline u8 oc_getreg_8(struct ocores_i2c *i2c, int reg) 89 + { 90 + return ioread8(i2c->base + (reg << i2c->reg_shift)); 91 + } 92 + 93 + static inline u8 oc_getreg_16(struct ocores_i2c *i2c, int reg) 94 + { 95 + return ioread16(i2c->base + (reg << i2c->reg_shift)); 96 + } 97 + 98 + static inline u8 oc_getreg_32(struct ocores_i2c *i2c, int reg) 99 + { 100 + return ioread32(i2c->base + (reg << i2c->reg_shift)); 101 + } 102 + 75 103 static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) 76 104 { 77 - if (i2c->reg_io_width == 4) 78 - iowrite32(value, i2c->base + (reg << i2c->reg_shift)); 79 - else if (i2c->reg_io_width == 2) 80 - iowrite16(value, i2c->base + (reg << i2c->reg_shift)); 81 - else 82 - iowrite8(value, i2c->base + (reg << i2c->reg_shift)); 105 + i2c->setreg(i2c, reg, value); 83 106 } 84 107 85 108 static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg) 86 109 { 87 - if (i2c->reg_io_width == 4) 88 - return ioread32(i2c->base + (reg << i2c->reg_shift)); 89 - else if (i2c->reg_io_width == 2) 90 - return ioread16(i2c->base + (reg << i2c->reg_shift)); 91 - else 92 - return ioread8(i2c->base + (reg << i2c->reg_shift)); 110 + return i2c->getreg(i2c, reg); 93 111 } 94 112 95 113 static void ocores_process(struct ocores_i2c *i2c) ··· 251 223 .algo = &ocores_algorithm, 252 224 }; 253 225 226 + static struct of_device_id ocores_i2c_match[] = { 227 + { 228 + .compatible = "opencores,i2c-ocores", 229 + .data = (void *)TYPE_OCORES, 230 + }, 231 + { 232 + .compatible = "aeroflexgaisler,i2cmst", 233 + .data = (void *)TYPE_GRLIB, 234 + }, 235 + {}, 236 + }; 237 + MODULE_DEVICE_TABLE(of, ocores_i2c_match); 238 + 254 239 #ifdef CONFIG_OF 240 + /* Read and write functions for the GRLIB port of the controller. Registers are 241 + * 32-bit big endian and the PRELOW and PREHIGH registers are merged into one 242 + * register. The subsequent registers has their offset decreased accordingly. */ 243 + static u8 oc_getreg_grlib(struct ocores_i2c *i2c, int reg) 244 + { 245 + u32 rd; 246 + int rreg = reg; 247 + if (reg != OCI2C_PRELOW) 248 + rreg--; 249 + rd = ioread32be(i2c->base + (rreg << i2c->reg_shift)); 250 + if (reg == OCI2C_PREHIGH) 251 + return (u8)(rd >> 8); 252 + else 253 + return (u8)rd; 254 + } 255 + 256 + static void oc_setreg_grlib(struct ocores_i2c *i2c, int reg, u8 value) 257 + { 258 + u32 curr, wr; 259 + int rreg = reg; 260 + if (reg != OCI2C_PRELOW) 261 + rreg--; 262 + if (reg == OCI2C_PRELOW || reg == OCI2C_PREHIGH) { 263 + curr = ioread32be(i2c->base + (rreg << i2c->reg_shift)); 264 + if (reg == OCI2C_PRELOW) 265 + wr = (curr & 0xff00) | value; 266 + else 267 + wr = (((u32)value) << 8) | (curr & 0xff); 268 + } else { 269 + wr = value; 270 + } 271 + iowrite32be(wr, i2c->base + (rreg << i2c->reg_shift)); 272 + } 273 + 255 274 static int ocores_i2c_of_probe(struct platform_device *pdev, 256 275 struct ocores_i2c *i2c) 257 276 { 258 277 struct device_node *np = pdev->dev.of_node; 278 + const struct of_device_id *match; 259 279 u32 val; 260 280 261 281 if (of_property_read_u32(np, "reg-shift", &i2c->reg_shift)) { ··· 329 253 330 254 of_property_read_u32(pdev->dev.of_node, "reg-io-width", 331 255 &i2c->reg_io_width); 256 + 257 + match = of_match_node(ocores_i2c_match, pdev->dev.of_node); 258 + if (match && (int)match->data == TYPE_GRLIB) { 259 + dev_dbg(&pdev->dev, "GRLIB variant of i2c-ocores\n"); 260 + i2c->setreg = oc_setreg_grlib; 261 + i2c->getreg = oc_getreg_grlib; 262 + } 263 + 332 264 return 0; 333 265 } 334 266 #else ··· 347 263 { 348 264 struct ocores_i2c *i2c; 349 265 struct ocores_i2c_platform_data *pdata; 350 - struct resource *res, *res2; 266 + struct resource *res; 267 + int irq; 351 268 int ret; 352 269 int i; 353 270 ··· 356 271 if (!res) 357 272 return -ENODEV; 358 273 359 - res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 360 - if (!res2) 361 - return -ENODEV; 274 + irq = platform_get_irq(pdev, 0); 275 + if (irq < 0) 276 + return irq; 362 277 363 278 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); 364 279 if (!i2c) 365 280 return -ENOMEM; 366 281 367 - if (!devm_request_mem_region(&pdev->dev, res->start, 368 - resource_size(res), pdev->name)) { 369 - dev_err(&pdev->dev, "Memory region busy\n"); 370 - return -EBUSY; 371 - } 372 - 373 - i2c->base = devm_ioremap_nocache(&pdev->dev, res->start, 374 - resource_size(res)); 375 - if (!i2c->base) { 376 - dev_err(&pdev->dev, "Unable to map registers\n"); 377 - return -EIO; 378 - } 282 + i2c->base = devm_request_and_ioremap(&pdev->dev, res); 283 + if (!i2c->base) 284 + return -EADDRNOTAVAIL; 379 285 380 286 pdata = pdev->dev.platform_data; 381 287 if (pdata) { ··· 382 306 if (i2c->reg_io_width == 0) 383 307 i2c->reg_io_width = 1; /* Set to default value */ 384 308 309 + if (!i2c->setreg || !i2c->getreg) { 310 + switch (i2c->reg_io_width) { 311 + case 1: 312 + i2c->setreg = oc_setreg_8; 313 + i2c->getreg = oc_getreg_8; 314 + break; 315 + 316 + case 2: 317 + i2c->setreg = oc_setreg_16; 318 + i2c->getreg = oc_getreg_16; 319 + break; 320 + 321 + case 4: 322 + i2c->setreg = oc_setreg_32; 323 + i2c->getreg = oc_getreg_32; 324 + break; 325 + 326 + default: 327 + dev_err(&pdev->dev, "Unsupported I/O width (%d)\n", 328 + i2c->reg_io_width); 329 + return -EINVAL; 330 + } 331 + } 332 + 385 333 ocores_init(i2c); 386 334 387 335 init_waitqueue_head(&i2c->wait); 388 - ret = devm_request_irq(&pdev->dev, res2->start, ocores_isr, 0, 336 + ret = devm_request_irq(&pdev->dev, irq, ocores_isr, 0, 389 337 pdev->name, i2c); 390 338 if (ret) { 391 339 dev_err(&pdev->dev, "Cannot claim IRQ\n"); ··· 482 382 #else 483 383 #define OCORES_I2C_PM NULL 484 384 #endif 485 - 486 - static struct of_device_id ocores_i2c_match[] = { 487 - { .compatible = "opencores,i2c-ocores", }, 488 - {}, 489 - }; 490 - MODULE_DEVICE_TABLE(of, ocores_i2c_match); 491 385 492 386 static struct platform_driver ocores_i2c_driver = { 493 387 .probe = ocores_i2c_probe,
+131 -93
drivers/i2c/busses/i2c-omap.c
··· 43 43 #include <linux/slab.h> 44 44 #include <linux/i2c-omap.h> 45 45 #include <linux/pm_runtime.h> 46 + #include <linux/pinctrl/consumer.h> 46 47 47 48 /* I2C controller revisions */ 48 49 #define OMAP_I2C_OMAP1_REV_2 0x20 49 50 50 51 /* I2C controller revisions present on specific hardware */ 51 - #define OMAP_I2C_REV_ON_2430 0x36 52 - #define OMAP_I2C_REV_ON_3430_3530 0x3C 53 - #define OMAP_I2C_REV_ON_3630_4430 0x40 52 + #define OMAP_I2C_REV_ON_2430 0x00000036 53 + #define OMAP_I2C_REV_ON_3430_3530 0x0000003C 54 + #define OMAP_I2C_REV_ON_3630 0x00000040 55 + #define OMAP_I2C_REV_ON_4430_PLUS 0x50400002 54 56 55 57 /* timeout waiting for the controller to respond */ 56 58 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) ··· 192 190 void (*set_mpu_wkup_lat)(struct device *dev, 193 191 long latency); 194 192 u32 speed; /* Speed of bus in kHz */ 195 - u32 dtrev; /* extra revision from DT */ 196 193 u32 flags; 197 194 u16 cmd_err; 198 195 u8 *buf; ··· 203 202 * fifo_size==0 implies no fifo 204 203 * if set, should be trsh+1 205 204 */ 206 - u8 rev; 205 + u32 rev; 207 206 unsigned b_hw:1; /* bad h/w fixes */ 208 207 unsigned receiver:1; /* true when we're in receiver mode */ 209 208 u16 iestate; /* Saved interrupt register */ 210 209 u16 pscstate; 211 210 u16 scllstate; 212 211 u16 sclhstate; 213 - u16 bufstate; 214 212 u16 syscstate; 215 213 u16 westate; 216 214 u16 errata; 215 + 216 + struct pinctrl *pins; 217 217 }; 218 218 219 219 static const u8 reg_map_ip_v1[] = { ··· 277 275 (i2c_dev->regs[reg] << i2c_dev->reg_shift)); 278 276 } 279 277 280 - static int omap_i2c_init(struct omap_i2c_dev *dev) 278 + static void __omap_i2c_init(struct omap_i2c_dev *dev) 281 279 { 282 - u16 psc = 0, scll = 0, sclh = 0, buf = 0; 283 - u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; 284 - unsigned long fclk_rate = 12000000; 280 + 281 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 282 + 283 + /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 284 + omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); 285 + 286 + /* SCL low and high time values */ 287 + omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); 288 + omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, dev->sclhstate); 289 + if (dev->rev >= OMAP_I2C_REV_ON_3430_3530) 290 + omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); 291 + 292 + /* Take the I2C module out of reset: */ 293 + omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 294 + 295 + /* 296 + * Don't write to this register if the IE state is 0 as it can 297 + * cause deadlock. 298 + */ 299 + if (dev->iestate) 300 + omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); 301 + } 302 + 303 + static int omap_i2c_reset(struct omap_i2c_dev *dev) 304 + { 285 305 unsigned long timeout; 286 - unsigned long internal_clk = 0; 287 - struct clk *fclk; 306 + u16 sysc; 288 307 289 308 if (dev->rev >= OMAP_I2C_OMAP1_REV_2) { 309 + sysc = omap_i2c_read_reg(dev, OMAP_I2C_SYSC_REG); 310 + 290 311 /* Disable I2C controller before soft reset */ 291 312 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 292 313 omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & ··· 331 306 } 332 307 333 308 /* SYSC register is cleared by the reset; rewrite it */ 334 - if (dev->rev == OMAP_I2C_REV_ON_2430) { 309 + omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, sysc); 335 310 336 - omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, 337 - SYSC_AUTOIDLE_MASK); 338 - 339 - } else if (dev->rev >= OMAP_I2C_REV_ON_3430_3530) { 340 - dev->syscstate = SYSC_AUTOIDLE_MASK; 341 - dev->syscstate |= SYSC_ENAWAKEUP_MASK; 342 - dev->syscstate |= (SYSC_IDLEMODE_SMART << 343 - __ffs(SYSC_SIDLEMODE_MASK)); 344 - dev->syscstate |= (SYSC_CLOCKACTIVITY_FCLK << 345 - __ffs(SYSC_CLOCKACTIVITY_MASK)); 346 - 347 - omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, 348 - dev->syscstate); 349 - /* 350 - * Enabling all wakup sources to stop I2C freezing on 351 - * WFI instruction. 352 - * REVISIT: Some wkup sources might not be needed. 353 - */ 354 - dev->westate = OMAP_I2C_WE_ALL; 355 - omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, 356 - dev->westate); 357 - } 358 311 } 359 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 312 + return 0; 313 + } 314 + 315 + static int omap_i2c_init(struct omap_i2c_dev *dev) 316 + { 317 + u16 psc = 0, scll = 0, sclh = 0; 318 + u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; 319 + unsigned long fclk_rate = 12000000; 320 + unsigned long internal_clk = 0; 321 + struct clk *fclk; 322 + 323 + if (dev->rev >= OMAP_I2C_REV_ON_3430_3530) { 324 + /* 325 + * Enabling all wakup sources to stop I2C freezing on 326 + * WFI instruction. 327 + * REVISIT: Some wkup sources might not be needed. 328 + */ 329 + dev->westate = OMAP_I2C_WE_ALL; 330 + } 360 331 361 332 if (dev->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) { 362 333 /* ··· 437 416 sclh = fclk_rate / (dev->speed * 2) - 7 + psc; 438 417 } 439 418 440 - /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 441 - omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc); 442 - 443 - /* SCL low and high time values */ 444 - omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); 445 - omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); 446 - 447 - /* Take the I2C module out of reset: */ 448 - omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 449 - 450 - /* Enable interrupts */ 451 419 dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 452 420 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 453 421 OMAP_I2C_IE_AL) | ((dev->fifo_size) ? 454 422 (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); 455 - omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); 456 - if (dev->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) { 457 - dev->pscstate = psc; 458 - dev->scllstate = scll; 459 - dev->sclhstate = sclh; 460 - dev->bufstate = buf; 461 - } 423 + 424 + dev->pscstate = psc; 425 + dev->scllstate = scll; 426 + dev->sclhstate = sclh; 427 + 428 + __omap_i2c_init(dev); 429 + 462 430 return 0; 463 431 } 464 432 ··· 500 490 501 491 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, buf); 502 492 503 - if (dev->rev < OMAP_I2C_REV_ON_3630_4430) 493 + if (dev->rev < OMAP_I2C_REV_ON_3630) 504 494 dev->b_hw = 1; /* Enable hardware fixes */ 505 495 506 496 /* calculate wakeup latency constraint for MPU */ ··· 596 586 OMAP_I2C_TIMEOUT); 597 587 if (timeout == 0) { 598 588 dev_err(dev->dev, "controller timed out\n"); 599 - omap_i2c_init(dev); 589 + omap_i2c_reset(dev); 590 + __omap_i2c_init(dev); 600 591 return -ETIMEDOUT; 601 592 } 602 593 ··· 607 596 /* We have an error */ 608 597 if (dev->cmd_err & (OMAP_I2C_STAT_AL | OMAP_I2C_STAT_ROVR | 609 598 OMAP_I2C_STAT_XUDF)) { 610 - omap_i2c_init(dev); 599 + omap_i2c_reset(dev); 600 + __omap_i2c_init(dev); 611 601 return -EIO; 612 602 } 613 603 ··· 654 642 break; 655 643 } 656 644 657 - if (dev->set_mpu_wkup_lat != NULL) 658 - dev->set_mpu_wkup_lat(dev->dev, -1); 659 - 660 645 if (r == 0) 661 646 r = num; 662 647 663 648 omap_i2c_wait_for_bb(dev); 649 + 650 + if (dev->set_mpu_wkup_lat != NULL) 651 + dev->set_mpu_wkup_lat(dev->dev, -1); 652 + 664 653 out: 665 654 pm_runtime_mark_last_busy(dev->dev); 666 655 pm_runtime_put_autosuspend(dev->dev); ··· 1038 1025 #ifdef CONFIG_OF 1039 1026 static struct omap_i2c_bus_platform_data omap3_pdata = { 1040 1027 .rev = OMAP_I2C_IP_VERSION_1, 1041 - .flags = OMAP_I2C_FLAG_APPLY_ERRATA_I207 | 1042 - OMAP_I2C_FLAG_RESET_REGS_POSTIDLE | 1043 - OMAP_I2C_FLAG_BUS_SHIFT_2, 1028 + .flags = OMAP_I2C_FLAG_BUS_SHIFT_2, 1044 1029 }; 1045 1030 1046 1031 static struct omap_i2c_bus_platform_data omap4_pdata = { ··· 1059 1048 MODULE_DEVICE_TABLE(of, omap_i2c_of_match); 1060 1049 #endif 1061 1050 1051 + #define OMAP_I2C_SCHEME(rev) ((rev & 0xc000) >> 14) 1052 + 1053 + #define OMAP_I2C_REV_SCHEME_0_MAJOR(rev) (rev >> 4) 1054 + #define OMAP_I2C_REV_SCHEME_0_MINOR(rev) (rev & 0xf) 1055 + 1056 + #define OMAP_I2C_REV_SCHEME_1_MAJOR(rev) ((rev & 0x0700) >> 7) 1057 + #define OMAP_I2C_REV_SCHEME_1_MINOR(rev) (rev & 0x1f) 1058 + #define OMAP_I2C_SCHEME_0 0 1059 + #define OMAP_I2C_SCHEME_1 1 1060 + 1062 1061 static int __devinit 1063 1062 omap_i2c_probe(struct platform_device *pdev) 1064 1063 { ··· 1081 1060 const struct of_device_id *match; 1082 1061 int irq; 1083 1062 int r; 1063 + u32 rev; 1064 + u16 minor, major, scheme; 1084 1065 1085 1066 /* NOTE: driver uses the static register mapping */ 1086 1067 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 1114 1091 u32 freq = 100000; /* default to 100000 Hz */ 1115 1092 1116 1093 pdata = match->data; 1117 - dev->dtrev = pdata->rev; 1118 1094 dev->flags = pdata->flags; 1119 1095 1120 1096 of_property_read_u32(node, "clock-frequency", &freq); ··· 1123 1101 dev->speed = pdata->clkrate; 1124 1102 dev->flags = pdata->flags; 1125 1103 dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat; 1126 - dev->dtrev = pdata->rev; 1104 + } 1105 + 1106 + dev->pins = devm_pinctrl_get_select_default(&pdev->dev); 1107 + if (IS_ERR(dev->pins)) { 1108 + if (PTR_ERR(dev->pins) == -EPROBE_DEFER) 1109 + return -EPROBE_DEFER; 1110 + 1111 + dev_warn(&pdev->dev, "did not get pins for i2c error: %li\n", 1112 + PTR_ERR(dev->pins)); 1113 + dev->pins = NULL; 1127 1114 } 1128 1115 1129 1116 dev->dev = &pdev->dev; ··· 1145 1114 1146 1115 dev->reg_shift = (dev->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3; 1147 1116 1148 - if (dev->dtrev == OMAP_I2C_IP_VERSION_2) 1149 - dev->regs = (u8 *)reg_map_ip_v2; 1150 - else 1151 - dev->regs = (u8 *)reg_map_ip_v1; 1152 - 1153 1117 pm_runtime_enable(dev->dev); 1154 1118 pm_runtime_set_autosuspend_delay(dev->dev, OMAP_I2C_PM_TIMEOUT); 1155 1119 pm_runtime_use_autosuspend(dev->dev); ··· 1153 1127 if (IS_ERR_VALUE(r)) 1154 1128 goto err_free_mem; 1155 1129 1156 - dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 1130 + /* 1131 + * Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2. 1132 + * On omap1/3/2 Offset 4 is IE Reg the bit [15:14] is 0 at reset. 1133 + * Also since the omap_i2c_read_reg uses reg_map_ip_* a 1134 + * raw_readw is done. 1135 + */ 1136 + rev = __raw_readw(dev->base + 0x04); 1137 + 1138 + scheme = OMAP_I2C_SCHEME(rev); 1139 + switch (scheme) { 1140 + case OMAP_I2C_SCHEME_0: 1141 + dev->regs = (u8 *)reg_map_ip_v1; 1142 + dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG); 1143 + minor = OMAP_I2C_REV_SCHEME_0_MAJOR(dev->rev); 1144 + major = OMAP_I2C_REV_SCHEME_0_MAJOR(dev->rev); 1145 + break; 1146 + case OMAP_I2C_SCHEME_1: 1147 + /* FALLTHROUGH */ 1148 + default: 1149 + dev->regs = (u8 *)reg_map_ip_v2; 1150 + rev = (rev << 16) | 1151 + omap_i2c_read_reg(dev, OMAP_I2C_IP_V2_REVNB_LO); 1152 + minor = OMAP_I2C_REV_SCHEME_1_MINOR(rev); 1153 + major = OMAP_I2C_REV_SCHEME_1_MAJOR(rev); 1154 + dev->rev = rev; 1155 + } 1157 1156 1158 1157 dev->errata = 0; 1159 1158 1160 - if (dev->flags & OMAP_I2C_FLAG_APPLY_ERRATA_I207) 1159 + if (dev->rev >= OMAP_I2C_REV_ON_2430 && 1160 + dev->rev < OMAP_I2C_REV_ON_4430_PLUS) 1161 1161 dev->errata |= I2C_OMAP_ERRATA_I207; 1162 1162 1163 1163 if (dev->rev <= OMAP_I2C_REV_ON_3430_3530) ··· 1204 1152 1205 1153 dev->fifo_size = (dev->fifo_size / 2); 1206 1154 1207 - if (dev->rev < OMAP_I2C_REV_ON_3630_4430) 1155 + if (dev->rev < OMAP_I2C_REV_ON_3630) 1208 1156 dev->b_hw = 1; /* Enable hardware fixes */ 1209 1157 1210 1158 /* calculate wakeup latency constraint for MPU */ ··· 1247 1195 goto err_unuse_clocks; 1248 1196 } 1249 1197 1250 - dev_info(dev->dev, "bus %d rev%d.%d.%d at %d kHz\n", adap->nr, 1251 - dev->dtrev, dev->rev >> 4, dev->rev & 0xf, dev->speed); 1198 + dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr, 1199 + major, minor, dev->speed); 1252 1200 1253 1201 of_i2c_register_devices(adap); 1254 1202 ··· 1291 1239 { 1292 1240 struct platform_device *pdev = to_platform_device(dev); 1293 1241 struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); 1294 - u16 iv; 1295 1242 1296 1243 _dev->iestate = omap_i2c_read_reg(_dev, OMAP_I2C_IE_REG); 1297 1244 1298 1245 omap_i2c_write_reg(_dev, OMAP_I2C_IE_REG, 0); 1299 1246 1300 1247 if (_dev->rev < OMAP_I2C_OMAP1_REV_2) { 1301 - iv = omap_i2c_read_reg(_dev, OMAP_I2C_IV_REG); /* Read clears */ 1248 + omap_i2c_read_reg(_dev, OMAP_I2C_IV_REG); /* Read clears */ 1302 1249 } else { 1303 1250 omap_i2c_write_reg(_dev, OMAP_I2C_STAT_REG, _dev->iestate); 1304 1251 ··· 1313 1262 struct platform_device *pdev = to_platform_device(dev); 1314 1263 struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); 1315 1264 1316 - if (_dev->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) { 1317 - omap_i2c_write_reg(_dev, OMAP_I2C_CON_REG, 0); 1318 - omap_i2c_write_reg(_dev, OMAP_I2C_PSC_REG, _dev->pscstate); 1319 - omap_i2c_write_reg(_dev, OMAP_I2C_SCLL_REG, _dev->scllstate); 1320 - omap_i2c_write_reg(_dev, OMAP_I2C_SCLH_REG, _dev->sclhstate); 1321 - omap_i2c_write_reg(_dev, OMAP_I2C_BUF_REG, _dev->bufstate); 1322 - omap_i2c_write_reg(_dev, OMAP_I2C_SYSC_REG, _dev->syscstate); 1323 - omap_i2c_write_reg(_dev, OMAP_I2C_WE_REG, _dev->westate); 1324 - omap_i2c_write_reg(_dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 1325 - } 1265 + if (!_dev->regs) 1266 + return 0; 1326 1267 1327 - /* 1328 - * Don't write to this register if the IE state is 0 as it can 1329 - * cause deadlock. 1330 - */ 1331 - if (_dev->iestate) 1332 - omap_i2c_write_reg(_dev, OMAP_I2C_IE_REG, _dev->iestate); 1268 + __omap_i2c_init(_dev); 1333 1269 1334 1270 return 0; 1335 1271 }
+3 -3
drivers/i2c/busses/i2c-rcar.c
··· 642 642 if (ret < 0) 643 643 return ret; 644 644 645 - priv->io = devm_ioremap(dev, res->start, resource_size(res)); 645 + priv->io = devm_request_and_ioremap(dev, res); 646 646 if (!priv->io) { 647 647 dev_err(dev, "cannot ioremap\n"); 648 648 return -ENODEV; ··· 693 693 return 0; 694 694 } 695 695 696 - static struct platform_driver rcar_i2c_drv = { 696 + static struct platform_driver rcar_i2c_driver = { 697 697 .driver = { 698 698 .name = "i2c-rcar", 699 699 .owner = THIS_MODULE, ··· 702 702 .remove = __devexit_p(rcar_i2c_remove), 703 703 }; 704 704 705 - module_platform_driver(rcar_i2c_drv); 705 + module_platform_driver(rcar_i2c_driver); 706 706 707 707 MODULE_LICENSE("GPL"); 708 708 MODULE_DESCRIPTION("Renesas R-Car I2C bus driver");
+130 -81
drivers/i2c/busses/i2c-s3c2410.c
··· 38 38 #include <linux/io.h> 39 39 #include <linux/of_i2c.h> 40 40 #include <linux/of_gpio.h> 41 + #include <linux/pinctrl/consumer.h> 41 42 42 43 #include <asm/irq.h> 43 44 ··· 50 49 #define QUIRK_HDMIPHY (1 << 1) 51 50 #define QUIRK_NO_GPIO (1 << 2) 52 51 52 + /* Max time to wait for bus to become idle after a xfer (in us) */ 53 + #define S3C2410_IDLE_TIMEOUT 5000 54 + 53 55 /* i2c controller state */ 54 56 enum s3c24xx_i2c_state { 55 57 STATE_IDLE, ··· 63 59 }; 64 60 65 61 struct s3c24xx_i2c { 66 - spinlock_t lock; 67 62 wait_queue_head_t wait; 68 63 unsigned int quirks; 69 64 unsigned int suspended:1; ··· 81 78 void __iomem *regs; 82 79 struct clk *clk; 83 80 struct device *dev; 84 - struct resource *ioarea; 85 81 struct i2c_adapter adap; 86 82 87 83 struct s3c2410_platform_i2c *pdata; 88 84 int gpios[2]; 85 + struct pinctrl *pctrl; 89 86 #ifdef CONFIG_CPU_FREQ 90 87 struct notifier_block freq_transition; 91 88 #endif ··· 238 235 239 236 dev_dbg(i2c->dev, "STOP\n"); 240 237 241 - /* stop the transfer */ 242 - iicstat &= ~S3C2410_IICSTAT_START; 238 + /* 239 + * The datasheet says that the STOP sequence should be: 240 + * 1) I2CSTAT.5 = 0 - Clear BUSY (or 'generate STOP') 241 + * 2) I2CCON.4 = 0 - Clear IRQPEND 242 + * 3) Wait until the stop condition takes effect. 243 + * 4*) I2CSTAT.4 = 0 - Clear TXRXEN 244 + * 245 + * Where, step "4*" is only for buses with the "HDMIPHY" quirk. 246 + * 247 + * However, after much experimentation, it appears that: 248 + * a) normal buses automatically clear BUSY and transition from 249 + * Master->Slave when they complete generating a STOP condition. 250 + * Therefore, step (3) can be done in doxfer() by polling I2CCON.4 251 + * after starting the STOP generation here. 252 + * b) HDMIPHY bus does neither, so there is no way to do step 3. 253 + * There is no indication when this bus has finished generating 254 + * STOP. 255 + * 256 + * In fact, we have found that as soon as the IRQPEND bit is cleared in 257 + * step 2, the HDMIPHY bus generates the STOP condition, and then 258 + * immediately starts transferring another data byte, even though the 259 + * bus is supposedly stopped. This is presumably because the bus is 260 + * still in "Master" mode, and its BUSY bit is still set. 261 + * 262 + * To avoid these extra post-STOP transactions on HDMI phy devices, we 263 + * just disable Serial Output on the bus (I2CSTAT.4 = 0) directly, 264 + * instead of first generating a proper STOP condition. This should 265 + * float SDA & SCK terminating the transfer. Subsequent transfers 266 + * start with a proper START condition, and proceed normally. 267 + * 268 + * The HDMIPHY bus is an internal bus that always has exactly two 269 + * devices, the host as Master and the HDMIPHY device as the slave. 270 + * Skipping the STOP condition has been tested on this bus and works. 271 + */ 272 + if (i2c->quirks & QUIRK_HDMIPHY) { 273 + /* Stop driving the I2C pins */ 274 + iicstat &= ~S3C2410_IICSTAT_TXRXEN; 275 + } else { 276 + /* stop the transfer */ 277 + iicstat &= ~S3C2410_IICSTAT_START; 278 + } 243 279 writel(iicstat, i2c->regs + S3C2410_IICSTAT); 244 280 245 281 i2c->state = STATE_STOP; ··· 532 490 unsigned long iicstat; 533 491 int timeout = 400; 534 492 535 - /* the timeout for HDMIPHY is reduced to 10 ms because 536 - * the hangup is expected to happen, so waiting 400 ms 537 - * causes only unnecessary system hangup 538 - */ 539 - if (i2c->quirks & QUIRK_HDMIPHY) 540 - timeout = 10; 541 - 542 493 while (timeout-- > 0) { 543 494 iicstat = readl(i2c->regs + S3C2410_IICSTAT); 544 495 ··· 541 506 msleep(1); 542 507 } 543 508 544 - /* hang-up of bus dedicated for HDMIPHY occurred, resetting */ 545 - if (i2c->quirks & QUIRK_HDMIPHY) { 546 - writel(0, i2c->regs + S3C2410_IICCON); 547 - writel(0, i2c->regs + S3C2410_IICSTAT); 548 - writel(0, i2c->regs + S3C2410_IICDS); 509 + return -ETIMEDOUT; 510 + } 549 511 550 - return 0; 512 + /* s3c24xx_i2c_wait_idle 513 + * 514 + * wait for the i2c bus to become idle. 515 + */ 516 + 517 + static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c) 518 + { 519 + unsigned long iicstat; 520 + ktime_t start, now; 521 + unsigned long delay; 522 + int spins; 523 + 524 + /* ensure the stop has been through the bus */ 525 + 526 + dev_dbg(i2c->dev, "waiting for bus idle\n"); 527 + 528 + start = now = ktime_get(); 529 + 530 + /* 531 + * Most of the time, the bus is already idle within a few usec of the 532 + * end of a transaction. However, really slow i2c devices can stretch 533 + * the clock, delaying STOP generation. 534 + * 535 + * On slower SoCs this typically happens within a very small number of 536 + * instructions so busy wait briefly to avoid scheduling overhead. 537 + */ 538 + spins = 3; 539 + iicstat = readl(i2c->regs + S3C2410_IICSTAT); 540 + while ((iicstat & S3C2410_IICSTAT_START) && --spins) { 541 + cpu_relax(); 542 + iicstat = readl(i2c->regs + S3C2410_IICSTAT); 551 543 } 552 544 553 - return -ETIMEDOUT; 545 + /* 546 + * If we do get an appreciable delay as a compromise between idle 547 + * detection latency for the normal, fast case, and system load in the 548 + * slow device case, use an exponential back off in the polling loop, 549 + * up to 1/10th of the total timeout, then continue to poll at a 550 + * constant rate up to the timeout. 551 + */ 552 + delay = 1; 553 + while ((iicstat & S3C2410_IICSTAT_START) && 554 + ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) { 555 + usleep_range(delay, 2 * delay); 556 + if (delay < S3C2410_IDLE_TIMEOUT / 10) 557 + delay <<= 1; 558 + now = ktime_get(); 559 + iicstat = readl(i2c->regs + S3C2410_IICSTAT); 560 + } 561 + 562 + if (iicstat & S3C2410_IICSTAT_START) 563 + dev_warn(i2c->dev, "timeout waiting for bus idle\n"); 554 564 } 555 565 556 566 /* s3c24xx_i2c_doxfer ··· 606 526 static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, 607 527 struct i2c_msg *msgs, int num) 608 528 { 609 - unsigned long iicstat, timeout; 610 - int spins = 20; 529 + unsigned long timeout; 611 530 int ret; 612 531 613 532 if (i2c->suspended) ··· 619 540 goto out; 620 541 } 621 542 622 - spin_lock_irq(&i2c->lock); 623 - 624 543 i2c->msg = msgs; 625 544 i2c->msg_num = num; 626 545 i2c->msg_ptr = 0; ··· 627 550 628 551 s3c24xx_i2c_enable_irq(i2c); 629 552 s3c24xx_i2c_message_start(i2c, msgs); 630 - spin_unlock_irq(&i2c->lock); 631 553 632 554 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 633 555 ··· 640 564 else if (ret != num) 641 565 dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret); 642 566 643 - /* ensure the stop has been through the bus */ 567 + /* For QUIRK_HDMIPHY, bus is already disabled */ 568 + if (i2c->quirks & QUIRK_HDMIPHY) 569 + goto out; 644 570 645 - dev_dbg(i2c->dev, "waiting for bus idle\n"); 646 - 647 - /* first, try busy waiting briefly */ 648 - do { 649 - cpu_relax(); 650 - iicstat = readl(i2c->regs + S3C2410_IICSTAT); 651 - } while ((iicstat & S3C2410_IICSTAT_START) && --spins); 652 - 653 - /* if that timed out sleep */ 654 - if (!spins) { 655 - msleep(1); 656 - iicstat = readl(i2c->regs + S3C2410_IICSTAT); 657 - } 658 - 659 - if (iicstat & S3C2410_IICSTAT_START) 660 - dev_warn(i2c->dev, "timeout waiting for bus idle\n"); 571 + s3c24xx_i2c_wait_idle(i2c); 661 572 662 573 out: 663 574 return ret; ··· 803 740 unsigned long val, void *data) 804 741 { 805 742 struct s3c24xx_i2c *i2c = freq_to_i2c(nb); 806 - unsigned long flags; 807 743 unsigned int got; 808 744 int delta_f; 809 745 int ret; ··· 816 754 817 755 if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) || 818 756 (val == CPUFREQ_PRECHANGE && delta_f > 0)) { 819 - spin_lock_irqsave(&i2c->lock, flags); 757 + i2c_lock_adapter(&i2c->adap); 820 758 ret = s3c24xx_i2c_clockrate(i2c, &got); 821 - spin_unlock_irqrestore(&i2c->lock, flags); 759 + i2c_unlock_adapter(&i2c->adap); 822 760 823 761 if (ret < 0) 824 762 dev_err(i2c->dev, "cannot find frequency\n"); ··· 920 858 921 859 pdata = i2c->pdata; 922 860 923 - /* inititalise the gpio */ 924 - 925 - if (pdata->cfg_gpio) 926 - pdata->cfg_gpio(to_platform_device(i2c->dev)); 927 - else 928 - if (s3c24xx_i2c_parse_dt_gpio(i2c)) 929 - return -EINVAL; 930 - 931 861 /* write slave address */ 932 862 933 863 writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); ··· 1017 963 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1018 964 i2c->tx_setup = 50; 1019 965 1020 - spin_lock_init(&i2c->lock); 1021 966 init_waitqueue_head(&i2c->wait); 1022 967 1023 968 /* find the clock and enable it */ ··· 1042 989 goto err_clk; 1043 990 } 1044 991 1045 - i2c->ioarea = request_mem_region(res->start, resource_size(res), 1046 - pdev->name); 1047 - 1048 - if (i2c->ioarea == NULL) { 1049 - dev_err(&pdev->dev, "cannot request IO\n"); 1050 - ret = -ENXIO; 1051 - goto err_clk; 1052 - } 1053 - 1054 - i2c->regs = ioremap(res->start, resource_size(res)); 992 + i2c->regs = devm_request_and_ioremap(&pdev->dev, res); 1055 993 1056 994 if (i2c->regs == NULL) { 1057 995 dev_err(&pdev->dev, "cannot map IO\n"); 1058 996 ret = -ENXIO; 1059 - goto err_ioarea; 997 + goto err_clk; 1060 998 } 1061 999 1062 - dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", 1063 - i2c->regs, i2c->ioarea, res); 1000 + dev_dbg(&pdev->dev, "registers %p (%p)\n", 1001 + i2c->regs, res); 1064 1002 1065 1003 /* setup info block for the i2c core */ 1066 1004 1067 1005 i2c->adap.algo_data = i2c; 1068 1006 i2c->adap.dev.parent = &pdev->dev; 1069 1007 1008 + i2c->pctrl = devm_pinctrl_get_select_default(i2c->dev); 1009 + 1010 + /* inititalise the i2c gpio lines */ 1011 + 1012 + if (i2c->pdata->cfg_gpio) { 1013 + i2c->pdata->cfg_gpio(to_platform_device(i2c->dev)); 1014 + } else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c)) { 1015 + ret = -EINVAL; 1016 + goto err_clk; 1017 + } 1018 + 1070 1019 /* initialise the i2c controller */ 1071 1020 1072 1021 ret = s3c24xx_i2c_init(i2c); 1073 1022 if (ret != 0) 1074 - goto err_iomap; 1023 + goto err_clk; 1075 1024 1076 1025 /* find the IRQ for this unit (note, this relies on the init call to 1077 1026 * ensure no current IRQs pending ··· 1082 1027 i2c->irq = ret = platform_get_irq(pdev, 0); 1083 1028 if (ret <= 0) { 1084 1029 dev_err(&pdev->dev, "cannot find IRQ\n"); 1085 - goto err_iomap; 1030 + goto err_clk; 1086 1031 } 1087 1032 1088 1033 ret = request_irq(i2c->irq, s3c24xx_i2c_irq, 0, ··· 1090 1035 1091 1036 if (ret != 0) { 1092 1037 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); 1093 - goto err_iomap; 1038 + goto err_clk; 1094 1039 } 1095 1040 1096 1041 ret = s3c24xx_i2c_register_cpufreq(i2c); ··· 1130 1075 err_irq: 1131 1076 free_irq(i2c->irq, i2c); 1132 1077 1133 - err_iomap: 1134 - iounmap(i2c->regs); 1135 - 1136 - err_ioarea: 1137 - release_resource(i2c->ioarea); 1138 - kfree(i2c->ioarea); 1139 - 1140 1078 err_clk: 1141 1079 clk_disable_unprepare(i2c->clk); 1142 1080 clk_put(i2c->clk); ··· 1158 1110 clk_disable_unprepare(i2c->clk); 1159 1111 clk_put(i2c->clk); 1160 1112 1161 - iounmap(i2c->regs); 1162 - 1163 - release_resource(i2c->ioarea); 1164 - s3c24xx_i2c_dt_gpio_free(i2c); 1165 - kfree(i2c->ioarea); 1113 + if (pdev->dev.of_node && IS_ERR(i2c->pctrl)) 1114 + s3c24xx_i2c_dt_gpio_free(i2c); 1166 1115 1167 1116 return 0; 1168 1117 } 1169 1118 1170 - #ifdef CONFIG_PM 1119 + #ifdef CONFIG_PM_SLEEP 1171 1120 static int s3c24xx_i2c_suspend_noirq(struct device *dev) 1172 1121 { 1173 1122 struct platform_device *pdev = to_platform_device(dev); ··· 1187 1142 1188 1143 return 0; 1189 1144 } 1145 + #endif 1190 1146 1147 + #ifdef CONFIG_PM 1191 1148 static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { 1149 + #ifdef CONFIG_PM_SLEEP 1192 1150 .suspend_noirq = s3c24xx_i2c_suspend_noirq, 1193 1151 .resume = s3c24xx_i2c_resume, 1152 + #endif 1194 1153 }; 1195 1154 1196 1155 #define S3C24XX_DEV_PM_OPS (&s3c24xx_i2c_dev_pm_ops)
+101 -57
drivers/i2c/busses/i2c-sh_mobile.c
··· 120 120 void __iomem *reg; 121 121 struct i2c_adapter adap; 122 122 unsigned long bus_speed; 123 + unsigned int clks_per_count; 123 124 struct clk *clk; 124 125 u_int8_t icic; 125 - u_int8_t iccl; 126 - u_int8_t icch; 127 126 u_int8_t flags; 127 + u_int16_t iccl; 128 + u_int16_t icch; 128 129 129 130 spinlock_t lock; 130 131 wait_queue_head_t wait; ··· 136 135 137 136 #define IIC_FLAG_HAS_ICIC67 (1 << 0) 138 137 139 - #define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */ 138 + #define STANDARD_MODE 100000 139 + #define FAST_MODE 400000 140 140 141 141 /* Register offsets */ 142 142 #define ICDR 0x00 ··· 189 187 iic_wr(pd, offs, (iic_rd(pd, offs) | set) & ~clr); 190 188 } 191 189 190 + static u32 sh_mobile_i2c_iccl(unsigned long count_khz, u32 tLOW, u32 tf, int offset) 191 + { 192 + /* 193 + * Conditional expression: 194 + * ICCL >= COUNT_CLK * (tLOW + tf) 195 + * 196 + * SH-Mobile IIC hardware starts counting the LOW period of 197 + * the SCL signal (tLOW) as soon as it pulls the SCL line. 198 + * In order to meet the tLOW timing spec, we need to take into 199 + * account the fall time of SCL signal (tf). Default tf value 200 + * should be 0.3 us, for safety. 201 + */ 202 + return (((count_khz * (tLOW + tf)) + 5000) / 10000) + offset; 203 + } 204 + 205 + static u32 sh_mobile_i2c_icch(unsigned long count_khz, u32 tHIGH, u32 tf, int offset) 206 + { 207 + /* 208 + * Conditional expression: 209 + * ICCH >= COUNT_CLK * (tHIGH + tf) 210 + * 211 + * SH-Mobile IIC hardware is aware of SCL transition period 'tr', 212 + * and can ignore it. SH-Mobile IIC controller starts counting 213 + * the HIGH period of the SCL signal (tHIGH) after the SCL input 214 + * voltage increases at VIH. 215 + * 216 + * Afterward it turned out calculating ICCH using only tHIGH spec 217 + * will result in violation of the tHD;STA timing spec. We need 218 + * to take into account the fall time of SDA signal (tf) at START 219 + * condition, in order to meet both tHIGH and tHD;STA specs. 220 + */ 221 + return (((count_khz * (tHIGH + tf)) + 5000) / 10000) + offset; 222 + } 223 + 224 + static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) 225 + { 226 + unsigned long i2c_clk_khz; 227 + u32 tHIGH, tLOW, tf; 228 + int offset; 229 + 230 + /* Get clock rate after clock is enabled */ 231 + clk_enable(pd->clk); 232 + i2c_clk_khz = clk_get_rate(pd->clk) / 1000; 233 + i2c_clk_khz /= pd->clks_per_count; 234 + 235 + if (pd->bus_speed == STANDARD_MODE) { 236 + tLOW = 47; /* tLOW = 4.7 us */ 237 + tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ 238 + tf = 3; /* tf = 0.3 us */ 239 + offset = 0; /* No offset */ 240 + } else if (pd->bus_speed == FAST_MODE) { 241 + tLOW = 13; /* tLOW = 1.3 us */ 242 + tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ 243 + tf = 3; /* tf = 0.3 us */ 244 + offset = 0; /* No offset */ 245 + } else { 246 + dev_err(pd->dev, "unrecognized bus speed %lu Hz\n", 247 + pd->bus_speed); 248 + goto out; 249 + } 250 + 251 + pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf, offset); 252 + /* one more bit of ICCL in ICIC */ 253 + if ((pd->iccl > 0xff) && (pd->flags & IIC_FLAG_HAS_ICIC67)) 254 + pd->icic |= ICIC_ICCLB8; 255 + else 256 + pd->icic &= ~ICIC_ICCLB8; 257 + 258 + pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf, offset); 259 + /* one more bit of ICCH in ICIC */ 260 + if ((pd->icch > 0xff) && (pd->flags & IIC_FLAG_HAS_ICIC67)) 261 + pd->icic |= ICIC_ICCHB8; 262 + else 263 + pd->icic &= ~ICIC_ICCHB8; 264 + 265 + out: 266 + clk_disable(pd->clk); 267 + } 268 + 192 269 static void activate_ch(struct sh_mobile_i2c_data *pd) 193 270 { 194 - unsigned long i2c_clk; 195 - u_int32_t num; 196 - u_int32_t denom; 197 - u_int32_t tmp; 198 - 199 271 /* Wake up device and enable clock */ 200 272 pm_runtime_get_sync(pd->dev); 201 273 clk_enable(pd->clk); 202 - 203 - /* Get clock rate after clock is enabled */ 204 - i2c_clk = clk_get_rate(pd->clk); 205 - 206 - /* Calculate the value for iccl. From the data sheet: 207 - * iccl = (p clock / transfer rate) * (L / (L + H)) 208 - * where L and H are the SCL low/high ratio (5/4 in this case). 209 - * We also round off the result. 210 - */ 211 - num = i2c_clk * 5; 212 - denom = pd->bus_speed * 9; 213 - tmp = num * 10 / denom; 214 - if (tmp % 10 >= 5) 215 - pd->iccl = (u_int8_t)((num/denom) + 1); 216 - else 217 - pd->iccl = (u_int8_t)(num/denom); 218 - 219 - /* one more bit of ICCL in ICIC */ 220 - if (pd->flags & IIC_FLAG_HAS_ICIC67) { 221 - if ((num/denom) > 0xff) 222 - pd->icic |= ICIC_ICCLB8; 223 - else 224 - pd->icic &= ~ICIC_ICCLB8; 225 - } 226 - 227 - /* Calculate the value for icch. From the data sheet: 228 - icch = (p clock / transfer rate) * (H / (L + H)) */ 229 - num = i2c_clk * 4; 230 - tmp = num * 10 / denom; 231 - if (tmp % 10 >= 5) 232 - pd->icch = (u_int8_t)((num/denom) + 1); 233 - else 234 - pd->icch = (u_int8_t)(num/denom); 235 - 236 - /* one more bit of ICCH in ICIC */ 237 - if (pd->flags & IIC_FLAG_HAS_ICIC67) { 238 - if ((num/denom) > 0xff) 239 - pd->icic |= ICIC_ICCHB8; 240 - else 241 - pd->icic &= ~ICIC_ICCHB8; 242 - } 243 274 244 275 /* Enable channel and configure rx ack */ 245 276 iic_set_clr(pd, ICCR, ICCR_ICE, 0); ··· 281 246 iic_wr(pd, ICIC, 0); 282 247 283 248 /* Set the clock */ 284 - iic_wr(pd, ICCL, pd->iccl); 285 - iic_wr(pd, ICCH, pd->icch); 249 + iic_wr(pd, ICCL, pd->iccl & 0xff); 250 + iic_wr(pd, ICCH, pd->icch & 0xff); 286 251 } 287 252 288 253 static void deactivate_ch(struct sh_mobile_i2c_data *pd) ··· 469 434 wake_up(&pd->wait); 470 435 } 471 436 437 + /* defeat write posting to avoid spurious WAIT interrupts */ 438 + iic_rd(pd, ICSR); 439 + 472 440 return IRQ_HANDLED; 473 441 } 474 442 ··· 489 451 iic_set_clr(pd, ICCR, ICCR_ICE, 0); 490 452 491 453 /* Set the clock */ 492 - iic_wr(pd, ICCL, pd->iccl); 493 - iic_wr(pd, ICCH, pd->icch); 454 + iic_wr(pd, ICCL, pd->iccl & 0xff); 455 + iic_wr(pd, ICCH, pd->icch & 0xff); 494 456 495 457 pd->msg = usr_msg; 496 458 pd->pos = -1; ··· 659 621 goto err_irq; 660 622 } 661 623 662 - /* Use platformd data bus speed or NORMAL_SPEED */ 663 - pd->bus_speed = NORMAL_SPEED; 624 + /* Use platform data bus speed or STANDARD_MODE */ 625 + pd->bus_speed = STANDARD_MODE; 664 626 if (pdata && pdata->bus_speed) 665 627 pd->bus_speed = pdata->bus_speed; 628 + pd->clks_per_count = 1; 629 + if (pdata && pdata->clks_per_count) 630 + pd->clks_per_count = pdata->clks_per_count; 666 631 667 632 /* The IIC blocks on SH-Mobile ARM processors 668 633 * come with two new bits in ICIC. 669 634 */ 670 635 if (size > 0x17) 671 636 pd->flags |= IIC_FLAG_HAS_ICIC67; 637 + 638 + sh_mobile_i2c_init(pd); 672 639 673 640 /* Enable Runtime PM for this device. 674 641 * ··· 710 667 goto err_all; 711 668 } 712 669 713 - dev_info(&dev->dev, "I2C adapter %d with bus speed %lu Hz\n", 714 - adap->nr, pd->bus_speed); 670 + dev_info(&dev->dev, 671 + "I2C adapter %d with bus speed %lu Hz (L/H=%x/%x)\n", 672 + adap->nr, pd->bus_speed, pd->iccl, pd->icch); 715 673 716 674 of_i2c_register_devices(adap); 717 675 return 0;
+114 -31
drivers/i2c/muxes/i2c-mux-gpio.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/gpio.h> 19 + #include <linux/of_i2c.h> 20 + #include <linux/of_gpio.h> 19 21 20 22 struct gpiomux { 21 23 struct i2c_adapter *parent; ··· 59 57 return !strcmp(chip->label, data); 60 58 } 61 59 60 + #ifdef CONFIG_OF 61 + static int __devinit i2c_mux_gpio_probe_dt(struct gpiomux *mux, 62 + struct platform_device *pdev) 63 + { 64 + struct device_node *np = pdev->dev.of_node; 65 + struct device_node *adapter_np, *child; 66 + struct i2c_adapter *adapter; 67 + unsigned *values, *gpios; 68 + int i = 0; 69 + 70 + if (!np) 71 + return -ENODEV; 72 + 73 + adapter_np = of_parse_phandle(np, "i2c-parent", 0); 74 + if (!adapter_np) { 75 + dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); 76 + return -ENODEV; 77 + } 78 + adapter = of_find_i2c_adapter_by_node(adapter_np); 79 + if (!adapter) { 80 + dev_err(&pdev->dev, "Cannot find parent bus\n"); 81 + return -ENODEV; 82 + } 83 + mux->data.parent = i2c_adapter_id(adapter); 84 + put_device(&adapter->dev); 85 + 86 + mux->data.n_values = of_get_child_count(np); 87 + 88 + values = devm_kzalloc(&pdev->dev, 89 + sizeof(*mux->data.values) * mux->data.n_values, 90 + GFP_KERNEL); 91 + if (!values) { 92 + dev_err(&pdev->dev, "Cannot allocate values array"); 93 + return -ENOMEM; 94 + } 95 + 96 + for_each_child_of_node(np, child) { 97 + of_property_read_u32(child, "reg", values + i); 98 + i++; 99 + } 100 + mux->data.values = values; 101 + 102 + if (of_property_read_u32(np, "idle-state", &mux->data.idle)) 103 + mux->data.idle = I2C_MUX_GPIO_NO_IDLE; 104 + 105 + mux->data.n_gpios = of_gpio_named_count(np, "mux-gpios"); 106 + if (mux->data.n_gpios < 0) { 107 + dev_err(&pdev->dev, "Missing mux-gpios property in the DT.\n"); 108 + return -EINVAL; 109 + } 110 + 111 + gpios = devm_kzalloc(&pdev->dev, 112 + sizeof(*mux->data.gpios) * mux->data.n_gpios, GFP_KERNEL); 113 + if (!gpios) { 114 + dev_err(&pdev->dev, "Cannot allocate gpios array"); 115 + return -ENOMEM; 116 + } 117 + 118 + for (i = 0; i < mux->data.n_gpios; i++) 119 + gpios[i] = of_get_named_gpio(np, "mux-gpios", i); 120 + 121 + mux->data.gpios = gpios; 122 + 123 + return 0; 124 + } 125 + #else 126 + static int __devinit i2c_mux_gpio_probe_dt(struct gpiomux *mux, 127 + struct platform_device *pdev) 128 + { 129 + return 0; 130 + } 131 + #endif 132 + 62 133 static int __devinit i2c_mux_gpio_probe(struct platform_device *pdev) 63 134 { 64 135 struct gpiomux *mux; 65 - struct i2c_mux_gpio_platform_data *pdata; 66 136 struct i2c_adapter *parent; 67 137 int (*deselect) (struct i2c_adapter *, void *, u32); 68 138 unsigned initial_state, gpio_base; 69 139 int i, ret; 70 140 71 - pdata = pdev->dev.platform_data; 72 - if (!pdata) { 73 - dev_err(&pdev->dev, "Missing platform data\n"); 74 - return -ENODEV; 141 + mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); 142 + if (!mux) { 143 + dev_err(&pdev->dev, "Cannot allocate gpiomux structure"); 144 + return -ENOMEM; 75 145 } 146 + 147 + platform_set_drvdata(pdev, mux); 148 + 149 + if (!pdev->dev.platform_data) { 150 + ret = i2c_mux_gpio_probe_dt(mux, pdev); 151 + if (ret < 0) 152 + return ret; 153 + } else 154 + memcpy(&mux->data, pdev->dev.platform_data, sizeof(mux->data)); 76 155 77 156 /* 78 157 * If a GPIO chip name is provided, the GPIO pin numbers provided are 79 158 * relative to its base GPIO number. Otherwise they are absolute. 80 159 */ 81 - if (pdata->gpio_chip) { 160 + if (mux->data.gpio_chip) { 82 161 struct gpio_chip *gpio; 83 162 84 - gpio = gpiochip_find(pdata->gpio_chip, 163 + gpio = gpiochip_find(mux->data.gpio_chip, 85 164 match_gpio_chip_by_label); 86 165 if (!gpio) 87 166 return -EPROBE_DEFER; ··· 172 89 gpio_base = 0; 173 90 } 174 91 175 - parent = i2c_get_adapter(pdata->parent); 92 + parent = i2c_get_adapter(mux->data.parent); 176 93 if (!parent) { 177 94 dev_err(&pdev->dev, "Parent adapter (%d) not found\n", 178 - pdata->parent); 95 + mux->data.parent); 179 96 return -ENODEV; 180 97 } 181 98 182 - mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); 183 - if (!mux) { 184 - ret = -ENOMEM; 185 - goto alloc_failed; 186 - } 187 - 188 99 mux->parent = parent; 189 - mux->data = *pdata; 190 100 mux->gpio_base = gpio_base; 101 + 191 102 mux->adap = devm_kzalloc(&pdev->dev, 192 - sizeof(*mux->adap) * pdata->n_values, 103 + sizeof(*mux->adap) * mux->data.n_values, 193 104 GFP_KERNEL); 194 105 if (!mux->adap) { 106 + dev_err(&pdev->dev, "Cannot allocate i2c_adapter structure"); 195 107 ret = -ENOMEM; 196 108 goto alloc_failed; 197 109 } 198 110 199 - if (pdata->idle != I2C_MUX_GPIO_NO_IDLE) { 200 - initial_state = pdata->idle; 111 + if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) { 112 + initial_state = mux->data.idle; 201 113 deselect = i2c_mux_gpio_deselect; 202 114 } else { 203 - initial_state = pdata->values[0]; 115 + initial_state = mux->data.values[0]; 204 116 deselect = NULL; 205 117 } 206 118 207 - for (i = 0; i < pdata->n_gpios; i++) { 208 - ret = gpio_request(gpio_base + pdata->gpios[i], "i2c-mux-gpio"); 119 + for (i = 0; i < mux->data.n_gpios; i++) { 120 + ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); 209 121 if (ret) 210 122 goto err_request_gpio; 211 - gpio_direction_output(gpio_base + pdata->gpios[i], 123 + gpio_direction_output(gpio_base + mux->data.gpios[i], 212 124 initial_state & (1 << i)); 213 125 } 214 126 215 - for (i = 0; i < pdata->n_values; i++) { 216 - u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0; 217 - unsigned int class = pdata->classes ? pdata->classes[i] : 0; 127 + for (i = 0; i < mux->data.n_values; i++) { 128 + u32 nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; 129 + unsigned int class = mux->data.classes ? mux->data.classes[i] : 0; 218 130 219 131 mux->adap[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, nr, 220 132 i, class, ··· 222 144 } 223 145 224 146 dev_info(&pdev->dev, "%d port mux on %s adapter\n", 225 - pdata->n_values, parent->name); 226 - 227 - platform_set_drvdata(pdev, mux); 147 + mux->data.n_values, parent->name); 228 148 229 149 return 0; 230 150 231 151 add_adapter_failed: 232 152 for (; i > 0; i--) 233 153 i2c_del_mux_adapter(mux->adap[i - 1]); 234 - i = pdata->n_gpios; 154 + i = mux->data.n_gpios; 235 155 err_request_gpio: 236 156 for (; i > 0; i--) 237 - gpio_free(gpio_base + pdata->gpios[i - 1]); 157 + gpio_free(gpio_base + mux->data.gpios[i - 1]); 238 158 alloc_failed: 239 159 i2c_put_adapter(parent); 240 160 ··· 256 180 return 0; 257 181 } 258 182 183 + static const struct of_device_id i2c_mux_gpio_of_match[] __devinitconst = { 184 + { .compatible = "i2c-mux-gpio", }, 185 + {}, 186 + }; 187 + MODULE_DEVICE_TABLE(of, i2c_mux_gpio_of_match); 188 + 259 189 static struct platform_driver i2c_mux_gpio_driver = { 260 190 .probe = i2c_mux_gpio_probe, 261 191 .remove = __devexit_p(i2c_mux_gpio_remove), 262 192 .driver = { 263 193 .owner = THIS_MODULE, 264 194 .name = "i2c-mux-gpio", 195 + .of_match_table = of_match_ptr(i2c_mux_gpio_of_match), 265 196 }, 266 197 }; 267 198
-2
include/linux/i2c-omap.h
··· 20 20 #define OMAP_I2C_FLAG_NO_FIFO BIT(0) 21 21 #define OMAP_I2C_FLAG_SIMPLE_CLOCK BIT(1) 22 22 #define OMAP_I2C_FLAG_16BIT_DATA_REG BIT(2) 23 - #define OMAP_I2C_FLAG_RESET_REGS_POSTIDLE BIT(3) 24 - #define OMAP_I2C_FLAG_APPLY_ERRATA_I207 BIT(4) 25 23 #define OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK BIT(5) 26 24 #define OMAP_I2C_FLAG_FORCE_19200_INT_CLK BIT(6) 27 25 /* how the CPU address bus must be translated for I2C unit access */
+1
include/linux/i2c/i2c-sh_mobile.h
··· 5 5 6 6 struct i2c_sh_mobile_platform_data { 7 7 unsigned long bus_speed; 8 + unsigned int clks_per_count; 8 9 }; 9 10 10 11 #endif /* __I2C_SH_MOBILE_H__ */
+27
include/linux/platform_data/i2c-cbus-gpio.h
··· 1 + /* 2 + * i2c-cbus-gpio.h - CBUS I2C platform_data definition 3 + * 4 + * Copyright (C) 2004-2009 Nokia Corporation 5 + * 6 + * Written by Felipe Balbi and Aaro Koskinen. 7 + * 8 + * This file is subject to the terms and conditions of the GNU General 9 + * Public License. See the file "COPYING" in the main directory of this 10 + * archive for more details. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #ifndef __INCLUDE_LINUX_I2C_CBUS_GPIO_H 19 + #define __INCLUDE_LINUX_I2C_CBUS_GPIO_H 20 + 21 + struct i2c_cbus_platform_data { 22 + int dat_gpio; 23 + int clk_gpio; 24 + int sel_gpio; 25 + }; 26 + 27 + #endif /* __INCLUDE_LINUX_I2C_CBUS_GPIO_H */