Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.17-rc2 110 lines 2.8 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2015-2023 Texas Instruments Incorporated - https://www.ti.com/ 4 * Andrew Davis <afd@ti.com> 5 * 6 * Based on the TPS65912 driver 7 */ 8 9#include <linux/gpio/driver.h> 10#include <linux/module.h> 11#include <linux/platform_device.h> 12 13#include <linux/mfd/tps65086.h> 14 15struct tps65086_gpio { 16 struct gpio_chip chip; 17 struct tps65086 *tps; 18}; 19 20static int tps65086_gpio_get_direction(struct gpio_chip *chip, 21 unsigned offset) 22{ 23 /* This device is output only */ 24 return GPIO_LINE_DIRECTION_OUT; 25} 26 27static int tps65086_gpio_direction_input(struct gpio_chip *chip, 28 unsigned offset) 29{ 30 /* This device is output only */ 31 return -EINVAL; 32} 33 34static int tps65086_gpio_direction_output(struct gpio_chip *chip, 35 unsigned offset, int value) 36{ 37 struct tps65086_gpio *gpio = gpiochip_get_data(chip); 38 39 /* Set the initial value */ 40 return regmap_update_bits(gpio->tps->regmap, TPS65086_GPOCTRL, 41 BIT(4 + offset), value ? BIT(4 + offset) : 0); 42} 43 44static int tps65086_gpio_get(struct gpio_chip *chip, unsigned offset) 45{ 46 struct tps65086_gpio *gpio = gpiochip_get_data(chip); 47 int ret, val; 48 49 ret = regmap_read(gpio->tps->regmap, TPS65086_GPOCTRL, &val); 50 if (ret < 0) 51 return ret; 52 53 return val & BIT(4 + offset); 54} 55 56static int tps65086_gpio_set(struct gpio_chip *chip, unsigned int offset, 57 int value) 58{ 59 struct tps65086_gpio *gpio = gpiochip_get_data(chip); 60 61 return regmap_update_bits(gpio->tps->regmap, TPS65086_GPOCTRL, 62 BIT(4 + offset), value ? BIT(4 + offset) : 0); 63} 64 65static const struct gpio_chip template_chip = { 66 .label = "tps65086-gpio", 67 .owner = THIS_MODULE, 68 .get_direction = tps65086_gpio_get_direction, 69 .direction_input = tps65086_gpio_direction_input, 70 .direction_output = tps65086_gpio_direction_output, 71 .get = tps65086_gpio_get, 72 .set = tps65086_gpio_set, 73 .base = -1, 74 .ngpio = 4, 75 .can_sleep = true, 76}; 77 78static int tps65086_gpio_probe(struct platform_device *pdev) 79{ 80 struct tps65086_gpio *gpio; 81 82 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 83 if (!gpio) 84 return -ENOMEM; 85 86 gpio->tps = dev_get_drvdata(pdev->dev.parent); 87 gpio->chip = template_chip; 88 gpio->chip.parent = gpio->tps->dev; 89 90 return devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); 91} 92 93static const struct platform_device_id tps65086_gpio_id_table[] = { 94 { "tps65086-gpio", }, 95 { /* sentinel */ } 96}; 97MODULE_DEVICE_TABLE(platform, tps65086_gpio_id_table); 98 99static struct platform_driver tps65086_gpio_driver = { 100 .driver = { 101 .name = "tps65086-gpio", 102 }, 103 .probe = tps65086_gpio_probe, 104 .id_table = tps65086_gpio_id_table, 105}; 106module_platform_driver(tps65086_gpio_driver); 107 108MODULE_AUTHOR("Andrew Davis <afd@ti.com>"); 109MODULE_DESCRIPTION("TPS65086 GPIO driver"); 110MODULE_LICENSE("GPL v2");