History

Merge branch 'for-linus/i2c-3.2' of git://git.fluff.org/bjdooks/linux

* '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 ...

Linus Torvalds committed 15 years ago

Commit b4beb4b2 parents f3c3f06 3945fe926 files · +1543 −684Browse files

Unified · Split

26 files
  1. Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt +25 −0
  2. Documentation/devicetree/bindings/i2c/samsung-i2c.txt +39 −0
  3. arch/arm/plat-mxc/include/mach/i2c.h +0 −4
  4. arch/arm/plat-omap/i2c.c +27 −0
  5. arch/mips/include/asm/mach-au1x00/au1xxx_psc.h +0 −13
  6. drivers/i2c/busses/Kconfig +13 −3
  7. drivers/i2c/busses/Makefile +4 −1
  8. drivers/i2c/busses/i2c-au1550.c +114 −166
  9. drivers/i2c/busses/i2c-bfin-twi.c +2 −2
  10. drivers/i2c/busses/i2c-designware-core.c +120 −262
  11. drivers/i2c/busses/i2c-designware-core.h +105 −0
  12. drivers/i2c/busses/i2c-designware-pcidrv.c +392 −0
  13. drivers/i2c/busses/i2c-designware-platdrv.c +215 −0
  14. drivers/i2c/busses/i2c-eg20t.c +196 −74
  15. drivers/i2c/busses/i2c-highlander.c +1 −1
  16. drivers/i2c/busses/i2c-imx.c +22 −24
  17. drivers/i2c/busses/i2c-nomadik.c +47 −44
  18. drivers/i2c/busses/i2c-nuc900.c +1 −1
  19. drivers/i2c/busses/i2c-omap.c +92 −72
  20. drivers/i2c/busses/i2c-pmcmsp.c +1 −1
  21. drivers/i2c/busses/i2c-s3c2410.c +121 −9
  22. drivers/i2c/busses/i2c-sh7760.c +1 −1
  23. drivers/i2c/busses/i2c-sh_mobile.c +1 −1
  24. drivers/i2c/busses/i2c-stu300.c +1 −1
  25. drivers/i2c/busses/i2c-tegra.c +1 −1
  26. include/linux/i2c-omap.h +2 −3
Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt+25−0
@@ -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+};
Documentation/devicetree/bindings/i2c/samsung-i2c.txt+39−0
@@ -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+ };
arch/arm/plat-mxc/include/mach/i2c.h+0−4
@@ -11,14 +11,10 @@ · 10 unmodified lines
1111
1212 /**
1313 * 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
1614 * @bitrate: Bus speed measured in Hz
1715 *
1816 **/
1917 struct imxi2c_platform_data {
20− int (*init)(struct device *dev);
21− void (*exit)(struct device *dev);
2218 int bitrate;
2319 };
2420
arch/arm/plat-omap/i2c.c+27−0
@@ -108,6 +108,22 @@ static inline int omap1_i2c_add_bus(int bus_id) · 107 unmodified lines
108108 res[1].start = INT_I2C;
109109 pdata = &i2c_pdata[bus_id - 1];
110110
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+
111127 return platform_device_register(pdev);
112128 }
113129
@@ -138,6 +154,7 @@ static inline int omap2_i2c_add_bus(int bus_id) · 24 unmodified lines
138154 struct omap_device *od;
139155 char oh_name[MAX_OMAP_I2C_HWMOD_NAME_LEN];
140156 struct omap_i2c_bus_platform_data *pdata;
157+ struct omap_i2c_dev_attr *dev_attr;
141158
142159 omap2_i2c_mux_pins(bus_id);
143160
@@ -151,6 +168,16 @@ static inline int omap2_i2c_add_bus(int bus_id) · 7 unmodified lines
151168 }
152169
153170 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+
154181 /*
155182 * When waiting for completion of a i2c transfer, we need to
156183 * set a wake up latency constraint for the MPU. This is to
arch/mips/include/asm/mach-au1x00/au1xxx_psc.h+0−13
@@ -394,19 +394,6 @@ typedef struct psc_spi { · 393 unmodified lines
394394 #define PSC_SPITXRX_LC (1 << 29)
395395 #define PSC_SPITXRX_SR (1 << 28)
396396
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−
410397 /* SMBus Config Register. */
411398 #define PSC_SMBCFG_RT_MASK (3 << 30)
412399 #define PSC_SMBCFG_RT_FIFO1 (0 << 30)
drivers/i2c/busses/Kconfig+13−3
@@ -350,15 +350,25 @@ config I2C_DAVINCI · 349 unmodified lines
350350 devices such as DaVinci NIC.
351351 For details please see http://www.ti.com/davinci
352352
353−config I2C_DESIGNWARE
354− tristate "Synopsys DesignWare"
353+config I2C_DESIGNWARE_PLATFORM
354+ tristate "Synopsys DesignWare Platfrom"
355355 depends on HAVE_CLK
356356 help
357357 If you say yes to this option, support will be included for the
358358 Synopsys DesignWare I2C adapter. Only master mode is supported.
359359
360360 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.
362372
363373 config I2C_GPIO
364374 tristate "GPIO-based bitbanging I2C"
drivers/i2c/busses/Makefile+4−1
@@ -33,7 +33,10 @@ obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o · 32 unmodified lines
3333 obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
3434 obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
3535 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
3740 obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
3841 obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o
3942 obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
drivers/i2c/busses/i2c-au1550.c+114−166
@@ -39,29 +39,41 @@ · 38 unmodified lines
3939 #include <asm/mach-au1x00/au1xxx.h>
4040 #include <asm/mach-au1x00/au1xxx_psc.h>
4141
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+
4252 struct i2c_au1550_data {
43− u32 psc_base;
53+ void __iomem *psc_base;
4454 int xfer_timeout;
45− int ack_timeout;
4655 struct i2c_adapter adap;
4756 struct resource *ioarea;
4857 };
4958
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)
5260 {
53− u32 stat;
54− int i;
55− volatile psc_smb_t *sp;
61+ __raw_writel(v, a->psc_base + r);
62+ wmb();
63+}
5664
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+}
5869
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 */
6175 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)
6577 return 0;
6678
6779 udelay(1);
@@ -70,41 +82,27 @@ wait_xfer_done(struct i2c_au1550_data *adap) · 2 unmodified lines
7082 return -ETIMEDOUT;
7183 }
7284
73−static int
74−wait_ack(struct i2c_au1550_data *adap)
85+static int wait_ack(struct i2c_au1550_data *adap)
7586 {
76− u32 stat;
77− volatile psc_smb_t *sp;
87+ unsigned long stat;
7888
7989 if (wait_xfer_done(adap))
8090 return -ETIMEDOUT;
8191
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);
8793 if ((stat & (PSC_SMBEVNT_DN | PSC_SMBEVNT_AN | PSC_SMBEVNT_AL)) != 0)
8894 return -ETIMEDOUT;
8995
9096 return 0;
9197 }
9298
93−static int
94−wait_master_done(struct i2c_au1550_data *adap)
99+static int wait_master_done(struct i2c_au1550_data *adap)
95100 {
96− u32 stat;
97− int i;
98− volatile psc_smb_t *sp;
101+ int i;
99102
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)
108106 return 0;
109107 udelay(1);
110108 }
@@ -115,29 +113,20 @@ wait_master_done(struct i2c_au1550_data *adap) · 4 unmodified lines
115113 static int
116114 do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q)
117115 {
118− volatile psc_smb_t *sp;
119− u32 stat;
116+ unsigned long stat;
120117
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);
128121
129122 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();
136126 udelay(50);
137127 }
138128
139− /* Write out the i2c chip address and specify operation
140− */
129+ /* Write out the i2c chip address and specify operation */
141130 addr <<= 1;
142131 if (rd)
143132 addr |= 1;
@@ -146,56 +135,42 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q) · 2 unmodified lines
146135 if (q)
147136 addr |= PSC_SMBTXRX_STP;
148137
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);
155141 if (wait_ack(adap))
156142 return -EIO;
157143 return (q) ? wait_master_done(adap) : 0;
158144 }
159145
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)
162147 {
163− int j;
164− u32 data, stat;
165− volatile psc_smb_t *sp;
148+ int j;
166149
167150 if (wait_xfer_done(adap))
168151 return -EIO;
169152
170− sp = (volatile psc_smb_t *)(adap->psc_base);
171−
172153 j = adap->xfer_timeout * 100;
173154 do {
174155 j--;
175156 if (j <= 0)
176157 return -EIO;
177158
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)
181160 j = 0;
182161 else
183162 udelay(1);
184163 } while (j > 0);
185− data = sp->psc_smbtxrx;
186− au_sync();
187− *ret_data = data;
164+
165+ *out = RD(adap, PSC_SMBTXRX);
188166
189167 return 0;
190168 }
191169
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,
194171 unsigned int len)
195172 {
196− int i;
197− u32 data;
198− volatile psc_smb_t *sp;
173+ int i;
199174
200175 if (len == 0)
201176 return 0;
@@ -204,62 +179,46 @@ i2c_read(struct i2c_au1550_data *adap, unsigned char *buf, · 2 unmodified lines
204179 * zero bytes for timing, waiting for bytes to appear in the
205180 * receive fifo, then reading the bytes.
206181 */
207−
208− sp = (volatile psc_smb_t *)(adap->psc_base);
209−
210182 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]))
215186 return -EIO;
216187
217− buf[i] = data;
218188 i++;
219189 }
220190
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);
225193 if (wait_master_done(adap))
226194 return -EIO;
227195
228− data = sp->psc_smbtxrx;
229− au_sync();
230− buf[i] = data;
196+ buf[i] = (unsigned char)(RD(adap, PSC_SMBTXRX) & 0xff);
231197 return 0;
232198 }
233199
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,
236201 unsigned int len)
237202 {
238− int i;
239− u32 data;
240− volatile psc_smb_t *sp;
203+ int i;
204+ unsigned long data;
241205
242206 if (len == 0)
243207 return 0;
244208
245− sp = (volatile psc_smb_t *)(adap->psc_base);
246−
247209 i = 0;
248210 while (i < (len-1)) {
249211 data = buf[i];
250− sp->psc_smbtxrx = data;
251− au_sync();
212+ WR(adap, PSC_SMBTXRX, data);
252213 if (wait_ack(adap))
253214 return -EIO;
254215 i++;
255216 }
256217
257− /* The last byte has to indicate transfer done.
258− */
218+ /* The last byte has to indicate transfer done. */
259219 data = buf[i];
260220 data |= PSC_SMBTXRX_STP;
261− sp->psc_smbtxrx = data;
262− au_sync();
221+ WR(adap, PSC_SMBTXRX, data);
263222 if (wait_master_done(adap))
264223 return -EIO;
265224 return 0;
@@ -269,12 +228,10 @@ static int · 3 unmodified lines
269228 au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
270229 {
271230 struct i2c_au1550_data *adap = i2c_adap->algo_data;
272− volatile psc_smb_t *sp = (volatile psc_smb_t *)adap->psc_base;
273231 struct i2c_msg *p;
274232 int i, err = 0;
275233
276− sp->psc_ctrl = PSC_CTRL_ENABLE;
277− au_sync();
234+ WR(adap, PSC_CTRL, PSC_CTRL_ENABLE);
278235
279236 for (i = 0; !err && i < num; i++) {
280237 p = &msgs[i];
@@ -293,14 +250,12 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) · 12 unmodified lines
293250 if (err == 0)
294251 err = num;
295252
296− sp->psc_ctrl = PSC_CTRL_SUSPEND;
297− au_sync();
253+ WR(adap, PSC_CTRL, PSC_CTRL_SUSPEND);
298254
299255 return err;
300256 }
301257
302−static u32
303−au1550_func(struct i2c_adapter *adap)
258+static u32 au1550_func(struct i2c_adapter *adap)
304259 {
305260 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
306261 }
@@ -312,57 +267,45 @@ static const struct i2c_algorithm au1550_algo = { · 5 unmodified lines
312267
313268 static void i2c_au1550_setup(struct i2c_au1550_data *priv)
314269 {
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;
329271
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);
332281
333282 /* Divide by 8 to get a 6.25 MHz clock. The later protocol
334283 * timings are based on this clock.
335284 */
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);
339288
340289 /* Set the protocol timer values. See Table 71 in the
341290 * Au1550 Data Book for standard timing values.
342291 */
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) | \
344293 PSC_SMBTMR_SET_PU(15) | PSC_SMBTMR_SET_SH(15) | \
345294 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));
348296
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();
354301
355− sp->psc_ctrl = PSC_CTRL_SUSPEND;
356− au_sync();
302+ WR(priv, PSC_CTRL, PSC_CTRL_SUSPEND);
357303 }
358304
359305 static void i2c_au1550_disable(struct i2c_au1550_data *priv)
360306 {
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);
366309 }
367310
368311 /*
@@ -396,9 +339,12 @@ i2c_au1550_probe(struct platform_device *pdev) · 27 unmodified lines
396339 goto out_mem;
397340 }
398341
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+ }
400347 priv->xfer_timeout = 200;
401− priv->ack_timeout = 200;
402348
403349 priv->adap.nr = pdev->id;
404350 priv->adap.algo = &au1550_algo;
@@ -406,8 +352,7 @@ i2c_au1550_probe(struct platform_device *pdev) · 1 unmodified line
406352 priv->adap.dev.parent = &pdev->dev;
407353 strlcpy(priv->adap.name, "Au1xxx PSC I2C", sizeof(priv->adap.name));
408354
409− /* Now, set up the PSC for SMBus PIO mode.
410− */
355+ /* Now, set up the PSC for SMBus PIO mode. */
411356 i2c_au1550_setup(priv);
412357
413358 ret = i2c_add_numbered_adapter(&priv->adap);
@@ -417,7 +362,8 @@ i2c_au1550_probe(struct platform_device *pdev) · 3 unmodified lines
417362 }
418363
419364 i2c_au1550_disable(priv);
420−
365+ iounmap(priv->psc_base);
366+out_map:
421367 release_resource(priv->ioarea);
422368 kfree(priv->ioarea);
423369 out_mem:
@@ -426,14 +372,14 @@ out: · 2 unmodified lines
426372 return ret;
427373 }
428374
429−static int __devexit
430−i2c_au1550_remove(struct platform_device *pdev)
375+static int __devexit i2c_au1550_remove(struct platform_device *pdev)
431376 {
432377 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
433378
434379 platform_set_drvdata(pdev, NULL);
435380 i2c_del_adapter(&priv->adap);
436381 i2c_au1550_disable(priv);
382+ iounmap(priv->psc_base);
437383 release_resource(priv->ioarea);
438384 kfree(priv->ioarea);
439385 kfree(priv);
@@ -441,49 +387,51 @@ i2c_au1550_remove(struct platform_device *pdev) · 1 unmodified line
441387 }
442388
443389 #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)
446391 {
447− struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
392+ struct i2c_au1550_data *priv = dev_get_drvdata(dev);
448393
449394 i2c_au1550_disable(priv);
450395
451396 return 0;
452397 }
453398
454−static int
455−i2c_au1550_resume(struct platform_device *pdev)
399+static int i2c_au1550_resume(struct device *dev)
456400 {
457− struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
401+ struct i2c_au1550_data *priv = dev_get_drvdata(dev);
458402
459403 i2c_au1550_setup(priv);
460404
461405 return 0;
462406 }
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+
463415 #else
464−#define i2c_au1550_suspend NULL
465−#define i2c_au1550_resume NULL
416+#define AU1XPSC_SMBUS_PMOPS NULL
466417 #endif
467418
468419 static struct platform_driver au1xpsc_smbus_driver = {
469420 .driver = {
470421 .name = "au1xpsc_smbus",
471422 .owner = THIS_MODULE,
423+ .pm = AU1XPSC_SMBUS_PMOPS,
472424 },
473425 .probe = i2c_au1550_probe,
474426 .remove = __devexit_p(i2c_au1550_remove),
475− .suspend = i2c_au1550_suspend,
476− .resume = i2c_au1550_resume,
477427 };
478428
479−static int __init
480−i2c_au1550_init(void)
429+static int __init i2c_au1550_init(void)
481430 {
482431 return platform_driver_register(&au1xpsc_smbus_driver);
483432 }
484433
485−static void __exit
486−i2c_au1550_exit(void)
434+static void __exit i2c_au1550_exit(void)
487435 {
488436 platform_driver_unregister(&au1xpsc_smbus_driver);
489437 }
drivers/i2c/busses/i2c-bfin-twi.c+2−2
@@ -631,7 +631,7 @@ static int i2c_bfin_twi_resume(struct platform_device *pdev) · 630 unmodified lines
631631 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
632632
633633 int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
634− IRQF_DISABLED, pdev->name, iface);
634+ 0, pdev->name, iface);
635635 if (rc) {
636636 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
637637 return -ENODEV;
@@ -702,7 +702,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) · 64 unmodified lines
702702 }
703703
704704 rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
705− IRQF_DISABLED, pdev->name, iface);
705+ 0, pdev->name, iface);
706706 if (rc) {
707707 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
708708 rc = -ENODEV;
drivers/i2c/busses/i2c-designware-core.crenamed from drivers/i2c/busses/i2c-designware.c+120−262
@@ -25,18 +25,15 @@ · 24 unmodified lines
2525 * ----------------------------------------------------------------------------
2626 *
2727 */
28−#include <linux/kernel.h>
29−#include <linux/module.h>
30−#include <linux/delay.h>
31−#include <linux/i2c.h>
3228 #include <linux/clk.h>
3329 #include <linux/errno.h>
34−#include <linux/sched.h>
3530 #include <linux/err.h>
31+#include <linux/i2c.h>
3632 #include <linux/interrupt.h>
37−#include <linux/platform_device.h>
3833 #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"
4037
4138 /*
4239 * Registers offset
@@ -68,15 +65,10 @@ · 25 unmodified lines
6865 #define DW_IC_STATUS 0x70
6966 #define DW_IC_TXFLR 0x74
7067 #define DW_IC_RXFLR 0x78
71−#define DW_IC_COMP_PARAM_1 0xf4
7268 #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
8072
8173 #define DW_IC_INTR_RX_UNDER 0x001
8274 #define DW_IC_INTR_RX_OVER 0x002
@@ -170,55 +162,23 @@ static char *abort_sources[] = { · 87 unmodified lines
170162 "lost arbitration",
171163 };
172164
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+}
222182
223183 static u32
224184 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
283243 * This function is called during I2C init function, and in case of timeout at
284244 * run time.
285245 */
286−static void i2c_dw_init(struct dw_i2c_dev *dev)
246+int i2c_dw_init(struct dw_i2c_dev *dev)
287247 {
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+ }
290266
291267 /* Disable the adapter */
292− writel(0, dev->base + DW_IC_ENABLE);
268+ dw_writel(dev, 0, DW_IC_ENABLE);
293269
294270 /* set standard and fast speed deviders for high/low periods */
295271
@@ -303,8 +279,8 @@ static void i2c_dw_init(struct dw_i2c_dev *dev) · 7 unmodified lines
303279 47, /* tLOW = 4.7 us */
304280 3, /* tf = 0.3 us */
305281 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);
308284 dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
309285
310286 /* Fast-mode */
@@ -317,18 +293,17 @@ static void i2c_dw_init(struct dw_i2c_dev *dev) · 6 unmodified lines
317293 13, /* tLOW = 1.3 us */
318294 3, /* tf = 0.3 us */
319295 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);
322298 dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
323299
324300 /* 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);
327303
328304 /* 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;
332307 }
333308
334309 /*
@@ -338,7 +313,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) · 3 unmodified lines
338313 {
339314 int timeout = TIMEOUT;
340315
341− while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
316+ while (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
342317 if (timeout <= 0) {
343318 dev_warn(dev->dev, "timeout waiting for bus ready\n");
344319 return -ETIMEDOUT;
@@ -356,24 +331,24 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) · 11 unmodified lines
356331 u32 ic_con;
357332
358333 /* Disable the adapter */
359− writel(0, dev->base + DW_IC_ENABLE);
334+ dw_writel(dev, 0, DW_IC_ENABLE);
360335
361336 /* 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);
363338
364339 /* 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);
366341 if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
367342 ic_con |= DW_IC_CON_10BITADDR_MASTER;
368343 else
369344 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);
371346
372347 /* Enable the adapter */
373− writel(1, dev->base + DW_IC_ENABLE);
348+ dw_writel(dev, 1, DW_IC_ENABLE);
374349
375350 /* 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);
377352 }
378353
379354 /*
@@ -382,7 +357,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) · 2 unmodified lines
382357 * messages into the tx buffer. Even if the size of i2c_msg data is
383358 * longer than the size of the tx buffer, it handles everything.
384359 */
385−static void
360+void
386361 i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
387362 {
388363 struct i2c_msg *msgs = dev->msgs;
@@ -420,15 +395,15 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) · 31 unmodified lines
420395 buf_len = msgs[dev->msg_write_idx].len;
421396 }
422397
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);
425400
426401 while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
427402 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);
429404 rx_limit--;
430405 } else
431− writel(*buf++, dev->base + DW_IC_DATA_CMD);
406+ dw_writel(dev, *buf++, DW_IC_DATA_CMD);
432407 tx_limit--; buf_len--;
433408 }
434409
@@ -453,7 +428,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) · 18 unmodified lines
453428 if (dev->msg_err)
454429 intr_mask = 0;
455430
456− writel(intr_mask, dev->base + DW_IC_INTR_MASK);
431+ dw_writel(dev, intr_mask, DW_IC_INTR_MASK);
457432 }
458433
459434 static void
@@ -477,10 +452,10 @@ i2c_dw_read(struct dw_i2c_dev *dev) · 17 unmodified lines
477452 buf = dev->rx_buf;
478453 }
479454
480− rx_valid = readl(dev->base + DW_IC_RXFLR);
455+ rx_valid = dw_readl(dev, DW_IC_RXFLR);
481456
482457 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);
484459
485460 if (len > 0) {
486461 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
518493 /*
519494 * Prepare controller for a transaction and call i2c_dw_xfer_msg
520495 */
521−static int
496+int
522497 i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
523498 {
524499 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
527502 dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
528503
529504 mutex_lock(&dev->lock);
505+ pm_runtime_get_sync(dev->dev);
530506
531507 INIT_COMPLETION(dev->cmd_complete);
532508 dev->msgs = msgs;
@@ -563,7 +539,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 30 unmodified lines
563539 /* no error */
564540 if (likely(!dev->cmd_err)) {
565541 /* Disable the adapter */
566− writel(0, dev->base + DW_IC_ENABLE);
542+ dw_writel(dev, 0, DW_IC_ENABLE);
567543 ret = num;
568544 goto done;
569545 }
@@ -576,19 +552,16 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 6 unmodified lines
576552 ret = -EIO;
577553
578554 done:
555+ pm_runtime_put(dev->dev);
579556 mutex_unlock(&dev->lock);
580557
581558 return ret;
582559 }
583560
584−static u32 i2c_dw_func(struct i2c_adapter *adap)
561+u32 i2c_dw_func(struct i2c_adapter *adap)
585562 {
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;
592565 }
593566
594567 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
601574 * in the IC_RAW_INTR_STAT register.
602575 *
603576 * That is,
604− * stat = readl(IC_INTR_STAT);
577+ * stat = dw_readl(IC_INTR_STAT);
605578 * 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);
607580 *
608581 * The raw version might be useful for debugging purposes.
609582 */
610− stat = readl(dev->base + DW_IC_INTR_STAT);
583+ stat = dw_readl(dev, DW_IC_INTR_STAT);
611584
612585 /*
613586 * Do not use the IC_CLR_INTR register to clear interrupts, or
614587 * 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).
616589 *
617590 * Instead, use the separately-prepared IC_CLR_* registers.
618591 */
619592 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);
621594 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);
623596 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);
625598 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);
627600 if (stat & DW_IC_INTR_TX_ABRT) {
628601 /*
629602 * The IC_TX_ABRT_SOURCE register is cleared whenever
630603 * the IC_CLR_TX_ABRT is read. Preserve it beforehand.
631604 */
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);
634607 }
635608 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);
637610 if (stat & DW_IC_INTR_ACTIVITY)
638− readl(dev->base + DW_IC_CLR_ACTIVITY);
611+ dw_readl(dev, DW_IC_CLR_ACTIVITY);
639612 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);
641614 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);
643616 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);
645618
646619 return stat;
647620 }
@@ -650,13 +623,19 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) · 2 unmodified lines
650623 * Interrupt service routine. This gets called whenever an I2C interrupt
651624 * occurs.
652625 */
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)
654627 {
655628 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;
657637
658638 stat = i2c_dw_read_clear_intrbits(dev);
659− dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
660639
661640 if (stat & DW_IC_INTR_TX_ABRT) {
662641 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
666645 * Anytime TX_ABRT is set, the contents of the tx/rx
667646 * buffers are flushed. Make sure to skip them.
668647 */
669− writel(0, dev->base + DW_IC_INTR_MASK);
648+ dw_writel(dev, 0, DW_IC_INTR_MASK);
670649 goto tx_aborted;
671650 }
672651
@@ -689,159 +668,38 @@ tx_aborted: · 16 unmodified lines
689668 return IRQ_HANDLED;
690669 }
691670
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)
698672 {
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);
798675 }
799676
800−static int __devexit dw_i2c_remove(struct platform_device *pdev)
677+u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev)
801678 {
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);
820680 }
821681
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);
824686
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+}
832691
833−static int __init dw_i2c_init_driver(void)
692+void i2c_dw_clear_int(struct dw_i2c_dev *dev)
834693 {
835− return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe);
694+ dw_readl(dev, DW_IC_CLR_INTR);
836695 }
837−module_init(dw_i2c_init_driver);
838696
839−static void __exit dw_i2c_exit_driver(void)
697+void i2c_dw_disable_int(struct dw_i2c_dev *dev)
840698 {
841− platform_driver_unregister(&dw_i2c_driver);
699+ dw_writel(dev, 0, DW_IC_INTR_MASK);
842700 }
843−module_exit(dw_i2c_exit_driver);
844701
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+}
drivers/i2c/busses/i2c-designware-core.h+105−0
@@ -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);
drivers/i2c/busses/i2c-designware-pcidrv.c+392−0
@@ -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");
drivers/i2c/busses/i2c-designware-platdrv.c+215−0
@@ -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");
drivers/i2c/busses/i2c-eg20t.c+196−74
@@ -64,6 +64,7 @@ · 63 unmodified lines
6464 #define TEN_BIT_ADDR_DEFAULT 0xF000
6565 #define TEN_BIT_ADDR_MASK 0xF0
6666 #define PCH_START 0x0020
67+#define PCH_RESTART 0x0004
6768 #define PCH_ESR_START 0x0001
6869 #define PCH_BUFF_START 0x1
6970 #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
273274 s32 timeout)
274275 {
275276 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;
276281
277282 /* 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);
279284 do {
280− if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
281− break;
282285 msleep(20);
286+ if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
287+ return 0;
283288 } while (ktime_lt(ktime_get(), ns_val));
284289
285290 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);
286293
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;
293295 }
294296
295297 /**
@@ -311,21 +313,19 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap) · 15 unmodified lines
311313 */
312314 static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap)
313315 {
314− s32 ret;
316+ long ret;
315317 ret = wait_event_timeout(pch_event,
316318 (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− }
321319
322320 if (ret == 0) {
323321 pch_err(adap, "timeout: %x\n", adap->pch_event_flag);
322+ adap->pch_event_flag = 0;
324323 return -ETIMEDOUT;
325324 }
326325
327326 if (adap->pch_event_flag & I2C_ERROR_MASK) {
328327 pch_err(adap, "error bits set: %x\n", adap->pch_event_flag);
328+ adap->pch_event_flag = 0;
329329 return -EIO;
330330 }
331331
@@ -394,6 +394,7 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, · 62 unmodified lines
394394 u32 addr_2_msb;
395395 u32 addr_8_lsb;
396396 s32 wrcount;
397+ s32 rtn;
397398 void __iomem *p = adap->pch_base_address;
398399
399400 length = msgs->len;
@@ -412,15 +413,29 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, · 12 unmodified lines
412413 }
413414
414415 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;
416417 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
417418 if (first)
418419 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+ }
421428 addr_8_lsb = (addr & I2C_ADDR_MSK);
422429 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 */
424439 pch_i2c_stop(adap);
425440 return -ETIME;
426441 }
@@ -431,30 +446,51 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, · 4 unmodified lines
431446 pch_i2c_start(adap);
432447 }
433448
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+ }
441466
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]);
444471
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");
446477 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;
447486 }
487+ }
448488
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)
455491 pch_i2c_stop(adap);
456− return -EIO;
457− }
492+ else
493+ pch_i2c_repstart(adap);
458494
459495 pch_dbg(adap, "return=%d\n", wrcount);
460496
@@ -483,6 +519,19 @@ static void pch_i2c_sendnack(struct i2c_algo_pch_data *adap) · 22 unmodified lines
483519 pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_ACK);
484520 }
485521
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+
486535 /**
487536 * pch_i2c_readbytes() - read data from I2C bus in normal mode.
488537 * @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
500549 u32 length;
501550 u32 addr;
502551 u32 addr_2_msb;
552+ u32 addr_8_lsb;
503553 void __iomem *p = adap->pch_base_address;
554+ s32 rtn;
504555
505556 length = msgs->len;
506557 buf = msgs->buf;
@@ -515,9 +566,55 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, · 8 unmodified lines
515566 }
516567
517568 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);
519570 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
571+ if (first)
572+ pch_i2c_start(adap);
520573
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+ }
521618 } else {
522619 /* 7 address bits + R/W bit */
523620 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
528625 if (first)
529626 pch_i2c_start(adap);
530627
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+ }
534645
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 */
538649
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);
544655
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);
548659
549− if (loop != 1)
550− read_index++;
660+ if (loop != 1)
661+ read_index++;
551662
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;
555669 }
556− } /* end for */
670+ } else { /* wait-event timeout */
671+ pch_i2c_stop(adap);
672+ return -ETIME;
673+ }
557674
558− pch_i2c_sendnack(adap);
675+ } /* end for */
559676
560− buf[read_index] = ioread32(p + PCH_I2CDR);
677+ pch_i2c_sendnack(adap);
561678
562− if (length != 1)
563− read_index++;
679+ buf[read_index] = ioread32(p + PCH_I2CDR); /* Read final - 1 */
564680
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++;
570683
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;
575690 }
576−
691+ } else { /* wait-event timeout */
692+ pch_i2c_stop(adap);
693+ return -ETIME;
577694 }
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;
581703 }
582704
583705 return count;
drivers/i2c/busses/i2c-highlander.c+1−1
@@ -387,7 +387,7 @@ static int __devinit highlander_i2c_probe(struct platform_device *pdev) · 386 unmodified lines
387387 dev->irq = 0;
388388
389389 if (dev->irq) {
390− ret = request_irq(dev->irq, highlander_i2c_irq, IRQF_DISABLED,
390+ ret = request_irq(dev->irq, highlander_i2c_irq, 0,
391391 pdev->name, dev);
392392 if (unlikely(ret))
393393 goto err_unmap;
drivers/i2c/busses/i2c-imx.c+22−24
@@ -48,6 +48,9 @@ · 47 unmodified lines
4848 #include <linux/platform_device.h>
4949 #include <linux/clk.h>
5050 #include <linux/slab.h>
51+#include <linux/of.h>
52+#include <linux/of_device.h>
53+#include <linux/of_i2c.h>
5154
5255 #include <mach/irqs.h>
5356 #include <mach/hardware.h>
@@ -125,6 +128,11 @@ struct imx_i2c_struct { · 71 unmodified lines
125128 unsigned int ifdr; /* IMX_I2C_IFDR */
126129 };
127130
131+static const struct of_device_id i2c_imx_dt_ids[] = {
132+ { .compatible = "fsl,imx1-i2c", },
133+ { /* sentinel */ }
134+};
135+
128136 /** Functions for IMX I2C adapter driver ***************************************
129137 *******************************************************************************/
130138
@@ -466,10 +474,10 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 335 unmodified lines
466474 {
467475 struct imx_i2c_struct *i2c_imx;
468476 struct resource *res;
469− struct imxi2c_platform_data *pdata;
477+ struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
470478 void __iomem *base;
471479 resource_size_t res_size;
472− int irq;
480+ int irq, bitrate;
473481 int ret;
474482
475483 dev_dbg(&pdev->dev, "<%s>\n", __func__);
@@ -485,19 +493,11 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 9 unmodified lines
485493 return -ENOENT;
486494 }
487495
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−
496496 res_size = resource_size(res);
497497
498498 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;
501501 }
502502
503503 base = ioremap(res->start, res_size);
@@ -520,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 16 unmodified lines
520520 i2c_imx->adapter.algo = &i2c_imx_algo;
521521 i2c_imx->adapter.dev.parent = &pdev->dev;
522522 i2c_imx->adapter.nr = pdev->id;
523+ i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
523524 i2c_imx->irq = irq;
524525 i2c_imx->base = base;
525526 i2c_imx->res = res;
@@ -546,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev) · 20 unmodified lines
546547 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx);
547548
548549 /* 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);
553556
554557 /* Set up chip registers to defaults */
555558 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
562565 goto fail5;
563566 }
564567
568+ of_i2c_register_devices(&i2c_imx->adapter);
569+
565570 /* Set up platform driver data */
566571 platform_set_drvdata(pdev, i2c_imx);
567572
@@ -586,16 +591,12 @@ fail2: · 18 unmodified lines
586591 iounmap(base);
587592 fail1:
588593 release_mem_region(res->start, resource_size(res));
589−fail0:
590− if (pdata && pdata->exit)
591− pdata->exit(&pdev->dev);
592594 return ret; /* Return error number */
593595 }
594596
595597 static int __exit i2c_imx_remove(struct platform_device *pdev)
596598 {
597599 struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
598− struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
599600
600601 /* remove adapter */
601602 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
611612 writeb(0, i2c_imx->base + IMX_I2C_I2CR);
612613 writeb(0, i2c_imx->base + IMX_I2C_I2SR);
613614
614− /* Shut down hardware */
615− if (pdata && pdata->exit)
616− pdata->exit(&pdev->dev);
617−
618615 clk_put(i2c_imx->clk);
619616
620617 iounmap(i2c_imx->base);
@@ -628,6 +625,7 @@ static struct platform_driver i2c_imx_driver = { · 7 unmodified lines
628625 .driver = {
629626 .name = DRIVER_NAME,
630627 .owner = THIS_MODULE,
628+ .of_match_table = i2c_imx_dt_ids,
631629 }
632630 };
633631
drivers/i2c/busses/i2c-nomadik.c+47−44
@@ -63,11 +63,11 @@ · 62 unmodified lines
6363 /* Master controller (MCR) register */
6464 #define I2C_MCR_OP (0x1 << 0) /* Operation */
6565 #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 */
6767 #define I2C_MCR_SB (0x1 << 11) /* Extended address */
6868 #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 */
7171
7272 /* Status register (SR) */
7373 #define I2C_SR_OP (0x3 << 0) /* Operation */
@@ -77,7 +77,7 @@ · 3 unmodified lines
7777 #define I2C_SR_LENGTH (0x7ff << 9) /* Transfer length */
7878
7979 /* Interrupt mask set/clear (IMSCR) bits */
80−#define I2C_IT_TXFE (0x1 << 0)
80+#define I2C_IT_TXFE (0x1 << 0)
8181 #define I2C_IT_TXFNE (0x1 << 1)
8282 #define I2C_IT_TXFF (0x1 << 2)
8383 #define I2C_IT_TXFOVR (0x1 << 3)
@@ -135,31 +135,31 @@ struct i2c_nmk_client { · 51 unmodified lines
135135 };
136136
137137 /**
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.
151151 */
152152 struct nmk_i2c_dev {
153153 struct platform_device *pdev;
154− struct i2c_adapter adap;
155− int irq;
154+ struct i2c_adapter adap;
155+ int irq;
156156 void __iomem *virtbase;
157157 struct clk *clk;
158158 struct nmk_i2c_controller cfg;
159159 struct i2c_nmk_client cli;
160− int stop;
160+ int stop;
161161 struct completion xfer_complete;
162− int result;
162+ int result;
163163 struct regulator *regulator;
164164 bool busy;
165165 };
@@ -217,8 +217,9 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev) · 51 unmodified lines
217217 }
218218 }
219219
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);
222223
223224 return -ETIMEDOUT;
224225 }
@@ -270,7 +271,7 @@ exit: · 45 unmodified lines
270271 }
271272
272273 /* 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)
274275
275276 /**
276277 * 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
363364 * and high speed (up to 3.4 Mb/s)
364365 */
365366 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");
368369 brcr2 = i2c_clk/(100000 * 2) & 0xffff;
369370 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR);
370371 writel(I2C_FREQ_MODE_STANDARD << 4,
@@ -423,7 +424,7 @@ static int read_i2c(struct nmk_i2c_dev *dev) · 52 unmodified lines
423424
424425 if (timeout < 0) {
425426 dev_err(&dev->pdev->dev,
426− "wait_for_completion_timeout"
427+ "wait_for_completion_timeout "
427428 "returned %d waiting for event\n", timeout);
428429 status = timeout;
429430 }
@@ -556,8 +557,8 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) · 126 unmodified lines
556557 if (((i2c_sr >> 2) & 0x3) == 0x3) {
557558 /* get the abort cause */
558559 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) ?
561562 "unknown reason" :
562563 abort_causes[cause]);
563564 }
@@ -582,13 +583,13 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) · 18 unmodified lines
582583 *
583584 * NOTE:
584585 * 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
592593 * idx = 0;
593594 * msg[0].addr = client->addr;
594595 * msg[0].flags = 0x0;
@@ -644,8 +645,8 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, · 49 unmodified lines
644645
645646 for (i = 0; i < num_msgs; i++) {
646647 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");
649650
650651 status = -EINVAL;
651652 goto out;
@@ -789,8 +790,9 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) · 137 unmodified lines
789790
790791 if (dev->cli.count) {
791792 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);
794796 (void) init_hw(dev);
795797 }
796798 complete(&dev->xfer_complete);
@@ -923,7 +925,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) · 126 unmodified lines
923925 }
924926
925927 if (request_mem_region(res->start, resource_size(res),
926− DRIVER_NAME "I/O region") == NULL) {
928+ DRIVER_NAME "I/O region") == NULL) {
927929 ret = -EBUSY;
928930 goto err_no_region;
929931 }
@@ -935,7 +937,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) · 5 unmodified lines
935937 }
936938
937939 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,
939941 DRIVER_NAME, dev);
940942 if (ret) {
941943 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
980982
981983 i2c_set_adapdata(adap, dev);
982984
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);
985988
986989 ret = i2c_add_numbered_adapter(adap);
987990 if (ret) {
drivers/i2c/busses/i2c-nuc900.c+1−1
@@ -610,7 +610,7 @@ static int __devinit nuc900_i2c_probe(struct platform_device *pdev) · 609 unmodified lines
610610 goto err_iomap;
611611 }
612612
613− ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_DISABLED | IRQF_SHARED,
613+ ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_SHARED,
614614 dev_name(&pdev->dev), i2c);
615615
616616 if (ret != 0) {
drivers/i2c/busses/i2c-omap.c+92−72
@@ -42,12 +42,12 @@ · 41 unmodified lines
4242 #include <linux/pm_runtime.h>
4343
4444 /* I2C controller revisions */
45−#define OMAP_I2C_REV_2 0x20
45+#define OMAP_I2C_OMAP1_REV_2 0x20
4646
4747 /* I2C controller revisions present on specific hardware */
4848 #define OMAP_I2C_REV_ON_2430 0x36
4949 #define OMAP_I2C_REV_ON_3430 0x3C
50−#define OMAP_I2C_REV_ON_4430 0x40
50+#define OMAP_I2C_REV_ON_3530_4430 0x40
5151
5252 /* timeout waiting for the controller to respond */
5353 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
@@ -72,11 +72,12 @@ enum { · 18 unmodified lines
7272 OMAP_I2C_SCLH_REG,
7373 OMAP_I2C_SYSTEST_REG,
7474 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,
8081 };
8182
8283 /* I2C Interrupt Enable Register (OMAP_I2C_IE): */
@@ -193,7 +194,6 @@ struct omap_i2c_dev { · 110 unmodified lines
193194 */
194195 u8 rev;
195196 unsigned b_hw:1; /* bad h/w fixes */
196− unsigned idle:1;
197197 u16 iestate; /* Saved interrupt register */
198198 u16 pscstate;
199199 u16 scllstate;
@@ -204,7 +204,7 @@ struct omap_i2c_dev { · 4 unmodified lines
204204 u16 errata;
205205 };
206206
207−static const u8 reg_map[] = {
207+static const u8 reg_map_ip_v1[] = {
208208 [OMAP_I2C_REV_REG] = 0x00,
209209 [OMAP_I2C_IE_REG] = 0x01,
210210 [OMAP_I2C_STAT_REG] = 0x02,
@@ -225,7 +225,7 @@ static const u8 reg_map[] = { · 14 unmodified lines
225225 [OMAP_I2C_BUFSTAT_REG] = 0x10,
226226 };
227227
228−static const u8 omap4_reg_map[] = {
228+static const u8 reg_map_ip_v2[] = {
229229 [OMAP_I2C_REV_REG] = 0x04,
230230 [OMAP_I2C_IE_REG] = 0x2c,
231231 [OMAP_I2C_STAT_REG] = 0x28,
@@ -244,11 +244,11 @@ static const u8 omap4_reg_map[] = { · 12 unmodified lines
244244 [OMAP_I2C_SCLH_REG] = 0xb8,
245245 [OMAP_I2C_SYSTEST_REG] = 0xbC,
246246 [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,
252252 };
253253
254254 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
266266
267267 static void omap_i2c_unidle(struct omap_i2c_dev *dev)
268268 {
269− struct platform_device *pdev;
270269 struct omap_i2c_bus_platform_data *pdata;
271270
272− WARN_ON(!dev->idle);
271+ pdata = dev->dev->platform_data;
273272
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) {
280274 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
281275 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate);
282276 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
286280 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate);
287281 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
288282 }
289− dev->idle = 0;
290283
291284 /*
292285 * 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
298291
299292 static void omap_i2c_idle(struct omap_i2c_dev *dev)
300293 {
301− struct platform_device *pdev;
302294 struct omap_i2c_bus_platform_data *pdata;
303295 u16 iv;
304296
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;
309298
310299 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);
313302 else
314303 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
315304
316− if (dev->rev < OMAP_I2C_REV_2) {
305+ if (dev->rev < OMAP_I2C_OMAP1_REV_2) {
317306 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
318307 } else {
319308 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate);
320309
321− /* Flush posted write before the dev->idle store occurs */
310+ /* Flush posted write */
322311 omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
323312 }
324− dev->idle = 1;
325−
326− pm_runtime_put_sync(&pdev->dev);
327313 }
328314
329315 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
334320 unsigned long timeout;
335321 unsigned long internal_clk = 0;
336322 struct clk *fclk;
323+ struct omap_i2c_bus_platform_data *pdata;
324+
325+ pdata = dev->dev->platform_data;
337326
338− if (dev->rev >= OMAP_I2C_REV_2) {
327+ if (dev->rev >= OMAP_I2C_OMAP1_REV_2) {
339328 /* Disable I2C controller before soft reset */
340329 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG,
341330 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
378367 * REVISIT: Some wkup sources might not be needed.
379368 */
380369 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);
382372 }
383373 }
384374 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
385375
386− if (cpu_class_is_omap1()) {
376+ if (pdata->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) {
387377 /*
388378 * The I2C functional clock is the armxor_ck, so there's
389379 * 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
407397 psc = fclk_rate / 12000000;
408398 }
409399
410− if (!(cpu_class_is_omap1() || cpu_is_omap2420())) {
400+ if (!(pdata->flags & OMAP_I2C_FLAG_SIMPLE_CLOCK)) {
411401
412402 /*
413403 * 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
415405 * to get longer filter period for better noise suppression.
416406 * The filter is iclk (fclk for HS) period.
417407 */
418− if (dev->speed > 400 || cpu_is_omap2430())
408+ if (dev->speed > 400 ||
409+ pdata->flags & OMAP_I2C_FLAG_FORCE_19200_INT_CLK)
419410 internal_clk = 19200;
420411 else if (dev->speed > 100)
421412 internal_clk = 9600;
@@ -484,7 +475,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 62 unmodified lines
484475
485476 dev->errata = 0;
486477
487− if (cpu_is_omap2430() || cpu_is_omap34xx())
478+ if (pdata->flags & OMAP_I2C_FLAG_APPLY_ERRATA_I207)
488479 dev->errata |= I2C_OMAP_ERRATA_I207;
489480
490481 /* Enable interrupts */
@@ -493,7 +484,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) · 2 unmodified lines
493484 OMAP_I2C_IE_AL) | ((dev->fifo_size) ?
494485 (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
495486 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) {
497488 dev->pscstate = psc;
498489 dev->scllstate = scll;
499490 dev->sclhstate = sclh;
@@ -642,7 +633,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 142 unmodified lines
642633 int i;
643634 int r;
644635
645− omap_i2c_unidle(dev);
636+ pm_runtime_get_sync(dev->dev);
646637
647638 r = omap_i2c_wait_for_bb(dev);
648639 if (r < 0)
@@ -665,7 +656,7 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · 16 unmodified lines
665656
666657 omap_i2c_wait_for_bb(dev);
667658 out:
668− omap_i2c_idle(dev);
659+ pm_runtime_put(dev->dev);
669660 return r;
670661 }
671662
@@ -720,12 +711,12 @@ static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat) · 48 unmodified lines
720711 #ifdef CONFIG_ARCH_OMAP15XX
721712
722713 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)
724715 {
725716 struct omap_i2c_dev *dev = dev_id;
726717 u16 iv, w;
727718
728− if (dev->idle)
719+ if (pm_runtime_suspended(dev->dev))
729720 return IRQ_NONE;
730721
731722 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
774765 return IRQ_HANDLED;
775766 }
776767 #else
777−#define omap_i2c_rev1_isr NULL
768+#define omap_i2c_omap1_isr NULL
778769 #endif
779770
780771 /*
@@ -813,8 +804,11 @@ omap_i2c_isr(int this_irq, void *dev_id) · 32 unmodified lines
813804 u16 bits;
814805 u16 stat, w;
815806 int err, count = 0;
807+ struct omap_i2c_bus_platform_data *pdata;
816808
817− if (dev->idle)
809+ pdata = dev->dev->platform_data;
810+
811+ if (pm_runtime_suspended(dev->dev))
818812 return IRQ_NONE;
819813
820814 bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
@@ -881,8 +875,8 @@ complete: · 60 unmodified lines
881875 * Data reg in 2430, omap3 and
882876 * omap4 is 8 bit wide
883877 */
884− if (cpu_class_is_omap1() ||
885− cpu_is_omap2420()) {
878+ if (pdata->flags &
879+ OMAP_I2C_FLAG_16BIT_DATA_REG) {
886880 if (dev->buf_len) {
887881 *dev->buf++ = w >> 8;
888882 dev->buf_len--;
@@ -924,8 +918,8 @@ complete: · 35 unmodified lines
924918 * Data reg in 2430, omap3 and
925919 * omap4 is 8 bit wide
926920 */
927− if (cpu_class_is_omap1() ||
928− cpu_is_omap2420()) {
921+ if (pdata->flags &
922+ OMAP_I2C_FLAG_16BIT_DATA_REG) {
929923 if (dev->buf_len) {
930924 w |= *dev->buf++ << 8;
931925 dev->buf_len--;
@@ -1016,7 +1010,6 @@ omap_i2c_probe(struct platform_device *pdev) · 84 unmodified lines
10161010 }
10171011
10181012 dev->speed = speed;
1019− dev->idle = 1;
10201013 dev->dev = &pdev->dev;
10211014 dev->irq = irq->start;
10221015 dev->base = ioremap(mem->start, resource_size(mem));
@@ -1027,27 +1020,22 @@ omap_i2c_probe(struct platform_device *pdev) · 4 unmodified lines
10271020
10281021 platform_set_drvdata(pdev, dev);
10291022
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;
10361024
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;
10391027 else
1040− dev->regs = (u8 *) reg_map;
1028+ dev->regs = (u8 *)reg_map_ip_v1;
10411029
1042− pm_runtime_enable(&pdev->dev);
1043− omap_i2c_unidle(dev);
1030+ pm_runtime_enable(dev->dev);
1031+ pm_runtime_get_sync(dev->dev);
10441032
10451033 dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
10461034
10471035 if (dev->rev <= OMAP_I2C_REV_ON_3430)
10481036 dev->errata |= I2C_OMAP3_1P153;
10491037
1050− if (!(cpu_class_is_omap1() || cpu_is_omap2420())) {
1038+ if (!(pdata->flags & OMAP_I2C_FLAG_NO_FIFO)) {
10511039 u16 s;
10521040
10531041 /* Set up the fifo size - Get total size */
@@ -1059,7 +1047,7 @@ omap_i2c_probe(struct platform_device *pdev) · 5 unmodified lines
10591047 * size. This is to ensure that we can handle the status on int
10601048 * call back latencies.
10611049 */
1062− if (dev->rev >= OMAP_I2C_REV_ON_4430) {
1050+ if (dev->rev >= OMAP_I2C_REV_ON_3530_4430) {
10631051 dev->fifo_size = 0;
10641052 dev->b_hw = 0; /* Disable hardware fixes */
10651053 } else {
@@ -1075,7 +1063,8 @@ omap_i2c_probe(struct platform_device *pdev) · 9 unmodified lines
10751063 /* reset ASAP, clearing any IRQs */
10761064 omap_i2c_init(dev);
10771065
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;
10791068 r = request_irq(dev->irq, isr, 0, pdev->name, dev);
10801069
10811070 if (r) {
@@ -1083,10 +1072,10 @@ omap_i2c_probe(struct platform_device *pdev) · 1 unmodified line
10831072 goto err_unuse_clocks;
10841073 }
10851074
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);
10881077
1089− omap_i2c_idle(dev);
1078+ pm_runtime_put(dev->dev);
10901079
10911080 adap = &dev->adapter;
10921081 i2c_set_adapdata(adap, dev);
@@ -1110,7 +1099,7 @@ err_free_irq: · 17 unmodified lines
11101099 free_irq(dev->irq, dev);
11111100 err_unuse_clocks:
11121101 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
1113− omap_i2c_idle(dev);
1102+ pm_runtime_put(dev->dev);
11141103 iounmap(dev->base);
11151104 err_free_mem:
11161105 platform_set_drvdata(pdev, NULL);
@@ -1139,12 +1128,43 @@ omap_i2c_remove(struct platform_device *pdev) · 22 unmodified lines
11391128 return 0;
11401129 }
11411130
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+
11421161 static struct platform_driver omap_i2c_driver = {
11431162 .probe = omap_i2c_probe,
11441163 .remove = omap_i2c_remove,
11451164 .driver = {
11461165 .name = "omap_i2c",
11471166 .owner = THIS_MODULE,
1167+ .pm = OMAP_I2C_PM_OPS,
11481168 },
11491169 };
11501170
drivers/i2c/busses/i2c-pmcmsp.c+1−1
@@ -306,7 +306,7 @@ static int __devinit pmcmsptwi_probe(struct platform_device *pldev) · 305 unmodified lines
306306 pmcmsptwi_data.irq = platform_get_irq(pldev, 0);
307307 if (pmcmsptwi_data.irq) {
308308 rc = request_irq(pmcmsptwi_data.irq, &pmcmsptwi_interrupt,
309− IRQF_SHARED | IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
309+ IRQF_SHARED | IRQF_SAMPLE_RANDOM,
310310 pldev->name, &pmcmsptwi_data);
311311 if (rc == 0) {
312312 /*
drivers/i2c/busses/i2c-s3c2410.c+121−9
@@ -35,6 +35,8 @@ · 34 unmodified lines
3535 #include <linux/cpufreq.h>
3636 #include <linux/slab.h>
3737 #include <linux/io.h>
38+#include <linux/of_i2c.h>
39+#include <linux/of_gpio.h>
3840
3941 #include <asm/irq.h>
4042
@@ -78,6 +80,8 @@ struct s3c24xx_i2c { · 37 unmodified lines
7880 struct resource *ioarea;
7981 struct i2c_adapter adap;
8082
83+ struct s3c2410_platform_i2c *pdata;
84+ int gpios[2];
8185 #ifdef CONFIG_CPU_FREQ
8286 struct notifier_block freq_transition;
8387 #endif
@@ -95,6 +99,12 @@ static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) · 11 unmodified lines
9599 struct platform_device *pdev = to_platform_device(i2c->dev);
96100 enum s3c24xx_i2c_type type;
97101
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+
98108 type = platform_get_device_id(pdev)->driver_data;
99109 return type == TYPE_S3C2440;
100110 }
@@ -625,7 +635,7 @@ static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted, · 524 unmodified lines
625635
626636 static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
627637 {
628− struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data;
638+ struct s3c2410_platform_i2c *pdata = i2c->pdata;
629639 unsigned long clkin = clk_get_rate(i2c->clk);
630640 unsigned int divs, div1;
631641 unsigned long target_frequency;
@@ -741,6 +751,49 @@ static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) · 109 unmodified lines
741751 }
742752 #endif
743753
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+
744797 /* s3c24xx_i2c_init
745798 *
746799 * 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
754807
755808 /* get the plafrom data */
756809
757− pdata = i2c->dev->platform_data;
810+ pdata = i2c->pdata;
758811
759812 /* inititalise the gpio */
760813
761814 if (pdata->cfg_gpio)
762815 pdata->cfg_gpio(to_platform_device(i2c->dev));
816+ else
817+ if (s3c24xx_i2c_parse_dt_gpio(i2c))
818+ return -EINVAL;
763819
764820 /* write slave address */
765821
@@ -785,6 +841,34 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) · 19 unmodified lines
785841 return 0;
786842 }
787843
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+
788872 /* s3c24xx_i2c_probe
789873 *
790874 * 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
793877 static int s3c24xx_i2c_probe(struct platform_device *pdev)
794878 {
795879 struct s3c24xx_i2c *i2c;
796− struct s3c2410_platform_i2c *pdata;
880+ struct s3c2410_platform_i2c *pdata = NULL;
797881 struct resource *res;
798882 int ret;
799883
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+ }
804890 }
805891
806892 i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL);
@@ -809,6 +895,17 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 2 unmodified lines
809895 return -ENOMEM;
810896 }
811897
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+
812909 strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
813910 i2c->adap.owner = THIS_MODULE;
814911 i2c->adap.algo = &s3c24xx_i2c_algorithm;
@@ -883,7 +980,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 68 unmodified lines
883980 goto err_iomap;
884981 }
885982
886− ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED,
983+ ret = request_irq(i2c->irq, s3c24xx_i2c_irq, 0,
887984 dev_name(&pdev->dev), i2c);
888985
889986 if (ret != 0) {
@@ -903,7 +1000,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 13 unmodified lines
9031000 * being bus 0.
9041001 */
9051002
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;
9071005
9081006 ret = i2c_add_numbered_adapter(&i2c->adap);
9091007 if (ret < 0) {
@@ -911,6 +1009,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) · 1 unmodified line
9111009 goto err_cpufreq;
9121010 }
9131011
1012+ of_i2c_register_devices(&i2c->adap);
9141013 platform_set_drvdata(pdev, i2c);
9151014
9161015 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
9591058 iounmap(i2c->regs);
9601059
9611060 release_resource(i2c->ioarea);
1061+ s3c24xx_i2c_dt_gpio_free(i2c);
9621062 kfree(i2c->ioarea);
9631063 kfree(i2c);
9641064
@@ -1012,6 +1112,17 @@ static struct platform_device_id s3c24xx_driver_ids[] = { · 47 unmodified lines
10121112 };
10131113 MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
10141114
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+
10151126 static struct platform_driver s3c24xx_i2c_driver = {
10161127 .probe = s3c24xx_i2c_probe,
10171128 .remove = s3c24xx_i2c_remove,
@@ -1020,6 +1131,7 @@ static struct platform_driver s3c24xx_i2c_driver = { · 2 unmodified lines
10201131 .owner = THIS_MODULE,
10211132 .name = "s3c-i2c",
10221133 .pm = S3C24XX_DEV_PM_OPS,
1134+ .of_match_table = s3c24xx_i2c_match,
10231135 },
10241136 };
10251137
drivers/i2c/busses/i2c-sh7760.c+1−1
@@ -502,7 +502,7 @@ static int __devinit sh7760_i2c_probe(struct platform_device *pdev) · 501 unmodified lines
502502 }
503503 OUT32(id, I2CCCR, ret);
504504
505− if (request_irq(id->irq, sh7760_i2c_irq, IRQF_DISABLED,
505+ if (request_irq(id->irq, sh7760_i2c_irq, 0,
506506 SH7760_I2C_DEVNAME, id)) {
507507 dev_err(&pdev->dev, "cannot get irq %d\n", id->irq);
508508 ret = -EBUSY;
drivers/i2c/busses/i2c-sh_mobile.c+1−1
@@ -543,7 +543,7 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) · 542 unmodified lines
543543
544544 while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
545545 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,
547547 dev_name(&dev->dev), dev)) {
548548 for (n--; n >= res->start; n--)
549549 free_irq(n, dev);
drivers/i2c/busses/i2c-stu300.c+1−1
@@ -916,7 +916,7 @@ stu300_probe(struct platform_device *pdev) · 915 unmodified lines
916916 }
917917
918918 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,
920920 NAME, dev)) {
921921 ret = -EIO;
922922 goto err_no_irq;
drivers/i2c/busses/i2c-tegra.c+1−1
@@ -566,7 +566,7 @@ static int tegra_i2c_probe(struct platform_device *pdev) · 565 unmodified lines
566566 struct clk *clk;
567567 struct clk *i2c_clk;
568568 const unsigned int *prop;
569− void *base;
569+ void __iomem *base;
570570 int irq;
571571 int ret = 0;
572572
include/linux/i2c-omap.h+2−3
@@ -32,10 +32,9 @@ · 31 unmodified lines
3232
3333 struct omap_i2c_bus_platform_data {
3434 u32 clkrate;
35+ u32 rev;
36+ u32 flags;
3537 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);
3938 };
4039
4140 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t