blob: 2b3196af811f3b92ee9b20e532a7d46acbb91310 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68knommu/platform/68360/config.c
3 *
4 * Copyright (c) 2000 Michael Leslie <mleslie@lineo.com>
5 * Copyright (C) 1993 Hamish Macdonald
6 * Copyright (C) 1999 D. Jeff Dionne <jeff@uclinux.org>
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/mm.h>
Greg Ungererb032fde2007-03-07 11:28:13 +100017#include <linux/interrupt.h>
Greg Ungereraa1f1d12007-07-27 01:09:00 +100018#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/setup.h>
21#include <asm/system.h>
22#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/machdep.h>
24#include <asm/m68360.h>
25
26#ifdef CONFIG_UCQUICC
27#include <asm/bootstd.h>
28#endif
29
30extern void m360_cpm_reset(void);
31
32// Mask to select if the PLL prescaler is enabled.
33#define MCU_PREEN ((unsigned short)(0x0001 << 13))
34
35#if defined(CONFIG_UCQUICC)
36#define OSCILLATOR (unsigned long int)33000000
37#endif
38
39unsigned long int system_clock;
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041extern 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;
46extern unsigned long int system_clock; //In kernel setup.c
47
Greg Ungerer7e6a3d42007-10-24 12:03:25 +100048
49static 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 arch_timer_interrupt(irq, dummy);
57}
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Greg Ungereraa1f1d12007-07-27 01:09:00 +100059static struct irqaction m68360_timer_irq = {
Greg Ungerer7e6a3d42007-10-24 12:03:25 +100060 .name = "timer",
61 .flags = IRQF_DISABLED | IRQF_TIMER,
62 .handler = hw_tick,
Greg Ungereraa1f1d12007-07-27 01:09:00 +100063};
64
Greg Ungerer7e6a3d42007-10-24 12:03:25 +100065void hw_timer_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 unsigned char prescaler;
68 unsigned short tgcr_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#if 0
71 /* Restart mode, Enable int, 32KHz, Enable timer */
72 TCTL = TCTL_OM | TCTL_IRQEN | TCTL_CLKSOURCE_32KHZ | TCTL_TEN;
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, IRQ_FLG_LOCK, "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 /* enable timer 1 interrupt in CIMR */
Greg Ungereraa1f1d12007-07-27 01:09:00 +100099 setup_irq(CPMVEC_TIMER1, &m68360_timer_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 /* Start timer 1: */
102 tgcr_save = (pquicc->timer_tgcr & 0xfff0) | 0x0001;
103 pquicc->timer_tgcr = tgcr_save;
104}
105
Greg Ungerer7e6a3d42007-10-24 12:03:25 +1000106unsigned long hw_timer_offset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 return 0;
109}
110
111void BSP_gettod (int *yearp, int *monp, int *dayp,
112 int *hourp, int *minp, int *secp)
113{
114}
115
Greg Ungerer7e6a3d42007-10-24 12:03:25 +1000116int BSP_set_clock_mmss(unsigned long nowtime)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118#if 0
119 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
120
121 tod->second1 = real_seconds / 10;
122 tod->second2 = real_seconds % 10;
123 tod->minute1 = real_minutes / 10;
124 tod->minute2 = real_minutes % 10;
125#endif
126 return 0;
127}
128
129void BSP_reset (void)
130{
131 local_irq_disable();
Greg Ungererbda65832006-06-28 16:21:38 +1000132 asm volatile (
133 "moveal #_start, %a0;\n"
134 "moveb #0, 0xFFFFF300;\n"
135 "moveal 0(%a0), %sp;\n"
136 "moveal 4(%a0), %a0;\n"
137 "jmp (%a0);\n"
138 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
141unsigned char *scc1_hwaddr;
142static int errno;
143
144#if defined (CONFIG_UCQUICC)
145_bsc0(char *, getserialnum)
146_bsc1(unsigned char *, gethwaddr, int, a)
147_bsc1(char *, getbenv, char *, a)
148#endif
149
150
151void config_BSP(char *command, int len)
152{
153 unsigned char *p;
154
155 m360_cpm_reset();
156
157 /* Calculate the real system clock value. */
158 {
159 unsigned int local_pllcr = (unsigned int)(pquicc->sim_pllcr);
160 if( local_pllcr & MCU_PREEN ) // If the prescaler is dividing by 128
161 {
162 int mf = (int)(pquicc->sim_pllcr & 0x0fff);
163 system_clock = (OSCILLATOR / 128) * (mf + 1);
164 }
165 else
166 {
167 int mf = (int)(pquicc->sim_pllcr & 0x0fff);
168 system_clock = (OSCILLATOR) * (mf + 1);
169 }
170 }
171
172 printk(KERN_INFO "\n68360 QUICC support (C) 2000 Lineo Inc.\n");
173
174#if defined(CONFIG_UCQUICC) && 0
175 printk(KERN_INFO "uCquicc serial string [%s]\n",getserialnum());
176 p = scc1_hwaddr = gethwaddr(0);
177 printk(KERN_INFO "uCquicc hwaddr %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
178 p[0], p[1], p[2], p[3], p[4], p[5]);
179
180 p = getbenv("APPEND");
181 if (p)
182 strcpy(p,command);
183 else
184 command[0] = 0;
185#else
186 scc1_hwaddr = "\00\01\02\03\04\05";
187#endif
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 mach_gettod = BSP_gettod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 mach_reset = BSP_reset;
191}