Hi Richard,

On Tue, Jan 06, 2026 at 11:30:41PM -0500, Richard Acayan wrote:
> A device tree compatible makes it possible for this driver to be used on
> Open Firmware devices. Initialization of power-managed resources such as
> the reset GPIO and voltage regulators can be specified in the device
> tree and handled by the driver. Add support for this so the Pixel 3a can
> use the driver.
> 
> Signed-off-by: Richard Acayan <[email protected]>
> Nacked-by: Krzysztof Kozlowski <[email protected]>

Uh-oh.

> ---
>  drivers/media/i2c/imx355.c | 116 ++++++++++++++++++++++++++++++++++---
>  1 file changed, 108 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
> index 776107efe386..4ac8495d1a3d 100644
> --- a/drivers/media/i2c/imx355.c
> +++ b/drivers/media/i2c/imx355.c
> @@ -3,9 +3,13 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/i2c.h>
>  #include <linux/module.h>
> +#include <linux/of.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/unaligned.h>
>  
>  #include <media/v4l2-ctrls.h>
> @@ -125,6 +129,15 @@ struct imx355 {
>        * Protect access to sensor v4l2 controls.
>        */
>       struct mutex mutex;
> +
> +     struct gpio_desc *reset_gpio;
> +     struct regulator_bulk_data *supplies;
> +};
> +
> +static const struct regulator_bulk_data imx355_supplies[] = {
> +     { .supply = "avdd" },
> +     { .supply = "dvdd" },
> +     { .supply = "dovdd" },
>  };
>  
>  static const struct imx355_reg imx355_global_regs[] = {
> @@ -1515,6 +1528,55 @@ static const struct v4l2_subdev_internal_ops 
> imx355_internal_ops = {
>       .open = imx355_open,
>  };
>  
> +static int imx355_power_off(struct device *dev)
> +{
> +     struct i2c_client *client = container_of(dev, struct i2c_client, dev);
> +     struct v4l2_subdev *sd = i2c_get_clientdata(client);
> +     struct imx355 *imx355 = to_imx355(sd);
> +
> +     gpiod_set_value_cansleep(imx355->reset_gpio, 1);
> +
> +     regulator_bulk_disable(ARRAY_SIZE(imx355_supplies), imx355->supplies);
> +     clk_disable_unprepare(imx355->clk);
> +
> +     return 0;
> +}
> +
> +static int imx355_power_on(struct device *dev)
> +{
> +     struct i2c_client *client = container_of(dev, struct i2c_client, dev);
> +     struct v4l2_subdev *sd = i2c_get_clientdata(client);
> +     struct imx355 *imx355 = to_imx355(sd);
> +     int ret;
> +
> +     ret = clk_prepare_enable(imx355->clk);
> +     if (ret) {
> +             dev_err(dev, "failed to enable clocks: %d\n", ret);
> +             return ret;
> +     }
> +
> +     ret = regulator_bulk_enable(ARRAY_SIZE(imx355_supplies),
> +                                 imx355->supplies);
> +     if (ret) {
> +             dev_err(dev, "failed to enable regulators: %d\n", ret);
> +             goto error_disable_clocks;
> +     }
> +
> +     gpiod_set_value_cansleep(imx355->reset_gpio, 1);
> +     usleep_range(5000, 5100);
> +     gpiod_set_value_cansleep(imx355->reset_gpio, 0);
> +     usleep_range(8000, 8100);

Where do these values come from? Apparently 1 ms is required (after lifting
xshutdown) before reading identification register and 10 ms is required
(from the same point of time) before streaming can be enabled.

> +
> +     return 0;
> +
> +error_disable_clocks:
> +     clk_disable_unprepare(imx355->clk);
> +     return ret;
> +}
> +
> +static DEFINE_RUNTIME_DEV_PM_OPS(imx355_pm_ops, imx355_power_off,
> +                              imx355_power_on, NULL);
> +
>  /* Initialize control handlers */
>  static int imx355_init_controls(struct imx355 *imx355)
>  {
> @@ -1689,16 +1751,26 @@ static int imx355_probe(struct i2c_client *client)
>                                    "external clock %lu is not supported\n",
>                                    freq);
>  
> -     /* Initialize subdev */
> -     v4l2_i2c_subdev_init(&imx355->sd, client, &imx355_subdev_ops);
> -
> -     /* Check module identity */
> -     ret = imx355_identify_module(imx355);
> +     ret = devm_regulator_bulk_get_const(imx355->dev,
> +                                   ARRAY_SIZE(imx355_supplies),
> +                                   imx355_supplies,
> +                                   &imx355->supplies);
>       if (ret) {
> -             dev_err(imx355->dev, "failed to find sensor: %d", ret);
> +             dev_err_probe(imx355->dev, ret, "could not get regulators");
>               goto error_probe;
>       }
>  
> +     imx355->reset_gpio = devm_gpiod_get_optional(imx355->dev, "reset",
> +                                                  GPIOD_OUT_LOW);

s/LOW/HIGH/

> +     if (IS_ERR(imx355->reset_gpio)) {
> +             ret = dev_err_probe(imx355->dev, PTR_ERR(imx355->reset_gpio),
> +                                 "failed to get gpios");
> +             goto error_probe;
> +     }
> +
> +     /* Initialize subdev */
> +     v4l2_i2c_subdev_init(&imx355->sd, client, &imx355_subdev_ops);
> +
>       imx355->hwcfg = imx355_get_hwcfg(imx355->dev);
>       if (!imx355->hwcfg) {
>               dev_err(imx355->dev, "failed to get hwcfg");
> @@ -1706,13 +1778,26 @@ static int imx355_probe(struct i2c_client *client)
>               goto error_probe;
>       }
>  
> +     ret = imx355_power_on(imx355->dev);
> +     if (ret) {
> +             dev_err(imx355->dev, "failed to power on sensor: %d", ret);
> +             goto error_probe;
> +     }
> +
> +     /* Check module identity */
> +     ret = imx355_identify_module(imx355);
> +     if (ret) {
> +             dev_err(imx355->dev, "failed to find sensor: %d", ret);
> +             goto error_power_off;
> +     }
> +
>       /* Set default mode to max resolution */
>       imx355->cur_mode = &supported_modes[0];
>  
>       ret = imx355_init_controls(imx355);
>       if (ret) {
>               dev_err(imx355->dev, "failed to init controls: %d", ret);
> -             goto error_probe;
> +             goto error_power_off;
>       }
>  
>       /* Initialize subdev */
> @@ -1752,6 +1837,9 @@ static int imx355_probe(struct i2c_client *client)
>  error_handler_free:
>       v4l2_ctrl_handler_free(imx355->sd.ctrl_handler);
>  
> +error_power_off:
> +     imx355_power_off(imx355->dev);
> +
>  error_probe:
>       mutex_destroy(&imx355->mutex);
>  
> @@ -1768,7 +1856,11 @@ static void imx355_remove(struct i2c_client *client)
>       v4l2_ctrl_handler_free(sd->ctrl_handler);
>  
>       pm_runtime_disable(imx355->dev);
> -     pm_runtime_set_suspended(imx355->dev);
> +
> +     if (!pm_runtime_status_suspended(imx355->dev)) {
> +             imx355_power_off(imx355->dev);
> +             pm_runtime_set_suspended(imx355->dev);
> +     }
>  
>       mutex_destroy(&imx355->mutex);
>  }
> @@ -1779,10 +1871,18 @@ static const struct acpi_device_id imx355_acpi_ids[] 
> __maybe_unused = {
>  };
>  MODULE_DEVICE_TABLE(acpi, imx355_acpi_ids);
>  
> +static const struct of_device_id imx355_match_table[] __maybe_unused = {

Please drop __maybe_unused; it's redundant.

> +     { .compatible = "sony,imx355", },
> +     { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, imx355_match_table);
> +
>  static struct i2c_driver imx355_i2c_driver = {
>       .driver = {
>               .name = "imx355",
>               .acpi_match_table = ACPI_PTR(imx355_acpi_ids),
> +             .of_match_table = imx355_match_table,
> +             .pm = &imx355_pm_ops,
>       },
>       .probe = imx355_probe,
>       .remove = imx355_remove,

-- 
Kind regards,

Sakari Ailus

Reply via email to