Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Based on Ocelot Linux port, which is |
| 3 | * Copyright 2001 MontaVista Software Inc. |
| 4 | * Author: jsun@mvista.com or jsun@junsun.net |
| 5 | * |
| 6 | * Copyright 2003 ICT CAS |
| 7 | * Author: Michael Guo <guoyi@ict.ac.cn> |
| 8 | * |
| 9 | * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology |
| 10 | * Author: Fuxin Zhang, zhangfx@lemote.com |
| 11 | * |
Wu Zhangjin | f7a904d | 2010-01-04 17:16:51 +0800 | [diff] [blame] | 12 | * Copyright (C) 2009 Lemote Inc. |
| 13 | * Author: Wu Zhangjin, wuzhangjin@gmail.com |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms of the GNU General Public License as published by the |
| 17 | * Free Software Foundation; either version 2 of the License, or (at your |
| 18 | * option) any later version. |
| 19 | */ |
Wu Zhangjin | f8ede0f | 2009-11-17 01:32:59 +0800 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 22 | #include <asm/bootinfo.h> |
| 23 | |
Wu Zhangjin | 5e983ff | 2009-07-02 23:23:03 +0800 | [diff] [blame] | 24 | #include <loongson.h> |
| 25 | |
Wu Zhangjin | eb11df4 | 2010-01-04 17:16:48 +0800 | [diff] [blame] | 26 | unsigned long cpu_clock_freq; |
Wu Zhangjin | f8ede0f | 2009-11-17 01:32:59 +0800 | [diff] [blame] | 27 | EXPORT_SYMBOL(cpu_clock_freq); |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 28 | unsigned long memsize, highmemsize; |
| 29 | |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 30 | #define parse_even_earlier(res, option, p) \ |
| 31 | do { \ |
Wu Zhangjin | ec79812 | 2010-11-08 21:25:24 +0800 | [diff] [blame] | 32 | int ret; \ |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 33 | if (strncmp(option, (char *)p, strlen(option)) == 0) \ |
Wu Zhangjin | ec79812 | 2010-11-08 21:25:24 +0800 | [diff] [blame] | 34 | ret = strict_strtol((char *)p + strlen(option"="), 10, &res); \ |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 35 | } while (0) |
| 36 | |
| 37 | void __init prom_init_env(void) |
| 38 | { |
Wu Zhangjin | eb11df4 | 2010-01-04 17:16:48 +0800 | [diff] [blame] | 39 | /* pmon passes arguments in 32bit pointers */ |
| 40 | int *_prom_envp; |
| 41 | unsigned long bus_clock; |
| 42 | unsigned int processor_id; |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 43 | long l; |
| 44 | |
| 45 | /* firmware arguments are initialized in head.S */ |
| 46 | _prom_envp = (int *)fw_arg2; |
| 47 | |
| 48 | l = (long)*_prom_envp; |
| 49 | while (l != 0) { |
| 50 | parse_even_earlier(bus_clock, "busclock", l); |
| 51 | parse_even_earlier(cpu_clock_freq, "cpuclock", l); |
| 52 | parse_even_earlier(memsize, "memsize", l); |
| 53 | parse_even_earlier(highmemsize, "highmemsize", l); |
| 54 | _prom_envp++; |
| 55 | l = (long)*_prom_envp; |
| 56 | } |
| 57 | if (memsize == 0) |
| 58 | memsize = 256; |
Wu Zhangjin | eb11df4 | 2010-01-04 17:16:48 +0800 | [diff] [blame] | 59 | if (bus_clock == 0) |
| 60 | bus_clock = 66000000; |
| 61 | if (cpu_clock_freq == 0) { |
| 62 | processor_id = (¤t_cpu_data)->processor_id; |
| 63 | switch (processor_id & PRID_REV_MASK) { |
| 64 | case PRID_REV_LOONGSON2E: |
| 65 | cpu_clock_freq = 533080000; |
| 66 | break; |
| 67 | case PRID_REV_LOONGSON2F: |
| 68 | cpu_clock_freq = 797000000; |
| 69 | break; |
| 70 | default: |
| 71 | cpu_clock_freq = 100000000; |
| 72 | break; |
| 73 | } |
| 74 | } |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 75 | |
| 76 | pr_info("busclock=%ld, cpuclock=%ld, memsize=%ld, highmemsize=%ld\n", |
| 77 | bus_clock, cpu_clock_freq, memsize, highmemsize); |
| 78 | } |