Loading...
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Driver for the Renesas PHY uPD60620.
4 *
5 * Copyright (C) 2015 Softing Industrial Automation GmbH
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/phy.h>
11
12#define UPD60620_PHY_ID 0xb8242824
13
14/* Extended Registers and values */
15/* PHY Special Control/Status */
16#define PHY_PHYSCR 0x1F /* PHY.31 */
17#define PHY_PHYSCR_10MB 0x0004 /* PHY speed = 10mb */
18#define PHY_PHYSCR_100MB 0x0008 /* PHY speed = 100mb */
19#define PHY_PHYSCR_DUPLEX 0x0010 /* PHY Duplex */
20
21/* PHY Special Modes */
22#define PHY_SPM 0x12 /* PHY.18 */
23
24/* Init PHY */
25
26static int upd60620_config_init(struct phy_device *phydev)
27{
28 /* Enable support for passive HUBs (could be a strap option) */
29 /* PHYMODE: All speeds, HD in parallel detect */
30 return phy_write(phydev, PHY_SPM, 0x0180 | phydev->mdio.addr);
31}
32
33/* Get PHY status from common registers */
34
35static int upd60620_read_status(struct phy_device *phydev)
36{
37 int phy_state;
38
39 /* Read negotiated state */
40 phy_state = phy_read(phydev, MII_BMSR);
41 if (phy_state < 0)
42 return phy_state;
43
44 phydev->link = 0;
45 linkmode_zero(phydev->lp_advertising);
46 phydev->pause = 0;
47 phydev->asym_pause = 0;
48
49 if (phy_state & (BMSR_ANEGCOMPLETE | BMSR_LSTATUS)) {
50 phy_state = phy_read(phydev, PHY_PHYSCR);
51 if (phy_state < 0)
52 return phy_state;
53
54 if (phy_state & (PHY_PHYSCR_10MB | PHY_PHYSCR_100MB)) {
55 phydev->link = 1;
56 phydev->speed = SPEED_10;
57 phydev->duplex = DUPLEX_HALF;
58
59 if (phy_state & PHY_PHYSCR_100MB)
60 phydev->speed = SPEED_100;
61 if (phy_state & PHY_PHYSCR_DUPLEX)
62 phydev->duplex = DUPLEX_FULL;
63
64 phy_state = phy_read(phydev, MII_LPA);
65 if (phy_state < 0)
66 return phy_state;
67
68 mii_lpa_to_linkmode_lpa_t(phydev->lp_advertising,
69 phy_state);
70
71 phy_resolve_aneg_pause(phydev);
72 }
73 }
74 return 0;
75}
76
77MODULE_DESCRIPTION("Renesas uPD60620 PHY driver");
78MODULE_AUTHOR("Bernd Edlinger <bernd.edlinger@hotmail.de>");
79MODULE_LICENSE("GPL");
80
81static struct phy_driver upd60620_driver[1] = { {
82 .phy_id = UPD60620_PHY_ID,
83 .phy_id_mask = 0xfffffffe,
84 .name = "Renesas uPD60620",
85 /* PHY_BASIC_FEATURES */
86 .flags = 0,
87 .config_init = upd60620_config_init,
88 .read_status = upd60620_read_status,
89} };
90
91module_phy_driver(upd60620_driver);
92
93static struct mdio_device_id __maybe_unused upd60620_tbl[] = {
94 { UPD60620_PHY_ID, 0xfffffffe },
95 { }
96};
97
98MODULE_DEVICE_TABLE(mdio, upd60620_tbl);
1/*
2 * Driver for the Renesas PHY uPD60620.
3 *
4 * Copyright (C) 2015 Softing Industrial Automation GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/phy.h>
16
17#define UPD60620_PHY_ID 0xb8242824
18
19/* Extended Registers and values */
20/* PHY Special Control/Status */
21#define PHY_PHYSCR 0x1F /* PHY.31 */
22#define PHY_PHYSCR_10MB 0x0004 /* PHY speed = 10mb */
23#define PHY_PHYSCR_100MB 0x0008 /* PHY speed = 100mb */
24#define PHY_PHYSCR_DUPLEX 0x0010 /* PHY Duplex */
25
26/* PHY Special Modes */
27#define PHY_SPM 0x12 /* PHY.18 */
28
29/* Init PHY */
30
31static int upd60620_config_init(struct phy_device *phydev)
32{
33 /* Enable support for passive HUBs (could be a strap option) */
34 /* PHYMODE: All speeds, HD in parallel detect */
35 return phy_write(phydev, PHY_SPM, 0x0180 | phydev->mdio.addr);
36}
37
38/* Get PHY status from common registers */
39
40static int upd60620_read_status(struct phy_device *phydev)
41{
42 int phy_state;
43
44 /* Read negotiated state */
45 phy_state = phy_read(phydev, MII_BMSR);
46 if (phy_state < 0)
47 return phy_state;
48
49 phydev->link = 0;
50 phydev->lp_advertising = 0;
51 phydev->pause = 0;
52 phydev->asym_pause = 0;
53
54 if (phy_state & (BMSR_ANEGCOMPLETE | BMSR_LSTATUS)) {
55 phy_state = phy_read(phydev, PHY_PHYSCR);
56 if (phy_state < 0)
57 return phy_state;
58
59 if (phy_state & (PHY_PHYSCR_10MB | PHY_PHYSCR_100MB)) {
60 phydev->link = 1;
61 phydev->speed = SPEED_10;
62 phydev->duplex = DUPLEX_HALF;
63
64 if (phy_state & PHY_PHYSCR_100MB)
65 phydev->speed = SPEED_100;
66 if (phy_state & PHY_PHYSCR_DUPLEX)
67 phydev->duplex = DUPLEX_FULL;
68
69 phy_state = phy_read(phydev, MII_LPA);
70 if (phy_state < 0)
71 return phy_state;
72
73 phydev->lp_advertising
74 = mii_lpa_to_ethtool_lpa_t(phy_state);
75
76 if (phydev->duplex == DUPLEX_FULL) {
77 if (phy_state & LPA_PAUSE_CAP)
78 phydev->pause = 1;
79 if (phy_state & LPA_PAUSE_ASYM)
80 phydev->asym_pause = 1;
81 }
82 }
83 }
84 return 0;
85}
86
87MODULE_DESCRIPTION("Renesas uPD60620 PHY driver");
88MODULE_AUTHOR("Bernd Edlinger <bernd.edlinger@hotmail.de>");
89MODULE_LICENSE("GPL");
90
91static struct phy_driver upd60620_driver[1] = { {
92 .phy_id = UPD60620_PHY_ID,
93 .phy_id_mask = 0xfffffffe,
94 .name = "Renesas uPD60620",
95 .features = PHY_BASIC_FEATURES,
96 .flags = 0,
97 .config_init = upd60620_config_init,
98 .read_status = upd60620_read_status,
99} };
100
101module_phy_driver(upd60620_driver);
102
103static struct mdio_device_id __maybe_unused upd60620_tbl[] = {
104 { UPD60620_PHY_ID, 0xfffffffe },
105 { }
106};
107
108MODULE_DEVICE_TABLE(mdio, upd60620_tbl);