diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/hwmon/jz4740-hwmon.c | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'drivers/hwmon/jz4740-hwmon.c')
-rw-r--r-- | drivers/hwmon/jz4740-hwmon.c | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c index e0d66b9590a..b65a4dae3f5 100644 --- a/drivers/hwmon/jz4740-hwmon.c +++ b/drivers/hwmon/jz4740-hwmon.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | #include <linux/io.h> | ||
24 | 23 | ||
25 | #include <linux/completion.h> | 24 | #include <linux/completion.h> |
26 | #include <linux/mfd/core.h> | 25 | #include <linux/mfd/core.h> |
@@ -102,42 +101,47 @@ static const struct attribute_group jz4740_hwmon_attr_group = { | |||
102 | .attrs = jz4740_hwmon_attributes, | 101 | .attrs = jz4740_hwmon_attributes, |
103 | }; | 102 | }; |
104 | 103 | ||
105 | static int jz4740_hwmon_probe(struct platform_device *pdev) | 104 | static int __devinit jz4740_hwmon_probe(struct platform_device *pdev) |
106 | { | 105 | { |
107 | int ret; | 106 | int ret; |
108 | struct jz4740_hwmon *hwmon; | 107 | struct jz4740_hwmon *hwmon; |
109 | 108 | ||
110 | hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); | 109 | hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL); |
111 | if (!hwmon) | 110 | if (!hwmon) { |
111 | dev_err(&pdev->dev, "Failed to allocate driver structure\n"); | ||
112 | return -ENOMEM; | 112 | return -ENOMEM; |
113 | } | ||
113 | 114 | ||
114 | hwmon->cell = mfd_get_cell(pdev); | 115 | hwmon->cell = mfd_get_cell(pdev); |
115 | 116 | ||
116 | hwmon->irq = platform_get_irq(pdev, 0); | 117 | hwmon->irq = platform_get_irq(pdev, 0); |
117 | if (hwmon->irq < 0) { | 118 | if (hwmon->irq < 0) { |
118 | dev_err(&pdev->dev, "Failed to get platform irq: %d\n", | 119 | ret = hwmon->irq; |
119 | hwmon->irq); | 120 | dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret); |
120 | return hwmon->irq; | 121 | goto err_free; |
121 | } | 122 | } |
122 | 123 | ||
123 | hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 124 | hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
124 | if (!hwmon->mem) { | 125 | if (!hwmon->mem) { |
126 | ret = -ENOENT; | ||
125 | dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); | 127 | dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); |
126 | return -ENOENT; | 128 | goto err_free; |
127 | } | 129 | } |
128 | 130 | ||
129 | hwmon->mem = devm_request_mem_region(&pdev->dev, hwmon->mem->start, | 131 | hwmon->mem = request_mem_region(hwmon->mem->start, |
130 | resource_size(hwmon->mem), pdev->name); | 132 | resource_size(hwmon->mem), pdev->name); |
131 | if (!hwmon->mem) { | 133 | if (!hwmon->mem) { |
134 | ret = -EBUSY; | ||
132 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); | 135 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); |
133 | return -EBUSY; | 136 | goto err_free; |
134 | } | 137 | } |
135 | 138 | ||
136 | hwmon->base = devm_ioremap_nocache(&pdev->dev, hwmon->mem->start, | 139 | hwmon->base = ioremap_nocache(hwmon->mem->start, |
137 | resource_size(hwmon->mem)); | 140 | resource_size(hwmon->mem)); |
138 | if (!hwmon->base) { | 141 | if (!hwmon->base) { |
142 | ret = -EBUSY; | ||
139 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); | 143 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); |
140 | return -EBUSY; | 144 | goto err_release_mem_region; |
141 | } | 145 | } |
142 | 146 | ||
143 | init_completion(&hwmon->read_completion); | 147 | init_completion(&hwmon->read_completion); |
@@ -145,18 +149,17 @@ static int jz4740_hwmon_probe(struct platform_device *pdev) | |||
145 | 149 | ||
146 | platform_set_drvdata(pdev, hwmon); | 150 | platform_set_drvdata(pdev, hwmon); |
147 | 151 | ||
148 | ret = devm_request_irq(&pdev->dev, hwmon->irq, jz4740_hwmon_irq, 0, | 152 | ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon); |
149 | pdev->name, hwmon); | ||
150 | if (ret) { | 153 | if (ret) { |
151 | dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); | 154 | dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); |
152 | return ret; | 155 | goto err_iounmap; |
153 | } | 156 | } |
154 | disable_irq(hwmon->irq); | 157 | disable_irq(hwmon->irq); |
155 | 158 | ||
156 | ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 159 | ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); |
157 | if (ret) { | 160 | if (ret) { |
158 | dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret); | 161 | dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret); |
159 | return ret; | 162 | goto err_free_irq; |
160 | } | 163 | } |
161 | 164 | ||
162 | hwmon->hwmon = hwmon_device_register(&pdev->dev); | 165 | hwmon->hwmon = hwmon_device_register(&pdev->dev); |
@@ -169,29 +172,57 @@ static int jz4740_hwmon_probe(struct platform_device *pdev) | |||
169 | 172 | ||
170 | err_remove_file: | 173 | err_remove_file: |
171 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 174 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); |
175 | err_free_irq: | ||
176 | free_irq(hwmon->irq, hwmon); | ||
177 | err_iounmap: | ||
178 | platform_set_drvdata(pdev, NULL); | ||
179 | iounmap(hwmon->base); | ||
180 | err_release_mem_region: | ||
181 | release_mem_region(hwmon->mem->start, resource_size(hwmon->mem)); | ||
182 | err_free: | ||
183 | kfree(hwmon); | ||
184 | |||
172 | return ret; | 185 | return ret; |
173 | } | 186 | } |
174 | 187 | ||
175 | static int jz4740_hwmon_remove(struct platform_device *pdev) | 188 | static int __devexit jz4740_hwmon_remove(struct platform_device *pdev) |
176 | { | 189 | { |
177 | struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev); | 190 | struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev); |
178 | 191 | ||
179 | hwmon_device_unregister(hwmon->hwmon); | 192 | hwmon_device_unregister(hwmon->hwmon); |
180 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 193 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); |
181 | 194 | ||
195 | free_irq(hwmon->irq, hwmon); | ||
196 | |||
197 | iounmap(hwmon->base); | ||
198 | release_mem_region(hwmon->mem->start, resource_size(hwmon->mem)); | ||
199 | |||
200 | platform_set_drvdata(pdev, NULL); | ||
201 | kfree(hwmon); | ||
202 | |||
182 | return 0; | 203 | return 0; |
183 | } | 204 | } |
184 | 205 | ||
185 | static struct platform_driver jz4740_hwmon_driver = { | 206 | struct platform_driver jz4740_hwmon_driver = { |
186 | .probe = jz4740_hwmon_probe, | 207 | .probe = jz4740_hwmon_probe, |
187 | .remove = jz4740_hwmon_remove, | 208 | .remove = __devexit_p(jz4740_hwmon_remove), |
188 | .driver = { | 209 | .driver = { |
189 | .name = "jz4740-hwmon", | 210 | .name = "jz4740-hwmon", |
190 | .owner = THIS_MODULE, | 211 | .owner = THIS_MODULE, |
191 | }, | 212 | }, |
192 | }; | 213 | }; |
193 | 214 | ||
194 | module_platform_driver(jz4740_hwmon_driver); | 215 | static int __init jz4740_hwmon_init(void) |
216 | { | ||
217 | return platform_driver_register(&jz4740_hwmon_driver); | ||
218 | } | ||
219 | module_init(jz4740_hwmon_init); | ||
220 | |||
221 | static void __exit jz4740_hwmon_exit(void) | ||
222 | { | ||
223 | platform_driver_unregister(&jz4740_hwmon_driver); | ||
224 | } | ||
225 | module_exit(jz4740_hwmon_exit); | ||
195 | 226 | ||
196 | MODULE_DESCRIPTION("JZ4740 SoC HWMON driver"); | 227 | MODULE_DESCRIPTION("JZ4740 SoC HWMON driver"); |
197 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); | 228 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |