public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Zhi Mao <zhi.mao@mediatek.com>,
	mchehab@kernel.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org
Cc: shengnan.wang@mediatek.com, yaya.chang@mediatek.com,
	10572168@qq.com,
	Project_Global_Chrome_Upstream_Group@mediatek.com,
	yunkec@chromium.org, conor+dt@kernel.org, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com,
	jacopo.mondi@ideasonboard.com, sakari.ailus@linux.intel.com,
	hverkuil-cisco@xs4all.nl, heiko@sntech.de,
	jernej.skrabec@gmail.com, macromorgan@hotmail.com,
	linus.walleij@linaro.org, laurent.pinchart@ideasonboard.com,
	hdegoede@redhat.com, tomi.valkeinen@ideasonboard.com,
	gerald.loacker@wolfvision.net, andy.shevchenko@gmail.com,
	bingbu.cao@intel.com, dan.scally@ideasonboard.com,
	linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH 2/2] media: i2c: Add GC08A3 image sensor driver
Date: Fri, 24 Nov 2023 09:09:48 +0100	[thread overview]
Message-ID: <4a4a3313-2fb5-4b20-a24f-4422aeedbc41@linaro.org> (raw)
In-Reply-To: <20231123115104.32094-3-zhi.mao@mediatek.com>

On 23/11/2023 12:51, Zhi Mao wrote:
> Add a V4L2 sub-device driver for Galaxycore GC08A3 image sensor.
> 
> Signed-off-by: Zhi Mao <zhi.mao@mediatek.com>
> ---
>  drivers/media/i2c/Kconfig  |   14 +
>  drivers/media/i2c/Makefile |    1 +
>  drivers/media/i2c/gc08a3.c | 2046 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 2061 insertions(+)
>  create mode 100644 drivers/media/i2c/gc08a3.c


> +static int gc08a3_start_streaming(struct gc08a3 *gc08a3)
> +{
> +	const struct gc08a3_mode *mode;
> +	const struct gc08a3_reg_list *reg_list;
> +	int link_freq_index;
> +	int ret;
> +
> +	dev_info(gc08a3->dev, "%s ++\n", __func__);

Drop

> +
> +	mutex_lock(&gc08a3->mutex);
> +
> +	link_freq_index = gc08a3->cur_mode->link_freq_index;
> +	dev_info(gc08a3->dev, "----link_freq_index = %d ", link_freq_index);
> +
> +	reg_list = &link_freq_configs[link_freq_index].reg_list;
> +	ret = gc08a3_write_reg_list(gc08a3, reg_list);
> +	if (ret) {
> +		dev_err(gc08a3->dev, "could not sent common table %d\n", ret);
> +		goto error;
> +	}
> +
> +	mode = gc08a3->cur_mode;
> +	dev_info(gc08a3->dev, "----write regtbl: mode(id:%d, WxH:%dx%d)",
> +		 mode->mode_id, mode->width, mode->height);
> +	reg_list = &mode->reg_list;
> +
> +	ret = gc08a3_write_reg_list(gc08a3, reg_list);
> +	if (ret < 0) {
> +		dev_err(gc08a3->dev, "could not sent mode table %d\n", ret);
> +		goto error;
> +	}
> +	ret = __v4l2_ctrl_handler_setup(&gc08a3->ctrls);
> +	if (ret < 0) {
> +		dev_err(gc08a3->dev, "could not sync v4l2 controls\n");
> +		goto error;
> +	}
> +
> +	ret = gc08a3_write_reg(gc08a3, GC08A3_STRAEMING_REG,
> +			       GC08A3_REG_VALUE_08BIT, 1);
> +	if (ret < 0) {
> +		dev_err(gc08a3->dev, "write STRAEMING_REG failed: %d\n", ret);
> +		goto error;
> +	}
> +
> +	mutex_unlock(&gc08a3->mutex);
> +
> +	dev_info(gc08a3->dev, "%s --\n", __func__);

Drop


> +
> +	return 0;
> +
> +error:
> +	mutex_unlock(&gc08a3->mutex);
> +	return ret;
> +}
> +
> +static int gc08a3_stop_streaming(struct gc08a3 *gc08a3)
> +{
> +	int ret;
> +
> +	dev_info(gc08a3->dev, "%s ++\n", __func__);

Drop

> +
> +	ret = gc08a3_write_reg(gc08a3, GC08A3_STRAEMING_REG,
> +			       GC08A3_REG_VALUE_08BIT, 0);
> +	if (ret < 0)
> +		dev_err(gc08a3->dev, "could not sent stop streaming %d\n", ret);
> +
> +	dev_info(gc08a3->dev, "%s --\n", __func__);
> +

Drop

...

> +
> +static int gc08a3_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct gc08a3 *gc08a3;
> +	int ret;
> +
> +	dev_info(dev, "--- %s +", __func__);


No, drop such silly debug messages. Everywhere. Really everywhere.

> +
> +	ret = gc08a3_parse_fwnode(dev);
> +	if (ret)
> +		return ret;
> +
> +	gc08a3 = devm_kzalloc(dev, sizeof(*gc08a3), GFP_KERNEL);
> +	if (!gc08a3)
> +		return -ENOMEM;
> +
> +	gc08a3->dev = dev;
> +
> +	gc08a3->xclk = devm_clk_get(dev, NULL);
> +	if (IS_ERR(gc08a3->xclk)) {
> +		dev_err(dev, "could not get xclk\n");

Syntax is:
return dev_err_probe()

> +		return PTR_ERR(gc08a3->xclk);
> +	}
> +
> +	ret = clk_set_rate(gc08a3->xclk, GC08A3_DEFAULT_CLK_FREQ);
> +	if (ret) {
> +		dev_err(dev, "could not set xclk frequency\n");
> +		return ret;
> +	}
> +
> +	ret = gc08a3_get_regulators(dev, gc08a3);
> +	if (ret < 0) {
> +		dev_err(dev, "cannot get regulators\n");

return dev_err_probe()

> +		return ret;
> +	}
> +
> +	gc08a3->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
> +	if (IS_ERR(gc08a3->enable_gpio)) {
> +		dev_err(dev, "cannot get enable gpio\n");

return dev_err_probe()

> +		return PTR_ERR(gc08a3->enable_gpio);
> +	}
> +
> +	gc08a3->regmap = devm_regmap_init_i2c(client, &sensor_regmap_config);
> +	if (IS_ERR(gc08a3->regmap)) {
> +		dev_err(dev, "regmap init failed\n");

return dev_err_probe()

> +		return PTR_ERR(gc08a3->regmap);
> +	}
> +
> +	v4l2_i2c_subdev_init(&gc08a3->sd, client, &gc08a3_subdev_ops);
> +
> +	gc08a3_power_on(gc08a3->dev);
> +
> +	ret = gc08a3_identify_module(gc08a3);
> +	if (ret) {
> +		dev_err(&client->dev, "failed to find sensor: %d\n", ret);
> +		gc08a3_power_off(gc08a3->dev);
> +		return ret;
> +	}
> +
> +	mutex_init(&gc08a3->mutex);
> +	gc08a3->cur_mode = &gc08a3_modes[0];
> +
> +	ret = gc08a3_init_controls(gc08a3);
> +	if (ret) {
> +		dev_err(&client->dev, "failed to init controls: %d", ret);

No power off?

> +		goto free_ctrl;
> +	}
> +
> +	gc08a3->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> +	gc08a3->pad.flags = MEDIA_PAD_FL_SOURCE;
> +	gc08a3->sd.dev = &client->dev;
> +	gc08a3->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
> +
> +	dev_dbg(&client->dev, "gc08a3->sd.name: %s, dev->of_node->name: %s\n",
> +		gc08a3->sd.name, dev->of_node->name);
> +	if (V4L2_SUBDEV_NAME_SIZE - strlen(gc08a3->sd.name) - 2 <
> +	    strlen(dev->of_node->name)) {
> +		dev_err(&client->dev,
> +			"the string length of (sd.name + of_node->name) is too long.\n");

This looks like random error handling. You had goto in previous cases.

> +		return -EINVAL;
> +	}
> +	strncat(gc08a3->sd.name, " ", 1);
> +	strncat(gc08a3->sd.name, dev->of_node->name,
> +		V4L2_SUBDEV_NAME_SIZE - strlen(gc08a3->sd.name) - 2);
> +	dev_dbg(&client->dev, "after: gc08a3->sd.name: %s\n", gc08a3->sd.name);
> +
> +	ret = media_entity_pads_init(&gc08a3->sd.entity, 1, &gc08a3->pad);
> +	if (ret < 0) {
> +		dev_err(dev, "could not register media entity\n");
> +		goto free_ctrl;
> +	}
> +
> +	ret = v4l2_async_register_subdev_sensor(&gc08a3->sd);
> +	if (ret < 0) {
> +		dev_err(dev, "could not register v4l2 device\n");
> +		goto free_entity;
> +	}
> +
> +	pm_runtime_set_active(gc08a3->dev);
> +	pm_runtime_enable(gc08a3->dev);
> +	pm_runtime_idle(gc08a3->dev);
> +
> +	dev_info(dev, "--- %s -", __func__);

No, drop such silly debug messages.

> +
> +	return 0;
> +
> +free_entity:
> +	media_entity_cleanup(&gc08a3->sd.entity);
> +free_ctrl:
> +	mutex_destroy(&gc08a3->mutex);
> +	v4l2_ctrl_handler_free(&gc08a3->ctrls);
> +	pm_runtime_disable(gc08a3->dev);
> +
> +	return ret;
> +}
> +
> +static void gc08a3_remove(struct i2c_client *client)
> +{
> +	struct v4l2_subdev *sd = i2c_get_clientdata(client);
> +	struct gc08a3 *gc08a3 = to_gc08a3(sd);
> +
> +	v4l2_async_unregister_subdev(&gc08a3->sd);
> +	media_entity_cleanup(&gc08a3->sd.entity);
> +	v4l2_ctrl_handler_free(&gc08a3->ctrls);
> +
> +	pm_runtime_disable(&client->dev);
> +	pm_runtime_set_suspended(&client->dev);
> +
> +	mutex_destroy(&gc08a3->mutex);
> +}
> +
> +static const struct of_device_id gc08a3_of_match[] = {
> +	{ .compatible = "GalaxyCore,gc08a3" },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, gc08a3_of_match);
> +
> +static const struct dev_pm_ops gc08a3_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(gc08a3_suspend, gc08a3_resume)
> +		SET_RUNTIME_PM_OPS(gc08a3_power_off, gc08a3_power_on, NULL)

Fix indentation.

This code has very pooro quality. I suggest you to do first internal
review to avoid commenting on trivial errors and using community
resources for this.


Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-11-24  8:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 11:51 [PATCH 0/2] media: i2c: Add support for GC08A3 sensor Zhi Mao
2023-11-23 11:51 ` [PATCH 1/2] media: dt-bindings: media: i2c: Document GC08A3 bindings Zhi Mao
2023-11-23 12:16   ` Rob Herring
2023-11-23 17:31   ` Conor Dooley
2023-12-07 10:25     ` Laurent Pinchart
2024-01-09  9:11       ` Zhi Mao (毛智)
2024-01-09  9:18         ` Laurent Pinchart
2023-11-23 11:51 ` [PATCH 2/2] media: i2c: Add GC08A3 image sensor driver Zhi Mao
2023-11-24  7:56   ` kernel test robot
2023-11-24  8:09   ` Krzysztof Kozlowski [this message]
2023-12-07 11:06   ` Laurent Pinchart
2024-01-09  9:25     ` Zhi Mao (毛智)

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=4a4a3313-2fb5-4b20-a24f-4422aeedbc41@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=10572168@qq.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bingbu.cao@intel.com \
    --cc=conor+dt@kernel.org \
    --cc=dan.scally@ideasonboard.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gerald.loacker@wolfvision.net \
    --cc=hdegoede@redhat.com \
    --cc=heiko@sntech.de \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=macromorgan@hotmail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=shengnan.wang@mediatek.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    --cc=yaya.chang@mediatek.com \
    --cc=yunkec@chromium.org \
    --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