static uint zynqmp_dp_aux_timeout_ms = 50;
module_param_named(aux_timeout_ms, zynqmp_dp_aux_timeout_ms, uint, 0444);
MODULE_PARM_DESC(aux_timeout_ms, "DP aux timeout value in msec (default: 50)");
/* * Some sink requires a delay after power on request
*/ static uint zynqmp_dp_power_on_delay_ms = 4;
module_param_named(power_on_delay_ms, zynqmp_dp_power_on_delay_ms, uint, 0444);
MODULE_PARM_DESC(power_on_delay_ms, "DP power on delay in msec (default: 4)");
/** * struct zynqmp_dp_link_config - Common link config between source and sink * @max_rate: maximum link rate * @max_lanes: maximum number of lanes
*/ struct zynqmp_dp_link_config { int max_rate;
u8 max_lanes;
};
/** * struct zynqmp_dp_mode - Configured mode of DisplayPort * @bw_code: code for bandwidth(link rate) * @lane_cnt: number of lanes * @pclock: pixel clock frequency of current mode * @fmt: format identifier string
*/ struct zynqmp_dp_mode { constchar *fmt; int pclock;
u8 bw_code;
u8 lane_cnt;
};
/** * enum test_pattern - Test patterns for test testing * @TEST_VIDEO: Use regular video input * @TEST_SYMBOL_ERROR: Symbol error measurement pattern * @TEST_PRBS7: Output of the PRBS7 (x^7 + x^6 + 1) polynomial * @TEST_80BIT_CUSTOM: A custom 80-bit pattern * @TEST_CP2520: HBR2 compliance eye pattern * @TEST_TPS1: Link training symbol pattern TPS1 (/D10.2/) * @TEST_TPS2: Link training symbol pattern TPS2 * @TEST_TPS3: Link training symbol pattern TPS3 (for HBR2)
*/ enum test_pattern {
TEST_VIDEO,
TEST_TPS1,
TEST_TPS2,
TEST_TPS3,
TEST_SYMBOL_ERROR,
TEST_PRBS7,
TEST_80BIT_CUSTOM,
TEST_CP2520,
};
/** * struct zynqmp_dp_test - Configuration for test mode * @pattern: The test pattern * @enhanced: Use enhanced framing * @downspread: Use SSC * @active: Whether test mode is active * @custom: Custom pattern for %TEST_80BIT_CUSTOM * @train_set: Voltage/preemphasis settings * @bw_code: Bandwidth code for the link * @link_cnt: Number of lanes
*/ struct zynqmp_dp_test { enum test_pattern pattern; bool enhanced, downspread, active;
u8 custom[10];
u8 train_set[ZYNQMP_DP_MAX_LANES];
u8 bw_code;
u8 link_cnt;
};
/** * struct zynqmp_dp_train_set_priv - Private data for train_set debugfs files * @dp: DisplayPort IP core structure * @lane: The lane for this file
*/ struct zynqmp_dp_train_set_priv { struct zynqmp_dp *dp; int lane;
};
/** * struct zynqmp_dp - Xilinx DisplayPort core * @dev: device structure * @dpsub: Display subsystem * @iomem: device I/O memory for register access * @reset: reset controller * @lock: Mutex protecting this struct and register access (but not AUX) * @irq: irq * @bridge: DRM bridge for the DP encoder * @next_bridge: The downstream bridge * @test: Configuration for test mode * @config: IP core configuration from DTS * @aux: aux channel * @aux_done: Completed when we get an AUX reply or timeout * @ignore_aux_errors: If set, AUX errors are suppressed * @phy: PHY handles for DP lanes * @num_lanes: number of enabled phy lanes * @hpd_work: hot plug detection worker * @hpd_irq_work: hot plug detection IRQ worker * @ignore_hpd: If set, HPD events and IRQs are ignored * @status: connection status * @enabled: flag to indicate if the device is enabled * @dpcd: DP configuration data from currently connected sink device * @link_config: common link configuration between IP core and sink device * @mode: current mode between IP core and sink device * @train_set: set of training data * @debugfs_train_set: Debugfs private data for @train_set * * @lock covers the link configuration in this struct and the device's * registers. It does not cover @aux or @ignore_aux_errors. It is not strictly * required for any of the members which are only modified at probe/remove time * (e.g. @dev).
*/ struct zynqmp_dp { struct drm_dp_aux aux; struct drm_bridge bridge; struct work_struct hpd_work; struct work_struct hpd_irq_work; struct completion aux_done; struct mutex lock;
if (assert)
reset_control_assert(dp->reset); else
reset_control_deassert(dp->reset);
/* Wait for the (de)assert to complete. */
timeout = jiffies + msecs_to_jiffies(RST_TIMEOUT_MS); while (!time_after_eq(jiffies, timeout)) { bool status = !!reset_control_status(dp->reset);
/** * zynqmp_dp_phy_init - Initialize the phy * @dp: DisplayPort IP core structure * * Initialize the phy. * * Return: 0 if the phy instances are initialized correctly, or the error code * returned from the callee functions.
*/ staticint zynqmp_dp_phy_init(struct zynqmp_dp *dp)
{ int ret; int i;
for (i = 0; i < dp->num_lanes; i++) {
ret = phy_init(dp->phy[i]); if (ret) {
dev_err(dp->dev, "failed to init phy lane %d\n", i); return ret;
}
}
/* * Power on lanes in reverse order as only lane 0 waits for the PLL to * lock.
*/ for (i = dp->num_lanes - 1; i >= 0; i--) {
ret = phy_power_on(dp->phy[i]); if (ret) {
dev_err(dp->dev, "failed to power on phy lane %d\n", i); return ret;
}
}
return 0;
}
/** * zynqmp_dp_phy_exit - Exit the phy * @dp: DisplayPort IP core structure * * Exit the phy.
*/ staticvoid zynqmp_dp_phy_exit(struct zynqmp_dp *dp)
{ unsignedint i; int ret;
for (i = 0; i < dp->num_lanes; i++) {
ret = phy_power_off(dp->phy[i]); if (ret)
dev_err(dp->dev, "failed to power off phy(%d) %d\n", i,
ret);
}
for (i = 0; i < dp->num_lanes; i++) {
ret = phy_exit(dp->phy[i]); if (ret)
dev_err(dp->dev, "failed to exit phy(%d) %d\n", i, ret);
}
}
/** * zynqmp_dp_phy_probe - Probe the PHYs * @dp: DisplayPort IP core structure * * Probe PHYs for all lanes. Less PHYs may be available than the number of * lanes, which is not considered an error as long as at least one PHY is * found. The caller can check dp->num_lanes to check how many PHYs were found. * * Return: * * 0 - Success * * -ENXIO - No PHY found * * -EPROBE_DEFER - Probe deferral requested * * Other negative value - PHY retrieval failure
*/ staticint zynqmp_dp_phy_probe(struct zynqmp_dp *dp)
{ unsignedint i;
for (i = 0; i < ZYNQMP_DP_MAX_LANES; i++) { char phy_name[16]; struct phy *phy;
if (IS_ERR(phy)) { switch (PTR_ERR(phy)) { case -ENODEV: if (dp->num_lanes) return 0;
dev_err(dp->dev, "no PHY found\n"); return -ENXIO;
case -EPROBE_DEFER: return -EPROBE_DEFER;
default:
dev_err(dp->dev, "failed to get PHY lane %u\n",
i); return PTR_ERR(phy);
}
}
dp->phy[i] = phy;
dp->num_lanes++;
}
return 0;
}
/** * zynqmp_dp_phy_ready - Check if PHY is ready * @dp: DisplayPort IP core structure * * Check if PHY is ready. If PHY is not ready, wait 1ms to check for 100 times. * This amount of delay was suggested by IP designer. * * Return: 0 if PHY is ready, or -ENODEV if PHY is not ready.
*/ staticint zynqmp_dp_phy_ready(struct zynqmp_dp *dp)
{
u32 i, reg, ready;
ready = (1 << dp->num_lanes) - 1;
/* Wait for 100 * 1ms. This should be enough time for PHY to be ready */ for (i = 0; ; i++) {
reg = zynqmp_dp_read(dp, ZYNQMP_DP_PHY_STATUS); if ((reg & ready) == ready) return 0;
if (i == 100) {
dev_err(dp->dev, "PHY isn't ready\n"); return -ENODEV;
}
usleep_range(1000, 1100);
}
return 0;
}
/* ----------------------------------------------------------------------------- * DisplayPort Link Training
*/
/** * zynqmp_dp_max_rate - Calculate and return available max pixel clock * @link_rate: link rate (Kilo-bytes / sec) * @lane_num: number of lanes * @bpp: bits per pixel * * Return: max pixel clock (KHz) supported by current link config.
*/ staticinlineint zynqmp_dp_max_rate(int link_rate, u8 lane_num, u8 bpp)
{ return link_rate * lane_num * 8 / bpp;
}
/** * zynqmp_dp_mode_configure - Configure the link values * @dp: DisplayPort IP core structure * @pclock: pixel clock for requested display mode * @current_bw: current link rate * * Find the link configuration values, rate and lane count for requested pixel * clock @pclock. The @pclock is stored in the mode to be used in other * functions later. The returned rate is downshifted from the current rate * @current_bw. * * Return: Current link rate code, or -EINVAL.
*/ staticint zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock,
u8 current_bw)
{ int max_rate = dp->link_config.max_rate;
u8 bw_code;
u8 max_lanes = dp->link_config.max_lanes;
u8 max_link_rate_code = drm_dp_link_rate_to_bw_code(max_rate);
u8 bpp = dp->config.bpp;
u8 lane_cnt;
/* Downshift from current bandwidth */ switch (current_bw) { case DP_LINK_BW_5_4:
bw_code = DP_LINK_BW_2_7; break; case DP_LINK_BW_2_7:
bw_code = DP_LINK_BW_1_62; break; case DP_LINK_BW_1_62:
dev_err(dp->dev, "can't downshift. already lowest link rate\n"); return -EINVAL; default: /* If not given, start with max supported */
bw_code = max_link_rate_code; break;
}
for (lane_cnt = 1; lane_cnt <= max_lanes; lane_cnt <<= 1) { int bw;
u32 rate;
dev_err(dp->dev, "failed to configure link values\n");
return -EINVAL;
}
/** * zynqmp_dp_adjust_train - Adjust train values * @dp: DisplayPort IP core structure * @link_status: link status from sink which contains requested training values
*/ staticvoid zynqmp_dp_adjust_train(struct zynqmp_dp *dp,
u8 link_status[DP_LINK_STATUS_SIZE])
{
u8 *train_set = dp->train_set;
u8 i;
for (i = 0; i < dp->mode.lane_cnt; i++) {
u8 voltage = drm_dp_get_adjust_request_voltage(link_status, i);
u8 preemphasis =
drm_dp_get_adjust_request_pre_emphasis(link_status, i);
if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
voltage |= DP_TRAIN_MAX_SWING_REACHED;
if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
train_set[i] = voltage | preemphasis;
}
}
/** * zynqmp_dp_update_vs_emph - Update the training values * @dp: DisplayPort IP core structure * @train_set: A set of training values * * Update the training values based on the request from sink. The mapped values * are predefined, and values(vs, pe, pc) are from the device manual. * * Return: 0 if vs and emph are updated successfully, or the error code returned * by drm_dp_dpcd_write().
*/ staticint zynqmp_dp_update_vs_emph(struct zynqmp_dp *dp, u8 *train_set)
{ unsignedint i; int ret;
ret = drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, train_set,
dp->mode.lane_cnt); if (ret < 0) return ret;
for (i = 0; i < dp->mode.lane_cnt; i++) {
u32 reg = ZYNQMP_DP_SUB_TX_PHY_PRECURSOR_LANE_0 + i * 4; union phy_configure_opts opts = { 0 };
u8 train = train_set[i];
/** * zynqmp_dp_link_train_cr - Train clock recovery * @dp: DisplayPort IP core structure * * Return: 0 if clock recovery train is done successfully, or corresponding * error code.
*/ staticint zynqmp_dp_link_train_cr(struct zynqmp_dp *dp)
{
u8 link_status[DP_LINK_STATUS_SIZE];
u8 lane_cnt = dp->mode.lane_cnt;
u8 vs = 0, tries = 0;
u16 max_tries, i; bool cr_done; int ret;
zynqmp_dp_write(dp, ZYNQMP_DP_TRAINING_PATTERN_SET,
DP_TRAINING_PATTERN_1);
ret = drm_dp_dpcd_writeb(&dp->aux, DP_TRAINING_PATTERN_SET,
DP_TRAINING_PATTERN_1 |
DP_LINK_SCRAMBLING_DISABLE); if (ret < 0) return ret;
/* * 256 loops should be maximum iterations for 4 lanes and 4 values. * So, This loop should exit before 512 iterations
*/ for (max_tries = 0; max_tries < 512; max_tries++) {
ret = zynqmp_dp_update_vs_emph(dp, dp->train_set); if (ret) return ret;
drm_dp_link_train_clock_recovery_delay(&dp->aux, dp->dpcd);
ret = drm_dp_dpcd_read_link_status(&dp->aux, link_status); if (ret < 0) return ret;
cr_done = drm_dp_clock_recovery_ok(link_status, lane_cnt); if (cr_done) break;
for (i = 0; i < lane_cnt; i++) if (!(dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED)) break; if (i == lane_cnt) break;
vs = dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
zynqmp_dp_adjust_train(dp, link_status);
}
if (!cr_done) return -EIO;
return 0;
}
/** * zynqmp_dp_link_train_ce - Train channel equalization * @dp: DisplayPort IP core structure * * Return: 0 if channel equalization train is done successfully, or * corresponding error code.
*/ staticint zynqmp_dp_link_train_ce(struct zynqmp_dp *dp)
{
u8 link_status[DP_LINK_STATUS_SIZE];
u8 lane_cnt = dp->mode.lane_cnt;
u32 pat, tries; int ret; bool ce_done;
if (dp->dpcd[DP_DPCD_REV] >= DP_V1_2 &&
dp->dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED)
pat = DP_TRAINING_PATTERN_3; else
pat = DP_TRAINING_PATTERN_2;
zynqmp_dp_write(dp, ZYNQMP_DP_TRAINING_PATTERN_SET, pat);
ret = drm_dp_dpcd_writeb(&dp->aux, DP_TRAINING_PATTERN_SET,
pat | DP_LINK_SCRAMBLING_DISABLE); if (ret < 0) return ret;
for (tries = 0; tries < DP_MAX_TRAINING_TRIES; tries++) {
ret = zynqmp_dp_update_vs_emph(dp, dp->train_set); if (ret) return ret;
drm_dp_link_train_channel_eq_delay(&dp->aux, dp->dpcd);
ret = drm_dp_dpcd_read_link_status(&dp->aux, link_status); if (ret < 0) return ret;
ce_done = drm_dp_channel_eq_ok(link_status, lane_cnt); if (ce_done) break;
zynqmp_dp_adjust_train(dp, link_status);
}
if (!ce_done) return -EIO;
return 0;
}
/** * zynqmp_dp_setup() - Set up major link parameters * @dp: DisplayPort IP core structure * @bw_code: The link bandwidth as a multiple of 270 MHz * @lane_cnt: The number of lanes to use * @enhanced: Use enhanced framing * @downspread: Enable spread-spectrum clocking * * Return: 0 on success, or -errno on failure
*/ staticint zynqmp_dp_setup(struct zynqmp_dp *dp, u8 bw_code, u8 lane_cnt, bool enhanced, bool downspread)
{
u32 reg;
u8 aux_lane_cnt = lane_cnt; int ret;
ret = drm_dp_dpcd_writeb(&dp->aux, DP_LANE_COUNT_SET, aux_lane_cnt); if (ret < 0) {
dev_err(dp->dev, "failed to set lane count\n"); return ret;
}
ret = drm_dp_dpcd_writeb(&dp->aux, DP_MAIN_LINK_CHANNEL_CODING_SET,
DP_SET_ANSI_8B10B); if (ret < 0) {
dev_err(dp->dev, "failed to set ANSI 8B/10B encoding\n"); return ret;
}
ret = drm_dp_dpcd_writeb(&dp->aux, DP_LINK_BW_SET, bw_code); if (ret < 0) {
dev_err(dp->dev, "failed to set DP bandwidth\n"); return ret;
}
zynqmp_dp_write(dp, ZYNQMP_DP_LINK_BW_SET, bw_code); switch (bw_code) { case DP_LINK_BW_1_62:
reg = ZYNQMP_DP_PHY_CLOCK_SELECT_1_62G; break; case DP_LINK_BW_2_7:
reg = ZYNQMP_DP_PHY_CLOCK_SELECT_2_70G; break; case DP_LINK_BW_5_4: default:
reg = ZYNQMP_DP_PHY_CLOCK_SELECT_5_40G; break;
}
/** * zynqmp_dp_train - Train the link * @dp: DisplayPort IP core structure * * Return: 0 if all trains are done successfully, or corresponding error code.
*/ staticint zynqmp_dp_train(struct zynqmp_dp *dp)
{ int ret;
ret = zynqmp_dp_setup(dp, dp->mode.bw_code, dp->mode.lane_cnt,
drm_dp_enhanced_frame_cap(dp->dpcd),
dp->dpcd[DP_MAX_DOWNSPREAD] &
DP_MAX_DOWNSPREAD_0_5); if (ret) return ret;
zynqmp_dp_write(dp, ZYNQMP_DP_SCRAMBLING_DISABLE, 1);
memset(dp->train_set, 0, sizeof(dp->train_set));
ret = zynqmp_dp_link_train_cr(dp); if (ret) return ret;
ret = zynqmp_dp_link_train_ce(dp); if (ret) return ret;
ret = drm_dp_dpcd_writeb(&dp->aux, DP_TRAINING_PATTERN_SET,
DP_TRAINING_PATTERN_DISABLE); if (ret < 0) {
dev_err(dp->dev, "failed to disable training pattern\n"); return ret;
}
zynqmp_dp_write(dp, ZYNQMP_DP_TRAINING_PATTERN_SET,
DP_TRAINING_PATTERN_DISABLE);
/** * zynqmp_dp_train_loop - Downshift the link rate during training * @dp: DisplayPort IP core structure * * Train the link by downshifting the link rate if training is not successful.
*/ staticvoid zynqmp_dp_train_loop(struct zynqmp_dp *dp)
{ struct zynqmp_dp_mode *mode = &dp->mode;
u8 bw = mode->bw_code; int ret;
do { if (dp->status == connector_status_disconnected ||
!dp->enabled) return;
ret = zynqmp_dp_train(dp); if (!ret) return;
ret = zynqmp_dp_mode_configure(dp, mode->pclock, bw); if (ret < 0) goto err_out;
bw = ret;
} while (bw >= DP_LINK_BW_1_62);
err_out:
dev_err(dp->dev, "failed to train the DP link\n");
}
/* ----------------------------------------------------------------------------- * DisplayPort AUX
*/
#define AUX_READ_BIT 0x1
/** * zynqmp_dp_aux_cmd_submit - Submit aux command * @dp: DisplayPort IP core structure * @cmd: aux command * @addr: aux address * @buf: buffer for command data * @bytes: number of bytes for @buf * @reply: reply code to be returned * * Submit an aux command. All aux related commands, native or i2c aux * read/write, are submitted through this function. The function is mapped to * the transfer function of struct drm_dp_aux. This function involves in * multiple register reads/writes, thus synchronization is needed, and it is * done by drm_dp_helper using @hw_mutex. The calling thread goes into sleep * if there's no immediate reply to the command submission. The reply code is * returned at @reply if @reply != NULL. * * Return: 0 if the command is submitted properly, or corresponding error code: * -EBUSY when there is any request already being processed * -ETIMEDOUT when receiving reply is timed out * -EIO when received bytes are less than requested
*/ staticint zynqmp_dp_aux_cmd_submit(struct zynqmp_dp *dp, u32 cmd, u16 addr,
u8 *buf, u8 bytes, u8 *reply)
{ bool is_read = (cmd & AUX_READ_BIT) ? true : false; unsignedlong time_left;
u32 reg, i;
reg = zynqmp_dp_read(dp, ZYNQMP_DP_INTERRUPT_SIGNAL_STATE); if (reg & ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_REQUEST) return -EBUSY;
reinit_completion(&dp->aux_done);
zynqmp_dp_write(dp, ZYNQMP_DP_AUX_ADDRESS, addr); if (!is_read) for (i = 0; i < bytes; i++)
zynqmp_dp_write(dp, ZYNQMP_DP_AUX_WRITE_FIFO,
buf[i]);
/* Wait for reply to be delivered upto 2ms */
time_left = wait_for_completion_timeout(&dp->aux_done,
msecs_to_jiffies(2)); if (!time_left) return -ETIMEDOUT;
reg = zynqmp_dp_read(dp, ZYNQMP_DP_INTERRUPT_SIGNAL_STATE); if (reg & ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_REPLY_TIMEOUT) return -ETIMEDOUT;
reg = zynqmp_dp_read(dp, ZYNQMP_DP_AUX_REPLY_CODE); if (reply)
*reply = reg;
/* Number of loops = timeout in msec / aux delay (400 usec) */
iter = zynqmp_dp_aux_timeout_ms * 1000 / 400;
iter = iter ? iter : 1;
for (i = 0; i < iter; i++) {
ret = zynqmp_dp_aux_cmd_submit(dp, msg->request, msg->address,
msg->buffer, msg->size,
&msg->reply); if (!ret) {
dev_vdbg(dp->dev, "aux %d retries\n", i); return msg->size;
}
if (dp->status == connector_status_disconnected) {
dev_dbg(dp->dev, "no connected aux device\n"); if (dp->ignore_aux_errors) goto fake_response; return -ENODEV;
}
usleep_range(400, 500);
}
dev_dbg(dp->dev, "failed to do aux transfer (%d)\n", ret);
/** * zynqmp_dp_aux_init - Initialize and register the DP AUX * @dp: DisplayPort IP core structure * * Program the AUX clock divider and filter and register the DP AUX adapter. * * Return: 0 on success, error value otherwise
*/ staticint zynqmp_dp_aux_init(struct zynqmp_dp *dp)
{ unsignedlong rate; unsignedint w;
/* * The AUX_SIGNAL_WIDTH_FILTER is the number of APB clock cycles * corresponding to the AUX pulse. Allowable values are 8, 16, 24, 32, * 40 and 48. The AUX pulse width must be between 0.4µs and 0.6µs, * compute the w / 8 value corresponding to 0.4µs rounded up, and make * sure it stays below 0.6µs and within the allowable values.
*/
rate = clk_get_rate(dp->dpsub->apb_clk);
w = DIV_ROUND_UP(4 * rate, 1000 * 1000 * 10 * 8) * 8; if (w > 6 * rate / (1000 * 1000 * 10) || w > 48) {
dev_err(dp->dev, "aclk frequency too high\n"); return -EINVAL;
}
/* ----------------------------------------------------------------------------- * DisplayPort Generic Support
*/
/** * zynqmp_dp_update_misc - Write the misc registers * @dp: DisplayPort IP core structure * * The misc register values are stored in the structure, and this * function applies the values into the registers.
*/ staticvoid zynqmp_dp_update_misc(struct zynqmp_dp *dp)
{
zynqmp_dp_write(dp, ZYNQMP_DP_MAIN_STREAM_MISC0, dp->config.misc0);
zynqmp_dp_write(dp, ZYNQMP_DP_MAIN_STREAM_MISC1, dp->config.misc1);
}
/** * zynqmp_dp_set_format - Set the input format * @dp: DisplayPort IP core structure * @info: Display info * @format: input format * @bpc: bits per component * * Update misc register values based on input @format and @bpc. * * Return: 0 on success, or -EINVAL.
*/ staticint zynqmp_dp_set_format(struct zynqmp_dp *dp, conststruct drm_display_info *info, enum zynqmp_dpsub_format format, unsignedint bpc)
{ struct zynqmp_dp_config *config = &dp->config; unsignedint num_colors;
switch (bpc) { case 6:
config->misc0 |= ZYNQMP_DP_MAIN_STREAM_MISC0_BPC_6; break; case 8:
config->misc0 |= ZYNQMP_DP_MAIN_STREAM_MISC0_BPC_8; break; case 10:
config->misc0 |= ZYNQMP_DP_MAIN_STREAM_MISC0_BPC_10; break; case 12:
config->misc0 |= ZYNQMP_DP_MAIN_STREAM_MISC0_BPC_12; break; case 16:
config->misc0 |= ZYNQMP_DP_MAIN_STREAM_MISC0_BPC_16; break; default:
dev_warn(dp->dev, "Not supported bpc (%u). fall back to 8bpc\n",
bpc);
config->misc0 |= ZYNQMP_DP_MAIN_STREAM_MISC0_BPC_8;
bpc = 8; break;
}
/* Update the current bpp based on the format. */
config->bpp = bpc * num_colors;
return 0;
}
/** * zynqmp_dp_encoder_mode_set_transfer_unit - Set the transfer unit values * @dp: DisplayPort IP core structure * @mode: requested display mode * * Set the transfer unit, and calculate all transfer unit size related values. * Calculation is based on DP and IP core specification.
*/ staticvoid
zynqmp_dp_encoder_mode_set_transfer_unit(struct zynqmp_dp *dp, conststruct drm_display_mode *mode)
{
u32 tu = ZYNQMP_DP_MSA_TRANSFER_UNIT_SIZE_TU_SIZE_DEF;
u32 bw, vid_kbytes, avg_bytes_per_tu, init_wait;
/* Use the max transfer unit size (default) */
zynqmp_dp_write(dp, ZYNQMP_DP_MSA_TRANSFER_UNIT_SIZE, tu);
/** * zynqmp_dp_encoder_mode_set_stream - Configure the main stream * @dp: DisplayPort IP core structure * @mode: requested display mode * * Configure the main stream based on the requested mode @mode. Calculation is * based on IP core specification.
*/ staticvoid zynqmp_dp_encoder_mode_set_stream(struct zynqmp_dp *dp, conststruct drm_display_mode *mode)
{
u8 lane_cnt = dp->mode.lane_cnt;
u32 reg, wpl;
/** * zynqmp_dp_disp_connected_live_layer - Return the first connected live layer * @dp: DisplayPort IP core structure * * Return: The first connected live display layer or NULL if none of the live * layers are connected.
*/ staticstruct zynqmp_disp_layer *
zynqmp_dp_disp_connected_live_layer(struct zynqmp_dp *dp)
{ if (dp->dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_LIVE_VIDEO)) return dp->dpsub->layers[ZYNQMP_DPSUB_LAYER_VID]; elseif (dp->dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_LIVE_GFX)) return dp->dpsub->layers[ZYNQMP_DPSUB_LAYER_GFX]; else return NULL;
}
/* Initialize and register the AUX adapter. */
ret = zynqmp_dp_aux_init(dp); if (ret) {
dev_err(dp->dev, "failed to initialize DP aux\n"); return ret;
}
if (dp->next_bridge) {
ret = drm_bridge_attach(encoder, dp->next_bridge,
bridge, flags); if (ret < 0) goto error;
}
/* Now that initialisation is complete, enable interrupts. */
zynqmp_dp_write(dp, ZYNQMP_DP_INT_EN, ZYNQMP_DP_INT_ALL);
if (mode->clock > ZYNQMP_MAX_FREQ) {
dev_dbg(dp->dev, "filtered mode %s for high pixel rate\n",
mode->name);
drm_mode_debug_printmodeline(mode); return MODE_CLOCK_HIGH;
}
/* Check with link rate and lane count */
scoped_guard(mutex, &dp->lock)
rate = zynqmp_dp_max_rate(dp->link_config.max_rate,
dp->link_config.max_lanes,
dp->config.bpp); if (mode->clock > rate) {
dev_dbg(dp->dev, "filtered mode %s for high pixel rate\n",
mode->name);
drm_mode_debug_printmodeline(mode); return MODE_CLOCK_HIGH;
}
/* * Retrieve the CRTC mode and adjusted mode. This requires a little * dance to go from the bridge to the encoder, to the connector and to * the CRTC.
*/
connector = drm_atomic_get_new_connector_for_encoder(state,
bridge->encoder);
crtc = drm_atomic_get_new_connector_state(state, connector)->crtc;
crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
adjusted_mode = &crtc_state->adjusted_mode;
mode = &crtc_state->mode;
/* Check again as bpp or format might have been changed */
rate = zynqmp_dp_max_rate(dp->link_config.max_rate,
dp->link_config.max_lanes, dp->config.bpp); if (mode->clock > rate) {
dev_err(dp->dev, "mode %s has too high pixel rate\n",
mode->name);
drm_mode_debug_printmodeline(mode);
}
/* Configure the mode */
ret = zynqmp_dp_mode_configure(dp, adjusted_mode->clock, 0); if (ret < 0) {
pm_runtime_put_sync(dp->dev); return;
}
/* Enable the encoder */
dp->enabled = true;
zynqmp_dp_update_misc(dp);
zynqmp_dp_write(dp, ZYNQMP_DP_TX_PHY_POWER_DOWN, 0); if (dp->status == connector_status_connected) { for (i = 0; i < 3; i++) {
ret = drm_dp_dpcd_writeb(&dp->aux, DP_SET_POWER,
DP_SET_POWER_D0); if (ret == 1) break;
usleep_range(300, 500);
} /* Some monitors take time to wake up properly */
msleep(zynqmp_dp_power_on_delay_ms);
} if (ret != 1)
dev_dbg(dp->dev, "DP aux failed\n"); else
zynqmp_dp_train_loop(dp);
zynqmp_dp_write(dp, ZYNQMP_DP_SOFTWARE_RESET,
ZYNQMP_DP_SOFTWARE_RESET_ALL);
zynqmp_dp_write(dp, ZYNQMP_DP_MAIN_STREAM_ENABLE, 1);
}
/* * ZynqMP DP requires horizontal backporch to be greater than 12. * This limitation may not be compatible with the sink device.
*/ if (diff < ZYNQMP_DP_MIN_H_BACKPORCH) { int vrefresh = (adjusted_mode->clock * 1000) /
(adjusted_mode->vtotal * adjusted_mode->htotal);
/* * This is from heuristic. It takes some delay (ex, 100 ~ 500 msec) to * get the HPD signal with some monitors.
*/ for (i = 0; i < 10; i++) {
state = zynqmp_dp_read(dp, ZYNQMP_DP_INTERRUPT_SIGNAL_STATE); if (state & ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_HPD) break;
msleep(100);
}
if (state & ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_HPD) {
ret = drm_dp_dpcd_read(&dp->aux, 0x0, dp->dpcd, sizeof(dp->dpcd)); if (ret < 0) {
dev_dbg(dp->dev, "DPCD read failed"); goto disconnected;
}
/** * zynqmp_dp_set_test_pattern() - Configure the link for a test pattern * @dp: DisplayPort IP core structure * @pattern: The test pattern to configure * @custom: The custom pattern to use if @pattern is %TEST_80BIT_CUSTOM * * Return: 0 on success, or negative errno on (DPCD) failure
*/ staticint zynqmp_dp_set_test_pattern(struct zynqmp_dp *dp, enum test_pattern pattern,
u8 *const custom)
{ bool scramble = false;
u32 train_pattern = 0;
u32 link_pattern = 0;
u8 dpcd_train = 0;
u8 dpcd_link = 0; int ret;
switch (pattern) { case TEST_TPS1:
train_pattern = 1; break; case TEST_TPS2:
train_pattern = 2; break; case TEST_TPS3:
train_pattern = 3; break; case TEST_SYMBOL_ERROR:
scramble = true;
link_pattern = DP_PHY_TEST_PATTERN_ERROR_COUNT; break; case TEST_PRBS7: /* We use a dedicated register to enable PRBS7 */
dpcd_link = DP_LINK_QUAL_PATTERN_ERROR_RATE; break; case TEST_80BIT_CUSTOM: { const u8 *p = custom;
if (dp->dpcd[DP_DPCD_REV] < 0x12) { if (pattern == TEST_CP2520)
dev_warn(dp->dev, "can't set sink link quality pattern to CP2520 for DPCD < r1.2; error counters will be invalid\n"); else
dpcd_train |= FIELD_PREP(DP_LINK_QUAL_PATTERN_11_MASK,
dpcd_link);
} else {
u8 dpcd_link_lane[ZYNQMP_DP_MAX_LANES];
memset(dpcd_link_lane, dpcd_link, ZYNQMP_DP_MAX_LANES);
ret = drm_dp_dpcd_write(&dp->aux, DP_LINK_QUAL_LANE0_SET,
dpcd_link_lane, ZYNQMP_DP_MAX_LANES); if (ret < 0) return ret;
}
ret = drm_dp_dpcd_writeb(&dp->aux, DP_TRAINING_PATTERN_SET, dpcd_train); return ret < 0 ? ret : 0;
}
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.