From patchwork Tue Nov 14 15:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455485 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 C0E6DC4167D for ; Tue, 14 Nov 2023 15:09:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 05FE410E21D; Tue, 14 Nov 2023 15:09:36 +0000 (UTC) Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D41E10E430 for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RX2Fmd7n/lPyGrqbFE5Q/i0VXpKAAer+IRR7UyADmdM=; b=klKW73kaFsLVaV8jy29fj+SNcq26CObnK9T7ZK0lbfaiZ9pJIWcWc3+wTt5eXRI9KAA9IR rUls9elRnQaFDjw61cap3rSDs05hBsnaiPASNuG2NcT5drLy2PiqB1Qa4EAtQDJuokeQSz y7hD8OiSWR6bdBFVNwZjIHmcC2KkW3s= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 1/8] drm/bridge: it66121: Use dev replace ctx->dev in the it66121_probe() Date: Tue, 14 Nov 2023 23:01:23 +0800 Message-Id: <20231114150130.497915-2-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng As the value of 'ctx->dev' has already been cached to the local variable 'dev', so keep the usage consistent. Just trivial cleanup, no functional change. Signed-off-by: Sui Jingfeng Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/bridge/ite-it66121.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 1cf3fb1f13dc..6e5c10cfa0bc 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -1536,20 +1536,20 @@ static int it66121_probe(struct i2c_client *client) ep = of_graph_get_remote_node(dev->of_node, 1, -1); if (!ep) { - dev_err(ctx->dev, "The endpoint is unconnected\n"); + dev_err(dev, "The endpoint is unconnected\n"); return -EINVAL; } if (!of_device_is_available(ep)) { of_node_put(ep); - dev_err(ctx->dev, "The remote device is disabled\n"); + dev_err(dev, "The remote device is disabled\n"); return -ENODEV; } ctx->next_bridge = of_drm_find_bridge(ep); of_node_put(ep); if (!ctx->next_bridge) { - dev_dbg(ctx->dev, "Next bridge not found, deferring probe\n"); + dev_dbg(dev, "Next bridge not found, deferring probe\n"); return -EPROBE_DEFER; } @@ -1599,7 +1599,7 @@ static int it66121_probe(struct i2c_client *client) drm_bridge_add(&ctx->bridge); - dev_info(ctx->dev, "IT66121 revision %d probed\n", revision_id); + dev_info(dev, "IT66121 revision %d probed\n", revision_id); return 0; } From patchwork Tue Nov 14 15:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455491 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 38C9AC4167B for ; Tue, 14 Nov 2023 15:09:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F1A4610E44B; Tue, 14 Nov 2023 15:09:41 +0000 (UTC) Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [IPv6:2001:41d0:203:375::bc]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2083A10E21D for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4/AJQfUuyoCHR0j5BR2C2vklNLNE7s2XZrrtydJkf1Y=; b=GbeqzuX9VdvKdWkR2XqDAMvGruVGq8spw3/v9UF6jqToYc3Z6Hew/hWfItzHXN0Xzk5wJD Qu/o7xOs2P/VBCJ3V5OjQ6v5AwiNp8C4t5HTkeduQYOhxoN0zK0isNsmlylCZAZn6/2x9L UxtcHTx8KMWl+yGrNIj0PtjKPD/pOIA= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 2/8] drm/bridge: it66121: Add bridge_to_it66121() helper and use it Date: Tue, 14 Nov 2023 23:01:24 +0800 Message-Id: <20231114150130.497915-3-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng Instead of using the container_of() directly, which avoid the code lines too long in horizontial. Just trivial cleanup, no functional change. Signed-off-by: Sui Jingfeng Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/bridge/ite-it66121.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 6e5c10cfa0bc..83dbdbfc9ed8 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -315,6 +315,11 @@ struct it66121_ctx { const struct it66121_chip_info *info; }; +static inline struct it66121_ctx *bridge_to_it66121(struct drm_bridge *bridge) +{ + return container_of(bridge, struct it66121_ctx, bridge); +} + static const struct regmap_range_cfg it66121_regmap_banks[] = { { .name = "it66121", @@ -588,7 +593,7 @@ static bool it66121_is_hpd_detect(struct it66121_ctx *ctx) static int it66121_bridge_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); int ret; if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) @@ -699,7 +704,7 @@ static u32 *it66121_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, u32 output_fmt, unsigned int *num_input_fmts) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); u32 *input_fmts; *num_input_fmts = 0; @@ -723,7 +728,7 @@ static u32 *it66121_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, static void it66121_bridge_enable(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); struct drm_atomic_state *state = bridge_state->base.state; ctx->connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder); @@ -734,7 +739,7 @@ static void it66121_bridge_enable(struct drm_bridge *bridge, static void it66121_bridge_disable(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); it66121_set_mute(ctx, true); @@ -746,7 +751,7 @@ static int it66121_bridge_check(struct drm_bridge *bridge, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); if (ctx->info->id == ID_IT6610) { /* The IT6610 only supports these settings */ @@ -765,7 +770,7 @@ void it66121_bridge_mode_set(struct drm_bridge *bridge, const struct drm_display_mode *adjusted_mode) { u8 buf[HDMI_INFOFRAME_SIZE(AVI)]; - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); int ret; mutex_lock(&ctx->lock); @@ -831,7 +836,7 @@ static enum drm_mode_status it66121_bridge_mode_valid(struct drm_bridge *bridge, const struct drm_display_info *info, const struct drm_display_mode *mode) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); unsigned long max_clock; max_clock = (ctx->bus_width == 12) ? 74250 : 148500; @@ -847,7 +852,7 @@ static enum drm_mode_status it66121_bridge_mode_valid(struct drm_bridge *bridge, static enum drm_connector_status it66121_bridge_detect(struct drm_bridge *bridge) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); return it66121_is_hpd_detect(ctx) ? connector_status_connected : connector_status_disconnected; @@ -855,7 +860,7 @@ static enum drm_connector_status it66121_bridge_detect(struct drm_bridge *bridge static void it66121_bridge_hpd_enable(struct drm_bridge *bridge) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); int ret; ret = regmap_write_bits(ctx->regmap, IT66121_INT_MASK1_REG, IT66121_INT_MASK1_HPD, 0); @@ -865,7 +870,7 @@ static void it66121_bridge_hpd_enable(struct drm_bridge *bridge) static void it66121_bridge_hpd_disable(struct drm_bridge *bridge) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); int ret; ret = regmap_write_bits(ctx->regmap, IT66121_INT_MASK1_REG, @@ -877,7 +882,7 @@ static void it66121_bridge_hpd_disable(struct drm_bridge *bridge) static struct edid *it66121_bridge_get_edid(struct drm_bridge *bridge, struct drm_connector *connector) { - struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge); + struct it66121_ctx *ctx = bridge_to_it66121(bridge); struct edid *edid; int ret; From patchwork Tue Nov 14 15:01:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455486 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 11E02C4167B for ; Tue, 14 Nov 2023 15:09:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2DD4810E21E; Tue, 14 Nov 2023 15:09:37 +0000 (UTC) Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3DEFD10E236 for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cnL8rRLdhxEUHMmzuPbpEqxboZkciFsFzGYdTqdV4zg=; b=PKDm94kMbgxgRSLDoJDDSVLVgpcMTPt7BhKDKq9u6fu0bN01BjveNYWGPsleYtML9yc6Vd eKvVW8SN4uT1AYUPGnTKzuZUQsbFIhPRfNrOrlPK588nvpPe3PyohC6pRUszauqnKiTdjK GJIH4tNSxWQ8DotrzwByn2N/K9Jo9og= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 3/8] drm/bridge: it66121: Add a helper function to read bus width Date: Tue, 14 Nov 2023 23:01:25 +0800 Message-Id: <20231114150130.497915-4-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng Group those relavent code lines (which with common purpose) into one helper function, suppress the dependency on DT to function level. Just trivial cleanup, no functional change. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 83dbdbfc9ed8..0f78737adc83 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -320,6 +320,26 @@ static inline struct it66121_ctx *bridge_to_it66121(struct drm_bridge *bridge) return container_of(bridge, struct it66121_ctx, bridge); } +static int it66121_of_read_bus_width(struct device *dev, u32 *bus_width) +{ + struct device_node *np; + u32 bw; + + np = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); + if (!np) + return -EINVAL; + + of_property_read_u32(np, "bus-width", &bw); + of_node_put(np); + + if (bw != 12 && bw != 24) + return -EINVAL; + + *bus_width = bw; + + return 0; +} + static const struct regmap_range_cfg it66121_regmap_banks[] = { { .name = "it66121", @@ -1525,19 +1545,13 @@ static int it66121_probe(struct i2c_client *client) if (!ctx) return -ENOMEM; - ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); - if (!ep) - return -EINVAL; - ctx->dev = dev; ctx->client = client; ctx->info = i2c_get_match_data(client); - of_property_read_u32(ep, "bus-width", &ctx->bus_width); - of_node_put(ep); - - if (ctx->bus_width != 12 && ctx->bus_width != 24) - return -EINVAL; + ret = it66121_of_read_bus_width(dev, &ctx->bus_width); + if (ret) + return ret; ep = of_graph_get_remote_node(dev->of_node, 1, -1); if (!ep) { From patchwork Tue Nov 14 15:01:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455489 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 0D119C4167B for ; Tue, 14 Nov 2023 15:09:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF24C10E449; Tue, 14 Nov 2023 15:09:41 +0000 (UTC) Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [IPv6:2001:41d0:203:375::bd]) by gabe.freedesktop.org (Postfix) with ESMTPS id A061110E21E for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m5kKprLLEL4tPCbX40jldFRROJifNOVhztsTzbLcjYw=; b=WyS6P1AXayZo5bIYUZyFvxH6Pcx9HWuPhtPw37v8O/C66WjCM/UsZI7uLcPBQhHcgaFult iAcTH0nqI4aF7oSAFTboO7pyfc69AuLknUW9GM/uJkXUWSgMdgnBcNGGZ9brJwJvjYiGsZ OuC9XAyhhLHvBgL2h19yod6bgx6jhXg= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 4/8] drm/bridge: it66121: Add a helper function to get the next bridge Date: Tue, 14 Nov 2023 23:01:26 +0800 Message-Id: <20231114150130.497915-5-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng Group the code lines(which with the same functional) into one dedicated function, which reduce the weight of it66121_probe() function. Just trivial cleanuo, no functional change. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 53 ++++++++++++++++++---------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 0f78737adc83..7e473beefc79 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -340,6 +340,37 @@ static int it66121_of_read_bus_width(struct device *dev, u32 *bus_width) return 0; } +static int it66121_of_get_next_bridge(struct device *dev, + struct drm_bridge **next_bridge) +{ + struct device_node *np; + struct drm_bridge *bridge; + + np = of_graph_get_remote_node(dev->of_node, 1, -1); + if (!np) { + dev_err(dev, "The endpoint is unconnected\n"); + return -EINVAL; + } + + if (!of_device_is_available(np)) { + of_node_put(np); + dev_err(dev, "The remote device is disabled\n"); + return -ENODEV; + } + + bridge = of_drm_find_bridge(np); + of_node_put(np); + + if (!bridge) { + dev_dbg(dev, "Next bridge not found, deferring probe\n"); + return -EPROBE_DEFER; + } + + *next_bridge = bridge; + + return 0; +} + static const struct regmap_range_cfg it66121_regmap_banks[] = { { .name = "it66121", @@ -1531,7 +1562,6 @@ static const char * const it66121_supplies[] = { static int it66121_probe(struct i2c_client *client) { u32 revision_id, vendor_ids[2] = { 0 }, device_ids[2] = { 0 }; - struct device_node *ep; int ret; struct it66121_ctx *ctx; struct device *dev = &client->dev; @@ -1553,24 +1583,9 @@ static int it66121_probe(struct i2c_client *client) if (ret) return ret; - ep = of_graph_get_remote_node(dev->of_node, 1, -1); - if (!ep) { - dev_err(dev, "The endpoint is unconnected\n"); - return -EINVAL; - } - - if (!of_device_is_available(ep)) { - of_node_put(ep); - dev_err(dev, "The remote device is disabled\n"); - return -ENODEV; - } - - ctx->next_bridge = of_drm_find_bridge(ep); - of_node_put(ep); - if (!ctx->next_bridge) { - dev_dbg(dev, "Next bridge not found, deferring probe\n"); - return -EPROBE_DEFER; - } + ret = it66121_of_get_next_bridge(dev, &ctx->next_bridge); + if (ret) + return ret; i2c_set_clientdata(client, ctx); mutex_init(&ctx->lock); From patchwork Tue Nov 14 15:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455484 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 3B754C4332F for ; Tue, 14 Nov 2023 15:09:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 61AD210E206; Tue, 14 Nov 2023 15:09:34 +0000 (UTC) X-Greylist: delayed 454 seconds by postgrey-1.36 at gabe; Tue, 14 Nov 2023 15:09:31 UTC Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [IPv6:2001:41d0:203:375::b0]) by gabe.freedesktop.org (Postfix) with ESMTPS id 033FB10E206 for ; Tue, 14 Nov 2023 15:09:31 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NjLEQ2aBUBcn+Sqc95rmrPoW3NH5ZZ26cu6iyzwpGc0=; b=kuURKlYbDIZkkE2VlZVqW0eLF4/yKYOCNNFEuflSWrkD8XOv6U9BWn3iVZmIUtoJqSidkD tHAtBcRbv/f+SkUPe+gNkccy0E/Nv7Yd/65IhYW7jtAtFcDG5baoSGFxCLWjC+195kewFe Ihq1rL5hTg0Go/FFQ+xyAE9m8Z5jvmw= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 5/8] drm/bridge: it66121: Add a helper function to read chip id Date: Tue, 14 Nov 2023 23:01:27 +0800 Message-Id: <20231114150130.497915-6-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng Read the required chip id data back by calling regmap_bulk_read() once, reduce the number of local variables needed in it66121_probe() function. And store its values into struct it66121_ctx, as it will be used latter. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 47 ++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 7e473beefc79..f36d05331f25 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -313,6 +313,9 @@ struct it66121_ctx { bool auto_cts; } audio; const struct it66121_chip_info *info; + u16 vender_id; + u16 device_id; + u8 revision; }; static inline struct it66121_ctx *bridge_to_it66121(struct drm_bridge *bridge) @@ -399,6 +402,30 @@ static void it66121_hw_reset(struct it66121_ctx *ctx) gpiod_set_value(ctx->gpio_reset, 0); } +static int it66121_read_chip_id(struct it66121_ctx *ctx, bool verbose) +{ + u8 id[4]; + int ret; + + ret = regmap_bulk_read(ctx->regmap, IT66121_VENDOR_ID0_REG, id, 4); + if (ret < 0) { + dev_err(ctx->dev, "Failed to read chip ID: %d\n", ret); + return ret; + } + + ctx->vender_id = (u16)id[1] << 8 | id[0]; + ctx->device_id = ((u16)(id[3] & IT66121_DEVICE_ID1_MASK) << 8 | id[2]); + /* Revision is shared with DEVICE_ID1 */ + ctx->revision = FIELD_GET(IT66121_REVISION_MASK, id[3]); + + if (verbose) { + dev_info(ctx->dev, "Found ITE66121: 0x%x%x, revision: %u\n", + ctx->vender_id, ctx->device_id, ctx->revision); + } + + return 0; +} + static inline int it66121_preamble_ddc(struct it66121_ctx *ctx) { return regmap_write(ctx->regmap, IT66121_MASTER_SEL_REG, IT66121_MASTER_SEL_HOST); @@ -1561,7 +1588,6 @@ static const char * const it66121_supplies[] = { static int it66121_probe(struct i2c_client *client) { - u32 revision_id, vendor_ids[2] = { 0 }, device_ids[2] = { 0 }; int ret; struct it66121_ctx *ctx; struct device *dev = &client->dev; @@ -1603,19 +1629,13 @@ static int it66121_probe(struct i2c_client *client) if (IS_ERR(ctx->regmap)) return PTR_ERR(ctx->regmap); - regmap_read(ctx->regmap, IT66121_VENDOR_ID0_REG, &vendor_ids[0]); - regmap_read(ctx->regmap, IT66121_VENDOR_ID1_REG, &vendor_ids[1]); - regmap_read(ctx->regmap, IT66121_DEVICE_ID0_REG, &device_ids[0]); - regmap_read(ctx->regmap, IT66121_DEVICE_ID1_REG, &device_ids[1]); - - /* Revision is shared with DEVICE_ID1 */ - revision_id = FIELD_GET(IT66121_REVISION_MASK, device_ids[1]); - device_ids[1] &= IT66121_DEVICE_ID1_MASK; + ret = it66121_read_chip_id(ctx, false); + if (ret) + return ret; - if ((vendor_ids[1] << 8 | vendor_ids[0]) != ctx->info->vid || - (device_ids[1] << 8 | device_ids[0]) != ctx->info->pid) { + if (ctx->vender_id != ctx->info->vid || + ctx->device_id != ctx->info->pid) return -ENODEV; - } ctx->bridge.funcs = &it66121_bridge_funcs; ctx->bridge.of_node = dev->of_node; @@ -1633,7 +1653,8 @@ static int it66121_probe(struct i2c_client *client) drm_bridge_add(&ctx->bridge); - dev_info(dev, "IT66121 revision %d probed\n", revision_id); + dev_info(dev, "IT66121 probed, chip id: 0x%x:0x%x, revision: %u\n", + ctx->vender_id, ctx->device_id, ctx->revision); return 0; } From patchwork Tue Nov 14 15:01:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455490 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 890CDC4167D for ; Tue, 14 Nov 2023 15:09:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 40AE510E430; Tue, 14 Nov 2023 15:09:42 +0000 (UTC) X-Greylist: delayed 453 seconds by postgrey-1.36 at gabe; Tue, 14 Nov 2023 15:09:32 UTC Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by gabe.freedesktop.org (Postfix) with ESMTPS id 39ED310E21E for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tk2pBXgQD0Hn7zpS98T/yj1apxuqc9nh5y9T0ytNhnY=; b=IG+qX9fhNU13FWEzeAZz9CPbGXv4Uly+pxQorlItWtMm/A+Gg8MLaKRo/b7sILbTskuT8o 4kIPnkiw7jtyV9we+sG8iA5WJrI4dONftKCvJ5peYK7Z5SVLke//m+V7D1J4WernaPkb2k vMg9KunawNFPE+bT756aiR/b3oyM738= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 6/8] drm/bridge: it66121: Add a helper to initialize the DRM bridge structure Date: Tue, 14 Nov 2023 23:01:28 +0800 Message-Id: <20231114150130.497915-7-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng Helps the it66121_probe() function to reduce weight, no functional change. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index f36d05331f25..2f7f00f1bedb 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -1004,6 +1004,21 @@ static const struct drm_bridge_funcs it66121_bridge_funcs = { .hpd_disable = it66121_bridge_hpd_disable, }; +static void it66121_bridge_init_base(struct drm_bridge *bridge, + struct device_node *of_node, + bool hpd_support) +{ + bridge->funcs = &it66121_bridge_funcs; + bridge->type = DRM_MODE_CONNECTOR_HDMIA; + bridge->ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID; + if (hpd_support) + bridge->ops |= DRM_BRIDGE_OP_HPD; + + bridge->of_node = of_node; + + drm_bridge_add(bridge); +} + static irqreturn_t it66121_irq_threaded_handler(int irq, void *dev_id) { int ret; @@ -1637,11 +1652,6 @@ static int it66121_probe(struct i2c_client *client) ctx->device_id != ctx->info->pid) return -ENODEV; - ctx->bridge.funcs = &it66121_bridge_funcs; - ctx->bridge.of_node = dev->of_node; - ctx->bridge.type = DRM_MODE_CONNECTOR_HDMIA; - ctx->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_HPD; - ret = devm_request_threaded_irq(dev, client->irq, NULL, it66121_irq_threaded_handler, IRQF_ONESHOT, dev_name(dev), ctx); if (ret < 0) { @@ -1649,9 +1659,9 @@ static int it66121_probe(struct i2c_client *client) return ret; } - it66121_audio_codec_init(ctx, dev); + it66121_bridge_init_base(&ctx->bridge, dev->of_node, true); - drm_bridge_add(&ctx->bridge); + it66121_audio_codec_init(ctx, dev); dev_info(dev, "IT66121 probed, chip id: 0x%x:0x%x, revision: %u\n", ctx->vender_id, ctx->device_id, ctx->revision); From patchwork Tue Nov 14 15:01:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455487 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 A02D3C074FD for ; Tue, 14 Nov 2023 15:09:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F60110E236; Tue, 14 Nov 2023 15:09:38 +0000 (UTC) Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5E0B810E206 for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7fhy2BdhWb4isZ8fdQwycwXhv0lYWLOPVT6/N56SGbY=; b=mmQDOwqK8B5ctogSr2HC/KmzDYYRDtMtPUdLgd4bOhuRUXf+o2wbSvB60vY1wXe4Trwv8N JSoEbBgebPLxXManXcCNGf4wDGVv7+gXTY1y6+0AE0XBKESbyoqG/LRpzFeL2R2Fj4o1hW gJKplKgscixJPf4rRPCLhYQEiKzq2P0= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 7/8] drm/bridge: it66121: Add another implementation for getting match data Date: Tue, 14 Nov 2023 23:01:29 +0800 Message-Id: <20231114150130.497915-8-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng Because if use the i2c_get_match_data() function on our platform, the following error will emerge. [ 3.597872] ACPI: bus type drm_connector registered [ 3.602877] loongson 0000:00:06.1: Found LS7A1000 bridge chipset, revision: 1 [ 3.610013] loongson 0000:00:06.1: [drm] dc: 264MHz, gmc: 529MHz, gpu: 529MHz [ 3.617111] loongson 0000:00:06.1: [drm] Dedicated vram start: 0xe0030000000, size: 64MiB [ 3.633628] loongson 0000:00:06.1: [drm] Loongson VBIOS version: 0.3 [ 3.639944] loongson 0000:00:06.1: [drm] Loongson VBIOS: has 8 DCBs [ 3.646271] Console: switching to colour dummy device 80x25 [ 3.651902] loongson 0000:00:06.1: [drm] VRAM: 4096 pages ready [ 3.657791] loongson 0000:00:06.1: [drm] GTT: 32768 pages ready [ 3.663731] loongson 0000:00:06.1: [drm] lsdc-i2c0(sda pin mask=1, scl pin mask=2) created [ 3.671966] loongson 0000:00:06.1: [drm] lsdc-i2c1(sda pin mask=4, scl pin mask=8) created [ 3.680188] loongson 0000:00:06.1: [drm] DisplayPipe-0 has DVO-0 connector [ 3.711860] debugfs: Directory '1-004c' with parent 'regmap' already present! [ 3.720312] CPU 0 Unable to handle kernel paging request at virtual address 0000000000000090, era == 9000000002faffec, ra == 9000000002faffc8 [ 3.732935] Oops[#1]: [ 3.735187] CPU: 0 PID: 8 Comm: kworker/0:0 Not tainted 6.6.0-rc3+ #941 [ 3.741757] Hardware name: Loongson Loongson-3A5000-7A1000-1w-ML5A/Loongson-LS3A5000-7A1000-1w-ML5A, BIOS vUDK2018-LoongArch-V4.0.05-test-stable202305 06/ [ 3.755500] Workqueue: events work_for_cpu_fn [ 3.759833] pc 9000000002faffec ra 9000000002faffc8 tp 900000010017c000 sp 900000010017fb80 [ 3.768132] a0 0000000000000000 a1 9000000101c00420 a2 0000000000000001 a3 900000010017fbc0 [ 3.776430] a4 0000000000000004 a5 0000000000000000 a6 0000000000000001 a7 0000000000000001 [ 3.784727] t0 0000000000000000 t1 0000000000000001 t2 0000000006124954 t3 0000000000000012 [ 3.793026] t4 0000000000004954 t5 900000000800b530 t6 0000000000000000 t7 0000000000018500 [ 3.801324] t8 90000001019c90c0 u0 9000000101c00c00 s9 fffffffffffff000 s0 9000000101c00400 [ 3.809621] s1 0000000000000000 s2 0000000000000000 s3 9000000003c42cb0 s4 9000000101c00420 [ 3.817920] s5 900000010017fc48 s6 0000000000000000 s7 0000000000000000 s8 90000000037fa000 [ 3.826219] ra: 9000000002faffc8 i2c_get_match_data+0x24/0xac [ 3.832189] ERA: 9000000002faffec i2c_get_match_data+0x48/0xac [ 3.838156] CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE) [ 3.844303] PRMD: 00000004 (PPLV0 +PIE -PWE) [ 3.848631] EUEN: 00000000 (-FPE -SXE -ASXE -BTE) [ 3.853391] ECFG: 00071c1d (LIE=0,2-4,10-12 VS=7) [ 3.858149] ESTAT: 00010000 [PIL] (IS= ECode=1 EsubCode=0) [ 3.863599] BADV: 0000000000000090 [ 3.867058] PRID: 0014c011 (Loongson-64bit, Loongson-3A5000) [ 3.872764] Modules linked in: [ 3.875793] Process kworker/0:0 (pid: 8, threadinfo=(____ptrval____), task=(____ptrval____)) [ 3.884180] Stack : 9000000101c00400 0000000000000000 900000010177f428 9000000002ceb734 [ 3.892137] 9000000101c00404 90000000037fa000 900000010017fc60 9000000101c00400 [ 3.900093] 9000000016124954 8c326e68047d36df 0000004c037fa000 900000010017fc50 [ 3.908050] 0000000000000080 9000000003c44490 900000010017fcb0 90000001003e9ec0 [ 3.916007] 0000000000000001 900000010044f000 900000010017fc60 9000000101c00400 [ 3.923964] 90000000037fa000 9000000002cf05a8 90000001003e8000 900000010017fcb2 [ 3.931920] 000000304c17fc68 0000000000000000 000000000000004c 0000000000000000 [ 3.939877] 4031323136365449 0000000000006334 004c000000000000 0000000000000000 [ 3.947833] 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 3.955790] 0000000000000000 0000000000000000 9000000100449a98 8c326e68047d36df [ 3.963746] ... [ 3.966170] Call Trace: [ 3.966172] [<9000000002faffec>] i2c_get_match_data+0x48/0xac [ 3.974304] [<9000000002ceb734>] it66121_create_bridge+0x15c/0x404 [ 3.980446] [<9000000002cf05a8>] ls7a1000_output_init+0x228/0x248 [ 3.986503] [<9000000002cee494>] lsdc_pci_probe+0x4dc/0x5b0 [ 3.992038] [<9000000002b86b50>] local_pci_probe+0x48/0xa0 [ 3.997487] [<90000000023b5d04>] work_for_cpu_fn+0x1c/0x30 [ 4.002936] [<90000000023b7c0c>] process_one_work+0x14c/0x288 [ 4.008644] [<90000000023b8084>] worker_thread+0x33c/0x438 [ 4.014092] [<90000000023c1ccc>] kthread+0x124/0x130 [ 4.019023] [<9000000002381188>] ret_from_kernel_thread+0xc/0xa4 [ 4.024991] [ 4.026463] Code: 26000079 02c08063 4c000020 <28c24318> 43ffe31f 43ffdeff 2a00030c 43ffd59f 02c012f7 [ 4.036154] [ 4.037630] ---[ end trace 0000000000000000 ]--- Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 51 +++++++++++++++++++--------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 2f7f00f1bedb..8971414a2a60 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -292,8 +292,39 @@ enum chip_id { struct it66121_chip_info { enum chip_id id; u16 vid, pid; + char name[24]; }; +static const struct it66121_chip_info it66121_chip_info[] = { + { + .id = ID_IT66121, + .vid = 0x4954, + .pid = 0x0612, + .name = "IT66121", + }, + { + .id = ID_IT6610, + .vid = 0xca00, + .pid = 0x0611, + .name = "IT6610", + }, +}; + +static const struct it66121_chip_info * +it66121_get_match_data(u16 vender_id, u16 device_id) +{ + const struct it66121_chip_info *info; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(it66121_chip_info); i++) { + info = &it66121_chip_info[i]; + if (info->vid == vender_id && info->pid == device_id) + return info; + } + + return NULL; +} + struct it66121_ctx { struct regmap *regmap; struct drm_bridge bridge; @@ -1677,28 +1708,16 @@ static void it66121_remove(struct i2c_client *client) mutex_destroy(&ctx->lock); } -static const struct it66121_chip_info it66121_chip_info = { - .id = ID_IT66121, - .vid = 0x4954, - .pid = 0x0612, -}; - -static const struct it66121_chip_info it6610_chip_info = { - .id = ID_IT6610, - .vid = 0xca00, - .pid = 0x0611, -}; - static const struct of_device_id it66121_dt_match[] = { - { .compatible = "ite,it66121", &it66121_chip_info }, - { .compatible = "ite,it6610", &it6610_chip_info }, + { .compatible = "ite,it66121", &it66121_chip_info[0] }, + { .compatible = "ite,it6610", &it66121_chip_info[1] }, { } }; MODULE_DEVICE_TABLE(of, it66121_dt_match); static const struct i2c_device_id it66121_id[] = { - { "it66121", (kernel_ulong_t) &it66121_chip_info }, - { "it6610", (kernel_ulong_t) &it6610_chip_info }, + { "it66121", (kernel_ulong_t) &it66121_chip_info[0] }, + { "it6610", (kernel_ulong_t) &it66121_chip_info[1] }, { } }; MODULE_DEVICE_TABLE(i2c, it66121_id); From patchwork Tue Nov 14 15:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13455492 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 CCC4FC4167D for ; Tue, 14 Nov 2023 15:09:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7AFDC10E443; Tue, 14 Nov 2023 15:09:50 +0000 (UTC) Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6329F10E237 for ; Tue, 14 Nov 2023 15:09:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699974151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=un07RUcu2zgWpUGIkjqz4RZwf2xRaP/AV1IDnwLkbiQ=; b=hbWJRAWGsb2GqirQOKQlvdC45YacNeKEi/rBOc4EJTe9WDpiaj6qOwW+Qf4/9hSOJSbGp8 mdMq5IocqxI5teuylhH5gVTr6qB9+xwhTPScfL7rJEmaa7LOzCK+zIEenJ4Uwdsj6jDvlH 8TBlWGDj2kfglMhHbLSBt1wAZnhyj5c= From: Sui Jingfeng To: Phong LE , Neil Armstrong Subject: [PATCH 8/8] drm/bridge: it66121: Allow link this driver as a lib Date: Tue, 14 Nov 2023 23:01:30 +0800 Message-Id: <20231114150130.497915-9-sui.jingfeng@linux.dev> In-Reply-To: <20231114150130.497915-1-sui.jingfeng@linux.dev> References: <20231114150130.497915-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: Maxime Ripard , Sui Jingfeng , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laurent Pinchart , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sui Jingfeng The it66121_create_bridge() and it66121_destroy_bridge() are added to export the core functionalities. Create a connector manually by using bridge connector helpers when link as a lib. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/bridge/ite-it66121.c | 134 +++++++++++++++++++-------- include/drm/bridge/ite-it66121.h | 17 ++++ 2 files changed, 113 insertions(+), 38 deletions(-) create mode 100644 include/drm/bridge/ite-it66121.h diff --git a/drivers/gpu/drm/bridge/ite-it66121.c b/drivers/gpu/drm/bridge/ite-it66121.c index 8971414a2a60..f5968b679c5d 100644 --- a/drivers/gpu/drm/bridge/ite-it66121.c +++ b/drivers/gpu/drm/bridge/ite-it66121.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -703,14 +704,32 @@ static int it66121_bridge_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) { struct it66121_ctx *ctx = bridge_to_it66121(bridge); + struct drm_bridge *next_bridge = ctx->next_bridge; + struct drm_encoder *encoder = bridge->encoder; int ret; - if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) - return -EINVAL; + if (next_bridge) { + if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) { + WARN_ON(1); + flags |= DRM_BRIDGE_ATTACH_NO_CONNECTOR; + } + ret = drm_bridge_attach(encoder, next_bridge, bridge, flags); + if (ret) + return ret; + } else { + struct drm_connector *connector; - ret = drm_bridge_attach(bridge->encoder, ctx->next_bridge, bridge, flags); - if (ret) - return ret; + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) + WARN_ON(1); + + connector = drm_bridge_connector_init(bridge->dev, encoder); + if (IS_ERR(connector)) + return PTR_ERR(connector); + + drm_connector_attach_encoder(connector, encoder); + + ctx->connector = connector; + } if (ctx->info->id == ID_IT66121) { ret = regmap_write_bits(ctx->regmap, IT66121_CLK_BANK_REG, @@ -1632,16 +1651,13 @@ static const char * const it66121_supplies[] = { "vcn33", "vcn18", "vrf12" }; -static int it66121_probe(struct i2c_client *client) +int it66121_create_bridge(struct i2c_client *client, bool of_support, + bool hpd_support, bool audio_support, + struct drm_bridge **bridge) { + struct device *dev = &client->dev; int ret; struct it66121_ctx *ctx; - struct device *dev = &client->dev; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - dev_err(dev, "I2C check functionality failed.\n"); - return -ENXIO; - } ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -1649,24 +1665,19 @@ static int it66121_probe(struct i2c_client *client) ctx->dev = dev; ctx->client = client; - ctx->info = i2c_get_match_data(client); - - ret = it66121_of_read_bus_width(dev, &ctx->bus_width); - if (ret) - return ret; - - ret = it66121_of_get_next_bridge(dev, &ctx->next_bridge); - if (ret) - return ret; - - i2c_set_clientdata(client, ctx); mutex_init(&ctx->lock); - ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(it66121_supplies), - it66121_supplies); - if (ret) { - dev_err(dev, "Failed to enable power supplies\n"); - return ret; + if (of_support) { + ret = it66121_of_read_bus_width(dev, &ctx->bus_width); + if (ret) + return ret; + + ret = it66121_of_get_next_bridge(dev, &ctx->next_bridge); + if (ret) + return ret; + } else { + ctx->bus_width = 24; + ctx->next_bridge = NULL; } it66121_hw_reset(ctx); @@ -1679,33 +1690,80 @@ static int it66121_probe(struct i2c_client *client) if (ret) return ret; - if (ctx->vender_id != ctx->info->vid || - ctx->device_id != ctx->info->pid) + ctx->info = it66121_get_match_data(ctx->vender_id, ctx->device_id); + if (!ctx->info) return -ENODEV; - ret = devm_request_threaded_irq(dev, client->irq, NULL, it66121_irq_threaded_handler, - IRQF_ONESHOT, dev_name(dev), ctx); - if (ret < 0) { - dev_err(dev, "Failed to request irq %d:%d\n", client->irq, ret); - return ret; + if (hpd_support) { + ret = devm_request_threaded_irq(dev, client->irq, NULL, + it66121_irq_threaded_handler, + IRQF_ONESHOT, dev_name(dev), + ctx); + if (ret < 0) { + dev_err(dev, "Failed to request irq: %d\n", ret); + return ret; + } } it66121_bridge_init_base(&ctx->bridge, dev->of_node, true); - it66121_audio_codec_init(ctx, dev); + if (audio_support) + it66121_audio_codec_init(ctx, dev); + + *bridge = &ctx->bridge; dev_info(dev, "IT66121 probed, chip id: 0x%x:0x%x, revision: %u\n", ctx->vender_id, ctx->device_id, ctx->revision); return 0; } +EXPORT_SYMBOL_GPL(it66121_create_bridge); + +static int it66121_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct it66121_ctx *ctx; + struct drm_bridge *bridge; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(dev, "I2C check functionality failed.\n"); + return -ENXIO; + } + + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(it66121_supplies), + it66121_supplies); + if (ret) { + dev_err(dev, "Failed to enable power supplies\n"); + return ret; + } + + ret = it66121_create_bridge(client, true, true, true, &bridge); + if (ret) + return ret; + + ctx = bridge_to_it66121(bridge); + + i2c_set_clientdata(client, ctx); + + return 0; +} + +void it66121_destroy_bridge(struct drm_bridge *bridge) +{ + struct it66121_ctx *ctx = bridge_to_it66121(bridge); + + drm_bridge_remove(bridge); + + mutex_destroy(&ctx->lock); +} +EXPORT_SYMBOL_GPL(it66121_destroy_bridge); static void it66121_remove(struct i2c_client *client) { struct it66121_ctx *ctx = i2c_get_clientdata(client); - drm_bridge_remove(&ctx->bridge); - mutex_destroy(&ctx->lock); + it66121_destroy_bridge(&ctx->bridge); } static const struct of_device_id it66121_dt_match[] = { diff --git a/include/drm/bridge/ite-it66121.h b/include/drm/bridge/ite-it66121.h new file mode 100644 index 000000000000..e6753f695b7f --- /dev/null +++ b/include/drm/bridge/ite-it66121.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ITE_IT66121_H__ +#define __ITE_IT66121_H__ + +#include + +#include +#include + +int it66121_create_bridge(struct i2c_client *client, bool of_support, + bool hpd_support, bool audio_support, + struct drm_bridge **bridge); + +void it66121_destroy_bridge(struct drm_bridge *bridge); + +#endif