1 /* 2 * ssp-uart.c SPI via SSP 3 * Copyright (C) 2011, Mark F. Brown <mark.f.brown (at) intel.com> Intel Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms and conditions of the GNU General Public License, 7 * version 2, as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * You should have received a copy of the GNU General Public License along with 15 * this program; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 */ 19 20 #include "ssp-uart.h" 21 #include "bootstub.h" 22 23 #define SSP_TIMEOUT 0xAFF 24 #define SSP_SLAVE 0x02 /* Slave select */ 25 #define SSP_SSCR0 0x00C0008F 26 #define SSP_SSCR1 0x10000000 27 28 static int ssp_inited = 0; 29 static volatile struct ssp_reg *pspi = 0; 30 31 #define WRITE_DATA (2<<14) 32 33 static void ssp_init() 34 { 35 pspi = (struct ssp_reg*)TNG_SSP5_ADDR_BASE; 36 pspi->SSPx_SSFS = SSP_SLAVE; 37 pspi->SSPx_SSCR1 = SSP_SSCR1; 38 pspi->SSPx_SSCR0 = SSP_SSCR0; 39 40 ssp_inited = 1; 41 } 42 43 static void ssp_max3110_putc(char c) 44 { 45 vu32 SSCR0 = 0; 46 vu32 i; 47 48 pspi = (struct ssp_reg*)TNG_SSP5_ADDR_BASE; 49 SSCR0 = (WRITE_DATA | c); 50 pspi->SSPx_SSDR = SSCR0; 51 52 for (i = 0; i < SSP_TIMEOUT; i++) 53 { 54 SSCR0 = pspi->SSPx_SSSR; 55 if ((SSCR0 & 0xF00) == 0) break; 56 } 57 58 SSCR0 = pspi->SSPx_SSDR; 59 } 60 61 void bs_ssp_printk(const char *str) 62 { 63 if (!str) 64 return; 65 66 if (!ssp_inited) 67 { 68 ssp_init(); 69 } 70 71 while (*str) { 72 if (*str == '\n') 73 ssp_max3110_putc('\r'); 74 75 ssp_max3110_putc(*str++); 76 } 77 } 78