Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6209768ybe; Tue, 17 Sep 2019 22:59:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLbDNg4W+6CdUNx8dHvffU+SIEks7ZrCI3+YCi5QTx8+jqinUCSRCOkpvub6UDeYnax+PD X-Received: by 2002:a17:906:7494:: with SMTP id e20mr8074332ejl.166.1568786345744; Tue, 17 Sep 2019 22:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568786345; cv=none; d=google.com; s=arc-20160816; b=OQ2Aa9K7DXsd4bm234fxBO+NomMRlU08hw1Y82yrVHj72KYXs+hmrpZpj1g4WFriLa o09UsrVLQjkxCRvKC5w8eLgNEAfOr0nD51TnwrgvDqfmQDpyTzeWr7Q1qqR6PUxyKeQx Z89JA/UZT7OrgIUGfot3sspaBNaUF9kvzrxnJxJlpuxYDw32toEpR2ytIk3GZtEszWjh 8bEQThrzQmVt9v/d9EKkxdmOhME3EwkpdyQ3Bcq+Z4xQxbF/+jPrR6A0XUjesrs/EP4m XPvOMdDqyKJNCmC7efzjzAUFxcWNxzyVEHRebXKf7Dpp7kSxr80uzBpSuoL4U4ULi26h xpGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=d13sjtjVCf+l6tcdwjCWa38culzV2DouiIDL/e/+4Tk=; b=V+vwfnrxz+n7gkfFT8oaR9TgXuvYgp7tmajoVkcW1Clpr5mAFOfCayyp/T/5vX5VDg lHLesBFVgYku4e/SV7lH4dZ8mFhzkRTCMKguByg5PGW7j2NVBKuHhzlkHWqVTEGG85GT vK54VdKNTMRSghzfli/p9qlDyRfh7u0CEYYASHwSN+fVYFB7CDQ1wD+Dc26JTwmI1rde Y9V6dTqYtFvyO/EUSbihmGSgJmRplXyHxJlJBrqENXKYnp6VIkg4KAIH95p8R7Pfu4KS 2uIJ6QzWDFnT0iVZeNw6xELawHZk66nw+C6eZFtGmourRxjT7PPOof8znN0QEK7H5hKc MI3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si2742785edc.386.2019.09.17.22.58.42; Tue, 17 Sep 2019 22:59:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727882AbfIRCjT (ORCPT + 99 others); Tue, 17 Sep 2019 22:39:19 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:9339 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727413AbfIRCjS (ORCPT ); Tue, 17 Sep 2019 22:39:18 -0400 X-UUID: 29c78a951bc547d5872844b8202129fe-20190918 X-UUID: 29c78a951bc547d5872844b8202129fe-20190918 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1910691371; Wed, 18 Sep 2019 10:39:11 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 18 Sep 2019 10:39:07 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 18 Sep 2019 10:39:07 +0800 From: Light Hsieh To: CC: , , , , Light Hsieh Subject: [PATCH v5 5/5] pinctrl: mediatek: Add support for pin configuration dump via debugfs. Date: Wed, 18 Sep 2019 10:39:08 +0800 Message-ID: <1568774348-24363-5-git-send-email-light.hsieh@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1568774348-24363-1-git-send-email-light.hsieh@mediatek.com> References: <1568774348-24363-1-git-send-email-light.hsieh@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 050E9B0BB55236DDC0BA422EE98141F138E6305774B40F2F6E4B8912D0BF1C8B2000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for pin configuration dump via catting /sys/kernel/debug/pinctrl/$platform_dependent_path/pinconf-pins. pinctrl framework had already support such dump. This patch implement the operation function pointer to fullfill this dump. --- drivers/pinctrl/mediatek/pinctrl-paris.c | 88 ++++++++++++++++++++++++++++++++ drivers/pinctrl/mediatek/pinctrl-paris.h | 30 +++++++++++ 2 files changed, 118 insertions(+) diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c index e847867..6acbdc3 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.c +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c @@ -530,12 +530,99 @@ static int mtk_pctrl_get_group_pins(struct pinctrl_dev *pctldev, return 0; } +int mtk_hw_get_value_wrap(struct mtk_pinctrl *hw, unsigned int gpio, int field) +{ + const struct mtk_pin_desc *desc; + int value, err; + + if (gpio > hw->soc->npins) + return -EINVAL; + + desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; + + err = mtk_hw_get_value(hw, desc, field, &value); + if (err) + return err; + + return value; +} + +ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw, + unsigned int gpio, char *buf, unsigned int bufLen) +{ + const struct mtk_pin_desc *desc; + int pinmux, pullup, pullen, r1 = -1, r0 = -1, len = 0; + + if (gpio > hw->soc->npins) + return -EINVAL; + + desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; + pinmux = mtk_pctrl_get_pinmux(hw, gpio); + if (pinmux >= hw->soc->nfuncs) + pinmux -= hw->soc->nfuncs; + + mtk_pinconf_bias_get_combo(hw, desc, &pullup, &pullen); + if (pullen == MTK_PUPD_SET_R1R0_00) { + pullen = 0; + r1 = 0; + r0 = 0; + } else if (pullen == MTK_PUPD_SET_R1R0_01) { + pullen = 1; + r1 = 0; + r0 = 1; + } else if (pullen == MTK_PUPD_SET_R1R0_10) { + pullen = 1; + r1 = 1; + r0 = 0; + } else if (pullen == MTK_PUPD_SET_R1R0_11) { + pullen = 1; + r1 = 1; + r0 = 1; + } else if (pullen != MTK_DISABLE && pullen != MTK_ENABLE) { + pullen = 0; + } + len += snprintf(buf + len, bufLen - len, + "%03d: %1d%1d%1d%1d%02d%1d%1d%1d%1d", + gpio, + pinmux, + mtk_pctrl_get_direction(hw, gpio), + mtk_pctrl_get_out(hw, gpio), + mtk_pctrl_get_in(hw, gpio), + mtk_pctrl_get_driving(hw, gpio), + mtk_pctrl_get_smt(hw, gpio), + mtk_pctrl_get_ies(hw, gpio), + pullen, + pullup); + + if (r1 != -1) { + len += snprintf(buf + len, bufLen - len, " (%1d %1d)\n", + r1, r0); + } else { + len += snprintf(buf + len, bufLen - len, "\n"); + } + + return len; +} + +#define PIN_DBG_BUF_SZ 96 +static void mtk_pctrl_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, + unsigned int gpio) +{ + struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev); + char buf[PIN_DBG_BUF_SZ]; + + (void)mtk_pctrl_show_one_pin(hw, gpio, buf, PIN_DBG_BUF_SZ); + + seq_printf(s, "%s", buf); +} + static const struct pinctrl_ops mtk_pctlops = { .dt_node_to_map = mtk_pctrl_dt_node_to_map, .dt_free_map = pinctrl_utils_free_map, .get_groups_count = mtk_pctrl_get_groups_count, .get_group_name = mtk_pctrl_get_group_name, .get_group_pins = mtk_pctrl_get_group_pins, + .pin_dbg_show = mtk_pctrl_dbg_show, }; static int mtk_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) @@ -632,6 +719,7 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, .pin_config_get = mtk_pinconf_get, .pin_config_group_get = mtk_pconf_group_get, .pin_config_group_set = mtk_pconf_group_set, + .is_generic = true, }; static struct pinctrl_desc mtk_desc = { diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.h b/drivers/pinctrl/mediatek/pinctrl-paris.h index 3d43771..d73f4b6 100644 --- a/drivers/pinctrl/mediatek/pinctrl-paris.h +++ b/drivers/pinctrl/mediatek/pinctrl-paris.h @@ -60,6 +60,36 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev, const struct mtk_pin_soc *soc); +int mtk_hw_get_value_wrap(struct mtk_pinctrl *hw, unsigned int gpio, int field); + +#define mtk_pctrl_get_pinmux(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_MODE) + +/* MTK HW use 0 as input, 1 for output + * This interface is for get direct register value, + * so don't reverse + */ +#define mtk_pctrl_get_direction(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_DIR) + +#define mtk_pctrl_get_out(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_DO) + +#define mtk_pctrl_get_in(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_DI) + +#define mtk_pctrl_get_smt(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_SMT) + +#define mtk_pctrl_get_ies(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_IES) + +#define mtk_pctrl_get_driving(hw, gpio) \ + mtk_hw_get_value_wrap(hw, gpio, PINCTRL_PIN_REG_DRV) + +ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw, + unsigned int gpio, char *buf, unsigned int bufLen); + extern const struct dev_pm_ops mtk_paris_pinctrl_pm_ops; #endif /* __PINCTRL_PARIS_H */ -- 1.8.1.1.dirty