Commit e552de24 authored by Magnus Damm's avatar Magnus Damm Committed by Paul Mundt

sh-sci: add platform device private data

This patch adds per-platform private data to the sh-sci driver.
Signed-off-by: default avatarMagnus Damm <damm@igel.co.jp>
Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent 7b551f9d
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/list.h>
#ifdef CONFIG_SUPERH #ifdef CONFIG_SUPERH
#include <asm/clock.h> #include <asm/clock.h>
...@@ -77,6 +78,16 @@ struct sci_port { ...@@ -77,6 +78,16 @@ struct sci_port {
#ifdef CONFIG_HAVE_CLK #ifdef CONFIG_HAVE_CLK
/* Port clock */ /* Port clock */
struct clk *clk; struct clk *clk;
#endif
struct list_head node;
};
struct sh_sci_priv {
spinlock_t lock;
struct list_head ports;
#ifdef CONFIG_HAVE_CLK
struct notifier_block clk_nb;
#endif #endif
}; };
...@@ -726,19 +737,22 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) ...@@ -726,19 +737,22 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
static int sci_notifier(struct notifier_block *self, static int sci_notifier(struct notifier_block *self,
unsigned long phase, void *p) unsigned long phase, void *p)
{ {
int i; struct sh_sci_priv *priv = container_of(self,
struct sh_sci_priv, clk_nb);
struct sci_port *sci_port;
unsigned long flags;
if ((phase == CPUFREQ_POSTCHANGE) || if ((phase == CPUFREQ_POSTCHANGE) ||
(phase == CPUFREQ_RESUMECHANGE)) (phase == CPUFREQ_RESUMECHANGE)) {
for (i = 0; i < SCI_NPORTS; i++) { spin_lock_irqsave(&priv->lock, flags);
struct sci_port *s = &sci_ports[i]; list_for_each_entry(sci_port, &priv->ports, node)
s->port.uartclk = clk_get_rate(s->clk); sci_port->port.uartclk = clk_get_rate(sci_port->clk);
}
spin_unlock_irqrestore(&priv->lock, flags);
}
return NOTIFY_OK; return NOTIFY_OK;
} }
static struct notifier_block sci_nb = { &sci_notifier, NULL, 0 };
#endif #endif
static int sci_request_irq(struct sci_port *port) static int sci_request_irq(struct sci_port *port)
...@@ -1201,6 +1215,27 @@ static struct uart_driver sci_uart_driver = { ...@@ -1201,6 +1215,27 @@ static struct uart_driver sci_uart_driver = {
.cons = SCI_CONSOLE, .cons = SCI_CONSOLE,
}; };
static int __devexit sci_remove(struct platform_device *dev)
{
struct sh_sci_priv *priv = platform_get_drvdata(dev);
struct sci_port *p;
unsigned long flags;
#ifdef CONFIG_HAVE_CLK
cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
#endif
spin_lock_irqsave(&priv->lock, flags);
list_for_each_entry(p, &priv->ports, node)
uart_remove_one_port(&sci_uart_driver, &p->port);
spin_unlock_irqrestore(&priv->lock, flags);
kfree(priv);
return 0;
}
/* /*
* Register a set of serial devices attached to a platform device. The * Register a set of serial devices attached to a platform device. The
* list is terminated with a zero flags entry, which means we expect * list is terminated with a zero flags entry, which means we expect
...@@ -1210,7 +1245,22 @@ static struct uart_driver sci_uart_driver = { ...@@ -1210,7 +1245,22 @@ static struct uart_driver sci_uart_driver = {
static int __devinit sci_probe(struct platform_device *dev) static int __devinit sci_probe(struct platform_device *dev)
{ {
struct plat_sci_port *p = dev->dev.platform_data; struct plat_sci_port *p = dev->dev.platform_data;
struct sh_sci_priv *priv;
int i, ret = -EINVAL; int i, ret = -EINVAL;
unsigned long flags;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
INIT_LIST_HEAD(&priv->ports);
spin_lock_init(&priv->lock);
platform_set_drvdata(dev, priv);
#ifdef CONFIG_HAVE_CLK
priv->clk_nb.notifier_call = sci_notifier;
cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
#endif
for (i = 0; p && p->flags != 0; p++, i++) { for (i = 0; p && p->flags != 0; p++, i++) {
struct sci_port *sciport = &sci_ports[i]; struct sci_port *sciport = &sci_ports[i];
...@@ -1254,12 +1304,19 @@ static int __devinit sci_probe(struct platform_device *dev) ...@@ -1254,12 +1304,19 @@ static int __devinit sci_probe(struct platform_device *dev)
memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs)); memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs));
uart_add_one_port(&sci_uart_driver, &sciport->port); ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
}
#ifdef CONFIG_HAVE_CLK if (ret && (p->flags & UPF_IOREMAP)) {
cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER); iounmap(p->membase);
#endif goto err_unreg;
}
INIT_LIST_HEAD(&sciport->node);
spin_lock_irqsave(&priv->lock, flags);
list_add(&sciport->node, &priv->ports);
spin_unlock_irqrestore(&priv->lock, flags);
}
#ifdef CONFIG_SH_STANDARD_BIOS #ifdef CONFIG_SH_STANDARD_BIOS
sh_bios_gdb_detach(); sh_bios_gdb_detach();
...@@ -1268,50 +1325,36 @@ static int __devinit sci_probe(struct platform_device *dev) ...@@ -1268,50 +1325,36 @@ static int __devinit sci_probe(struct platform_device *dev)
return 0; return 0;
err_unreg: err_unreg:
for (i = i - 1; i >= 0; i--) sci_remove(dev);
uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
return ret; return ret;
} }
static int __devexit sci_remove(struct platform_device *dev)
{
int i;
#ifdef CONFIG_HAVE_CLK
cpufreq_unregister_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
#endif
for (i = 0; i < SCI_NPORTS; i++)
uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
return 0;
}
static int sci_suspend(struct platform_device *dev, pm_message_t state) static int sci_suspend(struct platform_device *dev, pm_message_t state)
{ {
int i; struct sh_sci_priv *priv = platform_get_drvdata(dev);
struct sci_port *p;
unsigned long flags;
for (i = 0; i < SCI_NPORTS; i++) { spin_lock_irqsave(&priv->lock, flags);
struct sci_port *p = &sci_ports[i]; list_for_each_entry(p, &priv->ports, node)
uart_suspend_port(&sci_uart_driver, &p->port);
if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) spin_unlock_irqrestore(&priv->lock, flags);
uart_suspend_port(&sci_uart_driver, &p->port);
}
return 0; return 0;
} }
static int sci_resume(struct platform_device *dev) static int sci_resume(struct platform_device *dev)
{ {
int i; struct sh_sci_priv *priv = platform_get_drvdata(dev);
struct sci_port *p;
unsigned long flags;
for (i = 0; i < SCI_NPORTS; i++) { spin_lock_irqsave(&priv->lock, flags);
struct sci_port *p = &sci_ports[i]; list_for_each_entry(p, &priv->ports, node)
uart_resume_port(&sci_uart_driver, &p->port);
if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) spin_unlock_irqrestore(&priv->lock, flags);
uart_resume_port(&sci_uart_driver, &p->port);
}
return 0; return 0;
} }
......
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