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)  * Maxim MAX96752F GPIO driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
^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/gpio/driver.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/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mfd/max96752f.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) struct max96752f_gpio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct gpio_chip gpio_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int max96752f_gpio_direction_output(struct gpio_chip *gc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 					   unsigned int offset, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct max96752f_gpio *gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	regmap_update_bits(gpio->regmap, GPIO_A_REG(offset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			   GPIO_OUT_DIS | GPIO_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			   FIELD_PREP(GPIO_OUT_DIS, 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 			   FIELD_PREP(GPIO_OUT, value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void max96752f_gpio_set(struct gpio_chip *gc, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			       int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct max96752f_gpio *gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	regmap_update_bits(gpio->regmap, GPIO_A_REG(offset), GPIO_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			   FIELD_PREP(GPIO_OUT, value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int max96752f_gpio_get(struct gpio_chip *gc, unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct max96752f_gpio *gpio = gpiochip_get_data(gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	regmap_read(gpio->regmap, GPIO_A_REG(offset), &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return !!FIELD_GET(GPIO_OUT, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static int max96752f_gpio_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct max96752f_gpio *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (!gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	gpio->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	platform_set_drvdata(pdev, gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	gpio->regmap = dev_get_regmap(dev->parent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (!gpio->regmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return dev_err_probe(dev, -ENODEV, "failed to get regmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	gpio->gpio_chip.of_node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	gpio->gpio_chip.label = dev_name(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	gpio->gpio_chip.parent = dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	gpio->gpio_chip.direction_output = max96752f_gpio_direction_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	gpio->gpio_chip.set = max96752f_gpio_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	gpio->gpio_chip.get = max96752f_gpio_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	gpio->gpio_chip.ngpio = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	gpio->gpio_chip.can_sleep = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	gpio->gpio_chip.base = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	ret = devm_gpiochip_add_data(dev, &gpio->gpio_chip, gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return dev_err_probe(dev, ret, "failed to add gpio chip\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static const struct of_device_id max96752f_gpio_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	{ .name = "maxim,max96752f-gpio", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) MODULE_DEVICE_TABLE(of, max96752f_gpio_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static struct platform_driver max96752f_gpio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		.name	= "max96752f-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		.of_match_table = max96752f_gpio_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.probe = max96752f_gpio_probe,
^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(max96752f_gpio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) MODULE_AUTHOR("Wyon Bi <bivvy.bi@rock-chips.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_DESCRIPTION("Maxim MAX96752F GPIO driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) MODULE_LICENSE("GPL");