Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl/pinconfig: add debug interface

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 <laurent.meunier@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Laurent Meunier and committed by
Linus Walleij
f07512e6 06b62d82

+238
+232
drivers/pinctrl/pinconf.c
··· 17 17 #include <linux/slab.h> 18 18 #include <linux/debugfs.h> 19 19 #include <linux/seq_file.h> 20 + #include <linux/uaccess.h> 20 21 #include <linux/pinctrl/machine.h> 21 22 #include <linux/pinctrl/pinctrl.h> 22 23 #include <linux/pinctrl/pinconf.h> ··· 575 574 .release = single_release, 576 575 }; 577 576 577 + #define MAX_NAME_LEN 15 578 + 579 + struct dbg_cfg { 580 + enum pinctrl_map_type map_type; 581 + char dev_name[MAX_NAME_LEN+1]; 582 + char state_name[MAX_NAME_LEN+1]; 583 + char pin_name[MAX_NAME_LEN+1]; 584 + }; 585 + 586 + /* 587 + * Goal is to keep this structure as global in order to simply read the 588 + * pinconf-config file after a write to check config is as expected 589 + */ 590 + static struct dbg_cfg pinconf_dbg_conf; 591 + 592 + /** 593 + * pinconf_dbg_config_print() - display the pinctrl config from the pinctrl 594 + * map, of the dev/pin/state that was last written to pinconf-config file. 595 + * @s: string filled in with config description 596 + * @d: not used 597 + */ 598 + static int pinconf_dbg_config_print(struct seq_file *s, void *d) 599 + { 600 + struct pinctrl_maps *maps_node; 601 + const struct pinctrl_map *map; 602 + struct pinctrl_dev *pctldev = NULL; 603 + const struct pinconf_ops *confops = NULL; 604 + const struct pinctrl_map_configs *configs; 605 + struct dbg_cfg *dbg = &pinconf_dbg_conf; 606 + int i, j; 607 + bool found = false; 608 + unsigned long config; 609 + 610 + mutex_lock(&pinctrl_mutex); 611 + 612 + /* Parse the pinctrl map and look for the elected pin/state */ 613 + for_each_maps(maps_node, i, map) { 614 + if (map->type != dbg->map_type) 615 + continue; 616 + if (strcmp(map->dev_name, dbg->dev_name)) 617 + continue; 618 + if (strcmp(map->name, dbg->state_name)) 619 + continue; 620 + 621 + for (j = 0; j < map->data.configs.num_configs; j++) { 622 + if (!strcmp(map->data.configs.group_or_pin, 623 + dbg->pin_name)) { 624 + /* 625 + * We found the right pin / state, read the 626 + * config and he pctldev for later use 627 + */ 628 + configs = &map->data.configs; 629 + pctldev = get_pinctrl_dev_from_devname 630 + (map->ctrl_dev_name); 631 + found = true; 632 + break; 633 + } 634 + } 635 + } 636 + 637 + if (!found) { 638 + seq_printf(s, "No config found for dev/state/pin, expected:\n"); 639 + seq_printf(s, "Searched dev:%s\n", dbg->dev_name); 640 + seq_printf(s, "Searched state:%s\n", dbg->state_name); 641 + seq_printf(s, "Searched pin:%s\n", dbg->pin_name); 642 + seq_printf(s, "Use: modify config_pin <devname> "\ 643 + "<state> <pinname> <value>\n"); 644 + goto exit; 645 + } 646 + 647 + config = *(configs->configs); 648 + seq_printf(s, "Dev %s has config of %s in state %s: 0x%08lX\n", 649 + dbg->dev_name, dbg->pin_name, 650 + dbg->state_name, config); 651 + 652 + if (pctldev) 653 + confops = pctldev->desc->confops; 654 + 655 + if (confops && confops->pin_config_config_dbg_show) 656 + confops->pin_config_config_dbg_show(pctldev, s, config); 657 + 658 + exit: 659 + mutex_unlock(&pinctrl_mutex); 660 + 661 + return 0; 662 + } 663 + 664 + /** 665 + * pinconf_dbg_config_write() - modify the pinctrl config in the pinctrl 666 + * map, of a dev/pin/state entry based on user entries to pinconf-config 667 + * @user_buf: contains the modification request with expected format: 668 + * modify config_pin <devicename> <state> <pinname> <newvalue> 669 + * modify is literal string, alternatives like add/delete not supported yet 670 + * config_pin is literal, alternatives like config_mux not supported yet 671 + * <devicename> <state> <pinname> are values that should match the pinctrl-maps 672 + * <newvalue> reflects the new config and is driver dependant 673 + */ 674 + static int pinconf_dbg_config_write(struct file *file, 675 + const char __user *user_buf, size_t count, loff_t *ppos) 676 + { 677 + struct pinctrl_maps *maps_node; 678 + const struct pinctrl_map *map; 679 + struct pinctrl_dev *pctldev = NULL; 680 + const struct pinconf_ops *confops = NULL; 681 + struct dbg_cfg *dbg = &pinconf_dbg_conf; 682 + const struct pinctrl_map_configs *configs; 683 + char config[MAX_NAME_LEN+1]; 684 + bool found = false; 685 + char buf[128]; 686 + char *b = &buf[0]; 687 + int buf_size; 688 + char *token; 689 + int i; 690 + 691 + /* Get userspace string and assure termination */ 692 + buf_size = min(count, (sizeof(buf)-1)); 693 + if (copy_from_user(buf, user_buf, buf_size)) 694 + return -EFAULT; 695 + buf[buf_size] = 0; 696 + 697 + /* 698 + * need to parse entry and extract parameters: 699 + * modify configs_pin devicename state pinname newvalue 700 + */ 701 + 702 + /* Get arg: 'modify' */ 703 + token = strsep(&b, " "); 704 + if (!token) 705 + return -EINVAL; 706 + if (strcmp(token, "modify")) 707 + return -EINVAL; 708 + 709 + /* Get arg type: "config_pin" type supported so far */ 710 + token = strsep(&b, " "); 711 + if (!token) 712 + return -EINVAL; 713 + if (strcmp(token, "config_pin")) 714 + return -EINVAL; 715 + dbg->map_type = PIN_MAP_TYPE_CONFIGS_PIN; 716 + 717 + /* get arg 'device_name' */ 718 + token = strsep(&b, " "); 719 + if (token == NULL) 720 + return -EINVAL; 721 + if (strlen(token) >= MAX_NAME_LEN) 722 + return -EINVAL; 723 + strncpy(dbg->dev_name, token, MAX_NAME_LEN); 724 + 725 + /* get arg 'state_name' */ 726 + token = strsep(&b, " "); 727 + if (token == NULL) 728 + return -EINVAL; 729 + if (strlen(token) >= MAX_NAME_LEN) 730 + return -EINVAL; 731 + strncpy(dbg->state_name, token, MAX_NAME_LEN); 732 + 733 + /* get arg 'pin_name' */ 734 + token = strsep(&b, " "); 735 + if (token == NULL) 736 + return -EINVAL; 737 + if (strlen(token) >= MAX_NAME_LEN) 738 + return -EINVAL; 739 + strncpy(dbg->pin_name, token, MAX_NAME_LEN); 740 + 741 + /* get new_value of config' */ 742 + token = strsep(&b, " "); 743 + if (token == NULL) 744 + return -EINVAL; 745 + if (strlen(token) >= MAX_NAME_LEN) 746 + return -EINVAL; 747 + strncpy(config, token, MAX_NAME_LEN); 748 + 749 + mutex_lock(&pinctrl_mutex); 750 + 751 + /* Parse the pinctrl map and look for the selected dev/state/pin */ 752 + for_each_maps(maps_node, i, map) { 753 + if (strcmp(map->dev_name, dbg->dev_name)) 754 + continue; 755 + if (map->type != dbg->map_type) 756 + continue; 757 + if (strcmp(map->name, dbg->state_name)) 758 + continue; 759 + 760 + /* we found the right pin / state, so overwrite config */ 761 + if (!strcmp(map->data.configs.group_or_pin, dbg->pin_name)) { 762 + found = true; 763 + pctldev = get_pinctrl_dev_from_devname( 764 + map->ctrl_dev_name); 765 + configs = &map->data.configs; 766 + break; 767 + } 768 + } 769 + 770 + if (!found) { 771 + goto exit; 772 + count = -EINVAL; 773 + } 774 + 775 + if (pctldev) 776 + confops = pctldev->desc->confops; 777 + 778 + if (confops && confops->pin_config_dbg_parse_modify) { 779 + for (i = 0; i < configs->num_configs; i++) { 780 + confops->pin_config_dbg_parse_modify(pctldev, 781 + config, 782 + &configs->configs[i]); 783 + } 784 + } 785 + 786 + exit: 787 + mutex_unlock(&pinctrl_mutex); 788 + 789 + return count; 790 + } 791 + 792 + static int pinconf_dbg_config_open(struct inode *inode, struct file *file) 793 + { 794 + return single_open(file, pinconf_dbg_config_print, inode->i_private); 795 + } 796 + 797 + static const struct file_operations pinconf_dbg_pinconfig_fops = { 798 + .open = pinconf_dbg_config_open, 799 + .write = pinconf_dbg_config_write, 800 + .read = seq_read, 801 + .llseek = seq_lseek, 802 + .release = single_release, 803 + .owner = THIS_MODULE, 804 + }; 805 + 578 806 void pinconf_init_device_debugfs(struct dentry *devroot, 579 807 struct pinctrl_dev *pctldev) 580 808 { ··· 811 581 devroot, pctldev, &pinconf_pins_ops); 812 582 debugfs_create_file("pinconf-groups", S_IFREG | S_IRUGO, 813 583 devroot, pctldev, &pinconf_groups_ops); 584 + debugfs_create_file("pinconf-config", (S_IRUGO | S_IWUSR | S_IWGRP), 585 + devroot, pctldev, &pinconf_dbg_pinconfig_fops); 814 586 } 815 587 816 588 #endif
+6
include/linux/pinctrl/pinconf.h
··· 14 14 15 15 #ifdef CONFIG_PINCONF 16 16 17 + #include <linux/pinctrl/machine.h> 18 + 17 19 struct pinctrl_dev; 18 20 struct seq_file; 19 21 ··· 30 28 * @pin_config_set: configure an individual pin 31 29 * @pin_config_group_get: get configurations for an entire pin group 32 30 * @pin_config_group_set: configure all pins in a group 31 + * @pin_config_group_dbg_set: optional debugfs to modify a pin configuration 33 32 * @pin_config_dbg_show: optional debugfs display hook that will provide 34 33 * per-device info for a certain pin in debugfs 35 34 * @pin_config_group_dbg_show: optional debugfs display hook that will provide ··· 54 51 int (*pin_config_group_set) (struct pinctrl_dev *pctldev, 55 52 unsigned selector, 56 53 unsigned long config); 54 + int (*pin_config_dbg_parse_modify) (struct pinctrl_dev *pctldev, 55 + const char *arg, 56 + unsigned long *config); 57 57 void (*pin_config_dbg_show) (struct pinctrl_dev *pctldev, 58 58 struct seq_file *s, 59 59 unsigned offset);