Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6853685pxb; Wed, 17 Feb 2021 15:44:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsRkDSjEFyvXI6wVP3oIdxOQyH2puLALzok7+gfVGBDAaXH4zzGlP12a5NNNxwsgKlcqHD X-Received: by 2002:aa7:ce8a:: with SMTP id y10mr1212183edv.77.1613605472647; Wed, 17 Feb 2021 15:44:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613605472; cv=none; d=google.com; s=arc-20160816; b=yo/TehlcO5Mi9yCIo7pPU10tdqSeuf48Ab3obqkzBH3axHSJFn/9x7z66MaZ1syqbE u8sm7XNSs8vD91t1t6QCU6kXtgme9EJ/UyaGw3gZ7ZML9DzuFBdm0YOOC5m5TtcdmWeX PkC/LgiMTq8J88QfRdxTxuIM5kb1hXledPgluj1IVn13KRem7qVcLJ/bHqT2iOTSNKLA uFl8z+a39LClA+1ik4JAvpAEYFo8GHVijnzeokiU54Q3Iyj6/NnIKhN0XTybU81tCnvl gUvnwnXf4cRYSV6m0tHyflus07WOthdnXhnu+aWxEYCFQizWYmpohDOCoL11CDOJ9dfU 6aKA== 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=mYrs5q+oZ0V8NFKgrQvhQijPLQDbqQrnbdDwL86thTE=; b=SL0tkpgNA64lINR9Q4xNHbq7CQMnmBvjCsCASU7kJa5v4X11NbGdqO6lsd5pARFq8v Nj3saes+atXVYpyGXmZ4ydbwbNtSd/H6BfvyWdY2HwyZUSSuqomELgv+KARP0vx8rUPS N2ZNr+anBIl8sz9mR4YaXoVexB56V2Ha2GdvSDK8PYNupLQBq7mWWsHuhi0TtkyY1LYs plHbYfVMP1fAQME0Hpn61cael5RP4uN21zneRlOGkqZPhn4gxwaqoKLm8QkwUQldtplo 38IK9I2Pl4tiILm3x7GBCn49nzNxVwoy7uVfTO16Wh/IX39zd7wquhjs8wYSTPiWaTwC NwjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b="v7itPVT/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bg11si2324397ejb.283.2021.02.17.15.43.28; Wed, 17 Feb 2021 15:44:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b="v7itPVT/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233391AbhBQWQk (ORCPT + 99 others); Wed, 17 Feb 2021 17:16:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233287AbhBQWQf (ORCPT ); Wed, 17 Feb 2021 17:16:35 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA4F1C06178B for ; Wed, 17 Feb 2021 14:15:17 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id f8so98404plg.5 for ; Wed, 17 Feb 2021 14:15:17 -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=mYrs5q+oZ0V8NFKgrQvhQijPLQDbqQrnbdDwL86thTE=; b=v7itPVT/J8mcy/0YO0mjmXVgBZzDH0nevKAgtlM/qRxHJSQn89poN+TW42IJvBeaKS GK+lk5HR45pihNvKh1tmaQnt58AbBOfsj8PYqYlNWoSuggCj6qIdI9QycWQ+LyQEoGrw QpkcRXDPg5Iq2Ymc8iOTh5h59sNHVXO35khqgqxzzf4fLjZbeMLKSy7f8MF1vhMcsNjL ixROEJYs4/3Ua316RElrE1p1HnsdxjQHb48Egt2h9w0wHPB5jKijKw9fVHXje5UDJ4Yn IJAx9SBwAEScAH4jJ1ykrhKzzkJo6XlbJglc4kOMcszgD/GieKDuY9bzaEtfWgBjSfX9 FYJQ== 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=mYrs5q+oZ0V8NFKgrQvhQijPLQDbqQrnbdDwL86thTE=; b=IGGvZ+dTM8Pl337FQ9RCuaOSmHFBHLP/iq1Tv98oiuSBKPzZYka++wrDY8Cpf1LwPZ 0jJPSqlSWHPwvcryJ6WokRzDH1axEDX34pX62MR0q9F8wRVq7S3gQzT6eRVUzZGu5lbx xJqG8zxTtyLv+rczZoN+lWHBg620GQ4F8lGTQrgvJL9fnzI+epQclxjn64ksSG9VLUip OOq0LmnTbCsyz+MhjckPgR0tWzMWVW+lp5Ox7nru2XcfoZQVYI6UVmKILysEAmyUKdo4 nAgJOZlspEXKoH2LTleOhNXFlYIxEoSxl3vpllPfPcG3WbZKkCcaDL8RMF4sLbXZoYXP 6Vmw== X-Gm-Message-State: AOAM532ae4xtSRC/YBhHx8kkpuB8dEH5VYvcKFyU+8T4wNZOVXMH99uT u1b0QV2YuZOstH1HQCV1qVJ9hA== X-Received: by 2002:a17:90a:67ca:: with SMTP id g10mr957292pjm.28.1613600117391; Wed, 17 Feb 2021 14:15:17 -0800 (PST) Received: from x1.hsd1.or.comcast.net ([2601:1c0:4701:ae70:c31f:9bea:96ec:ef07]) by smtp.gmail.com with ESMTPSA id q43sm3142591pjq.25.2021.02.17.14.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 14:15:16 -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 Subject: [PATCH v7 2/3] pinctrl: pinmux: Add pinmux-select debugfs file Date: Wed, 17 Feb 2021 14:14:57 -0800 Message-Id: <20210217221457.1827266-3-drew@beagleboard.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210217221457.1827266-1-drew@beagleboard.org> References: <20210217221457.1827266-1-drew@beagleboard.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add "pinmux-select" to debugfs which will activate a function and 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 and group pinmux-i2c1-pins: echo "pinmux-i2c1 pinmux-i2c1-pins" > pinmux-select Reviewed-by: Andy Shevchenko Reviewed-by: Tony Lindgren 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..39770af56562 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 50 +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, *fname, *gname; + 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 */ + fname = strstrip(buf); + if (*fname == '\0') { + ret = -EINVAL; + goto exit_free_buf; + } + + /* find a separator which is a spacelike character */ + for (gname = fname; !isspace(*gname); gname++) { + if (*gname == '\0') { + ret = -EINVAL; + goto exit_free_buf; + } + } + *gname = '\0'; + + /* drop extra spaces between function and group names */ + gname = skip_spaces(gname + 1); + if (*gname == '\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 */ -- 2.25.1