1bc1aee7fSJitao Shi // SPDX-License-Identifier: GPL-2.0-only 2bc1aee7fSJitao Shi /* 3bc1aee7fSJitao Shi * Copyright (c) 2016 MediaTek Inc. 4bc1aee7fSJitao Shi */ 5bc1aee7fSJitao Shi 6bc1aee7fSJitao Shi #include <linux/delay.h> 7bc1aee7fSJitao Shi #include <linux/err.h> 8bc1aee7fSJitao Shi #include <linux/gpio/consumer.h> 9bc1aee7fSJitao Shi #include <linux/i2c.h> 10bc1aee7fSJitao Shi #include <linux/module.h> 11bc1aee7fSJitao Shi #include <linux/of_graph.h> 12826cff3fSPhilip Chen #include <linux/pm_runtime.h> 13692d8db0SPhilip Chen #include <linux/regmap.h> 14bc1aee7fSJitao Shi #include <linux/regulator/consumer.h> 15bc1aee7fSJitao Shi 16da68386dSThomas Zimmermann #include <drm/display/drm_dp_aux_bus.h> 17da68386dSThomas Zimmermann #include <drm/display/drm_dp_helper.h> 18102e80d1SSam Ravnborg #include <drm/drm_atomic_state_helper.h> 19bc1aee7fSJitao Shi #include <drm/drm_bridge.h> 20255490f9SVille Syrjälä #include <drm/drm_edid.h> 21bc1aee7fSJitao Shi #include <drm/drm_mipi_dsi.h> 22bc1aee7fSJitao Shi #include <drm/drm_of.h> 23bc1aee7fSJitao Shi #include <drm/drm_panel.h> 24bc1aee7fSJitao Shi #include <drm/drm_print.h> 25bc1aee7fSJitao Shi 2613afcdd7SPhilip Chen #define PAGE0_AUXCH_CFG3 0x76 2713afcdd7SPhilip Chen #define AUXCH_CFG3_RESET 0xff 2813afcdd7SPhilip Chen #define PAGE0_SWAUX_ADDR_7_0 0x7d 2913afcdd7SPhilip Chen #define PAGE0_SWAUX_ADDR_15_8 0x7e 3013afcdd7SPhilip Chen #define PAGE0_SWAUX_ADDR_23_16 0x7f 3113afcdd7SPhilip Chen #define SWAUX_ADDR_MASK GENMASK(19, 0) 3213afcdd7SPhilip Chen #define PAGE0_SWAUX_LENGTH 0x80 3313afcdd7SPhilip Chen #define SWAUX_LENGTH_MASK GENMASK(3, 0) 3413afcdd7SPhilip Chen #define SWAUX_NO_PAYLOAD BIT(7) 3513afcdd7SPhilip Chen #define PAGE0_SWAUX_WDATA 0x81 3613afcdd7SPhilip Chen #define PAGE0_SWAUX_RDATA 0x82 3713afcdd7SPhilip Chen #define PAGE0_SWAUX_CTRL 0x83 3813afcdd7SPhilip Chen #define SWAUX_SEND BIT(0) 3913afcdd7SPhilip Chen #define PAGE0_SWAUX_STATUS 0x84 4013afcdd7SPhilip Chen #define SWAUX_M_MASK GENMASK(4, 0) 4113afcdd7SPhilip Chen #define SWAUX_STATUS_MASK GENMASK(7, 5) 4213afcdd7SPhilip Chen #define SWAUX_STATUS_NACK (0x1 << 5) 4313afcdd7SPhilip Chen #define SWAUX_STATUS_DEFER (0x2 << 5) 4413afcdd7SPhilip Chen #define SWAUX_STATUS_ACKM (0x3 << 5) 4513afcdd7SPhilip Chen #define SWAUX_STATUS_INVALID (0x4 << 5) 4613afcdd7SPhilip Chen #define SWAUX_STATUS_I2C_NACK (0x5 << 5) 4713afcdd7SPhilip Chen #define SWAUX_STATUS_I2C_DEFER (0x6 << 5) 4813afcdd7SPhilip Chen #define SWAUX_STATUS_TIMEOUT (0x7 << 5) 4913afcdd7SPhilip Chen 50bc1aee7fSJitao Shi #define PAGE2_GPIO_H 0xa7 51bc1aee7fSJitao Shi #define PS_GPIO9 BIT(1) 52bc1aee7fSJitao Shi #define PAGE2_I2C_BYPASS 0xea 53bc1aee7fSJitao Shi #define I2C_BYPASS_EN 0xd0 54bc1aee7fSJitao Shi #define PAGE2_MCS_EN 0xf3 55bc1aee7fSJitao Shi #define MCS_EN BIT(0) 5628210a3fSPhilip Chen 57bc1aee7fSJitao Shi #define PAGE3_SET_ADD 0xfe 58bc1aee7fSJitao Shi #define VDO_CTL_ADD 0x13 59bc1aee7fSJitao Shi #define VDO_DIS 0x18 60bc1aee7fSJitao Shi #define VDO_EN 0x1c 6128210a3fSPhilip Chen 6228210a3fSPhilip Chen #define NUM_MIPI_LANES 4 63bc1aee7fSJitao Shi 64692d8db0SPhilip Chen #define COMMON_PS8640_REGMAP_CONFIG \ 65692d8db0SPhilip Chen .reg_bits = 8, \ 66692d8db0SPhilip Chen .val_bits = 8, \ 67692d8db0SPhilip Chen .cache_type = REGCACHE_NONE 68692d8db0SPhilip Chen 69bc1aee7fSJitao Shi /* 70bc1aee7fSJitao Shi * PS8640 uses multiple addresses: 71bc1aee7fSJitao Shi * page[0]: for DP control 72bc1aee7fSJitao Shi * page[1]: for VIDEO Bridge 73bc1aee7fSJitao Shi * page[2]: for control top 74bc1aee7fSJitao Shi * page[3]: for DSI Link Control1 75bc1aee7fSJitao Shi * page[4]: for MIPI Phy 76bc1aee7fSJitao Shi * page[5]: for VPLL 77bc1aee7fSJitao Shi * page[6]: for DSI Link Control2 78bc1aee7fSJitao Shi * page[7]: for SPI ROM mapping 79bc1aee7fSJitao Shi */ 80bc1aee7fSJitao Shi enum page_addr_offset { 81bc1aee7fSJitao Shi PAGE0_DP_CNTL = 0, 82bc1aee7fSJitao Shi PAGE1_VDO_BDG, 83bc1aee7fSJitao Shi PAGE2_TOP_CNTL, 84bc1aee7fSJitao Shi PAGE3_DSI_CNTL1, 85bc1aee7fSJitao Shi PAGE4_MIPI_PHY, 86bc1aee7fSJitao Shi PAGE5_VPLL, 87bc1aee7fSJitao Shi PAGE6_DSI_CNTL2, 88bc1aee7fSJitao Shi PAGE7_SPI_CNTL, 89bc1aee7fSJitao Shi MAX_DEVS 90bc1aee7fSJitao Shi }; 91bc1aee7fSJitao Shi 92bc1aee7fSJitao Shi enum ps8640_vdo_control { 93bc1aee7fSJitao Shi DISABLE = VDO_DIS, 94bc1aee7fSJitao Shi ENABLE = VDO_EN, 95bc1aee7fSJitao Shi }; 96bc1aee7fSJitao Shi 97bc1aee7fSJitao Shi struct ps8640 { 98bc1aee7fSJitao Shi struct drm_bridge bridge; 99bc1aee7fSJitao Shi struct drm_bridge *panel_bridge; 10013afcdd7SPhilip Chen struct drm_dp_aux aux; 101bc1aee7fSJitao Shi struct mipi_dsi_device *dsi; 102bc1aee7fSJitao Shi struct i2c_client *page[MAX_DEVS]; 103692d8db0SPhilip Chen struct regmap *regmap[MAX_DEVS]; 104bc1aee7fSJitao Shi struct regulator_bulk_data supplies[2]; 105bc1aee7fSJitao Shi struct gpio_desc *gpio_reset; 106bc1aee7fSJitao Shi struct gpio_desc *gpio_powerdown; 1079294914dSAngeloGioacchino Del Regno struct device_link *link; 108826cff3fSPhilip Chen bool pre_enabled; 109cb8e30ddSDouglas Anderson bool need_post_hpd_delay; 110*26db46bcSPin-yen Lin struct mutex aux_lock; 111bc1aee7fSJitao Shi }; 112bc1aee7fSJitao Shi 113692d8db0SPhilip Chen static const struct regmap_config ps8640_regmap_config[] = { 114692d8db0SPhilip Chen [PAGE0_DP_CNTL] = { 115692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 116692d8db0SPhilip Chen .max_register = 0xbf, 117692d8db0SPhilip Chen }, 118692d8db0SPhilip Chen [PAGE1_VDO_BDG] = { 119692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 120692d8db0SPhilip Chen .max_register = 0xff, 121692d8db0SPhilip Chen }, 122692d8db0SPhilip Chen [PAGE2_TOP_CNTL] = { 123692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 124692d8db0SPhilip Chen .max_register = 0xff, 125692d8db0SPhilip Chen }, 126692d8db0SPhilip Chen [PAGE3_DSI_CNTL1] = { 127692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 128692d8db0SPhilip Chen .max_register = 0xff, 129692d8db0SPhilip Chen }, 130692d8db0SPhilip Chen [PAGE4_MIPI_PHY] = { 131692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 132692d8db0SPhilip Chen .max_register = 0xff, 133692d8db0SPhilip Chen }, 134692d8db0SPhilip Chen [PAGE5_VPLL] = { 135692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 136692d8db0SPhilip Chen .max_register = 0x7f, 137692d8db0SPhilip Chen }, 138692d8db0SPhilip Chen [PAGE6_DSI_CNTL2] = { 139692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 140692d8db0SPhilip Chen .max_register = 0xff, 141692d8db0SPhilip Chen }, 142692d8db0SPhilip Chen [PAGE7_SPI_CNTL] = { 143692d8db0SPhilip Chen COMMON_PS8640_REGMAP_CONFIG, 144692d8db0SPhilip Chen .max_register = 0xff, 145692d8db0SPhilip Chen }, 146692d8db0SPhilip Chen }; 147692d8db0SPhilip Chen 148bc1aee7fSJitao Shi static inline struct ps8640 *bridge_to_ps8640(struct drm_bridge *e) 149bc1aee7fSJitao Shi { 150bc1aee7fSJitao Shi return container_of(e, struct ps8640, bridge); 151bc1aee7fSJitao Shi } 152bc1aee7fSJitao Shi 15313afcdd7SPhilip Chen static inline struct ps8640 *aux_to_ps8640(struct drm_dp_aux *aux) 15413afcdd7SPhilip Chen { 15513afcdd7SPhilip Chen return container_of(aux, struct ps8640, aux); 15613afcdd7SPhilip Chen } 15713afcdd7SPhilip Chen 158f5aa7d46SDouglas Anderson static int _ps8640_wait_hpd_asserted(struct ps8640 *ps_bridge, unsigned long wait_us) 159826cff3fSPhilip Chen { 160826cff3fSPhilip Chen struct regmap *map = ps_bridge->regmap[PAGE2_TOP_CNTL]; 161826cff3fSPhilip Chen int status; 162cb8e30ddSDouglas Anderson int ret; 163826cff3fSPhilip Chen 164826cff3fSPhilip Chen /* 165826cff3fSPhilip Chen * Apparently something about the firmware in the chip signals that 166826cff3fSPhilip Chen * HPD goes high by reporting GPIO9 as high (even though HPD isn't 167826cff3fSPhilip Chen * actually connected to GPIO9). 168826cff3fSPhilip Chen */ 169cb8e30ddSDouglas Anderson ret = regmap_read_poll_timeout(map, PAGE2_GPIO_H, status, 17042240113SPin-yen Lin status & PS_GPIO9, 20000, wait_us); 171cb8e30ddSDouglas Anderson 172cb8e30ddSDouglas Anderson /* 173cb8e30ddSDouglas Anderson * The first time we see HPD go high after a reset we delay an extra 174cb8e30ddSDouglas Anderson * 50 ms. The best guess is that the MCU is doing "stuff" during this 175cb8e30ddSDouglas Anderson * time (maybe talking to the panel) and we don't want to interrupt it. 176cb8e30ddSDouglas Anderson * 177cb8e30ddSDouglas Anderson * No locking is done around "need_post_hpd_delay". If we're here we 178cb8e30ddSDouglas Anderson * know we're holding a PM Runtime reference and the only other place 179cb8e30ddSDouglas Anderson * that touches this is PM Runtime resume. 180cb8e30ddSDouglas Anderson */ 181cb8e30ddSDouglas Anderson if (!ret && ps_bridge->need_post_hpd_delay) { 182cb8e30ddSDouglas Anderson ps_bridge->need_post_hpd_delay = false; 183cb8e30ddSDouglas Anderson msleep(50); 184cb8e30ddSDouglas Anderson } 185cb8e30ddSDouglas Anderson 186cb8e30ddSDouglas Anderson return ret; 187f5aa7d46SDouglas Anderson } 188826cff3fSPhilip Chen 189f5aa7d46SDouglas Anderson static int ps8640_wait_hpd_asserted(struct drm_dp_aux *aux, unsigned long wait_us) 190f5aa7d46SDouglas Anderson { 191f5aa7d46SDouglas Anderson struct ps8640 *ps_bridge = aux_to_ps8640(aux); 192f5aa7d46SDouglas Anderson struct device *dev = &ps_bridge->page[PAGE0_DP_CNTL]->dev; 193f5aa7d46SDouglas Anderson int ret; 194f5aa7d46SDouglas Anderson 195f5aa7d46SDouglas Anderson /* 196f5aa7d46SDouglas Anderson * Note that this function is called by code that has already powered 197f5aa7d46SDouglas Anderson * the panel. We have to power ourselves up but we don't need to worry 198f5aa7d46SDouglas Anderson * about powering the panel. 199f5aa7d46SDouglas Anderson */ 200f5aa7d46SDouglas Anderson pm_runtime_get_sync(dev); 201f5aa7d46SDouglas Anderson ret = _ps8640_wait_hpd_asserted(ps_bridge, wait_us); 202f5aa7d46SDouglas Anderson pm_runtime_mark_last_busy(dev); 203f5aa7d46SDouglas Anderson pm_runtime_put_autosuspend(dev); 204826cff3fSPhilip Chen 205826cff3fSPhilip Chen return ret; 206826cff3fSPhilip Chen } 207826cff3fSPhilip Chen 208826cff3fSPhilip Chen static ssize_t ps8640_aux_transfer_msg(struct drm_dp_aux *aux, 20913afcdd7SPhilip Chen struct drm_dp_aux_msg *msg) 21013afcdd7SPhilip Chen { 21113afcdd7SPhilip Chen struct ps8640 *ps_bridge = aux_to_ps8640(aux); 21213afcdd7SPhilip Chen struct regmap *map = ps_bridge->regmap[PAGE0_DP_CNTL]; 21313afcdd7SPhilip Chen struct device *dev = &ps_bridge->page[PAGE0_DP_CNTL]->dev; 21435ba6bd5SDouglas Anderson size_t len = msg->size; 21513afcdd7SPhilip Chen unsigned int data; 21613afcdd7SPhilip Chen unsigned int base; 21713afcdd7SPhilip Chen int ret; 21813afcdd7SPhilip Chen u8 request = msg->request & 21913afcdd7SPhilip Chen ~(DP_AUX_I2C_MOT | DP_AUX_I2C_WRITE_STATUS_UPDATE); 22013afcdd7SPhilip Chen u8 *buf = msg->buffer; 22113afcdd7SPhilip Chen u8 addr_len[PAGE0_SWAUX_LENGTH + 1 - PAGE0_SWAUX_ADDR_7_0]; 22213afcdd7SPhilip Chen u8 i; 22313afcdd7SPhilip Chen bool is_native_aux = false; 22413afcdd7SPhilip Chen 22513afcdd7SPhilip Chen if (len > DP_AUX_MAX_PAYLOAD_BYTES) 22613afcdd7SPhilip Chen return -EINVAL; 22713afcdd7SPhilip Chen 22813afcdd7SPhilip Chen if (msg->address & ~SWAUX_ADDR_MASK) 22913afcdd7SPhilip Chen return -EINVAL; 23013afcdd7SPhilip Chen 23113afcdd7SPhilip Chen switch (request) { 23213afcdd7SPhilip Chen case DP_AUX_NATIVE_WRITE: 23313afcdd7SPhilip Chen case DP_AUX_NATIVE_READ: 23413afcdd7SPhilip Chen is_native_aux = true; 23513afcdd7SPhilip Chen fallthrough; 23613afcdd7SPhilip Chen case DP_AUX_I2C_WRITE: 23713afcdd7SPhilip Chen case DP_AUX_I2C_READ: 23813afcdd7SPhilip Chen break; 23913afcdd7SPhilip Chen default: 24013afcdd7SPhilip Chen return -EINVAL; 24113afcdd7SPhilip Chen } 24213afcdd7SPhilip Chen 24313afcdd7SPhilip Chen ret = regmap_write(map, PAGE0_AUXCH_CFG3, AUXCH_CFG3_RESET); 24413afcdd7SPhilip Chen if (ret) { 24513afcdd7SPhilip Chen DRM_DEV_ERROR(dev, "failed to write PAGE0_AUXCH_CFG3: %d\n", 24613afcdd7SPhilip Chen ret); 24713afcdd7SPhilip Chen return ret; 24813afcdd7SPhilip Chen } 24913afcdd7SPhilip Chen 25013afcdd7SPhilip Chen /* Assume it's good */ 25113afcdd7SPhilip Chen msg->reply = 0; 25213afcdd7SPhilip Chen 25313afcdd7SPhilip Chen base = PAGE0_SWAUX_ADDR_7_0; 25413afcdd7SPhilip Chen addr_len[PAGE0_SWAUX_ADDR_7_0 - base] = msg->address; 25513afcdd7SPhilip Chen addr_len[PAGE0_SWAUX_ADDR_15_8 - base] = msg->address >> 8; 25613afcdd7SPhilip Chen addr_len[PAGE0_SWAUX_ADDR_23_16 - base] = (msg->address >> 16) | 25713afcdd7SPhilip Chen (msg->request << 4); 25813afcdd7SPhilip Chen addr_len[PAGE0_SWAUX_LENGTH - base] = (len == 0) ? SWAUX_NO_PAYLOAD : 25913afcdd7SPhilip Chen ((len - 1) & SWAUX_LENGTH_MASK); 26013afcdd7SPhilip Chen 26113afcdd7SPhilip Chen regmap_bulk_write(map, PAGE0_SWAUX_ADDR_7_0, addr_len, 26213afcdd7SPhilip Chen ARRAY_SIZE(addr_len)); 26313afcdd7SPhilip Chen 26413afcdd7SPhilip Chen if (len && (request == DP_AUX_NATIVE_WRITE || 26513afcdd7SPhilip Chen request == DP_AUX_I2C_WRITE)) { 26613afcdd7SPhilip Chen /* Write to the internal FIFO buffer */ 26713afcdd7SPhilip Chen for (i = 0; i < len; i++) { 26813afcdd7SPhilip Chen ret = regmap_write(map, PAGE0_SWAUX_WDATA, buf[i]); 26913afcdd7SPhilip Chen if (ret) { 27013afcdd7SPhilip Chen DRM_DEV_ERROR(dev, 27113afcdd7SPhilip Chen "failed to write WDATA: %d\n", 27213afcdd7SPhilip Chen ret); 27313afcdd7SPhilip Chen return ret; 27413afcdd7SPhilip Chen } 27513afcdd7SPhilip Chen } 27613afcdd7SPhilip Chen } 27713afcdd7SPhilip Chen 27813afcdd7SPhilip Chen regmap_write(map, PAGE0_SWAUX_CTRL, SWAUX_SEND); 27913afcdd7SPhilip Chen 28013afcdd7SPhilip Chen /* Zero delay loop because i2c transactions are slow already */ 28113afcdd7SPhilip Chen regmap_read_poll_timeout(map, PAGE0_SWAUX_CTRL, data, 28213afcdd7SPhilip Chen !(data & SWAUX_SEND), 0, 50 * 1000); 28313afcdd7SPhilip Chen 28413afcdd7SPhilip Chen regmap_read(map, PAGE0_SWAUX_STATUS, &data); 28513afcdd7SPhilip Chen if (ret) { 28613afcdd7SPhilip Chen DRM_DEV_ERROR(dev, "failed to read PAGE0_SWAUX_STATUS: %d\n", 28713afcdd7SPhilip Chen ret); 28813afcdd7SPhilip Chen return ret; 28913afcdd7SPhilip Chen } 29013afcdd7SPhilip Chen 29113afcdd7SPhilip Chen switch (data & SWAUX_STATUS_MASK) { 29213afcdd7SPhilip Chen case SWAUX_STATUS_NACK: 29313afcdd7SPhilip Chen case SWAUX_STATUS_I2C_NACK: 29413afcdd7SPhilip Chen /* 29513afcdd7SPhilip Chen * The programming guide is not clear about whether a I2C NACK 29613afcdd7SPhilip Chen * would trigger SWAUX_STATUS_NACK or SWAUX_STATUS_I2C_NACK. So 29713afcdd7SPhilip Chen * we handle both cases together. 29813afcdd7SPhilip Chen */ 29913afcdd7SPhilip Chen if (is_native_aux) 30013afcdd7SPhilip Chen msg->reply |= DP_AUX_NATIVE_REPLY_NACK; 30113afcdd7SPhilip Chen else 30213afcdd7SPhilip Chen msg->reply |= DP_AUX_I2C_REPLY_NACK; 30313afcdd7SPhilip Chen 30413afcdd7SPhilip Chen fallthrough; 30513afcdd7SPhilip Chen case SWAUX_STATUS_ACKM: 30613afcdd7SPhilip Chen len = data & SWAUX_M_MASK; 30713afcdd7SPhilip Chen break; 308562d2dd8SJason Yen case SWAUX_STATUS_DEFER: 309562d2dd8SJason Yen case SWAUX_STATUS_I2C_DEFER: 310562d2dd8SJason Yen if (is_native_aux) 311562d2dd8SJason Yen msg->reply |= DP_AUX_NATIVE_REPLY_DEFER; 312562d2dd8SJason Yen else 313562d2dd8SJason Yen msg->reply |= DP_AUX_I2C_REPLY_DEFER; 314562d2dd8SJason Yen len = data & SWAUX_M_MASK; 315562d2dd8SJason Yen break; 31613afcdd7SPhilip Chen case SWAUX_STATUS_INVALID: 31713afcdd7SPhilip Chen return -EOPNOTSUPP; 31813afcdd7SPhilip Chen case SWAUX_STATUS_TIMEOUT: 31913afcdd7SPhilip Chen return -ETIMEDOUT; 32013afcdd7SPhilip Chen } 32113afcdd7SPhilip Chen 32213afcdd7SPhilip Chen if (len && (request == DP_AUX_NATIVE_READ || 32313afcdd7SPhilip Chen request == DP_AUX_I2C_READ)) { 32413afcdd7SPhilip Chen /* Read from the internal FIFO buffer */ 32513afcdd7SPhilip Chen for (i = 0; i < len; i++) { 32613afcdd7SPhilip Chen ret = regmap_read(map, PAGE0_SWAUX_RDATA, &data); 32713afcdd7SPhilip Chen if (ret) { 32813afcdd7SPhilip Chen DRM_DEV_ERROR(dev, 32913afcdd7SPhilip Chen "failed to read RDATA: %d\n", 33013afcdd7SPhilip Chen ret); 33113afcdd7SPhilip Chen return ret; 33213afcdd7SPhilip Chen } 33313afcdd7SPhilip Chen 3343164c8a7SDouglas Anderson if (i < msg->size) 33513afcdd7SPhilip Chen buf[i] = data; 33613afcdd7SPhilip Chen } 33713afcdd7SPhilip Chen } 33813afcdd7SPhilip Chen 3393164c8a7SDouglas Anderson return min(len, msg->size); 34013afcdd7SPhilip Chen } 34113afcdd7SPhilip Chen 342826cff3fSPhilip Chen static ssize_t ps8640_aux_transfer(struct drm_dp_aux *aux, 343826cff3fSPhilip Chen struct drm_dp_aux_msg *msg) 344826cff3fSPhilip Chen { 345826cff3fSPhilip Chen struct ps8640 *ps_bridge = aux_to_ps8640(aux); 346826cff3fSPhilip Chen struct device *dev = &ps_bridge->page[PAGE0_DP_CNTL]->dev; 347826cff3fSPhilip Chen int ret; 348826cff3fSPhilip Chen 349*26db46bcSPin-yen Lin mutex_lock(&ps_bridge->aux_lock); 350826cff3fSPhilip Chen pm_runtime_get_sync(dev); 351024b32dbSDouglas Anderson ret = _ps8640_wait_hpd_asserted(ps_bridge, 200 * 1000); 352024b32dbSDouglas Anderson if (ret) { 353024b32dbSDouglas Anderson pm_runtime_put_sync_suspend(dev); 354024b32dbSDouglas Anderson return ret; 355024b32dbSDouglas Anderson } 356826cff3fSPhilip Chen ret = ps8640_aux_transfer_msg(aux, msg); 357826cff3fSPhilip Chen pm_runtime_mark_last_busy(dev); 358826cff3fSPhilip Chen pm_runtime_put_autosuspend(dev); 359*26db46bcSPin-yen Lin mutex_unlock(&ps_bridge->aux_lock); 360826cff3fSPhilip Chen 361826cff3fSPhilip Chen return ret; 362826cff3fSPhilip Chen } 363826cff3fSPhilip Chen 364826cff3fSPhilip Chen static void ps8640_bridge_vdo_control(struct ps8640 *ps_bridge, 365bc1aee7fSJitao Shi const enum ps8640_vdo_control ctrl) 366bc1aee7fSJitao Shi { 367692d8db0SPhilip Chen struct regmap *map = ps_bridge->regmap[PAGE3_DSI_CNTL1]; 368826cff3fSPhilip Chen struct device *dev = &ps_bridge->page[PAGE3_DSI_CNTL1]->dev; 369bc1aee7fSJitao Shi u8 vdo_ctrl_buf[] = { VDO_CTL_ADD, ctrl }; 370bc1aee7fSJitao Shi int ret; 371bc1aee7fSJitao Shi 372692d8db0SPhilip Chen ret = regmap_bulk_write(map, PAGE3_SET_ADD, 373692d8db0SPhilip Chen vdo_ctrl_buf, sizeof(vdo_ctrl_buf)); 374692d8db0SPhilip Chen 375826cff3fSPhilip Chen if (ret < 0) 376826cff3fSPhilip Chen dev_err(dev, "failed to %sable VDO: %d\n", 37794d4c132SEnric Balletbo i Serra ctrl == ENABLE ? "en" : "dis", ret); 37894d4c132SEnric Balletbo i Serra } 379bc1aee7fSJitao Shi 380826cff3fSPhilip Chen static int __maybe_unused ps8640_resume(struct device *dev) 381bc1aee7fSJitao Shi { 382826cff3fSPhilip Chen struct ps8640 *ps_bridge = dev_get_drvdata(dev); 383826cff3fSPhilip Chen int ret; 38446f20630SEnric Balletbo i Serra 385bc1aee7fSJitao Shi ret = regulator_bulk_enable(ARRAY_SIZE(ps_bridge->supplies), 386bc1aee7fSJitao Shi ps_bridge->supplies); 387bc1aee7fSJitao Shi if (ret < 0) { 388826cff3fSPhilip Chen dev_err(dev, "cannot enable regulators %d\n", ret); 389826cff3fSPhilip Chen return ret; 390bc1aee7fSJitao Shi } 391bc1aee7fSJitao Shi 392bc1aee7fSJitao Shi gpiod_set_value(ps_bridge->gpio_powerdown, 0); 393bc1aee7fSJitao Shi gpiod_set_value(ps_bridge->gpio_reset, 1); 394bc1aee7fSJitao Shi usleep_range(2000, 2500); 395bc1aee7fSJitao Shi gpiod_set_value(ps_bridge->gpio_reset, 0); 39655453c09SHsin-Yi Wang /* Double reset for T4 and T5 */ 39755453c09SHsin-Yi Wang msleep(50); 39855453c09SHsin-Yi Wang gpiod_set_value(ps_bridge->gpio_reset, 1); 39955453c09SHsin-Yi Wang msleep(50); 40055453c09SHsin-Yi Wang gpiod_set_value(ps_bridge->gpio_reset, 0); 401bc1aee7fSJitao Shi 402cb8e30ddSDouglas Anderson /* We just reset things, so we need a delay after the first HPD */ 403cb8e30ddSDouglas Anderson ps_bridge->need_post_hpd_delay = true; 404cb8e30ddSDouglas Anderson 405bc1aee7fSJitao Shi /* 406826cff3fSPhilip Chen * Mystery 200 ms delay for the "MCU to be ready". It's unclear if 407826cff3fSPhilip Chen * this is truly necessary since the MCU will already signal that 408826cff3fSPhilip Chen * things are "good to go" by signaling HPD on "gpio 9". See 409f5aa7d46SDouglas Anderson * _ps8640_wait_hpd_asserted(). For now we'll keep this mystery delay 410f5aa7d46SDouglas Anderson * just in case. 411bc1aee7fSJitao Shi */ 412bc1aee7fSJitao Shi msleep(200); 413bc1aee7fSJitao Shi 414826cff3fSPhilip Chen return 0; 415bc1aee7fSJitao Shi } 416bc1aee7fSJitao Shi 417826cff3fSPhilip Chen static int __maybe_unused ps8640_suspend(struct device *dev) 418826cff3fSPhilip Chen { 419826cff3fSPhilip Chen struct ps8640 *ps_bridge = dev_get_drvdata(dev); 420826cff3fSPhilip Chen int ret; 421826cff3fSPhilip Chen 422826cff3fSPhilip Chen gpiod_set_value(ps_bridge->gpio_reset, 1); 423826cff3fSPhilip Chen gpiod_set_value(ps_bridge->gpio_powerdown, 1); 424826cff3fSPhilip Chen ret = regulator_bulk_disable(ARRAY_SIZE(ps_bridge->supplies), 425826cff3fSPhilip Chen ps_bridge->supplies); 426826cff3fSPhilip Chen if (ret < 0) 427826cff3fSPhilip Chen dev_err(dev, "cannot disable regulators %d\n", ret); 428826cff3fSPhilip Chen 429826cff3fSPhilip Chen return ret; 430826cff3fSPhilip Chen } 431826cff3fSPhilip Chen 432826cff3fSPhilip Chen static const struct dev_pm_ops ps8640_pm_ops = { 433826cff3fSPhilip Chen SET_RUNTIME_PM_OPS(ps8640_suspend, ps8640_resume, NULL) 434826cff3fSPhilip Chen SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 435826cff3fSPhilip Chen pm_runtime_force_resume) 436826cff3fSPhilip Chen }; 437826cff3fSPhilip Chen 438102e80d1SSam Ravnborg static void ps8640_atomic_pre_enable(struct drm_bridge *bridge, 439102e80d1SSam Ravnborg struct drm_bridge_state *old_bridge_state) 440826cff3fSPhilip Chen { 441826cff3fSPhilip Chen struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); 442826cff3fSPhilip Chen struct regmap *map = ps_bridge->regmap[PAGE2_TOP_CNTL]; 443826cff3fSPhilip Chen struct device *dev = &ps_bridge->page[PAGE0_DP_CNTL]->dev; 444826cff3fSPhilip Chen int ret; 445826cff3fSPhilip Chen 446826cff3fSPhilip Chen pm_runtime_get_sync(dev); 447f5aa7d46SDouglas Anderson ret = _ps8640_wait_hpd_asserted(ps_bridge, 200 * 1000); 448f5aa7d46SDouglas Anderson if (ret < 0) 449f5aa7d46SDouglas Anderson dev_warn(dev, "HPD didn't go high: %d\n", ret); 450bc1aee7fSJitao Shi 451bc1aee7fSJitao Shi /* 452bc1aee7fSJitao Shi * The Manufacturer Command Set (MCS) is a device dependent interface 453bc1aee7fSJitao Shi * intended for factory programming of the display module default 454bc1aee7fSJitao Shi * parameters. Once the display module is configured, the MCS shall be 455bc1aee7fSJitao Shi * disabled by the manufacturer. Once disabled, all MCS commands are 456bc1aee7fSJitao Shi * ignored by the display interface. 457bc1aee7fSJitao Shi */ 458bc1aee7fSJitao Shi 459692d8db0SPhilip Chen ret = regmap_update_bits(map, PAGE2_MCS_EN, MCS_EN, 0); 460826cff3fSPhilip Chen if (ret < 0) 461826cff3fSPhilip Chen dev_warn(dev, "failed write PAGE2_MCS_EN: %d\n", ret); 462bc1aee7fSJitao Shi 463bc1aee7fSJitao Shi /* Switch access edp panel's edid through i2c */ 464692d8db0SPhilip Chen ret = regmap_write(map, PAGE2_I2C_BYPASS, I2C_BYPASS_EN); 465bc1aee7fSJitao Shi if (ret < 0) 466826cff3fSPhilip Chen dev_warn(dev, "failed write PAGE2_MCS_EN: %d\n", ret); 46746f20630SEnric Balletbo i Serra 468826cff3fSPhilip Chen ps8640_bridge_vdo_control(ps_bridge, ENABLE); 46946f20630SEnric Balletbo i Serra 470826cff3fSPhilip Chen ps_bridge->pre_enabled = true; 47146f20630SEnric Balletbo i Serra } 47246f20630SEnric Balletbo i Serra 473102e80d1SSam Ravnborg static void ps8640_atomic_post_disable(struct drm_bridge *bridge, 474102e80d1SSam Ravnborg struct drm_bridge_state *old_bridge_state) 47546f20630SEnric Balletbo i Serra { 47646f20630SEnric Balletbo i Serra struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); 47746f20630SEnric Balletbo i Serra 478826cff3fSPhilip Chen ps_bridge->pre_enabled = false; 479826cff3fSPhilip Chen 48046f20630SEnric Balletbo i Serra ps8640_bridge_vdo_control(ps_bridge, DISABLE); 481*26db46bcSPin-yen Lin 482*26db46bcSPin-yen Lin /* 483*26db46bcSPin-yen Lin * The bridge seems to expect everything to be power cycled at the 484*26db46bcSPin-yen Lin * disable process, so grab a lock here to make sure 485*26db46bcSPin-yen Lin * ps8640_aux_transfer() is not holding a runtime PM reference and 486*26db46bcSPin-yen Lin * preventing the bridge from suspend. 487*26db46bcSPin-yen Lin */ 488*26db46bcSPin-yen Lin mutex_lock(&ps_bridge->aux_lock); 489*26db46bcSPin-yen Lin 490826cff3fSPhilip Chen pm_runtime_put_sync_suspend(&ps_bridge->page[PAGE0_DP_CNTL]->dev); 491*26db46bcSPin-yen Lin 492*26db46bcSPin-yen Lin mutex_unlock(&ps_bridge->aux_lock); 493bc1aee7fSJitao Shi } 494bc1aee7fSJitao Shi 495a25b988fSLaurent Pinchart static int ps8640_bridge_attach(struct drm_bridge *bridge, 496a25b988fSLaurent Pinchart enum drm_bridge_attach_flags flags) 497bc1aee7fSJitao Shi { 498bc1aee7fSJitao Shi struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); 499bc1aee7fSJitao Shi struct device *dev = &ps_bridge->page[0]->dev; 500bc1aee7fSJitao Shi int ret; 501812a65baSEnric Balletbo i Serra 502812a65baSEnric Balletbo i Serra if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) 503812a65baSEnric Balletbo i Serra return -EINVAL; 504812a65baSEnric Balletbo i Serra 505f8378c04SDouglas Anderson ps_bridge->aux.drm_dev = bridge->dev; 50613afcdd7SPhilip Chen ret = drm_dp_aux_register(&ps_bridge->aux); 50713afcdd7SPhilip Chen if (ret) { 50813afcdd7SPhilip Chen dev_err(dev, "failed to register DP AUX channel: %d\n", ret); 509fe93ae80SMaxime Ripard return ret; 51013afcdd7SPhilip Chen } 511bc1aee7fSJitao Shi 5129294914dSAngeloGioacchino Del Regno ps_bridge->link = device_link_add(bridge->dev->dev, dev, DL_FLAG_STATELESS); 5139294914dSAngeloGioacchino Del Regno if (!ps_bridge->link) { 5149294914dSAngeloGioacchino Del Regno dev_err(dev, "failed to create device link"); 5159294914dSAngeloGioacchino Del Regno ret = -EINVAL; 5169294914dSAngeloGioacchino Del Regno goto err_devlink; 5179294914dSAngeloGioacchino Del Regno } 5189294914dSAngeloGioacchino Del Regno 519bc1aee7fSJitao Shi /* Attach the panel-bridge to the dsi bridge */ 5209294914dSAngeloGioacchino Del Regno ret = drm_bridge_attach(bridge->encoder, ps_bridge->panel_bridge, 521a25b988fSLaurent Pinchart &ps_bridge->bridge, flags); 5229294914dSAngeloGioacchino Del Regno if (ret) 5239294914dSAngeloGioacchino Del Regno goto err_bridge_attach; 5249294914dSAngeloGioacchino Del Regno 5259294914dSAngeloGioacchino Del Regno return 0; 5269294914dSAngeloGioacchino Del Regno 5279294914dSAngeloGioacchino Del Regno err_bridge_attach: 5289294914dSAngeloGioacchino Del Regno device_link_del(ps_bridge->link); 5299294914dSAngeloGioacchino Del Regno err_devlink: 5309294914dSAngeloGioacchino Del Regno drm_dp_aux_unregister(&ps_bridge->aux); 5319294914dSAngeloGioacchino Del Regno 5329294914dSAngeloGioacchino Del Regno return ret; 533bc1aee7fSJitao Shi } 534bc1aee7fSJitao Shi 53513afcdd7SPhilip Chen static void ps8640_bridge_detach(struct drm_bridge *bridge) 53613afcdd7SPhilip Chen { 5379294914dSAngeloGioacchino Del Regno struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); 5389294914dSAngeloGioacchino Del Regno 5399294914dSAngeloGioacchino Del Regno drm_dp_aux_unregister(&ps_bridge->aux); 5409294914dSAngeloGioacchino Del Regno if (ps_bridge->link) 5419294914dSAngeloGioacchino Del Regno device_link_del(ps_bridge->link); 54213afcdd7SPhilip Chen } 54313afcdd7SPhilip Chen 544826cff3fSPhilip Chen static void ps8640_runtime_disable(void *data) 545826cff3fSPhilip Chen { 546826cff3fSPhilip Chen pm_runtime_dont_use_autosuspend(data); 547826cff3fSPhilip Chen pm_runtime_disable(data); 548826cff3fSPhilip Chen } 549826cff3fSPhilip Chen 550bc1aee7fSJitao Shi static const struct drm_bridge_funcs ps8640_bridge_funcs = { 551bc1aee7fSJitao Shi .attach = ps8640_bridge_attach, 55213afcdd7SPhilip Chen .detach = ps8640_bridge_detach, 553102e80d1SSam Ravnborg .atomic_post_disable = ps8640_atomic_post_disable, 554102e80d1SSam Ravnborg .atomic_pre_enable = ps8640_atomic_pre_enable, 555102e80d1SSam Ravnborg .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, 556102e80d1SSam Ravnborg .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, 557102e80d1SSam Ravnborg .atomic_reset = drm_atomic_helper_bridge_reset, 558bc1aee7fSJitao Shi }; 559bc1aee7fSJitao Shi 56010e619f1SDouglas Anderson static int ps8640_bridge_get_dsi_resources(struct device *dev, struct ps8640 *ps_bridge) 5617abbc26fSMaxime Ripard { 5627abbc26fSMaxime Ripard struct device_node *in_ep, *dsi_node; 5637abbc26fSMaxime Ripard struct mipi_dsi_device *dsi; 5647abbc26fSMaxime Ripard struct mipi_dsi_host *host; 5657abbc26fSMaxime Ripard const struct mipi_dsi_device_info info = { .type = "ps8640", 5667abbc26fSMaxime Ripard .channel = 0, 5677abbc26fSMaxime Ripard .node = NULL, 5687abbc26fSMaxime Ripard }; 5697abbc26fSMaxime Ripard 5707abbc26fSMaxime Ripard /* port@0 is ps8640 dsi input port */ 5717abbc26fSMaxime Ripard in_ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1); 5727abbc26fSMaxime Ripard if (!in_ep) 5737abbc26fSMaxime Ripard return -ENODEV; 5747abbc26fSMaxime Ripard 5757abbc26fSMaxime Ripard dsi_node = of_graph_get_remote_port_parent(in_ep); 5767abbc26fSMaxime Ripard of_node_put(in_ep); 5777abbc26fSMaxime Ripard if (!dsi_node) 5787abbc26fSMaxime Ripard return -ENODEV; 5797abbc26fSMaxime Ripard 5807abbc26fSMaxime Ripard host = of_find_mipi_dsi_host_by_node(dsi_node); 5817abbc26fSMaxime Ripard of_node_put(dsi_node); 5827abbc26fSMaxime Ripard if (!host) 5837abbc26fSMaxime Ripard return -EPROBE_DEFER; 5847abbc26fSMaxime Ripard 5857abbc26fSMaxime Ripard dsi = devm_mipi_dsi_device_register_full(dev, host, &info); 5867abbc26fSMaxime Ripard if (IS_ERR(dsi)) { 5877abbc26fSMaxime Ripard dev_err(dev, "failed to create dsi device\n"); 5887abbc26fSMaxime Ripard return PTR_ERR(dsi); 5897abbc26fSMaxime Ripard } 5907abbc26fSMaxime Ripard 5917abbc26fSMaxime Ripard ps_bridge->dsi = dsi; 5927abbc26fSMaxime Ripard 5937abbc26fSMaxime Ripard dsi->host = host; 5947abbc26fSMaxime Ripard dsi->mode_flags = MIPI_DSI_MODE_VIDEO | 5957abbc26fSMaxime Ripard MIPI_DSI_MODE_VIDEO_SYNC_PULSE; 5967abbc26fSMaxime Ripard dsi->format = MIPI_DSI_FMT_RGB888; 5977abbc26fSMaxime Ripard dsi->lanes = NUM_MIPI_LANES; 5987abbc26fSMaxime Ripard 59910e619f1SDouglas Anderson return 0; 60010e619f1SDouglas Anderson } 60110e619f1SDouglas Anderson 60210e619f1SDouglas Anderson static int ps8640_bridge_link_panel(struct drm_dp_aux *aux) 60310e619f1SDouglas Anderson { 60410e619f1SDouglas Anderson struct ps8640 *ps_bridge = aux_to_ps8640(aux); 60510e619f1SDouglas Anderson struct device *dev = aux->dev; 60610e619f1SDouglas Anderson struct device_node *np = dev->of_node; 60710e619f1SDouglas Anderson int ret; 60810e619f1SDouglas Anderson 60910e619f1SDouglas Anderson /* 61010e619f1SDouglas Anderson * NOTE about returning -EPROBE_DEFER from this function: if we 61110e619f1SDouglas Anderson * return an error (most relevant to -EPROBE_DEFER) it will only 61210e619f1SDouglas Anderson * be passed out to ps8640_probe() if it called this directly (AKA the 61310e619f1SDouglas Anderson * panel isn't under the "aux-bus" node). That should be fine because 61410e619f1SDouglas Anderson * if the panel is under "aux-bus" it's guaranteed to have probed by 61510e619f1SDouglas Anderson * the time this function has been called. 61610e619f1SDouglas Anderson */ 61710e619f1SDouglas Anderson 61810e619f1SDouglas Anderson /* port@1 is ps8640 output port */ 61910e619f1SDouglas Anderson ps_bridge->panel_bridge = devm_drm_of_get_bridge(dev, np, 1, 0); 62010e619f1SDouglas Anderson if (IS_ERR(ps_bridge->panel_bridge)) 62110e619f1SDouglas Anderson return PTR_ERR(ps_bridge->panel_bridge); 62210e619f1SDouglas Anderson 62310e619f1SDouglas Anderson ret = devm_drm_bridge_add(dev, &ps_bridge->bridge); 62410e619f1SDouglas Anderson if (ret) 62510e619f1SDouglas Anderson return ret; 62610e619f1SDouglas Anderson 62710e619f1SDouglas Anderson return devm_mipi_dsi_attach(dev, ps_bridge->dsi); 6287abbc26fSMaxime Ripard } 6297abbc26fSMaxime Ripard 630bc1aee7fSJitao Shi static int ps8640_probe(struct i2c_client *client) 631bc1aee7fSJitao Shi { 632bc1aee7fSJitao Shi struct device *dev = &client->dev; 633bc1aee7fSJitao Shi struct ps8640 *ps_bridge; 634bc1aee7fSJitao Shi int ret; 635bc1aee7fSJitao Shi u32 i; 636bc1aee7fSJitao Shi 637bc1aee7fSJitao Shi ps_bridge = devm_kzalloc(dev, sizeof(*ps_bridge), GFP_KERNEL); 638bc1aee7fSJitao Shi if (!ps_bridge) 639bc1aee7fSJitao Shi return -ENOMEM; 640bc1aee7fSJitao Shi 641*26db46bcSPin-yen Lin mutex_init(&ps_bridge->aux_lock); 642*26db46bcSPin-yen Lin 643fc94224cSChen-Yu Tsai ps_bridge->supplies[0].supply = "vdd12"; 644fc94224cSChen-Yu Tsai ps_bridge->supplies[1].supply = "vdd33"; 645bc1aee7fSJitao Shi ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ps_bridge->supplies), 646bc1aee7fSJitao Shi ps_bridge->supplies); 647bc1aee7fSJitao Shi if (ret) 648bc1aee7fSJitao Shi return ret; 649bc1aee7fSJitao Shi 650bc1aee7fSJitao Shi ps_bridge->gpio_powerdown = devm_gpiod_get(&client->dev, "powerdown", 651bc1aee7fSJitao Shi GPIOD_OUT_HIGH); 652bc1aee7fSJitao Shi if (IS_ERR(ps_bridge->gpio_powerdown)) 653bc1aee7fSJitao Shi return PTR_ERR(ps_bridge->gpio_powerdown); 654bc1aee7fSJitao Shi 655bc1aee7fSJitao Shi /* 656bc1aee7fSJitao Shi * Assert the reset to avoid the bridge being initialized prematurely 657bc1aee7fSJitao Shi */ 658bc1aee7fSJitao Shi ps_bridge->gpio_reset = devm_gpiod_get(&client->dev, "reset", 659bc1aee7fSJitao Shi GPIOD_OUT_HIGH); 660bc1aee7fSJitao Shi if (IS_ERR(ps_bridge->gpio_reset)) 661bc1aee7fSJitao Shi return PTR_ERR(ps_bridge->gpio_reset); 662bc1aee7fSJitao Shi 663bc1aee7fSJitao Shi ps_bridge->bridge.funcs = &ps8640_bridge_funcs; 664bc1aee7fSJitao Shi ps_bridge->bridge.of_node = dev->of_node; 665d82c12abSEnric Balletbo i Serra ps_bridge->bridge.type = DRM_MODE_CONNECTOR_eDP; 666bc1aee7fSJitao Shi 667e9d9f958SPhilip Chen /* 66810e619f1SDouglas Anderson * Get MIPI DSI resources early. These can return -EPROBE_DEFER so 66910e619f1SDouglas Anderson * we want to get them out of the way sooner. 67010e619f1SDouglas Anderson */ 67110e619f1SDouglas Anderson ret = ps8640_bridge_get_dsi_resources(&client->dev, ps_bridge); 67210e619f1SDouglas Anderson if (ret) 67310e619f1SDouglas Anderson return ret; 67410e619f1SDouglas Anderson 675bc1aee7fSJitao Shi ps_bridge->page[PAGE0_DP_CNTL] = client; 676bc1aee7fSJitao Shi 677692d8db0SPhilip Chen ps_bridge->regmap[PAGE0_DP_CNTL] = devm_regmap_init_i2c(client, ps8640_regmap_config); 678692d8db0SPhilip Chen if (IS_ERR(ps_bridge->regmap[PAGE0_DP_CNTL])) 679692d8db0SPhilip Chen return PTR_ERR(ps_bridge->regmap[PAGE0_DP_CNTL]); 680692d8db0SPhilip Chen 681bc1aee7fSJitao Shi for (i = 1; i < ARRAY_SIZE(ps_bridge->page); i++) { 682bc1aee7fSJitao Shi ps_bridge->page[i] = devm_i2c_new_dummy_device(&client->dev, 683bc1aee7fSJitao Shi client->adapter, 684bc1aee7fSJitao Shi client->addr + i); 685692d8db0SPhilip Chen if (IS_ERR(ps_bridge->page[i])) 686bc1aee7fSJitao Shi return PTR_ERR(ps_bridge->page[i]); 687692d8db0SPhilip Chen 688692d8db0SPhilip Chen ps_bridge->regmap[i] = devm_regmap_init_i2c(ps_bridge->page[i], 689692d8db0SPhilip Chen ps8640_regmap_config + i); 690692d8db0SPhilip Chen if (IS_ERR(ps_bridge->regmap[i])) 691692d8db0SPhilip Chen return PTR_ERR(ps_bridge->regmap[i]); 692bc1aee7fSJitao Shi } 693bc1aee7fSJitao Shi 694bc1aee7fSJitao Shi i2c_set_clientdata(client, ps_bridge); 695bc1aee7fSJitao Shi 69613afcdd7SPhilip Chen ps_bridge->aux.name = "parade-ps8640-aux"; 69713afcdd7SPhilip Chen ps_bridge->aux.dev = dev; 69813afcdd7SPhilip Chen ps_bridge->aux.transfer = ps8640_aux_transfer; 699f5aa7d46SDouglas Anderson ps_bridge->aux.wait_hpd_asserted = ps8640_wait_hpd_asserted; 70013afcdd7SPhilip Chen drm_dp_aux_init(&ps_bridge->aux); 70113afcdd7SPhilip Chen 702826cff3fSPhilip Chen pm_runtime_enable(dev); 703826cff3fSPhilip Chen /* 704826cff3fSPhilip Chen * Powering on ps8640 takes ~300ms. To avoid wasting time on power 705b1d2751cSDrew Davenport * cycling ps8640 too often, set autosuspend_delay to 2000ms to ensure 706826cff3fSPhilip Chen * the bridge wouldn't suspend in between each _aux_transfer_msg() call 707826cff3fSPhilip Chen * during EDID read (~20ms in my experiment) and in between the last 708826cff3fSPhilip Chen * _aux_transfer_msg() call during EDID read and the _pre_enable() call 709826cff3fSPhilip Chen * (~100ms in my experiment). 710826cff3fSPhilip Chen */ 711b1d2751cSDrew Davenport pm_runtime_set_autosuspend_delay(dev, 2000); 712826cff3fSPhilip Chen pm_runtime_use_autosuspend(dev); 713826cff3fSPhilip Chen pm_suspend_ignore_children(dev, true); 714826cff3fSPhilip Chen ret = devm_add_action_or_reset(dev, ps8640_runtime_disable, dev); 715826cff3fSPhilip Chen if (ret) 716826cff3fSPhilip Chen return ret; 717826cff3fSPhilip Chen 71810e619f1SDouglas Anderson ret = devm_of_dp_aux_populate_bus(&ps_bridge->aux, ps8640_bridge_link_panel); 719e9d9f958SPhilip Chen 72010e619f1SDouglas Anderson /* 72110e619f1SDouglas Anderson * If devm_of_dp_aux_populate_bus() returns -ENODEV then it's up to 72210e619f1SDouglas Anderson * usa to call ps8640_bridge_link_panel() directly. NOTE: in this case 72310e619f1SDouglas Anderson * the function is allowed to -EPROBE_DEFER. 72410e619f1SDouglas Anderson */ 72510e619f1SDouglas Anderson if (ret == -ENODEV) 72610e619f1SDouglas Anderson return ps8640_bridge_link_panel(&ps_bridge->aux); 727e9d9f958SPhilip Chen 7287abbc26fSMaxime Ripard return ret; 729bc1aee7fSJitao Shi } 730bc1aee7fSJitao Shi 731bc1aee7fSJitao Shi static const struct of_device_id ps8640_match[] = { 732bc1aee7fSJitao Shi { .compatible = "parade,ps8640" }, 733bc1aee7fSJitao Shi { } 734bc1aee7fSJitao Shi }; 735bc1aee7fSJitao Shi MODULE_DEVICE_TABLE(of, ps8640_match); 736bc1aee7fSJitao Shi 737bc1aee7fSJitao Shi static struct i2c_driver ps8640_driver = { 738332af828SUwe Kleine-König .probe = ps8640_probe, 739bc1aee7fSJitao Shi .driver = { 740bc1aee7fSJitao Shi .name = "ps8640", 741bc1aee7fSJitao Shi .of_match_table = ps8640_match, 742826cff3fSPhilip Chen .pm = &ps8640_pm_ops, 743bc1aee7fSJitao Shi }, 744bc1aee7fSJitao Shi }; 745bc1aee7fSJitao Shi module_i2c_driver(ps8640_driver); 746bc1aee7fSJitao Shi 747bc1aee7fSJitao Shi MODULE_AUTHOR("Jitao Shi <jitao.shi@mediatek.com>"); 748bc1aee7fSJitao Shi MODULE_AUTHOR("CK Hu <ck.hu@mediatek.com>"); 749bc1aee7fSJitao Shi MODULE_AUTHOR("Enric Balletbo i Serra <enric.balletbo@collabora.com>"); 750bc1aee7fSJitao Shi MODULE_DESCRIPTION("PARADE ps8640 DSI-eDP converter driver"); 751bc1aee7fSJitao Shi MODULE_LICENSE("GPL v2"); 752