pinctrl-sandbox.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  4. */
  5. /* #define DEBUG */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dm/pinctrl.h>
  9. static const char * const sandbox_pins[] = {
  10. "SCL",
  11. "SDA",
  12. "TX",
  13. "RX",
  14. "W1"
  15. };
  16. static const char * const sandbox_groups[] = {
  17. "i2c",
  18. "serial_a",
  19. "serial_b",
  20. "spi",
  21. "w1",
  22. };
  23. static const char * const sandbox_functions[] = {
  24. "i2c",
  25. "serial",
  26. "spi",
  27. "w1",
  28. };
  29. static const struct pinconf_param sandbox_conf_params[] = {
  30. { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 },
  31. { "bias-high-impedance", PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0 },
  32. { "bias-bus-hold", PIN_CONFIG_BIAS_BUS_HOLD, 0 },
  33. { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 },
  34. { "bias-pull-down", PIN_CONFIG_BIAS_PULL_DOWN, 1 },
  35. { "bias-pull-pin-default", PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 1 },
  36. { "drive-open-drain", PIN_CONFIG_DRIVE_OPEN_DRAIN, 0 },
  37. { "drive-open-source", PIN_CONFIG_DRIVE_OPEN_SOURCE, 0 },
  38. { "drive-strength", PIN_CONFIG_DRIVE_STRENGTH, 0 },
  39. { "input-enable", PIN_CONFIG_INPUT_ENABLE, 1 },
  40. { "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
  41. };
  42. static int sandbox_get_pins_count(struct udevice *dev)
  43. {
  44. return ARRAY_SIZE(sandbox_pins);
  45. }
  46. static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector)
  47. {
  48. return sandbox_pins[selector];
  49. }
  50. static int sandbox_get_groups_count(struct udevice *dev)
  51. {
  52. return ARRAY_SIZE(sandbox_groups);
  53. }
  54. static const char *sandbox_get_group_name(struct udevice *dev,
  55. unsigned selector)
  56. {
  57. return sandbox_groups[selector];
  58. }
  59. static int sandbox_get_functions_count(struct udevice *dev)
  60. {
  61. return ARRAY_SIZE(sandbox_functions);
  62. }
  63. static const char *sandbox_get_function_name(struct udevice *dev,
  64. unsigned selector)
  65. {
  66. return sandbox_functions[selector];
  67. }
  68. static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
  69. unsigned func_selector)
  70. {
  71. debug("sandbox pinmux: pin = %d (%s), function = %d (%s)\n",
  72. pin_selector, sandbox_get_pin_name(dev, pin_selector),
  73. func_selector, sandbox_get_function_name(dev, func_selector));
  74. return 0;
  75. }
  76. static int sandbox_pinmux_group_set(struct udevice *dev,
  77. unsigned group_selector,
  78. unsigned func_selector)
  79. {
  80. debug("sandbox pinmux: group = %d (%s), function = %d (%s)\n",
  81. group_selector, sandbox_get_group_name(dev, group_selector),
  82. func_selector, sandbox_get_function_name(dev, func_selector));
  83. return 0;
  84. }
  85. static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
  86. unsigned param, unsigned argument)
  87. {
  88. debug("sandbox pinconf: pin = %d (%s), param = %d, arg = %d\n",
  89. pin_selector, sandbox_get_pin_name(dev, pin_selector),
  90. param, argument);
  91. return 0;
  92. }
  93. static int sandbox_pinconf_group_set(struct udevice *dev,
  94. unsigned group_selector,
  95. unsigned param, unsigned argument)
  96. {
  97. debug("sandbox pinconf: group = %d (%s), param = %d, arg = %d\n",
  98. group_selector, sandbox_get_group_name(dev, group_selector),
  99. param, argument);
  100. return 0;
  101. }
  102. const struct pinctrl_ops sandbox_pinctrl_ops = {
  103. .get_pins_count = sandbox_get_pins_count,
  104. .get_pin_name = sandbox_get_pin_name,
  105. .get_groups_count = sandbox_get_groups_count,
  106. .get_group_name = sandbox_get_group_name,
  107. .get_functions_count = sandbox_get_functions_count,
  108. .get_function_name = sandbox_get_function_name,
  109. .pinmux_set = sandbox_pinmux_set,
  110. .pinmux_group_set = sandbox_pinmux_group_set,
  111. .pinconf_num_params = ARRAY_SIZE(sandbox_conf_params),
  112. .pinconf_params = sandbox_conf_params,
  113. .pinconf_set = sandbox_pinconf_set,
  114. .pinconf_group_set = sandbox_pinconf_group_set,
  115. .set_state = pinctrl_generic_set_state,
  116. };
  117. static const struct udevice_id sandbox_pinctrl_match[] = {
  118. { .compatible = "sandbox,pinctrl" },
  119. { /* sentinel */ }
  120. };
  121. U_BOOT_DRIVER(sandbox_pinctrl) = {
  122. .name = "sandbox_pinctrl",
  123. .id = UCLASS_PINCTRL,
  124. .of_match = sandbox_pinctrl_match,
  125. .ops = &sandbox_pinctrl_ops,
  126. };