Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Philips UCB1400 GPIO driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author: Marek Vasut <marek.vasut@gmail.com>
^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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/ucb1400.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) static int ucb1400_gpio_dir_in(struct gpio_chip *gc, unsigned off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	struct ucb1400_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	ucb1400_gpio_set_direction(gpio->ac97, off, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static int ucb1400_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct ucb1400_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	ucb1400_gpio_set_direction(gpio->ac97, off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	ucb1400_gpio_set_value(gpio->ac97, off, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int ucb1400_gpio_get(struct gpio_chip *gc, unsigned off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct ucb1400_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return !!ucb1400_gpio_get_value(gpio->ac97, off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static void ucb1400_gpio_set(struct gpio_chip *gc, unsigned off, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct ucb1400_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	ucb1400_gpio_set_value(gpio->ac97, off, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int ucb1400_gpio_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct ucb1400_gpio *ucb = dev_get_platdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!(ucb && ucb->gpio_offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	platform_set_drvdata(dev, ucb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	ucb->gc.label = "ucb1400_gpio";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	ucb->gc.base = ucb->gpio_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ucb->gc.ngpio = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	ucb->gc.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	ucb->gc.direction_input = ucb1400_gpio_dir_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	ucb->gc.direction_output = ucb1400_gpio_dir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	ucb->gc.get = ucb1400_gpio_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	ucb->gc.set = ucb1400_gpio_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	ucb->gc.can_sleep = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (ucb->gpio_setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int ucb1400_gpio_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct ucb1400_gpio *ucb = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (ucb && ucb->gpio_teardown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		err = ucb->gpio_teardown(&dev->dev, ucb->gc.ngpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static struct platform_driver ucb1400_gpio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.probe	= ucb1400_gpio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.remove	= ucb1400_gpio_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		.name	= "ucb1400_gpio"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) module_platform_driver(ucb1400_gpio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) MODULE_DESCRIPTION("Philips UCB1400 GPIO driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) MODULE_ALIAS("platform:ucb1400_gpio");