p2sb.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2019 Google LLC
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef __p2sb_h
  7. #define __p2sb_h
  8. /* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */
  9. #define PCR_PORTID_SHIFT 16
  10. /**
  11. * struct p2sb_child_platdata - Information about each child of a p2sb device
  12. *
  13. * @pid: Port ID for this child
  14. */
  15. struct p2sb_child_platdata {
  16. uint pid;
  17. };
  18. /**
  19. * struct p2sb_uc_priv - information for the uclass about each device
  20. *
  21. * This must be set up by the driver when it is probed
  22. *
  23. * @mmio_base: Base address of P2SB region
  24. */
  25. struct p2sb_uc_priv {
  26. uint mmio_base;
  27. };
  28. /**
  29. * struct p2sb_ops - Operations for the P2SB
  30. */
  31. struct p2sb_ops {
  32. /**
  33. * set_hide() - Set/clear the 'hide' bit on the p2sb
  34. *
  35. * This device can be hidden from the PCI bus if needed. This method
  36. * can be called before the p2sb is probed.
  37. *
  38. * @dev: P2SB device
  39. * @hide: true to hide the device, false to show it
  40. * @return 0 if OK, -ve on error
  41. */
  42. int (*set_hide)(struct udevice *dev, bool hide);
  43. };
  44. #define p2sb_get_ops(dev) ((struct p2sb_ops *)(dev)->driver->ops)
  45. /**
  46. * p2sb_set_hide() - Set/clear the 'hide' bit on the p2sb
  47. *
  48. * This device can be hidden from the PCI bus if needed. This method
  49. * can be called before the p2sb is probed.
  50. *
  51. * @dev: P2SB device
  52. * @hide: true to hide the device, false to show it
  53. * @return 0 if OK, -ve on error
  54. */
  55. int p2sb_set_hide(struct udevice *dev, bool hide);
  56. /**
  57. * pcr_read32/16/8() - Read from a PCR device
  58. *
  59. * Reads data from a PCR device within the P2SB
  60. *
  61. * @dev: Device to read from
  62. * @offset: Offset within device to read
  63. * @return value read
  64. */
  65. uint pcr_read32(struct udevice *dev, uint offset);
  66. uint pcr_read16(struct udevice *dev, uint offset);
  67. uint pcr_read8(struct udevice *dev, uint offset);
  68. /**
  69. * pcr_read32/16/8() - Write to a PCR device
  70. *
  71. * Writes data to a PCR device within the P2SB
  72. *
  73. * @dev: Device to write to
  74. * @offset: Offset within device to write
  75. * @data: Data to write
  76. */
  77. void pcr_write32(struct udevice *dev, uint offset, uint data);
  78. void pcr_write16(struct udevice *dev, uint offset, uint data);
  79. void pcr_write8(struct udevice *dev, uint offset, uint data);
  80. /**
  81. * pcr_clrsetbits32/16/8() - Update a PCR device
  82. *
  83. * Updates dat in a PCR device within the P2SB
  84. *
  85. * This reads from the device, clears and set bits, then writes back.
  86. *
  87. * new_data = (old_data & ~clr) | set
  88. *
  89. * @dev: Device to update
  90. * @offset: Offset within device to update
  91. * @clr: Bits to clear after reading
  92. * @set: Bits to set before writing
  93. */
  94. void pcr_clrsetbits32(struct udevice *dev, uint offset, uint clr, uint set);
  95. void pcr_clrsetbits16(struct udevice *dev, uint offset, uint clr, uint set);
  96. void pcr_clrsetbits8(struct udevice *dev, uint offset, uint clr, uint set);
  97. static inline void pcr_setbits32(struct udevice *dev, uint offset, uint set)
  98. {
  99. return pcr_clrsetbits32(dev, offset, 0, set);
  100. }
  101. static inline void pcr_setbits16(struct udevice *dev, uint offset, uint set)
  102. {
  103. return pcr_clrsetbits16(dev, offset, 0, set);
  104. }
  105. static inline void pcr_setbits8(struct udevice *dev, uint offset, uint set)
  106. {
  107. return pcr_clrsetbits8(dev, offset, 0, set);
  108. }
  109. static inline void pcr_clrbits32(struct udevice *dev, uint offset, uint clr)
  110. {
  111. return pcr_clrsetbits32(dev, offset, clr, 0);
  112. }
  113. static inline void pcr_clrbits16(struct udevice *dev, uint offset, uint clr)
  114. {
  115. return pcr_clrsetbits16(dev, offset, clr, 0);
  116. }
  117. static inline void pcr_clrbits8(struct udevice *dev, uint offset, uint clr)
  118. {
  119. return pcr_clrsetbits8(dev, offset, clr, 0);
  120. }
  121. /**
  122. * p2sb_set_port_id() - Set the port ID for a p2sb child device
  123. *
  124. * This must be called in a device's bind() method when OF_PLATDATA is used
  125. * since the uclass cannot access the device's of-platdata.
  126. *
  127. * @dev: Child device (whose parent is UCLASS_P2SB)
  128. * @portid: Port ID of child device
  129. * @return 0 if OK, -ENODEV is the p2sb device could not be found
  130. */
  131. int p2sb_set_port_id(struct udevice *dev, int portid);
  132. /**
  133. * p2sb_get_port_id() - Get the port ID for a p2sb child device
  134. *
  135. * @dev: Child device (whose parent is UCLASS_P2SB)
  136. * @return Port ID of that child
  137. */
  138. int p2sb_get_port_id(struct udevice *dev);
  139. /**
  140. * pcr_reg_address() Convert an offset in p2sb space to an absolute address
  141. *
  142. * @dev: Child device (whose parent is UCLASS_P2SB)
  143. * @offset: Offset within that child's address space
  144. * @return pointer to that offset within the child's address space
  145. */
  146. void *pcr_reg_address(struct udevice *dev, uint offset);
  147. #endif