From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 AB97A1DA60B for ; Wed, 6 Nov 2024 09:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885652; cv=none; b=ozUBpEp3fEbPhvsLXjIGeTF0Cx/7uVe2dEN3S+Dvsn3IZdA3kZV3mcB1ZlkifvLLo3nXavSlwu3G0+S0tnOpWkIxNG7ra4rslTWQzL/f1zBiMLAutUjWghgjUYlqQ1v19N4lRqtGIHOoeav0V51xRDBiD6d4d9AZi/mBRmoBaeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885652; c=relaxed/simple; bh=Zz2M0sneWoPuGkYkdOhI3CuKEUZZTQY3lZ2/MbU5e84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=raRETTbf2+9h2jIAiCoUhk+tMIYLlj4a+5ugFEiLNMLMvAC4PV7teUBS9lbSJB8fPjcXDDG439WyMc8pTj3YfSKOAE8U/z8ss3wS/hw3/B03/BkTzP2wc6Y7RVFa/5FORdgZf14ltNKCtcpr/c1qzJwxLPYSjM61LImjCb7AfbM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ggpLwaxS; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ggpLwaxS" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20bb39d97d1so62180725ad.2 for ; Wed, 06 Nov 2024 01:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885649; x=1731490449; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=llYngkqgiFGTwpRX3D7wCxxqCsKOgB9wOxApc/ic0J8=; b=ggpLwaxSNqJ6WyfhBTQtUArmNcyxPQaoUBaQScnnuUI+4VF2zsEqIrg1EkE3IMRQ3+ cnyo4ZYbRCgGhvGtbSkKDotw4mQaZ9DZtSLKH19KibZN5V8hI1yVnHATX16yW1NoicHF gxlejT5I9bjdZ7CnaFP3QI85WI4OpkbDJXU04= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885649; x=1731490449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=llYngkqgiFGTwpRX3D7wCxxqCsKOgB9wOxApc/ic0J8=; b=WUQiz2/8347CYYi2um7MROSJgSN6AmqRQne9qBigP9nMdlF7JAn9E7wEEdBp7kVJSs PFFAc5uMylE1/WbSTzNZtzVIj0q9MMMaN3G80oMziBlZWKWEaaCofWHlM/J291ivUQ5G OLx6wnwosAKp3afFveehkNhHtpbwn4W2Tnxb2V8jzweYNRmbw8colYv3Uc9jnxMLKizj VeHS8K8oZ1/+AdGepBVZIOSLgOOcQgrBphKevq00VTNwUrC12UPU/Tiax48DiVPtLtjM ev3rAsrbYR8Hrst/qndSo+HDCI+/Ni+oOAOcoBGefdzHQR/llBdxHXztGH3d3wN97oX1 bHGQ== X-Forwarded-Encrypted: i=1; AJvYcCVFU8Xs+0dtJZq6siFctukZXpuz9X0X4ENnUuWceH7dc7MoO66W95xUtXu9PxAE5RR3cciEtRheCd7EmSQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1R56EQzolEASwOLsyV6UO2X0rnR6kXnv78N1t+E5XpKxgm2zH lBBZMUrWNDSLM3UIE2DE9CTaz5b7NcWExCy1yIBkJ4N8w/oQXMlo+FWRwmqGQA== X-Google-Smtp-Source: AGHT+IHKOHXdDAUgO9QjYpvJtulYfjKvmKS2PsJrrTevb2UOA/ICT/NZEufa/1uemsVqPCJNroTu4g== X-Received: by 2002:a17:903:230d:b0:20b:7731:e3df with SMTP id d9443c01a7336-210f76d6780mr400638435ad.43.1730885649028; Wed, 06 Nov 2024 01:34:09 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:08 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov Subject: [PATCH v11 1/7] of: dynamic: Add of_changeset_update_prop_string Date: Wed, 6 Nov 2024 17:33:28 +0800 Message-ID: <20241106093335.1582205-2-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" Add a helper function to add string property updates to an OF changeset. This is similar to of_changeset_add_prop_string(), but instead of adding the property (and failing if it exists), it will update the property. This shall be used later in the DT hardware prober. Signed-off-by: Chen-Yu Tsai Reviewed-by: Rob Herring (Arm) Reviewed-by: AngeloGioacchino Del Regno --- Changes since v7: none Changes since v6: none Changes since v5: - Collected Rob's tag Changes since v4: - Use modern designated initializer for |prop| Changes since v3: - Use new __of_prop_free() helper - Add new line before header declaration Changes since v2: - New patch added in v3 --- drivers/of/dynamic.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index d45a8df61380..0aba760f7577 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -1072,3 +1072,47 @@ int of_changeset_add_prop_bool(struct of_changeset *= ocs, struct device_node *np, return of_changeset_add_prop_helper(ocs, np, &prop); } EXPORT_SYMBOL_GPL(of_changeset_add_prop_bool); + +static int of_changeset_update_prop_helper(struct of_changeset *ocs, + struct device_node *np, + const struct property *pp) +{ + struct property *new_pp; + int ret; + + new_pp =3D __of_prop_dup(pp, GFP_KERNEL); + if (!new_pp) + return -ENOMEM; + + ret =3D of_changeset_update_property(ocs, np, new_pp); + if (ret) + __of_prop_free(new_pp); + + return ret; +} + +/** + * of_changeset_update_prop_string - Add a string property update to a cha= ngeset + * + * @ocs: changeset pointer + * @np: device node pointer + * @prop_name: name of the property to be updated + * @str: pointer to null terminated string + * + * Create a string property to be updated and add it to a changeset. + * + * Return: 0 on success, a negative error value in case of an error. + */ +int of_changeset_update_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str) +{ + struct property prop =3D { + .name =3D (char *)prop_name, + .length =3D strlen(str) + 1, + .value =3D (void *)str, + }; + + return of_changeset_update_prop_helper(ocs, np, &prop); +} +EXPORT_SYMBOL_GPL(of_changeset_update_prop_string); diff --git a/include/linux/of.h b/include/linux/of.h index 086a60f3b8a6..d0307e3b093d 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1651,6 +1651,10 @@ static inline int of_changeset_add_prop_u32(struct o= f_changeset *ocs, return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1); } =20 +int of_changeset_update_prop_string(struct of_changeset *ocs, + struct device_node *np, + const char *prop_name, const char *str); + int of_changeset_add_prop_bool(struct of_changeset *ocs, struct device_nod= e *np, const char *prop_name); =20 --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 2D7461DB92A for ; Wed, 6 Nov 2024 09:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885654; cv=none; b=eS3GNxD7uMD9oT9KB9IeYSEK14ZsGpCQw+EM0ZKSMmf8WXoIegLz3T3q0N73E8Ktd3MEG64vL3+d/Q0fTSJ68WdOFMREE9Oqc0DLg6IiAV+TrpT9smrAE4/hfypCKAi4ncADk2roKbEW6VLWTTtExtWgCuUVOVz0uczp90sxE9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885654; c=relaxed/simple; bh=F5ArjWom+MQi62Ghn0rbbhm+sqeF3wwa6gc09F6PrqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHo5BTJPTXYiAIwx1fI96IClMRqtZGQSYssU2e42tI1cDdWMlT19eNO9w/Yv+I/moUDaFvAEZWImKzZVl0ZQy2YcVxNhnWTBODoaH1jE66f/0i2oXHnv1Rsz0S4BCzmRGBerMcaskyna22+Oe2cJo+Y3pdSlNd92pZjnsnWLTyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=gtDX+Q/h; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gtDX+Q/h" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20c9978a221so65978245ad.1 for ; Wed, 06 Nov 2024 01:34:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885652; x=1731490452; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tbfB757zoogv3EY5nGOvTyWU1LRL3RJGksVkmiyRShA=; b=gtDX+Q/hoaHvFTRrGSk7/Ep1hTMTrB7P9ZuONBDwYm4n/nCqMn5dlSdAn8vgdBKypt hkzNnnj8XWkAECcl71McltVHCcndnic20ope4+cZap2ETZolM0i5vbG+09/GFk6TjG+A IfAv1FS2FZn2uhlgqXzrZqyqO8pB4cbvo/nas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885652; x=1731490452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tbfB757zoogv3EY5nGOvTyWU1LRL3RJGksVkmiyRShA=; b=e4Smc8uWokPak3cKicArYN8M5Djl4tppFFuROy5ANv3FoudCD3gfrYfy8OE9pxdHp2 HF8MJIsk/nw4g8m/g2CZlVdXr56MR6XthV3NQepA2Coh0QJIKXpwlgHTzrUuPQGNr8gk YgC/LgH2PGqHLeMd4TVRH4gQkVncBKpv+UgyEmtmrzmCgLtDrOKvOlixPt3tOb4/7tEj BpghsQxvXQQyeZv1qixx8+JPZyhPpsTYsH4hqZkyr0W6FrdmQmXspgSOwwnMQf//qceW oFfIZnGW7DP0x4YT/38mlZYpXE+8ueuB0MdRqXmZXrvLXnZNllmFWUzBvdK3VxrnwCIu 6gYQ== X-Forwarded-Encrypted: i=1; AJvYcCUOqv0I845WmXhrFtOQhoKpNOh20Lu7/eZhLNfpqcYDe4gopk0l6L+mrP1erQmggFh+6biLC/cASDPGBs0=@vger.kernel.org X-Gm-Message-State: AOJu0YwFzBTvtJJPscJn2/aFRQk9WmoHXZLFcoFQccyZ/88Ml0+PSvYd gfoFnItc4p1TrEALz+bbysb+f6e1DmrjGdSb2fAJZdSDL03HXDpGr+pu5VJNWw== X-Google-Smtp-Source: AGHT+IGsqJnP2c29fT7ec18QitUEURWR4HKremiykkNa1vQPN87ztDDGEmp/BT6g/9KjaXSGkYd/CA== X-Received: by 2002:a17:903:234c:b0:20c:5b80:930f with SMTP id d9443c01a7336-210c68a9c02mr560445915ad.12.1730885652382; Wed, 06 Nov 2024 01:34:12 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:12 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov Subject: [PATCH v11 2/7] of: base: Add for_each_child_of_node_with_prefix() Date: Wed, 6 Nov 2024 17:33:29 +0800 Message-ID: <20241106093335.1582205-3-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" There are cases where drivers would go through child device nodes and operate on only the ones whose node name starts with a given prefix. Provide a helper for these users. This will mainly be used in a subsequent patch that implements a hardware component prober for I2C busses. Signed-off-by: Chen-Yu Tsai Reviewed-by: Rob Herring (Arm) Reviewed-by: AngeloGioacchino Del Regno --- Changes since v7: - Collected Rob's Reviewed-by Changes since v6: - Changed helper name to "for_each_child_of_node_with_prefix()" Changes since v5: - New patch --- drivers/of/base.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index d94efee4a7fc..a01e5534c2fd 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -628,6 +628,41 @@ struct device_node *of_get_next_child(const struct dev= ice_node *node, } EXPORT_SYMBOL(of_get_next_child); =20 +/** + * of_get_next_child_with_prefix - Find the next child node with prefix + * @node: parent node + * @prev: previous child of the parent node, or NULL to get first + * + * This function is like of_get_next_child(), except that it automatically + * skips any nodes whose name doesn't have the given prefix. + * + * Return: A node pointer with refcount incremented, use + * of_node_put() on it when done. + */ +struct device_node *of_get_next_child_with_prefix(const struct device_node= *node, + struct device_node *prev, + const char *prefix) +{ + struct device_node *next; + unsigned long flags; + + if (!node) + return NULL; + + raw_spin_lock_irqsave(&devtree_lock, flags); + next =3D prev ? prev->sibling : node->child; + for (; next; next =3D next->sibling) { + if (!of_node_name_prefix(next, prefix)) + continue; + if (of_node_get(next)) + break; + } + of_node_put(prev); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + return next; +} +EXPORT_SYMBOL(of_get_next_child_with_prefix); + static struct device_node *of_get_next_status_child(const struct device_no= de *node, struct device_node *prev, bool (*checker)(const struct device_node *)) diff --git a/include/linux/of.h b/include/linux/of.h index d0307e3b093d..f921786cb8ac 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -289,6 +289,9 @@ extern struct device_node *of_get_parent(const struct d= evice_node *node); extern struct device_node *of_get_next_parent(struct device_node *node); extern struct device_node *of_get_next_child(const struct device_node *nod= e, struct device_node *prev); +extern struct device_node *of_get_next_child_with_prefix(const struct devi= ce_node *node, + struct device_node *prev, + const char *prefix); extern struct device_node *of_get_next_available_child( const struct device_node *node, struct device_node *prev); extern struct device_node *of_get_next_reserved_child( @@ -1468,6 +1471,12 @@ static inline int of_property_read_s32(const struct = device_node *np, child !=3D NULL; \ child =3D of_get_next_child(parent, child)) =20 +#define for_each_child_of_node_with_prefix(parent, child, prefix) \ + for (struct device_node *child __free(device_node) =3D \ + of_get_next_child_with_prefix(parent, NULL, prefix); \ + child !=3D NULL; \ + child =3D of_get_next_child_with_prefix(parent, child, prefix)) + #define for_each_available_child_of_node(parent, child) \ for (child =3D of_get_next_available_child(parent, NULL); child !=3D NULL= ; \ child =3D of_get_next_available_child(parent, child)) --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 9F3CD1DD0CB for ; Wed, 6 Nov 2024 09:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885659; cv=none; b=cld3xmuIGWvxjbvb27mqjP2s0uGtLPhBq6qjoXEGOOvltUJ6gIkczPZG1oL0sDX6HukRIRZPvSOT63Q+smJq0pAmcFxJy/p/wgl7zMeeB13CJpRVz7Ut55deYyShzzQFNEgDFhdTWBfgSd3V8QhO9Q5WyCWiiaiv+pL615vpx3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885659; c=relaxed/simple; bh=MlpNPqZyxvOIO88Cn3kn6MjIWWC3fPHQeSMk4UoUJsI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d1dvLyqxkDXneajToAFxmVoJAqckOj0fCsgSJe3Ns5hRQr2+YVL1+g0UDB0NtS4gylsOEJERbXs0c/mV93GZhqJstm3wC5cP4/hbpK/8cAPBUfkDfhCFW/IKd9ZwOJoXyTgzzCTiy1DOjgahE4rMq6HXsSkkzK2EFiffpjyw4qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ZnlcrSLP; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ZnlcrSLP" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20c8b557f91so66444185ad.2 for ; Wed, 06 Nov 2024 01:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885656; x=1731490456; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V9YWNiQV7UfISFGsxrUC0LHYRXl1oT91DPRmgjYHPeU=; b=ZnlcrSLPMWTqylCL2pIvKvHAGYaek9LocC4qO895fKut/je2U+qrLtj0v3x2ZKBKUJ XNpQndYdC5/okeqwT2chOZo/px4ISADK/yXqPzDKDKQ7USa11qX08B8bJAIEQ0BG49ll 6Ucb0bmy40UxR37MMlBtmay/POwwFsHv/oGKE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885656; x=1731490456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V9YWNiQV7UfISFGsxrUC0LHYRXl1oT91DPRmgjYHPeU=; b=hpz4IOXu2Uhwv+ZknIxh+YIgM56cfKOxISQ9N0pPT3BtvGGGcPBP214DW3uOisqZcB Blmk1ks9xpbybc7w6jKI3rr6Bi0lyBNxvPMM3/zIFKXQA182RDUAoMufvWNwMFMpTSo/ E1ejgU1+rKnq0yKGxmFr1VpbmLaTvam4vIuUI+ADKZBDdot+pxYPXWrV1qtDQBcIj2gf OHMonQBjhy8q1MVq2+QN3QujfH9sAsRruulcN629pxw489A+TlVCeIzs7ju4UVdGdPHu 5OMgR7G+k8v6xk6sLhob5lighFtzNPi1KXGuv3eQT1wLrVtlvrqbpAVMb7dVVLQveBPV qCgg== X-Forwarded-Encrypted: i=1; AJvYcCWcrZ9qGiABGSurrQQNBP4yfbMdxnF/HdmysTLcI8M7TXxYYSmsN+7DgbVd5y9muwOQw54JkBqZQKrKnus=@vger.kernel.org X-Gm-Message-State: AOJu0YyuALSXdVKENE/kZdYtd27h3eZ2eAudLeKybqPq18i/6dviY+Ne g3mq/h979KLBZbU3FKJyjqLYTeoml7lXgkziyk+b+UNDiz5zCI58RvvPB8Inbw== X-Google-Smtp-Source: AGHT+IGQaXlmVG56isfbKv5AqNR1DW/b1sfVXBLwutv0E9qOpoDIMAjzf/Z507RZQ99puv+tK8kijA== X-Received: by 2002:a17:902:dacb:b0:207:3a53:fe67 with SMTP id d9443c01a7336-210c6c0f5f2mr574697625ad.32.1730885655826; Wed, 06 Nov 2024 01:34:15 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:15 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov Subject: [PATCH v11 3/7] i2c: Introduce OF component probe function Date: Wed, 6 Nov 2024 17:33:30 +0800 Message-ID: <20241106093335.1582205-4-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" Some devices are designed and manufactured with some components having multiple drop-in replacement options. These components are often connected to the mainboard via ribbon cables, having the same signals and pin assignments across all options. These may include the display panel and touchscreen on laptops and tablets, and the trackpad on laptops. Sometimes which component option is used in a particular device can be detected by some firmware provided identifier, other times that information is not available, and the kernel has to try to probe each device. This change attempts to make the "probe each device" case cleaner. The current approach is to have all options added and enabled in the device tree. The kernel would then bind each device and run each driver's probe function. This works, but has been broken before due to the introduction of asynchronous probing, causing multiple instances requesting "shared" resources, such as pinmuxes, GPIO pins, interrupt lines, at the same time, with only one instance succeeding. Work arounds for these include moving the pinmux to the parent I2C controller, using GPIO hogs or pinmux settings to keep the GPIO pins in some fixed configuration, and requesting the interrupt line very late. Such configurations can be seen on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based Lenovo Thinkpad 13S. Instead of this delicate dance between drivers and device tree quirks, this change introduces a simple I2C component probe function. For a given class of devices on the same I2C bus, it will go through all of them, doing a simple I2C read transfer and see which one of them responds. It will then enable the device that responds. This requires some minor modifications in the existing device tree. The status for all the device nodes for the component options must be set to "fail-needs-probe". This makes it clear that some mechanism is needed to enable one of them, and also prevents the prober and device drivers running at the same time. Signed-off-by: Chen-Yu Tsai Reviewed-by: Andy Shevchenko Reviewed-by: Douglas Anderson Reviewed-by: AngeloGioacchino Del Regno --- Changes since v9: - Picked up review-bys - Added inclusion of stddef.h for NULL Changes since v8: - Added missing include of to i2c-of-prober.h - Expanded description of i2c_of_probe_ops::enable to mention that returning -EPROBE_DEFER is valid (Doug) - Reworded descrption of i2c_of_probe_ops::cleanup_early to avoid confusion with i2c_of_probe_ops::enable (Doug) - Reworked i2c_of_probe_get_i2c_node() to return NULL on failure, matching most functions that return |struct device_node *|. Changes since v7: - Dropped log level of "enabling component" to debug - Dropped file name from header file - Reverted to __free() cleanup for i2c bus node - Corrected "failed-needs-probe" to "fail-needs-probe" in commit message - Fixed incorrectly positioned period ('.') in commit message - Expanded description of i2c_of_probe_component() - Expanded comment explaining check for "available" devices to note that if such a device is found then the i2c probe function becomes a no-op - Simplified check for "available" devices for-each loop - Expanded description of @free_resources_early callback to explicitly state that it is not called if no working components are found - Dropped !cfg check - Replaced "fail" with "fail-needs-probe" in i2c_of_probe_component() kernel doc - Combined callbacks (.get_resources with .enable; .cleanup with .free_resources_late); .free_resources_early renamed to .cleanup_early Changes since v6: - Correctly replaced for_each_child_of_node_scoped() with for_each_child_of_node_with_prefix() - Added namespace for exported symbol - Made the probe function a framework with hooks - Split out a new header file - Added MAINTAINERS entry - Reworded kernel-doc - Dropped usage of __free from i2c_of_probe_component() since error path cleanup is needed anyway Changes since v5: - Fixed indent in Makefile - Split regulator and GPIO TODO items - Reversed final conditional in i2c_of_probe_enable_node() Changes since v4: - Split code into helper functions - Use scoped helpers and __free() to reduce error path Changes since v3: - Complete kernel-doc - Return different error if I2C controller is disabled - Expand comment to explain assumptions and constraints - Split for-loop finding target node and operations on target node - Add missing i2c_put_adapter() - Move prober code to separate file Rob also asked why there was a limitation of "exactly one touchscreen will be enabled across the whole tree". The use case this prober currently targets is a component on consumer electronics (tablet or laptop) being swapped out due to cost or supply reasons. Designs with multiple components of the same type are pretty rare. The way the next patch is written also assumes this for efficiency reasons. Changes since v2: - New patch split out from "of: Introduce hardware prober driver" - Addressed Rob's comments - Move i2c prober to i2c subsystem - Use of_node_is_available() to check if node is enabled. - Use OF changeset API to update status property - Addressed Andy's comments - Probe function now accepts "struct device *dev" instead to reduce line length and dereferences - Move "ret =3D 0" to just before for_each_child_of_node(i2c_node, node) --- MAINTAINERS | 8 ++ drivers/i2c/Makefile | 1 + drivers/i2c/i2c-core-of-prober.c | 183 +++++++++++++++++++++++++++++++ include/linux/i2c-of-prober.h | 75 +++++++++++++ 4 files changed, 267 insertions(+) create mode 100644 drivers/i2c/i2c-core-of-prober.c create mode 100644 include/linux/i2c-of-prober.h diff --git a/MAINTAINERS b/MAINTAINERS index f595ee8c2d14..3edf77f920fd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10739,6 +10739,14 @@ S: Maintained F: Documentation/devicetree/bindings/i2c/marvell,mv64xxx-i2c.yaml F: drivers/i2c/busses/i2c-mv64xxx.c =20 +I2C OF COMPONENT PROBER +M: Chen-Yu Tsai +L: linux-i2c@vger.kernel.org +L: devicetree@vger.kernel.org +S: Maintained +F: drivers/i2c/i2c-core-of-prober.c +F: include/linux-i2c-of-prober.h + I2C OVER PARALLEL PORT M: Jean Delvare L: linux-i2c@vger.kernel.org diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index af95d6e7f004..d27de18de46f 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -9,6 +9,7 @@ i2c-core-y :=3D i2c-core-base.o i2c-core-smbus.o i2c-core-$(CONFIG_ACPI) +=3D i2c-core-acpi.o i2c-core-$(CONFIG_I2C_SLAVE) +=3D i2c-core-slave.o i2c-core-$(CONFIG_OF) +=3D i2c-core-of.o +i2c-core-$(CONFIG_OF_DYNAMIC) +=3D i2c-core-of-prober.o =20 obj-$(CONFIG_I2C_SMBUS) +=3D i2c-smbus.o obj-$(CONFIG_I2C_CHARDEV) +=3D i2c-dev.o diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-pro= ber.c new file mode 100644 index 000000000000..21f7a4769293 --- /dev/null +++ b/drivers/i2c/i2c-core-of-prober.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Linux I2C core OF component prober code + * + * Copyright (C) 2024 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Some devices, such as Google Hana Chromebooks, are produced by multiple + * vendors each using their preferred components. Such components are all + * in the device tree. Instead of having all of them enabled and having ea= ch + * driver separately try and probe its device while fighting over shared + * resources, they can be marked as "fail-needs-probe" and have a prober + * figure out which one is actually used beforehand. + * + * This prober assumes such drop-in parts are on the same I2C bus, have + * non-conflicting addresses, and can be directly probed by seeing which + * address responds. + * + * TODO: + * - Support handling common regulators. + * - Support handling common GPIOs. + * - Support I2C muxes + */ + +static struct device_node *i2c_of_probe_get_i2c_node(struct device *dev, c= onst char *type) +{ + struct device_node *node __free(device_node) =3D of_find_node_by_name(NUL= L, type); + if (!node) { + dev_err(dev, "Could not find %s device node\n", type); + return NULL; + } + + struct device_node *i2c_node __free(device_node) =3D of_get_parent(node); + if (!of_node_name_eq(i2c_node, "i2c")) { + dev_err(dev, "%s device isn't on I2C bus\n", type); + return NULL; + } + + if (!of_device_is_available(i2c_node)) { + dev_err(dev, "I2C controller not available\n"); + return NULL; + } + + return no_free_ptr(i2c_node); +} + +static int i2c_of_probe_enable_node(struct device *dev, struct device_node= *node) +{ + int ret; + + dev_dbg(dev, "Enabling %pOF\n", node); + + struct of_changeset *ocs __free(kfree) =3D kzalloc(sizeof(*ocs), GFP_KERN= EL); + if (!ocs) + return -ENOMEM; + + of_changeset_init(ocs); + ret =3D of_changeset_update_prop_string(ocs, node, "status", "okay"); + if (ret) + return ret; + + ret =3D of_changeset_apply(ocs); + if (ret) { + /* ocs needs to be explicitly cleaned up before being freed. */ + of_changeset_destroy(ocs); + } else { + /* + * ocs is intentionally kept around as it needs to + * exist as long as the change is applied. + */ + void *ptr __always_unused =3D no_free_ptr(ocs); + } + + return ret; +} + +static const struct i2c_of_probe_ops i2c_of_probe_dummy_ops; + +/** + * i2c_of_probe_component() - probe for devices of "type" on the same i2c = bus + * @dev: Pointer to the &struct device of the caller, only used for dev_pr= intk() messages. + * @cfg: Pointer to the &struct i2c_of_probe_cfg containing callbacks and = other options + * for the prober. + * @ctx: Context data for callbacks. + * + * Probe for possible I2C components of the same "type" (&i2c_of_probe_cfg= ->type) + * on the same I2C bus that have their status marked as "fail-needs-probe". + * + * Assumes that across the entire device tree the only instances of nodes + * with "type" prefixed node names (not including the address portion) are + * the ones that need handling for second source components. In other word= s, + * if "type" is "touchscreen", then all device nodes named "touchscreen*" + * are the ones that need probing. There cannot be another "touchscreen*" + * node that is already enabled. + * + * Assumes that for each "type" of component, only one actually exists. In + * other words, only one matching and existing device will be enabled. + * + * Context: Process context only. Does non-atomic I2C transfers. + * Should only be used from a driver probe function, as the funct= ion + * can return -EPROBE_DEFER if the I2C adapter or other resources + * are unavailable. + * Return: 0 on success or no-op, error code otherwise. + * A no-op can happen when it seems like the device tree already + * has components of the type to be probed already enabled. This + * can happen when the device tree had not been updated to mark + * the status of the to-be-probed components as "fail-needs-probe". + * Or this function was already run with the same parameters and + * succeeded in enabling a component. The latter could happen if + * the user had multiple types of components to probe, and one of + * them down the list caused a deferred probe. This is expected + * behavior. + */ +int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_c= fg *cfg, void *ctx) +{ + const struct i2c_of_probe_ops *ops; + const char *type; + struct i2c_adapter *i2c; + int ret; + + ops =3D cfg->ops ?: &i2c_of_probe_dummy_ops; + type =3D cfg->type; + + struct device_node *i2c_node __free(device_node) =3D i2c_of_probe_get_i2c= _node(dev, type); + if (!i2c_node) + return -ENODEV; + + /* + * If any devices of the given "type" are already enabled then this funct= ion is a no-op. + * Either the device tree hasn't been modified to work with this probe fu= nction, or the + * function had already run before and enabled some component. + */ + for_each_child_of_node_with_prefix(i2c_node, node, type) + if (of_device_is_available(node)) + return 0; + + i2c =3D of_get_i2c_adapter_by_node(i2c_node); + if (!i2c) + return dev_err_probe(dev, -EPROBE_DEFER, "Couldn't get I2C adapter\n"); + + /* Grab and enable resources */ + ret =3D 0; + if (ops->enable) + ret =3D ops->enable(dev, i2c_node, ctx); + if (ret) + goto out_put_i2c_adapter; + + for_each_child_of_node_with_prefix(i2c_node, node, type) { + union i2c_smbus_data data; + u32 addr; + + if (of_property_read_u32(node, "reg", &addr)) + continue; + if (i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dat= a) < 0) + continue; + + /* Found a device that is responding */ + if (ops->cleanup_early) + ops->cleanup_early(dev, ctx); + ret =3D i2c_of_probe_enable_node(dev, node); + break; + } + + if (ops->cleanup) + ops->cleanup(dev, ctx); +out_put_i2c_adapter: + i2c_put_adapter(i2c); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_component, I2C_OF_PROBER); diff --git a/include/linux/i2c-of-prober.h b/include/linux/i2c-of-prober.h new file mode 100644 index 000000000000..e7e052ac9e48 --- /dev/null +++ b/include/linux/i2c-of-prober.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Definitions for the Linux I2C OF component prober + * + * Copyright (C) 2024 Google LLC + */ + +#ifndef _LINUX_I2C_OF_PROBER_H +#define _LINUX_I2C_OF_PROBER_H + +#include + +struct device; +struct device_node; + +/** + * struct i2c_of_probe_ops - I2C OF component prober callbacks + * + * A set of callbacks to be used by i2c_of_probe_component(). + * + * All callbacks are optional. Callbacks are called only once per run, and= are + * used in the order they are defined in this structure. + * + * All callbacks that have return values shall return %0 on success, + * or a negative error number on failure. + * + * The @dev parameter passed to the callbacks is the same as @dev passed to + * i2c_of_probe_component(). It should only be used for dev_printk() calls + * and nothing else, especially not managed device resource (devres) APIs. + */ +struct i2c_of_probe_ops { + /** + * @enable: Retrieve and enable resources so that the components respond = to probes. + * + * It is OK for this callback to return -EPROBE_DEFER since the intended = use includes + * retrieving resources and enables them. Resources should be reverted to= their initial + * state and released before returning if this fails. + */ + int (*enable)(struct device *dev, struct device_node *bus_node, void *dat= a); + + /** + * @cleanup_early: Release exclusive resources prior to calling probe() o= n a + * detected component. + * + * Only called if a matching component is actually found. If none are fou= nd, + * resources that would have been released in this callback should be rel= eased in + * @free_resourcs_late instead. + */ + void (*cleanup_early)(struct device *dev, void *data); + + /** + * @cleanup: Opposite of @enable to balance refcounts and free resources = after probing. + * + * Should check if resources were already freed by @cleanup_early. + */ + void (*cleanup)(struct device *dev, void *data); +}; + +/** + * struct i2c_of_probe_cfg - I2C OF component prober configuration + * @ops: Callbacks for the prober to use. + * @type: A string to match the device node name prefix to probe for. + */ +struct i2c_of_probe_cfg { + const struct i2c_of_probe_ops *ops; + const char *type; +}; + +#if IS_ENABLED(CONFIG_OF_DYNAMIC) + +int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_c= fg *cfg, void *ctx); + +#endif /* IS_ENABLED(CONFIG_OF_DYNAMIC) */ + +#endif /* _LINUX_I2C_OF_PROBER_H */ --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 D2BAA1DD0FE for ; Wed, 6 Nov 2024 09:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885662; cv=none; b=f61oI6ljv7oXNIIvXrXdY3SvhtZxM+4ys0i+DEnkEliDUB+70E99vSpKcyWsOVVYA/luv1PBB4e5kUPFrnPvKOvvvcxFVEF0oDDizGsJGIek+q8LumHsLkY4u91/6gT15MQgnTmA+1KoJsJIYByngExlSIB9k+ARht8qW78qsE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885662; c=relaxed/simple; bh=i7tB2LF9Va8QhzXWbLe5vhJbCYE/IUIrHJ7AVTFvlAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZQDLDvl9iF4KvTI/OzJhw2cn5/VrXrj3QGZvWmHUGbkPb9WtzodxPZF3d775Qi6ryu7cp2ddTUbdy6xrGYZ/ow+huyQ7U8oywTqwsbkPEaoJQOLK261CpCrlza34levLlRwlR0G+R1X9wz53ZVSC57lbv98izWhK1U02oUe/kdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=IF97lHj3; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IF97lHj3" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20cdbe608b3so64570035ad.1 for ; Wed, 06 Nov 2024 01:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885659; x=1731490459; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1ZQCxJwfexAjnJDSPigCQy78WL7sgzBAoIFw8zKeVQo=; b=IF97lHj3ZrAytBzYiFgmervHfRoF6LL4wLXLEWjRH9CTAQOt00l8+Fbv40A7Fo7hG7 /rCni39D43I0wO7eu7KiB0LeCV08G/TQQm0JC6aNUq+Rxjyc/CyfqIeQ+itzMePZCx1e /+SIFw2cwKeZk/HgKV2o/h7nRntLcwHNWnZcM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885659; x=1731490459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1ZQCxJwfexAjnJDSPigCQy78WL7sgzBAoIFw8zKeVQo=; b=kD+4HeQI0KfDWtoiSlbcqWDHtUsF4E5M/Mrr9yV/XyA3n75GpuqsV8n+jRk9t5nRYq 3N+L01OCDvn1/p5MoJVN0Sl2nUh2uwN6nsAtrWSkf2CnkTqJJHC7eCpF87JdU1lNShJE m32FoXQAOSdTvss7rb9ymQQvFxuc6KkZwsAtErUseUf+H2xjpnLaZwT9VU8LJOnRWwqV n4uyWMRlcvaHsc8I3kKicm95znIUZs6Qlaw00h6GAas7RPWfN61/gr8SX2jWW6WQdZCE 07Md1SSFD+Q8xLfUfDsyov2ilhyiYAweVML4n2WV38M0oVGhO0qC2gdnZA0aXrHYG3Tj nyQg== X-Forwarded-Encrypted: i=1; AJvYcCUV9ty6mQR591obM/zR0n/OMOHQJwr1vs5QbtAVZU93o+uIGJ1kTa1WlZSOoRmlmWH/r5F4hVdwO0xkLfU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyqv09Vu+Rqa8yOHawFqduNEg4BEDCjXnobv5Mc/y09Filc4Tai Rncfyd19xMB1YYlGArlC4H+L/TKeDB6ExTLJNCow90kVPw4Yjp4EId91AJ16zA== X-Google-Smtp-Source: AGHT+IEClACp1l7bIsTYEVdHiEtgpnPWujmbCJ8LMiaczL1P3ezxA2tzFOv4EeTcreC147LMJ38KLA== X-Received: by 2002:a17:902:f684:b0:20c:cd14:a7f3 with SMTP id d9443c01a7336-210f7523562mr382589885ad.22.1730885659184; Wed, 06 Nov 2024 01:34:19 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:18 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov Subject: [PATCH v11 4/7] i2c: of-prober: Add simple helpers for regulator support Date: Wed, 6 Nov 2024 17:33:31 +0800 Message-ID: <20241106093335.1582205-5-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" Add helpers to do regulator management for the I2C OF component prober. Components that the prober intends to probe likely require their regulator supplies be enabled, and GPIOs be toggled to enable them or bring them out of reset before they will respond to probe attempts. GPIOs will be handled in the next patch. The assumption is that the same class of components to be probed are always connected in the same fashion with the same regulator supply and GPIO. The names may vary due to binding differences, but the physical layout does not change. This set of helpers supports at most one regulator supply. The user must specify the node from which the supply is retrieved. The supply name and the amount of time to wait after the supply is enabled are also given by the user. Signed-off-by: Chen-Yu Tsai Reviewed-by: Douglas Anderson Reviewed-by: Andy Shevchenko Reviewed-by: AngeloGioacchino Del Regno --- Changes since v9: - Picked up Andy's reviewed-by Changes since v8: - Picked up Doug's reviewed-by Changes since v7: - Reworded comment in i2c_of_probe_simple_get_supply() as suggested (Andy) - Dropped mention of time unit in struct i2c_of_probe_simple_opts kernel doc (Andy) - Added mention of common GPIO line usages ("enable" or "reset") in I2C OF component prober kernel doc (Doug) - Added check for non-zero delay before msleep() (Doug) - Combined callback helpers (.get_resources with .enable; .cleanup with .free_resources_late) Changes since v6: - Moved change of of_get_next_child_scoped() to of_get_next_child_with_prefix() to previous patch - Restructured into helpers for the I2C OF component prober - Reduced to only handle one regulator - Commit message updated Changes since v5: - Split of_regulator_bulk_get_all() return value check and explain "ret =3D=3D 0" case - Switched to of_get_next_child_with_prefix_scoped() where applicable - Used krealloc_array() instead of directly calculating size - copy whole regulator array in one memcpy() call - Drop "0" from struct zeroing initializer - Split out regulator helper from i2c_of_probe_enable_res() to keep code cleaner when combined with the next patch - Added options for customizing power sequencing delay - Rename i2c_of_probe_get_regulator() to i2c_of_probe_get_regulators() - Add i2c_of_probe_free_regulator() helper Changes since v4: - Split out GPIO handling to separate patch - Rewrote using of_regulator_bulk_get_all() - Replaced "regulators" with "regulator supplies" in debug messages Changes since v3: - New patch --- drivers/i2c/i2c-core-of-prober.c | 138 ++++++++++++++++++++++++++++++- include/linux/i2c-of-prober.h | 44 ++++++++++ 2 files changed, 181 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-pro= ber.c index 21f7a4769293..76df75c51cae 100644 --- a/drivers/i2c/i2c-core-of-prober.c +++ b/drivers/i2c/i2c-core-of-prober.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include #include =20 @@ -29,7 +31,6 @@ * address responds. * * TODO: - * - Support handling common regulators. * - Support handling common GPIOs. * - Support I2C muxes */ @@ -181,3 +182,138 @@ int i2c_of_probe_component(struct device *dev, const = struct i2c_of_probe_cfg *cf return ret; } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_component, I2C_OF_PROBER); + +static int i2c_of_probe_simple_get_supply(struct device *dev, struct devic= e_node *node, + struct i2c_of_probe_simple_ctx *ctx) +{ + const char *supply_name; + struct regulator *supply; + + /* + * It's entirely possible for the component's device node to not have the + * regulator supplies. While it does not make sense from a hardware persp= ective, + * the supplies could be always on or otherwise not modeled in the device= tree, + * but the device would still work. + */ + supply_name =3D ctx->opts->supply_name; + if (!supply_name) + return 0; + + supply =3D of_regulator_get_optional(dev, node, supply_name); + if (IS_ERR(supply)) { + return dev_err_probe(dev, PTR_ERR(supply), + "Failed to get regulator supply \"%s\" from %pOF\n", + supply_name, node); + } + + ctx->supply =3D supply; + + return 0; +} + +static void i2c_of_probe_simple_put_supply(struct i2c_of_probe_simple_ctx = *ctx) +{ + regulator_put(ctx->supply); + ctx->supply =3D NULL; +} + +static int i2c_of_probe_simple_enable_regulator(struct device *dev, struct= i2c_of_probe_simple_ctx *ctx) +{ + int ret; + + if (!ctx->supply) + return 0; + + dev_dbg(dev, "Enabling regulator supply \"%s\"\n", ctx->opts->supply_name= ); + + ret =3D regulator_enable(ctx->supply); + if (ret) + return ret; + + if (ctx->opts->post_power_on_delay_ms) + msleep(ctx->opts->post_power_on_delay_ms); + + return 0; +} + +static void i2c_of_probe_simple_disable_regulator(struct device *dev, stru= ct i2c_of_probe_simple_ctx *ctx) +{ + if (!ctx->supply) + return; + + dev_dbg(dev, "Disabling regulator supply \"%s\"\n", ctx->opts->supply_nam= e); + + regulator_disable(ctx->supply); +} + +/** + * i2c_of_probe_simple_enable - Simple helper for I2C OF prober to get and= enable resources + * @dev: Pointer to the &struct device of the caller, only used for dev_pr= intk() messages + * @bus_node: Pointer to the &struct device_node of the I2C adapter. + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * If &i2c_of_probe_simple_opts->supply_name is given, request the named r= egulator supply. + * If a regulator supply was found, enable that regulator. + * + * Return: %0 on success or no-op, or a negative error number on failure. + */ +int i2c_of_probe_simple_enable(struct device *dev, struct device_node *bus= _node, void *data) +{ + struct i2c_of_probe_simple_ctx *ctx =3D data; + struct device_node *node; + const char *compat; + int ret; + + dev_dbg(dev, "Requesting resources for components under I2C bus %pOF\n", = bus_node); + + if (!ctx || !ctx->opts) + return -EINVAL; + + compat =3D ctx->opts->res_node_compatible; + if (!compat) + return -EINVAL; + + node =3D of_get_compatible_child(bus_node, compat); + if (!node) + return dev_err_probe(dev, -ENODEV, "No device compatible with \"%s\" fou= nd\n", + compat); + + ret =3D i2c_of_probe_simple_get_supply(dev, node, ctx); + if (ret) + goto out_put_node; + + ret =3D i2c_of_probe_simple_enable_regulator(dev, ctx); + if (ret) + goto out_put_supply; + + return 0; + +out_put_supply: + i2c_of_probe_simple_put_supply(ctx); +out_put_node: + of_node_put(node); + return ret; +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_enable, I2C_OF_PROBER); + +/** + * i2c_of_probe_simple_cleanup - Clean up and release resources for I2C OF= prober simple helpers + * @dev: Pointer to the &struct device of the caller, only used for dev_pr= intk() messages + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * * If a regulator supply was found, disable that regulator and release i= t. + */ +void i2c_of_probe_simple_cleanup(struct device *dev, void *data) +{ + struct i2c_of_probe_simple_ctx *ctx =3D data; + + i2c_of_probe_simple_disable_regulator(dev, ctx); + i2c_of_probe_simple_put_supply(ctx); +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_cleanup, I2C_OF_PROBER); + +struct i2c_of_probe_ops i2c_of_probe_simple_ops =3D { + .enable =3D i2c_of_probe_simple_enable, + .cleanup =3D i2c_of_probe_simple_cleanup, +}; +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_ops, I2C_OF_PROBER); diff --git a/include/linux/i2c-of-prober.h b/include/linux/i2c-of-prober.h index e7e052ac9e48..df95aa6ad90e 100644 --- a/include/linux/i2c-of-prober.h +++ b/include/linux/i2c-of-prober.h @@ -70,6 +70,50 @@ struct i2c_of_probe_cfg { =20 int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_c= fg *cfg, void *ctx); =20 +/** + * DOC: I2C OF component prober simple helpers + * + * Components such as trackpads are commonly connected to a devices basebo= ard + * with a 6-pin ribbon cable. That gives at most one voltage supply and one + * GPIO (commonly a "enable" or "reset" line) besides the I2C bus, interru= pt + * pin, and common ground. Touchscreens, while integrated into the display + * panel's connection, typically have the same set of connections. + * + * A simple set of helpers are provided here for use with the I2C OF compo= nent + * prober. This implementation targets such components, allowing for at mo= st + * one regulator supply. + * + * The following helpers are provided: + * * i2c_of_probe_simple_enable() + * * i2c_of_probe_simple_cleanup() + */ + +/** + * struct i2c_of_probe_simple_opts - Options for simple I2C component prob= er callbacks + * @res_node_compatible: Compatible string of device node to retrieve reso= urces from. + * @supply_name: Name of regulator supply. + * @post_power_on_delay_ms: Delay after regulators are powered on. Passed = to msleep(). + */ +struct i2c_of_probe_simple_opts { + const char *res_node_compatible; + const char *supply_name; + unsigned int post_power_on_delay_ms; +}; + +struct regulator; + +struct i2c_of_probe_simple_ctx { + /* public: provided by user before helpers are used. */ + const struct i2c_of_probe_simple_opts *opts; + /* private: internal fields for helpers. */ + struct regulator *supply; +}; + +int i2c_of_probe_simple_enable(struct device *dev, struct device_node *bus= _node, void *data); +void i2c_of_probe_simple_cleanup(struct device *dev, void *data); + +extern struct i2c_of_probe_ops i2c_of_probe_simple_ops; + #endif /* IS_ENABLED(CONFIG_OF_DYNAMIC) */ =20 #endif /* _LINUX_I2C_OF_PROBER_H */ --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 5BD5B1DD862 for ; Wed, 6 Nov 2024 09:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885665; cv=none; b=EYzDYlUOAPp/SgTJbJbFdIqGaVc+oqdOyPaxxIi21u5c07xqHDZj9yKElaUz7VOFBTDMVCVHzl6FLOTYyWSex1bxTGfix4TkrYtDQuesg2Ny6Rlp8wUcYp3gHHDTh1cJzyhpVD97BWp0Te2qeIK814cG+fD00dIg77y//0dwn6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885665; c=relaxed/simple; bh=tBlW6JhLTkyVljLWcXlC4Co0tDocmTG5vfxk3tmF+1M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UuZO3bb9cLJbWdjCSGOjv6q+cKhyAHMUDcKxYMUJV8xbk0G7ySi0/7VYfivuezGamfj9VzBMYpb8PLXHvKk9V/919Vl1ipVrH2/k0Upr4U3EwuM6LGkpcO0fAeL577f1Q3ZHvl9ekHcyFkd7Oly3YG0kEcB1/e+tPzL9QR4QmJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SBFfDkuo; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SBFfDkuo" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20c9978a221so65979745ad.1 for ; Wed, 06 Nov 2024 01:34:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885663; x=1731490463; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BGOV0059hbfeaZFhU219abBt+9+XtBAkRTCfbtRWJD8=; b=SBFfDkuo1z56PEXac03FSbEDCddrTP662xBMaIMelQG0KZvRj+L3iBl3zbY1F6UelA eVZUI7mzXTcMQTObiAi/IHBXvLfyDEeP5vls0F19OMaq4byo97ZhEadjo+NigGUah3OG im96HpvBqIFyGtfAOgwcHJmMavLaqiNpFxUzI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885663; x=1731490463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BGOV0059hbfeaZFhU219abBt+9+XtBAkRTCfbtRWJD8=; b=Gs9q0jtzNyAPUSiz30/dcks8P/5192pE34lsHv/i9I71BvdKiJh8vmU0unUg/Pk+e5 WWM0hVCObCt6nMZzV+ECIf1EV7EeVaaFx+rvI81//M3HO2O11/flp22mmc8HYknU64KW BcAR02OltiOOKUB40v7b+jqRoBY0M9wlPQYNQnyA7fJywKq0A3d7AdMHvO5pYQSLSsz2 uYMu8vuIseIFmvDgLvKif0poxMNOOKmwnFuxe+S2JFafQXiniRzgZXizLcndI1kssMdJ qNzjso5QOeTuOTdp52HMn2uV98In1yn6YAkzXFSJ3IVn6nT4HcthUNEeqaoJf+Sd0oVE 7JQw== X-Forwarded-Encrypted: i=1; AJvYcCUlhDDzwJNHkQQDwEdSO6yqeJjmYn2barW1Xz7nDcROFC8s+xZsdUXigcMIHtQyQmX+B1xNwLFkZ0xQcgs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+WE8MtjfTz3k3Qj0Kr40TrF8yrtTsjvVBeHPsWt+AkIIA/uI+ +pl28FI7IUvfRA+KylQxz+eIk+6t/triNftoR50Ur0bRAwhs1Ta7RH0Pv4Rvvg== X-Google-Smtp-Source: AGHT+IFl9b3g6u4y1B0yH1Dk8Xw9Rm7sTCp3VXmKhlnqKRu3HlwTX6AK1ZHYsqk7u/dW4Fbgz4pB/w== X-Received: by 2002:a17:903:2bce:b0:20b:9e14:c138 with SMTP id d9443c01a7336-210c6ae4f07mr563185255ad.23.1730885662615; Wed, 06 Nov 2024 01:34:22 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:22 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov Subject: [PATCH v11 5/7] i2c: of-prober: Add GPIO support to simple helpers Date: Wed, 6 Nov 2024 17:33:32 +0800 Message-ID: <20241106093335.1582205-6-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" Add GPIO support to the simple helpers for the I2C OF component prober. Components that the prober intends to probe likely require their regulator supplies be enabled, and GPIOs be toggled to enable them or bring them out of reset before they will respond to probe attempts. Regulator supplies were handled in the previous patch. The assumption is that the same class of components to be probed are always connected in the same fashion with the same regulator supply and GPIO. The names may vary due to binding differences, but the physical layout does not change. This supports at most one GPIO pin. The user must specify the GPIO name, the polarity, and the amount of time to wait after the GPIO is toggled. Devices with more than one GPIO pin likely require specific power sequencing beyond what generic code can easily support. Signed-off-by: Chen-Yu Tsai Reviewed-by: Douglas Anderson Reviewed-by: Andy Shevchenko Reviewed-by: AngeloGioacchino Del Regno Tested-by: Andrey Skvortsov --- Changes since v10: - Added include of linux/types.h for |bool| Changes since v9: - Picked up Andy's reviewed-by Changes since v8: - Moved |struct gpio_desc| forward declaration before |struct regulator| (Andy) - Dropped GPIO descriptor validity check from i2c_of_probe_simple_disable_gpio(); GPIO functions check it (Andy) - Dropped comment from i2c_of_probe_simple_disable_gpio() (Doug) - Reworded comment in i2c_of_probe_simple_cleanup() (Doug) - Picked up Doug's reviewed-by Changes since v7: - Dropped mention of time unit in struct i2c_of_probe_simple_opts kernel doc (Andy) - Added check for non-zero delay before msleep() (Doug) - Simplified GPIO name check and reverse conditional branches (Andy) - Added description about the supported power sequence - Switched GPIO usage to logical levels (Doug) - Changed some variable names and comments to fit - Added description of power sequence to struct i2c_of_probe_simple_opts (Doug) - Added comment saying i2c_of_probe_simple_put_gpiod() might be no-op (Doug) - Combined callbacks (.get_resources with .enable; .cleanup with .free_resources_late); renamed i2c_of_probe_simple_free_res_early() to i2c_of_probe_simple_cleanup_early() Changes since v6: - Restructured into helpers for the I2C OF component prober - Reduced to only handle one GPIO - Set GPIO to input on (failure) cleanup - Updated commit message Changes since v5: - Renamed "con" to "propname" in i2c_of_probe_get_gpiod() - Copy string first and check return value of strscpy() for overflow in i2c_of_probe_get_gpiod() - Add parenthesis around "enable" and "reset" GPIO names in comments - Split resource count debug message into two separate lines - Split out GPIO helper from i2c_of_probe_enable_res() to keep code cleaner following the previous patch - Adopted options for customizing power sequencing delay following previous patch Changes since v4: - Split out from previous patch - Moved GPIO property name check to common function in gpiolib.c in new patch - Moved i2c_of_probe_free_gpios() into for_each_child_of_node_scoped() - Rewrote in gpiod_*_array-esque fashion --- drivers/i2c/i2c-core-of-prober.c | 100 ++++++++++++++++++++++++++++++- include/linux/i2c-of-prober.h | 21 +++++++ 2 files changed, 119 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-pro= ber.c index 76df75c51cae..b9ca785f8b17 100644 --- a/drivers/i2c/i2c-core-of-prober.c +++ b/drivers/i2c/i2c-core-of-prober.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ * address responds. * * TODO: - * - Support handling common GPIOs. * - Support I2C muxes */ =20 @@ -246,6 +246,62 @@ static void i2c_of_probe_simple_disable_regulator(stru= ct device *dev, struct i2c regulator_disable(ctx->supply); } =20 +static int i2c_of_probe_simple_get_gpiod(struct device *dev, struct device= _node *node, + struct i2c_of_probe_simple_ctx *ctx) +{ + struct fwnode_handle *fwnode =3D of_fwnode_handle(node); + struct gpio_desc *gpiod; + const char *con_id; + + /* NULL signals no GPIO needed */ + if (!ctx->opts->gpio_name) + return 0; + + /* An empty string signals an unnamed GPIO */ + if (!ctx->opts->gpio_name[0]) + con_id =3D NULL; + else + con_id =3D ctx->opts->gpio_name; + + gpiod =3D fwnode_gpiod_get_index(fwnode, con_id, 0, GPIOD_ASIS, "i2c-of-p= rober"); + if (IS_ERR(gpiod)) + return PTR_ERR(gpiod); + + ctx->gpiod =3D gpiod; + + return 0; +} + +static void i2c_of_probe_simple_put_gpiod(struct i2c_of_probe_simple_ctx *= ctx) +{ + gpiod_put(ctx->gpiod); + ctx->gpiod =3D NULL; +} + +static int i2c_of_probe_simple_set_gpio(struct device *dev, struct i2c_of_= probe_simple_ctx *ctx) +{ + int ret; + + if (!ctx->gpiod) + return 0; + + dev_dbg(dev, "Configuring GPIO\n"); + + ret =3D gpiod_direction_output(ctx->gpiod, ctx->opts->gpio_assert_to_enab= le); + if (ret) + return ret; + + if (ctx->opts->post_gpio_config_delay_ms) + msleep(ctx->opts->post_gpio_config_delay_ms); + + return 0; +} + +static void i2c_of_probe_simple_disable_gpio(struct device *dev, struct i2= c_of_probe_simple_ctx *ctx) +{ + gpiod_set_value(ctx->gpiod, !ctx->opts->gpio_assert_to_enable); +} + /** * i2c_of_probe_simple_enable - Simple helper for I2C OF prober to get and= enable resources * @dev: Pointer to the &struct device of the caller, only used for dev_pr= intk() messages @@ -253,7 +309,11 @@ static void i2c_of_probe_simple_disable_regulator(stru= ct device *dev, struct i2c * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. * * If &i2c_of_probe_simple_opts->supply_name is given, request the named r= egulator supply. + * If &i2c_of_probe_simple_opts->gpio_name is given, request the named GPI= O. Or if it is + * the empty string, request the unnamed GPIO. * If a regulator supply was found, enable that regulator. + * If a GPIO line was found, configure the GPIO line to output and set val= ue + * according to given options. * * Return: %0 on success or no-op, or a negative error number on failure. */ @@ -282,12 +342,24 @@ int i2c_of_probe_simple_enable(struct device *dev, st= ruct device_node *bus_node, if (ret) goto out_put_node; =20 - ret =3D i2c_of_probe_simple_enable_regulator(dev, ctx); + ret =3D i2c_of_probe_simple_get_gpiod(dev, node, ctx); if (ret) goto out_put_supply; =20 + ret =3D i2c_of_probe_simple_enable_regulator(dev, ctx); + if (ret) + goto out_put_gpiod; + + ret =3D i2c_of_probe_simple_set_gpio(dev, ctx); + if (ret) + goto out_disable_regulator; + return 0; =20 +out_disable_regulator: + i2c_of_probe_simple_disable_regulator(dev, ctx); +out_put_gpiod: + i2c_of_probe_simple_put_gpiod(ctx); out_put_supply: i2c_of_probe_simple_put_supply(ctx); out_put_node: @@ -296,17 +368,40 @@ int i2c_of_probe_simple_enable(struct device *dev, st= ruct device_node *bus_node, } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_enable, I2C_OF_PROBER); =20 +/** + * i2c_of_probe_simple_cleanup_early - \ + * Simple helper for I2C OF prober to release GPIOs before component is en= abled + * @dev: Pointer to the &struct device of the caller; unused. + * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. + * + * GPIO descriptors are exclusive and have to be released before the + * actual driver probes so that the latter can acquire them. + */ +void i2c_of_probe_simple_cleanup_early(struct device *dev, void *data) +{ + struct i2c_of_probe_simple_ctx *ctx =3D data; + + i2c_of_probe_simple_put_gpiod(ctx); +} +EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_cleanup_early, I2C_OF_PROBER); + /** * i2c_of_probe_simple_cleanup - Clean up and release resources for I2C OF= prober simple helpers * @dev: Pointer to the &struct device of the caller, only used for dev_pr= intk() messages * @data: Pointer to &struct i2c_of_probe_simple_ctx helper context. * + * * If a GPIO line was found and not yet released, set its value to the o= pposite of that + * set in i2c_of_probe_simple_enable() and release it. * * If a regulator supply was found, disable that regulator and release i= t. */ void i2c_of_probe_simple_cleanup(struct device *dev, void *data) { struct i2c_of_probe_simple_ctx *ctx =3D data; =20 + /* GPIO operations here are no-ops if i2c_of_probe_simple_cleanup_early w= as called. */ + i2c_of_probe_simple_disable_gpio(dev, ctx); + i2c_of_probe_simple_put_gpiod(ctx); + i2c_of_probe_simple_disable_regulator(dev, ctx); i2c_of_probe_simple_put_supply(ctx); } @@ -314,6 +409,7 @@ EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_cleanup, I2C_O= F_PROBER); =20 struct i2c_of_probe_ops i2c_of_probe_simple_ops =3D { .enable =3D i2c_of_probe_simple_enable, + .cleanup_early =3D i2c_of_probe_simple_cleanup_early, .cleanup =3D i2c_of_probe_simple_cleanup, }; EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_ops, I2C_OF_PROBER); diff --git a/include/linux/i2c-of-prober.h b/include/linux/i2c-of-prober.h index df95aa6ad90e..bb6d47f50ee5 100644 --- a/include/linux/i2c-of-prober.h +++ b/include/linux/i2c-of-prober.h @@ -9,6 +9,7 @@ #define _LINUX_I2C_OF_PROBER_H =20 #include +#include =20 struct device; struct device_node; @@ -85,6 +86,7 @@ int i2c_of_probe_component(struct device *dev, const stru= ct i2c_of_probe_cfg *cf * * The following helpers are provided: * * i2c_of_probe_simple_enable() + * * i2c_of_probe_simple_cleanup_early() * * i2c_of_probe_simple_cleanup() */ =20 @@ -92,14 +94,31 @@ int i2c_of_probe_component(struct device *dev, const st= ruct i2c_of_probe_cfg *cf * struct i2c_of_probe_simple_opts - Options for simple I2C component prob= er callbacks * @res_node_compatible: Compatible string of device node to retrieve reso= urces from. * @supply_name: Name of regulator supply. + * @gpio_name: Name of GPIO. NULL if no GPIO line is used. Empty string ("= ") if GPIO + * line is unnamed. * @post_power_on_delay_ms: Delay after regulators are powered on. Passed = to msleep(). + * @post_gpio_config_delay_ms: Delay after GPIO is configured. Passed to m= sleep(). + * @gpio_assert_to_enable: %true if GPIO should be asserted, i.e. set to l= ogical high, + * to enable the component. + * + * This describes power sequences common for the class of components suppo= rted by the + * simple component prober: + * * @gpio_name is configured to the non-active setting according to @gpio= _assert_to_enable. + * * @supply_name regulator supply is enabled. + * * Wait for @post_power_on_delay_ms to pass. + * * @gpio_name is configured to the active setting according to @gpio_ass= ert_to_enable. + * * Wait for @post_gpio_config_delay_ms to pass. */ struct i2c_of_probe_simple_opts { const char *res_node_compatible; const char *supply_name; + const char *gpio_name; unsigned int post_power_on_delay_ms; + unsigned int post_gpio_config_delay_ms; + bool gpio_assert_to_enable; }; =20 +struct gpio_desc; struct regulator; =20 struct i2c_of_probe_simple_ctx { @@ -107,9 +126,11 @@ struct i2c_of_probe_simple_ctx { const struct i2c_of_probe_simple_opts *opts; /* private: internal fields for helpers. */ struct regulator *supply; + struct gpio_desc *gpiod; }; =20 int i2c_of_probe_simple_enable(struct device *dev, struct device_node *bus= _node, void *data); +void i2c_of_probe_simple_cleanup_early(struct device *dev, void *data); void i2c_of_probe_simple_cleanup(struct device *dev, void *data); =20 extern struct i2c_of_probe_ops i2c_of_probe_simple_ops; --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 C930E1DDC02 for ; Wed, 6 Nov 2024 09:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885668; cv=none; b=qqUeyAdCyc/BAWMFhId128cewqES6TbuyXuWjTfErSAxsxTzmhpq61/gpyOPbD0N22dVou+qY/x8aazTsodl8Rd5YAdi5rXY6z3VwLnheW3wVNp28w2D7Vd7L6pv+7+smEeO8Gg1zqiAup0hV3lS6d389x6dvzt+r6TR0+9NmBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885668; c=relaxed/simple; bh=g0Ke6cFQPAI//FG8l4hlBZS0GL2ftT1CUxfn+qFrqwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lT6ffzxA/p7LHaMCIXhIbYLGdUVjyCjT6ngHAqNOljz5LaXQebt4kwo94ZO7iGvsVH8UVGQDRWHqRSCu0kXbrzlE/JckluiFk3cox4abKQFdlpuBNoR0PtpfZGT4OaHOTQHnRz65mhTjI5RO/T3bJo7naESHU/hmnaDXdD0cTLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=AL+uqRjY; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AL+uqRjY" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20cd76c513cso50955115ad.3 for ; Wed, 06 Nov 2024 01:34:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885666; x=1731490466; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=huAJvy+H9l+GheA/RC75XQQKkdS5LpAA6/u7dPnX/o0=; b=AL+uqRjYtEOP9L/AIHFgpEmUBEOryr4xYDvponCVoArckJ0XsTRp5ATHCyDU3pxJHY E0sIcmXsoVm4rt4oTzUvB/7FbuM/4NTm2KIukyx5Oapte6aAcMkj2BDlMSBkCuh3S39J SWMSmQ687uFJF+5k6uyMugXdzgBlimvlaFDfY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885666; x=1731490466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=huAJvy+H9l+GheA/RC75XQQKkdS5LpAA6/u7dPnX/o0=; b=NwxRbJCWl5AsW4mcTSoAi9doKirYZBfqBVHejWQEqt5BTK2wUimwQF306I6YyULplD BkEblCQqaqCBukWGNXC08TxCsoef3MSuxiTc9SQZjvPnDeGfzi2efXsaly+6L6tUuWCn s/Cev69LjB6eKf9WDneiAC3IYEpzp/BeVMirohpA3PJN7/JFGjFxIHZNkTMpamLHbN+R VYX04gjFm03GOUQEDW9ViFu5FV3XTswr4A+pvObxs+HdcH8IH6j+M/bQpR5Z74Orh2UC lmwbncqwZ/nWkyzm7PtCXwIa6zUe97lqso5dxK4NP/LRCwnvacGrY8w9zAH7khcMitsP Frzw== X-Forwarded-Encrypted: i=1; AJvYcCUXDqDlbBAJAe4ySROm1lGnQdr92MHRrmcouraL9NrOt4Xv3yU6TcUlJRKxM37Veuf9yZ/599+Fs2bDPl8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4q1JEiSV4c0X6SoJ9SVxXmNGOIKvRwc0HKn9dI2CHLdTa8heS rCuUEWNMZQ9JCkDduUmTRg9yGcqyiQBvfWrSjdJD8NzRgwpVOZnWeOwSUcFqzQ== X-Google-Smtp-Source: AGHT+IE8snQcE1SrWqRDKoVNxvdLDszHzzVL8SuvRX5QTD4ROo5gi7GAvwYyTMVyyNbQu2tQSQbmrw== X-Received: by 2002:a17:902:e852:b0:20b:6458:ec83 with SMTP id d9443c01a7336-210f74f6e5emr384238155ad.4.1730885665976; Wed, 06 Nov 2024 01:34:25 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:25 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov Subject: [PATCH v11 6/7] platform/chrome: Introduce device tree hardware prober Date: Wed, 6 Nov 2024 17:33:33 +0800 Message-ID: <20241106093335.1582205-7-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" Some devices are designed and manufactured with some components having multiple drop-in replacement options. These components are often connected to the mainboard via ribbon cables, having the same signals and pin assignments across all options. These may include the display panel and touchscreen on laptops and tablets, and the trackpad on laptops. Sometimes which component option is used in a particular device can be detected by some firmware provided identifier, other times that information is not available, and the kernel has to try to probe each device. This change attempts to make the "probe each device" case cleaner. The current approach is to have all options added and enabled in the device tree. The kernel would then bind each device and run each driver's probe function. This works, but has been broken before due to the introduction of asynchronous probing, causing multiple instances requesting "shared" resources, such as pinmuxes, GPIO pins, interrupt lines, at the same time, with only one instance succeeding. Work arounds for these include moving the pinmux to the parent I2C controller, using GPIO hogs or pinmux settings to keep the GPIO pins in some fixed configuration, and requesting the interrupt line very late. Such configurations can be seen on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based Lenovo Thinkpad 13S. Instead of this delicate dance between drivers and device tree quirks, this change introduces a simple I2C component prober. For any given class of devices on the same I2C bus, it will go through all of them, doing a simple I2C read transfer and see which one of them responds. It will then enable the device that responds. This requires some minor modifications in the existing device tree. The status for all the device nodes for the component options must be set to "fail-needs-probe". This makes it clear that some mechanism is needed to enable one of them, and also prevents the prober and device drivers running at the same time. Signed-off-by: Chen-Yu Tsai Acked-by: Tzung-Bi Shih Reviewed-by: Douglas Anderson Reviewed-by: AngeloGioacchino Del Regno --- Maintainer expects this to be merged through I2C tree. Changes since v9: - Added inclusion of stddef.h for NULL Changes since v8: - Added trailing commas on last field in struct variable declarations (Andy) - Added macros wrapping chromeos_i2c_probe_dumb_* and chromeos_i2c_probe_simple_*_cfg variable declarations (Andy) - Split up hw_prober_platforms into one field per line (Andy) - Picked up Doug's reviewed-by Changes since v7: - Corrected Makefile item order - Replaced "failed-needs-probe" with "fail-needs-probe" in commit message - Added include of "linux/of.h" for of_machine_is_compatible() - Switched to simple probe helpers for trackpads on Hana Changes since v6: - Adapted to new I2C OF prober interface - Collected Acked-by Changes since v5: - Adapt to new i2c_of_probe_component() parameters Changes since v4: - Fix Kconfig dependency - Update copyright year - Drop "linux/of.h" header - Include "linux/errno.h" - Move |int ret| declaration to top of block - Return -ENODEV on no match instead of 0 - Unregister platform driver and device unconditionally after previous change Changes since v3: - Include linux/init.h - Rewrite for loop in driver probe function as suggested by Andy - Make prober driver buildable as module - Ignore prober errors other than probe deferral Changes since v2: - Addressed Rob's comments - Move remaining driver code to drivers/platform/chrome/ - Depend on rather than select CONFIG_I2C - Copy machine check to driver init function - Addressed Andy's comments - Explicitly mention "device tree" or OF in driver name, description and Kconfig symbol - Drop filename from inside the file - Switch to passing "struct device *" to shorten lines - Move "ret =3D 0" to just before for_each_child_of_node(i2c_node, node) - Make loop variable size_t (instead of unsigned int as Andy asked) - Use PLATFORM_DEVID_NONE instead of raw -1 - Use standard goto error path pattern in hw_prober_driver_init() - Changes since v1: - New patch --- drivers/platform/chrome/Kconfig | 11 ++ drivers/platform/chrome/Makefile | 1 + .../platform/chrome/chromeos_of_hw_prober.c | 154 ++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 drivers/platform/chrome/chromeos_of_hw_prober.c diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kcon= fig index 7dbeb786352a..b7dbaf77b6db 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -61,6 +61,17 @@ config CHROMEOS_TBMC To compile this driver as a module, choose M here: the module will be called chromeos_tbmc. =20 +config CHROMEOS_OF_HW_PROBER + tristate "ChromeOS Device Tree Hardware Prober" + depends on OF + depends on I2C + select OF_DYNAMIC + default OF + help + This option enables the device tree hardware prober for ChromeOS + devices. The driver will probe the correct component variant in + devices that have multiple drop-in options for one component. + config CROS_EC tristate "ChromeOS Embedded Controller" select CROS_EC_PROTO diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Mak= efile index 2dcc6ccc2302..fb8335458a22 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -6,6 +6,7 @@ CFLAGS_cros_ec_sensorhub_ring.o:=3D -I$(src) =20 obj-$(CONFIG_CHROMEOS_ACPI) +=3D chromeos_acpi.o obj-$(CONFIG_CHROMEOS_LAPTOP) +=3D chromeos_laptop.o +obj-$(CONFIG_CHROMEOS_OF_HW_PROBER) +=3D chromeos_of_hw_prober.o obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN) +=3D chromeos_privacy_screen.o obj-$(CONFIG_CHROMEOS_PSTORE) +=3D chromeos_pstore.o obj-$(CONFIG_CHROMEOS_TBMC) +=3D chromeos_tbmc.o diff --git a/drivers/platform/chrome/chromeos_of_hw_prober.c b/drivers/plat= form/chrome/chromeos_of_hw_prober.c new file mode 100644 index 000000000000..297d4704b75f --- /dev/null +++ b/drivers/platform/chrome/chromeos_of_hw_prober.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ChromeOS Device Tree Hardware Prober + * + * Copyright (c) 2024 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "chromeos_of_hw_prober" + +/** + * struct hw_prober_entry - Holds an entry for the hardware prober + * + * @compatible: compatible string to match against the machine + * @prober: prober function to call when machine matches + * @data: extra data for the prober function + */ +struct hw_prober_entry { + const char *compatible; + int (*prober)(struct device *dev, const void *data); + const void *data; +}; + +struct chromeos_i2c_probe_data { + const struct i2c_of_probe_cfg *cfg; + const struct i2c_of_probe_simple_opts *opts; +}; + +static int chromeos_i2c_component_prober(struct device *dev, const void *_= data) +{ + const struct chromeos_i2c_probe_data *data =3D _data; + struct i2c_of_probe_simple_ctx ctx =3D { + .opts =3D data->opts, + }; + + return i2c_of_probe_component(dev, data->cfg, &ctx); +} + +#define DEFINE_CHROMEOS_I2C_PROBE_CFG_SIMPLE_BY_TYPE(_type) \ + static const struct i2c_of_probe_cfg chromeos_i2c_probe_simple_ ## _type = ## _cfg =3D { \ + .type =3D #_type, \ + .ops =3D &i2c_of_probe_simple_ops, \ + } + +#define DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB_BY_TYPE(_type) \ + static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_ ## _= type =3D { \ + .cfg =3D &(const struct i2c_of_probe_cfg) { \ + .type =3D #_type, \ + }, \ + } + +DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB_BY_TYPE(touchscreen); + +DEFINE_CHROMEOS_I2C_PROBE_CFG_SIMPLE_BY_TYPE(trackpad); + +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_hana_trackp= ad =3D { + .cfg =3D &chromeos_i2c_probe_simple_trackpad_cfg, + .opts =3D &(const struct i2c_of_probe_simple_opts) { + .res_node_compatible =3D "elan,ekth3000", + .supply_name =3D "vcc", + /* + * ELAN trackpad needs 2 ms for H/W init and 100 ms for F/W init. + * Synaptics trackpad needs 100 ms. + * However, the regulator is set to "always-on", presumably to + * avoid this delay. The ELAN driver is also missing delays. + */ + .post_power_on_delay_ms =3D 0, + }, +}; + +static const struct hw_prober_entry hw_prober_platforms[] =3D { + { + .compatible =3D "google,hana", + .prober =3D chromeos_i2c_component_prober, + .data =3D &chromeos_i2c_probe_dumb_touchscreen, + }, { + .compatible =3D "google,hana", + .prober =3D chromeos_i2c_component_prober, + .data =3D &chromeos_i2c_probe_hana_trackpad, + }, +}; + +static int chromeos_of_hw_prober_probe(struct platform_device *pdev) +{ + for (size_t i =3D 0; i < ARRAY_SIZE(hw_prober_platforms); i++) { + int ret; + + if (!of_machine_is_compatible(hw_prober_platforms[i].compatible)) + continue; + + ret =3D hw_prober_platforms[i].prober(&pdev->dev, hw_prober_platforms[i]= .data); + /* Ignore unrecoverable errors and keep going through other probers */ + if (ret =3D=3D -EPROBE_DEFER) + return ret; + } + + return 0; +} + +static struct platform_driver chromeos_of_hw_prober_driver =3D { + .probe =3D chromeos_of_hw_prober_probe, + .driver =3D { + .name =3D DRV_NAME, + }, +}; + +static struct platform_device *chromeos_of_hw_prober_pdev; + +static int chromeos_of_hw_prober_driver_init(void) +{ + size_t i; + int ret; + + for (i =3D 0; i < ARRAY_SIZE(hw_prober_platforms); i++) + if (of_machine_is_compatible(hw_prober_platforms[i].compatible)) + break; + if (i =3D=3D ARRAY_SIZE(hw_prober_platforms)) + return -ENODEV; + + ret =3D platform_driver_register(&chromeos_of_hw_prober_driver); + if (ret) + return ret; + + chromeos_of_hw_prober_pdev =3D + platform_device_register_simple(DRV_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(chromeos_of_hw_prober_pdev)) + goto err; + + return 0; + +err: + platform_driver_unregister(&chromeos_of_hw_prober_driver); + + return PTR_ERR(chromeos_of_hw_prober_pdev); +} +module_init(chromeos_of_hw_prober_driver_init); + +static void chromeos_of_hw_prober_driver_exit(void) +{ + platform_device_unregister(chromeos_of_hw_prober_pdev); + platform_driver_unregister(&chromeos_of_hw_prober_driver); +} +module_exit(chromeos_of_hw_prober_driver_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("ChromeOS device tree hardware prober"); +MODULE_IMPORT_NS(I2C_OF_PROBER); --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:27:01 2024 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 1CD8C1DE2AF for ; Wed, 6 Nov 2024 09:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885671; cv=none; b=LoGqHi1O33+4qe8GLpS5YQ1xesQHpNj+CsEpZNy9lLR2UCAF+pdTM2wGtX48sZcTyH8lGrQYlfEbR9JnmeaFugFYPiPerWd/1J2L8ZAZYn19doPaGMmSJo5+5DTTc8TGEm3CM2WjnlK9KcXncLZLo/ft4EkUoO2oDk8n0JqiT2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730885671; c=relaxed/simple; bh=fbfS5+0BG4rw0gOZBk/i1Plr3VDHJVhinZJf5GjxUnQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HBAQx47RiHlA450189gRMqtB2FeEYCxnjaTgHx1VDBQMSJU4SHFr/e6xxt/KXF9lFx47mCR8/MLv5Sqp8VGOhXuFylDLK/Vxx2Vos97WejP2xSThHCoFQupBDiQt+c0usMVUEPuCsgEhgr7EdI9eRLk15iz+FlHaNFhBfb69boA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=bOteUN65; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="bOteUN65" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20bb39d97d1so62182945ad.2 for ; Wed, 06 Nov 2024 01:34:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730885669; x=1731490469; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O/GF/Qtpn6msAtbROl5IORl4ZiQde9+aAMX19fZKFEE=; b=bOteUN65E77BkS9lE9MWX2FA/GE27gSsZJWOcp1kd48nEQixyofrEf0bGBwbXoeniz +ti8R2qRg8s/DmUzJBBDD7Sxj+/eq081w+5/gkxNJXRksIxsaBcpCF2JYR9s/1q0Jwlq iPNNA5iLmn//dEiZDzlcnY6sBrcBEVfc0bbdM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730885669; x=1731490469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O/GF/Qtpn6msAtbROl5IORl4ZiQde9+aAMX19fZKFEE=; b=Rcgo8ZiC8W9t74FdCh9BIBV07kDtDAOTjy/Vx4vcOPnPn2oMe/91bhP0h7Jkr1UUjW /7dSyY4d44f0saq/GBx3367A7q5g55DEL7df+GEa37GOjkr2/A4D/qBiIf03J9SxgoBh tA0w0uvEI5BAbU+DaeatGL/1o37xNRlQBiTmjbvpgMs37ZQMrxbFTj3aTObt7buInwrU LFMKQNJPc44a/N10pq8tdEKqijVYTn6BOGtneIB41Mff19vPUP9VOlE/Bw0Ca9b1TW+Z 6IQL0MBHGfZBfybxnVmpP+4BvxIHC36jnMnwIhvsYJ6sijoMzZEqZWEg+SK7IbHLn+UD bxzA== X-Forwarded-Encrypted: i=1; AJvYcCWo2O8/fQSoEWvmYDMZCDsgWhGQ81ppr4Fdx3slZavau4L/sJPFqtZFKt9INnWO7da0Xt2g7mN6rcwz77I=@vger.kernel.org X-Gm-Message-State: AOJu0YzVvmb3pGFmLMBKSKnIEkVC4HSDrkwiiy9hbFZH7uIrcpkkib9X 6RBrlCDNjG8e+3uDN8EvfwVNC/Xmi5w480J+8CFe8nbX6eWSRsW/y1GlfXIcnA== X-Google-Smtp-Source: AGHT+IEFJaxMs5mAqrxaj0N0qXwA3k96U3FQh8ZQNA88MZaxh/utNb59Xt8KT+qflVg8MQLvbAXTtQ== X-Received: by 2002:a17:902:d481:b0:20c:5d78:4d8f with SMTP id d9443c01a7336-210f76f2d29mr381797155ad.52.1730885669470; Wed, 06 Nov 2024 01:34:29 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:93fe:1d68:b50:3213]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm91478665ad.63.2024.11.06.01.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 01:34:29 -0800 (PST) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang Cc: Chen-Yu Tsai , Rob Herring , Saravana Kannan , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org, Andrey Skvortsov , stable+noautosel@kernel.org Subject: [PATCH v11 7/7] arm64: dts: mediatek: mt8173-elm-hana: Mark touchscreens and trackpads as fail Date: Wed, 6 Nov 2024 17:33:34 +0800 Message-ID: <20241106093335.1582205-8-wenst@chromium.org> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog In-Reply-To: <20241106093335.1582205-1-wenst@chromium.org> References: <20241106093335.1582205-1-wenst@chromium.org> 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 Content-Type: text/plain; charset="utf-8" Instead of having them all available, mark them all as "fail-needs-probe" and have the implementation try to probe which one is present. Also remove the shared resource workaround by moving the pinctrl entry for the trackpad interrupt line back into the individual trackpad nodes. Cc: # Needs accompanying new driver to work Signed-off-by: Chen-Yu Tsai Reviewed-by: Douglas Anderson --- Changes since v9: - Picked up Doug's reviewed-by Changes since v8: none Changes since v7: - Mark touchscreen@40 as "fail-needs-probe" as well Changes since v6: none Changes since v5: none Changes since v4: - Rebased Changes since v3: - Also remove second source workaround, i.e. move the interrupt line pinctrl entry from the i2c node back to the components. Changes since v2: - Drop class from status --- arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi | 14 ++++++++++++++ arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi b/arch/arm64= /boot/dts/mediatek/mt8173-elm-hana.dtsi index ae0379fd42a9..dfc5c2f0ddef 100644 --- a/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtsi @@ -14,6 +14,7 @@ touchscreen2: touchscreen@34 { compatible =3D "melfas,mip4_ts"; reg =3D <0x34>; interrupts-extended =3D <&pio 88 IRQ_TYPE_LEVEL_LOW>; + status =3D "fail-needs-probe"; }; =20 /* @@ -26,6 +27,7 @@ touchscreen3: touchscreen@20 { reg =3D <0x20>; hid-descr-addr =3D <0x0020>; interrupts-extended =3D <&pio 88 IRQ_TYPE_LEVEL_LOW>; + status =3D "fail-needs-probe"; }; =20 /* Lenovo Ideapad C330 uses G2Touch touchscreen as a 2nd source touchscre= en */ @@ -35,6 +37,7 @@ touchscreen@40 { hid-descr-addr =3D <0x0001>; interrupt-parent =3D <&pio>; interrupts =3D <88 IRQ_TYPE_LEVEL_LOW>; + status =3D "fail-needs-probe"; }; }; =20 @@ -47,6 +50,8 @@ &i2c4 { trackpad2: trackpad@2c { compatible =3D "hid-over-i2c"; interrupts-extended =3D <&pio 117 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&trackpad_irq>; reg =3D <0x2c>; hid-descr-addr =3D <0x0020>; /* @@ -58,6 +63,7 @@ trackpad2: trackpad@2c { */ vdd-supply =3D <&mt6397_vgp6_reg>; wakeup-source; + status =3D "fail-needs-probe"; }; }; =20 @@ -82,3 +88,11 @@ pins_wp { }; }; }; + +&touchscreen { + status =3D "fail-needs-probe"; +}; + +&trackpad { + status =3D "fail-needs-probe"; +}; diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi b/arch/arm64/boot= /dts/mediatek/mt8173-elm.dtsi index b4d85147b77b..eee64461421f 100644 --- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi @@ -358,12 +358,12 @@ touchscreen: touchscreen@10 { &i2c4 { clock-frequency =3D <400000>; status =3D "okay"; - pinctrl-names =3D "default"; - pinctrl-0 =3D <&trackpad_irq>; =20 trackpad: trackpad@15 { compatible =3D "elan,ekth3000"; interrupts-extended =3D <&pio 117 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&trackpad_irq>; reg =3D <0x15>; vcc-supply =3D <&mt6397_vgp6_reg>; wakeup-source; --=20 2.47.0.199.ga7371fff76-goog