Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 6 | #include <asm/arch/device.h> |
| 7 | #include <asm/arch/msg_port.h> |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 8 | #include <asm/arch/quark.h> |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 9 | |
| 10 | void msg_port_setup(int op, int port, int reg) |
| 11 | { |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 12 | qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_REG, |
| 13 | (((op) << 24) | ((port) << 16) | |
| 14 | (((reg) << 8) & 0xff00) | MSG_BYTE_ENABLE)); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | u32 msg_port_read(u8 port, u32 reg) |
| 18 | { |
| 19 | u32 value; |
| 20 | |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 21 | qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG, |
| 22 | reg & 0xffffff00); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 23 | msg_port_setup(MSG_OP_READ, port, reg); |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 24 | qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 25 | |
| 26 | return value; |
| 27 | } |
| 28 | |
| 29 | void msg_port_write(u8 port, u32 reg, u32 value) |
| 30 | { |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 31 | 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 Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 34 | msg_port_setup(MSG_OP_WRITE, port, reg); |
| 35 | } |
| 36 | |
| 37 | u32 msg_port_alt_read(u8 port, u32 reg) |
| 38 | { |
| 39 | u32 value; |
| 40 | |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 41 | qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG, |
| 42 | reg & 0xffffff00); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 43 | msg_port_setup(MSG_OP_ALT_READ, port, reg); |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 44 | qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 45 | |
| 46 | return value; |
| 47 | } |
| 48 | |
| 49 | void msg_port_alt_write(u8 port, u32 reg, u32 value) |
| 50 | { |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 51 | 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 Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 54 | msg_port_setup(MSG_OP_ALT_WRITE, port, reg); |
| 55 | } |
| 56 | |
| 57 | u32 msg_port_io_read(u8 port, u32 reg) |
| 58 | { |
| 59 | u32 value; |
| 60 | |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 61 | qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG, |
| 62 | reg & 0xffffff00); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 63 | msg_port_setup(MSG_OP_IO_READ, port, reg); |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 64 | qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value); |
Bin Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 65 | |
| 66 | return value; |
| 67 | } |
| 68 | |
| 69 | void msg_port_io_write(u8 port, u32 reg, u32 value) |
| 70 | { |
Bin Meng | 7ba52a0 | 2015-09-03 05:37:23 -0700 | [diff] [blame] | 71 | 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 Meng | 96c05fc | 2015-02-02 22:35:24 +0800 | [diff] [blame] | 74 | msg_port_setup(MSG_OP_IO_WRITE, port, reg); |
| 75 | } |