From patchwork Mon Apr 4 12:01:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sharma, Shashank" X-Patchwork-Id: 8740741 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4EBF79F39A for ; Mon, 4 Apr 2016 11:52:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 571C22025A for ; Mon, 4 Apr 2016 11:52:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4DFE920172 for ; Mon, 4 Apr 2016 11:52:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E11316E599; Mon, 4 Apr 2016 11:52:40 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTP id A60AC6E599 for ; Mon, 4 Apr 2016 11:52:39 +0000 (UTC) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP; 04 Apr 2016 04:52:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,440,1455004800"; d="scan'208";a="777661496" Received: from shashanks-desktop.iind.intel.com ([10.223.26.24]) by orsmga003.jf.intel.com with ESMTP; 04 Apr 2016 04:52:36 -0700 From: Shashank Sharma To: intel-gfx@lists.freedesktop.org, ville.syrjala@linux.intel.com, daniel.vetter@intel.com, paulo.r.zanoni@intel.com, sonika.jindal@intel.com, sivakumar.thulasimani@intel.com Date: Mon, 4 Apr 2016 17:31:44 +0530 Message-Id: <1459771308-4405-8-git-send-email-shashank.sharma@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459771308-4405-1-git-send-email-shashank.sharma@intel.com> References: <1459771308-4405-1-git-send-email-shashank.sharma@intel.com> Subject: [Intel-gfx] [PATCH 08/12] drm: Add lspcon (custom type2 dp->hdmi) support X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for LSPCON devices in dp++ adaptor helper layer. LSPCON is DP++ type-2 adaptor with some customized functionalities, to provide additional features in Intel Gen9 HW. LSPCON needs I2C-over-aux support to read/write control and data registers. This patch adds following: - Functions for I2C over aux read/write - Function to read EDID using I2c-over-aux - Function to identify LSPCON among type-2 DP adaptors Signed-off-by: Shashank Sharma --- drivers/gpu/drm/drm_dp_dual_mode_helper.c | 100 ++++++++++++++++++++++++++++++ include/drm/drm_dp_dual_mode_helper.h | 10 +++ 2 files changed, 110 insertions(+) diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c index b72b7bb..ce8e11c 100644 --- a/drivers/gpu/drm/drm_dp_dual_mode_helper.c +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c @@ -132,6 +132,99 @@ ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter, } EXPORT_SYMBOL(drm_dp_dual_mode_write); +int drm_dp_dual_mode_get_edid(void *data, + u8 *buf, unsigned int block, size_t len) +{ + struct i2c_adapter *adapter = data; + unsigned char start = block * EDID_LENGTH; + unsigned char segment = block >> 1; + unsigned char xfers = segment ? 3 : 2; + int ret, retries = 5; + + do { + struct i2c_msg msgs[] = { + { + .addr = DP_DUAL_MODE_DDC_SEGMENT_ADDR, + .flags = 0, + .len = 1, + .buf = &segment, + }, { + .addr = DDC_ADDR, + .flags = 0, + .len = 1, + .buf = &start, + }, { + .addr = DDC_ADDR, + .flags = I2C_M_RD, + .len = len, + .buf = buf, + } + }; + + ret = adapter->algo->master_xfer(adapter, &msgs[3 - xfers], + xfers); + + if (ret == -ENXIO) { + DRM_ERROR("Non-existent adapter %s\n", + adapter->name); + break; + } + } while (ret != xfers && --retries); + + return ret == xfers ? 0 : -1; +} +EXPORT_SYMBOL(drm_dp_dual_mode_get_edid); + +/* +* drm_dp_dual_mode_ioa_xfer +* Few dp->hdmi type 2 adaptors allow i2c_over_aux read/write +* to the control and status registers. These functions help +* to read/write from those. +*/ +static int drm_dp_dual_mode_ioa_xfer(struct i2c_adapter *adapter, + u8 *buffer, u8 offset, u8 no_of_bytes, u8 rw_flag) +{ + int err = 0; + + struct i2c_msg msgs[] = { + { + .addr = DP_DUAL_MODE_SLAVE_ADDRESS, + .flags = 0, + .len = 1, + .buf = &offset, + }, { + .addr = DP_DUAL_MODE_SLAVE_ADDRESS, + .flags = rw_flag, + .len = no_of_bytes, + .buf = buffer, + } + }; + + /* I2C over AUX here */ + err = adapter->algo->master_xfer(adapter, msgs, 2); + if (err < 0) + DRM_ERROR("LSPCON: Failed I2C over Aux read(addr=0x%x)\n", + (unsigned int)offset); + + return err; +} + +int drm_dp_dual_mode_ioa_read(struct i2c_adapter *adapter, u8 *buffer, + u8 offset, u8 no_of_bytes) +{ + return drm_dp_dual_mode_ioa_xfer(adapter, buffer, offset, + no_of_bytes, I2C_M_RD); +} +EXPORT_SYMBOL(drm_dp_dual_mode_ioa_read); + +int drm_dp_dual_mode_ioa_write(struct i2c_adapter *adapter, u8 *buffer, + u8 offset, u8 no_of_bytes) +{ + return drm_dp_dual_mode_ioa_xfer(adapter, buffer, offset, + no_of_bytes, 0); +} +EXPORT_SYMBOL(drm_dp_dual_mode_ioa_write); + static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN]) { static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = @@ -141,6 +234,11 @@ static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN]) sizeof(dp_dual_mode_hdmi_id)) == 0; } +bool is_lspcon_adaptor(const uint8_t adaptor_id) +{ + return adaptor_id == 0xa8; +} + /** * drm_dp_dual_mode_detect - Identyfy the DP dual mode adaptor * adapter: I2C adapter for the DDC bus @@ -197,6 +295,8 @@ enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter) &adaptor_id, sizeof(adaptor_id)); if (ret || (adaptor_id != (DP_DUAL_MODE_TYPE_TYPE2 | DP_DUAL_MODE_REV_TYPE2))) { + if (is_lspcon_adaptor(adaptor_id)) + return DRM_DP_DUAL_MODE_TYPE2_LSPCON; if (is_hdmi_adaptor(hdmi_id)) return DRM_DP_DUAL_MODE_TYPE1_HDMI; else diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h index 8f8a8dc..26e3dd8 100644 --- a/include/drm/drm_dp_dual_mode_helper.h +++ b/include/drm/drm_dp_dual_mode_helper.h @@ -24,6 +24,7 @@ #define DRM_DP_DUAL_MODE_HELPER_H #include +#include /* * Optional for type 1 DVI adaptors @@ -55,6 +56,7 @@ #define DP_DUAL_MODE_CEC_ENABLE 0x01 #define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22 #define DP_DUAL_MODE_LAST_RESERVED 0xff +#define DP_DUAL_MODE_DDC_SEGMENT_ADDR 0x30 struct i2c_adapter; @@ -69,6 +71,7 @@ enum drm_dp_dual_mode_type { DRM_DP_DUAL_MODE_TYPE1_HDMI, DRM_DP_DUAL_MODE_TYPE2_DVI, DRM_DP_DUAL_MODE_TYPE2_HDMI, + DRM_DP_DUAL_MODE_TYPE2_LSPCON, }; enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter); @@ -81,4 +84,11 @@ drm_dp_dual_mode_set_tmds_output(struct i2c_adapter *adapter, bool enable); const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type); +int drm_dp_dual_mode_ioa_read(struct i2c_adapter *adapter, u8 *buffer, + u8 offset, u8 no_of_bytes); +int drm_dp_dual_mode_ioa_write(struct i2c_adapter *adapter, u8 *buffer, + u8 offset, u8 no_of_bytes); +int drm_dp_dual_mode_get_edid(void *data, + u8 *buf, unsigned int block, size_t len); + #endif