mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 8/8] serial: atmel: add start and shutdown support
Date: Thu,  3 Oct 2013 09:22:00 +0200	[thread overview]
Message-ID: <1380784920-30890-8-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1380784920-30890-1-git-send-email-plagnioj@jcrosoft.com>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/serial/atmel.c | 55 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c
index c2a5d33..a1eb4cb 100644
--- a/drivers/serial/atmel.c
+++ b/drivers/serial/atmel.c
@@ -20,6 +20,7 @@
 #include <malloc.h>
 #include <io.h>
 #include <linux/clk.h>
+#include <linux/err.h>
 
 /* USART3 register offsets */
 #define USART3_CR				0x0000
@@ -388,31 +389,50 @@ static int atmel_serial_set_mode(struct console_device *cdev, enum console_mode
 	return 0;
 }
 
+static void atmel_serial_shutdown(struct console_device *cdev)
+{
+	struct atmel_uart_port *uart = to_atmel_uart_port(cdev);
+
+	writel(USART3_BIT(RXDIS) | USART3_BIT(TXDIS), uart->base + USART3_CR);
+	writel(0, uart->base + USART3_BRGR);
+
+	clk_disable(uart->clk);
+}
+
+static int atmel_serial_startup(struct console_device *cdev)
+{
+	struct atmel_uart_port *uart = to_atmel_uart_port(cdev);
+
+	clk_enable(uart->clk);
+
+	writel(USART3_BIT(RXEN) | USART3_BIT(TXEN), uart->base + USART3_CR);
+
+	writel((USART3_BF(USART_MODE, USART3_USART_MODE_NORMAL)
+			   | USART3_BF(USCLKS, USART3_USCLKS_MCK)
+			   | USART3_BF(CHRL, USART3_CHRL_8)
+			   | USART3_BF(PAR, USART3_PAR_NONE)
+			   | USART3_BF(NBSTOP, USART3_NBSTOP_1)),
+			   uart->base + USART3_MR);
+
+	return 0;
+}
+
 /*
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  *
  */
-static int atmel_serial_init_port(struct console_device *cdev)
+static void atmel_serial_init(struct console_device *cdev)
 {
-	struct device_d *dev = cdev->dev;
 	struct atmel_uart_port *uart = to_atmel_uart_port(cdev);
 
-	uart->base = dev_request_mem_region(dev, 0);
-	uart->clk = clk_get(dev, "usart");
 	clk_enable(uart->clk);
+
 	uart->uartclk = clk_get_rate(uart->clk);
 
 	writel(USART3_BIT(RSTRX) | USART3_BIT(RSTTX), uart->base + USART3_CR);
 
-	writel(USART3_BIT(RXEN) | USART3_BIT(TXEN), uart->base + USART3_CR);
-	writel((USART3_BF(USART_MODE, USART3_USART_MODE_NORMAL)
-			   | USART3_BF(USCLKS, USART3_USCLKS_MCK)
-			   | USART3_BF(CHRL, USART3_CHRL_8)
-			   | USART3_BF(PAR, USART3_PAR_NONE)
-			   | USART3_BF(NBSTOP, USART3_NBSTOP_1)), uart->base + USART3_MR);
-
-	return 0;
+	clk_disable(uart->clk);
 }
 
 static int atmel_serial_probe(struct device_d *dev)
@@ -423,15 +443,22 @@ static int atmel_serial_probe(struct device_d *dev)
 	uart = xzalloc(sizeof(struct atmel_uart_port));
 	cdev = &uart->uart;
 	cdev->dev = dev;
+	cdev->startup = atmel_serial_startup;
+	cdev->shutdown = atmel_serial_shutdown;
 	cdev->tstc = atmel_serial_tstc;
 	cdev->putc = atmel_serial_putc;
 	cdev->getc = atmel_serial_getc;
 	cdev->setbrg = atmel_serial_setbaudrate;
 	cdev->set_mode = atmel_serial_set_mode;
 
-	atmel_serial_init_port(cdev);
+	uart->base = dev_request_mem_region(dev, 0);
+
+	uart->clk = clk_get(dev, "usart");
+
+	if (IS_ERR(uart->clk))
+		return PTR_ERR(uart->clk);
 
-	/* Enable UART */
+	atmel_serial_init(cdev);
 
 	console_register(cdev);
 
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-10-03  7:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-03  7:17 [PATCH 0/8 v2] more serial cleanup Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:21 ` [PATCH 1/8] console: factorise function to get the first enabled console Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:21   ` [PATCH 2/8] console: factorise function to get the console by name Jean-Christophe PLAGNIOL-VILLARD
2013-10-06 11:24     ` Sascha Hauer
2013-10-06 18:38       ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-07  6:23         ` Sascha Hauer
2013-10-03  7:21   ` [PATCH 3/8] console: introduce startup and shutdown Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:21   ` [PATCH 4/8] loadxy: use console_open/close Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:21   ` [PATCH 5/8] console: console_get_by_name pass flags Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:21   ` [PATCH 6/8] animeo_ip: update to use console_open/close for rs485 crossed detection Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:21   ` [PATCH 7/8] serial: amba-pl011: add start and shutdown support Jean-Christophe PLAGNIOL-VILLARD
2013-10-03  7:22   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-09-27  7:12 [PATCH 0/8] more serial cleanup Jean-Christophe PLAGNIOL-VILLARD
2013-09-27  7:14 ` [PATCH 1/8] console_simple: fix: set f_active Jean-Christophe PLAGNIOL-VILLARD
2013-09-27  7:14   ` [PATCH 8/8] serial: atmel: add start and shutdown support Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1380784920-30890-8-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox