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: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Daniel Scally <dan.scally@ideasonboard.com>,
	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
Subject: Re: [PATCH 11/12] media: intel-cio2-bridge: Add a runtime-pm device-link between VCM and sensor
Date: Wed, 28 Jun 2023 00:03:11 +0300	[thread overview]
Message-ID: <ZJtOj3q6sTkl2gw5@smile.fi.intel.com> (raw)
In-Reply-To: <20230627175643.114778-12-hdegoede@redhat.com>

On Tue, Jun 27, 2023 at 07:56:41PM +0200, Hans de Goede wrote:
> In most cases when a VCM is used there is a single integrated module
> with the sensor + VCM + lens. This means that the sensor and VCM often
> share regulators and possibly also something like a powerdown pin.
> 
> In the ACPI tables this is modelled as a single ACPI device with
> multiple I2cSerialBus resources.
> 
> On atomisp devices the regulators and clks are modelled as ACPI
> power-resources, which are controlled by the (ACPI) power state
> of the sensor. So the sensor must be in D0 power state for the VCM
> to work.
> 
> To make this work add a device-link with DL_FLAG_PM_RUNTIME flag
> so that the sensor will automatically be runtime-resumed whenever
> the VCM is runtime-resumed.
> 
> This requires the probing of the VCM and thus the creation of the VCM
> I2C-client to be delayed till after the sensor driver has bound.
> 
> Move the instantiation of the VCM I2C-client to the v4l2_async_notifier
> bound op, so that it is done after the sensor driver has bound; and
> add code to add the device-link.
> 
> This fixes the problem with the shared ACPI power-resources on atomisp2
> and this avoids the need for VCM related workarounds on IPU3.
> 
> E.g. until now the dw9719 driver needed to get and control a Vsio
> (V sensor IO) regulator since that needs to be enabled to enable I2C
> pass-through on the PMIC on the sensor module. So the driver was
> controlling this regulator even though the actual dw9719 chip has no
> Vsio pin / power-plane.
> 
> This also removes the need for intel_cio2_bridge_init() to return
> -EPROBE_DEFER since the VCM is now instantiated later.

...

> +struct intel_cio2_bridge_instantiate_vcm_work_data {

Hmm... A bit long name :-)

> +	struct work_struct work;
> +	struct device *sensor;
>  	char name[16];
> +	struct i2c_board_info board_info;
> +};

...

> +	if (IS_ERR(vcm_client)) {
> +		dev_err(work->sensor, "Error instantiating VCM client: %ld\n",

or even %pe

> +			PTR_ERR(vcm_client));

...

> +out:

out_put_pm: ?

> +	pm_runtime_put(work->sensor);
> +	put_device(work->sensor);
> +	if (put_fwnode)
> +		fwnode_handle_put(work->board_info.fwnode);
> +	kfree(work);

...

> +int intel_cio2_bridge_instantiate_vcm(struct device *sensor)
> +{
> +	struct intel_cio2_bridge_instantiate_vcm_work_data *work;
> +	struct acpi_device *adev = ACPI_COMPANION(sensor);
> +	struct fwnode_handle *vcm_fwnode;
> +	struct i2c_client *vcm_client;
> +	char *sep;


I would rather split assignment, so below won't look a bit puzzling.

	struct acpi_device *adev;
	...
	adev = ACPI_COMPANION(sensor);

> +	if (!adev)
> +		return 0;
> +
> +	vcm_fwnode = fwnode_find_reference(dev_fwnode(sensor), "lens-focus", 0);
> +	if (IS_ERR(vcm_fwnode))
> +		return 0;
> +
> +	/* When reloading modules the client will already exist */
> +	vcm_client = i2c_find_device_by_fwnode(vcm_fwnode);
> +	if (vcm_client) {
> +		fwnode_handle_put(vcm_fwnode);
> +		put_device(&vcm_client->dev);
> +		return 0;
> +	}
> +
> +	work = kzalloc(sizeof(*work), GFP_KERNEL);
> +	if (!work) {
> +		fwnode_handle_put(vcm_fwnode);
> +		return -ENOMEM;
> +	}
> +
> +	INIT_WORK(&work->work, intel_cio2_bridge_instantiate_vcm_work);
> +	work->sensor = get_device(sensor);
> +	snprintf(work->name, sizeof(work->name), "%s-VCM",
> +		 acpi_dev_name(adev));
> +	work->board_info.dev_name = work->name;
> +	work->board_info.fwnode = vcm_fwnode;
> +	strscpy(work->board_info.type, fwnode_get_name(vcm_fwnode),
> +		I2C_NAME_SIZE);
> +	/* Strip "-<link>" postfix */
> +	sep = strchrnul(work->board_info.type, '-');
> +	*sep = 0;
> +
> +	queue_work(system_long_wq, &work->work);
> +
> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-06-27 21:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 17:56 [PATCH 00/12] media: intel-cio2-bridge: Add shared intel-cio2-bridge code, rework VCM instantiation Hans de Goede
2023-06-27 17:56 ` [PATCH 01/12] media: ipu3-cio2: Do not use on stack memory for software_node.name field Hans de Goede
2023-06-27 17:56 ` [PATCH 02/12] media: ipu3-cio2: Move initialization of node_names.vcm to cio2_bridge_init_swnode_names() Hans de Goede
2023-06-27 17:56 ` [PATCH 03/12] media: ipu3-cio2: Make cio2_bridge_init() take a regular struct device as argument Hans de Goede
2023-06-27 17:56 ` [PATCH 04/12] media: ipu3-cio2: Store dev pointer in struct cio2_bridge Hans de Goede
2023-06-27 17:56 ` [PATCH 05/12] media: ipu3-cio2: Only keep PLD around while parsing Hans de Goede
2023-06-27 17:56 ` [PATCH 06/12] media: ipu3-cio2: Add a cio2_bridge_parse_sensor_fwnode() helper function Hans de Goede
2023-06-27 20:39   ` Andy Shevchenko
2023-06-27 17:56 ` [PATCH 07/12] media: ipu3-cio2: Add a parse_sensor_fwnode callback to cio2_bridge_init() Hans de Goede
2023-06-27 17:56 ` [PATCH 08/12] media: ipu3-cio2: Add supported_sensors parameter " Hans de Goede
2023-06-27 17:56 ` [PATCH 09/12] media: ipu3-cio2: Move cio2_bridge_init() code into a new shared intel-cio2-bridge.ko Hans de Goede
2023-06-27 20:55   ` Andy Shevchenko
2023-06-28 12:53     ` Dan Scally
2023-06-27 17:56 ` [PATCH 10/12] media: atomisp: csi2-bridge: Switch to new common cio2_bridge_init() Hans de Goede
2023-06-27 17:56 ` [PATCH 11/12] media: intel-cio2-bridge: Add a runtime-pm device-link between VCM and sensor Hans de Goede
2023-06-27 21:03   ` Andy Shevchenko [this message]
2023-10-30  8:30   ` Bingbu Cao
2023-10-30  8:55     ` Sakari Ailus
2023-10-30  8:58       ` Hans de Goede
2023-10-30  9:23         ` Sakari Ailus
2023-11-01  6:26           ` Cao, Bingbu
2023-11-01  7:12             ` Sakari Ailus
2023-11-01  7:38               ` Cao, Bingbu
2023-11-02 13:35                 ` Andy Shevchenko
2023-11-02 13:54                   ` Hans de Goede
2023-11-03  2:01                     ` Bingbu Cao
2023-06-27 17:56 ` [PATCH 12/12] [RFC] media: dw9719: Drop hack to enable "vsio" regulator Hans de Goede
2023-06-27 21:04 ` [PATCH 00/12] media: intel-cio2-bridge: Add shared intel-cio2-bridge code, rework VCM instantiation Andy Shevchenko
2023-06-28  1:19 ` Cao, Bingbu
2023-06-28 13:57   ` Hans de Goede
2023-06-29  8:22     ` Cao, Bingbu
2023-06-29 20:45       ` Hans de Goede
2023-06-30  9:07 ` Sakari Ailus

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=ZJtOj3q6sTkl2gw5@smile.fi.intel.com \
    --to=andy@kernel.org \
    --cc=bingbu.cao@intel.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=hao.yao@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=hpa@redhat.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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