pinconf-generic.c 3.5 KB

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