pinconf-generic.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_DISABLE, "input schmitt disabled", 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_LOW_POWER_MODE, "pin low power", "mode"),
  43. };
  44. void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
  45. struct seq_file *s, unsigned pin)
  46. {
  47. const struct pinconf_ops *ops = pctldev->desc->confops;
  48. int i;
  49. if (!ops->is_generic)
  50. return;
  51. for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
  52. unsigned long config;
  53. int ret;
  54. /* We want to check out this parameter */
  55. config = pinconf_to_config_packed(conf_items[i].param, 0);
  56. ret = pin_config_get_for_pin(pctldev, pin, &config);
  57. /* These are legal errors */
  58. if (ret == -EINVAL || ret == -ENOTSUPP)
  59. continue;
  60. if (ret) {
  61. seq_printf(s, "ERROR READING CONFIG SETTING %d ", i);
  62. continue;
  63. }
  64. /* Space between multiple configs */
  65. seq_puts(s, " ");
  66. seq_puts(s, conf_items[i].display);
  67. /* Print unit if available */
  68. if (conf_items[i].format &&
  69. pinconf_to_config_argument(config) != 0)
  70. seq_printf(s, " (%u %s)",
  71. pinconf_to_config_argument(config),
  72. conf_items[i].format);
  73. }
  74. }
  75. void pinconf_generic_dump_group(struct pinctrl_dev *pctldev,
  76. struct seq_file *s, const char *gname)
  77. {
  78. const struct pinconf_ops *ops = pctldev->desc->confops;
  79. int i;
  80. if (!ops->is_generic)
  81. return;
  82. for(i = 0; i < ARRAY_SIZE(conf_items); i++) {
  83. unsigned long config;
  84. int ret;
  85. /* We want to check out this parameter */
  86. config = pinconf_to_config_packed(conf_items[i].param, 0);
  87. ret = pin_config_group_get(dev_name(pctldev->dev), gname,
  88. &config);
  89. /* These are legal errors */
  90. if (ret == -EINVAL || ret == -ENOTSUPP)
  91. continue;
  92. if (ret) {
  93. seq_printf(s, "ERROR READING CONFIG SETTING %d ", i);
  94. continue;
  95. }
  96. /* Space between multiple configs */
  97. seq_puts(s, " ");
  98. seq_puts(s, conf_items[i].display);
  99. /* Print unit if available */
  100. if (conf_items[i].format && config != 0)
  101. seq_printf(s, " (%u %s)",
  102. pinconf_to_config_argument(config),
  103. conf_items[i].format);
  104. }
  105. }
  106. #endif