Re: [PATCH 1/2] OMAPDSS: Add Sil9022 DPI-HDMI Encoder Driver

2014-03-18 Thread Tomi Valkeinen
Hi Sathya,

On 18/03/14 12:07, Sathya Prakash M R wrote:
> Sil9022 DPI to HDMI Encoder driver is part of
> AM43xx SOC. Adding the basic Sil9022 driver

Umm it's not part of AM43xx SoC...

> HPD and Audio support is not present yet.
> 
> Signed-off-by: Sathya Prakash M R 
> ---
>  drivers/video/omap2/displays-new/Kconfig   |8 +
>  drivers/video/omap2/displays-new/Makefile  |1 +
>  drivers/video/omap2/displays-new/encoder-sil9022.c |  748 
> 
>  drivers/video/omap2/displays-new/encoder-sil9022.h |  105 +++
>  4 files changed, 862 insertions(+)
>  create mode 100644 drivers/video/omap2/displays-new/encoder-sil9022.c
>  create mode 100644 drivers/video/omap2/displays-new/encoder-sil9022.h
> 
> diff --git a/drivers/video/omap2/displays-new/Kconfig 
> b/drivers/video/omap2/displays-new/Kconfig
> index e6cfc38..9243dd7 100644
> --- a/drivers/video/omap2/displays-new/Kconfig
> +++ b/drivers/video/omap2/displays-new/Kconfig
> @@ -12,6 +12,14 @@ config DISPLAY_ENCODER_TPD12S015
> Driver for TPD12S015, which offers HDMI ESD protection and level
> shifting.
>  
> +config DISPLAY_ENCODER_SIL9022
> +tristate "Sil9022 DPI to HDMI Encoder"

Use a tab there.

> + depends on I2C
> + help
> +   Driver for Silicon Image Sil9022 DPI to HDMI encoder and
> +   a brief about Sil9022 can be found here:
> +   
> http://www.semiconductorstore.com/pdf/newsite/siliconimage/SiI9022a_pb.pdf
> +
>  config DISPLAY_CONNECTOR_DVI
>  tristate "DVI Connector"
>   depends on I2C
> diff --git a/drivers/video/omap2/displays-new/Makefile 
> b/drivers/video/omap2/displays-new/Makefile
> index 0323a8a..f3c8997 100644
> --- a/drivers/video/omap2/displays-new/Makefile
> +++ b/drivers/video/omap2/displays-new/Makefile
> @@ -1,5 +1,6 @@
>  obj-$(CONFIG_DISPLAY_ENCODER_TFP410) += encoder-tfp410.o
>  obj-$(CONFIG_DISPLAY_ENCODER_TPD12S015) += encoder-tpd12s015.o
> +obj-$(CONFIG_DISPLAY_ENCODER_SIL9022) += encoder-sil9022.o
>  obj-$(CONFIG_DISPLAY_CONNECTOR_DVI) += connector-dvi.o
>  obj-$(CONFIG_DISPLAY_CONNECTOR_HDMI) += connector-hdmi.o
>  obj-$(CONFIG_DISPLAY_CONNECTOR_ANALOG_TV) += connector-analog-tv.o
> diff --git a/drivers/video/omap2/displays-new/encoder-sil9022.c 
> b/drivers/video/omap2/displays-new/encoder-sil9022.c
> new file mode 100644
> index 000..411867b
> --- /dev/null
> +++ b/drivers/video/omap2/displays-new/encoder-sil9022.c
> @@ -0,0 +1,748 @@
> +/*
> + * Silicon image Sil9022 DPI-to-HDMI encoder driver

The chip is SiI9022, not Sil, according to the specs from Silicon Image.
I'm not sure what would be the best naming all around, but at least in
the comments and Kconfig help texts it would be best to use the correct
names to help finding the chip with google.

> + *
> + * Copyright (C) 2013 Texas Instruments
> + * Author: Sathya Prakash M R 
> + *
> + * This file is licensed under the terms of the GNU General Public License
> + * version 2. This program is licensed "as is" without any warranty of any
> + * kind, whether express or implied.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include "encoder-sil9022.h"

You should quickly go though the includes, and remove unneeded ones.
There are no platform devices here, nor is video/omap-panel-data.h needed.

> +struct panel_drv_data {
> + struct omap_dss_device dssdev;
> + struct omap_dss_device *in;
> + struct i2c_client *i2c_client;
> + int reset_gpio;
> + int data_lines;
> + struct regmap *regmap;
> + struct omap_video_timings timings;
> +};
> +
> +static struct regmap_config sil9022_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> +};

Can this be const?

> +
> +
> +#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
> +
> +static int sil9022_ddc_read(struct i2c_client *client,
> + unsigned char *buf, u16 count, u8 offset)
> +{
> + int r, retries;
> +
> + for (retries = 3; retries > 0; retries--) {
> + struct i2c_msg msgs[] = {
> + {
> + .addr   = 0x50,
> + .flags  = 0,
> + .len= 1,
> + .buf= &offset,
> + }, {
> + .addr   = 0x50,
> + .flags  = I2C_M_RD,
> + .len= count,
> + .buf= buf,
> + }
> + };
> +
> + r = i2c_transfer(client->adapter, msgs, 2);
> + if (r == 2)
> + return 0;
> +
> + if (r != -EAGAIN)
> + break;
> + }
> +
> + return r < 0 ? r : -EIO;
> +}
> +
> +static int sil9022_hw_ena

[PATCH 1/2] OMAPDSS: Add Sil9022 DPI-HDMI Encoder Driver

2014-03-18 Thread Sathya Prakash M R
Sil9022 DPI to HDMI Encoder driver is part of
AM43xx SOC. Adding the basic Sil9022 driver
HPD and Audio support is not present yet.

Signed-off-by: Sathya Prakash M R 
---
 drivers/video/omap2/displays-new/Kconfig   |8 +
 drivers/video/omap2/displays-new/Makefile  |1 +
 drivers/video/omap2/displays-new/encoder-sil9022.c |  748 
 drivers/video/omap2/displays-new/encoder-sil9022.h |  105 +++
 4 files changed, 862 insertions(+)
 create mode 100644 drivers/video/omap2/displays-new/encoder-sil9022.c
 create mode 100644 drivers/video/omap2/displays-new/encoder-sil9022.h

diff --git a/drivers/video/omap2/displays-new/Kconfig 
b/drivers/video/omap2/displays-new/Kconfig
index e6cfc38..9243dd7 100644
--- a/drivers/video/omap2/displays-new/Kconfig
+++ b/drivers/video/omap2/displays-new/Kconfig
@@ -12,6 +12,14 @@ config DISPLAY_ENCODER_TPD12S015
  Driver for TPD12S015, which offers HDMI ESD protection and level
  shifting.
 
+config DISPLAY_ENCODER_SIL9022
+tristate "Sil9022 DPI to HDMI Encoder"
+   depends on I2C
+   help
+ Driver for Silicon Image Sil9022 DPI to HDMI encoder and
+ a brief about Sil9022 can be found here:
+ 
http://www.semiconductorstore.com/pdf/newsite/siliconimage/SiI9022a_pb.pdf
+
 config DISPLAY_CONNECTOR_DVI
 tristate "DVI Connector"
depends on I2C
diff --git a/drivers/video/omap2/displays-new/Makefile 
b/drivers/video/omap2/displays-new/Makefile
index 0323a8a..f3c8997 100644
--- a/drivers/video/omap2/displays-new/Makefile
+++ b/drivers/video/omap2/displays-new/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_DISPLAY_ENCODER_TFP410) += encoder-tfp410.o
 obj-$(CONFIG_DISPLAY_ENCODER_TPD12S015) += encoder-tpd12s015.o
+obj-$(CONFIG_DISPLAY_ENCODER_SIL9022) += encoder-sil9022.o
 obj-$(CONFIG_DISPLAY_CONNECTOR_DVI) += connector-dvi.o
 obj-$(CONFIG_DISPLAY_CONNECTOR_HDMI) += connector-hdmi.o
 obj-$(CONFIG_DISPLAY_CONNECTOR_ANALOG_TV) += connector-analog-tv.o
diff --git a/drivers/video/omap2/displays-new/encoder-sil9022.c 
b/drivers/video/omap2/displays-new/encoder-sil9022.c
new file mode 100644
index 000..411867b
--- /dev/null
+++ b/drivers/video/omap2/displays-new/encoder-sil9022.c
@@ -0,0 +1,748 @@
+/*
+ * Silicon image Sil9022 DPI-to-HDMI encoder driver
+ *
+ * Copyright (C) 2013 Texas Instruments
+ * Author: Sathya Prakash M R 
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include "encoder-sil9022.h"
+
+struct panel_drv_data {
+   struct omap_dss_device dssdev;
+   struct omap_dss_device *in;
+   struct i2c_client *i2c_client;
+   int reset_gpio;
+   int data_lines;
+   struct regmap *regmap;
+   struct omap_video_timings timings;
+};
+
+static struct regmap_config sil9022_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+};
+
+
+#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
+
+static int sil9022_ddc_read(struct i2c_client *client,
+   unsigned char *buf, u16 count, u8 offset)
+{
+   int r, retries;
+
+   for (retries = 3; retries > 0; retries--) {
+   struct i2c_msg msgs[] = {
+   {
+   .addr   = 0x50,
+   .flags  = 0,
+   .len= 1,
+   .buf= &offset,
+   }, {
+   .addr   = 0x50,
+   .flags  = I2C_M_RD,
+   .len= count,
+   .buf= buf,
+   }
+   };
+
+   r = i2c_transfer(client->adapter, msgs, 2);
+   if (r == 2)
+   return 0;
+
+   if (r != -EAGAIN)
+   break;
+   }
+
+   return r < 0 ? r : -EIO;
+}
+
+static int sil9022_hw_enable(struct omap_dss_device *dssdev)
+{
+   int r = 0;
+   u8  vals[8];
+   unsigned int val;
+   u16 xres;
+   u16 yres;
+   u16 pclk;
+
+   struct panel_drv_data *ddata = to_panel_data(dssdev);
+   struct omap_video_timings *hdmi_timings = &ddata->timings;
+   struct i2c_client *sil9022_client = ddata->i2c_client;
+   struct regmap *map = ddata->regmap;
+
+   xres = hdmi_timings->x_res;
+   yres = hdmi_timings->y_res;
+   pclk = hdmi_timings->pixel_clock;
+
+   dev_info(dssdev->dev,
+"sii9022_ENABLE -> Timings\n"
+"pixel_clk = %d\n"
+