blob: 31713e321f2cf6c02e8b80f2458c38491d642fed [file] [log] [blame]
Bin Meng96c05fc2015-02-02 22:35:24 +08001/*
2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <pci.h>
9#include <asm/arch/device.h>
10#include <asm/arch/msg_port.h>
11
12void msg_port_setup(int op, int port, int reg)
13{
14 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_REG,
15 (((op) << 24) | ((port) << 16) |
16 (((reg) << 8) & 0xff00) | MSG_BYTE_ENABLE));
17}
18
19u32 msg_port_read(u8 port, u32 reg)
20{
21 u32 value;
22
23 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
24 reg & 0xffffff00);
25 msg_port_setup(MSG_OP_READ, port, reg);
26 pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
27
28 return value;
29}
30
31void msg_port_write(u8 port, u32 reg, u32 value)
32{
33 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
34 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
35 reg & 0xffffff00);
36 msg_port_setup(MSG_OP_WRITE, port, reg);
37}
38
39u32 msg_port_alt_read(u8 port, u32 reg)
40{
41 u32 value;
42
43 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
44 reg & 0xffffff00);
45 msg_port_setup(MSG_OP_ALT_READ, port, reg);
46 pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
47
48 return value;
49}
50
51void msg_port_alt_write(u8 port, u32 reg, u32 value)
52{
53 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
54 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
55 reg & 0xffffff00);
56 msg_port_setup(MSG_OP_ALT_WRITE, port, reg);
57}
58
59u32 msg_port_io_read(u8 port, u32 reg)
60{
61 u32 value;
62
63 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
64 reg & 0xffffff00);
65 msg_port_setup(MSG_OP_IO_READ, port, reg);
66 pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
67
68 return value;
69}
70
71void msg_port_io_write(u8 port, u32 reg, u32 value)
72{
73 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
74 pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
75 reg & 0xffffff00);
76 msg_port_setup(MSG_OP_IO_WRITE, port, reg);
77}