From patchwork Tue May 31 09:25:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sharma, Shashank" X-Patchwork-Id: 9143981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C8AE60777 for ; Tue, 31 May 2016 09:16:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F7742793B for ; Tue, 31 May 2016 09:16:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3451A28185; Tue, 31 May 2016 09:16:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28DA72793B for ; Tue, 31 May 2016 09:16:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E40466E24F; Tue, 31 May 2016 09:16:32 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id E79676E337 for ; Tue, 31 May 2016 09:16:22 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 31 May 2016 02:16:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,395,1459839600"; d="scan'208";a="711474847" Received: from shashanks-desktop.iind.intel.com ([10.223.26.24]) by FMSMGA003.fm.intel.com with ESMTP; 31 May 2016 02:16:20 -0700 From: Shashank Sharma To: intel-gfx@lists.freedesktop.org, ville.syrjala@linux.intel.com, paulo.r.zanoni@intel.com Date: Tue, 31 May 2016 14:55:42 +0530 Message-Id: <1464686746-5099-2-git-send-email-shashank.sharma@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464686746-5099-1-git-send-email-shashank.sharma@intel.com> References: <1464686746-5099-1-git-send-email-shashank.sharma@intel.com> Cc: daniel.vetter@intel.com Subject: [Intel-gfx] [PATCH 1/5] drm: Helper for LSPCON in drm_dp_dual_mode 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-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Shashank Sharma --- drivers/gpu/drm/drm_dp_dual_mode_helper.c | 85 +++++++++++++++++++++++++++++++ include/drm/drm_dp_dual_mode_helper.h | 29 +++++++++++ 2 files changed, 114 insertions(+) diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c index a7b2a75..11cab25 100644 --- a/drivers/gpu/drm/drm_dp_dual_mode_helper.c +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c @@ -148,6 +148,12 @@ static bool is_type2_adaptor(uint8_t adaptor_id) DP_DUAL_MODE_REV_TYPE2); } +bool is_lspcon_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN], + const uint8_t adaptor_id) +{ + return is_hdmi_adaptor(hdmi_id) && (adaptor_id == 0xa8); +} + /** * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor * @adapter: I2C adapter for the DDC bus @@ -203,6 +209,8 @@ enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter) ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID, &adaptor_id, sizeof(adaptor_id)); if (ret == 0) { + if (is_lspcon_adaptor(hdmi_id, adaptor_id)) + return DRM_DP_DUAL_MODE_LSPCON; if (is_type2_adaptor(adaptor_id)) { if (is_hdmi_adaptor(hdmi_id)) return DRM_DP_DUAL_MODE_TYPE2_HDMI; @@ -364,3 +372,80 @@ const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type) } } EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name); + +/** + * drm_lspcon_get_current_mode: Get LSPCON's current mode of operation by + * by reading offset (0x80, 0x41) + * @i2c_adapter: I2C-over-aux adapter + * + * Returns: + * Enum representing current mode of operation + */ +enum drm_lspcon_mode +drm_lspcon_get_current_mode(struct i2c_adapter *adapter) +{ + u8 data; + int err = 0; + + /* Read Status: i2c over aux */ + err = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_LSPCON_CURRENT_MODE, + (void *)&data, sizeof(data)); + if (err < 0) { + DRM_ERROR("LSPCON read(0x80, 0x41) failed\n"); + return DRM_LSPCON_MODE_INVALID; + } + + return data & DP_DUAL_MODE_LSPCON_MODE_MASK ? + DRM_LSPCON_MODE_PCON : DRM_LSPCON_MODE_LS; +} +EXPORT_SYMBOL(drm_lspcon_get_current_mode); + +/** + * drm_lspcon_change_mode: Change LSPCON's mode of operation by + * by writing offset (0x80, 0x40) + * @i2c_adapter: I2C-over-aux adapter + * @reqd_mode: required mode of operation + * + * Returns: + * 0 on success, -error on failure/timeout + */ +int drm_lspcon_change_mode(struct i2c_adapter *adapter, + enum drm_lspcon_mode reqd_mode) +{ + u8 data; + int err; + int time_out = 200; + + if (reqd_mode == DRM_LSPCON_MODE_LS) + data = ~DP_DUAL_MODE_LSPCON_MODE_MASK; + else + data = DP_DUAL_MODE_LSPCON_MODE_MASK; + + /* Change mode */ + err = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_LSPCON_MODE_CHANGE, + &data, sizeof(data)); + if (err < 0) { + DRM_ERROR("LSPCON mode change failed\n"); + return err; + } + + /* + * Confirm mode change by reading the status bit. + * Sometimes, it takes a while to change the mode, + * so wait and retry until time out or done. + */ + while (time_out) { + if (reqd_mode != drm_lspcon_get_current_mode(adapter)) { + mdelay(10); + time_out -= 10; + } else { + DRM_DEBUG_KMS("LSPCON mode changed to %s\n", + reqd_mode == DRM_LSPCON_MODE_LS ? "LS" : "PCON"); + return 0; + } + } + + DRM_ERROR("LSPCON mode change timed out\n"); + return -EFAULT; +} +EXPORT_SYMBOL(drm_lspcon_change_mode); diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h index e8a9dfd..f335df5 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 @@ -54,6 +55,9 @@ #define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21 #define DP_DUAL_MODE_CEC_ENABLE 0x01 #define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22 +#define DP_DUAL_MODE_LSPCON_MODE_CHANGE 0x40 +#define DP_DUAL_MODE_LSPCON_CURRENT_MODE 0x41 +#define DP_DUAL_MODE_LSPCON_MODE_MASK 0x1 struct i2c_adapter; @@ -63,6 +67,20 @@ ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter, u8 offset, const void *buffer, size_t size); /** +* enum drm_lspcon_mode +* @lspcon_mode_invalid: No idea what's going on +* @lspcon_mode_ls: Level shifter mode of LSPCON +* which drives DP++ to HDMI 1.4 conversion. +* @lspcon_mode_pcon: Protocol converter mode of LSPCON +* which drives DP++ to HDMI 2.0 active conversion. +*/ +enum drm_lspcon_mode { + DRM_LSPCON_MODE_INVALID, + DRM_LSPCON_MODE_LS, + DRM_LSPCON_MODE_PCON, +}; + +/** * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI adaptor @@ -70,6 +88,7 @@ ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter, * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor + * @DRM_DP_DUAL_MODE_TYPE2_LSPCON: Level shifter /protocol converter */ enum drm_dp_dual_mode_type { DRM_DP_DUAL_MODE_NONE, @@ -78,6 +97,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_LSPCON, }; enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter); @@ -89,4 +109,13 @@ int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type, 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); +enum drm_lspcon_mode drm_lspcon_get_current_mode(struct i2c_adapter *adapter); +int drm_lspcon_change_mode(struct i2c_adapter *adapter, + enum drm_lspcon_mode reqd_mode); #endif