pinctrl-zx.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2017 Sanechips Technology Co., Ltd.
  3. * Copyright 2017 Linaro Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef __PINCTRL_ZX_H
  10. #define __PINCTRL_ZX_H
  11. /**
  12. * struct zx_mux_desc - hardware mux descriptor
  13. * @name: mux function name
  14. * @muxval: mux register bit value
  15. */
  16. struct zx_mux_desc {
  17. const char *name;
  18. u8 muxval;
  19. };
  20. /**
  21. * struct zx_pin_data - hardware per-pin data
  22. * @aon_pin: whether it's an AON pin
  23. * @offset: register offset within TOP pinmux controller
  24. * @bitpos: bit position within TOP pinmux register
  25. * @width: bit width within TOP pinmux register
  26. * @coffset: pinconf register offset within AON controller
  27. * @cbitpos: pinconf bit position within AON register
  28. * @muxes: available mux function names and corresponding register values
  29. *
  30. * Unlike TOP pinmux and AON pinconf registers which are arranged pretty
  31. * arbitrarily, AON pinmux register bits are well organized per pin id, and
  32. * each pin occupies two bits, so that we can calculate the AON register offset
  33. * and bit position from pin id. Thus, we only need to define TOP pinmux and
  34. * AON pinconf register data for the pin.
  35. */
  36. struct zx_pin_data {
  37. bool aon_pin;
  38. u16 offset;
  39. u16 bitpos;
  40. u16 width;
  41. u16 coffset;
  42. u16 cbitpos;
  43. struct zx_mux_desc *muxes;
  44. };
  45. struct zx_pinctrl_soc_info {
  46. const struct pinctrl_pin_desc *pins;
  47. unsigned int npins;
  48. };
  49. #define TOP_PIN(pin, off, bp, wd, coff, cbp, ...) { \
  50. .number = pin, \
  51. .name = #pin, \
  52. .drv_data = &(struct zx_pin_data) { \
  53. .aon_pin = false, \
  54. .offset = off, \
  55. .bitpos = bp, \
  56. .width = wd, \
  57. .coffset = coff, \
  58. .cbitpos = cbp, \
  59. .muxes = (struct zx_mux_desc[]) { \
  60. __VA_ARGS__, { } }, \
  61. }, \
  62. }
  63. #define AON_PIN(pin, off, bp, wd, coff, cbp, ...) { \
  64. .number = pin, \
  65. .name = #pin, \
  66. .drv_data = &(struct zx_pin_data) { \
  67. .aon_pin = true, \
  68. .offset = off, \
  69. .bitpos = bp, \
  70. .width = wd, \
  71. .coffset = coff, \
  72. .cbitpos = cbp, \
  73. .muxes = (struct zx_mux_desc[]) { \
  74. __VA_ARGS__, { } }, \
  75. }, \
  76. }
  77. #define ZX_RESERVED(pin) PINCTRL_PIN(pin, #pin)
  78. #define TOP_MUX(_val, _name) { \
  79. .name = _name, \
  80. .muxval = _val, \
  81. }
  82. /*
  83. * When the flag is set, it's a mux configuration for an AON pin that sits in
  84. * AON register. Otherwise, it's one for AON pin but sitting in TOP register.
  85. */
  86. #define AON_MUX_FLAG BIT(7)
  87. #define AON_MUX(_val, _name) { \
  88. .name = _name, \
  89. .muxval = _val | AON_MUX_FLAG, \
  90. }
  91. int zx_pinctrl_init(struct platform_device *pdev,
  92. struct zx_pinctrl_soc_info *info);
  93. #endif /* __PINCTRL_ZX_H */