Merge commit 'refs/merge-requests/1' of git://gitorious.org/linux-on-wince-htc/linux_...
[htc-linux.git] / drivers / i2c / busses / i2c-pnx.c
blobfbab6846ae645a0a1324ecf3f23c939aae78289a
1 /*
2 * Provides I2C support for Philips PNX010x/PNX4008 boards.
4 * Authors: Dennis Kovalev <dkovalev@ru.mvista.com>
5 * Vitaly Wool <vwool@ru.mvista.com>
7 * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under
8 * the terms of the GNU General Public License version 2. This program
9 * is licensed "as is" without any warranty of any kind, whether express
10 * or implied.
13 #include <linux/module.h>
14 #include <linux/interrupt.h>
15 #include <linux/ioport.h>
16 #include <linux/delay.h>
17 #include <linux/i2c.h>
18 #include <linux/timer.h>
19 #include <linux/completion.h>
20 #include <linux/platform_device.h>
21 #include <linux/i2c-pnx.h>
22 #include <linux/io.h>
23 #include <mach/hardware.h>
24 #include <mach/i2c.h>
25 #include <asm/irq.h>
26 #include <asm/uaccess.h>
28 #define I2C_PNX_TIMEOUT 10 /* msec */
29 #define I2C_PNX_SPEED_KHZ 100
30 #define I2C_PNX_REGION_SIZE 0x100
31 #define PNX_DEFAULT_FREQ 13 /* MHz */
33 static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data)
35 while (timeout > 0 &&
36 (ioread32(I2C_REG_STS(data)) & mstatus_active)) {
37 mdelay(1);
38 timeout--;
40 return (timeout <= 0);
43 static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data)
45 while (timeout > 0 &&
46 (ioread32(I2C_REG_CTL(data)) & mcntrl_reset)) {
47 mdelay(1);
48 timeout--;
50 return (timeout <= 0);
53 static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap)
55 struct i2c_pnx_algo_data *data = adap->algo_data;
56 struct timer_list *timer = &data->mif.timer;
57 int expires = I2C_PNX_TIMEOUT / (1000 / HZ);
59 if (expires <= 1)
60 expires = 2;
62 del_timer_sync(timer);
64 dev_dbg(&adap->dev, "Timer armed at %lu plus %u jiffies.\n",
65 jiffies, expires);
67 timer->expires = jiffies + expires;
68 timer->data = (unsigned long)adap;
70 add_timer(timer);
73 /**
74 * i2c_pnx_start - start a device
75 * @slave_addr: slave address
76 * @adap: pointer to adapter structure
78 * Generate a START signal in the desired mode.
80 static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap)
82 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
84 dev_dbg(&adap->dev, "%s(): addr 0x%x mode %d\n", __func__,
85 slave_addr, alg_data->mif.mode);
87 /* Check for 7 bit slave addresses only */
88 if (slave_addr & ~0x7f) {
89 dev_err(&adap->dev, "%s: Invalid slave address %x. "
90 "Only 7-bit addresses are supported\n",
91 adap->name, slave_addr);
92 return -EINVAL;
95 /* First, make sure bus is idle */
96 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) {
97 /* Somebody else is monopolizing the bus */
98 dev_err(&adap->dev, "%s: Bus busy. Slave addr = %02x, "
99 "cntrl = %x, stat = %x\n",
100 adap->name, slave_addr,
101 ioread32(I2C_REG_CTL(alg_data)),
102 ioread32(I2C_REG_STS(alg_data)));
103 return -EBUSY;
104 } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) {
105 /* Sorry, we lost the bus */
106 dev_err(&adap->dev, "%s: Arbitration failure. "
107 "Slave addr = %02x\n", adap->name, slave_addr);
108 return -EIO;
112 * OK, I2C is enabled and we have the bus.
113 * Clear the current TDI and AFI status flags.
115 iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi,
116 I2C_REG_STS(alg_data));
118 dev_dbg(&adap->dev, "%s(): sending %#x\n", __func__,
119 (slave_addr << 1) | start_bit | alg_data->mif.mode);
121 /* Write the slave address, START bit and R/W bit */
122 iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode,
123 I2C_REG_TX(alg_data));
125 dev_dbg(&adap->dev, "%s(): exit\n", __func__);
127 return 0;
131 * i2c_pnx_stop - stop a device
132 * @adap: pointer to I2C adapter structure
134 * Generate a STOP signal to terminate the master transaction.
136 static void i2c_pnx_stop(struct i2c_adapter *adap)
138 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
139 /* Only 1 msec max timeout due to interrupt context */
140 long timeout = 1000;
142 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
143 __func__, ioread32(I2C_REG_STS(alg_data)));
145 /* Write a STOP bit to TX FIFO */
146 iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data));
148 /* Wait until the STOP is seen. */
149 while (timeout > 0 &&
150 (ioread32(I2C_REG_STS(alg_data)) & mstatus_active)) {
151 /* may be called from interrupt context */
152 udelay(1);
153 timeout--;
156 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
157 __func__, ioread32(I2C_REG_STS(alg_data)));
161 * i2c_pnx_master_xmit - transmit data to slave
162 * @adap: pointer to I2C adapter structure
164 * Sends one byte of data to the slave
166 static int i2c_pnx_master_xmit(struct i2c_adapter *adap)
168 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
169 u32 val;
171 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
172 __func__, ioread32(I2C_REG_STS(alg_data)));
174 if (alg_data->mif.len > 0) {
175 /* We still have something to talk about... */
176 val = *alg_data->mif.buf++;
178 if (alg_data->mif.len == 1) {
179 val |= stop_bit;
180 if (!alg_data->last)
181 val |= start_bit;
184 alg_data->mif.len--;
185 iowrite32(val, I2C_REG_TX(alg_data));
187 dev_dbg(&adap->dev, "%s(): xmit %#x [%d]\n", __func__,
188 val, alg_data->mif.len + 1);
190 if (alg_data->mif.len == 0) {
191 if (alg_data->last) {
192 /* Wait until the STOP is seen. */
193 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data))
194 dev_err(&adap->dev, "The bus is still "
195 "active after timeout\n");
197 /* Disable master interrupts */
198 iowrite32(ioread32(I2C_REG_CTL(alg_data)) &
199 ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie),
200 I2C_REG_CTL(alg_data));
202 del_timer_sync(&alg_data->mif.timer);
204 dev_dbg(&adap->dev, "%s(): Waking up xfer routine.\n",
205 __func__);
207 complete(&alg_data->mif.complete);
209 } else if (alg_data->mif.len == 0) {
210 /* zero-sized transfer */
211 i2c_pnx_stop(adap);
213 /* Disable master interrupts. */
214 iowrite32(ioread32(I2C_REG_CTL(alg_data)) &
215 ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie),
216 I2C_REG_CTL(alg_data));
218 /* Stop timer. */
219 del_timer_sync(&alg_data->mif.timer);
220 dev_dbg(&adap->dev, "%s(): Waking up xfer routine after "
221 "zero-xfer.\n", __func__);
223 complete(&alg_data->mif.complete);
226 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
227 __func__, ioread32(I2C_REG_STS(alg_data)));
229 return 0;
233 * i2c_pnx_master_rcv - receive data from slave
234 * @adap: pointer to I2C adapter structure
236 * Reads one byte data from the slave
238 static int i2c_pnx_master_rcv(struct i2c_adapter *adap)
240 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
241 unsigned int val = 0;
242 u32 ctl = 0;
244 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
245 __func__, ioread32(I2C_REG_STS(alg_data)));
247 /* Check, whether there is already data,
248 * or we didn't 'ask' for it yet.
250 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) {
251 dev_dbg(&adap->dev, "%s(): Write dummy data to fill "
252 "Rx-fifo...\n", __func__);
254 if (alg_data->mif.len == 1) {
255 /* Last byte, do not acknowledge next rcv. */
256 val |= stop_bit;
257 if (!alg_data->last)
258 val |= start_bit;
261 * Enable interrupt RFDAIE (data in Rx fifo),
262 * and disable DRMIE (need data for Tx)
264 ctl = ioread32(I2C_REG_CTL(alg_data));
265 ctl |= mcntrl_rffie | mcntrl_daie;
266 ctl &= ~mcntrl_drmie;
267 iowrite32(ctl, I2C_REG_CTL(alg_data));
271 * Now we'll 'ask' for data:
272 * For each byte we want to receive, we must
273 * write a (dummy) byte to the Tx-FIFO.
275 iowrite32(val, I2C_REG_TX(alg_data));
277 return 0;
280 /* Handle data. */
281 if (alg_data->mif.len > 0) {
282 val = ioread32(I2C_REG_RX(alg_data));
283 *alg_data->mif.buf++ = (u8) (val & 0xff);
284 dev_dbg(&adap->dev, "%s(): rcv 0x%x [%d]\n", __func__, val,
285 alg_data->mif.len);
287 alg_data->mif.len--;
288 if (alg_data->mif.len == 0) {
289 if (alg_data->last)
290 /* Wait until the STOP is seen. */
291 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data))
292 dev_err(&adap->dev, "The bus is still "
293 "active after timeout\n");
295 /* Disable master interrupts */
296 ctl = ioread32(I2C_REG_CTL(alg_data));
297 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie |
298 mcntrl_drmie | mcntrl_daie);
299 iowrite32(ctl, I2C_REG_CTL(alg_data));
301 /* Kill timer. */
302 del_timer_sync(&alg_data->mif.timer);
303 complete(&alg_data->mif.complete);
307 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
308 __func__, ioread32(I2C_REG_STS(alg_data)));
310 return 0;
313 static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
315 u32 stat, ctl;
316 struct i2c_adapter *adap = dev_id;
317 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
319 dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n",
320 __func__,
321 ioread32(I2C_REG_STS(alg_data)),
322 ioread32(I2C_REG_CTL(alg_data)),
323 alg_data->mif.mode);
324 stat = ioread32(I2C_REG_STS(alg_data));
326 /* let's see what kind of event this is */
327 if (stat & mstatus_afi) {
328 /* We lost arbitration in the midst of a transfer */
329 alg_data->mif.ret = -EIO;
331 /* Disable master interrupts. */
332 ctl = ioread32(I2C_REG_CTL(alg_data));
333 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie |
334 mcntrl_drmie);
335 iowrite32(ctl, I2C_REG_CTL(alg_data));
337 /* Stop timer, to prevent timeout. */
338 del_timer_sync(&alg_data->mif.timer);
339 complete(&alg_data->mif.complete);
340 } else if (stat & mstatus_nai) {
341 /* Slave did not acknowledge, generate a STOP */
342 dev_dbg(&adap->dev, "%s(): "
343 "Slave did not acknowledge, generating a STOP.\n",
344 __func__);
345 i2c_pnx_stop(adap);
347 /* Disable master interrupts. */
348 ctl = ioread32(I2C_REG_CTL(alg_data));
349 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie |
350 mcntrl_drmie);
351 iowrite32(ctl, I2C_REG_CTL(alg_data));
353 /* Our return value. */
354 alg_data->mif.ret = -EIO;
356 /* Stop timer, to prevent timeout. */
357 del_timer_sync(&alg_data->mif.timer);
358 complete(&alg_data->mif.complete);
359 } else {
361 * Two options:
362 * - Master Tx needs data.
363 * - There is data in the Rx-fifo
364 * The latter is only the case if we have requested for data,
365 * via a dummy write. (See 'i2c_pnx_master_rcv'.)
366 * We therefore check, as a sanity check, whether that interrupt
367 * has been enabled.
369 if ((stat & mstatus_drmi) || !(stat & mstatus_rfe)) {
370 if (alg_data->mif.mode == I2C_SMBUS_WRITE) {
371 i2c_pnx_master_xmit(adap);
372 } else if (alg_data->mif.mode == I2C_SMBUS_READ) {
373 i2c_pnx_master_rcv(adap);
378 /* Clear TDI and AFI bits */
379 stat = ioread32(I2C_REG_STS(alg_data));
380 iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data));
382 dev_dbg(&adap->dev, "%s(): exiting, stat = %x ctrl = %x.\n",
383 __func__, ioread32(I2C_REG_STS(alg_data)),
384 ioread32(I2C_REG_CTL(alg_data)));
386 return IRQ_HANDLED;
389 static void i2c_pnx_timeout(unsigned long data)
391 struct i2c_adapter *adap = (struct i2c_adapter *)data;
392 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
393 u32 ctl;
395 dev_err(&adap->dev, "Master timed out. stat = %04x, cntrl = %04x. "
396 "Resetting master...\n",
397 ioread32(I2C_REG_STS(alg_data)),
398 ioread32(I2C_REG_CTL(alg_data)));
400 /* Reset master and disable interrupts */
401 ctl = ioread32(I2C_REG_CTL(alg_data));
402 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie | mcntrl_drmie);
403 iowrite32(ctl, I2C_REG_CTL(alg_data));
405 ctl |= mcntrl_reset;
406 iowrite32(ctl, I2C_REG_CTL(alg_data));
407 wait_reset(I2C_PNX_TIMEOUT, alg_data);
408 alg_data->mif.ret = -EIO;
409 complete(&alg_data->mif.complete);
412 static inline void bus_reset_if_active(struct i2c_adapter *adap)
414 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
415 u32 stat;
417 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) {
418 dev_err(&adap->dev,
419 "%s: Bus is still active after xfer. Reset it...\n",
420 adap->name);
421 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
422 I2C_REG_CTL(alg_data));
423 wait_reset(I2C_PNX_TIMEOUT, alg_data);
424 } else if (!(stat & mstatus_rfe) || !(stat & mstatus_tfe)) {
425 /* If there is data in the fifo's after transfer,
426 * flush fifo's by reset.
428 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
429 I2C_REG_CTL(alg_data));
430 wait_reset(I2C_PNX_TIMEOUT, alg_data);
431 } else if (stat & mstatus_nai) {
432 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
433 I2C_REG_CTL(alg_data));
434 wait_reset(I2C_PNX_TIMEOUT, alg_data);
439 * i2c_pnx_xfer - generic transfer entry point
440 * @adap: pointer to I2C adapter structure
441 * @msgs: array of messages
442 * @num: number of messages
444 * Initiates the transfer
446 static int
447 i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
449 struct i2c_msg *pmsg;
450 int rc = 0, completed = 0, i;
451 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
452 u32 stat = ioread32(I2C_REG_STS(alg_data));
454 dev_dbg(&adap->dev, "%s(): entering: %d messages, stat = %04x.\n",
455 __func__, num, ioread32(I2C_REG_STS(alg_data)));
457 bus_reset_if_active(adap);
459 /* Process transactions in a loop. */
460 for (i = 0; rc >= 0 && i < num; i++) {
461 u8 addr;
463 pmsg = &msgs[i];
464 addr = pmsg->addr;
466 if (pmsg->flags & I2C_M_TEN) {
467 dev_err(&adap->dev,
468 "%s: 10 bits addr not supported!\n",
469 adap->name);
470 rc = -EINVAL;
471 break;
474 alg_data->mif.buf = pmsg->buf;
475 alg_data->mif.len = pmsg->len;
476 alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ?
477 I2C_SMBUS_READ : I2C_SMBUS_WRITE;
478 alg_data->mif.ret = 0;
479 alg_data->last = (i == num - 1);
481 dev_dbg(&adap->dev, "%s(): mode %d, %d bytes\n", __func__,
482 alg_data->mif.mode,
483 alg_data->mif.len);
485 i2c_pnx_arm_timer(adap);
487 /* initialize the completion var */
488 init_completion(&alg_data->mif.complete);
490 /* Enable master interrupt */
491 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie |
492 mcntrl_naie | mcntrl_drmie,
493 I2C_REG_CTL(alg_data));
495 /* Put start-code and slave-address on the bus. */
496 rc = i2c_pnx_start(addr, adap);
497 if (rc < 0)
498 break;
500 /* Wait for completion */
501 wait_for_completion(&alg_data->mif.complete);
503 if (!(rc = alg_data->mif.ret))
504 completed++;
505 dev_dbg(&adap->dev, "%s(): Complete, return code = %d.\n",
506 __func__, rc);
508 /* Clear TDI and AFI bits in case they are set. */
509 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) {
510 dev_dbg(&adap->dev,
511 "%s: TDI still set... clearing now.\n",
512 adap->name);
513 iowrite32(stat, I2C_REG_STS(alg_data));
515 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) {
516 dev_dbg(&adap->dev,
517 "%s: AFI still set... clearing now.\n",
518 adap->name);
519 iowrite32(stat, I2C_REG_STS(alg_data));
523 bus_reset_if_active(adap);
525 /* Cleanup to be sure... */
526 alg_data->mif.buf = NULL;
527 alg_data->mif.len = 0;
529 dev_dbg(&adap->dev, "%s(): exiting, stat = %x\n",
530 __func__, ioread32(I2C_REG_STS(alg_data)));
532 if (completed != num)
533 return ((rc < 0) ? rc : -EREMOTEIO);
535 return num;
538 static u32 i2c_pnx_func(struct i2c_adapter *adapter)
540 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
543 static struct i2c_algorithm pnx_algorithm = {
544 .master_xfer = i2c_pnx_xfer,
545 .functionality = i2c_pnx_func,
548 static int i2c_pnx_controller_suspend(struct platform_device *pdev,
549 pm_message_t state)
551 struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
552 return i2c_pnx->suspend(pdev, state);
555 static int i2c_pnx_controller_resume(struct platform_device *pdev)
557 struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
558 return i2c_pnx->resume(pdev);
561 static int __devinit i2c_pnx_probe(struct platform_device *pdev)
563 unsigned long tmp;
564 int ret = 0;
565 struct i2c_pnx_algo_data *alg_data;
566 int freq_mhz;
567 struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data;
569 if (!i2c_pnx || !i2c_pnx->adapter) {
570 dev_err(&pdev->dev, "%s: no platform data supplied\n",
571 __func__);
572 ret = -EINVAL;
573 goto out;
576 platform_set_drvdata(pdev, i2c_pnx);
578 if (i2c_pnx->calculate_input_freq)
579 freq_mhz = i2c_pnx->calculate_input_freq(pdev);
580 else {
581 freq_mhz = PNX_DEFAULT_FREQ;
582 dev_info(&pdev->dev, "Setting bus frequency to default value: "
583 "%d MHz\n", freq_mhz);
586 i2c_pnx->adapter->algo = &pnx_algorithm;
588 alg_data = i2c_pnx->adapter->algo_data;
589 init_timer(&alg_data->mif.timer);
590 alg_data->mif.timer.function = i2c_pnx_timeout;
591 alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter;
593 /* Register I/O resource */
594 if (!request_mem_region(alg_data->base, I2C_PNX_REGION_SIZE,
595 pdev->name)) {
596 dev_err(&pdev->dev,
597 "I/O region 0x%08x for I2C already in use.\n",
598 alg_data->base);
599 ret = -ENODEV;
600 goto out_drvdata;
603 if (!(alg_data->ioaddr =
604 (u32)ioremap(alg_data->base, I2C_PNX_REGION_SIZE))) {
605 dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n");
606 ret = -ENOMEM;
607 goto out_release;
610 i2c_pnx->set_clock_run(pdev);
613 * Clock Divisor High This value is the number of system clocks
614 * the serial clock (SCL) will be high.
615 * For example, if the system clock period is 50 ns and the maximum
616 * desired serial period is 10000 ns (100 kHz), then CLKHI would be
617 * set to 0.5*(f_sys/f_i2c)-2=0.5*(20e6/100e3)-2=98. The actual value
618 * programmed into CLKHI will vary from this slightly due to
619 * variations in the output pad's rise and fall times as well as
620 * the deglitching filter length.
623 tmp = ((freq_mhz * 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2;
624 iowrite32(tmp, I2C_REG_CKH(alg_data));
625 iowrite32(tmp, I2C_REG_CKL(alg_data));
627 iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data));
628 if (wait_reset(I2C_PNX_TIMEOUT, alg_data)) {
629 ret = -ENODEV;
630 goto out_unmap;
632 init_completion(&alg_data->mif.complete);
634 ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
635 0, pdev->name, i2c_pnx->adapter);
636 if (ret)
637 goto out_clock;
639 /* Register this adapter with the I2C subsystem */
640 i2c_pnx->adapter->dev.parent = &pdev->dev;
641 ret = i2c_add_adapter(i2c_pnx->adapter);
642 if (ret < 0) {
643 dev_err(&pdev->dev, "I2C: Failed to add bus\n");
644 goto out_irq;
647 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
648 i2c_pnx->adapter->name, alg_data->base, alg_data->irq);
650 return 0;
652 out_irq:
653 free_irq(alg_data->irq, i2c_pnx->adapter);
654 out_clock:
655 i2c_pnx->set_clock_stop(pdev);
656 out_unmap:
657 iounmap((void *)alg_data->ioaddr);
658 out_release:
659 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
660 out_drvdata:
661 platform_set_drvdata(pdev, NULL);
662 out:
663 return ret;
666 static int __devexit i2c_pnx_remove(struct platform_device *pdev)
668 struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
669 struct i2c_adapter *adap = i2c_pnx->adapter;
670 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
672 free_irq(alg_data->irq, i2c_pnx->adapter);
673 i2c_del_adapter(adap);
674 i2c_pnx->set_clock_stop(pdev);
675 iounmap((void *)alg_data->ioaddr);
676 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
677 platform_set_drvdata(pdev, NULL);
679 return 0;
682 static struct platform_driver i2c_pnx_driver = {
683 .driver = {
684 .name = "pnx-i2c",
685 .owner = THIS_MODULE,
687 .probe = i2c_pnx_probe,
688 .remove = __devexit_p(i2c_pnx_remove),
689 .suspend = i2c_pnx_controller_suspend,
690 .resume = i2c_pnx_controller_resume,
693 static int __init i2c_adap_pnx_init(void)
695 return platform_driver_register(&i2c_pnx_driver);
698 static void __exit i2c_adap_pnx_exit(void)
700 platform_driver_unregister(&i2c_pnx_driver);
703 MODULE_AUTHOR("Vitaly Wool, Dennis Kovalev <source@mvista.com>");
704 MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses");
705 MODULE_LICENSE("GPL");
706 MODULE_ALIAS("platform:pnx-i2c");
708 /* We need to make sure I2C is initialized before USB */
709 subsys_initcall(i2c_adap_pnx_init);
710 module_exit(i2c_adap_pnx_exit);