diff options
Diffstat (limited to 'drivers/gpio/gpio-da9055.c')
| -rw-r--r-- | drivers/gpio/gpio-da9055.c | 67 |
1 files changed, 16 insertions, 51 deletions
diff --git a/drivers/gpio/gpio-da9055.c b/drivers/gpio/gpio-da9055.c index fd6dfe382f13..a09bd6eb93cf 100644 --- a/drivers/gpio/gpio-da9055.c +++ b/drivers/gpio/gpio-da9055.c @@ -1,19 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * GPIO Driver for Dialog DA9055 PMICs. * * Copyright(c) 2012 Dialog Semiconductor Ltd. * * Author: David Dajun Chen <dchen@diasemi.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * */ #include <linux/module.h> #include <linux/platform_device.h> -#include <linux/gpio.h> +#include <linux/gpio/driver.h> #include <linux/mfd/da9055/core.h> #include <linux/mfd/da9055/reg.h> @@ -35,14 +30,9 @@ struct da9055_gpio { struct gpio_chip gp; }; -static inline struct da9055_gpio *to_da9055_gpio(struct gpio_chip *chip) -{ - return container_of(chip, struct da9055_gpio, gp); -} - static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) { - struct da9055_gpio *gpio = to_da9055_gpio(gc); + struct da9055_gpio *gpio = gpiochip_get_data(gc); int gpio_direction = 0; int ret; @@ -69,19 +59,17 @@ static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) } -static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value) +static int da9055_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) { - struct da9055_gpio *gpio = to_da9055_gpio(gc); + struct da9055_gpio *gpio = gpiochip_get_data(gc); - da9055_reg_update(gpio->da9055, - DA9055_REG_GPIO_MODE0_2, - 1 << offset, - value << offset); + return da9055_reg_update(gpio->da9055, DA9055_REG_GPIO_MODE0_2, + 1 << offset, value << offset); } static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { - struct da9055_gpio *gpio = to_da9055_gpio(gc); + struct da9055_gpio *gpio = gpiochip_get_data(gc); unsigned char reg_byte; reg_byte = (DA9055_ACT_LOW | DA9055_GPI) @@ -97,7 +85,7 @@ static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) static int da9055_gpio_direction_output(struct gpio_chip *gc, unsigned offset, int value) { - struct da9055_gpio *gpio = to_da9055_gpio(gc); + struct da9055_gpio *gpio = gpiochip_get_data(gc); unsigned char reg_byte; int ret; @@ -112,21 +100,19 @@ static int da9055_gpio_direction_output(struct gpio_chip *gc, if (ret < 0) return ret; - da9055_gpio_set(gc, offset, value); - - return 0; + return da9055_gpio_set(gc, offset, value); } static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset) { - struct da9055_gpio *gpio = to_da9055_gpio(gc); + struct da9055_gpio *gpio = gpiochip_get_data(gc); struct da9055 *da9055 = gpio->da9055; return regmap_irq_get_virq(da9055->irq_data, DA9055_IRQ_GPI0 + offset); } -static struct gpio_chip reference_gp = { +static const struct gpio_chip reference_gp = { .label = "da9055-gpio", .owner = THIS_MODULE, .get = da9055_gpio_get, @@ -134,7 +120,7 @@ static struct gpio_chip reference_gp = { .direction_input = da9055_gpio_direction_input, .direction_output = da9055_gpio_direction_output, .to_irq = da9055_gpio_to_irq, - .can_sleep = 1, + .can_sleep = true, .ngpio = 3, .base = -1, }; @@ -143,46 +129,25 @@ static int da9055_gpio_probe(struct platform_device *pdev) { struct da9055_gpio *gpio; struct da9055_pdata *pdata; - int ret; gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); - if (gpio == NULL) + if (!gpio) return -ENOMEM; gpio->da9055 = dev_get_drvdata(pdev->dev.parent); - pdata = gpio->da9055->dev->platform_data; + pdata = dev_get_platdata(gpio->da9055->dev); gpio->gp = reference_gp; if (pdata && pdata->gpio_base) gpio->gp.base = pdata->gpio_base; - ret = gpiochip_add(&gpio->gp); - if (ret < 0) { - dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); - goto err_mem; - } - - platform_set_drvdata(pdev, gpio); - - return 0; - -err_mem: - return ret; -} - -static int da9055_gpio_remove(struct platform_device *pdev) -{ - struct da9055_gpio *gpio = platform_get_drvdata(pdev); - - return gpiochip_remove(&gpio->gp); + return devm_gpiochip_add_data(&pdev->dev, &gpio->gp, gpio); } static struct platform_driver da9055_gpio_driver = { .probe = da9055_gpio_probe, - .remove = da9055_gpio_remove, .driver = { .name = "da9055-gpio", - .owner = THIS_MODULE, }, }; |
