aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorPramod Gurav <pramod.gurav@smartplayin.com>2014-10-08 14:26:29 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-10-22 13:50:16 -0400
commitdae7aa8d849615134a11704cbd37fb45a22bd316 (patch)
treea518fa8bb4c72427561088d99ca19416d02a5170 /drivers/input/keyboard
parent38c3807252085f97e1359400c8bf1312da3168c6 (diff)
Input: lpc32xx-keys - switch to using managed resources
This change switches to using devm_* managed resources APIs to request the resources in probe to simplify probe error path and module unloading. Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/lpc32xx-keys.c92
1 files changed, 20 insertions, 72 deletions
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c
index 8b1b01361ec6..9e9786d576cb 100644
--- a/drivers/input/keyboard/lpc32xx-keys.c
+++ b/drivers/input/keyboard/lpc32xx-keys.c
@@ -66,7 +66,6 @@
66struct lpc32xx_kscan_drv { 66struct lpc32xx_kscan_drv {
67 struct input_dev *input; 67 struct input_dev *input;
68 struct clk *clk; 68 struct clk *clk;
69 struct resource *iores;
70 void __iomem *kscan_base; 69 void __iomem *kscan_base;
71 unsigned int irq; 70 unsigned int irq;
72 71
@@ -188,32 +187,27 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev)
188 return -EINVAL; 187 return -EINVAL;
189 } 188 }
190 189
191 kscandat = kzalloc(sizeof(struct lpc32xx_kscan_drv), GFP_KERNEL); 190 kscandat = devm_kzalloc(&pdev->dev, sizeof(*kscandat),
192 if (!kscandat) { 191 GFP_KERNEL);
193 dev_err(&pdev->dev, "failed to allocate memory\n"); 192 if (!kscandat)
194 return -ENOMEM; 193 return -ENOMEM;
195 }
196 194
197 error = lpc32xx_parse_dt(&pdev->dev, kscandat); 195 error = lpc32xx_parse_dt(&pdev->dev, kscandat);
198 if (error) { 196 if (error) {
199 dev_err(&pdev->dev, "failed to parse device tree\n"); 197 dev_err(&pdev->dev, "failed to parse device tree\n");
200 goto err_free_mem; 198 return error;
201 } 199 }
202 200
203 keymap_size = sizeof(kscandat->keymap[0]) * 201 keymap_size = sizeof(kscandat->keymap[0]) *
204 (kscandat->matrix_sz << kscandat->row_shift); 202 (kscandat->matrix_sz << kscandat->row_shift);
205 kscandat->keymap = kzalloc(keymap_size, GFP_KERNEL); 203 kscandat->keymap = devm_kzalloc(&pdev->dev, keymap_size, GFP_KERNEL);
206 if (!kscandat->keymap) { 204 if (!kscandat->keymap)
207 dev_err(&pdev->dev, "could not allocate memory for keymap\n"); 205 return -ENOMEM;
208 error = -ENOMEM;
209 goto err_free_mem;
210 }
211 206
212 kscandat->input = input = input_allocate_device(); 207 kscandat->input = input = devm_input_allocate_device(&pdev->dev);
213 if (!input) { 208 if (!input) {
214 dev_err(&pdev->dev, "failed to allocate input device\n"); 209 dev_err(&pdev->dev, "failed to allocate input device\n");
215 error = -ENOMEM; 210 return -ENOMEM;
216 goto err_free_keymap;
217 } 211 }
218 212
219 /* Setup key input */ 213 /* Setup key input */
@@ -234,39 +228,26 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev)
234 kscandat->keymap, kscandat->input); 228 kscandat->keymap, kscandat->input);
235 if (error) { 229 if (error) {
236 dev_err(&pdev->dev, "failed to build keymap\n"); 230 dev_err(&pdev->dev, "failed to build keymap\n");
237 goto err_free_input; 231 return error;
238 } 232 }
239 233
240 input_set_drvdata(kscandat->input, kscandat); 234 input_set_drvdata(kscandat->input, kscandat);
241 235
242 kscandat->iores = request_mem_region(res->start, resource_size(res), 236 kscandat->kscan_base = devm_ioremap_resource(&pdev->dev, res);
243 pdev->name); 237 if (IS_ERR(kscandat->kscan_base))
244 if (!kscandat->iores) { 238 return PTR_ERR(kscandat->kscan_base);
245 dev_err(&pdev->dev, "failed to request I/O memory\n");
246 error = -EBUSY;
247 goto err_free_input;
248 }
249
250 kscandat->kscan_base = ioremap(kscandat->iores->start,
251 resource_size(kscandat->iores));
252 if (!kscandat->kscan_base) {
253 dev_err(&pdev->dev, "failed to remap I/O memory\n");
254 error = -EBUSY;
255 goto err_release_memregion;
256 }
257 239
258 /* Get the key scanner clock */ 240 /* Get the key scanner clock */
259 kscandat->clk = clk_get(&pdev->dev, NULL); 241 kscandat->clk = devm_clk_get(&pdev->dev, NULL);
260 if (IS_ERR(kscandat->clk)) { 242 if (IS_ERR(kscandat->clk)) {
261 dev_err(&pdev->dev, "failed to get clock\n"); 243 dev_err(&pdev->dev, "failed to get clock\n");
262 error = PTR_ERR(kscandat->clk); 244 return PTR_ERR(kscandat->clk);
263 goto err_unmap;
264 } 245 }
265 246
266 /* Configure the key scanner */ 247 /* Configure the key scanner */
267 error = clk_prepare_enable(kscandat->clk); 248 error = clk_prepare_enable(kscandat->clk);
268 if (error) 249 if (error)
269 goto err_clk_put; 250 return error;
270 251
271 writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base)); 252 writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base));
272 writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base)); 253 writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base));
@@ -277,52 +258,20 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev)
277 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); 258 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
278 clk_disable_unprepare(kscandat->clk); 259 clk_disable_unprepare(kscandat->clk);
279 260
280 error = request_irq(irq, lpc32xx_kscan_irq, 0, pdev->name, kscandat); 261 error = devm_request_irq(&pdev->dev, irq, lpc32xx_kscan_irq, 0,
262 pdev->name, kscandat);
281 if (error) { 263 if (error) {
282 dev_err(&pdev->dev, "failed to request irq\n"); 264 dev_err(&pdev->dev, "failed to request irq\n");
283 goto err_clk_put; 265 return error;
284 } 266 }
285 267
286 error = input_register_device(kscandat->input); 268 error = input_register_device(kscandat->input);
287 if (error) { 269 if (error) {
288 dev_err(&pdev->dev, "failed to register input device\n"); 270 dev_err(&pdev->dev, "failed to register input device\n");
289 goto err_free_irq; 271 return error;
290 } 272 }
291 273
292 platform_set_drvdata(pdev, kscandat); 274 platform_set_drvdata(pdev, kscandat);
293 return 0;
294
295err_free_irq:
296 free_irq(irq, kscandat);
297err_clk_put:
298 clk_put(kscandat->clk);
299err_unmap:
300 iounmap(kscandat->kscan_base);
301err_release_memregion:
302 release_mem_region(kscandat->iores->start,
303 resource_size(kscandat->iores));
304err_free_input:
305 input_free_device(kscandat->input);
306err_free_keymap:
307 kfree(kscandat->keymap);
308err_free_mem:
309 kfree(kscandat);
310
311 return error;
312}
313
314static int lpc32xx_kscan_remove(struct platform_device *pdev)
315{
316 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
317
318 free_irq(platform_get_irq(pdev, 0), kscandat);
319 clk_put(kscandat->clk);
320 iounmap(kscandat->kscan_base);
321 release_mem_region(kscandat->iores->start,
322 resource_size(kscandat->iores));
323 input_unregister_device(kscandat->input);
324 kfree(kscandat->keymap);
325 kfree(kscandat);
326 275
327 return 0; 276 return 0;
328} 277}
@@ -378,7 +327,6 @@ MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match);
378 327
379static struct platform_driver lpc32xx_kscan_driver = { 328static struct platform_driver lpc32xx_kscan_driver = {
380 .probe = lpc32xx_kscan_probe, 329 .probe = lpc32xx_kscan_probe,
381 .remove = lpc32xx_kscan_remove,
382 .driver = { 330 .driver = {
383 .name = DRV_NAME, 331 .name = DRV_NAME,
384 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,