diff mbox series

[4/4] media: i2c: imx219: Create DPHY helper function

Message ID 20220412135534.2796158-5-aford173@gmail.com (mailing list archive)
State New, archived
Headers show
Series media: i2c: imx219: Enable variable xclk and 4-lane | expand

Commit Message

Adam Ford April 12, 2022, 1:55 p.m. UTC
In the table of modes, each mode sets the DPHY to auto.
Create a helper function which does the same thing while
removing the entry for auto DPHY from ever mode entry.

Signed-off-by: Adam Ford <aford173@gmail.com>
---
 drivers/media/i2c/imx219.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

Comments

Dave Stevenson April 25, 2022, 4:07 p.m. UTC | #1
Hi Adam

On Tue, 12 Apr 2022 at 14:55, Adam Ford <aford173@gmail.com> wrote:
>
> In the table of modes, each mode sets the DPHY to auto.
> Create a helper function which does the same thing while
> removing the entry for auto DPHY from ever mode entry.

s/ever/every

>
> Signed-off-by: Adam Ford <aford173@gmail.com>
> ---
>  drivers/media/i2c/imx219.c | 24 ++++++++++++++++++++----
>  1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index 08e7d0e72430..bb0bc1b8d91c 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -35,6 +35,10 @@
>  #define IMX219_MODE_STANDBY            0x00
>  #define IMX219_MODE_STREAMING          0x01
>
> +
> +#define IMX219_REG_DPHY_CTRL           0x0128
> +#define IMX219_DPHY_AUTO               0
> +
>  /* Chip ID */
>  #define IMX219_REG_CHIP_ID             0x0000
>  #define IMX219_CHIP_ID                 0x0219
> @@ -183,7 +187,6 @@ static const struct imx219_reg pll_clk_table[] = {
>   * 3280x2464 = mode 2, 1920x1080 = mode 1, 1640x1232 = mode 4, 640x480 = mode 7.
>   */
>  static const struct imx219_reg mode_3280x2464_regs[] = {
> -       {0x0128, 0x00},
>         {0x012b, 0x00},
>         {0x0164, 0x00},
>         {0x0165, 0x00},
> @@ -222,7 +225,6 @@ static const struct imx219_reg mode_3280x2464_regs[] = {
>  };
>
>  static const struct imx219_reg mode_1920_1080_regs[] = {
> -       {0x0128, 0x00},
>         {0x012b, 0x00},
>         {0x0162, 0x0d},
>         {0x0163, 0x78},
> @@ -261,7 +263,6 @@ static const struct imx219_reg mode_1920_1080_regs[] = {
>  };
>
>  static const struct imx219_reg mode_1640_1232_regs[] = {
> -       {0x0128, 0x00},
>         {0x012b, 0x00},
>         {0x0164, 0x00},
>         {0x0165, 0x00},
> @@ -300,7 +301,6 @@ static const struct imx219_reg mode_1640_1232_regs[] = {
>  };
>
>  static const struct imx219_reg mode_640_480_regs[] = {
> -       {0x0128, 0x00},
>         {0x012b, 0x00},
>         {0x0162, 0x0d},
>         {0x0163, 0x78},
> @@ -999,6 +999,15 @@ static int imx219_get_selection(struct v4l2_subdev *sd,
>         return -EINVAL;
>  }
>
> +static int imx219_enable_dphy(struct imx219 *imx219, u8 mode)
> +{
> +       int ret;
> +
> +       ret = imx219_write_reg(imx219, IMX219_REG_DPHY_CTRL,
> +                              IMX219_REG_VALUE_08BIT, mode);

Is there a specific reason to extract this one register, but leave the block
    {0x455e, 0x00},
    {0x471e, 0x4b},
    {0x4767, 0x0f},
    {0x4750, 0x14},
    {0x4540, 0x00},
    {0x47b4, 0x14},
    {0x4713, 0x30},
    {0x478b, 0x10},
    {0x478f, 0x10},
    {0x4793, 0x10},
    {0x4797, 0x0e},
    {0x479b, 0x0e},
    {0x0162, 0x0d},
    {0x0163, 0x78},
that appear to also be common to all modes.

Other drivers break that lot out into a global registers array that is
always sent, rather than individual register writes.
Having this one register extra write as a new function is actually
likely to increase the size of the module overall, instead of reducing
it.

  Dave

> +       return ret;
> +};
> +
>  static int imx219_configure_lanes(struct imx219 *imx219)
>  {
>         int ret;
> @@ -1081,6 +1090,13 @@ static int imx219_start_streaming(struct imx219 *imx219)
>                 goto err_rpm_put;
>         }
>
> +       /* Setup DPHY */
> +       ret = imx219_enable_dphy(imx219, IMX219_DPHY_AUTO);
> +       if (ret) {
> +               dev_err(&client->dev, "%s failed to configure dphy\n", __func__);
> +               goto err_rpm_put;
> +       }
> +
>         /* Configure clock based on reference clock frequency */
>         imx219_set_exck_freq(imx219);
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 08e7d0e72430..bb0bc1b8d91c 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -35,6 +35,10 @@ 
 #define IMX219_MODE_STANDBY		0x00
 #define IMX219_MODE_STREAMING		0x01
 
+
+#define IMX219_REG_DPHY_CTRL		0x0128
+#define IMX219_DPHY_AUTO		0
+
 /* Chip ID */
 #define IMX219_REG_CHIP_ID		0x0000
 #define IMX219_CHIP_ID			0x0219
@@ -183,7 +187,6 @@  static const struct imx219_reg pll_clk_table[] = {
  * 3280x2464 = mode 2, 1920x1080 = mode 1, 1640x1232 = mode 4, 640x480 = mode 7.
  */
 static const struct imx219_reg mode_3280x2464_regs[] = {
-	{0x0128, 0x00},
 	{0x012b, 0x00},
 	{0x0164, 0x00},
 	{0x0165, 0x00},
@@ -222,7 +225,6 @@  static const struct imx219_reg mode_3280x2464_regs[] = {
 };
 
 static const struct imx219_reg mode_1920_1080_regs[] = {
-	{0x0128, 0x00},
 	{0x012b, 0x00},
 	{0x0162, 0x0d},
 	{0x0163, 0x78},
@@ -261,7 +263,6 @@  static const struct imx219_reg mode_1920_1080_regs[] = {
 };
 
 static const struct imx219_reg mode_1640_1232_regs[] = {
-	{0x0128, 0x00},
 	{0x012b, 0x00},
 	{0x0164, 0x00},
 	{0x0165, 0x00},
@@ -300,7 +301,6 @@  static const struct imx219_reg mode_1640_1232_regs[] = {
 };
 
 static const struct imx219_reg mode_640_480_regs[] = {
-	{0x0128, 0x00},
 	{0x012b, 0x00},
 	{0x0162, 0x0d},
 	{0x0163, 0x78},
@@ -999,6 +999,15 @@  static int imx219_get_selection(struct v4l2_subdev *sd,
 	return -EINVAL;
 }
 
+static int imx219_enable_dphy(struct imx219 *imx219, u8 mode)
+{
+	int ret;
+
+	ret = imx219_write_reg(imx219, IMX219_REG_DPHY_CTRL,
+			       IMX219_REG_VALUE_08BIT, mode);
+	return ret;
+};
+
 static int imx219_configure_lanes(struct imx219 *imx219)
 {
 	int ret;
@@ -1081,6 +1090,13 @@  static int imx219_start_streaming(struct imx219 *imx219)
 		goto err_rpm_put;
 	}
 
+	/* Setup DPHY */
+	ret = imx219_enable_dphy(imx219, IMX219_DPHY_AUTO);
+	if (ret) {
+		dev_err(&client->dev, "%s failed to configure dphy\n", __func__);
+		goto err_rpm_put;
+	}
+
 	/* Configure clock based on reference clock frequency */
 	imx219_set_exck_freq(imx219);