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