aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-nomadik.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-nomadik.c')
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c189
1 files changed, 102 insertions, 87 deletions
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index a92440dbef07..5e6f1eed4f83 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -14,7 +14,8 @@
14 */ 14 */
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/platform_device.h> 17#include <linux/amba/bus.h>
18#include <linux/atomic.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/i2c.h> 21#include <linux/i2c.h>
@@ -23,8 +24,7 @@
23#include <linux/io.h> 24#include <linux/io.h>
24#include <linux/regulator/consumer.h> 25#include <linux/regulator/consumer.h>
25#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
26 27#include <linux/platform_data/i2c-nomadik.h>
27#include <plat/i2c.h>
28 28
29#define DRIVER_NAME "nmk-i2c" 29#define DRIVER_NAME "nmk-i2c"
30 30
@@ -136,7 +136,7 @@ struct i2c_nmk_client {
136 136
137/** 137/**
138 * struct nmk_i2c_dev - private data structure of the controller. 138 * struct nmk_i2c_dev - private data structure of the controller.
139 * @pdev: parent platform device. 139 * @adev: parent amba device.
140 * @adap: corresponding I2C adapter. 140 * @adap: corresponding I2C adapter.
141 * @irq: interrupt line for the controller. 141 * @irq: interrupt line for the controller.
142 * @virtbase: virtual io memory area. 142 * @virtbase: virtual io memory area.
@@ -150,7 +150,7 @@ struct i2c_nmk_client {
150 * @busy: Busy doing transfer. 150 * @busy: Busy doing transfer.
151 */ 151 */
152struct nmk_i2c_dev { 152struct nmk_i2c_dev {
153 struct platform_device *pdev; 153 struct amba_device *adev;
154 struct i2c_adapter adap; 154 struct i2c_adapter adap;
155 int irq; 155 int irq;
156 void __iomem *virtbase; 156 void __iomem *virtbase;
@@ -217,7 +217,7 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev)
217 } 217 }
218 } 218 }
219 219
220 dev_err(&dev->pdev->dev, 220 dev_err(&dev->adev->dev,
221 "flushing operation timed out giving up after %d attempts", 221 "flushing operation timed out giving up after %d attempts",
222 LOOP_ATTEMPTS); 222 LOOP_ATTEMPTS);
223 223
@@ -276,15 +276,32 @@ exit:
276/** 276/**
277 * load_i2c_mcr_reg() - load the MCR register 277 * load_i2c_mcr_reg() - load the MCR register
278 * @dev: private data of controller 278 * @dev: private data of controller
279 * @flags: message flags
279 */ 280 */
280static u32 load_i2c_mcr_reg(struct nmk_i2c_dev *dev) 281static u32 load_i2c_mcr_reg(struct nmk_i2c_dev *dev, u16 flags)
281{ 282{
282 u32 mcr = 0; 283 u32 mcr = 0;
284 unsigned short slave_adr_3msb_bits;
283 285
284 /* 7-bit address transaction */
285 mcr |= GEN_MASK(1, I2C_MCR_AM, 12);
286 mcr |= GEN_MASK(dev->cli.slave_adr, I2C_MCR_A7, 1); 286 mcr |= GEN_MASK(dev->cli.slave_adr, I2C_MCR_A7, 1);
287 287
288 if (unlikely(flags & I2C_M_TEN)) {
289 /* 10-bit address transaction */
290 mcr |= GEN_MASK(2, I2C_MCR_AM, 12);
291 /*
292 * Get the top 3 bits.
293 * EA10 represents extended address in MCR. This includes
294 * the extension (MSB bits) of the 7 bit address loaded
295 * in A7
296 */
297 slave_adr_3msb_bits = (dev->cli.slave_adr >> 7) & 0x7;
298
299 mcr |= GEN_MASK(slave_adr_3msb_bits, I2C_MCR_EA10, 8);
300 } else {
301 /* 7-bit address transaction */
302 mcr |= GEN_MASK(1, I2C_MCR_AM, 12);
303 }
304
288 /* start byte procedure not applied */ 305 /* start byte procedure not applied */
289 mcr |= GEN_MASK(0, I2C_MCR_SB, 11); 306 mcr |= GEN_MASK(0, I2C_MCR_SB, 11);
290 307
@@ -364,7 +381,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
364 * and high speed (up to 3.4 Mb/s) 381 * and high speed (up to 3.4 Mb/s)
365 */ 382 */
366 if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { 383 if (dev->cfg.sm > I2C_FREQ_MODE_FAST) {
367 dev_err(&dev->pdev->dev, 384 dev_err(&dev->adev->dev,
368 "do not support this mode defaulting to std. mode\n"); 385 "do not support this mode defaulting to std. mode\n");
369 brcr2 = i2c_clk/(100000 * 2) & 0xffff; 386 brcr2 = i2c_clk/(100000 * 2) & 0xffff;
370 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); 387 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR);
@@ -381,19 +398,20 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
381/** 398/**
382 * read_i2c() - Read from I2C client device 399 * read_i2c() - Read from I2C client device
383 * @dev: private data of I2C Driver 400 * @dev: private data of I2C Driver
401 * @flags: message flags
384 * 402 *
385 * This function reads from i2c client device when controller is in 403 * This function reads from i2c client device when controller is in
386 * master mode. There is a completion timeout. If there is no transfer 404 * master mode. There is a completion timeout. If there is no transfer
387 * before timeout error is returned. 405 * before timeout error is returned.
388 */ 406 */
389static int read_i2c(struct nmk_i2c_dev *dev) 407static int read_i2c(struct nmk_i2c_dev *dev, u16 flags)
390{ 408{
391 u32 status = 0; 409 u32 status = 0;
392 u32 mcr; 410 u32 mcr;
393 u32 irq_mask = 0; 411 u32 irq_mask = 0;
394 int timeout; 412 int timeout;
395 413
396 mcr = load_i2c_mcr_reg(dev); 414 mcr = load_i2c_mcr_reg(dev, flags);
397 writel(mcr, dev->virtbase + I2C_MCR); 415 writel(mcr, dev->virtbase + I2C_MCR);
398 416
399 /* load the current CR value */ 417 /* load the current CR value */
@@ -423,7 +441,7 @@ static int read_i2c(struct nmk_i2c_dev *dev)
423 &dev->xfer_complete, dev->adap.timeout); 441 &dev->xfer_complete, dev->adap.timeout);
424 442
425 if (timeout < 0) { 443 if (timeout < 0) {
426 dev_err(&dev->pdev->dev, 444 dev_err(&dev->adev->dev,
427 "wait_for_completion_timeout " 445 "wait_for_completion_timeout "
428 "returned %d waiting for event\n", timeout); 446 "returned %d waiting for event\n", timeout);
429 status = timeout; 447 status = timeout;
@@ -431,7 +449,7 @@ static int read_i2c(struct nmk_i2c_dev *dev)
431 449
432 if (timeout == 0) { 450 if (timeout == 0) {
433 /* Controller timed out */ 451 /* Controller timed out */
434 dev_err(&dev->pdev->dev, "read from slave 0x%x timed out\n", 452 dev_err(&dev->adev->dev, "read from slave 0x%x timed out\n",
435 dev->cli.slave_adr); 453 dev->cli.slave_adr);
436 status = -ETIMEDOUT; 454 status = -ETIMEDOUT;
437 } 455 }
@@ -459,17 +477,18 @@ static void fill_tx_fifo(struct nmk_i2c_dev *dev, int no_bytes)
459/** 477/**
460 * write_i2c() - Write data to I2C client. 478 * write_i2c() - Write data to I2C client.
461 * @dev: private data of I2C Driver 479 * @dev: private data of I2C Driver
480 * @flags: message flags
462 * 481 *
463 * This function writes data to I2C client 482 * This function writes data to I2C client
464 */ 483 */
465static int write_i2c(struct nmk_i2c_dev *dev) 484static int write_i2c(struct nmk_i2c_dev *dev, u16 flags)
466{ 485{
467 u32 status = 0; 486 u32 status = 0;
468 u32 mcr; 487 u32 mcr;
469 u32 irq_mask = 0; 488 u32 irq_mask = 0;
470 int timeout; 489 int timeout;
471 490
472 mcr = load_i2c_mcr_reg(dev); 491 mcr = load_i2c_mcr_reg(dev, flags);
473 492
474 writel(mcr, dev->virtbase + I2C_MCR); 493 writel(mcr, dev->virtbase + I2C_MCR);
475 494
@@ -510,7 +529,7 @@ static int write_i2c(struct nmk_i2c_dev *dev)
510 &dev->xfer_complete, dev->adap.timeout); 529 &dev->xfer_complete, dev->adap.timeout);
511 530
512 if (timeout < 0) { 531 if (timeout < 0) {
513 dev_err(&dev->pdev->dev, 532 dev_err(&dev->adev->dev,
514 "wait_for_completion_timeout " 533 "wait_for_completion_timeout "
515 "returned %d waiting for event\n", timeout); 534 "returned %d waiting for event\n", timeout);
516 status = timeout; 535 status = timeout;
@@ -518,7 +537,7 @@ static int write_i2c(struct nmk_i2c_dev *dev)
518 537
519 if (timeout == 0) { 538 if (timeout == 0) {
520 /* Controller timed out */ 539 /* Controller timed out */
521 dev_err(&dev->pdev->dev, "write to slave 0x%x timed out\n", 540 dev_err(&dev->adev->dev, "write to slave 0x%x timed out\n",
522 dev->cli.slave_adr); 541 dev->cli.slave_adr);
523 status = -ETIMEDOUT; 542 status = -ETIMEDOUT;
524 } 543 }
@@ -538,11 +557,11 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
538 if (flags & I2C_M_RD) { 557 if (flags & I2C_M_RD) {
539 /* read operation */ 558 /* read operation */
540 dev->cli.operation = I2C_READ; 559 dev->cli.operation = I2C_READ;
541 status = read_i2c(dev); 560 status = read_i2c(dev, flags);
542 } else { 561 } else {
543 /* write operation */ 562 /* write operation */
544 dev->cli.operation = I2C_WRITE; 563 dev->cli.operation = I2C_WRITE;
545 status = write_i2c(dev); 564 status = write_i2c(dev, flags);
546 } 565 }
547 566
548 if (status || (dev->result)) { 567 if (status || (dev->result)) {
@@ -557,7 +576,7 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
557 if (((i2c_sr >> 2) & 0x3) == 0x3) { 576 if (((i2c_sr >> 2) & 0x3) == 0x3) {
558 /* get the abort cause */ 577 /* get the abort cause */
559 cause = (i2c_sr >> 4) & 0x7; 578 cause = (i2c_sr >> 4) & 0x7;
560 dev_err(&dev->pdev->dev, "%s\n", 579 dev_err(&dev->adev->dev, "%s\n",
561 cause >= ARRAY_SIZE(abort_causes) ? 580 cause >= ARRAY_SIZE(abort_causes) ?
562 "unknown reason" : 581 "unknown reason" :
563 abort_causes[cause]); 582 abort_causes[cause]);
@@ -630,7 +649,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
630 649
631 if (dev->regulator) 650 if (dev->regulator)
632 regulator_enable(dev->regulator); 651 regulator_enable(dev->regulator);
633 pm_runtime_get_sync(&dev->pdev->dev); 652 pm_runtime_get_sync(&dev->adev->dev);
634 653
635 clk_enable(dev->clk); 654 clk_enable(dev->clk);
636 655
@@ -644,13 +663,6 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
644 setup_i2c_controller(dev); 663 setup_i2c_controller(dev);
645 664
646 for (i = 0; i < num_msgs; i++) { 665 for (i = 0; i < num_msgs; i++) {
647 if (unlikely(msgs[i].flags & I2C_M_TEN)) {
648 dev_err(&dev->pdev->dev,
649 "10 bit addressing not supported\n");
650
651 status = -EINVAL;
652 goto out;
653 }
654 dev->cli.slave_adr = msgs[i].addr; 666 dev->cli.slave_adr = msgs[i].addr;
655 dev->cli.buffer = msgs[i].buf; 667 dev->cli.buffer = msgs[i].buf;
656 dev->cli.count = msgs[i].len; 668 dev->cli.count = msgs[i].len;
@@ -667,7 +679,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
667 679
668out: 680out:
669 clk_disable(dev->clk); 681 clk_disable(dev->clk);
670 pm_runtime_put_sync(&dev->pdev->dev); 682 pm_runtime_put_sync(&dev->adev->dev);
671 if (dev->regulator) 683 if (dev->regulator)
672 regulator_disable(dev->regulator); 684 regulator_disable(dev->regulator);
673 685
@@ -790,7 +802,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
790 802
791 if (dev->cli.count) { 803 if (dev->cli.count) {
792 dev->result = -EIO; 804 dev->result = -EIO;
793 dev_err(&dev->pdev->dev, 805 dev_err(&dev->adev->dev,
794 "%lu bytes still remain to be xfered\n", 806 "%lu bytes still remain to be xfered\n",
795 dev->cli.count); 807 dev->cli.count);
796 (void) init_hw(dev); 808 (void) init_hw(dev);
@@ -834,7 +846,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
834 dev->result = -EIO; 846 dev->result = -EIO;
835 (void) init_hw(dev); 847 (void) init_hw(dev);
836 848
837 dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); 849 dev_err(&dev->adev->dev, "Tx Fifo Over run\n");
838 complete(&dev->xfer_complete); 850 complete(&dev->xfer_complete);
839 851
840 break; 852 break;
@@ -847,10 +859,10 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
847 case I2C_IT_RFSE: 859 case I2C_IT_RFSE:
848 case I2C_IT_WTSR: 860 case I2C_IT_WTSR:
849 case I2C_IT_STD: 861 case I2C_IT_STD:
850 dev_err(&dev->pdev->dev, "unhandled Interrupt\n"); 862 dev_err(&dev->adev->dev, "unhandled Interrupt\n");
851 break; 863 break;
852 default: 864 default:
853 dev_err(&dev->pdev->dev, "spurious Interrupt..\n"); 865 dev_err(&dev->adev->dev, "spurious Interrupt..\n");
854 break; 866 break;
855 } 867 }
856 868
@@ -861,8 +873,8 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
861#ifdef CONFIG_PM 873#ifdef CONFIG_PM
862static int nmk_i2c_suspend(struct device *dev) 874static int nmk_i2c_suspend(struct device *dev)
863{ 875{
864 struct platform_device *pdev = to_platform_device(dev); 876 struct amba_device *adev = to_amba_device(dev);
865 struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev); 877 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
866 878
867 if (nmk_i2c->busy) 879 if (nmk_i2c->busy)
868 return -EBUSY; 880 return -EBUSY;
@@ -891,7 +903,7 @@ static const struct dev_pm_ops nmk_i2c_pm = {
891 903
892static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) 904static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
893{ 905{
894 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 906 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
895} 907}
896 908
897static const struct i2c_algorithm nmk_i2c_algo = { 909static const struct i2c_algorithm nmk_i2c_algo = {
@@ -899,78 +911,69 @@ static const struct i2c_algorithm nmk_i2c_algo = {
899 .functionality = nmk_i2c_functionality 911 .functionality = nmk_i2c_functionality
900}; 912};
901 913
902static int __devinit nmk_i2c_probe(struct platform_device *pdev) 914static atomic_t adapter_id = ATOMIC_INIT(0);
915
916static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
903{ 917{
904 int ret = 0; 918 int ret = 0;
905 struct resource *res;
906 struct nmk_i2c_controller *pdata = 919 struct nmk_i2c_controller *pdata =
907 pdev->dev.platform_data; 920 adev->dev.platform_data;
908 struct nmk_i2c_dev *dev; 921 struct nmk_i2c_dev *dev;
909 struct i2c_adapter *adap; 922 struct i2c_adapter *adap;
910 923
924 if (!pdata) {
925 dev_warn(&adev->dev, "no platform data\n");
926 return -ENODEV;
927 }
911 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); 928 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL);
912 if (!dev) { 929 if (!dev) {
913 dev_err(&pdev->dev, "cannot allocate memory\n"); 930 dev_err(&adev->dev, "cannot allocate memory\n");
914 ret = -ENOMEM; 931 ret = -ENOMEM;
915 goto err_no_mem; 932 goto err_no_mem;
916 } 933 }
917 dev->busy = false; 934 dev->busy = false;
918 dev->pdev = pdev; 935 dev->adev = adev;
919 platform_set_drvdata(pdev, dev); 936 amba_set_drvdata(adev, dev);
920 937
921 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 938 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
922 if (!res) {
923 ret = -ENOENT;
924 goto err_no_resource;
925 }
926
927 if (request_mem_region(res->start, resource_size(res),
928 DRIVER_NAME "I/O region") == NULL) {
929 ret = -EBUSY;
930 goto err_no_region;
931 }
932
933 dev->virtbase = ioremap(res->start, resource_size(res));
934 if (!dev->virtbase) { 939 if (!dev->virtbase) {
935 ret = -ENOMEM; 940 ret = -ENOMEM;
936 goto err_no_ioremap; 941 goto err_no_ioremap;
937 } 942 }
938 943
939 dev->irq = platform_get_irq(pdev, 0); 944 dev->irq = adev->irq[0];
940 ret = request_irq(dev->irq, i2c_irq_handler, 0, 945 ret = request_irq(dev->irq, i2c_irq_handler, 0,
941 DRIVER_NAME, dev); 946 DRIVER_NAME, dev);
942 if (ret) { 947 if (ret) {
943 dev_err(&pdev->dev, "cannot claim the irq %d\n", dev->irq); 948 dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq);
944 goto err_irq; 949 goto err_irq;
945 } 950 }
946 951
947 dev->regulator = regulator_get(&pdev->dev, "v-i2c"); 952 dev->regulator = regulator_get(&adev->dev, "v-i2c");
948 if (IS_ERR(dev->regulator)) { 953 if (IS_ERR(dev->regulator)) {
949 dev_warn(&pdev->dev, "could not get i2c regulator\n"); 954 dev_warn(&adev->dev, "could not get i2c regulator\n");
950 dev->regulator = NULL; 955 dev->regulator = NULL;
951 } 956 }
952 957
953 pm_suspend_ignore_children(&pdev->dev, true); 958 pm_suspend_ignore_children(&adev->dev, true);
954 pm_runtime_enable(&pdev->dev);
955 959
956 dev->clk = clk_get(&pdev->dev, NULL); 960 dev->clk = clk_get(&adev->dev, NULL);
957 if (IS_ERR(dev->clk)) { 961 if (IS_ERR(dev->clk)) {
958 dev_err(&pdev->dev, "could not get i2c clock\n"); 962 dev_err(&adev->dev, "could not get i2c clock\n");
959 ret = PTR_ERR(dev->clk); 963 ret = PTR_ERR(dev->clk);
960 goto err_no_clk; 964 goto err_no_clk;
961 } 965 }
962 966
963 adap = &dev->adap; 967 adap = &dev->adap;
964 adap->dev.parent = &pdev->dev; 968 adap->dev.parent = &adev->dev;
965 adap->owner = THIS_MODULE; 969 adap->owner = THIS_MODULE;
966 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 970 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
967 adap->algo = &nmk_i2c_algo; 971 adap->algo = &nmk_i2c_algo;
968 adap->timeout = msecs_to_jiffies(pdata->timeout); 972 adap->timeout = msecs_to_jiffies(pdata->timeout);
973 adap->nr = atomic_read(&adapter_id);
969 snprintf(adap->name, sizeof(adap->name), 974 snprintf(adap->name, sizeof(adap->name),
970 "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); 975 "Nomadik I2C%d at %pR", adap->nr, &adev->res);
971 976 atomic_inc(&adapter_id);
972 /* fetch the controller id */
973 adap->nr = pdev->id;
974 977
975 /* fetch the controller configuration from machine */ 978 /* fetch the controller configuration from machine */
976 dev->cfg.clk_freq = pdata->clk_freq; 979 dev->cfg.clk_freq = pdata->clk_freq;
@@ -981,16 +984,18 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
981 984
982 i2c_set_adapdata(adap, dev); 985 i2c_set_adapdata(adap, dev);
983 986
984 dev_info(&pdev->dev, 987 dev_info(&adev->dev,
985 "initialize %s on virtual base %p\n", 988 "initialize %s on virtual base %p\n",
986 adap->name, dev->virtbase); 989 adap->name, dev->virtbase);
987 990
988 ret = i2c_add_numbered_adapter(adap); 991 ret = i2c_add_numbered_adapter(adap);
989 if (ret) { 992 if (ret) {
990 dev_err(&pdev->dev, "failed to add adapter\n"); 993 dev_err(&adev->dev, "failed to add adapter\n");
991 goto err_add_adap; 994 goto err_add_adap;
992 } 995 }
993 996
997 pm_runtime_put(&adev->dev);
998
994 return 0; 999 return 0;
995 1000
996 err_add_adap: 1001 err_add_adap:
@@ -998,25 +1003,21 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
998 err_no_clk: 1003 err_no_clk:
999 if (dev->regulator) 1004 if (dev->regulator)
1000 regulator_put(dev->regulator); 1005 regulator_put(dev->regulator);
1001 pm_runtime_disable(&pdev->dev);
1002 free_irq(dev->irq, dev); 1006 free_irq(dev->irq, dev);
1003 err_irq: 1007 err_irq:
1004 iounmap(dev->virtbase); 1008 iounmap(dev->virtbase);
1005 err_no_ioremap: 1009 err_no_ioremap:
1006 release_mem_region(res->start, resource_size(res)); 1010 amba_set_drvdata(adev, NULL);
1007 err_no_region:
1008 platform_set_drvdata(pdev, NULL);
1009 err_no_resource:
1010 kfree(dev); 1011 kfree(dev);
1011 err_no_mem: 1012 err_no_mem:
1012 1013
1013 return ret; 1014 return ret;
1014} 1015}
1015 1016
1016static int __devexit nmk_i2c_remove(struct platform_device *pdev) 1017static int nmk_i2c_remove(struct amba_device *adev)
1017{ 1018{
1018 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1019 struct resource *res = &adev->res;
1019 struct nmk_i2c_dev *dev = platform_get_drvdata(pdev); 1020 struct nmk_i2c_dev *dev = amba_get_drvdata(adev);
1020 1021
1021 i2c_del_adapter(&dev->adap); 1022 i2c_del_adapter(&dev->adap);
1022 flush_i2c_fifo(dev); 1023 flush_i2c_fifo(dev);
@@ -1031,31 +1032,46 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev)
1031 clk_put(dev->clk); 1032 clk_put(dev->clk);
1032 if (dev->regulator) 1033 if (dev->regulator)
1033 regulator_put(dev->regulator); 1034 regulator_put(dev->regulator);
1034 pm_runtime_disable(&pdev->dev); 1035 pm_runtime_disable(&adev->dev);
1035 platform_set_drvdata(pdev, NULL); 1036 amba_set_drvdata(adev, NULL);
1036 kfree(dev); 1037 kfree(dev);
1037 1038
1038 return 0; 1039 return 0;
1039} 1040}
1040 1041
1041static struct platform_driver nmk_i2c_driver = { 1042static struct amba_id nmk_i2c_ids[] = {
1042 .driver = { 1043 {
1044 .id = 0x00180024,
1045 .mask = 0x00ffffff,
1046 },
1047 {
1048 .id = 0x00380024,
1049 .mask = 0x00ffffff,
1050 },
1051 {},
1052};
1053
1054MODULE_DEVICE_TABLE(amba, nmk_i2c_ids);
1055
1056static struct amba_driver nmk_i2c_driver = {
1057 .drv = {
1043 .owner = THIS_MODULE, 1058 .owner = THIS_MODULE,
1044 .name = DRIVER_NAME, 1059 .name = DRIVER_NAME,
1045 .pm = &nmk_i2c_pm, 1060 .pm = &nmk_i2c_pm,
1046 }, 1061 },
1062 .id_table = nmk_i2c_ids,
1047 .probe = nmk_i2c_probe, 1063 .probe = nmk_i2c_probe,
1048 .remove = __devexit_p(nmk_i2c_remove), 1064 .remove = nmk_i2c_remove,
1049}; 1065};
1050 1066
1051static int __init nmk_i2c_init(void) 1067static int __init nmk_i2c_init(void)
1052{ 1068{
1053 return platform_driver_register(&nmk_i2c_driver); 1069 return amba_driver_register(&nmk_i2c_driver);
1054} 1070}
1055 1071
1056static void __exit nmk_i2c_exit(void) 1072static void __exit nmk_i2c_exit(void)
1057{ 1073{
1058 platform_driver_unregister(&nmk_i2c_driver); 1074 amba_driver_unregister(&nmk_i2c_driver);
1059} 1075}
1060 1076
1061subsys_initcall(nmk_i2c_init); 1077subsys_initcall(nmk_i2c_init);
@@ -1064,4 +1080,3 @@ module_exit(nmk_i2c_exit);
1064MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR"); 1080MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR");
1065MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver"); 1081MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver");
1066MODULE_LICENSE("GPL"); 1082MODULE_LICENSE("GPL");
1067MODULE_ALIAS("platform:" DRIVER_NAME);