[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250423182332.GE2675@pendragon.ideasonboard.com>
Date: Wed, 23 Apr 2025 21:23:32 +0300
From: Laurent Pinchart <laurent.pinchart@...asonboard.com>
To: Mathis Foerst <mathis.foerst@...com>
Cc: linux-kernel@...r.kernel.org,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
linux-media@...r.kernel.org, devicetree@...r.kernel.org,
manuel.traut@...com, mathis.foerst@...hlke.com
Subject: Re: [PATCH v4 6/6] media: mt9m114: Set pad-slew-rate
Hi Mathis,
Thank you for the patch.
On Fri, Mar 07, 2025 at 10:31:40AM +0100, Mathis Foerst wrote:
> The MT9M114 supports the different slew rates (0 to 7) on the output pads.
> At the moment, this is hardcoded to 7 (the fastest rate).
> The user might want to change this values due to EMC requirements.
>
> Read the 'slew-rate' from the DT and configure the pad slew rates of
> the output pads accordingly in mt9m114_initialize().
> Remove the hardcoded slew rate setting from the mt9m114_init table.
>
> Signed-off-by: Mathis Foerst <mathis.foerst@...com>
> ---
> drivers/media/i2c/mt9m114.c | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/i2c/mt9m114.c b/drivers/media/i2c/mt9m114.c
> index 79c97ab19be9..fce24c587782 100644
> --- a/drivers/media/i2c/mt9m114.c
> +++ b/drivers/media/i2c/mt9m114.c
> @@ -42,6 +42,9 @@
> #define MT9M114_RESET_AND_MISC_CONTROL CCI_REG16(0x001a)
> #define MT9M114_RESET_SOC BIT(0)
> #define MT9M114_PAD_SLEW CCI_REG16(0x001e)
> +#define MT9M114_PAD_SLEW_MIN 0x00
> +#define MT9M114_PAD_SLEW_MAX 0x07
> +#define MT9M114_PAD_SLEW_DEFAULT 0x07
You can use decimal values here.
> #define MT9M114_PAD_CONTROL CCI_REG16(0x0032)
>
> /* XDMA registers */
> @@ -388,6 +391,7 @@ struct mt9m114 {
>
> unsigned int pixrate;
> bool streaming;
> + u32 pad_slew_rate;
>
> /* Pixel Array */
> struct {
> @@ -645,9 +649,6 @@ static const struct cci_reg_sequence mt9m114_init[] = {
> { MT9M114_CAM_SENSOR_CFG_FINE_INTEG_TIME_MAX, 1459 },
> { MT9M114_CAM_SENSOR_CFG_FINE_CORRECTION, 96 },
> { MT9M114_CAM_SENSOR_CFG_REG_0_DATA, 32 },
> -
> - /* Miscellaneous settings */
> - { MT9M114_PAD_SLEW, 0x0777 },
> };
>
> /* -----------------------------------------------------------------------------
> @@ -778,6 +779,13 @@ static int mt9m114_initialize(struct mt9m114 *sensor)
> if (ret < 0)
> return ret;
>
> + value = (sensor->pad_slew_rate & 0xF)
> + | (sensor->pad_slew_rate & 0xF) << 4
> + | (sensor->pad_slew_rate & 0xF) << 8;
No need for ' & 0xF' as you've ensured the slew rate value is in the
valid [0, 7] range.
> + cci_write(sensor->regmap, MT9M114_PAD_SLEW, value, &ret);
> + if (ret < 0)
> + return ret;
> +
> ret = mt9m114_set_state(sensor, MT9M114_SYS_STATE_ENTER_CONFIG_CHANGE);
> if (ret < 0)
> return ret;
> @@ -2357,6 +2365,8 @@ static int mt9m114_parse_dt(struct mt9m114 *sensor)
> {
> struct fwnode_handle *fwnode = dev_fwnode(&sensor->client->dev);
> struct fwnode_handle *ep;
> + struct device_node *dev_node = sensor->client->dev.of_node;
> + u32 slew_rate;
> int ret;
>
> ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
> @@ -2385,6 +2395,11 @@ static int mt9m114_parse_dt(struct mt9m114 *sensor)
> goto error;
> }
>
> + ret = of_property_read_u32(dev_node, "slew-rate", &slew_rate);
Direct usage of OF functions is discouraged. Use
device_property_read_u32() instead, which abstracts the firmware backend
(OF, ACPI, ...). Don't forget to include linux/property.h.
> + if (ret || slew_rate < MT9M114_PAD_SLEW_MIN || slew_rate > MT9M114_PAD_SLEW_MAX)
> + slew_rate = MT9M114_PAD_SLEW_DEFAULT;
If the value is erroneous, it indicates the DT is incorrect. I'd log a
message and return an error. As the DT property is optional, you can do
something like
sensor->slew_rate = MT9M114_PAD_SLEW_DEFAULT;
device_property_read_u32(&sensor->client.dev, "slew-rate",
&sensor->slew_rate);
if (sensor->slew_rate < MT9M114_PAD_SLEW_MIN ||
sensor->slew_rate > MT9M114_PAD_SLEW_MAX) {
dev_err(&sensor->client.dev, "Invalid slew-rate %u\n",
sensor->slew_rate);
return -EINVAL;
}
With this,
Reviewed-by: Laurent Pinchart <laurent.pinchart@...asonboard.com>
> + sensor->pad_slew_rate = slew_rate;
> +
> return 0;
>
> error:
--
Regards,
Laurent Pinchart
Powered by blists - more mailing lists