diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 13:40:57 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 13:40:57 -0500 |
commit | fe3c560b8a22cb28e54fe8950abef38e88d75831 (patch) | |
tree | 88db8742152559e1840832970066816e72a9009b | |
parent | d20056032e20061db6583f517a4d3ea4492a94f1 (diff) | |
parent | dad92924ea4c9167e64a2835ec9310c73570b10b (diff) |
Merge branch 'for-linus/i2c-2638' of git://git.fluff.org/bjdooks/linux
* 'for-linus/i2c-2638' of git://git.fluff.org/bjdooks/linux:
i2c-bfin-twi: move setup to the earlier subsys initcall
i2c-bfin-twi: handle faulty slave devices better
i2c-mv64xxx: send repeated START between messages in xfer
i2c-nomadik: fix regression on adapter name
i2c-omap: Set latency requirements only once for several messages
i2c-eg20t: add driver for Intel EG20T
i2c-ocores: add some device tree documentation
i2c-ocores: Use devres for resource allocation
i2c-ocores: Adapt for device tree
i2c-iop3xx: add iomem annotation
-rw-r--r-- | drivers/i2c/busses/Kconfig | 8 | ||||
-rw-r--r-- | drivers/i2c/busses/Makefile | 1 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-bfin-twi.c | 24 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-eg20t.c | 900 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-iop3xx.c | 6 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-iop3xx.h | 2 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-mv64xxx.c | 45 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-nomadik.c | 6 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-ocores.c | 145 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 10 |
10 files changed, 1086 insertions, 61 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 3a6321cb8030..113505a6434e 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -638,6 +638,14 @@ config I2C_XILINX | |||
638 | This driver can also be built as a module. If so, the module | 638 | This driver can also be built as a module. If so, the module |
639 | will be called xilinx_i2c. | 639 | will be called xilinx_i2c. |
640 | 640 | ||
641 | config I2C_EG20T | ||
642 | tristate "PCH I2C of Intel EG20T" | ||
643 | depends on PCI | ||
644 | help | ||
645 | This driver is for PCH(Platform controller Hub) I2C of EG20T which | ||
646 | is an IOH(Input/Output Hub) for x86 embedded processor. | ||
647 | This driver can access PCH I2C bus device. | ||
648 | |||
641 | comment "External I2C/SMBus adapter drivers" | 649 | comment "External I2C/SMBus adapter drivers" |
642 | 650 | ||
643 | config I2C_PARPORT | 651 | config I2C_PARPORT |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 84cb16ae6f9e..9d2d0ec7fb23 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -61,6 +61,7 @@ obj-$(CONFIG_I2C_STU300) += i2c-stu300.o | |||
61 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o | 61 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o |
62 | obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o | 62 | obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o |
63 | obj-$(CONFIG_I2C_XILINX) += i2c-xiic.o | 63 | obj-$(CONFIG_I2C_XILINX) += i2c-xiic.o |
64 | obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o | ||
64 | 65 | ||
65 | # External I2C/SMBus adapter drivers | 66 | # External I2C/SMBus adapter drivers |
66 | obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o | 67 | obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o |
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c index fb26e5c67515..52b545a795f2 100644 --- a/drivers/i2c/busses/i2c-bfin-twi.c +++ b/drivers/i2c/busses/i2c-bfin-twi.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/completion.h> | 20 | #include <linux/completion.h> |
21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
22 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
23 | #include <linux/delay.h> | ||
23 | 24 | ||
24 | #include <asm/blackfin.h> | 25 | #include <asm/blackfin.h> |
25 | #include <asm/portmux.h> | 26 | #include <asm/portmux.h> |
@@ -159,6 +160,27 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface, | |||
159 | if (mast_stat & BUFWRERR) | 160 | if (mast_stat & BUFWRERR) |
160 | dev_dbg(&iface->adap.dev, "Buffer Write Error\n"); | 161 | dev_dbg(&iface->adap.dev, "Buffer Write Error\n"); |
161 | 162 | ||
163 | /* Faulty slave devices, may drive SDA low after a transfer | ||
164 | * finishes. To release the bus this code generates up to 9 | ||
165 | * extra clocks until SDA is released. | ||
166 | */ | ||
167 | |||
168 | if (read_MASTER_STAT(iface) & SDASEN) { | ||
169 | int cnt = 9; | ||
170 | do { | ||
171 | write_MASTER_CTL(iface, SCLOVR); | ||
172 | udelay(6); | ||
173 | write_MASTER_CTL(iface, 0); | ||
174 | udelay(6); | ||
175 | } while ((read_MASTER_STAT(iface) & SDASEN) && cnt--); | ||
176 | |||
177 | write_MASTER_CTL(iface, SDAOVR | SCLOVR); | ||
178 | udelay(6); | ||
179 | write_MASTER_CTL(iface, SDAOVR); | ||
180 | udelay(6); | ||
181 | write_MASTER_CTL(iface, 0); | ||
182 | } | ||
183 | |||
162 | /* If it is a quick transfer, only address without data, | 184 | /* If it is a quick transfer, only address without data, |
163 | * not an err, return 1. | 185 | * not an err, return 1. |
164 | */ | 186 | */ |
@@ -760,7 +782,7 @@ static void __exit i2c_bfin_twi_exit(void) | |||
760 | platform_driver_unregister(&i2c_bfin_twi_driver); | 782 | platform_driver_unregister(&i2c_bfin_twi_driver); |
761 | } | 783 | } |
762 | 784 | ||
763 | module_init(i2c_bfin_twi_init); | 785 | subsys_initcall(i2c_bfin_twi_init); |
764 | module_exit(i2c_bfin_twi_exit); | 786 | module_exit(i2c_bfin_twi_exit); |
765 | 787 | ||
766 | MODULE_AUTHOR("Bryan Wu, Sonic Zhang"); | 788 | MODULE_AUTHOR("Bryan Wu, Sonic Zhang"); |
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c new file mode 100644 index 000000000000..2e067dd2ee51 --- /dev/null +++ b/drivers/i2c/busses/i2c-eg20t.c | |||
@@ -0,0 +1,900 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; version 2 of the License. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/fs.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/types.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/jiffies.h> | ||
29 | #include <linux/pci.h> | ||
30 | #include <linux/mutex.h> | ||
31 | #include <linux/ktime.h> | ||
32 | |||
33 | #define PCH_EVENT_SET 0 /* I2C Interrupt Event Set Status */ | ||
34 | #define PCH_EVENT_NONE 1 /* I2C Interrupt Event Clear Status */ | ||
35 | #define PCH_MAX_CLK 100000 /* Maximum Clock speed in MHz */ | ||
36 | #define PCH_BUFFER_MODE_ENABLE 0x0002 /* flag for Buffer mode enable */ | ||
37 | #define PCH_EEPROM_SW_RST_MODE_ENABLE 0x0008 /* EEPROM SW RST enable flag */ | ||
38 | |||
39 | #define PCH_I2CSADR 0x00 /* I2C slave address register */ | ||
40 | #define PCH_I2CCTL 0x04 /* I2C control register */ | ||
41 | #define PCH_I2CSR 0x08 /* I2C status register */ | ||
42 | #define PCH_I2CDR 0x0C /* I2C data register */ | ||
43 | #define PCH_I2CMON 0x10 /* I2C bus monitor register */ | ||
44 | #define PCH_I2CBC 0x14 /* I2C bus transfer rate setup counter */ | ||
45 | #define PCH_I2CMOD 0x18 /* I2C mode register */ | ||
46 | #define PCH_I2CBUFSLV 0x1C /* I2C buffer mode slave address register */ | ||
47 | #define PCH_I2CBUFSUB 0x20 /* I2C buffer mode subaddress register */ | ||
48 | #define PCH_I2CBUFFOR 0x24 /* I2C buffer mode format register */ | ||
49 | #define PCH_I2CBUFCTL 0x28 /* I2C buffer mode control register */ | ||
50 | #define PCH_I2CBUFMSK 0x2C /* I2C buffer mode interrupt mask register */ | ||
51 | #define PCH_I2CBUFSTA 0x30 /* I2C buffer mode status register */ | ||
52 | #define PCH_I2CBUFLEV 0x34 /* I2C buffer mode level register */ | ||
53 | #define PCH_I2CESRFOR 0x38 /* EEPROM software reset mode format register */ | ||
54 | #define PCH_I2CESRCTL 0x3C /* EEPROM software reset mode ctrl register */ | ||
55 | #define PCH_I2CESRMSK 0x40 /* EEPROM software reset mode */ | ||
56 | #define PCH_I2CESRSTA 0x44 /* EEPROM software reset mode status register */ | ||
57 | #define PCH_I2CTMR 0x48 /* I2C timer register */ | ||
58 | #define PCH_I2CSRST 0xFC /* I2C reset register */ | ||
59 | #define PCH_I2CNF 0xF8 /* I2C noise filter register */ | ||
60 | |||
61 | #define BUS_IDLE_TIMEOUT 20 | ||
62 | #define PCH_I2CCTL_I2CMEN 0x0080 | ||
63 | #define TEN_BIT_ADDR_DEFAULT 0xF000 | ||
64 | #define TEN_BIT_ADDR_MASK 0xF0 | ||
65 | #define PCH_START 0x0020 | ||
66 | #define PCH_ESR_START 0x0001 | ||
67 | #define PCH_BUFF_START 0x1 | ||
68 | #define PCH_REPSTART 0x0004 | ||
69 | #define PCH_ACK 0x0008 | ||
70 | #define PCH_GETACK 0x0001 | ||
71 | #define CLR_REG 0x0 | ||
72 | #define I2C_RD 0x1 | ||
73 | #define I2CMCF_BIT 0x0080 | ||
74 | #define I2CMIF_BIT 0x0002 | ||
75 | #define I2CMAL_BIT 0x0010 | ||
76 | #define I2CBMFI_BIT 0x0001 | ||
77 | #define I2CBMAL_BIT 0x0002 | ||
78 | #define I2CBMNA_BIT 0x0004 | ||
79 | #define I2CBMTO_BIT 0x0008 | ||
80 | #define I2CBMIS_BIT 0x0010 | ||
81 | #define I2CESRFI_BIT 0X0001 | ||
82 | #define I2CESRTO_BIT 0x0002 | ||
83 | #define I2CESRFIIE_BIT 0x1 | ||
84 | #define I2CESRTOIE_BIT 0x2 | ||
85 | #define I2CBMDZ_BIT 0x0040 | ||
86 | #define I2CBMAG_BIT 0x0020 | ||
87 | #define I2CMBB_BIT 0x0020 | ||
88 | #define BUFFER_MODE_MASK (I2CBMFI_BIT | I2CBMAL_BIT | I2CBMNA_BIT | \ | ||
89 | I2CBMTO_BIT | I2CBMIS_BIT) | ||
90 | #define I2C_ADDR_MSK 0xFF | ||
91 | #define I2C_MSB_2B_MSK 0x300 | ||
92 | #define FAST_MODE_CLK 400 | ||
93 | #define FAST_MODE_EN 0x0001 | ||
94 | #define SUB_ADDR_LEN_MAX 4 | ||
95 | #define BUF_LEN_MAX 32 | ||
96 | #define PCH_BUFFER_MODE 0x1 | ||
97 | #define EEPROM_SW_RST_MODE 0x0002 | ||
98 | #define NORMAL_INTR_ENBL 0x0300 | ||
99 | #define EEPROM_RST_INTR_ENBL (I2CESRFIIE_BIT | I2CESRTOIE_BIT) | ||
100 | #define EEPROM_RST_INTR_DISBL 0x0 | ||
101 | #define BUFFER_MODE_INTR_ENBL 0x001F | ||
102 | #define BUFFER_MODE_INTR_DISBL 0x0 | ||
103 | #define NORMAL_MODE 0x0 | ||
104 | #define BUFFER_MODE 0x1 | ||
105 | #define EEPROM_SR_MODE 0x2 | ||
106 | #define I2C_TX_MODE 0x0010 | ||
107 | #define PCH_BUF_TX 0xFFF7 | ||
108 | #define PCH_BUF_RD 0x0008 | ||
109 | #define I2C_ERROR_MASK (I2CESRTO_EVENT | I2CBMIS_EVENT | I2CBMTO_EVENT | \ | ||
110 | I2CBMNA_EVENT | I2CBMAL_EVENT | I2CMAL_EVENT) | ||
111 | #define I2CMAL_EVENT 0x0001 | ||
112 | #define I2CMCF_EVENT 0x0002 | ||
113 | #define I2CBMFI_EVENT 0x0004 | ||
114 | #define I2CBMAL_EVENT 0x0008 | ||
115 | #define I2CBMNA_EVENT 0x0010 | ||
116 | #define I2CBMTO_EVENT 0x0020 | ||
117 | #define I2CBMIS_EVENT 0x0040 | ||
118 | #define I2CESRFI_EVENT 0x0080 | ||
119 | #define I2CESRTO_EVENT 0x0100 | ||
120 | #define PCI_DEVICE_ID_PCH_I2C 0x8817 | ||
121 | |||
122 | #define pch_dbg(adap, fmt, arg...) \ | ||
123 | dev_dbg(adap->pch_adapter.dev.parent, "%s :" fmt, __func__, ##arg) | ||
124 | |||
125 | #define pch_err(adap, fmt, arg...) \ | ||
126 | dev_err(adap->pch_adapter.dev.parent, "%s :" fmt, __func__, ##arg) | ||
127 | |||
128 | #define pch_pci_err(pdev, fmt, arg...) \ | ||
129 | dev_err(&pdev->dev, "%s :" fmt, __func__, ##arg) | ||
130 | |||
131 | #define pch_pci_dbg(pdev, fmt, arg...) \ | ||
132 | dev_dbg(&pdev->dev, "%s :" fmt, __func__, ##arg) | ||
133 | |||
134 | /** | ||
135 | * struct i2c_algo_pch_data - for I2C driver functionalities | ||
136 | * @pch_adapter: stores the reference to i2c_adapter structure | ||
137 | * @p_adapter_info: stores the reference to adapter_info structure | ||
138 | * @pch_base_address: specifies the remapped base address | ||
139 | * @pch_buff_mode_en: specifies if buffer mode is enabled | ||
140 | * @pch_event_flag: specifies occurrence of interrupt events | ||
141 | * @pch_i2c_xfer_in_progress: specifies whether the transfer is completed | ||
142 | */ | ||
143 | struct i2c_algo_pch_data { | ||
144 | struct i2c_adapter pch_adapter; | ||
145 | struct adapter_info *p_adapter_info; | ||
146 | void __iomem *pch_base_address; | ||
147 | int pch_buff_mode_en; | ||
148 | u32 pch_event_flag; | ||
149 | bool pch_i2c_xfer_in_progress; | ||
150 | }; | ||
151 | |||
152 | /** | ||
153 | * struct adapter_info - This structure holds the adapter information for the | ||
154 | PCH i2c controller | ||
155 | * @pch_data: stores a list of i2c_algo_pch_data | ||
156 | * @pch_i2c_suspended: specifies whether the system is suspended or not | ||
157 | * perhaps with more lines and words. | ||
158 | * | ||
159 | * pch_data has as many elements as maximum I2C channels | ||
160 | */ | ||
161 | struct adapter_info { | ||
162 | struct i2c_algo_pch_data pch_data; | ||
163 | bool pch_i2c_suspended; | ||
164 | }; | ||
165 | |||
166 | |||
167 | static int pch_i2c_speed = 100; /* I2C bus speed in Kbps */ | ||
168 | static int pch_clk = 50000; /* specifies I2C clock speed in KHz */ | ||
169 | static wait_queue_head_t pch_event; | ||
170 | static DEFINE_MUTEX(pch_mutex); | ||
171 | |||
172 | static struct pci_device_id __devinitdata pch_pcidev_id[] = { | ||
173 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH_I2C)}, | ||
174 | {0,} | ||
175 | }; | ||
176 | |||
177 | static irqreturn_t pch_i2c_handler(int irq, void *pData); | ||
178 | |||
179 | static inline void pch_setbit(void __iomem *addr, u32 offset, u32 bitmask) | ||
180 | { | ||
181 | u32 val; | ||
182 | val = ioread32(addr + offset); | ||
183 | val |= bitmask; | ||
184 | iowrite32(val, addr + offset); | ||
185 | } | ||
186 | |||
187 | static inline void pch_clrbit(void __iomem *addr, u32 offset, u32 bitmask) | ||
188 | { | ||
189 | u32 val; | ||
190 | val = ioread32(addr + offset); | ||
191 | val &= (~bitmask); | ||
192 | iowrite32(val, addr + offset); | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * pch_i2c_init() - hardware initialization of I2C module | ||
197 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
198 | */ | ||
199 | static void pch_i2c_init(struct i2c_algo_pch_data *adap) | ||
200 | { | ||
201 | void __iomem *p = adap->pch_base_address; | ||
202 | u32 pch_i2cbc; | ||
203 | u32 pch_i2ctmr; | ||
204 | u32 reg_value; | ||
205 | |||
206 | /* reset I2C controller */ | ||
207 | iowrite32(0x01, p + PCH_I2CSRST); | ||
208 | msleep(20); | ||
209 | iowrite32(0x0, p + PCH_I2CSRST); | ||
210 | |||
211 | /* Initialize I2C registers */ | ||
212 | iowrite32(0x21, p + PCH_I2CNF); | ||
213 | |||
214 | pch_setbit(adap->pch_base_address, PCH_I2CCTL, | ||
215 | PCH_I2CCTL_I2CMEN); | ||
216 | |||
217 | if (pch_i2c_speed != 400) | ||
218 | pch_i2c_speed = 100; | ||
219 | |||
220 | reg_value = PCH_I2CCTL_I2CMEN; | ||
221 | if (pch_i2c_speed == FAST_MODE_CLK) { | ||
222 | reg_value |= FAST_MODE_EN; | ||
223 | pch_dbg(adap, "Fast mode enabled\n"); | ||
224 | } | ||
225 | |||
226 | if (pch_clk > PCH_MAX_CLK) | ||
227 | pch_clk = 62500; | ||
228 | |||
229 | pch_i2cbc = (pch_clk + (pch_i2c_speed * 4)) / pch_i2c_speed * 8; | ||
230 | /* Set transfer speed in I2CBC */ | ||
231 | iowrite32(pch_i2cbc, p + PCH_I2CBC); | ||
232 | |||
233 | pch_i2ctmr = (pch_clk) / 8; | ||
234 | iowrite32(pch_i2ctmr, p + PCH_I2CTMR); | ||
235 | |||
236 | reg_value |= NORMAL_INTR_ENBL; /* Enable interrupts in normal mode */ | ||
237 | iowrite32(reg_value, p + PCH_I2CCTL); | ||
238 | |||
239 | pch_dbg(adap, | ||
240 | "I2CCTL=%x pch_i2cbc=%x pch_i2ctmr=%x Enable interrupts\n", | ||
241 | ioread32(p + PCH_I2CCTL), pch_i2cbc, pch_i2ctmr); | ||
242 | |||
243 | init_waitqueue_head(&pch_event); | ||
244 | } | ||
245 | |||
246 | static inline bool ktime_lt(const ktime_t cmp1, const ktime_t cmp2) | ||
247 | { | ||
248 | return cmp1.tv64 < cmp2.tv64; | ||
249 | } | ||
250 | |||
251 | /** | ||
252 | * pch_i2c_wait_for_bus_idle() - check the status of bus. | ||
253 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
254 | * @timeout: waiting time counter (us). | ||
255 | */ | ||
256 | static s32 pch_i2c_wait_for_bus_idle(struct i2c_algo_pch_data *adap, | ||
257 | s32 timeout) | ||
258 | { | ||
259 | void __iomem *p = adap->pch_base_address; | ||
260 | |||
261 | /* MAX timeout value is timeout*1000*1000nsec */ | ||
262 | ktime_t ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000); | ||
263 | do { | ||
264 | if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0) | ||
265 | break; | ||
266 | msleep(20); | ||
267 | } while (ktime_lt(ktime_get(), ns_val)); | ||
268 | |||
269 | pch_dbg(adap, "I2CSR = %x\n", ioread32(p + PCH_I2CSR)); | ||
270 | |||
271 | if (timeout == 0) { | ||
272 | pch_err(adap, "%s: Timeout Error.return%d\n", __func__, -ETIME); | ||
273 | return -ETIME; | ||
274 | } | ||
275 | |||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | /** | ||
280 | * pch_i2c_start() - Generate I2C start condition in normal mode. | ||
281 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
282 | * | ||
283 | * Generate I2C start condition in normal mode by setting I2CCTL.I2CMSTA to 1. | ||
284 | */ | ||
285 | static void pch_i2c_start(struct i2c_algo_pch_data *adap) | ||
286 | { | ||
287 | void __iomem *p = adap->pch_base_address; | ||
288 | pch_dbg(adap, "I2CCTL = %x\n", ioread32(p + PCH_I2CCTL)); | ||
289 | pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_START); | ||
290 | } | ||
291 | |||
292 | /** | ||
293 | * pch_i2c_wait_for_xfer_complete() - initiates a wait for the tx complete event | ||
294 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
295 | */ | ||
296 | static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap) | ||
297 | { | ||
298 | s32 ret; | ||
299 | ret = wait_event_timeout(pch_event, | ||
300 | (adap->pch_event_flag != 0), msecs_to_jiffies(50)); | ||
301 | if (ret < 0) { | ||
302 | pch_err(adap, "timeout: %x\n", adap->pch_event_flag); | ||
303 | return ret; | ||
304 | } | ||
305 | |||
306 | if (ret == 0) { | ||
307 | pch_err(adap, "timeout: %x\n", adap->pch_event_flag); | ||
308 | return -ETIMEDOUT; | ||
309 | } | ||
310 | |||
311 | if (adap->pch_event_flag & I2C_ERROR_MASK) { | ||
312 | pch_err(adap, "error bits set: %x\n", adap->pch_event_flag); | ||
313 | return -EIO; | ||
314 | } | ||
315 | |||
316 | adap->pch_event_flag = 0; | ||
317 | |||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * pch_i2c_getack() - to confirm ACK/NACK | ||
323 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
324 | */ | ||
325 | static s32 pch_i2c_getack(struct i2c_algo_pch_data *adap) | ||
326 | { | ||
327 | u32 reg_val; | ||
328 | void __iomem *p = adap->pch_base_address; | ||
329 | reg_val = ioread32(p + PCH_I2CSR) & PCH_GETACK; | ||
330 | |||
331 | if (reg_val != 0) { | ||
332 | pch_err(adap, "return%d\n", -EPROTO); | ||
333 | return -EPROTO; | ||
334 | } | ||
335 | |||
336 | return 0; | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * pch_i2c_stop() - generate stop condition in normal mode. | ||
341 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
342 | */ | ||
343 | static void pch_i2c_stop(struct i2c_algo_pch_data *adap) | ||
344 | { | ||
345 | void __iomem *p = adap->pch_base_address; | ||
346 | pch_dbg(adap, "I2CCTL = %x\n", ioread32(p + PCH_I2CCTL)); | ||
347 | /* clear the start bit */ | ||
348 | pch_clrbit(adap->pch_base_address, PCH_I2CCTL, PCH_START); | ||
349 | } | ||
350 | |||
351 | /** | ||
352 | * pch_i2c_repstart() - generate repeated start condition in normal mode | ||
353 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
354 | */ | ||
355 | static void pch_i2c_repstart(struct i2c_algo_pch_data *adap) | ||
356 | { | ||
357 | void __iomem *p = adap->pch_base_address; | ||
358 | pch_dbg(adap, "I2CCTL = %x\n", ioread32(p + PCH_I2CCTL)); | ||
359 | pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_REPSTART); | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * pch_i2c_writebytes() - write data to I2C bus in normal mode | ||
364 | * @i2c_adap: Pointer to the struct i2c_adapter. | ||
365 | * @last: specifies whether last message or not. | ||
366 | * In the case of compound mode it will be 1 for last message, | ||
367 | * otherwise 0. | ||
368 | * @first: specifies whether first message or not. | ||
369 | * 1 for first message otherwise 0. | ||
370 | */ | ||
371 | static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap, | ||
372 | struct i2c_msg *msgs, u32 last, u32 first) | ||
373 | { | ||
374 | struct i2c_algo_pch_data *adap = i2c_adap->algo_data; | ||
375 | u8 *buf; | ||
376 | u32 length; | ||
377 | u32 addr; | ||
378 | u32 addr_2_msb; | ||
379 | u32 addr_8_lsb; | ||
380 | s32 wrcount; | ||
381 | void __iomem *p = adap->pch_base_address; | ||
382 | |||
383 | length = msgs->len; | ||
384 | buf = msgs->buf; | ||
385 | addr = msgs->addr; | ||
386 | |||
387 | /* enable master tx */ | ||
388 | pch_setbit(adap->pch_base_address, PCH_I2CCTL, I2C_TX_MODE); | ||
389 | |||
390 | pch_dbg(adap, "I2CCTL = %x msgs->len = %d\n", ioread32(p + PCH_I2CCTL), | ||
391 | length); | ||
392 | |||
393 | if (first) { | ||
394 | if (pch_i2c_wait_for_bus_idle(adap, BUS_IDLE_TIMEOUT) == -ETIME) | ||
395 | return -ETIME; | ||
396 | } | ||
397 | |||
398 | if (msgs->flags & I2C_M_TEN) { | ||
399 | addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7); | ||
400 | iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); | ||
401 | if (first) | ||
402 | pch_i2c_start(adap); | ||
403 | if (pch_i2c_wait_for_xfer_complete(adap) == 0 && | ||
404 | pch_i2c_getack(adap) == 0) { | ||
405 | addr_8_lsb = (addr & I2C_ADDR_MSK); | ||
406 | iowrite32(addr_8_lsb, p + PCH_I2CDR); | ||
407 | } else { | ||
408 | pch_i2c_stop(adap); | ||
409 | return -ETIME; | ||
410 | } | ||
411 | } else { | ||
412 | /* set 7 bit slave address and R/W bit as 0 */ | ||
413 | iowrite32(addr << 1, p + PCH_I2CDR); | ||
414 | if (first) | ||
415 | pch_i2c_start(adap); | ||
416 | } | ||
417 | |||
418 | if ((pch_i2c_wait_for_xfer_complete(adap) == 0) && | ||
419 | (pch_i2c_getack(adap) == 0)) { | ||
420 | for (wrcount = 0; wrcount < length; ++wrcount) { | ||
421 | /* write buffer value to I2C data register */ | ||
422 | iowrite32(buf[wrcount], p + PCH_I2CDR); | ||
423 | pch_dbg(adap, "writing %x to Data register\n", | ||
424 | buf[wrcount]); | ||
425 | |||
426 | if (pch_i2c_wait_for_xfer_complete(adap) != 0) | ||
427 | return -ETIME; | ||
428 | |||
429 | if (pch_i2c_getack(adap)) | ||
430 | return -EIO; | ||
431 | } | ||
432 | |||
433 | /* check if this is the last message */ | ||
434 | if (last) | ||
435 | pch_i2c_stop(adap); | ||
436 | else | ||
437 | pch_i2c_repstart(adap); | ||
438 | } else { | ||
439 | pch_i2c_stop(adap); | ||
440 | return -EIO; | ||
441 | } | ||
442 | |||
443 | pch_dbg(adap, "return=%d\n", wrcount); | ||
444 | |||
445 | return wrcount; | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * pch_i2c_sendack() - send ACK | ||
450 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
451 | */ | ||
452 | static void pch_i2c_sendack(struct i2c_algo_pch_data *adap) | ||
453 | { | ||
454 | void __iomem *p = adap->pch_base_address; | ||
455 | pch_dbg(adap, "I2CCTL = %x\n", ioread32(p + PCH_I2CCTL)); | ||
456 | pch_clrbit(adap->pch_base_address, PCH_I2CCTL, PCH_ACK); | ||
457 | } | ||
458 | |||
459 | /** | ||
460 | * pch_i2c_sendnack() - send NACK | ||
461 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
462 | */ | ||
463 | static void pch_i2c_sendnack(struct i2c_algo_pch_data *adap) | ||
464 | { | ||
465 | void __iomem *p = adap->pch_base_address; | ||
466 | pch_dbg(adap, "I2CCTL = %x\n", ioread32(p + PCH_I2CCTL)); | ||
467 | pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_ACK); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * pch_i2c_readbytes() - read data from I2C bus in normal mode. | ||
472 | * @i2c_adap: Pointer to the struct i2c_adapter. | ||
473 | * @msgs: Pointer to i2c_msg structure. | ||
474 | * @last: specifies whether last message or not. | ||
475 | * @first: specifies whether first message or not. | ||
476 | */ | ||
477 | s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, | ||
478 | u32 last, u32 first) | ||
479 | { | ||
480 | struct i2c_algo_pch_data *adap = i2c_adap->algo_data; | ||
481 | |||
482 | u8 *buf; | ||
483 | u32 count; | ||
484 | u32 length; | ||
485 | u32 addr; | ||
486 | u32 addr_2_msb; | ||
487 | void __iomem *p = adap->pch_base_address; | ||
488 | |||
489 | length = msgs->len; | ||
490 | buf = msgs->buf; | ||
491 | addr = msgs->addr; | ||
492 | |||
493 | /* enable master reception */ | ||
494 | pch_clrbit(adap->pch_base_address, PCH_I2CCTL, I2C_TX_MODE); | ||
495 | |||
496 | if (first) { | ||
497 | if (pch_i2c_wait_for_bus_idle(adap, BUS_IDLE_TIMEOUT) == -ETIME) | ||
498 | return -ETIME; | ||
499 | } | ||
500 | |||
501 | if (msgs->flags & I2C_M_TEN) { | ||
502 | addr_2_msb = (((addr & I2C_MSB_2B_MSK) >> 7) | (I2C_RD)); | ||
503 | iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); | ||
504 | |||
505 | } else { | ||
506 | /* 7 address bits + R/W bit */ | ||
507 | addr = (((addr) << 1) | (I2C_RD)); | ||
508 | iowrite32(addr, p + PCH_I2CDR); | ||
509 | } | ||
510 | |||
511 | /* check if it is the first message */ | ||
512 | if (first) | ||
513 | pch_i2c_start(adap); | ||
514 | |||
515 | if ((pch_i2c_wait_for_xfer_complete(adap) == 0) && | ||
516 | (pch_i2c_getack(adap) == 0)) { | ||
517 | pch_dbg(adap, "return %d\n", 0); | ||
518 | |||
519 | if (length == 0) { | ||
520 | pch_i2c_stop(adap); | ||
521 | ioread32(p + PCH_I2CDR); /* Dummy read needs */ | ||
522 | |||
523 | count = length; | ||
524 | } else { | ||
525 | int read_index; | ||
526 | int loop; | ||
527 | pch_i2c_sendack(adap); | ||
528 | |||
529 | /* Dummy read */ | ||
530 | for (loop = 1, read_index = 0; loop < length; loop++) { | ||
531 | buf[read_index] = ioread32(p + PCH_I2CDR); | ||
532 | |||
533 | if (loop != 1) | ||
534 | read_index++; | ||
535 | |||
536 | if (pch_i2c_wait_for_xfer_complete(adap) != 0) { | ||
537 | pch_i2c_stop(adap); | ||
538 | return -ETIME; | ||
539 | } | ||
540 | } /* end for */ | ||
541 | |||
542 | pch_i2c_sendnack(adap); | ||
543 | |||
544 | buf[read_index] = ioread32(p + PCH_I2CDR); | ||
545 | |||
546 | if (length != 1) | ||
547 | read_index++; | ||
548 | |||
549 | if (pch_i2c_wait_for_xfer_complete(adap) == 0) { | ||
550 | if (last) | ||
551 | pch_i2c_stop(adap); | ||
552 | else | ||
553 | pch_i2c_repstart(adap); | ||
554 | |||
555 | buf[read_index++] = ioread32(p + PCH_I2CDR); | ||
556 | count = read_index; | ||
557 | } else { | ||
558 | count = -ETIME; | ||
559 | } | ||
560 | |||
561 | } | ||
562 | } else { | ||
563 | count = -ETIME; | ||
564 | pch_i2c_stop(adap); | ||
565 | } | ||
566 | |||
567 | return count; | ||
568 | } | ||
569 | |||
570 | /** | ||
571 | * pch_i2c_cb_ch0() - Interrupt handler Call back function | ||
572 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
573 | */ | ||
574 | static void pch_i2c_cb_ch0(struct i2c_algo_pch_data *adap) | ||
575 | { | ||
576 | u32 sts; | ||
577 | void __iomem *p = adap->pch_base_address; | ||
578 | |||
579 | sts = ioread32(p + PCH_I2CSR); | ||
580 | sts &= (I2CMAL_BIT | I2CMCF_BIT | I2CMIF_BIT); | ||
581 | if (sts & I2CMAL_BIT) | ||
582 | adap->pch_event_flag |= I2CMAL_EVENT; | ||
583 | |||
584 | if (sts & I2CMCF_BIT) | ||
585 | adap->pch_event_flag |= I2CMCF_EVENT; | ||
586 | |||
587 | /* clear the applicable bits */ | ||
588 | pch_clrbit(adap->pch_base_address, PCH_I2CSR, sts); | ||
589 | |||
590 | pch_dbg(adap, "PCH_I2CSR = %x\n", ioread32(p + PCH_I2CSR)); | ||
591 | |||
592 | wake_up(&pch_event); | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * pch_i2c_handler() - interrupt handler for the PCH I2C controller | ||
597 | * @irq: irq number. | ||
598 | * @pData: cookie passed back to the handler function. | ||
599 | */ | ||
600 | static irqreturn_t pch_i2c_handler(int irq, void *pData) | ||
601 | { | ||
602 | s32 reg_val; | ||
603 | |||
604 | struct i2c_algo_pch_data *adap_data = (struct i2c_algo_pch_data *)pData; | ||
605 | void __iomem *p = adap_data->pch_base_address; | ||
606 | u32 mode = ioread32(p + PCH_I2CMOD) & (BUFFER_MODE | EEPROM_SR_MODE); | ||
607 | |||
608 | if (mode != NORMAL_MODE) { | ||
609 | pch_err(adap_data, "I2C mode is not supported\n"); | ||
610 | return IRQ_NONE; | ||
611 | } | ||
612 | |||
613 | reg_val = ioread32(p + PCH_I2CSR); | ||
614 | if (reg_val & (I2CMAL_BIT | I2CMCF_BIT | I2CMIF_BIT)) | ||
615 | pch_i2c_cb_ch0(adap_data); | ||
616 | else | ||
617 | return IRQ_NONE; | ||
618 | |||
619 | return IRQ_HANDLED; | ||
620 | } | ||
621 | |||
622 | /** | ||
623 | * pch_i2c_xfer() - Reading adnd writing data through I2C bus | ||
624 | * @i2c_adap: Pointer to the struct i2c_adapter. | ||
625 | * @msgs: Pointer to i2c_msg structure. | ||
626 | * @num: number of messages. | ||
627 | */ | ||
628 | static s32 pch_i2c_xfer(struct i2c_adapter *i2c_adap, | ||
629 | struct i2c_msg *msgs, s32 num) | ||
630 | { | ||
631 | struct i2c_msg *pmsg; | ||
632 | u32 i = 0; | ||
633 | u32 status; | ||
634 | u32 msglen; | ||
635 | u32 subaddrlen; | ||
636 | s32 ret; | ||
637 | |||
638 | struct i2c_algo_pch_data *adap = i2c_adap->algo_data; | ||
639 | |||
640 | ret = mutex_lock_interruptible(&pch_mutex); | ||
641 | if (ret) | ||
642 | return -ERESTARTSYS; | ||
643 | |||
644 | if (adap->p_adapter_info->pch_i2c_suspended) { | ||
645 | mutex_unlock(&pch_mutex); | ||
646 | return -EBUSY; | ||
647 | } | ||
648 | |||
649 | pch_dbg(adap, "adap->p_adapter_info->pch_i2c_suspended is %d\n", | ||
650 | adap->p_adapter_info->pch_i2c_suspended); | ||
651 | /* transfer not completed */ | ||
652 | adap->pch_i2c_xfer_in_progress = true; | ||
653 | |||
654 | pmsg = &msgs[0]; | ||
655 | pmsg->flags |= adap->pch_buff_mode_en; | ||
656 | status = pmsg->flags; | ||
657 | pch_dbg(adap, | ||
658 | "After invoking I2C_MODE_SEL :flag= 0x%x\n", status); | ||
659 | /* calculate sub address length and message length */ | ||
660 | /* these are applicable only for buffer mode */ | ||
661 | subaddrlen = pmsg->buf[0]; | ||
662 | /* calculate actual message length excluding | ||
663 | * the sub address fields */ | ||
664 | msglen = (pmsg->len) - (subaddrlen + 1); | ||
665 | if (status & (I2C_M_RD)) { | ||
666 | pch_dbg(adap, "invoking pch_i2c_readbytes\n"); | ||
667 | ret = pch_i2c_readbytes(i2c_adap, pmsg, (i + 1 == num), | ||
668 | (i == 0)); | ||
669 | } else { | ||
670 | pch_dbg(adap, "invoking pch_i2c_writebytes\n"); | ||
671 | ret = pch_i2c_writebytes(i2c_adap, pmsg, (i + 1 == num), | ||
672 | (i == 0)); | ||
673 | } | ||
674 | |||
675 | adap->pch_i2c_xfer_in_progress = false; /* transfer completed */ | ||
676 | |||
677 | mutex_unlock(&pch_mutex); | ||
678 | |||
679 | return ret; | ||
680 | } | ||
681 | |||
682 | /** | ||
683 | * pch_i2c_func() - return the functionality of the I2C driver | ||
684 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
685 | */ | ||
686 | static u32 pch_i2c_func(struct i2c_adapter *adap) | ||
687 | { | ||
688 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; | ||
689 | } | ||
690 | |||
691 | static struct i2c_algorithm pch_algorithm = { | ||
692 | .master_xfer = pch_i2c_xfer, | ||
693 | .functionality = pch_i2c_func | ||
694 | }; | ||
695 | |||
696 | /** | ||
697 | * pch_i2c_disbl_int() - Disable PCH I2C interrupts | ||
698 | * @adap: Pointer to struct i2c_algo_pch_data. | ||
699 | */ | ||
700 | static void pch_i2c_disbl_int(struct i2c_algo_pch_data *adap) | ||
701 | { | ||
702 | void __iomem *p = adap->pch_base_address; | ||
703 | |||
704 | pch_clrbit(adap->pch_base_address, PCH_I2CCTL, NORMAL_INTR_ENBL); | ||
705 | |||
706 | iowrite32(EEPROM_RST_INTR_DISBL, p + PCH_I2CESRMSK); | ||
707 | |||
708 | iowrite32(BUFFER_MODE_INTR_DISBL, p + PCH_I2CBUFMSK); | ||
709 | } | ||
710 | |||
711 | static int __devinit pch_i2c_probe(struct pci_dev *pdev, | ||
712 | const struct pci_device_id *id) | ||
713 | { | ||
714 | void __iomem *base_addr; | ||
715 | s32 ret; | ||
716 | struct adapter_info *adap_info; | ||
717 | |||
718 | pch_pci_dbg(pdev, "Entered.\n"); | ||
719 | |||
720 | adap_info = kzalloc((sizeof(struct adapter_info)), GFP_KERNEL); | ||
721 | if (adap_info == NULL) { | ||
722 | pch_pci_err(pdev, "Memory allocation FAILED\n"); | ||
723 | return -ENOMEM; | ||
724 | } | ||
725 | |||
726 | ret = pci_enable_device(pdev); | ||
727 | if (ret) { | ||
728 | pch_pci_err(pdev, "pci_enable_device FAILED\n"); | ||
729 | goto err_pci_enable; | ||
730 | } | ||
731 | |||
732 | ret = pci_request_regions(pdev, KBUILD_MODNAME); | ||
733 | if (ret) { | ||
734 | pch_pci_err(pdev, "pci_request_regions FAILED\n"); | ||
735 | goto err_pci_req; | ||
736 | } | ||
737 | |||
738 | base_addr = pci_iomap(pdev, 1, 0); | ||
739 | |||
740 | if (base_addr == NULL) { | ||
741 | pch_pci_err(pdev, "pci_iomap FAILED\n"); | ||
742 | ret = -ENOMEM; | ||
743 | goto err_pci_iomap; | ||
744 | } | ||
745 | |||
746 | adap_info->pch_i2c_suspended = false; | ||
747 | |||
748 | adap_info->pch_data.p_adapter_info = adap_info; | ||
749 | |||
750 | adap_info->pch_data.pch_adapter.owner = THIS_MODULE; | ||
751 | adap_info->pch_data.pch_adapter.class = I2C_CLASS_HWMON; | ||
752 | strcpy(adap_info->pch_data.pch_adapter.name, KBUILD_MODNAME); | ||
753 | adap_info->pch_data.pch_adapter.algo = &pch_algorithm; | ||
754 | adap_info->pch_data.pch_adapter.algo_data = | ||
755 | &adap_info->pch_data; | ||
756 | |||
757 | /* (i * 0x80) + base_addr; */ | ||
758 | adap_info->pch_data.pch_base_address = base_addr; | ||
759 | |||
760 | adap_info->pch_data.pch_adapter.dev.parent = &pdev->dev; | ||
761 | |||
762 | ret = i2c_add_adapter(&(adap_info->pch_data.pch_adapter)); | ||
763 | |||
764 | if (ret) { | ||
765 | pch_pci_err(pdev, "i2c_add_adapter FAILED\n"); | ||
766 | goto err_i2c_add_adapter; | ||
767 | } | ||
768 | |||
769 | pch_i2c_init(&adap_info->pch_data); | ||
770 | ret = request_irq(pdev->irq, pch_i2c_handler, IRQF_SHARED, | ||
771 | KBUILD_MODNAME, &adap_info->pch_data); | ||
772 | if (ret) { | ||
773 | pch_pci_err(pdev, "request_irq FAILED\n"); | ||
774 | goto err_request_irq; | ||
775 | } | ||
776 | |||
777 | pci_set_drvdata(pdev, adap_info); | ||
778 | pch_pci_dbg(pdev, "returns %d.\n", ret); | ||
779 | return 0; | ||
780 | |||
781 | err_request_irq: | ||
782 | i2c_del_adapter(&(adap_info->pch_data.pch_adapter)); | ||
783 | err_i2c_add_adapter: | ||
784 | pci_iounmap(pdev, base_addr); | ||
785 | err_pci_iomap: | ||
786 | pci_release_regions(pdev); | ||
787 | err_pci_req: | ||
788 | pci_disable_device(pdev); | ||
789 | err_pci_enable: | ||
790 | kfree(adap_info); | ||
791 | return ret; | ||
792 | } | ||
793 | |||
794 | static void __devexit pch_i2c_remove(struct pci_dev *pdev) | ||
795 | { | ||
796 | struct adapter_info *adap_info = pci_get_drvdata(pdev); | ||
797 | |||
798 | pch_i2c_disbl_int(&adap_info->pch_data); | ||
799 | free_irq(pdev->irq, &adap_info->pch_data); | ||
800 | i2c_del_adapter(&(adap_info->pch_data.pch_adapter)); | ||
801 | |||
802 | if (adap_info->pch_data.pch_base_address) { | ||
803 | pci_iounmap(pdev, adap_info->pch_data.pch_base_address); | ||
804 | adap_info->pch_data.pch_base_address = 0; | ||
805 | } | ||
806 | |||
807 | pci_set_drvdata(pdev, NULL); | ||
808 | |||
809 | pci_release_regions(pdev); | ||
810 | |||
811 | pci_disable_device(pdev); | ||
812 | kfree(adap_info); | ||
813 | } | ||
814 | |||
815 | #ifdef CONFIG_PM | ||
816 | static int pch_i2c_suspend(struct pci_dev *pdev, pm_message_t state) | ||
817 | { | ||
818 | int ret; | ||
819 | struct adapter_info *adap_info = pci_get_drvdata(pdev); | ||
820 | void __iomem *p = adap_info->pch_data.pch_base_address; | ||
821 | |||
822 | adap_info->pch_i2c_suspended = true; | ||
823 | |||
824 | while ((adap_info->pch_data.pch_i2c_xfer_in_progress)) { | ||
825 | /* Wait until all channel transfers are completed */ | ||
826 | msleep(20); | ||
827 | } | ||
828 | /* Disable the i2c interrupts */ | ||
829 | pch_i2c_disbl_int(&adap_info->pch_data); | ||
830 | |||
831 | pch_pci_dbg(pdev, "I2CSR = %x I2CBUFSTA = %x I2CESRSTA = %x " | ||
832 | "invoked function pch_i2c_disbl_int successfully\n", | ||
833 | ioread32(p + PCH_I2CSR), ioread32(p + PCH_I2CBUFSTA), | ||
834 | ioread32(p + PCH_I2CESRSTA)); | ||
835 | |||
836 | ret = pci_save_state(pdev); | ||
837 | |||
838 | if (ret) { | ||
839 | pch_pci_err(pdev, "pci_save_state\n"); | ||
840 | return ret; | ||
841 | } | ||
842 | |||
843 | pci_enable_wake(pdev, PCI_D3hot, 0); | ||
844 | pci_disable_device(pdev); | ||
845 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | ||
846 | |||
847 | return 0; | ||
848 | } | ||
849 | |||
850 | static int pch_i2c_resume(struct pci_dev *pdev) | ||
851 | { | ||
852 | struct adapter_info *adap_info = pci_get_drvdata(pdev); | ||
853 | |||
854 | pci_set_power_state(pdev, PCI_D0); | ||
855 | pci_restore_state(pdev); | ||
856 | |||
857 | if (pci_enable_device(pdev) < 0) { | ||
858 | pch_pci_err(pdev, "pch_i2c_resume:pci_enable_device FAILED\n"); | ||
859 | return -EIO; | ||
860 | } | ||
861 | |||
862 | pci_enable_wake(pdev, PCI_D3hot, 0); | ||
863 | |||
864 | pch_i2c_init(&adap_info->pch_data); | ||
865 | |||
866 | adap_info->pch_i2c_suspended = false; | ||
867 | |||
868 | return 0; | ||
869 | } | ||
870 | #else | ||
871 | #define pch_i2c_suspend NULL | ||
872 | #define pch_i2c_resume NULL | ||
873 | #endif | ||
874 | |||
875 | static struct pci_driver pch_pcidriver = { | ||
876 | .name = KBUILD_MODNAME, | ||
877 | .id_table = pch_pcidev_id, | ||
878 | .probe = pch_i2c_probe, | ||
879 | .remove = __devexit_p(pch_i2c_remove), | ||
880 | .suspend = pch_i2c_suspend, | ||
881 | .resume = pch_i2c_resume | ||
882 | }; | ||
883 | |||
884 | static int __init pch_pci_init(void) | ||
885 | { | ||
886 | return pci_register_driver(&pch_pcidriver); | ||
887 | } | ||
888 | module_init(pch_pci_init); | ||
889 | |||
890 | static void __exit pch_pci_exit(void) | ||
891 | { | ||
892 | pci_unregister_driver(&pch_pcidriver); | ||
893 | } | ||
894 | module_exit(pch_pci_exit); | ||
895 | |||
896 | MODULE_DESCRIPTION("PCH I2C PCI Driver"); | ||
897 | MODULE_LICENSE("GPL"); | ||
898 | MODULE_AUTHOR("Tomoya MORINAGA. <tomoya-linux@dsn.okisemi.com>"); | ||
899 | module_param(pch_i2c_speed, int, (S_IRUSR | S_IWUSR)); | ||
900 | module_param(pch_clk, int, (S_IRUSR | S_IWUSR)); | ||
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c index 112c61f7b8cd..f09c9319a2ba 100644 --- a/drivers/i2c/busses/i2c-iop3xx.c +++ b/drivers/i2c/busses/i2c-iop3xx.c | |||
@@ -409,7 +409,7 @@ iop3xx_i2c_remove(struct platform_device *pdev) | |||
409 | IOP3XX_ICR_RXFULL_IE | IOP3XX_ICR_TXEMPTY_IE); | 409 | IOP3XX_ICR_RXFULL_IE | IOP3XX_ICR_TXEMPTY_IE); |
410 | __raw_writel(cr, adapter_data->ioaddr + CR_OFFSET); | 410 | __raw_writel(cr, adapter_data->ioaddr + CR_OFFSET); |
411 | 411 | ||
412 | iounmap((void __iomem*)adapter_data->ioaddr); | 412 | iounmap(adapter_data->ioaddr); |
413 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); | 413 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); |
414 | kfree(adapter_data); | 414 | kfree(adapter_data); |
415 | kfree(padapter); | 415 | kfree(padapter); |
@@ -453,7 +453,7 @@ iop3xx_i2c_probe(struct platform_device *pdev) | |||
453 | /* set the adapter enumeration # */ | 453 | /* set the adapter enumeration # */ |
454 | adapter_data->id = i2c_id++; | 454 | adapter_data->id = i2c_id++; |
455 | 455 | ||
456 | adapter_data->ioaddr = (u32)ioremap(res->start, IOP3XX_I2C_IO_SIZE); | 456 | adapter_data->ioaddr = ioremap(res->start, IOP3XX_I2C_IO_SIZE); |
457 | if (!adapter_data->ioaddr) { | 457 | if (!adapter_data->ioaddr) { |
458 | ret = -ENOMEM; | 458 | ret = -ENOMEM; |
459 | goto release_region; | 459 | goto release_region; |
@@ -498,7 +498,7 @@ iop3xx_i2c_probe(struct platform_device *pdev) | |||
498 | return 0; | 498 | return 0; |
499 | 499 | ||
500 | unmap: | 500 | unmap: |
501 | iounmap((void __iomem*)adapter_data->ioaddr); | 501 | iounmap(adapter_data->ioaddr); |
502 | 502 | ||
503 | release_region: | 503 | release_region: |
504 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); | 504 | release_mem_region(res->start, IOP3XX_I2C_IO_SIZE); |
diff --git a/drivers/i2c/busses/i2c-iop3xx.h b/drivers/i2c/busses/i2c-iop3xx.h index 8485861f6a36..097e270955d0 100644 --- a/drivers/i2c/busses/i2c-iop3xx.h +++ b/drivers/i2c/busses/i2c-iop3xx.h | |||
@@ -97,7 +97,7 @@ | |||
97 | #define IOP3XX_I2C_IO_SIZE 0x18 | 97 | #define IOP3XX_I2C_IO_SIZE 0x18 |
98 | 98 | ||
99 | struct i2c_algo_iop3xx_data { | 99 | struct i2c_algo_iop3xx_data { |
100 | u32 ioaddr; | 100 | void __iomem *ioaddr; |
101 | wait_queue_head_t waitq; | 101 | wait_queue_head_t waitq; |
102 | spinlock_t lock; | 102 | spinlock_t lock; |
103 | u32 SR_enabled, SR_received; | 103 | u32 SR_enabled, SR_received; |
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index 16242063144f..a9941c65f226 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
@@ -59,6 +59,7 @@ enum { | |||
59 | MV64XXX_I2C_STATE_INVALID, | 59 | MV64XXX_I2C_STATE_INVALID, |
60 | MV64XXX_I2C_STATE_IDLE, | 60 | MV64XXX_I2C_STATE_IDLE, |
61 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND, | 61 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND, |
62 | MV64XXX_I2C_STATE_WAITING_FOR_RESTART, | ||
62 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK, | 63 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK, |
63 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK, | 64 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK, |
64 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK, | 65 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK, |
@@ -70,6 +71,7 @@ enum { | |||
70 | MV64XXX_I2C_ACTION_INVALID, | 71 | MV64XXX_I2C_ACTION_INVALID, |
71 | MV64XXX_I2C_ACTION_CONTINUE, | 72 | MV64XXX_I2C_ACTION_CONTINUE, |
72 | MV64XXX_I2C_ACTION_SEND_START, | 73 | MV64XXX_I2C_ACTION_SEND_START, |
74 | MV64XXX_I2C_ACTION_SEND_RESTART, | ||
73 | MV64XXX_I2C_ACTION_SEND_ADDR_1, | 75 | MV64XXX_I2C_ACTION_SEND_ADDR_1, |
74 | MV64XXX_I2C_ACTION_SEND_ADDR_2, | 76 | MV64XXX_I2C_ACTION_SEND_ADDR_2, |
75 | MV64XXX_I2C_ACTION_SEND_DATA, | 77 | MV64XXX_I2C_ACTION_SEND_DATA, |
@@ -91,6 +93,7 @@ struct mv64xxx_i2c_data { | |||
91 | u32 addr2; | 93 | u32 addr2; |
92 | u32 bytes_left; | 94 | u32 bytes_left; |
93 | u32 byte_posn; | 95 | u32 byte_posn; |
96 | u32 send_stop; | ||
94 | u32 block; | 97 | u32 block; |
95 | int rc; | 98 | int rc; |
96 | u32 freq_m; | 99 | u32 freq_m; |
@@ -159,8 +162,15 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status) | |||
159 | if ((drv_data->bytes_left == 0) | 162 | if ((drv_data->bytes_left == 0) |
160 | || (drv_data->aborting | 163 | || (drv_data->aborting |
161 | && (drv_data->byte_posn != 0))) { | 164 | && (drv_data->byte_posn != 0))) { |
162 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; | 165 | if (drv_data->send_stop) { |
163 | drv_data->state = MV64XXX_I2C_STATE_IDLE; | 166 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
167 | drv_data->state = MV64XXX_I2C_STATE_IDLE; | ||
168 | } else { | ||
169 | drv_data->action = | ||
170 | MV64XXX_I2C_ACTION_SEND_RESTART; | ||
171 | drv_data->state = | ||
172 | MV64XXX_I2C_STATE_WAITING_FOR_RESTART; | ||
173 | } | ||
164 | } else { | 174 | } else { |
165 | drv_data->action = MV64XXX_I2C_ACTION_SEND_DATA; | 175 | drv_data->action = MV64XXX_I2C_ACTION_SEND_DATA; |
166 | drv_data->state = | 176 | drv_data->state = |
@@ -228,6 +238,15 @@ static void | |||
228 | mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) | 238 | mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) |
229 | { | 239 | { |
230 | switch(drv_data->action) { | 240 | switch(drv_data->action) { |
241 | case MV64XXX_I2C_ACTION_SEND_RESTART: | ||
242 | drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START; | ||
243 | drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN; | ||
244 | writel(drv_data->cntl_bits, | ||
245 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); | ||
246 | drv_data->block = 0; | ||
247 | wake_up_interruptible(&drv_data->waitq); | ||
248 | break; | ||
249 | |||
231 | case MV64XXX_I2C_ACTION_CONTINUE: | 250 | case MV64XXX_I2C_ACTION_CONTINUE: |
232 | writel(drv_data->cntl_bits, | 251 | writel(drv_data->cntl_bits, |
233 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); | 252 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
@@ -386,7 +405,8 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data) | |||
386 | } | 405 | } |
387 | 406 | ||
388 | static int | 407 | static int |
389 | mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg) | 408 | mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg, |
409 | int is_first, int is_last) | ||
390 | { | 410 | { |
391 | unsigned long flags; | 411 | unsigned long flags; |
392 | 412 | ||
@@ -406,10 +426,18 @@ mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg) | |||
406 | drv_data->bytes_left--; | 426 | drv_data->bytes_left--; |
407 | } | 427 | } |
408 | } else { | 428 | } else { |
409 | drv_data->action = MV64XXX_I2C_ACTION_SEND_START; | 429 | if (is_first) { |
410 | drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND; | 430 | drv_data->action = MV64XXX_I2C_ACTION_SEND_START; |
431 | drv_data->state = | ||
432 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND; | ||
433 | } else { | ||
434 | drv_data->action = MV64XXX_I2C_ACTION_SEND_ADDR_1; | ||
435 | drv_data->state = | ||
436 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK; | ||
437 | } | ||
411 | } | 438 | } |
412 | 439 | ||
440 | drv_data->send_stop = is_last; | ||
413 | drv_data->block = 1; | 441 | drv_data->block = 1; |
414 | mv64xxx_i2c_do_action(drv_data); | 442 | mv64xxx_i2c_do_action(drv_data); |
415 | spin_unlock_irqrestore(&drv_data->lock, flags); | 443 | spin_unlock_irqrestore(&drv_data->lock, flags); |
@@ -437,9 +465,12 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
437 | struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); | 465 | struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); |
438 | int i, rc; | 466 | int i, rc; |
439 | 467 | ||
440 | for (i=0; i<num; i++) | 468 | for (i = 0; i < num; i++) { |
441 | if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) < 0) | 469 | rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i], |
470 | i == 0, i + 1 == num); | ||
471 | if (rc < 0) | ||
442 | return rc; | 472 | return rc; |
473 | } | ||
443 | 474 | ||
444 | return num; | 475 | return num; |
445 | } | 476 | } |
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 2bd3469b3071..594ed5059c4a 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c | |||
@@ -872,6 +872,8 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
872 | adap->owner = THIS_MODULE; | 872 | adap->owner = THIS_MODULE; |
873 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 873 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
874 | adap->algo = &nmk_i2c_algo; | 874 | adap->algo = &nmk_i2c_algo; |
875 | snprintf(adap->name, sizeof(adap->name), | ||
876 | "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); | ||
875 | 877 | ||
876 | /* fetch the controller id */ | 878 | /* fetch the controller id */ |
877 | adap->nr = pdev->id; | 879 | adap->nr = pdev->id; |
@@ -891,8 +893,8 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
891 | goto err_init_hw; | 893 | goto err_init_hw; |
892 | } | 894 | } |
893 | 895 | ||
894 | dev_dbg(&pdev->dev, "initialize I2C%d bus on virtual " | 896 | dev_info(&pdev->dev, "initialize %s on virtual " |
895 | "base %p\n", pdev->id, dev->virtbase); | 897 | "base %p\n", adap->name, dev->virtbase); |
896 | 898 | ||
897 | ret = i2c_add_numbered_adapter(adap); | 899 | ret = i2c_add_numbered_adapter(adap); |
898 | if (ret) { | 900 | if (ret) { |
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c index 0070371b29f3..ef3bcb1ce864 100644 --- a/drivers/i2c/busses/i2c-ocores.c +++ b/drivers/i2c/busses/i2c-ocores.c | |||
@@ -9,6 +9,41 @@ | |||
9 | * kind, whether express or implied. | 9 | * kind, whether express or implied. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /* | ||
13 | * Device tree configuration: | ||
14 | * | ||
15 | * Required properties: | ||
16 | * - compatible : "opencores,i2c-ocores" | ||
17 | * - reg : bus address start and address range size of device | ||
18 | * - interrupts : interrupt number | ||
19 | * - regstep : size of device registers in bytes | ||
20 | * - clock-frequency : frequency of bus clock in Hz | ||
21 | * | ||
22 | * Example: | ||
23 | * | ||
24 | * i2c0: ocores@a0000000 { | ||
25 | * compatible = "opencores,i2c-ocores"; | ||
26 | * reg = <0xa0000000 0x8>; | ||
27 | * interrupts = <10>; | ||
28 | * | ||
29 | * regstep = <1>; | ||
30 | * clock-frequency = <20000000>; | ||
31 | * | ||
32 | * -- Devices connected on this I2C bus get | ||
33 | * -- defined here; address- and size-cells | ||
34 | * -- apply to these child devices | ||
35 | * | ||
36 | * #address-cells = <1>; | ||
37 | * #size-cells = <0>; | ||
38 | * | ||
39 | * dummy@60 { | ||
40 | * compatible = "dummy"; | ||
41 | * reg = <60>; | ||
42 | * }; | ||
43 | * }; | ||
44 | * | ||
45 | */ | ||
46 | |||
12 | #include <linux/kernel.h> | 47 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | 48 | #include <linux/module.h> |
14 | #include <linux/init.h> | 49 | #include <linux/init.h> |
@@ -210,6 +245,32 @@ static struct i2c_adapter ocores_adapter = { | |||
210 | .algo = &ocores_algorithm, | 245 | .algo = &ocores_algorithm, |
211 | }; | 246 | }; |
212 | 247 | ||
248 | #ifdef CONFIG_OF | ||
249 | static int ocores_i2c_of_probe(struct platform_device* pdev, | ||
250 | struct ocores_i2c* i2c) | ||
251 | { | ||
252 | __be32* val; | ||
253 | |||
254 | val = of_get_property(pdev->dev.of_node, "regstep", NULL); | ||
255 | if (!val) { | ||
256 | dev_err(&pdev->dev, "Missing required parameter 'regstep'"); | ||
257 | return -ENODEV; | ||
258 | } | ||
259 | i2c->regstep = be32_to_cpup(val); | ||
260 | |||
261 | val = of_get_property(pdev->dev.of_node, "clock-frequency", NULL); | ||
262 | if (!val) { | ||
263 | dev_err(&pdev->dev, | ||
264 | "Missing required parameter 'clock-frequency'"); | ||
265 | return -ENODEV; | ||
266 | } | ||
267 | i2c->clock_khz = be32_to_cpup(val) / 1000; | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | #else | ||
272 | #define ocores_i2c_of_probe(pdev,i2c) -ENODEV | ||
273 | #endif | ||
213 | 274 | ||
214 | static int __devinit ocores_i2c_probe(struct platform_device *pdev) | 275 | static int __devinit ocores_i2c_probe(struct platform_device *pdev) |
215 | { | 276 | { |
@@ -227,37 +288,41 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) | |||
227 | if (!res2) | 288 | if (!res2) |
228 | return -ENODEV; | 289 | return -ENODEV; |
229 | 290 | ||
230 | pdata = (struct ocores_i2c_platform_data*) pdev->dev.platform_data; | 291 | i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); |
231 | if (!pdata) | ||
232 | return -ENODEV; | ||
233 | |||
234 | i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); | ||
235 | if (!i2c) | 292 | if (!i2c) |
236 | return -ENOMEM; | 293 | return -ENOMEM; |
237 | 294 | ||
238 | if (!request_mem_region(res->start, resource_size(res), | 295 | if (!devm_request_mem_region(&pdev->dev, res->start, |
239 | pdev->name)) { | 296 | resource_size(res), pdev->name)) { |
240 | dev_err(&pdev->dev, "Memory region busy\n"); | 297 | dev_err(&pdev->dev, "Memory region busy\n"); |
241 | ret = -EBUSY; | 298 | return -EBUSY; |
242 | goto request_mem_failed; | ||
243 | } | 299 | } |
244 | 300 | ||
245 | i2c->base = ioremap(res->start, resource_size(res)); | 301 | i2c->base = devm_ioremap_nocache(&pdev->dev, res->start, |
302 | resource_size(res)); | ||
246 | if (!i2c->base) { | 303 | if (!i2c->base) { |
247 | dev_err(&pdev->dev, "Unable to map registers\n"); | 304 | dev_err(&pdev->dev, "Unable to map registers\n"); |
248 | ret = -EIO; | 305 | return -EIO; |
249 | goto map_failed; | 306 | } |
307 | |||
308 | pdata = pdev->dev.platform_data; | ||
309 | if (pdata) { | ||
310 | i2c->regstep = pdata->regstep; | ||
311 | i2c->clock_khz = pdata->clock_khz; | ||
312 | } else { | ||
313 | ret = ocores_i2c_of_probe(pdev, i2c); | ||
314 | if (ret) | ||
315 | return ret; | ||
250 | } | 316 | } |
251 | 317 | ||
252 | i2c->regstep = pdata->regstep; | ||
253 | i2c->clock_khz = pdata->clock_khz; | ||
254 | ocores_init(i2c); | 318 | ocores_init(i2c); |
255 | 319 | ||
256 | init_waitqueue_head(&i2c->wait); | 320 | init_waitqueue_head(&i2c->wait); |
257 | ret = request_irq(res2->start, ocores_isr, 0, pdev->name, i2c); | 321 | ret = devm_request_irq(&pdev->dev, res2->start, ocores_isr, 0, |
322 | pdev->name, i2c); | ||
258 | if (ret) { | 323 | if (ret) { |
259 | dev_err(&pdev->dev, "Cannot claim IRQ\n"); | 324 | dev_err(&pdev->dev, "Cannot claim IRQ\n"); |
260 | goto request_irq_failed; | 325 | return ret; |
261 | } | 326 | } |
262 | 327 | ||
263 | /* hook up driver to tree */ | 328 | /* hook up driver to tree */ |
@@ -265,36 +330,29 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) | |||
265 | i2c->adap = ocores_adapter; | 330 | i2c->adap = ocores_adapter; |
266 | i2c_set_adapdata(&i2c->adap, i2c); | 331 | i2c_set_adapdata(&i2c->adap, i2c); |
267 | i2c->adap.dev.parent = &pdev->dev; | 332 | i2c->adap.dev.parent = &pdev->dev; |
333 | #ifdef CONFIG_OF | ||
334 | i2c->adap.dev.of_node = pdev->dev.of_node; | ||
335 | #endif | ||
268 | 336 | ||
269 | /* add i2c adapter to i2c tree */ | 337 | /* add i2c adapter to i2c tree */ |
270 | ret = i2c_add_adapter(&i2c->adap); | 338 | ret = i2c_add_adapter(&i2c->adap); |
271 | if (ret) { | 339 | if (ret) { |
272 | dev_err(&pdev->dev, "Failed to add adapter\n"); | 340 | dev_err(&pdev->dev, "Failed to add adapter\n"); |
273 | goto add_adapter_failed; | 341 | return ret; |
274 | } | 342 | } |
275 | 343 | ||
276 | /* add in known devices to the bus */ | 344 | /* add in known devices to the bus */ |
277 | for (i = 0; i < pdata->num_devices; i++) | 345 | if (pdata) { |
278 | i2c_new_device(&i2c->adap, pdata->devices + i); | 346 | for (i = 0; i < pdata->num_devices; i++) |
347 | i2c_new_device(&i2c->adap, pdata->devices + i); | ||
348 | } | ||
279 | 349 | ||
280 | return 0; | 350 | return 0; |
281 | |||
282 | add_adapter_failed: | ||
283 | free_irq(res2->start, i2c); | ||
284 | request_irq_failed: | ||
285 | iounmap(i2c->base); | ||
286 | map_failed: | ||
287 | release_mem_region(res->start, resource_size(res)); | ||
288 | request_mem_failed: | ||
289 | kfree(i2c); | ||
290 | |||
291 | return ret; | ||
292 | } | 351 | } |
293 | 352 | ||
294 | static int __devexit ocores_i2c_remove(struct platform_device* pdev) | 353 | static int __devexit ocores_i2c_remove(struct platform_device* pdev) |
295 | { | 354 | { |
296 | struct ocores_i2c *i2c = platform_get_drvdata(pdev); | 355 | struct ocores_i2c *i2c = platform_get_drvdata(pdev); |
297 | struct resource *res; | ||
298 | 356 | ||
299 | /* disable i2c logic */ | 357 | /* disable i2c logic */ |
300 | oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL) | 358 | oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL) |
@@ -304,18 +362,6 @@ static int __devexit ocores_i2c_remove(struct platform_device* pdev) | |||
304 | i2c_del_adapter(&i2c->adap); | 362 | i2c_del_adapter(&i2c->adap); |
305 | platform_set_drvdata(pdev, NULL); | 363 | platform_set_drvdata(pdev, NULL); |
306 | 364 | ||
307 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
308 | if (res) | ||
309 | free_irq(res->start, i2c); | ||
310 | |||
311 | iounmap(i2c->base); | ||
312 | |||
313 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
314 | if (res) | ||
315 | release_mem_region(res->start, resource_size(res)); | ||
316 | |||
317 | kfree(i2c); | ||
318 | |||
319 | return 0; | 365 | return 0; |
320 | } | 366 | } |
321 | 367 | ||
@@ -344,6 +390,16 @@ static int ocores_i2c_resume(struct platform_device *pdev) | |||
344 | #define ocores_i2c_resume NULL | 390 | #define ocores_i2c_resume NULL |
345 | #endif | 391 | #endif |
346 | 392 | ||
393 | #ifdef CONFIG_OF | ||
394 | static struct of_device_id ocores_i2c_match[] = { | ||
395 | { | ||
396 | .compatible = "opencores,i2c-ocores", | ||
397 | }, | ||
398 | {}, | ||
399 | }; | ||
400 | MODULE_DEVICE_TABLE(of, ocores_i2c_match); | ||
401 | #endif | ||
402 | |||
347 | /* work with hotplug and coldplug */ | 403 | /* work with hotplug and coldplug */ |
348 | MODULE_ALIAS("platform:ocores-i2c"); | 404 | MODULE_ALIAS("platform:ocores-i2c"); |
349 | 405 | ||
@@ -355,6 +411,9 @@ static struct platform_driver ocores_i2c_driver = { | |||
355 | .driver = { | 411 | .driver = { |
356 | .owner = THIS_MODULE, | 412 | .owner = THIS_MODULE, |
357 | .name = "ocores-i2c", | 413 | .name = "ocores-i2c", |
414 | #ifdef CONFIG_OF | ||
415 | .of_match_table = ocores_i2c_match, | ||
416 | #endif | ||
358 | }, | 417 | }, |
359 | }; | 418 | }; |
360 | 419 | ||
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 9d090833e245..b605ff3a1fa0 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -598,12 +598,8 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap, | |||
598 | * REVISIT: We should abort the transfer on signals, but the bus goes | 598 | * REVISIT: We should abort the transfer on signals, but the bus goes |
599 | * into arbitration and we're currently unable to recover from it. | 599 | * into arbitration and we're currently unable to recover from it. |
600 | */ | 600 | */ |
601 | if (dev->set_mpu_wkup_lat != NULL) | ||
602 | dev->set_mpu_wkup_lat(dev->dev, dev->latency); | ||
603 | r = wait_for_completion_timeout(&dev->cmd_complete, | 601 | r = wait_for_completion_timeout(&dev->cmd_complete, |
604 | OMAP_I2C_TIMEOUT); | 602 | OMAP_I2C_TIMEOUT); |
605 | if (dev->set_mpu_wkup_lat != NULL) | ||
606 | dev->set_mpu_wkup_lat(dev->dev, -1); | ||
607 | dev->buf_len = 0; | 603 | dev->buf_len = 0; |
608 | if (r < 0) | 604 | if (r < 0) |
609 | return r; | 605 | return r; |
@@ -654,12 +650,18 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
654 | if (r < 0) | 650 | if (r < 0) |
655 | goto out; | 651 | goto out; |
656 | 652 | ||
653 | if (dev->set_mpu_wkup_lat != NULL) | ||
654 | dev->set_mpu_wkup_lat(dev->dev, dev->latency); | ||
655 | |||
657 | for (i = 0; i < num; i++) { | 656 | for (i = 0; i < num; i++) { |
658 | r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1))); | 657 | r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1))); |
659 | if (r != 0) | 658 | if (r != 0) |
660 | break; | 659 | break; |
661 | } | 660 | } |
662 | 661 | ||
662 | if (dev->set_mpu_wkup_lat != NULL) | ||
663 | dev->set_mpu_wkup_lat(dev->dev, -1); | ||
664 | |||
663 | if (r == 0) | 665 | if (r == 0) |
664 | r = num; | 666 | r = num; |
665 | 667 | ||