blob: 6261766cdf886ccaf0eedaa6ee93e64c2d551924 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng96c05fc2015-02-02 22:35:24 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
Bin Meng96c05fc2015-02-02 22:35:24 +08004 */
5
Bin Meng96c05fc2015-02-02 22:35:24 +08006#include <asm/arch/device.h>
7#include <asm/arch/msg_port.h>
Bin Meng7ba52a02015-09-03 05:37:23 -07008#include <asm/arch/quark.h>
Bin Meng96c05fc2015-02-02 22:35:24 +08009
10void msg_port_setup(int op, int port, int reg)
11{
Bin Meng7ba52a02015-09-03 05:37:23 -070012 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_REG,
13 (((op) << 24) | ((port) << 16) |
14 (((reg) << 8) & 0xff00) | MSG_BYTE_ENABLE));
Bin Meng96c05fc2015-02-02 22:35:24 +080015}
16
17u32 msg_port_read(u8 port, u32 reg)
18{
19 u32 value;
20
Bin Meng7ba52a02015-09-03 05:37:23 -070021 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
22 reg & 0xffffff00);
Bin Meng96c05fc2015-02-02 22:35:24 +080023 msg_port_setup(MSG_OP_READ, port, reg);
Bin Meng7ba52a02015-09-03 05:37:23 -070024 qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
Bin Meng96c05fc2015-02-02 22:35:24 +080025
26 return value;
27}
28
29void msg_port_write(u8 port, u32 reg, u32 value)
30{
Bin Meng7ba52a02015-09-03 05:37:23 -070031 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
32 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
33 reg & 0xffffff00);
Bin Meng96c05fc2015-02-02 22:35:24 +080034 msg_port_setup(MSG_OP_WRITE, port, reg);
35}
36
37u32 msg_port_alt_read(u8 port, u32 reg)
38{
39 u32 value;
40
Bin Meng7ba52a02015-09-03 05:37:23 -070041 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
42 reg & 0xffffff00);
Bin Meng96c05fc2015-02-02 22:35:24 +080043 msg_port_setup(MSG_OP_ALT_READ, port, reg);
Bin Meng7ba52a02015-09-03 05:37:23 -070044 qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
Bin Meng96c05fc2015-02-02 22:35:24 +080045
46 return value;
47}
48
49void msg_port_alt_write(u8 port, u32 reg, u32 value)
50{
Bin Meng7ba52a02015-09-03 05:37:23 -070051 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
52 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
53 reg & 0xffffff00);
Bin Meng96c05fc2015-02-02 22:35:24 +080054 msg_port_setup(MSG_OP_ALT_WRITE, port, reg);
55}
56
57u32 msg_port_io_read(u8 port, u32 reg)
58{
59 u32 value;
60
Bin Meng7ba52a02015-09-03 05:37:23 -070061 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
62 reg & 0xffffff00);
Bin Meng96c05fc2015-02-02 22:35:24 +080063 msg_port_setup(MSG_OP_IO_READ, port, reg);
Bin Meng7ba52a02015-09-03 05:37:23 -070064 qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
Bin Meng96c05fc2015-02-02 22:35:24 +080065
66 return value;
67}
68
69void msg_port_io_write(u8 port, u32 reg, u32 value)
70{
Bin Meng7ba52a02015-09-03 05:37:23 -070071 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
72 qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
73 reg & 0xffffff00);
Bin Meng96c05fc2015-02-02 22:35:24 +080074 msg_port_setup(MSG_OP_IO_WRITE, port, reg);
75}