1 /*
2 * linux/arch/arm/mach-sa1100/sa1111.c
3 *
4 * SA1111 support
5 *
6 * Original code by John Dorsey
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This file contains all generic SA1111 support, except for DMA which is
13 * provided separately in dma-sa1111.c.
14 *
15 * All initialization functions provided here are intended to be called
16 * from machine specific code with proper arguments when required.
17 */
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/delay.h>
22 #include <linux/sched.h>
23 #include <linux/interrupt.h>
24 #include <linux/ptrace.h>
25 #include <linux/errno.h>
26 #include <linux/ioport.h>
27 #include <linux/list.h>
28 #include <linux/timer.h>
29
30 #include <asm/hardware.h>
31 #include <asm/irq.h>
32 #include <asm/mach/irq.h>
33 #include <asm/arch/irq.h>
34
35 #include <asm/hardware/sa1111.h>
36
37 #include "sa1111.h"
38
39 struct resource sa1111_resource = {
40 .name = "SA1111",
41 };
42
43 EXPORT_SYMBOL(sa1111_resource);
44
45 /*
46 * SA1111 interrupt support
47 */
sa1111_IRQ_demux(int irq,void * dev_id,struct pt_regs * regs)48 void sa1111_IRQ_demux(int irq, void *dev_id, struct pt_regs *regs)
49 {
50 unsigned long stat0, stat1;
51
52 while (1) {
53 int i;
54
55 stat0 = INTSTATCLR0;
56 stat1 = INTSTATCLR1;
57
58 if (stat0 == 0 && stat1 == 0)
59 break;
60
61 for (i = IRQ_SA1111_START; stat0; i++, stat0 >>= 1)
62 if (stat0 & 1)
63 do_IRQ(i, regs);
64
65 for (i = IRQ_SA1111_START + 32; stat1; i++, stat1 >>= 1)
66 if (stat1 & 1)
67 do_IRQ(i, regs);
68 }
69 }
70
71 #define SA1111_IRQMASK_LO(x) (1 << (x - IRQ_SA1111_START))
72 #define SA1111_IRQMASK_HI(x) (1 << (x - IRQ_SA1111_START - 32))
73
74 /*
75 * A note about masking IRQs:
76 *
77 * The GPIO IRQ edge detection only functions while the IRQ itself is
78 * enabled; edges are not detected while the IRQ is disabled.
79 *
80 * This is especially important for the PCMCIA signals, where we must
81 * pick up every transition. We therefore do not disable the IRQs
82 * while processing them.
83 *
84 * However, since we are changed to a GPIO on the host processor,
85 * all SA1111 IRQs will be disabled while we're processing any SA1111
86 * IRQ.
87 *
88 * Note also that changing INTPOL while an IRQ is enabled will itself
89 * trigger an IRQ.
90 */
sa1111_mask_and_ack_lowirq(unsigned int irq)91 static void sa1111_mask_and_ack_lowirq(unsigned int irq)
92 {
93 unsigned int mask = SA1111_IRQMASK_LO(irq);
94
95 //INTEN0 &= ~mask;
96 INTSTATCLR0 = mask;
97 }
98
sa1111_mask_and_ack_highirq(unsigned int irq)99 static void sa1111_mask_and_ack_highirq(unsigned int irq)
100 {
101 unsigned int mask = SA1111_IRQMASK_HI(irq);
102
103 //INTEN1 &= ~mask;
104 INTSTATCLR1 = mask;
105 }
106
sa1111_mask_lowirq(unsigned int irq)107 static void sa1111_mask_lowirq(unsigned int irq)
108 {
109 INTEN0 &= ~SA1111_IRQMASK_LO(irq);
110 }
111
sa1111_mask_highirq(unsigned int irq)112 static void sa1111_mask_highirq(unsigned int irq)
113 {
114 INTEN1 &= ~SA1111_IRQMASK_HI(irq);
115 }
116
sa1111_unmask_lowirq(unsigned int irq)117 static void sa1111_unmask_lowirq(unsigned int irq)
118 {
119 INTEN0 |= SA1111_IRQMASK_LO(irq);
120 }
121
sa1111_unmask_highirq(unsigned int irq)122 static void sa1111_unmask_highirq(unsigned int irq)
123 {
124 INTEN1 |= SA1111_IRQMASK_HI(irq);
125 }
126
sa1111_init_irq(int irq_nr)127 void __init sa1111_init_irq(int irq_nr)
128 {
129 int irq, ret;
130
131 request_mem_region(_INTTEST0, 512, "irqs");
132
133 /* disable all IRQs */
134 INTEN0 = 0;
135 INTEN1 = 0;
136
137 /*
138 * detect on rising edge. Note: Feb 2001 Errata for SA1111
139 * specifies that S0ReadyInt and S1ReadyInt should be '1'.
140 */
141 INTPOL0 = 0;
142 INTPOL1 = SA1111_IRQMASK_HI(S0_READY_NINT) |
143 SA1111_IRQMASK_HI(S1_READY_NINT);
144
145 /* clear all IRQs */
146 INTSTATCLR0 = -1;
147 INTSTATCLR1 = -1;
148
149 for (irq = IRQ_GPAIN0; irq <= SSPROR; irq++) {
150 irq_desc[irq].valid = 1;
151 irq_desc[irq].probe_ok = 0;
152 irq_desc[irq].mask_ack = sa1111_mask_and_ack_lowirq;
153 irq_desc[irq].mask = sa1111_mask_lowirq;
154 irq_desc[irq].unmask = sa1111_unmask_lowirq;
155 }
156 for (irq = AUDXMTDMADONEA; irq <= S1_BVD1_STSCHG; irq++) {
157 irq_desc[irq].valid = 1;
158 irq_desc[irq].probe_ok = 0;
159 irq_desc[irq].mask_ack = sa1111_mask_and_ack_highirq;
160 irq_desc[irq].mask = sa1111_mask_highirq;
161 irq_desc[irq].unmask = sa1111_unmask_highirq;
162 }
163
164 /* Register SA1111 interrupt */
165 if (irq_nr < 0)
166 return;
167
168 ret = request_irq(irq_nr, sa1111_IRQ_demux, SA_INTERRUPT,
169 "SA1111", NULL);
170 if (ret < 0)
171 printk(KERN_ERR "SA1111: unable to claim IRQ%d: %d\n",
172 irq_nr, ret);
173 }
174
175 /**
176 * sa1111_probe - probe for a single SA1111 chip.
177 * @phys_addr: physical address of device.
178 *
179 * Probe for a SA1111 chip. This must be called
180 * before any other SA1111-specific code.
181 *
182 * Returns:
183 * %-ENODEV device not found.
184 * %-EBUSY physical address already marked in-use.
185 * %0 successful.
186 */
sa1111_probe(unsigned long phys_addr)187 int __init sa1111_probe(unsigned long phys_addr)
188 {
189 unsigned long id;
190 int ret = -ENODEV;
191
192 sa1111_resource.start = phys_addr;
193 sa1111_resource.end = phys_addr + 0x2000;
194
195 if (request_resource(&iomem_resource, &sa1111_resource)) {
196 ret = -EBUSY;
197 goto out;
198 }
199
200 /*
201 * Probe for the chip. Only touch the SBI registers.
202 */
203 id = SBI_SKID;
204 if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
205 printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id);
206 ret = -ENODEV;
207 goto release;
208 }
209
210 printk(KERN_INFO "SA1111 Microprocessor Companion Chip: "
211 "silicon revision %lx, metal revision %lx\n",
212 (id & SKID_SIREV_MASK)>>4, (id & SKID_MTREV_MASK));
213
214 return 0;
215
216 release:
217 release_resource(&sa1111_resource);
218 out:
219 return ret;
220 }
221
222 /*
223 * Bring the SA1111 out of reset. This requires a set procedure:
224 * 1. nRESET asserted (by hardware)
225 * 2. CLK turned on from SA1110
226 * 3. nRESET deasserted
227 * 4. VCO turned on, PLL_BYPASS turned off
228 * 5. Wait lock time, then assert RCLKEn
229 * 7. PCR set to allow clocking of individual functions
230 *
231 * Until we've done this, the only registers we can access are:
232 * SBI_SKCR
233 * SBI_SMCR
234 * SBI_SKID
235 */
sa1111_wake(void)236 void sa1111_wake(void)
237 {
238 unsigned long flags;
239
240 local_irq_save(flags);
241
242 /*
243 * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
244 * (SA-1110 Developer's Manual, section 9.1.2.1)
245 */
246 GAFR |= GPIO_32_768kHz;
247 GPDR |= GPIO_32_768kHz;
248 TUCR = TUCR_3_6864MHz;
249
250 /*
251 * Turn VCO on, and disable PLL Bypass.
252 */
253 SBI_SKCR &= ~SKCR_VCO_OFF;
254 SBI_SKCR |= SKCR_PLL_BYPASS | SKCR_OE_EN;
255
256 /*
257 * Wait lock time. SA1111 manual _doesn't_
258 * specify a figure for this! We choose 100us.
259 */
260 udelay(100);
261
262 /*
263 * Enable RCLK. We also ensure that RDYEN is set.
264 */
265 SBI_SKCR |= SKCR_RCLKEN | SKCR_RDYEN;
266
267 /*
268 * Wait 14 RCLK cycles for the chip to finish coming out
269 * of reset. (RCLK=24MHz). This is 590ns.
270 */
271 udelay(1);
272
273 /*
274 * Ensure all clocks are initially off.
275 */
276 SKPCR = 0;
277
278 local_irq_restore(flags);
279 }
280
sa1111_doze(void)281 void sa1111_doze(void)
282 {
283 if (SKPCR & SKPCR_UCLKEN) {
284 printk("SA1111 doze mode refused\n");
285 return;
286 }
287 SBI_SKCR &= ~SKCR_RCLKEN;
288 }
289
290 /*
291 * Configure the SA1111 shared memory controller.
292 */
sa1111_configure_smc(int sdram,unsigned int drac,unsigned int cas_latency)293 void sa1111_configure_smc(int sdram, unsigned int drac, unsigned int cas_latency)
294 {
295 unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC);
296
297 if (cas_latency == 3)
298 smcr |= SMCR_CLAT;
299
300 SBI_SMCR = smcr;
301 }
302
303 /*
304 * Disable the memory bus request/grant signals on the SA1110 to
305 * ensure that we don't receive spurious memory requests. We set
306 * the MBGNT signal false to ensure the SA1111 doesn't own the
307 * SDRAM bus.
308 */
sa1110_mb_disable(void)309 void __init sa1110_mb_disable(void)
310 {
311 unsigned long flags;
312
313 local_irq_save(flags);
314
315 PGSR &= ~GPIO_MBGNT;
316 GPCR = GPIO_MBGNT;
317 GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
318
319 GAFR &= ~(GPIO_MBGNT | GPIO_MBREQ);
320
321 local_irq_restore(flags);
322 }
323
324 /*
325 * If the system is going to use the SA-1111 DMA engines, set up
326 * the memory bus request/grant pins.
327 */
sa1110_mb_enable(void)328 void __init sa1110_mb_enable(void)
329 {
330 unsigned long flags;
331
332 local_irq_save(flags);
333
334 PGSR &= ~GPIO_MBGNT;
335 GPCR = GPIO_MBGNT;
336 GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
337
338 GAFR |= (GPIO_MBGNT | GPIO_MBREQ);
339 TUCR |= TUCR_MR;
340
341 local_irq_restore(flags);
342 }
343
344 EXPORT_SYMBOL(sa1111_wake);
345 EXPORT_SYMBOL(sa1111_doze);
346