9 #define TIMEOUT_US 500000
11 /* Standard MMIO read, non-posted */
12 #define SB_MRD_NP 0x00
13 /* Standard MMIO write, non-posted */
14 #define SB_MWR_NP 0x01
15 /* Private register read, double-word addressing, non-posted */
16 #define SB_CRRDDA_NP 0x06
17 /* Private register write, double-word addressing, non-posted */
18 #define SB_CRWRDA_NP 0x07
20 static int vlv_sideband_rw(uint32_t port, uint8_t opcode, uint32_t addr,
24 uint32_t cmd, devfn, be, bar;
25 int is_read = (opcode == SB_CRRDDA_NP || opcode == SB_MRD_NP);
31 cmd = (devfn << IOSF_DEVFN_SHIFT) | (opcode << IOSF_OPCODE_SHIFT) |
32 (port << IOSF_PORT_SHIFT) | (be << IOSF_BYTE_ENABLES_SHIFT) |
33 (bar << IOSF_BAR_SHIFT);
35 if (intel_register_read(VLV_IOSF_DOORBELL_REQ) & IOSF_SB_BUSY) {
36 fprintf(stderr, "warning: pcode (%s) mailbox access failed\n",
37 is_read ? "read" : "write");
41 intel_register_write(VLV_IOSF_ADDR, addr);
43 intel_register_write(VLV_IOSF_DATA, *val);
45 intel_register_write(VLV_IOSF_DOORBELL_REQ, cmd);
50 } while (intel_register_read(VLV_IOSF_DOORBELL_REQ) & IOSF_SB_BUSY &&
51 timeout < TIMEOUT_US);
53 if (timeout >= TIMEOUT_US) {
54 fprintf(stderr, "timeout waiting for pcode %s (%d) to finish\n",
55 is_read ? "read" : "write", addr);
60 *val = intel_register_read(VLV_IOSF_DATA);
61 intel_register_write(VLV_IOSF_DATA, 0);
68 * @addr: register offset
69 * @val: pointer to starge for the read result
71 * 32-bit read of the register at @offset through the P-Unit sideband port.
74 * 0 when the register access succeeded, negative errno code on failure.
76 int intel_punit_read(uint8_t addr, uint32_t *val)
78 return vlv_sideband_rw(IOSF_PORT_PUNIT, SB_CRRDDA_NP, addr, val);
83 * @addr: register offset
84 * @val: value to write
86 * 32-bit write of the register at @offset through the P-Unit sideband port.
89 * 0 when the register access succeeded, negative errno code on failure.
91 int intel_punit_write(uint8_t addr, uint32_t val)
93 return vlv_sideband_rw(IOSF_PORT_PUNIT, SB_CRWRDA_NP, addr, &val);
98 * @addr: register offset
99 * @val: pointer to starge for the read result
101 * 32-bit read of the register at @offset through the NC sideband port.
104 * 0 when the register access succeeded, negative errno code on failure.
106 int intel_nc_read(uint8_t addr, uint32_t *val)
108 return vlv_sideband_rw(IOSF_PORT_NC, SB_CRRDDA_NP, addr, val);
113 * @addr: register offset
114 * @val: value to write
116 * 32-bit write of the register at @offset through the NC sideband port.
119 * 0 when the register access succeeded, negative errno code on failure.
121 int intel_nc_write(uint8_t addr, uint32_t val)
123 return vlv_sideband_rw(IOSF_PORT_NC, SB_CRWRDA_NP, addr, &val);
127 * intel_dpio_reg_read:
128 * @reg: register offset
129 * @phy: DPIO PHY to use
131 * 32-bit read of the register at @offset through the DPIO sideband port.
134 * The value read from the register.
136 uint32_t intel_dpio_reg_read(uint32_t reg, int phy)
141 vlv_sideband_rw(IOSF_PORT_DPIO, SB_MRD_NP, reg, &val);
143 vlv_sideband_rw(IOSF_PORT_DPIO_2, SB_MRD_NP, reg, &val);
148 * intel_dpio_reg_write:
149 * @reg: register offset
150 * @val: value to write
151 * @phy: dpio PHY to use
153 * 32-bit write of the register at @offset through the DPIO sideband port.
155 void intel_dpio_reg_write(uint32_t reg, uint32_t val, int phy)
158 vlv_sideband_rw(IOSF_PORT_DPIO, SB_MWR_NP, reg, &val);
160 vlv_sideband_rw(IOSF_PORT_DPIO_2, SB_MWR_NP, reg, &val);
163 uint32_t intel_flisdsi_reg_read(uint32_t reg)
167 vlv_sideband_rw(IOSF_PORT_FLISDSI, SB_CRRDDA_NP, reg, &val);
172 void intel_flisdsi_reg_write(uint32_t reg, uint32_t val)
174 vlv_sideband_rw(IOSF_PORT_FLISDSI, SB_CRWRDA_NP, reg, &val);
177 uint32_t intel_iosf_sb_read(uint32_t port, uint32_t reg)
181 vlv_sideband_rw(port, SB_CRRDDA_NP, reg, &val);
186 void intel_iosf_sb_write(uint32_t port, uint32_t reg, uint32_t val)
188 vlv_sideband_rw(port, SB_CRWRDA_NP, reg, &val);