From patchwork Tue Dec 3 12:31:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 180722 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1437746ile; Tue, 3 Dec 2019 04:31:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyIuqFL+PBL43KpN/kIH0dwH837LRIpGvJW6Eg+e6/rG4ueH698k0XN+a4cnKM+VgZfW/SD X-Received: by 2002:a17:902:7c04:: with SMTP id x4mr4770323pll.0.1575376312177; Tue, 03 Dec 2019 04:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575376312; cv=none; d=google.com; s=arc-20160816; b=DsesrAh9IBgYPkNIvPb0aSFwdLNHSTn4vpPc4dQ/lZOv7dQfL/U7ULKYO8zx8oT9Dm b0WJk/h/jxxVsvd8IPkevHN0TT2Spg8pb1c6UT0BhKrW4h0c/R2mUw9undFEfq5tr1Dc PU4J8pxZDb3SNLw1OZhTL/sxUO/hg3Em7FG2C3HzTn4vwh2j5jKOAsHj+V5vpU36k+1L 81MxVz+LlL2emYh3C3khtEmBdYMBaSggKpXcpT9I+TscyUo+QLQqHZj1gs0w9sTHAi4U XUFl88E3by3a0XKwCmDZmbGrKlOXA+aaNU7lL1zAAgg+AHvmjk4GZySziKaAnxmy5aMI 0Hew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :delivered-to; bh=i5Z+AVO7r4QH52TjL9VLhwINQ5ixBlyyyfffglL5Fr8=; b=qx+6l3958sU+ve0nteLxHzJ4wuhTRhXfIx0K60pVTkkOHC8H43HqZIAZnaJem29bBo xb2znCs/uiG578S3Lg0mgX0QPokPSMuDJwqsqPpv0BpxFNhOL6pqL4LqHu47XICRzzRs XSjfPpbso42oZe4b0r8qZZs5/vxBMuZrIzeCEnuixoYCwW7KtyGPWd+2T2n7Psqbfr8t 3gaobbEaHk2VKWeocjb/GNC2MhKfhfSY+1cNzHmc0tgvzmNRcBAsBU/gxzJJmx+FWt6K 4chGhyVjMI0KAsehL+rcuDfvtRqQsBs24V5na/n8FY0CxcX1fYE/elM70cRywDT7yLQ7 +bHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id 3si2036596pjj.28.2019.12.03.04.31.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2019 04:31:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0F66C6E492; Tue, 3 Dec 2019 12:31:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 866126E492 for ; Tue, 3 Dec 2019 12:31:48 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id e28so3562276ljo.9 for ; Tue, 03 Dec 2019 04:31:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ldBzZ1Hnv4Md6ugdhkJ4EQVLrMXepuHxee3+zE9wgo8=; b=FvyhBpKiTaQrnclx/vE1Jbf+RJQiwYVXyxWiQlEVKlgN/+L70yQ62DiV7bMcyFixdk U6aEf+6sv0arGPTc8idSanv5dUxRhocUWdmTFAdDM2eaDqgQ+3UmI8qBCzzr6Ls6r4km VaXwBpGFM94O8g2JJHKCwD+DKKcIzFh4v4KnurgQXl6gYlxvmydJoyOHiZ5ACL3WDDkQ 2/q2PYEclGfL/wXMRKYK3O2eB533jgl8MUKt4FqFM2bAUiESWnaNuahy38wEoF90XVMe nCLZpelz79qPgRkfOXBmcDzE+dWZAHnq1HvQM+vEJPsCN4j33GkrmqZyH9VyHrn/j2Ai U6xw== X-Gm-Message-State: APjAAAXnsEYLKBGy3wWJhAcZfm7ODuo3phtvTY7Zrhn5eERj7IcPLLW9 LrmNiMGPl7AlHrQF0QDrthJDEQ== X-Received: by 2002:a2e:98c4:: with SMTP id s4mr2472681ljj.102.1575376306550; Tue, 03 Dec 2019 04:31:46 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id h24sm1252617ljl.80.2019.12.03.04.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 04:31:45 -0800 (PST) From: Linus Walleij To: Lee Jones , Daniel Thompson , Jingoo Han , dri-devel@lists.freedesktop.org Subject: [PATCH] backlight: corgi: Convert to use GPIO descriptors Date: Tue, 3 Dec 2019 13:31:43 +0100 Message-Id: <20191203123143.118487-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ldBzZ1Hnv4Md6ugdhkJ4EQVLrMXepuHxee3+zE9wgo8=; b=qUh+JQO9W79q51CQ+pqfAWXX0ZhIwLtd78XjBU8vK/FqzbqBmts+LdJRLcJVdaJ/UV Qw97ogN/VCJH/T+iANzuQFvc4J+wA7TxOfBQPFk09KRaWbnq3tx+zH+t9omiWrh2sluN CkuUWZsLRKbMjoty6AdAY9z2cRMziWC/JOm5deF4mVCfHf4t+10+gJdYPvP+pz6Uvab4 DdaPdgOCJrJLVFY4EiHEfC7MCSUGki8Hz16T1Rw6H2mwpEE0LkHlskCTVmgjZeVLxqoR aX1Ue5Ivz6wYrse926T4o5rKd0p8DEadAv7r+mHRC8y/Cy6QztriUNrgv5GGHVv+QDKI sQiw== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Robert Jarzmik , Andrea Adami Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The code in the Corgi backlight driver can be considerably simplified by moving to GPIO descriptors and lookup tables from the board files instead of passing GPIO numbers using the old API. Make sure to encode inversion semantics for the Akita and Spitz platforms inside the GPIO lookup table and drop the custom inversion semantics from the driver. All in-tree users are converted in this patch. Cc: Andrea Adami Cc: Robert Jarzmik Signed-off-by: Linus Walleij Reviewed-by: Daniel Thompson Acked-by: Robert Jarzmik --- arch/arm/mach-pxa/corgi.c | 12 ++++- arch/arm/mach-pxa/spitz.c | 34 +++++++++++---- drivers/video/backlight/corgi_lcd.c | 68 ++++++++--------------------- include/linux/spi/corgi_lcd.h | 3 -- 4 files changed, 54 insertions(+), 63 deletions(-) diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c index f2d73289230f..c9625dcae27c 100644 --- a/arch/arm/mach-pxa/corgi.c +++ b/arch/arm/mach-pxa/corgi.c @@ -563,13 +563,20 @@ static void corgi_bl_kick_battery(void) } } +static struct gpiod_lookup_table corgi_lcdcon_gpio_table = { + .dev_id = "spi0.1", + .table = { + GPIO_LOOKUP("gpio-pxa", CORGI_GPIO_BACKLIGHT_CONT, + "BL_CONT", GPIO_ACTIVE_HIGH), + { }, + }, +}; + static struct corgi_lcd_platform_data corgi_lcdcon_info = { .init_mode = CORGI_LCD_MODE_VGA, .max_intensity = 0x2f, .default_intensity = 0x1f, .limit_mask = 0x0b, - .gpio_backlight_cont = CORGI_GPIO_BACKLIGHT_CONT, - .gpio_backlight_on = -1, .kick_battery = corgi_bl_kick_battery, }; @@ -609,6 +616,7 @@ static struct spi_board_info corgi_spi_devices[] = { static void __init corgi_init_spi(void) { pxa2xx_set_spi_info(1, &corgi_spi_info); + gpiod_add_lookup_table(&corgi_lcdcon_gpio_table); spi_register_board_info(ARRAY_AND_SIZE(corgi_spi_devices)); } #else diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index a4fdc399d152..82e80a257c0f 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c @@ -525,13 +525,33 @@ static void spitz_bl_kick_battery(void) } } +static struct gpiod_lookup_table spitz_lcdcon_gpio_table = { + .dev_id = "spi0.1", + .table = { + GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_CONT, + "BL_CONT", GPIO_ACTIVE_LOW), + GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_ON, + "BL_ON", GPIO_ACTIVE_HIGH), + { }, + }, +}; + +static struct gpiod_lookup_table akita_lcdcon_gpio_table = { + .dev_id = "spi0.1", + .table = { + GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_CONT, + "BL_CONT", GPIO_ACTIVE_LOW), + GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_ON, + "BL_ON", GPIO_ACTIVE_HIGH), + { }, + }, +}; + static struct corgi_lcd_platform_data spitz_lcdcon_info = { .init_mode = CORGI_LCD_MODE_VGA, .max_intensity = 0x2f, .default_intensity = 0x1f, .limit_mask = 0x0b, - .gpio_backlight_cont = SPITZ_GPIO_BACKLIGHT_CONT, - .gpio_backlight_on = SPITZ_GPIO_BACKLIGHT_ON, .kick_battery = spitz_bl_kick_battery, }; @@ -574,12 +594,10 @@ static struct pxa2xx_spi_controller spitz_spi_info = { static void __init spitz_spi_init(void) { - struct corgi_lcd_platform_data *lcd_data = &spitz_lcdcon_info; - - if (machine_is_akita()) { - lcd_data->gpio_backlight_cont = AKITA_GPIO_BACKLIGHT_CONT; - lcd_data->gpio_backlight_on = AKITA_GPIO_BACKLIGHT_ON; - } + if (machine_is_akita()) + gpiod_add_lookup_table(&akita_lcdcon_gpio_table); + else + gpiod_add_lookup_table(&spitz_lcdcon_gpio_table); pxa2xx_set_spi_info(2, &spitz_spi_info); spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices)); diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c index 68f7592c5060..25ef0cbd7583 100644 --- a/drivers/video/backlight/corgi_lcd.c +++ b/drivers/video/backlight/corgi_lcd.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -90,9 +90,8 @@ struct corgi_lcd { int mode; char buf[2]; - int gpio_backlight_on; - int gpio_backlight_cont; - int gpio_backlight_cont_inverted; + struct gpio_desc *backlight_on; + struct gpio_desc *backlight_cont; void (*kick_battery)(void); }; @@ -403,13 +402,13 @@ static int corgi_bl_set_intensity(struct corgi_lcd *lcd, int intensity) corgi_ssp_lcdtg_send(lcd, DUTYCTRL_ADRS, intensity); /* Bit 5 via GPIO_BACKLIGHT_CONT */ - cont = !!(intensity & 0x20) ^ lcd->gpio_backlight_cont_inverted; + cont = !!(intensity & 0x20); - if (gpio_is_valid(lcd->gpio_backlight_cont)) - gpio_set_value_cansleep(lcd->gpio_backlight_cont, cont); + if (lcd->backlight_cont) + gpiod_set_value_cansleep(lcd->backlight_cont, cont); - if (gpio_is_valid(lcd->gpio_backlight_on)) - gpio_set_value_cansleep(lcd->gpio_backlight_on, intensity); + if (lcd->backlight_on) + gpiod_set_value_cansleep(lcd->backlight_on, intensity); if (lcd->kick_battery) lcd->kick_battery(); @@ -482,48 +481,17 @@ static int setup_gpio_backlight(struct corgi_lcd *lcd, struct corgi_lcd_platform_data *pdata) { struct spi_device *spi = lcd->spi_dev; - int err; - - lcd->gpio_backlight_on = -1; - lcd->gpio_backlight_cont = -1; - - if (gpio_is_valid(pdata->gpio_backlight_on)) { - err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_on, - "BL_ON"); - if (err) { - dev_err(&spi->dev, - "failed to request GPIO%d for backlight_on\n", - pdata->gpio_backlight_on); - return err; - } - - lcd->gpio_backlight_on = pdata->gpio_backlight_on; - gpio_direction_output(lcd->gpio_backlight_on, 0); - } - if (gpio_is_valid(pdata->gpio_backlight_cont)) { - err = devm_gpio_request(&spi->dev, pdata->gpio_backlight_cont, - "BL_CONT"); - if (err) { - dev_err(&spi->dev, - "failed to request GPIO%d for backlight_cont\n", - pdata->gpio_backlight_cont); - return err; - } - - lcd->gpio_backlight_cont = pdata->gpio_backlight_cont; - - /* spitz and akita use both GPIOs for backlight, and - * have inverted polarity of GPIO_BACKLIGHT_CONT - */ - if (gpio_is_valid(lcd->gpio_backlight_on)) { - lcd->gpio_backlight_cont_inverted = 1; - gpio_direction_output(lcd->gpio_backlight_cont, 1); - } else { - lcd->gpio_backlight_cont_inverted = 0; - gpio_direction_output(lcd->gpio_backlight_cont, 0); - } - } + lcd->backlight_on = devm_gpiod_get_optional(&spi->dev, + "BL_ON", GPIOD_OUT_LOW); + if (IS_ERR(lcd->backlight_on)) + return PTR_ERR(lcd->backlight_on); + + lcd->backlight_cont = devm_gpiod_get_optional(&spi->dev, "BL_CONT", + GPIOD_OUT_LOW); + if (IS_ERR(lcd->backlight_cont)) + return PTR_ERR(lcd->backlight_cont); + return 0; } diff --git a/include/linux/spi/corgi_lcd.h b/include/linux/spi/corgi_lcd.h index edf4beccdadb..0b857616919c 100644 --- a/include/linux/spi/corgi_lcd.h +++ b/include/linux/spi/corgi_lcd.h @@ -11,9 +11,6 @@ struct corgi_lcd_platform_data { int default_intensity; int limit_mask; - int gpio_backlight_on; /* -1 if n/a */ - int gpio_backlight_cont; /* -1 if n/a */ - void (*notify)(int intensity); void (*kick_battery)(void); };