pinctrl_ast2500.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/pinctrl.h>
  10. #include <asm/arch/scu_ast2500.h>
  11. #include <dm/pinctrl.h>
  12. /*
  13. * This driver works with very simple configuration that has the same name
  14. * for group and function. This way it is compatible with the Linux Kernel
  15. * driver.
  16. */
  17. struct ast2500_pinctrl_priv {
  18. struct ast2500_scu *scu;
  19. };
  20. static int ast2500_pinctrl_probe(struct udevice *dev)
  21. {
  22. struct ast2500_pinctrl_priv *priv = dev_get_priv(dev);
  23. priv->scu = ast_get_scu();
  24. return 0;
  25. }
  26. struct ast2500_group_config {
  27. char *group_name;
  28. /* Control register number (1-10) */
  29. unsigned reg_num;
  30. /* The mask of control bits in the register */
  31. u32 ctrl_bit_mask;
  32. };
  33. static const struct ast2500_group_config ast2500_groups[] = {
  34. { "I2C1", 8, (1 << 13) | (1 << 12) },
  35. { "I2C2", 8, (1 << 15) | (1 << 14) },
  36. { "I2C3", 8, (1 << 16) },
  37. { "I2C4", 5, (1 << 17) },
  38. { "I2C4", 5, (1 << 17) },
  39. { "I2C5", 5, (1 << 18) },
  40. { "I2C6", 5, (1 << 19) },
  41. { "I2C7", 5, (1 << 20) },
  42. { "I2C8", 5, (1 << 21) },
  43. { "I2C9", 5, (1 << 22) },
  44. { "I2C10", 5, (1 << 23) },
  45. { "I2C11", 5, (1 << 24) },
  46. { "I2C12", 5, (1 << 25) },
  47. { "I2C13", 5, (1 << 26) },
  48. { "I2C14", 5, (1 << 27) },
  49. { "MAC1LINK", 1, (1 << 0) },
  50. { "MDIO1", 3, (1 << 31) | (1 << 30) },
  51. { "MAC2LINK", 1, (1 << 1) },
  52. { "MDIO2", 5, (1 << 2) },
  53. };
  54. static int ast2500_pinctrl_get_groups_count(struct udevice *dev)
  55. {
  56. debug("PINCTRL: get_(functions/groups)_count\n");
  57. return ARRAY_SIZE(ast2500_groups);
  58. }
  59. static const char *ast2500_pinctrl_get_group_name(struct udevice *dev,
  60. unsigned selector)
  61. {
  62. debug("PINCTRL: get_(function/group)_name %u\n", selector);
  63. return ast2500_groups[selector].group_name;
  64. }
  65. static int ast2500_pinctrl_group_set(struct udevice *dev, unsigned selector,
  66. unsigned func_selector)
  67. {
  68. struct ast2500_pinctrl_priv *priv = dev_get_priv(dev);
  69. const struct ast2500_group_config *config;
  70. u32 *ctrl_reg;
  71. debug("PINCTRL: group_set <%u, %u>\n", selector, func_selector);
  72. if (selector >= ARRAY_SIZE(ast2500_groups))
  73. return -EINVAL;
  74. config = &ast2500_groups[selector];
  75. if (config->reg_num > 6)
  76. ctrl_reg = &priv->scu->pinmux_ctrl1[config->reg_num - 7];
  77. else
  78. ctrl_reg = &priv->scu->pinmux_ctrl[config->reg_num - 1];
  79. ast_scu_unlock(priv->scu);
  80. setbits_le32(ctrl_reg, config->ctrl_bit_mask);
  81. ast_scu_lock(priv->scu);
  82. return 0;
  83. }
  84. static struct pinctrl_ops ast2500_pinctrl_ops = {
  85. .set_state = pinctrl_generic_set_state,
  86. .get_groups_count = ast2500_pinctrl_get_groups_count,
  87. .get_group_name = ast2500_pinctrl_get_group_name,
  88. .get_functions_count = ast2500_pinctrl_get_groups_count,
  89. .get_function_name = ast2500_pinctrl_get_group_name,
  90. .pinmux_group_set = ast2500_pinctrl_group_set,
  91. };
  92. static const struct udevice_id ast2500_pinctrl_ids[] = {
  93. { .compatible = "aspeed,ast2500-pinctrl" },
  94. { .compatible = "aspeed,g5-pinctrl" },
  95. { }
  96. };
  97. U_BOOT_DRIVER(pinctrl_ast2500) = {
  98. .name = "aspeed_ast2500_pinctrl",
  99. .id = UCLASS_PINCTRL,
  100. .of_match = ast2500_pinctrl_ids,
  101. .priv_auto_alloc_size = sizeof(struct ast2500_pinctrl_priv),
  102. .ops = &ast2500_pinctrl_ops,
  103. .probe = ast2500_pinctrl_probe,
  104. };