Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights |
| 3 | * reserved. |
| 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the NetLogic |
| 9 | * license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer. |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer in |
| 19 | * the documentation and/or other materials provided with the |
| 20 | * distribution. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR |
| 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE |
| 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 31 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 32 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/serial_8250.h> |
| 37 | #include <linux/pm.h> |
| 38 | |
| 39 | #include <asm/reboot.h> |
| 40 | #include <asm/time.h> |
| 41 | #include <asm/bootinfo.h> |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 42 | |
| 43 | #include <asm/netlogic/interrupt.h> |
| 44 | #include <asm/netlogic/psb-bootinfo.h> |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 45 | #include <asm/netlogic/haldefs.h> |
| 46 | #include <asm/netlogic/common.h> |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 47 | |
| 48 | #include <asm/netlogic/xlr/xlr.h> |
| 49 | #include <asm/netlogic/xlr/iomap.h> |
| 50 | #include <asm/netlogic/xlr/pic.h> |
| 51 | #include <asm/netlogic/xlr/gpio.h> |
| 52 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 53 | uint64_t nlm_io_base = DEFAULT_NETLOGIC_IO_BASE; |
| 54 | uint64_t nlm_pic_base; |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 55 | unsigned long nlm_common_ebase = 0x0; |
| 56 | struct psb_info nlm_prom_info; |
| 57 | |
Jayachandran C | a74e335 | 2011-06-22 01:37:05 +0530 | [diff] [blame] | 58 | static void __init nlm_early_serial_setup(void) |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 59 | { |
| 60 | struct uart_port s; |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 61 | unsigned long uart_base; |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 62 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 63 | uart_base = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_0_OFFSET); |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 64 | memset(&s, 0, sizeof(s)); |
| 65 | s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST; |
| 66 | s.iotype = UPIO_MEM32; |
| 67 | s.regshift = 2; |
| 68 | s.irq = PIC_UART_0_IRQ; |
| 69 | s.uartclk = PIC_CLKS_PER_SEC; |
| 70 | s.serial_in = nlm_xlr_uart_in; |
| 71 | s.serial_out = nlm_xlr_uart_out; |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 72 | s.mapbase = uart_base; |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 73 | s.membase = (unsigned char __iomem *)uart_base; |
| 74 | early_serial_setup(&s); |
| 75 | } |
| 76 | |
| 77 | static void nlm_linux_exit(void) |
| 78 | { |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 79 | uint64_t gpiobase; |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 80 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 81 | gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET); |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 82 | /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */ |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 83 | nlm_write_reg(gpiobase, NETLOGIC_GPIO_SWRESET_REG, 1); |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 84 | for ( ; ; ) |
| 85 | cpu_wait(); |
| 86 | } |
| 87 | |
| 88 | void __init plat_mem_setup(void) |
| 89 | { |
| 90 | panic_timeout = 5; |
| 91 | _machine_restart = (void (*)(char *))nlm_linux_exit; |
| 92 | _machine_halt = nlm_linux_exit; |
| 93 | pm_power_off = nlm_linux_exit; |
| 94 | } |
| 95 | |
| 96 | const char *get_system_type(void) |
| 97 | { |
| 98 | return "Netlogic XLR/XLS Series"; |
| 99 | } |
| 100 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 101 | unsigned int nlm_get_cpu_frequency(void) |
| 102 | { |
| 103 | return (unsigned int)nlm_prom_info.cpu_frequency; |
| 104 | } |
| 105 | |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 106 | void __init prom_free_prom_memory(void) |
| 107 | { |
| 108 | /* Nothing yet */ |
| 109 | } |
| 110 | |
Jayachandran C | a74e335 | 2011-06-22 01:37:05 +0530 | [diff] [blame] | 111 | static void __init build_arcs_cmdline(int *argv) |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 112 | { |
| 113 | int i, remain, len; |
| 114 | char *arg; |
| 115 | |
| 116 | remain = sizeof(arcs_cmdline) - 1; |
| 117 | arcs_cmdline[0] = '\0'; |
| 118 | for (i = 0; argv[i] != 0; i++) { |
| 119 | arg = (char *)(long)argv[i]; |
| 120 | len = strlen(arg); |
| 121 | if (len + 1 > remain) |
| 122 | break; |
| 123 | strcat(arcs_cmdline, arg); |
| 124 | strcat(arcs_cmdline, " "); |
| 125 | remain -= len + 1; |
| 126 | } |
| 127 | |
| 128 | /* Add the default options here */ |
| 129 | if ((strstr(arcs_cmdline, "console=")) == NULL) { |
| 130 | arg = "console=ttyS0,38400 "; |
| 131 | len = strlen(arg); |
| 132 | if (len > remain) |
| 133 | goto fail; |
| 134 | strcat(arcs_cmdline, arg); |
| 135 | remain -= len; |
| 136 | } |
| 137 | #ifdef CONFIG_BLK_DEV_INITRD |
| 138 | if ((strstr(arcs_cmdline, "rdinit=")) == NULL) { |
| 139 | arg = "rdinit=/sbin/init "; |
| 140 | len = strlen(arg); |
| 141 | if (len > remain) |
| 142 | goto fail; |
| 143 | strcat(arcs_cmdline, arg); |
| 144 | remain -= len; |
| 145 | } |
| 146 | #endif |
| 147 | return; |
| 148 | fail: |
| 149 | panic("Cannot add %s, command line too big!", arg); |
| 150 | } |
| 151 | |
| 152 | static void prom_add_memory(void) |
| 153 | { |
| 154 | struct nlm_boot_mem_map *bootm; |
| 155 | u64 start, size; |
| 156 | u64 pref_backup = 512; /* avoid pref walking beyond end */ |
| 157 | int i; |
| 158 | |
| 159 | bootm = (void *)(long)nlm_prom_info.psb_mem_map; |
| 160 | for (i = 0; i < bootm->nr_map; i++) { |
| 161 | if (bootm->map[i].type != BOOT_MEM_RAM) |
| 162 | continue; |
| 163 | start = bootm->map[i].addr; |
| 164 | size = bootm->map[i].size; |
| 165 | |
| 166 | /* Work around for using bootloader mem */ |
| 167 | if (i == 0 && start == 0 && size == 0x0c000000) |
| 168 | size = 0x0ff00000; |
| 169 | |
| 170 | add_memory_region(start, size - pref_backup, BOOT_MEM_RAM); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void __init prom_init(void) |
| 175 | { |
| 176 | int *argv, *envp; /* passed as 32 bit ptrs */ |
| 177 | struct psb_info *prom_infop; |
| 178 | |
| 179 | /* truncate to 32 bit and sign extend all args */ |
| 180 | argv = (int *)(long)(int)fw_arg1; |
| 181 | envp = (int *)(long)(int)fw_arg2; |
| 182 | prom_infop = (struct psb_info *)(long)(int)fw_arg3; |
| 183 | |
| 184 | nlm_prom_info = *prom_infop; |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame^] | 185 | nlm_pic_base = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET); |
Jayachandran C | 5c64250 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 186 | |
| 187 | nlm_early_serial_setup(); |
| 188 | build_arcs_cmdline(argv); |
| 189 | nlm_common_ebase = read_c0_ebase() & (~((1 << 12) - 1)); |
| 190 | prom_add_memory(); |
| 191 | |
| 192 | #ifdef CONFIG_SMP |
| 193 | nlm_wakeup_secondary_cpus(nlm_prom_info.online_cpu_map); |
| 194 | register_smp_ops(&nlm_smp_ops); |
| 195 | #endif |
| 196 | } |