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