2 * the IDE Virtual Support Module of AMD CS5536
4 * Copyright (C) 2007 Lemote, Inc.
5 * Author : jlliu, liujl@lemote.com
7 * Copyright (C) 2009 Lemote, Inc.
8 * Author: Wu Zhangjin, wuzj@lemote.com
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <cs5536/cs5536.h>
17 #include <cs5536/cs5536_pci.h>
19 void pci_ide_write_reg(int reg
, u32 value
)
21 u32 hi
= 0, lo
= value
;
25 _rdmsr(GLIU_MSR_REG(GLIU_PAE
), &hi
, &lo
);
26 if (value
& PCI_COMMAND_MASTER
)
30 _wrmsr(GLIU_MSR_REG(GLIU_PAE
), hi
, lo
);
33 if (value
& PCI_STATUS_PARITY
) {
34 _rdmsr(SB_MSR_REG(SB_ERROR
), &hi
, &lo
);
35 if (lo
& SB_PARE_ERR_FLAG
) {
36 lo
= (lo
& 0x0000ffff) | SB_PARE_ERR_FLAG
;
37 _wrmsr(SB_MSR_REG(SB_ERROR
), hi
, lo
);
41 case PCI_CACHE_LINE_SIZE
:
43 _rdmsr(SB_MSR_REG(SB_CTRL
), &hi
, &lo
);
46 _wrmsr(SB_MSR_REG(SB_CTRL
), hi
, lo
);
49 if (value
== PCI_BAR_RANGE_MASK
) {
50 _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM
), &hi
, &lo
);
51 lo
|= SOFT_BAR_IDE_FLAG
;
52 _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM
), hi
, lo
);
53 } else if (value
& 0x01) {
54 lo
= (value
& 0xfffffff0) | 0x1;
55 _wrmsr(IDE_MSR_REG(IDE_IO_BAR
), hi
, lo
);
58 hi
= 0x60000000 | ((value
& 0x000ff000) >> 12);
59 lo
= 0x000ffff0 | ((value
& 0x00000fff) << 20);
60 _wrmsr(GLIU_MSR_REG(GLIU_IOD_BM2
), hi
, lo
);
64 if (value
== CS5536_IDE_FLASH_SIGNATURE
) {
65 _rdmsr(DIVIL_MSR_REG(DIVIL_BALL_OPTS
), &hi
, &lo
);
67 _wrmsr(DIVIL_MSR_REG(DIVIL_BALL_OPTS
), hi
, lo
);
69 _wrmsr(IDE_MSR_REG(IDE_CFG
), hi
, lo
);
72 _wrmsr(IDE_MSR_REG(IDE_DTC
), hi
, lo
);
74 case PCI_IDE_CAST_REG
:
75 _wrmsr(IDE_MSR_REG(IDE_CAST
), hi
, lo
);
78 _wrmsr(IDE_MSR_REG(IDE_ETC
), hi
, lo
);
81 _wrmsr(IDE_MSR_REG(IDE_INTERNAL_PM
), hi
, lo
);
88 u32
pci_ide_read_reg(int reg
)
96 CFG_PCI_VENDOR_ID(CS5536_IDE_DEVICE_ID
, CS5536_VENDOR_ID
);
99 _rdmsr(IDE_MSR_REG(IDE_IO_BAR
), &hi
, &lo
);
101 conf_data
|= PCI_COMMAND_IO
;
102 _rdmsr(GLIU_MSR_REG(GLIU_PAE
), &hi
, &lo
);
103 if ((lo
& 0x30) == 0x30)
104 conf_data
|= PCI_COMMAND_MASTER
;
107 conf_data
|= PCI_STATUS_66MHZ
;
108 conf_data
|= PCI_STATUS_FAST_BACK
;
109 _rdmsr(SB_MSR_REG(SB_ERROR
), &hi
, &lo
);
110 if (lo
& SB_PARE_ERR_FLAG
)
111 conf_data
|= PCI_STATUS_PARITY
;
112 conf_data
|= PCI_STATUS_DEVSEL_MEDIUM
;
114 case PCI_CLASS_REVISION
:
115 _rdmsr(IDE_MSR_REG(IDE_CAP
), &hi
, &lo
);
116 conf_data
= lo
& 0x000000ff;
117 conf_data
|= (CS5536_IDE_CLASS_CODE
<< 8);
119 case PCI_CACHE_LINE_SIZE
:
120 _rdmsr(SB_MSR_REG(SB_CTRL
), &hi
, &lo
);
122 conf_data
= CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE
, hi
);
125 _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM
), &hi
, &lo
);
126 if (lo
& SOFT_BAR_IDE_FLAG
) {
127 conf_data
= CS5536_IDE_RANGE
|
128 PCI_BASE_ADDRESS_SPACE_IO
;
129 lo
&= ~SOFT_BAR_IDE_FLAG
;
130 _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM
), hi
, lo
);
132 _rdmsr(IDE_MSR_REG(IDE_IO_BAR
), &hi
, &lo
);
133 conf_data
= lo
& 0xfffffff0;
138 case PCI_CARDBUS_CIS
:
139 conf_data
= PCI_CARDBUS_CIS_POINTER
;
141 case PCI_SUBSYSTEM_VENDOR_ID
:
143 CFG_PCI_VENDOR_ID(CS5536_IDE_SUB_ID
, CS5536_SUB_VENDOR_ID
);
145 case PCI_ROM_ADDRESS
:
146 conf_data
= PCI_EXPANSION_ROM_BAR
;
148 case PCI_CAPABILITY_LIST
:
149 conf_data
= PCI_CAPLIST_POINTER
;
151 case PCI_INTERRUPT_LINE
:
153 CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN
, CS5536_IDE_INTR
);
155 case PCI_IDE_CFG_REG
:
156 _rdmsr(IDE_MSR_REG(IDE_CFG
), &hi
, &lo
);
159 case PCI_IDE_DTC_REG
:
160 _rdmsr(IDE_MSR_REG(IDE_DTC
), &hi
, &lo
);
163 case PCI_IDE_CAST_REG
:
164 _rdmsr(IDE_MSR_REG(IDE_CAST
), &hi
, &lo
);
167 case PCI_IDE_ETC_REG
:
168 _rdmsr(IDE_MSR_REG(IDE_ETC
), &hi
, &lo
);
171 _rdmsr(IDE_MSR_REG(IDE_INTERNAL_PM
), &hi
, &lo
);