diff options
| author | Alessandro Rubini <rubini@gnudd.com> | 2012-06-11 16:56:38 -0400 |
|---|---|---|
| committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-07-09 05:40:46 -0400 |
| commit | 235602146ec9c1882edf1ccc68389c1176be8198 (patch) | |
| tree | 7b3afcf452f9b8aa65d8091ac700f3dad7f524e7 | |
| parent | af97bace2cca58ee7c94bf4d31e820f29688d7a5 (diff) | |
i2c-nomadik: turn the platform driver to an amba driver
The i2c-nomadik gateware is really a PrimeCell APB device. By hosting
the driver under the amba bus we can access it more easily, for
example using the generic pci-amba driver. The patch also fixes the
mach-ux500 users, so they register an amba device instead than a
platform device.
Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Acked-by: Giancarlo Asnaghi <giancarlo.asnaghi@st.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
| -rw-r--r-- | arch/arm/mach-ux500/devices-common.h | 22 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-nomadik.c | 142 |
2 files changed, 78 insertions, 86 deletions
diff --git a/arch/arm/mach-ux500/devices-common.h b/arch/arm/mach-ux500/devices-common.h index 23cf734b5384..ecdd8386cffb 100644 --- a/arch/arm/mach-ux500/devices-common.h +++ b/arch/arm/mach-ux500/devices-common.h | |||
| @@ -56,27 +56,15 @@ dbx500_add_uart(struct device *parent, const char *name, resource_size_t base, | |||
| 56 | 56 | ||
| 57 | struct nmk_i2c_controller; | 57 | struct nmk_i2c_controller; |
| 58 | 58 | ||
| 59 | static inline struct platform_device * | 59 | static inline struct amba_device * |
| 60 | dbx500_add_i2c(struct device *parent, int id, resource_size_t base, int irq, | 60 | dbx500_add_i2c(struct device *parent, int id, resource_size_t base, int irq, |
| 61 | struct nmk_i2c_controller *data) | 61 | struct nmk_i2c_controller *data) |
| 62 | { | 62 | { |
| 63 | struct resource res[] = { | 63 | /* Conjure a name similar to what the platform device used to have */ |
| 64 | DEFINE_RES_MEM(base, SZ_4K), | 64 | char name[16]; |
| 65 | DEFINE_RES_IRQ(irq), | ||
| 66 | }; | ||
| 67 | 65 | ||
| 68 | struct platform_device_info pdevinfo = { | 66 | snprintf(name, sizeof(name), "nmk-i2c.%d", id); |
| 69 | .parent = parent, | 67 | return amba_apb_device_add(parent, name, base, SZ_4K, irq, 0, data, 0); |
| 70 | .name = "nmk-i2c", | ||
| 71 | .id = id, | ||
| 72 | .res = res, | ||
| 73 | .num_res = ARRAY_SIZE(res), | ||
| 74 | .data = data, | ||
| 75 | .size_data = sizeof(*data), | ||
| 76 | .dma_mask = DMA_BIT_MASK(32), | ||
| 77 | }; | ||
| 78 | |||
| 79 | return platform_device_register_full(&pdevinfo); | ||
| 80 | } | 68 | } |
| 81 | 69 | ||
| 82 | static inline struct amba_device * | 70 | static inline struct amba_device * |
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 752f1fda371f..6db453fe68e6 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> |
| @@ -135,7 +136,7 @@ struct i2c_nmk_client { | |||
| 135 | 136 | ||
| 136 | /** | 137 | /** |
| 137 | * struct nmk_i2c_dev - private data structure of the controller. | 138 | * struct nmk_i2c_dev - private data structure of the controller. |
| 138 | * @pdev: parent platform device. | 139 | * @adev: parent amba device. |
| 139 | * @adap: corresponding I2C adapter. | 140 | * @adap: corresponding I2C adapter. |
| 140 | * @irq: interrupt line for the controller. | 141 | * @irq: interrupt line for the controller. |
| 141 | * @virtbase: virtual io memory area. | 142 | * @virtbase: virtual io memory area. |
| @@ -149,7 +150,7 @@ struct i2c_nmk_client { | |||
| 149 | * @busy: Busy doing transfer. | 150 | * @busy: Busy doing transfer. |
| 150 | */ | 151 | */ |
| 151 | struct nmk_i2c_dev { | 152 | struct nmk_i2c_dev { |
| 152 | struct platform_device *pdev; | 153 | struct amba_device *adev; |
| 153 | struct i2c_adapter adap; | 154 | struct i2c_adapter adap; |
| 154 | int irq; | 155 | int irq; |
| 155 | void __iomem *virtbase; | 156 | void __iomem *virtbase; |
| @@ -216,7 +217,7 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev) | |||
| 216 | } | 217 | } |
| 217 | } | 218 | } |
| 218 | 219 | ||
| 219 | dev_err(&dev->pdev->dev, | 220 | dev_err(&dev->adev->dev, |
| 220 | "flushing operation timed out giving up after %d attempts", | 221 | "flushing operation timed out giving up after %d attempts", |
| 221 | LOOP_ATTEMPTS); | 222 | LOOP_ATTEMPTS); |
| 222 | 223 | ||
| @@ -363,7 +364,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev) | |||
| 363 | * and high speed (up to 3.4 Mb/s) | 364 | * and high speed (up to 3.4 Mb/s) |
| 364 | */ | 365 | */ |
| 365 | if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { | 366 | if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { |
| 366 | dev_err(&dev->pdev->dev, | 367 | dev_err(&dev->adev->dev, |
| 367 | "do not support this mode defaulting to std. mode\n"); | 368 | "do not support this mode defaulting to std. mode\n"); |
| 368 | brcr2 = i2c_clk/(100000 * 2) & 0xffff; | 369 | brcr2 = i2c_clk/(100000 * 2) & 0xffff; |
| 369 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); | 370 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); |
| @@ -422,7 +423,7 @@ static int read_i2c(struct nmk_i2c_dev *dev) | |||
| 422 | &dev->xfer_complete, dev->adap.timeout); | 423 | &dev->xfer_complete, dev->adap.timeout); |
| 423 | 424 | ||
| 424 | if (timeout < 0) { | 425 | if (timeout < 0) { |
| 425 | dev_err(&dev->pdev->dev, | 426 | dev_err(&dev->adev->dev, |
| 426 | "wait_for_completion_timeout " | 427 | "wait_for_completion_timeout " |
| 427 | "returned %d waiting for event\n", timeout); | 428 | "returned %d waiting for event\n", timeout); |
| 428 | status = timeout; | 429 | status = timeout; |
| @@ -430,7 +431,7 @@ static int read_i2c(struct nmk_i2c_dev *dev) | |||
| 430 | 431 | ||
| 431 | if (timeout == 0) { | 432 | if (timeout == 0) { |
| 432 | /* Controller timed out */ | 433 | /* Controller timed out */ |
| 433 | dev_err(&dev->pdev->dev, "read from slave 0x%x timed out\n", | 434 | dev_err(&dev->adev->dev, "read from slave 0x%x timed out\n", |
| 434 | dev->cli.slave_adr); | 435 | dev->cli.slave_adr); |
| 435 | status = -ETIMEDOUT; | 436 | status = -ETIMEDOUT; |
| 436 | } | 437 | } |
| @@ -509,7 +510,7 @@ static int write_i2c(struct nmk_i2c_dev *dev) | |||
| 509 | &dev->xfer_complete, dev->adap.timeout); | 510 | &dev->xfer_complete, dev->adap.timeout); |
| 510 | 511 | ||
| 511 | if (timeout < 0) { | 512 | if (timeout < 0) { |
| 512 | dev_err(&dev->pdev->dev, | 513 | dev_err(&dev->adev->dev, |
| 513 | "wait_for_completion_timeout " | 514 | "wait_for_completion_timeout " |
| 514 | "returned %d waiting for event\n", timeout); | 515 | "returned %d waiting for event\n", timeout); |
| 515 | status = timeout; | 516 | status = timeout; |
| @@ -517,7 +518,7 @@ static int write_i2c(struct nmk_i2c_dev *dev) | |||
| 517 | 518 | ||
| 518 | if (timeout == 0) { | 519 | if (timeout == 0) { |
| 519 | /* Controller timed out */ | 520 | /* Controller timed out */ |
| 520 | dev_err(&dev->pdev->dev, "write to slave 0x%x timed out\n", | 521 | dev_err(&dev->adev->dev, "write to slave 0x%x timed out\n", |
| 521 | dev->cli.slave_adr); | 522 | dev->cli.slave_adr); |
| 522 | status = -ETIMEDOUT; | 523 | status = -ETIMEDOUT; |
| 523 | } | 524 | } |
| @@ -556,7 +557,7 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) | |||
| 556 | if (((i2c_sr >> 2) & 0x3) == 0x3) { | 557 | if (((i2c_sr >> 2) & 0x3) == 0x3) { |
| 557 | /* get the abort cause */ | 558 | /* get the abort cause */ |
| 558 | cause = (i2c_sr >> 4) & 0x7; | 559 | cause = (i2c_sr >> 4) & 0x7; |
| 559 | dev_err(&dev->pdev->dev, "%s\n", | 560 | dev_err(&dev->adev->dev, "%s\n", |
| 560 | cause >= ARRAY_SIZE(abort_causes) ? | 561 | cause >= ARRAY_SIZE(abort_causes) ? |
| 561 | "unknown reason" : | 562 | "unknown reason" : |
| 562 | abort_causes[cause]); | 563 | abort_causes[cause]); |
| @@ -629,7 +630,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
| 629 | 630 | ||
| 630 | if (dev->regulator) | 631 | if (dev->regulator) |
| 631 | regulator_enable(dev->regulator); | 632 | regulator_enable(dev->regulator); |
| 632 | pm_runtime_get_sync(&dev->pdev->dev); | 633 | pm_runtime_get_sync(&dev->adev->dev); |
| 633 | 634 | ||
| 634 | clk_enable(dev->clk); | 635 | clk_enable(dev->clk); |
| 635 | 636 | ||
| @@ -644,7 +645,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
| 644 | 645 | ||
| 645 | for (i = 0; i < num_msgs; i++) { | 646 | for (i = 0; i < num_msgs; i++) { |
| 646 | if (unlikely(msgs[i].flags & I2C_M_TEN)) { | 647 | if (unlikely(msgs[i].flags & I2C_M_TEN)) { |
| 647 | dev_err(&dev->pdev->dev, | 648 | dev_err(&dev->adev->dev, |
| 648 | "10 bit addressing not supported\n"); | 649 | "10 bit addressing not supported\n"); |
| 649 | 650 | ||
| 650 | status = -EINVAL; | 651 | status = -EINVAL; |
| @@ -666,7 +667,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, | |||
| 666 | 667 | ||
| 667 | out: | 668 | out: |
| 668 | clk_disable(dev->clk); | 669 | clk_disable(dev->clk); |
| 669 | pm_runtime_put_sync(&dev->pdev->dev); | 670 | pm_runtime_put_sync(&dev->adev->dev); |
| 670 | if (dev->regulator) | 671 | if (dev->regulator) |
| 671 | regulator_disable(dev->regulator); | 672 | regulator_disable(dev->regulator); |
| 672 | 673 | ||
| @@ -789,7 +790,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 789 | 790 | ||
| 790 | if (dev->cli.count) { | 791 | if (dev->cli.count) { |
| 791 | dev->result = -EIO; | 792 | dev->result = -EIO; |
| 792 | dev_err(&dev->pdev->dev, | 793 | dev_err(&dev->adev->dev, |
| 793 | "%lu bytes still remain to be xfered\n", | 794 | "%lu bytes still remain to be xfered\n", |
| 794 | dev->cli.count); | 795 | dev->cli.count); |
| 795 | (void) init_hw(dev); | 796 | (void) init_hw(dev); |
| @@ -833,7 +834,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 833 | dev->result = -EIO; | 834 | dev->result = -EIO; |
| 834 | (void) init_hw(dev); | 835 | (void) init_hw(dev); |
| 835 | 836 | ||
| 836 | dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); | 837 | dev_err(&dev->adev->dev, "Tx Fifo Over run\n"); |
| 837 | complete(&dev->xfer_complete); | 838 | complete(&dev->xfer_complete); |
| 838 | 839 | ||
| 839 | break; | 840 | break; |
| @@ -846,10 +847,10 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 846 | case I2C_IT_RFSE: | 847 | case I2C_IT_RFSE: |
| 847 | case I2C_IT_WTSR: | 848 | case I2C_IT_WTSR: |
| 848 | case I2C_IT_STD: | 849 | case I2C_IT_STD: |
| 849 | dev_err(&dev->pdev->dev, "unhandled Interrupt\n"); | 850 | dev_err(&dev->adev->dev, "unhandled Interrupt\n"); |
| 850 | break; | 851 | break; |
| 851 | default: | 852 | default: |
| 852 | dev_err(&dev->pdev->dev, "spurious Interrupt..\n"); | 853 | dev_err(&dev->adev->dev, "spurious Interrupt..\n"); |
| 853 | break; | 854 | break; |
| 854 | } | 855 | } |
| 855 | 856 | ||
| @@ -860,8 +861,8 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) | |||
| 860 | #ifdef CONFIG_PM | 861 | #ifdef CONFIG_PM |
| 861 | static int nmk_i2c_suspend(struct device *dev) | 862 | static int nmk_i2c_suspend(struct device *dev) |
| 862 | { | 863 | { |
| 863 | struct platform_device *pdev = to_platform_device(dev); | 864 | struct amba_device *adev = to_amba_device(dev); |
| 864 | struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev); | 865 | struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); |
| 865 | 866 | ||
| 866 | if (nmk_i2c->busy) | 867 | if (nmk_i2c->busy) |
| 867 | return -EBUSY; | 868 | return -EBUSY; |
| @@ -898,79 +899,70 @@ static const struct i2c_algorithm nmk_i2c_algo = { | |||
| 898 | .functionality = nmk_i2c_functionality | 899 | .functionality = nmk_i2c_functionality |
| 899 | }; | 900 | }; |
| 900 | 901 | ||
| 901 | static int __devinit nmk_i2c_probe(struct platform_device *pdev) | 902 | static atomic_t adapter_id = ATOMIC_INIT(0); |
| 903 | |||
| 904 | static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) | ||
| 902 | { | 905 | { |
| 903 | int ret = 0; | 906 | int ret = 0; |
| 904 | struct resource *res; | ||
| 905 | struct nmk_i2c_controller *pdata = | 907 | struct nmk_i2c_controller *pdata = |
| 906 | pdev->dev.platform_data; | 908 | adev->dev.platform_data; |
| 907 | struct nmk_i2c_dev *dev; | 909 | struct nmk_i2c_dev *dev; |
| 908 | struct i2c_adapter *adap; | 910 | struct i2c_adapter *adap; |
| 909 | 911 | ||
| 912 | if (!pdata) { | ||
| 913 | dev_warn(&adev->dev, "no platform data\n"); | ||
| 914 | return -ENODEV; | ||
| 915 | } | ||
| 910 | dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); | 916 | dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); |
| 911 | if (!dev) { | 917 | if (!dev) { |
| 912 | dev_err(&pdev->dev, "cannot allocate memory\n"); | 918 | dev_err(&adev->dev, "cannot allocate memory\n"); |
| 913 | ret = -ENOMEM; | 919 | ret = -ENOMEM; |
| 914 | goto err_no_mem; | 920 | goto err_no_mem; |
| 915 | } | 921 | } |
| 916 | dev->busy = false; | 922 | dev->busy = false; |
| 917 | dev->pdev = pdev; | 923 | dev->adev = adev; |
| 918 | platform_set_drvdata(pdev, dev); | 924 | amba_set_drvdata(adev, dev); |
| 919 | |||
| 920 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 921 | if (!res) { | ||
| 922 | ret = -ENOENT; | ||
| 923 | goto err_no_resource; | ||
| 924 | } | ||
| 925 | 925 | ||
| 926 | if (request_mem_region(res->start, resource_size(res), | 926 | dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); |
| 927 | DRIVER_NAME "I/O region") == NULL) { | ||
| 928 | ret = -EBUSY; | ||
| 929 | goto err_no_region; | ||
| 930 | } | ||
| 931 | |||
| 932 | dev->virtbase = ioremap(res->start, resource_size(res)); | ||
| 933 | if (!dev->virtbase) { | 927 | if (!dev->virtbase) { |
| 934 | ret = -ENOMEM; | 928 | ret = -ENOMEM; |
| 935 | goto err_no_ioremap; | 929 | goto err_no_ioremap; |
| 936 | } | 930 | } |
| 937 | 931 | ||
| 938 | dev->irq = platform_get_irq(pdev, 0); | 932 | dev->irq = adev->irq[0]; |
| 939 | ret = request_irq(dev->irq, i2c_irq_handler, 0, | 933 | ret = request_irq(dev->irq, i2c_irq_handler, 0, |
| 940 | DRIVER_NAME, dev); | 934 | DRIVER_NAME, dev); |
| 941 | if (ret) { | 935 | if (ret) { |
| 942 | dev_err(&pdev->dev, "cannot claim the irq %d\n", dev->irq); | 936 | dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq); |
| 943 | goto err_irq; | 937 | goto err_irq; |
| 944 | } | 938 | } |
| 945 | 939 | ||
| 946 | dev->regulator = regulator_get(&pdev->dev, "v-i2c"); | 940 | dev->regulator = regulator_get(&adev->dev, "v-i2c"); |
| 947 | if (IS_ERR(dev->regulator)) { | 941 | if (IS_ERR(dev->regulator)) { |
| 948 | dev_warn(&pdev->dev, "could not get i2c regulator\n"); | 942 | dev_warn(&adev->dev, "could not get i2c regulator\n"); |
| 949 | dev->regulator = NULL; | 943 | dev->regulator = NULL; |
| 950 | } | 944 | } |
| 951 | 945 | ||
| 952 | pm_suspend_ignore_children(&pdev->dev, true); | 946 | pm_suspend_ignore_children(&adev->dev, true); |
| 953 | pm_runtime_enable(&pdev->dev); | ||
| 954 | 947 | ||
| 955 | dev->clk = clk_get(&pdev->dev, NULL); | 948 | dev->clk = clk_get(&adev->dev, NULL); |
| 956 | if (IS_ERR(dev->clk)) { | 949 | if (IS_ERR(dev->clk)) { |
| 957 | dev_err(&pdev->dev, "could not get i2c clock\n"); | 950 | dev_err(&adev->dev, "could not get i2c clock\n"); |
| 958 | ret = PTR_ERR(dev->clk); | 951 | ret = PTR_ERR(dev->clk); |
| 959 | goto err_no_clk; | 952 | goto err_no_clk; |
| 960 | } | 953 | } |
| 961 | 954 | ||
| 962 | adap = &dev->adap; | 955 | adap = &dev->adap; |
| 963 | adap->dev.parent = &pdev->dev; | 956 | adap->dev.parent = &adev->dev; |
| 964 | adap->owner = THIS_MODULE; | 957 | adap->owner = THIS_MODULE; |
| 965 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 958 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
| 966 | adap->algo = &nmk_i2c_algo; | 959 | adap->algo = &nmk_i2c_algo; |
| 967 | adap->timeout = pdata->timeout ? msecs_to_jiffies(pdata->timeout) : | 960 | adap->timeout = pdata->timeout ? msecs_to_jiffies(pdata->timeout) : |
| 968 | msecs_to_jiffies(20000); | 961 | msecs_to_jiffies(20000); |
| 962 | adap->nr = atomic_read(&adapter_id); | ||
| 969 | snprintf(adap->name, sizeof(adap->name), | 963 | snprintf(adap->name, sizeof(adap->name), |
| 970 | "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); | 964 | "Nomadik I2C%d at %pR", adap->nr, &adev->res); |
| 971 | 965 | atomic_inc(&adapter_id); | |
| 972 | /* fetch the controller id */ | ||
| 973 | adap->nr = pdev->id; | ||
| 974 | 966 | ||
| 975 | /* fetch the controller configuration from machine */ | 967 | /* fetch the controller configuration from machine */ |
| 976 | dev->cfg.clk_freq = pdata->clk_freq; | 968 | dev->cfg.clk_freq = pdata->clk_freq; |
| @@ -981,16 +973,18 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 981 | 973 | ||
| 982 | i2c_set_adapdata(adap, dev); | 974 | i2c_set_adapdata(adap, dev); |
| 983 | 975 | ||
| 984 | dev_info(&pdev->dev, | 976 | dev_info(&adev->dev, |
| 985 | "initialize %s on virtual base %p\n", | 977 | "initialize %s on virtual base %p\n", |
| 986 | adap->name, dev->virtbase); | 978 | adap->name, dev->virtbase); |
| 987 | 979 | ||
| 988 | ret = i2c_add_numbered_adapter(adap); | 980 | ret = i2c_add_numbered_adapter(adap); |
| 989 | if (ret) { | 981 | if (ret) { |
| 990 | dev_err(&pdev->dev, "failed to add adapter\n"); | 982 | dev_err(&adev->dev, "failed to add adapter\n"); |
| 991 | goto err_add_adap; | 983 | goto err_add_adap; |
| 992 | } | 984 | } |
| 993 | 985 | ||
| 986 | pm_runtime_put(&adev->dev); | ||
| 987 | |||
| 994 | return 0; | 988 | return 0; |
| 995 | 989 | ||
| 996 | err_add_adap: | 990 | err_add_adap: |
| @@ -998,25 +992,21 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev) | |||
| 998 | err_no_clk: | 992 | err_no_clk: |
| 999 | if (dev->regulator) | 993 | if (dev->regulator) |
| 1000 | regulator_put(dev->regulator); | 994 | regulator_put(dev->regulator); |
| 1001 | pm_runtime_disable(&pdev->dev); | ||
| 1002 | free_irq(dev->irq, dev); | 995 | free_irq(dev->irq, dev); |
| 1003 | err_irq: | 996 | err_irq: |
| 1004 | iounmap(dev->virtbase); | 997 | iounmap(dev->virtbase); |
| 1005 | err_no_ioremap: | 998 | err_no_ioremap: |
| 1006 | release_mem_region(res->start, resource_size(res)); | 999 | amba_set_drvdata(adev, NULL); |
| 1007 | err_no_region: | ||
| 1008 | platform_set_drvdata(pdev, NULL); | ||
| 1009 | err_no_resource: | ||
| 1010 | kfree(dev); | 1000 | kfree(dev); |
| 1011 | err_no_mem: | 1001 | err_no_mem: |
| 1012 | 1002 | ||
| 1013 | return ret; | 1003 | return ret; |
| 1014 | } | 1004 | } |
| 1015 | 1005 | ||
| 1016 | static int __devexit nmk_i2c_remove(struct platform_device *pdev) | 1006 | static int nmk_i2c_remove(struct amba_device *adev) |
| 1017 | { | 1007 | { |
| 1018 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1008 | struct resource *res = &adev->res; |
| 1019 | struct nmk_i2c_dev *dev = platform_get_drvdata(pdev); | 1009 | struct nmk_i2c_dev *dev = amba_get_drvdata(adev); |
| 1020 | 1010 | ||
| 1021 | i2c_del_adapter(&dev->adap); | 1011 | i2c_del_adapter(&dev->adap); |
| 1022 | flush_i2c_fifo(dev); | 1012 | flush_i2c_fifo(dev); |
| @@ -1031,31 +1021,46 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev) | |||
| 1031 | clk_put(dev->clk); | 1021 | clk_put(dev->clk); |
| 1032 | if (dev->regulator) | 1022 | if (dev->regulator) |
| 1033 | regulator_put(dev->regulator); | 1023 | regulator_put(dev->regulator); |
| 1034 | pm_runtime_disable(&pdev->dev); | 1024 | pm_runtime_disable(&adev->dev); |
| 1035 | platform_set_drvdata(pdev, NULL); | 1025 | amba_set_drvdata(adev, NULL); |
| 1036 | kfree(dev); | 1026 | kfree(dev); |
| 1037 | 1027 | ||
| 1038 | return 0; | 1028 | return 0; |
| 1039 | } | 1029 | } |
| 1040 | 1030 | ||
| 1041 | static struct platform_driver nmk_i2c_driver = { | 1031 | static struct amba_id nmk_i2c_ids[] = { |
| 1042 | .driver = { | 1032 | { |
| 1033 | .id = 0x00180024, | ||
| 1034 | .mask = 0x00ffffff, | ||
| 1035 | }, | ||
| 1036 | { | ||
| 1037 | .id = 0x00380024, | ||
| 1038 | .mask = 0x00ffffff, | ||
| 1039 | }, | ||
| 1040 | {}, | ||
| 1041 | }; | ||
| 1042 | |||
| 1043 | MODULE_DEVICE_TABLE(amba, nmk_i2c_ids); | ||
| 1044 | |||
| 1045 | static struct amba_driver nmk_i2c_driver = { | ||
| 1046 | .drv = { | ||
| 1043 | .owner = THIS_MODULE, | 1047 | .owner = THIS_MODULE, |
| 1044 | .name = DRIVER_NAME, | 1048 | .name = DRIVER_NAME, |
| 1045 | .pm = &nmk_i2c_pm, | 1049 | .pm = &nmk_i2c_pm, |
| 1046 | }, | 1050 | }, |
| 1051 | .id_table = nmk_i2c_ids, | ||
| 1047 | .probe = nmk_i2c_probe, | 1052 | .probe = nmk_i2c_probe, |
| 1048 | .remove = __devexit_p(nmk_i2c_remove), | 1053 | .remove = nmk_i2c_remove, |
| 1049 | }; | 1054 | }; |
| 1050 | 1055 | ||
| 1051 | static int __init nmk_i2c_init(void) | 1056 | static int __init nmk_i2c_init(void) |
| 1052 | { | 1057 | { |
| 1053 | return platform_driver_register(&nmk_i2c_driver); | 1058 | return amba_driver_register(&nmk_i2c_driver); |
| 1054 | } | 1059 | } |
| 1055 | 1060 | ||
| 1056 | static void __exit nmk_i2c_exit(void) | 1061 | static void __exit nmk_i2c_exit(void) |
| 1057 | { | 1062 | { |
| 1058 | platform_driver_unregister(&nmk_i2c_driver); | 1063 | amba_driver_unregister(&nmk_i2c_driver); |
| 1059 | } | 1064 | } |
| 1060 | 1065 | ||
| 1061 | subsys_initcall(nmk_i2c_init); | 1066 | subsys_initcall(nmk_i2c_init); |
| @@ -1064,4 +1069,3 @@ module_exit(nmk_i2c_exit); | |||
| 1064 | MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR"); | 1069 | MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR"); |
| 1065 | MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver"); | 1070 | MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver"); |
| 1066 | MODULE_LICENSE("GPL"); | 1071 | MODULE_LICENSE("GPL"); |
| 1067 | MODULE_ALIAS("platform:" DRIVER_NAME); | ||
