4848#include <linux/serial.h>
4949#include <linux/amba/bus.h>
5050#include <linux/amba/serial.h>
51+ #include <linux/clk.h>
5152
5253#include <asm/io.h>
5354
7071 */
7172struct uart_amba_port {
7273 struct uart_port port ;
74+ struct clk * clk ;
7375 struct amba_device * dev ;
7476 struct amba_pl010_data * data ;
7577 unsigned int old_status ;
@@ -312,12 +314,21 @@ static int pl010_startup(struct uart_port *port)
312314 struct uart_amba_port * uap = (struct uart_amba_port * )port ;
313315 int retval ;
314316
317+ /*
318+ * Try to enable the clock producer.
319+ */
320+ retval = clk_enable (uap -> clk );
321+ if (retval )
322+ goto out ;
323+
324+ uap -> port .uartclk = clk_get_rate (uap -> clk );
325+
315326 /*
316327 * Allocate the IRQ
317328 */
318329 retval = request_irq (uap -> port .irq , pl010_int , 0 , "uart-pl010" , uap );
319330 if (retval )
320- return retval ;
331+ goto clk_dis ;
321332
322333 /*
323334 * initialise the old status of the modem signals
@@ -331,6 +342,11 @@ static int pl010_startup(struct uart_port *port)
331342 uap -> port .membase + UART010_CR );
332343
333344 return 0 ;
345+
346+ clk_dis :
347+ clk_disable (uap -> clk );
348+ out :
349+ return retval ;
334350}
335351
336352static void pl010_shutdown (struct uart_port * port )
@@ -351,6 +367,11 @@ static void pl010_shutdown(struct uart_port *port)
351367 writel (readb (uap -> port .membase + UART010_LCRH ) &
352368 ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN ),
353369 uap -> port .membase + UART010_LCRH );
370+
371+ /*
372+ * Shut down the clock producer
373+ */
374+ clk_disable (uap -> clk );
354375}
355376
356377static void
@@ -540,6 +561,8 @@ pl010_console_write(struct console *co, const char *s, unsigned int count)
540561 struct uart_amba_port * uap = amba_ports [co -> index ];
541562 unsigned int status , old_cr ;
542563
564+ clk_enable (uap -> clk );
565+
543566 /*
544567 * First save the CR then disable the interrupts
545568 */
@@ -557,6 +580,8 @@ pl010_console_write(struct console *co, const char *s, unsigned int count)
557580 barrier ();
558581 } while (status & UART01x_FR_BUSY );
559582 writel (old_cr , uap -> port .membase + UART010_CR );
583+
584+ clk_disable (uap -> clk );
560585}
561586
562587static void __init
@@ -605,6 +630,8 @@ static int __init pl010_console_setup(struct console *co, char *options)
605630 if (!uap )
606631 return - ENODEV ;
607632
633+ uap -> port .uartclk = clk_get_rate (uap -> clk );
634+
608635 if (options )
609636 uart_parse_options (options , & baud , & parity , & bits , & flow );
610637 else
@@ -666,12 +693,17 @@ static int pl010_probe(struct amba_device *dev, void *id)
666693 goto free ;
667694 }
668695
696+ uap -> clk = clk_get (& dev -> dev , "UARTCLK" );
697+ if (IS_ERR (uap -> clk )) {
698+ ret = PTR_ERR (uap -> clk );
699+ goto unmap ;
700+ }
701+
669702 uap -> port .dev = & dev -> dev ;
670703 uap -> port .mapbase = dev -> res .start ;
671704 uap -> port .membase = base ;
672705 uap -> port .iotype = UPIO_MEM ;
673706 uap -> port .irq = dev -> irq [0 ];
674- uap -> port .uartclk = 14745600 ;
675707 uap -> port .fifosize = 16 ;
676708 uap -> port .ops = & amba_pl010_pops ;
677709 uap -> port .flags = UPF_BOOT_AUTOCONF ;
@@ -686,6 +718,8 @@ static int pl010_probe(struct amba_device *dev, void *id)
686718 if (ret ) {
687719 amba_set_drvdata (dev , NULL );
688720 amba_ports [i ] = NULL ;
721+ clk_put (uap -> clk );
722+ unmap :
689723 iounmap (base );
690724 free :
691725 kfree (uap );
@@ -708,6 +742,7 @@ static int pl010_remove(struct amba_device *dev)
708742 amba_ports [i ] = NULL ;
709743
710744 iounmap (uap -> port .membase );
745+ clk_put (uap -> clk );
711746 kfree (uap );
712747 return 0 ;
713748}
0 commit comments