From patchwork Sun Oct 29 19:46:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13439883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2222BC4332F for ; Sun, 29 Oct 2023 19:46:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C08310E1A4; Sun, 29 Oct 2023 19:46:44 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by gabe.freedesktop.org (Postfix) with ESMTP id 20C3E10E19F for ; Sun, 29 Oct 2023 19:46:14 +0000 (UTC) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8DxRvGEtj5lvJs1AA--.39307S3; Mon, 30 Oct 2023 03:46:12 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxXNx+tj5lKq02AA--.51878S6; Mon, 30 Oct 2023 03:46:11 +0800 (CST) From: Sui Jingfeng To: Maxime Ripard , Thomas Zimmermann Subject: [PATCH 4/8] drm/loongson: Started to attach display bridge driver for LS7A1000 Date: Mon, 30 Oct 2023 03:46:03 +0800 Message-Id: <20231029194607.379459-5-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231029194607.379459-1-suijingfeng@loongson.cn> References: <20231029194607.379459-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxXNx+tj5lKq02AA--.51878S6 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00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evJa73UjIFyTuYvjxUcCD7UUUUU X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Loongson ML5B_MA board using ITE IT66121 HDMI transmitter to support HDMI display output, with the vbios provided the necessary information, we are able to create a minimal drm bridge driver for it. After apply this patch we are able to change mode freely. Tested on LS3A5000+LS7A1000 ML5B_MA board. $ dmesg | grep drm [drm] dc: 264MHz, gmc: 529MHz, gpu: 529MHz [drm] Dedicated vram start: 0xe0030000000, size: 64MiB [drm] Loongson VBIOS version: 0.3 [drm] Loongson VBIOS: has 8 DCBs [drm] VRAM: 4096 pages ready [drm] GTT: 32768 pages ready [drm] lsdc-i2c0(sda pin mask=1, scl pin mask=2) created [drm] lsdc-i2c1(sda pin mask=4, scl pin mask=8) created [drm] DisplayPipe-0 has DVO-0 [drm] device address(0x4d) is not correct [drm] i2c client IT66121@0x4c created [drm] IT66121 attached, Vendor ID: 0x4954, Device ID: 0x612 [drm] Total 2 outputs [drm] registered irq: 40 [drm] Initialized loongson 1.0.0 20220701 for 0000:00:06.1 on minor 0 loongson 0000:00:06.1: [drm] fb0: loongsondrmfb frame buffer device Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/loongson/lsdc_output_7a1000.c | 144 +++++++----------- 1 file changed, 55 insertions(+), 89 deletions(-) diff --git a/drivers/gpu/drm/loongson/lsdc_output_7a1000.c b/drivers/gpu/drm/loongson/lsdc_output_7a1000.c index 6fc8dd1c7d9a..e12f9a0157d0 100644 --- a/drivers/gpu/drm/loongson/lsdc_output_7a1000.c +++ b/drivers/gpu/drm/loongson/lsdc_output_7a1000.c @@ -10,6 +10,7 @@ #include "lsdc_drv.h" #include "lsdc_output.h" +#include "ite_it66121.h" /* * The display controller in the LS7A1000 exports two DVO interfaces, thus * external encoder is required, except connected to the DPI panel directly. @@ -38,68 +39,6 @@ * TODO: Add support for non-transparent encoders */ -static int ls7a1000_dpi_connector_get_modes(struct drm_connector *conn) -{ - unsigned int num = 0; - struct edid *edid; - - if (conn->ddc) { - edid = drm_get_edid(conn, conn->ddc); - if (edid) { - drm_connector_update_edid_property(conn, edid); - num = drm_add_edid_modes(conn, edid); - kfree(edid); - } - - return num; - } - - num = drm_add_modes_noedid(conn, 1920, 1200); - - drm_set_preferred_mode(conn, 1024, 768); - - return num; -} - -static struct drm_encoder * -ls7a1000_dpi_connector_get_best_encoder(struct drm_connector *connector, - struct drm_atomic_state *state) -{ - struct lsdc_output *output = connector_to_lsdc_output(connector); - - return &output->encoder; -} - -static const struct drm_connector_helper_funcs -ls7a1000_dpi_connector_helpers = { - .atomic_best_encoder = ls7a1000_dpi_connector_get_best_encoder, - .get_modes = ls7a1000_dpi_connector_get_modes, -}; - -static enum drm_connector_status -ls7a1000_dpi_connector_detect(struct drm_connector *connector, bool force) -{ - struct i2c_adapter *ddc = connector->ddc; - - if (ddc) { - if (drm_probe_ddc(ddc)) - return connector_status_connected; - - return connector_status_disconnected; - } - - return connector_status_unknown; -} - -static const struct drm_connector_funcs ls7a1000_dpi_connector_funcs = { - .detect = ls7a1000_dpi_connector_detect, - .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, - .reset = drm_atomic_helper_connector_reset, - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state -}; - static void ls7a1000_pipe0_encoder_reset(struct drm_encoder *encoder) { struct drm_device *ddev = encoder->dev; @@ -139,40 +78,67 @@ static const struct drm_encoder_funcs ls7a1000_encoder_funcs[2] = { }, }; +/* + * This is a default output description for LS7A1000/LS2K1000, this is always + * true from the hardware perspective. It is just that when there are external + * display bridge connected, this description no longer complete. As it cannot + * describe the topology about the external encoders. + */ +static const struct lsdc_output_desc ls7a1000_output_desc[2] = { + { + .pipe = 0, + .encoder_type = DRM_MODE_ENCODER_DPI, + .connector_type = DRM_MODE_CONNECTOR_DPI, + .encoder_funcs = &ls7a1000_encoder_funcs[0], + .encoder_helper_funcs = &lsdc_encoder_helper_funcs, + .connector_funcs = &lsdc_connector_funcs, + .connector_helper_funcs = &lsdc_connector_helper_funcs, + .name = "DVO-0", + }, + { + .pipe = 1, + .encoder_type = DRM_MODE_ENCODER_DPI, + .connector_type = DRM_MODE_CONNECTOR_DPI, + .encoder_funcs = &ls7a1000_encoder_funcs[1], + .encoder_helper_funcs = &lsdc_encoder_helper_funcs, + .connector_funcs = &lsdc_connector_funcs, + .connector_helper_funcs = &lsdc_connector_helper_funcs, + .name = "DVO-1", + }, +}; + int ls7a1000_output_init(struct drm_device *ddev, struct lsdc_display_pipe *dispipe, struct i2c_adapter *ddc, unsigned int index) { struct lsdc_output *output = &dispipe->output; - struct drm_encoder *encoder = &output->encoder; - struct drm_connector *connector = &output->connector; - int ret; - - ret = drm_encoder_init(ddev, encoder, &ls7a1000_encoder_funcs[index], - DRM_MODE_ENCODER_TMDS, "encoder-%u", index); - if (ret) - return ret; - - encoder->possible_crtcs = BIT(index); - - ret = drm_connector_init_with_ddc(ddev, connector, - &ls7a1000_dpi_connector_funcs, - DRM_MODE_CONNECTOR_DPI, ddc); - if (ret) - return ret; - - drm_info(ddev, "display pipe-%u has a DVO\n", index); - - drm_connector_helper_add(connector, &ls7a1000_dpi_connector_helpers); - - drm_connector_attach_encoder(connector, encoder); + enum loongson_vbios_encoder_name encoder_name = 0; + struct drm_bridge *bridge = NULL; + u8 slave_addr; + bool ret; + + output->descp = &ls7a1000_output_desc[index]; + + ret = loongson_vbios_query_encoder_info(ddev, index, NULL, + &encoder_name, &slave_addr); + if (!ret) + goto skip; + + switch (encoder_name) { + case ENCODER_CHIP_IT66121: + bridge = it66121_bridge_create(ddev, ddc, slave_addr, false, + 0, index); + break; + default: + break; + } - connector->polled = DRM_CONNECTOR_POLL_CONNECT | - DRM_CONNECTOR_POLL_DISCONNECT; + if (IS_ERR(bridge)) + goto skip; - connector->interlace_allowed = 0; - connector->doublescan_allowed = 0; + output->bridge = bridge; - return 0; +skip: + return lsdc_output_init(ddev, dispipe, ddc, index); }