From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4FE42FE053 for ; Tue, 9 Sep 2025 07:21:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757402498; cv=none; b=dtiB/hZ7urq8e8Ceh40FZrBUEB51JhkwNrW6+XgzyP3D1hWHxO+ELwsk/QnlewAeTVUI4z7txkfFIxUYr6P+/OHaWH8p2r/FUPh+gBtqskRSGfyWnvDlpnIyFRyXL7Nvsr2hY26L5LUxLr/JxqTOgxDp5XKJ0jcup5zy0qiT0xE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757402498; c=relaxed/simple; bh=FZYcu02d23gGvTYtiwlzcioKxi440bDzszvTGMtYclo=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=VTfOx2ut018PdK4ylmr/mb1O50STinF8fr4iOXpMbnUSZ6mhRSUUFDy52w0O9YMPJNT8zLFSa0h7Zam97E4IGSTl4/kZoUHY+oA6KhAF48ckyEZmym1ozfLBXdY0Cl8UybJpYRFp1Wx3DordnY/kxubDjQQutoRWYziSk5YfwBg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=msNInWXk; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="msNInWXk" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-45b9853e630so48697465e9.0 for ; Tue, 09 Sep 2025 00:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1757402495; x=1758007295; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:references:cc:to:subject:reply-to:from:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=/If2BlMRU5hmxDmkphdZQWc2KIPCNetMGj6QmRvd2sI=; b=msNInWXkT0SOaf37Txl/xbifcFhHxkqkNLQT7w7EBwUTiMWlsBvK40u1Isq6MIfdOn a7bqzPaQDZsux9vvp1w5gpby5NEvCgIiPojkzyp8tp1gmo3cP9u46qMz21UVutu3FH+X eGU8irwn2oRzFR7Wy5hG9/ltjBU6KZitfzEfZpLXkdHZMnmKoA+49v1HN6mx9Ag5cteS rTBhyO9XlSPU9+9xizL5pDEDROn2pZu77k2NdHSqQn49vEynUnWZ7WRUFKriQkzN1j6Q iMUEJlcYvJaLpvqsqcInny1cJXgNEOkSVaeKba9k8xvcXD9gqxPEkrCtdjkr06h2ao67 U2kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757402495; x=1758007295; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:references:cc:to:subject:reply-to:from:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=/If2BlMRU5hmxDmkphdZQWc2KIPCNetMGj6QmRvd2sI=; b=IMgLbe1o9++bm3DUVfVrwRn05osxLHWlGTITSgmAcEHLmle5+2dujI9SqPU8d2/uhz 6pGRGj83TxrwP7zoSemnQeWPUSASVhbrKugVuRTqXrbsu8l+t8q7cGITwpMIEPiBtsbX oZd3MWjhh7H67j8CxcHbto/MiW2nrXkXqdqb2W3TSoJVc0VX6HhrevN0ZwUsrc9rLsRZ Y9wz97B9uv1a+UM762i7hDk/tz51i8Wrc+Dee8K8EIqMvsqVhVaPl2xcGq6bt7j/624j +VkltAcf6wGNH9xrq/mFyV8VzO0UI9EqxWQ8dVsGU7dkIcD9Z9IrfL3C9xHg5Ymb17HQ B55Q== X-Forwarded-Encrypted: i=1; AJvYcCVtmrrVObv19jAw3ZDoeEbAErabGbWlx2DcjbfWJfKPGSyxDJFvW2akJLe/HQv+1s5kzqbk6mdpLuzU@vger.kernel.org X-Gm-Message-State: AOJu0YzAy0vS738RIqmZHA5wexpg+GB/AexL1hQJgRaJJ7J+e8bI4f7D NSNBn1KnEPgHL6/nOgyzfefBVOk1dGARaKlDBUJVL/TK5FKxQQeQKOcJ8CE+cEHGNGE= X-Gm-Gg: ASbGnctmQBDJ9gN1dEu4nkKx4g8FJx+iMV/za0jN5jbnNzFhTn+bBM+R5pgfbA5phHk za0iCK9vJzsIhqsIWRy7BMJXTQckl++j0jtPqUGasT/59aeTxSdf9EIKc03vb1C1NpbqGVSnKdj vcvZMeNJD/vg3Nq94sEl15xz/LONK5WbfRgfe7KMFlSXSzFaGVZBsQcSKnVT16q8PiI/oCU31WH u7PIB58bAg6/ZLg7FKpeD2CLlEJ+gC+a83lDtOq35inSgOIlV1sx46r0rFmMLOjehvXuuGL+pzo ZsOpVjG4BiYYgP5K+eXpTCmm8Jkf457Fl+6+amuBjr7on3mJVh7r4XHd8prcYwZY2OK3aeN9gSE 2HY6pJXZq5j5gnLDxPltLwK060yNX5/Cmp6kL6I5CPw5bciIewVW7yyIIW7E/s+ba5fA4zPwChT LpYKOjTys= X-Google-Smtp-Source: AGHT+IFNocqpkjHVd4blpS2YweyUe/pouVlEX5U9yahCP7qMq/q0m882V0be09wucGuQT1GOgWRbjQ== X-Received: by 2002:a05:600c:4694:b0:45d:d908:dc02 with SMTP id 5b1f17b1804b1-45ddded9c21mr88532585e9.31.1757402495001; Tue, 09 Sep 2025 00:21:35 -0700 (PDT) Received: from ?IPV6:2a01:e0a:3d9:2080:25ab:4e12:265b:4b6? ([2a01:e0a:3d9:2080:25ab:4e12:265b:4b6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e7521c9cdbsm1485006f8f.16.2025.09.09.00.21.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Sep 2025 00:21:34 -0700 (PDT) Message-ID: Date: Tue, 9 Sep 2025 09:21:33 +0200 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Neil Armstrong Reply-To: Neil Armstrong Subject: Re: [PATCH v3 4/5] phy: qcom: qmp-combo: get the USB3 & DisplayPort lanes mapping from DT To: Dmitry Baryshkov Cc: Andrzej Hajda , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Vinod Koul , Kishon Vijay Abraham I , Bjorn Andersson , Konrad Dybcio , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org References: <20250908-topic-x1e80100-hdmi-v3-0-c53b0f2bc2fb@linaro.org> <20250908-topic-x1e80100-hdmi-v3-4-c53b0f2bc2fb@linaro.org> Content-Language: en-US, fr Autocrypt: addr=neil.armstrong@linaro.org; keydata= xsBNBE1ZBs8BCAD78xVLsXPwV/2qQx2FaO/7mhWL0Qodw8UcQJnkrWmgTFRobtTWxuRx8WWP GTjuhvbleoQ5Cxjr+v+1ARGCH46MxFP5DwauzPekwJUD5QKZlaw/bURTLmS2id5wWi3lqVH4 BVF2WzvGyyeV1o4RTCYDnZ9VLLylJ9bneEaIs/7cjCEbipGGFlfIML3sfqnIvMAxIMZrvcl9 qPV2k+KQ7q+aXavU5W+yLNn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YBYnNi3G5EpbwfBNuT3H8//rVvtOFK4OD8cRYkxXRQmTvqa3 3eDIHu/zr1HMKErm+2SD6PO9umRef8V82o2oaCLvf4WeIssFjwB0b6a12opuRP7yo3E3gTCS KmbUuLv1CtxKQF+fUV1cVaTPMyT25Od+RC1K+iOR0F54oUJvJeq7fUzbn/KdlhA8XPGzwGRy 4zcsPWvwnXgfe5tk680fEKZVwOZKIEuJC3v+/yZpQzDvGYJvbyix0lHnrCzq43WefRHI5XTT QbM0WUIBIcGmq38+OgUsMYu4NzLu7uZFAcmp6h8g Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 08/09/2025 23:24, Dmitry Baryshkov wrote: > On Mon, Sep 08, 2025 at 03:04:21PM +0200, Neil Armstrong wrote: >> The QMP USB3/DP Combo PHY hosts an USB3 phy and a DP PHY on top >> of a combo glue to route either lanes to the 4 shared physical lanes. >> >> The routing of the lanes can be: >> - 2 DP + 2 USB3 >> - 4 DP >> - 2 USB3 >> >> Get the lanes mapping from DT and stop registering the USB-C >> muxes in favor of a static mode and orientation detemined >> by the lanes mapping. >> >> This allows supporting boards with direct connection of USB3 and >> DisplayPort lanes to the QMP Combo PHY lanes, not using the >> USB-C Altmode feature. >> >> Signed-off-by: Neil Armstrong >> --- >> drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 132 ++++++++++++++++++++++++++++-- >> 1 file changed, 124 insertions(+), 8 deletions(-) > > Looking at the patch... Would it be possible to make it more generic? I > think some of the RockChips also have similar combo USB+DP PHY (and > similar issues). I believe, Mediatek might also have the same issue. Since they don't use the data-lanes property, it's hard to make it generic and I would avoid migrating their DT to data-lanes just to solve HDMI on the Thinkpas T14s... Let's solve this first, and code can be aggregated afterwards if the DT representation is correct. > >> diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c >> index 7b5af30f1d028c592500e723ecd27b54ed554709..f3f91a69dc8b81e049cd06f7ab4f04baf57776cd 100644 >> --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c >> +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c >> @@ -13,6 +13,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -1744,6 +1745,21 @@ static const u8 qmp_dp_v6_pre_emphasis_hbr_rbr[4][4] = { >> { 0x22, 0xff, 0xff, 0xff } >> }; >> >> +static const u32 usb3_data_lane_mapping[][2] = { >> + [TYPEC_ORIENTATION_NORMAL] = { 1, 0 }, >> + [TYPEC_ORIENTATION_REVERSE] = { 2, 3 }, >> +}; >> + >> +static const u32 dp_2_data_lanes_mapping[][2] = { >> + [TYPEC_ORIENTATION_NORMAL] = { 0, 1 }, >> + [TYPEC_ORIENTATION_REVERSE] = { 3, 2 }, >> +}; >> + >> +static const u32 dp_4_data_lanes_mapping[][4] = { >> + [TYPEC_ORIENTATION_NORMAL] = { 0, 1, 2, 3 }, >> + [TYPEC_ORIENTATION_REVERSE] = { 3, 2, 1, 0 }, >> +}; >> + >> struct qmp_combo; >> >> struct qmp_combo_offsets { >> @@ -4167,9 +4183,114 @@ static int qmp_combo_probe(struct platform_device *pdev) >> if (ret) >> goto err_node_put; >> >> - ret = qmp_combo_typec_register(qmp); >> - if (ret) >> - goto err_node_put; >> + qmp->qmpphy_mode = QMPPHY_MODE_USB3DP; >> + >> + if (of_find_property(dev->of_node, "mode-switch", NULL) || >> + of_find_property(dev->of_node, "orientation-switch", NULL)) { >> + ret = qmp_combo_typec_register(qmp); >> + if (ret) >> + goto err_node_put; >> + } else { > > At least this needs to be extracted to a function (or set of functions). Yes I was not sure about how to split, and overall I'm not supeer happy about the design. > >> + enum typec_orientation usb3_orientation = TYPEC_ORIENTATION_NONE; >> + enum typec_orientation dp_orientation = TYPEC_ORIENTATION_NONE; >> + struct device_node *usb3_ep, *dp_ep; >> + u32 data_lanes[4]; >> + int count, i; >> + >> + usb3_ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); >> + dp_ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 1); >> + >> + if (usb3_ep) { >> + ret = of_property_count_u32_elems(usb3_ep, "data-lanes"); >> + if (ret == -EINVAL) >> + /* Property isn't here, ignore property */ > > In all thsese error cases we are leaking a ref count on usb3_ep and > dp_ep. It would be much simpler to solve in a separate function. > >> + goto usb3_mapping_done; >> + if (ret < 0) >> + goto err_node_put; >> + >> + count = ret; >> + if (count != 2) >> + /* Property size is invalid, ignore property */ >> + goto usb3_mapping_done; >> + >> + ret = of_property_read_u32_array(usb3_ep, "data-lanes", data_lanes, count); >> + if (ret) >> + goto err_node_put; >> + >> + for (i = TYPEC_ORIENTATION_NORMAL; i <= TYPEC_ORIENTATION_REVERSE; i++) >> + if (!memcmp(data_lanes, usb3_data_lane_mapping[i], sizeof(u32) * 2)) >> + break; >> + >> + if (i >= TYPEC_ORIENTATION_REVERSE) >> + /* Property value is invalid, ignore property */ >> + goto usb3_mapping_done; >> + >> + usb3_orientation = i; >> + } >> + >> +usb3_mapping_done: >> + of_node_put(usb3_ep); >> + >> + if (dp_ep) { >> + ret = of_property_count_u32_elems(dp_ep, "data-lanes"); >> + if (ret == -EINVAL) >> + /* Property isn't here, ignore property */ >> + goto dp_mapping_done; >> + if (ret < 0) >> + goto err_node_put; >> + >> + count = ret; >> + if (count != 2 && count != 4) >> + /* Property size is invalid, ignore property */ >> + goto dp_mapping_done; >> + >> + ret = of_property_read_u32_array(dp_ep, "data-lanes", data_lanes, count); >> + >> + if (ret) >> + goto err_node_put; >> + >> + for (i = TYPEC_ORIENTATION_NORMAL; i <= TYPEC_ORIENTATION_REVERSE; i++) { >> + switch (count) { >> + case 2: >> + ret = memcmp(data_lanes, dp_2_data_lanes_mapping[i], >> + sizeof(u32) * count); >> + break; >> + case 4: >> + ret = memcmp(data_lanes, dp_4_data_lanes_mapping[i], >> + sizeof(u32) * count); >> + break; >> + } >> + >> + if (!ret) >> + break; >> + } >> + >> + if (i >= TYPEC_ORIENTATION_REVERSE) >> + /* Property value is invalid, ignore property */ >> + goto dp_mapping_done; >> + >> + dp_orientation = i; >> + } >> + >> +dp_mapping_done: >> + of_node_put(dp_ep); >> + >> + if (dp_orientation == TYPEC_ORIENTATION_NONE && >> + usb3_orientation != TYPEC_ORIENTATION_NONE) { >> + qmp->qmpphy_mode = QMPPHY_MODE_USB3_ONLY; >> + qmp->orientation = usb3_orientation; >> + } else if (usb3_orientation == TYPEC_ORIENTATION_NONE && >> + dp_orientation != TYPEC_ORIENTATION_NONE) { >> + qmp->qmpphy_mode = QMPPHY_MODE_DP_ONLY; >> + qmp->orientation = dp_orientation; >> + } else if (dp_orientation != TYPEC_ORIENTATION_NONE && >> + dp_orientation == usb3_orientation) { >> + qmp->qmpphy_mode = QMPPHY_MODE_USB3DP; >> + qmp->orientation = dp_orientation; >> + } else { >> + dev_warn(dev, "unable to determine orientation & mode from data-lanes"); >> + } >> + } >> >> ret = drm_aux_bridge_register(dev); >> if (ret) >> @@ -4189,11 +4310,6 @@ static int qmp_combo_probe(struct platform_device *pdev) >> if (ret) >> goto err_node_put; >> >> - /* >> - * The hw default is USB3_ONLY, but USB3+DP mode lets us more easily >> - * check both sub-blocks' init tables for blunders at probe time. >> - */ >> - qmp->qmpphy_mode = QMPPHY_MODE_USB3DP; >> >> qmp->usb_phy = devm_phy_create(dev, usb_np, &qmp_combo_usb_phy_ops); >> if (IS_ERR(qmp->usb_phy)) { >> >> -- >> 2.34.1 >> >