* [PATCH net-next 1/3] net: dsa: mv88e6xxx: Remove OF check for IRQ domain
2018-05-19 20:31 [PATCH net-next 0/3] Platform data support for mv88exxx Andrew Lunn
@ 2018-05-19 20:31 ` Andrew Lunn
2018-05-19 22:47 ` Florian Fainelli
2018-05-19 20:31 ` [PATCH net-next 2/3] net: dsa: mv88e6xxx: Add minimal platform_data support Andrew Lunn
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Andrew Lunn @ 2018-05-19 20:31 UTC (permalink / raw)
To: David Miller; +Cc: Vivien Didelot, Florian Fainelli, netdev, Andrew Lunn
An IRQ domain will work without an OF node. It is not possible to
reference interrupts via a phandle, but C code can still use
irq_find_mapping() to get an interrupt from the domain.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/dsa/mv88e6xxx/global2.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/net/dsa/mv88e6xxx/global2.c b/drivers/net/dsa/mv88e6xxx/global2.c
index f9bde011a3e6..91a3cb2452ac 100644
--- a/drivers/net/dsa/mv88e6xxx/global2.c
+++ b/drivers/net/dsa/mv88e6xxx/global2.c
@@ -1047,9 +1047,6 @@ int mv88e6xxx_g2_irq_setup(struct mv88e6xxx_chip *chip)
{
int err, irq, virq;
- if (!chip->dev->of_node)
- return -EINVAL;
-
chip->g2_irq.domain = irq_domain_add_simple(
chip->dev->of_node, 16, 0, &mv88e6xxx_g2_irq_domain_ops, chip);
if (!chip->g2_irq.domain)
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/3] net: dsa: mv88e6xxx: Add minimal platform_data support
2018-05-19 20:31 [PATCH net-next 0/3] Platform data support for mv88exxx Andrew Lunn
2018-05-19 20:31 ` [PATCH net-next 1/3] net: dsa: mv88e6xxx: Remove OF check for IRQ domain Andrew Lunn
@ 2018-05-19 20:31 ` Andrew Lunn
2018-05-19 22:52 ` Florian Fainelli
2018-05-19 20:31 ` [PATCH net-next 3/3] net: dsa: mv88e6xxx: Add support for EEPROM via platform data Andrew Lunn
2018-05-20 22:58 ` [PATCH net-next 0/3] Platform data support for mv88exxx David Miller
3 siblings, 1 reply; 8+ messages in thread
From: Andrew Lunn @ 2018-05-19 20:31 UTC (permalink / raw)
To: David Miller; +Cc: Vivien Didelot, Florian Fainelli, netdev, Andrew Lunn
Not all the world uses device tree. Some parts of the world still use
platform devices and platform data. Add basic support for probing a
Marvell switch via platform data.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
MAINTAINERS | 1 +
drivers/net/dsa/mv88e6xxx/chip.c | 56 +++++++++++++++++++++----
include/linux/platform_data/mv88e6xxx.h | 17 ++++++++
3 files changed, 67 insertions(+), 7 deletions(-)
create mode 100644 include/linux/platform_data/mv88e6xxx.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 658880464b9d..9f2045a5adac 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8466,6 +8466,7 @@ M: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
L: netdev@vger.kernel.org
S: Maintained
F: drivers/net/dsa/mv88e6xxx/
+F: linux/platform_data/mv88e6xxx.h
F: Documentation/devicetree/bindings/net/dsa/marvell.txt
MARVELL ARMADA DRM SUPPORT
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 2bb3f03ee1cb..5b40382036ea 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -28,6 +28,7 @@
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/of_mdio.h>
+#include <linux/platform_data/mv88e6xxx.h>
#include <linux/netdevice.h>
#include <linux/gpio/consumer.h>
#include <linux/phy.h>
@@ -4350,6 +4351,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
return -ENOMEM;
ds->priv = chip;
+ ds->dev = dev;
ds->ops = &mv88e6xxx_switch_ops;
ds->ageing_time_min = chip->info->age_time_coeff;
ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
@@ -4364,36 +4366,73 @@ static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
dsa_unregister_switch(chip->ds);
}
+static const void *pdata_device_get_match_data(struct device *dev)
+{
+ const struct of_device_id *matches = dev->driver->of_match_table;
+ const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
+
+ for (; matches->name[0] || matches->type[0] || matches->compatible[0];
+ matches++) {
+ if (!strcmp(pdata->compatible, matches->compatible))
+ return matches->data;
+ }
+ return NULL;
+}
+
static int mv88e6xxx_probe(struct mdio_device *mdiodev)
{
+ struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
struct device *dev = &mdiodev->dev;
struct device_node *np = dev->of_node;
const struct mv88e6xxx_info *compat_info;
struct mv88e6xxx_chip *chip;
u32 eeprom_len;
+ int port;
int err;
- compat_info = of_device_get_match_data(dev);
+ if (np)
+ compat_info = of_device_get_match_data(dev);
+
+ if (pdata) {
+ compat_info = pdata_device_get_match_data(dev);
+
+ if (!pdata->netdev)
+ return -EINVAL;
+
+ for (port = 0; port < DSA_MAX_PORTS; port++) {
+ if (!(pdata->enabled_ports & (1 << port)))
+ continue;
+ if (strcmp(pdata->cd.port_names[port], "cpu"))
+ continue;
+ pdata->cd.netdev[port] = &pdata->netdev->dev;
+ break;
+ }
+ }
+
if (!compat_info)
return -EINVAL;
chip = mv88e6xxx_alloc_chip(dev);
- if (!chip)
- return -ENOMEM;
+ if (!chip) {
+ err = -ENOMEM;
+ goto out;
+ }
chip->info = compat_info;
err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
if (err)
- return err;
+ goto out;
chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
- if (IS_ERR(chip->reset))
- return PTR_ERR(chip->reset);
+ if (IS_ERR(chip->reset)) {
+ err = PTR_ERR(chip->reset);
+ goto out;
+ }
err = mv88e6xxx_detect(chip);
if (err)
- return err;
+ goto out;
mv88e6xxx_phy_init(chip);
@@ -4468,6 +4507,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
mv88e6xxx_irq_poll_free(chip);
mutex_unlock(&chip->reg_lock);
out:
+ if (pdata)
+ dev_put(pdata->netdev);
+
return err;
}
diff --git a/include/linux/platform_data/mv88e6xxx.h b/include/linux/platform_data/mv88e6xxx.h
new file mode 100644
index 000000000000..88e91e05f48f
--- /dev/null
+++ b/include/linux/platform_data/mv88e6xxx.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __DSA_MV88E6XXX_H
+#define __DSA_MV88E6XXX_H
+
+#include <net/dsa.h>
+
+struct dsa_mv88e6xxx_pdata {
+ /* Must be first, such that dsa_register_switch() can access this
+ * without gory pointer manipulations
+ */
+ struct dsa_chip_data cd;
+ const char *compatible;
+ unsigned int enabled_ports;
+ struct net_device *netdev;
+};
+
+#endif
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 3/3] net: dsa: mv88e6xxx: Add support for EEPROM via platform data
2018-05-19 20:31 [PATCH net-next 0/3] Platform data support for mv88exxx Andrew Lunn
2018-05-19 20:31 ` [PATCH net-next 1/3] net: dsa: mv88e6xxx: Remove OF check for IRQ domain Andrew Lunn
2018-05-19 20:31 ` [PATCH net-next 2/3] net: dsa: mv88e6xxx: Add minimal platform_data support Andrew Lunn
@ 2018-05-19 20:31 ` Andrew Lunn
2018-05-19 22:52 ` Florian Fainelli
2018-05-20 22:58 ` [PATCH net-next 0/3] Platform data support for mv88exxx David Miller
3 siblings, 1 reply; 8+ messages in thread
From: Andrew Lunn @ 2018-05-19 20:31 UTC (permalink / raw)
To: David Miller; +Cc: Vivien Didelot, Florian Fainelli, netdev, Andrew Lunn
Add the size of the EEPROM to the platform data, so it can also be
instantiated by a platform device.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/dsa/mv88e6xxx/chip.c | 11 +++++++----
drivers/net/dsa/mv88e6xxx/chip.h | 2 +-
include/linux/platform_data/mv88e6xxx.h | 1 +
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 5b40382036ea..1fa1f820a437 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -4386,7 +4386,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
struct device_node *np = dev->of_node;
const struct mv88e6xxx_info *compat_info;
struct mv88e6xxx_chip *chip;
- u32 eeprom_len;
int port;
int err;
@@ -4436,9 +4435,13 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
mv88e6xxx_phy_init(chip);
- if (chip->info->ops->get_eeprom &&
- !of_property_read_u32(np, "eeprom-length", &eeprom_len))
- chip->eeprom_len = eeprom_len;
+ if (chip->info->ops->get_eeprom) {
+ if (np)
+ of_property_read_u32(np, "eeprom-length",
+ &chip->eeprom_len);
+ else
+ chip->eeprom_len = pdata->eeprom_len;
+ }
mutex_lock(&chip->reg_lock);
err = mv88e6xxx_switch_reset(chip);
diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h
index 012268046442..8ac3fbb15352 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.h
+++ b/drivers/net/dsa/mv88e6xxx/chip.h
@@ -238,7 +238,7 @@ struct mv88e6xxx_chip {
struct gpio_desc *reset;
/* set to size of eeprom if supported by the switch */
- int eeprom_len;
+ u32 eeprom_len;
/* List of mdio busses */
struct list_head mdios;
diff --git a/include/linux/platform_data/mv88e6xxx.h b/include/linux/platform_data/mv88e6xxx.h
index 88e91e05f48f..f63af2955ea0 100644
--- a/include/linux/platform_data/mv88e6xxx.h
+++ b/include/linux/platform_data/mv88e6xxx.h
@@ -12,6 +12,7 @@ struct dsa_mv88e6xxx_pdata {
const char *compatible;
unsigned int enabled_ports;
struct net_device *netdev;
+ u32 eeprom_len;
};
#endif
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/3] Platform data support for mv88exxx
2018-05-19 20:31 [PATCH net-next 0/3] Platform data support for mv88exxx Andrew Lunn
` (2 preceding siblings ...)
2018-05-19 20:31 ` [PATCH net-next 3/3] net: dsa: mv88e6xxx: Add support for EEPROM via platform data Andrew Lunn
@ 2018-05-20 22:58 ` David Miller
3 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2018-05-20 22:58 UTC (permalink / raw)
To: andrew; +Cc: vivien.didelot, f.fainelli, netdev
From: Andrew Lunn <andrew@lunn.ch>
Date: Sat, 19 May 2018 22:31:32 +0200
> There are a few Intel based platforms making use of the mv88exxx.
> These don't easily have access to device tree in order to instantiate
> the switch driver. These patches allow the use of platform data to
> hold the configuration.
Series applied, thank you.
^ permalink raw reply [flat|nested] 8+ messages in thread