Path: blob/master/arch/powerpc/platforms/embedded6xx/ls_uart.c
10819 views
/*1* AVR power-management chip interface for the Buffalo Linkstation /2* Kurobox Platform.3*4* Author: 2006 (c) G. Liakhovetski5* [email protected]6*7* This file is licensed under the terms of the GNU General Public License8* version 2. This program is licensed "as is" without any warranty of9* any kind, whether express or implied.10*/11#include <linux/workqueue.h>12#include <linux/string.h>13#include <linux/delay.h>14#include <linux/serial_reg.h>15#include <linux/serial_8250.h>16#include <asm/io.h>17#include <asm/prom.h>18#include <asm/termbits.h>1920#include "mpc10x.h"2122static void __iomem *avr_addr;23static unsigned long avr_clock;2425static struct work_struct wd_work;2627static void wd_stop(struct work_struct *unused)28{29const char string[] = "AAAAFFFFJJJJ>>>>VVVV>>>>ZZZZVVVVKKKK";30int i = 0, rescue = 8;31int len = strlen(string);3233while (rescue--) {34int j;35char lsr = in_8(avr_addr + UART_LSR);3637if (lsr & (UART_LSR_THRE | UART_LSR_TEMT)) {38for (j = 0; j < 16 && i < len; j++, i++)39out_8(avr_addr + UART_TX, string[i]);40if (i == len) {41/* Read "OK" back: 4ms for the last "KKKK"42plus a couple bytes back */43msleep(7);44printk("linkstation: disarming the AVR watchdog: ");45while (in_8(avr_addr + UART_LSR) & UART_LSR_DR)46printk("%c", in_8(avr_addr + UART_RX));47break;48}49}50msleep(17);51}52printk("\n");53}5455#define AVR_QUOT(clock) ((clock) + 8 * 9600) / (16 * 9600)5657void avr_uart_configure(void)58{59unsigned char cval = UART_LCR_WLEN8;60unsigned int quot = AVR_QUOT(avr_clock);6162if (!avr_addr || !avr_clock)63return;6465out_8(avr_addr + UART_LCR, cval); /* initialise UART */66out_8(avr_addr + UART_MCR, 0);67out_8(avr_addr + UART_IER, 0);6869cval |= UART_LCR_STOP | UART_LCR_PARITY | UART_LCR_EPAR;7071out_8(avr_addr + UART_LCR, cval); /* Set character format */7273out_8(avr_addr + UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */74out_8(avr_addr + UART_DLL, quot & 0xff); /* LS of divisor */75out_8(avr_addr + UART_DLM, quot >> 8); /* MS of divisor */76out_8(avr_addr + UART_LCR, cval); /* reset DLAB */77out_8(avr_addr + UART_FCR, UART_FCR_ENABLE_FIFO); /* enable FIFO */78}7980void avr_uart_send(const char c)81{82if (!avr_addr || !avr_clock)83return;8485out_8(avr_addr + UART_TX, c);86out_8(avr_addr + UART_TX, c);87out_8(avr_addr + UART_TX, c);88out_8(avr_addr + UART_TX, c);89}9091static void __init ls_uart_init(void)92{93local_irq_disable();9495#ifndef CONFIG_SERIAL_825096out_8(avr_addr + UART_FCR, UART_FCR_ENABLE_FIFO); /* enable FIFO */97out_8(avr_addr + UART_FCR, UART_FCR_ENABLE_FIFO |98UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); /* clear FIFOs */99out_8(avr_addr + UART_FCR, 0);100out_8(avr_addr + UART_IER, 0);101102/* Clear up interrupts */103(void) in_8(avr_addr + UART_LSR);104(void) in_8(avr_addr + UART_RX);105(void) in_8(avr_addr + UART_IIR);106(void) in_8(avr_addr + UART_MSR);107#endif108avr_uart_configure();109110local_irq_enable();111}112113static int __init ls_uarts_init(void)114{115struct device_node *avr;116phys_addr_t phys_addr;117int len;118119avr = of_find_node_by_path("/soc10x/serial@80004500");120if (!avr)121return -EINVAL;122123avr_clock = *(u32*)of_get_property(avr, "clock-frequency", &len);124phys_addr = ((u32*)of_get_property(avr, "reg", &len))[0];125126if (!avr_clock || !phys_addr)127return -EINVAL;128129avr_addr = ioremap(phys_addr, 32);130if (!avr_addr)131return -EFAULT;132133ls_uart_init();134135INIT_WORK(&wd_work, wd_stop);136schedule_work(&wd_work);137138return 0;139}140141machine_late_initcall(linkstation, ls_uarts_init);142143144