1 /* 2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef _QUARK_MSG_PORT_H_ 8 #define _QUARK_MSG_PORT_H_ 9 10 /* 11 * In the Quark SoC, some chipset commands are accomplished by utilizing 12 * the internal message network within the host bridge (D0:F0). Accesses 13 * to this network are accomplished by populating the message control 14 * register (MCR), Message Control Register eXtension (MCRX) and the 15 * message data register (MDR). 16 */ 17 #define MSG_CTRL_REG 0xd0 /* Message Control Register */ 18 #define MSG_DATA_REG 0xd4 /* Message Data Register */ 19 #define MSG_CTRL_EXT_REG 0xd8 /* Message Control Register EXT */ 20 21 /* Normal Read/Write OpCodes */ 22 #define MSG_OP_READ 0x10 23 #define MSG_OP_WRITE 0x11 24 25 /* Alternative Read/Write OpCodes */ 26 #define MSG_OP_ALT_READ 0x06 27 #define MSG_OP_ALT_WRITE 0x07 28 29 /* IO Read/Write OpCodes */ 30 #define MSG_OP_IO_READ 0x02 31 #define MSG_OP_IO_WRITE 0x03 32 33 /* All byte enables */ 34 #define MSG_BYTE_ENABLE 0xf0 35 36 #ifndef __ASSEMBLY__ 37 38 /** 39 * msg_port_setup - set up the message port control register 40 * 41 * @op: message bus access opcode 42 * @port: port number on the message bus 43 * @reg: register number within a port 44 */ 45 void msg_port_setup(int op, int port, int reg); 46 47 /** 48 * msg_port_read - read a message port register using normal opcode 49 * 50 * @port: port number on the message bus 51 * @reg: register number within a port 52 * 53 * @return: message port register value 54 */ 55 u32 msg_port_read(u8 port, u32 reg); 56 57 /** 58 * msg_port_write - write a message port register using normal opcode 59 * 60 * @port: port number on the message bus 61 * @reg: register number within a port 62 * @value: register value to write 63 */ 64 void msg_port_write(u8 port, u32 reg, u32 value); 65 66 /** 67 * msg_port_alt_read - read a message port register using alternative opcode 68 * 69 * @port: port number on the message bus 70 * @reg: register number within a port 71 * 72 * @return: message port register value 73 */ 74 u32 msg_port_alt_read(u8 port, u32 reg); 75 76 /** 77 * msg_port_alt_write - write a message port register using alternative opcode 78 * 79 * @port: port number on the message bus 80 * @reg: register number within a port 81 * @value: register value to write 82 */ 83 void msg_port_alt_write(u8 port, u32 reg, u32 value); 84 85 /** 86 * msg_port_io_read - read a message port register using I/O opcode 87 * 88 * @port: port number on the message bus 89 * @reg: register number within a port 90 * 91 * @return: message port register value 92 */ 93 u32 msg_port_io_read(u8 port, u32 reg); 94 95 /** 96 * msg_port_io_write - write a message port register using I/O opcode 97 * 98 * @port: port number on the message bus 99 * @reg: register number within a port 100 * @value: register value to write 101 */ 102 void msg_port_io_write(u8 port, u32 reg, u32 value); 103 104 /* clrbits, setbits, clrsetbits macros for message port access */ 105 106 #define msg_port_normal_read msg_port_read 107 #define msg_port_normal_write msg_port_write 108 109 #define msg_port_generic_clrsetbits(type, port, reg, clr, set) \ 110 msg_port_##type##_write(port, reg, \ 111 (msg_port_##type##_read(port, reg) \ 112 & ~(clr)) | (set)) 113 114 #define msg_port_clrbits(port, reg, clr) \ 115 msg_port_generic_clrsetbits(normal, port, reg, clr, 0) 116 #define msg_port_setbits(port, reg, set) \ 117 msg_port_generic_clrsetbits(normal, port, reg, 0, set) 118 #define msg_port_clrsetbits(port, reg, clr, set) \ 119 msg_port_generic_clrsetbits(normal, port, reg, clr, set) 120 121 #define msg_port_alt_clrbits(port, reg, clr) \ 122 msg_port_generic_clrsetbits(alt, port, reg, clr, 0) 123 #define msg_port_alt_setbits(port, reg, set) \ 124 msg_port_generic_clrsetbits(alt, port, reg, 0, set) 125 #define msg_port_alt_clrsetbits(port, reg, clr, set) \ 126 msg_port_generic_clrsetbits(alt, port, reg, clr, set) 127 128 #define msg_port_io_clrbits(port, reg, clr) \ 129 msg_port_generic_clrsetbits(io, port, reg, clr, 0) 130 #define msg_port_io_setbits(port, reg, set) \ 131 msg_port_generic_clrsetbits(io, port, reg, 0, set) 132 #define msg_port_io_clrsetbits(port, reg, clr, set) \ 133 msg_port_generic_clrsetbits(io, port, reg, clr, set) 134 135 #endif /* __ASSEMBLY__ */ 136 137 #endif /* _QUARK_MSG_PORT_H_ */ 138