| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* CLPS711X GPIO driver |
| 4 |
* |
| 5 |
* Copyright (C) 2012,2013 Alexander Shiyan <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <linux/err.h> |
| 9 |
#include <linux/module.h> |
| 10 |
#include <linux/gpio/driver.h> |
| 11 |
#include <linux/gpio/generic.h> |
| 12 |
#include <linux/platform_device.h> |
| 13 |
|
| 14 |
static int clps711x_gpio_probe(struct platform_device *pdev) |
| 15 |
{ |
| 16 |
struct gpio_generic_chip_config config = { }; |
| 17 |
struct device_node *np = pdev->dev.of_node; |
| 18 |
struct gpio_generic_chip *gen_gc; |
| 19 |
void __iomem *dat, *dir; |
| 20 |
int err, id; |
| 21 |
|
| 22 |
if (!np) |
| 23 |
return -ENODEV; |
| 24 |
|
| 25 |
id = of_alias_get_id(np, "gpio"); |
| 26 |
if ((id < 0) || (id > 4)) |
| 27 |
return -ENODEV; |
| 28 |
|
| 29 |
gen_gc = devm_kzalloc(&pdev->dev, sizeof(*gen_gc), GFP_KERNEL); |
| 30 |
if (!gen_gc) |
| 31 |
return -ENOMEM; |
| 32 |
|
| 33 |
dat = devm_platform_ioremap_resource(pdev, 0); |
| 34 |
if (IS_ERR(dat)) |
| 35 |
return PTR_ERR(dat); |
| 36 |
|
| 37 |
dir = devm_platform_ioremap_resource(pdev, 1); |
| 38 |
if (IS_ERR(dir)) |
| 39 |
return PTR_ERR(dir); |
| 40 |
|
| 41 |
config.dev = &pdev->dev; |
| 42 |
config.sz = 1; |
| 43 |
config.dat = dat; |
| 44 |
|
| 45 |
switch (id) { |
| 46 |
case 3: |
| 47 |
/* PORTD is inverted logic for direction register */ |
| 48 |
config.dirin = dir; |
| 49 |
break; |
| 50 |
default: |
| 51 |
config.dirout = dir; |
| 52 |
break; |
| 53 |
} |
| 54 |
|
| 55 |
err = gpio_generic_chip_init(gen_gc, &config); |
| 56 |
if (err) |
| 57 |
return err; |
| 58 |
|
| 59 |
switch (id) { |
| 60 |
case 4: |
| 61 |
/* PORTE is 3 lines only */ |
| 62 |
gen_gc->gc.ngpio = 3; |
| 63 |
break; |
| 64 |
default: |
| 65 |
break; |
| 66 |
} |
| 67 |
|
| 68 |
gen_gc->gc.base = -1; |
| 69 |
gen_gc->gc.owner = THIS_MODULE; |
| 70 |
|
| 71 |
return devm_gpiochip_add_data(&pdev->dev, &gen_gc->gc, NULL); |
| 72 |
} |
| 73 |
|
| 74 |
static const struct of_device_id clps711x_gpio_ids[] = { |
| 75 |
{ .compatible = "cirrus,ep7209-gpio" }, |
| 76 |
{ } |
| 77 |
}; |
| 78 |
MODULE_DEVICE_TABLE(of, clps711x_gpio_ids); |
| 79 |
|
| 80 |
static struct platform_driver clps711x_gpio_driver = { |
| 81 |
.driver = { |
| 82 |
.name = "clps711x-gpio", |
| 83 |
.of_match_table = clps711x_gpio_ids, |
| 84 |
}, |
| 85 |
.probe = clps711x_gpio_probe, |
| 86 |
}; |
| 87 |
module_platform_driver(clps711x_gpio_driver); |
| 88 |
|
| 89 |
MODULE_LICENSE("GPL"); |
| 90 |
MODULE_AUTHOR("Alexander Shiyan <[email protected]>"); |
| 91 |
MODULE_DESCRIPTION("CLPS711X GPIO driver"); |
| 92 |
MODULE_ALIAS("platform:clps711x-gpio"); |