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