2018-04-25 11:01:41

by Jacopo Mondi

[permalink] [raw]
Subject: [PATCH 0/2] media: i2c: mt9t112: Add OF tree support

Hello,

this small series add device tree support for the MT9T112 image
sensor.

As in the device tree bindings I used 'semi-standard' name for the
'powerdown' GPIO, I have changed that for all other users of the mt9t112
driver (SH Ecovec only).

A note on clock: as the mt9t112 driver expects to receive the PPL parameter
configuration from platform data (I know...), new OF users are only supported
with an external clock frequency of 24MHz.

Thanks
j

Jacopo Mondi (2):
dt-bindings: media: i2c: Add mt9t111 image sensor
media: i2c: mt9t112: Add device tree support

Documentation/devicetree/bindings/mt9t112.txt | 41 +++++++++++++
arch/sh/boards/mach-ecovec24/setup.c | 4 +-
drivers/media/i2c/mt9t112.c | 87 +++++++++++++++++++++++----
3 files changed, 118 insertions(+), 14 deletions(-)
create mode 100644 Documentation/devicetree/bindings/mt9t112.txt

--
2.7.4



2018-04-25 11:01:51

by Jacopo Mondi

[permalink] [raw]
Subject: [PATCH 2/2] media: i2c: mt9t112: Add device tree support

Add support for OF systems to mt9t112 image sensor driver.

As the devicetree bindings use standard name for 'powerdown' gpio, and while
at there, update the existing mt9t112 users to use the new name.

Signed-off-by: Jacopo Mondi <[email protected]>
---
arch/sh/boards/mach-ecovec24/setup.c | 4 +-
drivers/media/i2c/mt9t112.c | 87 +++++++++++++++++++++++++++++++-----
2 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index adc61d1..16de9ec 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -480,7 +480,7 @@ static struct gpiod_lookup_table tw9910_gpios = {
static struct gpiod_lookup_table mt9t112_0_gpios = {
.dev_id = "0-003c",
.table = {
- GPIO_LOOKUP("sh7724_pfc", GPIO_PTA3, "standby",
+ GPIO_LOOKUP("sh7724_pfc", GPIO_PTA3, "powerdown",
GPIO_ACTIVE_HIGH),
},
};
@@ -488,7 +488,7 @@ static struct gpiod_lookup_table mt9t112_0_gpios = {
static struct gpiod_lookup_table mt9t112_1_gpios = {
.dev_id = "1-003c",
.table = {
- GPIO_LOOKUP("sh7724_pfc", GPIO_PTA4, "standby",
+ GPIO_LOOKUP("sh7724_pfc", GPIO_PTA4, "powerdown",
GPIO_ACTIVE_HIGH),
},
};
diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c
index af8cca9..704e7fb 100644
--- a/drivers/media/i2c/mt9t112.c
+++ b/drivers/media/i2c/mt9t112.c
@@ -32,6 +32,7 @@

#include <media/i2c/mt9t112.h>
#include <media/v4l2-common.h>
+#include <media/v4l2-fwnode.h>
#include <media/v4l2-image-sizes.h>
#include <media/v4l2-subdev.h>

@@ -77,6 +78,15 @@
#define VAR(id, offset) _VAR(id, offset, 0x0000)
#define VAR8(id, offset) _VAR(id, offset, 0x8000)

+/*
+ * Default PLL configuration for 24MHz input clock
+ */
+static struct mt9t112_platform_data mt9t112_default_pdata_24MHz = {
+ .divider = {
+ 0x49, 0x6, 0, 6, 0, 9, 9, 6, 0,
+ },
+};
+
/************************************************************************
* struct
***********************************************************************/
@@ -88,6 +98,7 @@ struct mt9t112_format {
};

struct mt9t112_priv {
+ struct device *dev;
struct v4l2_subdev subdev;
struct mt9t112_platform_data *info;
struct i2c_client *client;
@@ -1066,13 +1077,39 @@ static int mt9t112_camera_probe(struct i2c_client *client)
return ret;
}

+static int mt9t112_parse_dt(struct mt9t112_priv *priv)
+{
+ struct fwnode_handle *fwnode = dev_fwnode(priv->dev);
+ struct fwnode_handle *ep;
+ struct v4l2_fwnode_endpoint vep;
+ int ret;
+
+ ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
+ if (IS_ERR_OR_NULL(ep)) {
+ dev_err(priv->dev, "No endpoint registered\n");
+ return PTR_ERR(ep);
+ }
+
+ ret = v4l2_fwnode_endpoint_parse(ep, &vep);
+ fwnode_handle_put(ep);
+ if (ret) {
+ dev_err(priv->dev, "Unable to parse endpoint: %d\n", ret);
+ return ret;
+ }
+
+ if (vep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
+ priv->info->flags = MT9T112_FLAG_PCLK_RISING_EDGE;
+
+ return 0;
+}
+
static int mt9t112_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{
struct mt9t112_priv *priv;
int ret;

- if (!client->dev.platform_data) {
+ if (!client->dev.of_node && !client->dev.platform_data) {
dev_err(&client->dev, "mt9t112: missing platform data!\n");
return -EINVAL;
}
@@ -1081,23 +1118,39 @@ static int mt9t112_probe(struct i2c_client *client,
if (!priv)
return -ENOMEM;

- priv->info = client->dev.platform_data;
priv->init_done = false;
-
- v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
-
- priv->clk = devm_clk_get(&client->dev, "extclk");
- if (PTR_ERR(priv->clk) == -ENOENT) {
+ priv->dev = &client->dev;
+
+ if (client->dev.platform_data) {
+ priv->info = client->dev.platform_data;
+
+ priv->clk = devm_clk_get(&client->dev, "extclk");
+ if (PTR_ERR(priv->clk) == -ENOENT) {
+ priv->clk = NULL;
+ } else if (IS_ERR(priv->clk)) {
+ dev_err(&client->dev,
+ "Unable to get clock \"extclk\"\n");
+ return PTR_ERR(priv->clk);
+ }
+ } else {
+ /*
+ * External clock frequencies != 24MHz are only supported
+ * for non-OF systems.
+ */
priv->clk = NULL;
- } else if (IS_ERR(priv->clk)) {
- dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
- return PTR_ERR(priv->clk);
+ priv->info = &mt9t112_default_pdata_24MHz;
+
+ ret = mt9t112_parse_dt(priv);
+ if (ret)
+ return ret;
}

- priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
+ v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
+
+ priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
GPIOD_OUT_HIGH);
if (IS_ERR(priv->standby_gpio)) {
- dev_err(&client->dev, "Unable to get gpio \"standby\"\n");
+ dev_err(&client->dev, "Unable to get gpio \"powerdown\"\n");
return PTR_ERR(priv->standby_gpio);
}

@@ -1124,9 +1177,19 @@ static const struct i2c_device_id mt9t112_id[] = {
};
MODULE_DEVICE_TABLE(i2c, mt9t112_id);

+#if IS_ENABLED(CONFIG_OF)
+static const struct of_device_id mt9t112_of_match[] = {
+ { .compatible = "micron,mt9t111", },
+ { .compatible = "micron,mt9t112", },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, mt9t112_of_match);
+#endif
+
static struct i2c_driver mt9t112_i2c_driver = {
.driver = {
.name = "mt9t112",
+ .of_match_table = of_match_ptr(mt9t112_of_match),
},
.probe = mt9t112_probe,
.remove = mt9t112_remove,
--
2.7.4


2018-04-25 11:02:22

by Jacopo Mondi

[permalink] [raw]
Subject: [PATCH 1/2] dt-bindings: media: i2c: Add mt9t111 image sensor

Add device tree bindings documentation for Micron MT9T111/MT9T112 image
sensors.

Signed-off-by: Jacopo Mondi <[email protected]>
---
Documentation/devicetree/bindings/mt9t112.txt | 41 +++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mt9t112.txt

diff --git a/Documentation/devicetree/bindings/mt9t112.txt b/Documentation/devicetree/bindings/mt9t112.txt
new file mode 100644
index 0000000..cbad475
--- /dev/null
+++ b/Documentation/devicetree/bindings/mt9t112.txt
@@ -0,0 +1,41 @@
+Micron 3.1Mp CMOS Digital Image Sensor
+--------------------------------------
+
+The Micron MT9T111 and MT9T112 are 1/4 inch 3.1Mp System-On-A-Chip (SOC) CMOS
+digital image sensors which support up to QXGA (2048x1536) image resolution in
+4/3 format.
+
+The sensors can be programmed through a two-wire serial interface and can
+work both in parallel data output mode as well as in MIPI CSI-2 mode.
+
+Required Properties:
+- compatible: shall be one of the following values
+ "micron,mt9t111" for MT9T111 sensors
+ "micron,mt9t112" for MT9T112 sensors
+
+Optional properties:
+- powerdown-gpios: reference to powerdown input GPIO signal. Pin name "STANDBY".
+ Active level is high.
+
+The device node shall contain one 'port' sub-node with one 'endpoint' child
+node, modeled accordingly to bindings described in:
+Documentation/devicetree/bindings/media/video-interfaces.txt
+
+Example:
+--------
+
+ mt9t112@3d {
+ compatible = "micron,mt9t112";
+ reg = <0x3d>;
+
+ powerdown-gpios = <&gpio4 2 GPIO_ACTIVE_HIGH>;
+
+ port {
+ mt9t112_out: endpoint {
+ pclk-sample = <1>;
+ remote-endpoint = <&ceu_in>;
+ };
+ };
+ };
+
+
--
2.7.4


2018-05-01 14:28:56

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: media: i2c: Add mt9t111 image sensor

On Wed, Apr 25, 2018 at 01:00:13PM +0200, Jacopo Mondi wrote:
> Add device tree bindings documentation for Micron MT9T111/MT9T112 image
> sensors.
>
> Signed-off-by: Jacopo Mondi <[email protected]>
> ---
> Documentation/devicetree/bindings/mt9t112.txt | 41 +++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mt9t112.txt
>
> diff --git a/Documentation/devicetree/bindings/mt9t112.txt b/Documentation/devicetree/bindings/mt9t112.txt
> new file mode 100644
> index 0000000..cbad475
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mt9t112.txt
> @@ -0,0 +1,41 @@
> +Micron 3.1Mp CMOS Digital Image Sensor
> +--------------------------------------
> +
> +The Micron MT9T111 and MT9T112 are 1/4 inch 3.1Mp System-On-A-Chip (SOC) CMOS
> +digital image sensors which support up to QXGA (2048x1536) image resolution in
> +4/3 format.
> +
> +The sensors can be programmed through a two-wire serial interface and can
> +work both in parallel data output mode as well as in MIPI CSI-2 mode.
> +
> +Required Properties:
> +- compatible: shall be one of the following values
> + "micron,mt9t111" for MT9T111 sensors
> + "micron,mt9t112" for MT9T112 sensors
> +
> +Optional properties:
> +- powerdown-gpios: reference to powerdown input GPIO signal. Pin name "STANDBY".
> + Active level is high.
> +
> +The device node shall contain one 'port' sub-node with one 'endpoint' child
> +node, modeled accordingly to bindings described in:
> +Documentation/devicetree/bindings/media/video-interfaces.txt
> +
> +Example:
> +--------
> +
> + mt9t112@3d {

camera-sensor@3d

Otherwise,

Reviewed-by: Rob Herring <[email protected]>

> + compatible = "micron,mt9t112";
> + reg = <0x3d>;
> +
> + powerdown-gpios = <&gpio4 2 GPIO_ACTIVE_HIGH>;
> +
> + port {
> + mt9t112_out: endpoint {
> + pclk-sample = <1>;
> + remote-endpoint = <&ceu_in>;
> + };
> + };
> + };
> +
> +
> --
> 2.7.4
>

2018-05-07 09:18:27

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: media: i2c: Add mt9t111 image sensor

Hi Jacopo,

On Wed, Apr 25, 2018 at 01:00:13PM +0200, Jacopo Mondi wrote:
> Add device tree bindings documentation for Micron MT9T111/MT9T112 image
> sensors.
>
> Signed-off-by: Jacopo Mondi <[email protected]>
> ---
> Documentation/devicetree/bindings/mt9t112.txt | 41 +++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/mt9t112.txt
>
> diff --git a/Documentation/devicetree/bindings/mt9t112.txt b/Documentation/devicetree/bindings/mt9t112.txt
> new file mode 100644
> index 0000000..cbad475
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mt9t112.txt
> @@ -0,0 +1,41 @@
> +Micron 3.1Mp CMOS Digital Image Sensor
> +--------------------------------------
> +
> +The Micron MT9T111 and MT9T112 are 1/4 inch 3.1Mp System-On-A-Chip (SOC) CMOS
> +digital image sensors which support up to QXGA (2048x1536) image resolution in
> +4/3 format.
> +
> +The sensors can be programmed through a two-wire serial interface and can
> +work both in parallel data output mode as well as in MIPI CSI-2 mode.
> +
> +Required Properties:
> +- compatible: shall be one of the following values
> + "micron,mt9t111" for MT9T111 sensors
> + "micron,mt9t112" for MT9T112 sensors
> +
> +Optional properties:
> +- powerdown-gpios: reference to powerdown input GPIO signal. Pin name "STANDBY".
> + Active level is high.
> +
> +The device node shall contain one 'port' sub-node with one 'endpoint' child
> +node, modeled accordingly to bindings described in:
> +Documentation/devicetree/bindings/media/video-interfaces.txt
> +
> +Example:
> +--------
> +
> + mt9t112@3d {
> + compatible = "micron,mt9t112";
> + reg = <0x3d>;
> +
> + powerdown-gpios = <&gpio4 2 GPIO_ACTIVE_HIGH>;
> +
> + port {
> + mt9t112_out: endpoint {
> + pclk-sample = <1>;

Could you document pclk-sample as an endpoint property? I'd suggest making
it optional with a default configuration.

> + remote-endpoint = <&ceu_in>;
> + };
> + };
> + };
> +
> +

--
Sakari Ailus
e-mail: [email protected]

2018-05-07 09:32:53

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH 2/2] media: i2c: mt9t112: Add device tree support

Hi Jacopo,

On Wed, Apr 25, 2018 at 01:00:14PM +0200, Jacopo Mondi wrote:
> Add support for OF systems to mt9t112 image sensor driver.
>
> As the devicetree bindings use standard name for 'powerdown' gpio, and while
> at there, update the existing mt9t112 users to use the new name.
>
> Signed-off-by: Jacopo Mondi <[email protected]>
> ---
> arch/sh/boards/mach-ecovec24/setup.c | 4 +-
> drivers/media/i2c/mt9t112.c | 87 +++++++++++++++++++++++++++++++-----
> 2 files changed, 77 insertions(+), 14 deletions(-)
>
> diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
> index adc61d1..16de9ec 100644
> --- a/arch/sh/boards/mach-ecovec24/setup.c
> +++ b/arch/sh/boards/mach-ecovec24/setup.c
> @@ -480,7 +480,7 @@ static struct gpiod_lookup_table tw9910_gpios = {
> static struct gpiod_lookup_table mt9t112_0_gpios = {
> .dev_id = "0-003c",
> .table = {
> - GPIO_LOOKUP("sh7724_pfc", GPIO_PTA3, "standby",
> + GPIO_LOOKUP("sh7724_pfc", GPIO_PTA3, "powerdown",
> GPIO_ACTIVE_HIGH),
> },
> };
> @@ -488,7 +488,7 @@ static struct gpiod_lookup_table mt9t112_0_gpios = {
> static struct gpiod_lookup_table mt9t112_1_gpios = {
> .dev_id = "1-003c",
> .table = {
> - GPIO_LOOKUP("sh7724_pfc", GPIO_PTA4, "standby",
> + GPIO_LOOKUP("sh7724_pfc", GPIO_PTA4, "powerdown",
> GPIO_ACTIVE_HIGH),
> },
> };
> diff --git a/drivers/media/i2c/mt9t112.c b/drivers/media/i2c/mt9t112.c
> index af8cca9..704e7fb 100644
> --- a/drivers/media/i2c/mt9t112.c
> +++ b/drivers/media/i2c/mt9t112.c
> @@ -32,6 +32,7 @@
>
> #include <media/i2c/mt9t112.h>
> #include <media/v4l2-common.h>
> +#include <media/v4l2-fwnode.h>
> #include <media/v4l2-image-sizes.h>
> #include <media/v4l2-subdev.h>
>
> @@ -77,6 +78,15 @@
> #define VAR(id, offset) _VAR(id, offset, 0x0000)
> #define VAR8(id, offset) _VAR(id, offset, 0x8000)
>
> +/*
> + * Default PLL configuration for 24MHz input clock
> + */
> +static struct mt9t112_platform_data mt9t112_default_pdata_24MHz = {
> + .divider = {
> + 0x49, 0x6, 0, 6, 0, 9, 9, 6, 0,
> + },
> +};
> +
> /************************************************************************
> * struct
> ***********************************************************************/
> @@ -88,6 +98,7 @@ struct mt9t112_format {
> };
>
> struct mt9t112_priv {
> + struct device *dev;
> struct v4l2_subdev subdev;
> struct mt9t112_platform_data *info;
> struct i2c_client *client;
> @@ -1066,13 +1077,39 @@ static int mt9t112_camera_probe(struct i2c_client *client)
> return ret;
> }
>
> +static int mt9t112_parse_dt(struct mt9t112_priv *priv)
> +{
> + struct fwnode_handle *fwnode = dev_fwnode(priv->dev);
> + struct fwnode_handle *ep;
> + struct v4l2_fwnode_endpoint vep;
> + int ret;
> +
> + ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
> + if (IS_ERR_OR_NULL(ep)) {
> + dev_err(priv->dev, "No endpoint registered\n");
> + return PTR_ERR(ep);
> + }
> +
> + ret = v4l2_fwnode_endpoint_parse(ep, &vep);
> + fwnode_handle_put(ep);
> + if (ret) {
> + dev_err(priv->dev, "Unable to parse endpoint: %d\n", ret);
> + return ret;
> + }
> +
> + if (vep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
> + priv->info->flags = MT9T112_FLAG_PCLK_RISING_EDGE;
> +
> + return 0;
> +}
> +
> static int mt9t112_probe(struct i2c_client *client,
> const struct i2c_device_id *did)
> {
> struct mt9t112_priv *priv;
> int ret;
>
> - if (!client->dev.platform_data) {
> + if (!client->dev.of_node && !client->dev.platform_data) {
> dev_err(&client->dev, "mt9t112: missing platform data!\n");
> return -EINVAL;
> }
> @@ -1081,23 +1118,39 @@ static int mt9t112_probe(struct i2c_client *client,
> if (!priv)
> return -ENOMEM;
>
> - priv->info = client->dev.platform_data;
> priv->init_done = false;
> -
> - v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> -
> - priv->clk = devm_clk_get(&client->dev, "extclk");
> - if (PTR_ERR(priv->clk) == -ENOENT) {
> + priv->dev = &client->dev;
> +
> + if (client->dev.platform_data) {
> + priv->info = client->dev.platform_data;
> +
> + priv->clk = devm_clk_get(&client->dev, "extclk");

extclk needs to be documented in DT binding documentation.

> + if (PTR_ERR(priv->clk) == -ENOENT) {
> + priv->clk = NULL;
> + } else if (IS_ERR(priv->clk)) {
> + dev_err(&client->dev,
> + "Unable to get clock \"extclk\"\n");
> + return PTR_ERR(priv->clk);
> + }
> + } else {
> + /*
> + * External clock frequencies != 24MHz are only supported
> + * for non-OF systems.
> + */

Shouldn't you actually set the frequency? Or perhaps even better to check
it, and use assigned-clocks and assigned-clock-rates properties?

> priv->clk = NULL;
> - } else if (IS_ERR(priv->clk)) {
> - dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
> - return PTR_ERR(priv->clk);
> + priv->info = &mt9t112_default_pdata_24MHz;
> +
> + ret = mt9t112_parse_dt(priv);
> + if (ret)
> + return ret;
> }
>
> - priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
> + v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> +
> + priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
> GPIOD_OUT_HIGH);
> if (IS_ERR(priv->standby_gpio)) {
> - dev_err(&client->dev, "Unable to get gpio \"standby\"\n");
> + dev_err(&client->dev, "Unable to get gpio \"powerdown\"\n");
> return PTR_ERR(priv->standby_gpio);
> }
>
> @@ -1124,9 +1177,19 @@ static const struct i2c_device_id mt9t112_id[] = {
> };
> MODULE_DEVICE_TABLE(i2c, mt9t112_id);
>
> +#if IS_ENABLED(CONFIG_OF)
> +static const struct of_device_id mt9t112_of_match[] = {
> + { .compatible = "micron,mt9t111", },
> + { .compatible = "micron,mt9t112", },
> + { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, mt9t112_of_match);
> +#endif
> +
> static struct i2c_driver mt9t112_i2c_driver = {
> .driver = {
> .name = "mt9t112",
> + .of_match_table = of_match_ptr(mt9t112_of_match),

No need to use of_match_ptr().

> },
> .probe = mt9t112_probe,
> .remove = mt9t112_remove,

--
Sakari Ailus
e-mail: [email protected]

2018-05-14 14:32:13

by jacopo mondi

[permalink] [raw]
Subject: Re: [PATCH 2/2] media: i2c: mt9t112: Add device tree support

Hi Sakari,

On Mon, May 07, 2018 at 12:32:19PM +0300, Sakari Ailus wrote:
> Hi Jacopo,
>
> On Wed, Apr 25, 2018 at 01:00:14PM +0200, Jacopo Mondi wrote:

[snip]

> > static int mt9t112_probe(struct i2c_client *client,
> > const struct i2c_device_id *did)
> > {
> > struct mt9t112_priv *priv;
> > int ret;
> >
> > - if (!client->dev.platform_data) {
> > + if (!client->dev.of_node && !client->dev.platform_data) {
> > dev_err(&client->dev, "mt9t112: missing platform data!\n");
> > return -EINVAL;
> > }
> > @@ -1081,23 +1118,39 @@ static int mt9t112_probe(struct i2c_client *client,
> > if (!priv)
> > return -ENOMEM;
> >
> > - priv->info = client->dev.platform_data;
> > priv->init_done = false;
> > -
> > - v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > -
> > - priv->clk = devm_clk_get(&client->dev, "extclk");
> > - if (PTR_ERR(priv->clk) == -ENOENT) {
> > + priv->dev = &client->dev;
> > +
> > + if (client->dev.platform_data) {
> > + priv->info = client->dev.platform_data;
> > +
> > + priv->clk = devm_clk_get(&client->dev, "extclk");
>
> extclk needs to be documented in DT binding documentation.
>
> > + if (PTR_ERR(priv->clk) == -ENOENT) {
> > + priv->clk = NULL;
> > + } else if (IS_ERR(priv->clk)) {
> > + dev_err(&client->dev,
> > + "Unable to get clock \"extclk\"\n");
> > + return PTR_ERR(priv->clk);
> > + }
> > + } else {
> > + /*
> > + * External clock frequencies != 24MHz are only supported
> > + * for non-OF systems.
> > + */
>
> Shouldn't you actually set the frequency? Or perhaps even better to check
> it, and use assigned-clocks and assigned-clock-rates properties?
>

I might be confused, but my intention was to use an external clock
reference, with a configurable frequency only in the platform data use
case. As you can see in this 'else' branch, in OF case, the priv->clk
field is null, and all the PLL and clock computations are performed
assuming a 24MHz input clock.

In my opinion, as the driver when running on OF systems does not
get any reference to 'extclk' clock, it should not be documented in
bindings. Do you agree?

Thanks
j

> > priv->clk = NULL;
> > - } else if (IS_ERR(priv->clk)) {
> > - dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
> > - return PTR_ERR(priv->clk);
> > + priv->info = &mt9t112_default_pdata_24MHz;
> > +
> > + ret = mt9t112_parse_dt(priv);
> > + if (ret)
> > + return ret;
> > }
> >
> > - priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
> > + v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > +
> > + priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
> > GPIOD_OUT_HIGH);
> > if (IS_ERR(priv->standby_gpio)) {
> > - dev_err(&client->dev, "Unable to get gpio \"standby\"\n");
> > + dev_err(&client->dev, "Unable to get gpio \"powerdown\"\n");
> > return PTR_ERR(priv->standby_gpio);
> > }
> >
> > @@ -1124,9 +1177,19 @@ static const struct i2c_device_id mt9t112_id[] = {
> > };
> > MODULE_DEVICE_TABLE(i2c, mt9t112_id);
> >
> > +#if IS_ENABLED(CONFIG_OF)
> > +static const struct of_device_id mt9t112_of_match[] = {
> > + { .compatible = "micron,mt9t111", },
> > + { .compatible = "micron,mt9t112", },
> > + { /* sentinel */ },
> > +};
> > +MODULE_DEVICE_TABLE(of, mt9t112_of_match);
> > +#endif
> > +
> > static struct i2c_driver mt9t112_i2c_driver = {
> > .driver = {
> > .name = "mt9t112",
> > + .of_match_table = of_match_ptr(mt9t112_of_match),
>
> No need to use of_match_ptr().
>
> > },
> > .probe = mt9t112_probe,
> > .remove = mt9t112_remove,
>
> --
> Sakari Ailus
> e-mail: [email protected]


Attachments:
(No filename) (3.70 kB)
signature.asc (836.00 B)
Download all attachments

2018-05-14 21:52:19

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH 2/2] media: i2c: mt9t112: Add device tree support

Hi Jacopo,

On Mon, May 14, 2018 at 04:30:44PM +0200, jacopo mondi wrote:
> Hi Sakari,
>
> On Mon, May 07, 2018 at 12:32:19PM +0300, Sakari Ailus wrote:
> > Hi Jacopo,
> >
> > On Wed, Apr 25, 2018 at 01:00:14PM +0200, Jacopo Mondi wrote:
>
> [snip]
>
> > > static int mt9t112_probe(struct i2c_client *client,
> > > const struct i2c_device_id *did)
> > > {
> > > struct mt9t112_priv *priv;
> > > int ret;
> > >
> > > - if (!client->dev.platform_data) {
> > > + if (!client->dev.of_node && !client->dev.platform_data) {
> > > dev_err(&client->dev, "mt9t112: missing platform data!\n");
> > > return -EINVAL;
> > > }
> > > @@ -1081,23 +1118,39 @@ static int mt9t112_probe(struct i2c_client *client,
> > > if (!priv)
> > > return -ENOMEM;
> > >
> > > - priv->info = client->dev.platform_data;
> > > priv->init_done = false;
> > > -
> > > - v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > > -
> > > - priv->clk = devm_clk_get(&client->dev, "extclk");
> > > - if (PTR_ERR(priv->clk) == -ENOENT) {
> > > + priv->dev = &client->dev;
> > > +
> > > + if (client->dev.platform_data) {
> > > + priv->info = client->dev.platform_data;
> > > +
> > > + priv->clk = devm_clk_get(&client->dev, "extclk");
> >
> > extclk needs to be documented in DT binding documentation.
> >
> > > + if (PTR_ERR(priv->clk) == -ENOENT) {
> > > + priv->clk = NULL;
> > > + } else if (IS_ERR(priv->clk)) {
> > > + dev_err(&client->dev,
> > > + "Unable to get clock \"extclk\"\n");
> > > + return PTR_ERR(priv->clk);
> > > + }
> > > + } else {
> > > + /*
> > > + * External clock frequencies != 24MHz are only supported
> > > + * for non-OF systems.
> > > + */
> >
> > Shouldn't you actually set the frequency? Or perhaps even better to check
> > it, and use assigned-clocks and assigned-clock-rates properties?
> >
>
> I might be confused, but my intention was to use an external clock
> reference, with a configurable frequency only in the platform data use
> case. As you can see in this 'else' branch, in OF case, the priv->clk
> field is null, and all the PLL and clock computations are performed
> assuming a 24MHz input clock.
>
> In my opinion, as the driver when running on OF systems does not
> get any reference to 'extclk' clock, it should not be documented in
> bindings. Do you agree?

Uh, isn't the clock generally controlled by the driver on OF-based systems?
You could assign the frequency in DT though, and not in the driver, but
that should be documented in binding documentation.

The register configuration the driver does not appear to be dependent on
the clock frequency, which suggests that it is only applicable to a
particular frequency --- 24 MHz?

>
> Thanks
> j
>
> > > priv->clk = NULL;
> > > - } else if (IS_ERR(priv->clk)) {
> > > - dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
> > > - return PTR_ERR(priv->clk);
> > > + priv->info = &mt9t112_default_pdata_24MHz;
> > > +
> > > + ret = mt9t112_parse_dt(priv);
> > > + if (ret)
> > > + return ret;
> > > }
> > >
> > > - priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
> > > + v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > > +
> > > + priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
> > > GPIOD_OUT_HIGH);
> > > if (IS_ERR(priv->standby_gpio)) {
> > > - dev_err(&client->dev, "Unable to get gpio \"standby\"\n");
> > > + dev_err(&client->dev, "Unable to get gpio \"powerdown\"\n");
> > > return PTR_ERR(priv->standby_gpio);
> > > }
> > >
> > > @@ -1124,9 +1177,19 @@ static const struct i2c_device_id mt9t112_id[] = {
> > > };
> > > MODULE_DEVICE_TABLE(i2c, mt9t112_id);
> > >
> > > +#if IS_ENABLED(CONFIG_OF)
> > > +static const struct of_device_id mt9t112_of_match[] = {
> > > + { .compatible = "micron,mt9t111", },
> > > + { .compatible = "micron,mt9t112", },
> > > + { /* sentinel */ },
> > > +};
> > > +MODULE_DEVICE_TABLE(of, mt9t112_of_match);
> > > +#endif
> > > +
> > > static struct i2c_driver mt9t112_i2c_driver = {
> > > .driver = {
> > > .name = "mt9t112",
> > > + .of_match_table = of_match_ptr(mt9t112_of_match),
> >
> > No need to use of_match_ptr().
> >
> > > },
> > > .probe = mt9t112_probe,
> > > .remove = mt9t112_remove,
> >
> > --
> > Sakari Ailus
> > e-mail: [email protected]



--
Sakari Ailus
e-mail: [email protected]

2018-05-15 07:12:25

by jacopo mondi

[permalink] [raw]
Subject: Re: [PATCH 2/2] media: i2c: mt9t112: Add device tree support

Hi Sakari,

On Tue, May 15, 2018 at 12:50:04AM +0300, Sakari Ailus wrote:
> Hi Jacopo,
>
> On Mon, May 14, 2018 at 04:30:44PM +0200, jacopo mondi wrote:
> > Hi Sakari,
> >
> > On Mon, May 07, 2018 at 12:32:19PM +0300, Sakari Ailus wrote:
> > > Hi Jacopo,
> > >
> > > On Wed, Apr 25, 2018 at 01:00:14PM +0200, Jacopo Mondi wrote:
> >
> > [snip]
> >
> > > > static int mt9t112_probe(struct i2c_client *client,
> > > > const struct i2c_device_id *did)
> > > > {
> > > > struct mt9t112_priv *priv;
> > > > int ret;
> > > >
> > > > - if (!client->dev.platform_data) {
> > > > + if (!client->dev.of_node && !client->dev.platform_data) {
> > > > dev_err(&client->dev, "mt9t112: missing platform data!\n");
> > > > return -EINVAL;
> > > > }
> > > > @@ -1081,23 +1118,39 @@ static int mt9t112_probe(struct i2c_client *client,
> > > > if (!priv)
> > > > return -ENOMEM;
> > > >
> > > > - priv->info = client->dev.platform_data;
> > > > priv->init_done = false;
> > > > -
> > > > - v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > > > -
> > > > - priv->clk = devm_clk_get(&client->dev, "extclk");
> > > > - if (PTR_ERR(priv->clk) == -ENOENT) {
> > > > + priv->dev = &client->dev;
> > > > +
> > > > + if (client->dev.platform_data) {
> > > > + priv->info = client->dev.platform_data;
> > > > +
> > > > + priv->clk = devm_clk_get(&client->dev, "extclk");
> > >
> > > extclk needs to be documented in DT binding documentation.
> > >
> > > > + if (PTR_ERR(priv->clk) == -ENOENT) {
> > > > + priv->clk = NULL;
> > > > + } else if (IS_ERR(priv->clk)) {
> > > > + dev_err(&client->dev,
> > > > + "Unable to get clock \"extclk\"\n");
> > > > + return PTR_ERR(priv->clk);
> > > > + }
> > > > + } else {
> > > > + /*
> > > > + * External clock frequencies != 24MHz are only supported
> > > > + * for non-OF systems.
> > > > + */
> > >
> > > Shouldn't you actually set the frequency? Or perhaps even better to check
> > > it, and use assigned-clocks and assigned-clock-rates properties?
> > >
> >
> > I might be confused, but my intention was to use an external clock
> > reference, with a configurable frequency only in the platform data use
> > case. As you can see in this 'else' branch, in OF case, the priv->clk
> > field is null, and all the PLL and clock computations are performed
> > assuming a 24MHz input clock.
> >
> > In my opinion, as the driver when running on OF systems does not
> > get any reference to 'extclk' clock, it should not be documented in
> > bindings. Do you agree?
>
> Uh, isn't the clock generally controlled by the driver on OF-based systems?
> You could assign the frequency in DT though, and not in the driver, but
> that should be documented in binding documentation.
>
> The register configuration the driver does not appear to be dependent on
> the clock frequency, which suggests that it is only applicable to a
> particular frequency --- 24 MHz?

Correct.
That's what the comment above here states...

/*
* External clock frequencies != 24MHz are only supported
* for non-OF systems.
*/

That's how it works: the driver expects to receive the PLL dividers
from platform data. It's ugly, I agree, but that's how it was. I do
not have time atm to poke around with PLL configuration, and I'm not
even sure I have the right documentation, so I made a 'default PLL
configuration' for 24MHz clock, copied from the platform data supplied
to the driver by the only user in mainline. In general, I would like
to have the driver calculate the PLL dividers based on the input clock
frequency, that should be supplied from DT. As this is not possible,
at the moment I made the driver only provide a PLL configuration for
24MHz, and that's the only clock the driver accepts.

+ priv->info = &mt9t112_default_pdata_24MHz;

Would you prefer I take a reference to an external clock, check it's
frequency and refuse it if != 24MHz?

By the way, I'm trying to run this driver with a camera module
connected to an ARM platform and so far I have not been able to
capture any image. The Ecovec I have (thanks Hans) has a camera module but the
cable is bad, so I can't test it on the platform the driver has
originally been developed on, but I assume on SH Ecovec it works properly.
Any confirmation from someone who has that board would be appreciate
though.

Thanks
j

>
> >
> > Thanks
> > j
> >
> > > > priv->clk = NULL;
> > > > - } else if (IS_ERR(priv->clk)) {
> > > > - dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
> > > > - return PTR_ERR(priv->clk);
> > > > + priv->info = &mt9t112_default_pdata_24MHz;
> > > > +
> > > > + ret = mt9t112_parse_dt(priv);
> > > > + if (ret)
> > > > + return ret;
> > > > }
> > > >
> > > > - priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
> > > > + v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
> > > > +
> > > > + priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
> > > > GPIOD_OUT_HIGH);
> > > > if (IS_ERR(priv->standby_gpio)) {
> > > > - dev_err(&client->dev, "Unable to get gpio \"standby\"\n");
> > > > + dev_err(&client->dev, "Unable to get gpio \"powerdown\"\n");
> > > > return PTR_ERR(priv->standby_gpio);
> > > > }
> > > >
> > > > @@ -1124,9 +1177,19 @@ static const struct i2c_device_id mt9t112_id[] = {
> > > > };
> > > > MODULE_DEVICE_TABLE(i2c, mt9t112_id);
> > > >
> > > > +#if IS_ENABLED(CONFIG_OF)
> > > > +static const struct of_device_id mt9t112_of_match[] = {
> > > > + { .compatible = "micron,mt9t111", },
> > > > + { .compatible = "micron,mt9t112", },
> > > > + { /* sentinel */ },
> > > > +};
> > > > +MODULE_DEVICE_TABLE(of, mt9t112_of_match);
> > > > +#endif
> > > > +
> > > > static struct i2c_driver mt9t112_i2c_driver = {
> > > > .driver = {
> > > > .name = "mt9t112",
> > > > + .of_match_table = of_match_ptr(mt9t112_of_match),
> > >
> > > No need to use of_match_ptr().
> > >
> > > > },
> > > > .probe = mt9t112_probe,
> > > > .remove = mt9t112_remove,
> > >
> > > --
> > > Sakari Ailus
> > > e-mail: [email protected]
>
>
>
> --
> Sakari Ailus
> e-mail: [email protected]


Attachments:
(No filename) (6.18 kB)
signature.asc (836.00 B)
Download all attachments