Skip to content

Commit

Permalink
net: dsa: microchip: lan937x: add interrupt support for port phy link
Browse files Browse the repository at this point in the history
This patch enables the interrupts for internal phy link detection for
LAN937x. The interrupt enable bits are active low. There is global
interrupt mask for each port. And each port has the individual interrupt
mask for TAS. QCI, SGMII, PTP, PHY and ACL.
The first level of interrupt domain is registered for global port
interrupt and second level of interrupt domain for the individual port
interrupts. The phy interrupt is enabled in the lan937x_mdio_register
function. Interrupt from which port is raised will be detected based on
the interrupt host data.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arun Ramadoss authored and David S. Miller committed Sep 5, 2022
1 parent f313936 commit c9cd961
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 4 deletions.
10 changes: 10 additions & 0 deletions drivers/net/dsa/microchip/ksz_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {

static const struct ksz_dev_ops lan937x_dev_ops = {
.setup = lan937x_setup,
.teardown = lan937x_teardown,
.get_port_addr = ksz9477_get_port_addr,
.cfg_port_member = ksz9477_cfg_port_member,
.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
Expand Down Expand Up @@ -1444,6 +1445,14 @@ static int ksz_setup(struct dsa_switch *ds)
return 0;
}

static void ksz_teardown(struct dsa_switch *ds)
{
struct ksz_device *dev = ds->priv;

if (dev->dev_ops->teardown)
dev->dev_ops->teardown(ds);
}

static void port_r_cnt(struct ksz_device *dev, int port)
{
struct ksz_port_mib *mib = &dev->ports[port].mib;
Expand Down Expand Up @@ -2193,6 +2202,7 @@ static const struct dsa_switch_ops ksz_switch_ops = {
.get_tag_protocol = ksz_get_tag_protocol,
.get_phy_flags = ksz_get_phy_flags,
.setup = ksz_setup,
.teardown = ksz_teardown,
.phy_read = ksz_phy_read16,
.phy_write = ksz_phy_write16,
.phylink_get_caps = ksz_phylink_get_caps,
Expand Down
14 changes: 14 additions & 0 deletions drivers/net/dsa/microchip/ksz_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/phy.h>
#include <linux/regmap.h>
#include <net/dsa.h>
#include <linux/irq.h>

#define KSZ_MAX_NUM_PORTS 8

Expand Down Expand Up @@ -68,6 +69,14 @@ struct ksz_chip_data {
const struct regmap_access_table *rd_table;
};

struct ksz_irq {
u16 masked;
struct irq_chip chip;
struct irq_domain *domain;
int nirqs;
char name[16];
};

struct ksz_port {
bool remove_tag; /* Remove Tag flag set, for ksz8795 only */
bool learning;
Expand All @@ -86,6 +95,7 @@ struct ksz_port {
u32 rgmii_tx_val;
u32 rgmii_rx_val;
struct ksz_device *ksz_dev;
struct ksz_irq pirq;
u8 num;
};

Expand All @@ -104,6 +114,7 @@ struct ksz_device {
struct regmap *regmap[3];

void *priv;
int irq;

struct gpio_desc *reset_gpio; /* Optional reset GPIO */

Expand All @@ -124,6 +135,8 @@ struct ksz_device {
u16 mirror_rx;
u16 mirror_tx;
u16 port_mask;
struct mutex lock_irq; /* IRQ Access */
struct ksz_irq girq;
};

/* List of supported models */
Expand Down Expand Up @@ -260,6 +273,7 @@ struct alu_struct {

struct ksz_dev_ops {
int (*setup)(struct dsa_switch *ds);
void (*teardown)(struct dsa_switch *ds);
u32 (*get_port_addr)(int port, int offset);
void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/dsa/microchip/ksz_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static int ksz_spi_probe(struct spi_device *spi)
if (ret)
return ret;

dev->irq = spi->irq;

ret = ksz_switch_register(dev);

/* Main DSA driver may not be started yet. */
Expand Down
1 change: 1 addition & 0 deletions drivers/net/dsa/microchip/lan937x.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

int lan937x_reset_switch(struct ksz_device *dev);
int lan937x_setup(struct dsa_switch *ds);
void lan937x_teardown(struct dsa_switch *ds);
void lan937x_port_setup(struct ksz_device *dev, int port, bool cpu_port);
void lan937x_config_cpu_port(struct dsa_switch *ds);
int lan937x_switch_init(struct ksz_device *dev);
Expand Down
Loading

0 comments on commit c9cd961

Please sign in to comment.