From patchwork Mon Jan 30 16:54:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 50375 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2294191wrn; Mon, 30 Jan 2023 09:09:57 -0800 (PST) X-Google-Smtp-Source: AK7set9z7UCbXZuqcdJAuY+yYbohQcp+t5t9K5Tw8iP80BibHSG/KluFalYO8vmQ9nd5l342+jfD X-Received: by 2002:a17:907:3f1f:b0:878:702c:bd86 with SMTP id hq31-20020a1709073f1f00b00878702cbd86mr204467ejc.74.1675098596981; Mon, 30 Jan 2023 09:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675098596; cv=none; d=google.com; s=arc-20160816; b=N9hvn9Cg4bwvxcSSKM6bq55VQqJNsNFnKLvgSy6Cs35vk/gW7qMtClGsMddvZfIV/x EjWKpLMteu7Hh8cCwA9TrOhg8CF8mZstwEHWEeLfaz9Dyyf0EV9dm0EGwiXV6lJ30T3U rxo1DZilskCTHy/suUyn/JyEKptKuO8o/WvvSrohDHhzwb59tjZMF14+t5MZAS7m4q99 jm6gQkdLzUN3r4X7CSv+C86waFOUzQC0GZd5wPsS6aKBy2lZk0hqQsw6g9vHL27IlN4j DJbPKxEDh8PdXw7otSPY5L9kt++VOQuqT/DHgUrJJbaNh0uaGkY/OXA4uMNKw/BjUuLc Pv3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ufhJAWNpVWI5s+uFKzVFnYTvPvLzKFeYy7PIx77olTQ=; b=Cjry01qP+5V6VErOoqnKMwvtB4uSfJTyhBlX9KFZnBea+83X7r0bh7M/aLyzQvoMBS OVrulzpnrYCSP458eJq+cG7ywyZJqbz3vefsxeop2WZGaKuIxmqMW9+Bt0dm7UD/rQHm oYHPp7c05UrxI8O1cc+XI/ezRewrQ2UNyJ7/cZB/mWVUhbLWIQNNRaNPplfudgWBrXL0 8SOerz9TrrH7/DNOiyYspUdDht8HEdmSQDCJsdXxNNt8cYXtYxEtXTbSUE/4Qciyzoe2 vHKGi70fUoUzVh4UyKY4G0+GGjTWfi1gP3Ny4QFivTjJoxuJplNNs8+CUzEpakm96Q0R akYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GOoodPz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e23-20020a170906749700b00877da25cb31si14846553ejl.869.2023.01.30.09.09.33; Mon, 30 Jan 2023 09:09:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GOoodPz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236610AbjA3QzB (ORCPT + 99 others); Mon, 30 Jan 2023 11:55:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236268AbjA3Qyt (ORCPT ); Mon, 30 Jan 2023 11:54:49 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405C93D935 for ; Mon, 30 Jan 2023 08:54:47 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id ud5so33627862ejc.4 for ; Mon, 30 Jan 2023 08:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=ufhJAWNpVWI5s+uFKzVFnYTvPvLzKFeYy7PIx77olTQ=; b=GOoodPz+j/Nj3krXYVUmcMvp7eE4Q9UnmiITSbTtixmCz/KCJv/O6ZSWAte9XLOJNx EoYDCRXJVT4C5BBRlNTB2AwOe3F5exjMz23eDTpl/ISOgpFuMd53TJYDzlc5yzTq0Q7p FV8E3uD+zyzedG3+64Q1DBSYdkCJiTZwLdzg/d2/7czrMJcFhH1iRpoAwM/jQleWbbkX 0adA11S0DNb1eY4JMhEBvQmCWXkctklrW47nmZ0StqH446q98+48qUNgmYQDdDgWUQKT e9+p+kIOvT7lwhLsKDdg23VtyqMAIK/V+wUt8RPWnJHYWWKB0yA2q7wUhTaQAI8kSjxs ErUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ufhJAWNpVWI5s+uFKzVFnYTvPvLzKFeYy7PIx77olTQ=; b=JnrLZjrQ34fYM8AOQehw0aCuxtwzjQzfNKBHU/7kBdgAi40doHLX/URnfr+bm1yllo cRA+U4sdXwnz3sN7hp3ZfbZy58X3aZ5nvp5LDeJXALXIngIg7SJU3jBDfzpsy7uKA+iZ F72AxajU//JN3kNjODyNZRCkzXMMMIeqmAsRVFDDq9RiTIWnHBA3FsaJl6jAivn66Tca 5oqpAI5PaURaBJ/Z/uzGeutL71TG9rdFik2ztbgPw++mbsOFDRqNveLNDCvwXfC3NgZj TvLE9kQiGlLITNeP03WuMBO8oNKvkNzPdGi/1KBVzd9x19DYtEDBK3A5Rlst+vU56b6r haoQ== X-Gm-Message-State: AO0yUKXMwY2Z6/A/u2zGfkoIQKbcIFpd4sOm2VXqxnxFlPv4SXAOjRwE +sYsK3q4iIEBeE1GpaQQdTTsVw== X-Received: by 2002:a17:907:8b90:b0:87b:db63:1e18 with SMTP id tb16-20020a1709078b9000b0087bdb631e18mr122730ejc.71.1675097685873; Mon, 30 Jan 2023 08:54:45 -0800 (PST) Received: from localhost.localdomain (abyl20.neoplus.adsl.tpnet.pl. [83.9.31.20]) by smtp.gmail.com with ESMTPSA id lj14-20020a170906f9ce00b0088744fc7084sm2590651ejb.38.2023.01.30.08.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 08:54:45 -0800 (PST) From: Konrad Dybcio To: linux-arm-msm@vger.kernel.org, andersson@kernel.org, agross@kernel.org, krzysztof.kozlowski@linaro.org Cc: marijn.suijten@somainline.org, Konrad Dybcio , Linus Walleij , Rob Herring , Krzysztof Kozlowski , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] pinctrl: pinconf-generic: Add an overridable way to set bias property Date: Mon, 30 Jan 2023 17:54:35 +0100 Message-Id: <20230130165435.2347569-2-konrad.dybcio@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130165435.2347569-1-konrad.dybcio@linaro.org> References: <20230130165435.2347569-1-konrad.dybcio@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756468186451769710?= X-GMAIL-MSGID: =?utf-8?q?1756468186451769710?= We came to a point where we sometimes we support a few dozen boards with a given SoC. Sometimes, we have to take into consideration configurations which deviate rather significatly from the reference or most common designs. In the context of pinctrl, this often comes down to wildly different pin configurations. While pins, function and drive-strength are easily overridable, the (mostly) boolean properties associated with setting bias, aren't. This wouldn't be much of a problem if they didn't differ between boards so often, preventing us from having a "nice" baseline setup without inevitably having to go with an ugly /delete-property/. Introduce logic to handle bias-type, a property which sets a single boolean type of bias on the pin (more than one type of BIAS_ does not make sense, anyway) to make it easily overridable. Signed-off-by: Konrad Dybcio --- drivers/pinctrl/pinconf-generic.c | 35 ++++++++++++++++++++++--- include/linux/pinctrl/pinconf-generic.h | 1 + 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c index 365c4b0ca465..b99c2a85486e 100644 --- a/drivers/pinctrl/pinconf-generic.c +++ b/drivers/pinctrl/pinconf-generic.c @@ -206,11 +206,38 @@ static void parse_dt_cfg(struct device_node *np, unsigned int count, unsigned long *cfg, unsigned int *ncfg) { - int i; + int i, ret; + u32 val; + + /* Let's assume only one type of bias is used.. as it should be.. */ + ret = of_property_read_u32(np, "bias-type", &val); + if (!ret) { + /* Bias properties end at idx PIN_CONFIG_BIAS_PULL_UP */ + if (ret > PIN_CONFIG_BIAS_PULL_UP) { + pr_err("invalid type: %u\n", val); + goto generic_parse; + } - for (i = 0; i < count; i++) { - u32 val; - int ret; + pr_debug("found bias type %u\n", val); + /* + * Properties between PIN_CONFIG_BIAS_PULL_DOWN and PIN_CONFIG_BIAS_PULL_UP + * have a default value of one, others default to zero. + */ + cfg[*ncfg] = pinconf_to_config_packed(val, val >= PIN_CONFIG_BIAS_PULL_DOWN); + (*ncfg)++; + + /* Start the generic property read loop where bias properties end. */ + i = PIN_CONFIG_DRIVE_OPEN_DRAIN; + } else { + /* + * If we don't set bias through bias-type, search for all DT + * properties like nothing ever happened. + */ +generic_parse: + i = 0; + } + + for (; i < count; i++) { const struct pinconf_generic_params *par = ¶ms[i]; ret = of_property_read_u32(np, par->property, &val); diff --git a/include/linux/pinctrl/pinconf-generic.h b/include/linux/pinctrl/pinconf-generic.h index d74b7a4ea154..bcf68ba1ea46 100644 --- a/include/linux/pinctrl/pinconf-generic.h +++ b/include/linux/pinctrl/pinconf-generic.h @@ -117,6 +117,7 @@ struct pinctrl_map; * presented using the packed format. */ enum pin_config_param { + /* Keep in sync with dt-bindings/pinctrl/pinconf-generic.h! */ PIN_CONFIG_BIAS_BUS_HOLD, PIN_CONFIG_BIAS_DISABLE, PIN_CONFIG_BIAS_HIGH_IMPEDANCE,