Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Core driver for the generic pin config portions of the pin control subsystem |
| 3 | * |
| 4 | * Copyright (C) 2011 ST-Ericsson SA |
| 5 | * Written on behalf of Linaro for ST-Ericsson |
| 6 | * |
| 7 | * Author: Linus Walleij <linus.walleij@linaro.org> |
| 8 | * |
| 9 | * License terms: GNU General Public License (GPL) version 2 |
| 10 | */ |
| 11 | |
| 12 | #define pr_fmt(fmt) "generic pinconfig core: " fmt |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/debugfs.h> |
| 19 | #include <linux/seq_file.h> |
| 20 | #include <linux/pinctrl/pinctrl.h> |
| 21 | #include <linux/pinctrl/pinconf.h> |
| 22 | #include <linux/pinctrl/pinconf-generic.h> |
| 23 | #include "core.h" |
| 24 | #include "pinconf.h" |
| 25 | |
| 26 | #ifdef CONFIG_DEBUG_FS |
| 27 | |
| 28 | struct pin_config_item { |
| 29 | const enum pin_config_param param; |
| 30 | const char * const display; |
| 31 | const char * const format; |
| 32 | }; |
| 33 | |
| 34 | #define PCONFDUMP(a, b, c) { .param = a, .display = b, .format = c } |
| 35 | |
| 36 | struct pin_config_item conf_items[] = { |
| 37 | PCONFDUMP(PIN_CONFIG_BIAS_DISABLE, "input bias disabled", NULL), |
| 38 | PCONFDUMP(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, "input bias high impedance", NULL), |
| 39 | PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", NULL), |
| 40 | PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", NULL), |
| 41 | PCONFDUMP(PIN_CONFIG_DRIVE_PUSH_PULL, "output drive push pull", NULL), |
| 42 | PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_DRAIN, "output drive open drain", NULL), |
| 43 | PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_SOURCE, "output drive open source", NULL), |
| 44 | PCONFDUMP(PIN_CONFIG_INPUT_SCHMITT, "input schmitt trigger", NULL), |
| 45 | PCONFDUMP(PIN_CONFIG_INPUT_DEBOUNCE, "input debounce", "time units"), |
| 46 | PCONFDUMP(PIN_CONFIG_POWER_SOURCE, "pin power source", "selector"), |
| 47 | PCONFDUMP(PIN_CONFIG_LOW_POWER_MODE, "pin low power", "mode"), |
| 48 | }; |
| 49 | |
| 50 | void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev, |
| 51 | struct seq_file *s, unsigned pin) |
| 52 | { |
| 53 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 54 | int i; |
| 55 | |
| 56 | if (!ops->is_generic) |
| 57 | return; |
| 58 | |
| 59 | for(i = 0; i < ARRAY_SIZE(conf_items); i++) { |
| 60 | unsigned long config; |
| 61 | int ret; |
| 62 | |
| 63 | /* We want to check out this parameter */ |
| 64 | config = pinconf_to_config_packed(conf_items[i].param, 0); |
| 65 | ret = pin_config_get_for_pin(pctldev, pin, &config); |
| 66 | /* These are legal errors */ |
| 67 | if (ret == -EINVAL || ret == -ENOTSUPP) |
| 68 | continue; |
| 69 | if (ret) { |
| 70 | seq_printf(s, "ERROR READING CONFIG SETTING %d ", i); |
| 71 | continue; |
| 72 | } |
| 73 | /* Space between multiple configs */ |
| 74 | seq_puts(s, " "); |
| 75 | seq_puts(s, conf_items[i].display); |
| 76 | /* Print unit if available */ |
| 77 | if (conf_items[i].format && |
| 78 | pinconf_to_config_argument(config) != 0) |
| 79 | seq_printf(s, " (%u %s)", |
| 80 | pinconf_to_config_argument(config), |
| 81 | conf_items[i].format); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, |
| 86 | struct seq_file *s, const char *gname) |
| 87 | { |
| 88 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 89 | int i; |
| 90 | |
| 91 | if (!ops->is_generic) |
| 92 | return; |
| 93 | |
| 94 | for(i = 0; i < ARRAY_SIZE(conf_items); i++) { |
| 95 | unsigned long config; |
| 96 | int ret; |
| 97 | |
| 98 | /* We want to check out this parameter */ |
| 99 | config = pinconf_to_config_packed(conf_items[i].param, 0); |
| 100 | ret = pin_config_group_get(dev_name(pctldev->dev), gname, |
| 101 | &config); |
| 102 | /* These are legal errors */ |
| 103 | if (ret == -EINVAL || ret == -ENOTSUPP) |
| 104 | continue; |
| 105 | if (ret) { |
| 106 | seq_printf(s, "ERROR READING CONFIG SETTING %d ", i); |
| 107 | continue; |
| 108 | } |
| 109 | /* Space between multiple configs */ |
| 110 | seq_puts(s, " "); |
| 111 | seq_puts(s, conf_items[i].display); |
| 112 | /* Print unit if available */ |
| 113 | if (conf_items[i].format && config != 0) |
| 114 | seq_printf(s, " (%u %s)", |
| 115 | pinconf_to_config_argument(config), |
| 116 | conf_items[i].format); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | #endif |