| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* drivers/leds/leds-s3c24xx.c |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * (c) 2006 Simtec Electronics |
|---|
| .. | .. |
|---|
| 5 | 6 | * Ben Dooks <ben@simtec.co.uk> |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * S3C24XX - LEDs GPIO driver |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 11 | | - * published by the Free Software Foundation. |
|---|
| 12 | 9 | */ |
|---|
| 13 | 10 | |
|---|
| 14 | 11 | #include <linux/kernel.h> |
|---|
| 15 | 12 | #include <linux/platform_device.h> |
|---|
| 16 | 13 | #include <linux/leds.h> |
|---|
| 17 | | -#include <linux/gpio.h> |
|---|
| 14 | +#include <linux/gpio/consumer.h> |
|---|
| 18 | 15 | #include <linux/slab.h> |
|---|
| 19 | 16 | #include <linux/module.h> |
|---|
| 20 | 17 | #include <linux/platform_data/leds-s3c24xx.h> |
|---|
| 21 | | - |
|---|
| 22 | | -#include <mach/regs-gpio.h> |
|---|
| 23 | | -#include <plat/gpio-cfg.h> |
|---|
| 24 | 18 | |
|---|
| 25 | 19 | /* our context */ |
|---|
| 26 | 20 | |
|---|
| 27 | 21 | struct s3c24xx_gpio_led { |
|---|
| 28 | 22 | struct led_classdev cdev; |
|---|
| 29 | 23 | struct s3c24xx_led_platdata *pdata; |
|---|
| 24 | + struct gpio_desc *gpiod; |
|---|
| 30 | 25 | }; |
|---|
| 31 | 26 | |
|---|
| 32 | 27 | static inline struct s3c24xx_gpio_led *to_gpio(struct led_classdev *led_cdev) |
|---|
| .. | .. |
|---|
| 38 | 33 | enum led_brightness value) |
|---|
| 39 | 34 | { |
|---|
| 40 | 35 | struct s3c24xx_gpio_led *led = to_gpio(led_cdev); |
|---|
| 41 | | - struct s3c24xx_led_platdata *pd = led->pdata; |
|---|
| 42 | | - int state = (value ? 1 : 0) ^ (pd->flags & S3C24XX_LEDF_ACTLOW); |
|---|
| 43 | 36 | |
|---|
| 44 | | - /* there will be a short delay between setting the output and |
|---|
| 45 | | - * going from output to input when using tristate. */ |
|---|
| 46 | | - |
|---|
| 47 | | - gpio_set_value(pd->gpio, state); |
|---|
| 48 | | - |
|---|
| 49 | | - if (pd->flags & S3C24XX_LEDF_TRISTATE) { |
|---|
| 50 | | - if (value) |
|---|
| 51 | | - gpio_direction_output(pd->gpio, state); |
|---|
| 52 | | - else |
|---|
| 53 | | - gpio_direction_input(pd->gpio); |
|---|
| 54 | | - } |
|---|
| 37 | + gpiod_set_value(led->gpiod, !!value); |
|---|
| 55 | 38 | } |
|---|
| 56 | 39 | |
|---|
| 57 | 40 | static int s3c24xx_led_probe(struct platform_device *dev) |
|---|
| .. | .. |
|---|
| 72 | 55 | |
|---|
| 73 | 56 | led->pdata = pdata; |
|---|
| 74 | 57 | |
|---|
| 75 | | - ret = devm_gpio_request(&dev->dev, pdata->gpio, "S3C24XX_LED"); |
|---|
| 76 | | - if (ret < 0) |
|---|
| 77 | | - return ret; |
|---|
| 78 | | - |
|---|
| 79 | | - /* no point in having a pull-up if we are always driving */ |
|---|
| 80 | | - |
|---|
| 81 | | - s3c_gpio_setpull(pdata->gpio, S3C_GPIO_PULL_NONE); |
|---|
| 82 | | - |
|---|
| 83 | | - if (pdata->flags & S3C24XX_LEDF_TRISTATE) |
|---|
| 84 | | - gpio_direction_input(pdata->gpio); |
|---|
| 85 | | - else |
|---|
| 86 | | - gpio_direction_output(pdata->gpio, |
|---|
| 87 | | - pdata->flags & S3C24XX_LEDF_ACTLOW ? 1 : 0); |
|---|
| 58 | + /* Default to off */ |
|---|
| 59 | + led->gpiod = devm_gpiod_get(&dev->dev, NULL, GPIOD_OUT_LOW); |
|---|
| 60 | + if (IS_ERR(led->gpiod)) |
|---|
| 61 | + return PTR_ERR(led->gpiod); |
|---|
| 88 | 62 | |
|---|
| 89 | 63 | /* register our new led device */ |
|---|
| 90 | | - |
|---|
| 91 | 64 | ret = devm_led_classdev_register(&dev->dev, &led->cdev); |
|---|
| 92 | 65 | if (ret < 0) |
|---|
| 93 | 66 | dev_err(&dev->dev, "led_classdev_register failed\n"); |
|---|