/* * PS8640 uses multiple addresses: * page[0]: for DP control * page[1]: for VIDEO Bridge * page[2]: for control top * page[3]: for DSI Link Control1 * page[4]: for MIPI Phy * page[5]: for VPLL * page[6]: for DSI Link Control2 * page[7]: for SPI ROM mapping
*/ enum page_addr_offset {
PAGE0_DP_CNTL = 0,
PAGE1_VDO_BDG,
PAGE2_TOP_CNTL,
PAGE3_DSI_CNTL1,
PAGE4_MIPI_PHY,
PAGE5_VPLL,
PAGE6_DSI_CNTL2,
PAGE7_SPI_CNTL,
MAX_DEVS
};
staticint _ps8640_wait_hpd_asserted(struct ps8640 *ps_bridge, unsignedlong wait_us)
{ struct regmap *map = ps_bridge->regmap[PAGE2_TOP_CNTL]; int status; int ret;
/* * Apparently something about the firmware in the chip signals that * HPD goes high by reporting GPIO9 as high (even though HPD isn't * actually connected to GPIO9).
*/
ret = regmap_read_poll_timeout(map, PAGE2_GPIO_H, status,
status & PS_GPIO9, 20000, wait_us);
/* * The first time we see HPD go high after a reset we delay an extra * 50 ms. The best guess is that the MCU is doing "stuff" during this * time (maybe talking to the panel) and we don't want to interrupt it. * * No locking is done around "need_post_hpd_delay". If we're here we * know we're holding a PM Runtime reference and the only other place * that touches this is PM Runtime resume.
*/ if (!ret && ps_bridge->need_post_hpd_delay) {
ps_bridge->need_post_hpd_delay = false;
msleep(50);
}
/* * Note that this function is called by code that has already powered * the panel. We have to power ourselves up but we don't need to worry * about powering the panel.
*/
pm_runtime_get_sync(dev);
ret = _ps8640_wait_hpd_asserted(ps_bridge, wait_us);
pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev);
if (len > DP_AUX_MAX_PAYLOAD_BYTES) return -EINVAL;
if (msg->address & ~SWAUX_ADDR_MASK) return -EINVAL;
switch (request) { case DP_AUX_NATIVE_WRITE: case DP_AUX_NATIVE_READ:
is_native_aux = true;
fallthrough; case DP_AUX_I2C_WRITE: case DP_AUX_I2C_READ: break; default: return -EINVAL;
}
ret = regmap_write(map, PAGE0_AUXCH_CFG3, AUXCH_CFG3_RESET); if (ret) {
DRM_DEV_ERROR(dev, "failed to write PAGE0_AUXCH_CFG3: %d\n",
ret); return ret;
}
if (len && (request == DP_AUX_NATIVE_WRITE ||
request == DP_AUX_I2C_WRITE)) { /* Write to the internal FIFO buffer */ for (i = 0; i < len; i++) {
ret = regmap_write(map, PAGE0_SWAUX_WDATA, buf[i]); if (ret) {
DRM_DEV_ERROR(dev, "failed to write WDATA: %d\n",
ret); return ret;
}
}
}
regmap_write(map, PAGE0_SWAUX_CTRL, SWAUX_SEND);
/* Zero delay loop because i2c transactions are slow already */
regmap_read_poll_timeout(map, PAGE0_SWAUX_CTRL, data,
!(data & SWAUX_SEND), 0, 50 * 1000);
regmap_read(map, PAGE0_SWAUX_STATUS, &data); if (ret) {
DRM_DEV_ERROR(dev, "failed to read PAGE0_SWAUX_STATUS: %d\n",
ret); return ret;
}
switch (data & SWAUX_STATUS_MASK) { case SWAUX_STATUS_NACK: case SWAUX_STATUS_I2C_NACK: /* * The programming guide is not clear about whether a I2C NACK * would trigger SWAUX_STATUS_NACK or SWAUX_STATUS_I2C_NACK. So * we handle both cases together.
*/ if (is_native_aux)
msg->reply |= DP_AUX_NATIVE_REPLY_NACK; else
msg->reply |= DP_AUX_I2C_REPLY_NACK;
fallthrough; case SWAUX_STATUS_ACKM:
len = data & SWAUX_M_MASK; break; case SWAUX_STATUS_DEFER: case SWAUX_STATUS_I2C_DEFER: if (is_native_aux)
msg->reply |= DP_AUX_NATIVE_REPLY_DEFER; else
msg->reply |= DP_AUX_I2C_REPLY_DEFER;
len = data & SWAUX_M_MASK; break; case SWAUX_STATUS_INVALID: return -EOPNOTSUPP; case SWAUX_STATUS_TIMEOUT: return -ETIMEDOUT;
}
if (len && (request == DP_AUX_NATIVE_READ ||
request == DP_AUX_I2C_READ)) { /* Read from the internal FIFO buffer */ for (i = 0; i < len; i++) {
ret = regmap_read(map, PAGE0_SWAUX_RDATA, &data); if (ret) {
DRM_DEV_ERROR(dev, "failed to read RDATA: %d\n",
ret); return ret;
}
/* We just reset things, so we need a delay after the first HPD */
ps_bridge->need_post_hpd_delay = true;
/* * Mystery 200 ms delay for the "MCU to be ready". It's unclear if * this is truly necessary since the MCU will already signal that * things are "good to go" by signaling HPD on "gpio 9". See * _ps8640_wait_hpd_asserted(). For now we'll keep this mystery delay * just in case.
*/
msleep(200);
pm_runtime_get_sync(dev);
ret = _ps8640_wait_hpd_asserted(ps_bridge, 200 * 1000); if (ret < 0)
dev_warn(dev, "HPD didn't go high: %d\n", ret);
/* * The Manufacturer Command Set (MCS) is a device dependent interface * intended for factory programming of the display module default * parameters. Once the display module is configured, the MCS shall be * disabled by the manufacturer. Once disabled, all MCS commands are * ignored by the display interface.
*/
ret = regmap_update_bits(map, PAGE2_MCS_EN, MCS_EN, 0); if (ret < 0)
dev_warn(dev, "failed write PAGE2_MCS_EN: %d\n", ret);
/* Switch access edp panel's edid through i2c */
ret = regmap_write(map, PAGE2_I2C_BYPASS, I2C_BYPASS_EN); if (ret < 0)
dev_warn(dev, "failed write PAGE2_MCS_EN: %d\n", ret);
/* * The bridge seems to expect everything to be power cycled at the * disable process, so grab a lock here to make sure * ps8640_aux_transfer() is not holding a runtime PM reference and * preventing the bridge from suspend.
*/
mutex_lock(&ps_bridge->aux_lock);
if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) return -EINVAL;
ps_bridge->aux.drm_dev = bridge->dev;
ret = drm_dp_aux_register(&ps_bridge->aux); if (ret) {
dev_err(dev, "failed to register DP AUX channel: %d\n", ret); return ret;
}
ps_bridge->link = device_link_add(bridge->dev->dev, dev, DL_FLAG_STATELESS); if (!ps_bridge->link) {
dev_err(dev, "failed to create device link");
ret = -EINVAL; goto err_devlink;
}
/* Attach the panel-bridge to the dsi bridge */
ret = drm_bridge_attach(encoder, ps_bridge->panel_bridge,
&ps_bridge->bridge, flags); if (ret) goto err_bridge_attach;
/* * NOTE about returning -EPROBE_DEFER from this function: if we * return an error (most relevant to -EPROBE_DEFER) it will only * be passed out to ps8640_probe() if it called this directly (AKA the * panel isn't under the "aux-bus" node). That should be fine because * if the panel is under "aux-bus" it's guaranteed to have probed by * the time this function has been called.
*/
/* port@1 is ps8640 output port */
ps_bridge->panel_bridge = devm_drm_of_get_bridge(dev, np, 1, 0); if (IS_ERR(ps_bridge->panel_bridge)) return PTR_ERR(ps_bridge->panel_bridge);
ret = devm_drm_bridge_add(dev, &ps_bridge->bridge); if (ret) return ret;
ps_bridge->supplies[0].supply = "vdd12";
ps_bridge->supplies[1].supply = "vdd33";
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ps_bridge->supplies),
ps_bridge->supplies); if (ret) return ret;
ps_bridge->gpio_powerdown = devm_gpiod_get(&client->dev, "powerdown",
GPIOD_OUT_HIGH); if (IS_ERR(ps_bridge->gpio_powerdown)) return PTR_ERR(ps_bridge->gpio_powerdown);
/* * Assert the reset to avoid the bridge being initialized prematurely
*/
ps_bridge->gpio_reset = devm_gpiod_get(&client->dev, "reset",
GPIOD_OUT_HIGH); if (IS_ERR(ps_bridge->gpio_reset)) return PTR_ERR(ps_bridge->gpio_reset);
/* * Get MIPI DSI resources early. These can return -EPROBE_DEFER so * we want to get them out of the way sooner.
*/
ret = ps8640_bridge_get_dsi_resources(&client->dev, ps_bridge); if (ret) return ret;
ps_bridge->page[PAGE0_DP_CNTL] = client;
ps_bridge->regmap[PAGE0_DP_CNTL] = devm_regmap_init_i2c(client, ps8640_regmap_config); if (IS_ERR(ps_bridge->regmap[PAGE0_DP_CNTL])) return PTR_ERR(ps_bridge->regmap[PAGE0_DP_CNTL]);
for (i = 1; i < ARRAY_SIZE(ps_bridge->page); i++) {
ps_bridge->page[i] = devm_i2c_new_dummy_device(&client->dev,
client->adapter,
client->addr + i); if (IS_ERR(ps_bridge->page[i])) return PTR_ERR(ps_bridge->page[i]);
pm_runtime_enable(dev); /* * Powering on ps8640 takes ~300ms. To avoid wasting time on power * cycling ps8640 too often, set autosuspend_delay to 2000ms to ensure * the bridge wouldn't suspend in between each _aux_transfer_msg() call * during EDID read (~20ms in my experiment) and in between the last * _aux_transfer_msg() call during EDID read and the _pre_enable() call * (~100ms in my experiment).
*/
pm_runtime_set_autosuspend_delay(dev, 2000);
pm_runtime_use_autosuspend(dev);
pm_suspend_ignore_children(dev, true);
ret = devm_add_action_or_reset(dev, ps8640_runtime_disable, dev); if (ret) return ret;
ret = devm_of_dp_aux_populate_bus(&ps_bridge->aux, ps8640_bridge_link_panel);
/* * If devm_of_dp_aux_populate_bus() returns -ENODEV then it's up to * usa to call ps8640_bridge_link_panel() directly. NOTE: in this case * the function is allowed to -EPROBE_DEFER.
*/ if (ret == -ENODEV) return ps8640_bridge_link_panel(&ps_bridge->aux);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.