mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 07:31:29 +00:00
99a0d9f5e8
Core changes: - Expose pull up/down flags for the GPIO character device to userspace. After clear input from the RaspberryPi and Beagle communities, it has been established that prototyping, industrial automation and make communities strongly need this feature, and as we want people to use the character device, we have implemented the simple pull up/down interface for GPIO lines. This means we can specify that a (chip-specific) pull up/down resistor can be enabled, but does not offer fine-grained control such as cases where the resistance of the same pull resistor can be controlled (yet). - Introduce devm_fwnode_gpiod_get_index() and start to phase out the old symbol devm_fwnode_get_index_gpiod_from_child(). - A bit of documentation clean-up work. - Introduce a define for GPIO line directions and deploy it in all GPIO drivers in the drivers/gpio directory. - Add a special callback to populate pin ranges when cooperating with the pin control subsystem and registering ranges as part of adding a gpiolib driver and a gpio_irq_chip driver at the same time. This is also deployed in the Intel Merrifield driver. New drivers: - RDA Micro GPIO controller. - XGS-iproc GPIO driver. Driver improvements: - Wake event and debounce support on the Tegra 186 driver. - Finalize the Aspeed SGPIO driver. - MPC8xxx uses a normal IRQ handler rather than a chained handler. -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEElDRnuGcz/wPCXQWMQRCzN7AZXXMFAl3hIDcACgkQQRCzN7AZ XXOOyw/8DcaBV6j3EZPDS+b+N74/flNf9JitdJRCtUPn8mjdm+uKNPxbtL/znZc8 zd3rlpiZOqHy8klB3gOPJsJhgXY9QX/b+F5j8fHZvu0DACugRndCqMJ7wrgwUiPn 2ni6KJmz6z5urhcfaAIgyinTWOMegvSVfqjISaUCRCAg3F9dIeQoulRvTPk2ybvv f31jAGemGbvvQPpd81SYCxuTbMg+jxBIgnOCaX+VmUaBLzh8J2W4It3Myp6M4Sbg Td6QU4b2J2Q0quk/Dc7c4saT+qRODkg2syPKV2YqmWwdLRDxZyKESMdkCXLWlWJU fP+KZ4lDxhCaOAYUrY2sEAYMw4E8MzrfeWikdIe0nk0DWqNQhWvDyzsNsB90XGFb aGgeCPH2W1MdE6usPhLidBaHbLeowzndw5BiEl0UCJUqz7tzTCd5iMIAhoSU/Sr5 ymO8J45G9rdx5pscA3cXhpR/PmqaETYQ/uNrLuxTdI4F4xY12+M0vPrV8z3oDPxB U/uL0v6HndDcFAavQQiMd9eL6Hocirnn+Z2xFut3nOznHY96ozXSnZb3lzvH/kqI Du2C8geboVcZsiZJTKVN1zxnfIA8oDauzTOEpGFbIGFhmy0zt4RRRptL4W8NxeFm KCOk/HqlGeuqJ49epta3mqhUC0MSASA9fdicCdiDqvw+puEznwU= =o13I -----END PGP SIGNATURE----- Merge tag 'gpio-v5.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for the v5.5 kernel cycle Core changes: - Expose pull up/down flags for the GPIO character device to userspace. After clear input from the RaspberryPi and Beagle communities, it has been established that prototyping, industrial automation and make communities strongly need this feature, and as we want people to use the character device, we have implemented the simple pull up/down interface for GPIO lines. This means we can specify that a (chip-specific) pull up/down resistor can be enabled, but does not offer fine-grained control such as cases where the resistance of the same pull resistor can be controlled (yet). - Introduce devm_fwnode_gpiod_get_index() and start to phase out the old symbol devm_fwnode_get_index_gpiod_from_child(). - A bit of documentation clean-up work. - Introduce a define for GPIO line directions and deploy it in all GPIO drivers in the drivers/gpio directory. - Add a special callback to populate pin ranges when cooperating with the pin control subsystem and registering ranges as part of adding a gpiolib driver and a gpio_irq_chip driver at the same time. This is also deployed in the Intel Merrifield driver. New drivers: - RDA Micro GPIO controller. - XGS-iproc GPIO driver. Driver improvements: - Wake event and debounce support on the Tegra 186 driver. - Finalize the Aspeed SGPIO driver. - MPC8xxx uses a normal IRQ handler rather than a chained handler" * tag 'gpio-v5.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (64 commits) gpio: Add TODO item for regmap helper Documentation: gpio: driver.rst: Fix warnings gpio: of: Fix bogus reference to gpiod_get_count() gpiolib: Grammar s/manager/managed/ gpio: lynxpoint: Setup correct IRQ handlers MAINTAINERS: Replace my email by one @kernel.org gpiolib: acpi: Make acpi_gpiochip_alloc_event always return AE_OK gpio/mpc8xxx: fix qoriq GPIO reading gpio: mpc8xxx: Don't overwrite default irq_set_type callback gpiolib: acpi: Print pin number on acpi_gpiochip_alloc_event errors gpiolib: fix coding style in gpiod_hog() drm/bridge: ti-tfp410: switch to using fwnode_gpiod_get_index() gpio: merrifield: Pass irqchip when adding gpiochip gpio: merrifield: Add GPIO <-> pin mapping ranges via callback gpiolib: Introduce ->add_pin_ranges() callback gpio: mmio: remove untrue leftover comment gpio: em: Use platform_get_irq() to obtain interrupts gpio: tegra186: Add debounce support gpio: tegra186: Program interrupt route mapping gpio: tegra186: Derive register offsets from bank/port ...
236 lines
6.4 KiB
C
236 lines
6.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
// Copyright (C) 2018 ROHM Semiconductors
|
|
// gpio-bd70528.c ROHM BD70528MWV gpio driver
|
|
|
|
#include <linux/gpio/driver.h>
|
|
#include <linux/mfd/rohm-bd70528.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/regmap.h>
|
|
|
|
#define GPIO_IN_REG(offset) (BD70528_REG_GPIO1_IN + (offset) * 2)
|
|
#define GPIO_OUT_REG(offset) (BD70528_REG_GPIO1_OUT + (offset) * 2)
|
|
|
|
struct bd70528_gpio {
|
|
struct rohm_regmap_dev chip;
|
|
struct gpio_chip gpio;
|
|
};
|
|
|
|
static int bd70528_set_debounce(struct bd70528_gpio *bdgpio,
|
|
unsigned int offset, unsigned int debounce)
|
|
{
|
|
u8 val;
|
|
|
|
switch (debounce) {
|
|
case 0:
|
|
val = BD70528_DEBOUNCE_DISABLE;
|
|
break;
|
|
case 1 ... 15000:
|
|
val = BD70528_DEBOUNCE_15MS;
|
|
break;
|
|
case 15001 ... 30000:
|
|
val = BD70528_DEBOUNCE_30MS;
|
|
break;
|
|
case 30001 ... 50000:
|
|
val = BD70528_DEBOUNCE_50MS;
|
|
break;
|
|
default:
|
|
dev_err(bdgpio->chip.dev,
|
|
"Invalid debounce value %u\n", debounce);
|
|
return -EINVAL;
|
|
}
|
|
return regmap_update_bits(bdgpio->chip.regmap, GPIO_IN_REG(offset),
|
|
BD70528_DEBOUNCE_MASK, val);
|
|
}
|
|
|
|
static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset)
|
|
{
|
|
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
|
|
int val, ret;
|
|
|
|
/* Do we need to do something to IRQs here? */
|
|
ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val);
|
|
if (ret) {
|
|
dev_err(bdgpio->chip.dev, "Could not read gpio direction\n");
|
|
return ret;
|
|
}
|
|
if (val & BD70528_GPIO_OUT_EN_MASK)
|
|
return GPIO_LINE_DIRECTION_OUT;
|
|
|
|
return GPIO_LINE_DIRECTION_IN;
|
|
}
|
|
|
|
static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
|
|
unsigned long config)
|
|
{
|
|
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
|
|
|
|
switch (pinconf_to_config_param(config)) {
|
|
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
|
|
return regmap_update_bits(bdgpio->chip.regmap,
|
|
GPIO_OUT_REG(offset),
|
|
BD70528_GPIO_DRIVE_MASK,
|
|
BD70528_GPIO_OPEN_DRAIN);
|
|
break;
|
|
case PIN_CONFIG_DRIVE_PUSH_PULL:
|
|
return regmap_update_bits(bdgpio->chip.regmap,
|
|
GPIO_OUT_REG(offset),
|
|
BD70528_GPIO_DRIVE_MASK,
|
|
BD70528_GPIO_PUSH_PULL);
|
|
break;
|
|
case PIN_CONFIG_INPUT_DEBOUNCE:
|
|
return bd70528_set_debounce(bdgpio, offset,
|
|
pinconf_to_config_argument(config));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return -ENOTSUPP;
|
|
}
|
|
|
|
static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset)
|
|
{
|
|
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
|
|
|
|
/* Do we need to do something to IRQs here? */
|
|
return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset),
|
|
BD70528_GPIO_OUT_EN_MASK,
|
|
BD70528_GPIO_OUT_DISABLE);
|
|
}
|
|
|
|
static void bd70528_gpio_set(struct gpio_chip *chip, unsigned int offset,
|
|
int value)
|
|
{
|
|
int ret;
|
|
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
|
|
u8 val = (value) ? BD70528_GPIO_OUT_HI : BD70528_GPIO_OUT_LO;
|
|
|
|
ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset),
|
|
BD70528_GPIO_OUT_MASK, val);
|
|
if (ret)
|
|
dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value);
|
|
}
|
|
|
|
static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset,
|
|
int value)
|
|
{
|
|
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
|
|
|
|
bd70528_gpio_set(chip, offset, value);
|
|
return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset),
|
|
BD70528_GPIO_OUT_EN_MASK,
|
|
BD70528_GPIO_OUT_ENABLE);
|
|
}
|
|
|
|
#define GPIO_IN_STATE_MASK(offset) (BD70528_GPIO_IN_STATE_BASE << (offset))
|
|
|
|
static int bd70528_gpio_get_o(struct bd70528_gpio *bdgpio, unsigned int offset)
|
|
{
|
|
int ret;
|
|
unsigned int val;
|
|
|
|
ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val);
|
|
if (!ret)
|
|
ret = !!(val & BD70528_GPIO_OUT_MASK);
|
|
else
|
|
dev_err(bdgpio->chip.dev, "GPIO (out) state read failed\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int bd70528_gpio_get_i(struct bd70528_gpio *bdgpio, unsigned int offset)
|
|
{
|
|
unsigned int val;
|
|
int ret;
|
|
|
|
ret = regmap_read(bdgpio->chip.regmap, BD70528_REG_GPIO_STATE, &val);
|
|
|
|
if (!ret)
|
|
ret = !(val & GPIO_IN_STATE_MASK(offset));
|
|
else
|
|
dev_err(bdgpio->chip.dev, "GPIO (in) state read failed\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset)
|
|
{
|
|
int ret;
|
|
struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
|
|
|
|
/*
|
|
* There is a race condition where someone might be changing the
|
|
* GPIO direction after we get it but before we read the value. But
|
|
* application design where GPIO direction may be changed just when
|
|
* we read GPIO value would be pointless as reader could not know
|
|
* whether the returned high/low state is caused by input or output.
|
|
* Or then there must be other ways to mitigate the issue. Thus
|
|
* locking would make no sense.
|
|
*/
|
|
ret = bd70528_get_direction(chip, offset);
|
|
if (ret == GPIO_LINE_DIRECTION_OUT)
|
|
ret = bd70528_gpio_get_o(bdgpio, offset);
|
|
else if (ret == GPIO_LINE_DIRECTION_IN)
|
|
ret = bd70528_gpio_get_i(bdgpio, offset);
|
|
else
|
|
dev_err(bdgpio->chip.dev, "failed to read GPIO direction\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int bd70528_probe(struct platform_device *pdev)
|
|
{
|
|
struct bd70528_gpio *bdgpio;
|
|
struct rohm_regmap_dev *bd70528;
|
|
int ret;
|
|
|
|
bd70528 = dev_get_drvdata(pdev->dev.parent);
|
|
if (!bd70528) {
|
|
dev_err(&pdev->dev, "No MFD driver data\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio),
|
|
GFP_KERNEL);
|
|
if (!bdgpio)
|
|
return -ENOMEM;
|
|
bdgpio->chip.dev = &pdev->dev;
|
|
bdgpio->gpio.parent = pdev->dev.parent;
|
|
bdgpio->gpio.label = "bd70528-gpio";
|
|
bdgpio->gpio.owner = THIS_MODULE;
|
|
bdgpio->gpio.get_direction = bd70528_get_direction;
|
|
bdgpio->gpio.direction_input = bd70528_direction_input;
|
|
bdgpio->gpio.direction_output = bd70528_direction_output;
|
|
bdgpio->gpio.set_config = bd70528_gpio_set_config;
|
|
bdgpio->gpio.can_sleep = true;
|
|
bdgpio->gpio.get = bd70528_gpio_get;
|
|
bdgpio->gpio.set = bd70528_gpio_set;
|
|
bdgpio->gpio.ngpio = 4;
|
|
bdgpio->gpio.base = -1;
|
|
#ifdef CONFIG_OF_GPIO
|
|
bdgpio->gpio.of_node = pdev->dev.parent->of_node;
|
|
#endif
|
|
bdgpio->chip.regmap = bd70528->regmap;
|
|
|
|
ret = devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio,
|
|
bdgpio);
|
|
if (ret)
|
|
dev_err(&pdev->dev, "gpio_init: Failed to add bd70528-gpio\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct platform_driver bd70528_gpio = {
|
|
.driver = {
|
|
.name = "bd70528-gpio"
|
|
},
|
|
.probe = bd70528_probe,
|
|
};
|
|
|
|
module_platform_driver(bd70528_gpio);
|
|
|
|
MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
|
|
MODULE_DESCRIPTION("BD70528 voltage regulator driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:bd70528-gpio");
|