From nobody Sat Apr 18 09:24:17 2026 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 A9A6FCCA47B for ; Thu, 14 Jul 2022 22:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241039AbiGNWMW (ORCPT ); Thu, 14 Jul 2022 18:12:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241022AbiGNWMU (ORCPT ); Thu, 14 Jul 2022 18:12:20 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1CEE70E6C; Thu, 14 Jul 2022 15:12:19 -0700 (PDT) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4LkTHl3jbhzDqmJ; Thu, 14 Jul 2022 22:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1657836739; bh=ssoi08sEhr0Lz2fizpI6XjmymvgbqQVIa2Tf3XLP/Pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p8GCSOJSf7KQ1YpC5YBsMMam2DmcDV+rYRcfKBdTV1B+NiQOZydBID06H3omfUr5l sw5fgLPWj9/JTEJABkM22UAjHX7IPBU/3ODapgsFhwDKAd0PLISIT6yY3lzgmkvTCi 7m5Nk5hBTzObCs7R1bFpJPZG+KDURD+SCQaHJDSM= X-Riseup-User-ID: CE49D1B04BF757D7B4CAE73DCFC36B2EBAFFEF4D8B795BB0DC5B5BFE06971E4C Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4LkTHg5S10z1yWZ; Thu, 14 Jul 2022 22:12:15 +0000 (UTC) From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: mchehab@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, s.nawrocki@samsung.com, andrzej.hajda@intel.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Ma=C3=ADra=20Canal?= , =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [PATCH RESEND 1/2] media: s5c73m3: Replace legacy gpio interface for gpiod Date: Thu, 14 Jul 2022 19:12:01 -0300 Message-Id: <20220714221202.86768-2-mairacanal@riseup.net> In-Reply-To: <20220714221202.86768-1-mairacanal@riseup.net> References: <20220714221202.86768-1-mairacanal@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ma=C3=ADra Canal Considering the current transition of the GPIO subsystem, remove all dependencies of the legacy GPIO interface (linux/gpio.h and linux /of_gpio.h) and replace it with the descriptor-based GPIO approach. Signed-off-by: Ma=C3=ADra Canal --- drivers/media/i2c/s5c73m3/s5c73m3-core.c | 95 ++++++++++-------------- drivers/media/i2c/s5c73m3/s5c73m3.h | 9 +-- include/media/i2c/s5c73m3.h | 15 +--- 3 files changed, 44 insertions(+), 75 deletions(-) diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s= 5c73m3/s5c73m3-core.c index e2b88c5e4f98..8af785fbf25b 100644 --- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c +++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c @@ -10,12 +10,11 @@ #include #include #include -#include +#include #include #include #include #include -#include #include #include #include @@ -1347,22 +1346,26 @@ static int s5c73m3_oif_open(struct v4l2_subdev *sd,= struct v4l2_subdev_fh *fh) return 0; } =20 -static int s5c73m3_gpio_set_value(struct s5c73m3 *priv, int id, u32 val) +static int s5c73m3_gpio_set_value(struct gpio_desc *gpio, int val) { - if (!gpio_is_valid(priv->gpio[id].gpio)) + if (!gpio) return 0; - gpio_set_value(priv->gpio[id].gpio, !!val); + gpiod_set_value(gpio, !!val); return 1; } =20 -static int s5c73m3_gpio_assert(struct s5c73m3 *priv, int id) +static int s5c73m3_gpio_assert(struct gpio_desc *gpio) { - return s5c73m3_gpio_set_value(priv, id, priv->gpio[id].level); + int val =3D gpiod_get_value(gpio); + + return s5c73m3_gpio_set_value(gpio, val); } =20 -static int s5c73m3_gpio_deassert(struct s5c73m3 *priv, int id) +static int s5c73m3_gpio_deassert(struct gpio_desc *gpio) { - return s5c73m3_gpio_set_value(priv, id, !priv->gpio[id].level); + int val =3D gpiod_get_value(gpio); + + return s5c73m3_gpio_set_value(gpio, !val); } =20 static int __s5c73m3_power_on(struct s5c73m3 *state) @@ -1386,10 +1389,10 @@ static int __s5c73m3_power_on(struct s5c73m3 *state) v4l2_dbg(1, s5c73m3_dbg, &state->oif_sd, "clock frequency: %ld\n", clk_get_rate(state->clock)); =20 - s5c73m3_gpio_deassert(state, STBY); + s5c73m3_gpio_deassert(state->gpio_stby); usleep_range(100, 200); =20 - s5c73m3_gpio_deassert(state, RSET); + s5c73m3_gpio_deassert(state->gpio_reset); usleep_range(50, 100); =20 return 0; @@ -1404,10 +1407,10 @@ static int __s5c73m3_power_off(struct s5c73m3 *stat= e) { int i, ret; =20 - if (s5c73m3_gpio_assert(state, RSET)) + if (s5c73m3_gpio_assert(state->gpio_reset)) usleep_range(10, 50); =20 - if (s5c73m3_gpio_assert(state, STBY)) + if (s5c73m3_gpio_assert(state->gpio_stby)) usleep_range(100, 200); =20 clk_disable_unprepare(state->clock); @@ -1545,50 +1548,34 @@ static const struct v4l2_subdev_ops oif_subdev_ops = =3D { =20 static int s5c73m3_configure_gpios(struct s5c73m3 *state) { - static const char * const gpio_names[] =3D { - "S5C73M3_STBY", "S5C73M3_RST" - }; struct i2c_client *c =3D state->i2c_client; - struct s5c73m3_gpio *g =3D state->gpio; - int ret, i; + struct device *dev =3D &c->dev; + struct device_node *np =3D dev->of_node; =20 - for (i =3D 0; i < GPIO_NUM; ++i) { - unsigned int flags =3D GPIOF_DIR_OUT; - if (g[i].level) - flags |=3D GPIOF_INIT_HIGH; - ret =3D devm_gpio_request_one(&c->dev, g[i].gpio, flags, - gpio_names[i]); - if (ret) { - v4l2_err(c, "failed to request gpio %s\n", - gpio_names[i]); - return ret; - } + state->gpio_stby =3D gpiod_get_from_of_node(np, "standby-gpios", 0, GPIOD= _ASIS, + "S5C73M3_STBY"); + + if (IS_ERR(state->gpio_stby)) { + v4l2_err(c, "failed to request gpio S5C73M3_STBY"); + return PTR_ERR(state->gpio_stby); } - return 0; -} =20 -static int s5c73m3_parse_gpios(struct s5c73m3 *state) -{ - static const char * const prop_names[] =3D { - "standby-gpios", "xshutdown-gpios", - }; - struct device *dev =3D &state->i2c_client->dev; - struct device_node *node =3D dev->of_node; - int ret, i; + if (state->gpio_stby) + gpiod_direction_output(state->gpio_stby, + !gpiod_is_active_low(state->gpio_stby)); =20 - for (i =3D 0; i < GPIO_NUM; ++i) { - enum of_gpio_flags of_flags; + state->gpio_reset =3D gpiod_get_from_of_node(np, "xshutdown-gpios", 0, GP= IOD_ASIS, + "S5C73M3_RST"); =20 - ret =3D of_get_named_gpio_flags(node, prop_names[i], - 0, &of_flags); - if (ret < 0) { - dev_err(dev, "failed to parse %s DT property\n", - prop_names[i]); - return -EINVAL; - } - state->gpio[i].gpio =3D ret; - state->gpio[i].level =3D !(of_flags & OF_GPIO_ACTIVE_LOW); + if (IS_ERR(state->gpio_reset)) { + v4l2_err(c, "failed to request gpio S5C73M3_RST"); + return PTR_ERR(state->gpio_reset); } + + if (state->gpio_reset) + gpiod_direction_output(state->gpio_reset, + !gpiod_is_active_low(state->gpio_reset)); + return 0; } =20 @@ -1608,8 +1595,8 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *= state) } =20 state->mclk_frequency =3D pdata->mclk_frequency; - state->gpio[STBY] =3D pdata->gpio_stby; - state->gpio[RSET] =3D pdata->gpio_reset; + state->gpio_stby =3D pdata->gpio_stby; + state->gpio_reset =3D pdata->gpio_reset; return 0; } =20 @@ -1624,10 +1611,6 @@ static int s5c73m3_get_platform_data(struct s5c73m3 = *state) state->mclk_frequency); } =20 - ret =3D s5c73m3_parse_gpios(state); - if (ret < 0) - return -EINVAL; - node_ep =3D of_graph_get_next_endpoint(node, NULL); if (!node_ep) { dev_warn(dev, "no endpoint defined for node: %pOF\n", node); diff --git a/drivers/media/i2c/s5c73m3/s5c73m3.h b/drivers/media/i2c/s5c73m= 3/s5c73m3.h index c3fcfdd3ea66..f0056ae6e51a 100644 --- a/drivers/media/i2c/s5c73m3/s5c73m3.h +++ b/drivers/media/i2c/s5c73m3/s5c73m3.h @@ -351,12 +351,6 @@ struct s5c73m3_ctrls { struct v4l2_ctrl *scene_mode; }; =20 -enum s5c73m3_gpio_id { - STBY, - RSET, - GPIO_NUM, -}; - enum s5c73m3_resolution_types { RES_ISP, RES_JPEG, @@ -383,7 +377,8 @@ struct s5c73m3 { u32 i2c_read_address; =20 struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES]; - struct s5c73m3_gpio gpio[GPIO_NUM]; + struct gpio_desc *gpio_stby; + struct gpio_desc *gpio_reset; =20 struct clk *clock; =20 diff --git a/include/media/i2c/s5c73m3.h b/include/media/i2c/s5c73m3.h index a51f1025ba1c..caad855a8394 100644 --- a/include/media/i2c/s5c73m3.h +++ b/include/media/i2c/s5c73m3.h @@ -17,19 +17,10 @@ #ifndef MEDIA_S5C73M3__ #define MEDIA_S5C73M3__ =20 +#include #include #include =20 -/** - * struct s5c73m3_gpio - data structure describing a GPIO - * @gpio: GPIO number - * @level: indicates active state of the @gpio - */ -struct s5c73m3_gpio { - int gpio; - int level; -}; - /** * struct s5c73m3_platform_data - s5c73m3 driver platform data * @mclk_frequency: sensor's master clock frequency in Hz @@ -44,8 +35,8 @@ struct s5c73m3_gpio { struct s5c73m3_platform_data { unsigned long mclk_frequency; =20 - struct s5c73m3_gpio gpio_reset; - struct s5c73m3_gpio gpio_stby; + struct gpio_desc *gpio_reset; + struct gpio_desc *gpio_stby; =20 enum v4l2_mbus_type bus_type; u8 nlanes; --=20 2.36.1 From nobody Sat Apr 18 09:24:17 2026 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 9CFF1C43334 for ; Thu, 14 Jul 2022 22:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241056AbiGNWMa (ORCPT ); Thu, 14 Jul 2022 18:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241037AbiGNWM1 (ORCPT ); Thu, 14 Jul 2022 18:12:27 -0400 Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6AD70E75 for ; Thu, 14 Jul 2022 15:12:27 -0700 (PDT) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4LkTHt3DDCz9sQt; Thu, 14 Jul 2022 22:12:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1657836746; bh=nN8OVxxrhkv2QzlJp1RLZitf9bmBRAzLYPYKcObmvks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FPBWn8/fCH53e16UY/EheNrXpt2jfK2VtMv48QLI76GA5g62sANdiEfYp5CBMpBXi lYLT3o6msUFK1pqZ8IMZQaQZg/bGfVJpTWIOdGlOjxHsljvTXZEaD2/gQyW4dbtqBh b6af3134iyb1twX9I7r1TR7PWFM1MIL1/SrPpmAI= X-Riseup-User-ID: 52F8D95B0879F3E12E6299DA0CB9927E43DA238409F402D037997E981A91189D Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4LkTHp3lGJz1yWZ; Thu, 14 Jul 2022 22:12:22 +0000 (UTC) From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: mchehab@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, s.nawrocki@samsung.com, andrzej.hajda@intel.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Ma=C3=ADra=20Canal?= , Krzysztof Kozlowski , =?UTF-8?q?Ma=C3=ADra=20Canal?= Subject: [PATCH RESEND 2/2] dt-bindings: media: s5c73m3: Fix reset-gpio descriptor Date: Thu, 14 Jul 2022 19:12:02 -0300 Message-Id: <20220714221202.86768-3-mairacanal@riseup.net> In-Reply-To: <20220714221202.86768-1-mairacanal@riseup.net> References: <20220714221202.86768-1-mairacanal@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ma=C3=ADra Canal The reset-gpios is described as xshutdown-gpios on the required properties, as it is on the driver. Despite that, the device tree example set the property 'reset-gpios' instead of the property 'xshutdown-gpios'. Therefore, this patch updates the example to match the property specified on the driver. Acked-by: Krzysztof Kozlowski Signed-off-by: Ma=C3=ADra Canal --- Documentation/devicetree/bindings/media/samsung-s5c73m3.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/samsung-s5c73m3.txt b/= Documentation/devicetree/bindings/media/samsung-s5c73m3.txt index 21f31fdf5543..f0ea9adad442 100644 --- a/Documentation/devicetree/bindings/media/samsung-s5c73m3.txt +++ b/Documentation/devicetree/bindings/media/samsung-s5c73m3.txt @@ -76,7 +76,7 @@ i2c@138a000000 { clock-frequency =3D <24000000>; clocks =3D <&clk 0>; clock-names =3D "cis_extclk"; - reset-gpios =3D <&gpf1 3 1>; + xshutdown-gpios =3D <&gpf1 3 1>; standby-gpios =3D <&gpm0 1 1>; port { s5c73m3_ep: endpoint { --=20 2.36.1