From nobody Fri Jan 31 00:09:42 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38D0B2AE68 for ; Mon, 27 Jan 2025 03:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737948442; cv=none; b=AYRP9p+8ev1Ekhu39OXR9c5elb1Co0RH/SxOJVlWWIaPfoSX+mfT2RdvEGBtK+aSj9ZSt9k11hMcM1u9klx/bE5zgN0Sz2/EkP6CkpoDB0I0CMCkRstDu9IvNLfQLXB2fF1R0MFGwNIxcy0dhTsO2bqGSQgKVOI+kI9B9mi+plg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737948442; c=relaxed/simple; bh=2QFjkdN5AGOHdbnVYfdqtt9Jo+tK0c4uSa9j6VWbsek=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T3iF3lSz5Jop5gbXJSo2b27ZNEFyA8mHU/P9Nbm2nDaR5dk76wktSW1iKodu9b0XSd7v7EhBRpkU/THxJSqz5knlzGzwm3opeFjQ1fxXIfqItoPP623cI0+uuOVbQQTiBpbL8l4qPGukwGDYuQY83kaUCucrKorMRaMuKFHYOgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4YhDMS1fmczrSlq; Mon, 27 Jan 2025 11:25:40 +0800 (CST) Received: from kwepemd500013.china.huawei.com (unknown [7.221.188.12]) by mail.maildlp.com (Postfix) with ESMTPS id 314AC1402CF; Mon, 27 Jan 2025 11:27:18 +0800 (CST) Received: from localhost.huawei.com (10.169.71.169) by kwepemd500013.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 27 Jan 2025 11:27:16 +0800 From: Yongbang Shi To: , , , , , , , CC: , , , , , , , , Subject: [PATCH v1 drm-dp 2/4] drm/hisilicon/hibmc: Getting connector info and edid by using aux channel Date: Mon, 27 Jan 2025 11:20:22 +0800 Message-ID: <20250127032024.1542219-3-shiyongbang@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250127032024.1542219-1-shiyongbang@huawei.com> References: <20250127032024.1542219-1-shiyongbang@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd500013.china.huawei.com (7.221.188.12) Content-Type: text/plain; charset="utf-8" From: Baihan Li Registering drm_aux and using it to get connector edid with drm functions. Refactoring some structs to fit aux's register framework. Signed-off-by: Baihan Li Signed-off-by: Yongbang Shi --- drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c | 16 +++++--- drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h | 7 +++- drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c | 5 ++- drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h | 2 + drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c | 22 +++++----- .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c | 40 +++++++++++++++++-- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 5 +++ 7 files changed, 72 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c b/drivers/gpu/drm/= hisilicon/hibmc/dp/dp_aux.c index 0a903cce1fa9..c07c970d2e50 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c +++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c @@ -8,6 +8,7 @@ #include #include "dp_comm.h" #include "dp_reg.h" +#include "dp_hw.h" =20 #define HIBMC_AUX_CMD_REQ_LEN GENMASK(7, 4) #define HIBMC_AUX_CMD_ADDR GENMASK(27, 8) @@ -124,7 +125,8 @@ static int hibmc_dp_aux_parse_xfer(struct hibmc_dp_dev = *dp, struct drm_dp_aux_ms /* ret >=3D 0 ,ret is size; ret < 0, ret is err code */ static ssize_t hibmc_dp_aux_xfer(struct drm_dp_aux *aux, struct drm_dp_aux= _msg *msg) { - struct hibmc_dp_dev *dp =3D container_of(aux, struct hibmc_dp_dev, aux); + struct hibmc_dp_dev *dp =3D ((struct hibmc_dp *)container_of(aux, struct = hibmc_dp, + aux))->dp_dev; u32 aux_cmd; int ret; u32 val; /* val will be assigned at the beginning of readl_poll_timeout f= unction */ @@ -151,14 +153,16 @@ static ssize_t hibmc_dp_aux_xfer(struct drm_dp_aux *a= ux, struct drm_dp_aux_msg * return hibmc_dp_aux_parse_xfer(dp, msg); } =20 -void hibmc_dp_aux_init(struct hibmc_dp_dev *dp) +void hibmc_dp_aux_init(struct hibmc_dp *dp) { - hibmc_dp_reg_write_field(dp, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_SYNC_LEN_= SEL, 0x0); - hibmc_dp_reg_write_field(dp, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_TIMER_TIM= EOUT, 0x1); - hibmc_dp_reg_write_field(dp, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_MIN_PULSE= _NUM, + hibmc_dp_reg_write_field(dp->dp_dev, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_S= YNC_LEN_SEL, 0x0); + hibmc_dp_reg_write_field(dp->dp_dev, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_T= IMER_TIMEOUT, 0x1); + hibmc_dp_reg_write_field(dp->dp_dev, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_M= IN_PULSE_NUM, HIBMC_DP_MIN_PULSE_NUM); =20 dp->aux.transfer =3D hibmc_dp_aux_xfer; - dp->aux.is_remote =3D 0; + dp->aux.name =3D kasprintf(GFP_KERNEL, "HIBMC DRM dp aux"); + dp->aux.drm_dev =3D dp->drm_dev; drm_dp_aux_init(&dp->aux); + dp->dp_dev->aux =3D &dp->aux; } diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h b/drivers/gpu/drm= /hisilicon/hibmc/dp/dp_comm.h index 00b23301d26e..7edcecd5a5f0 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h +++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h @@ -11,8 +11,11 @@ #include #include #include + #include =20 +#include "dp_hw.h" + #define HIBMC_DP_LANE_NUM_MAX 2 =20 struct hibmc_link_status { @@ -32,7 +35,7 @@ struct hibmc_dp_link { }; =20 struct hibmc_dp_dev { - struct drm_dp_aux aux; + struct drm_dp_aux *aux; struct drm_device *dev; void __iomem *base; struct mutex lock; /* protects concurrent RW in hibmc_dp_reg_write_field(= ) */ @@ -58,7 +61,7 @@ struct hibmc_dp_dev { mutex_unlock(&_dp->lock); \ } while (0) =20 -void hibmc_dp_aux_init(struct hibmc_dp_dev *dp); +void hibmc_dp_aux_init(struct hibmc_dp *dp); int hibmc_dp_link_training(struct hibmc_dp_dev *dp); =20 #endif diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c b/drivers/gpu/drm/h= isilicon/hibmc/dp/dp_hw.c index 0dac4cfdde7c..50050908606f 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c @@ -3,6 +3,7 @@ =20 #include #include +#include #include "dp_config.h" #include "dp_comm.h" #include "dp_reg.h" @@ -156,7 +157,7 @@ int hibmc_dp_hw_init(struct hibmc_dp *dp) struct drm_device *drm_dev =3D dp->drm_dev; struct hibmc_dp_dev *dp_dev; =20 - dp_dev =3D devm_kzalloc(drm_dev->dev, sizeof(struct hibmc_dp_dev), GFP_KE= RNEL); + dp_dev =3D drmm_kcalloc(drm_dev, 1, sizeof(struct hibmc_dp_dev), GFP_KERN= EL); if (!dp_dev) return -ENOMEM; =20 @@ -167,7 +168,7 @@ int hibmc_dp_hw_init(struct hibmc_dp *dp) dp_dev->dev =3D drm_dev; dp_dev->base =3D dp->mmio + HIBMC_DP_OFFSET; =20 - hibmc_dp_aux_init(dp_dev); + hibmc_dp_aux_init(dp); =20 if (hibmc_dp_phy_init(dp_dev)) return -EAGAIN; diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h b/drivers/gpu/drm/h= isilicon/hibmc/dp/dp_hw.h index 4dc13b3d9875..53b6d0beecea 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h +++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h @@ -10,6 +10,7 @@ #include #include #include +#include =20 struct hibmc_dp_dev; =20 @@ -19,6 +20,7 @@ struct hibmc_dp { struct drm_encoder encoder; struct drm_connector connector; void __iomem *mmio; + struct drm_dp_aux aux; }; =20 int hibmc_dp_hw_init(struct hibmc_dp *dp); diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c b/drivers/gpu/drm= /hisilicon/hibmc/dp/dp_link.c index 1124cd70c320..695cb9c0b643 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c +++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c @@ -27,7 +27,7 @@ static int hibmc_dp_link_training_configure(struct hibmc_= dp_dev *dp) /* set rate and lane count */ buf[0] =3D dp->link.cap.link_rate; buf[1] =3D DP_LANE_COUNT_ENHANCED_FRAME_EN | dp->link.cap.lanes; - ret =3D drm_dp_dpcd_write(&dp->aux, DP_LINK_BW_SET, buf, sizeof(buf)); + ret =3D drm_dp_dpcd_write(dp->aux, DP_LINK_BW_SET, buf, sizeof(buf)); if (ret !=3D sizeof(buf)) { drm_dbg_dp(dp->dev, "dp aux write link rate and lanes failed, ret: %d\n"= , ret); return ret >=3D 0 ? -EIO : ret; @@ -36,13 +36,13 @@ static int hibmc_dp_link_training_configure(struct hibm= c_dp_dev *dp) /* set 8b/10b and downspread */ buf[0] =3D DP_SPREAD_AMP_0_5; buf[1] =3D DP_SET_ANSI_8B10B; - ret =3D drm_dp_dpcd_write(&dp->aux, DP_DOWNSPREAD_CTRL, buf, sizeof(buf)); + ret =3D drm_dp_dpcd_write(dp->aux, DP_DOWNSPREAD_CTRL, buf, sizeof(buf)); if (ret !=3D sizeof(buf)) { drm_dbg_dp(dp->dev, "dp aux write 8b/10b and downspread failed, ret: %d\= n", ret); return ret >=3D 0 ? -EIO : ret; } =20 - ret =3D drm_dp_read_dpcd_caps(&dp->aux, dp->dpcd); + ret =3D drm_dp_read_dpcd_caps(dp->aux, dp->dpcd); if (ret) drm_err(dp->dev, "dp aux read dpcd failed, ret: %d\n", ret); =20 @@ -85,7 +85,7 @@ static int hibmc_dp_link_set_pattern(struct hibmc_dp_dev = *dp, int pattern) =20 hibmc_dp_reg_write_field(dp, HIBMC_DP_PHYIF_CTRL0, HIBMC_DP_CFG_PAT_SEL, = val); =20 - ret =3D drm_dp_dpcd_write(&dp->aux, DP_TRAINING_PATTERN_SET, &buf, sizeof= (buf)); + ret =3D drm_dp_dpcd_write(dp->aux, DP_TRAINING_PATTERN_SET, &buf, sizeof(= buf)); if (ret !=3D sizeof(buf)) { drm_dbg_dp(dp->dev, "dp aux write training pattern set failed\n"); return ret >=3D 0 ? -EIO : ret; @@ -115,7 +115,7 @@ static int hibmc_dp_link_training_cr_pre(struct hibmc_d= p_dev *dp) if (ret) return ret; =20 - ret =3D drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, train_set, dp-= >link.cap.lanes); + ret =3D drm_dp_dpcd_write(dp->aux, DP_TRAINING_LANE0_SET, train_set, dp->= link.cap.lanes); if (ret !=3D dp->link.cap.lanes) { drm_dbg_dp(dp->dev, "dp aux write training lane set failed\n"); return ret >=3D 0 ? -EIO : ret; @@ -198,9 +198,9 @@ static int hibmc_dp_link_training_cr(struct hibmc_dp_de= v *dp) =20 voltage_tries =3D 1; for (cr_tries =3D 0; cr_tries < 80; cr_tries++) { - drm_dp_link_train_clock_recovery_delay(&dp->aux, dp->dpcd); + drm_dp_link_train_clock_recovery_delay(dp->aux, dp->dpcd); =20 - ret =3D drm_dp_dpcd_read_link_status(&dp->aux, lane_status); + ret =3D drm_dp_dpcd_read_link_status(dp->aux, lane_status); if (ret !=3D DP_LINK_STATUS_SIZE) { drm_err(dp->dev, "Get lane status failed\n"); return ret; @@ -224,7 +224,7 @@ static int hibmc_dp_link_training_cr(struct hibmc_dp_de= v *dp) if (ret) return ret; =20 - ret =3D drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, dp->link.trai= n_set, + ret =3D drm_dp_dpcd_write(dp->aux, DP_TRAINING_LANE0_SET, dp->link.train= _set, dp->link.cap.lanes); if (ret !=3D dp->link.cap.lanes) { drm_dbg_dp(dp->dev, "Update link training failed\n"); @@ -251,9 +251,9 @@ static int hibmc_dp_link_training_channel_eq(struct hib= mc_dp_dev *dp) return ret; =20 for (eq_tries =3D 0; eq_tries < HIBMC_EQ_MAX_RETRY; eq_tries++) { - drm_dp_link_train_channel_eq_delay(&dp->aux, dp->dpcd); + drm_dp_link_train_channel_eq_delay(dp->aux, dp->dpcd); =20 - ret =3D drm_dp_dpcd_read_link_status(&dp->aux, lane_status); + ret =3D drm_dp_dpcd_read_link_status(dp->aux, lane_status); if (ret !=3D DP_LINK_STATUS_SIZE) { drm_err(dp->dev, "get lane status failed\n"); break; @@ -278,7 +278,7 @@ static int hibmc_dp_link_training_channel_eq(struct hib= mc_dp_dev *dp) if (ret) return ret; =20 - ret =3D drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, + ret =3D drm_dp_dpcd_write(dp->aux, DP_TRAINING_LANE0_SET, dp->link.train_set, dp->link.cap.lanes); if (ret !=3D dp->link.cap.lanes) { drm_dbg_dp(dp->dev, "Update link training failed\n"); diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/d= rm/hisilicon/hibmc/hibmc_drm_dp.c index 603d6b198a54..fac8485a69d9 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c @@ -15,11 +15,27 @@ =20 static int hibmc_dp_connector_get_modes(struct drm_connector *connector) { + struct hibmc_dp *dp =3D to_hibmc_dp(connector); + const struct drm_edid *drm_edid; int count; =20 - count =3D drm_add_modes_noedid(connector, connector->dev->mode_config.max= _width, + drm_edid =3D drm_edid_read_ddc(connector, &dp->aux.ddc); + + drm_edid_connector_update(connector, drm_edid); + + if (drm_edid) { + count =3D drm_edid_connector_add_modes(connector); + if (count) + goto out; + } + + count =3D drm_add_modes_noedid(connector, + connector->dev->mode_config.max_width, connector->dev->mode_config.max_height); - drm_set_preferred_mode(connector, 1024, 768); // temporary implementation + drm_set_preferred_mode(connector, 1024, 768); + +out: + drm_edid_free(drm_edid); =20 return count; } @@ -28,12 +44,28 @@ static const struct drm_connector_helper_funcs hibmc_dp= _conn_helper_funcs =3D { .get_modes =3D hibmc_dp_connector_get_modes, }; =20 +static int hibmc_dp_late_register(struct drm_connector *connector) +{ + struct hibmc_dp *dp =3D to_hibmc_dp(connector); + + return drm_dp_aux_register(&dp->aux); +} + +static void hibmc_dp_early_unregister(struct drm_connector *connector) +{ + struct hibmc_dp *dp =3D to_hibmc_dp(connector); + + drm_dp_aux_unregister(&dp->aux); +} + static const struct drm_connector_funcs hibmc_dp_conn_funcs =3D { .reset =3D drm_atomic_helper_connector_reset, .fill_modes =3D drm_helper_probe_single_connector_modes, .destroy =3D drm_connector_cleanup, .atomic_duplicate_state =3D drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state =3D drm_atomic_helper_connector_destroy_state, + .late_register =3D hibmc_dp_late_register, + .early_unregister =3D hibmc_dp_early_unregister, }; =20 static inline int hibmc_dp_prepare(struct hibmc_dp *dp, struct drm_display= _mode *mode) @@ -103,8 +135,8 @@ int hibmc_dp_init(struct hibmc_drm_private *priv) =20 drm_encoder_helper_add(encoder, &hibmc_dp_encoder_helper_funcs); =20 - ret =3D drm_connector_init(dev, connector, &hibmc_dp_conn_funcs, - DRM_MODE_CONNECTOR_DisplayPort); + ret =3D drm_connector_init_with_ddc(dev, connector, &hibmc_dp_conn_funcs, + DRM_MODE_CONNECTOR_DisplayPort, &dp->aux.ddc); if (ret) { drm_err(dev, "init dp connector failed: %d\n", ret); return ret; diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/= drm/hisilicon/hibmc/hibmc_drm_drv.h index d982f1e4b958..3ddd71aada66 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h @@ -47,6 +47,11 @@ static inline struct hibmc_vdac *to_hibmc_vdac(struct dr= m_connector *connector) return container_of(connector, struct hibmc_vdac, connector); } =20 +static inline struct hibmc_dp *to_hibmc_dp(struct drm_connector *connector) +{ + return container_of(connector, struct hibmc_dp, connector); +} + static inline struct hibmc_drm_private *to_hibmc_drm_private(struct drm_de= vice *dev) { return container_of(dev, struct hibmc_drm_private, dev); --=20 2.33.0