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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2025 Aspeed Technology Inc.
*/
#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/phy/pcie.h>
#include <linux/phy/phy.h>
/* AST2600 PCIe Host Controller Registers */
#define PEHR_GLOBAL 0x30
#define AST2600_PORT_TYPE_MASK GENMASK(5, 4)
#define PEHR_LOCK 0x7c
#define PCIE_UNLOCK 0xa8
/* AST2700 PEHR */
#define PEHR_MISC_58 0x58
#define LOCAL_SCALE_SUP BIT(0)
#define PEHR_MISC_5C 0x5c
#define CONFIG_RC_DEVICE BIT(30)
#define PEHR_MISC_60 0x60
#define AST2700_PORT_TYPE_MASK GENMASK(7, 4)
#define PORT_TYPE_ROOT 0x4
#define PEHR_MISC_70 0x70
#define POSTED_DATA_CREDITS(x) FIELD_PREP(GENMASK(15, 0), x)
#define POSTED_HEADER_CREDITS(x) FIELD_PREP(GENMASK(27, 16), x)
#define PEHR_MISC_78 0x78
#define COMPLETION_DATA_CREDITS(x) FIELD_PREP(GENMASK(15, 0), x)
#define COMPLETION_HEADER_CREDITS(x) FIELD_PREP(GENMASK(27, 16), x)
#define PEHR_MISC_278 0x278
#define SET_TO_DOWNSTREAM BIT(22)
#define ASSERT_INTERNAL_RESET BIT(31)
#define PEHR_MISC_280 0x280
#define SEL_INTERNAL_RESET BIT(0)
/**
* struct aspeed_pcie_phy - PCIe PHY information
* @reg: PCIe host register base address
* @clk: PCIe reference clock
* @phy: pointer to PHY structure
* @platform: platform specific information
*/
struct aspeed_pcie_phy {
void __iomem *reg;
struct clk *clk;
struct phy *phy;
const struct aspeed_pcie_phy_platform *platform;
};
/**
* struct aspeed_pcie_phy_platform - Platform information
* @phy_ops: phy operations
*/
struct aspeed_pcie_phy_platform {
const struct phy_ops *phy_ops;
};
static int ast2600_phy_init(struct phy *phy)
{
struct aspeed_pcie_phy *pcie_phy = phy_get_drvdata(phy);
int ret;
ret = clk_prepare_enable(pcie_phy->clk);
if (ret)
return ret;
writel(PCIE_UNLOCK, pcie_phy->reg + PEHR_LOCK);
return 0;
}
static int aspeed_pcie_phy_exit(struct phy *phy)
{
struct aspeed_pcie_phy *pcie_phy = phy_get_drvdata(phy);
clk_disable_unprepare(pcie_phy->clk);
return 0;
}
static int ast2600_phy_set_mode(struct phy *phy, enum phy_mode mode,
int submode)
{
struct aspeed_pcie_phy *pcie_phy = phy_get_drvdata(phy);
u32 cfg_val;
switch (submode) {
case PHY_MODE_PCIE_RC:
cfg_val = readl(pcie_phy->reg + PEHR_GLOBAL);
FIELD_MODIFY(AST2600_PORT_TYPE_MASK, &cfg_val, 0x3);
writel(cfg_val, pcie_phy->reg + PEHR_GLOBAL);
break;
default:
dev_err(&phy->dev, "Unsupported submode %d\n", submode);
return -EINVAL;
}
return 0;
}
static const struct phy_ops ast2600_phy_ops = {
.init = ast2600_phy_init,
.exit = aspeed_pcie_phy_exit,
.set_mode = ast2600_phy_set_mode,
.owner = THIS_MODULE,
};
static int ast2700_phy_init(struct phy *phy)
{
struct aspeed_pcie_phy *pcie_phy = phy_get_drvdata(phy);
return clk_prepare_enable(pcie_phy->clk);
}
static int ast2700_phy_set_mode(struct phy *phy, enum phy_mode mode,
int submode)
{
struct aspeed_pcie_phy *pcie_phy = phy_get_drvdata(phy);
u32 cfg_val;
switch (submode) {
case PHY_MODE_PCIE_RC:
writel(0, pcie_phy->reg + PEHR_MISC_278);
writel(SEL_INTERNAL_RESET, pcie_phy->reg + PEHR_MISC_280);
writel(POSTED_DATA_CREDITS(0xc0) | POSTED_HEADER_CREDITS(0xa),
pcie_phy->reg + PEHR_MISC_70);
writel(COMPLETION_DATA_CREDITS(0x30) | COMPLETION_HEADER_CREDITS(0x8),
pcie_phy->reg + PEHR_MISC_78);
writel(LOCAL_SCALE_SUP, pcie_phy->reg + PEHR_MISC_58);
writel(CONFIG_RC_DEVICE, pcie_phy->reg + PEHR_MISC_5C);
cfg_val = readl(pcie_phy->reg + PEHR_MISC_60);
FIELD_MODIFY(AST2700_PORT_TYPE_MASK, &cfg_val,
PORT_TYPE_ROOT);
writel(cfg_val, pcie_phy->reg + PEHR_MISC_60);
writel(ASSERT_INTERNAL_RESET | SET_TO_DOWNSTREAM,
pcie_phy->reg + PEHR_MISC_278);
break;
default:
dev_err(&phy->dev, "Unsupported submode %d\n", submode);
return -EINVAL;
}
return 0;
}
static const struct phy_ops ast2700_phy_ops = {
.init = ast2700_phy_init,
.exit = aspeed_pcie_phy_exit,
.set_mode = ast2700_phy_set_mode,
.owner = THIS_MODULE,
};
static const struct aspeed_pcie_phy_platform pcie_phy_ast2600 = {
.phy_ops = &ast2600_phy_ops,
};
static const struct aspeed_pcie_phy_platform pcie_phy_ast2700 = {
.phy_ops = &ast2700_phy_ops,
};
static int aspeed_pcie_phy_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct phy_provider *phy_provider;
struct aspeed_pcie_phy *pcie_phy;
const struct aspeed_pcie_phy_platform *md;
md = of_device_get_match_data(dev);
if (!md)
return -ENODEV;
pcie_phy = devm_kzalloc(dev, sizeof(*pcie_phy), GFP_KERNEL);
if (!pcie_phy)
return -ENOMEM;
pcie_phy->reg = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pcie_phy->reg))
return PTR_ERR(pcie_phy->reg);
pcie_phy->clk = devm_clk_get(dev, NULL);
if (IS_ERR(pcie_phy->clk))
return dev_err_probe(dev, PTR_ERR(pcie_phy->clk),
"failed to get clock\n");
pcie_phy->platform = md;
pcie_phy->phy = devm_phy_create(dev, dev->of_node,
pcie_phy->platform->phy_ops);
if (IS_ERR(pcie_phy->phy))
return dev_err_probe(dev, PTR_ERR(pcie_phy->phy),
"failed to create PHY\n");
phy_set_drvdata(pcie_phy->phy, pcie_phy);
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
return PTR_ERR_OR_ZERO(phy_provider);
}
static const struct of_device_id aspeed_pcie_phy_of_match_table[] = {
{
.compatible = "aspeed,ast2600-pcie-phy",
.data = &pcie_phy_ast2600,
},
{
.compatible = "aspeed,ast2700-pcie-phy",
.data = &pcie_phy_ast2700,
},
{ },
};
MODULE_DEVICE_TABLE(of, aspeed_pcie_phy_of_match_table);
static struct platform_driver aspeed_pcie_driver = {
.probe = aspeed_pcie_phy_probe,
.driver = {
.name = "aspeed-pcie-phy",
.of_match_table = aspeed_pcie_phy_of_match_table,
},
};
module_platform_driver(aspeed_pcie_driver);
MODULE_AUTHOR("Jacky Chou <jacky_chou@aspeedtech.com>");
MODULE_DESCRIPTION("ASPEED PCIe PHY");
MODULE_LICENSE("GPL");
|