pinctrl-cv18xx.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2024 Inochi Amaoto <inochiama@outlook.com>
  4. */
  5. #ifndef _PINCTRL_SOPHGO_CV18XX_H
  6. #define _PINCTRL_SOPHGO_CV18XX_H
  7. #include <linux/bits.h>
  8. #include <linux/bitfield.h>
  9. #include <linux/device.h>
  10. #include <linux/mutex.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/pinctrl/pinctrl.h>
  14. #include <linux/pinctrl/pinconf.h>
  15. enum cv1800_pin_io_type {
  16. IO_TYPE_1V8_ONLY = 0,
  17. IO_TYPE_1V8_OR_3V3 = 1,
  18. IO_TYPE_AUDIO = 2,
  19. IO_TYPE_ETH = 3
  20. };
  21. #define CV1800_PINCONF_AREA_SYS 0
  22. #define CV1800_PINCONF_AREA_RTC 1
  23. struct cv1800_pinmux {
  24. u16 offset;
  25. u8 area;
  26. u8 max;
  27. };
  28. struct cv1800_pinmux2 {
  29. u16 offset;
  30. u8 area;
  31. u8 max;
  32. u8 pfunc;
  33. };
  34. struct cv1800_pinconf {
  35. u16 offset;
  36. u8 area;
  37. };
  38. #define CV1800_PIN_HAVE_MUX2 BIT(0)
  39. #define CV1800_PIN_IO_TYPE GENMASK(2, 1)
  40. #define CV1800_PIN_FLAG_IO_TYPE(type) \
  41. FIELD_PREP_CONST(CV1800_PIN_IO_TYPE, type)
  42. struct cv1800_pin {
  43. u16 pin;
  44. u16 flags;
  45. u8 power_domain;
  46. struct cv1800_pinmux mux;
  47. struct cv1800_pinmux2 mux2;
  48. struct cv1800_pinconf conf;
  49. };
  50. #define PIN_POWER_STATE_1V8 1800
  51. #define PIN_POWER_STATE_3V3 3300
  52. /**
  53. * struct cv1800_vddio_cfg_ops - pin vddio operations
  54. *
  55. * @get_pull_up: get resistor for pull up;
  56. * @get_pull_down: get resistor for pull down.
  57. * @get_oc_map: get mapping for typical low level output current value to
  58. * register value map.
  59. * @get_schmitt_map: get mapping for register value to typical schmitt
  60. * threshold.
  61. */
  62. struct cv1800_vddio_cfg_ops {
  63. int (*get_pull_up)(struct cv1800_pin *pin, const u32 *psmap);
  64. int (*get_pull_down)(struct cv1800_pin *pin, const u32 *psmap);
  65. int (*get_oc_map)(struct cv1800_pin *pin, const u32 *psmap,
  66. const u32 **map);
  67. int (*get_schmitt_map)(struct cv1800_pin *pin, const u32 *psmap,
  68. const u32 **map);
  69. };
  70. struct cv1800_pinctrl_data {
  71. const struct pinctrl_pin_desc *pins;
  72. const struct cv1800_pin *pindata;
  73. const char * const *pdnames;
  74. const struct cv1800_vddio_cfg_ops *vddio_ops;
  75. u16 npins;
  76. u16 npd;
  77. };
  78. static inline enum cv1800_pin_io_type cv1800_pin_io_type(struct cv1800_pin *pin)
  79. {
  80. return FIELD_GET(CV1800_PIN_IO_TYPE, pin->flags);
  81. };
  82. int cv1800_pinctrl_probe(struct platform_device *pdev);
  83. #define CV1800_FUNC_PIN(_id, _power_domain, _type, \
  84. _mux_area, _mux_offset, _mux_func_max) \
  85. { \
  86. .pin = (_id), \
  87. .power_domain = (_power_domain), \
  88. .flags = CV1800_PIN_FLAG_IO_TYPE(_type), \
  89. .mux = { \
  90. .area = (_mux_area), \
  91. .offset = (_mux_offset), \
  92. .max = (_mux_func_max), \
  93. }, \
  94. }
  95. #define CV1800_GENERAL_PIN(_id, _power_domain, _type, \
  96. _mux_area, _mux_offset, _mux_func_max, \
  97. _conf_area, _conf_offset) \
  98. { \
  99. .pin = (_id), \
  100. .power_domain = (_power_domain), \
  101. .flags = CV1800_PIN_FLAG_IO_TYPE(_type), \
  102. .mux = { \
  103. .area = (_mux_area), \
  104. .offset = (_mux_offset), \
  105. .max = (_mux_func_max), \
  106. }, \
  107. .conf = { \
  108. .area = (_conf_area), \
  109. .offset = (_conf_offset), \
  110. }, \
  111. }
  112. #define CV1800_GENERATE_PIN_MUX2(_id, _power_domain, _type, \
  113. _mux_area, _mux_offset, _mux_func_max, \
  114. _mux2_area, _mux2_offset, \
  115. _mux2_func_max, \
  116. _conf_area, _conf_offset) \
  117. { \
  118. .pin = (_id), \
  119. .power_domain = (_power_domain), \
  120. .flags = CV1800_PIN_FLAG_IO_TYPE(_type) | \
  121. CV1800_PIN_HAVE_MUX2, \
  122. .mux = { \
  123. .area = (_mux_area), \
  124. .offset = (_mux_offset), \
  125. .max = (_mux_func_max), \
  126. }, \
  127. .mux2 = { \
  128. .area = (_mux2_area), \
  129. .offset = (_mux2_offset), \
  130. .max = (_mux2_func_max), \
  131. }, \
  132. .conf = { \
  133. .area = (_conf_area), \
  134. .offset = (_conf_offset), \
  135. }, \
  136. }
  137. #endif