walnut.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * BK Id: SCCS/s.walnut_setup.c 1.10 11/13/01 21:26:07 paulus
  3.  */
  4. /*
  5.  *
  6.  *    Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
  7.  *
  8.  *    Module name: walnut_setup.c
  9.  *
  10.  *    Description:
  11.  *      Architecture- / platform-specific boot-time initialization code for
  12.  *      the IBM PowerPC 403GP "Walnut" evaluation board. Adapted from original
  13.  *      code by Gary Thomas, Cort Dougan <cort@fsmlabs.com>, and Dan Malek
  14.  *      <dan@net4x.com>.
  15.  *
  16.  */
  17. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <linux/smp.h>
  20. #include <linux/threads.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/param.h>
  23. #include <linux/string.h>
  24. #include <linux/blk.h>
  25. #include <linux/seq_file.h>
  26. #include <asm/processor.h>
  27. #include <asm/board.h>
  28. #include <asm/machdep.h>
  29. #include <asm/page.h>
  30. #include "ppc4xx_pic.h"
  31. #include <asm/time.h>
  32. #include "walnut_setup.h"
  33. /* Function Prototypes */
  34. extern void abort(void);
  35. /* Global Variables */
  36. unsigned char __res[sizeof(bd_t)];
  37. /*
  38.  * void __init walnut_init()
  39.  *
  40.  * Description:
  41.  *   This routine...
  42.  *
  43.  * Input(s):
  44.  *   r3 - Optional pointer to a board information structure.
  45.  *   r4 - Optional pointer to the physical starting address of the init RAM
  46.  *        disk.
  47.  *   r5 - Optional pointer to the physical ending address of the init RAM
  48.  *        disk.
  49.  *   r6 - Optional pointer to the physical starting address of any kernel
  50.  *        command-line parameters.
  51.  *   r7 - Optional pointer to the physical ending address of any kernel
  52.  *        command-line parameters.
  53.  *
  54.  * Output(s):
  55.  *   N/A
  56.  *
  57.  * Returns:
  58.  *   N/A
  59.  *
  60.  */
  61. void __init
  62. walnut_init(unsigned long r3, unsigned long r4, unsigned long r5, 
  63.     unsigned long r6, unsigned long r7)
  64. {
  65. /*
  66.  * If we were passed in a board information, copy it into the
  67.  * residual data area.
  68.  */
  69. if (r3) {
  70. memcpy((void *)__res, (void *)(r3 + KERNELBASE), sizeof(bd_t));
  71. }
  72. #if defined(CONFIG_BLK_DEV_INITRD)
  73. /*
  74.  * If the init RAM disk has been configured in, and there's a valid
  75.  * starting address for it, set it up.
  76.  */
  77. if (r4) {
  78. initrd_start = r4 + KERNELBASE;
  79. initrd_end = r5 + KERNELBASE;
  80. }
  81. #endif /* CONFIG_BLK_DEV_INITRD */
  82. /* Copy the kernel command line arguments to a safe place. */
  83. if (r6) {
  84.   *(char *)(r7 + KERNELBASE) = 0;
  85. strcpy(cmd_line, (char *)(r6 + KERNELBASE));
  86. }
  87. /* Initialize machine-dependency vectors */
  88. ppc_md.setup_arch   = walnut_setup_arch;
  89. ppc_md.show_percpuinfo   = walnut_show_percpuinfo;
  90. ppc_md.irq_cannonicalize  = NULL;
  91. ppc_md.init_IRQ   = walnut_init_IRQ;
  92. ppc_md.get_irq   = walnut_get_irq;
  93. ppc_md.init   = NULL;
  94. ppc_md.restart   = walnut_restart;
  95. ppc_md.power_off   = walnut_power_off;
  96. ppc_md.halt   = walnut_halt;
  97. ppc_md.time_init   = walnut_time_init;
  98. ppc_md.set_rtc_time   = walnut_set_rtc_time;
  99. ppc_md.get_rtc_time   = walnut_get_rtc_time;
  100. ppc_md.calibrate_decr   = walnut_calibrate_decr;
  101. ppc_md.kbd_setkeycode     = NULL;
  102. ppc_md.kbd_getkeycode     = NULL;
  103. ppc_md.kbd_translate      = NULL;
  104. ppc_md.kbd_unexpected_up  = NULL;
  105. ppc_md.kbd_leds           = NULL;
  106. ppc_md.kbd_init_hw        = NULL;
  107. ppc_md.ppc_kbd_sysrq_xlate = NULL;
  108. }
  109. /*
  110.  * Document me.
  111.  */
  112. void __init
  113. walnut_setup_arch(void)
  114. {
  115. /* XXX - Implement me */
  116. }
  117. /*
  118.  * int walnut_show_percpuinfo()
  119.  *
  120.  * Description:
  121.  *   This routine pretty-prints the platform's internal CPU and bus clock
  122.  *   frequencies into the buffer for usage in /proc/cpuinfo.
  123.  *
  124.  * Input(s):
  125.  *  *buffer - Buffer into which CPU and bus clock frequencies are to be
  126.  *            printed.
  127.  *
  128.  * Output(s):
  129.  *  *buffer - Buffer with the CPU and bus clock frequencies.
  130.  *
  131.  * Returns:
  132.  *   The number of bytes copied into 'buffer' if OK, otherwise zero or less
  133.  *   on error.
  134.  */
  135. int
  136. walnut_show_percpuinfo(struct seq_file *m)
  137. {
  138. bd_t *bp = (bd_t *)__res;
  139. seq_printf(m, "clocktt: %dMHzn"
  140.    "bus clocktt: %dMHzn",
  141.    bp->bi_intfreq / 1000000,
  142.    bp->bi_busfreq / 1000000);
  143. return 0;
  144. }
  145. /*
  146.  * Document me.
  147.  */
  148. void __init
  149. walnut_init_IRQ(void)
  150. {
  151. int i;
  152. ppc4xx_pic_init();
  153. for (i = 0; i < NR_IRQS; i++) {
  154. irq_desc[i].handler = ppc4xx_pic;
  155. }
  156. return;
  157. }
  158. /*
  159.  * Document me.
  160.  */
  161. int
  162. walnut_get_irq(struct pt_regs *regs)
  163. {
  164. return (ppc4xx_pic_get_irq(regs));
  165. }
  166. /*
  167.  * Document me.
  168.  */
  169. void
  170. walnut_restart(char *cmd)
  171. {
  172. abort();
  173. }
  174. /*
  175.  * Document me.
  176.  */
  177. void
  178. walnut_power_off(void)
  179. {
  180. walnut_restart(NULL);
  181. }
  182. /*
  183.  * Document me.
  184.  */
  185. void
  186. walnut_halt(void)
  187. {
  188. walnut_restart(NULL);
  189. }
  190. /*
  191.  * Document me.
  192.  */
  193. long __init
  194. walnut_time_init(void)
  195. {
  196. /* XXX - Implement me */
  197. return 0;
  198. }
  199. /*
  200.  * Document me.
  201.  */
  202. int __init
  203. walnut_set_rtc_time(unsigned long time)
  204. {
  205. /* XXX - Implement me */
  206. return (0);
  207. }
  208. /*
  209.  * Document me.
  210.  */
  211. unsigned long __init
  212. walnut_get_rtc_time(void)
  213. {
  214. /* XXX - Implement me */
  215. return (0);
  216. }
  217. /*
  218.  * void __init walnut_calibrate_decr()
  219.  *
  220.  * Description:
  221.  *   This routine retrieves the internal processor frequency from the board
  222.  *   information structure, sets up the kernel timer decrementer based on
  223.  *   that value, enables the 403 programmable interval timer (PIT) and sets
  224.  *   it up for auto-reload.
  225.  *
  226.  * Input(s):
  227.  *   N/A
  228.  *
  229.  * Output(s):
  230.  *   N/A
  231.  *
  232.  * Returns:
  233.  *   N/A
  234.  *
  235.  */
  236. void __init
  237. walnut_calibrate_decr(void)
  238. {
  239. unsigned int freq;
  240. bd_t *bip = (bd_t *)__res;
  241. freq = bip->bi_intfreq;
  242. decrementer_count = freq / HZ;
  243. count_period_num = 1;
  244. count_period_den = freq;
  245. /* Enable the PIT and set auto-reload of its value */
  246. mtspr(SPRN_TCR, TCR_PIE | TCR_ARE);
  247. /* Clear any pending timer interrupts */
  248. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_PIS | TSR_FIS);
  249. }