sppctl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * SP7021 Pin Controller Driver.
  4. * Copyright (C) Sunplus Tech / Tibbo Tech.
  5. */
  6. #ifndef __SPPCTL_H__
  7. #define __SPPCTL_H__
  8. #include <linux/bits.h>
  9. #include <linux/gpio/driver.h>
  10. #include <linux/kernel.h>
  11. #include <linux/pinctrl/pinctrl.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/types.h>
  14. #define SPPCTL_MODULE_NAME "sppctl_sp7021"
  15. #define SPPCTL_GPIO_OFF_FIRST 0x00
  16. #define SPPCTL_GPIO_OFF_MASTER 0x00
  17. #define SPPCTL_GPIO_OFF_OE 0x20
  18. #define SPPCTL_GPIO_OFF_OUT 0x40
  19. #define SPPCTL_GPIO_OFF_IN 0x60
  20. #define SPPCTL_GPIO_OFF_IINV 0x80
  21. #define SPPCTL_GPIO_OFF_OINV 0xa0
  22. #define SPPCTL_GPIO_OFF_OD 0xc0
  23. #define SPPCTL_FULLY_PINMUX_MASK_MASK GENMASK(22, 16)
  24. #define SPPCTL_FULLY_PINMUX_SEL_MASK GENMASK(6, 0)
  25. #define SPPCTL_FULLY_PINMUX_UPPER_SHIFT 8
  26. /*
  27. * Mask-fields and control-fields of MOON registers of SP7021 are
  28. * arranged as shown below:
  29. *
  30. * register | mask-fields | control-fields
  31. * ----------+--------------+----------------
  32. * base[0] | (31 : 16) | (15 : 0)
  33. * base[1] | (31 : 24) | (15 : 0)
  34. * base[2] | (31 : 24) | (15 : 0)
  35. * : | : | :
  36. *
  37. * where mask-fields are used to protect control-fields from write-in
  38. * accidentally. Set the corresponding bits in the mask-field before
  39. * you write a value into a control-field.
  40. */
  41. #define SPPCTL_MOON_REG_MASK_SHIFT 16
  42. #define SPPCTL_SET_MOON_REG_BIT(bit) (BIT((bit) + SPPCTL_MOON_REG_MASK_SHIFT) | BIT(bit))
  43. #define SPPCTL_CLR_MOON_REG_BIT(bit) BIT((bit) + SPPCTL_MOON_REG_MASK_SHIFT)
  44. #define SPPCTL_IOP_CONFIGS 0xff
  45. #define FNCE(n, r, o, bo, bl, g) { \
  46. .name = n, \
  47. .type = r, \
  48. .roff = o, \
  49. .boff = bo, \
  50. .blen = bl, \
  51. .grps = (g), \
  52. .gnum = ARRAY_SIZE(g), \
  53. }
  54. #define FNCN(n, r, o, bo, bl) { \
  55. .name = n, \
  56. .type = r, \
  57. .roff = o, \
  58. .boff = bo, \
  59. .blen = bl, \
  60. .grps = NULL, \
  61. .gnum = 0, \
  62. }
  63. #define EGRP(n, v, p) { \
  64. .name = n, \
  65. .gval = (v), \
  66. .pins = (p), \
  67. .pnum = ARRAY_SIZE(p), \
  68. }
  69. /**
  70. * enum mux_first_reg - Define modes of access of FIRST register
  71. * @mux_f_mux: Set the corresponding pin to a fully-pinmux pin
  72. * @mux_f_gpio: Set the corresponding pin to a GPIO or IOP pin
  73. * @mux_f_keep: Don't change (keep intact)
  74. */
  75. enum mux_first_reg {
  76. mux_f_mux = 0,
  77. mux_f_gpio = 1,
  78. mux_f_keep = 2,
  79. };
  80. /**
  81. * enum mux_master_reg - Define modes of access of MASTER register
  82. * @mux_m_iop: Set the corresponding pin to an IO processor (IOP) pin
  83. * @mux_m_gpio: Set the corresponding pin to a digital GPIO pin
  84. * @mux_m_keep: Don't change (keep intact)
  85. */
  86. enum mux_master_reg {
  87. mux_m_iop = 0,
  88. mux_m_gpio = 1,
  89. mux_m_keep = 2,
  90. };
  91. /**
  92. * enum pinmux_type - Define types of pinmux pins
  93. * @pinmux_type_fpmx: A fully-pinmux pin
  94. * @pinmux_type_grp: A group-pinmux pin
  95. */
  96. enum pinmux_type {
  97. pinmux_type_fpmx,
  98. pinmux_type_grp,
  99. };
  100. /**
  101. * struct grp2fp_map - A map storing indexes
  102. * @f_idx: an index to function table
  103. * @g_idx: an index to group table
  104. */
  105. struct grp2fp_map {
  106. u16 f_idx;
  107. u16 g_idx;
  108. };
  109. struct sppctl_gpio_chip;
  110. struct sppctl_pdata {
  111. void __iomem *moon2_base; /* MOON2 */
  112. void __iomem *gpioxt_base; /* MASTER, OE, OUT, IN, I_INV, O_INV, OD */
  113. void __iomem *first_base; /* FIRST */
  114. void __iomem *moon1_base; /* MOON1 */
  115. struct pinctrl_desc pctl_desc;
  116. struct pinctrl_dev *pctl_dev;
  117. struct pinctrl_gpio_range pctl_grange;
  118. struct sppctl_gpio_chip *spp_gchip;
  119. char const **unq_grps;
  120. size_t unq_grps_sz;
  121. struct grp2fp_map *g2fp_maps;
  122. };
  123. struct sppctl_grp {
  124. const char * const name;
  125. const u8 gval; /* group number */
  126. const unsigned * const pins; /* list of pins */
  127. const unsigned int pnum; /* number of pins */
  128. };
  129. struct sppctl_func {
  130. const char * const name;
  131. const enum pinmux_type type; /* function type */
  132. const u8 roff; /* register offset */
  133. const u8 boff; /* bit offset */
  134. const u8 blen; /* bit length */
  135. const struct sppctl_grp * const grps; /* list of groups */
  136. const unsigned int gnum; /* number of groups */
  137. };
  138. extern const struct sppctl_func sppctl_list_funcs[];
  139. extern const char * const sppctl_pmux_list_s[];
  140. extern const char * const sppctl_gpio_list_s[];
  141. extern const struct pinctrl_pin_desc sppctl_pins_all[];
  142. extern const unsigned int sppctl_pins_gpio[];
  143. extern const size_t sppctl_list_funcs_sz;
  144. extern const size_t sppctl_pmux_list_sz;
  145. extern const size_t sppctl_gpio_list_sz;
  146. extern const size_t sppctl_pins_all_sz;
  147. #endif