Re: [PATCH v2 08/10] drm/bridge: tc358764: Add DSI to LVDS bridge driver

From: Maciej Purski
Date: Mon Jun 18 2018 - 07:20:46 EST


On 05/31/2018 08:51 AM, Archit Taneja wrote:
> Hi,
>
> On Wednesday 30 May 2018 05:45 PM, Maciej Purski wrote:
>> From: Andrzej Hajda <a.hajda@xxxxxxxxxxx>
>>
>> Add a drm_bridge driver for the Toshiba TC358764 DSI to LVDS bridge.
>>
>> Signed-off-by: Andrzej Hajda <a.hajda@xxxxxxxxxxx>
>> Signed-off-by: Maciej Purski <m.purski@xxxxxxxxxxx>
>> ---
>> Â drivers/gpu/drm/bridge/KconfigÂÂÂ |ÂÂ 9 +
>> Â drivers/gpu/drm/bridge/MakefileÂÂ |ÂÂ 1 +
>> Â drivers/gpu/drm/bridge/tc358764.c | 547 ++++++++++++++++++++++++++++++++++++++
>> Â 3 files changed, 557 insertions(+)
>> Â create mode 100644 drivers/gpu/drm/bridge/tc358764.c
>>
>> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
>> index fa2c799..9bd3eb8 100644
>> --- a/drivers/gpu/drm/bridge/Kconfig
>> +++ b/drivers/gpu/drm/bridge/Kconfig
>> @@ -110,6 +110,15 @@ config DRM_THINE_THC63LVD1024
>> ÂÂÂÂÂ ---help---
>> ÂÂÂÂÂÂÂ Thine THC63LVD1024 LVDS/parallel converter driver.
>> +config DRM_TOSHIBA_TC358764
>> +ÂÂÂ tristate "TC358764 DSI/LVDS bridge"
>> +ÂÂÂ depends on DRM && DRM_PANEL
>> +ÂÂÂ depends on OF
>> +ÂÂÂ select DRM_MIPI_DSI
>> +ÂÂÂ select VIDEOMODE_HELPERS
>
> I don't see videomode usage in the driver, can we drop this if it isn't
> used?
>

It seems that those are some remains of old versions. It is not required now.

>> +ÂÂÂ help
>> +ÂÂÂÂÂ Toshiba TC358764 DSI/LVDS bridge driver
>> +
>> Â config DRM_TOSHIBA_TC358767
>> ÂÂÂÂÂ tristate "Toshiba TC358767 eDP bridge"
>> ÂÂÂÂÂ depends on OF
>> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
>> index 35f88d4..bf7c0ce 100644
>> --- a/drivers/gpu/drm/bridge/Makefile
>> +++ b/drivers/gpu/drm/bridge/Makefile
>> @@ -10,6 +10,7 @@ obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
>> Â obj-$(CONFIG_DRM_SII902X) += sii902x.o
>> Â obj-$(CONFIG_DRM_SII9234) += sii9234.o
>> Â obj-$(CONFIG_DRM_THINE_THC63LVD1024) += thc63lvd1024.o
>> +obj-$(CONFIG_DRM_TOSHIBA_TC358764) += tc358764.o
>> Â obj-$(CONFIG_DRM_TOSHIBA_TC358767) += tc358767.o
>> Â obj-$(CONFIG_DRM_ANALOGIX_DP) += analogix/
>> Â obj-$(CONFIG_DRM_I2C_ADV7511) += adv7511/
>> diff --git a/drivers/gpu/drm/bridge/tc358764.c b/drivers/gpu/drm/bridge/tc358764.c
>> new file mode 100644
>> index 0000000..3109eba
>> --- /dev/null
>> +++ b/drivers/gpu/drm/bridge/tc358764.c
>> @@ -0,0 +1,547 @@
>
> We'd need a SPDX license here?
>> +/*
>> + * Copyright (C) 2018 Samsung Electronics Co., Ltd
>> + *
>> + * Authors:
>> + *ÂÂÂ Andrzej Hajda <a.hajda@xxxxxxxxxxx>
>> + *ÂÂÂ Maciej Purski <m.purski@xxxxxxxxxxx>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program.
>> + *
>> + */
>> +
>> +#include <drm/drm_atomic_helper.h>
>> +
>> +#include <drm/drmP.h>
>> +#include <drm/drm_mipi_dsi.h>
>> +#include <drm/drm_panel.h>
>> +
>> +#include <drm/drm_crtc.h>
>> +#include <drm/drm_crtc_helper.h>
>> +
>> +#include <linux/gpio/consumer.h>
>> +#include <linux/of_graph.h>
>> +#include <linux/regulator/consumer.h>
>> +
>> +#include <video/mipi_display.h>
>> +#include <video/of_videomode.h>
>> +#include <video/videomode.h>
>> +
>> +#define FLD_MASK(start, end)ÂÂÂ (((1 << ((start) - (end) + 1)) - 1) << (end))
>> +#define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
>> +
>> +/* PPI layer registers */
>> +#define PPI_STARTPPIÂÂÂÂÂÂÂ 0x0104 /* START control bit */
>> +#define PPI_LPTXTIMECNTÂÂÂÂÂÂÂ 0x0114 /* LPTX timing signal */
>> +#define PPI_LANEENABLEÂÂÂÂÂÂÂ 0x0134 /* Enables each lane */
>> +#define PPI_TX_RX_TAÂÂÂÂÂÂÂ 0x013C /* BTA timing parameters */
>> +#define PPI_D0S_CLRSIPOCOUNTÂÂÂ 0x0164 /* Assertion timer for Lane 0 */
>> +#define PPI_D1S_CLRSIPOCOUNTÂÂÂ 0x0168 /* Assertion timer for Lane 1 */
>> +#define PPI_D2S_CLRSIPOCOUNTÂÂÂ 0x016C /* Assertion timer for Lane 2 */
>> +#define PPI_D3S_CLRSIPOCOUNTÂÂÂ 0x0170 /* Assertion timer for Lane 3 */
>> +#define PPI_START_FUNCTIONÂÂÂ 1
>> +
>> +/* DSI layer registers */
>> +#define DSI_STARTDSIÂÂÂÂÂÂÂ 0x0204 /* START control bit of DSI-TX */
>> +#define DSI_LANEENABLEÂÂÂÂÂÂÂ 0x0210 /* Enables each lane */
>> +#define DSI_RX_STARTÂÂÂÂÂÂÂ 1
>> +
>> +/* Video path registers */
>> +#define VP_CTRLÂÂÂÂÂÂÂÂÂÂÂ 0x0450 /* Video Path Control */
>> +#define VP_CTRL_MSF(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 0, 0) /* Magic square in RGB666 */
>> +#define VP_CTRL_VTGEN(v)ÂÂÂ FLD_VAL(v, 4, 4) /* Use chip clock for timing */
>> +#define VP_CTRL_EVTMODE(v)ÂÂÂ FLD_VAL(v, 5, 5) /* Event mode */
>> +#define VP_CTRL_RGB888(v)ÂÂÂ FLD_VAL(v, 8, 8) /* RGB888 mode */
>> +#define VP_CTRL_VSDELAY(v)ÂÂÂ FLD_VAL(v, 31, 20) /* VSYNC delay */
>> +#define VP_CTRL_HSPOLÂÂÂÂÂÂÂ BIT(17) /* Polarity of HSYNC signal */
>> +#define VP_CTRL_DEPOLÂÂÂÂÂÂÂ BIT(18) /* Polarity of DE signal */
>> +#define VP_CTRL_VSPOLÂÂÂÂÂÂÂ BIT(19) /* Polarity of VSYNC signal */
>> +#define VP_HTIM1ÂÂÂÂÂÂÂ 0x0454 /* Horizontal Timing Control 1 */
>> +#define VP_HTIM1_HBP(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 24, 16)
>> +#define VP_HTIM1_HSYNC(v)ÂÂÂ FLD_VAL(v, 8, 0)
>> +#define VP_HTIM2ÂÂÂÂÂÂÂ 0x0458 /* Horizontal Timing Control 2 */
>> +#define VP_HTIM2_HFP(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 24, 16)
>> +#define VP_HTIM2_HACT(v)ÂÂÂ FLD_VAL(v, 10, 0)
>> +#define VP_VTIM1ÂÂÂÂÂÂÂ 0x045C /* Vertical Timing Control 1 */
>> +#define VP_VTIM1_VBP(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 23, 16)
>> +#define VP_VTIM1_VSYNC(v)ÂÂÂ FLD_VAL(v, 7, 0)
>> +#define VP_VTIM2ÂÂÂÂÂÂÂ 0x0460 /* Vertical Timing Control 2 */
>> +#define VP_VTIM2_VFP(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 23, 16)
>> +#define VP_VTIM2_VACT(v)ÂÂÂ FLD_VAL(v, 10, 0)
>> +#define VP_VFUENÂÂÂÂÂÂÂ 0x0464 /* Video Frame Timing Update Enable */
>> +
>> +/* LVDS registers */
>> +#define LV_MX0003ÂÂÂÂÂÂÂ 0x0480 /* Mux input bit 0 to 3 */
>> +#define LV_MX0407ÂÂÂÂÂÂÂ 0x0484 /* Mux input bit 4 to 7 */
>> +#define LV_MX0811ÂÂÂÂÂÂÂ 0x0488 /* Mux input bit 8 to 11 */
>> +#define LV_MX1215ÂÂÂÂÂÂÂ 0x048C /* Mux input bit 12 to 15 */
>> +#define LV_MX1619ÂÂÂÂÂÂÂ 0x0490 /* Mux input bit 16 to 19 */
>> +#define LV_MX2023ÂÂÂÂÂÂÂ 0x0494 /* Mux input bit 20 to 23 */
>> +#define LV_MX2427ÂÂÂÂÂÂÂ 0x0498 /* Mux input bit 24 to 27 */
>> +#define LV_MX(b0, b1, b2, b3)ÂÂÂ (FLD_VAL(b0, 4, 0) | FLD_VAL(b1, 12, 8) | \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ FLD_VAL(b2, 20, 16) | FLD_VAL(b3, 28, 24))
>> +
>> +/* Input bit numbers used in mux registers */
>> +enum {
>> +ÂÂÂ LVI_R0,
>> +ÂÂÂ LVI_R1,
>> +ÂÂÂ LVI_R2,
>> +ÂÂÂ LVI_R3,
>> +ÂÂÂ LVI_R4,
>> +ÂÂÂ LVI_R5,
>> +ÂÂÂ LVI_R6,
>> +ÂÂÂ LVI_R7,
>> +ÂÂÂ LVI_G0,
>> +ÂÂÂ LVI_G1,
>> +ÂÂÂ LVI_G2,
>> +ÂÂÂ LVI_G3,
>> +ÂÂÂ LVI_G4,
>> +ÂÂÂ LVI_G5,
>> +ÂÂÂ LVI_G6,
>> +ÂÂÂ LVI_G7,
>> +ÂÂÂ LVI_B0,
>> +ÂÂÂ LVI_B1,
>> +ÂÂÂ LVI_B2,
>> +ÂÂÂ LVI_B3,
>> +ÂÂÂ LVI_B4,
>> +ÂÂÂ LVI_B5,
>> +ÂÂÂ LVI_B6,
>> +ÂÂÂ LVI_B7,
>> +ÂÂÂ LVI_HS,
>> +ÂÂÂ LVI_VS,
>> +ÂÂÂ LVI_DE,
>> +ÂÂÂ LVI_L0
>> +};
>> +
>> +#define LV_CFGÂÂÂÂÂÂÂÂÂÂÂ 0x049C /* LVDS Configuration */
>> +#define LV_PHY0ÂÂÂÂÂÂÂÂÂÂÂ 0x04A0 /* LVDS PHY 0 */
>> +#define LV_PHY0_RST(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 22, 22) /* PHY reset */
>> +#define LV_PHY0_IS(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 15, 14)
>> +#define LV_PHY0_ND(v)ÂÂÂÂÂÂÂ FLD_VAL(v, 4, 0) /* Frequency range select */
>> +#define LV_PHY0_PRBS_ON(v)ÂÂÂ FLD_VAL(v, 20, 16) /* Clock/Data Flag pins */
>> +
>> +/* System registers */
>> +#define SYS_RSTÂÂÂÂÂÂÂÂÂÂÂ 0x0504 /* System Reset */
>> +#define SYS_IDÂÂÂÂÂÂÂÂÂÂÂ 0x0580 /* System ID */
>> +
>> +#define SYS_RST_I2CSÂÂÂÂÂÂÂ BIT(0) /* Reset I2C-Slave controller */
>> +#define SYS_RST_I2CMÂÂÂÂÂÂÂ BIT(1) /* Reset I2C-Master controller */
>> +#define SYS_RST_LCDÂÂÂÂÂÂÂ BIT(2) /* Reset LCD controller */
>> +#define SYS_RST_BMÂÂÂÂÂÂÂ BIT(3) /* Reset Bus Management controller */
>> +#define SYS_RST_DSIRXÂÂÂÂÂÂÂ BIT(4) /* Reset DSI-RX and App controller */
>> +#define SYS_RST_REGÂÂÂÂÂÂÂ BIT(5) /* Reset Register module */
>> +
>> +#define LPX_PERIODÂÂÂÂÂÂÂ 2
>> +#define TTA_SUREÂÂÂÂÂÂÂ 3
>> +#define TTA_GETÂÂÂÂÂÂÂÂÂÂÂ 0x20000
>> +
>> +/* Lane enable PPI and DSI register bits */
>> +#define LANEENABLE_CLENÂÂÂÂÂÂÂ BIT(0)
>> +#define LANEENABLE_L0ENÂÂÂÂÂÂÂ BIT(1)
>> +#define LANEENABLE_L1ENÂÂÂÂÂÂÂ BIT(2)
>> +#define LANEENABLE_L2ENÂÂÂÂÂÂÂ BIT(3)
>> +#define LANEENABLE_L3ENÂÂÂÂÂÂÂ BIT(4)
>> +
>> +/* LVCFG fields */
>> +#define LV_CFG_LVENÂÂÂÂÂÂÂ BIT(0)
>> +#define LV_CFG_LVDLINKÂÂÂÂÂÂÂ BIT(1)
>> +#define LV_CFG_CLKPOL1ÂÂÂÂÂÂÂ BIT(2)
>> +#define LV_CFG_CLKPOL2ÂÂÂÂÂÂÂ BIT(3)
>> +
>> +static const char * const tc358764_supplies[] = {
>> +ÂÂÂ "vddc", "vddio", "vddmipi", "vddlvds133", "vddlvds112"
>> +};
>> +
>> +struct tc358764 {
>> +ÂÂÂ struct device *dev;
>> +ÂÂÂ struct drm_bridge bridge;
>> +ÂÂÂ struct drm_connector connector;
>> +ÂÂÂ struct regulator_bulk_data supplies[ARRAY_SIZE(tc358764_supplies)];
>> +ÂÂÂ struct gpio_desc *gpio_reset;
>> +
>> +ÂÂÂ struct drm_panel *panel;
>> +};
>> +
>> +static int tc358764_read(struct tc358764 *ctx, u16 addr, u32 *val)
>> +{
>> +ÂÂÂ struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
>> +ÂÂÂ const struct mipi_dsi_host_ops *ops = dsi->host->ops;
>> +ÂÂÂ struct mipi_dsi_msg msg = {
>> +ÂÂÂÂÂÂÂ .type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM,
>> +ÂÂÂÂÂÂÂ .channel = dsi->channel,
>> +ÂÂÂÂÂÂÂ .flags = MIPI_DSI_MSG_USE_LPM,
>> +ÂÂÂÂÂÂÂ .tx_buf = &addr,
>> +ÂÂÂÂÂÂÂ .tx_len = 2,
>> +ÂÂÂÂÂÂÂ .rx_buf = val,
>> +ÂÂÂÂÂÂÂ .rx_len = 4
>> +ÂÂÂ };
>> +ÂÂÂ ssize_t ret;
>> +
>> +ÂÂÂ if (!ops || !ops->transfer)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ cpu_to_le16s(&addr);
>> +
>> +ÂÂÂ ret = ops->transfer(dsi->host, &msg);
>> +ÂÂÂ if (ret >= 0)
>> +ÂÂÂÂÂÂÂ le32_to_cpus(val); > +
>> +ÂÂÂ dev_dbg(ctx->dev, "read: %d, addr: %d\n", addr, *val);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static int tc358764_write(struct tc358764 *ctx, u16 addr, u32 val)
>> +{
>> +ÂÂÂ struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
>> +ÂÂÂ const struct mipi_dsi_host_ops *ops = dsi->host->ops;
>> +ÂÂÂ u8 data[6];
>> +ÂÂÂ int ret;
>> +ÂÂÂ struct mipi_dsi_msg msg = {
>> +ÂÂÂÂÂÂÂ .type = MIPI_DSI_GENERIC_LONG_WRITE,
>> +ÂÂÂÂÂÂÂ .channel = dsi->channel,
>> +ÂÂÂÂÂÂÂ .flags = MIPI_DSI_MSG_USE_LPM | MIPI_DSI_MSG_REQ_ACK,
>> +ÂÂÂÂÂÂÂ .tx_buf = data,
>> +ÂÂÂÂÂÂÂ .tx_len = 6
>> +ÂÂÂ };
>> +
>> +ÂÂÂ if (!ops || !ops->transfer)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ data[0] = addr;
>> +ÂÂÂ data[1] = addr >> 8;
>> +ÂÂÂ data[2] = val;
>> +ÂÂÂ data[3] = val >> 8;
>> +ÂÂÂ data[4] = val >> 16;
>> +ÂÂÂ data[5] = val >> 24;
>> +
>> +ÂÂÂ ret = ops->transfer(dsi->host, &msg);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static inline struct tc358764 *bridge_to_tc358764(struct drm_bridge *bridge)
>> +{
>> +ÂÂÂ return container_of(bridge, struct tc358764, bridge);
>> +}
>> +
>> +static inline
>> +struct tc358764 *connector_to_tc358764(struct drm_connector *connector)
>> +{
>> +ÂÂÂ return container_of(connector, struct tc358764, connector);
>> +}
>> +
>> +static int tc358764_init(struct tc358764 *ctx)
>> +{
>> +ÂÂÂ u32 v = 0;
>> +
>> +ÂÂÂ tc358764_read(ctx, SYS_ID, &v);
>> +ÂÂÂ dev_info(ctx->dev, "ID: %#x\n", v);
>> +
>> +ÂÂÂ /* configure PPI counters */
>> +ÂÂÂ tc358764_write(ctx, PPI_TX_RX_TA, TTA_GET | TTA_SURE);
>> +ÂÂÂ tc358764_write(ctx, PPI_LPTXTIMECNT, LPX_PERIOD);
>> +ÂÂÂ tc358764_write(ctx, PPI_D0S_CLRSIPOCOUNT, 5);
>> +ÂÂÂ tc358764_write(ctx, PPI_D1S_CLRSIPOCOUNT, 5);
>> +ÂÂÂ tc358764_write(ctx, PPI_D2S_CLRSIPOCOUNT, 5);
>> +ÂÂÂ tc358764_write(ctx, PPI_D3S_CLRSIPOCOUNT, 5);
>> +
>> +ÂÂÂ /* enable four data lanes and clock lane */
>> +ÂÂÂ tc358764_write(ctx, PPI_LANEENABLE, LANEENABLE_L3EN | LANEENABLE_L2EN |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ LANEENABLE_L1EN | LANEENABLE_L0EN | LANEENABLE_CLEN);
>> +ÂÂÂ tc358764_write(ctx, DSI_LANEENABLE, LANEENABLE_L3EN | LANEENABLE_L2EN |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ LANEENABLE_L1EN | LANEENABLE_L0EN | LANEENABLE_CLEN);
>> +
>> +ÂÂÂ /* start */
>> +ÂÂÂ tc358764_write(ctx, PPI_STARTPPI, PPI_START_FUNCTION);
>> +ÂÂÂ tc358764_write(ctx, DSI_STARTDSI, DSI_RX_START);
>> +
>> +ÂÂÂ /* configure video path */
>> +ÂÂÂ tc358764_write(ctx, VP_CTRL, VP_CTRL_VSDELAY(15) | VP_CTRL_RGB888(1) |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ VP_CTRL_EVTMODE(1) | VP_CTRL_HSPOL | VP_CTRL_VSPOL);
>
> Could we specify somewhere that

Could you clarify, what do you mean here?

>> +
>> +ÂÂÂ /* reset PHY */
>> +ÂÂÂ tc358764_write(ctx, LV_PHY0, LV_PHY0_RST(1) |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ LV_PHY0_PRBS_ON(4) | LV_PHY0_IS(2) | LV_PHY0_ND(6));
>> +ÂÂÂ tc358764_write(ctx, LV_PHY0, LV_PHY0_PRBS_ON(4) | LV_PHY0_IS(2) |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ LV_PHY0_ND(6));
>> +
>> +ÂÂÂ /* reset bridge */
>> +ÂÂÂ tc358764_write(ctx, SYS_RST, SYS_RST_LCD);
>> +
>> +ÂÂÂ /* set bit order */
>> +ÂÂÂ tc358764_write(ctx, LV_MX0003, LV_MX(LVI_R0, LVI_R1, LVI_R2, LVI_R3));
>> +ÂÂÂ tc358764_write(ctx, LV_MX0407, LV_MX(LVI_R4, LVI_R7, LVI_R5, LVI_G0));
>> +ÂÂÂ tc358764_write(ctx, LV_MX0811, LV_MX(LVI_G1, LVI_G2, LVI_G6, LVI_G7));
>> +ÂÂÂ tc358764_write(ctx, LV_MX1215, LV_MX(LVI_G3, LVI_G4, LVI_G5, LVI_B0));
>> +ÂÂÂ tc358764_write(ctx, LV_MX1619, LV_MX(LVI_B6, LVI_B7, LVI_B1, LVI_B2));
>> +ÂÂÂ tc358764_write(ctx, LV_MX2023, LV_MX(LVI_B3, LVI_B4, LVI_B5, LVI_L0));
>> +ÂÂÂ tc358764_write(ctx, LV_MX2427, LV_MX(LVI_HS, LVI_VS, LVI_DE, LVI_R6));
>> +ÂÂÂ tc358764_write(ctx, LV_CFG, LV_CFG_CLKPOL2 | LV_CFG_CLKPOL1 |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ LV_CFG_LVEN);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static void tc358764_reset(struct tc358764 *ctx)
>> +{
>> +ÂÂÂ msleep(20);
>> +ÂÂÂ gpiod_set_value(ctx->gpio_reset, 0);
>> +ÂÂÂ msleep(20);
>> +ÂÂÂ gpiod_set_value(ctx->gpio_reset, 1);
>> +ÂÂÂ msleep(40);
>> +}
>> +
>> +static void tc358764_poweroff(struct tc358764 *ctx)
>> +{
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ tc358764_reset(ctx);
>> +
>> +ÂÂÂ drm_panel_disable(ctx->panel);
>> +ÂÂÂ msleep(40);
>> +
>> +ÂÂÂ ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
>> +ÂÂÂ if (ret < 0)
>> +ÂÂÂÂÂÂÂ dev_err(ctx->dev, "error disabling regulators (%d)\n", ret);
>> +}
>> +
>> +static int tc358764_get_modes(struct drm_connector *connector)
>> +{
>> +ÂÂÂ struct tc358764 *ctx = connector_to_tc358764(connector);
>> +
>> +ÂÂÂ if (ctx->panel && ctx->panel->funcs && ctx->panel->funcs->get_modes)
>> +ÂÂÂÂÂÂÂ return ctx->panel->funcs->get_modes(ctx->panel);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static const
>> +struct drm_connector_helper_funcs tc358764_connector_helper_funcs = {
>> +ÂÂÂ .get_modes = tc358764_get_modes,
>> +};
>> +
>> +static const struct drm_connector_funcs tc358764_connector_funcs = {
>> +ÂÂÂ .fill_modes = drm_helper_probe_single_connector_modes,
>> +ÂÂÂ .destroy = drm_connector_cleanup,
>> +ÂÂÂ .reset = drm_atomic_helper_connector_reset,
>> +ÂÂÂ .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
>> +ÂÂÂ .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>> +};
>> +
>> +static void tc358764_disable(struct drm_bridge *bridge)
>> +{
>> +ÂÂÂ struct tc358764 *ctx = bridge_to_tc358764(bridge);
>> +
>> +ÂÂÂ tc358764_poweroff(ctx);
>> +}
>> +
>> +static void tc358764_pre_enable(struct drm_bridge *bridge)
>> +{
>> +ÂÂÂ struct tc358764 *ctx = bridge_to_tc358764(bridge);
>> +ÂÂÂ int ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ctx->supplies);
>> +ÂÂÂ if (ret < 0)
>> +ÂÂÂÂÂÂÂ dev_err(ctx->dev, "error enabling regulators (%d)\n", ret);
>> +
>> +ÂÂÂ tc358764_reset(ctx);
>> +ÂÂÂ tc358764_init(ctx);
>> +}
>> +
>> +static void tc358764_enable(struct drm_bridge *bridge)
>> +{
>> +ÂÂÂ struct tc358764 *ctx = bridge_to_tc358764(bridge);
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ drm_panel_prepare(ctx->panel);
>> +
>> +ÂÂÂ ret = drm_panel_enable(ctx->panel);
>> +ÂÂÂ if (ret < 0)
>> +ÂÂÂÂÂÂÂ pr_err("panel enable failed\n");
>> +
>> +ÂÂÂ msleep(40);
>> +}
>> +
>> +static int tc358764_attach(struct drm_bridge *bridge)
>> +{
>> +ÂÂÂ struct tc358764 *ctx = bridge_to_tc358764(bridge);
>> +ÂÂÂ struct drm_device *drm = bridge->dev;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ if (!bridge->encoder) {
>> +ÂÂÂÂÂÂÂ DRM_ERROR("Encoder not found\n");
>> +ÂÂÂÂÂÂÂ return -ENODEV;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ctx->connector.polled = DRM_CONNECTOR_POLL_HPD;
>> +ÂÂÂ ret = drm_connector_init(drm, &ctx->connector,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &tc358764_connector_funcs,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ DRM_MODE_CONNECTOR_LVDS);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ DRM_ERROR("Failed to initialize connector\n");
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ drm_connector_helper_add(&ctx->connector,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &tc358764_connector_helper_funcs);
>> +
>> +ÂÂÂ drm_mode_connector_attach_encoder(&ctx->connector, bridge->encoder);
>> +
>> +ÂÂÂ if (ctx->panel)
>> +ÂÂÂÂÂÂÂ drm_panel_attach(ctx->panel, &ctx->connector);
>> +
>> +ÂÂÂ drm_atomic_helper_connector_reset(&ctx->connector);
>> +ÂÂÂ drm_connector_register(&ctx->connector);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static const struct drm_bridge_funcs tc358764_bridge_funcs = {
>> +ÂÂÂ .disable = tc358764_disable,
>> +ÂÂÂ .enable = tc358764_enable,
>> +ÂÂÂ .pre_enable = tc358764_pre_enable,
>> +ÂÂÂ .attach = tc358764_attach,
>> +};
>> +
>> +static struct device_node *tc358764_of_find_panel_node(struct device *dev)
>> +{
>> +ÂÂÂ struct device_node *np, *ep;
>> +
>> +ÂÂÂ ep = of_graph_get_endpoint_by_regs(dev->of_node, 1, 0);
>> +ÂÂÂ if (!ep) {
>> +ÂÂÂÂÂÂÂ pr_err("faile to get endpoint\n");
>> +ÂÂÂÂÂÂÂ return NULL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ np = of_graph_get_remote_port_parent(ep);
>> +
>> +ÂÂÂ return np;
>> +}
>> +
>> +static int tc358764_parse_dt(struct tc358764 *ctx)
>> +{
>> +ÂÂÂ struct device *dev = ctx->dev;
>> +ÂÂÂ struct device_node *np = dev->of_node;
>> +ÂÂÂ struct device_node *lvds;
>> +
>> +ÂÂÂ ctx->gpio_reset = devm_gpiod_get_from_of_node(dev, np, "reset", 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GPIOD_OUT_LOW,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "tc358764-reset");
>> +ÂÂÂ if (IS_ERR(ctx->gpio_reset)) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "no reset GPIO pin provided\n");
>> +ÂÂÂÂÂÂÂ return PTR_ERR(ctx->gpio_reset);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ lvds = tc358764_of_find_panel_node(ctx->dev);
>> +ÂÂÂ if (!lvds) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "cannot find panel node\n");
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ctx->panel = of_drm_find_panel(lvds);
>> +ÂÂÂ if (!ctx->panel) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "panel not registered\n");
>> +ÂÂÂÂÂÂÂ return -EPROBE_DEFER;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static int tc358764_configure_regulators(struct tc358764 *ctx)
>> +{
>> +ÂÂÂ int i, ret;
>> +
>> +ÂÂÂ for (i = 0; i < ARRAY_SIZE(ctx->supplies); ++i)
>> +ÂÂÂÂÂÂÂ ctx->supplies[i].supply = tc358764_supplies[i];
>> +
>> +ÂÂÂ ret = devm_regulator_bulk_get(ctx->dev, ARRAY_SIZE(ctx->supplies),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ctx->supplies);
>> +ÂÂÂ if (ret < 0)
>> +ÂÂÂÂÂÂÂ dev_err(ctx->dev, "failed to get regulators: %d\n", ret);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static int tc358764_probe(struct mipi_dsi_device *dsi)
>> +{
>> +ÂÂÂ struct device *dev = &dsi->dev;
>> +ÂÂÂ struct tc358764 *ctx;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ctx = devm_kzalloc(dev, sizeof(struct tc358764), GFP_KERNEL);
>> +ÂÂÂ if (!ctx)
>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>> +
>> +ÂÂÂ mipi_dsi_set_drvdata(dsi, ctx);
>> +
>> +ÂÂÂ ctx->dev = dev;
>> +
>> +ÂÂÂ dsi->lanes = 4;
>> +ÂÂÂ dsi->format = MIPI_DSI_FMT_RGB888;
>> +ÂÂÂ dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST
>> +ÂÂÂÂÂÂÂ | MIPI_DSI_MODE_VIDEO_AUTO_VERT;
>
> if you use the mipi_dsi_device_transfer() helper, I guess you'd need to
> add the LPM flag here.
>

I'll check, if we can use the helper instead of calling ops->transfer() directly.

Thanks,

Maciej Purski

> Looks good to me otherwise. Once the DT port issue is concluded:
>
> Reviewed-by: Archit Taneja <architt@xxxxxxxxxxxxxx>
>
>> +
>> +ÂÂÂ ret = tc358764_parse_dt(ctx);
>> +ÂÂÂ if (ret < 0)
>> +ÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂ ret = tc358764_configure_regulators(ctx);
>> +ÂÂÂ if (ret < 0)
>> +ÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂ ctx->bridge.funcs = &tc358764_bridge_funcs;
>> +ÂÂÂ ctx->bridge.of_node = dev->of_node;
>> +
>> +ÂÂÂ drm_bridge_add(&ctx->bridge);
>> +
>> +ÂÂÂ ret = mipi_dsi_attach(dsi);
>> +ÂÂÂ if (ret < 0) {
>> +ÂÂÂÂÂÂÂ drm_bridge_remove(&ctx->bridge);
>> +ÂÂÂÂÂÂÂ dev_err(dev, "failed to attach dsi\n");
>> +ÂÂÂ }
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static int tc358764_remove(struct mipi_dsi_device *dsi)
>> +{
>> +ÂÂÂ struct tc358764 *ctx = mipi_dsi_get_drvdata(dsi);
>> +
>> +ÂÂÂ tc358764_poweroff(ctx);
>> +
>> +ÂÂÂ mipi_dsi_detach(dsi);
>> +ÂÂÂ drm_bridge_remove(&ctx->bridge);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static const struct of_device_id tc358764_of_match[] = {
>> +ÂÂÂ { .compatible = "toshiba,tc358764" },
>> +ÂÂÂ { }
>> +};
>> +MODULE_DEVICE_TABLE(of, tc358764_of_match);
>> +
>> +static struct mipi_dsi_driver tc358764_driver = {
>> +ÂÂÂ .probe = tc358764_probe,
>> +ÂÂÂ .remove = tc358764_remove,
>> +ÂÂÂ .driver = {
>> +ÂÂÂÂÂÂÂ .name = "tc358764",
>> +ÂÂÂÂÂÂÂ .owner = THIS_MODULE,
>> +ÂÂÂÂÂÂÂ .of_match_table = tc358764_of_match,
>> +ÂÂÂ },
>> +};
>> +module_mipi_dsi_driver(tc358764_driver);
>> +
>> +MODULE_AUTHOR("Andrzej Hajda <a.hajda@xxxxxxxxxxx>");
>> +MODULE_AUTHOR("Maciej Purski <m.purski@xxxxxxxxxxx>");
>> +MODULE_DESCRIPTION("MIPI-DSI based Driver for TC358764 DSI/LVDS Bridge");
>> +MODULE_LICENSE("GPL v2");
>>
>
>
>