Commit 501b825d authored by Magnus Damm's avatar Magnus Damm Committed by Paul Mundt

sh-sci: improve clock framework support

Use enable/disable hooks for clock framework integration.
Make sure we control the clock for the serial console as well.
Signed-off-by: default avatarMagnus Damm <damm@igel.co.jp>
Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent 08f8cb31
...@@ -76,8 +76,10 @@ struct sci_port { ...@@ -76,8 +76,10 @@ struct sci_port {
int break_flag; int break_flag;
#ifdef CONFIG_HAVE_CLK #ifdef CONFIG_HAVE_CLK
/* Port clock */ /* Interface clock */
struct clk *clk; struct clk *iclk;
/* Data clock */
struct clk *dclk;
#endif #endif
struct list_head node; struct list_head node;
}; };
...@@ -166,12 +168,12 @@ static void h8300_sci_config(struct uart_port *port, unsigned int ctrl) ...@@ -166,12 +168,12 @@ static void h8300_sci_config(struct uart_port *port, unsigned int ctrl)
*mstpcrl &= ~mask; *mstpcrl &= ~mask;
} }
static inline void h8300_sci_enable(struct uart_port *port) static void h8300_sci_enable(struct uart_port *port)
{ {
h8300_sci_config(port, sci_enable); h8300_sci_config(port, sci_enable);
} }
static inline void h8300_sci_disable(struct uart_port *port) static void h8300_sci_disable(struct uart_port *port)
{ {
h8300_sci_config(port, sci_disable); h8300_sci_config(port, sci_disable);
} }
...@@ -742,13 +744,34 @@ static int sci_notifier(struct notifier_block *self, ...@@ -742,13 +744,34 @@ static int sci_notifier(struct notifier_block *self,
(phase == CPUFREQ_RESUMECHANGE)) { (phase == CPUFREQ_RESUMECHANGE)) {
spin_lock_irqsave(&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
list_for_each_entry(sci_port, &priv->ports, node) list_for_each_entry(sci_port, &priv->ports, node)
sci_port->port.uartclk = clk_get_rate(sci_port->clk); sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
} }
return NOTIFY_OK; return NOTIFY_OK;
} }
static void sci_clk_enable(struct uart_port *port)
{
struct sci_port *sci_port = to_sci_port(port);
clk_enable(sci_port->dclk);
sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
if (sci_port->iclk)
clk_enable(sci_port->iclk);
}
static void sci_clk_disable(struct uart_port *port)
{
struct sci_port *sci_port = to_sci_port(port);
if (sci_port->iclk)
clk_disable(sci_port->iclk);
clk_disable(sci_port->dclk);
}
#endif #endif
static int sci_request_irq(struct sci_port *port) static int sci_request_irq(struct sci_port *port)
...@@ -880,10 +903,6 @@ static int sci_startup(struct uart_port *port) ...@@ -880,10 +903,6 @@ static int sci_startup(struct uart_port *port)
if (s->enable) if (s->enable)
s->enable(port); s->enable(port);
#ifdef CONFIG_HAVE_CLK
s->clk = clk_get(NULL, "module_clk");
#endif
sci_request_irq(s); sci_request_irq(s);
sci_start_tx(port); sci_start_tx(port);
sci_start_rx(port, 1); sci_start_rx(port, 1);
...@@ -901,11 +920,6 @@ static void sci_shutdown(struct uart_port *port) ...@@ -901,11 +920,6 @@ static void sci_shutdown(struct uart_port *port)
if (s->disable) if (s->disable)
s->disable(port); s->disable(port);
#ifdef CONFIG_HAVE_CLK
clk_put(s->clk);
s->clk = NULL;
#endif
} }
static void sci_set_termios(struct uart_port *port, struct ktermios *termios, static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
...@@ -1048,7 +1062,8 @@ static struct uart_ops sci_uart_ops = { ...@@ -1048,7 +1062,8 @@ static struct uart_ops sci_uart_ops = {
#endif #endif
}; };
static void __devinit sci_init_single(struct sci_port *sci_port, static void __devinit sci_init_single(struct platform_device *dev,
struct sci_port *sci_port,
unsigned int index, unsigned int index,
struct plat_sci_port *p) struct plat_sci_port *p)
{ {
...@@ -1064,14 +1079,10 @@ static void __devinit sci_init_single(struct sci_port *sci_port, ...@@ -1064,14 +1079,10 @@ static void __devinit sci_init_single(struct sci_port *sci_port,
#endif #endif
sci_port->port.uartclk = CONFIG_CPU_CLOCK; sci_port->port.uartclk = CONFIG_CPU_CLOCK;
#elif defined(CONFIG_HAVE_CLK) #elif defined(CONFIG_HAVE_CLK)
/* sci_port->iclk = p->clk ? clk_get(&dev->dev, p->clk) : NULL;
* XXX: We should use a proper SCI/SCIF clock sci_port->dclk = clk_get(&dev->dev, "module_clk");
*/ sci_port->enable = sci_clk_enable;
{ sci_port->disable = sci_clk_disable;
struct clk *clk = clk_get(NULL, "module_clk");
sci_port->port.uartclk = clk_get_rate(clk);
clk_put(clk);
}
#else #else
#error "Need a valid uartclk" #error "Need a valid uartclk"
#endif #endif
...@@ -1085,9 +1096,11 @@ static void __devinit sci_init_single(struct sci_port *sci_port, ...@@ -1085,9 +1096,11 @@ static void __devinit sci_init_single(struct sci_port *sci_port,
sci_port->port.irq = p->irqs[SCIx_TXI_IRQ]; sci_port->port.irq = p->irqs[SCIx_TXI_IRQ];
sci_port->port.flags = p->flags; sci_port->port.flags = p->flags;
sci_port->port.dev = &dev->dev;
sci_port->type = sci_port->port.type = p->type; sci_port->type = sci_port->port.type = p->type;
memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs)); memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs));
} }
#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
...@@ -1111,14 +1124,21 @@ static void serial_console_write(struct console *co, const char *s, ...@@ -1111,14 +1124,21 @@ static void serial_console_write(struct console *co, const char *s,
unsigned count) unsigned count)
{ {
struct uart_port *port = co->data; struct uart_port *port = co->data;
struct sci_port *sci_port = to_sci_port(port);
unsigned short bits; unsigned short bits;
uart_console_write(co->data, s, count, serial_console_putchar); if (sci_port->enable)
sci_port->enable(port);
uart_console_write(port, s, count, serial_console_putchar);
/* wait until fifo is empty and last bit has been transmitted */ /* wait until fifo is empty and last bit has been transmitted */
bits = SCxSR_TDxE(port) | SCxSR_TEND(port); bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
while ((sci_in(port, SCxSR) & bits) != bits) while ((sci_in(port, SCxSR) & bits) != bits)
cpu_relax(); cpu_relax();
if (sci_port->disable);
sci_port->disable(port);
} }
static int __init serial_console_setup(struct console *co, char *options) static int __init serial_console_setup(struct console *co, char *options)
...@@ -1152,11 +1172,6 @@ static int __init serial_console_setup(struct console *co, char *options) ...@@ -1152,11 +1172,6 @@ static int __init serial_console_setup(struct console *co, char *options)
if (!port->type) if (!port->type)
return -ENODEV; return -ENODEV;
#ifdef CONFIG_HAVE_CLK
if (!sci_port->clk)
sci_port->clk = clk_get(NULL, "module_clk");
#endif
sci_config_port(port, 0); sci_config_port(port, 0);
if (sci_port->enable) if (sci_port->enable)
...@@ -1171,6 +1186,7 @@ static int __init serial_console_setup(struct console *co, char *options) ...@@ -1171,6 +1186,7 @@ static int __init serial_console_setup(struct console *co, char *options)
if (ret == 0) if (ret == 0)
sci_stop_rx(port); sci_stop_rx(port);
#endif #endif
/* TODO: disable clock */
return ret; return ret;
} }
...@@ -1250,8 +1266,7 @@ static int __devinit sci_probe_single(struct platform_device *dev, ...@@ -1250,8 +1266,7 @@ static int __devinit sci_probe_single(struct platform_device *dev,
return 0; return 0;
} }
sciport->port.dev = &dev->dev; sci_init_single(dev, sciport, index, p);
sci_init_single(sciport, index, p);
ret = uart_add_one_port(&sci_uart_driver, &sciport->port); ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
if (ret) if (ret)
......
...@@ -25,6 +25,7 @@ struct plat_sci_port { ...@@ -25,6 +25,7 @@ struct plat_sci_port {
unsigned int irqs[SCIx_NR_IRQS]; /* ERI, RXI, TXI, BRI */ unsigned int irqs[SCIx_NR_IRQS]; /* ERI, RXI, TXI, BRI */
unsigned int type; /* SCI / SCIF / IRDA */ unsigned int type; /* SCI / SCIF / IRDA */
upf_t flags; /* UPF_* flags */ upf_t flags; /* UPF_* flags */
char *clk; /* clock string */
}; };
#endif /* __LINUX_SERIAL_SCI_H */ #endif /* __LINUX_SERIAL_SCI_H */
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