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