From patchwork Tue Mar 2 05:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Drew Fustini X-Patchwork-Id: 392380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BD68C433DB for ; Tue, 2 Mar 2021 21:20:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 490D264F32 for ; Tue, 2 Mar 2021 21:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383586AbhCBVPs (ORCPT ); Tue, 2 Mar 2021 16:15:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1576907AbhCBFfK (ORCPT ); Tue, 2 Mar 2021 00:35:10 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2119AC0617A9 for ; Mon, 1 Mar 2021 21:32:14 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id q204so12039832pfq.10 for ; Mon, 01 Mar 2021 21:32:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2DbGvfOj1DMYYHtWVJxAg+wtPMMn58r4EIDpHlv7W5Y=; b=oJL1BJF+uyiVd6FSeZRvyOFmVXxR6JUbGB57F3OnJesw3QFTlRvwU6hSWEmgfiS2bR ElgM4iKD06OAh+kp+Yso+Xpj7PERqnZ9dp1jUaJSumbU81Oqn+/ti2SkIcLXfT3+2LiL cIdK+e0TyM3gD655GkI9ZNm5hQsJ7Pi/G3o1+rhXzrxx/dggP0zFs6V2uo3rzahv0kUB vAaHwrx0Te+gDe6Xix7rFx4akwgDVreho6yHu/T3L33cUthHdUuCdsJfULDXLG7sviSH 33wxvUq9SJkPiW49UQzM6noCYtFeykGRbFsWWkCjsqSLjEcAGEbxWDbq5pgi5FSmTFoM Cfbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2DbGvfOj1DMYYHtWVJxAg+wtPMMn58r4EIDpHlv7W5Y=; b=oP8bU4fhZxlfby6dQSX/rUJSlV6Y8ZG6tUNqdkGOb8RqpRtfw68Dkjie2/yjQYgtSG 9vZVMzNBbkcujhunEs4NrVd8jelTfIuu3egzx9PoFhkcKGTaQzr4DIXNARbGNZv39QCq tS4KjDSeh55Xy52yDpgZQfJAtttYfdRa24KgzsPPAxkmRd5C/pqCqeeNqICQCVFPKHyO 2RBZ+OZCR0hDpvwqZvE40syQ4O41D8s4S6AxE1bYG1DI2Dym6x2sdAu64xjR2uO7rKXB LQlgcYfYLkqsBkfjXlBG5GUK8glXFlquDmyjvBZpvVYw9XPiy20744rTvZDNlH5QDALY YsMg== X-Gm-Message-State: AOAM532cd5sdbmvSkkD8jdEzKXjLh207Ncr2kajddroTdat4HVt2H/ER /AfeRIqIP7juvsx63yuECjPPBQ== X-Google-Smtp-Source: ABdhPJyhWpprOajovew/hxFF0zbRLsFXE+yVL4rITdbVY9l+SQvRWEhH932A6nx0YSHs02mI8SI3Eg== X-Received: by 2002:a63:6dc3:: with SMTP id i186mr9446310pgc.314.1614663133698; Mon, 01 Mar 2021 21:32:13 -0800 (PST) Received: from x1.hsd1.or.comcast.net ([2601:1c0:4701:ae70:37ab:7b44:a136:e385]) by smtp.gmail.com with ESMTPSA id o129sm17929757pgo.27.2021.03.01.21.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 21:32:12 -0800 (PST) From: Drew Fustini To: Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Lindgren , Andy Shevchenko , Alexandre Belloni , Geert Uytterhoeven , Pantelis Antoniou , Jason Kridner , Robert Nelson , Joe Perches , Dan Carpenter , Jonathan Corbet , linux-doc@vger.kernel.org Cc: Drew Fustini , Geert Uytterhoeven Subject: [PATCH v9 2/4] pinctrl: pinmux: Add pinmux-select debugfs file Date: Mon, 1 Mar 2021 21:30:57 -0800 Message-Id: <20210302053059.1049035-3-drew@beagleboard.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210302053059.1049035-1-drew@beagleboard.org> References: <20210302053059.1049035-1-drew@beagleboard.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add "pinmux-select" to debugfs which will activate a pin function for a given pin group: echo "" > pinmux-select The write operation pinmux_select() handles this by checking that the names map to valid selectors and then calling ops->set_mux(). The existing "pinmux-functions" debugfs file lists the pin functions registered for the pin controller. For example: function: pinmux-uart0, groups = [ pinmux-uart0-pins ] function: pinmux-mmc0, groups = [ pinmux-mmc0-pins ] function: pinmux-mmc1, groups = [ pinmux-mmc1-pins ] function: pinmux-i2c0, groups = [ pinmux-i2c0-pins ] function: pinmux-i2c1, groups = [ pinmux-i2c1-pins ] function: pinmux-spi1, groups = [ pinmux-spi1-pins ] To activate function pinmux-i2c1 on group pinmux-i2c1-pins: echo "pinmux-i2c1-pins pinmux-i2c1" > pinmux-select Reviewed-by: Andy Shevchenko Reviewed-by: Tony Lindgren Reviewed-by: Geert Uytterhoeven Tested-by: Geert Uytterhoeven Signed-off-by: Drew Fustini --- drivers/pinctrl/pinmux.c | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index c651b2db0925..f4abfaecfc5c 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -12,6 +12,7 @@ */ #define pr_fmt(fmt) "pinmux core: " fmt +#include #include #include #include @@ -673,6 +674,105 @@ void pinmux_show_setting(struct seq_file *s, DEFINE_SHOW_ATTRIBUTE(pinmux_functions); DEFINE_SHOW_ATTRIBUTE(pinmux_pins); +#define PINMUX_SELECT_MAX 128 +static ssize_t pinmux_select(struct file *file, const char __user *user_buf, + size_t len, loff_t *ppos) +{ + struct seq_file *sfile = file->private_data; + struct pinctrl_dev *pctldev = sfile->private; + const struct pinmux_ops *pmxops = pctldev->desc->pmxops; + const char *const *groups; + char *buf, *gname, *fname; + unsigned int num_groups; + int fsel, gsel, ret; + + if (len > PINMUX_SELECT_MAX) + return -ENOMEM; + + buf = kzalloc(PINMUX_SELECT_MAX, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = strncpy_from_user(buf, user_buf, PINMUX_SELECT_MAX); + if (ret < 0) + goto exit_free_buf; + buf[len-1] = '\0'; + + /* remove leading and trailing spaces of input buffer */ + gname = strstrip(buf); + if (*gname == '\0') { + ret = -EINVAL; + goto exit_free_buf; + } + + /* find a separator which is a spacelike character */ + for (fname = gname; !isspace(*fname); fname++) { + if (*fname == '\0') { + ret = -EINVAL; + goto exit_free_buf; + } + } + *fname = '\0'; + + /* drop extra spaces between function and group names */ + fname = skip_spaces(fname + 1); + if (*fname == '\0') { + ret = -EINVAL; + goto exit_free_buf; + } + + ret = pinmux_func_name_to_selector(pctldev, fname); + if (ret < 0) { + dev_err(pctldev->dev, "invalid function %s in map table\n", fname); + goto exit_free_buf; + } + fsel = ret; + + ret = pmxops->get_function_groups(pctldev, fsel, &groups, &num_groups); + if (ret) { + dev_err(pctldev->dev, "no groups for function %d (%s)", fsel, fname); + goto exit_free_buf; + } + + ret = match_string(groups, num_groups, gname); + if (ret < 0) { + dev_err(pctldev->dev, "invalid group %s", gname); + goto exit_free_buf; + } + + ret = pinctrl_get_group_selector(pctldev, gname); + if (ret < 0) { + dev_err(pctldev->dev, "failed to get group selector for %s", gname); + goto exit_free_buf; + } + gsel = ret; + + ret = pmxops->set_mux(pctldev, fsel, gsel); + if (ret) { + dev_err(pctldev->dev, "set_mux() failed: %d", ret); + goto exit_free_buf; + } + ret = len; + +exit_free_buf: + kfree(buf); + + return ret; +} + +static int pinmux_select_open(struct inode *inode, struct file *file) +{ + return single_open(file, NULL, inode->i_private); +} + +static const struct file_operations pinmux_select_ops = { + .owner = THIS_MODULE, + .open = pinmux_select_open, + .write = pinmux_select, + .llseek = no_llseek, + .release = single_release, +}; + void pinmux_init_device_debugfs(struct dentry *devroot, struct pinctrl_dev *pctldev) { @@ -680,6 +780,8 @@ void pinmux_init_device_debugfs(struct dentry *devroot, devroot, pctldev, &pinmux_functions_fops); debugfs_create_file("pinmux-pins", 0444, devroot, pctldev, &pinmux_pins_fops); + debugfs_create_file("pinmux-select", 0200, + devroot, pctldev, &pinmux_select_ops); } #endif /* CONFIG_DEBUG_FS */