1*39e661bcSEtienne Carriere /* 2*39e661bcSEtienne Carriere * Copyright (c) 2017, Linaro Limited 3*39e661bcSEtienne Carriere * All rights reserved. 4*39e661bcSEtienne Carriere * 5*39e661bcSEtienne Carriere * Redistribution and use in source and binary forms, with or without 6*39e661bcSEtienne Carriere * modification, are permitted provided that the following conditions are met: 7*39e661bcSEtienne Carriere * 8*39e661bcSEtienne Carriere * 1. Redistributions of source code must retain the above copyright notice, 9*39e661bcSEtienne Carriere * this list of conditions and the following disclaimer. 10*39e661bcSEtienne Carriere * 11*39e661bcSEtienne Carriere * 2. Redistributions in binary form must reproduce the above copyright notice, 12*39e661bcSEtienne Carriere * this list of conditions and the following disclaimer in the documentation 13*39e661bcSEtienne Carriere * and/or other materials provided with the distribution. 14*39e661bcSEtienne Carriere * 15*39e661bcSEtienne Carriere * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16*39e661bcSEtienne Carriere * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*39e661bcSEtienne Carriere * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*39e661bcSEtienne Carriere * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19*39e661bcSEtienne Carriere * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*39e661bcSEtienne Carriere * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*39e661bcSEtienne Carriere * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*39e661bcSEtienne Carriere * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*39e661bcSEtienne Carriere * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*39e661bcSEtienne Carriere * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*39e661bcSEtienne Carriere * POSSIBILITY OF SUCH DAMAGE. 26*39e661bcSEtienne Carriere */ 27*39e661bcSEtienne Carriere #include <drivers/stih_asc.h> 28*39e661bcSEtienne Carriere #include <io.h> 29*39e661bcSEtienne Carriere #include <util.h> 30*39e661bcSEtienne Carriere 31*39e661bcSEtienne Carriere #define ASC_BAUDRATE 0x00 32*39e661bcSEtienne Carriere #define ASC_TXBUFFER 0x04 33*39e661bcSEtienne Carriere #define ASC_STATUS 0x14 34*39e661bcSEtienne Carriere 35*39e661bcSEtienne Carriere #define ASC_STATUS_TX_EMPTY BIT(1) 36*39e661bcSEtienne Carriere #define ASC_STATUS_TX_HALF_EMPTY BIT(2) 37*39e661bcSEtienne Carriere 38*39e661bcSEtienne Carriere void stih_asc_flush(vaddr_t base) 39*39e661bcSEtienne Carriere { 40*39e661bcSEtienne Carriere while (!(read32(base + ASC_STATUS) & ASC_STATUS_TX_EMPTY)) 41*39e661bcSEtienne Carriere ; 42*39e661bcSEtienne Carriere } 43*39e661bcSEtienne Carriere 44*39e661bcSEtienne Carriere void stih_asc_putc(int ch, vaddr_t base) 45*39e661bcSEtienne Carriere { 46*39e661bcSEtienne Carriere /* Wait until there is space in the FIFO */ 47*39e661bcSEtienne Carriere while (!(read32(base + ASC_STATUS) & ASC_STATUS_TX_HALF_EMPTY)) 48*39e661bcSEtienne Carriere ; 49*39e661bcSEtienne Carriere 50*39e661bcSEtienne Carriere /* Send the character */ 51*39e661bcSEtienne Carriere write32(ch, base + ASC_TXBUFFER); 52*39e661bcSEtienne Carriere } 53*39e661bcSEtienne Carriere 54*39e661bcSEtienne Carriere void stih_asc_init(vaddr_t base) 55*39e661bcSEtienne Carriere { 56*39e661bcSEtienne Carriere /* 57*39e661bcSEtienne Carriere * Console setup relies on early bootstage or nonsecure world. 58*39e661bcSEtienne Carriere * Only flush ASC FIFO if possible. 59*39e661bcSEtienne Carriere */ 60*39e661bcSEtienne Carriere console_flush(); 61*39e661bcSEtienne Carriere } 62