Skip to content

Commit 61365ca

Browse files
linuswLee Jones
authored andcommitted
backlight: l4f00242t03: Convert to GPIO descriptors
This converts the l4f00242t03 backlight driver to use GPIO descriptors and switches the two Freescale i.MX boards over to passing descriptors instead of global GPIO numbers. We use the typical names "enable" and "reset" as found in the device tree bindings for panel GPIOs. This saves a lot of code in the driver and makes it possible to get rid of the platform data header altogether. Signed-off-by: Linus Walleij <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Acked-by: Shawn Guo <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent d8207c1 commit 61365ca

File tree

4 files changed

+52
-55
lines changed

4 files changed

+52
-55
lines changed

arch/arm/mach-imx/mach-mx27_3ds.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414
#include <linux/platform_device.h>
1515
#include <linux/gpio.h>
16+
#include <linux/gpio/machine.h>
1617
#include <linux/irq.h>
1718
#include <linux/usb/otg.h>
1819
#include <linux/usb/ulpi.h>
1920
#include <linux/delay.h>
2021
#include <linux/mfd/mc13783.h>
2122
#include <linux/spi/spi.h>
2223
#include <linux/regulator/machine.h>
23-
#include <linux/spi/l4f00242t03.h>
24-
2524

2625
#include <asm/mach-types.h>
2726
#include <asm/mach/arch.h>
@@ -351,9 +350,19 @@ static const struct imx_fb_platform_data mx27_3ds_fb_data __initconst = {
351350
};
352351

353352
/* LCD */
354-
static struct l4f00242t03_pdata mx27_3ds_lcd_pdata = {
355-
.reset_gpio = LCD_RESET,
356-
.data_enable_gpio = LCD_ENABLE,
353+
static struct gpiod_lookup_table mx27_3ds_lcd_gpiod_table = {
354+
.dev_id = "spi0.0", /* Bus 0 chipselect 0 */
355+
.table = {
356+
/*
357+
* The i.MX27 has the i.MX21 GPIO controller, the GPIOs
358+
* numbered IMX_GPIO_NR(1, 3) and IMX_GPIO_NR(1, 31)
359+
* are in "bank 1" which is subtracted by one in the macro
360+
* so these are actually bank 0 on "imx21-gpio.0".
361+
*/
362+
GPIO_LOOKUP("imx21-gpio.0", 3, "reset", GPIO_ACTIVE_HIGH),
363+
GPIO_LOOKUP("imx21-gpio.0", 31, "enable", GPIO_ACTIVE_HIGH),
364+
{ },
365+
},
357366
};
358367

359368
static struct spi_board_info mx27_3ds_spi_devs[] __initdata = {
@@ -370,7 +379,6 @@ static struct spi_board_info mx27_3ds_spi_devs[] __initdata = {
370379
.max_speed_hz = 5000000,
371380
.bus_num = 0,
372381
.chip_select = 0, /* SS0 */
373-
.platform_data = &mx27_3ds_lcd_pdata,
374382
},
375383
};
376384

@@ -416,6 +424,7 @@ static void __init mx27pdk_late_init(void)
416424
if (!otg_mode_host)
417425
imx27_add_fsl_usb2_udc(&otg_device_pdata);
418426

427+
gpiod_add_lookup_table(&mx27_3ds_lcd_gpiod_table);
419428
mx27_3ds_spi_devs[0].irq = gpio_to_irq(PMIC_INT);
420429
spi_register_board_info(mx27_3ds_spi_devs,
421430
ARRAY_SIZE(mx27_3ds_spi_devs));

arch/arm/mach-imx/mach-mx31_3ds.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#include <linux/clk.h>
1111
#include <linux/irq.h>
1212
#include <linux/gpio.h>
13+
#include <linux/gpio/machine.h>
1314
#include <linux/platform_device.h>
1415
#include <linux/mfd/mc13783.h>
1516
#include <linux/spi/spi.h>
16-
#include <linux/spi/l4f00242t03.h>
1717
#include <linux/regulator/machine.h>
1818
#include <linux/usb/otg.h>
1919
#include <linux/usb/ulpi.h>
@@ -160,9 +160,23 @@ static struct mx3fb_platform_data mx3fb_pdata __initdata = {
160160
};
161161

162162
/* LCD */
163-
static struct l4f00242t03_pdata mx31_3ds_l4f00242t03_pdata = {
164-
.reset_gpio = IOMUX_TO_GPIO(MX31_PIN_LCS1),
165-
.data_enable_gpio = IOMUX_TO_GPIO(MX31_PIN_SER_RS),
163+
static struct gpiod_lookup_table mx31_3ds_lcd_gpiod_table = {
164+
.dev_id = "spi0.2", /* Bus 0 chipselect 2 */
165+
.table = {
166+
/*
167+
* "reset" has IOMUX_TO_GPIO(IOMUX_PIN(88, 28)).
168+
* The macro only shifts 88 to bits 9..16 and then
169+
* mask it and shift it back. The GPIO number is 88.
170+
* 88 is 2*32+24
171+
*/
172+
GPIO_LOOKUP("imx31-gpio.2", 24, "reset", GPIO_ACTIVE_HIGH),
173+
/*
174+
* Same reasoning as above for
175+
* IOMUX_TO_GPIO(IOMUX_PIN(89, 27), pin 89 is 2*32+25.
176+
*/
177+
GPIO_LOOKUP("imx31-gpio.2", 25, "enable", GPIO_ACTIVE_HIGH),
178+
{ },
179+
},
166180
};
167181

168182
/*
@@ -387,7 +401,6 @@ static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
387401
.max_speed_hz = 5000000,
388402
.bus_num = 0,
389403
.chip_select = 2, /* SS2 */
390-
.platform_data = &mx31_3ds_l4f00242t03_pdata,
391404
},
392405
};
393406

@@ -566,6 +579,7 @@ static void __init mx31_3ds_init(void)
566579

567580
static void __init mx31_3ds_late(void)
568581
{
582+
gpiod_add_lookup_table(&mx31_3ds_lcd_gpiod_table);
569583
mx31_3ds_spi_devs[0].irq = gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO1_3));
570584
spi_register_board_info(mx31_3ds_spi_devs,
571585
ARRAY_SIZE(mx31_3ds_spi_devs));

drivers/video/backlight/l4f00242t03.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,37 @@
1414
#include <linux/kernel.h>
1515
#include <linux/delay.h>
1616
#include <linux/module.h>
17-
#include <linux/gpio.h>
17+
#include <linux/gpio/consumer.h>
1818
#include <linux/lcd.h>
1919
#include <linux/slab.h>
2020
#include <linux/regulator/consumer.h>
21-
2221
#include <linux/spi/spi.h>
23-
#include <linux/spi/l4f00242t03.h>
2422

2523
struct l4f00242t03_priv {
2624
struct spi_device *spi;
2725
struct lcd_device *ld;
2826
int lcd_state;
2927
struct regulator *io_reg;
3028
struct regulator *core_reg;
29+
struct gpio_desc *reset;
30+
struct gpio_desc *enable;
3131
};
3232

33-
static void l4f00242t03_reset(unsigned int gpio)
33+
static void l4f00242t03_reset(struct gpio_desc *gpiod)
3434
{
3535
pr_debug("l4f00242t03_reset.\n");
36-
gpio_set_value(gpio, 1);
36+
gpiod_set_value(gpiod, 1);
3737
mdelay(100);
38-
gpio_set_value(gpio, 0);
38+
gpiod_set_value(gpiod, 0);
3939
mdelay(10); /* tRES >= 100us */
40-
gpio_set_value(gpio, 1);
40+
gpiod_set_value(gpiod, 1);
4141
mdelay(20);
4242
}
4343

4444
#define param(x) ((x) | 0x100)
4545

4646
static void l4f00242t03_lcd_init(struct spi_device *spi)
4747
{
48-
struct l4f00242t03_pdata *pdata = dev_get_platdata(&spi->dev);
4948
struct l4f00242t03_priv *priv = spi_get_drvdata(spi);
5049
const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) };
5150
int ret;
@@ -76,21 +75,20 @@ static void l4f00242t03_lcd_init(struct spi_device *spi)
7675
return;
7776
}
7877

79-
l4f00242t03_reset(pdata->reset_gpio);
78+
l4f00242t03_reset(priv->reset);
8079

81-
gpio_set_value(pdata->data_enable_gpio, 1);
80+
gpiod_set_value(priv->enable, 1);
8281
msleep(60);
8382
spi_write(spi, (const u8 *)cmd, ARRAY_SIZE(cmd) * sizeof(u16));
8483
}
8584

8685
static void l4f00242t03_lcd_powerdown(struct spi_device *spi)
8786
{
88-
struct l4f00242t03_pdata *pdata = dev_get_platdata(&spi->dev);
8987
struct l4f00242t03_priv *priv = spi_get_drvdata(spi);
9088

9189
dev_dbg(&spi->dev, "Powering down LCD\n");
9290

93-
gpio_set_value(pdata->data_enable_gpio, 0);
91+
gpiod_set_value(priv->enable, 0);
9492

9593
regulator_disable(priv->io_reg);
9694
regulator_disable(priv->core_reg);
@@ -168,13 +166,6 @@ static struct lcd_ops l4f_ops = {
168166
static int l4f00242t03_probe(struct spi_device *spi)
169167
{
170168
struct l4f00242t03_priv *priv;
171-
struct l4f00242t03_pdata *pdata = dev_get_platdata(&spi->dev);
172-
int ret;
173-
174-
if (pdata == NULL) {
175-
dev_err(&spi->dev, "Uninitialized platform data.\n");
176-
return -EINVAL;
177-
}
178169

179170
priv = devm_kzalloc(&spi->dev, sizeof(struct l4f00242t03_priv),
180171
GFP_KERNEL);
@@ -187,21 +178,21 @@ static int l4f00242t03_probe(struct spi_device *spi)
187178

188179
priv->spi = spi;
189180

190-
ret = devm_gpio_request_one(&spi->dev, pdata->reset_gpio,
191-
GPIOF_OUT_INIT_HIGH, "lcd l4f00242t03 reset");
192-
if (ret) {
181+
priv->reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH);
182+
if (IS_ERR(priv->reset)) {
193183
dev_err(&spi->dev,
194184
"Unable to get the lcd l4f00242t03 reset gpio.\n");
195-
return ret;
185+
return PTR_ERR(priv->reset);
196186
}
187+
gpiod_set_consumer_name(priv->reset, "lcd l4f00242t03 reset");
197188

198-
ret = devm_gpio_request_one(&spi->dev, pdata->data_enable_gpio,
199-
GPIOF_OUT_INIT_LOW, "lcd l4f00242t03 data enable");
200-
if (ret) {
189+
priv->enable = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW);
190+
if (IS_ERR(priv->enable)) {
201191
dev_err(&spi->dev,
202192
"Unable to get the lcd l4f00242t03 data en gpio.\n");
203-
return ret;
193+
return PTR_ERR(priv->enable);
204194
}
195+
gpiod_set_consumer_name(priv->enable, "lcd l4f00242t03 data enable");
205196

206197
priv->io_reg = devm_regulator_get(&spi->dev, "vdd");
207198
if (IS_ERR(priv->io_reg)) {

include/linux/spi/l4f00242t03.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)