pinconf-generic.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #define pr_fmt(fmt) "generic pinconfig core: " fmt
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/device.h>
  15. #include <linux/slab.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/pinctrl/pinctrl.h>
  19. #include <linux/pinctrl/pinconf.h>
  20. #include <linux/pinctrl/pinconf-generic.h>
  21. #include "core.h"
  22. #include "pinconf.h"
  23. #ifdef CONFIG_DEBUG_FS
  24. struct pin_config_item {
  25. const enum pin_config_param param;
  26. const char * const display;
  27. const char * const format;
  28. };
  29. #define PCONFDUMP(a, b, c) { .param = a, .display = b, .format = c }
  30. struct pin_config_item conf_items[] = {
  31. PCONFDUMP(PIN_CONFIG_BIAS_DISABLE, "input bias disabled", NULL),
  32. PCONFDUMP(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, "input bias high impedance", NULL),
  33. PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", NULL),
  34. PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", NULL),
  35. PCONFDUMP(PIN_CONFIG_DRIVE_PUSH_PULL, "output drive push pull", NULL),
  36. PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_DRAIN, "output drive open drain", NULL),
  37. PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_SOURCE, "output drive open source", NULL),
  38. PCONFDUMP(PIN_CONFIG_INPUT_SCHMITT_ENABLE, "input schmitt enabled", NULL),
  39. PCONFDUMP(PIN_CONFIG_INPUT_SCHMITT, "input schmitt trigger", NULL),
  40. PCONFDUMP(PIN_CONFIG_INPUT_DEBOUNCE, "input debounce", "time units"),
  41. PCONFDUMP(PIN_CONFIG_POWER_SOURCE, "pin power source", "selector"),
  42. PCONFDUMP(PIN_CONFIG_SLEW_RATE, "slew rate", NULL),
  43. PCONFDUMP(PIN_CONFIG_LOW_POWER_MODE, "pin low power", "mode"),
  44. PCONFDUMP(PIN_CONFIG_OUTPUT, "pin output", "level"),
  45. };
  46. void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
  47. struct seq_file *s, unsigned pin)
  48. {
  49. const struct pinconf_ops *ops = pctldev->desc->confops;
  50. int i;
  51. if (!ops->is_generic)
  52. return;
  53. for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
  54. unsigned long config;
  55. int ret;
  56. /* We want to check out this parameter */
  57. config = pinconf_to_config_packed(conf_items[i].param, 0);
  58. ret = pin_config_get_for_pin(pctldev, pin, &config);
  59. /* These are legal errors */
  60. if (ret == -EINVAL || ret == -ENOTSUPP)
  61. continue;
  62. if (ret) {
  63. seq_printf(s, "ERROR READING CONFIG SETTING %d ", i);
  64. continue;
  65. }
  66. /* Space between multiple configs */
  67. seq_puts(s, " ");
  68. seq_puts(s, conf_items[i].display);
  69. /* Print unit if available */
  70. if (conf_items[i].format &&
  71. pinconf_to_config_argument(config) != 0)
  72. seq_printf(s, " (%u %s)",
  73. pinconf_to_config_argument(config),
  74. conf_items[i].format);
  75. }
  76. }
  77. void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
  78. struct seq_file *s, const char *gname)
  79. {
  80. const struct pinconf_ops *ops = pctldev->desc->confops;
  81. int i;
  82. if (!ops->is_generic)
  83. return;
  84. for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
  85. unsigned long config;
  86. int ret;
  87. /* We want to check out this parameter */
  88. config = pinconf_to_config_packed(conf_items[i].param, 0);
  89. ret = pin_config_group_get(dev_name(pctldev->dev), gname,
  90. &config);
  91. /* These are legal errors */
  92. if (ret == -EINVAL || ret == -ENOTSUPP)
  93. continue;
  94. if (ret) {
  95. seq_printf(s, "ERROR READING CONFIG SETTING %d ", i);
  96. continue;
  97. }
  98. /* Space between multiple configs */
  99. seq_puts(s, " ");
  100. seq_puts(s, conf_items[i].display);
  101. /* Print unit if available */
  102. if (conf_items[i].format && config != 0)
  103. seq_printf(s, " (%u %s)",
  104. pinconf_to_config_argument(config),
  105. conf_items[i].format);
  106. }
  107. }
  108. #endif