Re: [PATCH v3 9/9] drm/panel: Add driver for the Toppoly TD043MTEA1 panel

2019-08-13 Thread Sam Ravnborg
On Tue, Aug 13, 2019 at 04:33:11PM +0300, Laurent Pinchart wrote:
> This panel is used on the OMAP3 Pandora.
> 
> The code is based on the omapdrm-specific panel-tpo-td043mtea1 driver.
> 
> Signed-off-by: Laurent Pinchart 
Reviewed-by: Sam Ravnborg 

> ---
> Changes since v2:
> 
> - Call drm_panel_disable() in .remove() handler
> 
> Changes since v1:
> 
> - Mention boards using the panel in Kconfig
> - Renamed td043mtea1_device to td043mtea1_panel
> - Fixed typo in Toppoly name
> - Comments updates
> - Store width_mm and height_mm in drm_display_mode
> - Use drm_panel_unprepare() in .remove() handler
> - Replace enable/disable with prepare/unprepare
> ---
>  drivers/gpu/drm/panel/Kconfig|   7 +
>  drivers/gpu/drm/panel/Makefile   |   1 +
>  drivers/gpu/drm/panel/panel-tpo-td043mtea1.c | 509 +++
>  3 files changed, 517 insertions(+)
>  create mode 100644 drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
> 
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
> index c2689420d2dd..f152bc4eeb53 100644
> --- a/drivers/gpu/drm/panel/Kconfig
> +++ b/drivers/gpu/drm/panel/Kconfig
> @@ -332,6 +332,13 @@ config DRM_PANEL_TPO_TD028TTEC1
> Say Y here if you want to enable support for TPO TD028TTEC1 480x640
> 2.8" panel (found on the OpenMoko Neo FreeRunner and Neo 1973).
>  
> +config DRM_PANEL_TPO_TD043MTEA1
> + tristate "Toppoly (TPO) TD043MTEA1 panel driver"
> + depends on GPIOLIB && OF && REGULATOR && SPI
> + help
> +   Say Y here if you want to enable support for TPO TD043MTEA1 800x480
> +   4.3" panel (found on the OMAP3 Pandora board).
> +
>  config DRM_PANEL_TPO_TPG110
>   tristate "TPO TPG 800x400 panel"
>   depends on OF && SPI && GPIOLIB
> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
> index 27b776737ad3..b6cd39fe0f20 100644
> --- a/drivers/gpu/drm/panel/Makefile
> +++ b/drivers/gpu/drm/panel/Makefile
> @@ -35,5 +35,6 @@ obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7701) += 
> panel-sitronix-st7701.o
>  obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7789V) += panel-sitronix-st7789v.o
>  obj-$(CONFIG_DRM_PANEL_SONY_ACX565AKM) += panel-sony-acx565akm.o
>  obj-$(CONFIG_DRM_PANEL_TPO_TD028TTEC1) += panel-tpo-td028ttec1.o
> +obj-$(CONFIG_DRM_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o
>  obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
>  obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
> diff --git a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c 
> b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
> new file mode 100644
> index ..71824a334af7
> --- /dev/null
> +++ b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
> @@ -0,0 +1,509 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Toppoly TD043MTEA1 Panel Driver
> + *
> + * Copyright (C) 2019 Texas Instruments Incorporated
> + *
> + * Based on the omapdrm-specific panel-tpo-td043mtea1 driver
> + *
> + * Author: Gražvydas Ignotas 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#define TPO_R02_MODE(x)  ((x) & 7)
> +#define TPO_R02_MODE_800x480 7
> +#define TPO_R02_NCLK_RISING  BIT(3)
> +#define TPO_R02_HSYNC_HIGH   BIT(4)
> +#define TPO_R02_VSYNC_HIGH   BIT(5)
> +
> +#define TPO_R03_NSTANDBY BIT(0)
> +#define TPO_R03_EN_CP_CLKBIT(1)
> +#define TPO_R03_EN_VGL_PUMP  BIT(2)
> +#define TPO_R03_EN_PWM   BIT(3)
> +#define TPO_R03_DRIVING_CAP_100  BIT(4)
> +#define TPO_R03_EN_PRE_CHARGEBIT(6)
> +#define TPO_R03_SOFTWARE_CTL BIT(7)
> +
> +#define TPO_R04_NFLIP_H  BIT(0)
> +#define TPO_R04_NFLIP_V  BIT(1)
> +#define TPO_R04_CP_CLK_FREQ_1H   BIT(2)
> +#define TPO_R04_VGL_FREQ_1H  BIT(4)
> +
> +#define TPO_R03_VAL_NORMAL \
> + (TPO_R03_NSTANDBY | TPO_R03_EN_CP_CLK | TPO_R03_EN_VGL_PUMP | \
> +  TPO_R03_EN_PWM | TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \
> +  TPO_R03_SOFTWARE_CTL)
> +
> +#define TPO_R03_VAL_STANDBY \
> + (TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \
> +  TPO_R03_SOFTWARE_CTL)
> +
> +static const u16 td043mtea1_def_gamma[12] = {
> + 105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023
> +};
> +
> +struct td043mtea1_panel {
> + struct drm_panel panel;
> +
> + struct spi_device *spi;
> + struct regulator *vcc_reg;
> + struct gpio_desc *reset_gpio;
> +
> + unsigned int mode;
> + u16 gamma[12];
> + bool vmirror;
> + bool powered_on;
> + bool spi_suspended;
> + bool power_on_resume;
> +};
> +
> +#define to_td043mtea1_device(p) container_of(p, struct td043mtea1_panel, 
> panel)
> +
> +/* 
> -
> + * Hardware Access
> + */
> +
> +static int td043mtea1_write(struct td043mtea1_panel *lcd, u8 add

[PATCH v3 9/9] drm/panel: Add driver for the Toppoly TD043MTEA1 panel

2019-08-13 Thread Laurent Pinchart
This panel is used on the OMAP3 Pandora.

The code is based on the omapdrm-specific panel-tpo-td043mtea1 driver.

Signed-off-by: Laurent Pinchart 
---
Changes since v2:

- Call drm_panel_disable() in .remove() handler

Changes since v1:

- Mention boards using the panel in Kconfig
- Renamed td043mtea1_device to td043mtea1_panel
- Fixed typo in Toppoly name
- Comments updates
- Store width_mm and height_mm in drm_display_mode
- Use drm_panel_unprepare() in .remove() handler
- Replace enable/disable with prepare/unprepare
---
 drivers/gpu/drm/panel/Kconfig|   7 +
 drivers/gpu/drm/panel/Makefile   |   1 +
 drivers/gpu/drm/panel/panel-tpo-td043mtea1.c | 509 +++
 3 files changed, 517 insertions(+)
 create mode 100644 drivers/gpu/drm/panel/panel-tpo-td043mtea1.c

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index c2689420d2dd..f152bc4eeb53 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -332,6 +332,13 @@ config DRM_PANEL_TPO_TD028TTEC1
  Say Y here if you want to enable support for TPO TD028TTEC1 480x640
  2.8" panel (found on the OpenMoko Neo FreeRunner and Neo 1973).
 
+config DRM_PANEL_TPO_TD043MTEA1
+   tristate "Toppoly (TPO) TD043MTEA1 panel driver"
+   depends on GPIOLIB && OF && REGULATOR && SPI
+   help
+ Say Y here if you want to enable support for TPO TD043MTEA1 800x480
+ 4.3" panel (found on the OMAP3 Pandora board).
+
 config DRM_PANEL_TPO_TPG110
tristate "TPO TPG 800x400 panel"
depends on OF && SPI && GPIOLIB
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index 27b776737ad3..b6cd39fe0f20 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -35,5 +35,6 @@ obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7701) += 
panel-sitronix-st7701.o
 obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7789V) += panel-sitronix-st7789v.o
 obj-$(CONFIG_DRM_PANEL_SONY_ACX565AKM) += panel-sony-acx565akm.o
 obj-$(CONFIG_DRM_PANEL_TPO_TD028TTEC1) += panel-tpo-td028ttec1.o
+obj-$(CONFIG_DRM_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o
 obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
 obj-$(CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA) += panel-truly-nt35597.o
diff --git a/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c 
b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
new file mode 100644
index ..71824a334af7
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-tpo-td043mtea1.c
@@ -0,0 +1,509 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Toppoly TD043MTEA1 Panel Driver
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated
+ *
+ * Based on the omapdrm-specific panel-tpo-td043mtea1 driver
+ *
+ * Author: Gražvydas Ignotas 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define TPO_R02_MODE(x)((x) & 7)
+#define TPO_R02_MODE_800x480   7
+#define TPO_R02_NCLK_RISINGBIT(3)
+#define TPO_R02_HSYNC_HIGH BIT(4)
+#define TPO_R02_VSYNC_HIGH BIT(5)
+
+#define TPO_R03_NSTANDBY   BIT(0)
+#define TPO_R03_EN_CP_CLK  BIT(1)
+#define TPO_R03_EN_VGL_PUMPBIT(2)
+#define TPO_R03_EN_PWM BIT(3)
+#define TPO_R03_DRIVING_CAP_100BIT(4)
+#define TPO_R03_EN_PRE_CHARGE  BIT(6)
+#define TPO_R03_SOFTWARE_CTL   BIT(7)
+
+#define TPO_R04_NFLIP_HBIT(0)
+#define TPO_R04_NFLIP_VBIT(1)
+#define TPO_R04_CP_CLK_FREQ_1H BIT(2)
+#define TPO_R04_VGL_FREQ_1HBIT(4)
+
+#define TPO_R03_VAL_NORMAL \
+   (TPO_R03_NSTANDBY | TPO_R03_EN_CP_CLK | TPO_R03_EN_VGL_PUMP | \
+TPO_R03_EN_PWM | TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \
+TPO_R03_SOFTWARE_CTL)
+
+#define TPO_R03_VAL_STANDBY \
+   (TPO_R03_DRIVING_CAP_100 | TPO_R03_EN_PRE_CHARGE | \
+TPO_R03_SOFTWARE_CTL)
+
+static const u16 td043mtea1_def_gamma[12] = {
+   105, 315, 381, 431, 490, 537, 579, 686, 780, 837, 880, 1023
+};
+
+struct td043mtea1_panel {
+   struct drm_panel panel;
+
+   struct spi_device *spi;
+   struct regulator *vcc_reg;
+   struct gpio_desc *reset_gpio;
+
+   unsigned int mode;
+   u16 gamma[12];
+   bool vmirror;
+   bool powered_on;
+   bool spi_suspended;
+   bool power_on_resume;
+};
+
+#define to_td043mtea1_device(p) container_of(p, struct td043mtea1_panel, panel)
+
+/* 
-
+ * Hardware Access
+ */
+
+static int td043mtea1_write(struct td043mtea1_panel *lcd, u8 addr, u8 value)
+{
+   struct spi_message msg;
+   struct spi_transfer xfer;
+   u16 data;
+   int ret;
+
+   spi_message_init(&msg);
+
+   memset(&xfer, 0, sizeof(xfer));
+
+   data = ((u16)addr << 10) | (1 << 8) | value;
+   xfer.tx_buf = &data;
+   xfer.bits_per_word = 16;
+