Message ID | 20220329090133.338073-4-jacopo@jmondi.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | media: i2c: ov5670: OF support, runtime_pm, regulators | expand |
Hi Jacopo, On Tue, Mar 29, 2022 at 11:01:28AM +0200, Jacopo Mondi wrote: > Add support for probing the main system clock using the common clock > framework and its OF bindings. > > Maintain ACPI compatibility by falling back to parse 'clock-frequency'. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > --- > drivers/media/i2c/ov5670.c | 22 ++++++++++++++++++---- > 1 file changed, 18 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c > index 721441024598..1cc312981c82 100644 > --- a/drivers/media/i2c/ov5670.c > +++ b/drivers/media/i2c/ov5670.c > @@ -2,6 +2,7 @@ > // Copyright (c) 2017 Intel Corporation. > > #include <linux/acpi.h> > +#include <linux/clk.h> > #include <linux/i2c.h> > #include <linux/mod_devicetable.h> > #include <linux/module.h> > @@ -2475,13 +2476,10 @@ static int ov5670_probe(struct i2c_client *client) > struct ov5670 *ov5670; > const char *err_msg; > u32 input_clk = 0; > + struct clk *clk; > bool full_power; > int ret; > > - device_property_read_u32(&client->dev, "clock-frequency", &input_clk); > - if (input_clk != 19200000) > - return -EINVAL; > - > ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL); > if (!ov5670) { > ret = -ENOMEM; > @@ -2489,6 +2487,22 @@ static int ov5670_probe(struct i2c_client *client) > goto error_print; > } > > + /* OF uses the common clock framework, ACPI uses "clock-frequency". */ > + if (is_of_node(dev_fwnode(&client->dev))) { > + clk = devm_clk_get(&client->dev, NULL); > + if (IS_ERR(clk)) > + return dev_err_probe(&client->dev, PTR_ERR(clk), > + "error getting clock\n"); > + > + input_clk = clk_get_rate(clk); > + } else { > + device_property_read_u32(&client->dev, "clock-frequency", > + &input_clk); > + } > + > + if (input_clk != 19200000) > + return -EINVAL; You could tell what that wrong frequency is. Up to you. > + > /* Initialize subdev */ > v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops); >
diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 721441024598..1cc312981c82 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -2,6 +2,7 @@ // Copyright (c) 2017 Intel Corporation. #include <linux/acpi.h> +#include <linux/clk.h> #include <linux/i2c.h> #include <linux/mod_devicetable.h> #include <linux/module.h> @@ -2475,13 +2476,10 @@ static int ov5670_probe(struct i2c_client *client) struct ov5670 *ov5670; const char *err_msg; u32 input_clk = 0; + struct clk *clk; bool full_power; int ret; - device_property_read_u32(&client->dev, "clock-frequency", &input_clk); - if (input_clk != 19200000) - return -EINVAL; - ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL); if (!ov5670) { ret = -ENOMEM; @@ -2489,6 +2487,22 @@ static int ov5670_probe(struct i2c_client *client) goto error_print; } + /* OF uses the common clock framework, ACPI uses "clock-frequency". */ + if (is_of_node(dev_fwnode(&client->dev))) { + clk = devm_clk_get(&client->dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(&client->dev, PTR_ERR(clk), + "error getting clock\n"); + + input_clk = clk_get_rate(clk); + } else { + device_property_read_u32(&client->dev, "clock-frequency", + &input_clk); + } + + if (input_clk != 19200000) + return -EINVAL; + /* Initialize subdev */ v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
Add support for probing the main system clock using the common clock framework and its OF bindings. Maintain ACPI compatibility by falling back to parse 'clock-frequency'. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- drivers/media/i2c/ov5670.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)