p2sb.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 (none at present)
  30. */
  31. struct p2sb_ops {
  32. };
  33. #define p2sb_get_ops(dev) ((struct p2sb_ops *)(dev)->driver->ops)
  34. /**
  35. * pcr_read32/16/8() - Read from a PCR device
  36. *
  37. * Reads data from a PCR device within the P2SB
  38. *
  39. * @dev: Device to read from
  40. * @offset: Offset within device to read
  41. * @return value read
  42. */
  43. uint pcr_read32(struct udevice *dev, uint offset);
  44. uint pcr_read16(struct udevice *dev, uint offset);
  45. uint pcr_read8(struct udevice *dev, uint offset);
  46. /**
  47. * pcr_read32/16/8() - Write to a PCR device
  48. *
  49. * Writes data to a PCR device within the P2SB
  50. *
  51. * @dev: Device to write to
  52. * @offset: Offset within device to write
  53. * @data: Data to write
  54. */
  55. void pcr_write32(struct udevice *dev, uint offset, uint data);
  56. void pcr_write16(struct udevice *dev, uint offset, uint data);
  57. void pcr_write8(struct udevice *dev, uint offset, uint data);
  58. /**
  59. * pcr_clrsetbits32/16/8() - Update a PCR device
  60. *
  61. * Updates dat in a PCR device within the P2SB
  62. *
  63. * This reads from the device, clears and set bits, then writes back.
  64. *
  65. * new_data = (old_data & ~clr) | set
  66. *
  67. * @dev: Device to update
  68. * @offset: Offset within device to update
  69. * @clr: Bits to clear after reading
  70. * @set: Bits to set before writing
  71. */
  72. void pcr_clrsetbits32(struct udevice *dev, uint offset, uint clr, uint set);
  73. void pcr_clrsetbits16(struct udevice *dev, uint offset, uint clr, uint set);
  74. void pcr_clrsetbits8(struct udevice *dev, uint offset, uint clr, uint set);
  75. static inline void pcr_setbits32(struct udevice *dev, uint offset, uint set)
  76. {
  77. return pcr_clrsetbits32(dev, offset, 0, set);
  78. }
  79. static inline void pcr_setbits16(struct udevice *dev, uint offset, uint set)
  80. {
  81. return pcr_clrsetbits16(dev, offset, 0, set);
  82. }
  83. static inline void pcr_setbits8(struct udevice *dev, uint offset, uint set)
  84. {
  85. return pcr_clrsetbits8(dev, offset, 0, set);
  86. }
  87. static inline void pcr_clrbits32(struct udevice *dev, uint offset, uint clr)
  88. {
  89. return pcr_clrsetbits32(dev, offset, clr, 0);
  90. }
  91. static inline void pcr_clrbits16(struct udevice *dev, uint offset, uint clr)
  92. {
  93. return pcr_clrsetbits16(dev, offset, clr, 0);
  94. }
  95. static inline void pcr_clrbits8(struct udevice *dev, uint offset, uint clr)
  96. {
  97. return pcr_clrsetbits8(dev, offset, clr, 0);
  98. }
  99. /**
  100. * p2sb_set_port_id() - Set the port ID for a p2sb child device
  101. *
  102. * This must be called in a device's bind() method when OF_PLATDATA is used
  103. * since the uclass cannot access the device's of-platdata.
  104. *
  105. * @dev: Child device (whose parent is UCLASS_P2SB)
  106. * @portid: Port ID of child device
  107. * @return 0 if OK, -ENODEV is the p2sb device could not be found
  108. */
  109. int p2sb_set_port_id(struct udevice *dev, int portid);
  110. /**
  111. * p2sb_get_port_id() - Get the port ID for a p2sb child device
  112. *
  113. * @dev: Child device (whose parent is UCLASS_P2SB)
  114. * @return Port ID of that child
  115. */
  116. int p2sb_get_port_id(struct udevice *dev);
  117. #endif