Skip to content

Commit 721ad32

Browse files
committed
Merge branch 'Meson-GXL-internal-phy'
Neil Armstrong says: ==================== ARM64: Add Internal PHY support for Meson GXL The Amlogic Meson GXL SoCs have an internal RMII PHY that is muxed with the external RGMII pins. In order to support switching between the two PHYs links, extended registers size for mdio-mux-mmioreg must be added. The DT related patches submitted as RFC in [3] will be sent in a separate patchset due to multiple patchsets and DTSI migrations. Changes since v2 RFC patchset at : [3] - Change phy Kconfig/Makefile alphabetic order - GXL dtsi cleanup Changes since original RFC patchset at : [2] - Remove meson8b experimental phy switching - Switch to mdio-mux-mmioreg with extennded size support - Add internal phy support for S905x and p231 - Add external PHY support for p230 [1] http://lkml.kernel.org/r/1477932286-27482-1-git-send-email-narmstrong@baylibre.com [2] http://lkml.kernel.org/r/1477060838-14164-1-git-send-email-narmstrong@baylibre.com [3] http://lkml.kernel.org/r/1477932987-27871-1-git-send-email-narmstrong@baylibre.com ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ddc5e15 + 7334b3e commit 721ad32

5 files changed

Lines changed: 136 additions & 15 deletions

File tree

‎Documentation/devicetree/bindings/net/mdio-mux-mmioreg.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ Properties for an MDIO bus multiplexer controlled by a memory-mapped device
33
This is a special case of a MDIO bus multiplexer. A memory-mapped device,
44
like an FPGA, is used to control which child bus is connected. The mdio-mux
55
node must be a child of the memory-mapped device. The driver currently only
6-
supports devices with eight-bit registers.
6+
supports devices with 8, 16 or 32-bit registers.
77

88
Required properties in addition to the generic multiplexer properties:
99

1010
- compatible : string, must contain "mdio-mux-mmioreg"
1111

1212
- reg : integer, contains the offset of the register that controls the bus
1313
multiplexer. The size field in the 'reg' property is the size of
14-
register, and must therefore be 1.
14+
register, and must therefore be 1, 2, or 4.
1515

1616
- mux-mask : integer, contains an eight-bit mask that specifies which
1717
bits in the register control the actual bus multiplexer. The

‎drivers/net/phy/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ config MARVELL_PHY
277277
---help---
278278
Currently has a driver for the 88E1011S
279279

280+
config MESON_GXL_PHY
281+
tristate "Amlogic Meson GXL Internal PHY"
282+
---help---
283+
Currently has a driver for the Amlogic Meson GXL Internal PHY
284+
280285
config MICREL_PHY
281286
tristate "Micrel PHYs"
282287
---help---

‎drivers/net/phy/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ obj-$(CONFIG_INTEL_XWAY_PHY) += intel-xway.o
4242
obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
4343
obj-$(CONFIG_LXT_PHY) += lxt.o
4444
obj-$(CONFIG_MARVELL_PHY) += marvell.o
45+
obj-$(CONFIG_MESON_GXL_PHY) += meson-gxl.o
4546
obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
4647
obj-$(CONFIG_MICREL_PHY) += micrel.o
4748
obj-$(CONFIG_MICROCHIP_PHY) += microchip.o

‎drivers/net/phy/mdio-mux-mmioreg.c‎

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
struct mdio_mux_mmioreg_state {
2222
void *mux_handle;
2323
phys_addr_t phys;
24-
uint8_t mask;
24+
unsigned int iosize;
25+
unsigned int mask;
2526
};
2627

2728
/*
@@ -47,17 +48,47 @@ static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child,
4748
struct mdio_mux_mmioreg_state *s = data;
4849

4950
if (current_child ^ desired_child) {
50-
void __iomem *p = ioremap(s->phys, 1);
51-
uint8_t x, y;
52-
51+
void __iomem *p = ioremap(s->phys, s->iosize);
5352
if (!p)
5453
return -ENOMEM;
5554

56-
x = ioread8(p);
57-
y = (x & ~s->mask) | desired_child;
58-
if (x != y) {
59-
iowrite8((x & ~s->mask) | desired_child, p);
60-
pr_debug("%s: %02x -> %02x\n", __func__, x, y);
55+
switch (s->iosize) {
56+
case sizeof(uint8_t): {
57+
uint8_t x, y;
58+
59+
x = ioread8(p);
60+
y = (x & ~s->mask) | desired_child;
61+
if (x != y) {
62+
iowrite8((x & ~s->mask) | desired_child, p);
63+
pr_debug("%s: %02x -> %02x\n", __func__, x, y);
64+
}
65+
66+
break;
67+
}
68+
case sizeof(uint16_t): {
69+
uint16_t x, y;
70+
71+
x = ioread16(p);
72+
y = (x & ~s->mask) | desired_child;
73+
if (x != y) {
74+
iowrite16((x & ~s->mask) | desired_child, p);
75+
pr_debug("%s: %04x -> %04x\n", __func__, x, y);
76+
}
77+
78+
break;
79+
}
80+
case sizeof(uint32_t): {
81+
uint32_t x, y;
82+
83+
x = ioread32(p);
84+
y = (x & ~s->mask) | desired_child;
85+
if (x != y) {
86+
iowrite32((x & ~s->mask) | desired_child, p);
87+
pr_debug("%s: %08x -> %08x\n", __func__, x, y);
88+
}
89+
90+
break;
91+
}
6192
}
6293

6394
iounmap(p);
@@ -88,8 +119,11 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
88119
}
89120
s->phys = res.start;
90121

91-
if (resource_size(&res) != sizeof(uint8_t)) {
92-
dev_err(&pdev->dev, "only 8-bit registers are supported\n");
122+
s->iosize = resource_size(&res);
123+
if (s->iosize != sizeof(uint8_t) &&
124+
s->iosize != sizeof(uint16_t) &&
125+
s->iosize != sizeof(uint32_t)) {
126+
dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n");
93127
return -EINVAL;
94128
}
95129

@@ -98,8 +132,8 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
98132
dev_err(&pdev->dev, "missing or invalid mux-mask property\n");
99133
return -ENODEV;
100134
}
101-
if (be32_to_cpup(iprop) > 255) {
102-
dev_err(&pdev->dev, "only 8-bit registers are supported\n");
135+
if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) {
136+
dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n");
103137
return -EINVAL;
104138
}
105139
s->mask = be32_to_cpup(iprop);

‎drivers/net/phy/meson-gxl.c‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Amlogic Meson GXL Internal PHY Driver
3+
*
4+
* Copyright (C) 2015 Amlogic, Inc. All rights reserved.
5+
* Copyright (C) 2016 BayLibre, SAS. All rights reserved.
6+
* Author: Neil Armstrong <narmstrong@baylibre.com>
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16+
* more details.
17+
*
18+
*/
19+
#include <linux/kernel.h>
20+
#include <linux/module.h>
21+
#include <linux/mii.h>
22+
#include <linux/ethtool.h>
23+
#include <linux/phy.h>
24+
#include <linux/netdevice.h>
25+
26+
static int meson_gxl_config_init(struct phy_device *phydev)
27+
{
28+
/* Enable Analog and DSP register Bank access by */
29+
phy_write(phydev, 0x14, 0x0000);
30+
phy_write(phydev, 0x14, 0x0400);
31+
phy_write(phydev, 0x14, 0x0000);
32+
phy_write(phydev, 0x14, 0x0400);
33+
34+
/* Write Analog register 23 */
35+
phy_write(phydev, 0x17, 0x8E0D);
36+
phy_write(phydev, 0x14, 0x4417);
37+
38+
/* Enable fractional PLL */
39+
phy_write(phydev, 0x17, 0x0005);
40+
phy_write(phydev, 0x14, 0x5C1B);
41+
42+
/* Program fraction FR_PLL_DIV1 */
43+
phy_write(phydev, 0x17, 0x029A);
44+
phy_write(phydev, 0x14, 0x5C1D);
45+
46+
/* Program fraction FR_PLL_DIV1 */
47+
phy_write(phydev, 0x17, 0xAAAA);
48+
phy_write(phydev, 0x14, 0x5C1C);
49+
50+
return 0;
51+
}
52+
53+
static struct phy_driver meson_gxl_phy[] = {
54+
{
55+
.phy_id = 0x01814400,
56+
.phy_id_mask = 0xfffffff0,
57+
.name = "Meson GXL Internal PHY",
58+
.features = PHY_BASIC_FEATURES,
59+
.flags = PHY_IS_INTERNAL,
60+
.config_init = meson_gxl_config_init,
61+
.config_aneg = genphy_config_aneg,
62+
.aneg_done = genphy_aneg_done,
63+
.read_status = genphy_read_status,
64+
.suspend = genphy_suspend,
65+
.resume = genphy_resume,
66+
},
67+
};
68+
69+
static struct mdio_device_id __maybe_unused meson_gxl_tbl[] = {
70+
{ 0x01814400, 0xfffffff0 },
71+
{ }
72+
};
73+
74+
module_phy_driver(meson_gxl_phy);
75+
76+
MODULE_DEVICE_TABLE(mdio, meson_gxl_tbl);
77+
78+
MODULE_DESCRIPTION("Amlogic Meson GXL Internal PHY driver");
79+
MODULE_AUTHOR("Baoqi wang");
80+
MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
81+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)