From patchwork Wed Apr 3 19:47:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 15884 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 7556923E2C for ; Wed, 3 Apr 2013 19:47:47 +0000 (UTC) Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by fiordland.canonical.com (Postfix) with ESMTP id 489FEA189A8 for ; Wed, 3 Apr 2013 19:47:47 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gw10sf2811837lab.3 for ; Wed, 03 Apr 2013 12:47:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf:x-received :x-forwarded-to:x-forwarded-for:delivered-to:x-received:received-spf :from:to:cc:subject:date:message-id:x-mailer:mime-version :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=fD1px2zu5GUOZjamkCEkgSUHRMfXw2Are99x3umUIRM=; b=HJMvk4xpqpJA7dnInswhiXI6xiD7j/mPPem4X5HqX4DLTUda/A+WBpJbk7TS79pjlH TPMnwRACByonkCDQnYRXMM0nyhRUwvj2pIy2dT/cN6fmb0bEj1hE0bvEcWc1+dS/aTpy JwL5OppWHyj6+yXCsHhxtbdmHmUtKiu5VqWt0VG72hG+1NGqnx7qxLEJNECBetrwEKob WUdYmd3aIFsuiT3vX7ixYnyWr3Uam8cv46RDIjr/7llZZWSjZFW1hkcc6Aszm6hB73r4 vH9Hfi+5CQg83jdT7KL668izHxpQWKTXvXHYVPf0NFXJvA9Gqc+14asK4FPWvIYLJRga Lr9Q== X-Received: by 10.180.182.229 with SMTP id eh5mr4769820wic.1.1365018466874; Wed, 03 Apr 2013 12:47:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.181.13.242 with SMTP id fb18ls745051wid.22.gmail; Wed, 03 Apr 2013 12:47:46 -0700 (PDT) X-Received: by 10.194.157.42 with SMTP id wj10mr4986603wjb.12.1365018466435; Wed, 03 Apr 2013 12:47:46 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id bl9si3076778wib.102.2013.04.03.12.47.46 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 12:47:46 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id jw11so1995387veb.8 for ; Wed, 03 Apr 2013 12:47:45 -0700 (PDT) X-Received: by 10.52.233.225 with SMTP id tz1mr2112106vdc.54.1365018465230; Wed, 03 Apr 2013 12:47:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp185071ved; Wed, 3 Apr 2013 12:47:44 -0700 (PDT) X-Received: by 10.14.210.8 with SMTP id t8mr5659631eeo.35.1365018463513; Wed, 03 Apr 2013 12:47:43 -0700 (PDT) Received: from eu1sys200aog112.obsmtp.com (eu1sys200aog112.obsmtp.com [207.126.144.133]) by mx.google.com with SMTP id a9si9782776eem.245.2013.04.03.12.47.35 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Apr 2013 12:47:43 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.133 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.133; Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob112.postini.com ([207.126.147.11]) with SMTP ID DSNKUVyHV0j4E//kt23Ns6bweGXqPoGKuOhz@postini.com; Wed, 03 Apr 2013 19:47:42 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 59E6BA6; Wed, 3 Apr 2013 19:39:24 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 31820795; Wed, 3 Apr 2013 19:47:31 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 69EF8A8083; Wed, 3 Apr 2013 21:47:22 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.279.5; Wed, 3 Apr 2013 21:47:29 +0200 From: Linus Walleij To: , Cc: Stephen Warren , Anmar Oueja , Laurent Meunier , Linus Walleij Subject: [PATCH v2] pinctrl/pinconfig: add debug interface Date: Wed, 3 Apr 2013 21:47:27 +0200 Message-ID: <1365018447-28062-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkZ5I/cUL3z8Jtm+786GHmhaZilx30ZZAWg7Lk0TifsFh4FES9qyMBRWz6Y8z6z+AZuHjx1 X-Original-Sender: linus.walleij@stericsson.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Laurent Meunier This update adds a debugfs interface to modify a pin configuration for a given state in the pinctrl map. This allows to modify the configuration for a non-active state, typically sleep state. This configuration is not applied right away, but only when the state will be entered. This solution is mandated for us by HW validation: in order to test and verify several pin configurations during sleep without recompiling the software. Signed-off-by: Laurent Meunier Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Change name of the debugfs string processing function in the driver API to pin_config_dbg_parse() because that is what it shall do, then have that be passed a pointer to fill in the parsed result. --- drivers/pinctrl/pinconf.c | 231 ++++++++++++++++++++++++++++++++++++++++ include/linux/pinctrl/pinconf.h | 4 + 2 files changed, 235 insertions(+) diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index baee2cc..faabc25 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -574,6 +575,234 @@ static const struct file_operations pinconf_groups_ops = { .release = single_release, }; +/* 32bit read/write resources */ +#define MAX_NAME_LEN 15 + +enum pinconf_dbg_request_type { + PINCONF_DBG_REQ_TYPE_INVALID, + PINCONF_DBG_REQ_TYPE_MODIFY, +}; + +struct dbg_cfg { + enum pinconf_dbg_request_type req_type; + enum pinctrl_map_type map_type; + char dev_name[MAX_NAME_LEN+1]; + char state_name[MAX_NAME_LEN+1]; + char pin_name[MAX_NAME_LEN+1]; + char config[MAX_NAME_LEN+1]; +}; + +static struct dbg_cfg pinconf_dbg_conf; + +/** + * pinconf_dbg_config_print() - display the pinctrl config from the pinctrl + * map, of a pin/state pair based on pinname and state that have been + * selected with the debugfs entries pinconf-name and pinconf-state + * @s: contains the 32bits config to be written + * @d: not used + */ +static int pinconf_dbg_config_print(struct seq_file *s, void *d) +{ + struct pinctrl_maps *maps_node; + struct pinctrl_map const *map; + struct pinctrl_dev *pctldev = NULL; + struct pinconf_ops const *confops = NULL; + int i, j; + bool found = false; + struct dbg_cfg *dbg = &pinconf_dbg_conf; + unsigned long config = 0; + + mutex_lock(&pinctrl_mutex); + + /* Parse the pinctrl map and look for the elected pin/state */ + for_each_maps(maps_node, i, map) { + if (map->type != dbg->map_type) + continue; + if (strncmp(map->dev_name, dbg->dev_name, MAX_NAME_LEN) != 0) + continue; + if (strncmp(map->name, dbg->state_name, MAX_NAME_LEN) != 0) + continue; + + for (j = 0; j < map->data.configs.num_configs; j++) { + if (0 == strncmp(map->data.configs.group_or_pin, + dbg->pin_name, MAX_NAME_LEN)) { + /* + * We found the right pin / state, read the + * config and store the pctldev + */ + config = map->data.configs.configs[j]; + pctldev = get_pinctrl_dev_from_devname + (map->ctrl_dev_name); + found = true; + break; + } + } + } + + mutex_unlock(&pinctrl_mutex); + + if (!found) { + seq_printf(s, "No config found for dev/state/pin, expected:\n"); + seq_printf(s, "modify config_pins devname " \ + "state pinname value\n"); + } + + seq_printf(s, "Dev %s has config of %s in state %s: 0x%08lX\n", + dbg->dev_name, dbg->pin_name, + dbg->state_name, config); + + if (pctldev) + confops = pctldev->desc->confops; + + if (confops && confops->pin_config_config_dbg_show) + confops->pin_config_config_dbg_show(pctldev, + s, config); + return 0; +} + +/** + * pinconf_dbg_config_write() - overwrite the pinctrl config in the pinctrl + * map, of a pin/state pair based on pinname and state that have been + * selected with the debugfs entries pinconf-name and pinconf-state + * @user_buf: contains 'modify configs_pin devicename state pinname newvalue' + */ +static int pinconf_dbg_config_write(struct file *file, + const char __user *user_buf, size_t count, loff_t *ppos) +{ + struct pinctrl_maps *maps_node; + struct pinctrl_map const *map; + struct pinctrl_dev *pctldev = NULL; + struct pinconf_ops const *confops = NULL; + struct dbg_cfg *dbg = &pinconf_dbg_conf; + bool found = false; + char buf[128]; + char *b = &buf[0]; + int buf_size; + char *token; + struct pinctrl_map_configs const *configs; + int i; + + /* Get userspace string and assure termination */ + buf_size = min(count, (sizeof(buf)-1)); + if (copy_from_user(buf, user_buf, buf_size)) + return -EFAULT; + + buf[buf_size] = 0; + + /* + * need to parse entry and extract parameters: + * modify configs_pin devicename state pinname newvalue + */ + + /* Get arg: 'modify' */ + if (!strncmp(b, "modify ", strlen("modify "))) { + dbg->req_type = PINCONF_DBG_REQ_TYPE_MODIFY; + b += strlen("modify "); + } else { + return -EINVAL; + } + + /* Get arg type: "config_pin" type supported so far */ + if (!strncmp(b, "config_pins ", strlen("config_pins "))) { + dbg->map_type = PIN_MAP_TYPE_CONFIGS_PIN; + b += strlen("config_pins "); + } else { + return -EINVAL; + } + + /* get arg 'device_name' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) < MAX_NAME_LEN) + sscanf(token, "%s", dbg->dev_name); + else + return -EINVAL; + + /* get arg 'state_name' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) < MAX_NAME_LEN) + sscanf(token, "%s", dbg->state_name); + else + return -EINVAL; + + /* get arg 'pin_name' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) < MAX_NAME_LEN) + sscanf(token, "%s", dbg->pin_name); + else + return -EINVAL; + + /* get new_value of config' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + + if (strlen(token) < MAX_NAME_LEN) + sscanf(token, "%s", dbg->config); + else + return -EINVAL; + + mutex_lock(&pinctrl_mutex); + + /* Parse the pinctrl map and look for the selected dev/state/pin */ + for_each_maps(maps_node, i, map) { + if (strncmp(map->dev_name, dbg->dev_name, MAX_NAME_LEN) != 0) + continue; + if (map->type != dbg->map_type) + continue; + if (strncmp(map->name, dbg->state_name, MAX_NAME_LEN) != 0) + continue; + + /* we found the right pin / state, so overwrite config */ + if (strncmp(map->data.configs.group_or_pin, + dbg->pin_name, MAX_NAME_LEN) == 0) { + + found = true; + pctldev = get_pinctrl_dev_from_devname( + map->ctrl_dev_name); + configs = &map->data.configs; + break; + } + } + + mutex_unlock(&pinctrl_mutex); + + if (!found) + return -EINVAL; + + if (pctldev) + confops = pctldev->desc->confops; + + if (confops && confops->pin_config_dbg_parse) { + for (i = 0; i < configs->num_configs; i++) { + confops->pin_config_dbg_parse(pctldev, + dbg->config, + &configs->configs[i]); + } + } + + return count; +} + +static int pinconf_dbg_config_open(struct inode *inode, struct file *file) +{ + return single_open(file, pinconf_dbg_config_print, inode->i_private); +} + +static const struct file_operations pinconf_dbg_pinconfig_fops = { + .open = pinconf_dbg_config_open, + .write = pinconf_dbg_config_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner = THIS_MODULE, +}; + void pinconf_init_device_debugfs(struct dentry *devroot, struct pinctrl_dev *pctldev) { @@ -581,6 +810,8 @@ void pinconf_init_device_debugfs(struct dentry *devroot, devroot, pctldev, &pinconf_pins_ops); debugfs_create_file("pinconf-groups", S_IFREG | S_IRUGO, devroot, pctldev, &pinconf_groups_ops); + debugfs_create_file("pinconf-config", (S_IRUGO | S_IWUSR | S_IWGRP), + devroot, pctldev, &pinconf_dbg_pinconfig_fops); } #endif diff --git a/include/linux/pinctrl/pinconf.h b/include/linux/pinctrl/pinconf.h index e7a7201..fbe02de 100644 --- a/include/linux/pinctrl/pinconf.h +++ b/include/linux/pinctrl/pinconf.h @@ -28,6 +28,7 @@ struct seq_file; * @pin_config_set: configure an individual pin * @pin_config_group_get: get configurations for an entire pin group * @pin_config_group_set: configure all pins in a group + * @pin_config_dbg_parse: optional debugfs to parse a string pin configuration * @pin_config_dbg_show: optional debugfs display hook that will provide * per-device info for a certain pin in debugfs * @pin_config_group_dbg_show: optional debugfs display hook that will provide @@ -51,6 +52,9 @@ struct pinconf_ops { int (*pin_config_group_set) (struct pinctrl_dev *pctldev, unsigned selector, unsigned long config); + int (*pin_config_dbg_parse) (struct pinctrl_dev *pctldev, + const char *arg, + unsigned long *config); void (*pin_config_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s, unsigned offset);