2018-08-29 17:49:14 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-07-18 10:20:48 +04:00
|
|
|
/*
|
|
|
|
* TI TPS6586x GPIO driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
* Author: Laxman dewangan <ldewangan@nvidia.com>
|
|
|
|
*
|
|
|
|
* Based on tps6586x.c
|
|
|
|
* Copyright (c) 2010 CompuLab Ltd.
|
|
|
|
* Mike Rapoport <mike@compulab.co.il>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
2018-08-29 17:45:30 +03:00
|
|
|
#include <linux/gpio/driver.h>
|
2012-07-18 10:20:48 +04:00
|
|
|
#include <linux/kernel.h>
|
2016-04-01 21:49:38 +03:00
|
|
|
#include <linux/init.h>
|
2012-07-18 10:20:48 +04:00
|
|
|
#include <linux/mfd/tps6586x.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
|
|
|
/* GPIO control registers */
|
|
|
|
#define TPS6586X_GPIOSET1 0x5d
|
|
|
|
#define TPS6586X_GPIOSET2 0x5e
|
|
|
|
|
|
|
|
struct tps6586x_gpio {
|
|
|
|
struct gpio_chip gpio_chip;
|
|
|
|
struct device *parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int tps6586x_gpio_get(struct gpio_chip *gc, unsigned offset)
|
|
|
|
{
|
2015-12-07 16:46:45 +03:00
|
|
|
struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc);
|
2012-07-18 10:20:48 +04:00
|
|
|
uint8_t val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = tps6586x_read(tps6586x_gpio->parent, TPS6586X_GPIOSET2, &val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return !!(val & (1 << offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tps6586x_gpio_set(struct gpio_chip *gc, unsigned offset,
|
|
|
|
int value)
|
|
|
|
{
|
2015-12-07 16:46:45 +03:00
|
|
|
struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc);
|
2012-07-18 10:20:48 +04:00
|
|
|
|
|
|
|
tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET2,
|
|
|
|
value << offset, 1 << offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset,
|
|
|
|
int value)
|
|
|
|
{
|
2015-12-07 16:46:45 +03:00
|
|
|
struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc);
|
2012-07-18 10:20:48 +04:00
|
|
|
uint8_t val, mask;
|
|
|
|
|
|
|
|
tps6586x_gpio_set(gc, offset, value);
|
|
|
|
|
|
|
|
val = 0x1 << (offset * 2);
|
|
|
|
mask = 0x3 << (offset * 2);
|
|
|
|
|
|
|
|
return tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET1,
|
|
|
|
val, mask);
|
|
|
|
}
|
|
|
|
|
2012-11-13 17:48:07 +04:00
|
|
|
static int tps6586x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
|
|
|
|
{
|
2015-12-07 16:46:45 +03:00
|
|
|
struct tps6586x_gpio *tps6586x_gpio = gpiochip_get_data(gc);
|
2012-11-13 17:48:07 +04:00
|
|
|
|
|
|
|
return tps6586x_irq_get_virq(tps6586x_gpio->parent,
|
|
|
|
TPS6586X_INT_PLDO_0 + offset);
|
|
|
|
}
|
|
|
|
|
2012-11-19 22:22:34 +04:00
|
|
|
static int tps6586x_gpio_probe(struct platform_device *pdev)
|
2012-07-18 10:20:48 +04:00
|
|
|
{
|
|
|
|
struct tps6586x_platform_data *pdata;
|
|
|
|
struct tps6586x_gpio *tps6586x_gpio;
|
|
|
|
|
|
|
|
pdata = dev_get_platdata(pdev->dev.parent);
|
|
|
|
tps6586x_gpio = devm_kzalloc(&pdev->dev,
|
|
|
|
sizeof(*tps6586x_gpio), GFP_KERNEL);
|
2014-04-29 12:44:48 +04:00
|
|
|
if (!tps6586x_gpio)
|
2012-07-18 10:20:48 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
tps6586x_gpio->parent = pdev->dev.parent;
|
|
|
|
|
|
|
|
tps6586x_gpio->gpio_chip.owner = THIS_MODULE;
|
|
|
|
tps6586x_gpio->gpio_chip.label = pdev->name;
|
2015-11-04 11:56:26 +03:00
|
|
|
tps6586x_gpio->gpio_chip.parent = &pdev->dev;
|
2012-07-18 10:20:48 +04:00
|
|
|
tps6586x_gpio->gpio_chip.ngpio = 4;
|
2013-12-04 17:42:46 +04:00
|
|
|
tps6586x_gpio->gpio_chip.can_sleep = true;
|
2012-07-18 10:20:48 +04:00
|
|
|
|
|
|
|
/* FIXME: add handling of GPIOs as dedicated inputs */
|
|
|
|
tps6586x_gpio->gpio_chip.direction_output = tps6586x_gpio_output;
|
|
|
|
tps6586x_gpio->gpio_chip.set = tps6586x_gpio_set;
|
|
|
|
tps6586x_gpio->gpio_chip.get = tps6586x_gpio_get;
|
2012-11-13 17:48:07 +04:00
|
|
|
tps6586x_gpio->gpio_chip.to_irq = tps6586x_gpio_to_irq;
|
2012-07-18 10:20:48 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_OF_GPIO
|
|
|
|
tps6586x_gpio->gpio_chip.of_node = pdev->dev.parent->of_node;
|
|
|
|
#endif
|
|
|
|
if (pdata && pdata->gpio_base)
|
|
|
|
tps6586x_gpio->gpio_chip.base = pdata->gpio_base;
|
|
|
|
else
|
|
|
|
tps6586x_gpio->gpio_chip.base = -1;
|
|
|
|
|
2021-05-15 10:52:33 +03:00
|
|
|
return devm_gpiochip_add_data(&pdev->dev, &tps6586x_gpio->gpio_chip,
|
|
|
|
tps6586x_gpio);
|
2012-07-18 10:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver tps6586x_gpio_driver = {
|
|
|
|
.driver.name = "tps6586x-gpio",
|
|
|
|
.probe = tps6586x_gpio_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init tps6586x_gpio_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&tps6586x_gpio_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(tps6586x_gpio_init);
|