Path: blob/master/arch/powerpc/platforms/powermac/udbg_scc.c
10818 views
/*1* udbg for zilog scc ports as found on Apple PowerMacs2*3* Copyright (C) 2001-2005 PPC 64 Team, IBM Corp4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public License7* as published by the Free Software Foundation; either version8* 2 of the License, or (at your option) any later version.9*/10#include <linux/types.h>11#include <asm/udbg.h>12#include <asm/processor.h>13#include <asm/io.h>14#include <asm/prom.h>15#include <asm/pmac_feature.h>1617extern u8 real_readb(volatile u8 __iomem *addr);18extern void real_writeb(u8 data, volatile u8 __iomem *addr);1920#define SCC_TXRDY 421#define SCC_RXRDY 12223static volatile u8 __iomem *sccc;24static volatile u8 __iomem *sccd;2526static void udbg_scc_putc(char c)27{28if (sccc) {29while ((in_8(sccc) & SCC_TXRDY) == 0)30;31out_8(sccd, c);32if (c == '\n')33udbg_scc_putc('\r');34}35}3637static int udbg_scc_getc_poll(void)38{39if (sccc) {40if ((in_8(sccc) & SCC_RXRDY) != 0)41return in_8(sccd);42else43return -1;44}45return -1;46}4748static int udbg_scc_getc(void)49{50if (sccc) {51while ((in_8(sccc) & SCC_RXRDY) == 0)52;53return in_8(sccd);54}55return -1;56}5758static unsigned char scc_inittab[] = {5913, 0, /* set baud rate divisor */6012, 0,6114, 1, /* baud rate gen enable, src=rtxc */6211, 0x50, /* clocks = br gen */635, 0xea, /* tx 8 bits, assert DTR & RTS */644, 0x46, /* x16 clock, 1 stop */653, 0xc1, /* rx enable, 8 bits */66};6768void udbg_scc_init(int force_scc)69{70const u32 *reg;71unsigned long addr;72struct device_node *stdout = NULL, *escc = NULL, *macio = NULL;73struct device_node *ch, *ch_def = NULL, *ch_a = NULL;74const char *path;75int i, x;7677escc = of_find_node_by_name(NULL, "escc");78if (escc == NULL)79goto bail;80macio = of_get_parent(escc);81if (macio == NULL)82goto bail;83path = of_get_property(of_chosen, "linux,stdout-path", NULL);84if (path != NULL)85stdout = of_find_node_by_path(path);86for (ch = NULL; (ch = of_get_next_child(escc, ch)) != NULL;) {87if (ch == stdout)88ch_def = of_node_get(ch);89if (strcmp(ch->name, "ch-a") == 0)90ch_a = of_node_get(ch);91}92if (ch_def == NULL && !force_scc)93goto bail;9495ch = ch_def ? ch_def : ch_a;9697/* Get address within mac-io ASIC */98reg = of_get_property(escc, "reg", NULL);99if (reg == NULL)100goto bail;101addr = reg[0];102103/* Get address of mac-io PCI itself */104reg = of_get_property(macio, "assigned-addresses", NULL);105if (reg == NULL)106goto bail;107addr += reg[2];108109/* Lock the serial port */110pmac_call_feature(PMAC_FTR_SCC_ENABLE, ch,111PMAC_SCC_ASYNC | PMAC_SCC_FLAG_XMON, 1);112113if (ch == ch_a)114addr += 0x20;115sccc = ioremap(addr & PAGE_MASK, PAGE_SIZE) ;116sccc += addr & ~PAGE_MASK;117sccd = sccc + 0x10;118119mb();120121for (i = 20000; i != 0; --i)122x = in_8(sccc);123out_8(sccc, 0x09); /* reset A or B side */124out_8(sccc, 0xc0);125126/* If SCC was the OF output port, read the BRG value, else127* Setup for 38400 or 57600 8N1 depending on the machine128*/129if (ch_def != NULL) {130out_8(sccc, 13);131scc_inittab[1] = in_8(sccc);132out_8(sccc, 12);133scc_inittab[3] = in_8(sccc);134} else if (of_machine_is_compatible("RackMac1,1")135|| of_machine_is_compatible("RackMac1,2")136|| of_machine_is_compatible("MacRISC4")) {137/* Xserves and G5s default to 57600 */138scc_inittab[1] = 0;139scc_inittab[3] = 0;140} else {141/* Others default to 38400 */142scc_inittab[1] = 0;143scc_inittab[3] = 1;144}145146for (i = 0; i < sizeof(scc_inittab); ++i)147out_8(sccc, scc_inittab[i]);148149150udbg_putc = udbg_scc_putc;151udbg_getc = udbg_scc_getc;152udbg_getc_poll = udbg_scc_getc_poll;153154udbg_puts("Hello World !\n");155156bail:157of_node_put(macio);158of_node_put(escc);159of_node_put(stdout);160of_node_put(ch_def);161of_node_put(ch_a);162}163164#ifdef CONFIG_PPC64165static void udbg_real_scc_putc(char c)166{167while ((real_readb(sccc) & SCC_TXRDY) == 0)168;169real_writeb(c, sccd);170if (c == '\n')171udbg_real_scc_putc('\r');172}173174void __init udbg_init_pmac_realmode(void)175{176sccc = (volatile u8 __iomem *)0x80013020ul;177sccd = (volatile u8 __iomem *)0x80013030ul;178179udbg_putc = udbg_real_scc_putc;180udbg_getc = NULL;181udbg_getc_poll = NULL;182}183#endif /* CONFIG_PPC64 */184185186