Lines Matching +full:i2c +full:- +full:retry +full:- +full:count

25 #include <linux/i2c.h>
51 return link_status[r - DP_LANE0_1_STATUS]; in dp_link_status()
191 const char *arrow = request == DP_AUX_NATIVE_READ ? "->" : "<-"; in drm_dp_dump_access()
195 aux->name, offset, arrow, ret, min(ret, 20), buffer); in drm_dp_dump_access()
198 aux->name, offset, arrow, ret); in drm_dp_dump_access()
204 * The DisplayPort AUX channel is an abstraction to allow generic, driver-
208 * Transactions are described using a hardware-independent drm_dp_aux_msg
210 * Both native and I2C-over-AUX transactions are supported.
217 unsigned int retry, native_reply; in drm_dp_dpcd_access() local
226 mutex_lock(&aux->hw_mutex); in drm_dp_dpcd_access()
230 * retry native transactions. We used to retry 7 times like for in drm_dp_dpcd_access()
231 * aux i2c transactions but real world devices this wasn't in drm_dp_dpcd_access()
234 for (retry = 0; retry < 32; retry++) { in drm_dp_dpcd_access()
235 if (ret != 0 && ret != -ETIMEDOUT) { in drm_dp_dpcd_access()
240 ret = aux->transfer(aux, &msg); in drm_dp_dpcd_access()
247 ret = -EPROTO; in drm_dp_dpcd_access()
249 ret = -EIO; in drm_dp_dpcd_access()
255 * next time we retry in drm_dp_dpcd_access()
262 aux->name, err); in drm_dp_dpcd_access()
266 mutex_unlock(&aux->hw_mutex); in drm_dp_dpcd_access()
271 * drm_dp_dpcd_read() - read a series of bytes from the DPCD
278 * code on failure. -EIO is returned if the request was NAKed by the sink or
279 * if the retry count was exceeded. If not all bytes were transferred, this
280 * function returns -EPROTO. Errors from the underlying AUX channel transfer
281 * function, with the exception of -EBUSY (which causes the transaction to
294 * gets woken up and subsequently re-enters power save mode. in drm_dp_dpcd_read()
301 if (!aux->is_remote) { in drm_dp_dpcd_read()
308 if (aux->is_remote) in drm_dp_dpcd_read()
321 * drm_dp_dpcd_write() - write a series of bytes to the DPCD
328 * code on failure. -EIO is returned if the request was NAKed by the sink or
329 * if the retry count was exceeded. If not all bytes were transferred, this
330 * function returns -EPROTO. Errors from the underlying AUX channel transfer
331 * function, with the exception of -EBUSY (which causes the transaction to
339 if (aux->is_remote) in drm_dp_dpcd_write()
351 * drm_dp_dpcd_read_link_status() - read DPCD link status (bytes 0x202-0x207)
368 return edid && edid->revision >= 4 && in is_edid_digital_input_dp()
369 edid->input & DRM_EDID_INPUT_DIGITAL && in is_edid_digital_input_dp()
370 (edid->input & DRM_EDID_DIGITAL_TYPE_MASK) == DRM_EDID_DIGITAL_TYPE_DP; in is_edid_digital_input_dp()
374 * drm_dp_downstream_is_type() - is the downstream facing port of certain type?
396 * drm_dp_downstream_is_tmds() - is the downstream facing port TMDS?
431 * drm_dp_send_real_edid_checksum() - send back real edid checksum value
446 aux->name, DP_DEVICE_SERVICE_IRQ_VECTOR); in drm_dp_send_real_edid_checksum()
453 aux->name, DP_TEST_REQUEST); in drm_dp_send_real_edid_checksum()
460 aux->name); in drm_dp_send_real_edid_checksum()
467 aux->name, DP_DEVICE_SERVICE_IRQ_VECTOR); in drm_dp_send_real_edid_checksum()
475 aux->name, DP_TEST_EDID_CHECKSUM); in drm_dp_send_real_edid_checksum()
482 aux->name, DP_TEST_RESPONSE); in drm_dp_send_real_edid_checksum()
522 return -EIO; in drm_dp_read_extended_dpcd_caps()
526 aux->name, dpcd[DP_DPCD_REV], in drm_dp_read_extended_dpcd_caps()
535 aux->name, DP_RECEIVER_CAP_SIZE, dpcd); in drm_dp_read_extended_dpcd_caps()
543 * drm_dp_read_dpcd_caps() - read DPCD caps and extended DPCD caps if
564 return -EIO; in drm_dp_read_dpcd_caps()
571 aux->name, DP_RECEIVER_CAP_SIZE, dpcd); in drm_dp_read_dpcd_caps()
578 * drm_dp_read_downstream_info() - read DPCD downstream port info if available
613 return -EIO; in drm_dp_read_downstream_info()
616 aux->name, len, downstream_ports); in drm_dp_read_downstream_info()
623 * drm_dp_downstream_max_dotclock() - extract downstream facing port max dot clock
651 * drm_dp_downstream_max_tmds_clock() - extract downstream facing port max TMDS clock
684 * may not fordward that the DP dual mode i2c in drm_dp_downstream_max_tmds_clock()
685 * access so we just usually get i2c nak :( in drm_dp_downstream_max_tmds_clock()
716 * drm_dp_downstream_min_tmds_clock() - extract downstream facing port min TMDS clock
759 * drm_dp_downstream_max_bpc() - extract downstream facing port max
816 * drm_dp_downstream_420_passthrough() - determine downstream facing port
817 * YCbCr 4:2:0 pass-through capability
847 * drm_dp_downstream_444_to_420_conversion() - determine downstream facing port
848 * YCbCr 4:4:4->4:2:0 conversion capability
876 * drm_dp_downstream_mode() - return a mode for downstream facing port
931 * drm_dp_downstream_id() - identify branch device
944 * drm_dp_downstream_debug() - debug DP branch devices
1035 * drm_dp_subconnector_type() - get DP branch device type
1053 /* Can be HDMI or DVI-D, DVI-D is a safer option */ in drm_dp_subconnector_type()
1056 /* Can be VGA or DVI-A, VGA is more popular */ in drm_dp_subconnector_type()
1087 * drm_mode_set_dp_subconnector_property - set subconnector for DP connector
1104 drm_object_property_set_value(&connector->base, in drm_dp_set_subconnector_property()
1105 connector->dev->mode_config.dp_subconnector_property, in drm_dp_set_subconnector_property()
1111 * drm_dp_read_sink_count_cap() - Check whether a given connector has a valid sink
1112 * count
1119 * Returns: %True if the (e)DP connector has a valid sink count that should
1126 /* Some eDP panels don't set a valid value for the sink count */ in drm_dp_read_sink_count_cap()
1127 return connector->connector_type != DRM_MODE_CONNECTOR_eDP && in drm_dp_read_sink_count_cap()
1135 * drm_dp_read_sink_count() - Retrieve the sink count for a given sink
1140 * Returns: The current sink count reported by @aux, or a negative error code
1145 u8 count; in drm_dp_read_sink_count() local
1148 ret = drm_dp_dpcd_readb(aux, DP_SINK_COUNT, &count); in drm_dp_read_sink_count()
1152 return -EIO; in drm_dp_read_sink_count()
1154 return DP_GET_SINK_COUNT(count); in drm_dp_read_sink_count()
1159 * I2C-over-AUX implementation
1173 * In case of i2c defer or short i2c ack reply to a write, in drm_dp_i2c_msg_write_status_update()
1177 if ((msg->request & ~DP_AUX_I2C_MOT) == DP_AUX_I2C_WRITE) { in drm_dp_i2c_msg_write_status_update()
1178 msg->request &= DP_AUX_I2C_MOT; in drm_dp_i2c_msg_write_status_update()
1179 msg->request |= DP_AUX_I2C_WRITE_STATUS_UPDATE; in drm_dp_i2c_msg_write_status_update()
1200 if ((msg->request & DP_AUX_I2C_READ) == 0) in drm_dp_aux_req_duration()
1201 len += msg->size * 8; in drm_dp_aux_req_duration()
1215 if (msg->request & DP_AUX_I2C_READ) in drm_dp_aux_reply_duration()
1216 len += msg->size * 8; in drm_dp_aux_reply_duration()
1227 * Calculate the length of the i2c transfer in usec, assuming
1228 * the i2c bus speed is as specified. Gives the the "worst"
1237 /* AUX bitrate is 1MHz, i2c bitrate as specified */ in drm_dp_i2c_msg_duration()
1239 msg->size * I2C_DATA_LEN + in drm_dp_i2c_msg_duration()
1246 * i2c and AUX transfers.
1265 "Assumed speed of the i2c bus in kHz, (1-400, default 10)");
1268 * Transfer a single I2C-over-AUX message and handle various error conditions,
1277 unsigned int retry, defer_i2c; in drm_dp_i2c_do_msg() local
1281 * is required to retry at least seven times upon receiving AUX_DEFER in drm_dp_i2c_do_msg()
1284 * We also try to account for the i2c bus speed. in drm_dp_i2c_do_msg()
1288 for (retry = 0, defer_i2c = 0; retry < (max_retries + defer_i2c); retry++) { in drm_dp_i2c_do_msg()
1289 ret = aux->transfer(aux, msg); in drm_dp_i2c_do_msg()
1291 if (ret == -EBUSY) in drm_dp_i2c_do_msg()
1297 * communicate with a non-existant DisplayPort device). in drm_dp_i2c_do_msg()
1300 if (ret == -ETIMEDOUT) in drm_dp_i2c_do_msg()
1302 aux->name); in drm_dp_i2c_do_msg()
1305 aux->name, ret); in drm_dp_i2c_do_msg()
1310 switch (msg->reply & DP_AUX_NATIVE_REPLY_MASK) { in drm_dp_i2c_do_msg()
1313 * For I2C-over-AUX transactions this isn't enough, we in drm_dp_i2c_do_msg()
1314 * need to check for the I2C ACK reply. in drm_dp_i2c_do_msg()
1320 aux->name, ret, msg->size); in drm_dp_i2c_do_msg()
1321 return -EREMOTEIO; in drm_dp_i2c_do_msg()
1324 DRM_DEBUG_KMS("%s: native defer\n", aux->name); in drm_dp_i2c_do_msg()
1326 * We could check for I2C bit rate capabilities and if in drm_dp_i2c_do_msg()
1328 * more careful with DP-to-legacy adapters where a in drm_dp_i2c_do_msg()
1329 * long legacy cable may force very low I2C bit rates. in drm_dp_i2c_do_msg()
1332 * safe for all use-cases. in drm_dp_i2c_do_msg()
1339 aux->name, msg->reply); in drm_dp_i2c_do_msg()
1340 return -EREMOTEIO; in drm_dp_i2c_do_msg()
1343 switch (msg->reply & DP_AUX_I2C_REPLY_MASK) { in drm_dp_i2c_do_msg()
1346 * Both native ACK and I2C ACK replies received. We in drm_dp_i2c_do_msg()
1349 if (ret != msg->size) in drm_dp_i2c_do_msg()
1354 DRM_DEBUG_KMS("%s: I2C nack (result=%d, size=%zu)\n", in drm_dp_i2c_do_msg()
1355 aux->name, ret, msg->size); in drm_dp_i2c_do_msg()
1356 aux->i2c_nack_count++; in drm_dp_i2c_do_msg()
1357 return -EREMOTEIO; in drm_dp_i2c_do_msg()
1360 DRM_DEBUG_KMS("%s: I2C defer\n", aux->name); in drm_dp_i2c_do_msg()
1362 * Must have at least 7 retries for I2C defers on the in drm_dp_i2c_do_msg()
1365 aux->i2c_defer_count++; in drm_dp_i2c_do_msg()
1374 DRM_ERROR("%s: invalid I2C reply %#04x\n", in drm_dp_i2c_do_msg()
1375 aux->name, msg->reply); in drm_dp_i2c_do_msg()
1376 return -EREMOTEIO; in drm_dp_i2c_do_msg()
1380 DRM_DEBUG_KMS("%s: Too many retries, giving up\n", aux->name); in drm_dp_i2c_do_msg()
1381 return -EREMOTEIO; in drm_dp_i2c_do_msg()
1387 msg->request = (i2c_msg->flags & I2C_M_RD) ? in drm_dp_i2c_msg_set_request()
1389 if (!(i2c_msg->flags & I2C_M_STOP)) in drm_dp_i2c_msg_set_request()
1390 msg->request |= DP_AUX_I2C_MOT; in drm_dp_i2c_msg_set_request()
1400 int err, ret = orig_msg->size; in drm_dp_i2c_drain_msg()
1406 return err == 0 ? -EPROTO : err; in drm_dp_i2c_drain_msg()
1409 DRM_DEBUG_KMS("%s: Partial I2C reply: requested %zu bytes got %d bytes\n", in drm_dp_i2c_drain_msg()
1410 aux->name, msg.size, err); in drm_dp_i2c_drain_msg()
1414 msg.size -= err; in drm_dp_i2c_drain_msg()
1422 * Bizlink designed DP->DVI-D Dual Link adapters require the I2C over AUX
1423 * packets to be as large as possible. If not, the I2C transactions never
1429 "Number of bytes to transfer in a single I2C over DP AUX CH message, (1-16, default 16)");
1434 struct drm_dp_aux *aux = adapter->algo_data; in drm_dp_i2c_xfer()
1470 msg.size = min(transfer_size, msgs[i].len - j); in drm_dp_i2c_xfer()
1506 static struct drm_dp_aux *i2c_to_aux(struct i2c_adapter *i2c) in i2c_to_aux() argument
1508 return container_of(i2c, struct drm_dp_aux, ddc); in i2c_to_aux()
1511 static void lock_bus(struct i2c_adapter *i2c, unsigned int flags) in lock_bus() argument
1513 mutex_lock(&i2c_to_aux(i2c)->hw_mutex); in lock_bus()
1516 static int trylock_bus(struct i2c_adapter *i2c, unsigned int flags) in trylock_bus() argument
1518 return mutex_trylock(&i2c_to_aux(i2c)->hw_mutex); in trylock_bus()
1521 static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags) in unlock_bus() argument
1523 mutex_unlock(&i2c_to_aux(i2c)->hw_mutex); in unlock_bus()
1534 u8 buf, count; in drm_dp_aux_get_crc() local
1547 count = buf & DP_TEST_COUNT_MASK; in drm_dp_aux_get_crc()
1548 if (count == aux->crc_count) in drm_dp_aux_get_crc()
1549 return -EAGAIN; /* No CRC yet */ in drm_dp_aux_get_crc()
1551 aux->crc_count = count; in drm_dp_aux_get_crc()
1573 if (WARN_ON(!aux->crtc)) in drm_dp_aux_crc_work()
1576 crtc = aux->crtc; in drm_dp_aux_crc_work()
1577 while (crtc->crc.opened) { in drm_dp_aux_crc_work()
1579 if (!crtc->crc.opened) in drm_dp_aux_crc_work()
1583 if (ret == -EAGAIN) { in drm_dp_aux_crc_work()
1588 if (ret == -EAGAIN) { in drm_dp_aux_crc_work()
1590 aux->name, ret); in drm_dp_aux_crc_work()
1594 aux->name, ret); in drm_dp_aux_crc_work()
1606 * drm_dp_remote_aux_init() - minimally initialise a remote aux channel
1614 INIT_WORK(&aux->crc_work, drm_dp_aux_crc_work); in drm_dp_remote_aux_init()
1619 * drm_dp_aux_init() - minimally initialise an aux channel
1622 * If you need to use the drm_dp_aux's i2c adapter prior to registering it
1629 mutex_init(&aux->hw_mutex); in drm_dp_aux_init()
1630 mutex_init(&aux->cec.lock); in drm_dp_aux_init()
1631 INIT_WORK(&aux->crc_work, drm_dp_aux_crc_work); in drm_dp_aux_init()
1633 aux->ddc.algo = &drm_dp_i2c_algo; in drm_dp_aux_init()
1634 aux->ddc.algo_data = aux; in drm_dp_aux_init()
1635 aux->ddc.retries = 3; in drm_dp_aux_init()
1637 aux->ddc.lock_ops = &drm_dp_i2c_lock_ops; in drm_dp_aux_init()
1642 * drm_dp_aux_register() - initialise and register aux channel
1661 if (!aux->ddc.algo) in drm_dp_aux_register()
1664 aux->ddc.class = I2C_CLASS_DDC; in drm_dp_aux_register()
1665 aux->ddc.owner = THIS_MODULE; in drm_dp_aux_register()
1666 aux->ddc.dev.parent = aux->dev; in drm_dp_aux_register()
1668 strlcpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), in drm_dp_aux_register()
1669 sizeof(aux->ddc.name)); in drm_dp_aux_register()
1675 ret = i2c_add_adapter(&aux->ddc); in drm_dp_aux_register()
1686 * drm_dp_aux_unregister() - unregister an AUX adapter
1692 i2c_del_adapter(&aux->ddc); in drm_dp_aux_unregister()
1699 * drm_dp_psr_setup_time() - PSR setup in time usec
1721 return -EINVAL; in drm_dp_psr_setup_time()
1730 * drm_dp_start_crc() - start capture of frame CRCs
1749 aux->crc_count = 0; in drm_dp_start_crc()
1750 aux->crtc = crtc; in drm_dp_start_crc()
1751 schedule_work(&aux->crc_work); in drm_dp_start_crc()
1758 * drm_dp_stop_crc() - stop capture of frame CRCs
1776 flush_work(&aux->crc_work); in drm_dp_stop_crc()
1777 aux->crtc = NULL; in drm_dp_stop_crc()
1799 /* LG LP140WF6-SPM1 eDP panel */
1832 if (quirk->is_branch != is_branch) in drm_dp_get_quirks()
1835 if (memcmp(quirk->oui, ident->oui, sizeof(ident->oui)) != 0) in drm_dp_get_quirks()
1838 if (memcmp(quirk->device_id, any_device, sizeof(any_device)) != 0 && in drm_dp_get_quirks()
1839 memcmp(quirk->device_id, ident->device_id, sizeof(ident->device_id)) != 0) in drm_dp_get_quirks()
1842 quirks |= quirk->quirks; in drm_dp_get_quirks()
1891 * drm_dp_get_edid_quirks() - Check the EDID of a DP device to find additional
1892 * DP-specific quirks
1897 * the dev-ID in, making it impossible to only use OUIDs for determining
1916 if (memcmp(quirk->mfg_id, edid->mfg_id, in drm_dp_get_edid_quirks()
1917 sizeof(edid->mfg_id)) == 0 && in drm_dp_get_edid_quirks()
1918 memcmp(quirk->prod_id, edid->prod_code, in drm_dp_get_edid_quirks()
1919 sizeof(edid->prod_code)) == 0) in drm_dp_get_edid_quirks()
1920 quirks |= quirk->quirks; in drm_dp_get_edid_quirks()
1923 DRM_DEBUG_KMS("DP sink: EDID mfg %*phD prod-ID %*phD quirks: 0x%04x\n", in drm_dp_get_edid_quirks()
1924 (int)sizeof(edid->mfg_id), edid->mfg_id, in drm_dp_get_edid_quirks()
1925 (int)sizeof(edid->prod_code), edid->prod_code, quirks); in drm_dp_get_edid_quirks()
1932 * drm_dp_read_desc - read sink/branch descriptor from DPCD
1945 struct drm_dp_dpcd_ident *ident = &desc->ident; in drm_dp_read_desc()
1953 desc->quirks = drm_dp_get_quirks(ident, is_branch); in drm_dp_read_desc()
1955 dev_id_len = strnlen(ident->device_id, sizeof(ident->device_id)); in drm_dp_read_desc()
1957 DRM_DEBUG_KMS("%s: DP %s: OUI %*phD dev-ID %*pE HW-rev %d.%d SW-rev %d.%d quirks 0x%04x\n", in drm_dp_read_desc()
1958 aux->name, is_branch ? "branch" : "sink", in drm_dp_read_desc()
1959 (int)sizeof(ident->oui), ident->oui, in drm_dp_read_desc()
1960 dev_id_len, ident->device_id, in drm_dp_read_desc()
1961 ident->hw_rev >> 4, ident->hw_rev & 0xf, in drm_dp_read_desc()
1962 ident->sw_major_rev, ident->sw_minor_rev, in drm_dp_read_desc()
1963 desc->quirks); in drm_dp_read_desc()
1970 * drm_dp_dsc_sink_max_slice_count() - Get the max slice count
1976 * the maximum slice count supported. This is used to populate
1983 * Maximum slice count supported by DSC sink or 0 its invalid
1988 u8 slice_cap1 = dsc_dpcd[DP_DSC_SLICE_CAP_1 - DP_DSC_SUPPORT]; in drm_dp_dsc_sink_max_slice_count()
1991 /* For eDP, register DSC_SLICE_CAPABILITIES_1 gives slice count */ in drm_dp_dsc_sink_max_slice_count()
2000 u8 slice_cap2 = dsc_dpcd[DP_DSC_SLICE_CAP_2 - DP_DSC_SUPPORT]; in drm_dp_dsc_sink_max_slice_count()
2029 * drm_dp_dsc_sink_line_buf_depth() - Get the line buffer depth in bits
2045 u8 line_buf_depth = dsc_dpcd[DP_DSC_LINE_BUF_BIT_DEPTH - DP_DSC_SUPPORT]; in drm_dp_dsc_sink_line_buf_depth()
2073 * drm_dp_dsc_sink_supported_input_bpcs() - Get all the input bits per component
2093 u8 color_depth = dsc_dpcd[DP_DSC_DEC_COLOR_DEPTH_CAP - DP_DSC_SUPPORT]; in drm_dp_dsc_sink_supported_input_bpcs()
2107 * drm_dp_get_phy_test_pattern() - get the requested pattern from the sink.
2122 data->link_rate = drm_dp_bw_code_to_link_rate(rate); in drm_dp_get_phy_test_pattern()
2127 data->num_lanes = lanes & DP_MAX_LANE_COUNT_MASK; in drm_dp_get_phy_test_pattern()
2130 data->enhanced_frame_cap = true; in drm_dp_get_phy_test_pattern()
2132 err = drm_dp_dpcd_readb(aux, DP_PHY_TEST_PATTERN, &data->phy_pattern); in drm_dp_get_phy_test_pattern()
2136 switch (data->phy_pattern) { in drm_dp_get_phy_test_pattern()
2139 &data->custom80, sizeof(data->custom80)); in drm_dp_get_phy_test_pattern()
2146 &data->hbr2_reset, in drm_dp_get_phy_test_pattern()
2147 sizeof(data->hbr2_reset)); in drm_dp_get_phy_test_pattern()
2157 * drm_dp_set_phy_test_pattern() - set the pattern to the sink.
2171 link_config[0] = drm_dp_link_rate_to_bw_code(data->link_rate); in drm_dp_set_phy_test_pattern()
2172 link_config[1] = data->num_lanes; in drm_dp_set_phy_test_pattern()
2173 if (data->enhanced_frame_cap) in drm_dp_set_phy_test_pattern()
2179 test_pattern = data->phy_pattern; in drm_dp_set_phy_test_pattern()
2188 for (i = 0; i < data->num_lanes; i++) { in drm_dp_set_phy_test_pattern()
2282 return "DCI-P3"; in dp_colorimetry_get_name()
2361 vsc->revision, vsc->length); in drm_dp_vsc_sdp_log()
2363 dp_pixelformat_get_name(vsc->pixelformat)); in drm_dp_vsc_sdp_log()
2365 dp_colorimetry_get_name(vsc->pixelformat, vsc->colorimetry)); in drm_dp_vsc_sdp_log()
2366 DP_SDP_LOG(" bpc: %u\n", vsc->bpc); in drm_dp_vsc_sdp_log()
2368 dp_dynamic_range_get_name(vsc->dynamic_range)); in drm_dp_vsc_sdp_log()
2370 dp_content_type_get_name(vsc->content_type)); in drm_dp_vsc_sdp_log()