public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy@kernel.org>
To: Hans de Goede <hdegoede@redhat.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Daniel Scally <dan.scally@ideasonboard.com>,
	linux-acpi@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Kate Hsuan <hpa@redhat.com>, Hao Yao <hao.yao@intel.com>,
	Bingbu Cao <bingbu.cao@intel.com>,
	linux-media@vger.kernel.org, Daniel Scally <djrscally@gmail.com>
Subject: Re: [PATCH v3 14/18] media: i2c: Add driver for DW9719 VCM
Date: Thu, 6 Jul 2023 13:06:07 +0300	[thread overview]
Message-ID: <ZKaSD0CHRBd+zu/T@smile.fi.intel.com> (raw)
In-Reply-To: <20230705213010.390849-15-hdegoede@redhat.com>

On Wed, Jul 05, 2023 at 11:30:06PM +0200, Hans de Goede wrote:
> From: Daniel Scally <djrscally@gmail.com>
> 
> Add a driver for the DW9719 VCM. The driver creates a v4l2 subdevice
> and registers a control to set the desired focus.

...

> +/*
> + * Based on linux/modules/camera/drivers/media/i2c/imx/dw9719.c in this repo:

Sakari, also long line? :-)

> + * https://github.com/ZenfoneArea/android_kernel_asus_zenfone5
> + */

...

> +#include <asm/unaligned.h>

Usually we include headers from generic to particular / private,
hence asm/* usually goes after linux/*.

> +#include <linux/delay.h>
> +#include <linux/i2c.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/types.h>

...

> +#define DW9719_CTRL_DELAY_US	1000

USEC_PER_MSEC ?

...

> +#define DELAY_MAX_PER_STEP_NS	(1000000 * 1023)

NSEC_PER_MSEC ?

...

> +#define DW9719_DEFAULT_VCM_FREQ		0x60

Any comment what this value means in Hz?

...

> +#define to_dw9719_device(x) container_of(x, struct dw9719_device, sd)

You can make this no-op at compile time by...

...

> +struct dw9719_device {
> +	struct device *dev;
> +	struct i2c_client *client;
> +	struct regulator *regulator;

> +	struct v4l2_subdev sd;

...having this to be the first member in the structure.

However bloat-o-meter can show grow of the code in case the dev is used more
often. The rule of thumb is to combine two aspects:
- frequency of usage (hence pointer arithmetics);
- hot path vs. slow path (hence importance of the lesser code).

> +	u32 sac_mode;
> +	u32 vcm_freq;
> +
> +	struct dw9719_v4l2_ctrls {
> +		struct v4l2_ctrl_handler handler;
> +		struct v4l2_ctrl *focus;
> +	} ctrls;
> +};

...

> +static int dw9719_i2c_rd8(struct i2c_client *client, u8 reg, u8 *val)
> +{
> +	struct i2c_msg msg[2];
> +	u8 buf[2] = { reg };
> +	int ret;
> +
> +	msg[0].addr = client->addr;
> +	msg[0].flags = 0;

> +	msg[0].len = 1;
> +	msg[0].buf = buf;

	sizeof(buf[0])
	&buf[0]

looks more explicit.

> +	msg[1].addr = client->addr;
> +	msg[1].flags = I2C_M_RD;
> +	msg[1].len = 1;
> +	msg[1].buf = &buf[1];

Ditto.

> +	*val = 0;
> +
> +	ret = i2c_transfer(client->adapter, msg, 2);

ARRAY_SIZE()

> +	if (ret < 0)
> +		return ret;
> +
> +	*val = buf[1];
> +
> +	return 0;
> +}

But as Sakari said this perhaps could go into CCI library.

...

> +	ret = dw9719_i2c_rd8(dw9719->client, DW9719_INFO, &val);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (val != DW9719_ID) {
> +		dev_err(dw9719->dev, "Failed to detect correct id\n");
> +		ret = -ENXIO;

		return -ENXIO;

> +	}
> +
> +	return 0;

...

> +	/* Need 100us to transit from SHUTDOWN to STANDBY*/

Missing space.

> +	usleep_range(100, 1000);

Perhaps fsleep() would be better, but I'm fine with either here.

...

> +static int dw9719_t_focus_abs(struct dw9719_device *dw9719, s32 value)
> +{
> +	int ret;

Redundant?

> +	value = clamp(value, 0, DW9719_MAX_FOCUS_POS);

> +	ret = dw9719_i2c_wr16(dw9719->client, DW9719_VCM_CURRENT, value);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;

	return _wr16(...);

or can it return positive values?

> +}

...

> +static int __maybe_unused dw9719_suspend(struct device *dev)

Can we use new PM macros instead of __maybe_unused?

> +{
> +	struct v4l2_subdev *sd = dev_get_drvdata(dev);
> +	struct dw9719_device *dw9719 = to_dw9719_device(sd);
> +	int ret;
> +	int val;
> +
> +	for (val = dw9719->ctrls.focus->val; val >= 0;
> +	     val -= DW9719_CTRL_STEPS) {
> +		ret = dw9719_t_focus_abs(dw9719, val);
> +		if (ret)
> +			return ret;

> +		usleep_range(DW9719_CTRL_DELAY_US, DW9719_CTRL_DELAY_US + 10);

fsleep() ?

> +	}
> +
> +	return dw9719_power_down(dw9719);
> +}

> +static int __maybe_unused dw9719_resume(struct device *dev)
> +{

As per above function.

...

> +err_power_down:

In one functions you use err_ in another fail_, be consistent.

> +	dw9719_power_down(dw9719);
> +	return ret;
> +}

...

> +	dw9719->regulator = devm_regulator_get(&client->dev, "vdd");
> +	if (IS_ERR(dw9719->regulator))
> +		return dev_err_probe(&client->dev, PTR_ERR(dw9719->regulator),

With

	struct device *dev = &client->dev;

code may look neater.

> +				     "getting regulator\n");

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2023-07-06 10:06 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 21:29 [PATCH v3 00/18] media: ipu-bridge: Shared with atomisp, rework VCM instantiation Hans de Goede
2023-07-05 21:29 ` [PATCH v3 01/18] media: ipu-bridge: Fix null pointer deref on SSDB/PLD parsing warnings Hans de Goede
2023-07-06 13:07   ` Dan Scally
2023-07-05 21:29 ` [PATCH v3 02/18] media: ipu-bridge: Do not use on stack memory for software_node.name field Hans de Goede
2023-07-05 21:29 ` [PATCH v3 03/18] media: ipu-bridge: Move initialization of node_names.vcm to ipu_bridge_init_swnode_names() Hans de Goede
2023-07-05 21:29 ` [PATCH v3 04/18] media: ipu-bridge: Allow building as module Hans de Goede
2023-07-06  9:47   ` Andy Shevchenko
2023-07-05 21:29 ` [PATCH v3 05/18] media: ipu-bridge: Make ipu_bridge_init() take a regular struct device as argument Hans de Goede
2023-07-05 21:29 ` [PATCH v3 06/18] media: ipu-bridge: Store dev pointer in struct ipu_bridge Hans de Goede
2023-07-05 21:29 ` [PATCH v3 07/18] media: ipu-bridge: Only keep PLD around while parsing Hans de Goede
2023-07-05 21:30 ` [PATCH v3 08/18] media: ipu-bridge: Add a ipu_bridge_parse_ssdb() helper function Hans de Goede
2023-07-05 21:30 ` [PATCH v3 09/18] media: ipu-bridge: Drop early setting of sensor->adev Hans de Goede
2023-07-05 21:30 ` [PATCH v3 10/18] media: ipu-bridge: Add a parse_sensor_fwnode callback to ipu_bridge_init() Hans de Goede
2023-07-06  9:50   ` Andy Shevchenko
2023-07-05 21:30 ` [PATCH v3 11/18] media: ipu-bridge: Move ipu-bridge.h to include/media/ Hans de Goede
2023-07-05 21:30 ` [PATCH v3 12/18] media: ipu-bridge: Add GalaxyCore GC0310 to ipu_supported_sensors[] Hans de Goede
2023-07-05 21:30 ` [PATCH v3 13/18] media: ipu-bridge: Add a runtime-pm device-link between VCM and sensor Hans de Goede
2023-07-05 21:30 ` [PATCH v3 14/18] media: i2c: Add driver for DW9719 VCM Hans de Goede
2023-07-06  7:47   ` Sakari Ailus
2023-07-06  9:14     ` Andy Shevchenko
2023-07-06  9:30       ` Sakari Ailus
2023-07-06 10:06   ` Andy Shevchenko [this message]
2023-07-06 10:27     ` Sakari Ailus
2023-07-06 10:48       ` Andy Shevchenko
2023-07-06 11:02         ` Sakari Ailus
2023-07-06 14:34     ` Hans de Goede
2023-07-06 14:47       ` Andy Shevchenko
2023-07-06 11:18   ` Dave Stevenson
2023-07-06 12:34     ` Hans de Goede
2023-07-06 12:52     ` Hans de Goede
2023-07-05 21:30 ` [PATCH v3 15/18] ACPI: bus: Introduce acpi_match_acpi_device() function Hans de Goede
2023-07-06  9:19   ` Andy Shevchenko
2023-07-06 12:29     ` Hans de Goede
2023-07-06 12:40       ` Andy Shevchenko
2023-07-06 13:26       ` Rafael J. Wysocki
2023-07-06 13:28         ` Hans de Goede
2023-07-06 13:31         ` Andy Shevchenko
2023-07-05 21:30 ` [PATCH v3 16/18] media: atomisp: csi2-bridge: Switch to new common ipu_bridge_init() Hans de Goede
2023-07-05 21:30 ` [PATCH v3 17/18] media: atomisp: csi2-bridge: Add dev_name() to acpi_handle_info() logging Hans de Goede
2023-07-06 10:09   ` Andy Shevchenko
2023-07-06 11:12     ` Laurent Pinchart
2023-07-06 12:23       ` Andy Shevchenko
2023-07-06 13:07         ` Laurent Pinchart
2023-07-06 13:22           ` Andy Shevchenko
2023-07-06 13:43           ` Sakari Ailus
2023-07-05 21:30 ` [PATCH v3 18/18] media: atomisp: csi2-bridge: Add support for VCM I2C-client instantiation Hans de Goede
2023-07-06 10:15   ` Andy Shevchenko
2023-07-06 12:31     ` Hans de Goede
2023-07-06 12:42       ` Andy Shevchenko
2023-07-06 12:47         ` Hans de Goede
2023-07-06 12:56           ` Andy Shevchenko
2023-07-06 12:58             ` Hans de Goede

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=ZKaSD0CHRBd+zu/T@smile.fi.intel.com \
    --to=andy@kernel.org \
    --cc=bingbu.cao@intel.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=djrscally@gmail.com \
    --cc=hao.yao@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=hpa@redhat.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rafael@kernel.org \
    --cc=sakari.ailus@linux.intel.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