Commit 16994374 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: dsa: b53: Make SRAB driver manage port interrupts

Update the SRAB driver to manage per-port interrupts. Since we cannot
sleep during b53_io_ops, schedule a workqueue whenever we get a port
specific interrupt. We will later make use of this to call back into
PHYLINK when there is e.g: a link state change.
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8ca7c160
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/platform_data/b53.h> #include <linux/platform_data/b53.h>
#include <linux/of.h> #include <linux/of.h>
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
/* command and status register of the SRAB */ /* command and status register of the SRAB */
#define B53_SRAB_CTRLS 0x40 #define B53_SRAB_CTRLS 0x40
#define B53_SRAB_CTRLS_HOST_INTR BIT(1)
#define B53_SRAB_CTRLS_RCAREQ BIT(3) #define B53_SRAB_CTRLS_RCAREQ BIT(3)
#define B53_SRAB_CTRLS_RCAGNT BIT(4) #define B53_SRAB_CTRLS_RCAGNT BIT(4)
#define B53_SRAB_CTRLS_SW_INIT_DONE BIT(6) #define B53_SRAB_CTRLS_SW_INIT_DONE BIT(6)
...@@ -60,8 +62,16 @@ ...@@ -60,8 +62,16 @@
#define B53_SRAB_P7_SLEEP_TIMER BIT(11) #define B53_SRAB_P7_SLEEP_TIMER BIT(11)
#define B53_SRAB_IMP0_SLEEP_TIMER BIT(12) #define B53_SRAB_IMP0_SLEEP_TIMER BIT(12)
struct b53_srab_port_priv {
int irq;
bool irq_enabled;
struct b53_device *dev;
unsigned int num;
};
struct b53_srab_priv { struct b53_srab_priv {
void __iomem *regs; void __iomem *regs;
struct b53_srab_port_priv port_intrs[B53_N_PORTS];
}; };
static int b53_srab_request_grant(struct b53_device *dev) static int b53_srab_request_grant(struct b53_device *dev)
...@@ -344,6 +354,49 @@ static int b53_srab_write64(struct b53_device *dev, u8 page, u8 reg, ...@@ -344,6 +354,49 @@ static int b53_srab_write64(struct b53_device *dev, u8 page, u8 reg,
return ret; return ret;
} }
static irqreturn_t b53_srab_port_thread(int irq, void *dev_id)
{
return IRQ_HANDLED;
}
static irqreturn_t b53_srab_port_isr(int irq, void *dev_id)
{
struct b53_srab_port_priv *port = dev_id;
struct b53_device *dev = port->dev;
struct b53_srab_priv *priv = dev->priv;
/* Acknowledge the interrupt */
writel(BIT(port->num), priv->regs + B53_SRAB_INTR);
return IRQ_WAKE_THREAD;
}
static int b53_srab_irq_enable(struct b53_device *dev, int port)
{
struct b53_srab_priv *priv = dev->priv;
struct b53_srab_port_priv *p = &priv->port_intrs[port];
int ret;
ret = request_threaded_irq(p->irq, b53_srab_port_isr,
b53_srab_port_thread, 0,
dev_name(dev->dev), p);
if (!ret)
p->irq_enabled = true;
return ret;
}
static void b53_srab_irq_disable(struct b53_device *dev, int port)
{
struct b53_srab_priv *priv = dev->priv;
struct b53_srab_port_priv *p = &priv->port_intrs[port];
if (p->irq_enabled) {
free_irq(p->irq, p);
p->irq_enabled = false;
}
}
static const struct b53_io_ops b53_srab_ops = { static const struct b53_io_ops b53_srab_ops = {
.read8 = b53_srab_read8, .read8 = b53_srab_read8,
.read16 = b53_srab_read16, .read16 = b53_srab_read16,
...@@ -355,6 +408,8 @@ static const struct b53_io_ops b53_srab_ops = { ...@@ -355,6 +408,8 @@ static const struct b53_io_ops b53_srab_ops = {
.write32 = b53_srab_write32, .write32 = b53_srab_write32,
.write48 = b53_srab_write48, .write48 = b53_srab_write48,
.write64 = b53_srab_write64, .write64 = b53_srab_write64,
.irq_enable = b53_srab_irq_enable,
.irq_disable = b53_srab_irq_disable,
}; };
static const struct of_device_id b53_srab_of_match[] = { static const struct of_device_id b53_srab_of_match[] = {
...@@ -379,6 +434,52 @@ static const struct of_device_id b53_srab_of_match[] = { ...@@ -379,6 +434,52 @@ static const struct of_device_id b53_srab_of_match[] = {
}; };
MODULE_DEVICE_TABLE(of, b53_srab_of_match); MODULE_DEVICE_TABLE(of, b53_srab_of_match);
static void b53_srab_intr_set(struct b53_srab_priv *priv, bool set)
{
u32 reg;
reg = readl(priv->regs + B53_SRAB_CTRLS);
if (set)
reg |= B53_SRAB_CTRLS_HOST_INTR;
else
reg &= ~B53_SRAB_CTRLS_HOST_INTR;
writel(reg, priv->regs + B53_SRAB_CTRLS);
}
static void b53_srab_prepare_irq(struct platform_device *pdev)
{
struct b53_device *dev = platform_get_drvdata(pdev);
struct b53_srab_priv *priv = dev->priv;
struct b53_srab_port_priv *port;
unsigned int i;
char *name;
/* Clear all pending interrupts */
writel(0xffffffff, priv->regs + B53_SRAB_INTR);
if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
return;
for (i = 0; i < B53_N_PORTS; i++) {
port = &priv->port_intrs[i];
/* There is no port 6 */
if (i == 6)
continue;
name = kasprintf(GFP_KERNEL, "link_state_p%d", i);
if (!name)
return;
port->num = i;
port->dev = dev;
port->irq = platform_get_irq_byname(pdev, name);
kfree(name);
}
b53_srab_intr_set(priv, true);
}
static int b53_srab_probe(struct platform_device *pdev) static int b53_srab_probe(struct platform_device *pdev)
{ {
struct b53_platform_data *pdata = pdev->dev.platform_data; struct b53_platform_data *pdata = pdev->dev.platform_data;
...@@ -417,13 +518,17 @@ static int b53_srab_probe(struct platform_device *pdev) ...@@ -417,13 +518,17 @@ static int b53_srab_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, dev); platform_set_drvdata(pdev, dev);
b53_srab_prepare_irq(pdev);
return b53_switch_register(dev); return b53_switch_register(dev);
} }
static int b53_srab_remove(struct platform_device *pdev) static int b53_srab_remove(struct platform_device *pdev)
{ {
struct b53_device *dev = platform_get_drvdata(pdev); struct b53_device *dev = platform_get_drvdata(pdev);
struct b53_srab_priv *priv = dev->priv;
b53_srab_intr_set(priv, false);
if (dev) if (dev)
b53_switch_remove(dev); b53_switch_remove(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment