diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-05 21:58:06 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-05 21:58:06 -0500 |
commit | c58bd34d00e04df9a0691732086cf8102b20d907 (patch) | |
tree | 82e0a95b582974351f24cdf812d023c38d921474 /drivers/i2c/busses/i2c-s3c2410.c | |
parent | 8606ab6d30dbaaafff985bd462bf33c36997eae9 (diff) | |
parent | 88f60f62f31092db46aa5c71bf6da67c958bc420 (diff) |
Merge branch 'i2c-next' of git://aeryn.fluff.org.uk/bjdooks/linux
* 'i2c-next' of git://aeryn.fluff.org.uk/bjdooks/linux:
i2c-omap: fix type of irq handler function
i2c-s3c2410: Change IRQ to be plain integer.
i2c-s3c2410: Allow more than one i2c-s3c2410 adapter
i2c-s3c2410: Remove default platform data.
i2c-s3c2410: Use platform data for gpio configuration
i2c-s3c2410: Fixup style problems from checkpatch.pl
i2c-omap: Enable I2C wakeups for 34xx
i2c-omap: reprogram OCP_SYSCONFIG register after reset
i2c-omap: convert 'rev1' flag to generic 'rev' u8
i2c-omap: fix I2C timeouts due to recursive omap_i2c_{un,}idle()
i2c-omap: Clean-up i2c-omap
i2c-omap: Don't compile in OMAP15xx I2C ISR for non-OMAP15xx builds
i2c-omap: Mark init-only functions as __init
i2c-omap: Add support for omap34xx
i2c-omap: FIFO handling support and broken hw workaround for i2c-omap
i2c-omap: Add high-speed support to omap-i2c
i2c-omap: Close suspected race between omap_i2c_idle() and omap_i2c_isr()
i2c-omap: Do not use interruptible wait call in omap_i2c_xfer_msg
Fix up apparently-trivial conflict in drivers/i2c/busses/i2c-s3c2410.c
Diffstat (limited to 'drivers/i2c/busses/i2c-s3c2410.c')
-rw-r--r-- | drivers/i2c/busses/i2c-s3c2410.c | 185 |
1 files changed, 78 insertions, 107 deletions
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index c39079f9c73f..f69f91ffb469 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c | |||
@@ -35,11 +35,9 @@ | |||
35 | #include <linux/clk.h> | 35 | #include <linux/clk.h> |
36 | #include <linux/cpufreq.h> | 36 | #include <linux/cpufreq.h> |
37 | 37 | ||
38 | #include <mach/hardware.h> | ||
39 | #include <asm/irq.h> | 38 | #include <asm/irq.h> |
40 | #include <asm/io.h> | 39 | #include <asm/io.h> |
41 | 40 | ||
42 | #include <mach/regs-gpio.h> | ||
43 | #include <plat/regs-iic.h> | 41 | #include <plat/regs-iic.h> |
44 | #include <plat/iic.h> | 42 | #include <plat/iic.h> |
45 | 43 | ||
@@ -64,6 +62,7 @@ struct s3c24xx_i2c { | |||
64 | unsigned int msg_ptr; | 62 | unsigned int msg_ptr; |
65 | 63 | ||
66 | unsigned int tx_setup; | 64 | unsigned int tx_setup; |
65 | unsigned int irq; | ||
67 | 66 | ||
68 | enum s3c24xx_i2c_state state; | 67 | enum s3c24xx_i2c_state state; |
69 | unsigned long clkrate; | 68 | unsigned long clkrate; |
@@ -71,7 +70,6 @@ struct s3c24xx_i2c { | |||
71 | void __iomem *regs; | 70 | void __iomem *regs; |
72 | struct clk *clk; | 71 | struct clk *clk; |
73 | struct device *dev; | 72 | struct device *dev; |
74 | struct resource *irq; | ||
75 | struct resource *ioarea; | 73 | struct resource *ioarea; |
76 | struct i2c_adapter adap; | 74 | struct i2c_adapter adap; |
77 | 75 | ||
@@ -80,16 +78,7 @@ struct s3c24xx_i2c { | |||
80 | #endif | 78 | #endif |
81 | }; | 79 | }; |
82 | 80 | ||
83 | /* default platform data to use if not supplied in the platform_device | 81 | /* default platform data removed, dev should always carry data. */ |
84 | */ | ||
85 | |||
86 | static struct s3c2410_platform_i2c s3c24xx_i2c_default_platform = { | ||
87 | .flags = 0, | ||
88 | .slave_addr = 0x10, | ||
89 | .bus_freq = 100*1000, | ||
90 | .max_freq = 400*1000, | ||
91 | .sda_delay = S3C2410_IICLC_SDA_DELAY5 | S3C2410_IICLC_FILTER_ON, | ||
92 | }; | ||
93 | 82 | ||
94 | /* s3c24xx_i2c_is2440() | 83 | /* s3c24xx_i2c_is2440() |
95 | * | 84 | * |
@@ -103,21 +92,6 @@ static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) | |||
103 | return !strcmp(pdev->name, "s3c2440-i2c"); | 92 | return !strcmp(pdev->name, "s3c2440-i2c"); |
104 | } | 93 | } |
105 | 94 | ||
106 | |||
107 | /* s3c24xx_i2c_get_platformdata | ||
108 | * | ||
109 | * get the platform data associated with the given device, or return | ||
110 | * the default if there is none | ||
111 | */ | ||
112 | |||
113 | static inline struct s3c2410_platform_i2c *s3c24xx_i2c_get_platformdata(struct device *dev) | ||
114 | { | ||
115 | if (dev->platform_data != NULL) | ||
116 | return (struct s3c2410_platform_i2c *)dev->platform_data; | ||
117 | |||
118 | return &s3c24xx_i2c_default_platform; | ||
119 | } | ||
120 | |||
121 | /* s3c24xx_i2c_master_complete | 95 | /* s3c24xx_i2c_master_complete |
122 | * | 96 | * |
123 | * complete the message and wake up the caller, using the given return code, | 97 | * complete the message and wake up the caller, using the given return code, |
@@ -130,7 +104,7 @@ static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret) | |||
130 | 104 | ||
131 | i2c->msg_ptr = 0; | 105 | i2c->msg_ptr = 0; |
132 | i2c->msg = NULL; | 106 | i2c->msg = NULL; |
133 | i2c->msg_idx ++; | 107 | i2c->msg_idx++; |
134 | i2c->msg_num = 0; | 108 | i2c->msg_num = 0; |
135 | if (ret) | 109 | if (ret) |
136 | i2c->msg_idx = ret; | 110 | i2c->msg_idx = ret; |
@@ -141,19 +115,17 @@ static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret) | |||
141 | static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) | 115 | static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) |
142 | { | 116 | { |
143 | unsigned long tmp; | 117 | unsigned long tmp; |
144 | 118 | ||
145 | tmp = readl(i2c->regs + S3C2410_IICCON); | 119 | tmp = readl(i2c->regs + S3C2410_IICCON); |
146 | writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); | 120 | writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); |
147 | |||
148 | } | 121 | } |
149 | 122 | ||
150 | static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) | 123 | static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) |
151 | { | 124 | { |
152 | unsigned long tmp; | 125 | unsigned long tmp; |
153 | 126 | ||
154 | tmp = readl(i2c->regs + S3C2410_IICCON); | 127 | tmp = readl(i2c->regs + S3C2410_IICCON); |
155 | writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); | 128 | writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); |
156 | |||
157 | } | 129 | } |
158 | 130 | ||
159 | /* irq enable/disable functions */ | 131 | /* irq enable/disable functions */ |
@@ -161,7 +133,7 @@ static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) | |||
161 | static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) | 133 | static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) |
162 | { | 134 | { |
163 | unsigned long tmp; | 135 | unsigned long tmp; |
164 | 136 | ||
165 | tmp = readl(i2c->regs + S3C2410_IICCON); | 137 | tmp = readl(i2c->regs + S3C2410_IICCON); |
166 | writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); | 138 | writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); |
167 | } | 139 | } |
@@ -169,7 +141,7 @@ static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) | |||
169 | static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) | 141 | static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) |
170 | { | 142 | { |
171 | unsigned long tmp; | 143 | unsigned long tmp; |
172 | 144 | ||
173 | tmp = readl(i2c->regs + S3C2410_IICCON); | 145 | tmp = readl(i2c->regs + S3C2410_IICCON); |
174 | writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); | 146 | writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); |
175 | } | 147 | } |
@@ -177,10 +149,10 @@ static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) | |||
177 | 149 | ||
178 | /* s3c24xx_i2c_message_start | 150 | /* s3c24xx_i2c_message_start |
179 | * | 151 | * |
180 | * put the start of a message onto the bus | 152 | * put the start of a message onto the bus |
181 | */ | 153 | */ |
182 | 154 | ||
183 | static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, | 155 | static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, |
184 | struct i2c_msg *msg) | 156 | struct i2c_msg *msg) |
185 | { | 157 | { |
186 | unsigned int addr = (msg->addr & 0x7f) << 1; | 158 | unsigned int addr = (msg->addr & 0x7f) << 1; |
@@ -199,15 +171,15 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, | |||
199 | if (msg->flags & I2C_M_REV_DIR_ADDR) | 171 | if (msg->flags & I2C_M_REV_DIR_ADDR) |
200 | addr ^= 1; | 172 | addr ^= 1; |
201 | 173 | ||
202 | // todo - check for wether ack wanted or not | 174 | /* todo - check for wether ack wanted or not */ |
203 | s3c24xx_i2c_enable_ack(i2c); | 175 | s3c24xx_i2c_enable_ack(i2c); |
204 | 176 | ||
205 | iiccon = readl(i2c->regs + S3C2410_IICCON); | 177 | iiccon = readl(i2c->regs + S3C2410_IICCON); |
206 | writel(stat, i2c->regs + S3C2410_IICSTAT); | 178 | writel(stat, i2c->regs + S3C2410_IICSTAT); |
207 | 179 | ||
208 | dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); | 180 | dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); |
209 | writeb(addr, i2c->regs + S3C2410_IICDS); | 181 | writeb(addr, i2c->regs + S3C2410_IICDS); |
210 | 182 | ||
211 | /* delay here to ensure the data byte has gotten onto the bus | 183 | /* delay here to ensure the data byte has gotten onto the bus |
212 | * before the transaction is started */ | 184 | * before the transaction is started */ |
213 | 185 | ||
@@ -215,8 +187,8 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, | |||
215 | 187 | ||
216 | dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); | 188 | dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); |
217 | writel(iiccon, i2c->regs + S3C2410_IICCON); | 189 | writel(iiccon, i2c->regs + S3C2410_IICCON); |
218 | 190 | ||
219 | stat |= S3C2410_IICSTAT_START; | 191 | stat |= S3C2410_IICSTAT_START; |
220 | writel(stat, i2c->regs + S3C2410_IICSTAT); | 192 | writel(stat, i2c->regs + S3C2410_IICSTAT); |
221 | } | 193 | } |
222 | 194 | ||
@@ -227,11 +199,11 @@ static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) | |||
227 | dev_dbg(i2c->dev, "STOP\n"); | 199 | dev_dbg(i2c->dev, "STOP\n"); |
228 | 200 | ||
229 | /* stop the transfer */ | 201 | /* stop the transfer */ |
230 | iicstat &= ~ S3C2410_IICSTAT_START; | 202 | iicstat &= ~S3C2410_IICSTAT_START; |
231 | writel(iicstat, i2c->regs + S3C2410_IICSTAT); | 203 | writel(iicstat, i2c->regs + S3C2410_IICSTAT); |
232 | 204 | ||
233 | i2c->state = STATE_STOP; | 205 | i2c->state = STATE_STOP; |
234 | 206 | ||
235 | s3c24xx_i2c_master_complete(i2c, ret); | 207 | s3c24xx_i2c_master_complete(i2c, ret); |
236 | s3c24xx_i2c_disable_irq(i2c); | 208 | s3c24xx_i2c_disable_irq(i2c); |
237 | } | 209 | } |
@@ -241,7 +213,7 @@ static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) | |||
241 | 213 | ||
242 | /* is_lastmsg() | 214 | /* is_lastmsg() |
243 | * | 215 | * |
244 | * returns TRUE if the current message is the last in the set | 216 | * returns TRUE if the current message is the last in the set |
245 | */ | 217 | */ |
246 | 218 | ||
247 | static inline int is_lastmsg(struct s3c24xx_i2c *i2c) | 219 | static inline int is_lastmsg(struct s3c24xx_i2c *i2c) |
@@ -289,14 +261,14 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
289 | 261 | ||
290 | case STATE_STOP: | 262 | case STATE_STOP: |
291 | dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); | 263 | dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); |
292 | s3c24xx_i2c_disable_irq(i2c); | 264 | s3c24xx_i2c_disable_irq(i2c); |
293 | goto out_ack; | 265 | goto out_ack; |
294 | 266 | ||
295 | case STATE_START: | 267 | case STATE_START: |
296 | /* last thing we did was send a start condition on the | 268 | /* last thing we did was send a start condition on the |
297 | * bus, or started a new i2c message | 269 | * bus, or started a new i2c message |
298 | */ | 270 | */ |
299 | 271 | ||
300 | if (iicstat & S3C2410_IICSTAT_LASTBIT && | 272 | if (iicstat & S3C2410_IICSTAT_LASTBIT && |
301 | !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { | 273 | !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { |
302 | /* ack was not received... */ | 274 | /* ack was not received... */ |
@@ -322,7 +294,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
322 | if (i2c->state == STATE_READ) | 294 | if (i2c->state == STATE_READ) |
323 | goto prepare_read; | 295 | goto prepare_read; |
324 | 296 | ||
325 | /* fall through to the write state, as we will need to | 297 | /* fall through to the write state, as we will need to |
326 | * send a byte as well */ | 298 | * send a byte as well */ |
327 | 299 | ||
328 | case STATE_WRITE: | 300 | case STATE_WRITE: |
@@ -339,7 +311,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
339 | } | 311 | } |
340 | } | 312 | } |
341 | 313 | ||
342 | retry_write: | 314 | retry_write: |
343 | 315 | ||
344 | if (!is_msgend(i2c)) { | 316 | if (!is_msgend(i2c)) { |
345 | byte = i2c->msg->buf[i2c->msg_ptr++]; | 317 | byte = i2c->msg->buf[i2c->msg_ptr++]; |
@@ -359,9 +331,9 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
359 | dev_dbg(i2c->dev, "WRITE: Next Message\n"); | 331 | dev_dbg(i2c->dev, "WRITE: Next Message\n"); |
360 | 332 | ||
361 | i2c->msg_ptr = 0; | 333 | i2c->msg_ptr = 0; |
362 | i2c->msg_idx ++; | 334 | i2c->msg_idx++; |
363 | i2c->msg++; | 335 | i2c->msg++; |
364 | 336 | ||
365 | /* check to see if we need to do another message */ | 337 | /* check to see if we need to do another message */ |
366 | if (i2c->msg->flags & I2C_M_NOSTART) { | 338 | if (i2c->msg->flags & I2C_M_NOSTART) { |
367 | 339 | ||
@@ -375,7 +347,6 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
375 | 347 | ||
376 | goto retry_write; | 348 | goto retry_write; |
377 | } else { | 349 | } else { |
378 | |||
379 | /* send the new start */ | 350 | /* send the new start */ |
380 | s3c24xx_i2c_message_start(i2c, i2c->msg); | 351 | s3c24xx_i2c_message_start(i2c, i2c->msg); |
381 | i2c->state = STATE_START; | 352 | i2c->state = STATE_START; |
@@ -389,7 +360,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
389 | break; | 360 | break; |
390 | 361 | ||
391 | case STATE_READ: | 362 | case STATE_READ: |
392 | /* we have a byte of data in the data register, do | 363 | /* we have a byte of data in the data register, do |
393 | * something with it, and then work out wether we are | 364 | * something with it, and then work out wether we are |
394 | * going to do any more read/write | 365 | * going to do any more read/write |
395 | */ | 366 | */ |
@@ -397,13 +368,13 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
397 | byte = readb(i2c->regs + S3C2410_IICDS); | 368 | byte = readb(i2c->regs + S3C2410_IICDS); |
398 | i2c->msg->buf[i2c->msg_ptr++] = byte; | 369 | i2c->msg->buf[i2c->msg_ptr++] = byte; |
399 | 370 | ||
400 | prepare_read: | 371 | prepare_read: |
401 | if (is_msglast(i2c)) { | 372 | if (is_msglast(i2c)) { |
402 | /* last byte of buffer */ | 373 | /* last byte of buffer */ |
403 | 374 | ||
404 | if (is_lastmsg(i2c)) | 375 | if (is_lastmsg(i2c)) |
405 | s3c24xx_i2c_disable_ack(i2c); | 376 | s3c24xx_i2c_disable_ack(i2c); |
406 | 377 | ||
407 | } else if (is_msgend(i2c)) { | 378 | } else if (is_msgend(i2c)) { |
408 | /* ok, we've read the entire buffer, see if there | 379 | /* ok, we've read the entire buffer, see if there |
409 | * is anything else we need to do */ | 380 | * is anything else we need to do */ |
@@ -429,7 +400,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) | |||
429 | /* acknowlegde the IRQ and get back on with the work */ | 400 | /* acknowlegde the IRQ and get back on with the work */ |
430 | 401 | ||
431 | out_ack: | 402 | out_ack: |
432 | tmp = readl(i2c->regs + S3C2410_IICCON); | 403 | tmp = readl(i2c->regs + S3C2410_IICCON); |
433 | tmp &= ~S3C2410_IICCON_IRQPEND; | 404 | tmp &= ~S3C2410_IICCON_IRQPEND; |
434 | writel(tmp, i2c->regs + S3C2410_IICCON); | 405 | writel(tmp, i2c->regs + S3C2410_IICCON); |
435 | out: | 406 | out: |
@@ -450,19 +421,19 @@ static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id) | |||
450 | status = readl(i2c->regs + S3C2410_IICSTAT); | 421 | status = readl(i2c->regs + S3C2410_IICSTAT); |
451 | 422 | ||
452 | if (status & S3C2410_IICSTAT_ARBITR) { | 423 | if (status & S3C2410_IICSTAT_ARBITR) { |
453 | // deal with arbitration loss | 424 | /* deal with arbitration loss */ |
454 | dev_err(i2c->dev, "deal with arbitration loss\n"); | 425 | dev_err(i2c->dev, "deal with arbitration loss\n"); |
455 | } | 426 | } |
456 | 427 | ||
457 | if (i2c->state == STATE_IDLE) { | 428 | if (i2c->state == STATE_IDLE) { |
458 | dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); | 429 | dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); |
459 | 430 | ||
460 | tmp = readl(i2c->regs + S3C2410_IICCON); | 431 | tmp = readl(i2c->regs + S3C2410_IICCON); |
461 | tmp &= ~S3C2410_IICCON_IRQPEND; | 432 | tmp &= ~S3C2410_IICCON_IRQPEND; |
462 | writel(tmp, i2c->regs + S3C2410_IICCON); | 433 | writel(tmp, i2c->regs + S3C2410_IICCON); |
463 | goto out; | 434 | goto out; |
464 | } | 435 | } |
465 | 436 | ||
466 | /* pretty much this leaves us with the fact that we've | 437 | /* pretty much this leaves us with the fact that we've |
467 | * transmitted or received whatever byte we last sent */ | 438 | * transmitted or received whatever byte we last sent */ |
468 | 439 | ||
@@ -485,16 +456,13 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) | |||
485 | 456 | ||
486 | while (timeout-- > 0) { | 457 | while (timeout-- > 0) { |
487 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); | 458 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); |
488 | 459 | ||
489 | if (!(iicstat & S3C2410_IICSTAT_BUSBUSY)) | 460 | if (!(iicstat & S3C2410_IICSTAT_BUSBUSY)) |
490 | return 0; | 461 | return 0; |
491 | 462 | ||
492 | msleep(1); | 463 | msleep(1); |
493 | } | 464 | } |
494 | 465 | ||
495 | dev_dbg(i2c->dev, "timeout: GPEDAT is %08x\n", | ||
496 | __raw_readl(S3C2410_GPEDAT)); | ||
497 | |||
498 | return -ETIMEDOUT; | 466 | return -ETIMEDOUT; |
499 | } | 467 | } |
500 | 468 | ||
@@ -503,7 +471,8 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) | |||
503 | * this starts an i2c transfer | 471 | * this starts an i2c transfer |
504 | */ | 472 | */ |
505 | 473 | ||
506 | static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num) | 474 | static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, |
475 | struct i2c_msg *msgs, int num) | ||
507 | { | 476 | { |
508 | unsigned long timeout; | 477 | unsigned long timeout; |
509 | int ret; | 478 | int ret; |
@@ -529,12 +498,12 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int | |||
529 | s3c24xx_i2c_enable_irq(i2c); | 498 | s3c24xx_i2c_enable_irq(i2c); |
530 | s3c24xx_i2c_message_start(i2c, msgs); | 499 | s3c24xx_i2c_message_start(i2c, msgs); |
531 | spin_unlock_irq(&i2c->lock); | 500 | spin_unlock_irq(&i2c->lock); |
532 | 501 | ||
533 | timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); | 502 | timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); |
534 | 503 | ||
535 | ret = i2c->msg_idx; | 504 | ret = i2c->msg_idx; |
536 | 505 | ||
537 | /* having these next two as dev_err() makes life very | 506 | /* having these next two as dev_err() makes life very |
538 | * noisy when doing an i2cdetect */ | 507 | * noisy when doing an i2cdetect */ |
539 | 508 | ||
540 | if (timeout == 0) | 509 | if (timeout == 0) |
@@ -591,19 +560,6 @@ static const struct i2c_algorithm s3c24xx_i2c_algorithm = { | |||
591 | .functionality = s3c24xx_i2c_func, | 560 | .functionality = s3c24xx_i2c_func, |
592 | }; | 561 | }; |
593 | 562 | ||
594 | static struct s3c24xx_i2c s3c24xx_i2c = { | ||
595 | .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_i2c.lock), | ||
596 | .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), | ||
597 | .tx_setup = 50, | ||
598 | .adap = { | ||
599 | .name = "s3c2410-i2c", | ||
600 | .owner = THIS_MODULE, | ||
601 | .algo = &s3c24xx_i2c_algorithm, | ||
602 | .retries = 2, | ||
603 | .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, | ||
604 | }, | ||
605 | }; | ||
606 | |||
607 | /* s3c24xx_i2c_calcdivisor | 563 | /* s3c24xx_i2c_calcdivisor |
608 | * | 564 | * |
609 | * return the divisor settings for a given frequency | 565 | * return the divisor settings for a given frequency |
@@ -643,7 +599,7 @@ static inline int freq_acceptable(unsigned int freq, unsigned int wanted) | |||
643 | { | 599 | { |
644 | int diff = freq - wanted; | 600 | int diff = freq - wanted; |
645 | 601 | ||
646 | return (diff >= -2 && diff <= 2); | 602 | return diff >= -2 && diff <= 2; |
647 | } | 603 | } |
648 | 604 | ||
649 | /* s3c24xx_i2c_clockrate | 605 | /* s3c24xx_i2c_clockrate |
@@ -655,7 +611,7 @@ static inline int freq_acceptable(unsigned int freq, unsigned int wanted) | |||
655 | 611 | ||
656 | static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) | 612 | static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) |
657 | { | 613 | { |
658 | struct s3c2410_platform_i2c *pdata; | 614 | struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data; |
659 | unsigned long clkin = clk_get_rate(i2c->clk); | 615 | unsigned long clkin = clk_get_rate(i2c->clk); |
660 | unsigned int divs, div1; | 616 | unsigned int divs, div1; |
661 | u32 iiccon; | 617 | u32 iiccon; |
@@ -663,10 +619,8 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) | |||
663 | int start, end; | 619 | int start, end; |
664 | 620 | ||
665 | i2c->clkrate = clkin; | 621 | i2c->clkrate = clkin; |
666 | |||
667 | pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent); | ||
668 | clkin /= 1000; /* clkin now in KHz */ | 622 | clkin /= 1000; /* clkin now in KHz */ |
669 | 623 | ||
670 | dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", | 624 | dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", |
671 | pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); | 625 | pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); |
672 | 626 | ||
@@ -774,7 +728,7 @@ static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) | |||
774 | 728 | ||
775 | /* s3c24xx_i2c_init | 729 | /* s3c24xx_i2c_init |
776 | * | 730 | * |
777 | * initialise the controller, set the IO lines and frequency | 731 | * initialise the controller, set the IO lines and frequency |
778 | */ | 732 | */ |
779 | 733 | ||
780 | static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) | 734 | static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) |
@@ -785,15 +739,15 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) | |||
785 | 739 | ||
786 | /* get the plafrom data */ | 740 | /* get the plafrom data */ |
787 | 741 | ||
788 | pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent); | 742 | pdata = i2c->dev->platform_data; |
789 | 743 | ||
790 | /* inititalise the gpio */ | 744 | /* inititalise the gpio */ |
791 | 745 | ||
792 | s3c2410_gpio_cfgpin(S3C2410_GPE15, S3C2410_GPE15_IICSDA); | 746 | if (pdata->cfg_gpio) |
793 | s3c2410_gpio_cfgpin(S3C2410_GPE14, S3C2410_GPE14_IICSCL); | 747 | pdata->cfg_gpio(to_platform_device(i2c->dev)); |
794 | 748 | ||
795 | /* write slave address */ | 749 | /* write slave address */ |
796 | 750 | ||
797 | writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); | 751 | writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); |
798 | 752 | ||
799 | dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); | 753 | dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); |
@@ -831,12 +785,32 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) | |||
831 | 785 | ||
832 | static int s3c24xx_i2c_probe(struct platform_device *pdev) | 786 | static int s3c24xx_i2c_probe(struct platform_device *pdev) |
833 | { | 787 | { |
834 | struct s3c24xx_i2c *i2c = &s3c24xx_i2c; | 788 | struct s3c24xx_i2c *i2c; |
835 | struct s3c2410_platform_i2c *pdata; | 789 | struct s3c2410_platform_i2c *pdata; |
836 | struct resource *res; | 790 | struct resource *res; |
837 | int ret; | 791 | int ret; |
838 | 792 | ||
839 | pdata = s3c24xx_i2c_get_platformdata(&pdev->dev); | 793 | pdata = pdev->dev.platform_data; |
794 | if (!pdata) { | ||
795 | dev_err(&pdev->dev, "no platform data\n"); | ||
796 | return -EINVAL; | ||
797 | } | ||
798 | |||
799 | i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL); | ||
800 | if (!i2c) { | ||
801 | dev_err(&pdev->dev, "no memory for state\n"); | ||
802 | return -ENOMEM; | ||
803 | } | ||
804 | |||
805 | strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name)); | ||
806 | i2c->adap.owner = THIS_MODULE; | ||
807 | i2c->adap.algo = &s3c24xx_i2c_algorithm; | ||
808 | i2c->adap.retries = 2; | ||
809 | i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | ||
810 | i2c->tx_setup = 50; | ||
811 | |||
812 | spin_lock_init(&i2c->lock); | ||
813 | init_waitqueue_head(&i2c->wait); | ||
840 | 814 | ||
841 | /* find the clock and enable it */ | 815 | /* find the clock and enable it */ |
842 | 816 | ||
@@ -878,7 +852,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
878 | goto err_ioarea; | 852 | goto err_ioarea; |
879 | } | 853 | } |
880 | 854 | ||
881 | dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); | 855 | dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", |
856 | i2c->regs, i2c->ioarea, res); | ||
882 | 857 | ||
883 | /* setup info block for the i2c core */ | 858 | /* setup info block for the i2c core */ |
884 | 859 | ||
@@ -892,29 +867,23 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
892 | goto err_iomap; | 867 | goto err_iomap; |
893 | 868 | ||
894 | /* find the IRQ for this unit (note, this relies on the init call to | 869 | /* find the IRQ for this unit (note, this relies on the init call to |
895 | * ensure no current IRQs pending | 870 | * ensure no current IRQs pending |
896 | */ | 871 | */ |
897 | 872 | ||
898 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 873 | i2c->irq = ret = platform_get_irq(pdev, 0); |
899 | if (res == NULL) { | 874 | if (ret <= 0) { |
900 | dev_err(&pdev->dev, "cannot find IRQ\n"); | 875 | dev_err(&pdev->dev, "cannot find IRQ\n"); |
901 | ret = -ENOENT; | ||
902 | goto err_iomap; | 876 | goto err_iomap; |
903 | } | 877 | } |
904 | 878 | ||
905 | ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, | 879 | ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED, |
906 | pdev->name, i2c); | 880 | dev_name(&pdev->dev), i2c); |
907 | 881 | ||
908 | if (ret != 0) { | 882 | if (ret != 0) { |
909 | dev_err(&pdev->dev, "cannot claim IRQ\n"); | 883 | dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); |
910 | goto err_iomap; | 884 | goto err_iomap; |
911 | } | 885 | } |
912 | 886 | ||
913 | i2c->irq = res; | ||
914 | |||
915 | dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res, | ||
916 | (unsigned long)res->start); | ||
917 | |||
918 | ret = s3c24xx_i2c_register_cpufreq(i2c); | 887 | ret = s3c24xx_i2c_register_cpufreq(i2c); |
919 | if (ret < 0) { | 888 | if (ret < 0) { |
920 | dev_err(&pdev->dev, "failed to register cpufreq notifier\n"); | 889 | dev_err(&pdev->dev, "failed to register cpufreq notifier\n"); |
@@ -944,7 +913,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
944 | s3c24xx_i2c_deregister_cpufreq(i2c); | 913 | s3c24xx_i2c_deregister_cpufreq(i2c); |
945 | 914 | ||
946 | err_irq: | 915 | err_irq: |
947 | free_irq(i2c->irq->start, i2c); | 916 | free_irq(i2c->irq, i2c); |
948 | 917 | ||
949 | err_iomap: | 918 | err_iomap: |
950 | iounmap(i2c->regs); | 919 | iounmap(i2c->regs); |
@@ -958,6 +927,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
958 | clk_put(i2c->clk); | 927 | clk_put(i2c->clk); |
959 | 928 | ||
960 | err_noclk: | 929 | err_noclk: |
930 | kfree(i2c); | ||
961 | return ret; | 931 | return ret; |
962 | } | 932 | } |
963 | 933 | ||
@@ -973,7 +943,7 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) | |||
973 | s3c24xx_i2c_deregister_cpufreq(i2c); | 943 | s3c24xx_i2c_deregister_cpufreq(i2c); |
974 | 944 | ||
975 | i2c_del_adapter(&i2c->adap); | 945 | i2c_del_adapter(&i2c->adap); |
976 | free_irq(i2c->irq->start, i2c); | 946 | free_irq(i2c->irq, i2c); |
977 | 947 | ||
978 | clk_disable(i2c->clk); | 948 | clk_disable(i2c->clk); |
979 | clk_put(i2c->clk); | 949 | clk_put(i2c->clk); |
@@ -982,6 +952,7 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) | |||
982 | 952 | ||
983 | release_resource(i2c->ioarea); | 953 | release_resource(i2c->ioarea); |
984 | kfree(i2c->ioarea); | 954 | kfree(i2c->ioarea); |
955 | kfree(i2c); | ||
985 | 956 | ||
986 | return 0; | 957 | return 0; |
987 | } | 958 | } |