From patchwork Tue Jan 31 22:57:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13123552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B4D4C636CC for ; Tue, 31 Jan 2023 22:57:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF45C10E396; Tue, 31 Jan 2023 22:57:14 +0000 (UTC) Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by gabe.freedesktop.org (Postfix) with ESMTPS id C665310E396 for ; Tue, 31 Jan 2023 22:57:13 +0000 (UTC) Received: by mail-pj1-x1029.google.com with SMTP id cq16-20020a17090af99000b0022c9791ac39so155433pjb.4 for ; Tue, 31 Jan 2023 14:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kpHHAw+i1ZP/EdJYy8iLuB5fyNZHOMf4w2HHkl2VS3k=; b=aK7X6+aPOLty1cU5iJDPudo7Et/cOC8RejVJ0Z7h4CPmE3GCVqCrqoWmSWmjefY5fq ToGJYbRfEFCB7CtQTbEPIczBYoRKPvnrooecqPfLMMo8/aBTcBvIdu+DFlf7vNKaV+ZO ogA34MLPbXMnvLbh5EItV4TKxPGo/Fd93CCGjm+9tRKqJMRBYVAZx7k32GER2hkvsYRY bXGDHOe39IOugodjLDAlYfvWg00kafQgtYdeCPO8TLw4DG2SnuRP55YJOYabyIpJDmyM xc7oo+Tq/N0Q2WkNmURx0pIsIAemFzBnBDhVuyHW5ro4Aa1Z30iGidKMdtgtTZAaxaJ1 rNJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kpHHAw+i1ZP/EdJYy8iLuB5fyNZHOMf4w2HHkl2VS3k=; b=lDoAPzrQlJ5ctOa5tEa8/U+ImR9lzk2zpbyVvzkuc8XYXvoMDhpLYp6HAPr3CggKPk zjewOH0VYUxcRIEFHCFgK0dWuQQAjCpC7wqteGmn6duWoY7LYsyaevNPKYlE/xnfxXR/ hZpq2TjKC5vGo/ZeOxBIYw4Oau2G81qNyekWZ1VKQq7xfxqhYD91egOQ7hcaruuQvTXJ bRnxIjZar5K3iU+6u7jTWZu0OSuoNJmL8Kol9nv6uY+Ul7fnGA3/v51kSE1kHVUcUwIT Tx5QwtIDuQHxFzW+BL/Rjwb5dO1MUaJ56J5jM9L059F9s1KPoffNJtVFRAtYBdQprSXb A9hA== X-Gm-Message-State: AO0yUKWcAohK6WYMZyXSpKXnavBGlIWC+nqDHrRpIVxDwIoaaVX07Dg8 ZNTDHUhFiQFdNLLyQ7DwYhc= X-Google-Smtp-Source: AK7set+Ji9OBJYURmyAYP9SXKiCgfigEX/0ltPB+8ioE1R+p9GdDWYdYRNMDhDIUCGcMkMbFfgWA2w== X-Received: by 2002:a17:902:dac5:b0:195:e577:231c with SMTP id q5-20020a170902dac500b00195e577231cmr759984plx.31.1675205832830; Tue, 31 Jan 2023 14:57:12 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:effb:a74f:225a:28ef]) by smtp.gmail.com with ESMTPSA id t3-20020a170902b20300b001963bc7bdb8sm10229945plr.274.2023.01.31.14.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 14:57:12 -0800 (PST) From: Dmitry Torokhov To: Daniel Thompson , Lee Jones , Jingoo Han Subject: [PATCH 1/2] backlight: hx8357: switch to using gpiod API Date: Tue, 31 Jan 2023 14:57:06 -0800 Message-Id: <20230131225707.3599889-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Switch the driver from legacy gpio API that is deprecated to the newer gpiod API that respects line polarities described in ACPI/DT. This makes driver use standard property name for the reset gpio ("reset-gpios" vs "gpios-reset"), however there is a quirk in gpiolib to also recognize the legacy name and keep compatibility with older DTSes. Signed-off-by: Dmitry Torokhov Reviewed-by: Daniel Thompson --- All preparation gpiolib work to handle legacy names and polarity quirks has landed in mainline... drivers/video/backlight/hx8357.c | 82 ++++++++++++++------------------ 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c index 9b50bc96e00f..a93e14adb846 100644 --- a/drivers/video/backlight/hx8357.c +++ b/drivers/video/backlight/hx8357.c @@ -6,11 +6,12 @@ */ #include +#include +#include #include #include #include #include -#include #include #define HX8357_NUM_IM_PINS 3 @@ -83,8 +84,8 @@ #define HX8369_SET_GAMMA_CURVE_RELATED 0xe0 struct hx8357_data { - unsigned im_pins[HX8357_NUM_IM_PINS]; - unsigned reset; + struct gpio_desc *im_pins[HX8357_NUM_IM_PINS]; + struct gpio_desc *reset; struct spi_device *spi; int state; bool use_im_pins; @@ -321,11 +322,11 @@ static void hx8357_lcd_reset(struct lcd_device *lcdev) struct hx8357_data *lcd = lcd_get_data(lcdev); /* Reset the screen */ - gpio_set_value(lcd->reset, 1); + gpiod_set_value_cansleep(lcd->reset, 0); usleep_range(10000, 12000); - gpio_set_value(lcd->reset, 0); + gpiod_set_value_cansleep(lcd->reset, 1); usleep_range(10000, 12000); - gpio_set_value(lcd->reset, 1); + gpiod_set_value_cansleep(lcd->reset, 0); /* The controller needs 120ms to recover from reset */ msleep(120); @@ -341,9 +342,9 @@ static int hx8357_lcd_init(struct lcd_device *lcdev) * wires */ if (lcd->use_im_pins) { - gpio_set_value_cansleep(lcd->im_pins[0], 1); - gpio_set_value_cansleep(lcd->im_pins[1], 0); - gpio_set_value_cansleep(lcd->im_pins[2], 1); + gpiod_set_value_cansleep(lcd->im_pins[0], 1); + gpiod_set_value_cansleep(lcd->im_pins[1], 0); + gpiod_set_value_cansleep(lcd->im_pins[2], 1); } ret = hx8357_spi_write_array(lcdev, hx8357_seq_power, @@ -601,48 +602,39 @@ static int hx8357_probe(struct spi_device *spi) if (!match || !match->data) return -EINVAL; - lcd->reset = of_get_named_gpio(spi->dev.of_node, "gpios-reset", 0); - if (!gpio_is_valid(lcd->reset)) { - dev_err(&spi->dev, "Missing dt property: gpios-reset\n"); - return -EINVAL; - } - - ret = devm_gpio_request_one(&spi->dev, lcd->reset, - GPIOF_OUT_INIT_HIGH, - "hx8357-reset"); + lcd->reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW); + ret = PTR_ERR_OR_ZERO(lcd->reset); if (ret) { - dev_err(&spi->dev, - "failed to request gpio %d: %d\n", - lcd->reset, ret); - return -EINVAL; + dev_err(&spi->dev, "failed to request reset gpio: %d\n", ret); + return ret; } - if (of_find_property(spi->dev.of_node, "im-gpios", NULL)) { - lcd->use_im_pins = 1; - - for (i = 0; i < HX8357_NUM_IM_PINS; i++) { - lcd->im_pins[i] = of_get_named_gpio(spi->dev.of_node, - "im-gpios", i); - if (lcd->im_pins[i] == -EPROBE_DEFER) { - dev_info(&spi->dev, "GPIO requested is not here yet, deferring the probe\n"); - return -EPROBE_DEFER; - } - if (!gpio_is_valid(lcd->im_pins[i])) { - dev_err(&spi->dev, "Missing dt property: im-gpios\n"); - return -EINVAL; + gpiod_set_consumer_name(lcd->reset, "hx8357-reset"); + + for (i = 0; i < HX8357_NUM_IM_PINS; i++) { + lcd->im_pins[i] = devm_gpiod_get_index(&spi->dev, + "im", i, GPIOD_OUT_LOW); + ret = PTR_ERR_OR_ZERO(lcd->im_pins[i]); + if (ret) { + if (ret == -ENOENT) { + if (i == 0) + break; + dev_err(&spi->dev, "Missing im gpios[%d]\n", i); + ret = -EINVAL; + } if (ret == -EPROBE_DEFER) { + dev_info(&spi->dev, "im gpio[%d] is not here yet, deferring the probe\n", + i); + } else { + dev_err(&spi->dev, "failed to request im gpio[%d]: %d\n", + i, ret); } - ret = devm_gpio_request_one(&spi->dev, lcd->im_pins[i], - GPIOF_OUT_INIT_LOW, - "im_pins"); - if (ret) { - dev_err(&spi->dev, "failed to request gpio %d: %d\n", - lcd->im_pins[i], ret); - return -EINVAL; - } + return ret; } - } else { - lcd->use_im_pins = 0; + + gpiod_set_consumer_name(lcd->im_pins[i], "im_pins"); + + lcd->use_im_pins = true; } lcdev = devm_lcd_device_register(&spi->dev, "mxsfb", &spi->dev, lcd, From patchwork Tue Jan 31 22:57:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13123553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DEB63C636CC for ; Tue, 31 Jan 2023 22:57:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC0A910E39E; Tue, 31 Jan 2023 22:57:22 +0000 (UTC) Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by gabe.freedesktop.org (Postfix) with ESMTPS id C193A10E39F for ; Tue, 31 Jan 2023 22:57:15 +0000 (UTC) Received: by mail-pl1-x633.google.com with SMTP id z1so9116879plg.6 for ; Tue, 31 Jan 2023 14:57:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q69dgLqN6kO5gAwOLys8/HsP5kHBTFUQsrWWIDgTKOA=; b=WlyQM2M1BRD/grSwpqjxowafQRbiTF3h/qMkf/UVUkLbjBuEdMjv/YbDWF3nXuur7J JCEAelUYFgODW5vL5AuDv6QOf0M3DbsAD/JGdQPzHgmeE7ntQ5+7RGUhF/4zRQ90Wicq n4jHkleJL3sHGKF/VrjyrrxqRNpKig2VyaDskDKO5fLtRJYZadqIYNMS0GHYQA+dRicp LPV2tCE3RYgEdwlxXKY4TucbW1z0acQjT0v9qi9MmWqjZY0XwdhXjjErQCugoCq9+jHa WGk7K3pdwkd0bkwOntpa0dCzo5qCLmdpYm03D8NPTFlk6NF8jwS67G0IcfsSt6bajPOJ 5NtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q69dgLqN6kO5gAwOLys8/HsP5kHBTFUQsrWWIDgTKOA=; b=MDHB3UCTTG85vhiWc8P0k/sxNT8xC7IvnPlZKBf3Cu/irfmBjXEOApRFnnBhPkH32W FCBUvvC64ryRnJU6Pb+FCPuHlL7m7zcv9wBRbtymHEa7C0opxh+CGDu5IOXqS2zLbNH3 FxVPN1L8BwqHPJN5t5L7Oo2ZMem7OiIPshlH6fMiCWdh6PXI2GUXXUo9RwFE4+/7GE6w Akb+JcKC4o7Jo0excJPGMQHfCbHSQn24diFJ34hOw4Pe/HeyRx6Lih5dZUFJw9zJzGDo v5Ip2TYsJ/nDkmYPxN29CR1z6KlY2wTxYFz0gyn7JKItmx7k78EIzUDiCBbFIQIzA5Gj M2Sg== X-Gm-Message-State: AO0yUKU+RSjdbIlL7/zLsz3vlOV2YY09TIQDzyvsMU3/qzr2vAWe5Xjr tx9CgNrA1AmLe9zKW8kcDSE= X-Google-Smtp-Source: AK7set9PKo7V/pKdXXqVAGSTAu7KzGfvjB03OhbiIWYP7LFi7RALAmjSfrliCkYrGmvTRSQ1DeTDpw== X-Received: by 2002:a17:903:2053:b0:194:3cef:31 with SMTP id q19-20020a170903205300b001943cef0031mr487814pla.49.1675205835275; Tue, 31 Jan 2023 14:57:15 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:effb:a74f:225a:28ef]) by smtp.gmail.com with ESMTPSA id t3-20020a170902b20300b001963bc7bdb8sm10229945plr.274.2023.01.31.14.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 14:57:13 -0800 (PST) From: Dmitry Torokhov To: Daniel Thompson , Lee Jones , Jingoo Han Subject: [PATCH 2/2] backlight: hx8357: stop using of-specific APIs Date: Tue, 31 Jan 2023 14:57:07 -0800 Message-Id: <20230131225707.3599889-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog In-Reply-To: <20230131225707.3599889-1-dmitry.torokhov@gmail.com> References: <20230131225707.3599889-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There is no need for this driver to be OF-specific, so switch it to use device_get_match_data() and stop including various of-related headers. Signed-off-by: Dmitry Torokhov Reviewed-by: Daniel Thompson --- drivers/video/backlight/hx8357.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c index a93e14adb846..2e162a70c1ce 100644 --- a/drivers/video/backlight/hx8357.c +++ b/drivers/video/backlight/hx8357.c @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include #include #define HX8357_NUM_IM_PINS 3 @@ -581,11 +581,15 @@ MODULE_DEVICE_TABLE(of, hx8357_dt_ids); static int hx8357_probe(struct spi_device *spi) { + int (*lcd_init_fn)(struct lcd_device *); struct lcd_device *lcdev; struct hx8357_data *lcd; - const struct of_device_id *match; int i, ret; + lcd_init_fn = device_get_match_data(&spi->dev); + if (!lcd_init_fn) + return -EINVAL; + lcd = devm_kzalloc(&spi->dev, sizeof(*lcd), GFP_KERNEL); if (!lcd) return -ENOMEM; @@ -598,10 +602,6 @@ static int hx8357_probe(struct spi_device *spi) lcd->spi = spi; - match = of_match_device(hx8357_dt_ids, &spi->dev); - if (!match || !match->data) - return -EINVAL; - lcd->reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW); ret = PTR_ERR_OR_ZERO(lcd->reset); if (ret) { @@ -647,7 +647,7 @@ static int hx8357_probe(struct spi_device *spi) hx8357_lcd_reset(lcdev); - ret = ((int (*)(struct lcd_device *))match->data)(lcdev); + ret = lcd_init_fn(lcdev); if (ret) { dev_err(&spi->dev, "Couldn't initialize panel\n"); return ret;