From patchwork Thu Apr 18 10:35:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 16231 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f198.google.com (mail-gg0-f198.google.com [209.85.161.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 81F8623974 for ; Thu, 18 Apr 2013 10:36:19 +0000 (UTC) Received: by mail-gg0-f198.google.com with SMTP id a5sf3708172ggn.9 for ; Thu, 18 Apr 2013 03:35:42 -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=NXg+bz0vKrbSj4Wmw4rivqONGEz7TYHSf9MccapzXbM=; b=QdOsILZZPLx2024ndtRxJajViPqwBahsnCrli+S28FmliAOlCFBbDtFyTq+uDcC435 rBvRBmpYErpKB4SsFl8MzWO+utXxxQSlCiIMoq3qVDxJjslzIZvImQO76c3iT2NN227c Gkm7m9knsxb4FhWAL05ZhcZM04rX2ZGVzfMizYl78Spdg4yPpK4IKNURI4/8+5SV1gem dZGVfgdXHdDivCE7R+lD6jogpqY3UrgnAljITpTN4bgVVBcOW4dHZQJzv1V2Hs9BWAd/ ukXYQ8XgwqmqxkjC3gGCo4OtIgRQjfu+D3e0A0G9d2P5dm7pkJnum44r2tNE8AZaX1+7 eZZw== X-Received: by 10.224.215.194 with SMTP id hf2mr7337807qab.0.1366281342444; Thu, 18 Apr 2013 03:35:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.3.41 with SMTP id 9ls1541321qez.41.gmail; Thu, 18 Apr 2013 03:35:42 -0700 (PDT) X-Received: by 10.52.101.129 with SMTP id fg1mr6522266vdb.112.1366281342230; Thu, 18 Apr 2013 03:35:42 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id sa4si6284245vdc.36.2013.04.18.03.35.42 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Apr 2013 03:35:42 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id ha12so2266846vcb.16 for ; Thu, 18 Apr 2013 03:35:42 -0700 (PDT) X-Received: by 10.58.84.164 with SMTP id a4mr7121628vez.9.1366281341928; Thu, 18 Apr 2013 03:35:41 -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.58.127.98 with SMTP id nf2csp116667veb; Thu, 18 Apr 2013 03:35:41 -0700 (PDT) X-Received: by 10.14.175.134 with SMTP id z6mr28820970eel.15.1366281339140; Thu, 18 Apr 2013 03:35:39 -0700 (PDT) Received: from eu1sys200aog113.obsmtp.com (eu1sys200aog113.obsmtp.com [207.126.144.135]) by mx.google.com with SMTP id m41si14917715een.3.2013.04.18.03.35.30 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 18 Apr 2013 03:35:39 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.135 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.135; Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob113.postini.com ([207.126.147.11]) with SMTP ID DSNKUW/McQmpGdGspc+BPMElKncaBenOF9B4@postini.com; Thu, 18 Apr 2013 10:35:38 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 861B841; Thu, 18 Apr 2013 10:34:28 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id DF5F54A; Thu, 18 Apr 2013 03:46:57 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 70EFD24C07D; Thu, 18 Apr 2013 12:35:15 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.279.5; Thu, 18 Apr 2013 12:35:20 +0200 From: Linus Walleij To: , Cc: Stephen Warren , Anmar Oueja , Laurent Meunier , Linus Walleij Subject: [PATCH v3] pinctrl/pinconfig: add debug interface Date: Thu, 18 Apr 2013 12:35:14 +0200 Message-ID: <1366281314-14613-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: ALoCoQmA39d8y1/+CBFnAJhgvK8/HLbffmiu3uCn0TKvLgtuny/71ZdrTHJlwTL1uXZ348XYcWeQ X-Original-Sender: linus.walleij@stericsson.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.171 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. Change log in this patch set; Take into account latest feedback from Stephen Warren: - stale comments update - improved code efficiency and readibility - limit size of global variable pinconf_dbg_conf - remove req_type as it can easily be added later when add/delete requests support is implemented Signed-off-by: Laurent Meunier Signed-off-by: Linus Walleij --- drivers/pinctrl/pinconf.c | 232 ++++++++++++++++++++++++++++++++++++++++ include/linux/pinctrl/pinconf.h | 6 ++ 2 files changed, 238 insertions(+) diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index baee2cc..1b6047d 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,235 @@ static const struct file_operations pinconf_groups_ops = { .release = single_release, }; +#define MAX_NAME_LEN 15 + +struct dbg_cfg { + 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]; +}; + +/* + * Goal is to keep this structure as global in order to simply read the + * pinconf-config file after a write to check config is as expected + */ +static struct dbg_cfg pinconf_dbg_conf; + +/** + * pinconf_dbg_config_print() - display the pinctrl config from the pinctrl + * map, of the dev/pin/state that was last written to pinconf-config file. + * @s: string filled in with config description + * @d: not used + */ +static int pinconf_dbg_config_print(struct seq_file *s, void *d) +{ + struct pinctrl_maps *maps_node; + const struct pinctrl_map *map; + struct pinctrl_dev *pctldev = NULL; + const struct pinconf_ops *confops = NULL; + const struct pinctrl_map_configs *configs; + struct dbg_cfg *dbg = &pinconf_dbg_conf; + int i, j; + bool found = false; + unsigned long config; + + 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 (!!strcmp(map->dev_name, dbg->dev_name)) + continue; + if (!!strcmp(map->name, dbg->state_name)) + continue; + + for (j = 0; j < map->data.configs.num_configs; j++) { + if (!strcmp(map->data.configs.group_or_pin, + dbg->pin_name)) { + /* + * We found the right pin / state, read the + * config and he pctldev for later use + */ + configs = &map->data.configs; + pctldev = get_pinctrl_dev_from_devname + (map->ctrl_dev_name); + found = true; + break; + } + } + } + + if (!found) { + seq_printf(s, "No config found for dev/state/pin, expected:\n"); + seq_printf(s, "Searched dev:%s\n", dbg->dev_name); + seq_printf(s, "Searched state:%s\n", dbg->state_name); + seq_printf(s, "Searched pin:%s\n", dbg->pin_name); + seq_printf(s, "Use: modify config_pin "\ + " \n"); + goto exit; + } + + config = *(configs->configs); + 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); + +exit: + mutex_unlock(&pinctrl_mutex); + + return 0; +} + +/** + * pinconf_dbg_config_write() - modify the pinctrl config in the pinctrl + * map, of a dev/pin/state entry based on user entries to pinconf-config + * @user_buf: contains the modification request with expected format: + * modify config_pin + * modify is literal string, alternatives like add/delete not supported yet + * config_pin is literal, alternatives like config_mux not supported yet + * are values that should match the pinctrl-maps + * reflects the new config and is driver dependant + */ +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; + const struct pinctrl_map *map; + struct pinctrl_dev *pctldev = NULL; + const struct pinconf_ops *confops = NULL; + struct dbg_cfg *dbg = &pinconf_dbg_conf; + const struct pinctrl_map_configs *configs; + char config[MAX_NAME_LEN+1]; + bool found = false; + char buf[128]; + char *b = &buf[0]; + int buf_size; + char *token; + 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' */ + token = strsep(&b, " "); + if (!token) + return -EINVAL; + if (!!strcmp(token, "modify")) + return -EINVAL; + + /* Get arg type: "config_pin" type supported so far */ + token = strsep(&b, " "); + if (!token) + return -EINVAL; + if (!!strcmp(token, "config_pin")) + return -EINVAL; + dbg->map_type = PIN_MAP_TYPE_CONFIGS_PIN; + + /* get arg 'device_name' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) >= MAX_NAME_LEN) + return -EINVAL; + strncpy(dbg->dev_name, token, MAX_NAME_LEN); + + /* get arg 'state_name' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) >= MAX_NAME_LEN) + return -EINVAL; + strncpy(dbg->state_name, token, MAX_NAME_LEN); + + /* get arg 'pin_name' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) >= MAX_NAME_LEN) + return -EINVAL; + strncpy(dbg->pin_name, token, MAX_NAME_LEN); + + /* get new_value of config' */ + token = strsep(&b, " "); + if (token == NULL) + return -EINVAL; + if (strlen(token) >= MAX_NAME_LEN) + return -EINVAL; + strncpy(config, token, MAX_NAME_LEN); + + mutex_lock(&pinctrl_mutex); + + /* Parse the pinctrl map and look for the selected dev/state/pin */ + for_each_maps(maps_node, i, map) { + if (!!strcmp(map->dev_name, dbg->dev_name)) + continue; + if (map->type != dbg->map_type) + continue; + if (!!strcmp(map->name, dbg->state_name)) + continue; + + /* we found the right pin / state, so overwrite config */ + if (!strcmp(map->data.configs.group_or_pin, dbg->pin_name)) { + found = true; + pctldev = get_pinctrl_dev_from_devname( + map->ctrl_dev_name); + configs = &map->data.configs; + break; + } + } + + if (!found) { + goto exit; + count = -EINVAL; + } + + if (pctldev) + confops = pctldev->desc->confops; + + if (confops && confops->pin_config_dbg_parse_modify) { + for (i = 0; i < configs->num_configs; i++) { + confops->pin_config_dbg_parse_modify(pctldev, + config, + &configs->configs[i]); + } + } + +exit: + mutex_unlock(&pinctrl_mutex); + + 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 +811,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..1ad4f31 100644 --- a/include/linux/pinctrl/pinconf.h +++ b/include/linux/pinctrl/pinconf.h @@ -14,6 +14,8 @@ #ifdef CONFIG_PINCONF +#include + struct pinctrl_dev; struct seq_file; @@ -28,6 +30,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_group_dbg_set: optional debugfs to modify a 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 +54,9 @@ struct pinconf_ops { int (*pin_config_group_set) (struct pinctrl_dev *pctldev, unsigned selector, unsigned long config); + int (*pin_config_dbg_parse_modify) (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);