Skip to content

Commit 7f78322

Browse files
grygoriySvinodkoul
authored andcommitted
phy: ti: gmii-sel: retrieve ports number and base offset from dt
On K3 AM654x/J721E platforms the Port MII mode selection register(s) have similar format and placed in the System Control Module (SCM) module sequentially as one register per port, but, depending SOC and CPSW instance, the base offset and number of ports can be different. Hence, add possibility to retrieve number of ports and base registers offset from DT and support for max possible number of ports supported by K3 SoCs like J721E. Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> Link: https://lore.kernel.org/r/20200828201943.29155-4-grygorii.strashko@ti.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent d3fa20b commit 7f78322

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

‎drivers/phy/ti/phy-gmii-sel.c‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/module.h>
1212
#include <linux/mfd/syscon.h>
1313
#include <linux/of.h>
14+
#include <linux/of_address.h>
1415
#include <linux/of_net.h>
1516
#include <linux/phy.h>
1617
#include <linux/phy/phy.h>
@@ -41,6 +42,7 @@ struct phy_gmii_sel_soc_data {
4142
u32 num_ports;
4243
u32 features;
4344
const struct reg_field (*regfields)[PHY_GMII_SEL_LAST];
45+
bool use_of_data;
4446
};
4547

4648
struct phy_gmii_sel_priv {
@@ -49,6 +51,8 @@ struct phy_gmii_sel_priv {
4951
struct regmap *regmap;
5052
struct phy_provider *phy_provider;
5153
struct phy_gmii_sel_phy_priv *if_phys;
54+
u32 num_ports;
55+
u32 reg_offset;
5256
};
5357

5458
static int phy_gmii_sel_mode(struct phy *phy, enum phy_mode mode, int submode)
@@ -168,14 +172,19 @@ struct phy_gmii_sel_soc_data phy_gmii_sel_soc_dm814 = {
168172

169173
static const
170174
struct reg_field phy_gmii_sel_fields_am654[][PHY_GMII_SEL_LAST] = {
171-
{
172-
[PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x4040, 0, 1),
173-
},
175+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x0, 0, 2), },
176+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x4, 0, 2), },
177+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x8, 0, 2), },
178+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0xC, 0, 2), },
179+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x10, 0, 2), },
180+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x14, 0, 2), },
181+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x18, 0, 2), },
182+
{ [PHY_GMII_SEL_PORT_MODE] = REG_FIELD(0x1C, 0, 2), },
174183
};
175184

176185
static const
177186
struct phy_gmii_sel_soc_data phy_gmii_sel_soc_am654 = {
178-
.num_ports = 1,
187+
.use_of_data = true,
179188
.regfields = phy_gmii_sel_fields_am654,
180189
};
181190

@@ -222,7 +231,7 @@ static struct phy *phy_gmii_sel_of_xlate(struct device *dev,
222231
if (priv->soc_data->features & BIT(PHY_GMII_SEL_RMII_IO_CLK_EN) &&
223232
args->args_count < 2)
224233
return ERR_PTR(-EINVAL);
225-
if (phy_id > priv->soc_data->num_ports)
234+
if (phy_id > priv->num_ports)
226235
return ERR_PTR(-EINVAL);
227236
if (phy_id != priv->if_phys[phy_id - 1].id)
228237
return ERR_PTR(-EINVAL);
@@ -251,6 +260,7 @@ static int phy_gmii_init_phy(struct phy_gmii_sel_priv *priv, int port,
251260

252261
fields = soc_data->regfields[port - 1];
253262
field = *fields++;
263+
field.reg += priv->reg_offset;
254264
dev_dbg(dev, "%s field %x %d %d\n", __func__,
255265
field.reg, field.msb, field.lsb);
256266

@@ -260,6 +270,7 @@ static int phy_gmii_init_phy(struct phy_gmii_sel_priv *priv, int port,
260270
if_phy->fields[PHY_GMII_SEL_PORT_MODE] = regfield;
261271

262272
field = *fields++;
273+
field.reg += priv->reg_offset;
263274
if (soc_data->features & BIT(PHY_GMII_SEL_RGMII_ID_MODE)) {
264275
regfield = devm_regmap_field_alloc(dev,
265276
priv->regmap,
@@ -272,6 +283,7 @@ static int phy_gmii_init_phy(struct phy_gmii_sel_priv *priv, int port,
272283
}
273284

274285
field = *fields;
286+
field.reg += priv->reg_offset;
275287
if (soc_data->features & BIT(PHY_GMII_SEL_RMII_IO_CLK_EN)) {
276288
regfield = devm_regmap_field_alloc(dev,
277289
priv->regmap,
@@ -299,19 +311,28 @@ static int phy_gmii_init_phy(struct phy_gmii_sel_priv *priv, int port,
299311
static int phy_gmii_sel_init_ports(struct phy_gmii_sel_priv *priv)
300312
{
301313
const struct phy_gmii_sel_soc_data *soc_data = priv->soc_data;
302-
struct device *dev = priv->dev;
303314
struct phy_gmii_sel_phy_priv *if_phys;
304-
int i, num_ports, ret;
315+
struct device *dev = priv->dev;
316+
int i, ret;
317+
318+
if (soc_data->use_of_data) {
319+
const __be32 *offset;
320+
u64 size;
305321

306-
num_ports = soc_data->num_ports;
322+
offset = of_get_address(dev->of_node, 0, &size, NULL);
323+
priv->num_ports = size / sizeof(u32);
324+
if (!priv->num_ports)
325+
return -EINVAL;
326+
priv->reg_offset = __be32_to_cpu(*offset);
327+
}
307328

308-
if_phys = devm_kcalloc(priv->dev, num_ports,
329+
if_phys = devm_kcalloc(dev, priv->num_ports,
309330
sizeof(*if_phys), GFP_KERNEL);
310331
if (!if_phys)
311332
return -ENOMEM;
312-
dev_dbg(dev, "%s %d\n", __func__, num_ports);
333+
dev_dbg(dev, "%s %d\n", __func__, priv->num_ports);
313334

314-
for (i = 0; i < num_ports; i++) {
335+
for (i = 0; i < priv->num_ports; i++) {
315336
ret = phy_gmii_init_phy(priv, i + 1, &if_phys[i]);
316337
if (ret)
317338
return ret;
@@ -339,6 +360,7 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
339360

340361
priv->dev = &pdev->dev;
341362
priv->soc_data = of_id->data;
363+
priv->num_ports = priv->soc_data->num_ports;
342364

343365
priv->regmap = syscon_node_to_regmap(node->parent);
344366
if (IS_ERR(priv->regmap)) {

0 commit comments

Comments
 (0)