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