diff mbox series

[v6,13/15] media: ipu3-cio2: Defer probing until the PMIC is fully setup

Message ID 20211125165412.535063-14-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show
Series Add support for X86/ACPI camera sensor/PMIC setup with clk and regulator platform data | expand

Commit Message

Hans de Goede Nov. 25, 2021, 4:54 p.m. UTC
On devices where things are not fully describe in devicetree (1)
and where the code thus falls back to calling cio2_bridge_init(),
the i2c-clients for any VCMs also need to be instantiated manually.

The VCM can be probed by its driver as soon as the code instantiates
the i2c-client and this probing must not happen before the PMIC is
fully setup.

Make cio2_bridge_init() return -EPROBE_DEFER when the PMIC is not
fully-setup, deferring the probe of the ipu3-cio2 driver.

This is a preparation patch for adding VCM enumeration support to
the ipu3-cio2-bridge code.

1) Through embedding of devicetree info in the ACPI tables

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/pci/intel/ipu3/cio2-bridge.c | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Comments

kernel test robot Nov. 25, 2021, 9:31 p.m. UTC | #1
Hi Hans,

I love your patch! Perhaps something to improve:

[auto build test WARNING on media-tree/master]
[also build test WARNING on wsa/i2c/for-next broonie-regulator/for-next linus/master v5.16-rc2 next-20211125]
[cannot apply to clk/clk-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917
base:   git://linuxtv.org/media_tree.git master
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20211126/202111260530.KpKC5Rrw-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/e5cd2c79411cf24a2cabc5c7d2a222c1a3557460
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917
        git checkout e5cd2c79411cf24a2cabc5c7d2a222c1a3557460
        # save the config file to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/media/pci/intel/ipu3/cio2-bridge.c:321:5: warning: no previous prototype for 'cio2_bridge_sensors_are_ready' [-Wmissing-prototypes]
     321 | int cio2_bridge_sensors_are_ready(void)
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/cio2_bridge_sensors_are_ready +321 drivers/media/pci/intel/ipu3/cio2-bridge.c

   308	
   309	/*
   310	 * The VCM cannot be probed until the PMIC is completely setup. We cannot rely
   311	 * on -EPROBE_DEFER for this, since the consumer<->supplier relations between
   312	 * the VCM and regulators/clks are not described in ACPI, instead they are
   313	 * passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work
   314	 * for the clks/regulators the VCM i2c-clients must not be instantiated until
   315	 * the PMIC is fully setup.
   316	 *
   317	 * The sensor/VCM ACPI device has an ACPI _DEP on the PMIC, check this using the
   318	 * acpi_dev_ready_for_enumeration() helper, like the i2c-core-acpi code does
   319	 * for the sensors.
   320	 */
 > 321	int cio2_bridge_sensors_are_ready(void)
   322	{
   323		struct acpi_device *adev;
   324		bool ready = true;
   325		unsigned int i;
   326	
   327		for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) {
   328			const struct cio2_sensor_config *cfg =
   329				&cio2_supported_sensors[i];
   330	
   331			for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
   332				if (!adev->status.enabled)
   333					continue;
   334	
   335				if (!acpi_dev_ready_for_enumeration(adev))
   336					ready = false;
   337			}
   338		}
   339	
   340		return ready;
   341	}
   342	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hans de Goede Nov. 26, 2021, 11:01 a.m. UTC | #2
Hi,

On 11/25/21 22:31, kernel test robot wrote:
> Hi Hans,
> 
> I love your patch! Perhaps something to improve:
> 
> [auto build test WARNING on media-tree/master]
> [also build test WARNING on wsa/i2c/for-next broonie-regulator/for-next linus/master v5.16-rc2 next-20211125]
> [cannot apply to clk/clk-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917
> base:   git://linuxtv.org/media_tree.git master
> config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20211126/202111260530.KpKC5Rrw-lkp@intel.com/config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> reproduce (this is a W=1 build):
>         # https://github.com/0day-ci/linux/commit/e5cd2c79411cf24a2cabc5c7d2a222c1a3557460
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Hans-de-Goede/Add-support-for-X86-ACPI-camera-sensor-PMIC-setup-with-clk-and-regulator-platform-data/20211126-005917
>         git checkout e5cd2c79411cf24a2cabc5c7d2a222c1a3557460
>         # save the config file to linux build tree
>         make W=1 ARCH=i386 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
>>> drivers/media/pci/intel/ipu3/cio2-bridge.c:321:5: warning: no previous prototype for 'cio2_bridge_sensors_are_ready' [-Wmissing-prototypes]
>      321 | int cio2_bridge_sensors_are_ready(void)
>          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Right this needs to be static I will fix this for v7 of the series.

Regards,

Hans


> 
> 
> vim +/cio2_bridge_sensors_are_ready +321 drivers/media/pci/intel/ipu3/cio2-bridge.c
> 
>    308	
>    309	/*
>    310	 * The VCM cannot be probed until the PMIC is completely setup. We cannot rely
>    311	 * on -EPROBE_DEFER for this, since the consumer<->supplier relations between
>    312	 * the VCM and regulators/clks are not described in ACPI, instead they are
>    313	 * passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work
>    314	 * for the clks/regulators the VCM i2c-clients must not be instantiated until
>    315	 * the PMIC is fully setup.
>    316	 *
>    317	 * The sensor/VCM ACPI device has an ACPI _DEP on the PMIC, check this using the
>    318	 * acpi_dev_ready_for_enumeration() helper, like the i2c-core-acpi code does
>    319	 * for the sensors.
>    320	 */
>  > 321	int cio2_bridge_sensors_are_ready(void)
>    322	{
>    323		struct acpi_device *adev;
>    324		bool ready = true;
>    325		unsigned int i;
>    326	
>    327		for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) {
>    328			const struct cio2_sensor_config *cfg =
>    329				&cio2_supported_sensors[i];
>    330	
>    331			for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
>    332				if (!adev->status.enabled)
>    333					continue;
>    334	
>    335				if (!acpi_dev_ready_for_enumeration(adev))
>    336					ready = false;
>    337			}
>    338		}
>    339	
>    340		return ready;
>    341	}
>    342	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
>
diff mbox series

Patch

diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
index 1cbbcbf4e157..460ef7f78234 100644
--- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
+++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
@@ -308,6 +308,40 @@  static int cio2_bridge_connect_sensors(struct cio2_bridge *bridge,
 	return ret;
 }
 
+/*
+ * The VCM cannot be probed until the PMIC is completely setup. We cannot rely
+ * on -EPROBE_DEFER for this, since the consumer<->supplier relations between
+ * the VCM and regulators/clks are not described in ACPI, instead they are
+ * passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work
+ * for the clks/regulators the VCM i2c-clients must not be instantiated until
+ * the PMIC is fully setup.
+ *
+ * The sensor/VCM ACPI device has an ACPI _DEP on the PMIC, check this using the
+ * acpi_dev_ready_for_enumeration() helper, like the i2c-core-acpi code does
+ * for the sensors.
+ */
+int cio2_bridge_sensors_are_ready(void)
+{
+	struct acpi_device *adev;
+	bool ready = true;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) {
+		const struct cio2_sensor_config *cfg =
+			&cio2_supported_sensors[i];
+
+		for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
+			if (!adev->status.enabled)
+				continue;
+
+			if (!acpi_dev_ready_for_enumeration(adev))
+				ready = false;
+		}
+	}
+
+	return ready;
+}
+
 int cio2_bridge_init(struct pci_dev *cio2)
 {
 	struct device *dev = &cio2->dev;
@@ -316,6 +350,9 @@  int cio2_bridge_init(struct pci_dev *cio2)
 	unsigned int i;
 	int ret;
 
+	if (!cio2_bridge_sensors_are_ready())
+		return -EPROBE_DEFER;
+
 	bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
 	if (!bridge)
 		return -ENOMEM;