diff options
author | Felipe Balbi <balbi@ti.com> | 2012-09-12 06:57:55 -0400 |
---|---|---|
committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-09-12 09:01:45 -0400 |
commit | d9ebd04d3476634c29ce0feffbc982e1cb25ed80 (patch) | |
tree | deb23d91d4c1b2dc89ae8227e209ecd8d9770d36 /drivers | |
parent | fbc1871511ed201504d6e5b36f13ea77e4be2907 (diff) |
i2c: omap: switch to devm_* API
that helps deleting some boiler plate code
and lets driver-core manage our resources
for us.
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 5d19a49803c1..2d9b03c94614 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -943,7 +943,7 @@ omap_i2c_probe(struct platform_device *pdev) | |||
943 | { | 943 | { |
944 | struct omap_i2c_dev *dev; | 944 | struct omap_i2c_dev *dev; |
945 | struct i2c_adapter *adap; | 945 | struct i2c_adapter *adap; |
946 | struct resource *mem, *irq, *ioarea; | 946 | struct resource *mem, *irq; |
947 | struct omap_i2c_bus_platform_data *pdata = pdev->dev.platform_data; | 947 | struct omap_i2c_bus_platform_data *pdata = pdev->dev.platform_data; |
948 | struct device_node *node = pdev->dev.of_node; | 948 | struct device_node *node = pdev->dev.of_node; |
949 | const struct of_device_id *match; | 949 | const struct of_device_id *match; |
@@ -962,17 +962,16 @@ omap_i2c_probe(struct platform_device *pdev) | |||
962 | return -ENODEV; | 962 | return -ENODEV; |
963 | } | 963 | } |
964 | 964 | ||
965 | ioarea = request_mem_region(mem->start, resource_size(mem), | 965 | dev = devm_kzalloc(&pdev->dev, sizeof(struct omap_i2c_dev), GFP_KERNEL); |
966 | pdev->name); | 966 | if (!dev) { |
967 | if (!ioarea) { | 967 | dev_err(&pdev->dev, "Menory allocation failed\n"); |
968 | dev_err(&pdev->dev, "I2C region already claimed\n"); | 968 | return -ENOMEM; |
969 | return -EBUSY; | ||
970 | } | 969 | } |
971 | 970 | ||
972 | dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL); | 971 | dev->base = devm_request_and_ioremap(&pdev->dev, mem); |
973 | if (!dev) { | 972 | if (!dev->base) { |
974 | r = -ENOMEM; | 973 | dev_err(&pdev->dev, "I2C region already claimed\n"); |
975 | goto err_release_region; | 974 | return -ENOMEM; |
976 | } | 975 | } |
977 | 976 | ||
978 | match = of_match_device(of_match_ptr(omap_i2c_of_match), &pdev->dev); | 977 | match = of_match_device(of_match_ptr(omap_i2c_of_match), &pdev->dev); |
@@ -995,11 +994,6 @@ omap_i2c_probe(struct platform_device *pdev) | |||
995 | 994 | ||
996 | dev->dev = &pdev->dev; | 995 | dev->dev = &pdev->dev; |
997 | dev->irq = irq->start; | 996 | dev->irq = irq->start; |
998 | dev->base = ioremap(mem->start, resource_size(mem)); | ||
999 | if (!dev->base) { | ||
1000 | r = -ENOMEM; | ||
1001 | goto err_free_mem; | ||
1002 | } | ||
1003 | 997 | ||
1004 | platform_set_drvdata(pdev, dev); | 998 | platform_set_drvdata(pdev, dev); |
1005 | init_completion(&dev->cmd_complete); | 999 | init_completion(&dev->cmd_complete); |
@@ -1057,7 +1051,8 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1057 | 1051 | ||
1058 | isr = (dev->rev < OMAP_I2C_OMAP1_REV_2) ? omap_i2c_omap1_isr : | 1052 | isr = (dev->rev < OMAP_I2C_OMAP1_REV_2) ? omap_i2c_omap1_isr : |
1059 | omap_i2c_isr; | 1053 | omap_i2c_isr; |
1060 | r = request_irq(dev->irq, isr, IRQF_NO_SUSPEND, pdev->name, dev); | 1054 | r = devm_request_irq(&pdev->dev, dev->irq, isr, IRQF_NO_SUSPEND, |
1055 | pdev->name, dev); | ||
1061 | 1056 | ||
1062 | if (r) { | 1057 | if (r) { |
1063 | dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); | 1058 | dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); |
@@ -1081,7 +1076,7 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1081 | r = i2c_add_numbered_adapter(adap); | 1076 | r = i2c_add_numbered_adapter(adap); |
1082 | if (r) { | 1077 | if (r) { |
1083 | dev_err(dev->dev, "failure adding adapter\n"); | 1078 | dev_err(dev->dev, "failure adding adapter\n"); |
1084 | goto err_free_irq; | 1079 | goto err_unuse_clocks; |
1085 | } | 1080 | } |
1086 | 1081 | ||
1087 | of_i2c_register_devices(adap); | 1082 | of_i2c_register_devices(adap); |
@@ -1090,18 +1085,12 @@ omap_i2c_probe(struct platform_device *pdev) | |||
1090 | 1085 | ||
1091 | return 0; | 1086 | return 0; |
1092 | 1087 | ||
1093 | err_free_irq: | ||
1094 | free_irq(dev->irq, dev); | ||
1095 | err_unuse_clocks: | 1088 | err_unuse_clocks: |
1096 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1089 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
1097 | pm_runtime_put(dev->dev); | 1090 | pm_runtime_put(dev->dev); |
1098 | iounmap(dev->base); | ||
1099 | pm_runtime_disable(&pdev->dev); | 1091 | pm_runtime_disable(&pdev->dev); |
1100 | err_free_mem: | 1092 | err_free_mem: |
1101 | platform_set_drvdata(pdev, NULL); | 1093 | platform_set_drvdata(pdev, NULL); |
1102 | kfree(dev); | ||
1103 | err_release_region: | ||
1104 | release_mem_region(mem->start, resource_size(mem)); | ||
1105 | 1094 | ||
1106 | return r; | 1095 | return r; |
1107 | } | 1096 | } |
@@ -1109,12 +1098,10 @@ err_release_region: | |||
1109 | static int __devexit omap_i2c_remove(struct platform_device *pdev) | 1098 | static int __devexit omap_i2c_remove(struct platform_device *pdev) |
1110 | { | 1099 | { |
1111 | struct omap_i2c_dev *dev = platform_get_drvdata(pdev); | 1100 | struct omap_i2c_dev *dev = platform_get_drvdata(pdev); |
1112 | struct resource *mem; | ||
1113 | int ret; | 1101 | int ret; |
1114 | 1102 | ||
1115 | platform_set_drvdata(pdev, NULL); | 1103 | platform_set_drvdata(pdev, NULL); |
1116 | 1104 | ||
1117 | free_irq(dev->irq, dev); | ||
1118 | i2c_del_adapter(&dev->adapter); | 1105 | i2c_del_adapter(&dev->adapter); |
1119 | ret = pm_runtime_get_sync(&pdev->dev); | 1106 | ret = pm_runtime_get_sync(&pdev->dev); |
1120 | if (IS_ERR_VALUE(ret)) | 1107 | if (IS_ERR_VALUE(ret)) |
@@ -1123,10 +1110,6 @@ static int __devexit omap_i2c_remove(struct platform_device *pdev) | |||
1123 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1110 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
1124 | pm_runtime_put(&pdev->dev); | 1111 | pm_runtime_put(&pdev->dev); |
1125 | pm_runtime_disable(&pdev->dev); | 1112 | pm_runtime_disable(&pdev->dev); |
1126 | iounmap(dev->base); | ||
1127 | kfree(dev); | ||
1128 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1129 | release_mem_region(mem->start, resource_size(mem)); | ||
1130 | return 0; | 1113 | return 0; |
1131 | } | 1114 | } |
1132 | 1115 | ||