From: Johan Hovold <johan@kernel.org>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Bruno Thomsen <bth@kamstrup.dk>,
Sascha Hauer <s.hauer@pengutronix.de>,
Mark Rutland <mark.rutland@arm.com>,
Johan Hovold <johan@kernel.org>
Subject: [PATCH 02/10] net: phy: micrel: add device-type abstraction
Date: Wed, 19 Nov 2014 12:59:15 +0100 [thread overview]
Message-ID: <1416398363-32306-3-git-send-email-johan@kernel.org> (raw)
In-Reply-To: <1416398363-32306-1-git-send-email-johan@kernel.org>
Add structured device-type information and support for generic led-mode
setup to the generic config_init callback.
This is a first step in ultimately getting rid of device-type specific
callbacks.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/net/phy/micrel.c | 83 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 70 insertions(+), 13 deletions(-)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 30e894d6ffbd..1b528137afd9 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -73,6 +73,30 @@
#define PS_TO_REG 200
+struct kszphy_type {
+ u32 led_mode_reg;
+};
+
+struct kszphy_priv {
+ const struct kszphy_type *type;
+};
+
+static const struct kszphy_type ksz8021_type = {
+ .led_mode_reg = MII_KSZPHY_CTRL_2,
+};
+
+static const struct kszphy_type ksz8041_type = {
+ .led_mode_reg = MII_KSZPHY_CTRL_1,
+};
+
+static const struct kszphy_type ksz8051_type = {
+ .led_mode_reg = MII_KSZPHY_CTRL_2,
+};
+
+static const struct kszphy_type ksz8081_type = {
+ .led_mode_reg = MII_KSZPHY_CTRL_2,
+};
+
static int ksz_config_flags(struct phy_device *phydev)
{
int regval;
@@ -229,19 +253,25 @@ out:
static int kszphy_config_init(struct phy_device *phydev)
{
- return 0;
-}
+ struct kszphy_priv *priv = phydev->priv;
+ const struct kszphy_type *type;
-static int kszphy_config_init_led8041(struct phy_device *phydev)
-{
- return kszphy_setup_led(phydev, MII_KSZPHY_CTRL_1);
+ if (!priv)
+ return 0;
+
+ type = priv->type;
+
+ if (type->led_mode_reg)
+ kszphy_setup_led(phydev, type->led_mode_reg);
+
+ return 0;
}
static int ksz8021_config_init(struct phy_device *phydev)
{
int rc;
- kszphy_setup_led(phydev, MII_KSZPHY_CTRL_2);
+ kszphy_config_init(phydev);
rc = ksz_config_flags(phydev);
if (rc < 0)
@@ -256,7 +286,7 @@ static int ks8051_config_init(struct phy_device *phydev)
{
int rc;
- kszphy_setup_led(phydev, MII_KSZPHY_CTRL_2);
+ kszphy_config_init(phydev);
rc = ksz_config_flags(phydev);
return rc < 0 ? rc : 0;
@@ -265,9 +295,8 @@ static int ks8051_config_init(struct phy_device *phydev)
static int ksz8081_config_init(struct phy_device *phydev)
{
kszphy_broadcast_disable(phydev);
- kszphy_setup_led(phydev, MII_KSZPHY_CTRL_2);
- return 0;
+ return kszphy_config_init(phydev);
}
static int ksz9021_load_values_from_of(struct phy_device *phydev,
@@ -499,6 +528,22 @@ ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,
{
}
+static int kszphy_probe(struct phy_device *phydev)
+{
+ const struct kszphy_type *type = phydev->drv->driver_data;
+ struct kszphy_priv *priv;
+
+ priv = devm_kzalloc(&phydev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ phydev->priv = priv;
+
+ priv->type = type;
+
+ return 0;
+}
+
static int ksz8021_probe(struct phy_device *phydev)
{
struct clk *clk;
@@ -517,7 +562,7 @@ static int ksz8021_probe(struct phy_device *phydev)
}
}
- return 0;
+ return kszphy_probe(phydev);
}
static struct phy_driver ksphy_driver[] = {
@@ -542,6 +587,7 @@ static struct phy_driver ksphy_driver[] = {
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
SUPPORTED_Asym_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
+ .driver_data = &ksz8021_type,
.probe = ksz8021_probe,
.config_init = ksz8021_config_init,
.config_aneg = genphy_config_aneg,
@@ -558,6 +604,7 @@ static struct phy_driver ksphy_driver[] = {
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
SUPPORTED_Asym_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
+ .driver_data = &ksz8021_type,
.probe = ksz8021_probe,
.config_init = ksz8021_config_init,
.config_aneg = genphy_config_aneg,
@@ -574,7 +621,9 @@ static struct phy_driver ksphy_driver[] = {
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
| SUPPORTED_Asym_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
- .config_init = kszphy_config_init_led8041,
+ .driver_data = &ksz8041_type,
+ .probe = kszphy_probe,
+ .config_init = kszphy_config_init,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
.ack_interrupt = kszphy_ack_interrupt,
@@ -589,7 +638,9 @@ static struct phy_driver ksphy_driver[] = {
.features = PHY_BASIC_FEATURES |
SUPPORTED_Pause | SUPPORTED_Asym_Pause,
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
- .config_init = kszphy_config_init_led8041,
+ .driver_data = &ksz8041_type,
+ .probe = kszphy_probe,
+ .config_init = kszphy_config_init,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
.ack_interrupt = kszphy_ack_interrupt,
@@ -604,6 +655,8 @@ static struct phy_driver ksphy_driver[] = {
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
| SUPPORTED_Asym_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
+ .driver_data = &ksz8051_type,
+ .probe = kszphy_probe,
.config_init = ks8051_config_init,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
@@ -618,7 +671,9 @@ static struct phy_driver ksphy_driver[] = {
.phy_id_mask = 0x00ffffff,
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
- .config_init = kszphy_config_init_led8041,
+ .driver_data = &ksz8041_type,
+ .probe = kszphy_probe,
+ .config_init = kszphy_config_init,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
.ack_interrupt = kszphy_ack_interrupt,
@@ -632,6 +687,8 @@ static struct phy_driver ksphy_driver[] = {
.phy_id_mask = 0x00fffff0,
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
+ .driver_data = &ksz8081_type,
+ .probe = kszphy_probe,
.config_init = ksz8081_config_init,
.config_aneg = genphy_config_aneg,
.read_status = genphy_read_status,
--
2.0.4
next prev parent reply other threads:[~2014-11-19 11:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-19 11:59 [PATCH 00/10] net: phy: add device-type abstraction Johan Hovold
2014-11-19 11:59 ` [PATCH 01/10] net: phy: add static data field to struct phy_driver Johan Hovold
2014-11-19 11:59 ` Johan Hovold [this message]
2014-11-19 11:59 ` [PATCH 03/10] net: phy: micrel: parse of nodes at probe Johan Hovold
2014-11-19 11:59 ` [PATCH 04/10] net: phy: micrel: add has-broadcast-disable flag to type data Johan Hovold
2014-11-19 11:59 ` [PATCH 05/10] net: phy: micrel: add generic clock-mode-select support Johan Hovold
2014-11-19 11:59 ` [PATCH 06/10] net: phy: micrel: add support for clock-mode select to KSZ8081/KSZ8091 Johan Hovold
2014-11-19 11:59 ` [PATCH 07/10] dt/bindings: reformat micrel eth-phy documentation Johan Hovold
2014-11-19 11:59 ` [PATCH 08/10] dt/bindings: add clock-select function property to micrel phy binding Johan Hovold
2014-11-20 9:08 ` Sascha Hauer
2014-11-19 11:59 ` [PATCH 09/10] net: phy: micrel: refactor interrupt config Johan Hovold
2014-11-19 11:59 ` [PATCH 10/10] net: phy: micrel: add copyright entry Johan Hovold
2014-11-20 16:18 ` [PATCH 00/10] net: phy: add device-type abstraction Florian Fainelli
2014-11-21 19:16 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1416398363-32306-3-git-send-email-johan@kernel.org \
--to=johan@kernel.org \
--cc=bth@kamstrup.dk \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=netdev@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).