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:
"Highlights:

- new drivers for Intel ismt & Broadcom bcm2835
- a number of drivers got support for more variants and mostly got
cleaned up on the way (sis630, i801, at91, tegra, designware)
- i2c got rid of all *_set_drvdata(..., NULL) on remove/probe failure
- removed the i2c_smbus_process_call from the core since there are no
users
- mxs can now switch between PIO and DMA depending on the message
size and the bus speed can now be arbitrary

In addition, there is the usual bunch of fixes, cleanups, devm_*
conversions, etc"

Fixed conflict (and buggy devm_* conversion) in i2c-s3c2410.c

* 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (39 commits)
i2c: Remove unneeded xxx_set_drvdata(..., NULL) calls
i2c: pxa: remove incorrect __exit annotations
i2c: ocores: Fix pointer to integer cast warning
i2c: tegra: remove warning dump if timeout happen in transfer
i2c: fix i2c-ismt.c printk format warning
i2c: i801: Add Device IDs for Intel Wellsburg PCH
i2c: add bcm2835 driver
i2c: ismt: Add Seth and Myself as maintainers
i2c: sis630: checkpatch cleanup
i2c: sis630: display unsigned hex
i2c: sis630: use hex to constants for SMBus commands
i2c: sis630: fix behavior after collision
i2c: sis630: clear sticky bits
i2c: sis630: Add SIS964 support
i2c: isch: Add module parameter for backbone clock rate if divider is unset
i2c: at91: fix unsed variable warning when building with !CONFIG_OF
i2c: Adding support for Intel iSMT SMBus 2.0 host controller
i2c: sh_mobile: don't send a stop condition by default inside transfers
i2c: sh_mobile: eliminate an open-coded "goto" loop
i2c: sh_mobile: fix timeout error handling
...

+2314 -518
+20
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt
··· 1 + Broadcom BCM2835 I2C controller 2 + 3 + Required properties: 4 + - compatible : Should be "brcm,bcm2835-i2c". 5 + - reg: Should contain register location and length. 6 + - interrupts: Should contain interrupt. 7 + - clocks : The clock feeding the I2C controller. 8 + 9 + Recommended properties: 10 + - clock-frequency : desired I2C bus clock frequency in Hz. 11 + 12 + Example: 13 + 14 + i2c@20205000 { 15 + compatible = "brcm,bcm2835-i2c"; 16 + reg = <0x7e205000 0x1000>; 17 + interrupts = <2 21>; 18 + clocks = <&clk_i2c>; 19 + clock-frequency = <100000>; 20 + };
+2
Documentation/devicetree/bindings/i2c/i2c-s3c2410.txt
··· 8 8 (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c. 9 9 (c) "samsung, s3c2440-hdmiphy-i2c", for s3c2440-like i2c used 10 10 inside HDMIPHY block found on several samsung SoCs 11 + (d) "samsung, exynos5440-i2c", for s3c2440-like i2c used 12 + on EXYNOS5440 which does not need GPIO configuration. 11 13 - reg: physical base address of the controller and length of memory mapped 12 14 region. 13 15 - interrupts: interrupt number to the cpu.
+2
Documentation/i2c/busses/i2c-i801
··· 22 22 * Intel Panther Point (PCH) 23 23 * Intel Lynx Point (PCH) 24 24 * Intel Lynx Point-LP (PCH) 25 + * Intel Avoton (SOC) 26 + * Intel Wellsburg (PCH) 25 27 Datasheets: Publicly available at the Intel website 26 28 27 29 On Intel Patsburg and later chipsets, both the normal host SMBus controller
+36
Documentation/i2c/busses/i2c-ismt
··· 1 + Kernel driver i2c-ismt 2 + 3 + Supported adapters: 4 + * Intel S12xx series SOCs 5 + 6 + Authors: 7 + Bill Brown <bill.e.brown@intel.com> 8 + 9 + 10 + Module Parameters 11 + ----------------- 12 + 13 + * bus_speed (unsigned int) 14 + Allows changing of the bus speed. Normally, the bus speed is set by the BIOS 15 + and never needs to be changed. However, some SMBus analyzers are too slow for 16 + monitoring the bus during debug, thus the need for this module parameter. 17 + Specify the bus speed in kHz. 18 + Available bus frequency settings: 19 + 0 no change 20 + 80 kHz 21 + 100 kHz 22 + 400 kHz 23 + 1000 kHz 24 + 25 + 26 + Description 27 + ----------- 28 + 29 + The S12xx series of SOCs have a pair of integrated SMBus 2.0 controllers 30 + targeted primarily at the microserver and storage markets. 31 + 32 + The S12xx series contain a pair of PCI functions. An output of lspci will show 33 + something similar to the following: 34 + 35 + 00:13.0 System peripheral: Intel Corporation Centerton SMBus 2.0 Controller 0 36 + 00:13.1 System peripheral: Intel Corporation Centerton SMBus 2.0 Controller 1
+9
Documentation/i2c/busses/i2c-sis630
··· 4 4 * Silicon Integrated Systems Corp (SiS) 5 5 630 chipset (Datasheet: available at http://www.sfr-fresh.com/linux) 6 6 730 chipset 7 + 964 chipset 7 8 * Possible other SiS chipsets ? 8 9 9 10 Author: Alexander Malysh <amalysh@web.de> 11 + Amaury Decrême <amaury.decreme@gmail.com> - SiS964 support 10 12 11 13 Module Parameters 12 14 ----------------- ··· 20 18 * high_clock = [1|0] Forcibly set Host Master Clock to 56KHz (default, 21 19 what your BIOS use). DANGEROUS! This should be a bit 22 20 faster, but freeze some systems (i.e. my Laptop). 21 + SIS630/730 chip only. 23 22 24 23 25 24 Description ··· 38 35 39 36 00:00.0 Host bridge: Silicon Integrated Systems [SiS] 730 Host (rev 02) 40 37 00:01.0 ISA bridge: Silicon Integrated Systems [SiS] 85C503/5513 38 + 39 + or like this: 40 + 41 + 00:00.0 Host bridge: Silicon Integrated Systems [SiS] 760/M760 Host (rev 02) 42 + 00:02.0 ISA bridge: Silicon Integrated Systems [SiS] SiS964 [MuTIOL Media IO] 43 + LPC Controller (rev 36) 41 44 42 45 in your 'lspci' output , then this driver is for your chipset. 43 46
+2 -2
Documentation/i2c/smbus-protocol
··· 137 137 around (not SMBus compliant, but very popular.) 138 138 139 139 140 - SMBus Process Call: i2c_smbus_process_call() 141 - ============================================= 140 + SMBus Process Call: 141 + =================== 142 142 143 143 This command selects a device register (through the Comm byte), sends 144 144 16 bits of data to it, and reads 16 bits of data in return.
+2 -2
Documentation/i2c/writing-clients
··· 365 365 s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command); 366 366 s32 i2c_smbus_write_word_data(struct i2c_client *client, 367 367 u8 command, u16 value); 368 - s32 i2c_smbus_process_call(struct i2c_client *client, 369 - u8 command, u16 value); 370 368 s32 i2c_smbus_read_block_data(struct i2c_client *client, 371 369 u8 command, u8 *values); 372 370 s32 i2c_smbus_write_block_data(struct i2c_client *client, ··· 379 381 be added back later if needed: 380 382 381 383 s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value); 384 + s32 i2c_smbus_process_call(struct i2c_client *client, 385 + u8 command, u16 value); 382 386 s32 i2c_smbus_block_process_call(struct i2c_client *client, 383 387 u8 command, u8 length, u8 *values); 384 388
+7
MAINTAINERS
··· 3852 3852 F: drivers/i2c/busses/i2c-via.c 3853 3853 F: drivers/i2c/busses/i2c-viapro.c 3854 3854 3855 + I2C/SMBUS ISMT DRIVER 3856 + M: Seth Heasley <seth.heasley@intel.com> 3857 + M: Neil Horman <nhorman@tuxdriver.com> 3858 + L: linux-i2c@vger.kernel.org 3859 + F: drivers/i2c/busses/i2c-ismt.c 3860 + F: Documentation/i2c/busses/i2c-ismt 3861 + 3855 3862 I2C/SMBUS STUB DRIVER 3856 3863 M: "Mark M. Hoffman" <mhoffman@lightlink.com> 3857 3864 L: linux-i2c@vger.kernel.org
+26 -2
drivers/i2c/busses/Kconfig
··· 106 106 Panther Point (PCH) 107 107 Lynx Point (PCH) 108 108 Lynx Point-LP (PCH) 109 + Avoton (SOC) 110 + Wellsburg (PCH) 109 111 110 112 This driver can also be built as a module. If so, the module 111 113 will be called i2c-i801. ··· 122 120 123 121 This driver can also be built as a module. If so, the module 124 122 will be called i2c-isch. 123 + 124 + config I2C_ISMT 125 + tristate "Intel iSMT SMBus Controller" 126 + depends on PCI && X86 127 + help 128 + If you say yes to this option, support will be included for the Intel 129 + iSMT SMBus host controller interface. 130 + 131 + This driver can also be built as a module. If so, the module will be 132 + called i2c-ismt. 125 133 126 134 config I2C_PIIX4 127 135 tristate "Intel PIIX4 and compatible (ATI/AMD/Serverworks/Broadcom/SMSC)" ··· 198 186 will be called i2c-sis5595. 199 187 200 188 config I2C_SIS630 201 - tristate "SiS 630/730" 189 + tristate "SiS 630/730/964" 202 190 depends on PCI 203 191 help 204 192 If you say yes to this option, support will be included for the 205 - SiS630 and SiS730 SMBus (a subset of I2C) interface. 193 + SiS630, SiS730 and SiS964 SMBus (a subset of I2C) interface. 206 194 207 195 This driver can also be built as a module. If so, the module 208 196 will be called i2c-sis630. ··· 330 318 331 319 This driver can also be built as a module. If so, the module 332 320 will be called i2c-au1550. 321 + 322 + config I2C_BCM2835 323 + tristate "Broadcom BCM2835 I2C controller" 324 + depends on ARCH_BCM2835 325 + help 326 + If you say yes to this option, support will be included for the 327 + BCM2835 I2C controller. 328 + 329 + If you don't know what to do here, say N. 330 + 331 + This support is also available as a module. If so, the module 332 + will be called i2c-bcm2835. 333 333 334 334 config I2C_BLACKFIN_TWI 335 335 tristate "Blackfin TWI I2C support"
+2
drivers/i2c/busses/Makefile
··· 14 14 obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 15 15 obj-$(CONFIG_I2C_I801) += i2c-i801.o 16 16 obj-$(CONFIG_I2C_ISCH) += i2c-isch.o 17 + obj-$(CONFIG_I2C_ISMT) += i2c-ismt.o 17 18 obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 18 19 obj-$(CONFIG_I2C_NFORCE2_S4985) += i2c-nforce2-s4985.o 19 20 obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o ··· 31 30 # Embedded system I2C/SMBus host controller drivers 32 31 obj-$(CONFIG_I2C_AT91) += i2c-at91.o 33 32 obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 33 + obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o 34 34 obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o 35 35 obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o 36 36 obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
+10 -7
drivers/i2c/busses/i2c-at91.c
··· 553 553 .has_dma_support = false, 554 554 }; 555 555 556 - static struct at91_twi_pdata at91sam9x5_config = { 557 - .clk_max_div = 7, 558 - .clk_offset = 4, 559 - .has_unre_flag = false, 560 - .has_dma_support = true, 561 - }; 562 - 563 556 static const struct platform_device_id at91_twi_devtypes[] = { 564 557 { 565 558 .name = "i2c-at91rm9200", ··· 575 582 }; 576 583 577 584 #if defined(CONFIG_OF) 585 + static struct at91_twi_pdata at91sam9x5_config = { 586 + .clk_max_div = 7, 587 + .clk_offset = 4, 588 + .has_unre_flag = false, 589 + .has_dma_support = true, 590 + }; 591 + 578 592 static const struct of_device_id atmel_twi_dt_ids[] = { 579 593 { 594 + .compatible = "atmel,at91rm9200-i2c", 595 + .data = &at91rm9200_config, 596 + } , { 580 597 .compatible = "atmel,at91sam9260-i2c", 581 598 .data = &at91sam9260_config, 582 599 } , {
-1
drivers/i2c/busses/i2c-au1550.c
··· 376 376 { 377 377 struct i2c_au1550_data *priv = platform_get_drvdata(pdev); 378 378 379 - platform_set_drvdata(pdev, NULL); 380 379 i2c_del_adapter(&priv->adap); 381 380 i2c_au1550_disable(priv); 382 381 iounmap(priv->psc_base);
+342
drivers/i2c/busses/i2c-bcm2835.c
··· 1 + /* 2 + * BCM2835 master mode driver 3 + * 4 + * This software is licensed under the terms of the GNU General Public 5 + * License version 2, as published by the Free Software Foundation, and 6 + * may be copied, distributed, and modified under those terms. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #include <linux/clk.h> 15 + #include <linux/completion.h> 16 + #include <linux/err.h> 17 + #include <linux/i2c.h> 18 + #include <linux/interrupt.h> 19 + #include <linux/io.h> 20 + #include <linux/module.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/slab.h> 23 + 24 + #define BCM2835_I2C_C 0x0 25 + #define BCM2835_I2C_S 0x4 26 + #define BCM2835_I2C_DLEN 0x8 27 + #define BCM2835_I2C_A 0xc 28 + #define BCM2835_I2C_FIFO 0x10 29 + #define BCM2835_I2C_DIV 0x14 30 + #define BCM2835_I2C_DEL 0x18 31 + #define BCM2835_I2C_CLKT 0x1c 32 + 33 + #define BCM2835_I2C_C_READ BIT(0) 34 + #define BCM2835_I2C_C_CLEAR BIT(4) /* bits 4 and 5 both clear */ 35 + #define BCM2835_I2C_C_ST BIT(7) 36 + #define BCM2835_I2C_C_INTD BIT(8) 37 + #define BCM2835_I2C_C_INTT BIT(9) 38 + #define BCM2835_I2C_C_INTR BIT(10) 39 + #define BCM2835_I2C_C_I2CEN BIT(15) 40 + 41 + #define BCM2835_I2C_S_TA BIT(0) 42 + #define BCM2835_I2C_S_DONE BIT(1) 43 + #define BCM2835_I2C_S_TXW BIT(2) 44 + #define BCM2835_I2C_S_RXR BIT(3) 45 + #define BCM2835_I2C_S_TXD BIT(4) 46 + #define BCM2835_I2C_S_RXD BIT(5) 47 + #define BCM2835_I2C_S_TXE BIT(6) 48 + #define BCM2835_I2C_S_RXF BIT(7) 49 + #define BCM2835_I2C_S_ERR BIT(8) 50 + #define BCM2835_I2C_S_CLKT BIT(9) 51 + #define BCM2835_I2C_S_LEN BIT(10) /* Fake bit for SW error reporting */ 52 + 53 + #define BCM2835_I2C_TIMEOUT (msecs_to_jiffies(1000)) 54 + 55 + struct bcm2835_i2c_dev { 56 + struct device *dev; 57 + void __iomem *regs; 58 + struct clk *clk; 59 + int irq; 60 + struct i2c_adapter adapter; 61 + struct completion completion; 62 + u32 msg_err; 63 + u8 *msg_buf; 64 + size_t msg_buf_remaining; 65 + }; 66 + 67 + static inline void bcm2835_i2c_writel(struct bcm2835_i2c_dev *i2c_dev, 68 + u32 reg, u32 val) 69 + { 70 + writel(val, i2c_dev->regs + reg); 71 + } 72 + 73 + static inline u32 bcm2835_i2c_readl(struct bcm2835_i2c_dev *i2c_dev, u32 reg) 74 + { 75 + return readl(i2c_dev->regs + reg); 76 + } 77 + 78 + static void bcm2835_fill_txfifo(struct bcm2835_i2c_dev *i2c_dev) 79 + { 80 + u32 val; 81 + 82 + while (i2c_dev->msg_buf_remaining) { 83 + val = bcm2835_i2c_readl(i2c_dev, BCM2835_I2C_S); 84 + if (!(val & BCM2835_I2C_S_TXD)) 85 + break; 86 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_FIFO, 87 + *i2c_dev->msg_buf); 88 + i2c_dev->msg_buf++; 89 + i2c_dev->msg_buf_remaining--; 90 + } 91 + } 92 + 93 + static void bcm2835_drain_rxfifo(struct bcm2835_i2c_dev *i2c_dev) 94 + { 95 + u32 val; 96 + 97 + while (i2c_dev->msg_buf_remaining) { 98 + val = bcm2835_i2c_readl(i2c_dev, BCM2835_I2C_S); 99 + if (!(val & BCM2835_I2C_S_RXD)) 100 + break; 101 + *i2c_dev->msg_buf = bcm2835_i2c_readl(i2c_dev, 102 + BCM2835_I2C_FIFO); 103 + i2c_dev->msg_buf++; 104 + i2c_dev->msg_buf_remaining--; 105 + } 106 + } 107 + 108 + static irqreturn_t bcm2835_i2c_isr(int this_irq, void *data) 109 + { 110 + struct bcm2835_i2c_dev *i2c_dev = data; 111 + u32 val, err; 112 + 113 + val = bcm2835_i2c_readl(i2c_dev, BCM2835_I2C_S); 114 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_S, val); 115 + 116 + err = val & (BCM2835_I2C_S_CLKT | BCM2835_I2C_S_ERR); 117 + if (err) { 118 + i2c_dev->msg_err = err; 119 + complete(&i2c_dev->completion); 120 + return IRQ_HANDLED; 121 + } 122 + 123 + if (val & BCM2835_I2C_S_RXD) { 124 + bcm2835_drain_rxfifo(i2c_dev); 125 + if (!(val & BCM2835_I2C_S_DONE)) 126 + return IRQ_HANDLED; 127 + } 128 + 129 + if (val & BCM2835_I2C_S_DONE) { 130 + if (i2c_dev->msg_buf_remaining) 131 + i2c_dev->msg_err = BCM2835_I2C_S_LEN; 132 + else 133 + i2c_dev->msg_err = 0; 134 + complete(&i2c_dev->completion); 135 + return IRQ_HANDLED; 136 + } 137 + 138 + if (val & BCM2835_I2C_S_TXD) { 139 + bcm2835_fill_txfifo(i2c_dev); 140 + return IRQ_HANDLED; 141 + } 142 + 143 + return IRQ_NONE; 144 + } 145 + 146 + static int bcm2835_i2c_xfer_msg(struct bcm2835_i2c_dev *i2c_dev, 147 + struct i2c_msg *msg) 148 + { 149 + u32 c; 150 + int time_left; 151 + 152 + i2c_dev->msg_buf = msg->buf; 153 + i2c_dev->msg_buf_remaining = msg->len; 154 + INIT_COMPLETION(i2c_dev->completion); 155 + 156 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, BCM2835_I2C_C_CLEAR); 157 + 158 + if (msg->flags & I2C_M_RD) { 159 + c = BCM2835_I2C_C_READ | BCM2835_I2C_C_INTR; 160 + } else { 161 + c = BCM2835_I2C_C_INTT; 162 + bcm2835_fill_txfifo(i2c_dev); 163 + } 164 + c |= BCM2835_I2C_C_ST | BCM2835_I2C_C_INTD | BCM2835_I2C_C_I2CEN; 165 + 166 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_A, msg->addr); 167 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DLEN, msg->len); 168 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, c); 169 + 170 + time_left = wait_for_completion_timeout(&i2c_dev->completion, 171 + BCM2835_I2C_TIMEOUT); 172 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, BCM2835_I2C_C_CLEAR); 173 + if (!time_left) { 174 + dev_err(i2c_dev->dev, "i2c transfer timed out\n"); 175 + return -ETIMEDOUT; 176 + } 177 + 178 + if (likely(!i2c_dev->msg_err)) 179 + return 0; 180 + 181 + if ((i2c_dev->msg_err & BCM2835_I2C_S_ERR) && 182 + (msg->flags & I2C_M_IGNORE_NAK)) 183 + return 0; 184 + 185 + dev_err(i2c_dev->dev, "i2c transfer failed: %x\n", i2c_dev->msg_err); 186 + 187 + if (i2c_dev->msg_err & BCM2835_I2C_S_ERR) 188 + return -EREMOTEIO; 189 + else 190 + return -EIO; 191 + } 192 + 193 + static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], 194 + int num) 195 + { 196 + struct bcm2835_i2c_dev *i2c_dev = i2c_get_adapdata(adap); 197 + int i; 198 + int ret = 0; 199 + 200 + for (i = 0; i < num; i++) { 201 + ret = bcm2835_i2c_xfer_msg(i2c_dev, &msgs[i]); 202 + if (ret) 203 + break; 204 + } 205 + 206 + return ret ?: i; 207 + } 208 + 209 + static u32 bcm2835_i2c_func(struct i2c_adapter *adap) 210 + { 211 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 212 + } 213 + 214 + static const struct i2c_algorithm bcm2835_i2c_algo = { 215 + .master_xfer = bcm2835_i2c_xfer, 216 + .functionality = bcm2835_i2c_func, 217 + }; 218 + 219 + static int bcm2835_i2c_probe(struct platform_device *pdev) 220 + { 221 + struct bcm2835_i2c_dev *i2c_dev; 222 + struct resource *mem, *requested, *irq; 223 + u32 bus_clk_rate, divider; 224 + int ret; 225 + struct i2c_adapter *adap; 226 + 227 + i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 228 + if (!i2c_dev) { 229 + dev_err(&pdev->dev, "Cannot allocate i2c_dev\n"); 230 + return -ENOMEM; 231 + } 232 + platform_set_drvdata(pdev, i2c_dev); 233 + i2c_dev->dev = &pdev->dev; 234 + init_completion(&i2c_dev->completion); 235 + 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 + } 256 + 257 + i2c_dev->clk = devm_clk_get(&pdev->dev, NULL); 258 + if (IS_ERR(i2c_dev->clk)) { 259 + dev_err(&pdev->dev, "Could not get clock\n"); 260 + return PTR_ERR(i2c_dev->clk); 261 + } 262 + 263 + ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", 264 + &bus_clk_rate); 265 + if (ret < 0) { 266 + dev_warn(&pdev->dev, 267 + "Could not read clock-frequency property\n"); 268 + bus_clk_rate = 100000; 269 + } 270 + 271 + divider = DIV_ROUND_UP(clk_get_rate(i2c_dev->clk), bus_clk_rate); 272 + /* 273 + * Per the datasheet, the register is always interpreted as an even 274 + * number, by rounding down. In other words, the LSB is ignored. So, 275 + * if the LSB is set, increment the divider to avoid any issue. 276 + */ 277 + if (divider & 1) 278 + divider++; 279 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider); 280 + 281 + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 282 + if (!irq) { 283 + dev_err(&pdev->dev, "No IRQ resource\n"); 284 + return -ENODEV; 285 + } 286 + i2c_dev->irq = irq->start; 287 + 288 + ret = request_irq(i2c_dev->irq, bcm2835_i2c_isr, IRQF_SHARED, 289 + dev_name(&pdev->dev), i2c_dev); 290 + if (ret) { 291 + dev_err(&pdev->dev, "Could not request IRQ\n"); 292 + return -ENODEV; 293 + } 294 + 295 + adap = &i2c_dev->adapter; 296 + i2c_set_adapdata(adap, i2c_dev); 297 + adap->owner = THIS_MODULE; 298 + adap->class = I2C_CLASS_HWMON; 299 + strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name)); 300 + adap->algo = &bcm2835_i2c_algo; 301 + adap->dev.parent = &pdev->dev; 302 + 303 + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, 0); 304 + 305 + ret = i2c_add_adapter(adap); 306 + if (ret) 307 + free_irq(i2c_dev->irq, i2c_dev); 308 + 309 + return ret; 310 + } 311 + 312 + static int bcm2835_i2c_remove(struct platform_device *pdev) 313 + { 314 + struct bcm2835_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 315 + 316 + free_irq(i2c_dev->irq, i2c_dev); 317 + i2c_del_adapter(&i2c_dev->adapter); 318 + 319 + return 0; 320 + } 321 + 322 + static const struct of_device_id bcm2835_i2c_of_match[] = { 323 + { .compatible = "brcm,bcm2835-i2c" }, 324 + {}, 325 + }; 326 + MODULE_DEVICE_TABLE(of, bcm2835_i2c_of_match); 327 + 328 + static struct platform_driver bcm2835_i2c_driver = { 329 + .probe = bcm2835_i2c_probe, 330 + .remove = bcm2835_i2c_remove, 331 + .driver = { 332 + .name = "i2c-bcm2835", 333 + .owner = THIS_MODULE, 334 + .of_match_table = bcm2835_i2c_of_match, 335 + }, 336 + }; 337 + module_platform_driver(bcm2835_i2c_driver); 338 + 339 + MODULE_AUTHOR("Stephen Warren <swarren@wwwdotorg.org>"); 340 + MODULE_DESCRIPTION("BCM2835 I2C bus adapter"); 341 + MODULE_LICENSE("GPL v2"); 342 + MODULE_ALIAS("platform:i2c-bcm2835");
-2
drivers/i2c/busses/i2c-bfin-twi.c
··· 724 724 { 725 725 struct bfin_twi_iface *iface = platform_get_drvdata(pdev); 726 726 727 - platform_set_drvdata(pdev, NULL); 728 - 729 727 i2c_del_adapter(&(iface->adap)); 730 728 free_irq(iface->irq, iface); 731 729 peripheral_free_list((unsigned short *)pdev->dev.platform_data);
-2
drivers/i2c/busses/i2c-cpm.c
··· 682 682 out_shut: 683 683 cpm_i2c_shutdown(cpm); 684 684 out_free: 685 - dev_set_drvdata(&ofdev->dev, NULL); 686 685 kfree(cpm); 687 686 688 687 return result; ··· 695 696 696 697 cpm_i2c_shutdown(cpm); 697 698 698 - dev_set_drvdata(&ofdev->dev, NULL); 699 699 kfree(cpm); 700 700 701 701 return 0;
-2
drivers/i2c/busses/i2c-davinci.c
··· 755 755 clk_put(dev->clk); 756 756 dev->clk = NULL; 757 757 err_free_mem: 758 - platform_set_drvdata(pdev, NULL); 759 758 put_device(&pdev->dev); 760 759 kfree(dev); 761 760 err_release_region: ··· 770 771 771 772 i2c_davinci_cpufreq_deregister(dev); 772 773 773 - platform_set_drvdata(pdev, NULL); 774 774 i2c_del_adapter(&dev->adapter); 775 775 put_device(&pdev->dev); 776 776
+14 -2
drivers/i2c/busses/i2c-designware-core.c
··· 413 413 rx_limit = dev->rx_fifo_depth - dw_readl(dev, DW_IC_RXFLR); 414 414 415 415 while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { 416 + u32 cmd = 0; 417 + 418 + /* 419 + * If IC_EMPTYFIFO_HOLD_MASTER_EN is set we must 420 + * manually set the stop bit. However, it cannot be 421 + * detected from the registers so we set it always 422 + * when writing/reading the last byte. 423 + */ 424 + if (dev->msg_write_idx == dev->msgs_num - 1 && 425 + buf_len == 1) 426 + cmd |= BIT(9); 427 + 416 428 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { 417 - dw_writel(dev, 0x100, DW_IC_DATA_CMD); 429 + dw_writel(dev, cmd | 0x100, DW_IC_DATA_CMD); 418 430 rx_limit--; 419 431 } else 420 - dw_writel(dev, *buf++, DW_IC_DATA_CMD); 432 + dw_writel(dev, cmd | *buf++, DW_IC_DATA_CMD); 421 433 tx_limit--; buf_len--; 422 434 } 423 435
-2
drivers/i2c/busses/i2c-designware-pcidrv.c
··· 319 319 free_irq(pdev->irq, dev); 320 320 err_iounmap: 321 321 iounmap(dev->base); 322 - pci_set_drvdata(pdev, NULL); 323 322 put_device(&pdev->dev); 324 323 kfree(dev); 325 324 err_release_region: ··· 335 336 pm_runtime_forbid(&pdev->dev); 336 337 pm_runtime_get_noresume(&pdev->dev); 337 338 338 - pci_set_drvdata(pdev, NULL); 339 339 i2c_del_adapter(&dev->adapter); 340 340 put_device(&pdev->dev); 341 341
+56 -5
drivers/i2c/busses/i2c-designware-platdrv.c
··· 37 37 #include <linux/of_i2c.h> 38 38 #include <linux/platform_device.h> 39 39 #include <linux/pm.h> 40 + #include <linux/pm_runtime.h> 40 41 #include <linux/io.h> 41 42 #include <linux/slab.h> 43 + #include <linux/acpi.h> 42 44 #include "i2c-designware-core.h" 43 45 44 46 static struct i2c_algorithm i2c_dw_algo = { ··· 51 49 { 52 50 return clk_get_rate(dev->clk)/1000; 53 51 } 52 + 53 + #ifdef CONFIG_ACPI 54 + static int dw_i2c_acpi_configure(struct platform_device *pdev) 55 + { 56 + struct dw_i2c_dev *dev = platform_get_drvdata(pdev); 57 + struct acpi_device *adev; 58 + int busno, ret; 59 + 60 + if (!ACPI_HANDLE(&pdev->dev)) 61 + return -ENODEV; 62 + 63 + ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); 64 + if (ret) 65 + return -ENODEV; 66 + 67 + dev->adapter.nr = -1; 68 + if (adev->pnp.unique_id && !kstrtoint(adev->pnp.unique_id, 0, &busno)) 69 + dev->adapter.nr = busno; 70 + 71 + dev->tx_fifo_depth = 32; 72 + dev->rx_fifo_depth = 32; 73 + return 0; 74 + } 75 + 76 + static const struct acpi_device_id dw_i2c_acpi_match[] = { 77 + { "INT33C2", 0 }, 78 + { "INT33C3", 0 }, 79 + { } 80 + }; 81 + MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match); 82 + #else 83 + static inline int dw_i2c_acpi_configure(struct platform_device *pdev) 84 + { 85 + return -ENODEV; 86 + } 87 + #endif 54 88 55 89 static int dw_i2c_probe(struct platform_device *pdev) 56 90 { ··· 152 114 r = -EBUSY; 153 115 goto err_unuse_clocks; 154 116 } 155 - { 117 + 118 + /* Try first if we can configure the device from ACPI */ 119 + r = dw_i2c_acpi_configure(pdev); 120 + if (r) { 156 121 u32 param1 = i2c_dw_read_comp_param(dev); 157 122 158 123 dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; 159 124 dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; 125 + dev->adapter.nr = pdev->id; 160 126 } 161 127 r = i2c_dw_init(dev); 162 128 if (r) 163 129 goto err_iounmap; 164 130 165 131 i2c_dw_disable_int(dev); 166 - r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev); 132 + r = request_irq(dev->irq, i2c_dw_isr, IRQF_SHARED, pdev->name, dev); 167 133 if (r) { 168 134 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); 169 135 goto err_iounmap; ··· 182 140 adap->algo = &i2c_dw_algo; 183 141 adap->dev.parent = &pdev->dev; 184 142 adap->dev.of_node = pdev->dev.of_node; 143 + ACPI_HANDLE_SET(&adap->dev, ACPI_HANDLE(&pdev->dev)); 185 144 186 - adap->nr = pdev->id; 187 145 r = i2c_add_numbered_adapter(adap); 188 146 if (r) { 189 147 dev_err(&pdev->dev, "failure adding adapter\n"); 190 148 goto err_free_irq; 191 149 } 192 150 of_i2c_register_devices(adap); 151 + acpi_i2c_register_devices(adap); 152 + 153 + pm_runtime_set_active(&pdev->dev); 154 + pm_runtime_enable(&pdev->dev); 155 + pm_runtime_put(&pdev->dev); 193 156 194 157 return 0; 195 158 ··· 207 160 clk_put(dev->clk); 208 161 dev->clk = NULL; 209 162 err_free_mem: 210 - platform_set_drvdata(pdev, NULL); 211 163 put_device(&pdev->dev); 212 164 kfree(dev); 213 165 err_release_region: ··· 220 174 struct dw_i2c_dev *dev = platform_get_drvdata(pdev); 221 175 struct resource *mem; 222 176 223 - platform_set_drvdata(pdev, NULL); 177 + pm_runtime_get_sync(&pdev->dev); 178 + 224 179 i2c_del_adapter(&dev->adapter); 225 180 put_device(&pdev->dev); 226 181 ··· 232 185 i2c_dw_disable(dev); 233 186 free_irq(dev->irq, dev); 234 187 kfree(dev); 188 + 189 + pm_runtime_put(&pdev->dev); 190 + pm_runtime_disable(&pdev->dev); 235 191 236 192 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 237 193 release_mem_region(mem->start, resource_size(mem)); ··· 283 233 .name = "i2c_designware", 284 234 .owner = THIS_MODULE, 285 235 .of_match_table = of_match_ptr(dw_i2c_of_match), 236 + .acpi_match_table = ACPI_PTR(dw_i2c_acpi_match), 286 237 .pm = &dw_i2c_dev_pm_ops, 287 238 }, 288 239 };
-2
drivers/i2c/busses/i2c-eg20t.c
··· 869 869 for (i = 0; i < adap_info->ch_num; i++) 870 870 adap_info->pch_data[i].pch_base_address = NULL; 871 871 872 - pci_set_drvdata(pdev, NULL); 873 - 874 872 pci_release_regions(pdev); 875 873 876 874 pci_disable_device(pdev);
-4
drivers/i2c/busses/i2c-highlander.c
··· 436 436 err: 437 437 kfree(dev); 438 438 439 - platform_set_drvdata(pdev, NULL); 440 - 441 439 return ret; 442 440 } 443 441 ··· 450 452 451 453 iounmap(dev->base); 452 454 kfree(dev); 453 - 454 - platform_set_drvdata(pdev, NULL); 455 455 456 456 return 0; 457 457 }
+18 -1
drivers/i2c/busses/i2c-i801.c
··· 53 53 Panther Point (PCH) 0x1e22 32 hard yes yes yes 54 54 Lynx Point (PCH) 0x8c22 32 hard yes yes yes 55 55 Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes 56 + Avoton (SOC) 0x1f3c 32 hard yes yes yes 57 + Wellsburg (PCH) 0x8d22 32 hard yes yes yes 58 + Wellsburg (PCH) MS 0x8d7d 32 hard yes yes yes 59 + Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes 60 + Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes 56 61 57 62 Features supported by this driver: 58 63 Software PEC no ··· 167 162 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71 168 163 #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72 169 164 #define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22 165 + #define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c 170 166 #define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330 171 167 #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30 172 168 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22 169 + #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22 170 + #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d 171 + #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e 172 + #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f 173 173 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22 174 174 175 175 struct i801_mux_config { ··· 808 798 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) }, 809 799 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) }, 810 800 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) }, 801 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMBUS) }, 802 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS) }, 803 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0) }, 804 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) }, 805 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) }, 811 806 { 0, } 812 807 }; 813 808 ··· 1118 1103 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0: 1119 1104 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1: 1120 1105 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2: 1106 + case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0: 1107 + case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1: 1108 + case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2: 1121 1109 priv->features |= FEATURE_IDF; 1122 1110 /* fall through */ 1123 1111 default: ··· 1254 1236 free_irq(dev->irq, priv); 1255 1237 pci_release_region(dev, SMBBAR); 1256 1238 1257 - pci_set_drvdata(dev, NULL); 1258 1239 kfree(priv); 1259 1240 /* 1260 1241 * do not call pci_disable_device(dev) since it can cause hard hangs on
-3
drivers/i2c/busses/i2c-ibm_iic.c
··· 773 773 if (dev->vaddr) 774 774 iounmap(dev->vaddr); 775 775 776 - dev_set_drvdata(&ofdev->dev, NULL); 777 776 kfree(dev); 778 777 return ret; 779 778 } ··· 783 784 static int iic_remove(struct platform_device *ofdev) 784 785 { 785 786 struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev); 786 - 787 - dev_set_drvdata(&ofdev->dev, NULL); 788 787 789 788 i2c_del_adapter(&dev->adap); 790 789
-1
drivers/i2c/busses/i2c-imx.c
··· 605 605 /* remove adapter */ 606 606 dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); 607 607 i2c_del_adapter(&i2c_imx->adapter); 608 - platform_set_drvdata(pdev, NULL); 609 608 610 609 /* setup chip registers to defaults */ 611 610 writeb(0, i2c_imx->base + IMX_I2C_IADR);
-2
drivers/i2c/busses/i2c-intel-mid.c
··· 1069 1069 fail3: 1070 1070 free_irq(dev->irq, mrst); 1071 1071 fail2: 1072 - pci_set_drvdata(dev, NULL); 1073 1072 kfree(mrst); 1074 1073 fail1: 1075 1074 iounmap(base); ··· 1086 1087 dev_err(&dev->dev, "Failed to delete i2c adapter"); 1087 1088 1088 1089 free_irq(dev->irq, mrst); 1089 - pci_set_drvdata(dev, NULL); 1090 1090 iounmap(mrst->base); 1091 1091 kfree(mrst); 1092 1092 pci_release_region(dev, 0);
-2
drivers/i2c/busses/i2c-iop3xx.c
··· 415 415 kfree(adapter_data); 416 416 kfree(padapter); 417 417 418 - platform_set_drvdata(pdev, NULL); 419 - 420 418 return 0; 421 419 } 422 420
+17
drivers/i2c/busses/i2c-isch.c
··· 40 40 /* SCH SMBus address offsets */ 41 41 #define SMBHSTCNT (0 + sch_smba) 42 42 #define SMBHSTSTS (1 + sch_smba) 43 + #define SMBHSTCLK (2 + sch_smba) 43 44 #define SMBHSTADD (4 + sch_smba) /* TSA */ 44 45 #define SMBHSTCMD (5 + sch_smba) 45 46 #define SMBHSTDAT0 (6 + sch_smba) ··· 59 58 60 59 static unsigned short sch_smba; 61 60 static struct i2c_adapter sch_adapter; 61 + static int backbone_speed = 33000; /* backbone speed in kHz */ 62 + module_param(backbone_speed, int, S_IRUSR | S_IWUSR); 63 + MODULE_PARM_DESC(backbone_speed, "Backbone speed in kHz, (default = 33000)"); 62 64 63 65 /* 64 66 * Start the i2c transaction -- the i2c_access will prepare the transaction ··· 160 156 dev_dbg(&sch_adapter.dev, "SMBus busy (%02x)\n", temp); 161 157 return -EAGAIN; 162 158 } 159 + temp = inw(SMBHSTCLK); 160 + if (!temp) { 161 + /* 162 + * We can't determine if we have 33 or 25 MHz clock for 163 + * SMBus, so expect 33 MHz and calculate a bus clock of 164 + * 100 kHz. If we actually run at 25 MHz the bus will be 165 + * run ~75 kHz instead which should do no harm. 166 + */ 167 + dev_notice(&sch_adapter.dev, 168 + "Clock divider unitialized. Setting defaults\n"); 169 + outw(backbone_speed / (4 * 100), SMBHSTCLK); 170 + } 171 + 163 172 dev_dbg(&sch_adapter.dev, "access size: %d %s\n", size, 164 173 (read_write)?"READ":"WRITE"); 165 174 switch (size) {
+963
drivers/i2c/busses/i2c-ismt.c
··· 1 + /* 2 + * This file is provided under a dual BSD/GPLv2 license. When using or 3 + * redistributing this file, you may do so under either license. 4 + * 5 + * Copyright(c) 2012 Intel Corporation. All rights reserved. 6 + * 7 + * GPL LICENSE SUMMARY 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of version 2 of the GNU General Public License as 11 + * published by the Free Software Foundation. 12 + * 13 + * This program is distributed in the hope that it will be useful, but 14 + * WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 + * General Public License for more details. 17 + * 18 + * You should have received a copy of the GNU General Public License 19 + * along with this program; if not, write to the Free Software 20 + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 21 + * The full GNU General Public License is included in this distribution 22 + * in the file called LICENSE.GPL. 23 + * 24 + * BSD LICENSE 25 + * 26 + * Redistribution and use in source and binary forms, with or without 27 + * modification, are permitted provided that the following conditions 28 + * are met: 29 + * 30 + * * Redistributions of source code must retain the above copyright 31 + * notice, this list of conditions and the following disclaimer. 32 + * * Redistributions in binary form must reproduce the above copyright 33 + * notice, this list of conditions and the following disclaimer in 34 + * the documentation and/or other materials provided with the 35 + * distribution. 36 + * * Neither the name of Intel Corporation nor the names of its 37 + * contributors may be used to endorse or promote products derived 38 + * from this software without specific prior written permission. 39 + * 40 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 + */ 52 + 53 + /* 54 + * Supports the SMBus Message Transport (SMT) in the Intel Atom Processor 55 + * S12xx Product Family. 56 + * 57 + * Features supported by this driver: 58 + * Hardware PEC yes 59 + * Block buffer yes 60 + * Block process call transaction no 61 + * Slave mode no 62 + */ 63 + 64 + #include <linux/module.h> 65 + #include <linux/init.h> 66 + #include <linux/pci.h> 67 + #include <linux/kernel.h> 68 + #include <linux/stddef.h> 69 + #include <linux/completion.h> 70 + #include <linux/dma-mapping.h> 71 + #include <linux/i2c.h> 72 + #include <linux/acpi.h> 73 + #include <linux/interrupt.h> 74 + 75 + #include <asm-generic/io-64-nonatomic-lo-hi.h> 76 + 77 + /* PCI Address Constants */ 78 + #define SMBBAR 0 79 + 80 + /* PCI DIDs for the Intel SMBus Message Transport (SMT) Devices */ 81 + #define PCI_DEVICE_ID_INTEL_S1200_SMT0 0x0c59 82 + #define PCI_DEVICE_ID_INTEL_S1200_SMT1 0x0c5a 83 + 84 + #define ISMT_DESC_ENTRIES 32 /* number of descriptor entries */ 85 + #define ISMT_MAX_RETRIES 3 /* number of SMBus retries to attempt */ 86 + 87 + /* Hardware Descriptor Constants - Control Field */ 88 + #define ISMT_DESC_CWRL 0x01 /* Command/Write Length */ 89 + #define ISMT_DESC_BLK 0X04 /* Perform Block Transaction */ 90 + #define ISMT_DESC_FAIR 0x08 /* Set fairness flag upon successful arbit. */ 91 + #define ISMT_DESC_PEC 0x10 /* Packet Error Code */ 92 + #define ISMT_DESC_I2C 0x20 /* I2C Enable */ 93 + #define ISMT_DESC_INT 0x40 /* Interrupt */ 94 + #define ISMT_DESC_SOE 0x80 /* Stop On Error */ 95 + 96 + /* Hardware Descriptor Constants - Status Field */ 97 + #define ISMT_DESC_SCS 0x01 /* Success */ 98 + #define ISMT_DESC_DLTO 0x04 /* Data Low Time Out */ 99 + #define ISMT_DESC_NAK 0x08 /* NAK Received */ 100 + #define ISMT_DESC_CRC 0x10 /* CRC Error */ 101 + #define ISMT_DESC_CLTO 0x20 /* Clock Low Time Out */ 102 + #define ISMT_DESC_COL 0x40 /* Collisions */ 103 + #define ISMT_DESC_LPR 0x80 /* Large Packet Received */ 104 + 105 + /* Macros */ 106 + #define ISMT_DESC_ADDR_RW(addr, rw) (((addr) << 1) | (rw)) 107 + 108 + /* iSMT General Register address offsets (SMBBAR + <addr>) */ 109 + #define ISMT_GR_GCTRL 0x000 /* General Control */ 110 + #define ISMT_GR_SMTICL 0x008 /* SMT Interrupt Cause Location */ 111 + #define ISMT_GR_ERRINTMSK 0x010 /* Error Interrupt Mask */ 112 + #define ISMT_GR_ERRAERMSK 0x014 /* Error AER Mask */ 113 + #define ISMT_GR_ERRSTS 0x018 /* Error Status */ 114 + #define ISMT_GR_ERRINFO 0x01c /* Error Information */ 115 + 116 + /* iSMT Master Registers */ 117 + #define ISMT_MSTR_MDBA 0x100 /* Master Descriptor Base Address */ 118 + #define ISMT_MSTR_MCTRL 0x108 /* Master Control */ 119 + #define ISMT_MSTR_MSTS 0x10c /* Master Status */ 120 + #define ISMT_MSTR_MDS 0x110 /* Master Descriptor Size */ 121 + #define ISMT_MSTR_RPOLICY 0x114 /* Retry Policy */ 122 + 123 + /* iSMT Miscellaneous Registers */ 124 + #define ISMT_SPGT 0x300 /* SMBus PHY Global Timing */ 125 + 126 + /* General Control Register (GCTRL) bit definitions */ 127 + #define ISMT_GCTRL_TRST 0x04 /* Target Reset */ 128 + #define ISMT_GCTRL_KILL 0x08 /* Kill */ 129 + #define ISMT_GCTRL_SRST 0x40 /* Soft Reset */ 130 + 131 + /* Master Control Register (MCTRL) bit definitions */ 132 + #define ISMT_MCTRL_SS 0x01 /* Start/Stop */ 133 + #define ISMT_MCTRL_MEIE 0x10 /* Master Error Interrupt Enable */ 134 + #define ISMT_MCTRL_FMHP 0x00ff0000 /* Firmware Master Head Ptr (FMHP) */ 135 + 136 + /* Master Status Register (MSTS) bit definitions */ 137 + #define ISMT_MSTS_HMTP 0xff0000 /* HW Master Tail Pointer (HMTP) */ 138 + #define ISMT_MSTS_MIS 0x20 /* Master Interrupt Status (MIS) */ 139 + #define ISMT_MSTS_MEIS 0x10 /* Master Error Int Status (MEIS) */ 140 + #define ISMT_MSTS_IP 0x01 /* In Progress */ 141 + 142 + /* Master Descriptor Size (MDS) bit definitions */ 143 + #define ISMT_MDS_MASK 0xff /* Master Descriptor Size mask (MDS) */ 144 + 145 + /* SMBus PHY Global Timing Register (SPGT) bit definitions */ 146 + #define ISMT_SPGT_SPD_MASK 0xc0000000 /* SMBus Speed mask */ 147 + #define ISMT_SPGT_SPD_80K 0x00 /* 80 kHz */ 148 + #define ISMT_SPGT_SPD_100K (0x1 << 30) /* 100 kHz */ 149 + #define ISMT_SPGT_SPD_400K (0x2 << 30) /* 400 kHz */ 150 + #define ISMT_SPGT_SPD_1M (0x3 << 30) /* 1 MHz */ 151 + 152 + 153 + /* MSI Control Register (MSICTL) bit definitions */ 154 + #define ISMT_MSICTL_MSIE 0x01 /* MSI Enable */ 155 + 156 + /* iSMT Hardware Descriptor */ 157 + struct ismt_desc { 158 + u8 tgtaddr_rw; /* target address & r/w bit */ 159 + u8 wr_len_cmd; /* write length in bytes or a command */ 160 + u8 rd_len; /* read length */ 161 + u8 control; /* control bits */ 162 + u8 status; /* status bits */ 163 + u8 retry; /* collision retry and retry count */ 164 + u8 rxbytes; /* received bytes */ 165 + u8 txbytes; /* transmitted bytes */ 166 + u32 dptr_low; /* lower 32 bit of the data pointer */ 167 + u32 dptr_high; /* upper 32 bit of the data pointer */ 168 + } __packed; 169 + 170 + struct ismt_priv { 171 + struct i2c_adapter adapter; 172 + void *smba; /* PCI BAR */ 173 + struct pci_dev *pci_dev; 174 + struct ismt_desc *hw; /* descriptor virt base addr */ 175 + dma_addr_t io_rng_dma; /* descriptor HW base addr */ 176 + u8 head; /* ring buffer head pointer */ 177 + struct completion cmp; /* interrupt completion */ 178 + u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* temp R/W data buffer */ 179 + bool using_msi; /* type of interrupt flag */ 180 + }; 181 + 182 + /** 183 + * ismt_ids - PCI device IDs supported by this driver 184 + */ 185 + static const DEFINE_PCI_DEVICE_TABLE(ismt_ids) = { 186 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) }, 187 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) }, 188 + { 0, } 189 + }; 190 + 191 + MODULE_DEVICE_TABLE(pci, ismt_ids); 192 + 193 + /* Bus speed control bits for slow debuggers - refer to the docs for usage */ 194 + static unsigned int bus_speed; 195 + module_param(bus_speed, uint, S_IRUGO); 196 + MODULE_PARM_DESC(bus_speed, "Bus Speed in kHz (0 = BIOS default)"); 197 + 198 + /** 199 + * __ismt_desc_dump() - dump the contents of a specific descriptor 200 + */ 201 + static void __ismt_desc_dump(struct device *dev, const struct ismt_desc *desc) 202 + { 203 + 204 + dev_dbg(dev, "Descriptor struct: %p\n", desc); 205 + dev_dbg(dev, "\ttgtaddr_rw=0x%02X\n", desc->tgtaddr_rw); 206 + dev_dbg(dev, "\twr_len_cmd=0x%02X\n", desc->wr_len_cmd); 207 + dev_dbg(dev, "\trd_len= 0x%02X\n", desc->rd_len); 208 + dev_dbg(dev, "\tcontrol= 0x%02X\n", desc->control); 209 + dev_dbg(dev, "\tstatus= 0x%02X\n", desc->status); 210 + dev_dbg(dev, "\tretry= 0x%02X\n", desc->retry); 211 + dev_dbg(dev, "\trxbytes= 0x%02X\n", desc->rxbytes); 212 + dev_dbg(dev, "\ttxbytes= 0x%02X\n", desc->txbytes); 213 + dev_dbg(dev, "\tdptr_low= 0x%08X\n", desc->dptr_low); 214 + dev_dbg(dev, "\tdptr_high= 0x%08X\n", desc->dptr_high); 215 + } 216 + /** 217 + * ismt_desc_dump() - dump the contents of a descriptor for debug purposes 218 + * @priv: iSMT private data 219 + */ 220 + static void ismt_desc_dump(struct ismt_priv *priv) 221 + { 222 + struct device *dev = &priv->pci_dev->dev; 223 + struct ismt_desc *desc = &priv->hw[priv->head]; 224 + 225 + dev_dbg(dev, "Dump of the descriptor struct: 0x%X\n", priv->head); 226 + __ismt_desc_dump(dev, desc); 227 + } 228 + 229 + /** 230 + * ismt_gen_reg_dump() - dump the iSMT General Registers 231 + * @priv: iSMT private data 232 + */ 233 + static void ismt_gen_reg_dump(struct ismt_priv *priv) 234 + { 235 + struct device *dev = &priv->pci_dev->dev; 236 + 237 + dev_dbg(dev, "Dump of the iSMT General Registers\n"); 238 + dev_dbg(dev, " GCTRL.... : (0x%p)=0x%X\n", 239 + priv->smba + ISMT_GR_GCTRL, 240 + readl(priv->smba + ISMT_GR_GCTRL)); 241 + dev_dbg(dev, " SMTICL... : (0x%p)=0x%016llX\n", 242 + priv->smba + ISMT_GR_SMTICL, 243 + (long long unsigned int)readq(priv->smba + ISMT_GR_SMTICL)); 244 + dev_dbg(dev, " ERRINTMSK : (0x%p)=0x%X\n", 245 + priv->smba + ISMT_GR_ERRINTMSK, 246 + readl(priv->smba + ISMT_GR_ERRINTMSK)); 247 + dev_dbg(dev, " ERRAERMSK : (0x%p)=0x%X\n", 248 + priv->smba + ISMT_GR_ERRAERMSK, 249 + readl(priv->smba + ISMT_GR_ERRAERMSK)); 250 + dev_dbg(dev, " ERRSTS... : (0x%p)=0x%X\n", 251 + priv->smba + ISMT_GR_ERRSTS, 252 + readl(priv->smba + ISMT_GR_ERRSTS)); 253 + dev_dbg(dev, " ERRINFO.. : (0x%p)=0x%X\n", 254 + priv->smba + ISMT_GR_ERRINFO, 255 + readl(priv->smba + ISMT_GR_ERRINFO)); 256 + } 257 + 258 + /** 259 + * ismt_mstr_reg_dump() - dump the iSMT Master Registers 260 + * @priv: iSMT private data 261 + */ 262 + static void ismt_mstr_reg_dump(struct ismt_priv *priv) 263 + { 264 + struct device *dev = &priv->pci_dev->dev; 265 + 266 + dev_dbg(dev, "Dump of the iSMT Master Registers\n"); 267 + dev_dbg(dev, " MDBA..... : (0x%p)=0x%016llX\n", 268 + priv->smba + ISMT_MSTR_MDBA, 269 + (long long unsigned int)readq(priv->smba + ISMT_MSTR_MDBA)); 270 + dev_dbg(dev, " MCTRL.... : (0x%p)=0x%X\n", 271 + priv->smba + ISMT_MSTR_MCTRL, 272 + readl(priv->smba + ISMT_MSTR_MCTRL)); 273 + dev_dbg(dev, " MSTS..... : (0x%p)=0x%X\n", 274 + priv->smba + ISMT_MSTR_MSTS, 275 + readl(priv->smba + ISMT_MSTR_MSTS)); 276 + dev_dbg(dev, " MDS...... : (0x%p)=0x%X\n", 277 + priv->smba + ISMT_MSTR_MDS, 278 + readl(priv->smba + ISMT_MSTR_MDS)); 279 + dev_dbg(dev, " RPOLICY.. : (0x%p)=0x%X\n", 280 + priv->smba + ISMT_MSTR_RPOLICY, 281 + readl(priv->smba + ISMT_MSTR_RPOLICY)); 282 + dev_dbg(dev, " SPGT..... : (0x%p)=0x%X\n", 283 + priv->smba + ISMT_SPGT, 284 + readl(priv->smba + ISMT_SPGT)); 285 + } 286 + 287 + /** 288 + * ismt_submit_desc() - add a descriptor to the ring 289 + * @priv: iSMT private data 290 + */ 291 + static void ismt_submit_desc(struct ismt_priv *priv) 292 + { 293 + uint fmhp; 294 + uint val; 295 + 296 + ismt_desc_dump(priv); 297 + ismt_gen_reg_dump(priv); 298 + ismt_mstr_reg_dump(priv); 299 + 300 + /* Set the FMHP (Firmware Master Head Pointer)*/ 301 + fmhp = ((priv->head + 1) % ISMT_DESC_ENTRIES) << 16; 302 + val = readl(priv->smba + ISMT_MSTR_MCTRL); 303 + writel((val & ~ISMT_MCTRL_FMHP) | fmhp, 304 + priv->smba + ISMT_MSTR_MCTRL); 305 + 306 + /* Set the start bit */ 307 + val = readl(priv->smba + ISMT_MSTR_MCTRL); 308 + writel(val | ISMT_MCTRL_SS, 309 + priv->smba + ISMT_MSTR_MCTRL); 310 + } 311 + 312 + /** 313 + * ismt_process_desc() - handle the completion of the descriptor 314 + * @desc: the iSMT hardware descriptor 315 + * @data: data buffer from the upper layer 316 + * @priv: ismt_priv struct holding our dma buffer 317 + * @size: SMBus transaction type 318 + * @read_write: flag to indicate if this is a read or write 319 + */ 320 + static int ismt_process_desc(const struct ismt_desc *desc, 321 + union i2c_smbus_data *data, 322 + struct ismt_priv *priv, int size, 323 + char read_write) 324 + { 325 + u8 *dma_buffer = priv->dma_buffer; 326 + 327 + dev_dbg(&priv->pci_dev->dev, "Processing completed descriptor\n"); 328 + __ismt_desc_dump(&priv->pci_dev->dev, desc); 329 + 330 + if (desc->status & ISMT_DESC_SCS) { 331 + if (read_write == I2C_SMBUS_WRITE && 332 + size != I2C_SMBUS_PROC_CALL) 333 + return 0; 334 + 335 + switch (size) { 336 + case I2C_SMBUS_BYTE: 337 + case I2C_SMBUS_BYTE_DATA: 338 + data->byte = dma_buffer[0]; 339 + break; 340 + case I2C_SMBUS_WORD_DATA: 341 + case I2C_SMBUS_PROC_CALL: 342 + data->word = dma_buffer[0] | (dma_buffer[1] << 8); 343 + break; 344 + case I2C_SMBUS_BLOCK_DATA: 345 + memcpy(&data->block[1], dma_buffer, desc->rxbytes); 346 + data->block[0] = desc->rxbytes; 347 + break; 348 + } 349 + return 0; 350 + } 351 + 352 + if (likely(desc->status & ISMT_DESC_NAK)) 353 + return -ENXIO; 354 + 355 + if (desc->status & ISMT_DESC_CRC) 356 + return -EBADMSG; 357 + 358 + if (desc->status & ISMT_DESC_COL) 359 + return -EAGAIN; 360 + 361 + if (desc->status & ISMT_DESC_LPR) 362 + return -EPROTO; 363 + 364 + if (desc->status & (ISMT_DESC_DLTO | ISMT_DESC_CLTO)) 365 + return -ETIMEDOUT; 366 + 367 + return -EIO; 368 + } 369 + 370 + /** 371 + * ismt_access() - process an SMBus command 372 + * @adap: the i2c host adapter 373 + * @addr: address of the i2c/SMBus target 374 + * @flags: command options 375 + * @read_write: read from or write to device 376 + * @command: the i2c/SMBus command to issue 377 + * @size: SMBus transaction type 378 + * @data: read/write data buffer 379 + */ 380 + static int ismt_access(struct i2c_adapter *adap, u16 addr, 381 + unsigned short flags, char read_write, u8 command, 382 + int size, union i2c_smbus_data *data) 383 + { 384 + int ret; 385 + dma_addr_t dma_addr = 0; /* address of the data buffer */ 386 + u8 dma_size = 0; 387 + enum dma_data_direction dma_direction = 0; 388 + struct ismt_desc *desc; 389 + struct ismt_priv *priv = i2c_get_adapdata(adap); 390 + struct device *dev = &priv->pci_dev->dev; 391 + 392 + desc = &priv->hw[priv->head]; 393 + 394 + /* Initialize the descriptor */ 395 + memset(desc, 0, sizeof(struct ismt_desc)); 396 + desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write); 397 + 398 + /* Initialize common control bits */ 399 + if (likely(priv->using_msi)) 400 + desc->control = ISMT_DESC_INT | ISMT_DESC_FAIR; 401 + else 402 + desc->control = ISMT_DESC_FAIR; 403 + 404 + if ((flags & I2C_CLIENT_PEC) && (size != I2C_SMBUS_QUICK) 405 + && (size != I2C_SMBUS_I2C_BLOCK_DATA)) 406 + desc->control |= ISMT_DESC_PEC; 407 + 408 + switch (size) { 409 + case I2C_SMBUS_QUICK: 410 + dev_dbg(dev, "I2C_SMBUS_QUICK\n"); 411 + break; 412 + 413 + case I2C_SMBUS_BYTE: 414 + if (read_write == I2C_SMBUS_WRITE) { 415 + /* 416 + * Send Byte 417 + * The command field contains the write data 418 + */ 419 + dev_dbg(dev, "I2C_SMBUS_BYTE: WRITE\n"); 420 + desc->control |= ISMT_DESC_CWRL; 421 + desc->wr_len_cmd = command; 422 + } else { 423 + /* Receive Byte */ 424 + dev_dbg(dev, "I2C_SMBUS_BYTE: READ\n"); 425 + dma_size = 1; 426 + dma_direction = DMA_FROM_DEVICE; 427 + desc->rd_len = 1; 428 + } 429 + break; 430 + 431 + case I2C_SMBUS_BYTE_DATA: 432 + if (read_write == I2C_SMBUS_WRITE) { 433 + /* 434 + * Write Byte 435 + * Command plus 1 data byte 436 + */ 437 + dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: WRITE\n"); 438 + desc->wr_len_cmd = 2; 439 + dma_size = 2; 440 + dma_direction = DMA_TO_DEVICE; 441 + priv->dma_buffer[0] = command; 442 + priv->dma_buffer[1] = data->byte; 443 + } else { 444 + /* Read Byte */ 445 + dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: READ\n"); 446 + desc->control |= ISMT_DESC_CWRL; 447 + desc->wr_len_cmd = command; 448 + desc->rd_len = 1; 449 + dma_size = 1; 450 + dma_direction = DMA_FROM_DEVICE; 451 + } 452 + break; 453 + 454 + case I2C_SMBUS_WORD_DATA: 455 + if (read_write == I2C_SMBUS_WRITE) { 456 + /* Write Word */ 457 + dev_dbg(dev, "I2C_SMBUS_WORD_DATA: WRITE\n"); 458 + desc->wr_len_cmd = 3; 459 + dma_size = 3; 460 + dma_direction = DMA_TO_DEVICE; 461 + priv->dma_buffer[0] = command; 462 + priv->dma_buffer[1] = data->word & 0xff; 463 + priv->dma_buffer[2] = data->word >> 8; 464 + } else { 465 + /* Read Word */ 466 + dev_dbg(dev, "I2C_SMBUS_WORD_DATA: READ\n"); 467 + desc->wr_len_cmd = command; 468 + desc->control |= ISMT_DESC_CWRL; 469 + desc->rd_len = 2; 470 + dma_size = 2; 471 + dma_direction = DMA_FROM_DEVICE; 472 + } 473 + break; 474 + 475 + case I2C_SMBUS_PROC_CALL: 476 + dev_dbg(dev, "I2C_SMBUS_PROC_CALL\n"); 477 + desc->wr_len_cmd = 3; 478 + desc->rd_len = 2; 479 + dma_size = 3; 480 + dma_direction = DMA_BIDIRECTIONAL; 481 + priv->dma_buffer[0] = command; 482 + priv->dma_buffer[1] = data->word & 0xff; 483 + priv->dma_buffer[2] = data->word >> 8; 484 + break; 485 + 486 + case I2C_SMBUS_BLOCK_DATA: 487 + if (read_write == I2C_SMBUS_WRITE) { 488 + /* Block Write */ 489 + dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: WRITE\n"); 490 + dma_size = data->block[0] + 1; 491 + dma_direction = DMA_TO_DEVICE; 492 + desc->wr_len_cmd = dma_size; 493 + desc->control |= ISMT_DESC_BLK; 494 + priv->dma_buffer[0] = command; 495 + memcpy(&priv->dma_buffer[1], &data->block[1], dma_size); 496 + } else { 497 + /* Block Read */ 498 + dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: READ\n"); 499 + dma_size = I2C_SMBUS_BLOCK_MAX; 500 + dma_direction = DMA_FROM_DEVICE; 501 + desc->rd_len = dma_size; 502 + desc->wr_len_cmd = command; 503 + desc->control |= (ISMT_DESC_BLK | ISMT_DESC_CWRL); 504 + } 505 + break; 506 + 507 + default: 508 + dev_err(dev, "Unsupported transaction %d\n", 509 + size); 510 + return -EOPNOTSUPP; 511 + } 512 + 513 + /* map the data buffer */ 514 + if (dma_size != 0) { 515 + dev_dbg(dev, " dev=%p\n", dev); 516 + dev_dbg(dev, " data=%p\n", data); 517 + dev_dbg(dev, " dma_buffer=%p\n", priv->dma_buffer); 518 + dev_dbg(dev, " dma_size=%d\n", dma_size); 519 + dev_dbg(dev, " dma_direction=%d\n", dma_direction); 520 + 521 + dma_addr = dma_map_single(dev, 522 + priv->dma_buffer, 523 + dma_size, 524 + dma_direction); 525 + 526 + if (dma_mapping_error(dev, dma_addr)) { 527 + dev_err(dev, "Error in mapping dma buffer %p\n", 528 + priv->dma_buffer); 529 + return -EIO; 530 + } 531 + 532 + dev_dbg(dev, " dma_addr = 0x%016llX\n", 533 + (unsigned long long)dma_addr); 534 + 535 + desc->dptr_low = lower_32_bits(dma_addr); 536 + desc->dptr_high = upper_32_bits(dma_addr); 537 + } 538 + 539 + INIT_COMPLETION(priv->cmp); 540 + 541 + /* Add the descriptor */ 542 + ismt_submit_desc(priv); 543 + 544 + /* Now we wait for interrupt completion, 1s */ 545 + ret = wait_for_completion_timeout(&priv->cmp, HZ*1); 546 + 547 + /* unmap the data buffer */ 548 + if (dma_size != 0) 549 + dma_unmap_single(&adap->dev, dma_addr, dma_size, dma_direction); 550 + 551 + if (unlikely(!ret)) { 552 + dev_err(dev, "completion wait timed out\n"); 553 + ret = -ETIMEDOUT; 554 + goto out; 555 + } 556 + 557 + /* do any post processing of the descriptor here */ 558 + ret = ismt_process_desc(desc, data, priv, size, read_write); 559 + 560 + out: 561 + /* Update the ring pointer */ 562 + priv->head++; 563 + priv->head %= ISMT_DESC_ENTRIES; 564 + 565 + return ret; 566 + } 567 + 568 + /** 569 + * ismt_func() - report which i2c commands are supported by this adapter 570 + * @adap: the i2c host adapter 571 + */ 572 + static u32 ismt_func(struct i2c_adapter *adap) 573 + { 574 + return I2C_FUNC_SMBUS_QUICK | 575 + I2C_FUNC_SMBUS_BYTE | 576 + I2C_FUNC_SMBUS_BYTE_DATA | 577 + I2C_FUNC_SMBUS_WORD_DATA | 578 + I2C_FUNC_SMBUS_PROC_CALL | 579 + I2C_FUNC_SMBUS_BLOCK_DATA | 580 + I2C_FUNC_SMBUS_PEC; 581 + } 582 + 583 + /** 584 + * smbus_algorithm - the adapter algorithm and supported functionality 585 + * @smbus_xfer: the adapter algorithm 586 + * @functionality: functionality supported by the adapter 587 + */ 588 + static const struct i2c_algorithm smbus_algorithm = { 589 + .smbus_xfer = ismt_access, 590 + .functionality = ismt_func, 591 + }; 592 + 593 + /** 594 + * ismt_handle_isr() - interrupt handler bottom half 595 + * @priv: iSMT private data 596 + */ 597 + static irqreturn_t ismt_handle_isr(struct ismt_priv *priv) 598 + { 599 + complete(&priv->cmp); 600 + 601 + return IRQ_HANDLED; 602 + } 603 + 604 + 605 + /** 606 + * ismt_do_interrupt() - IRQ interrupt handler 607 + * @vec: interrupt vector 608 + * @data: iSMT private data 609 + */ 610 + static irqreturn_t ismt_do_interrupt(int vec, void *data) 611 + { 612 + u32 val; 613 + struct ismt_priv *priv = data; 614 + 615 + /* 616 + * check to see it's our interrupt, return IRQ_NONE if not ours 617 + * since we are sharing interrupt 618 + */ 619 + val = readl(priv->smba + ISMT_MSTR_MSTS); 620 + 621 + if (!(val & (ISMT_MSTS_MIS | ISMT_MSTS_MEIS))) 622 + return IRQ_NONE; 623 + else 624 + writel(val | ISMT_MSTS_MIS | ISMT_MSTS_MEIS, 625 + priv->smba + ISMT_MSTR_MSTS); 626 + 627 + return ismt_handle_isr(priv); 628 + } 629 + 630 + /** 631 + * ismt_do_msi_interrupt() - MSI interrupt handler 632 + * @vec: interrupt vector 633 + * @data: iSMT private data 634 + */ 635 + static irqreturn_t ismt_do_msi_interrupt(int vec, void *data) 636 + { 637 + return ismt_handle_isr(data); 638 + } 639 + 640 + /** 641 + * ismt_hw_init() - initialize the iSMT hardware 642 + * @priv: iSMT private data 643 + */ 644 + static void ismt_hw_init(struct ismt_priv *priv) 645 + { 646 + u32 val; 647 + struct device *dev = &priv->pci_dev->dev; 648 + 649 + /* initialize the Master Descriptor Base Address (MDBA) */ 650 + writeq(priv->io_rng_dma, priv->smba + ISMT_MSTR_MDBA); 651 + 652 + /* initialize the Master Control Register (MCTRL) */ 653 + writel(ISMT_MCTRL_MEIE, priv->smba + ISMT_MSTR_MCTRL); 654 + 655 + /* initialize the Master Status Register (MSTS) */ 656 + writel(0, priv->smba + ISMT_MSTR_MSTS); 657 + 658 + /* initialize the Master Descriptor Size (MDS) */ 659 + val = readl(priv->smba + ISMT_MSTR_MDS); 660 + writel((val & ~ISMT_MDS_MASK) | (ISMT_DESC_ENTRIES - 1), 661 + priv->smba + ISMT_MSTR_MDS); 662 + 663 + /* 664 + * Set the SMBus speed (could use this for slow HW debuggers) 665 + */ 666 + 667 + val = readl(priv->smba + ISMT_SPGT); 668 + 669 + switch (bus_speed) { 670 + case 0: 671 + break; 672 + 673 + case 80: 674 + dev_dbg(dev, "Setting SMBus clock to 80 kHz\n"); 675 + writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_80K), 676 + priv->smba + ISMT_SPGT); 677 + break; 678 + 679 + case 100: 680 + dev_dbg(dev, "Setting SMBus clock to 100 kHz\n"); 681 + writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_100K), 682 + priv->smba + ISMT_SPGT); 683 + break; 684 + 685 + case 400: 686 + dev_dbg(dev, "Setting SMBus clock to 400 kHz\n"); 687 + writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_400K), 688 + priv->smba + ISMT_SPGT); 689 + break; 690 + 691 + case 1000: 692 + dev_dbg(dev, "Setting SMBus clock to 1000 kHz\n"); 693 + writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_1M), 694 + priv->smba + ISMT_SPGT); 695 + break; 696 + 697 + default: 698 + dev_warn(dev, "Invalid SMBus clock speed, only 0, 80, 100, 400, and 1000 are valid\n"); 699 + break; 700 + } 701 + 702 + val = readl(priv->smba + ISMT_SPGT); 703 + 704 + switch (val & ISMT_SPGT_SPD_MASK) { 705 + case ISMT_SPGT_SPD_80K: 706 + bus_speed = 80; 707 + break; 708 + case ISMT_SPGT_SPD_100K: 709 + bus_speed = 100; 710 + break; 711 + case ISMT_SPGT_SPD_400K: 712 + bus_speed = 400; 713 + break; 714 + case ISMT_SPGT_SPD_1M: 715 + bus_speed = 1000; 716 + break; 717 + } 718 + dev_dbg(dev, "SMBus clock is running at %d kHz\n", bus_speed); 719 + } 720 + 721 + /** 722 + * ismt_dev_init() - initialize the iSMT data structures 723 + * @priv: iSMT private data 724 + */ 725 + static int ismt_dev_init(struct ismt_priv *priv) 726 + { 727 + /* allocate memory for the descriptor */ 728 + priv->hw = dmam_alloc_coherent(&priv->pci_dev->dev, 729 + (ISMT_DESC_ENTRIES 730 + * sizeof(struct ismt_desc)), 731 + &priv->io_rng_dma, 732 + GFP_KERNEL); 733 + if (!priv->hw) 734 + return -ENOMEM; 735 + 736 + memset(priv->hw, 0, (ISMT_DESC_ENTRIES * sizeof(struct ismt_desc))); 737 + 738 + priv->head = 0; 739 + init_completion(&priv->cmp); 740 + 741 + return 0; 742 + } 743 + 744 + /** 745 + * ismt_int_init() - initialize interrupts 746 + * @priv: iSMT private data 747 + */ 748 + static int ismt_int_init(struct ismt_priv *priv) 749 + { 750 + int err; 751 + 752 + /* Try using MSI interrupts */ 753 + err = pci_enable_msi(priv->pci_dev); 754 + if (err) { 755 + dev_warn(&priv->pci_dev->dev, 756 + "Unable to use MSI interrupts, falling back to legacy\n"); 757 + goto intx; 758 + } 759 + 760 + err = devm_request_irq(&priv->pci_dev->dev, 761 + priv->pci_dev->irq, 762 + ismt_do_msi_interrupt, 763 + 0, 764 + "ismt-msi", 765 + priv); 766 + if (err) { 767 + pci_disable_msi(priv->pci_dev); 768 + goto intx; 769 + } 770 + 771 + priv->using_msi = true; 772 + goto done; 773 + 774 + /* Try using legacy interrupts */ 775 + intx: 776 + err = devm_request_irq(&priv->pci_dev->dev, 777 + priv->pci_dev->irq, 778 + ismt_do_interrupt, 779 + IRQF_SHARED, 780 + "ismt-intx", 781 + priv); 782 + if (err) { 783 + dev_err(&priv->pci_dev->dev, "no usable interrupts\n"); 784 + return -ENODEV; 785 + } 786 + 787 + priv->using_msi = false; 788 + 789 + done: 790 + return 0; 791 + } 792 + 793 + static struct pci_driver ismt_driver; 794 + 795 + /** 796 + * ismt_probe() - probe for iSMT devices 797 + * @pdev: PCI-Express device 798 + * @id: PCI-Express device ID 799 + */ 800 + static int 801 + ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) 802 + { 803 + int err; 804 + struct ismt_priv *priv; 805 + unsigned long start, len; 806 + 807 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 808 + if (!priv) 809 + return -ENOMEM; 810 + 811 + pci_set_drvdata(pdev, priv); 812 + i2c_set_adapdata(&priv->adapter, priv); 813 + priv->adapter.owner = THIS_MODULE; 814 + 815 + priv->adapter.class = I2C_CLASS_HWMON; 816 + 817 + priv->adapter.algo = &smbus_algorithm; 818 + 819 + /* set up the sysfs linkage to our parent device */ 820 + priv->adapter.dev.parent = &pdev->dev; 821 + 822 + /* number of retries on lost arbitration */ 823 + priv->adapter.retries = ISMT_MAX_RETRIES; 824 + 825 + priv->pci_dev = pdev; 826 + 827 + err = pcim_enable_device(pdev); 828 + if (err) { 829 + dev_err(&pdev->dev, "Failed to enable SMBus PCI device (%d)\n", 830 + err); 831 + return err; 832 + } 833 + 834 + /* enable bus mastering */ 835 + pci_set_master(pdev); 836 + 837 + /* Determine the address of the SMBus area */ 838 + start = pci_resource_start(pdev, SMBBAR); 839 + len = pci_resource_len(pdev, SMBBAR); 840 + if (!start || !len) { 841 + dev_err(&pdev->dev, 842 + "SMBus base address uninitialized, upgrade BIOS\n"); 843 + return -ENODEV; 844 + } 845 + 846 + snprintf(priv->adapter.name, sizeof(priv->adapter.name), 847 + "SMBus iSMT adapter at %lx", start); 848 + 849 + dev_dbg(&priv->pci_dev->dev, " start=0x%lX\n", start); 850 + dev_dbg(&priv->pci_dev->dev, " len=0x%lX\n", len); 851 + 852 + err = acpi_check_resource_conflict(&pdev->resource[SMBBAR]); 853 + if (err) { 854 + dev_err(&pdev->dev, "ACPI resource conflict!\n"); 855 + return err; 856 + } 857 + 858 + err = pci_request_region(pdev, SMBBAR, ismt_driver.name); 859 + if (err) { 860 + dev_err(&pdev->dev, 861 + "Failed to request SMBus region 0x%lx-0x%lx\n", 862 + start, start + len); 863 + return err; 864 + } 865 + 866 + priv->smba = pcim_iomap(pdev, SMBBAR, len); 867 + if (!priv->smba) { 868 + dev_err(&pdev->dev, "Unable to ioremap SMBus BAR\n"); 869 + err = -ENODEV; 870 + goto fail; 871 + } 872 + 873 + if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || 874 + (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { 875 + if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || 876 + (pci_set_consistent_dma_mask(pdev, 877 + DMA_BIT_MASK(32)) != 0)) { 878 + dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n", 879 + pdev); 880 + goto fail; 881 + } 882 + } 883 + 884 + err = ismt_dev_init(priv); 885 + if (err) 886 + goto fail; 887 + 888 + ismt_hw_init(priv); 889 + 890 + err = ismt_int_init(priv); 891 + if (err) 892 + goto fail; 893 + 894 + err = i2c_add_adapter(&priv->adapter); 895 + if (err) { 896 + dev_err(&pdev->dev, "Failed to add SMBus iSMT adapter\n"); 897 + err = -ENODEV; 898 + goto fail; 899 + } 900 + return 0; 901 + 902 + fail: 903 + pci_release_region(pdev, SMBBAR); 904 + return err; 905 + } 906 + 907 + /** 908 + * ismt_remove() - release driver resources 909 + * @pdev: PCI-Express device 910 + */ 911 + static void ismt_remove(struct pci_dev *pdev) 912 + { 913 + struct ismt_priv *priv = pci_get_drvdata(pdev); 914 + 915 + i2c_del_adapter(&priv->adapter); 916 + pci_release_region(pdev, SMBBAR); 917 + } 918 + 919 + /** 920 + * ismt_suspend() - place the device in suspend 921 + * @pdev: PCI-Express device 922 + * @mesg: PM message 923 + */ 924 + #ifdef CONFIG_PM 925 + static int ismt_suspend(struct pci_dev *pdev, pm_message_t mesg) 926 + { 927 + pci_save_state(pdev); 928 + pci_set_power_state(pdev, pci_choose_state(pdev, mesg)); 929 + return 0; 930 + } 931 + 932 + /** 933 + * ismt_resume() - PCI resume code 934 + * @pdev: PCI-Express device 935 + */ 936 + static int ismt_resume(struct pci_dev *pdev) 937 + { 938 + pci_set_power_state(pdev, PCI_D0); 939 + pci_restore_state(pdev); 940 + return pci_enable_device(pdev); 941 + } 942 + 943 + #else 944 + 945 + #define ismt_suspend NULL 946 + #define ismt_resume NULL 947 + 948 + #endif 949 + 950 + static struct pci_driver ismt_driver = { 951 + .name = "ismt_smbus", 952 + .id_table = ismt_ids, 953 + .probe = ismt_probe, 954 + .remove = ismt_remove, 955 + .suspend = ismt_suspend, 956 + .resume = ismt_resume, 957 + }; 958 + 959 + module_pci_driver(ismt_driver); 960 + 961 + MODULE_LICENSE("Dual BSD/GPL"); 962 + MODULE_AUTHOR("Bill E. Brown <bill.e.brown@intel.com>"); 963 + MODULE_DESCRIPTION("Intel SMBus Message Transport (iSMT) driver");
-2
drivers/i2c/busses/i2c-mpc.c
··· 696 696 return result; 697 697 698 698 fail_add: 699 - dev_set_drvdata(&op->dev, NULL); 700 699 free_irq(i2c->irq, i2c); 701 700 fail_request: 702 701 irq_dispose_mapping(i2c->irq); ··· 710 711 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev); 711 712 712 713 i2c_del_adapter(&i2c->adap); 713 - dev_set_drvdata(&op->dev, NULL); 714 714 715 715 if (i2c->irq) 716 716 free_irq(i2c->irq, i2c);
+218 -54
drivers/i2c/busses/i2c-mxs.c
··· 39 39 #define MXS_I2C_CTRL0_SET (0x04) 40 40 41 41 #define MXS_I2C_CTRL0_SFTRST 0x80000000 42 + #define MXS_I2C_CTRL0_RUN 0x20000000 42 43 #define MXS_I2C_CTRL0_SEND_NAK_ON_LAST 0x02000000 43 44 #define MXS_I2C_CTRL0_RETAIN_CLOCK 0x00200000 44 45 #define MXS_I2C_CTRL0_POST_SEND_STOP 0x00100000 ··· 65 64 #define MXS_I2C_CTRL1_SLAVE_STOP_IRQ 0x02 66 65 #define MXS_I2C_CTRL1_SLAVE_IRQ 0x01 67 66 67 + #define MXS_I2C_DATA (0xa0) 68 + 69 + #define MXS_I2C_DEBUG0 (0xb0) 70 + #define MXS_I2C_DEBUG0_CLR (0xb8) 71 + 72 + #define MXS_I2C_DEBUG0_DMAREQ 0x80000000 73 + 68 74 #define MXS_I2C_IRQ_MASK (MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ | \ 69 75 MXS_I2C_CTRL1_NO_SLAVE_ACK_IRQ | \ 70 76 MXS_I2C_CTRL1_EARLY_TERM_IRQ | \ ··· 93 85 #define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \ 94 86 MXS_I2C_CTRL0_MASTER_MODE) 95 87 96 - struct mxs_i2c_speed_config { 97 - uint32_t timing0; 98 - uint32_t timing1; 99 - uint32_t timing2; 100 - }; 101 - 102 - /* 103 - * Timing values for the default 24MHz clock supplied into the i2c block. 104 - * 105 - * The bus can operate at 95kHz or at 400kHz with the following timing 106 - * register configurations. The 100kHz mode isn't present because it's 107 - * values are not stated in the i.MX233/i.MX28 datasheet. The 95kHz mode 108 - * shall be close enough replacement. Therefore when the bus is configured 109 - * for 100kHz operation, 95kHz timing settings are actually loaded. 110 - * 111 - * For details, see i.MX233 [25.4.2 - 25.4.4] and i.MX28 [27.5.2 - 27.5.4]. 112 - */ 113 - static const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = { 114 - .timing0 = 0x00780030, 115 - .timing1 = 0x00800030, 116 - .timing2 = 0x00300030, 117 - }; 118 - 119 - static const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = { 120 - .timing0 = 0x000f0007, 121 - .timing1 = 0x001f000f, 122 - .timing2 = 0x00300030, 123 - }; 124 - 125 88 /** 126 89 * struct mxs_i2c_dev - per device, private MXS-I2C data 127 90 * ··· 108 129 struct completion cmd_complete; 109 130 int cmd_err; 110 131 struct i2c_adapter adapter; 111 - const struct mxs_i2c_speed_config *speed; 132 + 133 + uint32_t timing0; 134 + uint32_t timing1; 112 135 113 136 /* DMA support components */ 114 137 int dma_channel; ··· 126 145 { 127 146 stmp_reset_block(i2c->regs); 128 147 129 - writel(i2c->speed->timing0, i2c->regs + MXS_I2C_TIMING0); 130 - writel(i2c->speed->timing1, i2c->regs + MXS_I2C_TIMING1); 131 - writel(i2c->speed->timing2, i2c->regs + MXS_I2C_TIMING2); 148 + /* 149 + * Configure timing for the I2C block. The I2C TIMING2 register has to 150 + * be programmed with this particular magic number. The rest is derived 151 + * from the XTAL speed and requested I2C speed. 152 + * 153 + * For details, see i.MX233 [25.4.2 - 25.4.4] and i.MX28 [27.5.2 - 27.5.4]. 154 + */ 155 + writel(i2c->timing0, i2c->regs + MXS_I2C_TIMING0); 156 + writel(i2c->timing1, i2c->regs + MXS_I2C_TIMING1); 157 + writel(0x00300030, i2c->regs + MXS_I2C_TIMING2); 132 158 133 159 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); 134 160 } ··· 286 298 return -EINVAL; 287 299 } 288 300 301 + static int mxs_i2c_pio_wait_dmareq(struct mxs_i2c_dev *i2c) 302 + { 303 + unsigned long timeout = jiffies + msecs_to_jiffies(1000); 304 + 305 + while (!(readl(i2c->regs + MXS_I2C_DEBUG0) & 306 + MXS_I2C_DEBUG0_DMAREQ)) { 307 + if (time_after(jiffies, timeout)) 308 + return -ETIMEDOUT; 309 + cond_resched(); 310 + } 311 + 312 + writel(MXS_I2C_DEBUG0_DMAREQ, i2c->regs + MXS_I2C_DEBUG0_CLR); 313 + 314 + return 0; 315 + } 316 + 317 + static int mxs_i2c_pio_wait_cplt(struct mxs_i2c_dev *i2c) 318 + { 319 + unsigned long timeout = jiffies + msecs_to_jiffies(1000); 320 + 321 + /* 322 + * We do not use interrupts in the PIO mode. Due to the 323 + * maximum transfer length being 8 bytes in PIO mode, the 324 + * overhead of interrupt would be too large and this would 325 + * neglect the gain from using the PIO mode. 326 + */ 327 + 328 + while (!(readl(i2c->regs + MXS_I2C_CTRL1) & 329 + MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ)) { 330 + if (time_after(jiffies, timeout)) 331 + return -ETIMEDOUT; 332 + cond_resched(); 333 + } 334 + 335 + writel(MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ, 336 + i2c->regs + MXS_I2C_CTRL1_CLR); 337 + 338 + return 0; 339 + } 340 + 341 + static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap, 342 + struct i2c_msg *msg, uint32_t flags) 343 + { 344 + struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 345 + uint32_t addr_data = msg->addr << 1; 346 + uint32_t data = 0; 347 + int i, shifts_left, ret; 348 + 349 + /* Mute IRQs coming from this block. */ 350 + writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_CLR); 351 + 352 + if (msg->flags & I2C_M_RD) { 353 + addr_data |= I2C_SMBUS_READ; 354 + 355 + /* SELECT command. */ 356 + writel(MXS_I2C_CTRL0_RUN | MXS_CMD_I2C_SELECT, 357 + i2c->regs + MXS_I2C_CTRL0); 358 + 359 + ret = mxs_i2c_pio_wait_dmareq(i2c); 360 + if (ret) 361 + return ret; 362 + 363 + writel(addr_data, i2c->regs + MXS_I2C_DATA); 364 + 365 + ret = mxs_i2c_pio_wait_cplt(i2c); 366 + if (ret) 367 + return ret; 368 + 369 + /* READ command. */ 370 + writel(MXS_I2C_CTRL0_RUN | MXS_CMD_I2C_READ | flags | 371 + MXS_I2C_CTRL0_XFER_COUNT(msg->len), 372 + i2c->regs + MXS_I2C_CTRL0); 373 + 374 + for (i = 0; i < msg->len; i++) { 375 + if ((i & 3) == 0) { 376 + ret = mxs_i2c_pio_wait_dmareq(i2c); 377 + if (ret) 378 + return ret; 379 + data = readl(i2c->regs + MXS_I2C_DATA); 380 + } 381 + msg->buf[i] = data & 0xff; 382 + data >>= 8; 383 + } 384 + } else { 385 + addr_data |= I2C_SMBUS_WRITE; 386 + 387 + /* WRITE command. */ 388 + writel(MXS_I2C_CTRL0_RUN | MXS_CMD_I2C_WRITE | flags | 389 + MXS_I2C_CTRL0_XFER_COUNT(msg->len + 1), 390 + i2c->regs + MXS_I2C_CTRL0); 391 + 392 + /* 393 + * The LSB of data buffer is the first byte blasted across 394 + * the bus. Higher order bytes follow. Thus the following 395 + * filling schematic. 396 + */ 397 + data = addr_data << 24; 398 + for (i = 0; i < msg->len; i++) { 399 + data >>= 8; 400 + data |= (msg->buf[i] << 24); 401 + if ((i & 3) == 2) { 402 + ret = mxs_i2c_pio_wait_dmareq(i2c); 403 + if (ret) 404 + return ret; 405 + writel(data, i2c->regs + MXS_I2C_DATA); 406 + } 407 + } 408 + 409 + shifts_left = 24 - (i & 3) * 8; 410 + if (shifts_left) { 411 + data >>= shifts_left; 412 + ret = mxs_i2c_pio_wait_dmareq(i2c); 413 + if (ret) 414 + return ret; 415 + writel(data, i2c->regs + MXS_I2C_DATA); 416 + } 417 + } 418 + 419 + ret = mxs_i2c_pio_wait_cplt(i2c); 420 + if (ret) 421 + return ret; 422 + 423 + /* Clear any dangling IRQs and re-enable interrupts. */ 424 + writel(MXS_I2C_IRQ_MASK, i2c->regs + MXS_I2C_CTRL1_CLR); 425 + writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); 426 + 427 + return 0; 428 + } 429 + 289 430 /* 290 431 * Low level master read/write transaction. 291 432 */ ··· 433 316 if (msg->len == 0) 434 317 return -EINVAL; 435 318 436 - INIT_COMPLETION(i2c->cmd_complete); 437 - i2c->cmd_err = 0; 319 + /* 320 + * The current boundary to select between PIO/DMA transfer method 321 + * is set to 8 bytes, transfers shorter than 8 bytes are transfered 322 + * using PIO mode while longer transfers use DMA. The 8 byte border is 323 + * based on this empirical measurement and a lot of previous frobbing. 324 + */ 325 + if (msg->len < 8) { 326 + ret = mxs_i2c_pio_setup_xfer(adap, msg, flags); 327 + if (ret) 328 + mxs_i2c_reset(i2c); 329 + } else { 330 + i2c->cmd_err = 0; 331 + INIT_COMPLETION(i2c->cmd_complete); 332 + ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); 333 + if (ret) 334 + return ret; 438 335 439 - ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); 440 - if (ret) 441 - return ret; 442 - 443 - ret = wait_for_completion_timeout(&i2c->cmd_complete, 336 + ret = wait_for_completion_timeout(&i2c->cmd_complete, 444 337 msecs_to_jiffies(1000)); 445 - if (ret == 0) 446 - goto timeout; 338 + if (ret == 0) 339 + goto timeout; 447 340 448 - if (i2c->cmd_err == -ENXIO) 449 - mxs_i2c_reset(i2c); 341 + if (i2c->cmd_err == -ENXIO) 342 + mxs_i2c_reset(i2c); 450 343 451 - dev_dbg(i2c->dev, "Done with err=%d\n", i2c->cmd_err); 344 + ret = i2c->cmd_err; 345 + } 452 346 453 - return i2c->cmd_err; 347 + dev_dbg(i2c->dev, "Done with err=%d\n", ret); 348 + 349 + return ret; 454 350 455 351 timeout: 456 352 dev_dbg(i2c->dev, "Timeout!\n"); ··· 533 403 return true; 534 404 } 535 405 406 + static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, int speed) 407 + { 408 + /* The I2C block clock run at 24MHz */ 409 + const uint32_t clk = 24000000; 410 + uint32_t base; 411 + uint16_t high_count, low_count, rcv_count, xmit_count; 412 + struct device *dev = i2c->dev; 413 + 414 + if (speed > 540000) { 415 + dev_warn(dev, "Speed too high (%d Hz), using 540 kHz\n", speed); 416 + speed = 540000; 417 + } else if (speed < 12000) { 418 + dev_warn(dev, "Speed too low (%d Hz), using 12 kHz\n", speed); 419 + speed = 12000; 420 + } 421 + 422 + /* 423 + * The timing derivation algorithm. There is no documentation for this 424 + * algorithm available, it was derived by using the scope and fiddling 425 + * with constants until the result observed on the scope was good enough 426 + * for 20kHz, 50kHz, 100kHz, 200kHz, 300kHz and 400kHz. It should be 427 + * possible to assume the algorithm works for other frequencies as well. 428 + * 429 + * Note it was necessary to cap the frequency on both ends as it's not 430 + * possible to configure completely arbitrary frequency for the I2C bus 431 + * clock. 432 + */ 433 + base = ((clk / speed) - 38) / 2; 434 + high_count = base + 3; 435 + low_count = base - 3; 436 + rcv_count = (high_count * 3) / 4; 437 + xmit_count = low_count / 4; 438 + 439 + i2c->timing0 = (high_count << 16) | rcv_count; 440 + i2c->timing1 = (low_count << 16) | xmit_count; 441 + } 442 + 536 443 static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c) 537 444 { 538 445 uint32_t speed; ··· 589 422 } 590 423 591 424 ret = of_property_read_u32(node, "clock-frequency", &speed); 592 - if (ret) 425 + if (ret) { 593 426 dev_warn(dev, "No I2C speed selected, using 100kHz\n"); 594 - else if (speed == 400000) 595 - i2c->speed = &mxs_i2c_400kHz_config; 596 - else if (speed != 100000) 597 - dev_warn(dev, "Unsupported I2C speed selected, using 100kHz\n"); 427 + speed = 100000; 428 + } 429 + 430 + mxs_i2c_derive_timing(i2c, speed); 598 431 599 432 return 0; 600 433 } ··· 638 471 return err; 639 472 640 473 i2c->dev = dev; 641 - i2c->speed = &mxs_i2c_95kHz_config; 642 474 643 475 init_completion(&i2c->cmd_complete); 644 476 ··· 696 530 dma_release_channel(i2c->dmach); 697 531 698 532 writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET); 699 - 700 - platform_set_drvdata(pdev, NULL); 701 533 702 534 return 0; 703 535 }
+73 -73
drivers/i2c/busses/i2c-nforce2.c
··· 60 60 #include <linux/io.h> 61 61 62 62 MODULE_LICENSE("GPL"); 63 - MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>"); 63 + MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>"); 64 64 MODULE_DESCRIPTION("nForce2/3/4/5xx SMBus driver"); 65 65 66 66 ··· 188 188 } 189 189 190 190 /* Return negative errno on error */ 191 - static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, 191 + static s32 nforce2_access(struct i2c_adapter *adap, u16 addr, 192 192 unsigned short flags, char read_write, 193 - u8 command, int size, union i2c_smbus_data * data) 193 + u8 command, int size, union i2c_smbus_data *data) 194 194 { 195 195 struct nforce2_smbus *smbus = adap->algo_data; 196 196 unsigned char protocol, pec; ··· 202 202 pec = (flags & I2C_CLIENT_PEC) ? NVIDIA_SMB_PRTCL_PEC : 0; 203 203 204 204 switch (size) { 205 + case I2C_SMBUS_QUICK: 206 + protocol |= NVIDIA_SMB_PRTCL_QUICK; 207 + read_write = I2C_SMBUS_WRITE; 208 + break; 205 209 206 - case I2C_SMBUS_QUICK: 207 - protocol |= NVIDIA_SMB_PRTCL_QUICK; 208 - read_write = I2C_SMBUS_WRITE; 209 - break; 210 - 211 - case I2C_SMBUS_BYTE: 212 - if (read_write == I2C_SMBUS_WRITE) 213 - outb_p(command, NVIDIA_SMB_CMD); 214 - protocol |= NVIDIA_SMB_PRTCL_BYTE; 215 - break; 216 - 217 - case I2C_SMBUS_BYTE_DATA: 210 + case I2C_SMBUS_BYTE: 211 + if (read_write == I2C_SMBUS_WRITE) 218 212 outb_p(command, NVIDIA_SMB_CMD); 219 - if (read_write == I2C_SMBUS_WRITE) 220 - outb_p(data->byte, NVIDIA_SMB_DATA); 221 - protocol |= NVIDIA_SMB_PRTCL_BYTE_DATA; 222 - break; 213 + protocol |= NVIDIA_SMB_PRTCL_BYTE; 214 + break; 223 215 224 - case I2C_SMBUS_WORD_DATA: 225 - outb_p(command, NVIDIA_SMB_CMD); 226 - if (read_write == I2C_SMBUS_WRITE) { 227 - outb_p(data->word, NVIDIA_SMB_DATA); 228 - outb_p(data->word >> 8, NVIDIA_SMB_DATA+1); 216 + case I2C_SMBUS_BYTE_DATA: 217 + outb_p(command, NVIDIA_SMB_CMD); 218 + if (read_write == I2C_SMBUS_WRITE) 219 + outb_p(data->byte, NVIDIA_SMB_DATA); 220 + protocol |= NVIDIA_SMB_PRTCL_BYTE_DATA; 221 + break; 222 + 223 + case I2C_SMBUS_WORD_DATA: 224 + outb_p(command, NVIDIA_SMB_CMD); 225 + if (read_write == I2C_SMBUS_WRITE) { 226 + outb_p(data->word, NVIDIA_SMB_DATA); 227 + outb_p(data->word >> 8, NVIDIA_SMB_DATA + 1); 228 + } 229 + protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec; 230 + break; 231 + 232 + case I2C_SMBUS_BLOCK_DATA: 233 + outb_p(command, NVIDIA_SMB_CMD); 234 + if (read_write == I2C_SMBUS_WRITE) { 235 + len = data->block[0]; 236 + if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX)) { 237 + dev_err(&adap->dev, 238 + "Transaction failed (requested block size: %d)\n", 239 + len); 240 + return -EINVAL; 229 241 } 230 - protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec; 231 - break; 242 + outb_p(len, NVIDIA_SMB_BCNT); 243 + for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) 244 + outb_p(data->block[i + 1], 245 + NVIDIA_SMB_DATA + i); 246 + } 247 + protocol |= NVIDIA_SMB_PRTCL_BLOCK_DATA | pec; 248 + break; 232 249 233 - case I2C_SMBUS_BLOCK_DATA: 234 - outb_p(command, NVIDIA_SMB_CMD); 235 - if (read_write == I2C_SMBUS_WRITE) { 236 - len = data->block[0]; 237 - if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX)) { 238 - dev_err(&adap->dev, 239 - "Transaction failed " 240 - "(requested block size: %d)\n", 241 - len); 242 - return -EINVAL; 243 - } 244 - outb_p(len, NVIDIA_SMB_BCNT); 245 - for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) 246 - outb_p(data->block[i + 1], 247 - NVIDIA_SMB_DATA+i); 248 - } 249 - protocol |= NVIDIA_SMB_PRTCL_BLOCK_DATA | pec; 250 - break; 251 - 252 - default: 253 - dev_err(&adap->dev, "Unsupported transaction %d\n", size); 254 - return -EOPNOTSUPP; 250 + default: 251 + dev_err(&adap->dev, "Unsupported transaction %d\n", size); 252 + return -EOPNOTSUPP; 255 253 } 256 254 257 255 outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR); ··· 263 265 return 0; 264 266 265 267 switch (size) { 268 + case I2C_SMBUS_BYTE: 269 + case I2C_SMBUS_BYTE_DATA: 270 + data->byte = inb_p(NVIDIA_SMB_DATA); 271 + break; 266 272 267 - case I2C_SMBUS_BYTE: 268 - case I2C_SMBUS_BYTE_DATA: 269 - data->byte = inb_p(NVIDIA_SMB_DATA); 270 - break; 273 + case I2C_SMBUS_WORD_DATA: 274 + data->word = inb_p(NVIDIA_SMB_DATA) | 275 + (inb_p(NVIDIA_SMB_DATA + 1) << 8); 276 + break; 271 277 272 - case I2C_SMBUS_WORD_DATA: 273 - data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8); 274 - break; 275 - 276 - case I2C_SMBUS_BLOCK_DATA: 277 - len = inb_p(NVIDIA_SMB_BCNT); 278 - if ((len <= 0) || (len > I2C_SMBUS_BLOCK_MAX)) { 279 - dev_err(&adap->dev, "Transaction failed " 280 - "(received block size: 0x%02x)\n", 281 - len); 282 - return -EPROTO; 283 - } 284 - for (i = 0; i < len; i++) 285 - data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i); 286 - data->block[0] = len; 287 - break; 278 + case I2C_SMBUS_BLOCK_DATA: 279 + len = inb_p(NVIDIA_SMB_BCNT); 280 + if ((len <= 0) || (len > I2C_SMBUS_BLOCK_MAX)) { 281 + dev_err(&adap->dev, 282 + "Transaction failed (received block size: 0x%02x)\n", 283 + len); 284 + return -EPROTO; 285 + } 286 + for (i = 0; i < len; i++) 287 + data->block[i + 1] = inb_p(NVIDIA_SMB_DATA + i); 288 + data->block[0] = len; 289 + break; 288 290 } 289 291 290 292 return 0; ··· 297 299 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 298 300 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 299 301 I2C_FUNC_SMBUS_PEC | 300 - (((struct nforce2_smbus*)adapter->algo_data)->blockops ? 302 + (((struct nforce2_smbus *)adapter->algo_data)->blockops ? 301 303 I2C_FUNC_SMBUS_BLOCK_DATA : 0); 302 304 } 303 305 ··· 325 327 { 0 } 326 328 }; 327 329 328 - MODULE_DEVICE_TABLE (pci, nforce2_ids); 330 + MODULE_DEVICE_TABLE(pci, nforce2_ids); 329 331 330 332 331 333 static int nforce2_probe_smb(struct pci_dev *dev, int bar, int alt_reg, ··· 375 377 release_region(smbus->base, smbus->size); 376 378 return error; 377 379 } 378 - dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base); 380 + dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", 381 + smbus->base); 379 382 return 0; 380 383 } 381 384 ··· 387 388 int res1, res2; 388 389 389 390 /* we support 2 SMBus adapters */ 390 - if (!(smbuses = kzalloc(2*sizeof(struct nforce2_smbus), GFP_KERNEL))) 391 + smbuses = kzalloc(2 * sizeof(struct nforce2_smbus), GFP_KERNEL); 392 + if (!smbuses) 391 393 return -ENOMEM; 392 394 pci_set_drvdata(dev, smbuses); 393 395 394 - switch(dev->device) { 396 + switch (dev->device) { 395 397 case PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS: 396 398 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS: 397 399 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS:
+92 -8
drivers/i2c/busses/i2c-nomadik.c
··· 26 26 #include <linux/platform_data/i2c-nomadik.h> 27 27 #include <linux/of.h> 28 28 #include <linux/of_i2c.h> 29 + #include <linux/pinctrl/consumer.h> 29 30 30 31 #define DRIVER_NAME "nmk-i2c" 31 32 ··· 148 147 * @stop: stop condition. 149 148 * @xfer_complete: acknowledge completion for a I2C message. 150 149 * @result: controller propogated result. 150 + * @pinctrl: pinctrl handle. 151 + * @pins_default: default state for the pins. 152 + * @pins_idle: idle state for the pins. 153 + * @pins_sleep: sleep state for the pins. 151 154 * @busy: Busy doing transfer. 152 155 */ 153 156 struct nmk_i2c_dev { ··· 165 160 int stop; 166 161 struct completion xfer_complete; 167 162 int result; 163 + /* Three pin states - default, idle & sleep */ 164 + struct pinctrl *pinctrl; 165 + struct pinctrl_state *pins_default; 166 + struct pinctrl_state *pins_idle; 167 + struct pinctrl_state *pins_sleep; 168 168 bool busy; 169 169 }; 170 170 ··· 412 402 static int read_i2c(struct nmk_i2c_dev *dev, u16 flags) 413 403 { 414 404 u32 status = 0; 415 - u32 mcr; 416 - u32 irq_mask = 0; 405 + u32 mcr, irq_mask; 417 406 int timeout; 418 407 419 408 mcr = load_i2c_mcr_reg(dev, flags); ··· 481 472 static int write_i2c(struct nmk_i2c_dev *dev, u16 flags) 482 473 { 483 474 u32 status = 0; 484 - u32 mcr; 485 - u32 irq_mask = 0; 475 + u32 mcr, irq_mask; 486 476 int timeout; 487 477 488 478 mcr = load_i2c_mcr_reg(dev, flags); ··· 644 636 goto out_clk; 645 637 } 646 638 639 + /* Optionaly enable pins to be muxed in and configured */ 640 + if (!IS_ERR(dev->pins_default)) { 641 + status = pinctrl_select_state(dev->pinctrl, 642 + dev->pins_default); 643 + if (status) 644 + dev_err(&dev->adev->dev, 645 + "could not set default pins\n"); 646 + } 647 + 647 648 status = init_hw(dev); 648 649 if (status) 649 650 goto out; ··· 680 663 out: 681 664 clk_disable_unprepare(dev->clk); 682 665 out_clk: 666 + /* Optionally let pins go into idle state */ 667 + if (!IS_ERR(dev->pins_idle)) { 668 + status = pinctrl_select_state(dev->pinctrl, 669 + dev->pins_idle); 670 + if (status) 671 + dev_err(&dev->adev->dev, 672 + "could not set pins to idle state\n"); 673 + } 674 + 683 675 pm_runtime_put_sync(&dev->adev->dev); 684 676 685 677 dev->busy = false; ··· 729 703 struct nmk_i2c_dev *dev = arg; 730 704 u32 tft, rft; 731 705 u32 count; 732 - u32 misr; 733 - u32 src = 0; 706 + u32 misr, src; 734 707 735 708 /* load Tx FIFO and Rx FIFO threshold values */ 736 709 tft = readl(dev->virtbase + I2C_TFTR); ··· 882 857 { 883 858 struct amba_device *adev = to_amba_device(dev); 884 859 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 860 + int ret; 885 861 886 862 if (nmk_i2c->busy) 887 863 return -EBUSY; 864 + 865 + if (!IS_ERR(nmk_i2c->pins_sleep)) { 866 + ret = pinctrl_select_state(nmk_i2c->pinctrl, 867 + nmk_i2c->pins_sleep); 868 + if (ret) 869 + dev_err(dev, "could not set pins to sleep state\n"); 870 + } 888 871 889 872 return 0; 890 873 } 891 874 892 875 static int nmk_i2c_resume(struct device *dev) 893 876 { 877 + struct amba_device *adev = to_amba_device(dev); 878 + struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 879 + int ret; 880 + 881 + /* First go to the default state */ 882 + if (!IS_ERR(nmk_i2c->pins_default)) { 883 + ret = pinctrl_select_state(nmk_i2c->pinctrl, 884 + nmk_i2c->pins_default); 885 + if (ret) 886 + dev_err(dev, "could not set pins to default state\n"); 887 + } 888 + /* Then let's idle the pins until the next transfer happens */ 889 + if (!IS_ERR(nmk_i2c->pins_idle)) { 890 + ret = pinctrl_select_state(nmk_i2c->pinctrl, 891 + nmk_i2c->pins_idle); 892 + if (ret) 893 + dev_err(dev, "could not set pins to idle state\n"); 894 + } 894 895 return 0; 895 896 } 896 897 #else ··· 1004 953 dev->adev = adev; 1005 954 amba_set_drvdata(adev, dev); 1006 955 956 + dev->pinctrl = devm_pinctrl_get(&adev->dev); 957 + if (IS_ERR(dev->pinctrl)) { 958 + ret = PTR_ERR(dev->pinctrl); 959 + goto err_pinctrl; 960 + } 961 + 962 + dev->pins_default = pinctrl_lookup_state(dev->pinctrl, 963 + PINCTRL_STATE_DEFAULT); 964 + if (IS_ERR(dev->pins_default)) { 965 + dev_err(&adev->dev, "could not get default pinstate\n"); 966 + } else { 967 + ret = pinctrl_select_state(dev->pinctrl, 968 + dev->pins_default); 969 + if (ret) 970 + dev_dbg(&adev->dev, "could not set default pinstate\n"); 971 + } 972 + 973 + dev->pins_idle = pinctrl_lookup_state(dev->pinctrl, 974 + PINCTRL_STATE_IDLE); 975 + if (IS_ERR(dev->pins_idle)) { 976 + dev_dbg(&adev->dev, "could not get idle pinstate\n"); 977 + } else { 978 + /* If possible, let's go to idle until the first transfer */ 979 + ret = pinctrl_select_state(dev->pinctrl, 980 + dev->pins_idle); 981 + if (ret) 982 + dev_dbg(&adev->dev, "could not set idle pinstate\n"); 983 + } 984 + 985 + dev->pins_sleep = pinctrl_lookup_state(dev->pinctrl, 986 + PINCTRL_STATE_SLEEP); 987 + if (IS_ERR(dev->pins_sleep)) 988 + dev_dbg(&adev->dev, "could not get sleep pinstate\n"); 989 + 1007 990 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 1008 991 if (!dev->virtbase) { 1009 992 ret = -ENOMEM; ··· 1105 1020 err_irq: 1106 1021 iounmap(dev->virtbase); 1107 1022 err_no_ioremap: 1108 - amba_set_drvdata(adev, NULL); 1109 1023 kfree(dev); 1024 + err_pinctrl: 1110 1025 err_no_mem: 1111 1026 1112 1027 return ret; ··· 1129 1044 release_mem_region(res->start, resource_size(res)); 1130 1045 clk_put(dev->clk); 1131 1046 pm_runtime_disable(&adev->dev); 1132 - amba_set_drvdata(adev, NULL); 1133 1047 kfree(dev); 1134 1048 1135 1049 return 0;
+1 -2
drivers/i2c/busses/i2c-ocores.c
··· 332 332 &i2c->reg_io_width); 333 333 334 334 match = of_match_node(ocores_i2c_match, pdev->dev.of_node); 335 - if (match && (int)match->data == TYPE_GRLIB) { 335 + if (match && (long)match->data == TYPE_GRLIB) { 336 336 dev_dbg(&pdev->dev, "GRLIB variant of i2c-ocores\n"); 337 337 i2c->setreg = oc_setreg_grlib; 338 338 i2c->getreg = oc_getreg_grlib; ··· 452 452 453 453 /* remove adapter & data */ 454 454 i2c_del_adapter(&i2c->adap); 455 - platform_set_drvdata(pdev, NULL); 456 455 457 456 return 0; 458 457 }
+1 -4
drivers/i2c/busses/i2c-octeon.c
··· 595 595 result = i2c_add_adapter(&i2c->adap); 596 596 if (result < 0) { 597 597 dev_err(i2c->dev, "failed to add adapter\n"); 598 - goto fail_add; 598 + goto out; 599 599 } 600 600 dev_info(i2c->dev, "version %s\n", DRV_VERSION); 601 601 ··· 603 603 604 604 return 0; 605 605 606 - fail_add: 607 - platform_set_drvdata(pdev, NULL); 608 606 out: 609 607 return result; 610 608 }; ··· 612 614 struct octeon_i2c *i2c = platform_get_drvdata(pdev); 613 615 614 616 i2c_del_adapter(&i2c->adap); 615 - platform_set_drvdata(pdev, NULL); 616 617 return 0; 617 618 }; 618 619
-3
drivers/i2c/busses/i2c-omap.c
··· 1260 1260 pm_runtime_put(dev->dev); 1261 1261 pm_runtime_disable(&pdev->dev); 1262 1262 err_free_mem: 1263 - platform_set_drvdata(pdev, NULL); 1264 1263 1265 1264 return r; 1266 1265 } ··· 1268 1269 { 1269 1270 struct omap_i2c_dev *dev = platform_get_drvdata(pdev); 1270 1271 int ret; 1271 - 1272 - platform_set_drvdata(pdev, NULL); 1273 1272 1274 1273 i2c_del_adapter(&dev->adapter); 1275 1274 ret = pm_runtime_get_sync(&pdev->dev);
-1
drivers/i2c/busses/i2c-pca-platform.c
··· 260 260 static int i2c_pca_pf_remove(struct platform_device *pdev) 261 261 { 262 262 struct i2c_pca_pf_data *i2c = platform_get_drvdata(pdev); 263 - platform_set_drvdata(pdev, NULL); 264 263 265 264 i2c_del_adapter(&i2c->adap); 266 265
-2
drivers/i2c/busses/i2c-pmcmsp.c
··· 349 349 return 0; 350 350 351 351 ret_unmap: 352 - platform_set_drvdata(pldev, NULL); 353 352 if (pmcmsptwi_data.irq) { 354 353 pmcmsptwi_writel(0, 355 354 pmcmsptwi_data.iobase + MSP_TWI_INT_MSK_REG_OFFSET); ··· 373 374 374 375 i2c_del_adapter(&pmcmsptwi_adapter); 375 376 376 - platform_set_drvdata(pldev, NULL); 377 377 if (pmcmsptwi_data.irq) { 378 378 pmcmsptwi_writel(0, 379 379 pmcmsptwi_data.iobase + MSP_TWI_INT_MSK_REG_OFFSET);
-2
drivers/i2c/busses/i2c-pnx.c
··· 761 761 out_drvdata: 762 762 kfree(alg_data); 763 763 err_kzalloc: 764 - platform_set_drvdata(pdev, NULL); 765 764 return ret; 766 765 } 767 766 ··· 775 776 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE); 776 777 clk_put(alg_data->clk); 777 778 kfree(alg_data); 778 - platform_set_drvdata(pdev, NULL); 779 779 780 780 return 0; 781 781 }
-1
drivers/i2c/busses/i2c-powermac.c
··· 221 221 printk(KERN_WARNING 222 222 "i2c-powermac.c: Failed to remove bus %s !\n", 223 223 adapter->name); 224 - platform_set_drvdata(dev, NULL); 225 224 memset(adapter, 0, sizeof(*adapter)); 226 225 227 226 return 0;
-2
drivers/i2c/busses/i2c-puv3.c
··· 223 223 return 0; 224 224 225 225 fail_add_adapter: 226 - platform_set_drvdata(pdev, NULL); 227 226 kfree(adapter); 228 227 fail_nomem: 229 228 release_mem_region(mem->start, resource_size(mem)); ··· 244 245 } 245 246 246 247 put_device(&pdev->dev); 247 - platform_set_drvdata(pdev, NULL); 248 248 249 249 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 250 250 release_mem_region(mem->start, resource_size(mem));
-2
drivers/i2c/busses/i2c-pxa-pci.c
··· 128 128 return 0; 129 129 130 130 err_dev_add: 131 - pci_set_drvdata(dev, NULL); 132 131 kfree(sds); 133 132 err_mem: 134 133 pci_disable_device(dev); ··· 140 141 unsigned int i; 141 142 142 143 sds = pci_get_drvdata(dev); 143 - pci_set_drvdata(dev, NULL); 144 144 145 145 for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) 146 146 platform_device_unregister(sds->pdev[i]);
+2 -4
drivers/i2c/busses/i2c-pxa.c
··· 1215 1215 return ret; 1216 1216 } 1217 1217 1218 - static int __exit i2c_pxa_remove(struct platform_device *dev) 1218 + static int i2c_pxa_remove(struct platform_device *dev) 1219 1219 { 1220 1220 struct pxa_i2c *i2c = platform_get_drvdata(dev); 1221 - 1222 - platform_set_drvdata(dev, NULL); 1223 1221 1224 1222 i2c_del_adapter(&i2c->adap); 1225 1223 if (!i2c->use_pio) ··· 1267 1269 1268 1270 static struct platform_driver i2c_pxa_driver = { 1269 1271 .probe = i2c_pxa_probe, 1270 - .remove = __exit_p(i2c_pxa_remove), 1272 + .remove = i2c_pxa_remove, 1271 1273 .driver = { 1272 1274 .name = "pxa2xx-i2c", 1273 1275 .owner = THIS_MODULE,
+23 -39
drivers/i2c/busses/i2c-s3c2410.c
··· 111 111 { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 }, 112 112 { .compatible = "samsung,s3c2440-hdmiphy-i2c", 113 113 .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) }, 114 + { .compatible = "samsung,exynos5440-i2c", 115 + .data = (void *)(QUIRK_S3C2440 | QUIRK_NO_GPIO) }, 114 116 {}, 115 117 }; 116 118 MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match); ··· 1002 1000 1003 1001 i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1004 1002 if (!i2c->pdata) { 1005 - ret = -ENOMEM; 1006 - goto err_noclk; 1003 + dev_err(&pdev->dev, "no memory for platform data\n"); 1004 + return -ENOMEM; 1007 1005 } 1008 1006 1009 1007 i2c->quirks = s3c24xx_get_device_quirks(pdev); ··· 1024 1022 /* find the clock and enable it */ 1025 1023 1026 1024 i2c->dev = &pdev->dev; 1027 - i2c->clk = clk_get(&pdev->dev, "i2c"); 1025 + i2c->clk = devm_clk_get(&pdev->dev, "i2c"); 1028 1026 if (IS_ERR(i2c->clk)) { 1029 1027 dev_err(&pdev->dev, "cannot get clock\n"); 1030 - ret = -ENOENT; 1031 - goto err_noclk; 1028 + return -ENOENT; 1032 1029 } 1033 1030 1034 1031 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); 1035 1032 1036 - clk_prepare_enable(i2c->clk); 1037 1033 1038 1034 /* map the registers */ 1039 1035 1040 1036 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1041 1037 if (res == NULL) { 1042 1038 dev_err(&pdev->dev, "cannot find IO resource\n"); 1043 - ret = -ENOENT; 1044 - goto err_clk; 1039 + return -ENOENT; 1045 1040 } 1046 1041 1047 1042 i2c->regs = devm_ioremap_resource(&pdev->dev, res); 1048 1043 1049 - if (IS_ERR(i2c->regs)) { 1050 - ret = PTR_ERR(i2c->regs); 1051 - goto err_clk; 1052 - } 1044 + if (IS_ERR(i2c->regs)) 1045 + return PTR_ERR(i2c->regs); 1053 1046 1054 1047 dev_dbg(&pdev->dev, "registers %p (%p)\n", 1055 1048 i2c->regs, res); ··· 1061 1064 if (i2c->pdata->cfg_gpio) { 1062 1065 i2c->pdata->cfg_gpio(to_platform_device(i2c->dev)); 1063 1066 } else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c)) { 1064 - ret = -EINVAL; 1065 - goto err_clk; 1067 + return -EINVAL; 1066 1068 } 1067 1069 1068 1070 /* initialise the i2c controller */ 1069 1071 1072 + clk_prepare_enable(i2c->clk); 1070 1073 ret = s3c24xx_i2c_init(i2c); 1071 - if (ret != 0) 1072 - goto err_clk; 1073 - 1074 + clk_disable_unprepare(i2c->clk); 1075 + if (ret != 0) { 1076 + dev_err(&pdev->dev, "I2C controller init failed\n"); 1077 + return ret; 1078 + } 1074 1079 /* find the IRQ for this unit (note, this relies on the init call to 1075 1080 * ensure no current IRQs pending 1076 1081 */ ··· 1080 1081 i2c->irq = ret = platform_get_irq(pdev, 0); 1081 1082 if (ret <= 0) { 1082 1083 dev_err(&pdev->dev, "cannot find IRQ\n"); 1083 - goto err_clk; 1084 + return ret; 1084 1085 } 1085 1086 1086 - ret = request_irq(i2c->irq, s3c24xx_i2c_irq, 0, 1087 - dev_name(&pdev->dev), i2c); 1087 + ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, 0, 1088 + dev_name(&pdev->dev), i2c); 1088 1089 1089 1090 if (ret != 0) { 1090 1091 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); 1091 - goto err_clk; 1092 + return ret; 1092 1093 } 1093 1094 1094 1095 ret = s3c24xx_i2c_register_cpufreq(i2c); 1095 1096 if (ret < 0) { 1096 1097 dev_err(&pdev->dev, "failed to register cpufreq notifier\n"); 1097 - goto err_irq; 1098 + return ret; 1098 1099 } 1099 1100 1100 1101 /* Note, previous versions of the driver used i2c_add_adapter() ··· 1109 1110 ret = i2c_add_numbered_adapter(&i2c->adap); 1110 1111 if (ret < 0) { 1111 1112 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 1112 - goto err_cpufreq; 1113 + s3c24xx_i2c_deregister_cpufreq(i2c); 1114 + return ret; 1113 1115 } 1114 1116 1115 1117 of_i2c_register_devices(&i2c->adap); ··· 1120 1120 pm_runtime_enable(&i2c->adap.dev); 1121 1121 1122 1122 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev)); 1123 - clk_disable_unprepare(i2c->clk); 1124 1123 return 0; 1125 - 1126 - err_cpufreq: 1127 - s3c24xx_i2c_deregister_cpufreq(i2c); 1128 - 1129 - err_irq: 1130 - free_irq(i2c->irq, i2c); 1131 - 1132 - err_clk: 1133 - clk_disable_unprepare(i2c->clk); 1134 - clk_put(i2c->clk); 1135 - 1136 - err_noclk: 1137 - return ret; 1138 1124 } 1139 1125 1140 1126 /* s3c24xx_i2c_remove ··· 1138 1152 s3c24xx_i2c_deregister_cpufreq(i2c); 1139 1153 1140 1154 i2c_del_adapter(&i2c->adap); 1141 - free_irq(i2c->irq, i2c); 1142 1155 1143 1156 clk_disable_unprepare(i2c->clk); 1144 - clk_put(i2c->clk); 1145 1157 1146 1158 if (pdev->dev.of_node && IS_ERR(i2c->pctrl)) 1147 1159 s3c24xx_i2c_dt_gpio_free(i2c);
-1
drivers/i2c/busses/i2c-s6000.c
··· 365 365 { 366 366 struct s6i2c_if *iface = platform_get_drvdata(pdev); 367 367 i2c_wr16(iface, S6_I2C_ENABLE, 0); 368 - platform_set_drvdata(pdev, NULL); 369 368 i2c_del_adapter(&iface->adap); 370 369 free_irq(iface->irq, iface); 371 370 clk_disable(iface->clk);
-1
drivers/i2c/busses/i2c-sh7760.c
··· 546 546 release_resource(id->ioarea); 547 547 kfree(id->ioarea); 548 548 kfree(id); 549 - platform_set_drvdata(pdev, NULL); 550 549 551 550 return 0; 552 551 }
+106 -62
drivers/i2c/busses/i2c-sh_mobile.c
··· 38 38 /* Transmit operation: */ 39 39 /* */ 40 40 /* 0 byte transmit */ 41 - /* BUS: S A8 ACK P */ 41 + /* BUS: S A8 ACK P(*) */ 42 42 /* IRQ: DTE WAIT */ 43 43 /* ICIC: */ 44 44 /* ICCR: 0x94 0x90 */ 45 45 /* ICDR: A8 */ 46 46 /* */ 47 47 /* 1 byte transmit */ 48 - /* BUS: S A8 ACK D8(1) ACK P */ 48 + /* BUS: S A8 ACK D8(1) ACK P(*) */ 49 49 /* IRQ: DTE WAIT WAIT */ 50 50 /* ICIC: -DTE */ 51 51 /* ICCR: 0x94 0x90 */ 52 52 /* ICDR: A8 D8(1) */ 53 53 /* */ 54 54 /* 2 byte transmit */ 55 - /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P */ 55 + /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P(*) */ 56 56 /* IRQ: DTE WAIT WAIT WAIT */ 57 57 /* ICIC: -DTE */ 58 58 /* ICCR: 0x94 0x90 */ ··· 66 66 /* 0 byte receive - not supported since slave may hold SDA low */ 67 67 /* */ 68 68 /* 1 byte receive [TX] | [RX] */ 69 - /* BUS: S A8 ACK | D8(1) ACK P */ 69 + /* BUS: S A8 ACK | D8(1) ACK P(*) */ 70 70 /* IRQ: DTE WAIT | WAIT DTE */ 71 71 /* ICIC: -DTE | +DTE */ 72 72 /* ICCR: 0x94 0x81 | 0xc0 */ 73 73 /* ICDR: A8 | D8(1) */ 74 74 /* */ 75 75 /* 2 byte receive [TX]| [RX] */ 76 - /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK P */ 76 + /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK P(*) */ 77 77 /* IRQ: DTE WAIT | WAIT WAIT DTE */ 78 78 /* ICIC: -DTE | +DTE */ 79 79 /* ICCR: 0x94 0x81 | 0xc0 */ 80 80 /* ICDR: A8 | D8(1) D8(2) */ 81 81 /* */ 82 - /* 3 byte receive [TX] | [RX] */ 82 + /* 3 byte receive [TX] | [RX] (*) */ 83 83 /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK D8(3) ACK P */ 84 84 /* IRQ: DTE WAIT | WAIT WAIT WAIT DTE */ 85 85 /* ICIC: -DTE | +DTE */ ··· 94 94 /* SDA ___\___XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXAAAAAAAAA___/ */ 95 95 /* SCL \_/1\_/2\_/3\_/4\_/5\_/6\_/7\_/8\___/9\_____/ */ 96 96 /* */ 97 - /* S D7 D6 D5 D4 D3 D2 D1 D0 P */ 97 + /* S D7 D6 D5 D4 D3 D2 D1 D0 P(*) */ 98 98 /* ___ */ 99 99 /* WAIT IRQ ________________________________/ \___________ */ 100 100 /* TACK IRQ ____________________________________/ \_______ */ ··· 102 102 /* AL IRQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ 103 103 /* _______________________________________________ */ 104 104 /* BUSY __/ \_ */ 105 + /* */ 106 + /* (*) The STOP condition is only sent by the master at the end of the last */ 107 + /* I2C message or if the I2C_M_STOP flag is set. Similarly, the BUSY bit is */ 108 + /* only cleared after the STOP condition, so, between messages we have to */ 109 + /* poll for the DTE bit. */ 105 110 /* */ 106 111 107 112 enum sh_mobile_i2c_op { ··· 137 132 struct i2c_msg *msg; 138 133 int pos; 139 134 int sr; 135 + bool send_stop; 140 136 }; 141 137 142 138 #define IIC_FLAG_HAS_ICIC67 (1 << 0) ··· 328 322 break; 329 323 case OP_TX_STOP: /* write data and issue a stop afterwards */ 330 324 iic_wr(pd, ICDR, data); 331 - iic_wr(pd, ICCR, 0x90); 325 + iic_wr(pd, ICCR, pd->send_stop ? 0x90 : 0x94); 332 326 break; 333 327 case OP_TX_TO_RX: /* select read mode */ 334 328 iic_wr(pd, ICCR, 0x81); ··· 355 349 return ret; 356 350 } 357 351 358 - static int sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd) 352 + static bool sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd) 359 353 { 360 - if (pd->pos == -1) 361 - return 1; 362 - 363 - return 0; 354 + return pd->pos == -1; 364 355 } 365 356 366 - static int sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd) 357 + static bool sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd) 367 358 { 368 - if (pd->pos == (pd->msg->len - 1)) 369 - return 1; 370 - 371 - return 0; 359 + return pd->pos == pd->msg->len - 1; 372 360 } 373 361 374 362 static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd, ··· 475 475 return IRQ_HANDLED; 476 476 } 477 477 478 - static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg) 478 + static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg, 479 + bool do_init) 479 480 { 480 481 if (usr_msg->len == 0 && (usr_msg->flags & I2C_M_RD)) { 481 482 dev_err(pd->dev, "Unsupported zero length i2c read\n"); 482 483 return -EIO; 483 484 } 484 485 485 - /* Initialize channel registers */ 486 - iic_set_clr(pd, ICCR, 0, ICCR_ICE); 486 + if (do_init) { 487 + /* Initialize channel registers */ 488 + iic_set_clr(pd, ICCR, 0, ICCR_ICE); 487 489 488 - /* Enable channel and configure rx ack */ 489 - iic_set_clr(pd, ICCR, ICCR_ICE, 0); 490 + /* Enable channel and configure rx ack */ 491 + iic_set_clr(pd, ICCR, ICCR_ICE, 0); 490 492 491 - /* Set the clock */ 492 - iic_wr(pd, ICCL, pd->iccl & 0xff); 493 - iic_wr(pd, ICCH, pd->icch & 0xff); 493 + /* Set the clock */ 494 + iic_wr(pd, ICCL, pd->iccl & 0xff); 495 + iic_wr(pd, ICCH, pd->icch & 0xff); 496 + } 494 497 495 498 pd->msg = usr_msg; 496 499 pd->pos = -1; ··· 504 501 return 0; 505 502 } 506 503 507 - static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, 508 - struct i2c_msg *msgs, 509 - int num) 504 + static int poll_dte(struct sh_mobile_i2c_data *pd) 510 505 { 511 - struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter); 512 - struct i2c_msg *msg; 513 - int err = 0; 514 - u_int8_t val; 515 - int i, k, retry_count; 506 + int i; 516 507 517 - activate_ch(pd); 508 + for (i = 1000; i; i--) { 509 + u_int8_t val = iic_rd(pd, ICSR); 518 510 519 - /* Process all messages */ 520 - for (i = 0; i < num; i++) { 521 - msg = &msgs[i]; 522 - 523 - err = start_ch(pd, msg); 524 - if (err) 511 + if (val & ICSR_DTE) 525 512 break; 526 513 527 - i2c_op(pd, OP_START, 0); 514 + if (val & ICSR_TACK) 515 + return -EIO; 528 516 529 - /* The interrupt handler takes care of the rest... */ 530 - k = wait_event_timeout(pd->wait, 531 - pd->sr & (ICSR_TACK | SW_DONE), 532 - 5 * HZ); 533 - if (!k) 534 - dev_err(pd->dev, "Transfer request timed out\n"); 517 + udelay(10); 518 + } 535 519 536 - retry_count = 1000; 537 - again: 538 - val = iic_rd(pd, ICSR); 520 + if (!i) { 521 + dev_warn(pd->dev, "Timeout polling for DTE!\n"); 522 + return -ETIMEDOUT; 523 + } 524 + 525 + return 0; 526 + } 527 + 528 + static int poll_busy(struct sh_mobile_i2c_data *pd) 529 + { 530 + int i; 531 + 532 + for (i = 1000; i; i--) { 533 + u_int8_t val = iic_rd(pd, ICSR); 539 534 540 535 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); 541 536 ··· 541 540 * transfer is finished, so poll the hardware 542 541 * until we're done. 543 542 */ 544 - if (val & ICSR_BUSY) { 545 - udelay(10); 546 - if (retry_count--) 547 - goto again; 548 - 549 - err = -EIO; 550 - dev_err(pd->dev, "Polling timed out\n"); 543 + if (!(val & ICSR_BUSY)) { 544 + /* handle missing acknowledge and arbitration lost */ 545 + if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) 546 + return -EIO; 551 547 break; 552 548 } 553 549 554 - /* handle missing acknowledge and arbitration lost */ 555 - if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) { 556 - err = -EIO; 550 + udelay(10); 551 + } 552 + 553 + if (!i) { 554 + dev_err(pd->dev, "Polling timed out\n"); 555 + return -ETIMEDOUT; 556 + } 557 + 558 + return 0; 559 + } 560 + 561 + static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, 562 + struct i2c_msg *msgs, 563 + int num) 564 + { 565 + struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter); 566 + struct i2c_msg *msg; 567 + int err = 0; 568 + int i, k; 569 + 570 + activate_ch(pd); 571 + 572 + /* Process all messages */ 573 + for (i = 0; i < num; i++) { 574 + bool do_start = pd->send_stop || !i; 575 + msg = &msgs[i]; 576 + pd->send_stop = i == num - 1 || msg->flags & I2C_M_STOP; 577 + 578 + err = start_ch(pd, msg, do_start); 579 + if (err) 580 + break; 581 + 582 + if (do_start) 583 + i2c_op(pd, OP_START, 0); 584 + 585 + /* The interrupt handler takes care of the rest... */ 586 + k = wait_event_timeout(pd->wait, 587 + pd->sr & (ICSR_TACK | SW_DONE), 588 + 5 * HZ); 589 + if (!k) { 590 + dev_err(pd->dev, "Transfer request timed out\n"); 591 + err = -ETIMEDOUT; 557 592 break; 558 593 } 594 + 595 + if (pd->send_stop) 596 + err = poll_busy(pd); 597 + else 598 + err = poll_dte(pd); 599 + if (err < 0) 600 + break; 559 601 } 560 602 561 603 deactivate_ch(pd); ··· 610 566 611 567 static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter) 612 568 { 613 - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 569 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING; 614 570 } 615 571 616 572 static struct i2c_algorithm sh_mobile_i2c_algorithm = {
+200 -158
drivers/i2c/busses/i2c-sis630.c
··· 17 17 */ 18 18 19 19 /* 20 - Changes: 21 - 24.08.2002 22 - Fixed the typo in sis630_access (Thanks to Mark M. Hoffman) 23 - Changed sis630_transaction.(Thanks to Mark M. Hoffman) 24 - 18.09.2002 25 - Added SIS730 as supported. 26 - 21.09.2002 27 - Added high_clock module option.If this option is set 28 - used Host Master Clock 56KHz (default 14KHz).For now we save old Host 29 - Master Clock and after transaction completed restore (otherwise 30 - it's confuse BIOS and hung Machine). 31 - 24.09.2002 32 - Fixed typo in sis630_access 33 - Fixed logical error by restoring of Host Master Clock 34 - 31.07.2003 35 - Added block data read/write support. 36 - */ 37 - 38 - /* 39 20 Status: beta 40 21 41 22 Supports: 42 23 SIS 630 43 24 SIS 730 25 + SIS 964 26 + 27 + Notable differences between chips: 28 + +------------------------+--------------------+-------------------+ 29 + | | SIS630/730 | SIS964 | 30 + +------------------------+--------------------+-------------------+ 31 + | Clock | 14kHz/56kHz | 55.56kHz/27.78kHz | 32 + | SMBus registers offset | 0x80 | 0xE0 | 33 + | SMB_CNT | Bit 1 = Slave Busy | Bit 1 = Bus probe | 34 + | (not used yet) | Bit 3 is reserved | Bit 3 = Last byte | 35 + | SMB_PCOUNT | Offset + 0x06 | Offset + 0x14 | 36 + | SMB_COUNT | 4:0 bits | 5:0 bits | 37 + +------------------------+--------------------+-------------------+ 38 + (Other differences don't affect the functions provided by the driver) 44 39 45 40 Note: we assume there can only be one device, with one SMBus interface. 46 41 */ ··· 50 55 #include <linux/acpi.h> 51 56 #include <linux/io.h> 52 57 53 - /* SIS630 SMBus registers */ 54 - #define SMB_STS 0x80 /* status */ 55 - #define SMB_EN 0x81 /* status enable */ 56 - #define SMB_CNT 0x82 57 - #define SMBHOST_CNT 0x83 58 - #define SMB_ADDR 0x84 59 - #define SMB_CMD 0x85 60 - #define SMB_PCOUNT 0x86 /* processed count */ 61 - #define SMB_COUNT 0x87 62 - #define SMB_BYTE 0x88 /* ~0x8F data byte field */ 63 - #define SMBDEV_ADDR 0x90 64 - #define SMB_DB0 0x91 65 - #define SMB_DB1 0x92 66 - #define SMB_SAA 0x93 58 + /* SIS964 id is defined here as we are the only file using it */ 59 + #define PCI_DEVICE_ID_SI_964 0x0964 67 60 68 - /* register count for request_region */ 61 + /* SIS630/730/964 SMBus registers */ 62 + #define SMB_STS 0x00 /* status */ 63 + #define SMB_CNT 0x02 /* control */ 64 + #define SMBHOST_CNT 0x03 /* host control */ 65 + #define SMB_ADDR 0x04 /* address */ 66 + #define SMB_CMD 0x05 /* command */ 67 + #define SMB_COUNT 0x07 /* byte count */ 68 + #define SMB_BYTE 0x08 /* ~0x8F data byte field */ 69 + 70 + /* SMB_STS register */ 71 + #define BYTE_DONE_STS 0x10 /* Byte Done Status / Block Array */ 72 + #define SMBCOL_STS 0x04 /* Collision */ 73 + #define SMBERR_STS 0x02 /* Device error */ 74 + 75 + /* SMB_CNT register */ 76 + #define MSTO_EN 0x40 /* Host Master Timeout Enable */ 77 + #define SMBCLK_SEL 0x20 /* Host master clock selection */ 78 + #define SMB_PROBE 0x02 /* Bus Probe/Slave busy */ 79 + #define SMB_HOSTBUSY 0x01 /* Host Busy */ 80 + 81 + /* SMBHOST_CNT register */ 82 + #define SMB_KILL 0x20 /* Kill */ 83 + #define SMB_START 0x10 /* Start */ 84 + 85 + /* register count for request_region 86 + * As we don't use SMB_PCOUNT, 20 is ok for SiS630 and SiS964 87 + */ 69 88 #define SIS630_SMB_IOREGION 20 70 89 71 90 /* PCI address constants */ ··· 105 96 static bool high_clock; 106 97 static bool force; 107 98 module_param(high_clock, bool, 0); 108 - MODULE_PARM_DESC(high_clock, "Set Host Master Clock to 56KHz (default 14KHz)."); 99 + MODULE_PARM_DESC(high_clock, 100 + "Set Host Master Clock to 56KHz (default 14KHz) (SIS630/730 only)."); 109 101 module_param(force, bool, 0); 110 102 MODULE_PARM_DESC(force, "Forcibly enable the SIS630. DANGEROUS!"); 111 103 112 - /* acpi base address */ 113 - static unsigned short acpi_base; 104 + /* SMBus base adress */ 105 + static unsigned short smbus_base; 114 106 115 107 /* supported chips */ 116 108 static int supported[] = { 117 109 PCI_DEVICE_ID_SI_630, 118 110 PCI_DEVICE_ID_SI_730, 111 + PCI_DEVICE_ID_SI_760, 119 112 0 /* terminates the list */ 120 113 }; 121 114 122 115 static inline u8 sis630_read(u8 reg) 123 116 { 124 - return inb(acpi_base + reg); 117 + return inb(smbus_base + reg); 125 118 } 126 119 127 120 static inline void sis630_write(u8 reg, u8 data) 128 121 { 129 - outb(data, acpi_base + reg); 122 + outb(data, smbus_base + reg); 130 123 } 131 124 132 - static int sis630_transaction_start(struct i2c_adapter *adap, int size, u8 *oldclock) 125 + static int sis630_transaction_start(struct i2c_adapter *adap, int size, 126 + u8 *oldclock) 133 127 { 134 - int temp; 128 + int temp; 135 129 136 130 /* Make sure the SMBus host is ready to start transmitting. */ 137 - if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { 138 - dev_dbg(&adap->dev, "SMBus busy (%02x).Resetting...\n",temp); 131 + temp = sis630_read(SMB_CNT); 132 + if ((temp & (SMB_PROBE | SMB_HOSTBUSY)) != 0x00) { 133 + dev_dbg(&adap->dev, "SMBus busy (%02x). Resetting...\n", temp); 139 134 /* kill smbus transaction */ 140 - sis630_write(SMBHOST_CNT, 0x20); 135 + sis630_write(SMBHOST_CNT, SMB_KILL); 141 136 142 - if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { 137 + temp = sis630_read(SMB_CNT); 138 + if (temp & (SMB_PROBE | SMB_HOSTBUSY)) { 143 139 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); 144 140 return -EBUSY; 145 - } else { 141 + } else { 146 142 dev_dbg(&adap->dev, "Successful!\n"); 147 143 } 148 - } 144 + } 149 145 150 146 /* save old clock, so we can prevent machine for hung */ 151 147 *oldclock = sis630_read(SMB_CNT); 152 148 153 149 dev_dbg(&adap->dev, "saved clock 0x%02x\n", *oldclock); 154 150 155 - /* disable timeout interrupt , set Host Master Clock to 56KHz if requested */ 151 + /* disable timeout interrupt, 152 + * set Host Master Clock to 56KHz if requested */ 156 153 if (high_clock) 157 - sis630_write(SMB_CNT, 0x20); 154 + sis630_write(SMB_CNT, SMBCLK_SEL); 158 155 else 159 - sis630_write(SMB_CNT, (*oldclock & ~0x40)); 156 + sis630_write(SMB_CNT, (*oldclock & ~MSTO_EN)); 160 157 161 158 /* clear all sticky bits */ 162 159 temp = sis630_read(SMB_STS); 163 160 sis630_write(SMB_STS, temp & 0x1e); 164 161 165 162 /* start the transaction by setting bit 4 and size */ 166 - sis630_write(SMBHOST_CNT,0x10 | (size & 0x07)); 163 + sis630_write(SMBHOST_CNT, SMB_START | (size & 0x07)); 167 164 168 165 return 0; 169 166 } ··· 183 168 msleep(1); 184 169 temp = sis630_read(SMB_STS); 185 170 /* check if block transmitted */ 186 - if (size == SIS630_BLOCK_DATA && (temp & 0x10)) 171 + if (size == SIS630_BLOCK_DATA && (temp & BYTE_DONE_STS)) 187 172 break; 188 173 } while (!(temp & 0x0e) && (timeout++ < MAX_TIMEOUT)); 189 174 ··· 193 178 result = -ETIMEDOUT; 194 179 } 195 180 196 - if (temp & 0x02) { 181 + if (temp & SMBERR_STS) { 197 182 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 198 183 result = -ENXIO; 199 184 } 200 185 201 - if (temp & 0x04) { 186 + if (temp & SMBCOL_STS) { 202 187 dev_err(&adap->dev, "Bus collision!\n"); 203 - result = -EIO; 204 - /* 205 - TBD: Datasheet say: 206 - the software should clear this bit and restart SMBUS operation. 207 - Should we do it or user start request again? 208 - */ 188 + result = -EAGAIN; 209 189 } 210 190 211 191 return result; ··· 208 198 209 199 static void sis630_transaction_end(struct i2c_adapter *adap, u8 oldclock) 210 200 { 211 - int temp = 0; 212 - 213 201 /* clear all status "sticky" bits */ 214 - sis630_write(SMB_STS, temp); 202 + sis630_write(SMB_STS, 0xFF); 215 203 216 - dev_dbg(&adap->dev, "SMB_CNT before clock restore 0x%02x\n", sis630_read(SMB_CNT)); 204 + dev_dbg(&adap->dev, 205 + "SMB_CNT before clock restore 0x%02x\n", sis630_read(SMB_CNT)); 217 206 218 207 /* 219 208 * restore old Host Master Clock if high_clock is set 220 209 * and oldclock was not 56KHz 221 210 */ 222 - if (high_clock && !(oldclock & 0x20)) 223 - sis630_write(SMB_CNT,(sis630_read(SMB_CNT) & ~0x20)); 211 + if (high_clock && !(oldclock & SMBCLK_SEL)) 212 + sis630_write(SMB_CNT, sis630_read(SMB_CNT) & ~SMBCLK_SEL); 224 213 225 - dev_dbg(&adap->dev, "SMB_CNT after clock restore 0x%02x\n", sis630_read(SMB_CNT)); 214 + dev_dbg(&adap->dev, 215 + "SMB_CNT after clock restore 0x%02x\n", sis630_read(SMB_CNT)); 226 216 } 227 217 228 218 static int sis630_transaction(struct i2c_adapter *adap, int size) ··· 239 229 return result; 240 230 } 241 231 242 - static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *data, int read_write) 232 + static int sis630_block_data(struct i2c_adapter *adap, 233 + union i2c_smbus_data *data, int read_write) 243 234 { 244 235 int i, len = 0, rc = 0; 245 236 u8 oldclock = 0; ··· 252 241 else if (len > 32) 253 242 len = 32; 254 243 sis630_write(SMB_COUNT, len); 255 - for (i=1; i <= len; i++) { 256 - dev_dbg(&adap->dev, "set data 0x%02x\n", data->block[i]); 244 + for (i = 1; i <= len; i++) { 245 + dev_dbg(&adap->dev, 246 + "set data 0x%02x\n", data->block[i]); 257 247 /* set data */ 258 - sis630_write(SMB_BYTE+(i-1)%8, data->block[i]); 259 - if (i==8 || (len<8 && i==len)) { 260 - dev_dbg(&adap->dev, "start trans len=%d i=%d\n",len ,i); 248 + sis630_write(SMB_BYTE + (i - 1) % 8, data->block[i]); 249 + if (i == 8 || (len < 8 && i == len)) { 250 + dev_dbg(&adap->dev, 251 + "start trans len=%d i=%d\n", len, i); 261 252 /* first transaction */ 262 253 rc = sis630_transaction_start(adap, 263 254 SIS630_BLOCK_DATA, &oldclock); 264 255 if (rc) 265 256 return rc; 266 - } 267 - else if ((i-1)%8 == 7 || i==len) { 268 - dev_dbg(&adap->dev, "trans_wait len=%d i=%d\n",len,i); 269 - if (i>8) { 270 - dev_dbg(&adap->dev, "clear smbary_sts len=%d i=%d\n",len,i); 257 + } else if ((i - 1) % 8 == 7 || i == len) { 258 + dev_dbg(&adap->dev, 259 + "trans_wait len=%d i=%d\n", len, i); 260 + if (i > 8) { 261 + dev_dbg(&adap->dev, 262 + "clear smbary_sts" 263 + " len=%d i=%d\n", len, i); 271 264 /* 272 265 If this is not first transaction, 273 266 we must clear sticky bit. 274 267 clear SMBARY_STS 275 268 */ 276 - sis630_write(SMB_STS,0x10); 269 + sis630_write(SMB_STS, BYTE_DONE_STS); 277 270 } 278 271 rc = sis630_transaction_wait(adap, 279 272 SIS630_BLOCK_DATA); 280 273 if (rc) { 281 - dev_dbg(&adap->dev, "trans_wait failed\n"); 274 + dev_dbg(&adap->dev, 275 + "trans_wait failed\n"); 282 276 break; 283 277 } 284 278 } 285 279 } 286 - } 287 - else { 280 + } else { 288 281 /* read request */ 289 282 data->block[0] = len = 0; 290 283 rc = sis630_transaction_start(adap, ··· 309 294 if (data->block[0] > 32) 310 295 data->block[0] = 32; 311 296 312 - dev_dbg(&adap->dev, "block data read len=0x%x\n", data->block[0]); 297 + dev_dbg(&adap->dev, 298 + "block data read len=0x%x\n", data->block[0]); 313 299 314 - for (i=0; i < 8 && len < data->block[0]; i++,len++) { 315 - dev_dbg(&adap->dev, "read i=%d len=%d\n", i, len); 316 - data->block[len+1] = sis630_read(SMB_BYTE+i); 300 + for (i = 0; i < 8 && len < data->block[0]; i++, len++) { 301 + dev_dbg(&adap->dev, 302 + "read i=%d len=%d\n", i, len); 303 + data->block[len + 1] = sis630_read(SMB_BYTE + 304 + i); 317 305 } 318 306 319 - dev_dbg(&adap->dev, "clear smbary_sts len=%d i=%d\n",len,i); 307 + dev_dbg(&adap->dev, 308 + "clear smbary_sts len=%d i=%d\n", len, i); 320 309 321 310 /* clear SMBARY_STS */ 322 - sis630_write(SMB_STS,0x10); 323 - } while(len < data->block[0]); 311 + sis630_write(SMB_STS, BYTE_DONE_STS); 312 + } while (len < data->block[0]); 324 313 } 325 314 326 315 sis630_transaction_end(adap, oldclock); ··· 340 321 int status; 341 322 342 323 switch (size) { 343 - case I2C_SMBUS_QUICK: 344 - sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); 345 - size = SIS630_QUICK; 346 - break; 347 - case I2C_SMBUS_BYTE: 348 - sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); 349 - if (read_write == I2C_SMBUS_WRITE) 350 - sis630_write(SMB_CMD, command); 351 - size = SIS630_BYTE; 352 - break; 353 - case I2C_SMBUS_BYTE_DATA: 354 - sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); 324 + case I2C_SMBUS_QUICK: 325 + sis630_write(SMB_ADDR, 326 + ((addr & 0x7f) << 1) | (read_write & 0x01)); 327 + size = SIS630_QUICK; 328 + break; 329 + case I2C_SMBUS_BYTE: 330 + sis630_write(SMB_ADDR, 331 + ((addr & 0x7f) << 1) | (read_write & 0x01)); 332 + if (read_write == I2C_SMBUS_WRITE) 355 333 sis630_write(SMB_CMD, command); 356 - if (read_write == I2C_SMBUS_WRITE) 357 - sis630_write(SMB_BYTE, data->byte); 358 - size = SIS630_BYTE_DATA; 359 - break; 360 - case I2C_SMBUS_PROC_CALL: 361 - case I2C_SMBUS_WORD_DATA: 362 - sis630_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01)); 363 - sis630_write(SMB_CMD, command); 364 - if (read_write == I2C_SMBUS_WRITE) { 365 - sis630_write(SMB_BYTE, data->word & 0xff); 366 - sis630_write(SMB_BYTE + 1,(data->word & 0xff00) >> 8); 367 - } 368 - size = (size == I2C_SMBUS_PROC_CALL ? SIS630_PCALL : SIS630_WORD_DATA); 369 - break; 370 - case I2C_SMBUS_BLOCK_DATA: 371 - sis630_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01)); 372 - sis630_write(SMB_CMD, command); 373 - size = SIS630_BLOCK_DATA; 374 - return sis630_block_data(adap, data, read_write); 375 - default: 376 - dev_warn(&adap->dev, "Unsupported transaction %d\n", 377 - size); 378 - return -EOPNOTSUPP; 334 + size = SIS630_BYTE; 335 + break; 336 + case I2C_SMBUS_BYTE_DATA: 337 + sis630_write(SMB_ADDR, 338 + ((addr & 0x7f) << 1) | (read_write & 0x01)); 339 + sis630_write(SMB_CMD, command); 340 + if (read_write == I2C_SMBUS_WRITE) 341 + sis630_write(SMB_BYTE, data->byte); 342 + size = SIS630_BYTE_DATA; 343 + break; 344 + case I2C_SMBUS_PROC_CALL: 345 + case I2C_SMBUS_WORD_DATA: 346 + sis630_write(SMB_ADDR, 347 + ((addr & 0x7f) << 1) | (read_write & 0x01)); 348 + sis630_write(SMB_CMD, command); 349 + if (read_write == I2C_SMBUS_WRITE) { 350 + sis630_write(SMB_BYTE, data->word & 0xff); 351 + sis630_write(SMB_BYTE + 1, (data->word & 0xff00) >> 8); 352 + } 353 + size = (size == I2C_SMBUS_PROC_CALL ? 354 + SIS630_PCALL : SIS630_WORD_DATA); 355 + break; 356 + case I2C_SMBUS_BLOCK_DATA: 357 + sis630_write(SMB_ADDR, 358 + ((addr & 0x7f) << 1) | (read_write & 0x01)); 359 + sis630_write(SMB_CMD, command); 360 + size = SIS630_BLOCK_DATA; 361 + return sis630_block_data(adap, data, read_write); 362 + default: 363 + dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 364 + return -EOPNOTSUPP; 379 365 } 380 366 381 367 status = sis630_transaction(adap, size); ··· 392 368 return 0; 393 369 } 394 370 395 - switch(size) { 396 - case SIS630_BYTE: 397 - case SIS630_BYTE_DATA: 398 - data->byte = sis630_read(SMB_BYTE); 399 - break; 400 - case SIS630_PCALL: 401 - case SIS630_WORD_DATA: 402 - data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8); 403 - break; 371 + switch (size) { 372 + case SIS630_BYTE: 373 + case SIS630_BYTE_DATA: 374 + data->byte = sis630_read(SMB_BYTE); 375 + break; 376 + case SIS630_PCALL: 377 + case SIS630_WORD_DATA: 378 + data->word = sis630_read(SMB_BYTE) + 379 + (sis630_read(SMB_BYTE + 1) << 8); 380 + break; 404 381 } 405 382 406 383 return 0; ··· 409 384 410 385 static u32 sis630_func(struct i2c_adapter *adapter) 411 386 { 412 - return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA | 413 - I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_PROC_CALL | 414 - I2C_FUNC_SMBUS_BLOCK_DATA; 387 + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 388 + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 389 + I2C_FUNC_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_BLOCK_DATA; 415 390 } 416 391 417 392 static int sis630_setup(struct pci_dev *sis630_dev) ··· 419 394 unsigned char b; 420 395 struct pci_dev *dummy = NULL; 421 396 int retval, i; 397 + /* acpi base address */ 398 + unsigned short acpi_base; 422 399 423 400 /* check for supported SiS devices */ 424 - for (i=0; supported[i] > 0 ; i++) { 425 - if ((dummy = pci_get_device(PCI_VENDOR_ID_SI, supported[i], dummy))) 401 + for (i = 0; supported[i] > 0; i++) { 402 + dummy = pci_get_device(PCI_VENDOR_ID_SI, supported[i], dummy); 403 + if (dummy) 426 404 break; /* found */ 427 405 } 428 406 429 407 if (dummy) { 430 408 pci_dev_put(dummy); 431 - } 432 - else if (force) { 433 - dev_err(&sis630_dev->dev, "WARNING: Can't detect SIS630 compatible device, but " 409 + } else if (force) { 410 + dev_err(&sis630_dev->dev, 411 + "WARNING: Can't detect SIS630 compatible device, but " 434 412 "loading because of force option enabled\n"); 435 - } 436 - else { 413 + } else { 437 414 return -ENODEV; 438 415 } 439 416 ··· 443 416 Enable ACPI first , so we can accsess reg 74-75 444 417 in acpi io space and read acpi base addr 445 418 */ 446 - if (pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG,&b)) { 419 + if (pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, &b)) { 447 420 dev_err(&sis630_dev->dev, "Error: Can't read bios ctl reg\n"); 448 421 retval = -ENODEV; 449 422 goto exit; ··· 457 430 } 458 431 459 432 /* Determine the ACPI base address */ 460 - if (pci_read_config_word(sis630_dev,SIS630_ACPI_BASE_REG,&acpi_base)) { 461 - dev_err(&sis630_dev->dev, "Error: Can't determine ACPI base address\n"); 433 + if (pci_read_config_word(sis630_dev, 434 + SIS630_ACPI_BASE_REG, &acpi_base)) { 435 + dev_err(&sis630_dev->dev, 436 + "Error: Can't determine ACPI base address\n"); 462 437 retval = -ENODEV; 463 438 goto exit; 464 439 } 465 440 466 - dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base); 441 + dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04hx\n", acpi_base); 467 442 468 - retval = acpi_check_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION, 443 + if (supported[i] == PCI_DEVICE_ID_SI_760) 444 + smbus_base = acpi_base + 0xE0; 445 + else 446 + smbus_base = acpi_base + 0x80; 447 + 448 + dev_dbg(&sis630_dev->dev, "SMBus base at 0x%04hx\n", smbus_base); 449 + 450 + retval = acpi_check_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION, 469 451 sis630_driver.name); 470 452 if (retval) 471 453 goto exit; 472 454 473 455 /* Everything is happy, let's grab the memory and set things up. */ 474 - if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION, 456 + if (!request_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION, 475 457 sis630_driver.name)) { 476 - dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already " 477 - "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA); 458 + dev_err(&sis630_dev->dev, 459 + "I/O Region 0x%04hx-0x%04hx for SMBus already in use.\n", 460 + smbus_base + SMB_STS, 461 + smbus_base + SMB_STS + SIS630_SMB_IOREGION - 1); 478 462 retval = -EBUSY; 479 463 goto exit; 480 464 } ··· 494 456 495 457 exit: 496 458 if (retval) 497 - acpi_base = 0; 459 + smbus_base = 0; 498 460 return retval; 499 461 } 500 462 ··· 508 470 .owner = THIS_MODULE, 509 471 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 510 472 .algo = &smbus_algorithm, 473 + .retries = 3 511 474 }; 512 475 513 476 static DEFINE_PCI_DEVICE_TABLE(sis630_ids) = { 514 477 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 515 478 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, 479 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_964) }, 516 480 { 0, } 517 481 }; 518 482 519 - MODULE_DEVICE_TABLE (pci, sis630_ids); 483 + MODULE_DEVICE_TABLE(pci, sis630_ids); 520 484 521 485 static int sis630_probe(struct pci_dev *dev, const struct pci_device_id *id) 522 486 { 523 487 if (sis630_setup(dev)) { 524 - dev_err(&dev->dev, "SIS630 comp. bus not detected, module not inserted.\n"); 488 + dev_err(&dev->dev, 489 + "SIS630 compatible bus not detected, " 490 + "module not inserted.\n"); 525 491 return -ENODEV; 526 492 } 527 493 ··· 533 491 sis630_adapter.dev.parent = &dev->dev; 534 492 535 493 snprintf(sis630_adapter.name, sizeof(sis630_adapter.name), 536 - "SMBus SIS630 adapter at %04x", acpi_base + SMB_STS); 494 + "SMBus SIS630 adapter at %04hx", smbus_base + SMB_STS); 537 495 538 496 return i2c_add_adapter(&sis630_adapter); 539 497 } 540 498 541 499 static void sis630_remove(struct pci_dev *dev) 542 500 { 543 - if (acpi_base) { 501 + if (smbus_base) { 544 502 i2c_del_adapter(&sis630_adapter); 545 - release_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION); 546 - acpi_base = 0; 503 + release_region(smbus_base + SMB_STS, SIS630_SMB_IOREGION); 504 + smbus_base = 0; 547 505 } 548 506 } 549 507
-1
drivers/i2c/busses/i2c-stu300.c
··· 975 975 i2c_del_adapter(&dev->adapter); 976 976 /* Turn off everything */ 977 977 stu300_wr8(0x00, dev->virtbase + I2C_CR); 978 - platform_set_drvdata(pdev, NULL); 979 978 return 0; 980 979 } 981 980
-2
drivers/i2c/busses/i2c-taos-evm.c
··· 271 271 exit_close: 272 272 serio_close(serio); 273 273 exit_kfree: 274 - serio_set_drvdata(serio, NULL); 275 274 kfree(taos); 276 275 exit: 277 276 return err; ··· 284 285 i2c_unregister_device(taos->client); 285 286 i2c_del_adapter(&taos->adapter); 286 287 serio_close(serio); 287 - serio_set_drvdata(serio, NULL); 288 288 kfree(taos); 289 289 290 290 dev_info(&serio->dev, "Disconnected from TAOS EVM\n");
+64 -15
drivers/i2c/busses/i2c-tegra.c
··· 70 70 #define I2C_INT_TX_FIFO_DATA_REQ (1<<1) 71 71 #define I2C_INT_RX_FIFO_DATA_REQ (1<<0) 72 72 #define I2C_CLK_DIVISOR 0x06c 73 + #define I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT 16 74 + #define I2C_CLK_MULTIPLIER_STD_FAST_MODE 8 73 75 74 76 #define DVC_CTRL_REG1 0x000 75 77 #define DVC_CTRL_REG1_INTR_EN (1<<10) ··· 118 116 /** 119 117 * struct tegra_i2c_hw_feature : Different HW support on Tegra 120 118 * @has_continue_xfer_support: Continue transfer supports. 119 + * @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer 120 + * complete interrupt per packet basis. 121 + * @has_single_clk_source: The i2c controller has single clock source. Tegra30 122 + * and earlier Socs has two clock sources i.e. div-clk and 123 + * fast-clk. 124 + * @clk_divisor_hs_mode: Clock divisor in HS mode. 125 + * @clk_divisor_std_fast_mode: Clock divisor in standard/fast mode. It is 126 + * applicable if there is no fast clock source i.e. single clock 127 + * source. 121 128 */ 122 129 123 130 struct tegra_i2c_hw_feature { 124 131 bool has_continue_xfer_support; 132 + bool has_per_pkt_xfer_complete_irq; 133 + bool has_single_clk_source; 134 + int clk_divisor_hs_mode; 135 + int clk_divisor_std_fast_mode; 125 136 }; 126 137 127 138 /** ··· 380 365 static inline int tegra_i2c_clock_enable(struct tegra_i2c_dev *i2c_dev) 381 366 { 382 367 int ret; 383 - ret = clk_prepare_enable(i2c_dev->fast_clk); 384 - if (ret < 0) { 385 - dev_err(i2c_dev->dev, 386 - "Enabling fast clk failed, err %d\n", ret); 387 - return ret; 368 + if (!i2c_dev->hw->has_single_clk_source) { 369 + ret = clk_prepare_enable(i2c_dev->fast_clk); 370 + if (ret < 0) { 371 + dev_err(i2c_dev->dev, 372 + "Enabling fast clk failed, err %d\n", ret); 373 + return ret; 374 + } 388 375 } 389 376 ret = clk_prepare_enable(i2c_dev->div_clk); 390 377 if (ret < 0) { ··· 400 383 static inline void tegra_i2c_clock_disable(struct tegra_i2c_dev *i2c_dev) 401 384 { 402 385 clk_disable_unprepare(i2c_dev->div_clk); 403 - clk_disable_unprepare(i2c_dev->fast_clk); 386 + if (!i2c_dev->hw->has_single_clk_source) 387 + clk_disable_unprepare(i2c_dev->fast_clk); 404 388 } 405 389 406 390 static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) 407 391 { 408 392 u32 val; 409 393 int err = 0; 394 + int clk_multiplier = I2C_CLK_MULTIPLIER_STD_FAST_MODE; 395 + u32 clk_divisor; 410 396 411 397 tegra_i2c_clock_enable(i2c_dev); 412 398 ··· 424 404 (0x2 << I2C_CNFG_DEBOUNCE_CNT_SHIFT); 425 405 i2c_writel(i2c_dev, val, I2C_CNFG); 426 406 i2c_writel(i2c_dev, 0, I2C_INT_MASK); 427 - clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * 8); 407 + 408 + clk_multiplier *= (i2c_dev->hw->clk_divisor_std_fast_mode + 1); 409 + clk_set_rate(i2c_dev->div_clk, i2c_dev->bus_clk_rate * clk_multiplier); 410 + 411 + /* Make sure clock divisor programmed correctly */ 412 + clk_divisor = i2c_dev->hw->clk_divisor_hs_mode; 413 + clk_divisor |= i2c_dev->hw->clk_divisor_std_fast_mode << 414 + I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT; 415 + i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); 428 416 429 417 if (!i2c_dev->is_dvc) { 430 418 u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG); ··· 574 546 tegra_i2c_fill_tx_fifo(i2c_dev); 575 547 576 548 int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; 549 + if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) 550 + int_mask |= I2C_INT_PACKET_XFER_COMPLETE; 577 551 if (msg->flags & I2C_M_RD) 578 552 int_mask |= I2C_INT_RX_FIFO_DATA_REQ; 579 553 else if (i2c_dev->msg_buf_remaining) ··· 587 557 ret = wait_for_completion_timeout(&i2c_dev->msg_complete, TEGRA_I2C_TIMEOUT); 588 558 tegra_i2c_mask_irq(i2c_dev, int_mask); 589 559 590 - if (WARN_ON(ret == 0)) { 560 + if (ret == 0) { 591 561 dev_err(i2c_dev->dev, "i2c transfer timed out\n"); 592 562 593 563 tegra_i2c_init(i2c_dev); ··· 663 633 664 634 static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { 665 635 .has_continue_xfer_support = false, 636 + .has_per_pkt_xfer_complete_irq = false, 637 + .has_single_clk_source = false, 638 + .clk_divisor_hs_mode = 3, 639 + .clk_divisor_std_fast_mode = 0, 666 640 }; 667 641 668 642 static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { 669 643 .has_continue_xfer_support = true, 644 + .has_per_pkt_xfer_complete_irq = false, 645 + .has_single_clk_source = false, 646 + .clk_divisor_hs_mode = 3, 647 + .clk_divisor_std_fast_mode = 0, 648 + }; 649 + 650 + static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { 651 + .has_continue_xfer_support = true, 652 + .has_per_pkt_xfer_complete_irq = true, 653 + .has_single_clk_source = true, 654 + .clk_divisor_hs_mode = 1, 655 + .clk_divisor_std_fast_mode = 0x19, 670 656 }; 671 657 672 658 #if defined(CONFIG_OF) 673 659 /* Match table for of_platform binding */ 674 660 static const struct of_device_id tegra_i2c_of_match[] = { 661 + { .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, }, 675 662 { .compatible = "nvidia,tegra30-i2c", .data = &tegra30_i2c_hw, }, 676 663 { .compatible = "nvidia,tegra20-i2c", .data = &tegra20_i2c_hw, }, 677 664 { .compatible = "nvidia,tegra20-i2c-dvc", .data = &tegra20_i2c_hw, }, ··· 732 685 return PTR_ERR(div_clk); 733 686 } 734 687 735 - fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); 736 - if (IS_ERR(fast_clk)) { 737 - dev_err(&pdev->dev, "missing bus clock"); 738 - return PTR_ERR(fast_clk); 739 - } 740 - 741 688 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); 742 689 if (!i2c_dev) { 743 690 dev_err(&pdev->dev, "Could not allocate struct tegra_i2c_dev"); ··· 740 699 741 700 i2c_dev->base = base; 742 701 i2c_dev->div_clk = div_clk; 743 - i2c_dev->fast_clk = fast_clk; 744 702 i2c_dev->adapter.algo = &tegra_i2c_algo; 745 703 i2c_dev->irq = irq; 746 704 i2c_dev->cont_id = pdev->id; ··· 769 729 i2c_dev->is_dvc = 1; 770 730 } 771 731 init_completion(&i2c_dev->msg_complete); 732 + 733 + if (!i2c_dev->hw->has_single_clk_source) { 734 + fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); 735 + if (IS_ERR(fast_clk)) { 736 + dev_err(&pdev->dev, "missing fast clock"); 737 + return PTR_ERR(fast_clk); 738 + } 739 + i2c_dev->fast_clk = fast_clk; 740 + } 772 741 773 742 platform_set_drvdata(pdev, i2c_dev); 774 743
-2
drivers/i2c/busses/i2c-versatile.c
··· 125 125 { 126 126 struct i2c_versatile *i2c = platform_get_drvdata(dev); 127 127 128 - platform_set_drvdata(dev, NULL); 129 - 130 128 i2c_del_adapter(&i2c->adap); 131 129 return 0; 132 130 }
-2
drivers/i2c/busses/i2c-xiic.c
··· 784 784 785 785 xiic_deinit(i2c); 786 786 787 - platform_set_drvdata(pdev, NULL); 788 - 789 787 free_irq(platform_get_irq(pdev, 0), i2c); 790 788 791 789 iounmap(i2c->base);
-1
drivers/i2c/busses/i2c-xlr.c
··· 256 256 257 257 priv = platform_get_drvdata(pdev); 258 258 i2c_del_adapter(&priv->adap); 259 - platform_set_drvdata(pdev, NULL); 260 259 return 0; 261 260 } 262 261
-1
drivers/i2c/busses/scx200_acb.c
··· 542 542 struct scx200_acb_iface *iface; 543 543 544 544 iface = platform_get_drvdata(pdev); 545 - platform_set_drvdata(pdev, NULL); 546 545 scx200_cleanup_iface(iface); 547 546 548 547 return 0;
-23
drivers/i2c/i2c-core.c
··· 1866 1866 EXPORT_SYMBOL(i2c_smbus_write_word_data); 1867 1867 1868 1868 /** 1869 - * i2c_smbus_process_call - SMBus "process call" protocol 1870 - * @client: Handle to slave device 1871 - * @command: Byte interpreted by slave 1872 - * @value: 16-bit "word" being written 1873 - * 1874 - * This executes the SMBus "process call" protocol, returning negative errno 1875 - * else a 16-bit unsigned "word" received from the device. 1876 - */ 1877 - s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command, 1878 - u16 value) 1879 - { 1880 - union i2c_smbus_data data; 1881 - int status; 1882 - data.word = value; 1883 - 1884 - status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, 1885 - I2C_SMBUS_WRITE, command, 1886 - I2C_SMBUS_PROC_CALL, &data); 1887 - return (status < 0) ? status : data.word; 1888 - } 1889 - EXPORT_SYMBOL(i2c_smbus_process_call); 1890 - 1891 - /** 1892 1869 * i2c_smbus_read_block_data - SMBus "block read" protocol 1893 1870 * @client: Handle to slave device 1894 1871 * @command: Byte interpreted by slave
-1
drivers/i2c/muxes/i2c-mux-gpio.c
··· 250 250 for (i = 0; i < mux->data.n_gpios; i++) 251 251 gpio_free(mux->gpio_base + mux->data.gpios[i]); 252 252 253 - platform_set_drvdata(pdev, NULL); 254 253 i2c_put_adapter(mux->parent); 255 254 256 255 return 0;
+6 -5
drivers/misc/eeprom/Kconfig
··· 1 1 menu "EEPROM support" 2 2 3 3 config EEPROM_AT24 4 - tristate "I2C EEPROMs from most vendors" 4 + tristate "I2C EEPROMs / RAMs / ROMs from most vendors" 5 5 depends on I2C && SYSFS 6 6 help 7 - Enable this driver to get read/write support to most I2C EEPROMs, 8 - after you configure the driver to know about each EEPROM on 9 - your target board. Use these generic chip names, instead of 10 - vendor-specific ones like at24c64 or 24lc02: 7 + Enable this driver to get read/write support to most I2C EEPROMs 8 + and compatible devices like FRAMs, SRAMs, ROMs etc. After you 9 + configure the driver to know about each chip on your target 10 + board. Use these generic chip names, instead of vendor-specific 11 + ones like at24c64, 24lc02 or fm24c04: 11 12 12 13 24c00, 24c01, 24c02, spd (readonly 24c02), 24c04, 24c08, 13 14 24c16, 24c32, 24c64, 24c128, 24c256, 24c512, 24c1024