Skip to content

Commit 7d84a63

Browse files
andy-shevlag-linaro
authored andcommitted
backlight: hx8357: Convert to agnostic GPIO API
The of_gpio.h is going to be removed. In preparation of that convert the driver to the agnostic API. Fixes: fbbbcd1 ("gpiolib: of: add quirk for locating reset lines with legacy bindings") Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 769ff52 commit 7d84a63

File tree

2 files changed

+24
-54
lines changed

2 files changed

+24
-54
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
184184
const char *propname;
185185
bool active_high;
186186
} gpios[] = {
187-
#if !IS_ENABLED(CONFIG_LCD_HX8357)
187+
#if IS_ENABLED(CONFIG_LCD_HX8357)
188188
/*
189189
* Himax LCD controllers used incorrectly named
190190
* "gpios-reset" property and also specified wrong
@@ -478,7 +478,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
478478
*/
479479
const char *compatible;
480480
} gpios[] = {
481-
#if !IS_ENABLED(CONFIG_LCD_HX8357)
481+
#if IS_ENABLED(CONFIG_LCD_HX8357)
482482
/* Himax LCD controllers used "gpios-reset" */
483483
{ "reset", "gpios-reset", "himax,hx8357" },
484484
{ "reset", "gpios-reset", "himax,hx8369" },

drivers/video/backlight/hx8357.c

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
*/
77

88
#include <linux/delay.h>
9+
#include <linux/gpio/consumer.h>
910
#include <linux/lcd.h>
1011
#include <linux/module.h>
1112
#include <linux/of.h>
1213
#include <linux/of_device.h>
13-
#include <linux/of_gpio.h>
1414
#include <linux/spi/spi.h>
1515

1616
#define HX8357_NUM_IM_PINS 3
@@ -83,11 +83,10 @@
8383
#define HX8369_SET_GAMMA_CURVE_RELATED 0xe0
8484

8585
struct hx8357_data {
86-
unsigned im_pins[HX8357_NUM_IM_PINS];
87-
unsigned reset;
86+
struct gpio_descs *im_pins;
87+
struct gpio_desc *reset;
8888
struct spi_device *spi;
8989
int state;
90-
bool use_im_pins;
9190
};
9291

9392
static u8 hx8357_seq_power[] = {
@@ -321,11 +320,11 @@ static void hx8357_lcd_reset(struct lcd_device *lcdev)
321320
struct hx8357_data *lcd = lcd_get_data(lcdev);
322321

323322
/* Reset the screen */
324-
gpio_set_value(lcd->reset, 1);
323+
gpiod_set_value(lcd->reset, 0);
325324
usleep_range(10000, 12000);
326-
gpio_set_value(lcd->reset, 0);
325+
gpiod_set_value(lcd->reset, 1);
327326
usleep_range(10000, 12000);
328-
gpio_set_value(lcd->reset, 1);
327+
gpiod_set_value(lcd->reset, 0);
329328

330329
/* The controller needs 120ms to recover from reset */
331330
msleep(120);
@@ -340,10 +339,10 @@ static int hx8357_lcd_init(struct lcd_device *lcdev)
340339
* Set the interface selection pins to SPI mode, with three
341340
* wires
342341
*/
343-
if (lcd->use_im_pins) {
344-
gpio_set_value_cansleep(lcd->im_pins[0], 1);
345-
gpio_set_value_cansleep(lcd->im_pins[1], 0);
346-
gpio_set_value_cansleep(lcd->im_pins[2], 1);
342+
if (lcd->im_pins) {
343+
gpiod_set_value_cansleep(lcd->im_pins->desc[0], 1);
344+
gpiod_set_value_cansleep(lcd->im_pins->desc[1], 0);
345+
gpiod_set_value_cansleep(lcd->im_pins->desc[2], 1);
347346
}
348347

349348
ret = hx8357_spi_write_array(lcdev, hx8357_seq_power,
@@ -580,6 +579,7 @@ MODULE_DEVICE_TABLE(of, hx8357_dt_ids);
580579

581580
static int hx8357_probe(struct spi_device *spi)
582581
{
582+
struct device *dev = &spi->dev;
583583
struct lcd_device *lcdev;
584584
struct hx8357_data *lcd;
585585
const struct of_device_id *match;
@@ -601,49 +601,19 @@ static int hx8357_probe(struct spi_device *spi)
601601
if (!match || !match->data)
602602
return -EINVAL;
603603

604-
lcd->reset = of_get_named_gpio(spi->dev.of_node, "gpios-reset", 0);
605-
if (!gpio_is_valid(lcd->reset)) {
606-
dev_err(&spi->dev, "Missing dt property: gpios-reset\n");
607-
return -EINVAL;
608-
}
604+
lcd->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
605+
if (IS_ERR(lcd->reset))
606+
return dev_err_probe(dev, PTR_ERR(lcd->reset), "failed to request reset GPIO\n");
607+
gpiod_set_consumer_name(lcd->reset, "hx8357-reset");
609608

610-
ret = devm_gpio_request_one(&spi->dev, lcd->reset,
611-
GPIOF_OUT_INIT_HIGH,
612-
"hx8357-reset");
613-
if (ret) {
614-
dev_err(&spi->dev,
615-
"failed to request gpio %d: %d\n",
616-
lcd->reset, ret);
617-
return -EINVAL;
618-
}
609+
lcd->im_pins = devm_gpiod_get_array_optional(dev, "im", GPIOD_OUT_LOW);
610+
if (IS_ERR(lcd->im_pins))
611+
return dev_err_probe(dev, PTR_ERR(lcd->im_pins), "failed to request im GPIOs\n");
612+
if (lcd->im_pins->ndescs < HX8357_NUM_IM_PINS)
613+
return dev_err_probe(dev, -EINVAL, "not enough im GPIOs\n");
619614

620-
if (of_property_present(spi->dev.of_node, "im-gpios")) {
621-
lcd->use_im_pins = 1;
622-
623-
for (i = 0; i < HX8357_NUM_IM_PINS; i++) {
624-
lcd->im_pins[i] = of_get_named_gpio(spi->dev.of_node,
625-
"im-gpios", i);
626-
if (lcd->im_pins[i] == -EPROBE_DEFER) {
627-
dev_info(&spi->dev, "GPIO requested is not here yet, deferring the probe\n");
628-
return -EPROBE_DEFER;
629-
}
630-
if (!gpio_is_valid(lcd->im_pins[i])) {
631-
dev_err(&spi->dev, "Missing dt property: im-gpios\n");
632-
return -EINVAL;
633-
}
634-
635-
ret = devm_gpio_request_one(&spi->dev, lcd->im_pins[i],
636-
GPIOF_OUT_INIT_LOW,
637-
"im_pins");
638-
if (ret) {
639-
dev_err(&spi->dev, "failed to request gpio %d: %d\n",
640-
lcd->im_pins[i], ret);
641-
return -EINVAL;
642-
}
643-
}
644-
} else {
645-
lcd->use_im_pins = 0;
646-
}
615+
for (i = 0; i < HX8357_NUM_IM_PINS; i++)
616+
gpiod_set_consumer_name(lcd->im_pins->desc[i], "im_pins");
647617

648618
lcdev = devm_lcd_device_register(&spi->dev, "mxsfb", &spi->dev, lcd,
649619
&hx8357_ops);

0 commit comments

Comments
 (0)