diff options
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/pwm-imx.c | 57 |
1 files changed, 10 insertions, 47 deletions
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index 900d14562de8..2a0b35333972 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c | |||
@@ -159,18 +159,16 @@ static int __devinit imx_pwm_probe(struct platform_device *pdev) | |||
159 | struct resource *r; | 159 | struct resource *r; |
160 | int ret = 0; | 160 | int ret = 0; |
161 | 161 | ||
162 | imx = kzalloc(sizeof(*imx), GFP_KERNEL); | 162 | imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); |
163 | if (imx == NULL) { | 163 | if (imx == NULL) { |
164 | dev_err(&pdev->dev, "failed to allocate memory\n"); | 164 | dev_err(&pdev->dev, "failed to allocate memory\n"); |
165 | return -ENOMEM; | 165 | return -ENOMEM; |
166 | } | 166 | } |
167 | 167 | ||
168 | imx->clk = clk_get(&pdev->dev, "pwm"); | 168 | imx->clk = devm_clk_get(&pdev->dev, "pwm"); |
169 | 169 | ||
170 | if (IS_ERR(imx->clk)) { | 170 | if (IS_ERR(imx->clk)) |
171 | ret = PTR_ERR(imx->clk); | 171 | return PTR_ERR(imx->clk); |
172 | goto err_free; | ||
173 | } | ||
174 | 172 | ||
175 | imx->chip.ops = &imx_pwm_ops; | 173 | imx->chip.ops = &imx_pwm_ops; |
176 | imx->chip.dev = &pdev->dev; | 174 | imx->chip.dev = &pdev->dev; |
@@ -182,65 +180,30 @@ static int __devinit imx_pwm_probe(struct platform_device *pdev) | |||
182 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 180 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
183 | if (r == NULL) { | 181 | if (r == NULL) { |
184 | dev_err(&pdev->dev, "no memory resource defined\n"); | 182 | dev_err(&pdev->dev, "no memory resource defined\n"); |
185 | ret = -ENODEV; | 183 | return -ENODEV; |
186 | goto err_free_clk; | ||
187 | } | ||
188 | |||
189 | r = request_mem_region(r->start, resource_size(r), pdev->name); | ||
190 | if (r == NULL) { | ||
191 | dev_err(&pdev->dev, "failed to request memory resource\n"); | ||
192 | ret = -EBUSY; | ||
193 | goto err_free_clk; | ||
194 | } | 184 | } |
195 | 185 | ||
196 | imx->mmio_base = ioremap(r->start, resource_size(r)); | 186 | imx->mmio_base = devm_request_and_ioremap(&pdev->dev, r); |
197 | if (imx->mmio_base == NULL) { | 187 | if (imx->mmio_base == NULL) |
198 | dev_err(&pdev->dev, "failed to ioremap() registers\n"); | 188 | return -EADDRNOTAVAIL; |
199 | ret = -ENODEV; | ||
200 | goto err_free_mem; | ||
201 | } | ||
202 | 189 | ||
203 | ret = pwmchip_add(&imx->chip); | 190 | ret = pwmchip_add(&imx->chip); |
204 | if (ret < 0) | 191 | if (ret < 0) |
205 | goto err_iounmap; | 192 | return ret; |
206 | 193 | ||
207 | platform_set_drvdata(pdev, imx); | 194 | platform_set_drvdata(pdev, imx); |
208 | return 0; | 195 | return 0; |
209 | |||
210 | err_iounmap: | ||
211 | iounmap(imx->mmio_base); | ||
212 | err_free_mem: | ||
213 | release_mem_region(r->start, resource_size(r)); | ||
214 | err_free_clk: | ||
215 | clk_put(imx->clk); | ||
216 | err_free: | ||
217 | kfree(imx); | ||
218 | return ret; | ||
219 | } | 196 | } |
220 | 197 | ||
221 | static int __devexit imx_pwm_remove(struct platform_device *pdev) | 198 | static int __devexit imx_pwm_remove(struct platform_device *pdev) |
222 | { | 199 | { |
223 | struct imx_chip *imx; | 200 | struct imx_chip *imx; |
224 | struct resource *r; | ||
225 | int ret; | ||
226 | 201 | ||
227 | imx = platform_get_drvdata(pdev); | 202 | imx = platform_get_drvdata(pdev); |
228 | if (imx == NULL) | 203 | if (imx == NULL) |
229 | return -ENODEV; | 204 | return -ENODEV; |
230 | 205 | ||
231 | ret = pwmchip_remove(&imx->chip); | 206 | return pwmchip_remove(&imx->chip); |
232 | if (ret) | ||
233 | return ret; | ||
234 | |||
235 | iounmap(imx->mmio_base); | ||
236 | |||
237 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
238 | release_mem_region(r->start, resource_size(r)); | ||
239 | |||
240 | clk_put(imx->clk); | ||
241 | |||
242 | kfree(imx); | ||
243 | return 0; | ||
244 | } | 207 | } |
245 | 208 | ||
246 | static struct platform_driver imx_pwm_driver = { | 209 | static struct platform_driver imx_pwm_driver = { |