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: 13123550 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3060DC636D4 for ; Tue, 31 Jan 2023 22:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232041AbjAaW5Y (ORCPT ); Tue, 31 Jan 2023 17:57:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232108AbjAaW5P (ORCPT ); Tue, 31 Jan 2023 17:57:15 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC4093C30; Tue, 31 Jan 2023 14:57:13 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id n20-20020a17090aab9400b00229ca6a4636so212608pjq.0; 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=YZaBqUAfVFTjdEm2we7w+MW/aUVlebj1NXAHHn2edVToPjWV0g/vRUczpGw6LsnZrP Q3CyJv33bnGKkgzNFs8u0pCgQW8RGd68vFIXPRBh8qvyenkaGJWFGVfwrKPD9gqEpDvt 9voLA2v8Da/huRJxUTDLTqvcNVniCnR3428OJnUNqieL315FOVPnZ14mmDAEQaHrYW+A RR921e6PPbUHosuOkUWHCQ037GhuSv2JlH3+CVNHF+8i6OynsqxMuygRLAKxalk6E2FD EsqHUGMWfsYg6J+iBiSgT4zuG/l5g494qlB2Nm+NuG6LxkR5cQXRFErr0YSoon23X0ep QCEg== X-Gm-Message-State: AO0yUKWG72XBU12St/hDtj948P5pmOQeYvXELD2Sh6knqicf1aAWTDIu JayxC6phC/3dHh+nqUY6vbY= 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 Cc: Helge Deller , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org 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 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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: 13123551 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2248FC38142 for ; Tue, 31 Jan 2023 22:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231859AbjAaW5Y (ORCPT ); Tue, 31 Jan 2023 17:57:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232115AbjAaW5Q (ORCPT ); Tue, 31 Jan 2023 17:57:16 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2ECA410AE; Tue, 31 Jan 2023 14:57:15 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id 5so16666849plo.3; 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=KCWvAg6lVeBCu+rO8Hzry20IZ40vAGuObSkEGTU6lzFUHQIOFlFbxN6sBH3O6nmuKu rW3so0wYBJ1+zWmcTueOc8ydDfHbAGk4R4m78Efhb+R6YK5GqtMGN8yFKlwMVwsU2nh7 pxJJ3F/P7TK2g7ZOs+7ed49jpQxOeZm+kRtseAMKD68QuI/RaLGrTfuszUhWGDDDbEpu aCEGHZf1sz/pNreGtiyS2iHkpn2+Ng5M80Q1mAjJpED9Xe2x8H1fZMh+mHtiqe6fR6+o NJkbMxbkOggRPdbownEopCdLpfYkAfoSKzJnFdCWh5YLzH2CFmjB8YzDvsHrmfkjdkKb 1gcw== X-Gm-Message-State: AO0yUKX6yfwzB33i+s829htob6LhUcECkOKZoBEELP5Kg6GAwp6rN4wL zze2humOWHtRVrkL72a+sEQ= 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 Cc: Helge Deller , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org 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 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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;