pinctrl-brcmstb.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Header for Broadcom brcmstb GPIO based drivers
  4. *
  5. * Copyright (C) 2024-2025 Ivan T. Ivanov, Andrea della Porta
  6. * Copyright (C) 2021-3 Raspberry Pi Ltd.
  7. * Copyright (C) 2012 Chris Boot, Simon Arlott, Stephen Warren
  8. *
  9. * Based heavily on the BCM2835 GPIO & pinctrl driver, which was inspired by:
  10. * pinctrl-nomadik.c, please see original file for copyright information
  11. * pinctrl-tegra.c, please see original file for copyright information
  12. */
  13. #ifndef __PINCTRL_BRCMSTB_H__
  14. #define __PINCTRL_BRCMSTB_H__
  15. #include <linux/types.h>
  16. #include <linux/platform_device.h>
  17. #define BRCMSTB_FUNC(f) \
  18. [func_##f] = #f
  19. #define MUX_BIT_VALID 0x8000
  20. #define PAD_BIT_INVALID 0xffff
  21. #define MUX_BIT(muxreg, muxshift) \
  22. (MUX_BIT_VALID + ((muxreg) << 5) + ((muxshift) << 2))
  23. #define PAD_BIT(padreg, padshift) \
  24. (((padreg) << 5) + ((padshift) << 1))
  25. #define GPIO_REGS(n, muxreg, muxshift, padreg, padshift) \
  26. [n] = { MUX_BIT(muxreg, muxshift), PAD_BIT(padreg, padshift) }
  27. #define EMMC_REGS(n, padreg, padshift) \
  28. [n] = { 0, PAD_BIT(padreg, padshift) }
  29. #define AON_GPIO_REGS(n, muxreg, muxshift, padreg, padshift) \
  30. GPIO_REGS(n, muxreg, muxshift, padreg, padshift)
  31. #define AON_SGPIO_REGS(n, muxreg, muxshift) \
  32. [(n) + 32] = { MUX_BIT(muxreg, muxshift), PAD_BIT_INVALID }
  33. #define GPIO_PIN(n) PINCTRL_PIN(n, "gpio" #n)
  34. /**
  35. * AON pins are in the Always-On power domain. SGPIOs are also 'Safe'
  36. * being 5V tolerant (necessary for the HDMI I2C pins), and can be driven
  37. * while the power is off.
  38. */
  39. #define AON_GPIO_PIN(n) PINCTRL_PIN(n, "aon_gpio" #n)
  40. #define AON_SGPIO_PIN(n) PINCTRL_PIN((n) + 32, "aon_sgpio" #n)
  41. struct pin_regs {
  42. u16 mux_bit;
  43. u16 pad_bit;
  44. };
  45. /**
  46. * struct brcmstb_pin_funcs - pins provide their primary/alternate
  47. * functions in this struct
  48. * @func_mask: mask representing valid bits of the function selector
  49. * in the registers
  50. * @funcs: array of function identifiers
  51. * @n_funcs: number of identifiers of the @funcs array above
  52. */
  53. struct brcmstb_pin_funcs {
  54. const u32 func_mask;
  55. const u8 *funcs;
  56. const unsigned int n_funcs;
  57. };
  58. /**
  59. * struct brcmstb_pdata - specific data for a pinctrl chip implementation
  60. * @pctl_desc: pin controller descriptor for this implementation
  61. * @gpio_range: range of GPIOs served by this controller
  62. * @pin_regs: array of register descriptors for each pin
  63. * @pin_funcs: array of all possible assignable function for each pin
  64. * @func_count: total number of functions
  65. * @func_gpio: which function number is GPIO (usually 0)
  66. * @func_names: an array listing all function names
  67. */
  68. struct brcmstb_pdata {
  69. const struct pinctrl_desc *pctl_desc;
  70. const struct pinctrl_gpio_range *gpio_range;
  71. const struct pin_regs *pin_regs;
  72. const struct brcmstb_pin_funcs *pin_funcs;
  73. const unsigned int func_count;
  74. const unsigned int func_gpio;
  75. const char * const *func_names;
  76. };
  77. int brcmstb_pinctrl_probe(struct platform_device *pdev);
  78. #endif