Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
config.c
Go to the documentation of this file.
1 /*
2  * linux/arch/m68knommu/platform/68360/config.c
3  *
4  * Copyright (c) 2000 Michael Leslie <[email protected]>
5  * Copyright (C) 1993 Hamish Macdonald
6  * Copyright (C) 1999 D. Jeff Dionne <[email protected]>
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License. See the file COPYING in the main directory of this archive
10  * for more details.
11  */
12 
13 #include <stdarg.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/mm.h>
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
19 
20 #include <asm/setup.h>
21 #include <asm/pgtable.h>
22 #include <asm/machdep.h>
23 #include <asm/m68360.h>
24 
25 #ifdef CONFIG_UCQUICC
26 #include <asm/bootstd.h>
27 #endif
28 
29 extern void m360_cpm_reset(void);
30 
31 // Mask to select if the PLL prescaler is enabled.
32 #define MCU_PREEN ((unsigned short)(0x0001 << 13))
33 
34 #if defined(CONFIG_UCQUICC)
35 #define OSCILLATOR (unsigned long int)33000000
36 #endif
37 
38 static irq_handler_t timer_interrupt;
39 unsigned long int system_clock;
40 
41 extern QUICC *pquicc;
42 
43 /* TODO DON"T Hard Code this */
44 /* calculate properly using the right PLL and prescaller */
45 // unsigned int system_clock = 33000000l;
46 extern unsigned long int system_clock; //In kernel setup.c
47 
48 
49 static irqreturn_t hw_tick(int irq, void *dummy)
50 {
51  /* Reset Timer1 */
52  /* TSTAT &= 0; */
53 
54  pquicc->timer_ter1 = 0x0002; /* clear timer event */
55 
56  return timer_interrupt(irq, dummy);
57 }
58 
59 static struct irqaction m68360_timer_irq = {
60  .name = "timer",
61  .flags = IRQF_DISABLED | IRQF_TIMER,
62  .handler = hw_tick,
63 };
64 
66 {
67  unsigned char prescaler;
68  unsigned short tgcr_save;
69 
70 #if 0
71  /* Restart mode, Enable int, 32KHz, Enable timer */
73  /* Set prescaler (Divide 32KHz by 32)*/
74  TPRER = 31;
75  /* Set compare register 32Khz / 32 / 10 = 100 */
76  TCMP = 10;
77 
78  request_irq(IRQ_MACHSPEC | 1, timer_routine, 0, "timer", NULL);
79 #endif
80 
81  /* General purpose quicc timers: MC68360UM p7-20 */
82 
83  /* Set up timer 1 (in [1..4]) to do 100Hz */
84  tgcr_save = pquicc->timer_tgcr & 0xfff0;
85  pquicc->timer_tgcr = tgcr_save; /* stop and reset timer 1 */
86  /* pquicc->timer_tgcr |= 0x4444; */ /* halt timers when FREEZE (ie bdm freeze) */
87 
88  prescaler = 8;
89  pquicc->timer_tmr1 = 0x001a | /* or=1, frr=1, iclk=01b */
90  (unsigned short)((prescaler - 1) << 8);
91 
92  pquicc->timer_tcn1 = 0x0000; /* initial count */
93  /* calculate interval for 100Hz based on the _system_clock: */
94  pquicc->timer_trr1 = (system_clock/ prescaler) / HZ; /* reference count */
95 
96  pquicc->timer_ter1 = 0x0003; /* clear timer events */
97 
98  timer_interrupt = handler;
99 
100  /* enable timer 1 interrupt in CIMR */
101  setup_irq(CPMVEC_TIMER1, &m68360_timer_irq);
102 
103  /* Start timer 1: */
104  tgcr_save = (pquicc->timer_tgcr & 0xfff0) | 0x0001;
105  pquicc->timer_tgcr = tgcr_save;
106 }
107 
108 int BSP_set_clock_mmss(unsigned long nowtime)
109 {
110 #if 0
111  short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
112 
113  tod->second1 = real_seconds / 10;
114  tod->second2 = real_seconds % 10;
115  tod->minute1 = real_minutes / 10;
116  tod->minute2 = real_minutes % 10;
117 #endif
118  return 0;
119 }
120 
121 void BSP_reset (void)
122 {
124  asm volatile (
125  "moveal #_start, %a0;\n"
126  "moveb #0, 0xFFFFF300;\n"
127  "moveal 0(%a0), %sp;\n"
128  "moveal 4(%a0), %a0;\n"
129  "jmp (%a0);\n"
130  );
131 }
132 
133 unsigned char *scc1_hwaddr;
134 static int errno;
135 
136 #if defined (CONFIG_UCQUICC)
137 _bsc0(char *, getserialnum)
138 _bsc1(unsigned char *, gethwaddr, int, a)
139 _bsc1(char *, getbenv, char *, a)
140 #endif
141 
142 
143 void config_BSP(char *command, int len)
144 {
145  unsigned char *p;
146 
147  m360_cpm_reset();
148 
149  /* Calculate the real system clock value. */
150  {
151  unsigned int local_pllcr = (unsigned int)(pquicc->sim_pllcr);
152  if( local_pllcr & MCU_PREEN ) // If the prescaler is dividing by 128
153  {
154  int mf = (int)(pquicc->sim_pllcr & 0x0fff);
155  system_clock = (OSCILLATOR / 128) * (mf + 1);
156  }
157  else
158  {
159  int mf = (int)(pquicc->sim_pllcr & 0x0fff);
160  system_clock = (OSCILLATOR) * (mf + 1);
161  }
162  }
163 
164  printk(KERN_INFO "\n68360 QUICC support (C) 2000 Lineo Inc.\n");
165 
166 #if defined(CONFIG_UCQUICC) && 0
167  printk(KERN_INFO "uCquicc serial string [%s]\n",getserialnum());
168  p = scc1_hwaddr = gethwaddr(0);
169  printk(KERN_INFO "uCquicc hwaddr %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
170  p[0], p[1], p[2], p[3], p[4], p[5]);
171 
172  p = getbenv("APPEND");
173  if (p)
174  strcpy(p,command);
175  else
176  command[0] = 0;
177 #else
178  scc1_hwaddr = "\00\01\02\03\04\05";
179 #endif
180 
182 }