* 'for-linus/i2c-3.2' of git://git.fluff.org/bjdooks/linux: (47 commits) i2c-s3c2410: Add device tree support i2c-s3c2410: Keep a copy of platform data and use it i2c-nomadik: cosmetic coding style corrections i2c-au1550: dev_pm_ops conversion i2c-au1550: increase timeout waiting for master done i2c-au1550: remove unused ack_timeout i2c-au1550: remove usage of volatile keyword i2c-tegra: __iomem annotation fix i2c-eg20t: Add initialize processing in case i2c-error occurs i2c-eg20t: Fix flag setting issue i2c-eg20t: add stop sequence in case wait-event timeout occurs i2c-eg20t: Separate error processing i2c-eg20t: Fix 10bit access issue i2c-eg20t: Modify returned value s32 to long i2c-eg20t: Fix bus-idle waiting issue i2c-designware: Fix PCI core warning on suspend/resume i2c-designware: Add runtime power management support i2c-designware: Add support for Designware core behind PCI devices. i2c-designware: Push all register reads/writes into the core code. i2c-designware: Support multiple cores using same ISR ...
Unified · Split
| @@ -0,0 +1,25 @@ | ||
| 1 | +* Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX | |
| 2 | + | |
| 3 | +Required properties: | |
| 4 | +- compatible : Should be "fsl,<chip>-i2c" | |
| 5 | +- reg : Should contain I2C/HS-I2C registers location and length | |
| 6 | +- interrupts : Should contain I2C/HS-I2C interrupt | |
| 7 | + | |
| 8 | +Optional properties: | |
| 9 | +- clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz. | |
| 10 | + The absence of the propoerty indicates the default frequency 100 kHz. | |
| 11 | + | |
| 12 | +Examples: | |
| 13 | + | |
| 14 | +i2c@83fc4000 { /* I2C2 on i.MX51 */ | |
| 15 | + compatible = "fsl,imx51-i2c", "fsl,imx1-i2c"; | |
| 16 | + reg = <0x83fc4000 0x4000>; | |
| 17 | + interrupts = <63>; | |
| 18 | +}; | |
| 19 | + | |
| 20 | +i2c@70038000 { /* HS-I2C on i.MX51 */ | |
| 21 | + compatible = "fsl,imx51-i2c", "fsl,imx1-i2c"; | |
| 22 | + reg = <0x70038000 0x4000>; | |
| 23 | + interrupts = <64>; | |
| 24 | + clock-frequency = <400000>; | |
| 25 | +}; | |
| @@ -0,0 +1,39 @@ | ||
| 1 | +* Samsung's I2C controller | |
| 2 | + | |
| 3 | +The Samsung's I2C controller is used to interface with I2C devices. | |
| 4 | + | |
| 5 | +Required properties: | |
| 6 | + - compatible: value should be either of the following. | |
| 7 | + (a) "samsung, s3c2410-i2c", for i2c compatible with s3c2410 i2c. | |
| 8 | + (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c. | |
| 9 | + - reg: physical base address of the controller and length of memory mapped | |
| 10 | + region. | |
| 11 | + - interrupts: interrupt number to the cpu. | |
| 12 | + - samsung,i2c-sda-delay: Delay (in ns) applied to data line (SDA) edges. | |
| 13 | + - gpios: The order of the gpios should be the following: <SDA, SCL>. | |
| 14 | + The gpio specifier depends on the gpio controller. | |
| 15 | + | |
| 16 | +Optional properties: | |
| 17 | + - samsung,i2c-slave-addr: Slave address in multi-master enviroment. If not | |
| 18 | + specified, default value is 0. | |
| 19 | + - samsung,i2c-max-bus-freq: Desired frequency in Hz of the bus. If not | |
| 20 | + specified, the default value in Hz is 100000. | |
| 21 | + | |
| 22 | +Example: | |
| 23 | + | |
| 24 | + i2c@13870000 { | |
| 25 | + compatible = "samsung,s3c2440-i2c"; | |
| 26 | + reg = <0x13870000 0x100>; | |
| 27 | + interrupts = <345>; | |
| 28 | + samsung,i2c-sda-delay = <100>; | |
| 29 | + samsung,i2c-max-bus-freq = <100000>; | |
| 30 | + gpios = <&gpd1 2 0 /* SDA */ | |
| 31 | + &gpd1 3 0 /* SCL */>; | |
| 32 | + #address-cells = <1>; | |
| 33 | + #size-cells = <0>; | |
| 34 | + | |
| 35 | + wm8994@1a { | |
| 36 | + compatible = "wlf,wm8994"; | |
| 37 | + reg = <0x1a>; | |
| 38 | + }; | |
| 39 | + }; | |
| @@ -11,14 +11,10 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * struct imxi2c_platform_data - structure of platform data for MXC I2C driver |
| 14 | − * @init: Initialise gpio's and other board specific things | |
| 15 | − * @exit: Free everything initialised by @init | |
| 16 | 14 | * @bitrate: Bus speed measured in Hz |
| 17 | 15 | * |
| 18 | 16 | **/ |
| 19 | 17 | struct imxi2c_platform_data { |
| 20 | − int (*init)(struct device *dev); | |
| 21 | − void (*exit)(struct device *dev); | |
| 22 | 18 | int bitrate; |
| 23 | 19 | }; |
| 24 | 20 | |
| @@ -108,6 +108,22 @@ static inline int omap1_i2c_add_bus(int bus_id) · 107 unmodified lines | ||
| 108 | 108 | res[1].start = INT_I2C; |
| 109 | 109 | pdata = &i2c_pdata[bus_id - 1]; |
| 110 | 110 | |
| 111 | + /* all OMAP1 have IP version 1 register set */ | |
| 112 | + pdata->rev = OMAP_I2C_IP_VERSION_1; | |
| 113 | + | |
| 114 | + /* all OMAP1 I2C are implemented like this */ | |
| 115 | + pdata->flags = OMAP_I2C_FLAG_NO_FIFO | | |
| 116 | + OMAP_I2C_FLAG_SIMPLE_CLOCK | | |
| 117 | + OMAP_I2C_FLAG_16BIT_DATA_REG | | |
| 118 | + OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK; | |
| 119 | + | |
| 120 | + /* how the cpu bus is wired up differs for 7xx only */ | |
| 121 | + | |
| 122 | + if (cpu_is_omap7xx()) | |
| 123 | + pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_1; | |
| 124 | + else | |
| 125 | + pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2; | |
| 126 | + | |
| 111 | 127 | return platform_device_register(pdev); |
| 112 | 128 | } |
| 113 | 129 | |
| @@ -138,6 +154,7 @@ static inline int omap2_i2c_add_bus(int bus_id) · 24 unmodified lines | ||
| 138 | 154 | struct omap_device *od; |
| 139 | 155 | char oh_name[MAX_OMAP_I2C_HWMOD_NAME_LEN]; |
| 140 | 156 | struct omap_i2c_bus_platform_data *pdata; |
| 157 | + struct omap_i2c_dev_attr *dev_attr; | |
| 141 | 158 | |
| 142 | 159 | omap2_i2c_mux_pins(bus_id); |
| 143 | 160 | |
| @@ -151,6 +168,16 @@ static inline int omap2_i2c_add_bus(int bus_id) · 7 unmodified lines | ||
| 151 | 168 | } |
| 152 | 169 | |
| 153 | 170 | pdata = &i2c_pdata[bus_id - 1]; |
| 171 | + /* | |
| 172 | + * pass the hwmod class's CPU-specific knowledge of I2C IP revision in | |
| 173 | + * use, and functionality implementation flags, up to the OMAP I2C | |
| 174 | + * driver via platform data | |
| 175 | + */ | |
| 176 | + pdata->rev = oh->class->rev; | |
| 177 | + | |
| 178 | + dev_attr = (struct omap_i2c_dev_attr *)oh->dev_attr; | |
| 179 | + pdata->flags = dev_attr->flags; | |
| 180 | + | |
| 154 | 181 | /* |
| 155 | 182 | * When waiting for completion of a i2c transfer, we need to |
| 156 | 183 | * set a wake up latency constraint for the MPU. This is to |
| @@ -394,19 +394,6 @@ typedef struct psc_spi { · 393 unmodified lines | ||
| 394 | 394 | #define PSC_SPITXRX_LC (1 << 29) |
| 395 | 395 | #define PSC_SPITXRX_SR (1 << 28) |
| 396 | 396 | |
| 397 | −/* PSC in SMBus (I2C) Mode. */ | |
| 398 | −typedef struct psc_smb { | |
| 399 | − u32 psc_sel; | |
| 400 | − u32 psc_ctrl; | |
| 401 | − u32 psc_smbcfg; | |
| 402 | − u32 psc_smbmsk; | |
| 403 | − u32 psc_smbpcr; | |
| 404 | − u32 psc_smbstat; | |
| 405 | − u32 psc_smbevnt; | |
| 406 | − u32 psc_smbtxrx; | |
| 407 | − u32 psc_smbtmr; | |
| 408 | −} psc_smb_t; | |
| 409 | − | |
| 410 | 397 | /* SMBus Config Register. */ |
| 411 | 398 | #define PSC_SMBCFG_RT_MASK (3 << 30) |
| 412 | 399 | #define PSC_SMBCFG_RT_FIFO1 (0 << 30) |
| @@ -350,15 +350,25 @@ config I2C_DAVINCI · 349 unmodified lines | ||
| 350 | 350 | devices such as DaVinci NIC. |
| 351 | 351 | For details please see http://www.ti.com/davinci |
| 352 | 352 | |
| 353 | −config I2C_DESIGNWARE | |
| 354 | − tristate "Synopsys DesignWare" | |
| 353 | +config I2C_DESIGNWARE_PLATFORM | |
| 354 | + tristate "Synopsys DesignWare Platfrom" | |
| 355 | 355 | depends on HAVE_CLK |
| 356 | 356 | help |
| 357 | 357 | If you say yes to this option, support will be included for the |
| 358 | 358 | Synopsys DesignWare I2C adapter. Only master mode is supported. |
| 359 | 359 | |
| 360 | 360 | This driver can also be built as a module. If so, the module |
| 361 | − will be called i2c-designware. | |
| 361 | + will be called i2c-designware-platform. | |
| 362 | + | |
| 363 | +config I2C_DESIGNWARE_PCI | |
| 364 | + tristate "Synopsys DesignWare PCI" | |
| 365 | + depends on PCI | |
| 366 | + help | |
| 367 | + If you say yes to this option, support will be included for the | |
| 368 | + Synopsys DesignWare I2C adapter. Only master mode is supported. | |
| 369 | + | |
| 370 | + This driver can also be built as a module. If so, the module | |
| 371 | + will be called i2c-designware-pci. | |
| 362 | 372 | |
| 363 | 373 | config I2C_GPIO |
| 364 | 374 | tristate "GPIO-based bitbanging I2C" |
| @@ -33,7 +33,10 @@ obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o · 32 unmodified lines | ||
| 33 | 33 | obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o |
| 34 | 34 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o |
| 35 | 35 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o |
| 36 | −obj-$(CONFIG_I2C_DESIGNWARE) += i2c-designware.o | |
| 36 | +obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o | |
| 37 | +i2c-designware-platform-objs := i2c-designware-platdrv.o i2c-designware-core.o | |
| 38 | +obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o | |
| 39 | +i2c-designware-pci-objs := i2c-designware-pcidrv.o i2c-designware-core.o | |
| 37 | 40 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o |
| 38 | 41 | obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o |
| 39 | 42 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o |
| @@ -39,29 +39,41 @@ · 38 unmodified lines | ||
| 39 | 39 | #include <asm/mach-au1x00/au1xxx.h> |
| 40 | 40 | #include <asm/mach-au1x00/au1xxx_psc.h> |
| 41 | 41 | |
| 42 | +#define PSC_SEL 0x00 | |
| 43 | +#define PSC_CTRL 0x04 | |
| 44 | +#define PSC_SMBCFG 0x08 | |
| 45 | +#define PSC_SMBMSK 0x0C | |
| 46 | +#define PSC_SMBPCR 0x10 | |
| 47 | +#define PSC_SMBSTAT 0x14 | |
| 48 | +#define PSC_SMBEVNT 0x18 | |
| 49 | +#define PSC_SMBTXRX 0x1C | |
| 50 | +#define PSC_SMBTMR 0x20 | |
| 51 | + | |
| 42 | 52 | struct i2c_au1550_data { |
| 43 | − u32 psc_base; | |
| 53 | + void __iomem *psc_base; | |
| 44 | 54 | int xfer_timeout; |
| 45 | − int ack_timeout; | |
| 46 | 55 | struct i2c_adapter adap; |
| 47 | 56 | struct resource *ioarea; |
| 48 | 57 | }; |
| 49 | 58 | |
| 50 | −static int | |
| 51 | −wait_xfer_done(struct i2c_au1550_data *adap) | |
| 59 | +static inline void WR(struct i2c_au1550_data *a, int r, unsigned long v) | |
| 52 | 60 | { |
| 53 | − u32 stat; | |
| 54 | − int i; | |
| 55 | − volatile psc_smb_t *sp; | |
| 61 | + __raw_writel(v, a->psc_base + r); | |
| 62 | + wmb(); | |
| 63 | +} | |
| 56 | 64 | |
| 57 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 65 | +static inline unsigned long RD(struct i2c_au1550_data *a, int r) | |
| 66 | +{ | |
| 67 | + return __raw_readl(a->psc_base + r); | |
| 68 | +} | |
| 58 | 69 | |
| 59 | − /* Wait for Tx Buffer Empty | |
| 60 | − */ | |
| 70 | +static int wait_xfer_done(struct i2c_au1550_data *adap) | |
| 71 | +{ | |
| 72 | + int i; | |
| 73 | + | |
| 74 | + /* Wait for Tx Buffer Empty */ | |
| 61 | 75 | for (i = 0; i < adap->xfer_timeout; i++) { |
| 62 | − stat = sp->psc_smbstat; | |
| 63 | − au_sync(); | |
| 64 | − if ((stat & PSC_SMBSTAT_TE) != 0) | |
| 76 | + if (RD(adap, PSC_SMBSTAT) & PSC_SMBSTAT_TE) | |
| 65 | 77 | return 0; |
| 66 | 78 | |
| 67 | 79 | udelay(1); |
| @@ -70,41 +82,27 @@ wait_xfer_done(struct i2c_au1550_data *adap) · 2 unmodified lines | ||
| 70 | 82 | return -ETIMEDOUT; |
| 71 | 83 | } |
| 72 | 84 | |
| 73 | −static int | |
| 74 | −wait_ack(struct i2c_au1550_data *adap) | |
| 85 | +static int wait_ack(struct i2c_au1550_data *adap) | |
| 75 | 86 | { |
| 76 | − u32 stat; | |
| 77 | − volatile psc_smb_t *sp; | |
| 87 | + unsigned long stat; | |
| 78 | 88 | |
| 79 | 89 | if (wait_xfer_done(adap)) |
| 80 | 90 | return -ETIMEDOUT; |
| 81 | 91 | |
| 82 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 83 | − | |
| 84 | − stat = sp->psc_smbevnt; | |
| 85 | − au_sync(); | |
| 86 | − | |
| 92 | + stat = RD(adap, PSC_SMBEVNT); | |
| 87 | 93 | if ((stat & (PSC_SMBEVNT_DN | PSC_SMBEVNT_AN | PSC_SMBEVNT_AL)) != 0) |
| 88 | 94 | return -ETIMEDOUT; |
| 89 | 95 | |
| 90 | 96 | return 0; |
| 91 | 97 | } |
| 92 | 98 | |
| 93 | −static int | |
| 94 | −wait_master_done(struct i2c_au1550_data *adap) | |
| 99 | +static int wait_master_done(struct i2c_au1550_data *adap) | |
| 95 | 100 | { |
| 96 | − u32 stat; | |
| 97 | − int i; | |
| 98 | − volatile psc_smb_t *sp; | |
| 101 | + int i; | |
| 99 | 102 | |
| 100 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 101 | − | |
| 102 | − /* Wait for Master Done. | |
| 103 | − */ | |
| 104 | − for (i = 0; i < adap->xfer_timeout; i++) { | |
| 105 | − stat = sp->psc_smbevnt; | |
| 106 | − au_sync(); | |
| 107 | − if ((stat & PSC_SMBEVNT_MD) != 0) | |
| 103 | + /* Wait for Master Done. */ | |
| 104 | + for (i = 0; i < 2 * adap->xfer_timeout; i++) { | |
| 105 | + if ((RD(adap, PSC_SMBEVNT) & PSC_SMBEVNT_MD) != 0) | |
| 108 | 106 | return 0; |
| 109 | 107 | udelay(1); |
| 110 | 108 | } |
| @@ -115,29 +113,20 @@ wait_master_done(struct i2c_au1550_data *adap) · 4 unmodified lines | ||
| 115 | 113 | static int |
| 116 | 114 | do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q) |
| 117 | 115 | { |
| 118 | − volatile psc_smb_t *sp; | |
| 119 | − u32 stat; | |
| 116 | + unsigned long stat; | |
| 120 | 117 | |
| 121 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 122 | − | |
| 123 | − /* Reset the FIFOs, clear events. | |
| 124 | − */ | |
| 125 | − stat = sp->psc_smbstat; | |
| 126 | − sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR; | |
| 127 | − au_sync(); | |
| 118 | + /* Reset the FIFOs, clear events. */ | |
| 119 | + stat = RD(adap, PSC_SMBSTAT); | |
| 120 | + WR(adap, PSC_SMBEVNT, PSC_SMBEVNT_ALLCLR); | |
| 128 | 121 | |
| 129 | 122 | if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) { |
| 130 | − sp->psc_smbpcr = PSC_SMBPCR_DC; | |
| 131 | − au_sync(); | |
| 132 | − do { | |
| 133 | − stat = sp->psc_smbpcr; | |
| 134 | − au_sync(); | |
| 135 | − } while ((stat & PSC_SMBPCR_DC) != 0); | |
| 123 | + WR(adap, PSC_SMBPCR, PSC_SMBPCR_DC); | |
| 124 | + while ((RD(adap, PSC_SMBPCR) & PSC_SMBPCR_DC) != 0) | |
| 125 | + cpu_relax(); | |
| 136 | 126 | udelay(50); |
| 137 | 127 | } |
| 138 | 128 | |
| 139 | − /* Write out the i2c chip address and specify operation | |
| 140 | − */ | |
| 129 | + /* Write out the i2c chip address and specify operation */ | |
| 141 | 130 | addr <<= 1; |
| 142 | 131 | if (rd) |
| 143 | 132 | addr |= 1; |
| @@ -146,56 +135,42 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q) · 2 unmodified lines | ||
| 146 | 135 | if (q) |
| 147 | 136 | addr |= PSC_SMBTXRX_STP; |
| 148 | 137 | |
| 149 | − /* Put byte into fifo, start up master. | |
| 150 | − */ | |
| 151 | − sp->psc_smbtxrx = addr; | |
| 152 | − au_sync(); | |
| 153 | − sp->psc_smbpcr = PSC_SMBPCR_MS; | |
| 154 | − au_sync(); | |
| 138 | + /* Put byte into fifo, start up master. */ | |
| 139 | + WR(adap, PSC_SMBTXRX, addr); | |
| 140 | + WR(adap, PSC_SMBPCR, PSC_SMBPCR_MS); | |
| 155 | 141 | if (wait_ack(adap)) |
| 156 | 142 | return -EIO; |
| 157 | 143 | return (q) ? wait_master_done(adap) : 0; |
| 158 | 144 | } |
| 159 | 145 | |
| 160 | −static u32 | |
| 161 | −wait_for_rx_byte(struct i2c_au1550_data *adap, u32 *ret_data) | |
| 146 | +static int wait_for_rx_byte(struct i2c_au1550_data *adap, unsigned char *out) | |
| 162 | 147 | { |
| 163 | − int j; | |
| 164 | − u32 data, stat; | |
| 165 | − volatile psc_smb_t *sp; | |
| 148 | + int j; | |
| 166 | 149 | |
| 167 | 150 | if (wait_xfer_done(adap)) |
| 168 | 151 | return -EIO; |
| 169 | 152 | |
| 170 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 171 | − | |
| 172 | 153 | j = adap->xfer_timeout * 100; |
| 173 | 154 | do { |
| 174 | 155 | j--; |
| 175 | 156 | if (j <= 0) |
| 176 | 157 | return -EIO; |
| 177 | 158 | |
| 178 | − stat = sp->psc_smbstat; | |
| 179 | − au_sync(); | |
| 180 | − if ((stat & PSC_SMBSTAT_RE) == 0) | |
| 159 | + if ((RD(adap, PSC_SMBSTAT) & PSC_SMBSTAT_RE) == 0) | |
| 181 | 160 | j = 0; |
| 182 | 161 | else |
| 183 | 162 | udelay(1); |
| 184 | 163 | } while (j > 0); |
| 185 | − data = sp->psc_smbtxrx; | |
| 186 | − au_sync(); | |
| 187 | − *ret_data = data; | |
| 164 | + | |
| 165 | + *out = RD(adap, PSC_SMBTXRX); | |
| 188 | 166 | |
| 189 | 167 | return 0; |
| 190 | 168 | } |
| 191 | 169 | |
| 192 | −static int | |
| 193 | −i2c_read(struct i2c_au1550_data *adap, unsigned char *buf, | |
| 170 | +static int i2c_read(struct i2c_au1550_data *adap, unsigned char *buf, | |
| 194 | 171 | unsigned int len) |
| 195 | 172 | { |
| 196 | − int i; | |
| 197 | − u32 data; | |
| 198 | − volatile psc_smb_t *sp; | |
| 173 | + int i; | |
| 199 | 174 | |
| 200 | 175 | if (len == 0) |
| 201 | 176 | return 0; |
| @@ -204,62 +179,46 @@ i2c_read(struct i2c_au1550_data *adap, unsigned char *buf, · 2 unmodified lines | ||
| 204 | 179 | * zero bytes for timing, waiting for bytes to appear in the |
| 205 | 180 | * receive fifo, then reading the bytes. |
| 206 | 181 | */ |
| 207 | − | |
| 208 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 209 | − | |
| 210 | 182 | i = 0; |
| 211 | − while (i < (len-1)) { | |
| 212 | − sp->psc_smbtxrx = 0; | |
| 213 | − au_sync(); | |
| 214 | − if (wait_for_rx_byte(adap, &data)) | |
| 183 | + while (i < (len - 1)) { | |
| 184 | + WR(adap, PSC_SMBTXRX, 0); | |
| 185 | + if (wait_for_rx_byte(adap, &buf[i])) | |
| 215 | 186 | return -EIO; |
| 216 | 187 | |
| 217 | − buf[i] = data; | |
| 218 | 188 | i++; |
| 219 | 189 | } |
| 220 | 190 | |
| 221 | − /* The last byte has to indicate transfer done. | |
| 222 | − */ | |
| 223 | − sp->psc_smbtxrx = PSC_SMBTXRX_STP; | |
| 224 | − au_sync(); | |
| 191 | + /* The last byte has to indicate transfer done. */ | |
| 192 | + WR(adap, PSC_SMBTXRX, PSC_SMBTXRX_STP); | |
| 225 | 193 | if (wait_master_done(adap)) |
| 226 | 194 | return -EIO; |
| 227 | 195 | |
| 228 | − data = sp->psc_smbtxrx; | |
| 229 | − au_sync(); | |
| 230 | − buf[i] = data; | |
| 196 | + buf[i] = (unsigned char)(RD(adap, PSC_SMBTXRX) & 0xff); | |
| 231 | 197 | return 0; |
| 232 | 198 | } |
| 233 | 199 | |
| 234 | −static int | |
| 235 | −i2c_write(struct i2c_au1550_data *adap, unsigned char *buf, | |
| 200 | +static int i2c_write(struct i2c_au1550_data *adap, unsigned char *buf, | |
| 236 | 201 | unsigned int len) |
| 237 | 202 | { |
| 238 | − int i; | |
| 239 | − u32 data; | |
| 240 | − volatile psc_smb_t *sp; | |
| 203 | + int i; | |
| 204 | + unsigned long data; | |
| 241 | 205 | |
| 242 | 206 | if (len == 0) |
| 243 | 207 | return 0; |
| 244 | 208 | |
| 245 | − sp = (volatile psc_smb_t *)(adap->psc_base); | |
| 246 | − | |
| 247 | 209 | i = 0; |
| 248 | 210 | while (i < (len-1)) { |
| 249 | 211 | data = buf[i]; |
| 250 | − sp->psc_smbtxrx = data; | |
| 251 | − au_sync(); | |
| 212 | + WR(adap, PSC_SMBTXRX, data); | |
| 252 | 213 | if (wait_ack(adap)) |
| 253 | 214 | return -EIO; |
| 254 | 215 | i++; |
| 255 | 216 | } |
| 256 | 217 | |
| 257 | − /* The last byte has to indicate transfer done. | |
| 258 | − */ | |
| 218 | + /* The last byte has to indicate transfer done. */ | |
| 259 | 219 | data = buf[i]; |
| 260 | 220 | data |= PSC_SMBTXRX_STP; |
| 261 | − sp->psc_smbtxrx = data; | |
| 262 | − au_sync(); | |
| 221 | + WR(adap, PSC_SMBTXRX, data); | |
| 263 | 222 | if (wait_master_done(adap)) |
| 264 | 223 | return -EIO; |
| 265 | 224 | return 0; |
| @@ -269,12 +228,10 @@ static int · 3 unmodified lines | ||
| 269 | 228 | au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) |
| 270 | 229 | { |
| 271 | 230 | struct i2c_au1550_data *adap = i2c_adap->algo_data; |
| 272 | − volatile psc_smb_t *sp = (volatile psc_smb_t *)adap->psc_base; | |
| 273 | 231 | struct i2c_msg *p; |
| 274 | 232 | int i, err = 0; |
| 275 | 233 | |
| 276 | − sp->psc_ctrl = PSC_CTRL_ENABLE; | |
| 277 | − au_sync(); | |
| 234 | + WR(adap, PSC_CTRL, PSC_CTRL_ENABLE); | |
| 278 | 235 | |
| 279 | 236 | for (i = 0; !err && i < num; i++) { |
| 280 | 237 | p = &msgs[i]; |
| @@ -293,14 +250,12 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) · 12 unmodified lines | ||
| 293 | 250 | if (err == 0) |
| 294 | 251 | err = num; |
| 295 | 252 | |
| 296 | − sp->psc_ctrl = PSC_CTRL_SUSPEND; | |
| 297 | − au_sync(); | |
| 253 | + WR(adap, PSC_CTRL, PSC_CTRL_SUSPEND); | |
| 298 | 254 | |
| 299 | 255 | return err; |
| 300 | 256 | } |
| 301 | 257 | |
| 302 | −static u32 | |
| 303 | −au1550_func(struct i2c_adapter *adap) | |
| 258 | +static u32 au1550_func(struct i2c_adapter *adap) | |
| 304 | 259 | { |
| 305 | 260 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
| 306 | 261 | } |
| @@ -312,57 +267,45 @@ static const struct i2c_algorithm au1550_algo = { · 5 unmodified lines | ||
| 312 | 267 | |
| 313 | 268 | static void i2c_au1550_setup(struct i2c_au1550_data *priv) |
| 314 | 269 | { |
| 315 | − volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base; | |
| 316 | − u32 stat; | |
| 317 | − | |
| 318 | − sp->psc_ctrl = PSC_CTRL_DISABLE; | |
| 319 | − au_sync(); | |
| 320 | − sp->psc_sel = PSC_SEL_PS_SMBUSMODE; | |
| 321 | − sp->psc_smbcfg = 0; | |
| 322 | − au_sync(); | |
| 323 | − sp->psc_ctrl = PSC_CTRL_ENABLE; | |
| 324 | − au_sync(); | |
| 325 | − do { | |
| 326 | − stat = sp->psc_smbstat; | |
| 327 | − au_sync(); | |
| 328 | − } while ((stat & PSC_SMBSTAT_SR) == 0); | |
| 270 | + unsigned long cfg; | |
| 329 | 271 | |
| 330 | − sp->psc_smbcfg = (PSC_SMBCFG_RT_FIFO8 | PSC_SMBCFG_TT_FIFO8 | | |
| 331 | − PSC_SMBCFG_DD_DISABLE); | |
| 272 | + WR(priv, PSC_CTRL, PSC_CTRL_DISABLE); | |
| 273 | + WR(priv, PSC_SEL, PSC_SEL_PS_SMBUSMODE); | |
| 274 | + WR(priv, PSC_SMBCFG, 0); | |
| 275 | + WR(priv, PSC_CTRL, PSC_CTRL_ENABLE); | |
| 276 | + while ((RD(priv, PSC_SMBSTAT) & PSC_SMBSTAT_SR) == 0) | |
| 277 | + cpu_relax(); | |
| 278 | + | |
| 279 | + cfg = PSC_SMBCFG_RT_FIFO8 | PSC_SMBCFG_TT_FIFO8 | PSC_SMBCFG_DD_DISABLE; | |
| 280 | + WR(priv, PSC_SMBCFG, cfg); | |
| 332 | 281 | |
| 333 | 282 | /* Divide by 8 to get a 6.25 MHz clock. The later protocol |
| 334 | 283 | * timings are based on this clock. |
| 335 | 284 | */ |
| 336 | − sp->psc_smbcfg |= PSC_SMBCFG_SET_DIV(PSC_SMBCFG_DIV8); | |
| 337 | − sp->psc_smbmsk = PSC_SMBMSK_ALLMASK; | |
| 338 | − au_sync(); | |
| 285 | + cfg |= PSC_SMBCFG_SET_DIV(PSC_SMBCFG_DIV8); | |
| 286 | + WR(priv, PSC_SMBCFG, cfg); | |
| 287 | + WR(priv, PSC_SMBMSK, PSC_SMBMSK_ALLMASK); | |
| 339 | 288 | |
| 340 | 289 | /* Set the protocol timer values. See Table 71 in the |
| 341 | 290 | * Au1550 Data Book for standard timing values. |
| 342 | 291 | */ |
| 343 | − sp->psc_smbtmr = PSC_SMBTMR_SET_TH(0) | PSC_SMBTMR_SET_PS(15) | \ | |
| 292 | + WR(priv, PSC_SMBTMR, PSC_SMBTMR_SET_TH(0) | PSC_SMBTMR_SET_PS(15) | \ | |
| 344 | 293 | PSC_SMBTMR_SET_PU(15) | PSC_SMBTMR_SET_SH(15) | \ |
| 345 | 294 | PSC_SMBTMR_SET_SU(15) | PSC_SMBTMR_SET_CL(15) | \ |
| 346 | − PSC_SMBTMR_SET_CH(15); | |
| 347 | − au_sync(); | |
| 295 | + PSC_SMBTMR_SET_CH(15)); | |
| 348 | 296 | |
| 349 | − sp->psc_smbcfg |= PSC_SMBCFG_DE_ENABLE; | |
| 350 | − do { | |
| 351 | − stat = sp->psc_smbstat; | |
| 352 | − au_sync(); | |
| 353 | − } while ((stat & PSC_SMBSTAT_SR) == 0); | |
| 297 | + cfg |= PSC_SMBCFG_DE_ENABLE; | |
| 298 | + WR(priv, PSC_SMBCFG, cfg); | |
| 299 | + while ((RD(priv, PSC_SMBSTAT) & PSC_SMBSTAT_SR) == 0) | |
| 300 | + cpu_relax(); | |
| 354 | 301 | |
| 355 | − sp->psc_ctrl = PSC_CTRL_SUSPEND; | |
| 356 | − au_sync(); | |
| 302 | + WR(priv, PSC_CTRL, PSC_CTRL_SUSPEND); | |
| 357 | 303 | } |
| 358 | 304 | |
| 359 | 305 | static void i2c_au1550_disable(struct i2c_au1550_data *priv) |
| 360 | 306 | { |
| 361 | − volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base; | |
| 362 | − | |
| 363 | − sp->psc_smbcfg = 0; | |
| 364 | − sp->psc_ctrl = PSC_CTRL_DISABLE; | |
| 365 | − au_sync(); | |
| 307 | + WR(priv, PSC_SMBCFG, 0); | |
| 308 | + WR(priv, PSC_CTRL, PSC_CTRL_DISABLE); | |
| 366 | 309 | } |
| 367 | 310 | |
| 368 | 311 | /* |
| @@ -396,9 +339,12 @@ i2c_au1550_probe(struct platform_device *pdev) · 27 unmodified lines | ||
| 396 | 339 | goto out_mem; |
| 397 | 340 | } |
| 398 | 341 | |
| 399 | − priv->psc_base = CKSEG1ADDR(r->start); | |
| 342 | + priv->psc_base = ioremap(r->start, resource_size(r)); | |
| 343 | + if (!priv->psc_base) { | |
| 344 | + ret = -EIO; | |
| 345 | + goto out_map; | |
| 346 | + } | |
| 400 | 347 | priv->xfer_timeout = 200; |
| 401 | − priv->ack_timeout = 200; | |
| 402 | 348 | |
| 403 | 349 | priv->adap.nr = pdev->id; |
| 404 | 350 | priv->adap.algo = &au1550_algo; |
| @@ -406,8 +352,7 @@ i2c_au1550_probe(struct platform_device *pdev) · 1 unmodified line | ||
| 406 | 352 | priv->adap.dev.parent = &pdev->dev; |
| 407 | 353 | strlcpy(priv->adap.name, "Au1xxx PSC I2C", sizeof(priv->adap.name)); |
| 408 | 354 | |
| 409 | − /* Now, set up the PSC for SMBus PIO mode. | |
| 410 | − */ | |
| 355 | + /* Now, set up the PSC for SMBus PIO mode. */ | |
| 411 | 356 | i2c_au1550_setup(priv); |
| 412 | 357 | |
| 413 | 358 | ret = i2c_add_numbered_adapter(&priv->adap); |
| @@ -417,7 +362,8 @@ i2c_au1550_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 417 | 362 | } |
| 418 | 363 | |
| 419 | 364 | i2c_au1550_disable(priv); |
| 420 | − | |
| 365 | + iounmap(priv->psc_base); | |
| 366 | +out_map: | |
| 421 | 367 | release_resource(priv->ioarea); |
| 422 | 368 | kfree(priv->ioarea); |
| 423 | 369 | out_mem: |
| @@ -426,14 +372,14 @@ out: · 2 unmodified lines | ||
| 426 | 372 | return ret; |
| 427 | 373 | } |
| 428 | 374 | |
| 429 | −static int __devexit | |
| 430 | −i2c_au1550_remove(struct platform_device *pdev) | |
| 375 | +static int __devexit i2c_au1550_remove(struct platform_device *pdev) | |
| 431 | 376 | { |
| 432 | 377 | struct i2c_au1550_data *priv = platform_get_drvdata(pdev); |
| 433 | 378 | |
| 434 | 379 | platform_set_drvdata(pdev, NULL); |
| 435 | 380 | i2c_del_adapter(&priv->adap); |
| 436 | 381 | i2c_au1550_disable(priv); |
| 382 | + iounmap(priv->psc_base); | |
| 437 | 383 | release_resource(priv->ioarea); |
| 438 | 384 | kfree(priv->ioarea); |
| 439 | 385 | kfree(priv); |
| @@ -441,49 +387,51 @@ i2c_au1550_remove(struct platform_device *pdev) · 1 unmodified line | ||
| 441 | 387 | } |
| 442 | 388 | |
| 443 | 389 | #ifdef CONFIG_PM |
| 444 | −static int | |
| 445 | −i2c_au1550_suspend(struct platform_device *pdev, pm_message_t state) | |
| 390 | +static int i2c_au1550_suspend(struct device *dev) | |
| 446 | 391 | { |
| 447 | − struct i2c_au1550_data *priv = platform_get_drvdata(pdev); | |
| 392 | + struct i2c_au1550_data *priv = dev_get_drvdata(dev); | |
| 448 | 393 | |
| 449 | 394 | i2c_au1550_disable(priv); |
| 450 | 395 | |
| 451 | 396 | return 0; |
| 452 | 397 | } |
| 453 | 398 | |
| 454 | −static int | |
| 455 | −i2c_au1550_resume(struct platform_device *pdev) | |
| 399 | +static int i2c_au1550_resume(struct device *dev) | |
| 456 | 400 | { |
| 457 | − struct i2c_au1550_data *priv = platform_get_drvdata(pdev); | |
| 401 | + struct i2c_au1550_data *priv = dev_get_drvdata(dev); | |
| 458 | 402 | |
| 459 | 403 | i2c_au1550_setup(priv); |
| 460 | 404 | |
| 461 | 405 | return 0; |
| 462 | 406 | } |
| 407 | + | |
| 408 | +static const struct dev_pm_ops i2c_au1550_pmops = { | |
| 409 | + .suspend = i2c_au1550_suspend, | |
| 410 | + .resume = i2c_au1550_resume, | |
| 411 | +}; | |
| 412 | + | |
| 413 | +#define AU1XPSC_SMBUS_PMOPS (&i2c_au1550_pmops) | |
| 414 | + | |
| 463 | 415 | #else |
| 464 | −#define i2c_au1550_suspend NULL | |
| 465 | −#define i2c_au1550_resume NULL | |
| 416 | +#define AU1XPSC_SMBUS_PMOPS NULL | |
| 466 | 417 | #endif |
| 467 | 418 | |
| 468 | 419 | static struct platform_driver au1xpsc_smbus_driver = { |
| 469 | 420 | .driver = { |
| 470 | 421 | .name = "au1xpsc_smbus", |
| 471 | 422 | .owner = THIS_MODULE, |
| 423 | + .pm = AU1XPSC_SMBUS_PMOPS, | |
| 472 | 424 | }, |
| 473 | 425 | .probe = i2c_au1550_probe, |
| 474 | 426 | .remove = __devexit_p(i2c_au1550_remove), |
| 475 | − .suspend = i2c_au1550_suspend, | |
| 476 | − .resume = i2c_au1550_resume, | |
| 477 | 427 | }; |
| 478 | 428 | |
| 479 | −static int __init | |
| 480 | −i2c_au1550_init(void) | |
| 429 | +static int __init i2c_au1550_init(void) | |
| 481 | 430 | { |
| 482 | 431 | return platform_driver_register(&au1xpsc_smbus_driver); |
| 483 | 432 | } |
| 484 | 433 | |
| 485 | −static void __exit | |
| 486 | −i2c_au1550_exit(void) | |
| 434 | +static void __exit i2c_au1550_exit(void) | |
| 487 | 435 | { |
| 488 | 436 | platform_driver_unregister(&au1xpsc_smbus_driver); |
| 489 | 437 | } |
| @@ -631,7 +631,7 @@ static int i2c_bfin_twi_resume(struct platform_device *pdev) · 630 unmodified lines | ||
| 631 | 631 | struct bfin_twi_iface *iface = platform_get_drvdata(pdev); |
| 632 | 632 | |
| 633 | 633 | int rc = request_irq(iface->irq, bfin_twi_interrupt_entry, |
| 634 | − IRQF_DISABLED, pdev->name, iface); | |
| 634 | + 0, pdev->name, iface); | |
| 635 | 635 | if (rc) { |
| 636 | 636 | dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq); |
| 637 | 637 | return -ENODEV; |
| @@ -702,7 +702,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) · 64 unmodified lines | ||
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | rc = request_irq(iface->irq, bfin_twi_interrupt_entry, |
| 705 | − IRQF_DISABLED, pdev->name, iface); | |
| 705 | + 0, pdev->name, iface); | |
| 706 | 706 | if (rc) { |
| 707 | 707 | dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq); |
| 708 | 708 | rc = -ENODEV; |
| @@ -25,18 +25,15 @@ · 24 unmodified lines | ||
| 25 | 25 | * ---------------------------------------------------------------------------- |
| 26 | 26 | * |
| 27 | 27 | */ |
| 28 | −#include <linux/kernel.h> | |
| 29 | −#include <linux/module.h> | |
| 30 | −#include <linux/delay.h> | |
| 31 | −#include <linux/i2c.h> | |
| 32 | 28 | #include <linux/clk.h> |
| 33 | 29 | #include <linux/errno.h> |
| 34 | −#include <linux/sched.h> | |
| 35 | 30 | #include <linux/err.h> |
| 31 | +#include <linux/i2c.h> | |
| 36 | 32 | #include <linux/interrupt.h> |
| 37 | −#include <linux/platform_device.h> | |
| 38 | 33 | #include <linux/io.h> |
| 39 | −#include <linux/slab.h> | |
| 34 | +#include <linux/pm_runtime.h> | |
| 35 | +#include <linux/delay.h> | |
| 36 | +#include "i2c-designware-core.h" | |
| 40 | 37 | |
| 41 | 38 | /* |
| 42 | 39 | * Registers offset |
| @@ -68,15 +65,10 @@ · 25 unmodified lines | ||
| 68 | 65 | #define DW_IC_STATUS 0x70 |
| 69 | 66 | #define DW_IC_TXFLR 0x74 |
| 70 | 67 | #define DW_IC_RXFLR 0x78 |
| 71 | −#define DW_IC_COMP_PARAM_1 0xf4 | |
| 72 | 68 | #define DW_IC_TX_ABRT_SOURCE 0x80 |
| 73 | − | |
| 74 | −#define DW_IC_CON_MASTER 0x1 | |
| 75 | −#define DW_IC_CON_SPEED_STD 0x2 | |
| 76 | −#define DW_IC_CON_SPEED_FAST 0x4 | |
| 77 | −#define DW_IC_CON_10BITADDR_MASTER 0x10 | |
| 78 | −#define DW_IC_CON_RESTART_EN 0x20 | |
| 79 | −#define DW_IC_CON_SLAVE_DISABLE 0x40 | |
| 69 | +#define DW_IC_COMP_PARAM_1 0xf4 | |
| 70 | +#define DW_IC_COMP_TYPE 0xfc | |
| 71 | +#define DW_IC_COMP_TYPE_VALUE 0x44570140 | |
| 80 | 72 | |
| 81 | 73 | #define DW_IC_INTR_RX_UNDER 0x001 |
| 82 | 74 | #define DW_IC_INTR_RX_OVER 0x002 |
| @@ -170,55 +162,23 @@ static char *abort_sources[] = { · 87 unmodified lines | ||
| 170 | 162 | "lost arbitration", |
| 171 | 163 | }; |
| 172 | 164 | |
| 173 | −/** | |
| 174 | − * struct dw_i2c_dev - private i2c-designware data | |
| 175 | − * @dev: driver model device node | |
| 176 | − * @base: IO registers pointer | |
| 177 | − * @cmd_complete: tx completion indicator | |
| 178 | − * @lock: protect this struct and IO registers | |
| 179 | − * @clk: input reference clock | |
| 180 | − * @cmd_err: run time hadware error code | |
| 181 | − * @msgs: points to an array of messages currently being transferred | |
| 182 | − * @msgs_num: the number of elements in msgs | |
| 183 | − * @msg_write_idx: the element index of the current tx message in the msgs | |
| 184 | − * array | |
| 185 | − * @tx_buf_len: the length of the current tx buffer | |
| 186 | − * @tx_buf: the current tx buffer | |
| 187 | − * @msg_read_idx: the element index of the current rx message in the msgs | |
| 188 | − * array | |
| 189 | − * @rx_buf_len: the length of the current rx buffer | |
| 190 | − * @rx_buf: the current rx buffer | |
| 191 | − * @msg_err: error status of the current transfer | |
| 192 | − * @status: i2c master status, one of STATUS_* | |
| 193 | − * @abort_source: copy of the TX_ABRT_SOURCE register | |
| 194 | − * @irq: interrupt number for the i2c master | |
| 195 | − * @adapter: i2c subsystem adapter node | |
| 196 | − * @tx_fifo_depth: depth of the hardware tx fifo | |
| 197 | − * @rx_fifo_depth: depth of the hardware rx fifo | |
| 198 | − */ | |
| 199 | −struct dw_i2c_dev { | |
| 200 | − struct device *dev; | |
| 201 | − void __iomem *base; | |
| 202 | − struct completion cmd_complete; | |
| 203 | − struct mutex lock; | |
| 204 | − struct clk *clk; | |
| 205 | − int cmd_err; | |
| 206 | − struct i2c_msg *msgs; | |
| 207 | − int msgs_num; | |
| 208 | − int msg_write_idx; | |
| 209 | − u32 tx_buf_len; | |
| 210 | − u8 *tx_buf; | |
| 211 | − int msg_read_idx; | |
| 212 | − u32 rx_buf_len; | |
| 213 | − u8 *rx_buf; | |
| 214 | − int msg_err; | |
| 215 | − unsigned int status; | |
| 216 | − u32 abort_source; | |
| 217 | − int irq; | |
| 218 | − struct i2c_adapter adapter; | |
| 219 | − unsigned int tx_fifo_depth; | |
| 220 | − unsigned int rx_fifo_depth; | |
| 221 | −}; | |
| 165 | +u32 dw_readl(struct dw_i2c_dev *dev, int offset) | |
| 166 | +{ | |
| 167 | + u32 value = readl(dev->base + offset); | |
| 168 | + | |
| 169 | + if (dev->swab) | |
| 170 | + return swab32(value); | |
| 171 | + else | |
| 172 | + return value; | |
| 173 | +} | |
| 174 | + | |
| 175 | +void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset) | |
| 176 | +{ | |
| 177 | + if (dev->swab) | |
| 178 | + b = swab32(b); | |
| 179 | + | |
| 180 | + writel(b, dev->base + offset); | |
| 181 | +} | |
| 222 | 182 | |
| 223 | 183 | static u32 |
| 224 | 184 | i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) |
| @@ -283,13 +243,29 @@ static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) · 58 unmodified lines | ||
| 283 | 243 | * This function is called during I2C init function, and in case of timeout at |
| 284 | 244 | * run time. |
| 285 | 245 | */ |
| 286 | −static void i2c_dw_init(struct dw_i2c_dev *dev) | |
| 246 | +int i2c_dw_init(struct dw_i2c_dev *dev) | |
| 287 | 247 | { |
| 288 | − u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; | |
| 289 | − u32 ic_con, hcnt, lcnt; | |
| 248 | + u32 input_clock_khz; | |
| 249 | + u32 hcnt, lcnt; | |
| 250 | + u32 reg; | |
| 251 | + | |
| 252 | + input_clock_khz = dev->get_clk_rate_khz(dev); | |
| 253 | + | |
| 254 | + /* Configure register endianess access */ | |
| 255 | + reg = dw_readl(dev, DW_IC_COMP_TYPE); | |
| 256 | + if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) { | |
| 257 | + dev->swab = 1; | |
| 258 | + reg = DW_IC_COMP_TYPE_VALUE; | |
| 259 | + } | |
| 260 | + | |
| 261 | + if (reg != DW_IC_COMP_TYPE_VALUE) { | |
| 262 | + dev_err(dev->dev, "Unknown Synopsys component type: " | |
| 263 | + "0x%08x\n", reg); | |
| 264 | + return -ENODEV; | |
| 265 | + } | |
| 290 | 266 | |
| 291 | 267 | /* Disable the adapter */ |
| 292 | − writel(0, dev->base + DW_IC_ENABLE); | |
| 268 | + dw_writel(dev, 0, DW_IC_ENABLE); | |
| 293 | 269 | |
| 294 | 270 | /* set standard and fast speed deviders for high/low periods */ |
| 295 | 271 | |
| @@ -303,8 +279,8 @@ static void i2c_dw_init(struct dw_i2c_dev *dev) · 7 unmodified lines | ||
| 303 | 279 | 47, /* tLOW = 4.7 us */ |
| 304 | 280 | 3, /* tf = 0.3 us */ |
| 305 | 281 | 0); /* No offset */ |
| 306 | − writel(hcnt, dev->base + DW_IC_SS_SCL_HCNT); | |
| 307 | − writel(lcnt, dev->base + DW_IC_SS_SCL_LCNT); | |
| 282 | + dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT); | |
| 283 | + dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT); | |
| 308 | 284 | dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); |
| 309 | 285 | |
| 310 | 286 | /* Fast-mode */ |
| @@ -317,18 +293,17 @@ static void i2c_dw_init(struct dw_i2c_dev *dev) · 6 unmodified lines | ||
| 317 | 293 | 13, /* tLOW = 1.3 us */ |
| 318 | 294 | 3, /* tf = 0.3 us */ |
| 319 | 295 | 0); /* No offset */ |
| 320 | − writel(hcnt, dev->base + DW_IC_FS_SCL_HCNT); | |
| 321 | − writel(lcnt, dev->base + DW_IC_FS_SCL_LCNT); | |
| 296 | + dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT); | |
| 297 | + dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT); | |
| 322 | 298 | dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); |
| 323 | 299 | |
| 324 | 300 | /* Configure Tx/Rx FIFO threshold levels */ |
| 325 | − writel(dev->tx_fifo_depth - 1, dev->base + DW_IC_TX_TL); | |
| 326 | − writel(0, dev->base + DW_IC_RX_TL); | |
| 301 | + dw_writel(dev, dev->tx_fifo_depth - 1, DW_IC_TX_TL); | |
| 302 | + dw_writel(dev, 0, DW_IC_RX_TL); | |
| 327 | 303 | |
| 328 | 304 | /* configure the i2c master */ |
| 329 | − ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | | |
| 330 | − DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; | |
| 331 | − writel(ic_con, dev->base + DW_IC_CON); | |
| 305 | + dw_writel(dev, dev->master_cfg , DW_IC_CON); | |
| 306 | + return 0; | |
| 332 | 307 | } |
| 333 | 308 | |
| 334 | 309 | /* |
| @@ -338,7 +313,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) · 3 unmodified lines | ||
| 338 | 313 | { |
| 339 | 314 | int timeout = TIMEOUT; |
| 340 | 315 | |
| 341 | − while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { | |
| 316 | + while (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { | |
| 342 | 317 | if (timeout <= 0) { |
| 343 | 318 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); |
| 344 | 319 | return -ETIMEDOUT; |
| @@ -356,24 +331,24 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) · 11 unmodified lines | ||
| 356 | 331 | u32 ic_con; |
| 357 | 332 | |
| 358 | 333 | /* Disable the adapter */ |
| 359 | − writel(0, dev->base + DW_IC_ENABLE); | |
| 334 | + dw_writel(dev, 0, DW_IC_ENABLE); | |
| 360 | 335 | |
| 361 | 336 | /* set the slave (target) address */ |
| 362 | − writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR); | |
| 337 | + dw_writel(dev, msgs[dev->msg_write_idx].addr, DW_IC_TAR); | |
| 363 | 338 | |
| 364 | 339 | /* if the slave address is ten bit address, enable 10BITADDR */ |
| 365 | − ic_con = readl(dev->base + DW_IC_CON); | |
| 340 | + ic_con = dw_readl(dev, DW_IC_CON); | |
| 366 | 341 | if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) |
| 367 | 342 | ic_con |= DW_IC_CON_10BITADDR_MASTER; |
| 368 | 343 | else |
| 369 | 344 | ic_con &= ~DW_IC_CON_10BITADDR_MASTER; |
| 370 | − writel(ic_con, dev->base + DW_IC_CON); | |
| 345 | + dw_writel(dev, ic_con, DW_IC_CON); | |
| 371 | 346 | |
| 372 | 347 | /* Enable the adapter */ |
| 373 | − writel(1, dev->base + DW_IC_ENABLE); | |
| 348 | + dw_writel(dev, 1, DW_IC_ENABLE); | |
| 374 | 349 | |
| 375 | 350 | /* Enable interrupts */ |
| 376 | − writel(DW_IC_INTR_DEFAULT_MASK, dev->base + DW_IC_INTR_MASK); | |
| 351 | + dw_writel(dev, DW_IC_INTR_DEFAULT_MASK, DW_IC_INTR_MASK); | |
| 377 | 352 | } |
| 378 | 353 | |
| 379 | 354 | /* |
| @@ -382,7 +357,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) · 2 unmodified lines | ||
| 382 | 357 | * messages into the tx buffer. Even if the size of i2c_msg data is |
| 383 | 358 | * longer than the size of the tx buffer, it handles everything. |
| 384 | 359 | */ |
| 385 | −static void | |
| 360 | +void | |
| 386 | 361 | i2c_dw_xfer_msg(struct dw_i2c_dev *dev) |
| 387 | 362 | { |
| 388 | 363 | struct i2c_msg *msgs = dev->msgs; |
| @@ -420,15 +395,15 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) · 31 unmodified lines | ||
| 420 | 395 | buf_len = msgs[dev->msg_write_idx].len; |
| 421 | 396 | } |
| 422 | 397 | |
| 423 | − tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR); | |
| 424 | − rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR); | |
| 398 | + tx_limit = dev->tx_fifo_depth - dw_readl(dev, DW_IC_TXFLR); | |
| 399 | + rx_limit = dev->rx_fifo_depth - dw_readl(dev, DW_IC_RXFLR); | |
| 425 | 400 | |
| 426 | 401 | while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { |
| 427 | 402 | if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { |
| 428 | − writel(0x100, dev->base + DW_IC_DATA_CMD); | |
| 403 | + dw_writel(dev, 0x100, DW_IC_DATA_CMD); | |
| 429 | 404 | rx_limit--; |
| 430 | 405 | } else |
| 431 | − writel(*buf++, dev->base + DW_IC_DATA_CMD); | |
| 406 | + dw_writel(dev, *buf++, DW_IC_DATA_CMD); | |
| 432 | 407 | tx_limit--; buf_len--; |
| 433 | 408 | } |
| 434 | 409 | |
| @@ -453,7 +428,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) · 18 unmodified lines | ||
| 453 | 428 | if (dev->msg_err) |
| 454 | 429 | intr_mask = 0; |
| 455 | 430 | |
| 456 | − writel(intr_mask, dev->base + DW_IC_INTR_MASK); | |
| 431 | + dw_writel(dev, intr_mask, DW_IC_INTR_MASK); | |
| 457 | 432 | } |
| 458 | 433 | |
| 459 | 434 | static void |
| @@ -477,10 +452,10 @@ i2c_dw_read(struct dw_i2c_dev *dev) · 17 unmodified lines | ||
| 477 | 452 | buf = dev->rx_buf; |
| 478 | 453 | } |
| 479 | 454 | |
| 480 | − rx_valid = readl(dev->base + DW_IC_RXFLR); | |
| 455 | + rx_valid = dw_readl(dev, DW_IC_RXFLR); | |
| 481 | 456 | |
| 482 | 457 | for (; len > 0 && rx_valid > 0; len--, rx_valid--) |
| 483 | − *buf++ = readl(dev->base + DW_IC_DATA_CMD); | |
| 458 | + *buf++ = dw_readl(dev, DW_IC_DATA_CMD); | |
| 484 | 459 | |
| 485 | 460 | if (len > 0) { |
| 486 | 461 | dev->status |= STATUS_READ_IN_PROGRESS; |
| @@ -518,7 +493,7 @@ static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev) · 31 unmodified lines | ||
| 518 | 493 | /* |
| 519 | 494 | * Prepare controller for a transaction and call i2c_dw_xfer_msg |
| 520 | 495 | */ |
| 521 | −static int | |
| 496 | +int | |
| 522 | 497 | i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) |
| 523 | 498 | { |
| 524 | 499 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); |
| @@ -527,6 +502,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 2 unmodified lines | ||
| 527 | 502 | dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); |
| 528 | 503 | |
| 529 | 504 | mutex_lock(&dev->lock); |
| 505 | + pm_runtime_get_sync(dev->dev); | |
| 530 | 506 | |
| 531 | 507 | INIT_COMPLETION(dev->cmd_complete); |
| 532 | 508 | dev->msgs = msgs; |
| @@ -563,7 +539,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 30 unmodified lines | ||
| 563 | 539 | /* no error */ |
| 564 | 540 | if (likely(!dev->cmd_err)) { |
| 565 | 541 | /* Disable the adapter */ |
| 566 | − writel(0, dev->base + DW_IC_ENABLE); | |
| 542 | + dw_writel(dev, 0, DW_IC_ENABLE); | |
| 567 | 543 | ret = num; |
| 568 | 544 | goto done; |
| 569 | 545 | } |
| @@ -576,19 +552,16 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 6 unmodified lines | ||
| 576 | 552 | ret = -EIO; |
| 577 | 553 | |
| 578 | 554 | done: |
| 555 | + pm_runtime_put(dev->dev); | |
| 579 | 556 | mutex_unlock(&dev->lock); |
| 580 | 557 | |
| 581 | 558 | return ret; |
| 582 | 559 | } |
| 583 | 560 | |
| 584 | −static u32 i2c_dw_func(struct i2c_adapter *adap) | |
| 561 | +u32 i2c_dw_func(struct i2c_adapter *adap) | |
| 585 | 562 | { |
| 586 | − return I2C_FUNC_I2C | | |
| 587 | − I2C_FUNC_10BIT_ADDR | | |
| 588 | − I2C_FUNC_SMBUS_BYTE | | |
| 589 | − I2C_FUNC_SMBUS_BYTE_DATA | | |
| 590 | − I2C_FUNC_SMBUS_WORD_DATA | | |
| 591 | − I2C_FUNC_SMBUS_I2C_BLOCK; | |
| 563 | + struct dw_i2c_dev *dev = i2c_get_adapdata(adap); | |
| 564 | + return dev->functionality; | |
| 592 | 565 | } |
| 593 | 566 | |
| 594 | 567 | static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) |
| @@ -601,47 +574,47 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) · 6 unmodified lines | ||
| 601 | 574 | * in the IC_RAW_INTR_STAT register. |
| 602 | 575 | * |
| 603 | 576 | * That is, |
| 604 | − * stat = readl(IC_INTR_STAT); | |
| 577 | + * stat = dw_readl(IC_INTR_STAT); | |
| 605 | 578 | * equals to, |
| 606 | − * stat = readl(IC_RAW_INTR_STAT) & readl(IC_INTR_MASK); | |
| 579 | + * stat = dw_readl(IC_RAW_INTR_STAT) & dw_readl(IC_INTR_MASK); | |
| 607 | 580 | * |
| 608 | 581 | * The raw version might be useful for debugging purposes. |
| 609 | 582 | */ |
| 610 | − stat = readl(dev->base + DW_IC_INTR_STAT); | |
| 583 | + stat = dw_readl(dev, DW_IC_INTR_STAT); | |
| 611 | 584 | |
| 612 | 585 | /* |
| 613 | 586 | * Do not use the IC_CLR_INTR register to clear interrupts, or |
| 614 | 587 | * you'll miss some interrupts, triggered during the period from |
| 615 | − * readl(IC_INTR_STAT) to readl(IC_CLR_INTR). | |
| 588 | + * dw_readl(IC_INTR_STAT) to dw_readl(IC_CLR_INTR). | |
| 616 | 589 | * |
| 617 | 590 | * Instead, use the separately-prepared IC_CLR_* registers. |
| 618 | 591 | */ |
| 619 | 592 | if (stat & DW_IC_INTR_RX_UNDER) |
| 620 | − readl(dev->base + DW_IC_CLR_RX_UNDER); | |
| 593 | + dw_readl(dev, DW_IC_CLR_RX_UNDER); | |
| 621 | 594 | if (stat & DW_IC_INTR_RX_OVER) |
| 622 | − readl(dev->base + DW_IC_CLR_RX_OVER); | |
| 595 | + dw_readl(dev, DW_IC_CLR_RX_OVER); | |
| 623 | 596 | if (stat & DW_IC_INTR_TX_OVER) |
| 624 | − readl(dev->base + DW_IC_CLR_TX_OVER); | |
| 597 | + dw_readl(dev, DW_IC_CLR_TX_OVER); | |
| 625 | 598 | if (stat & DW_IC_INTR_RD_REQ) |
| 626 | − readl(dev->base + DW_IC_CLR_RD_REQ); | |
| 599 | + dw_readl(dev, DW_IC_CLR_RD_REQ); | |
| 627 | 600 | if (stat & DW_IC_INTR_TX_ABRT) { |
| 628 | 601 | /* |
| 629 | 602 | * The IC_TX_ABRT_SOURCE register is cleared whenever |
| 630 | 603 | * the IC_CLR_TX_ABRT is read. Preserve it beforehand. |
| 631 | 604 | */ |
| 632 | − dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE); | |
| 633 | − readl(dev->base + DW_IC_CLR_TX_ABRT); | |
| 605 | + dev->abort_source = dw_readl(dev, DW_IC_TX_ABRT_SOURCE); | |
| 606 | + dw_readl(dev, DW_IC_CLR_TX_ABRT); | |
| 634 | 607 | } |
| 635 | 608 | if (stat & DW_IC_INTR_RX_DONE) |
| 636 | − readl(dev->base + DW_IC_CLR_RX_DONE); | |
| 609 | + dw_readl(dev, DW_IC_CLR_RX_DONE); | |
| 637 | 610 | if (stat & DW_IC_INTR_ACTIVITY) |
| 638 | − readl(dev->base + DW_IC_CLR_ACTIVITY); | |
| 611 | + dw_readl(dev, DW_IC_CLR_ACTIVITY); | |
| 639 | 612 | if (stat & DW_IC_INTR_STOP_DET) |
| 640 | − readl(dev->base + DW_IC_CLR_STOP_DET); | |
| 613 | + dw_readl(dev, DW_IC_CLR_STOP_DET); | |
| 641 | 614 | if (stat & DW_IC_INTR_START_DET) |
| 642 | − readl(dev->base + DW_IC_CLR_START_DET); | |
| 615 | + dw_readl(dev, DW_IC_CLR_START_DET); | |
| 643 | 616 | if (stat & DW_IC_INTR_GEN_CALL) |
| 644 | − readl(dev->base + DW_IC_CLR_GEN_CALL); | |
| 617 | + dw_readl(dev, DW_IC_CLR_GEN_CALL); | |
| 645 | 618 | |
| 646 | 619 | return stat; |
| 647 | 620 | } |
| @@ -650,13 +623,19 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) · 2 unmodified lines | ||
| 650 | 623 | * Interrupt service routine. This gets called whenever an I2C interrupt |
| 651 | 624 | * occurs. |
| 652 | 625 | */ |
| 653 | −static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) | |
| 626 | +irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) | |
| 654 | 627 | { |
| 655 | 628 | struct dw_i2c_dev *dev = dev_id; |
| 656 | − u32 stat; | |
| 629 | + u32 stat, enabled; | |
| 630 | + | |
| 631 | + enabled = dw_readl(dev, DW_IC_ENABLE); | |
| 632 | + stat = dw_readl(dev, DW_IC_RAW_INTR_STAT); | |
| 633 | + dev_dbg(dev->dev, "%s: %s enabled= 0x%x stat=0x%x\n", __func__, | |
| 634 | + dev->adapter.name, enabled, stat); | |
| 635 | + if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY)) | |
| 636 | + return IRQ_NONE; | |
| 657 | 637 | |
| 658 | 638 | stat = i2c_dw_read_clear_intrbits(dev); |
| 659 | − dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); | |
| 660 | 639 | |
| 661 | 640 | if (stat & DW_IC_INTR_TX_ABRT) { |
| 662 | 641 | dev->cmd_err |= DW_IC_ERR_TX_ABRT; |
| @@ -666,7 +645,7 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) · 3 unmodified lines | ||
| 666 | 645 | * Anytime TX_ABRT is set, the contents of the tx/rx |
| 667 | 646 | * buffers are flushed. Make sure to skip them. |
| 668 | 647 | */ |
| 669 | − writel(0, dev->base + DW_IC_INTR_MASK); | |
| 648 | + dw_writel(dev, 0, DW_IC_INTR_MASK); | |
| 670 | 649 | goto tx_aborted; |
| 671 | 650 | } |
| 672 | 651 | |
| @@ -689,159 +668,38 @@ tx_aborted: · 16 unmodified lines | ||
| 689 | 668 | return IRQ_HANDLED; |
| 690 | 669 | } |
| 691 | 670 | |
| 692 | −static struct i2c_algorithm i2c_dw_algo = { | |
| 693 | − .master_xfer = i2c_dw_xfer, | |
| 694 | − .functionality = i2c_dw_func, | |
| 695 | −}; | |
| 696 | − | |
| 697 | −static int __devinit dw_i2c_probe(struct platform_device *pdev) | |
| 671 | +void i2c_dw_enable(struct dw_i2c_dev *dev) | |
| 698 | 672 | { |
| 699 | − struct dw_i2c_dev *dev; | |
| 700 | − struct i2c_adapter *adap; | |
| 701 | − struct resource *mem, *ioarea; | |
| 702 | − int irq, r; | |
| 703 | − | |
| 704 | − /* NOTE: driver uses the static register mapping */ | |
| 705 | − mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
| 706 | − if (!mem) { | |
| 707 | − dev_err(&pdev->dev, "no mem resource?\n"); | |
| 708 | − return -EINVAL; | |
| 709 | − } | |
| 710 | − | |
| 711 | − irq = platform_get_irq(pdev, 0); | |
| 712 | − if (irq < 0) { | |
| 713 | − dev_err(&pdev->dev, "no irq resource?\n"); | |
| 714 | − return irq; /* -ENXIO */ | |
| 715 | − } | |
| 716 | − | |
| 717 | − ioarea = request_mem_region(mem->start, resource_size(mem), | |
| 718 | − pdev->name); | |
| 719 | − if (!ioarea) { | |
| 720 | − dev_err(&pdev->dev, "I2C region already claimed\n"); | |
| 721 | − return -EBUSY; | |
| 722 | − } | |
| 723 | − | |
| 724 | − dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); | |
| 725 | − if (!dev) { | |
| 726 | − r = -ENOMEM; | |
| 727 | − goto err_release_region; | |
| 728 | − } | |
| 729 | − | |
| 730 | − init_completion(&dev->cmd_complete); | |
| 731 | − mutex_init(&dev->lock); | |
| 732 | − dev->dev = get_device(&pdev->dev); | |
| 733 | − dev->irq = irq; | |
| 734 | − platform_set_drvdata(pdev, dev); | |
| 735 | − | |
| 736 | − dev->clk = clk_get(&pdev->dev, NULL); | |
| 737 | − if (IS_ERR(dev->clk)) { | |
| 738 | − r = -ENODEV; | |
| 739 | − goto err_free_mem; | |
| 740 | − } | |
| 741 | − clk_enable(dev->clk); | |
| 742 | − | |
| 743 | − dev->base = ioremap(mem->start, resource_size(mem)); | |
| 744 | − if (dev->base == NULL) { | |
| 745 | − dev_err(&pdev->dev, "failure mapping io resources\n"); | |
| 746 | − r = -EBUSY; | |
| 747 | − goto err_unuse_clocks; | |
| 748 | − } | |
| 749 | − { | |
| 750 | − u32 param1 = readl(dev->base + DW_IC_COMP_PARAM_1); | |
| 751 | − | |
| 752 | − dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; | |
| 753 | − dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; | |
| 754 | − } | |
| 755 | − i2c_dw_init(dev); | |
| 756 | − | |
| 757 | − writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ | |
| 758 | − r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev); | |
| 759 | − if (r) { | |
| 760 | − dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | |
| 761 | − goto err_iounmap; | |
| 762 | − } | |
| 763 | − | |
| 764 | − adap = &dev->adapter; | |
| 765 | − i2c_set_adapdata(adap, dev); | |
| 766 | − adap->owner = THIS_MODULE; | |
| 767 | − adap->class = I2C_CLASS_HWMON; | |
| 768 | − strlcpy(adap->name, "Synopsys DesignWare I2C adapter", | |
| 769 | − sizeof(adap->name)); | |
| 770 | − adap->algo = &i2c_dw_algo; | |
| 771 | − adap->dev.parent = &pdev->dev; | |
| 772 | − | |
| 773 | − adap->nr = pdev->id; | |
| 774 | − r = i2c_add_numbered_adapter(adap); | |
| 775 | − if (r) { | |
| 776 | − dev_err(&pdev->dev, "failure adding adapter\n"); | |
| 777 | − goto err_free_irq; | |
| 778 | − } | |
| 779 | − | |
| 780 | − return 0; | |
| 781 | − | |
| 782 | −err_free_irq: | |
| 783 | − free_irq(dev->irq, dev); | |
| 784 | −err_iounmap: | |
| 785 | − iounmap(dev->base); | |
| 786 | −err_unuse_clocks: | |
| 787 | − clk_disable(dev->clk); | |
| 788 | − clk_put(dev->clk); | |
| 789 | − dev->clk = NULL; | |
| 790 | −err_free_mem: | |
| 791 | − platform_set_drvdata(pdev, NULL); | |
| 792 | − put_device(&pdev->dev); | |
| 793 | − kfree(dev); | |
| 794 | −err_release_region: | |
| 795 | − release_mem_region(mem->start, resource_size(mem)); | |
| 796 | − | |
| 797 | − return r; | |
| 673 | + /* Enable the adapter */ | |
| 674 | + dw_writel(dev, 1, DW_IC_ENABLE); | |
| 798 | 675 | } |
| 799 | 676 | |
| 800 | −static int __devexit dw_i2c_remove(struct platform_device *pdev) | |
| 677 | +u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev) | |
| 801 | 678 | { |
| 802 | − struct dw_i2c_dev *dev = platform_get_drvdata(pdev); | |
| 803 | − struct resource *mem; | |
| 804 | − | |
| 805 | − platform_set_drvdata(pdev, NULL); | |
| 806 | − i2c_del_adapter(&dev->adapter); | |
| 807 | − put_device(&pdev->dev); | |
| 808 | − | |
| 809 | − clk_disable(dev->clk); | |
| 810 | − clk_put(dev->clk); | |
| 811 | − dev->clk = NULL; | |
| 812 | − | |
| 813 | − writel(0, dev->base + DW_IC_ENABLE); | |
| 814 | − free_irq(dev->irq, dev); | |
| 815 | − kfree(dev); | |
| 816 | − | |
| 817 | − mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
| 818 | − release_mem_region(mem->start, resource_size(mem)); | |
| 819 | − return 0; | |
| 679 | + return dw_readl(dev, DW_IC_ENABLE); | |
| 820 | 680 | } |
| 821 | 681 | |
| 822 | −/* work with hotplug and coldplug */ | |
| 823 | −MODULE_ALIAS("platform:i2c_designware"); | |
| 682 | +void i2c_dw_disable(struct dw_i2c_dev *dev) | |
| 683 | +{ | |
| 684 | + /* Disable controller */ | |
| 685 | + dw_writel(dev, 0, DW_IC_ENABLE); | |
| 824 | 686 | |
| 825 | −static struct platform_driver dw_i2c_driver = { | |
| 826 | − .remove = __devexit_p(dw_i2c_remove), | |
| 827 | − .driver = { | |
| 828 | − .name = "i2c_designware", | |
| 829 | − .owner = THIS_MODULE, | |
| 830 | − }, | |
| 831 | −}; | |
| 687 | + /* Disable all interupts */ | |
| 688 | + dw_writel(dev, 0, DW_IC_INTR_MASK); | |
| 689 | + dw_readl(dev, DW_IC_CLR_INTR); | |
| 690 | +} | |
| 832 | 691 | |
| 833 | −static int __init dw_i2c_init_driver(void) | |
| 692 | +void i2c_dw_clear_int(struct dw_i2c_dev *dev) | |
| 834 | 693 | { |
| 835 | − return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe); | |
| 694 | + dw_readl(dev, DW_IC_CLR_INTR); | |
| 836 | 695 | } |
| 837 | −module_init(dw_i2c_init_driver); | |
| 838 | 696 | |
| 839 | −static void __exit dw_i2c_exit_driver(void) | |
| 697 | +void i2c_dw_disable_int(struct dw_i2c_dev *dev) | |
| 840 | 698 | { |
| 841 | − platform_driver_unregister(&dw_i2c_driver); | |
| 699 | + dw_writel(dev, 0, DW_IC_INTR_MASK); | |
| 842 | 700 | } |
| 843 | −module_exit(dw_i2c_exit_driver); | |
| 844 | 701 | |
| 845 | −MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); | |
| 846 | −MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter"); | |
| 847 | −MODULE_LICENSE("GPL"); | |
| 702 | +u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev) | |
| 703 | +{ | |
| 704 | + return dw_readl(dev, DW_IC_COMP_PARAM_1); | |
| 705 | +} | |
| @@ -0,0 +1,105 @@ | ||
| 1 | +/* | |
| 2 | + * Synopsys DesignWare I2C adapter driver (master only). | |
| 3 | + * | |
| 4 | + * Based on the TI DAVINCI I2C adapter driver. | |
| 5 | + * | |
| 6 | + * Copyright (C) 2006 Texas Instruments. | |
| 7 | + * Copyright (C) 2007 MontaVista Software Inc. | |
| 8 | + * Copyright (C) 2009 Provigent Ltd. | |
| 9 | + * | |
| 10 | + * ---------------------------------------------------------------------------- | |
| 11 | + * | |
| 12 | + * This program is free software; you can redistribute it and/or modify | |
| 13 | + * it under the terms of the GNU General Public License as published by | |
| 14 | + * the Free Software Foundation; either version 2 of the License, or | |
| 15 | + * (at your option) any later version. | |
| 16 | + * | |
| 17 | + * This program is distributed in the hope that it will be useful, | |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | + * GNU General Public License for more details. | |
| 21 | + * | |
| 22 | + * You should have received a copy of the GNU General Public License | |
| 23 | + * along with this program; if not, write to the Free Software | |
| 24 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 25 | + * ---------------------------------------------------------------------------- | |
| 26 | + * | |
| 27 | + */ | |
| 28 | + | |
| 29 | + | |
| 30 | +#define DW_IC_CON_MASTER 0x1 | |
| 31 | +#define DW_IC_CON_SPEED_STD 0x2 | |
| 32 | +#define DW_IC_CON_SPEED_FAST 0x4 | |
| 33 | +#define DW_IC_CON_10BITADDR_MASTER 0x10 | |
| 34 | +#define DW_IC_CON_RESTART_EN 0x20 | |
| 35 | +#define DW_IC_CON_SLAVE_DISABLE 0x40 | |
| 36 | + | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * struct dw_i2c_dev - private i2c-designware data | |
| 40 | + * @dev: driver model device node | |
| 41 | + * @base: IO registers pointer | |
| 42 | + * @cmd_complete: tx completion indicator | |
| 43 | + * @lock: protect this struct and IO registers | |
| 44 | + * @clk: input reference clock | |
| 45 | + * @cmd_err: run time hadware error code | |
| 46 | + * @msgs: points to an array of messages currently being transfered | |
| 47 | + * @msgs_num: the number of elements in msgs | |
| 48 | + * @msg_write_idx: the element index of the current tx message in the msgs | |
| 49 | + * array | |
| 50 | + * @tx_buf_len: the length of the current tx buffer | |
| 51 | + * @tx_buf: the current tx buffer | |
| 52 | + * @msg_read_idx: the element index of the current rx message in the msgs | |
| 53 | + * array | |
| 54 | + * @rx_buf_len: the length of the current rx buffer | |
| 55 | + * @rx_buf: the current rx buffer | |
| 56 | + * @msg_err: error status of the current transfer | |
| 57 | + * @status: i2c master status, one of STATUS_* | |
| 58 | + * @abort_source: copy of the TX_ABRT_SOURCE register | |
| 59 | + * @irq: interrupt number for the i2c master | |
| 60 | + * @adapter: i2c subsystem adapter node | |
| 61 | + * @tx_fifo_depth: depth of the hardware tx fifo | |
| 62 | + * @rx_fifo_depth: depth of the hardware rx fifo | |
| 63 | + */ | |
| 64 | +struct dw_i2c_dev { | |
| 65 | + struct device *dev; | |
| 66 | + void __iomem *base; | |
| 67 | + struct completion cmd_complete; | |
| 68 | + struct mutex lock; | |
| 69 | + struct clk *clk; | |
| 70 | + u32 (*get_clk_rate_khz) (struct dw_i2c_dev *dev); | |
| 71 | + struct dw_pci_controller *controller; | |
| 72 | + int cmd_err; | |
| 73 | + struct i2c_msg *msgs; | |
| 74 | + int msgs_num; | |
| 75 | + int msg_write_idx; | |
| 76 | + u32 tx_buf_len; | |
| 77 | + u8 *tx_buf; | |
| 78 | + int msg_read_idx; | |
| 79 | + u32 rx_buf_len; | |
| 80 | + u8 *rx_buf; | |
| 81 | + int msg_err; | |
| 82 | + unsigned int status; | |
| 83 | + u32 abort_source; | |
| 84 | + int irq; | |
| 85 | + int swab; | |
| 86 | + struct i2c_adapter adapter; | |
| 87 | + u32 functionality; | |
| 88 | + u32 master_cfg; | |
| 89 | + unsigned int tx_fifo_depth; | |
| 90 | + unsigned int rx_fifo_depth; | |
| 91 | +}; | |
| 92 | + | |
| 93 | +extern u32 dw_readl(struct dw_i2c_dev *dev, int offset); | |
| 94 | +extern void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset); | |
| 95 | +extern int i2c_dw_init(struct dw_i2c_dev *dev); | |
| 96 | +extern int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], | |
| 97 | + int num); | |
| 98 | +extern u32 i2c_dw_func(struct i2c_adapter *adap); | |
| 99 | +extern irqreturn_t i2c_dw_isr(int this_irq, void *dev_id); | |
| 100 | +extern void i2c_dw_enable(struct dw_i2c_dev *dev); | |
| 101 | +extern u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev); | |
| 102 | +extern void i2c_dw_disable(struct dw_i2c_dev *dev); | |
| 103 | +extern void i2c_dw_clear_int(struct dw_i2c_dev *dev); | |
| 104 | +extern void i2c_dw_disable_int(struct dw_i2c_dev *dev); | |
| 105 | +extern u32 i2c_dw_read_comp_param(struct dw_i2c_dev *dev); | |
| @@ -0,0 +1,392 @@ | ||
| 1 | +/* | |
| 2 | + * Synopsys DesignWare I2C adapter driver (master only). | |
| 3 | + * | |
| 4 | + * Based on the TI DAVINCI I2C adapter driver. | |
| 5 | + * | |
| 6 | + * Copyright (C) 2006 Texas Instruments. | |
| 7 | + * Copyright (C) 2007 MontaVista Software Inc. | |
| 8 | + * Copyright (C) 2009 Provigent Ltd. | |
| 9 | + * Copyright (C) 2011 Intel corporation. | |
| 10 | + * | |
| 11 | + * ---------------------------------------------------------------------------- | |
| 12 | + * | |
| 13 | + * This program is free software; you can redistribute it and/or modify | |
| 14 | + * it under the terms of the GNU General Public License as published by | |
| 15 | + * the Free Software Foundation; either version 2 of the License, or | |
| 16 | + * (at your option) any later version. | |
| 17 | + * | |
| 18 | + * This program is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | + * GNU General Public License for more details. | |
| 22 | + * | |
| 23 | + * You should have received a copy of the GNU General Public License | |
| 24 | + * along with this program; if not, write to the Free Software | |
| 25 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 26 | + * ---------------------------------------------------------------------------- | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | +#include <linux/kernel.h> | |
| 31 | +#include <linux/module.h> | |
| 32 | +#include <linux/delay.h> | |
| 33 | +#include <linux/i2c.h> | |
| 34 | +#include <linux/errno.h> | |
| 35 | +#include <linux/sched.h> | |
| 36 | +#include <linux/err.h> | |
| 37 | +#include <linux/interrupt.h> | |
| 38 | +#include <linux/io.h> | |
| 39 | +#include <linux/slab.h> | |
| 40 | +#include <linux/pci.h> | |
| 41 | +#include <linux/pm_runtime.h> | |
| 42 | +#include "i2c-designware-core.h" | |
| 43 | + | |
| 44 | +#define DRIVER_NAME "i2c-designware-pci" | |
| 45 | + | |
| 46 | +enum dw_pci_ctl_id_t { | |
| 47 | + moorestown_0, | |
| 48 | + moorestown_1, | |
| 49 | + moorestown_2, | |
| 50 | + | |
| 51 | + medfield_0, | |
| 52 | + medfield_1, | |
| 53 | + medfield_2, | |
| 54 | + medfield_3, | |
| 55 | + medfield_4, | |
| 56 | + medfield_5, | |
| 57 | +}; | |
| 58 | + | |
| 59 | +struct dw_pci_controller { | |
| 60 | + u32 bus_num; | |
| 61 | + u32 bus_cfg; | |
| 62 | + u32 tx_fifo_depth; | |
| 63 | + u32 rx_fifo_depth; | |
| 64 | + u32 clk_khz; | |
| 65 | +}; | |
| 66 | + | |
| 67 | +#define INTEL_MID_STD_CFG (DW_IC_CON_MASTER | \ | |
| 68 | + DW_IC_CON_SLAVE_DISABLE | \ | |
| 69 | + DW_IC_CON_RESTART_EN) | |
| 70 | + | |
| 71 | +static struct dw_pci_controller dw_pci_controllers[] = { | |
| 72 | + [moorestown_0] = { | |
| 73 | + .bus_num = 0, | |
| 74 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 75 | + .tx_fifo_depth = 32, | |
| 76 | + .rx_fifo_depth = 32, | |
| 77 | + .clk_khz = 25000, | |
| 78 | + }, | |
| 79 | + [moorestown_1] = { | |
| 80 | + .bus_num = 1, | |
| 81 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 82 | + .tx_fifo_depth = 32, | |
| 83 | + .rx_fifo_depth = 32, | |
| 84 | + .clk_khz = 25000, | |
| 85 | + }, | |
| 86 | + [moorestown_2] = { | |
| 87 | + .bus_num = 2, | |
| 88 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 89 | + .tx_fifo_depth = 32, | |
| 90 | + .rx_fifo_depth = 32, | |
| 91 | + .clk_khz = 25000, | |
| 92 | + }, | |
| 93 | + [medfield_0] = { | |
| 94 | + .bus_num = 0, | |
| 95 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 96 | + .tx_fifo_depth = 32, | |
| 97 | + .rx_fifo_depth = 32, | |
| 98 | + .clk_khz = 25000, | |
| 99 | + }, | |
| 100 | + [medfield_1] = { | |
| 101 | + .bus_num = 1, | |
| 102 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 103 | + .tx_fifo_depth = 32, | |
| 104 | + .rx_fifo_depth = 32, | |
| 105 | + .clk_khz = 25000, | |
| 106 | + }, | |
| 107 | + [medfield_2] = { | |
| 108 | + .bus_num = 2, | |
| 109 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 110 | + .tx_fifo_depth = 32, | |
| 111 | + .rx_fifo_depth = 32, | |
| 112 | + .clk_khz = 25000, | |
| 113 | + }, | |
| 114 | + [medfield_3] = { | |
| 115 | + .bus_num = 3, | |
| 116 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_STD, | |
| 117 | + .tx_fifo_depth = 32, | |
| 118 | + .rx_fifo_depth = 32, | |
| 119 | + .clk_khz = 25000, | |
| 120 | + }, | |
| 121 | + [medfield_4] = { | |
| 122 | + .bus_num = 4, | |
| 123 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 124 | + .tx_fifo_depth = 32, | |
| 125 | + .rx_fifo_depth = 32, | |
| 126 | + .clk_khz = 25000, | |
| 127 | + }, | |
| 128 | + [medfield_5] = { | |
| 129 | + .bus_num = 5, | |
| 130 | + .bus_cfg = INTEL_MID_STD_CFG | DW_IC_CON_SPEED_FAST, | |
| 131 | + .tx_fifo_depth = 32, | |
| 132 | + .rx_fifo_depth = 32, | |
| 133 | + .clk_khz = 25000, | |
| 134 | + }, | |
| 135 | +}; | |
| 136 | +static struct i2c_algorithm i2c_dw_algo = { | |
| 137 | + .master_xfer = i2c_dw_xfer, | |
| 138 | + .functionality = i2c_dw_func, | |
| 139 | +}; | |
| 140 | + | |
| 141 | +static int i2c_dw_pci_suspend(struct device *dev) | |
| 142 | +{ | |
| 143 | + struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); | |
| 144 | + struct dw_i2c_dev *i2c = pci_get_drvdata(pdev); | |
| 145 | + int err; | |
| 146 | + | |
| 147 | + | |
| 148 | + i2c_dw_disable(i2c); | |
| 149 | + | |
| 150 | + err = pci_save_state(pdev); | |
| 151 | + if (err) { | |
| 152 | + dev_err(&pdev->dev, "pci_save_state failed\n"); | |
| 153 | + return err; | |
| 154 | + } | |
| 155 | + | |
| 156 | + err = pci_set_power_state(pdev, PCI_D3hot); | |
| 157 | + if (err) { | |
| 158 | + dev_err(&pdev->dev, "pci_set_power_state failed\n"); | |
| 159 | + return err; | |
| 160 | + } | |
| 161 | + | |
| 162 | + return 0; | |
| 163 | +} | |
| 164 | + | |
| 165 | +static int i2c_dw_pci_resume(struct device *dev) | |
| 166 | +{ | |
| 167 | + struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); | |
| 168 | + struct dw_i2c_dev *i2c = pci_get_drvdata(pdev); | |
| 169 | + int err; | |
| 170 | + u32 enabled; | |
| 171 | + | |
| 172 | + enabled = i2c_dw_is_enabled(i2c); | |
| 173 | + if (enabled) | |
| 174 | + return 0; | |
| 175 | + | |
| 176 | + err = pci_set_power_state(pdev, PCI_D0); | |
| 177 | + if (err) { | |
| 178 | + dev_err(&pdev->dev, "pci_set_power_state() failed\n"); | |
| 179 | + return err; | |
| 180 | + } | |
| 181 | + | |
| 182 | + pci_restore_state(pdev); | |
| 183 | + | |
| 184 | + i2c_dw_init(i2c); | |
| 185 | + i2c_dw_enable(i2c); | |
| 186 | + return 0; | |
| 187 | +} | |
| 188 | + | |
| 189 | +static int i2c_dw_pci_runtime_idle(struct device *dev) | |
| 190 | +{ | |
| 191 | + int err = pm_schedule_suspend(dev, 500); | |
| 192 | + dev_dbg(dev, "runtime_idle called\n"); | |
| 193 | + | |
| 194 | + if (err != 0) | |
| 195 | + return 0; | |
| 196 | + return -EBUSY; | |
| 197 | +} | |
| 198 | + | |
| 199 | +static const struct dev_pm_ops i2c_dw_pm_ops = { | |
| 200 | + .resume = i2c_dw_pci_resume, | |
| 201 | + .suspend = i2c_dw_pci_suspend, | |
| 202 | + SET_RUNTIME_PM_OPS(i2c_dw_pci_suspend, i2c_dw_pci_resume, | |
| 203 | + i2c_dw_pci_runtime_idle) | |
| 204 | +}; | |
| 205 | + | |
| 206 | +static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) | |
| 207 | +{ | |
| 208 | + return dev->controller->clk_khz; | |
| 209 | +} | |
| 210 | + | |
| 211 | +static int __devinit i2c_dw_pci_probe(struct pci_dev *pdev, | |
| 212 | +const struct pci_device_id *id) | |
| 213 | +{ | |
| 214 | + struct dw_i2c_dev *dev; | |
| 215 | + struct i2c_adapter *adap; | |
| 216 | + unsigned long start, len; | |
| 217 | + void __iomem *base; | |
| 218 | + int r; | |
| 219 | + struct dw_pci_controller *controller; | |
| 220 | + | |
| 221 | + if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) { | |
| 222 | + printk(KERN_ERR "dw_i2c_pci_probe: invalid driver data %ld\n", | |
| 223 | + id->driver_data); | |
| 224 | + return -EINVAL; | |
| 225 | + } | |
| 226 | + | |
| 227 | + controller = &dw_pci_controllers[id->driver_data]; | |
| 228 | + | |
| 229 | + r = pci_enable_device(pdev); | |
| 230 | + if (r) { | |
| 231 | + dev_err(&pdev->dev, "Failed to enable I2C PCI device (%d)\n", | |
| 232 | + r); | |
| 233 | + goto exit; | |
| 234 | + } | |
| 235 | + | |
| 236 | + /* Determine the address of the I2C area */ | |
| 237 | + start = pci_resource_start(pdev, 0); | |
| 238 | + len = pci_resource_len(pdev, 0); | |
| 239 | + if (!start || len == 0) { | |
| 240 | + dev_err(&pdev->dev, "base address not set\n"); | |
| 241 | + r = -ENODEV; | |
| 242 | + goto exit; | |
| 243 | + } | |
| 244 | + | |
| 245 | + r = pci_request_region(pdev, 0, DRIVER_NAME); | |
| 246 | + if (r) { | |
| 247 | + dev_err(&pdev->dev, "failed to request I2C region " | |
| 248 | + "0x%lx-0x%lx\n", start, | |
| 249 | + (unsigned long)pci_resource_end(pdev, 0)); | |
| 250 | + goto exit; | |
| 251 | + } | |
| 252 | + | |
| 253 | + base = ioremap_nocache(start, len); | |
| 254 | + if (!base) { | |
| 255 | + dev_err(&pdev->dev, "I/O memory remapping failed\n"); | |
| 256 | + r = -ENOMEM; | |
| 257 | + goto err_release_region; | |
| 258 | + } | |
| 259 | + | |
| 260 | + | |
| 261 | + dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); | |
| 262 | + if (!dev) { | |
| 263 | + r = -ENOMEM; | |
| 264 | + goto err_release_region; | |
| 265 | + } | |
| 266 | + | |
| 267 | + init_completion(&dev->cmd_complete); | |
| 268 | + mutex_init(&dev->lock); | |
| 269 | + dev->clk = NULL; | |
| 270 | + dev->controller = controller; | |
| 271 | + dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; | |
| 272 | + dev->base = base; | |
| 273 | + dev->dev = get_device(&pdev->dev); | |
| 274 | + dev->functionality = | |
| 275 | + I2C_FUNC_I2C | | |
| 276 | + I2C_FUNC_SMBUS_BYTE | | |
| 277 | + I2C_FUNC_SMBUS_BYTE_DATA | | |
| 278 | + I2C_FUNC_SMBUS_WORD_DATA | | |
| 279 | + I2C_FUNC_SMBUS_I2C_BLOCK; | |
| 280 | + dev->master_cfg = controller->bus_cfg; | |
| 281 | + | |
| 282 | + pci_set_drvdata(pdev, dev); | |
| 283 | + | |
| 284 | + dev->tx_fifo_depth = controller->tx_fifo_depth; | |
| 285 | + dev->rx_fifo_depth = controller->rx_fifo_depth; | |
| 286 | + r = i2c_dw_init(dev); | |
| 287 | + if (r) | |
| 288 | + goto err_iounmap; | |
| 289 | + | |
| 290 | + adap = &dev->adapter; | |
| 291 | + i2c_set_adapdata(adap, dev); | |
| 292 | + adap->owner = THIS_MODULE; | |
| 293 | + adap->class = 0; | |
| 294 | + adap->algo = &i2c_dw_algo; | |
| 295 | + adap->dev.parent = &pdev->dev; | |
| 296 | + adap->nr = controller->bus_num; | |
| 297 | + snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d", | |
| 298 | + adap->nr); | |
| 299 | + | |
| 300 | + r = request_irq(pdev->irq, i2c_dw_isr, IRQF_SHARED, adap->name, dev); | |
| 301 | + if (r) { | |
| 302 | + dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | |
| 303 | + goto err_iounmap; | |
| 304 | + } | |
| 305 | + | |
| 306 | + i2c_dw_disable_int(dev); | |
| 307 | + i2c_dw_clear_int(dev); | |
| 308 | + r = i2c_add_numbered_adapter(adap); | |
| 309 | + if (r) { | |
| 310 | + dev_err(&pdev->dev, "failure adding adapter\n"); | |
| 311 | + goto err_free_irq; | |
| 312 | + } | |
| 313 | + | |
| 314 | + pm_runtime_put_noidle(&pdev->dev); | |
| 315 | + pm_runtime_allow(&pdev->dev); | |
| 316 | + | |
| 317 | + return 0; | |
| 318 | + | |
| 319 | +err_free_irq: | |
| 320 | + free_irq(pdev->irq, dev); | |
| 321 | +err_iounmap: | |
| 322 | + iounmap(dev->base); | |
| 323 | + pci_set_drvdata(pdev, NULL); | |
| 324 | + put_device(&pdev->dev); | |
| 325 | + kfree(dev); | |
| 326 | +err_release_region: | |
| 327 | + pci_release_region(pdev, 0); | |
| 328 | +exit: | |
| 329 | + return r; | |
| 330 | +} | |
| 331 | + | |
| 332 | +static void __devexit i2c_dw_pci_remove(struct pci_dev *pdev) | |
| 333 | +{ | |
| 334 | + struct dw_i2c_dev *dev = pci_get_drvdata(pdev); | |
| 335 | + | |
| 336 | + i2c_dw_disable(dev); | |
| 337 | + pm_runtime_forbid(&pdev->dev); | |
| 338 | + pm_runtime_get_noresume(&pdev->dev); | |
| 339 | + | |
| 340 | + pci_set_drvdata(pdev, NULL); | |
| 341 | + i2c_del_adapter(&dev->adapter); | |
| 342 | + put_device(&pdev->dev); | |
| 343 | + | |
| 344 | + free_irq(dev->irq, dev); | |
| 345 | + kfree(dev); | |
| 346 | + pci_release_region(pdev, 0); | |
| 347 | +} | |
| 348 | + | |
| 349 | +/* work with hotplug and coldplug */ | |
| 350 | +MODULE_ALIAS("i2c_designware-pci"); | |
| 351 | + | |
| 352 | +DEFINE_PCI_DEVICE_TABLE(i2_designware_pci_ids) = { | |
| 353 | + /* Moorestown */ | |
| 354 | + { PCI_VDEVICE(INTEL, 0x0802), moorestown_0 }, | |
| 355 | + { PCI_VDEVICE(INTEL, 0x0803), moorestown_1 }, | |
| 356 | + { PCI_VDEVICE(INTEL, 0x0804), moorestown_2 }, | |
| 357 | + /* Medfield */ | |
| 358 | + { PCI_VDEVICE(INTEL, 0x0817), medfield_3,}, | |
| 359 | + { PCI_VDEVICE(INTEL, 0x0818), medfield_4 }, | |
| 360 | + { PCI_VDEVICE(INTEL, 0x0819), medfield_5 }, | |
| 361 | + { PCI_VDEVICE(INTEL, 0x082C), medfield_0 }, | |
| 362 | + { PCI_VDEVICE(INTEL, 0x082D), medfield_1 }, | |
| 363 | + { PCI_VDEVICE(INTEL, 0x082E), medfield_2 }, | |
| 364 | + { 0,} | |
| 365 | +}; | |
| 366 | +MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids); | |
| 367 | + | |
| 368 | +static struct pci_driver dw_i2c_driver = { | |
| 369 | + .name = DRIVER_NAME, | |
| 370 | + .id_table = i2_designware_pci_ids, | |
| 371 | + .probe = i2c_dw_pci_probe, | |
| 372 | + .remove = __devexit_p(i2c_dw_pci_remove), | |
| 373 | + .driver = { | |
| 374 | + .pm = &i2c_dw_pm_ops, | |
| 375 | + }, | |
| 376 | +}; | |
| 377 | + | |
| 378 | +static int __init dw_i2c_init_driver(void) | |
| 379 | +{ | |
| 380 | + return pci_register_driver(&dw_i2c_driver); | |
| 381 | +} | |
| 382 | +module_init(dw_i2c_init_driver); | |
| 383 | + | |
| 384 | +static void __exit dw_i2c_exit_driver(void) | |
| 385 | +{ | |
| 386 | + pci_unregister_driver(&dw_i2c_driver); | |
| 387 | +} | |
| 388 | +module_exit(dw_i2c_exit_driver); | |
| 389 | + | |
| 390 | +MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); | |
| 391 | +MODULE_DESCRIPTION("Synopsys DesignWare PCI I2C bus adapter"); | |
| 392 | +MODULE_LICENSE("GPL"); | |
| @@ -0,0 +1,215 @@ | ||
| 1 | +/* | |
| 2 | + * Synopsys DesignWare I2C adapter driver (master only). | |
| 3 | + * | |
| 4 | + * Based on the TI DAVINCI I2C adapter driver. | |
| 5 | + * | |
| 6 | + * Copyright (C) 2006 Texas Instruments. | |
| 7 | + * Copyright (C) 2007 MontaVista Software Inc. | |
| 8 | + * Copyright (C) 2009 Provigent Ltd. | |
| 9 | + * | |
| 10 | + * ---------------------------------------------------------------------------- | |
| 11 | + * | |
| 12 | + * This program is free software; you can redistribute it and/or modify | |
| 13 | + * it under the terms of the GNU General Public License as published by | |
| 14 | + * the Free Software Foundation; either version 2 of the License, or | |
| 15 | + * (at your option) any later version. | |
| 16 | + * | |
| 17 | + * This program is distributed in the hope that it will be useful, | |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | + * GNU General Public License for more details. | |
| 21 | + * | |
| 22 | + * You should have received a copy of the GNU General Public License | |
| 23 | + * along with this program; if not, write to the Free Software | |
| 24 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 25 | + * ---------------------------------------------------------------------------- | |
| 26 | + * | |
| 27 | + */ | |
| 28 | +#include <linux/kernel.h> | |
| 29 | +#include <linux/module.h> | |
| 30 | +#include <linux/delay.h> | |
| 31 | +#include <linux/i2c.h> | |
| 32 | +#include <linux/clk.h> | |
| 33 | +#include <linux/errno.h> | |
| 34 | +#include <linux/sched.h> | |
| 35 | +#include <linux/err.h> | |
| 36 | +#include <linux/interrupt.h> | |
| 37 | +#include <linux/platform_device.h> | |
| 38 | +#include <linux/io.h> | |
| 39 | +#include <linux/slab.h> | |
| 40 | +#include "i2c-designware-core.h" | |
| 41 | + | |
| 42 | +static struct i2c_algorithm i2c_dw_algo = { | |
| 43 | + .master_xfer = i2c_dw_xfer, | |
| 44 | + .functionality = i2c_dw_func, | |
| 45 | +}; | |
| 46 | +static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) | |
| 47 | +{ | |
| 48 | + return clk_get_rate(dev->clk)/1000; | |
| 49 | +} | |
| 50 | + | |
| 51 | +static int __devinit dw_i2c_probe(struct platform_device *pdev) | |
| 52 | +{ | |
| 53 | + struct dw_i2c_dev *dev; | |
| 54 | + struct i2c_adapter *adap; | |
| 55 | + struct resource *mem, *ioarea; | |
| 56 | + int irq, r; | |
| 57 | + | |
| 58 | + /* NOTE: driver uses the static register mapping */ | |
| 59 | + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
| 60 | + if (!mem) { | |
| 61 | + dev_err(&pdev->dev, "no mem resource?\n"); | |
| 62 | + return -EINVAL; | |
| 63 | + } | |
| 64 | + | |
| 65 | + irq = platform_get_irq(pdev, 0); | |
| 66 | + if (irq < 0) { | |
| 67 | + dev_err(&pdev->dev, "no irq resource?\n"); | |
| 68 | + return irq; /* -ENXIO */ | |
| 69 | + } | |
| 70 | + | |
| 71 | + ioarea = request_mem_region(mem->start, resource_size(mem), | |
| 72 | + pdev->name); | |
| 73 | + if (!ioarea) { | |
| 74 | + dev_err(&pdev->dev, "I2C region already claimed\n"); | |
| 75 | + return -EBUSY; | |
| 76 | + } | |
| 77 | + | |
| 78 | + dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); | |
| 79 | + if (!dev) { | |
| 80 | + r = -ENOMEM; | |
| 81 | + goto err_release_region; | |
| 82 | + } | |
| 83 | + | |
| 84 | + init_completion(&dev->cmd_complete); | |
| 85 | + mutex_init(&dev->lock); | |
| 86 | + dev->dev = get_device(&pdev->dev); | |
| 87 | + dev->irq = irq; | |
| 88 | + platform_set_drvdata(pdev, dev); | |
| 89 | + | |
| 90 | + dev->clk = clk_get(&pdev->dev, NULL); | |
| 91 | + dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; | |
| 92 | + | |
| 93 | + if (IS_ERR(dev->clk)) { | |
| 94 | + r = -ENODEV; | |
| 95 | + goto err_free_mem; | |
| 96 | + } | |
| 97 | + clk_enable(dev->clk); | |
| 98 | + | |
| 99 | + dev->functionality = | |
| 100 | + I2C_FUNC_I2C | | |
| 101 | + I2C_FUNC_10BIT_ADDR | | |
| 102 | + I2C_FUNC_SMBUS_BYTE | | |
| 103 | + I2C_FUNC_SMBUS_BYTE_DATA | | |
| 104 | + I2C_FUNC_SMBUS_WORD_DATA | | |
| 105 | + I2C_FUNC_SMBUS_I2C_BLOCK; | |
| 106 | + dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | | |
| 107 | + DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; | |
| 108 | + | |
| 109 | + dev->base = ioremap(mem->start, resource_size(mem)); | |
| 110 | + if (dev->base == NULL) { | |
| 111 | + dev_err(&pdev->dev, "failure mapping io resources\n"); | |
| 112 | + r = -EBUSY; | |
| 113 | + goto err_unuse_clocks; | |
| 114 | + } | |
| 115 | + { | |
| 116 | + u32 param1 = i2c_dw_read_comp_param(dev); | |
| 117 | + | |
| 118 | + dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; | |
| 119 | + dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; | |
| 120 | + } | |
| 121 | + r = i2c_dw_init(dev); | |
| 122 | + if (r) | |
| 123 | + goto err_iounmap; | |
| 124 | + | |
| 125 | + i2c_dw_disable_int(dev); | |
| 126 | + r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev); | |
| 127 | + if (r) { | |
| 128 | + dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | |
| 129 | + goto err_iounmap; | |
| 130 | + } | |
| 131 | + | |
| 132 | + adap = &dev->adapter; | |
| 133 | + i2c_set_adapdata(adap, dev); | |
| 134 | + adap->owner = THIS_MODULE; | |
| 135 | + adap->class = I2C_CLASS_HWMON; | |
| 136 | + strlcpy(adap->name, "Synopsys DesignWare I2C adapter", | |
| 137 | + sizeof(adap->name)); | |
| 138 | + adap->algo = &i2c_dw_algo; | |
| 139 | + adap->dev.parent = &pdev->dev; | |
| 140 | + | |
| 141 | + adap->nr = pdev->id; | |
| 142 | + r = i2c_add_numbered_adapter(adap); | |
| 143 | + if (r) { | |
| 144 | + dev_err(&pdev->dev, "failure adding adapter\n"); | |
| 145 | + goto err_free_irq; | |
| 146 | + } | |
| 147 | + | |
| 148 | + return 0; | |
| 149 | + | |
| 150 | +err_free_irq: | |
| 151 | + free_irq(dev->irq, dev); | |
| 152 | +err_iounmap: | |
| 153 | + iounmap(dev->base); | |
| 154 | +err_unuse_clocks: | |
| 155 | + clk_disable(dev->clk); | |
| 156 | + clk_put(dev->clk); | |
| 157 | + dev->clk = NULL; | |
| 158 | +err_free_mem: | |
| 159 | + platform_set_drvdata(pdev, NULL); | |
| 160 | + put_device(&pdev->dev); | |
| 161 | + kfree(dev); | |
| 162 | +err_release_region: | |
| 163 | + release_mem_region(mem->start, resource_size(mem)); | |
| 164 | + | |
| 165 | + return r; | |
| 166 | +} | |
| 167 | + | |
| 168 | +static int __devexit dw_i2c_remove(struct platform_device *pdev) | |
| 169 | +{ | |
| 170 | + struct dw_i2c_dev *dev = platform_get_drvdata(pdev); | |
| 171 | + struct resource *mem; | |
| 172 | + | |
| 173 | + platform_set_drvdata(pdev, NULL); | |
| 174 | + i2c_del_adapter(&dev->adapter); | |
| 175 | + put_device(&pdev->dev); | |
| 176 | + | |
| 177 | + clk_disable(dev->clk); | |
| 178 | + clk_put(dev->clk); | |
| 179 | + dev->clk = NULL; | |
| 180 | + | |
| 181 | + i2c_dw_disable(dev); | |
| 182 | + free_irq(dev->irq, dev); | |
| 183 | + kfree(dev); | |
| 184 | + | |
| 185 | + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
| 186 | + release_mem_region(mem->start, resource_size(mem)); | |
| 187 | + return 0; | |
| 188 | +} | |
| 189 | + | |
| 190 | +/* work with hotplug and coldplug */ | |
| 191 | +MODULE_ALIAS("platform:i2c_designware"); | |
| 192 | + | |
| 193 | +static struct platform_driver dw_i2c_driver = { | |
| 194 | + .remove = __devexit_p(dw_i2c_remove), | |
| 195 | + .driver = { | |
| 196 | + .name = "i2c_designware", | |
| 197 | + .owner = THIS_MODULE, | |
| 198 | + }, | |
| 199 | +}; | |
| 200 | + | |
| 201 | +static int __init dw_i2c_init_driver(void) | |
| 202 | +{ | |
| 203 | + return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe); | |
| 204 | +} | |
| 205 | +module_init(dw_i2c_init_driver); | |
| 206 | + | |
| 207 | +static void __exit dw_i2c_exit_driver(void) | |
| 208 | +{ | |
| 209 | + platform_driver_unregister(&dw_i2c_driver); | |
| 210 | +} | |
| 211 | +module_exit(dw_i2c_exit_driver); | |
| 212 | + | |
| 213 | +MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); | |
| 214 | +MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter"); | |
| 215 | +MODULE_LICENSE("GPL"); | |
| @@ -64,6 +64,7 @@ · 63 unmodified lines | ||
| 64 | 64 | #define TEN_BIT_ADDR_DEFAULT 0xF000 |
| 65 | 65 | #define TEN_BIT_ADDR_MASK 0xF0 |
| 66 | 66 | #define PCH_START 0x0020 |
| 67 | +#define PCH_RESTART 0x0004 | |
| 67 | 68 | #define PCH_ESR_START 0x0001 |
| 68 | 69 | #define PCH_BUFF_START 0x1 |
| 69 | 70 | #define PCH_REPSTART 0x0004 |
| @@ -273,23 +274,24 @@ static s32 pch_i2c_wait_for_bus_idle(struct i2c_algo_pch_data *adap, · 203 unmodified lines | ||
| 273 | 274 | s32 timeout) |
| 274 | 275 | { |
| 275 | 276 | void __iomem *p = adap->pch_base_address; |
| 277 | + ktime_t ns_val; | |
| 278 | + | |
| 279 | + if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0) | |
| 280 | + return 0; | |
| 276 | 281 | |
| 277 | 282 | /* MAX timeout value is timeout*1000*1000nsec */ |
| 278 | − ktime_t ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000); | |
| 283 | + ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000); | |
| 279 | 284 | do { |
| 280 | − if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0) | |
| 281 | − break; | |
| 282 | 285 | msleep(20); |
| 286 | + if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0) | |
| 287 | + return 0; | |
| 283 | 288 | } while (ktime_lt(ktime_get(), ns_val)); |
| 284 | 289 | |
| 285 | 290 | pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR)); |
| 291 | + pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME); | |
| 292 | + pch_i2c_init(adap); | |
| 286 | 293 | |
| 287 | − if (timeout == 0) { | |
| 288 | − pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME); | |
| 289 | − return -ETIME; | |
| 290 | − } | |
| 291 | − | |
| 292 | − return 0; | |
| 294 | + return -ETIME; | |
| 293 | 295 | } |
| 294 | 296 | |
| 295 | 297 | /** |
| @@ -311,21 +313,19 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap) · 15 unmodified lines | ||
| 311 | 313 | */ |
| 312 | 314 | static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap) |
| 313 | 315 | { |
| 314 | − s32 ret; | |
| 316 | + long ret; | |
| 315 | 317 | ret = wait_event_timeout(pch_event, |
| 316 | 318 | (adap->pch_event_flag != 0), msecs_to_jiffies(50)); |
| 317 | − if (ret < 0) { | |
| 318 | − pch_err(adap, "timeout: %x\n", adap->pch_event_flag); | |
| 319 | − return ret; | |
| 320 | − } | |
| 321 | 319 | |
| 322 | 320 | if (ret == 0) { |
| 323 | 321 | pch_err(adap, "timeout: %x\n", adap->pch_event_flag); |
| 322 | + adap->pch_event_flag = 0; | |
| 324 | 323 | return -ETIMEDOUT; |
| 325 | 324 | } |
| 326 | 325 | |
| 327 | 326 | if (adap->pch_event_flag & I2C_ERROR_MASK) { |
| 328 | 327 | pch_err(adap, "error bits set: %x\n", adap->pch_event_flag); |
| 328 | + adap->pch_event_flag = 0; | |
| 329 | 329 | return -EIO; |
| 330 | 330 | } |
| 331 | 331 | |
| @@ -394,6 +394,7 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, · 62 unmodified lines | ||
| 394 | 394 | u32 addr_2_msb; |
| 395 | 395 | u32 addr_8_lsb; |
| 396 | 396 | s32 wrcount; |
| 397 | + s32 rtn; | |
| 397 | 398 | void __iomem *p = adap->pch_base_address; |
| 398 | 399 | |
| 399 | 400 | length = msgs->len; |
| @@ -412,15 +413,29 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, · 12 unmodified lines | ||
| 412 | 413 | } |
| 413 | 414 | |
| 414 | 415 | if (msgs->flags & I2C_M_TEN) { |
| 415 | − addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7); | |
| 416 | + addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7) & 0x06; | |
| 416 | 417 | iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); |
| 417 | 418 | if (first) |
| 418 | 419 | pch_i2c_start(adap); |
| 419 | − if (pch_i2c_wait_for_xfer_complete(adap) == 0 && | |
| 420 | − pch_i2c_getack(adap) == 0) { | |
| 420 | + | |
| 421 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 422 | + if (rtn == 0) { | |
| 423 | + if (pch_i2c_getack(adap)) { | |
| 424 | + pch_dbg(adap, "Receive NACK for slave address" | |
| 425 | + "setting\n"); | |
| 426 | + return -EIO; | |
| 427 | + } | |
| 421 | 428 | addr_8_lsb = (addr & I2C_ADDR_MSK); |
| 422 | 429 | iowrite32(addr_8_lsb, p + PCH_I2CDR); |
| 423 | − } else { | |
| 430 | + } else if (rtn == -EIO) { /* Arbitration Lost */ | |
| 431 | + pch_err(adap, "Lost Arbitration\n"); | |
| 432 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 433 | + I2CMAL_BIT); | |
| 434 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 435 | + I2CMIF_BIT); | |
| 436 | + pch_i2c_init(adap); | |
| 437 | + return -EAGAIN; | |
| 438 | + } else { /* wait-event timeout */ | |
| 424 | 439 | pch_i2c_stop(adap); |
| 425 | 440 | return -ETIME; |
| 426 | 441 | } |
| @@ -431,30 +446,51 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, · 4 unmodified lines | ||
| 431 | 446 | pch_i2c_start(adap); |
| 432 | 447 | } |
| 433 | 448 | |
| 434 | − if ((pch_i2c_wait_for_xfer_complete(adap) == 0) && | |
| 435 | − (pch_i2c_getack(adap) == 0)) { | |
| 436 | − for (wrcount = 0; wrcount < length; ++wrcount) { | |
| 437 | − /* write buffer value to I2C data register */ | |
| 438 | − iowrite32(buf[wrcount], p + PCH_I2CDR); | |
| 439 | − pch_dbg(adap, "writing %x to Data register\n", | |
| 440 | − buf[wrcount]); | |
| 449 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 450 | + if (rtn == 0) { | |
| 451 | + if (pch_i2c_getack(adap)) { | |
| 452 | + pch_dbg(adap, "Receive NACK for slave address" | |
| 453 | + "setting\n"); | |
| 454 | + return -EIO; | |
| 455 | + } | |
| 456 | + } else if (rtn == -EIO) { /* Arbitration Lost */ | |
| 457 | + pch_err(adap, "Lost Arbitration\n"); | |
| 458 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT); | |
| 459 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT); | |
| 460 | + pch_i2c_init(adap); | |
| 461 | + return -EAGAIN; | |
| 462 | + } else { /* wait-event timeout */ | |
| 463 | + pch_i2c_stop(adap); | |
| 464 | + return -ETIME; | |
| 465 | + } | |
| 441 | 466 | |
| 442 | − if (pch_i2c_wait_for_xfer_complete(adap) != 0) | |
| 443 | − return -ETIME; | |
| 467 | + for (wrcount = 0; wrcount < length; ++wrcount) { | |
| 468 | + /* write buffer value to I2C data register */ | |
| 469 | + iowrite32(buf[wrcount], p + PCH_I2CDR); | |
| 470 | + pch_dbg(adap, "writing %x to Data register\n", buf[wrcount]); | |
| 444 | 471 | |
| 445 | − if (pch_i2c_getack(adap)) | |
| 472 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 473 | + if (rtn == 0) { | |
| 474 | + if (pch_i2c_getack(adap)) { | |
| 475 | + pch_dbg(adap, "Receive NACK for slave address" | |
| 476 | + "setting\n"); | |
| 446 | 477 | return -EIO; |
| 478 | + } | |
| 479 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 480 | + I2CMCF_BIT); | |
| 481 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 482 | + I2CMIF_BIT); | |
| 483 | + } else { /* wait-event timeout */ | |
| 484 | + pch_i2c_stop(adap); | |
| 485 | + return -ETIME; | |
| 447 | 486 | } |
| 487 | + } | |
| 448 | 488 | |
| 449 | − /* check if this is the last message */ | |
| 450 | − if (last) | |
| 451 | − pch_i2c_stop(adap); | |
| 452 | − else | |
| 453 | − pch_i2c_repstart(adap); | |
| 454 | − } else { | |
| 489 | + /* check if this is the last message */ | |
| 490 | + if (last) | |
| 455 | 491 | pch_i2c_stop(adap); |
| 456 | − return -EIO; | |
| 457 | − } | |
| 492 | + else | |
| 493 | + pch_i2c_repstart(adap); | |
| 458 | 494 | |
| 459 | 495 | pch_dbg(adap, "return=%d\n", wrcount); |
| 460 | 496 | |
| @@ -483,6 +519,19 @@ static void pch_i2c_sendnack(struct i2c_algo_pch_data *adap) · 22 unmodified lines | ||
| 483 | 519 | pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_ACK); |
| 484 | 520 | } |
| 485 | 521 | |
| 522 | +/** | |
| 523 | + * pch_i2c_restart() - Generate I2C restart condition in normal mode. | |
| 524 | + * @adap: Pointer to struct i2c_algo_pch_data. | |
| 525 | + * | |
| 526 | + * Generate I2C restart condition in normal mode by setting I2CCTL.I2CRSTA. | |
| 527 | + */ | |
| 528 | +static void pch_i2c_restart(struct i2c_algo_pch_data *adap) | |
| 529 | +{ | |
| 530 | + void __iomem *p = adap->pch_base_address; | |
| 531 | + pch_dbg(adap, "I2CCTL = %x\n", ioread32(p + PCH_I2CCTL)); | |
| 532 | + pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_RESTART); | |
| 533 | +} | |
| 534 | + | |
| 486 | 535 | /** |
| 487 | 536 | * pch_i2c_readbytes() - read data from I2C bus in normal mode. |
| 488 | 537 | * @i2c_adap: Pointer to the struct i2c_adapter. |
| @@ -500,7 +549,9 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, · 11 unmodified lines | ||
| 500 | 549 | u32 length; |
| 501 | 550 | u32 addr; |
| 502 | 551 | u32 addr_2_msb; |
| 552 | + u32 addr_8_lsb; | |
| 503 | 553 | void __iomem *p = adap->pch_base_address; |
| 554 | + s32 rtn; | |
| 504 | 555 | |
| 505 | 556 | length = msgs->len; |
| 506 | 557 | buf = msgs->buf; |
| @@ -515,9 +566,55 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, · 8 unmodified lines | ||
| 515 | 566 | } |
| 516 | 567 | |
| 517 | 568 | if (msgs->flags & I2C_M_TEN) { |
| 518 | − addr_2_msb = (((addr & I2C_MSB_2B_MSK) >> 7) | (I2C_RD)); | |
| 569 | + addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7); | |
| 519 | 570 | iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); |
| 571 | + if (first) | |
| 572 | + pch_i2c_start(adap); | |
| 520 | 573 | |
| 574 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 575 | + if (rtn == 0) { | |
| 576 | + if (pch_i2c_getack(adap)) { | |
| 577 | + pch_dbg(adap, "Receive NACK for slave address" | |
| 578 | + "setting\n"); | |
| 579 | + return -EIO; | |
| 580 | + } | |
| 581 | + addr_8_lsb = (addr & I2C_ADDR_MSK); | |
| 582 | + iowrite32(addr_8_lsb, p + PCH_I2CDR); | |
| 583 | + } else if (rtn == -EIO) { /* Arbitration Lost */ | |
| 584 | + pch_err(adap, "Lost Arbitration\n"); | |
| 585 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 586 | + I2CMAL_BIT); | |
| 587 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 588 | + I2CMIF_BIT); | |
| 589 | + pch_i2c_init(adap); | |
| 590 | + return -EAGAIN; | |
| 591 | + } else { /* wait-event timeout */ | |
| 592 | + pch_i2c_stop(adap); | |
| 593 | + return -ETIME; | |
| 594 | + } | |
| 595 | + pch_i2c_restart(adap); | |
| 596 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 597 | + if (rtn == 0) { | |
| 598 | + if (pch_i2c_getack(adap)) { | |
| 599 | + pch_dbg(adap, "Receive NACK for slave address" | |
| 600 | + "setting\n"); | |
| 601 | + return -EIO; | |
| 602 | + } | |
| 603 | + addr_2_msb |= I2C_RD; | |
| 604 | + iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, | |
| 605 | + p + PCH_I2CDR); | |
| 606 | + } else if (rtn == -EIO) { /* Arbitration Lost */ | |
| 607 | + pch_err(adap, "Lost Arbitration\n"); | |
| 608 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 609 | + I2CMAL_BIT); | |
| 610 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, | |
| 611 | + I2CMIF_BIT); | |
| 612 | + pch_i2c_init(adap); | |
| 613 | + return -EAGAIN; | |
| 614 | + } else { /* wait-event timeout */ | |
| 615 | + pch_i2c_stop(adap); | |
| 616 | + return -ETIME; | |
| 617 | + } | |
| 521 | 618 | } else { |
| 522 | 619 | /* 7 address bits + R/W bit */ |
| 523 | 620 | addr = (((addr) << 1) | (I2C_RD)); |
| @@ -528,56 +625,81 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, · 4 unmodified lines | ||
| 528 | 625 | if (first) |
| 529 | 626 | pch_i2c_start(adap); |
| 530 | 627 | |
| 531 | − if ((pch_i2c_wait_for_xfer_complete(adap) == 0) && | |
| 532 | − (pch_i2c_getack(adap) == 0)) { | |
| 533 | − pch_dbg(adap, "return %d\n", 0); | |
| 628 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 629 | + if (rtn == 0) { | |
| 630 | + if (pch_i2c_getack(adap)) { | |
| 631 | + pch_dbg(adap, "Receive NACK for slave address" | |
| 632 | + "setting\n"); | |
| 633 | + return -EIO; | |
| 634 | + } | |
| 635 | + } else if (rtn == -EIO) { /* Arbitration Lost */ | |
| 636 | + pch_err(adap, "Lost Arbitration\n"); | |
| 637 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT); | |
| 638 | + pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT); | |
| 639 | + pch_i2c_init(adap); | |
| 640 | + return -EAGAIN; | |
| 641 | + } else { /* wait-event timeout */ | |
| 642 | + pch_i2c_stop(adap); | |
| 643 | + return -ETIME; | |
| 644 | + } | |
| 534 | 645 | |
| 535 | − if (length == 0) { | |
| 536 | − pch_i2c_stop(adap); | |
| 537 | − ioread32(p + PCH_I2CDR); /* Dummy read needs */ | |
| 646 | + if (length == 0) { | |
| 647 | + pch_i2c_stop(adap); | |
| 648 | + ioread32(p + PCH_I2CDR); /* Dummy read needs */ | |
| 538 | 649 | |
| 539 | − count = length; | |
| 540 | − } else { | |
| 541 | − int read_index; | |
| 542 | − int loop; | |
| 543 | − pch_i2c_sendack(adap); | |
| 650 | + count = length; | |
| 651 | + } else { | |
| 652 | + int read_index; | |
| 653 | + int loop; | |
| 654 | + pch_i2c_sendack(adap); | |
| 544 | 655 | |
| 545 | − /* Dummy read */ | |
| 546 | − for (loop = 1, read_index = 0; loop < length; loop++) { | |
| 547 | − buf[read_index] = ioread32(p + PCH_I2CDR); | |
| 656 | + /* Dummy read */ | |
| 657 | + for (loop = 1, read_index = 0; loop < length; loop++) { | |
| 658 | + buf[read_index] = ioread32(p + PCH_I2CDR); | |
| 548 | 659 | |
| 549 | − if (loop != 1) | |
| 550 | − read_index++; | |
| 660 | + if (loop != 1) | |
| 661 | + read_index++; | |
| 551 | 662 | |
| 552 | − if (pch_i2c_wait_for_xfer_complete(adap) != 0) { | |
| 553 | − pch_i2c_stop(adap); | |
| 554 | − return -ETIME; | |
| 663 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 664 | + if (rtn == 0) { | |
| 665 | + if (pch_i2c_getack(adap)) { | |
| 666 | + pch_dbg(adap, "Receive NACK for slave" | |
| 667 | + "address setting\n"); | |
| 668 | + return -EIO; | |
| 555 | 669 | } |
| 556 | − } /* end for */ | |
| 670 | + } else { /* wait-event timeout */ | |
| 671 | + pch_i2c_stop(adap); | |
| 672 | + return -ETIME; | |
| 673 | + } | |
| 557 | 674 | |
| 558 | − pch_i2c_sendnack(adap); | |
| 675 | + } /* end for */ | |
| 559 | 676 | |
| 560 | − buf[read_index] = ioread32(p + PCH_I2CDR); | |
| 677 | + pch_i2c_sendnack(adap); | |
| 561 | 678 | |
| 562 | − if (length != 1) | |
| 563 | − read_index++; | |
| 679 | + buf[read_index] = ioread32(p + PCH_I2CDR); /* Read final - 1 */ | |
| 564 | 680 | |
| 565 | − if (pch_i2c_wait_for_xfer_complete(adap) == 0) { | |
| 566 | − if (last) | |
| 567 | − pch_i2c_stop(adap); | |
| 568 | − else | |
| 569 | − pch_i2c_repstart(adap); | |
| 681 | + if (length != 1) | |
| 682 | + read_index++; | |
| 570 | 683 | |
| 571 | − buf[read_index++] = ioread32(p + PCH_I2CDR); | |
| 572 | − count = read_index; | |
| 573 | − } else { | |
| 574 | − count = -ETIME; | |
| 684 | + rtn = pch_i2c_wait_for_xfer_complete(adap); | |
| 685 | + if (rtn == 0) { | |
| 686 | + if (pch_i2c_getack(adap)) { | |
| 687 | + pch_dbg(adap, "Receive NACK for slave" | |
| 688 | + "address setting\n"); | |
| 689 | + return -EIO; | |
| 575 | 690 | } |
| 576 | − | |
| 691 | + } else { /* wait-event timeout */ | |
| 692 | + pch_i2c_stop(adap); | |
| 693 | + return -ETIME; | |
| 577 | 694 | } |
| 578 | − } else { | |
| 579 | − count = -ETIME; | |
| 580 | − pch_i2c_stop(adap); | |
| 695 | + | |
| 696 | + if (last) | |
| 697 | + pch_i2c_stop(adap); | |
| 698 | + else | |
| 699 | + pch_i2c_repstart(adap); | |
| 700 | + | |
| 701 | + buf[read_index++] = ioread32(p + PCH_I2CDR); /* Read Final */ | |
| 702 | + count = read_index; | |
| 581 | 703 | } |
| 582 | 704 | |
| 583 | 705 | return count; |
| @@ -387,7 +387,7 @@ static int __devinit highlander_i2c_probe(struct platform_device *pdev) · 386 unmodified lines | ||
| 387 | 387 | dev->irq = 0; |
| 388 | 388 | |
| 389 | 389 | if (dev->irq) { |
| 390 | − ret = request_irq(dev->irq, highlander_i2c_irq, IRQF_DISABLED, | |
| 390 | + ret = request_irq(dev->irq, highlander_i2c_irq, 0, | |
| 391 | 391 | pdev->name, dev); |
| 392 | 392 | if (unlikely(ret)) |
| 393 | 393 | goto err_unmap; |
| @@ -48,6 +48,9 @@ · 47 unmodified lines | ||
| 48 | 48 | #include <linux/platform_device.h> |
| 49 | 49 | #include <linux/clk.h> |
| 50 | 50 | #include <linux/slab.h> |
| 51 | +#include <linux/of.h> | |
| 52 | +#include <linux/of_device.h> | |
| 53 | +#include <linux/of_i2c.h> | |
| 51 | 54 | |
| 52 | 55 | #include <mach/irqs.h> |
| 53 | 56 | #include <mach/hardware.h> |
| @@ -125,6 +128,11 @@ struct imx_i2c_struct { · 71 unmodified lines | ||
| 125 | 128 | unsigned int ifdr; /* IMX_I2C_IFDR */ |
| 126 | 129 | }; |
| 127 | 130 | |
| 131 | +static const struct of_device_id i2c_imx_dt_ids[] = { | |
| 132 | + { .compatible = "fsl,imx1-i2c", }, | |
| 133 | + { /* sentinel */ } | |
| 134 | +}; | |
| 135 | + | |
| 128 | 136 | /** Functions for IMX I2C adapter driver *************************************** |
| 129 | 137 | *******************************************************************************/ |
| 130 | 138 | |
| @@ -466,10 +474,10 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 335 unmodified lines | ||
| 466 | 474 | { |
| 467 | 475 | struct imx_i2c_struct *i2c_imx; |
| 468 | 476 | struct resource *res; |
| 469 | − struct imxi2c_platform_data *pdata; | |
| 477 | + struct imxi2c_platform_data *pdata = pdev->dev.platform_data; | |
| 470 | 478 | void __iomem *base; |
| 471 | 479 | resource_size_t res_size; |
| 472 | − int irq; | |
| 480 | + int irq, bitrate; | |
| 473 | 481 | int ret; |
| 474 | 482 | |
| 475 | 483 | dev_dbg(&pdev->dev, "<%s>\n", __func__); |
| @@ -485,19 +493,11 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 9 unmodified lines | ||
| 485 | 493 | return -ENOENT; |
| 486 | 494 | } |
| 487 | 495 | |
| 488 | − pdata = pdev->dev.platform_data; | |
| 489 | − | |
| 490 | − if (pdata && pdata->init) { | |
| 491 | − ret = pdata->init(&pdev->dev); | |
| 492 | − if (ret) | |
| 493 | − return ret; | |
| 494 | − } | |
| 495 | − | |
| 496 | 496 | res_size = resource_size(res); |
| 497 | 497 | |
| 498 | 498 | if (!request_mem_region(res->start, res_size, DRIVER_NAME)) { |
| 499 | − ret = -EBUSY; | |
| 500 | − goto fail0; | |
| 499 | + dev_err(&pdev->dev, "request_mem_region failed\n"); | |
| 500 | + return -EBUSY; | |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | base = ioremap(res->start, res_size); |
| @@ -520,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 16 unmodified lines | ||
| 520 | 520 | i2c_imx->adapter.algo = &i2c_imx_algo; |
| 521 | 521 | i2c_imx->adapter.dev.parent = &pdev->dev; |
| 522 | 522 | i2c_imx->adapter.nr = pdev->id; |
| 523 | + i2c_imx->adapter.dev.of_node = pdev->dev.of_node; | |
| 523 | 524 | i2c_imx->irq = irq; |
| 524 | 525 | i2c_imx->base = base; |
| 525 | 526 | i2c_imx->res = res; |
| @@ -546,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 20 unmodified lines | ||
| 546 | 547 | i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); |
| 547 | 548 | |
| 548 | 549 | /* Set up clock divider */ |
| 549 | − if (pdata && pdata->bitrate) | |
| 550 | − i2c_imx_set_clk(i2c_imx, pdata->bitrate); | |
| 551 | − else | |
| 552 | − i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE); | |
| 550 | + bitrate = IMX_I2C_BIT_RATE; | |
| 551 | + ret = of_property_read_u32(pdev->dev.of_node, | |
| 552 | + "clock-frequency", &bitrate); | |
| 553 | + if (ret < 0 && pdata && pdata->bitrate) | |
| 554 | + bitrate = pdata->bitrate; | |
| 555 | + i2c_imx_set_clk(i2c_imx, bitrate); | |
| 553 | 556 | |
| 554 | 557 | /* Set up chip registers to defaults */ |
| 555 | 558 | writeb(0, i2c_imx->base + IMX_I2C_I2CR); |
| @@ -562,6 +565,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 6 unmodified lines | ||
| 562 | 565 | goto fail5; |
| 563 | 566 | } |
| 564 | 567 | |
| 568 | + of_i2c_register_devices(&i2c_imx->adapter); | |
| 569 | + | |
| 565 | 570 | /* Set up platform driver data */ |
| 566 | 571 | platform_set_drvdata(pdev, i2c_imx); |
| 567 | 572 | |
| @@ -586,16 +591,12 @@ fail2: · 18 unmodified lines | ||
| 586 | 591 | iounmap(base); |
| 587 | 592 | fail1: |
| 588 | 593 | release_mem_region(res->start, resource_size(res)); |
| 589 | −fail0: | |
| 590 | − if (pdata && pdata->exit) | |
| 591 | − pdata->exit(&pdev->dev); | |
| 592 | 594 | return ret; /* Return error number */ |
| 593 | 595 | } |
| 594 | 596 | |
| 595 | 597 | static int __exit i2c_imx_remove(struct platform_device *pdev) |
| 596 | 598 | { |
| 597 | 599 | struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); |
| 598 | − struct imxi2c_platform_data *pdata = pdev->dev.platform_data; | |
| 599 | 600 | |
| 600 | 601 | /* remove adapter */ |
| 601 | 602 | dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); |
| @@ -611,10 +612,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev) · 9 unmodified lines | ||
| 611 | 612 | writeb(0, i2c_imx->base + IMX_I2C_I2CR); |
| 612 | 613 | writeb(0, i2c_imx->base + IMX_I2C_I2SR); |
| 613 | 614 | |
| 614 | − /* Shut down hardware */ | |
| 615 | − if (pdata && pdata->exit) | |
| 616 | − pdata->exit(&pdev->dev); | |
| 617 | − | |
| 618 | 615 | clk_put(i2c_imx->clk); |
| 619 | 616 | |
| 620 | 617 | iounmap(i2c_imx->base); |
| @@ -628,6 +625,7 @@ static struct platform_driver i2c_imx_driver = { · 7 unmodified lines | ||
| 628 | 625 | .driver = { |
| 629 | 626 | .name = DRIVER_NAME, |
| 630 | 627 | .owner = THIS_MODULE, |
| 628 | + .of_match_table = i2c_imx_dt_ids, | |
| 631 | 629 | } |
| 632 | 630 | }; |
| 633 | 631 | |
| @@ -63,11 +63,11 @@ · 62 unmodified lines | ||
| 63 | 63 | /* Master controller (MCR) register */ |
| 64 | 64 | #define I2C_MCR_OP (0x1 << 0) /* Operation */ |
| 65 | 65 | #define I2C_MCR_A7 (0x7f << 1) /* 7-bit address */ |
| 66 | −#define I2C_MCR_EA10 (0x7 << 8) /* 10-bit Extended address */ | |
| 66 | +#define I2C_MCR_EA10 (0x7 << 8) /* 10-bit Extended address */ | |
| 67 | 67 | #define I2C_MCR_SB (0x1 << 11) /* Extended address */ |
| 68 | 68 | #define I2C_MCR_AM (0x3 << 12) /* Address type */ |
| 69 | −#define I2C_MCR_STOP (0x1 << 14) /* Stop condition */ | |
| 70 | −#define I2C_MCR_LENGTH (0x7ff << 15) /* Transaction length */ | |
| 69 | +#define I2C_MCR_STOP (0x1 << 14) /* Stop condition */ | |
| 70 | +#define I2C_MCR_LENGTH (0x7ff << 15) /* Transaction length */ | |
| 71 | 71 | |
| 72 | 72 | /* Status register (SR) */ |
| 73 | 73 | #define I2C_SR_OP (0x3 << 0) /* Operation */ |
| @@ -77,7 +77,7 @@ · 3 unmodified lines | ||
| 77 | 77 | #define I2C_SR_LENGTH (0x7ff << 9) /* Transfer length */ |
| 78 | 78 | |
| 79 | 79 | /* Interrupt mask set/clear (IMSCR) bits */ |
| 80 | −#define I2C_IT_TXFE (0x1 << 0) | |
| 80 | +#define I2C_IT_TXFE (0x1 << 0) | |
| 81 | 81 | #define I2C_IT_TXFNE (0x1 << 1) |
| 82 | 82 | #define I2C_IT_TXFF (0x1 << 2) |
| 83 | 83 | #define I2C_IT_TXFOVR (0x1 << 3) |
| @@ -135,31 +135,31 @@ struct i2c_nmk_client { · 51 unmodified lines | ||
| 135 | 135 | }; |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | − * struct nmk_i2c_dev - private data structure of the controller | |
| 139 | − * @pdev: parent platform device | |
| 140 | − * @adap: corresponding I2C adapter | |
| 141 | − * @irq: interrupt line for the controller | |
| 142 | − * @virtbase: virtual io memory area | |
| 143 | − * @clk: hardware i2c block clock | |
| 144 | − * @cfg: machine provided controller configuration | |
| 145 | − * @cli: holder of client specific data | |
| 146 | − * @stop: stop condition | |
| 147 | − * @xfer_complete: acknowledge completion for a I2C message | |
| 148 | − * @result: controller propogated result | |
| 149 | − * @regulator: pointer to i2c regulator | |
| 150 | − * @busy: Busy doing transfer | |
| 138 | + * struct nmk_i2c_dev - private data structure of the controller. | |
| 139 | + * @pdev: parent platform device. | |
| 140 | + * @adap: corresponding I2C adapter. | |
| 141 | + * @irq: interrupt line for the controller. | |
| 142 | + * @virtbase: virtual io memory area. | |
| 143 | + * @clk: hardware i2c block clock. | |
| 144 | + * @cfg: machine provided controller configuration. | |
| 145 | + * @cli: holder of client specific data. | |
| 146 | + * @stop: stop condition. | |
| 147 | + * @xfer_complete: acknowledge completion for a I2C message. | |
| 148 | + * @result: controller propogated result. | |
| 149 | + * @regulator: pointer to i2c regulator. | |
| 150 | + * @busy: Busy doing transfer. | |
| 151 | 151 | */ |
| 152 | 152 | struct nmk_i2c_dev { |
| 153 | 153 | struct platform_device *pdev; |
| 154 | − struct i2c_adapter adap; | |
| 155 | − int irq; | |
| 154 | + struct i2c_adapter adap; | |
| 155 | + int irq; | |
| 156 | 156 | void __iomem *virtbase; |
| 157 | 157 | struct clk *clk; |
| 158 | 158 | struct nmk_i2c_controller cfg; |
| 159 | 159 | struct i2c_nmk_client cli; |
| 160 | − int stop; | |
| 160 | + int stop; | |
| 161 | 161 | struct completion xfer_complete; |
| 162 | − int result; | |
| 162 | + int result; | |
| 163 | 163 | struct regulator *regulator; |
| 164 | 164 | bool busy; |
| 165 | 165 | }; |
| @@ -217,8 +217,9 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev) · 51 unmodified lines | ||
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | − dev_err(&dev->pdev->dev, "flushing operation timed out " | |
| 221 | − "giving up after %d attempts", LOOP_ATTEMPTS); | |
| 220 | + dev_err(&dev->pdev->dev, | |
| 221 | + "flushing operation timed out giving up after %d attempts", | |
| 222 | + LOOP_ATTEMPTS); | |
| 222 | 223 | |
| 223 | 224 | return -ETIMEDOUT; |
| 224 | 225 | } |
| @@ -270,7 +271,7 @@ exit: · 45 unmodified lines | ||
| 270 | 271 | } |
| 271 | 272 | |
| 272 | 273 | /* enable peripheral, master mode operation */ |
| 273 | −#define DEFAULT_I2C_REG_CR ((1 << 1) | I2C_CR_PE) | |
| 274 | +#define DEFAULT_I2C_REG_CR ((1 << 1) | I2C_CR_PE) | |
| 274 | 275 | |
| 275 | 276 | /** |
| 276 | 277 | * load_i2c_mcr_reg() - load the MCR register |
| @@ -363,8 +364,8 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev) · 86 unmodified lines | ||
| 363 | 364 | * and high speed (up to 3.4 Mb/s) |
| 364 | 365 | */ |
| 365 | 366 | if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { |
| 366 | − dev_err(&dev->pdev->dev, "do not support this mode " | |
| 367 | − "defaulting to std. mode\n"); | |
| 367 | + dev_err(&dev->pdev->dev, | |
| 368 | + "do not support this mode defaulting to std. mode\n"); | |
| 368 | 369 | brcr2 = i2c_clk/(100000 * 2) & 0xffff; |
| 369 | 370 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); |
| 370 | 371 | writel(I2C_FREQ_MODE_STANDARD << 4, |
| @@ -423,7 +424,7 @@ static int read_i2c(struct nmk_i2c_dev *dev) · 52 unmodified lines | ||
| 423 | 424 | |
| 424 | 425 | if (timeout < 0) { |
| 425 | 426 | dev_err(&dev->pdev->dev, |
| 426 | − "wait_for_completion_timeout" | |
| 427 | + "wait_for_completion_timeout " | |
| 427 | 428 | "returned %d waiting for event\n", timeout); |
| 428 | 429 | status = timeout; |
| 429 | 430 | } |
| @@ -556,8 +557,8 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) · 126 unmodified lines | ||
| 556 | 557 | if (((i2c_sr >> 2) & 0x3) == 0x3) { |
| 557 | 558 | /* get the abort cause */ |
| 558 | 559 | cause = (i2c_sr >> 4) & 0x7; |
| 559 | − dev_err(&dev->pdev->dev, "%s\n", cause | |
| 560 | − >= ARRAY_SIZE(abort_causes) ? | |
| 560 | + dev_err(&dev->pdev->dev, "%s\n", | |
| 561 | + cause >= ARRAY_SIZE(abort_causes) ? | |
| 561 | 562 | "unknown reason" : |
| 562 | 563 | abort_causes[cause]); |
| 563 | 564 | } |
| @@ -582,13 +583,13 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) · 18 unmodified lines | ||
| 582 | 583 | * |
| 583 | 584 | * NOTE: |
| 584 | 585 | * READ TRANSFER : We impose a restriction of the first message to be the |
| 585 | − * index message for any read transaction. | |
| 586 | − * - a no index is coded as '0', | |
| 587 | − * - 2byte big endian index is coded as '3' | |
| 588 | − * !!! msg[0].buf holds the actual index. | |
| 589 | − * This is compatible with generic messages of smbus emulator | |
| 590 | − * that send a one byte index. | |
| 591 | − * eg. a I2C transation to read 2 bytes from index 0 | |
| 586 | + * index message for any read transaction. | |
| 587 | + * - a no index is coded as '0', | |
| 588 | + * - 2byte big endian index is coded as '3' | |
| 589 | + * !!! msg[0].buf holds the actual index. | |
| 590 | + * This is compatible with generic messages of smbus emulator | |
| 591 | + * that send a one byte index. | |
| 592 | + * eg. a I2C transation to read 2 bytes from index 0 | |
| 592 | 593 | * idx = 0; |
| 593 | 594 | * msg[0].addr = client->addr; |
| 594 | 595 | * msg[0].flags = 0x0; |
| @@ -644,8 +645,8 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, · 49 unmodified lines | ||
| 644 | 645 | |
| 645 | 646 | for (i = 0; i < num_msgs; i++) { |
| 646 | 647 | if (unlikely(msgs[i].flags & I2C_M_TEN)) { |
| 647 | − dev_err(&dev->pdev->dev, "10 bit addressing" | |
| 648 | − "not supported\n"); | |
| 648 | + dev_err(&dev->pdev->dev, | |
| 649 | + "10 bit addressing not supported\n"); | |
| 649 | 650 | |
| 650 | 651 | status = -EINVAL; |
| 651 | 652 | goto out; |
| @@ -789,8 +790,9 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) · 137 unmodified lines | ||
| 789 | 790 | |
| 790 | 791 | if (dev->cli.count) { |
| 791 | 792 | dev->result = -EIO; |
| 792 | − dev_err(&dev->pdev->dev, "%lu bytes still remain to be" | |
| 793 | − "xfered\n", dev->cli.count); | |
| 793 | + dev_err(&dev->pdev->dev, | |
| 794 | + "%lu bytes still remain to be xfered\n", | |
| 795 | + dev->cli.count); | |
| 794 | 796 | (void) init_hw(dev); |
| 795 | 797 | } |
| 796 | 798 | complete(&dev->xfer_complete); |
| @@ -923,7 +925,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) · 126 unmodified lines | ||
| 923 | 925 | } |
| 924 | 926 | |
| 925 | 927 | if (request_mem_region(res->start, resource_size(res), |
| 926 | − DRIVER_NAME "I/O region") == NULL) { | |
| 928 | + DRIVER_NAME "I/O region") == NULL) { | |
| 927 | 929 | ret = -EBUSY; |
| 928 | 930 | goto err_no_region; |
| 929 | 931 | } |
| @@ -935,7 +937,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) · 5 unmodified lines | ||
| 935 | 937 | } |
| 936 | 938 | |
| 937 | 939 | dev->irq = platform_get_irq(pdev, 0); |
| 938 | − ret = request_irq(dev->irq, i2c_irq_handler, IRQF_DISABLED, | |
| 940 | + ret = request_irq(dev->irq, i2c_irq_handler, 0, | |
| 939 | 941 | DRIVER_NAME, dev); |
| 940 | 942 | if (ret) { |
| 941 | 943 | dev_err(&pdev->dev, "cannot claim the irq %d\n", dev->irq); |
| @@ -980,8 +982,9 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) · 38 unmodified lines | ||
| 980 | 982 | |
| 981 | 983 | i2c_set_adapdata(adap, dev); |
| 982 | 984 | |
| 983 | − dev_info(&pdev->dev, "initialize %s on virtual " | |
| 984 | − "base %p\n", adap->name, dev->virtbase); | |
| 985 | + dev_info(&pdev->dev, | |
| 986 | + "initialize %s on virtual base %p\n", | |
| 987 | + adap->name, dev->virtbase); | |
| 985 | 988 | |
| 986 | 989 | ret = i2c_add_numbered_adapter(adap); |
| 987 | 990 | if (ret) { |
| @@ -610,7 +610,7 @@ static int __devinit nuc900_i2c_probe(struct platform_device *pdev) · 609 unmodified lines | ||
| 610 | 610 | goto err_iomap; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | − ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_DISABLED | IRQF_SHARED, | |
| 613 | + ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_SHARED, | |
| 614 | 614 | dev_name(&pdev->dev), i2c); |
| 615 | 615 | |
| 616 | 616 | if (ret != 0) { |
| @@ -42,12 +42,12 @@ · 41 unmodified lines | ||
| 42 | 42 | #include <linux/pm_runtime.h> |
| 43 | 43 | |
| 44 | 44 | /* I2C controller revisions */ |
| 45 | −#define OMAP_I2C_REV_2 0x20 | |
| 45 | +#define OMAP_I2C_OMAP1_REV_2 0x20 | |
| 46 | 46 | |
| 47 | 47 | /* I2C controller revisions present on specific hardware */ |
| 48 | 48 | #define OMAP_I2C_REV_ON_2430 0x36 |
| 49 | 49 | #define OMAP_I2C_REV_ON_3430 0x3C |
| 50 | −#define OMAP_I2C_REV_ON_4430 0x40 | |
| 50 | +#define OMAP_I2C_REV_ON_3530_4430 0x40 | |
| 51 | 51 | |
| 52 | 52 | /* timeout waiting for the controller to respond */ |
| 53 | 53 | #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) |
| @@ -72,11 +72,12 @@ enum { · 18 unmodified lines | ||
| 72 | 72 | OMAP_I2C_SCLH_REG, |
| 73 | 73 | OMAP_I2C_SYSTEST_REG, |
| 74 | 74 | OMAP_I2C_BUFSTAT_REG, |
| 75 | − OMAP_I2C_REVNB_LO, | |
| 76 | − OMAP_I2C_REVNB_HI, | |
| 77 | − OMAP_I2C_IRQSTATUS_RAW, | |
| 78 | − OMAP_I2C_IRQENABLE_SET, | |
| 79 | − OMAP_I2C_IRQENABLE_CLR, | |
| 75 | + /* only on OMAP4430 */ | |
| 76 | + OMAP_I2C_IP_V2_REVNB_LO, | |
| 77 | + OMAP_I2C_IP_V2_REVNB_HI, | |
| 78 | + OMAP_I2C_IP_V2_IRQSTATUS_RAW, | |
| 79 | + OMAP_I2C_IP_V2_IRQENABLE_SET, | |
| 80 | + OMAP_I2C_IP_V2_IRQENABLE_CLR, | |
| 80 | 81 | }; |
| 81 | 82 | |
| 82 | 83 | /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ |
| @@ -193,7 +194,6 @@ struct omap_i2c_dev { · 110 unmodified lines | ||
| 193 | 194 | */ |
| 194 | 195 | u8 rev; |
| 195 | 196 | unsigned b_hw:1; /* bad h/w fixes */ |
| 196 | − unsigned idle:1; | |
| 197 | 197 | u16 iestate; /* Saved interrupt register */ |
| 198 | 198 | u16 pscstate; |
| 199 | 199 | u16 scllstate; |
| @@ -204,7 +204,7 @@ struct omap_i2c_dev { · 4 unmodified lines | ||
| 204 | 204 | u16 errata; |
| 205 | 205 | }; |
| 206 | 206 | |
| 207 | −static const u8 reg_map[] = { | |
| 207 | +static const u8 reg_map_ip_v1[] = { | |
| 208 | 208 | [OMAP_I2C_REV_REG] = 0x00, |
| 209 | 209 | [OMAP_I2C_IE_REG] = 0x01, |
| 210 | 210 | [OMAP_I2C_STAT_REG] = 0x02, |
| @@ -225,7 +225,7 @@ static const u8 reg_map[] = { · 14 unmodified lines | ||
| 225 | 225 | [OMAP_I2C_BUFSTAT_REG] = 0x10, |
| 226 | 226 | }; |
| 227 | 227 | |
| 228 | −static const u8 omap4_reg_map[] = { | |
| 228 | +static const u8 reg_map_ip_v2[] = { | |
| 229 | 229 | [OMAP_I2C_REV_REG] = 0x04, |
| 230 | 230 | [OMAP_I2C_IE_REG] = 0x2c, |
| 231 | 231 | [OMAP_I2C_STAT_REG] = 0x28, |
| @@ -244,11 +244,11 @@ static const u8 omap4_reg_map[] = { · 12 unmodified lines | ||
| 244 | 244 | [OMAP_I2C_SCLH_REG] = 0xb8, |
| 245 | 245 | [OMAP_I2C_SYSTEST_REG] = 0xbC, |
| 246 | 246 | [OMAP_I2C_BUFSTAT_REG] = 0xc0, |
| 247 | − [OMAP_I2C_REVNB_LO] = 0x00, | |
| 248 | − [OMAP_I2C_REVNB_HI] = 0x04, | |
| 249 | − [OMAP_I2C_IRQSTATUS_RAW] = 0x24, | |
| 250 | − [OMAP_I2C_IRQENABLE_SET] = 0x2c, | |
| 251 | − [OMAP_I2C_IRQENABLE_CLR] = 0x30, | |
| 247 | + [OMAP_I2C_IP_V2_REVNB_LO] = 0x00, | |
| 248 | + [OMAP_I2C_IP_V2_REVNB_HI] = 0x04, | |
| 249 | + [OMAP_I2C_IP_V2_IRQSTATUS_RAW] = 0x24, | |
| 250 | + [OMAP_I2C_IP_V2_IRQENABLE_SET] = 0x2c, | |
| 251 | + [OMAP_I2C_IP_V2_IRQENABLE_CLR] = 0x30, | |
| 252 | 252 | }; |
| 253 | 253 | |
| 254 | 254 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, |
| @@ -266,17 +266,11 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) · 11 unmodified lines | ||
| 266 | 266 | |
| 267 | 267 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) |
| 268 | 268 | { |
| 269 | − struct platform_device *pdev; | |
| 270 | 269 | struct omap_i2c_bus_platform_data *pdata; |
| 271 | 270 | |
| 272 | − WARN_ON(!dev->idle); | |
| 271 | + pdata = dev->dev->platform_data; | |
| 273 | 272 | |
| 274 | − pdev = to_platform_device(dev->dev); | |
| 275 | − pdata = pdev->dev.platform_data; | |
| 276 | − | |
| 277 | − pm_runtime_get_sync(&pdev->dev); | |
| 278 | − | |
| 279 | − if (cpu_is_omap34xx()) { | |
| 273 | + if (pdata->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) { | |
| 280 | 274 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
| 281 | 275 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); |
| 282 | 276 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); |
| @@ -286,7 +280,6 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev) · 3 unmodified lines | ||
| 286 | 280 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); |
| 287 | 281 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); |
| 288 | 282 | } |
| 289 | − dev->idle = 0; | |
| 290 | 283 | |
| 291 | 284 | /* |
| 292 | 285 | * Don't write to this register if the IE state is 0 as it can |
| @@ -298,32 +291,25 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev) · 5 unmodified lines | ||
| 298 | 291 | |
| 299 | 292 | static void omap_i2c_idle(struct omap_i2c_dev *dev) |
| 300 | 293 | { |
| 301 | − struct platform_device *pdev; | |
| 302 | 294 | struct omap_i2c_bus_platform_data *pdata; |
| 303 | 295 | u16 iv; |
| 304 | 296 | |
| 305 | − WARN_ON(dev->idle); | |
| 306 | − | |
| 307 | − pdev = to_platform_device(dev->dev); | |
| 308 | − pdata = pdev->dev.platform_data; | |
| 297 | + pdata = dev->dev->platform_data; | |
| 309 | 298 | |
| 310 | 299 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); |
| 311 | − if (dev->rev >= OMAP_I2C_REV_ON_4430) | |
| 312 | − omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1); | |
| 300 | + if (pdata->rev == OMAP_I2C_IP_VERSION_2) | |
| 301 | + omap_i2c_write_reg(dev, OMAP_I2C_IP_V2_IRQENABLE_CLR, 1); | |
| 313 | 302 | else |
| 314 | 303 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); |
| 315 | 304 | |
| 316 | − if (dev->rev < OMAP_I2C_REV_2) { | |
| 305 | + if (dev->rev < OMAP_I2C_OMAP1_REV_2) { | |
| 317 | 306 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ |
| 318 | 307 | } else { |
| 319 | 308 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate); |
| 320 | 309 | |
| 321 | − /* Flush posted write before the dev->idle store occurs */ | |
| 310 | + /* Flush posted write */ | |
| 322 | 311 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); |
| 323 | 312 | } |
| 324 | − dev->idle = 1; | |
| 325 | − | |
| 326 | − pm_runtime_put_sync(&pdev->dev); | |
| 327 | 313 | } |
| 328 | 314 | |
| 329 | 315 | static int omap_i2c_init(struct omap_i2c_dev *dev) |
| @@ -334,8 +320,11 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 4 unmodified lines | ||
| 334 | 320 | unsigned long timeout; |
| 335 | 321 | unsigned long internal_clk = 0; |
| 336 | 322 | struct clk *fclk; |
| 323 | + struct omap_i2c_bus_platform_data *pdata; | |
| 324 | + | |
| 325 | + pdata = dev->dev->platform_data; | |
| 337 | 326 | |
| 338 | − if (dev->rev >= OMAP_I2C_REV_2) { | |
| 327 | + if (dev->rev >= OMAP_I2C_OMAP1_REV_2) { | |
| 339 | 328 | /* Disable I2C controller before soft reset */ |
| 340 | 329 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, |
| 341 | 330 | omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & |
| @@ -378,12 +367,13 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 36 unmodified lines | ||
| 378 | 367 | * REVISIT: Some wkup sources might not be needed. |
| 379 | 368 | */ |
| 380 | 369 | dev->westate = OMAP_I2C_WE_ALL; |
| 381 | − omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); | |
| 370 | + omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, | |
| 371 | + dev->westate); | |
| 382 | 372 | } |
| 383 | 373 | } |
| 384 | 374 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
| 385 | 375 | |
| 386 | − if (cpu_class_is_omap1()) { | |
| 376 | + if (pdata->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) { | |
| 387 | 377 | /* |
| 388 | 378 | * The I2C functional clock is the armxor_ck, so there's |
| 389 | 379 | * no need to get "armxor_ck" separately. Now, if OMAP2420 |
| @@ -407,7 +397,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 17 unmodified lines | ||
| 407 | 397 | psc = fclk_rate / 12000000; |
| 408 | 398 | } |
| 409 | 399 | |
| 410 | − if (!(cpu_class_is_omap1() || cpu_is_omap2420())) { | |
| 400 | + if (!(pdata->flags & OMAP_I2C_FLAG_SIMPLE_CLOCK)) { | |
| 411 | 401 | |
| 412 | 402 | /* |
| 413 | 403 | * HSI2C controller internal clk rate should be 19.2 Mhz for |
| @@ -415,7 +405,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 1 unmodified line | ||
| 415 | 405 | * to get longer filter period for better noise suppression. |
| 416 | 406 | * The filter is iclk (fclk for HS) period. |
| 417 | 407 | */ |
| 418 | − if (dev->speed > 400 || cpu_is_omap2430()) | |
| 408 | + if (dev->speed > 400 || | |
| 409 | + pdata->flags & OMAP_I2C_FLAG_FORCE_19200_INT_CLK) | |
| 419 | 410 | internal_clk = 19200; |
| 420 | 411 | else if (dev->speed > 100) |
| 421 | 412 | internal_clk = 9600; |
| @@ -484,7 +475,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 62 unmodified lines | ||
| 484 | 475 | |
| 485 | 476 | dev->errata = 0; |
| 486 | 477 | |
| 487 | − if (cpu_is_omap2430() || cpu_is_omap34xx()) | |
| 478 | + if (pdata->flags & OMAP_I2C_FLAG_APPLY_ERRATA_I207) | |
| 488 | 479 | dev->errata |= I2C_OMAP_ERRATA_I207; |
| 489 | 480 | |
| 490 | 481 | /* Enable interrupts */ |
| @@ -493,7 +484,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 2 unmodified lines | ||
| 493 | 484 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? |
| 494 | 485 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); |
| 495 | 486 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); |
| 496 | − if (cpu_is_omap34xx()) { | |
| 487 | + if (pdata->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) { | |
| 497 | 488 | dev->pscstate = psc; |
| 498 | 489 | dev->scllstate = scll; |
| 499 | 490 | dev->sclhstate = sclh; |
| @@ -642,7 +633,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 142 unmodified lines | ||
| 642 | 633 | int i; |
| 643 | 634 | int r; |
| 644 | 635 | |
| 645 | − omap_i2c_unidle(dev); | |
| 636 | + pm_runtime_get_sync(dev->dev); | |
| 646 | 637 | |
| 647 | 638 | r = omap_i2c_wait_for_bb(dev); |
| 648 | 639 | if (r < 0) |
| @@ -665,7 +656,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 16 unmodified lines | ||
| 665 | 656 | |
| 666 | 657 | omap_i2c_wait_for_bb(dev); |
| 667 | 658 | out: |
| 668 | − omap_i2c_idle(dev); | |
| 659 | + pm_runtime_put(dev->dev); | |
| 669 | 660 | return r; |
| 670 | 661 | } |
| 671 | 662 | |
| @@ -720,12 +711,12 @@ static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat) · 48 unmodified lines | ||
| 720 | 711 | #ifdef CONFIG_ARCH_OMAP15XX |
| 721 | 712 | |
| 722 | 713 | static irqreturn_t |
| 723 | −omap_i2c_rev1_isr(int this_irq, void *dev_id) | |
| 714 | +omap_i2c_omap1_isr(int this_irq, void *dev_id) | |
| 724 | 715 | { |
| 725 | 716 | struct omap_i2c_dev *dev = dev_id; |
| 726 | 717 | u16 iv, w; |
| 727 | 718 | |
| 728 | − if (dev->idle) | |
| 719 | + if (pm_runtime_suspended(dev->dev)) | |
| 729 | 720 | return IRQ_NONE; |
| 730 | 721 | |
| 731 | 722 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); |
| @@ -774,7 +765,7 @@ omap_i2c_rev1_isr(int this_irq, void *dev_id) · 42 unmodified lines | ||
| 774 | 765 | return IRQ_HANDLED; |
| 775 | 766 | } |
| 776 | 767 | #else |
| 777 | −#define omap_i2c_rev1_isr NULL | |
| 768 | +#define omap_i2c_omap1_isr NULL | |
| 778 | 769 | #endif |
| 779 | 770 | |
| 780 | 771 | /* |
| @@ -813,8 +804,11 @@ omap_i2c_isr(int this_irq, void *dev_id) · 32 unmodified lines | ||
| 813 | 804 | u16 bits; |
| 814 | 805 | u16 stat, w; |
| 815 | 806 | int err, count = 0; |
| 807 | + struct omap_i2c_bus_platform_data *pdata; | |
| 816 | 808 | |
| 817 | − if (dev->idle) | |
| 809 | + pdata = dev->dev->platform_data; | |
| 810 | + | |
| 811 | + if (pm_runtime_suspended(dev->dev)) | |
| 818 | 812 | return IRQ_NONE; |
| 819 | 813 | |
| 820 | 814 | bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); |
| @@ -881,8 +875,8 @@ complete: · 60 unmodified lines | ||
| 881 | 875 | * Data reg in 2430, omap3 and |
| 882 | 876 | * omap4 is 8 bit wide |
| 883 | 877 | */ |
| 884 | − if (cpu_class_is_omap1() || | |
| 885 | − cpu_is_omap2420()) { | |
| 878 | + if (pdata->flags & | |
| 879 | + OMAP_I2C_FLAG_16BIT_DATA_REG) { | |
| 886 | 880 | if (dev->buf_len) { |
| 887 | 881 | *dev->buf++ = w >> 8; |
| 888 | 882 | dev->buf_len--; |
| @@ -924,8 +918,8 @@ complete: · 35 unmodified lines | ||
| 924 | 918 | * Data reg in 2430, omap3 and |
| 925 | 919 | * omap4 is 8 bit wide |
| 926 | 920 | */ |
| 927 | − if (cpu_class_is_omap1() || | |
| 928 | − cpu_is_omap2420()) { | |
| 921 | + if (pdata->flags & | |
| 922 | + OMAP_I2C_FLAG_16BIT_DATA_REG) { | |
| 929 | 923 | if (dev->buf_len) { |
| 930 | 924 | w |= *dev->buf++ << 8; |
| 931 | 925 | dev->buf_len--; |
| @@ -1016,7 +1010,6 @@ omap_i2c_probe(struct platform_device *pdev) · 84 unmodified lines | ||
| 1016 | 1010 | } |
| 1017 | 1011 | |
| 1018 | 1012 | dev->speed = speed; |
| 1019 | − dev->idle = 1; | |
| 1020 | 1013 | dev->dev = &pdev->dev; |
| 1021 | 1014 | dev->irq = irq->start; |
| 1022 | 1015 | dev->base = ioremap(mem->start, resource_size(mem)); |
| @@ -1027,27 +1020,22 @@ omap_i2c_probe(struct platform_device *pdev) · 4 unmodified lines | ||
| 1027 | 1020 | |
| 1028 | 1021 | platform_set_drvdata(pdev, dev); |
| 1029 | 1022 | |
| 1030 | − if (cpu_is_omap7xx()) | |
| 1031 | − dev->reg_shift = 1; | |
| 1032 | − else if (cpu_is_omap44xx()) | |
| 1033 | − dev->reg_shift = 0; | |
| 1034 | − else | |
| 1035 | − dev->reg_shift = 2; | |
| 1023 | + dev->reg_shift = (pdata->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3; | |
| 1036 | 1024 | |
| 1037 | − if (cpu_is_omap44xx()) | |
| 1038 | − dev->regs = (u8 *) omap4_reg_map; | |
| 1025 | + if (pdata->rev == OMAP_I2C_IP_VERSION_2) | |
| 1026 | + dev->regs = (u8 *)reg_map_ip_v2; | |
| 1039 | 1027 | else |
| 1040 | − dev->regs = (u8 *) reg_map; | |
| 1028 | + dev->regs = (u8 *)reg_map_ip_v1; | |
| 1041 | 1029 | |
| 1042 | − pm_runtime_enable(&pdev->dev); | |
| 1043 | − omap_i2c_unidle(dev); | |
| 1030 | + pm_runtime_enable(dev->dev); | |
| 1031 | + pm_runtime_get_sync(dev->dev); | |
| 1044 | 1032 | |
| 1045 | 1033 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; |
| 1046 | 1034 | |
| 1047 | 1035 | if (dev->rev <= OMAP_I2C_REV_ON_3430) |
| 1048 | 1036 | dev->errata |= I2C_OMAP3_1P153; |
| 1049 | 1037 | |
| 1050 | − if (!(cpu_class_is_omap1() || cpu_is_omap2420())) { | |
| 1038 | + if (!(pdata->flags & OMAP_I2C_FLAG_NO_FIFO)) { | |
| 1051 | 1039 | u16 s; |
| 1052 | 1040 | |
| 1053 | 1041 | /* Set up the fifo size - Get total size */ |
| @@ -1059,7 +1047,7 @@ omap_i2c_probe(struct platform_device *pdev) · 5 unmodified lines | ||
| 1059 | 1047 | * size. This is to ensure that we can handle the status on int |
| 1060 | 1048 | * call back latencies. |
| 1061 | 1049 | */ |
| 1062 | − if (dev->rev >= OMAP_I2C_REV_ON_4430) { | |
| 1050 | + if (dev->rev >= OMAP_I2C_REV_ON_3530_4430) { | |
| 1063 | 1051 | dev->fifo_size = 0; |
| 1064 | 1052 | dev->b_hw = 0; /* Disable hardware fixes */ |
| 1065 | 1053 | } else { |
| @@ -1075,7 +1063,8 @@ omap_i2c_probe(struct platform_device *pdev) · 9 unmodified lines | ||
| 1075 | 1063 | /* reset ASAP, clearing any IRQs */ |
| 1076 | 1064 | omap_i2c_init(dev); |
| 1077 | 1065 | |
| 1078 | − isr = (dev->rev < OMAP_I2C_REV_2) ? omap_i2c_rev1_isr : omap_i2c_isr; | |
| 1066 | + isr = (dev->rev < OMAP_I2C_OMAP1_REV_2) ? omap_i2c_omap1_isr : | |
| 1067 | + omap_i2c_isr; | |
| 1079 | 1068 | r = request_irq(dev->irq, isr, 0, pdev->name, dev); |
| 1080 | 1069 | |
| 1081 | 1070 | if (r) { |
| @@ -1083,10 +1072,10 @@ omap_i2c_probe(struct platform_device *pdev) · 1 unmodified line | ||
| 1083 | 1072 | goto err_unuse_clocks; |
| 1084 | 1073 | } |
| 1085 | 1074 | |
| 1086 | − dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", | |
| 1087 | − pdev->id, dev->rev >> 4, dev->rev & 0xf, dev->speed); | |
| 1075 | + dev_info(dev->dev, "bus %d rev%d.%d.%d at %d kHz\n", pdev->id, | |
| 1076 | + pdata->rev, dev->rev >> 4, dev->rev & 0xf, dev->speed); | |
| 1088 | 1077 | |
| 1089 | − omap_i2c_idle(dev); | |
| 1078 | + pm_runtime_put(dev->dev); | |
| 1090 | 1079 | |
| 1091 | 1080 | adap = &dev->adapter; |
| 1092 | 1081 | i2c_set_adapdata(adap, dev); |
| @@ -1110,7 +1099,7 @@ err_free_irq: · 17 unmodified lines | ||
| 1110 | 1099 | free_irq(dev->irq, dev); |
| 1111 | 1100 | err_unuse_clocks: |
| 1112 | 1101 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
| 1113 | − omap_i2c_idle(dev); | |
| 1102 | + pm_runtime_put(dev->dev); | |
| 1114 | 1103 | iounmap(dev->base); |
| 1115 | 1104 | err_free_mem: |
| 1116 | 1105 | platform_set_drvdata(pdev, NULL); |
| @@ -1139,12 +1128,43 @@ omap_i2c_remove(struct platform_device *pdev) · 22 unmodified lines | ||
| 1139 | 1128 | return 0; |
| 1140 | 1129 | } |
| 1141 | 1130 | |
| 1131 | +#ifdef CONFIG_PM_RUNTIME | |
| 1132 | +static int omap_i2c_runtime_suspend(struct device *dev) | |
| 1133 | +{ | |
| 1134 | + struct platform_device *pdev = to_platform_device(dev); | |
| 1135 | + struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); | |
| 1136 | + | |
| 1137 | + omap_i2c_idle(_dev); | |
| 1138 | + | |
| 1139 | + return 0; | |
| 1140 | +} | |
| 1141 | + | |
| 1142 | +static int omap_i2c_runtime_resume(struct device *dev) | |
| 1143 | +{ | |
| 1144 | + struct platform_device *pdev = to_platform_device(dev); | |
| 1145 | + struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); | |
| 1146 | + | |
| 1147 | + omap_i2c_unidle(_dev); | |
| 1148 | + | |
| 1149 | + return 0; | |
| 1150 | +} | |
| 1151 | + | |
| 1152 | +static struct dev_pm_ops omap_i2c_pm_ops = { | |
| 1153 | + .runtime_suspend = omap_i2c_runtime_suspend, | |
| 1154 | + .runtime_resume = omap_i2c_runtime_resume, | |
| 1155 | +}; | |
| 1156 | +#define OMAP_I2C_PM_OPS (&omap_i2c_pm_ops) | |
| 1157 | +#else | |
| 1158 | +#define OMAP_I2C_PM_OPS NULL | |
| 1159 | +#endif | |
| 1160 | + | |
| 1142 | 1161 | static struct platform_driver omap_i2c_driver = { |
| 1143 | 1162 | .probe = omap_i2c_probe, |
| 1144 | 1163 | .remove = omap_i2c_remove, |
| 1145 | 1164 | .driver = { |
| 1146 | 1165 | .name = "omap_i2c", |
| 1147 | 1166 | .owner = THIS_MODULE, |
| 1167 | + .pm = OMAP_I2C_PM_OPS, | |
| 1148 | 1168 | }, |
| 1149 | 1169 | }; |
| 1150 | 1170 | |
| @@ -306,7 +306,7 @@ static int __devinit pmcmsptwi_probe(struct platform_device *pldev) · 305 unmodified lines | ||
| 306 | 306 | pmcmsptwi_data.irq = platform_get_irq(pldev, 0); |
| 307 | 307 | if (pmcmsptwi_data.irq) { |
| 308 | 308 | rc = request_irq(pmcmsptwi_data.irq, &pmcmsptwi_interrupt, |
| 309 | − IRQF_SHARED | IRQF_DISABLED | IRQF_SAMPLE_RANDOM, | |
| 309 | + IRQF_SHARED | IRQF_SAMPLE_RANDOM, | |
| 310 | 310 | pldev->name, &pmcmsptwi_data); |
| 311 | 311 | if (rc == 0) { |
| 312 | 312 | /* |
| @@ -35,6 +35,8 @@ · 34 unmodified lines | ||
| 35 | 35 | #include <linux/cpufreq.h> |
| 36 | 36 | #include <linux/slab.h> |
| 37 | 37 | #include <linux/io.h> |
| 38 | +#include <linux/of_i2c.h> | |
| 39 | +#include <linux/of_gpio.h> | |
| 38 | 40 | |
| 39 | 41 | #include <asm/irq.h> |
| 40 | 42 | |
| @@ -78,6 +80,8 @@ struct s3c24xx_i2c { · 37 unmodified lines | ||
| 78 | 80 | struct resource *ioarea; |
| 79 | 81 | struct i2c_adapter adap; |
| 80 | 82 | |
| 83 | + struct s3c2410_platform_i2c *pdata; | |
| 84 | + int gpios[2]; | |
| 81 | 85 | #ifdef CONFIG_CPU_FREQ |
| 82 | 86 | struct notifier_block freq_transition; |
| 83 | 87 | #endif |
| @@ -95,6 +99,12 @@ static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) · 11 unmodified lines | ||
| 95 | 99 | struct platform_device *pdev = to_platform_device(i2c->dev); |
| 96 | 100 | enum s3c24xx_i2c_type type; |
| 97 | 101 | |
| 102 | +#ifdef CONFIG_OF | |
| 103 | + if (i2c->dev->of_node) | |
| 104 | + return of_device_is_compatible(i2c->dev->of_node, | |
| 105 | + "samsung,s3c2440-i2c"); | |
| 106 | +#endif | |
| 107 | + | |
| 98 | 108 | type = platform_get_device_id(pdev)->driver_data; |
| 99 | 109 | return type == TYPE_S3C2440; |
| 100 | 110 | } |
| @@ -625,7 +635,7 @@ static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted, · 524 unmodified lines | ||
| 625 | 635 | |
| 626 | 636 | static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) |
| 627 | 637 | { |
| 628 | − struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data; | |
| 638 | + struct s3c2410_platform_i2c *pdata = i2c->pdata; | |
| 629 | 639 | unsigned long clkin = clk_get_rate(i2c->clk); |
| 630 | 640 | unsigned int divs, div1; |
| 631 | 641 | unsigned long target_frequency; |
| @@ -741,6 +751,49 @@ static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) · 109 unmodified lines | ||
| 741 | 751 | } |
| 742 | 752 | #endif |
| 743 | 753 | |
| 754 | +#ifdef CONFIG_OF | |
| 755 | +static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) | |
| 756 | +{ | |
| 757 | + int idx, gpio, ret; | |
| 758 | + | |
| 759 | + for (idx = 0; idx < 2; idx++) { | |
| 760 | + gpio = of_get_gpio(i2c->dev->of_node, idx); | |
| 761 | + if (!gpio_is_valid(gpio)) { | |
| 762 | + dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio); | |
| 763 | + goto free_gpio; | |
| 764 | + } | |
| 765 | + | |
| 766 | + ret = gpio_request(gpio, "i2c-bus"); | |
| 767 | + if (ret) { | |
| 768 | + dev_err(i2c->dev, "gpio [%d] request failed\n", gpio); | |
| 769 | + goto free_gpio; | |
| 770 | + } | |
| 771 | + } | |
| 772 | + return 0; | |
| 773 | + | |
| 774 | +free_gpio: | |
| 775 | + while (--idx >= 0) | |
| 776 | + gpio_free(i2c->gpios[idx]); | |
| 777 | + return -EINVAL; | |
| 778 | +} | |
| 779 | + | |
| 780 | +static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c) | |
| 781 | +{ | |
| 782 | + unsigned int idx; | |
| 783 | + for (idx = 0; idx < 2; idx++) | |
| 784 | + gpio_free(i2c->gpios[idx]); | |
| 785 | +} | |
| 786 | +#else | |
| 787 | +static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) | |
| 788 | +{ | |
| 789 | + return -EINVAL; | |
| 790 | +} | |
| 791 | + | |
| 792 | +static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c) | |
| 793 | +{ | |
| 794 | +} | |
| 795 | +#endif | |
| 796 | + | |
| 744 | 797 | /* s3c24xx_i2c_init |
| 745 | 798 | * |
| 746 | 799 | * initialise the controller, set the IO lines and frequency |
| @@ -754,12 +807,15 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) · 7 unmodified lines | ||
| 754 | 807 | |
| 755 | 808 | /* get the plafrom data */ |
| 756 | 809 | |
| 757 | − pdata = i2c->dev->platform_data; | |
| 810 | + pdata = i2c->pdata; | |
| 758 | 811 | |
| 759 | 812 | /* inititalise the gpio */ |
| 760 | 813 | |
| 761 | 814 | if (pdata->cfg_gpio) |
| 762 | 815 | pdata->cfg_gpio(to_platform_device(i2c->dev)); |
| 816 | + else | |
| 817 | + if (s3c24xx_i2c_parse_dt_gpio(i2c)) | |
| 818 | + return -EINVAL; | |
| 763 | 819 | |
| 764 | 820 | /* write slave address */ |
| 765 | 821 | |
| @@ -785,6 +841,34 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) · 19 unmodified lines | ||
| 785 | 841 | return 0; |
| 786 | 842 | } |
| 787 | 843 | |
| 844 | +#ifdef CONFIG_OF | |
| 845 | +/* s3c24xx_i2c_parse_dt | |
| 846 | + * | |
| 847 | + * Parse the device tree node and retreive the platform data. | |
| 848 | +*/ | |
| 849 | + | |
| 850 | +static void | |
| 851 | +s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c) | |
| 852 | +{ | |
| 853 | + struct s3c2410_platform_i2c *pdata = i2c->pdata; | |
| 854 | + | |
| 855 | + if (!np) | |
| 856 | + return; | |
| 857 | + | |
| 858 | + pdata->bus_num = -1; /* i2c bus number is dynamically assigned */ | |
| 859 | + of_property_read_u32(np, "samsung,i2c-sda-delay", &pdata->sda_delay); | |
| 860 | + of_property_read_u32(np, "samsung,i2c-slave-addr", &pdata->slave_addr); | |
| 861 | + of_property_read_u32(np, "samsung,i2c-max-bus-freq", | |
| 862 | + (u32 *)&pdata->frequency); | |
| 863 | +} | |
| 864 | +#else | |
| 865 | +static void | |
| 866 | +s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c) | |
| 867 | +{ | |
| 868 | + return; | |
| 869 | +} | |
| 870 | +#endif | |
| 871 | + | |
| 788 | 872 | /* s3c24xx_i2c_probe |
| 789 | 873 | * |
| 790 | 874 | * called by the bus driver when a suitable device is found |
| @@ -793,14 +877,16 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) · 2 unmodified lines | ||
| 793 | 877 | static int s3c24xx_i2c_probe(struct platform_device *pdev) |
| 794 | 878 | { |
| 795 | 879 | struct s3c24xx_i2c *i2c; |
| 796 | − struct s3c2410_platform_i2c *pdata; | |
| 880 | + struct s3c2410_platform_i2c *pdata = NULL; | |
| 797 | 881 | struct resource *res; |
| 798 | 882 | int ret; |
| 799 | 883 | |
| 800 | − pdata = pdev->dev.platform_data; | |
| 801 | − if (!pdata) { | |
| 802 | − dev_err(&pdev->dev, "no platform data\n"); | |
| 803 | − return -EINVAL; | |
| 884 | + if (!pdev->dev.of_node) { | |
| 885 | + pdata = pdev->dev.platform_data; | |
| 886 | + if (!pdata) { | |
| 887 | + dev_err(&pdev->dev, "no platform data\n"); | |
| 888 | + return -EINVAL; | |
| 889 | + } | |
| 804 | 890 | } |
| 805 | 891 | |
| 806 | 892 | i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL); |
| @@ -809,6 +895,17 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 809 | 895 | return -ENOMEM; |
| 810 | 896 | } |
| 811 | 897 | |
| 898 | + i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | |
| 899 | + if (!i2c->pdata) { | |
| 900 | + ret = -ENOMEM; | |
| 901 | + goto err_noclk; | |
| 902 | + } | |
| 903 | + | |
| 904 | + if (pdata) | |
| 905 | + memcpy(i2c->pdata, pdata, sizeof(*pdata)); | |
| 906 | + else | |
| 907 | + s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c); | |
| 908 | + | |
| 812 | 909 | strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name)); |
| 813 | 910 | i2c->adap.owner = THIS_MODULE; |
| 814 | 911 | i2c->adap.algo = &s3c24xx_i2c_algorithm; |
| @@ -883,7 +980,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 68 unmodified lines | ||
| 883 | 980 | goto err_iomap; |
| 884 | 981 | } |
| 885 | 982 | |
| 886 | − ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED, | |
| 983 | + ret = request_irq(i2c->irq, s3c24xx_i2c_irq, 0, | |
| 887 | 984 | dev_name(&pdev->dev), i2c); |
| 888 | 985 | |
| 889 | 986 | if (ret != 0) { |
| @@ -903,7 +1000,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 13 unmodified lines | ||
| 903 | 1000 | * being bus 0. |
| 904 | 1001 | */ |
| 905 | 1002 | |
| 906 | − i2c->adap.nr = pdata->bus_num; | |
| 1003 | + i2c->adap.nr = i2c->pdata->bus_num; | |
| 1004 | + i2c->adap.dev.of_node = pdev->dev.of_node; | |
| 907 | 1005 | |
| 908 | 1006 | ret = i2c_add_numbered_adapter(&i2c->adap); |
| 909 | 1007 | if (ret < 0) { |
| @@ -911,6 +1009,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 1 unmodified line | ||
| 911 | 1009 | goto err_cpufreq; |
| 912 | 1010 | } |
| 913 | 1011 | |
| 1012 | + of_i2c_register_devices(&i2c->adap); | |
| 914 | 1013 | platform_set_drvdata(pdev, i2c); |
| 915 | 1014 | |
| 916 | 1015 | dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev)); |
| @@ -959,6 +1058,7 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) · 42 unmodified lines | ||
| 959 | 1058 | iounmap(i2c->regs); |
| 960 | 1059 | |
| 961 | 1060 | release_resource(i2c->ioarea); |
| 1061 | + s3c24xx_i2c_dt_gpio_free(i2c); | |
| 962 | 1062 | kfree(i2c->ioarea); |
| 963 | 1063 | kfree(i2c); |
| 964 | 1064 | |
| @@ -1012,6 +1112,17 @@ static struct platform_device_id s3c24xx_driver_ids[] = { · 47 unmodified lines | ||
| 1012 | 1112 | }; |
| 1013 | 1113 | MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); |
| 1014 | 1114 | |
| 1115 | +#ifdef CONFIG_OF | |
| 1116 | +static const struct of_device_id s3c24xx_i2c_match[] = { | |
| 1117 | + { .compatible = "samsung,s3c2410-i2c" }, | |
| 1118 | + { .compatible = "samsung,s3c2440-i2c" }, | |
| 1119 | + {}, | |
| 1120 | +}; | |
| 1121 | +MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match); | |
| 1122 | +#else | |
| 1123 | +#define s3c24xx_i2c_match NULL | |
| 1124 | +#endif | |
| 1125 | + | |
| 1015 | 1126 | static struct platform_driver s3c24xx_i2c_driver = { |
| 1016 | 1127 | .probe = s3c24xx_i2c_probe, |
| 1017 | 1128 | .remove = s3c24xx_i2c_remove, |
| @@ -1020,6 +1131,7 @@ static struct platform_driver s3c24xx_i2c_driver = { · 2 unmodified lines | ||
| 1020 | 1131 | .owner = THIS_MODULE, |
| 1021 | 1132 | .name = "s3c-i2c", |
| 1022 | 1133 | .pm = S3C24XX_DEV_PM_OPS, |
| 1134 | + .of_match_table = s3c24xx_i2c_match, | |
| 1023 | 1135 | }, |
| 1024 | 1136 | }; |
| 1025 | 1137 | |
| @@ -502,7 +502,7 @@ static int __devinit sh7760_i2c_probe(struct platform_device *pdev) · 501 unmodified lines | ||
| 502 | 502 | } |
| 503 | 503 | OUT32(id, I2CCCR, ret); |
| 504 | 504 | |
| 505 | − if (request_irq(id->irq, sh7760_i2c_irq, IRQF_DISABLED, | |
| 505 | + if (request_irq(id->irq, sh7760_i2c_irq, 0, | |
| 506 | 506 | SH7760_I2C_DEVNAME, id)) { |
| 507 | 507 | dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); |
| 508 | 508 | ret = -EBUSY; |
| @@ -543,7 +543,7 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) · 542 unmodified lines | ||
| 543 | 543 | |
| 544 | 544 | while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) { |
| 545 | 545 | for (n = res->start; hook && n <= res->end; n++) { |
| 546 | − if (request_irq(n, sh_mobile_i2c_isr, IRQF_DISABLED, | |
| 546 | + if (request_irq(n, sh_mobile_i2c_isr, 0, | |
| 547 | 547 | dev_name(&dev->dev), dev)) { |
| 548 | 548 | for (n--; n >= res->start; n--) |
| 549 | 549 | free_irq(n, dev); |
| @@ -916,7 +916,7 @@ stu300_probe(struct platform_device *pdev) · 915 unmodified lines | ||
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | dev->irq = platform_get_irq(pdev, 0); |
| 919 | − if (request_irq(dev->irq, stu300_irh, IRQF_DISABLED, | |
| 919 | + if (request_irq(dev->irq, stu300_irh, 0, | |
| 920 | 920 | NAME, dev)) { |
| 921 | 921 | ret = -EIO; |
| 922 | 922 | goto err_no_irq; |
| @@ -566,7 +566,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) · 565 unmodified lines | ||
| 566 | 566 | struct clk *clk; |
| 567 | 567 | struct clk *i2c_clk; |
| 568 | 568 | const unsigned int *prop; |
| 569 | − void *base; | |
| 569 | + void __iomem *base; | |
| 570 | 570 | int irq; |
| 571 | 571 | int ret = 0; |
| 572 | 572 | |
| @@ -32,10 +32,9 @@ · 31 unmodified lines | ||
| 32 | 32 | |
| 33 | 33 | struct omap_i2c_bus_platform_data { |
| 34 | 34 | u32 clkrate; |
| 35 | + u32 rev; | |
| 36 | + u32 flags; | |
| 35 | 37 | void (*set_mpu_wkup_lat)(struct device *dev, long set); |
| 36 | − int (*device_enable) (struct platform_device *pdev); | |
| 37 | − int (*device_shutdown) (struct platform_device *pdev); | |
| 38 | − int (*device_idle) (struct platform_device *pdev); | |
| 39 | 38 | }; |
| 40 | 39 | |
| 41 | 40 | #endif |