2022-06-29 16:06:33

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH v3 0/6] media: ov5693: cleanup code and add dts support

Hi All,
This series cleanup code on ov5693 driver and bring up dts support, also add
documentation for ov5693 camera sensor

Inspired by recently Quentin series:

- https://patchwork.kernel.org/project/linux-media/list/?series=64807

Tommaso Merciai (6):
media: ov5693: count num_supplies using array_size
media: ov5693: add dvdd into ov5693_supply_names array
media: ov5693: rename clk into xvclk
media: ov5693: move hw cfg functions into ov5693_hwcfg
media: dt-bindings: ov5693: document YAML binding
media: ov5693: add ov5693_of_match, dts support

.../bindings/media/i2c/ovti,ov5693.yaml | 106 ++++++++++++++++++
MAINTAINERS | 1 +
drivers/media/i2c/ov5693.c | 86 ++++++++------
3 files changed, 159 insertions(+), 34 deletions(-)
create mode 100644 Documentation/devicetree/bindings/media/i2c/ovti,ov5693.yaml

--
2.25.1


2022-06-29 16:07:05

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH v3 4/6] media: ov5693: move hw cfg functions into ov5693_hwcfg

Move hw configuration functions into ov5693_hwcfg. This is done to
separate the code that handle the hw cfg from probe in a clean way.
Add also support to get clock from "clock-frequency" fwnode in
ov5675_hwcfg function

Signed-off-by: Tommaso Merciai <[email protected]>
---
Changes since v2:
- Fix commit body as suggested by Sakari, Jacopo
- Add details to commit body as suggested Jacopo
- Move ov5693_check_hwcfg into ov5693_hwcfg
- Fix xvclk_rate position as suggested Jacopo

drivers/media/i2c/ov5693.c | 57 +++++++++++++++++++++++---------------
1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
index d2adc5513a21..3c805a5a5181 100644
--- a/drivers/media/i2c/ov5693.c
+++ b/drivers/media/i2c/ov5693.c
@@ -1339,16 +1339,48 @@ static int ov5693_get_regulators(struct ov5693_device *ov5693)
ov5693->supplies);
}

-static int ov5693_check_hwcfg(struct ov5693_device *ov5693)
+static int ov5693_hwcfg(struct ov5693_device *ov5693)
{
struct fwnode_handle *fwnode = dev_fwnode(ov5693->dev);
struct v4l2_fwnode_endpoint bus_cfg = {
.bus_type = V4L2_MBUS_CSI2_DPHY,
};
struct fwnode_handle *endpoint;
+ u32 xvclk_rate;
unsigned int i;
int ret;

+ ov5693->xvclk = devm_clk_get_optional(ov5693->dev, "xvclk");
+ if (IS_ERR(ov5693->xvclk))
+ return dev_err_probe(ov5693->dev, PTR_ERR(ov5693->xvclk),
+ "failed to get xvclk: %ld\n",
+ PTR_ERR(ov5693->xvclk));
+
+ if (ov5693->xvclk) {
+ xvclk_rate = clk_get_rate(ov5693->xvclk);
+ } else {
+ ret = fwnode_property_read_u32(fwnode, "clock-frequency",
+ &xvclk_rate);
+
+ if (ret) {
+ dev_err(ov5693->dev, "can't get clock frequency");
+ return ret;
+ }
+ }
+
+ if (xvclk_rate != OV5693_XVCLK_FREQ)
+ dev_warn(ov5693->dev, "Found clk freq %u, expected %u\n",
+ xvclk_rate, OV5693_XVCLK_FREQ);
+
+ ret = ov5693_configure_gpios(ov5693);
+ if (ret)
+ return ret;
+
+ ret = ov5693_get_regulators(ov5693);
+ if (ret)
+ return dev_err_probe(ov5693->dev, ret,
+ "Error fetching regulators\n");
+
endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
if (!endpoint)
return -EPROBE_DEFER; /* Could be provided by cio2-bridge */
@@ -1390,7 +1422,6 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693)
static int ov5693_probe(struct i2c_client *client)
{
struct ov5693_device *ov5693;
- u32 xvclk_rate;
int ret = 0;

ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
@@ -1400,7 +1431,7 @@ static int ov5693_probe(struct i2c_client *client)
ov5693->client = client;
ov5693->dev = &client->dev;

- ret = ov5693_check_hwcfg(ov5693);
+ ret = ov5693_hwcfg(ov5693);
if (ret)
return ret;

@@ -1408,26 +1439,6 @@ static int ov5693_probe(struct i2c_client *client)

v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);

- ov5693->xvclk = devm_clk_get(&client->dev, "xvclk");
- if (IS_ERR(ov5693->xvclk)) {
- dev_err(&client->dev, "Error getting clock\n");
- return PTR_ERR(ov5693->xvclk);
- }
-
- xvclk_rate = clk_get_rate(ov5693->xvclk);
- if (xvclk_rate != OV5693_XVCLK_FREQ)
- dev_warn(&client->dev, "Found clk freq %u, expected %u\n",
- xvclk_rate, OV5693_XVCLK_FREQ);
-
- ret = ov5693_configure_gpios(ov5693);
- if (ret)
- return ret;
-
- ret = ov5693_get_regulators(ov5693);
- if (ret)
- return dev_err_probe(&client->dev, ret,
- "Error fetching regulators\n");
-
ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
--
2.25.1

2022-06-29 16:08:00

by Tommaso Merciai

[permalink] [raw]
Subject: [PATCH v3 1/6] media: ov5693: count num_supplies using array_size

Instead of hardcode OV5693_NUM_SUPPLIES in a define is better use
ARRAY_SIZE function to count the number of supplies from
ov5693_supply_names array

Signed-off-by: Tommaso Merciai <[email protected]>
---
drivers/media/i2c/ov5693.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
index 117ff5403312..f410333c4c67 100644
--- a/drivers/media/i2c/ov5693.c
+++ b/drivers/media/i2c/ov5693.c
@@ -127,11 +127,15 @@
#define OV5693_LINK_FREQ_419_2MHZ 419200000
#define OV5693_PIXEL_RATE 167680000

-/* Miscellaneous */
-#define OV5693_NUM_SUPPLIES 2
-
#define to_ov5693_sensor(x) container_of(x, struct ov5693_device, sd)

+static const char * const ov5693_supply_names[] = {
+ "avdd", /* Analog power */
+ "dovdd", /* Digital I/O power */
+};
+
+#define OV5693_NUM_SUPPLIES ARRAY_SIZE(ov5693_supply_names)
+
struct ov5693_reg {
u32 reg;
u8 val;
@@ -352,11 +356,6 @@ static const s64 link_freq_menu_items[] = {
OV5693_LINK_FREQ_419_2MHZ
};

-static const char * const ov5693_supply_names[] = {
- "avdd",
- "dovdd",
-};
-
static const char * const ov5693_test_pattern_menu[] = {
"Disabled",
"Random Data",
--
2.25.1

2022-06-29 16:38:50

by jacopo mondi

[permalink] [raw]
Subject: Re: [PATCH v3 4/6] media: ov5693: move hw cfg functions into ov5693_hwcfg

Hi Tommaso,

On Wed, Jun 29, 2022 at 05:29:31PM +0200, Tommaso Merciai wrote:
> Move hw configuration functions into ov5693_hwcfg. This is done to
> separate the code that handle the hw cfg from probe in a clean way.
> Add also support to get clock from "clock-frequency" fwnode in
> ov5675_hwcfg function

Why ? :)

What about:

"Add support for ACPI-based platforms that specify the clock frequency by
using the "clock-frequency" property instead of specifying a clock
provider reference."

>
> Signed-off-by: Tommaso Merciai <[email protected]>

Not on this patch, but it seems you have not collected the tags
received on the previous version of the series.

> ---
> Changes since v2:
> - Fix commit body as suggested by Sakari, Jacopo
> - Add details to commit body as suggested Jacopo
> - Move ov5693_check_hwcfg into ov5693_hwcfg
> - Fix xvclk_rate position as suggested Jacopo

Also fixed a bug it seems :)

>
> drivers/media/i2c/ov5693.c | 57 +++++++++++++++++++++++---------------
> 1 file changed, 34 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
> index d2adc5513a21..3c805a5a5181 100644
> --- a/drivers/media/i2c/ov5693.c
> +++ b/drivers/media/i2c/ov5693.c
> @@ -1339,16 +1339,48 @@ static int ov5693_get_regulators(struct ov5693_device *ov5693)
> ov5693->supplies);
> }
>
> -static int ov5693_check_hwcfg(struct ov5693_device *ov5693)
> +static int ov5693_hwcfg(struct ov5693_device *ov5693)
> {
> struct fwnode_handle *fwnode = dev_fwnode(ov5693->dev);
> struct v4l2_fwnode_endpoint bus_cfg = {
> .bus_type = V4L2_MBUS_CSI2_DPHY,
> };
> struct fwnode_handle *endpoint;
> + u32 xvclk_rate;
> unsigned int i;
> int ret;
>
> + ov5693->xvclk = devm_clk_get_optional(ov5693->dev, "xvclk");
> + if (IS_ERR(ov5693->xvclk))
> + return dev_err_probe(ov5693->dev, PTR_ERR(ov5693->xvclk),
> + "failed to get xvclk: %ld\n",
> + PTR_ERR(ov5693->xvclk));
> +
> + if (ov5693->xvclk) {
> + xvclk_rate = clk_get_rate(ov5693->xvclk);
> + } else {
> + ret = fwnode_property_read_u32(fwnode, "clock-frequency",
> + &xvclk_rate);
> +
> + if (ret) {
> + dev_err(ov5693->dev, "can't get clock frequency");
> + return ret;
> + }
> + }

This now looks good to me, thanks!

> +
> + if (xvclk_rate != OV5693_XVCLK_FREQ)
> + dev_warn(ov5693->dev, "Found clk freq %u, expected %u\n",
> + xvclk_rate, OV5693_XVCLK_FREQ);
> +
> + ret = ov5693_configure_gpios(ov5693);
> + if (ret)
> + return ret;
> +
> + ret = ov5693_get_regulators(ov5693);
> + if (ret)
> + return dev_err_probe(ov5693->dev, ret,
> + "Error fetching regulators\n");
> +
> endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
> if (!endpoint)
> return -EPROBE_DEFER; /* Could be provided by cio2-bridge */
> @@ -1390,7 +1422,6 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693)
> static int ov5693_probe(struct i2c_client *client)
> {
> struct ov5693_device *ov5693;
> - u32 xvclk_rate;
> int ret = 0;

No need for ret to be intialized, but it was already like this...

The patch itself looks good
Reviewed-by: Jacopo Mondi <[email protected]>

Thanks
j

>
> ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
> @@ -1400,7 +1431,7 @@ static int ov5693_probe(struct i2c_client *client)
> ov5693->client = client;
> ov5693->dev = &client->dev;
>
> - ret = ov5693_check_hwcfg(ov5693);
> + ret = ov5693_hwcfg(ov5693);
> if (ret)
> return ret;
>
> @@ -1408,26 +1439,6 @@ static int ov5693_probe(struct i2c_client *client)
>
> v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
>
> - ov5693->xvclk = devm_clk_get(&client->dev, "xvclk");
> - if (IS_ERR(ov5693->xvclk)) {
> - dev_err(&client->dev, "Error getting clock\n");
> - return PTR_ERR(ov5693->xvclk);
> - }
> -
> - xvclk_rate = clk_get_rate(ov5693->xvclk);
> - if (xvclk_rate != OV5693_XVCLK_FREQ)
> - dev_warn(&client->dev, "Found clk freq %u, expected %u\n",
> - xvclk_rate, OV5693_XVCLK_FREQ);
> -
> - ret = ov5693_configure_gpios(ov5693);
> - if (ret)
> - return ret;
> -
> - ret = ov5693_get_regulators(ov5693);
> - if (ret)
> - return dev_err_probe(&client->dev, ret,
> - "Error fetching regulators\n");
> -
> ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
> ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
> --
> 2.25.1
>

2022-06-30 08:08:44

by Tommaso Merciai

[permalink] [raw]
Subject: Re: [PATCH v3 4/6] media: ov5693: move hw cfg functions into ov5693_hwcfg

Hi Jacopo,

On Wed, Jun 29, 2022 at 06:07:56PM +0200, Jacopo Mondi wrote:
> Hi Tommaso,
>
> On Wed, Jun 29, 2022 at 05:29:31PM +0200, Tommaso Merciai wrote:
> > Move hw configuration functions into ov5693_hwcfg. This is done to
> > separate the code that handle the hw cfg from probe in a clean way.
> > Add also support to get clock from "clock-frequency" fwnode in
> > ov5675_hwcfg function
>
> Why ? :)
>
> What about:
>
> "Add support for ACPI-based platforms that specify the clock frequency by
> using the "clock-frequency" property instead of specifying a clock
> provider reference."

Thanks for suggestion. I use this in v4

>
> >
> > Signed-off-by: Tommaso Merciai <[email protected]>
>
> Not on this patch, but it seems you have not collected the tags
> received on the previous version of the series.
>
> > ---
> > Changes since v2:
> > - Fix commit body as suggested by Sakari, Jacopo
> > - Add details to commit body as suggested Jacopo
> > - Move ov5693_check_hwcfg into ov5693_hwcfg
> > - Fix xvclk_rate position as suggested Jacopo
>
> Also fixed a bug it seems :)

You are right :'(

>
> >
> > drivers/media/i2c/ov5693.c | 57 +++++++++++++++++++++++---------------
> > 1 file changed, 34 insertions(+), 23 deletions(-)
> >
> > diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
> > index d2adc5513a21..3c805a5a5181 100644
> > --- a/drivers/media/i2c/ov5693.c
> > +++ b/drivers/media/i2c/ov5693.c
> > @@ -1339,16 +1339,48 @@ static int ov5693_get_regulators(struct ov5693_device *ov5693)
> > ov5693->supplies);
> > }
> >
> > -static int ov5693_check_hwcfg(struct ov5693_device *ov5693)
> > +static int ov5693_hwcfg(struct ov5693_device *ov5693)
> > {
> > struct fwnode_handle *fwnode = dev_fwnode(ov5693->dev);
> > struct v4l2_fwnode_endpoint bus_cfg = {
> > .bus_type = V4L2_MBUS_CSI2_DPHY,
> > };
> > struct fwnode_handle *endpoint;
> > + u32 xvclk_rate;
> > unsigned int i;
> > int ret;
> >
> > + ov5693->xvclk = devm_clk_get_optional(ov5693->dev, "xvclk");
> > + if (IS_ERR(ov5693->xvclk))
> > + return dev_err_probe(ov5693->dev, PTR_ERR(ov5693->xvclk),
> > + "failed to get xvclk: %ld\n",
> > + PTR_ERR(ov5693->xvclk));
> > +
> > + if (ov5693->xvclk) {
> > + xvclk_rate = clk_get_rate(ov5693->xvclk);
> > + } else {
> > + ret = fwnode_property_read_u32(fwnode, "clock-frequency",
> > + &xvclk_rate);
> > +
> > + if (ret) {
> > + dev_err(ov5693->dev, "can't get clock frequency");
> > + return ret;
> > + }
> > + }
>
> This now looks good to me, thanks!
>
> > +
> > + if (xvclk_rate != OV5693_XVCLK_FREQ)
> > + dev_warn(ov5693->dev, "Found clk freq %u, expected %u\n",
> > + xvclk_rate, OV5693_XVCLK_FREQ);
> > +
> > + ret = ov5693_configure_gpios(ov5693);
> > + if (ret)
> > + return ret;
> > +
> > + ret = ov5693_get_regulators(ov5693);
> > + if (ret)
> > + return dev_err_probe(ov5693->dev, ret,
> > + "Error fetching regulators\n");
> > +
> > endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
> > if (!endpoint)
> > return -EPROBE_DEFER; /* Could be provided by cio2-bridge */
> > @@ -1390,7 +1422,6 @@ static int ov5693_check_hwcfg(struct ov5693_device *ov5693)
> > static int ov5693_probe(struct i2c_client *client)
> > {
> > struct ov5693_device *ov5693;
> > - u32 xvclk_rate;
> > int ret = 0;
>
> No need for ret to be intialized, but it was already like this...

I can send patch later for this, or you prefer to fix this in this
series?

Regards,
Tommaso

>
> The patch itself looks good
> Reviewed-by: Jacopo Mondi <[email protected]>
>
> Thanks
> j
>
> >
> > ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
> > @@ -1400,7 +1431,7 @@ static int ov5693_probe(struct i2c_client *client)
> > ov5693->client = client;
> > ov5693->dev = &client->dev;
> >
> > - ret = ov5693_check_hwcfg(ov5693);
> > + ret = ov5693_hwcfg(ov5693);
> > if (ret)
> > return ret;
> >
> > @@ -1408,26 +1439,6 @@ static int ov5693_probe(struct i2c_client *client)
> >
> > v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
> >
> > - ov5693->xvclk = devm_clk_get(&client->dev, "xvclk");
> > - if (IS_ERR(ov5693->xvclk)) {
> > - dev_err(&client->dev, "Error getting clock\n");
> > - return PTR_ERR(ov5693->xvclk);
> > - }
> > -
> > - xvclk_rate = clk_get_rate(ov5693->xvclk);
> > - if (xvclk_rate != OV5693_XVCLK_FREQ)
> > - dev_warn(&client->dev, "Found clk freq %u, expected %u\n",
> > - xvclk_rate, OV5693_XVCLK_FREQ);
> > -
> > - ret = ov5693_configure_gpios(ov5693);
> > - if (ret)
> > - return ret;
> > -
> > - ret = ov5693_get_regulators(ov5693);
> > - if (ret)
> > - return dev_err_probe(&client->dev, ret,
> > - "Error fetching regulators\n");
> > -
> > ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> > ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
> > ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
> > --
> > 2.25.1
> >

--
Tommaso Merciai
Embedded Linux Engineer
[email protected]
__________________________________

Amarula Solutions SRL
Via Le Canevare 30, 31100 Treviso, Veneto, IT
T. +39 042 243 5310
[email protected]
http://www.amarulasolutions.com