1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
* Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <asm/errno.h>
#include <mach/ahci_sata.h>
int write_phy_ctl_ack_polling(u32 data, void __iomem *mmio,
int max_iterations, u32 exp_val)
{
u32 i, val;
writel(data, mmio + PORT_PHY_CTL);
for (i = 0; i < max_iterations + 1; i++) {
val = readl(mmio + PORT_PHY_SR);
val = (val >> PORT_PHY_STAT_ACK_LOC) & 0x1;
if (val == exp_val)
return 0;
if (i == max_iterations) {
pr_err("Wait for CR ACK error!\n");
return 1;
}
usleep_range(100, 200);
}
return 0;
}
int sata_phy_cr_addr(u32 addr, void __iomem *mmio)
{
u32 temp_wr_data;
/* write addr */
temp_wr_data = addr;
writel(temp_wr_data, mmio + PORT_PHY_CTL);
/* capture addr */
temp_wr_data |= PORT_PHY_CTL_CAP_ADR_LOC;
/* wait for ack */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 1))
return 1;
/* deassert cap addr */
temp_wr_data &= 0xffff;
/* wait for ack de-assetion */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 0))
return 1;
return 0;
}
int sata_phy_cr_write(u32 data, void __iomem *mmio)
{
u32 temp_wr_data;
/* write data */
temp_wr_data = data;
/* capture data */
temp_wr_data |= PORT_PHY_CTL_CAP_DAT_LOC;
/* wait for ack */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 1))
return 1;
/* deassert cap data */
temp_wr_data &= 0xffff;
/* wait for ack de-assetion */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 0))
return 1;
/* assert wr signal */
temp_wr_data |= PORT_PHY_CTL_WRITE_LOC;
/* wait for ack */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 1))
return 1;
/* deassert wr _signal */
temp_wr_data = 0x0;
/* wait for ack de-assetion */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 0))
return 1;
return 0;
}
int sata_phy_cr_read(u32 *data, void __iomem *mmio)
{
u32 temp_rd_data, temp_wr_data;
/* assert rd signal */
temp_wr_data = PORT_PHY_CTL_READ_LOC;
/* wait for ack */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 1))
return 1;
/* after got ack return data */
temp_rd_data = readl(mmio + PORT_PHY_SR);
*data = (temp_rd_data & 0xffff);
/* deassert rd _signal */
temp_wr_data = 0x0 ;
/* wait for ack de-assetion */
if (write_phy_ctl_ack_polling(temp_wr_data, mmio, 100, 0))
return 1;
return 0;
}
/* AHCI module Initialization, if return 0, initialization is successful. */
int sata_init(void __iomem *addr, unsigned long timer1ms)
{
u32 tmpdata;
int iterations = 20;
/* Reset HBA */
writel(HOST_RESET, addr + HOST_CTL);
tmpdata = readl(addr + HOST_VERSIONR);
tmpdata = 0;
while (readl(addr + HOST_VERSIONR) == 0) {
tmpdata++;
if (tmpdata > 100000) {
pr_err("Can't recover from RESET HBA!\n");
break;
}
}
tmpdata = readl(addr + HOST_CAP);
if (!(tmpdata & HOST_CAP_SSS)) {
tmpdata |= HOST_CAP_SSS;
writel(tmpdata, addr + HOST_CAP);
}
tmpdata = readl(addr + HOST_CAP);
if (!(readl(addr + HOST_PORTS_IMPL) & 0x1))
writel((readl(addr + HOST_PORTS_IMPL) | 0x1),
addr + HOST_PORTS_IMPL);
writel(timer1ms, addr + HOST_TIMER1MS);
/* Release resources when there is no device on the port */
do {
if ((readl(addr + PORT_SATA_SR) & 0xF) == 0)
msleep(25);
else
break;
if (iterations == 0) {
pr_info("No sata disk.\n");
/* Enter into PDDQ mode, save power */
tmpdata = readl(addr + PORT_PHY_CTL);
writel(tmpdata | PORT_PHY_CTL_PDDQ_LOC,
addr + PORT_PHY_CTL);
return -ENODEV;
}
} while (iterations-- > 0);
return 0;
}
|