Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 1 | /* |
| 2 | * CLPS711X GPIO driver |
| 3 | * |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 4 | * Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru> |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 12 | #include <linux/err.h> |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 13 | #include <linux/module.h> |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 14 | #include <linux/gpio/driver.h> |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
| 16 | |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 17 | static int clps711x_gpio_probe(struct platform_device *pdev) |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 18 | { |
Alexander Shiyan | a180132 | 2013-04-26 19:47:30 +0400 | [diff] [blame] | 19 | struct device_node *np = pdev->dev.of_node; |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 20 | void __iomem *dat, *dir; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 21 | struct gpio_chip *gc; |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 22 | struct resource *res; |
Alexander Shiyan | 1bdb5c8 | 2016-06-04 10:10:12 +0300 | [diff] [blame] | 23 | int err, id; |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 24 | |
Alexander Shiyan | 1bdb5c8 | 2016-06-04 10:10:12 +0300 | [diff] [blame] | 25 | if (!np) |
| 26 | return -ENODEV; |
| 27 | |
| 28 | id = of_alias_get_id(np, "gpio"); |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 29 | if ((id < 0) || (id > 4)) |
| 30 | return -ENODEV; |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 31 | |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 32 | gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); |
| 33 | if (!gc) |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 34 | return -ENOMEM; |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 35 | |
| 36 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 37 | dat = devm_ioremap_resource(&pdev->dev, res); |
| 38 | if (IS_ERR(dat)) |
| 39 | return PTR_ERR(dat); |
| 40 | |
| 41 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 42 | dir = devm_ioremap_resource(&pdev->dev, res); |
| 43 | if (IS_ERR(dir)) |
| 44 | return PTR_ERR(dir); |
| 45 | |
| 46 | switch (id) { |
| 47 | case 3: |
| 48 | /* PORTD is inverted logic for direction register */ |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 49 | err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 50 | NULL, dir, 0); |
| 51 | break; |
| 52 | default: |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 53 | err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL, |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 54 | dir, NULL, 0); |
| 55 | break; |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 56 | } |
| 57 | |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 58 | if (err) |
| 59 | return err; |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 60 | |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 61 | switch (id) { |
| 62 | case 4: |
| 63 | /* PORTE is 3 lines only */ |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 64 | gc->ngpio = 3; |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 65 | break; |
| 66 | default: |
| 67 | break; |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 68 | } |
| 69 | |
Alexander Shiyan | 1bdb5c8 | 2016-06-04 10:10:12 +0300 | [diff] [blame] | 70 | gc->base = -1; |
Linus Walleij | 0f4630f | 2015-12-04 14:02:58 +0100 | [diff] [blame] | 71 | gc->owner = THIS_MODULE; |
| 72 | platform_set_drvdata(pdev, gc); |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 73 | |
Laxman Dewangan | da9d670 | 2016-02-22 17:43:28 +0530 | [diff] [blame] | 74 | return devm_gpiochip_add_data(&pdev->dev, gc, NULL); |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 75 | } |
| 76 | |
Alexander Shiyan | e8b49e0 | 2013-12-24 18:08:53 +0400 | [diff] [blame] | 77 | static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = { |
Alexander Shiyan | 1a4d458 | 2016-06-04 10:09:59 +0300 | [diff] [blame] | 78 | { .compatible = "cirrus,ep7209-gpio" }, |
Alexander Shiyan | a180132 | 2013-04-26 19:47:30 +0400 | [diff] [blame] | 79 | { } |
| 80 | }; |
| 81 | MODULE_DEVICE_TABLE(of, clps711x_gpio_ids); |
| 82 | |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 83 | static struct platform_driver clps711x_gpio_driver = { |
| 84 | .driver = { |
Alexander Shiyan | a180132 | 2013-04-26 19:47:30 +0400 | [diff] [blame] | 85 | .name = "clps711x-gpio", |
Alexander Shiyan | e8b49e0 | 2013-12-24 18:08:53 +0400 | [diff] [blame] | 86 | .of_match_table = of_match_ptr(clps711x_gpio_ids), |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 87 | }, |
| 88 | .probe = clps711x_gpio_probe, |
Alexander Shiyan | 55fe14a | 2013-04-26 19:47:28 +0400 | [diff] [blame] | 89 | }; |
| 90 | module_platform_driver(clps711x_gpio_driver); |
| 91 | |
| 92 | MODULE_LICENSE("GPL"); |
Alexander Shiyan | a3b8d4a | 2012-10-09 20:05:56 +0400 | [diff] [blame] | 93 | MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>"); |
| 94 | MODULE_DESCRIPTION("CLPS711X GPIO driver"); |
Axel Lin | 21708c9 | 2014-02-04 17:39:15 +0800 | [diff] [blame] | 95 | MODULE_ALIAS("platform:clps711x-gpio"); |