devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Sebastian LaVine <slavine@d3embedded.com>,
	devicetree@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Cc: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
	"Abel Vesa" <abel.vesa@linaro.org>,
	"Achath Vaishnav" <vaishnav.a@ti.com>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Benjamin Mugnier" <benjamin.mugnier@foss.st.com>,
	"Biju Das" <biju.das.jz@bp.renesas.com>,
	"Bjorn Andersson" <quic_bjorande@quicinc.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
	"Elinor Montmasson" <elinor.montmasson@savoirfairelinux.com>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Hans Verkuil" <hverkuil@xs4all.nl>,
	"Javier Carrasco" <javier.carrasco@wolfvision.net>,
	"Jianzhong Xu" <xuj@ti.com>,
	"Julien Massot" <julien.massot@collabora.com>,
	"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	"Kory Maincent" <kory.maincent@bootlin.com>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Mikhail Rudenko" <mike.rudenko@gmail.com>,
	"Nishanth Menon" <nm@ti.com>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Rob Herring" <robh@kernel.org>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Stuart Burtner" <sburtner@d3embedded.com>,
	"Tero Kristo" <kristo@kernel.org>,
	"Thakkar Devarsh" <devarsht@ti.com>,
	"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>,
	"Umang Jain" <umang.jain@ideasonboard.com>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Will Deacon" <will@kernel.org>, "Zhi Mao" <zhi.mao@mediatek.com>
Subject: Re: [PATCH 2/4] media: i2c: Add driver for Sony IMX728
Date: Wed, 12 Feb 2025 21:11:58 +0100	[thread overview]
Message-ID: <416d75fd-40d0-45d7-9590-0322abb480ca@linaro.org> (raw)
In-Reply-To: <20250212195656.69528-3-slavine@d3embedded.com>

On 12/02/2025 20:56, Sebastian LaVine wrote:
> +static int imx728_detect(struct imx728 *imx728)
> +{
> +       int ret = 0;
> +       u64 minor, major;
> +
> +       cci_read(imx728->regmap, IMX728_REG_VMAJOR, &major, &ret);
> +       if (ret != 0) {
> +               dev_err(imx728->dev, "Could not read PARAM_MAJOR_VER!");
> +               return ret;
> +       }
> +       cci_read(imx728->regmap, IMX728_REG_VMINOR, &minor, &ret);
> +       if (ret != 0) {
> +               dev_err(imx728->dev, "Could not read PARAM_MINOR_VER!");
> +               return ret;
> +       }
> +       dev_dbg(imx728->dev, "Got version: %lld.%lld", major, minor);
> +
> +       return 0;
> +}
> +
> +static int imx728_reset(struct imx728 *imx728)
> +{
> +
> +       int ret = 0;
> +
> +       // Prefer hardware reset if available.
> +       if (!IS_ERR_OR_NULL(imx728->reset_gpio)) {

Here can be ERR (although why?) but...

> +               gpiod_set_value_cansleep(imx728->reset_gpio, 1);
> +               usleep_range(1000, 10000);
> +               gpiod_set_value_cansleep(imx728->reset_gpio, 0);
> +               msleep(100);
> +       } else {
> +               // Software reset.
> +               cci_write(imx728->regmap, IMX728_REG_RESET_0, 0xc3, &ret);
> +               cci_update_bits(imx728->regmap, IMX728_REG_RESET_1, 0x1, 0x1, &ret);
> +               msleep(100);
> +       }
> +
> +       return ret;
> +}
> +
> +static int imx728_power_on(struct imx728 *imx728)
> +{
> +       int ret;
> +
> +       ret = clk_prepare_enable(imx728->clk);
> +       if (ret < 0)
> +               return ret;
> +
> +       imx728_reset(imx728);
> +       return 0;
> +}
> +
> +static int imx728_power_off(struct imx728 *imx728)
> +{
> +
> +       if (imx728->reset_gpio) {

Here cannot.

> +               gpiod_set_value_cansleep(imx728->reset_gpio, 1);
> +
> +               usleep_range(1, 10);
> +       }
> +       clk_disable_unprepare(imx728->clk);
> +       return 0;
> +}
> +


...

> +
> +static int imx728_set_stream(struct v4l2_subdev *sd, int enable)
> +{
> +       struct imx728 *imx728 = to_imx728(sd);
> +       int ret;
> +
> +       mutex_lock(&imx728->lock);

Just use guard. That's actually perfect candidate.


> +       if (imx728->streaming == enable) {
> +               mutex_unlock(&imx728->lock);
> +               return 0;
> +       }
> +
> +       if (enable) {
> +               ret = pm_runtime_get_sync(imx728->dev);
> +               if (ret < 0) {
> +                       pm_runtime_put_noidle(imx728->dev);
> +                       goto err_unlock;
> +               }
> +
> +               ret = imx728_start_stream(imx728);
> +               if (ret < 0)
> +                       goto err_runtime_put;
> +       } else {
> +               ret = imx728_stop_stream(imx728);
> +               if (ret < 0)
> +                       goto err_runtime_put;
> +               pm_runtime_mark_last_busy(imx728->dev);
> +               pm_runtime_put_autosuspend(imx728->dev);
> +       }
> +
> +       imx728->streaming = enable;
> +
> +       __v4l2_ctrl_grab(imx728->ctrl.h_flip, enable);
> +       __v4l2_ctrl_grab(imx728->ctrl.v_flip, enable);
> +
> +       mutex_unlock(&imx728->lock);
> +
> +       return 0;
> +
> +err_runtime_put:
> +       pm_runtime_put(imx728->dev);
> +
> +err_unlock:
> +       mutex_unlock(&imx728->lock);
> +       dev_err(imx728->dev,
> +               "%s: failed to setup streaming %d\n", __func__, ret);
> +       return ret;
> +}
> +
> +static const struct v4l2_subdev_core_ops imx728_core_ops = {
> +       .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
> +       .unsubscribe_event = v4l2_event_subdev_unsubscribe,
> +};
> +
> +static const struct v4l2_subdev_video_ops imx728_subdev_video_ops = {
> +       .s_stream = imx728_set_stream,
> +};
> +
> +static const struct v4l2_subdev_pad_ops imx728_subdev_pad_ops = {
> +       .enum_frame_size = imx728_enum_frame_sizes,
> +       .enum_mbus_code = imx728_enum_mbus_code,
> +       .get_fmt = v4l2_subdev_get_fmt,
> +       .get_frame_desc = imx728_get_frame_desc,
> +       .get_frame_interval = imx728_get_frame_interval,
> +       .get_selection = imx728_get_selection,
> +       .set_fmt = imx728_set_fmt,
> +       .set_frame_interval = imx728_set_frame_interval,
> +       .set_routing = imx728_set_routing,
> +};
> +
> +static const struct v4l2_subdev_ops imx728_subdev_ops = {
> +       .core  = &imx728_core_ops,
> +       .video = &imx728_subdev_video_ops,
> +       .pad   = &imx728_subdev_pad_ops,
> +};
> +
> +static const struct v4l2_subdev_internal_ops imx728_internal_ops = {
> +       .init_state = imx728_init_state,
> +};
> +
> +
> +static const struct v4l2_ctrl_ops imx728_ctrl_ops = {
> +       .s_ctrl = imx728_set_ctrl,
> +};
> +
> +static int imx728_probe(struct i2c_client *client)
> +{
> +       struct imx728 *imx728;
> +       struct v4l2_subdev *sd;
> +       struct v4l2_ctrl_handler *ctrl_hdr;
> +       int ret;
> +
> +       imx728 = devm_kzalloc(&client->dev, sizeof(*imx728), GFP_KERNEL);
> +       if (!imx728)
> +               return -ENOMEM;
> +
> +       imx728->dev = &client->dev;
> +
> +       imx728->regmap = devm_cci_regmap_init_i2c(client, 16);
> +       if (IS_ERR(imx728->regmap))
> +               return PTR_ERR(imx728->regmap);
> +
> +       imx728->reset_gpio = devm_gpiod_get_optional(imx728->dev,
> +                                            "reset", GPIOD_OUT_LOW);
> +       if (IS_ERR(imx728->reset_gpio))
> +               return PTR_ERR(imx728->reset_gpio);

So can it be ERR after that point? Looks like not.



Best regards,
Krzysztof

  reply	other threads:[~2025-02-12 20:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12 19:56 [PATCH 0/4] media: i2c: Add driver for Sony IMX728 Sebastian LaVine
2025-02-12 19:56 ` [PATCH 1/4] media: dt-bindings: Add " Sebastian LaVine
2025-02-12 20:07   ` Krzysztof Kozlowski
2025-02-26 19:15     ` Sebastian LaVine
2025-02-13  9:26   ` Krzysztof Kozlowski
2025-02-26 17:50     ` Sebastian LaVine
2025-02-26 18:53       ` Sebastian LaVine
2025-02-26 21:38       ` Krzysztof Kozlowski
2025-02-12 19:56 ` [PATCH 2/4] media: i2c: Add driver for " Sebastian LaVine
2025-02-12 20:11   ` Krzysztof Kozlowski [this message]
2025-02-26 20:13     ` Sebastian LaVine
2025-02-26 21:40       ` Krzysztof Kozlowski
2025-02-13 10:19   ` Laurent Pinchart
2025-03-10 19:39     ` Sebastian LaVine
2025-03-11 10:18       ` Sakari Ailus
2025-02-13 18:19   ` Krzysztof Kozlowski
2025-03-07 21:21     ` Sebastian LaVine
2025-02-19 17:51   ` Markus Elfring
2025-02-26 21:17     ` Sebastian LaVine
2025-02-12 19:56 ` [PATCH 3/4] arm64: dts: ti: k3-am62a7-sk: Add overlay for fusion 2 board Sebastian LaVine
2025-02-12 20:13   ` Krzysztof Kozlowski
2025-02-26 22:00     ` Sebastian LaVine
2025-02-18 18:45   ` Nishanth Menon
2025-02-26 22:04     ` Sebastian LaVine
2025-02-18 19:07   ` Vaishnav Achath
2025-03-10 18:32     ` Sebastian LaVine
2025-02-19  9:31   ` Tomi Valkeinen
2025-02-26 22:06     ` Sebastian LaVine
2025-02-12 19:56 ` [PATCH 4/4] arm64: dts: ti: Add overlays for IMX728 RCM Sebastian LaVine
2025-02-18 18:46   ` Nishanth Menon
2025-02-12 20:04 ` [PATCH 0/4] media: i2c: Add driver for Sony IMX728 Krzysztof Kozlowski
2025-02-26 16:50   ` Sebastian LaVine
2025-02-13 10:40 ` Kieran Bingham
2025-02-26 17:05   ` Sebastian LaVine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=416d75fd-40d0-45d7-9590-0322abb480ca@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=abel.vesa@linaro.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=ardb@kernel.org \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devarsht@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=elinor.montmasson@savoirfairelinux.com \
    --cc=festevam@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=hverkuil@xs4all.nl \
    --cc=imx@lists.linux.dev \
    --cc=javier.carrasco@wolfvision.net \
    --cc=julien.massot@collabora.com \
    --cc=kernel@pengutronix.de \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=kory.maincent@bootlin.com \
    --cc=kristo@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mike.rudenko@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=nm@ti.com \
    --cc=quic_bjorande@quicinc.com \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sburtner@d3embedded.com \
    --cc=shawnguo@kernel.org \
    --cc=slavine@d3embedded.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    --cc=umang.jain@ideasonboard.com \
    --cc=vaishnav.a@ti.com \
    --cc=vigneshr@ti.com \
    --cc=will@kernel.org \
    --cc=xuj@ti.com \
    --cc=zhi.mao@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).