-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathintel-m10-bmc-retimer.c
More file actions
230 lines (180 loc) · 5.55 KB
/
intel-m10-bmc-retimer.c
File metadata and controls
230 lines (180 loc) · 5.55 KB
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
/* Intel Max10 BMC Retimer Interface Driver
*
* Copyright (C) 2018-2020 Intel Corporation. All rights reserved.
*
*/
#include <linux/device.h>
#include <linux/mfd/intel-m10-bmc.h>
#include <linux/module.h>
#include <linux/phy.h>
#include <linux/platform_device.h>
#define NUM_CHIP 2
#define MAX_LINK 4
#define BITS_MASK(nbits) ((1 << (nbits)) - 1)
#define N3000BMC_RETIMER_DEV_NAME "n3000bmc-retimer"
#define M10BMC_RETIMER_MII_NAME "m10bmc retimer mii"
struct m10bmc_retimer {
struct device *dev;
struct intel_m10bmc *m10bmc;
int num_devs;
struct device *base_dev;
struct mii_bus *retimer_mii_bus;
};
#define RETIMER_LINK_STAT_BIT(retimer_id, link_id) \
BIT(((retimer_id) << 2) + (link_id))
static u32 retimer_get_link(struct m10bmc_retimer *retimer, int index)
{
unsigned int val;
if (m10bmc_sys_read(retimer->m10bmc, PKVL_LINK_STATUS, &val)) {
dev_err(retimer->dev, "fail to read PKVL_LINK_STATUS\n");
return 0;
}
if (val & BIT(index))
return 1;
return 0;
}
static int m10bmc_retimer_phy_match(struct phy_device *phydev)
{
if (phydev->mdio.bus->name &&
!strcmp(phydev->mdio.bus->name, M10BMC_RETIMER_MII_NAME)) {
return 1;
}
return 0;
}
static int m10bmc_retimer_phy_probe(struct phy_device *phydev)
{
struct m10bmc_retimer *retimer = phydev->mdio.bus->priv;
phydev->priv = retimer;
return 0;
}
static void m10bmc_retimer_phy_remove(struct phy_device *phydev)
{
if (phydev->attached_dev)
phy_disconnect(phydev);
}
static int m10bmc_retimer_read_status(struct phy_device *phydev)
{
struct m10bmc_retimer *retimer = phydev->priv;
phydev->link = retimer_get_link(retimer, phydev->mdio.addr);
phydev->duplex = DUPLEX_FULL;
return 0;
}
static int m10bmc_retimer_get_features(struct phy_device *phydev)
{
linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
phydev->supported);
linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported);
return 0;
}
static struct phy_driver m10bmc_retimer_phy_driver = {
.phy_id = 0xffffffff,
.phy_id_mask = 0xffffffff,
.name = "m10bmc retimer PHY",
.match_phy_device = m10bmc_retimer_phy_match,
.probe = m10bmc_retimer_phy_probe,
.remove = m10bmc_retimer_phy_remove,
.read_status = m10bmc_retimer_read_status,
.get_features = m10bmc_retimer_get_features,
.read_mmd = genphy_read_mmd_unsupported,
.write_mmd = genphy_write_mmd_unsupported,
};
static int m10bmc_retimer_read(struct mii_bus *bus, int addr, int regnum)
{
struct m10bmc_retimer *retimer = bus->priv;
if (addr < retimer->num_devs &&
(regnum == MII_PHYSID1 || regnum == MII_PHYSID2))
return 0;
return 0xffff;
}
static int m10bmc_retimer_write(struct mii_bus *bus, int addr, int regnum, u16 val)
{
return 0;
}
static int m10bmc_retimer_mii_bus_init(struct m10bmc_retimer *retimer)
{
struct mii_bus *bus;
int ret;
bus = devm_mdiobus_alloc(retimer->dev);
if (!bus)
return -ENOMEM;
bus->priv = (void *)retimer;
bus->name = M10BMC_RETIMER_MII_NAME;
bus->read = m10bmc_retimer_read;
bus->write = m10bmc_retimer_write;
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii",
dev_name(retimer->base_dev));
bus->parent = retimer->dev;
bus->phy_mask = ~(BITS_MASK(retimer->num_devs));
ret = mdiobus_register(bus);
if (ret)
return ret;
retimer->retimer_mii_bus = bus;
return 0;
}
static void m10bmc_retimer_mii_bus_uinit(struct m10bmc_retimer *retimer)
{
mdiobus_unregister(retimer->retimer_mii_bus);
}
static int intel_m10bmc_retimer_probe(struct platform_device *pdev)
{
struct intel_m10bmc_retimer_pdata *pdata = dev_get_platdata(&pdev->dev);
struct intel_m10bmc *m10bmc = dev_get_drvdata(pdev->dev.parent);
struct m10bmc_retimer *retimer;
retimer = devm_kzalloc(&pdev->dev, sizeof(*retimer), GFP_KERNEL);
if (!retimer)
return -ENOMEM;
dev_set_drvdata(&pdev->dev, retimer);
retimer->dev = &pdev->dev;
retimer->m10bmc = m10bmc;
retimer->base_dev = pdata->retimer_master;
retimer->num_devs = NUM_CHIP * MAX_LINK;
return m10bmc_retimer_mii_bus_init(retimer);
}
static int intel_m10bmc_retimer_remove(struct platform_device *pdev)
{
struct m10bmc_retimer *retimer = dev_get_drvdata(&pdev->dev);
m10bmc_retimer_mii_bus_uinit(retimer);
return 0;
}
static struct platform_driver intel_m10bmc_retimer_driver = {
.probe = intel_m10bmc_retimer_probe,
.remove = intel_m10bmc_retimer_remove,
.driver = {
.name = N3000BMC_RETIMER_DEV_NAME,
},
};
static int __init intel_m10bmc_retimer_init(void)
{
int ret;
ret = phy_driver_register(&m10bmc_retimer_phy_driver, THIS_MODULE);
if (ret)
return ret;
return platform_driver_register(&intel_m10bmc_retimer_driver);
}
module_init(intel_m10bmc_retimer_init);
static void __exit intel_m10bmc_retimer_exit(void)
{
platform_driver_unregister(&intel_m10bmc_retimer_driver);
phy_driver_unregister(&m10bmc_retimer_phy_driver);
}
module_exit(intel_m10bmc_retimer_exit);
MODULE_ALIAS("platform:" N3000BMC_RETIMER_DEV_NAME);
MODULE_AUTHOR("Intel Corporation");
MODULE_DESCRIPTION("Intel MAX 10 BMC retimer driver");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS(INTEL_M10_BMC_CORE);