pinctrl-sandbox.c 3.9 KB

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