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

Linux/Unix编程

开发平台:

Unix_Linux

  1. #include <linux/config.h>
  2. #include <linux/types.h>
  3. #include <linux/kernel.h>
  4. #include <linux/mm.h>
  5. #include <linux/tty.h>
  6. #include <linux/console.h>
  7. #include <linux/rtc.h>
  8. #include <linux/vt_kern.h>
  9. #include <asm/setup.h>
  10. #include <asm/bootinfo.h>
  11. #include <asm/system.h>
  12. #include <asm/pgtable.h>
  13. #include <asm/apollohw.h>
  14. #include <asm/irq.h>
  15. #include <asm/rtc.h>
  16. #include <asm/machdep.h>
  17. u_long sio01_physaddr;
  18. u_long sio23_physaddr;
  19. u_long rtc_physaddr;
  20. u_long pica_physaddr;
  21. u_long picb_physaddr;
  22. u_long cpuctrl_physaddr;
  23. u_long timer_physaddr;
  24. u_long apollo_model;
  25. extern void dn_sched_init(void (*handler)(int,void *,struct pt_regs *));
  26. extern int dn_keyb_init(void);
  27. extern int dn_dummy_kbdrate(struct kbd_repeat *);
  28. extern void dn_init_IRQ(void);
  29. extern int dn_request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
  30. extern void dn_free_irq(unsigned int irq, void *dev_id);
  31. extern void dn_enable_irq(unsigned int);
  32. extern void dn_disable_irq(unsigned int);
  33. extern int dn_get_irq_list(char *);
  34. extern unsigned long dn_gettimeoffset(void);
  35. extern void dn_gettod(int *, int *, int *, int *, int *, int *);
  36. extern int dn_dummy_hwclk(int, struct rtc_time *);
  37. extern int dn_dummy_set_clock_mmss(unsigned long);
  38. extern void dn_mksound(unsigned int count, unsigned int ticks);
  39. extern void dn_dummy_reset(void);
  40. extern void dn_dummy_waitbut(void);
  41. extern struct fb_info *dn_fb_init(long *);
  42. extern void dn_dummy_debug_init(void);
  43. extern void dn_dummy_video_setup(char *,int *);
  44. extern void dn_process_int(int irq, struct pt_regs *fp);
  45. #ifdef CONFIG_HEARTBEAT
  46. static void dn_heartbeat(int on);
  47. #endif
  48. static void dn_timer_int(int irq,void *, struct pt_regs *);
  49. static void (*sched_timer_handler)(int, void *, struct pt_regs *)=NULL;
  50. static void dn_get_model(char *model);
  51. static int dn_cpuctrl=0xff00;
  52. static const char *apollo_models[] = {
  53. "DN3000 (Otter)",
  54. "DN3010 (Otter)",
  55. "DN3500 (Cougar II)",
  56. "DN4000 (Mink)",
  57. "DN4500 (Roadrunner)" };
  58. int apollo_parse_bootinfo(const struct bi_record *record) {
  59. int unknown = 0;
  60. const unsigned long *data = record->data;
  61. switch(record->tag) {
  62. case BI_APOLLO_MODEL: 
  63. apollo_model=*data;
  64. break;
  65. default:
  66.  unknown=1;
  67. }
  68. return unknown;
  69. }
  70. void dn_setup_model(void) {
  71. printk("Apollo hardware found: ");
  72. printk("[%s]n", apollo_models[apollo_model - APOLLO_DN3000]);
  73. switch(apollo_model) {
  74. case APOLLO_UNKNOWN:
  75. panic("Unknown apollo model");
  76. break;
  77. case APOLLO_DN3000:
  78. case APOLLO_DN3010:
  79. sio01_physaddr=SAU8_SIO01_PHYSADDR;
  80. rtc_physaddr=SAU8_RTC_PHYSADDR;
  81. pica_physaddr=SAU8_PICA;
  82. picb_physaddr=SAU8_PICB;
  83. cpuctrl_physaddr=SAU8_CPUCTRL;
  84. timer_physaddr=SAU8_TIMER;
  85. break;
  86. case APOLLO_DN4000:
  87. sio01_physaddr=SAU7_SIO01_PHYSADDR;
  88. sio23_physaddr=SAU7_SIO23_PHYSADDR;
  89. rtc_physaddr=SAU7_RTC_PHYSADDR;
  90. pica_physaddr=SAU7_PICA;
  91. picb_physaddr=SAU7_PICB;
  92. cpuctrl_physaddr=SAU7_CPUCTRL;
  93. timer_physaddr=SAU7_TIMER;
  94. break;
  95. case APOLLO_DN4500:
  96. panic("Apollo model not yet supported");
  97. break;
  98. case APOLLO_DN3500:
  99. sio01_physaddr=SAU7_SIO01_PHYSADDR;
  100. sio23_physaddr=SAU7_SIO23_PHYSADDR;
  101. rtc_physaddr=SAU7_RTC_PHYSADDR;
  102. pica_physaddr=SAU7_PICA;
  103. picb_physaddr=SAU7_PICB;
  104. cpuctrl_physaddr=SAU7_CPUCTRL;
  105. timer_physaddr=SAU7_TIMER;
  106. break;
  107. default:
  108. panic("Undefined apollo model");
  109. break;
  110. }
  111. }
  112. int dn_serial_console_wait_key(struct console *co) {
  113. while(!(sio01.srb_csrb & 1))
  114. barrier();
  115. return sio01.rhrb_thrb;
  116. }
  117. void dn_serial_console_write (struct console *co, const char *str,unsigned int count)
  118. {
  119.    while(count--) {
  120. if (*str == 'n') { 
  121.      sio01.rhrb_thrb = (unsigned char)'r';
  122.         while (!(sio01.srb_csrb & 0x4))
  123.                 ;
  124.   }
  125.     sio01.rhrb_thrb = (unsigned char)*str++;
  126.     while (!(sio01.srb_csrb & 0x4))
  127.             ;
  128.   }
  129. }
  130.  
  131. void dn_serial_print (const char *str)
  132. {
  133.     while (*str) {
  134.         if (*str == 'n') {
  135.             sio01.rhrb_thrb = (unsigned char)'r';
  136.             while (!(sio01.srb_csrb & 0x4))
  137.                 ;
  138.         }
  139.         sio01.rhrb_thrb = (unsigned char)*str++;
  140.         while (!(sio01.srb_csrb & 0x4))
  141.             ;
  142.     }
  143. }
  144. void config_apollo(void) {
  145. int i;
  146. dn_setup_model();
  147. mach_sched_init=dn_sched_init; /* */
  148. #ifdef CONFIG_VT
  149. mach_keyb_init=dn_keyb_init;
  150. mach_kbdrate=dn_dummy_kbdrate;
  151. kd_mksound      = dn_mksound;
  152. #endif
  153. mach_init_IRQ=dn_init_IRQ;
  154. mach_default_handler=NULL;
  155. mach_request_irq     = dn_request_irq;
  156. mach_free_irq        = dn_free_irq;
  157. enable_irq      = dn_enable_irq;
  158. disable_irq     = dn_disable_irq;
  159. mach_get_irq_list    = dn_get_irq_list;
  160. mach_gettimeoffset   = dn_gettimeoffset;
  161. mach_gettod      = dn_gettod; /* */
  162. mach_max_dma_address = 0xffffffff;
  163. mach_hwclk           = dn_dummy_hwclk; /* */
  164. mach_set_clock_mmss  = dn_dummy_set_clock_mmss; /* */
  165. mach_process_int     = dn_process_int;
  166. #ifdef CONFIG_BLK_DEV_FD
  167. mach_floppy_init     = dn_dummy_floppy_init;
  168. mach_floppy_setup    = dn_dummy_floppy_setup;
  169. #endif
  170. mach_reset      = dn_dummy_reset;  /* */
  171. #ifdef CONFIG_DUMMY_CONSOLE
  172.         conswitchp           = &dummy_con;
  173. #endif
  174. #ifdef CONFIG_HEARTBEAT
  175.    mach_heartbeat = dn_heartbeat;
  176. #endif
  177. mach_get_model       = dn_get_model;
  178. cpuctrl=0xaa00;
  179. /* clear DMA translation table */
  180. for(i=0;i<0x400;i++) 
  181. addr_xlat_map[i]=0;
  182. }
  183. void dn_timer_int(int irq, void *dev_id, struct pt_regs *fp) {
  184. volatile unsigned char x;
  185. sched_timer_handler(irq,dev_id,fp);
  186. x=*(volatile unsigned char *)(timer+3);
  187. x=*(volatile unsigned char *)(timer+5);
  188. }
  189. void dn_sched_init(void (*timer_routine)(int, void *, struct pt_regs *)) {
  190. /* program timer 1 */       
  191. *(volatile unsigned char *)(timer+3)=0x01;
  192. *(volatile unsigned char *)(timer+1)=0x40;
  193. *(volatile unsigned char *)(timer+5)=0x09;
  194. *(volatile unsigned char *)(timer+7)=0xc4;
  195. /* enable IRQ of PIC B */
  196. *(volatile unsigned char *)(pica+1)&=(~8);
  197. #if 0
  198. printk("*(0x10803) %02xn",*(volatile unsigned char *)(timer+0x3));
  199. printk("*(0x10803) %02xn",*(volatile unsigned char *)(timer+0x3));
  200. #endif
  201. sched_timer_handler=timer_routine;
  202. request_irq(0,dn_timer_int,0,NULL,NULL);
  203. }
  204. unsigned long dn_gettimeoffset(void) {
  205. return 0xdeadbeef;
  206. }
  207. void dn_gettod(int *yearp, int *monp, int *dayp,
  208.        int *hourp, int *minp, int *secp) {
  209.   *yearp=rtc->year;
  210.   *monp=rtc->month;
  211.   *dayp=rtc->day_of_month;
  212.   *hourp=rtc->hours;
  213.   *minp=rtc->minute;
  214.   *secp=rtc->second;
  215. printk("gettod: %d %d %d %d %d %dn",*yearp,*monp,*dayp,*hourp,*minp,*secp);
  216. }
  217. int dn_dummy_hwclk(int op, struct rtc_time *t) {
  218.   if(!op) { /* read */
  219.     t->tm_sec=rtc->second;
  220.     t->tm_min=rtc->minute;
  221.     t->tm_hour=rtc->hours;
  222.     t->tm_mday=rtc->day_of_month;
  223.     t->tm_wday=rtc->day_of_week;
  224.     t->tm_mon=rtc->month;
  225.     t->tm_year=rtc->year;
  226.   } else {
  227.     rtc->second=t->tm_sec;
  228.     rtc->minute=t->tm_min;
  229.     rtc->hours=t->tm_hour;
  230.     rtc->day_of_month=t->tm_mday;
  231.     if(t->tm_wday!=-1)
  232.       rtc->day_of_week=t->tm_wday;
  233.     rtc->month=t->tm_mon;
  234.     rtc->year=t->tm_year;
  235.   }
  236.   return 0;
  237. }
  238. int dn_dummy_set_clock_mmss(unsigned long nowtime) {
  239.   printk("set_clock_mmssn");
  240.   return 0;
  241. }
  242. void dn_dummy_reset(void) {
  243.   dn_serial_print("The end !n");
  244.   for(;;);
  245. }
  246. void dn_dummy_waitbut(void) {
  247.   dn_serial_print("waitbutn");
  248. }
  249. static void dn_get_model(char *model)
  250. {
  251.     strcpy(model, "Apollo ");
  252.     if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
  253.         strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);
  254. }
  255. #ifdef CONFIG_HEARTBEAT
  256. static void dn_heartbeat(int on) {
  257. if(on) { 
  258. dn_cpuctrl&=~0x100;
  259. cpuctrl=dn_cpuctrl;
  260. }
  261. else {
  262. dn_cpuctrl&=~0x100;
  263. dn_cpuctrl|=0x100;
  264. cpuctrl=dn_cpuctrl;
  265. }
  266. }
  267. #endif