From 873910050ea0efc92db49ed233e70df7276a3f5b Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 4 Aug 2010 03:33:15 +0200 Subject: at91: implement clock framework this implementation is based on linux one (v2.6.35-rc5-76-gd0c6f62) it will calculate all the clock dynamically instead of statictly this will use also the new clock framework it will also print the clock status after the console init Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- drivers/net/macb.c | 11 ++++++++++- drivers/serial/atmel.c | 32 +++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 4feeed0ba1..6864119bd5 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include "macb.h" @@ -412,6 +412,9 @@ static int macb_probe(struct device_d *dev) unsigned long macb_hz; u32 ncfgr; struct at91_ether_platform_data *pdata; +#if defined(CONFIG_ARCH_AT91) + struct clk *pclk; +#endif if (!dev->platform_data) { printf("macb: no platform_data\n"); @@ -450,7 +453,13 @@ static int macb_probe(struct device_d *dev) * Do some basic initialization so that we at least can talk * to the PHY */ +#if defined(CONFIG_ARCH_AT91) + pclk = clk_get(dev, "macb_clk"); + clk_enable(pclk); + macb_hz = clk_get_rate(pclk); +#else macb_hz = get_macb_pclk_rate(0); +#endif if (macb_hz < 20000000) ncfgr = MACB_BF(CLK, MACB_CLK_DIV8); else if (macb_hz < 40000000) diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c index e9e8116619..b99ec4dacc 100644 --- a/drivers/serial/atmel.c +++ b/drivers/serial/atmel.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include /* USART3 register offsets */ #define USART3_CR 0x0000 @@ -309,6 +309,21 @@ << USART3_##name##_OFFSET)) \ | USART3_BF(name,value)) +/* + * We wrap our port structure around the generic console_device. + */ +struct atmel_uart_port { + struct console_device uart; /* uart */ + struct clk *clk; /* uart clock */ + u32 uartclk; +}; + +static inline struct atmel_uart_port * +to_atmel_uart_port(struct console_device *uart) +{ + return container_of(uart, struct atmel_uart_port, uart); +} + static void atmel_serial_putc(struct console_device *cdev, char c) { struct device_d *dev = cdev->dev; @@ -336,16 +351,15 @@ static int atmel_serial_getc(struct console_device *cdev) static int atmel_serial_setbaudrate(struct console_device *cdev, int baudrate) { struct device_d *dev = cdev->dev; + struct atmel_uart_port *uart = to_atmel_uart_port(cdev); unsigned long divisor; - unsigned long usart_hz; /* * Master Clock * Baud Rate = -------------- * 16 * CD */ - usart_hz = get_usart_clk_rate(0); - divisor = (usart_hz / 16 + baudrate / 2) / baudrate; + divisor = (uart->uartclk / 16 + baudrate / 2) / baudrate; writel(USART3_BF(CD, divisor), dev->map_base + USART3_BRGR); return 0; @@ -359,6 +373,11 @@ static int atmel_serial_setbaudrate(struct console_device *cdev, int baudrate) static int atmel_serial_init_port(struct console_device *cdev) { struct device_d *dev = cdev->dev; + struct atmel_uart_port *uart = to_atmel_uart_port(cdev); + + uart->clk = clk_get(dev, "usart"); + clk_enable(uart->clk); + uart->uartclk = clk_get_rate(uart->clk); writel(USART3_BIT(RSTRX) | USART3_BIT(RSTTX), dev->map_base + USART3_CR); @@ -376,9 +395,12 @@ static int atmel_serial_init_port(struct console_device *cdev) static int atmel_serial_probe(struct device_d *dev) { + struct atmel_uart_port *uart; struct console_device *cdev; - cdev = malloc(sizeof(struct console_device)); + uart = malloc(sizeof(struct atmel_uart_port)); + + cdev = &uart->uart; dev->type_data = cdev; cdev->dev = dev; cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR; -- cgit v1.2.3