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, wuzhangjin@gmail.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 _rdmsr(IDE_MSR_REG(IDE_IO_BAR
), &hi
, &lo
);
55 lo
= (value
& 0xfffffff0) | 0x1;
56 _wrmsr(IDE_MSR_REG(IDE_IO_BAR
), hi
, lo
);
59 hi
= 0x60000000 | ((value
& 0x000ff000) >> 12);
60 lo
= 0x000ffff0 | ((value
& 0x00000fff) << 20);
61 _wrmsr(GLIU_MSR_REG(GLIU_IOD_BM2
), hi
, lo
);
65 if (value
== CS5536_IDE_FLASH_SIGNATURE
) {
66 _rdmsr(DIVIL_MSR_REG(DIVIL_BALL_OPTS
), &hi
, &lo
);
68 _wrmsr(DIVIL_MSR_REG(DIVIL_BALL_OPTS
), hi
, lo
);
70 _rdmsr(IDE_MSR_REG(IDE_CFG
), &hi
, &lo
);
72 _wrmsr(IDE_MSR_REG(IDE_CFG
), hi
, lo
);
76 _rdmsr(IDE_MSR_REG(IDE_DTC
), &hi
, &lo
);
78 _wrmsr(IDE_MSR_REG(IDE_DTC
), hi
, lo
);
80 case PCI_IDE_CAST_REG
:
81 _rdmsr(IDE_MSR_REG(IDE_CAST
), &hi
, &lo
);
83 _wrmsr(IDE_MSR_REG(IDE_CAST
), hi
, lo
);
86 _rdmsr(IDE_MSR_REG(IDE_ETC
), &hi
, &lo
);
88 _wrmsr(IDE_MSR_REG(IDE_ETC
), hi
, lo
);
91 _rdmsr(IDE_MSR_REG(IDE_INTERNAL_PM
), &hi
, &lo
);
93 _wrmsr(IDE_MSR_REG(IDE_INTERNAL_PM
), hi
, lo
);
100 u32
pci_ide_read_reg(int reg
)
108 CFG_PCI_VENDOR_ID(CS5536_IDE_DEVICE_ID
, CS5536_VENDOR_ID
);
111 _rdmsr(IDE_MSR_REG(IDE_IO_BAR
), &hi
, &lo
);
113 conf_data
|= PCI_COMMAND_IO
;
114 _rdmsr(GLIU_MSR_REG(GLIU_PAE
), &hi
, &lo
);
115 if ((lo
& 0x30) == 0x30)
116 conf_data
|= PCI_COMMAND_MASTER
;
119 conf_data
|= PCI_STATUS_66MHZ
;
120 conf_data
|= PCI_STATUS_FAST_BACK
;
121 _rdmsr(SB_MSR_REG(SB_ERROR
), &hi
, &lo
);
122 if (lo
& SB_PARE_ERR_FLAG
)
123 conf_data
|= PCI_STATUS_PARITY
;
124 conf_data
|= PCI_STATUS_DEVSEL_MEDIUM
;
126 case PCI_CLASS_REVISION
:
127 _rdmsr(IDE_MSR_REG(IDE_CAP
), &hi
, &lo
);
128 conf_data
= lo
& 0x000000ff;
129 conf_data
|= (CS5536_IDE_CLASS_CODE
<< 8);
131 case PCI_CACHE_LINE_SIZE
:
132 _rdmsr(SB_MSR_REG(SB_CTRL
), &hi
, &lo
);
134 conf_data
= CFG_PCI_CACHE_LINE_SIZE(PCI_NORMAL_HEADER_TYPE
, hi
);
137 _rdmsr(GLCP_MSR_REG(GLCP_SOFT_COM
), &hi
, &lo
);
138 if (lo
& SOFT_BAR_IDE_FLAG
) {
139 conf_data
= CS5536_IDE_RANGE
|
140 PCI_BASE_ADDRESS_SPACE_IO
;
141 lo
&= ~SOFT_BAR_IDE_FLAG
;
142 _wrmsr(GLCP_MSR_REG(GLCP_SOFT_COM
), hi
, lo
);
144 _rdmsr(IDE_MSR_REG(IDE_IO_BAR
), &hi
, &lo
);
145 conf_data
= lo
& 0xfffffff0;
150 case PCI_CARDBUS_CIS
:
151 conf_data
= PCI_CARDBUS_CIS_POINTER
;
153 case PCI_SUBSYSTEM_VENDOR_ID
:
155 CFG_PCI_VENDOR_ID(CS5536_IDE_SUB_ID
, CS5536_SUB_VENDOR_ID
);
157 case PCI_ROM_ADDRESS
:
158 conf_data
= PCI_EXPANSION_ROM_BAR
;
160 case PCI_CAPABILITY_LIST
:
161 conf_data
= PCI_CAPLIST_POINTER
;
163 case PCI_INTERRUPT_LINE
:
165 CFG_PCI_INTERRUPT_LINE(PCI_DEFAULT_PIN
, CS5536_IDE_INTR
);
167 case PCI_IDE_CFG_REG
:
168 _rdmsr(IDE_MSR_REG(IDE_CFG
), &hi
, &lo
);
171 case PCI_IDE_DTC_REG
:
172 _rdmsr(IDE_MSR_REG(IDE_DTC
), &hi
, &lo
);
175 case PCI_IDE_CAST_REG
:
176 _rdmsr(IDE_MSR_REG(IDE_CAST
), &hi
, &lo
);
179 case PCI_IDE_ETC_REG
:
180 _rdmsr(IDE_MSR_REG(IDE_ETC
), &hi
, &lo
);
184 _rdmsr(IDE_MSR_REG(IDE_INTERNAL_PM
), &hi
, &lo
);