Loading...
1/*
2 * Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au)
3 * Ben. Herrenschmidt (benh@kernel.crashing.org)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 *
10 * TODO:
11 *
12 * - Replace mdelay with some schedule loop if possible
13 * - Shorten some obfuscated delays on some routines (like modem
14 * power)
15 * - Refcount some clocks (see darwin)
16 * - Split split split...
17 *
18 */
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/kernel.h>
23#include <linux/sched.h>
24#include <linux/of.h>
25#include <linux/of_address.h>
26#include <linux/spinlock.h>
27#include <linux/adb.h>
28#include <linux/pmu.h>
29#include <linux/ioport.h>
30#include <linux/export.h>
31#include <linux/pci.h>
32#include <asm/sections.h>
33#include <asm/errno.h>
34#include <asm/ohare.h>
35#include <asm/heathrow.h>
36#include <asm/keylargo.h>
37#include <asm/uninorth.h>
38#include <asm/io.h>
39#include <asm/prom.h>
40#include <asm/machdep.h>
41#include <asm/pmac_feature.h>
42#include <asm/dbdma.h>
43#include <asm/pci-bridge.h>
44#include <asm/pmac_low_i2c.h>
45
46#undef DEBUG_FEATURE
47
48#ifdef DEBUG_FEATURE
49#define DBG(fmt...) printk(KERN_DEBUG fmt)
50#else
51#define DBG(fmt...)
52#endif
53
54#ifdef CONFIG_6xx
55extern int powersave_lowspeed;
56#endif
57
58extern int powersave_nap;
59extern struct device_node *k2_skiplist[2];
60
61/*
62 * We use a single global lock to protect accesses. Each driver has
63 * to take care of its own locking
64 */
65DEFINE_RAW_SPINLOCK(feature_lock);
66
67#define LOCK(flags) raw_spin_lock_irqsave(&feature_lock, flags);
68#define UNLOCK(flags) raw_spin_unlock_irqrestore(&feature_lock, flags);
69
70
71/*
72 * Instance of some macio stuffs
73 */
74struct macio_chip macio_chips[MAX_MACIO_CHIPS];
75
76struct macio_chip *macio_find(struct device_node *child, int type)
77{
78 while(child) {
79 int i;
80
81 for (i=0; i < MAX_MACIO_CHIPS && macio_chips[i].of_node; i++)
82 if (child == macio_chips[i].of_node &&
83 (!type || macio_chips[i].type == type))
84 return &macio_chips[i];
85 child = child->parent;
86 }
87 return NULL;
88}
89EXPORT_SYMBOL_GPL(macio_find);
90
91static const char *macio_names[] =
92{
93 "Unknown",
94 "Grand Central",
95 "OHare",
96 "OHareII",
97 "Heathrow",
98 "Gatwick",
99 "Paddington",
100 "Keylargo",
101 "Pangea",
102 "Intrepid",
103 "K2",
104 "Shasta",
105};
106
107
108struct device_node *uninorth_node;
109u32 __iomem *uninorth_base;
110
111static u32 uninorth_rev;
112static int uninorth_maj;
113static void __iomem *u3_ht_base;
114
115/*
116 * For each motherboard family, we have a table of functions pointers
117 * that handle the various features.
118 */
119
120typedef long (*feature_call)(struct device_node *node, long param, long value);
121
122struct feature_table_entry {
123 unsigned int selector;
124 feature_call function;
125};
126
127struct pmac_mb_def
128{
129 const char* model_string;
130 const char* model_name;
131 int model_id;
132 struct feature_table_entry* features;
133 unsigned long board_flags;
134};
135static struct pmac_mb_def pmac_mb;
136
137/*
138 * Here are the chip specific feature functions
139 */
140
141static inline int simple_feature_tweak(struct device_node *node, int type,
142 int reg, u32 mask, int value)
143{
144 struct macio_chip* macio;
145 unsigned long flags;
146
147 macio = macio_find(node, type);
148 if (!macio)
149 return -ENODEV;
150 LOCK(flags);
151 if (value)
152 MACIO_BIS(reg, mask);
153 else
154 MACIO_BIC(reg, mask);
155 (void)MACIO_IN32(reg);
156 UNLOCK(flags);
157
158 return 0;
159}
160
161#ifndef CONFIG_POWER4
162
163static long ohare_htw_scc_enable(struct device_node *node, long param,
164 long value)
165{
166 struct macio_chip* macio;
167 unsigned long chan_mask;
168 unsigned long fcr;
169 unsigned long flags;
170 int htw, trans;
171 unsigned long rmask;
172
173 macio = macio_find(node, 0);
174 if (!macio)
175 return -ENODEV;
176 if (!strcmp(node->name, "ch-a"))
177 chan_mask = MACIO_FLAG_SCCA_ON;
178 else if (!strcmp(node->name, "ch-b"))
179 chan_mask = MACIO_FLAG_SCCB_ON;
180 else
181 return -ENODEV;
182
183 htw = (macio->type == macio_heathrow || macio->type == macio_paddington
184 || macio->type == macio_gatwick);
185 /* On these machines, the HRW_SCC_TRANS_EN_N bit mustn't be touched */
186 trans = (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
187 pmac_mb.model_id != PMAC_TYPE_YIKES);
188 if (value) {
189#ifdef CONFIG_ADB_PMU
190 if ((param & 0xfff) == PMAC_SCC_IRDA)
191 pmu_enable_irled(1);
192#endif /* CONFIG_ADB_PMU */
193 LOCK(flags);
194 fcr = MACIO_IN32(OHARE_FCR);
195 /* Check if scc cell need enabling */
196 if (!(fcr & OH_SCC_ENABLE)) {
197 fcr |= OH_SCC_ENABLE;
198 if (htw) {
199 /* Side effect: this will also power up the
200 * modem, but it's too messy to figure out on which
201 * ports this controls the tranceiver and on which
202 * it controls the modem
203 */
204 if (trans)
205 fcr &= ~HRW_SCC_TRANS_EN_N;
206 MACIO_OUT32(OHARE_FCR, fcr);
207 fcr |= (rmask = HRW_RESET_SCC);
208 MACIO_OUT32(OHARE_FCR, fcr);
209 } else {
210 fcr |= (rmask = OH_SCC_RESET);
211 MACIO_OUT32(OHARE_FCR, fcr);
212 }
213 UNLOCK(flags);
214 (void)MACIO_IN32(OHARE_FCR);
215 mdelay(15);
216 LOCK(flags);
217 fcr &= ~rmask;
218 MACIO_OUT32(OHARE_FCR, fcr);
219 }
220 if (chan_mask & MACIO_FLAG_SCCA_ON)
221 fcr |= OH_SCCA_IO;
222 if (chan_mask & MACIO_FLAG_SCCB_ON)
223 fcr |= OH_SCCB_IO;
224 MACIO_OUT32(OHARE_FCR, fcr);
225 macio->flags |= chan_mask;
226 UNLOCK(flags);
227 if (param & PMAC_SCC_FLAG_XMON)
228 macio->flags |= MACIO_FLAG_SCC_LOCKED;
229 } else {
230 if (macio->flags & MACIO_FLAG_SCC_LOCKED)
231 return -EPERM;
232 LOCK(flags);
233 fcr = MACIO_IN32(OHARE_FCR);
234 if (chan_mask & MACIO_FLAG_SCCA_ON)
235 fcr &= ~OH_SCCA_IO;
236 if (chan_mask & MACIO_FLAG_SCCB_ON)
237 fcr &= ~OH_SCCB_IO;
238 MACIO_OUT32(OHARE_FCR, fcr);
239 if ((fcr & (OH_SCCA_IO | OH_SCCB_IO)) == 0) {
240 fcr &= ~OH_SCC_ENABLE;
241 if (htw && trans)
242 fcr |= HRW_SCC_TRANS_EN_N;
243 MACIO_OUT32(OHARE_FCR, fcr);
244 }
245 macio->flags &= ~(chan_mask);
246 UNLOCK(flags);
247 mdelay(10);
248#ifdef CONFIG_ADB_PMU
249 if ((param & 0xfff) == PMAC_SCC_IRDA)
250 pmu_enable_irled(0);
251#endif /* CONFIG_ADB_PMU */
252 }
253 return 0;
254}
255
256static long ohare_floppy_enable(struct device_node *node, long param,
257 long value)
258{
259 return simple_feature_tweak(node, macio_ohare,
260 OHARE_FCR, OH_FLOPPY_ENABLE, value);
261}
262
263static long ohare_mesh_enable(struct device_node *node, long param, long value)
264{
265 return simple_feature_tweak(node, macio_ohare,
266 OHARE_FCR, OH_MESH_ENABLE, value);
267}
268
269static long ohare_ide_enable(struct device_node *node, long param, long value)
270{
271 switch(param) {
272 case 0:
273 /* For some reason, setting the bit in set_initial_features()
274 * doesn't stick. I'm still investigating... --BenH.
275 */
276 if (value)
277 simple_feature_tweak(node, macio_ohare,
278 OHARE_FCR, OH_IOBUS_ENABLE, 1);
279 return simple_feature_tweak(node, macio_ohare,
280 OHARE_FCR, OH_IDE0_ENABLE, value);
281 case 1:
282 return simple_feature_tweak(node, macio_ohare,
283 OHARE_FCR, OH_BAY_IDE_ENABLE, value);
284 default:
285 return -ENODEV;
286 }
287}
288
289static long ohare_ide_reset(struct device_node *node, long param, long value)
290{
291 switch(param) {
292 case 0:
293 return simple_feature_tweak(node, macio_ohare,
294 OHARE_FCR, OH_IDE0_RESET_N, !value);
295 case 1:
296 return simple_feature_tweak(node, macio_ohare,
297 OHARE_FCR, OH_IDE1_RESET_N, !value);
298 default:
299 return -ENODEV;
300 }
301}
302
303static long ohare_sleep_state(struct device_node *node, long param, long value)
304{
305 struct macio_chip* macio = &macio_chips[0];
306
307 if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
308 return -EPERM;
309 if (value == 1) {
310 MACIO_BIC(OHARE_FCR, OH_IOBUS_ENABLE);
311 } else if (value == 0) {
312 MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
313 }
314
315 return 0;
316}
317
318static long heathrow_modem_enable(struct device_node *node, long param,
319 long value)
320{
321 struct macio_chip* macio;
322 u8 gpio;
323 unsigned long flags;
324
325 macio = macio_find(node, macio_unknown);
326 if (!macio)
327 return -ENODEV;
328 gpio = MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1;
329 if (!value) {
330 LOCK(flags);
331 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
332 UNLOCK(flags);
333 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
334 mdelay(250);
335 }
336 if (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
337 pmac_mb.model_id != PMAC_TYPE_YIKES) {
338 LOCK(flags);
339 if (value)
340 MACIO_BIC(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
341 else
342 MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
343 UNLOCK(flags);
344 (void)MACIO_IN32(HEATHROW_FCR);
345 mdelay(250);
346 }
347 if (value) {
348 LOCK(flags);
349 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
350 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
351 UNLOCK(flags); mdelay(250); LOCK(flags);
352 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
353 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
354 UNLOCK(flags); mdelay(250); LOCK(flags);
355 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
356 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
357 UNLOCK(flags); mdelay(250);
358 }
359 return 0;
360}
361
362static long heathrow_floppy_enable(struct device_node *node, long param,
363 long value)
364{
365 return simple_feature_tweak(node, macio_unknown,
366 HEATHROW_FCR,
367 HRW_SWIM_ENABLE|HRW_BAY_FLOPPY_ENABLE,
368 value);
369}
370
371static long heathrow_mesh_enable(struct device_node *node, long param,
372 long value)
373{
374 struct macio_chip* macio;
375 unsigned long flags;
376
377 macio = macio_find(node, macio_unknown);
378 if (!macio)
379 return -ENODEV;
380 LOCK(flags);
381 /* Set clear mesh cell enable */
382 if (value)
383 MACIO_BIS(HEATHROW_FCR, HRW_MESH_ENABLE);
384 else
385 MACIO_BIC(HEATHROW_FCR, HRW_MESH_ENABLE);
386 (void)MACIO_IN32(HEATHROW_FCR);
387 udelay(10);
388 /* Set/Clear termination power */
389 if (value)
390 MACIO_BIC(HEATHROW_MBCR, 0x04000000);
391 else
392 MACIO_BIS(HEATHROW_MBCR, 0x04000000);
393 (void)MACIO_IN32(HEATHROW_MBCR);
394 udelay(10);
395 UNLOCK(flags);
396
397 return 0;
398}
399
400static long heathrow_ide_enable(struct device_node *node, long param,
401 long value)
402{
403 switch(param) {
404 case 0:
405 return simple_feature_tweak(node, macio_unknown,
406 HEATHROW_FCR, HRW_IDE0_ENABLE, value);
407 case 1:
408 return simple_feature_tweak(node, macio_unknown,
409 HEATHROW_FCR, HRW_BAY_IDE_ENABLE, value);
410 default:
411 return -ENODEV;
412 }
413}
414
415static long heathrow_ide_reset(struct device_node *node, long param,
416 long value)
417{
418 switch(param) {
419 case 0:
420 return simple_feature_tweak(node, macio_unknown,
421 HEATHROW_FCR, HRW_IDE0_RESET_N, !value);
422 case 1:
423 return simple_feature_tweak(node, macio_unknown,
424 HEATHROW_FCR, HRW_IDE1_RESET_N, !value);
425 default:
426 return -ENODEV;
427 }
428}
429
430static long heathrow_bmac_enable(struct device_node *node, long param,
431 long value)
432{
433 struct macio_chip* macio;
434 unsigned long flags;
435
436 macio = macio_find(node, 0);
437 if (!macio)
438 return -ENODEV;
439 if (value) {
440 LOCK(flags);
441 MACIO_BIS(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
442 MACIO_BIS(HEATHROW_FCR, HRW_BMAC_RESET);
443 UNLOCK(flags);
444 (void)MACIO_IN32(HEATHROW_FCR);
445 mdelay(10);
446 LOCK(flags);
447 MACIO_BIC(HEATHROW_FCR, HRW_BMAC_RESET);
448 UNLOCK(flags);
449 (void)MACIO_IN32(HEATHROW_FCR);
450 mdelay(10);
451 } else {
452 LOCK(flags);
453 MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
454 UNLOCK(flags);
455 }
456 return 0;
457}
458
459static long heathrow_sound_enable(struct device_node *node, long param,
460 long value)
461{
462 struct macio_chip* macio;
463 unsigned long flags;
464
465 /* B&W G3 and Yikes don't support that properly (the
466 * sound appear to never come back after beeing shut down).
467 */
468 if (pmac_mb.model_id == PMAC_TYPE_YOSEMITE ||
469 pmac_mb.model_id == PMAC_TYPE_YIKES)
470 return 0;
471
472 macio = macio_find(node, 0);
473 if (!macio)
474 return -ENODEV;
475 if (value) {
476 LOCK(flags);
477 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
478 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
479 UNLOCK(flags);
480 (void)MACIO_IN32(HEATHROW_FCR);
481 } else {
482 LOCK(flags);
483 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
484 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
485 UNLOCK(flags);
486 }
487 return 0;
488}
489
490static u32 save_fcr[6];
491static u32 save_mbcr;
492static struct dbdma_regs save_dbdma[13];
493static struct dbdma_regs save_alt_dbdma[13];
494
495static void dbdma_save(struct macio_chip *macio, struct dbdma_regs *save)
496{
497 int i;
498
499 /* Save state & config of DBDMA channels */
500 for (i = 0; i < 13; i++) {
501 volatile struct dbdma_regs __iomem * chan = (void __iomem *)
502 (macio->base + ((0x8000+i*0x100)>>2));
503 save[i].cmdptr_hi = in_le32(&chan->cmdptr_hi);
504 save[i].cmdptr = in_le32(&chan->cmdptr);
505 save[i].intr_sel = in_le32(&chan->intr_sel);
506 save[i].br_sel = in_le32(&chan->br_sel);
507 save[i].wait_sel = in_le32(&chan->wait_sel);
508 }
509}
510
511static void dbdma_restore(struct macio_chip *macio, struct dbdma_regs *save)
512{
513 int i;
514
515 /* Save state & config of DBDMA channels */
516 for (i = 0; i < 13; i++) {
517 volatile struct dbdma_regs __iomem * chan = (void __iomem *)
518 (macio->base + ((0x8000+i*0x100)>>2));
519 out_le32(&chan->control, (ACTIVE|DEAD|WAKE|FLUSH|PAUSE|RUN)<<16);
520 while (in_le32(&chan->status) & ACTIVE)
521 mb();
522 out_le32(&chan->cmdptr_hi, save[i].cmdptr_hi);
523 out_le32(&chan->cmdptr, save[i].cmdptr);
524 out_le32(&chan->intr_sel, save[i].intr_sel);
525 out_le32(&chan->br_sel, save[i].br_sel);
526 out_le32(&chan->wait_sel, save[i].wait_sel);
527 }
528}
529
530static void heathrow_sleep(struct macio_chip *macio, int secondary)
531{
532 if (secondary) {
533 dbdma_save(macio, save_alt_dbdma);
534 save_fcr[2] = MACIO_IN32(0x38);
535 save_fcr[3] = MACIO_IN32(0x3c);
536 } else {
537 dbdma_save(macio, save_dbdma);
538 save_fcr[0] = MACIO_IN32(0x38);
539 save_fcr[1] = MACIO_IN32(0x3c);
540 save_mbcr = MACIO_IN32(0x34);
541 /* Make sure sound is shut down */
542 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
543 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
544 /* This seems to be necessary as well or the fan
545 * keeps coming up and battery drains fast */
546 MACIO_BIC(HEATHROW_FCR, HRW_IOBUS_ENABLE);
547 MACIO_BIC(HEATHROW_FCR, HRW_IDE0_RESET_N);
548 /* Make sure eth is down even if module or sleep
549 * won't work properly */
550 MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE | HRW_BMAC_RESET);
551 }
552 /* Make sure modem is shut down */
553 MACIO_OUT8(HRW_GPIO_MODEM_RESET,
554 MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1);
555 MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
556 MACIO_BIC(HEATHROW_FCR, OH_SCCA_IO|OH_SCCB_IO|HRW_SCC_ENABLE);
557
558 /* Let things settle */
559 (void)MACIO_IN32(HEATHROW_FCR);
560}
561
562static void heathrow_wakeup(struct macio_chip *macio, int secondary)
563{
564 if (secondary) {
565 MACIO_OUT32(0x38, save_fcr[2]);
566 (void)MACIO_IN32(0x38);
567 mdelay(1);
568 MACIO_OUT32(0x3c, save_fcr[3]);
569 (void)MACIO_IN32(0x38);
570 mdelay(10);
571 dbdma_restore(macio, save_alt_dbdma);
572 } else {
573 MACIO_OUT32(0x38, save_fcr[0] | HRW_IOBUS_ENABLE);
574 (void)MACIO_IN32(0x38);
575 mdelay(1);
576 MACIO_OUT32(0x3c, save_fcr[1]);
577 (void)MACIO_IN32(0x38);
578 mdelay(1);
579 MACIO_OUT32(0x34, save_mbcr);
580 (void)MACIO_IN32(0x38);
581 mdelay(10);
582 dbdma_restore(macio, save_dbdma);
583 }
584}
585
586static long heathrow_sleep_state(struct device_node *node, long param,
587 long value)
588{
589 if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
590 return -EPERM;
591 if (value == 1) {
592 if (macio_chips[1].type == macio_gatwick)
593 heathrow_sleep(&macio_chips[0], 1);
594 heathrow_sleep(&macio_chips[0], 0);
595 } else if (value == 0) {
596 heathrow_wakeup(&macio_chips[0], 0);
597 if (macio_chips[1].type == macio_gatwick)
598 heathrow_wakeup(&macio_chips[0], 1);
599 }
600 return 0;
601}
602
603static long core99_scc_enable(struct device_node *node, long param, long value)
604{
605 struct macio_chip* macio;
606 unsigned long flags;
607 unsigned long chan_mask;
608 u32 fcr;
609
610 macio = macio_find(node, 0);
611 if (!macio)
612 return -ENODEV;
613 if (!strcmp(node->name, "ch-a"))
614 chan_mask = MACIO_FLAG_SCCA_ON;
615 else if (!strcmp(node->name, "ch-b"))
616 chan_mask = MACIO_FLAG_SCCB_ON;
617 else
618 return -ENODEV;
619
620 if (value) {
621 int need_reset_scc = 0;
622 int need_reset_irda = 0;
623
624 LOCK(flags);
625 fcr = MACIO_IN32(KEYLARGO_FCR0);
626 /* Check if scc cell need enabling */
627 if (!(fcr & KL0_SCC_CELL_ENABLE)) {
628 fcr |= KL0_SCC_CELL_ENABLE;
629 need_reset_scc = 1;
630 }
631 if (chan_mask & MACIO_FLAG_SCCA_ON) {
632 fcr |= KL0_SCCA_ENABLE;
633 /* Don't enable line drivers for I2S modem */
634 if ((param & 0xfff) == PMAC_SCC_I2S1)
635 fcr &= ~KL0_SCC_A_INTF_ENABLE;
636 else
637 fcr |= KL0_SCC_A_INTF_ENABLE;
638 }
639 if (chan_mask & MACIO_FLAG_SCCB_ON) {
640 fcr |= KL0_SCCB_ENABLE;
641 /* Perform irda specific inits */
642 if ((param & 0xfff) == PMAC_SCC_IRDA) {
643 fcr &= ~KL0_SCC_B_INTF_ENABLE;
644 fcr |= KL0_IRDA_ENABLE;
645 fcr |= KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE;
646 fcr |= KL0_IRDA_SOURCE1_SEL;
647 fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
648 fcr &= ~(KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
649 need_reset_irda = 1;
650 } else
651 fcr |= KL0_SCC_B_INTF_ENABLE;
652 }
653 MACIO_OUT32(KEYLARGO_FCR0, fcr);
654 macio->flags |= chan_mask;
655 if (need_reset_scc) {
656 MACIO_BIS(KEYLARGO_FCR0, KL0_SCC_RESET);
657 (void)MACIO_IN32(KEYLARGO_FCR0);
658 UNLOCK(flags);
659 mdelay(15);
660 LOCK(flags);
661 MACIO_BIC(KEYLARGO_FCR0, KL0_SCC_RESET);
662 }
663 if (need_reset_irda) {
664 MACIO_BIS(KEYLARGO_FCR0, KL0_IRDA_RESET);
665 (void)MACIO_IN32(KEYLARGO_FCR0);
666 UNLOCK(flags);
667 mdelay(15);
668 LOCK(flags);
669 MACIO_BIC(KEYLARGO_FCR0, KL0_IRDA_RESET);
670 }
671 UNLOCK(flags);
672 if (param & PMAC_SCC_FLAG_XMON)
673 macio->flags |= MACIO_FLAG_SCC_LOCKED;
674 } else {
675 if (macio->flags & MACIO_FLAG_SCC_LOCKED)
676 return -EPERM;
677 LOCK(flags);
678 fcr = MACIO_IN32(KEYLARGO_FCR0);
679 if (chan_mask & MACIO_FLAG_SCCA_ON)
680 fcr &= ~KL0_SCCA_ENABLE;
681 if (chan_mask & MACIO_FLAG_SCCB_ON) {
682 fcr &= ~KL0_SCCB_ENABLE;
683 /* Perform irda specific clears */
684 if ((param & 0xfff) == PMAC_SCC_IRDA) {
685 fcr &= ~KL0_IRDA_ENABLE;
686 fcr &= ~(KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE);
687 fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
688 fcr &= ~(KL0_IRDA_SOURCE1_SEL|KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
689 }
690 }
691 MACIO_OUT32(KEYLARGO_FCR0, fcr);
692 if ((fcr & (KL0_SCCA_ENABLE | KL0_SCCB_ENABLE)) == 0) {
693 fcr &= ~KL0_SCC_CELL_ENABLE;
694 MACIO_OUT32(KEYLARGO_FCR0, fcr);
695 }
696 macio->flags &= ~(chan_mask);
697 UNLOCK(flags);
698 mdelay(10);
699 }
700 return 0;
701}
702
703static long
704core99_modem_enable(struct device_node *node, long param, long value)
705{
706 struct macio_chip* macio;
707 u8 gpio;
708 unsigned long flags;
709
710 /* Hack for internal USB modem */
711 if (node == NULL) {
712 if (macio_chips[0].type != macio_keylargo)
713 return -ENODEV;
714 node = macio_chips[0].of_node;
715 }
716 macio = macio_find(node, 0);
717 if (!macio)
718 return -ENODEV;
719 gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
720 gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
721 gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
722
723 if (!value) {
724 LOCK(flags);
725 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
726 UNLOCK(flags);
727 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
728 mdelay(250);
729 }
730 LOCK(flags);
731 if (value) {
732 MACIO_BIC(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
733 UNLOCK(flags);
734 (void)MACIO_IN32(KEYLARGO_FCR2);
735 mdelay(250);
736 } else {
737 MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
738 UNLOCK(flags);
739 }
740 if (value) {
741 LOCK(flags);
742 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
743 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
744 UNLOCK(flags); mdelay(250); LOCK(flags);
745 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
746 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
747 UNLOCK(flags); mdelay(250); LOCK(flags);
748 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
749 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
750 UNLOCK(flags); mdelay(250);
751 }
752 return 0;
753}
754
755static long
756pangea_modem_enable(struct device_node *node, long param, long value)
757{
758 struct macio_chip* macio;
759 u8 gpio;
760 unsigned long flags;
761
762 /* Hack for internal USB modem */
763 if (node == NULL) {
764 if (macio_chips[0].type != macio_pangea &&
765 macio_chips[0].type != macio_intrepid)
766 return -ENODEV;
767 node = macio_chips[0].of_node;
768 }
769 macio = macio_find(node, 0);
770 if (!macio)
771 return -ENODEV;
772 gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
773 gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
774 gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
775
776 if (!value) {
777 LOCK(flags);
778 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
779 UNLOCK(flags);
780 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
781 mdelay(250);
782 }
783 LOCK(flags);
784 if (value) {
785 MACIO_OUT8(KL_GPIO_MODEM_POWER,
786 KEYLARGO_GPIO_OUTPUT_ENABLE);
787 UNLOCK(flags);
788 (void)MACIO_IN32(KEYLARGO_FCR2);
789 mdelay(250);
790 } else {
791 MACIO_OUT8(KL_GPIO_MODEM_POWER,
792 KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
793 UNLOCK(flags);
794 }
795 if (value) {
796 LOCK(flags);
797 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
798 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
799 UNLOCK(flags); mdelay(250); LOCK(flags);
800 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
801 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
802 UNLOCK(flags); mdelay(250); LOCK(flags);
803 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
804 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
805 UNLOCK(flags); mdelay(250);
806 }
807 return 0;
808}
809
810static long
811core99_ata100_enable(struct device_node *node, long value)
812{
813 unsigned long flags;
814 struct pci_dev *pdev = NULL;
815 u8 pbus, pid;
816 int rc;
817
818 if (uninorth_rev < 0x24)
819 return -ENODEV;
820
821 LOCK(flags);
822 if (value)
823 UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);
824 else
825 UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);
826 (void)UN_IN(UNI_N_CLOCK_CNTL);
827 UNLOCK(flags);
828 udelay(20);
829
830 if (value) {
831 if (pci_device_from_OF_node(node, &pbus, &pid) == 0)
832 pdev = pci_get_bus_and_slot(pbus, pid);
833 if (pdev == NULL)
834 return 0;
835 rc = pci_enable_device(pdev);
836 if (rc == 0)
837 pci_set_master(pdev);
838 pci_dev_put(pdev);
839 if (rc)
840 return rc;
841 }
842 return 0;
843}
844
845static long
846core99_ide_enable(struct device_node *node, long param, long value)
847{
848 /* Bus ID 0 to 2 are KeyLargo based IDE, busID 3 is U2
849 * based ata-100
850 */
851 switch(param) {
852 case 0:
853 return simple_feature_tweak(node, macio_unknown,
854 KEYLARGO_FCR1, KL1_EIDE0_ENABLE, value);
855 case 1:
856 return simple_feature_tweak(node, macio_unknown,
857 KEYLARGO_FCR1, KL1_EIDE1_ENABLE, value);
858 case 2:
859 return simple_feature_tweak(node, macio_unknown,
860 KEYLARGO_FCR1, KL1_UIDE_ENABLE, value);
861 case 3:
862 return core99_ata100_enable(node, value);
863 default:
864 return -ENODEV;
865 }
866}
867
868static long
869core99_ide_reset(struct device_node *node, long param, long value)
870{
871 switch(param) {
872 case 0:
873 return simple_feature_tweak(node, macio_unknown,
874 KEYLARGO_FCR1, KL1_EIDE0_RESET_N, !value);
875 case 1:
876 return simple_feature_tweak(node, macio_unknown,
877 KEYLARGO_FCR1, KL1_EIDE1_RESET_N, !value);
878 case 2:
879 return simple_feature_tweak(node, macio_unknown,
880 KEYLARGO_FCR1, KL1_UIDE_RESET_N, !value);
881 default:
882 return -ENODEV;
883 }
884}
885
886static long
887core99_gmac_enable(struct device_node *node, long param, long value)
888{
889 unsigned long flags;
890
891 LOCK(flags);
892 if (value)
893 UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
894 else
895 UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
896 (void)UN_IN(UNI_N_CLOCK_CNTL);
897 UNLOCK(flags);
898 udelay(20);
899
900 return 0;
901}
902
903static long
904core99_gmac_phy_reset(struct device_node *node, long param, long value)
905{
906 unsigned long flags;
907 struct macio_chip *macio;
908
909 macio = &macio_chips[0];
910 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
911 macio->type != macio_intrepid)
912 return -ENODEV;
913
914 LOCK(flags);
915 MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE);
916 (void)MACIO_IN8(KL_GPIO_ETH_PHY_RESET);
917 UNLOCK(flags);
918 mdelay(10);
919 LOCK(flags);
920 MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, /*KEYLARGO_GPIO_OUTPUT_ENABLE | */
921 KEYLARGO_GPIO_OUTOUT_DATA);
922 UNLOCK(flags);
923 mdelay(10);
924
925 return 0;
926}
927
928static long
929core99_sound_chip_enable(struct device_node *node, long param, long value)
930{
931 struct macio_chip* macio;
932 unsigned long flags;
933
934 macio = macio_find(node, 0);
935 if (!macio)
936 return -ENODEV;
937
938 /* Do a better probe code, screamer G4 desktops &
939 * iMacs can do that too, add a recalibrate in
940 * the driver as well
941 */
942 if (pmac_mb.model_id == PMAC_TYPE_PISMO ||
943 pmac_mb.model_id == PMAC_TYPE_TITANIUM) {
944 LOCK(flags);
945 if (value)
946 MACIO_OUT8(KL_GPIO_SOUND_POWER,
947 KEYLARGO_GPIO_OUTPUT_ENABLE |
948 KEYLARGO_GPIO_OUTOUT_DATA);
949 else
950 MACIO_OUT8(KL_GPIO_SOUND_POWER,
951 KEYLARGO_GPIO_OUTPUT_ENABLE);
952 (void)MACIO_IN8(KL_GPIO_SOUND_POWER);
953 UNLOCK(flags);
954 }
955 return 0;
956}
957
958static long
959core99_airport_enable(struct device_node *node, long param, long value)
960{
961 struct macio_chip* macio;
962 unsigned long flags;
963 int state;
964
965 macio = macio_find(node, 0);
966 if (!macio)
967 return -ENODEV;
968
969 /* Hint: we allow passing of macio itself for the sake of the
970 * sleep code
971 */
972 if (node != macio->of_node &&
973 (!node->parent || node->parent != macio->of_node))
974 return -ENODEV;
975 state = (macio->flags & MACIO_FLAG_AIRPORT_ON) != 0;
976 if (value == state)
977 return 0;
978 if (value) {
979 /* This code is a reproduction of OF enable-cardslot
980 * and init-wireless methods, slightly hacked until
981 * I got it working.
982 */
983 LOCK(flags);
984 MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 5);
985 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
986 UNLOCK(flags);
987 mdelay(10);
988 LOCK(flags);
989 MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 4);
990 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
991 UNLOCK(flags);
992
993 mdelay(10);
994
995 LOCK(flags);
996 MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
997 (void)MACIO_IN32(KEYLARGO_FCR2);
998 udelay(10);
999 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xb, 0);
1000 (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xb);
1001 udelay(10);
1002 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xa, 0x28);
1003 (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xa);
1004 udelay(10);
1005 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xd, 0x28);
1006 (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xd);
1007 udelay(10);
1008 MACIO_OUT8(KEYLARGO_GPIO_0+0xd, 0x28);
1009 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xd);
1010 udelay(10);
1011 MACIO_OUT8(KEYLARGO_GPIO_0+0xe, 0x28);
1012 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xe);
1013 UNLOCK(flags);
1014 udelay(10);
1015 MACIO_OUT32(0x1c000, 0);
1016 mdelay(1);
1017 MACIO_OUT8(0x1a3e0, 0x41);
1018 (void)MACIO_IN8(0x1a3e0);
1019 udelay(10);
1020 LOCK(flags);
1021 MACIO_BIS(KEYLARGO_FCR2, KL2_CARDSEL_16);
1022 (void)MACIO_IN32(KEYLARGO_FCR2);
1023 UNLOCK(flags);
1024 mdelay(100);
1025
1026 macio->flags |= MACIO_FLAG_AIRPORT_ON;
1027 } else {
1028 LOCK(flags);
1029 MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
1030 (void)MACIO_IN32(KEYLARGO_FCR2);
1031 MACIO_OUT8(KL_GPIO_AIRPORT_0, 0);
1032 MACIO_OUT8(KL_GPIO_AIRPORT_1, 0);
1033 MACIO_OUT8(KL_GPIO_AIRPORT_2, 0);
1034 MACIO_OUT8(KL_GPIO_AIRPORT_3, 0);
1035 MACIO_OUT8(KL_GPIO_AIRPORT_4, 0);
1036 (void)MACIO_IN8(KL_GPIO_AIRPORT_4);
1037 UNLOCK(flags);
1038
1039 macio->flags &= ~MACIO_FLAG_AIRPORT_ON;
1040 }
1041 return 0;
1042}
1043
1044#ifdef CONFIG_SMP
1045static long
1046core99_reset_cpu(struct device_node *node, long param, long value)
1047{
1048 unsigned int reset_io = 0;
1049 unsigned long flags;
1050 struct macio_chip *macio;
1051 struct device_node *np;
1052 struct device_node *cpus;
1053 const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0,
1054 KL_GPIO_RESET_CPU1,
1055 KL_GPIO_RESET_CPU2,
1056 KL_GPIO_RESET_CPU3 };
1057
1058 macio = &macio_chips[0];
1059 if (macio->type != macio_keylargo)
1060 return -ENODEV;
1061
1062 cpus = of_find_node_by_path("/cpus");
1063 if (cpus == NULL)
1064 return -ENODEV;
1065 for (np = cpus->child; np != NULL; np = np->sibling) {
1066 const u32 *num = of_get_property(np, "reg", NULL);
1067 const u32 *rst = of_get_property(np, "soft-reset", NULL);
1068 if (num == NULL || rst == NULL)
1069 continue;
1070 if (param == *num) {
1071 reset_io = *rst;
1072 break;
1073 }
1074 }
1075 of_node_put(cpus);
1076 if (np == NULL || reset_io == 0)
1077 reset_io = dflt_reset_lines[param];
1078
1079 LOCK(flags);
1080 MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
1081 (void)MACIO_IN8(reset_io);
1082 udelay(1);
1083 MACIO_OUT8(reset_io, 0);
1084 (void)MACIO_IN8(reset_io);
1085 UNLOCK(flags);
1086
1087 return 0;
1088}
1089#endif /* CONFIG_SMP */
1090
1091static long
1092core99_usb_enable(struct device_node *node, long param, long value)
1093{
1094 struct macio_chip *macio;
1095 unsigned long flags;
1096 const char *prop;
1097 int number;
1098 u32 reg;
1099
1100 macio = &macio_chips[0];
1101 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1102 macio->type != macio_intrepid)
1103 return -ENODEV;
1104
1105 prop = of_get_property(node, "AAPL,clock-id", NULL);
1106 if (!prop)
1107 return -ENODEV;
1108 if (strncmp(prop, "usb0u048", 8) == 0)
1109 number = 0;
1110 else if (strncmp(prop, "usb1u148", 8) == 0)
1111 number = 2;
1112 else if (strncmp(prop, "usb2u248", 8) == 0)
1113 number = 4;
1114 else
1115 return -ENODEV;
1116
1117 /* Sorry for the brute-force locking, but this is only used during
1118 * sleep and the timing seem to be critical
1119 */
1120 LOCK(flags);
1121 if (value) {
1122 /* Turn ON */
1123 if (number == 0) {
1124 MACIO_BIC(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
1125 (void)MACIO_IN32(KEYLARGO_FCR0);
1126 UNLOCK(flags);
1127 mdelay(1);
1128 LOCK(flags);
1129 MACIO_BIS(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
1130 } else if (number == 2) {
1131 MACIO_BIC(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
1132 UNLOCK(flags);
1133 (void)MACIO_IN32(KEYLARGO_FCR0);
1134 mdelay(1);
1135 LOCK(flags);
1136 MACIO_BIS(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
1137 } else if (number == 4) {
1138 MACIO_BIC(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
1139 UNLOCK(flags);
1140 (void)MACIO_IN32(KEYLARGO_FCR1);
1141 mdelay(1);
1142 LOCK(flags);
1143 MACIO_BIS(KEYLARGO_FCR1, KL1_USB2_CELL_ENABLE);
1144 }
1145 if (number < 4) {
1146 reg = MACIO_IN32(KEYLARGO_FCR4);
1147 reg &= ~(KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
1148 KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number));
1149 reg &= ~(KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
1150 KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1));
1151 MACIO_OUT32(KEYLARGO_FCR4, reg);
1152 (void)MACIO_IN32(KEYLARGO_FCR4);
1153 udelay(10);
1154 } else {
1155 reg = MACIO_IN32(KEYLARGO_FCR3);
1156 reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
1157 KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0));
1158 reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
1159 KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1));
1160 MACIO_OUT32(KEYLARGO_FCR3, reg);
1161 (void)MACIO_IN32(KEYLARGO_FCR3);
1162 udelay(10);
1163 }
1164 if (macio->type == macio_intrepid) {
1165 /* wait for clock stopped bits to clear */
1166 u32 test0 = 0, test1 = 0;
1167 u32 status0, status1;
1168 int timeout = 1000;
1169
1170 UNLOCK(flags);
1171 switch (number) {
1172 case 0:
1173 test0 = UNI_N_CLOCK_STOPPED_USB0;
1174 test1 = UNI_N_CLOCK_STOPPED_USB0PCI;
1175 break;
1176 case 2:
1177 test0 = UNI_N_CLOCK_STOPPED_USB1;
1178 test1 = UNI_N_CLOCK_STOPPED_USB1PCI;
1179 break;
1180 case 4:
1181 test0 = UNI_N_CLOCK_STOPPED_USB2;
1182 test1 = UNI_N_CLOCK_STOPPED_USB2PCI;
1183 break;
1184 }
1185 do {
1186 if (--timeout <= 0) {
1187 printk(KERN_ERR "core99_usb_enable: "
1188 "Timeout waiting for clocks\n");
1189 break;
1190 }
1191 mdelay(1);
1192 status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);
1193 status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);
1194 } while ((status0 & test0) | (status1 & test1));
1195 LOCK(flags);
1196 }
1197 } else {
1198 /* Turn OFF */
1199 if (number < 4) {
1200 reg = MACIO_IN32(KEYLARGO_FCR4);
1201 reg |= KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
1202 KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number);
1203 reg |= KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
1204 KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1);
1205 MACIO_OUT32(KEYLARGO_FCR4, reg);
1206 (void)MACIO_IN32(KEYLARGO_FCR4);
1207 udelay(1);
1208 } else {
1209 reg = MACIO_IN32(KEYLARGO_FCR3);
1210 reg |= KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
1211 KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0);
1212 reg |= KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
1213 KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1);
1214 MACIO_OUT32(KEYLARGO_FCR3, reg);
1215 (void)MACIO_IN32(KEYLARGO_FCR3);
1216 udelay(1);
1217 }
1218 if (number == 0) {
1219 if (macio->type != macio_intrepid)
1220 MACIO_BIC(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
1221 (void)MACIO_IN32(KEYLARGO_FCR0);
1222 udelay(1);
1223 MACIO_BIS(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
1224 (void)MACIO_IN32(KEYLARGO_FCR0);
1225 } else if (number == 2) {
1226 if (macio->type != macio_intrepid)
1227 MACIO_BIC(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
1228 (void)MACIO_IN32(KEYLARGO_FCR0);
1229 udelay(1);
1230 MACIO_BIS(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
1231 (void)MACIO_IN32(KEYLARGO_FCR0);
1232 } else if (number == 4) {
1233 udelay(1);
1234 MACIO_BIS(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
1235 (void)MACIO_IN32(KEYLARGO_FCR1);
1236 }
1237 udelay(1);
1238 }
1239 UNLOCK(flags);
1240
1241 return 0;
1242}
1243
1244static long
1245core99_firewire_enable(struct device_node *node, long param, long value)
1246{
1247 unsigned long flags;
1248 struct macio_chip *macio;
1249
1250 macio = &macio_chips[0];
1251 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1252 macio->type != macio_intrepid)
1253 return -ENODEV;
1254 if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
1255 return -ENODEV;
1256
1257 LOCK(flags);
1258 if (value) {
1259 UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
1260 (void)UN_IN(UNI_N_CLOCK_CNTL);
1261 } else {
1262 UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
1263 (void)UN_IN(UNI_N_CLOCK_CNTL);
1264 }
1265 UNLOCK(flags);
1266 mdelay(1);
1267
1268 return 0;
1269}
1270
1271static long
1272core99_firewire_cable_power(struct device_node *node, long param, long value)
1273{
1274 unsigned long flags;
1275 struct macio_chip *macio;
1276
1277 /* Trick: we allow NULL node */
1278 if ((pmac_mb.board_flags & PMAC_MB_HAS_FW_POWER) == 0)
1279 return -ENODEV;
1280 macio = &macio_chips[0];
1281 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1282 macio->type != macio_intrepid)
1283 return -ENODEV;
1284 if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
1285 return -ENODEV;
1286
1287 LOCK(flags);
1288 if (value) {
1289 MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 0);
1290 MACIO_IN8(KL_GPIO_FW_CABLE_POWER);
1291 udelay(10);
1292 } else {
1293 MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 4);
1294 MACIO_IN8(KL_GPIO_FW_CABLE_POWER); udelay(10);
1295 }
1296 UNLOCK(flags);
1297 mdelay(1);
1298
1299 return 0;
1300}
1301
1302static long
1303intrepid_aack_delay_enable(struct device_node *node, long param, long value)
1304{
1305 unsigned long flags;
1306
1307 if (uninorth_rev < 0xd2)
1308 return -ENODEV;
1309
1310 LOCK(flags);
1311 if (param)
1312 UN_BIS(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
1313 else
1314 UN_BIC(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
1315 UNLOCK(flags);
1316
1317 return 0;
1318}
1319
1320
1321#endif /* CONFIG_POWER4 */
1322
1323static long
1324core99_read_gpio(struct device_node *node, long param, long value)
1325{
1326 struct macio_chip *macio = &macio_chips[0];
1327
1328 return MACIO_IN8(param);
1329}
1330
1331
1332static long
1333core99_write_gpio(struct device_node *node, long param, long value)
1334{
1335 struct macio_chip *macio = &macio_chips[0];
1336
1337 MACIO_OUT8(param, (u8)(value & 0xff));
1338 return 0;
1339}
1340
1341#ifdef CONFIG_POWER4
1342static long g5_gmac_enable(struct device_node *node, long param, long value)
1343{
1344 struct macio_chip *macio = &macio_chips[0];
1345 unsigned long flags;
1346
1347 if (node == NULL)
1348 return -ENODEV;
1349
1350 LOCK(flags);
1351 if (value) {
1352 MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
1353 mb();
1354 k2_skiplist[0] = NULL;
1355 } else {
1356 k2_skiplist[0] = node;
1357 mb();
1358 MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
1359 }
1360
1361 UNLOCK(flags);
1362 mdelay(1);
1363
1364 return 0;
1365}
1366
1367static long g5_fw_enable(struct device_node *node, long param, long value)
1368{
1369 struct macio_chip *macio = &macio_chips[0];
1370 unsigned long flags;
1371
1372 if (node == NULL)
1373 return -ENODEV;
1374
1375 LOCK(flags);
1376 if (value) {
1377 MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
1378 mb();
1379 k2_skiplist[1] = NULL;
1380 } else {
1381 k2_skiplist[1] = node;
1382 mb();
1383 MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
1384 }
1385
1386 UNLOCK(flags);
1387 mdelay(1);
1388
1389 return 0;
1390}
1391
1392static long g5_mpic_enable(struct device_node *node, long param, long value)
1393{
1394 unsigned long flags;
1395 struct device_node *parent = of_get_parent(node);
1396 int is_u3;
1397
1398 if (parent == NULL)
1399 return 0;
1400 is_u3 = strcmp(parent->name, "u3") == 0 ||
1401 strcmp(parent->name, "u4") == 0;
1402 of_node_put(parent);
1403 if (!is_u3)
1404 return 0;
1405
1406 LOCK(flags);
1407 UN_BIS(U3_TOGGLE_REG, U3_MPIC_RESET | U3_MPIC_OUTPUT_ENABLE);
1408 UNLOCK(flags);
1409
1410 return 0;
1411}
1412
1413static long g5_eth_phy_reset(struct device_node *node, long param, long value)
1414{
1415 struct macio_chip *macio = &macio_chips[0];
1416 struct device_node *phy;
1417 int need_reset;
1418
1419 /*
1420 * We must not reset the combo PHYs, only the BCM5221 found in
1421 * the iMac G5.
1422 */
1423 phy = of_get_next_child(node, NULL);
1424 if (!phy)
1425 return -ENODEV;
1426 need_reset = of_device_is_compatible(phy, "B5221");
1427 of_node_put(phy);
1428 if (!need_reset)
1429 return 0;
1430
1431 /* PHY reset is GPIO 29, not in device-tree unfortunately */
1432 MACIO_OUT8(K2_GPIO_EXTINT_0 + 29,
1433 KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
1434 /* Thankfully, this is now always called at a time when we can
1435 * schedule by sungem.
1436 */
1437 msleep(10);
1438 MACIO_OUT8(K2_GPIO_EXTINT_0 + 29, 0);
1439
1440 return 0;
1441}
1442
1443static long g5_i2s_enable(struct device_node *node, long param, long value)
1444{
1445 /* Very crude implementation for now */
1446 struct macio_chip *macio = &macio_chips[0];
1447 unsigned long flags;
1448 int cell;
1449 u32 fcrs[3][3] = {
1450 { 0,
1451 K2_FCR1_I2S0_CELL_ENABLE |
1452 K2_FCR1_I2S0_CLK_ENABLE_BIT | K2_FCR1_I2S0_ENABLE,
1453 KL3_I2S0_CLK18_ENABLE
1454 },
1455 { KL0_SCC_A_INTF_ENABLE,
1456 K2_FCR1_I2S1_CELL_ENABLE |
1457 K2_FCR1_I2S1_CLK_ENABLE_BIT | K2_FCR1_I2S1_ENABLE,
1458 KL3_I2S1_CLK18_ENABLE
1459 },
1460 { KL0_SCC_B_INTF_ENABLE,
1461 SH_FCR1_I2S2_CELL_ENABLE |
1462 SH_FCR1_I2S2_CLK_ENABLE_BIT | SH_FCR1_I2S2_ENABLE,
1463 SH_FCR3_I2S2_CLK18_ENABLE
1464 },
1465 };
1466
1467 if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
1468 return -ENODEV;
1469 if (strncmp(node->name, "i2s-", 4))
1470 return -ENODEV;
1471 cell = node->name[4] - 'a';
1472 switch(cell) {
1473 case 0:
1474 case 1:
1475 break;
1476 case 2:
1477 if (macio->type == macio_shasta)
1478 break;
1479 default:
1480 return -ENODEV;
1481 }
1482
1483 LOCK(flags);
1484 if (value) {
1485 MACIO_BIC(KEYLARGO_FCR0, fcrs[cell][0]);
1486 MACIO_BIS(KEYLARGO_FCR1, fcrs[cell][1]);
1487 MACIO_BIS(KEYLARGO_FCR3, fcrs[cell][2]);
1488 } else {
1489 MACIO_BIC(KEYLARGO_FCR3, fcrs[cell][2]);
1490 MACIO_BIC(KEYLARGO_FCR1, fcrs[cell][1]);
1491 MACIO_BIS(KEYLARGO_FCR0, fcrs[cell][0]);
1492 }
1493 udelay(10);
1494 UNLOCK(flags);
1495
1496 return 0;
1497}
1498
1499
1500#ifdef CONFIG_SMP
1501static long g5_reset_cpu(struct device_node *node, long param, long value)
1502{
1503 unsigned int reset_io = 0;
1504 unsigned long flags;
1505 struct macio_chip *macio;
1506 struct device_node *np;
1507 struct device_node *cpus;
1508
1509 macio = &macio_chips[0];
1510 if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
1511 return -ENODEV;
1512
1513 cpus = of_find_node_by_path("/cpus");
1514 if (cpus == NULL)
1515 return -ENODEV;
1516 for (np = cpus->child; np != NULL; np = np->sibling) {
1517 const u32 *num = of_get_property(np, "reg", NULL);
1518 const u32 *rst = of_get_property(np, "soft-reset", NULL);
1519 if (num == NULL || rst == NULL)
1520 continue;
1521 if (param == *num) {
1522 reset_io = *rst;
1523 break;
1524 }
1525 }
1526 of_node_put(cpus);
1527 if (np == NULL || reset_io == 0)
1528 return -ENODEV;
1529
1530 LOCK(flags);
1531 MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
1532 (void)MACIO_IN8(reset_io);
1533 udelay(1);
1534 MACIO_OUT8(reset_io, 0);
1535 (void)MACIO_IN8(reset_io);
1536 UNLOCK(flags);
1537
1538 return 0;
1539}
1540#endif /* CONFIG_SMP */
1541
1542/*
1543 * This can be called from pmac_smp so isn't static
1544 *
1545 * This takes the second CPU off the bus on dual CPU machines
1546 * running UP
1547 */
1548void g5_phy_disable_cpu1(void)
1549{
1550 if (uninorth_maj == 3)
1551 UN_OUT(U3_API_PHY_CONFIG_1, 0);
1552}
1553#endif /* CONFIG_POWER4 */
1554
1555#ifndef CONFIG_POWER4
1556
1557
1558#ifdef CONFIG_PM
1559static u32 save_gpio_levels[2];
1560static u8 save_gpio_extint[KEYLARGO_GPIO_EXTINT_CNT];
1561static u8 save_gpio_normal[KEYLARGO_GPIO_CNT];
1562static u32 save_unin_clock_ctl;
1563
1564static void keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
1565{
1566 u32 temp;
1567
1568 if (sleep_mode) {
1569 mdelay(1);
1570 MACIO_BIS(KEYLARGO_FCR0, KL0_USB_REF_SUSPEND);
1571 (void)MACIO_IN32(KEYLARGO_FCR0);
1572 mdelay(1);
1573 }
1574
1575 MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
1576 KL0_SCC_CELL_ENABLE |
1577 KL0_IRDA_ENABLE | KL0_IRDA_CLK32_ENABLE |
1578 KL0_IRDA_CLK19_ENABLE);
1579
1580 MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);
1581 MACIO_BIS(KEYLARGO_MBCR, KL_MBCR_MB0_IDE_ENABLE);
1582
1583 MACIO_BIC(KEYLARGO_FCR1,
1584 KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
1585 KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
1586 KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
1587 KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
1588 KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
1589 KL1_EIDE0_ENABLE | KL1_EIDE0_RESET_N |
1590 KL1_EIDE1_ENABLE | KL1_EIDE1_RESET_N |
1591 KL1_UIDE_ENABLE);
1592
1593 MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
1594 MACIO_BIC(KEYLARGO_FCR2, KL2_IOBUS_ENABLE);
1595
1596 temp = MACIO_IN32(KEYLARGO_FCR3);
1597 if (macio->rev >= 2) {
1598 temp |= KL3_SHUTDOWN_PLL2X;
1599 if (sleep_mode)
1600 temp |= KL3_SHUTDOWN_PLL_TOTAL;
1601 }
1602
1603 temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
1604 KL3_SHUTDOWN_PLLKW35;
1605 if (sleep_mode)
1606 temp |= KL3_SHUTDOWN_PLLKW12;
1607 temp &= ~(KL3_CLK66_ENABLE | KL3_CLK49_ENABLE | KL3_CLK45_ENABLE
1608 | KL3_CLK31_ENABLE | KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
1609 if (sleep_mode)
1610 temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);
1611 MACIO_OUT32(KEYLARGO_FCR3, temp);
1612
1613 /* Flush posted writes & wait a bit */
1614 (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
1615}
1616
1617static void pangea_shutdown(struct macio_chip *macio, int sleep_mode)
1618{
1619 u32 temp;
1620
1621 MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
1622 KL0_SCC_CELL_ENABLE |
1623 KL0_USB0_CELL_ENABLE | KL0_USB1_CELL_ENABLE);
1624
1625 MACIO_BIC(KEYLARGO_FCR1,
1626 KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
1627 KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
1628 KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
1629 KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
1630 KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
1631 KL1_UIDE_ENABLE);
1632 if (pmac_mb.board_flags & PMAC_MB_MOBILE)
1633 MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
1634
1635 MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
1636
1637 temp = MACIO_IN32(KEYLARGO_FCR3);
1638 temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
1639 KL3_SHUTDOWN_PLLKW35;
1640 temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE | KL3_CLK31_ENABLE
1641 | KL3_I2S0_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE);
1642 if (sleep_mode)
1643 temp &= ~(KL3_VIA_CLK16_ENABLE | KL3_TIMER_CLK18_ENABLE);
1644 MACIO_OUT32(KEYLARGO_FCR3, temp);
1645
1646 /* Flush posted writes & wait a bit */
1647 (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
1648}
1649
1650static void intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
1651{
1652 u32 temp;
1653
1654 MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
1655 KL0_SCC_CELL_ENABLE);
1656
1657 MACIO_BIC(KEYLARGO_FCR1,
1658 KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
1659 KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
1660 KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
1661 KL1_EIDE0_ENABLE);
1662 if (pmac_mb.board_flags & PMAC_MB_MOBILE)
1663 MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
1664
1665 temp = MACIO_IN32(KEYLARGO_FCR3);
1666 temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE |
1667 KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
1668 if (sleep_mode)
1669 temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_IT_VIA_CLK32_ENABLE);
1670 MACIO_OUT32(KEYLARGO_FCR3, temp);
1671
1672 /* Flush posted writes & wait a bit */
1673 (void)MACIO_IN32(KEYLARGO_FCR0);
1674 mdelay(10);
1675}
1676
1677
1678static int
1679core99_sleep(void)
1680{
1681 struct macio_chip *macio;
1682 int i;
1683
1684 macio = &macio_chips[0];
1685 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1686 macio->type != macio_intrepid)
1687 return -ENODEV;
1688
1689 /* We power off the wireless slot in case it was not done
1690 * by the driver. We don't power it on automatically however
1691 */
1692 if (macio->flags & MACIO_FLAG_AIRPORT_ON)
1693 core99_airport_enable(macio->of_node, 0, 0);
1694
1695 /* We power off the FW cable. Should be done by the driver... */
1696 if (macio->flags & MACIO_FLAG_FW_SUPPORTED) {
1697 core99_firewire_enable(NULL, 0, 0);
1698 core99_firewire_cable_power(NULL, 0, 0);
1699 }
1700
1701 /* We make sure int. modem is off (in case driver lost it) */
1702 if (macio->type == macio_keylargo)
1703 core99_modem_enable(macio->of_node, 0, 0);
1704 else
1705 pangea_modem_enable(macio->of_node, 0, 0);
1706
1707 /* We make sure the sound is off as well */
1708 core99_sound_chip_enable(macio->of_node, 0, 0);
1709
1710 /*
1711 * Save various bits of KeyLargo
1712 */
1713
1714 /* Save the state of the various GPIOs */
1715 save_gpio_levels[0] = MACIO_IN32(KEYLARGO_GPIO_LEVELS0);
1716 save_gpio_levels[1] = MACIO_IN32(KEYLARGO_GPIO_LEVELS1);
1717 for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
1718 save_gpio_extint[i] = MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+i);
1719 for (i=0; i<KEYLARGO_GPIO_CNT; i++)
1720 save_gpio_normal[i] = MACIO_IN8(KEYLARGO_GPIO_0+i);
1721
1722 /* Save the FCRs */
1723 if (macio->type == macio_keylargo)
1724 save_mbcr = MACIO_IN32(KEYLARGO_MBCR);
1725 save_fcr[0] = MACIO_IN32(KEYLARGO_FCR0);
1726 save_fcr[1] = MACIO_IN32(KEYLARGO_FCR1);
1727 save_fcr[2] = MACIO_IN32(KEYLARGO_FCR2);
1728 save_fcr[3] = MACIO_IN32(KEYLARGO_FCR3);
1729 save_fcr[4] = MACIO_IN32(KEYLARGO_FCR4);
1730 if (macio->type == macio_pangea || macio->type == macio_intrepid)
1731 save_fcr[5] = MACIO_IN32(KEYLARGO_FCR5);
1732
1733 /* Save state & config of DBDMA channels */
1734 dbdma_save(macio, save_dbdma);
1735
1736 /*
1737 * Turn off as much as we can
1738 */
1739 if (macio->type == macio_pangea)
1740 pangea_shutdown(macio, 1);
1741 else if (macio->type == macio_intrepid)
1742 intrepid_shutdown(macio, 1);
1743 else if (macio->type == macio_keylargo)
1744 keylargo_shutdown(macio, 1);
1745
1746 /*
1747 * Put the host bridge to sleep
1748 */
1749
1750 save_unin_clock_ctl = UN_IN(UNI_N_CLOCK_CNTL);
1751 /* Note: do not switch GMAC off, driver does it when necessary, WOL must keep it
1752 * enabled !
1753 */
1754 UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl &
1755 ~(/*UNI_N_CLOCK_CNTL_GMAC|*/UNI_N_CLOCK_CNTL_FW/*|UNI_N_CLOCK_CNTL_PCI*/));
1756 udelay(100);
1757 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
1758 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_SLEEP);
1759 mdelay(10);
1760
1761 /*
1762 * FIXME: A bit of black magic with OpenPIC (don't ask me why)
1763 */
1764 if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
1765 MACIO_BIS(0x506e0, 0x00400000);
1766 MACIO_BIS(0x506e0, 0x80000000);
1767 }
1768 return 0;
1769}
1770
1771static int
1772core99_wake_up(void)
1773{
1774 struct macio_chip *macio;
1775 int i;
1776
1777 macio = &macio_chips[0];
1778 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1779 macio->type != macio_intrepid)
1780 return -ENODEV;
1781
1782 /*
1783 * Wakeup the host bridge
1784 */
1785 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
1786 udelay(10);
1787 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
1788 udelay(10);
1789
1790 /*
1791 * Restore KeyLargo
1792 */
1793
1794 if (macio->type == macio_keylargo) {
1795 MACIO_OUT32(KEYLARGO_MBCR, save_mbcr);
1796 (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
1797 }
1798 MACIO_OUT32(KEYLARGO_FCR0, save_fcr[0]);
1799 (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
1800 MACIO_OUT32(KEYLARGO_FCR1, save_fcr[1]);
1801 (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
1802 MACIO_OUT32(KEYLARGO_FCR2, save_fcr[2]);
1803 (void)MACIO_IN32(KEYLARGO_FCR2); udelay(10);
1804 MACIO_OUT32(KEYLARGO_FCR3, save_fcr[3]);
1805 (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
1806 MACIO_OUT32(KEYLARGO_FCR4, save_fcr[4]);
1807 (void)MACIO_IN32(KEYLARGO_FCR4); udelay(10);
1808 if (macio->type == macio_pangea || macio->type == macio_intrepid) {
1809 MACIO_OUT32(KEYLARGO_FCR5, save_fcr[5]);
1810 (void)MACIO_IN32(KEYLARGO_FCR5); udelay(10);
1811 }
1812
1813 dbdma_restore(macio, save_dbdma);
1814
1815 MACIO_OUT32(KEYLARGO_GPIO_LEVELS0, save_gpio_levels[0]);
1816 MACIO_OUT32(KEYLARGO_GPIO_LEVELS1, save_gpio_levels[1]);
1817 for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
1818 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+i, save_gpio_extint[i]);
1819 for (i=0; i<KEYLARGO_GPIO_CNT; i++)
1820 MACIO_OUT8(KEYLARGO_GPIO_0+i, save_gpio_normal[i]);
1821
1822 /* FIXME more black magic with OpenPIC ... */
1823 if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
1824 MACIO_BIC(0x506e0, 0x00400000);
1825 MACIO_BIC(0x506e0, 0x80000000);
1826 }
1827
1828 UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl);
1829 udelay(100);
1830
1831 return 0;
1832}
1833
1834#endif /* CONFIG_PM */
1835
1836static long
1837core99_sleep_state(struct device_node *node, long param, long value)
1838{
1839 /* Param == 1 means to enter the "fake sleep" mode that is
1840 * used for CPU speed switch
1841 */
1842 if (param == 1) {
1843 if (value == 1) {
1844 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
1845 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_IDLE2);
1846 } else {
1847 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
1848 udelay(10);
1849 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
1850 udelay(10);
1851 }
1852 return 0;
1853 }
1854 if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
1855 return -EPERM;
1856
1857#ifdef CONFIG_PM
1858 if (value == 1)
1859 return core99_sleep();
1860 else if (value == 0)
1861 return core99_wake_up();
1862
1863#endif /* CONFIG_PM */
1864 return 0;
1865}
1866
1867#endif /* CONFIG_POWER4 */
1868
1869static long
1870generic_dev_can_wake(struct device_node *node, long param, long value)
1871{
1872 /* Todo: eventually check we are really dealing with on-board
1873 * video device ...
1874 */
1875
1876 if (pmac_mb.board_flags & PMAC_MB_MAY_SLEEP)
1877 pmac_mb.board_flags |= PMAC_MB_CAN_SLEEP;
1878 return 0;
1879}
1880
1881static long generic_get_mb_info(struct device_node *node, long param, long value)
1882{
1883 switch(param) {
1884 case PMAC_MB_INFO_MODEL:
1885 return pmac_mb.model_id;
1886 case PMAC_MB_INFO_FLAGS:
1887 return pmac_mb.board_flags;
1888 case PMAC_MB_INFO_NAME:
1889 /* hack hack hack... but should work */
1890 *((const char **)value) = pmac_mb.model_name;
1891 return 0;
1892 }
1893 return -EINVAL;
1894}
1895
1896
1897/*
1898 * Table definitions
1899 */
1900
1901/* Used on any machine
1902 */
1903static struct feature_table_entry any_features[] = {
1904 { PMAC_FTR_GET_MB_INFO, generic_get_mb_info },
1905 { PMAC_FTR_DEVICE_CAN_WAKE, generic_dev_can_wake },
1906 { 0, NULL }
1907};
1908
1909#ifndef CONFIG_POWER4
1910
1911/* OHare based motherboards. Currently, we only use these on the
1912 * 2400,3400 and 3500 series powerbooks. Some older desktops seem
1913 * to have issues with turning on/off those asic cells
1914 */
1915static struct feature_table_entry ohare_features[] = {
1916 { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
1917 { PMAC_FTR_SWIM3_ENABLE, ohare_floppy_enable },
1918 { PMAC_FTR_MESH_ENABLE, ohare_mesh_enable },
1919 { PMAC_FTR_IDE_ENABLE, ohare_ide_enable},
1920 { PMAC_FTR_IDE_RESET, ohare_ide_reset},
1921 { PMAC_FTR_SLEEP_STATE, ohare_sleep_state },
1922 { 0, NULL }
1923};
1924
1925/* Heathrow desktop machines (Beige G3).
1926 * Separated as some features couldn't be properly tested
1927 * and the serial port control bits appear to confuse it.
1928 */
1929static struct feature_table_entry heathrow_desktop_features[] = {
1930 { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
1931 { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
1932 { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
1933 { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
1934 { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
1935 { 0, NULL }
1936};
1937
1938/* Heathrow based laptop, that is the Wallstreet and mainstreet
1939 * powerbooks.
1940 */
1941static struct feature_table_entry heathrow_laptop_features[] = {
1942 { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
1943 { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
1944 { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
1945 { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
1946 { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
1947 { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
1948 { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
1949 { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
1950 { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
1951 { 0, NULL }
1952};
1953
1954/* Paddington based machines
1955 * The lombard (101) powerbook, first iMac models, B&W G3 and Yikes G4.
1956 */
1957static struct feature_table_entry paddington_features[] = {
1958 { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
1959 { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
1960 { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
1961 { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
1962 { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
1963 { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
1964 { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
1965 { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
1966 { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
1967 { 0, NULL }
1968};
1969
1970/* Core99 & MacRISC 2 machines (all machines released since the
1971 * iBook (included), that is all AGP machines, except pangea
1972 * chipset. The pangea chipset is the "combo" UniNorth/KeyLargo
1973 * used on iBook2 & iMac "flow power".
1974 */
1975static struct feature_table_entry core99_features[] = {
1976 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
1977 { PMAC_FTR_MODEM_ENABLE, core99_modem_enable },
1978 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
1979 { PMAC_FTR_IDE_RESET, core99_ide_reset },
1980 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
1981 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
1982 { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
1983 { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
1984 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
1985 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
1986 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
1987#ifdef CONFIG_PM
1988 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
1989#endif
1990#ifdef CONFIG_SMP
1991 { PMAC_FTR_RESET_CPU, core99_reset_cpu },
1992#endif /* CONFIG_SMP */
1993 { PMAC_FTR_READ_GPIO, core99_read_gpio },
1994 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
1995 { 0, NULL }
1996};
1997
1998/* RackMac
1999 */
2000static struct feature_table_entry rackmac_features[] = {
2001 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
2002 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
2003 { PMAC_FTR_IDE_RESET, core99_ide_reset },
2004 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
2005 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
2006 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
2007 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
2008 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
2009 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
2010#ifdef CONFIG_SMP
2011 { PMAC_FTR_RESET_CPU, core99_reset_cpu },
2012#endif /* CONFIG_SMP */
2013 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2014 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2015 { 0, NULL }
2016};
2017
2018/* Pangea features
2019 */
2020static struct feature_table_entry pangea_features[] = {
2021 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
2022 { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
2023 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
2024 { PMAC_FTR_IDE_RESET, core99_ide_reset },
2025 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
2026 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
2027 { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
2028 { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
2029 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
2030 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
2031 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
2032 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
2033 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2034 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2035 { 0, NULL }
2036};
2037
2038/* Intrepid features
2039 */
2040static struct feature_table_entry intrepid_features[] = {
2041 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
2042 { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
2043 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
2044 { PMAC_FTR_IDE_RESET, core99_ide_reset },
2045 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
2046 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
2047 { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
2048 { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
2049 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
2050 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
2051 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
2052 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
2053 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2054 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2055 { PMAC_FTR_AACK_DELAY_ENABLE, intrepid_aack_delay_enable },
2056 { 0, NULL }
2057};
2058
2059#else /* CONFIG_POWER4 */
2060
2061/* G5 features
2062 */
2063static struct feature_table_entry g5_features[] = {
2064 { PMAC_FTR_GMAC_ENABLE, g5_gmac_enable },
2065 { PMAC_FTR_1394_ENABLE, g5_fw_enable },
2066 { PMAC_FTR_ENABLE_MPIC, g5_mpic_enable },
2067 { PMAC_FTR_GMAC_PHY_RESET, g5_eth_phy_reset },
2068 { PMAC_FTR_SOUND_CHIP_ENABLE, g5_i2s_enable },
2069#ifdef CONFIG_SMP
2070 { PMAC_FTR_RESET_CPU, g5_reset_cpu },
2071#endif /* CONFIG_SMP */
2072 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2073 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2074 { 0, NULL }
2075};
2076
2077#endif /* CONFIG_POWER4 */
2078
2079static struct pmac_mb_def pmac_mb_defs[] = {
2080#ifndef CONFIG_POWER4
2081 /*
2082 * Desktops
2083 */
2084
2085 { "AAPL,8500", "PowerMac 8500/8600",
2086 PMAC_TYPE_PSURGE, NULL,
2087 0
2088 },
2089 { "AAPL,9500", "PowerMac 9500/9600",
2090 PMAC_TYPE_PSURGE, NULL,
2091 0
2092 },
2093 { "AAPL,7200", "PowerMac 7200",
2094 PMAC_TYPE_PSURGE, NULL,
2095 0
2096 },
2097 { "AAPL,7300", "PowerMac 7200/7300",
2098 PMAC_TYPE_PSURGE, NULL,
2099 0
2100 },
2101 { "AAPL,7500", "PowerMac 7500",
2102 PMAC_TYPE_PSURGE, NULL,
2103 0
2104 },
2105 { "AAPL,ShinerESB", "Apple Network Server",
2106 PMAC_TYPE_ANS, NULL,
2107 0
2108 },
2109 { "AAPL,e407", "Alchemy",
2110 PMAC_TYPE_ALCHEMY, NULL,
2111 0
2112 },
2113 { "AAPL,e411", "Gazelle",
2114 PMAC_TYPE_GAZELLE, NULL,
2115 0
2116 },
2117 { "AAPL,Gossamer", "PowerMac G3 (Gossamer)",
2118 PMAC_TYPE_GOSSAMER, heathrow_desktop_features,
2119 0
2120 },
2121 { "AAPL,PowerMac G3", "PowerMac G3 (Silk)",
2122 PMAC_TYPE_SILK, heathrow_desktop_features,
2123 0
2124 },
2125 { "PowerMac1,1", "Blue&White G3",
2126 PMAC_TYPE_YOSEMITE, paddington_features,
2127 0
2128 },
2129 { "PowerMac1,2", "PowerMac G4 PCI Graphics",
2130 PMAC_TYPE_YIKES, paddington_features,
2131 0
2132 },
2133 { "PowerMac2,1", "iMac FireWire",
2134 PMAC_TYPE_FW_IMAC, core99_features,
2135 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2136 },
2137 { "PowerMac2,2", "iMac FireWire",
2138 PMAC_TYPE_FW_IMAC, core99_features,
2139 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2140 },
2141 { "PowerMac3,1", "PowerMac G4 AGP Graphics",
2142 PMAC_TYPE_SAWTOOTH, core99_features,
2143 PMAC_MB_OLD_CORE99
2144 },
2145 { "PowerMac3,2", "PowerMac G4 AGP Graphics",
2146 PMAC_TYPE_SAWTOOTH, core99_features,
2147 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2148 },
2149 { "PowerMac3,3", "PowerMac G4 AGP Graphics",
2150 PMAC_TYPE_SAWTOOTH, core99_features,
2151 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2152 },
2153 { "PowerMac3,4", "PowerMac G4 Silver",
2154 PMAC_TYPE_QUICKSILVER, core99_features,
2155 PMAC_MB_MAY_SLEEP
2156 },
2157 { "PowerMac3,5", "PowerMac G4 Silver",
2158 PMAC_TYPE_QUICKSILVER, core99_features,
2159 PMAC_MB_MAY_SLEEP
2160 },
2161 { "PowerMac3,6", "PowerMac G4 Windtunnel",
2162 PMAC_TYPE_WINDTUNNEL, core99_features,
2163 PMAC_MB_MAY_SLEEP,
2164 },
2165 { "PowerMac4,1", "iMac \"Flower Power\"",
2166 PMAC_TYPE_PANGEA_IMAC, pangea_features,
2167 PMAC_MB_MAY_SLEEP
2168 },
2169 { "PowerMac4,2", "Flat panel iMac",
2170 PMAC_TYPE_FLAT_PANEL_IMAC, pangea_features,
2171 PMAC_MB_CAN_SLEEP
2172 },
2173 { "PowerMac4,4", "eMac",
2174 PMAC_TYPE_EMAC, core99_features,
2175 PMAC_MB_MAY_SLEEP
2176 },
2177 { "PowerMac5,1", "PowerMac G4 Cube",
2178 PMAC_TYPE_CUBE, core99_features,
2179 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2180 },
2181 { "PowerMac6,1", "Flat panel iMac",
2182 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2183 PMAC_MB_MAY_SLEEP,
2184 },
2185 { "PowerMac6,3", "Flat panel iMac",
2186 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2187 PMAC_MB_MAY_SLEEP,
2188 },
2189 { "PowerMac6,4", "eMac",
2190 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2191 PMAC_MB_MAY_SLEEP,
2192 },
2193 { "PowerMac10,1", "Mac mini",
2194 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2195 PMAC_MB_MAY_SLEEP,
2196 },
2197 { "PowerMac10,2", "Mac mini (Late 2005)",
2198 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2199 PMAC_MB_MAY_SLEEP,
2200 },
2201 { "iMac,1", "iMac (first generation)",
2202 PMAC_TYPE_ORIG_IMAC, paddington_features,
2203 0
2204 },
2205
2206 /*
2207 * Xserve's
2208 */
2209
2210 { "RackMac1,1", "XServe",
2211 PMAC_TYPE_RACKMAC, rackmac_features,
2212 0,
2213 },
2214 { "RackMac1,2", "XServe rev. 2",
2215 PMAC_TYPE_RACKMAC, rackmac_features,
2216 0,
2217 },
2218
2219 /*
2220 * Laptops
2221 */
2222
2223 { "AAPL,3400/2400", "PowerBook 3400",
2224 PMAC_TYPE_HOOPER, ohare_features,
2225 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2226 },
2227 { "AAPL,3500", "PowerBook 3500",
2228 PMAC_TYPE_KANGA, ohare_features,
2229 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2230 },
2231 { "AAPL,PowerBook1998", "PowerBook Wallstreet",
2232 PMAC_TYPE_WALLSTREET, heathrow_laptop_features,
2233 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2234 },
2235 { "PowerBook1,1", "PowerBook 101 (Lombard)",
2236 PMAC_TYPE_101_PBOOK, paddington_features,
2237 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2238 },
2239 { "PowerBook2,1", "iBook (first generation)",
2240 PMAC_TYPE_ORIG_IBOOK, core99_features,
2241 PMAC_MB_CAN_SLEEP | PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
2242 },
2243 { "PowerBook2,2", "iBook FireWire",
2244 PMAC_TYPE_FW_IBOOK, core99_features,
2245 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
2246 PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
2247 },
2248 { "PowerBook3,1", "PowerBook Pismo",
2249 PMAC_TYPE_PISMO, core99_features,
2250 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
2251 PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
2252 },
2253 { "PowerBook3,2", "PowerBook Titanium",
2254 PMAC_TYPE_TITANIUM, core99_features,
2255 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2256 },
2257 { "PowerBook3,3", "PowerBook Titanium II",
2258 PMAC_TYPE_TITANIUM2, core99_features,
2259 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2260 },
2261 { "PowerBook3,4", "PowerBook Titanium III",
2262 PMAC_TYPE_TITANIUM3, core99_features,
2263 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2264 },
2265 { "PowerBook3,5", "PowerBook Titanium IV",
2266 PMAC_TYPE_TITANIUM4, core99_features,
2267 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2268 },
2269 { "PowerBook4,1", "iBook 2",
2270 PMAC_TYPE_IBOOK2, pangea_features,
2271 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2272 },
2273 { "PowerBook4,2", "iBook 2",
2274 PMAC_TYPE_IBOOK2, pangea_features,
2275 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2276 },
2277 { "PowerBook4,3", "iBook 2 rev. 2",
2278 PMAC_TYPE_IBOOK2, pangea_features,
2279 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2280 },
2281 { "PowerBook5,1", "PowerBook G4 17\"",
2282 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2283 PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2284 },
2285 { "PowerBook5,2", "PowerBook G4 15\"",
2286 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2287 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2288 },
2289 { "PowerBook5,3", "PowerBook G4 17\"",
2290 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2291 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2292 },
2293 { "PowerBook5,4", "PowerBook G4 15\"",
2294 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2295 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2296 },
2297 { "PowerBook5,5", "PowerBook G4 17\"",
2298 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2299 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2300 },
2301 { "PowerBook5,6", "PowerBook G4 15\"",
2302 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2303 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2304 },
2305 { "PowerBook5,7", "PowerBook G4 17\"",
2306 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2307 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2308 },
2309 { "PowerBook5,8", "PowerBook G4 15\"",
2310 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2311 PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
2312 },
2313 { "PowerBook5,9", "PowerBook G4 17\"",
2314 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2315 PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
2316 },
2317 { "PowerBook6,1", "PowerBook G4 12\"",
2318 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2319 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2320 },
2321 { "PowerBook6,2", "PowerBook G4",
2322 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2323 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2324 },
2325 { "PowerBook6,3", "iBook G4",
2326 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2327 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2328 },
2329 { "PowerBook6,4", "PowerBook G4 12\"",
2330 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2331 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2332 },
2333 { "PowerBook6,5", "iBook G4",
2334 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2335 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2336 },
2337 { "PowerBook6,7", "iBook G4",
2338 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2339 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2340 },
2341 { "PowerBook6,8", "PowerBook G4 12\"",
2342 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2343 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2344 },
2345#else /* CONFIG_POWER4 */
2346 { "PowerMac7,2", "PowerMac G5",
2347 PMAC_TYPE_POWERMAC_G5, g5_features,
2348 0,
2349 },
2350#ifdef CONFIG_PPC64
2351 { "PowerMac7,3", "PowerMac G5",
2352 PMAC_TYPE_POWERMAC_G5, g5_features,
2353 0,
2354 },
2355 { "PowerMac8,1", "iMac G5",
2356 PMAC_TYPE_IMAC_G5, g5_features,
2357 0,
2358 },
2359 { "PowerMac9,1", "PowerMac G5",
2360 PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
2361 0,
2362 },
2363 { "PowerMac11,2", "PowerMac G5 Dual Core",
2364 PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
2365 0,
2366 },
2367 { "PowerMac12,1", "iMac G5 (iSight)",
2368 PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
2369 0,
2370 },
2371 { "RackMac3,1", "XServe G5",
2372 PMAC_TYPE_XSERVE_G5, g5_features,
2373 0,
2374 },
2375#endif /* CONFIG_PPC64 */
2376#endif /* CONFIG_POWER4 */
2377};
2378
2379/*
2380 * The toplevel feature_call callback
2381 */
2382long pmac_do_feature_call(unsigned int selector, ...)
2383{
2384 struct device_node *node;
2385 long param, value;
2386 int i;
2387 feature_call func = NULL;
2388 va_list args;
2389
2390 if (pmac_mb.features)
2391 for (i=0; pmac_mb.features[i].function; i++)
2392 if (pmac_mb.features[i].selector == selector) {
2393 func = pmac_mb.features[i].function;
2394 break;
2395 }
2396 if (!func)
2397 for (i=0; any_features[i].function; i++)
2398 if (any_features[i].selector == selector) {
2399 func = any_features[i].function;
2400 break;
2401 }
2402 if (!func)
2403 return -ENODEV;
2404
2405 va_start(args, selector);
2406 node = (struct device_node*)va_arg(args, void*);
2407 param = va_arg(args, long);
2408 value = va_arg(args, long);
2409 va_end(args);
2410
2411 return func(node, param, value);
2412}
2413
2414static int __init probe_motherboard(void)
2415{
2416 int i;
2417 struct macio_chip *macio = &macio_chips[0];
2418 const char *model = NULL;
2419 struct device_node *dt;
2420 int ret = 0;
2421
2422 /* Lookup known motherboard type in device-tree. First try an
2423 * exact match on the "model" property, then try a "compatible"
2424 * match is none is found.
2425 */
2426 dt = of_find_node_by_name(NULL, "device-tree");
2427 if (dt != NULL)
2428 model = of_get_property(dt, "model", NULL);
2429 for(i=0; model && i<ARRAY_SIZE(pmac_mb_defs); i++) {
2430 if (strcmp(model, pmac_mb_defs[i].model_string) == 0) {
2431 pmac_mb = pmac_mb_defs[i];
2432 goto found;
2433 }
2434 }
2435 for(i=0; i<ARRAY_SIZE(pmac_mb_defs); i++) {
2436 if (of_machine_is_compatible(pmac_mb_defs[i].model_string)) {
2437 pmac_mb = pmac_mb_defs[i];
2438 goto found;
2439 }
2440 }
2441
2442 /* Fallback to selection depending on mac-io chip type */
2443 switch(macio->type) {
2444#ifndef CONFIG_POWER4
2445 case macio_grand_central:
2446 pmac_mb.model_id = PMAC_TYPE_PSURGE;
2447 pmac_mb.model_name = "Unknown PowerSurge";
2448 break;
2449 case macio_ohare:
2450 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_OHARE;
2451 pmac_mb.model_name = "Unknown OHare-based";
2452 break;
2453 case macio_heathrow:
2454 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_HEATHROW;
2455 pmac_mb.model_name = "Unknown Heathrow-based";
2456 pmac_mb.features = heathrow_desktop_features;
2457 break;
2458 case macio_paddington:
2459 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PADDINGTON;
2460 pmac_mb.model_name = "Unknown Paddington-based";
2461 pmac_mb.features = paddington_features;
2462 break;
2463 case macio_keylargo:
2464 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_CORE99;
2465 pmac_mb.model_name = "Unknown Keylargo-based";
2466 pmac_mb.features = core99_features;
2467 break;
2468 case macio_pangea:
2469 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PANGEA;
2470 pmac_mb.model_name = "Unknown Pangea-based";
2471 pmac_mb.features = pangea_features;
2472 break;
2473 case macio_intrepid:
2474 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_INTREPID;
2475 pmac_mb.model_name = "Unknown Intrepid-based";
2476 pmac_mb.features = intrepid_features;
2477 break;
2478#else /* CONFIG_POWER4 */
2479 case macio_keylargo2:
2480 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_K2;
2481 pmac_mb.model_name = "Unknown K2-based";
2482 pmac_mb.features = g5_features;
2483 break;
2484 case macio_shasta:
2485 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_SHASTA;
2486 pmac_mb.model_name = "Unknown Shasta-based";
2487 pmac_mb.features = g5_features;
2488 break;
2489#endif /* CONFIG_POWER4 */
2490 default:
2491 ret = -ENODEV;
2492 goto done;
2493 }
2494found:
2495#ifndef CONFIG_POWER4
2496 /* Fixup Hooper vs. Comet */
2497 if (pmac_mb.model_id == PMAC_TYPE_HOOPER) {
2498 u32 __iomem * mach_id_ptr = ioremap(0xf3000034, 4);
2499 if (!mach_id_ptr) {
2500 ret = -ENODEV;
2501 goto done;
2502 }
2503 /* Here, I used to disable the media-bay on comet. It
2504 * appears this is wrong, the floppy connector is actually
2505 * a kind of media-bay and works with the current driver.
2506 */
2507 if (__raw_readl(mach_id_ptr) & 0x20000000UL)
2508 pmac_mb.model_id = PMAC_TYPE_COMET;
2509 iounmap(mach_id_ptr);
2510 }
2511
2512 /* Set default value of powersave_nap on machines that support it.
2513 * It appears that uninorth rev 3 has a problem with it, we don't
2514 * enable it on those. In theory, the flush-on-lock property is
2515 * supposed to be set when not supported, but I'm not very confident
2516 * that all Apple OF revs did it properly, I do it the paranoid way.
2517 */
2518 while (uninorth_base && uninorth_rev > 3) {
2519 struct device_node *cpus = of_find_node_by_path("/cpus");
2520 struct device_node *np;
2521
2522 if (!cpus || !cpus->child) {
2523 printk(KERN_WARNING "Can't find CPU(s) in device tree !\n");
2524 of_node_put(cpus);
2525 break;
2526 }
2527 np = cpus->child;
2528 /* Nap mode not supported on SMP */
2529 if (np->sibling) {
2530 of_node_put(cpus);
2531 break;
2532 }
2533 /* Nap mode not supported if flush-on-lock property is present */
2534 if (of_get_property(np, "flush-on-lock", NULL)) {
2535 of_node_put(cpus);
2536 break;
2537 }
2538 of_node_put(cpus);
2539 powersave_nap = 1;
2540 printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n");
2541 break;
2542 }
2543
2544 /* On CPUs that support it (750FX), lowspeed by default during
2545 * NAP mode
2546 */
2547 powersave_lowspeed = 1;
2548
2549#else /* CONFIG_POWER4 */
2550 powersave_nap = 1;
2551#endif /* CONFIG_POWER4 */
2552
2553 /* Check for "mobile" machine */
2554 if (model && (strncmp(model, "PowerBook", 9) == 0
2555 || strncmp(model, "iBook", 5) == 0))
2556 pmac_mb.board_flags |= PMAC_MB_MOBILE;
2557
2558
2559 printk(KERN_INFO "PowerMac motherboard: %s\n", pmac_mb.model_name);
2560done:
2561 of_node_put(dt);
2562 return ret;
2563}
2564
2565/* Initialize the Core99 UniNorth host bridge and memory controller
2566 */
2567static void __init probe_uninorth(void)
2568{
2569 const u32 *addrp;
2570 phys_addr_t address;
2571 unsigned long actrl;
2572
2573 /* Locate core99 Uni-N */
2574 uninorth_node = of_find_node_by_name(NULL, "uni-n");
2575 uninorth_maj = 1;
2576
2577 /* Locate G5 u3 */
2578 if (uninorth_node == NULL) {
2579 uninorth_node = of_find_node_by_name(NULL, "u3");
2580 uninorth_maj = 3;
2581 }
2582 /* Locate G5 u4 */
2583 if (uninorth_node == NULL) {
2584 uninorth_node = of_find_node_by_name(NULL, "u4");
2585 uninorth_maj = 4;
2586 }
2587 if (uninorth_node == NULL) {
2588 uninorth_maj = 0;
2589 return;
2590 }
2591
2592 addrp = of_get_property(uninorth_node, "reg", NULL);
2593 if (addrp == NULL)
2594 return;
2595 address = of_translate_address(uninorth_node, addrp);
2596 if (address == 0)
2597 return;
2598 uninorth_base = ioremap(address, 0x40000);
2599 if (uninorth_base == NULL)
2600 return;
2601 uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
2602 if (uninorth_maj == 3 || uninorth_maj == 4) {
2603 u3_ht_base = ioremap(address + U3_HT_CONFIG_BASE, 0x1000);
2604 if (u3_ht_base == NULL) {
2605 iounmap(uninorth_base);
2606 return;
2607 }
2608 }
2609
2610 printk(KERN_INFO "Found %s memory controller & host bridge"
2611 " @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :
2612 uninorth_maj == 4 ? "U4" : "UniNorth",
2613 (unsigned int)address, uninorth_rev);
2614 printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);
2615
2616 /* Set the arbitrer QAck delay according to what Apple does
2617 */
2618 if (uninorth_rev < 0x11) {
2619 actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;
2620 actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :
2621 UNI_N_ARB_CTRL_QACK_DELAY) <<
2622 UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
2623 UN_OUT(UNI_N_ARB_CTRL, actrl);
2624 }
2625
2626 /* Some more magic as done by them in recent MacOS X on UniNorth
2627 * revs 1.5 to 2.O and Pangea. Seem to toggle the UniN Maxbus/PCI
2628 * memory timeout
2629 */
2630 if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) ||
2631 uninorth_rev == 0xc0)
2632 UN_OUT(0x2160, UN_IN(0x2160) & 0x00ffffff);
2633}
2634
2635static void __init probe_one_macio(const char *name, const char *compat, int type)
2636{
2637 struct device_node* node;
2638 int i;
2639 volatile u32 __iomem *base;
2640 const u32 *addrp, *revp;
2641 phys_addr_t addr;
2642 u64 size;
2643
2644 for (node = NULL; (node = of_find_node_by_name(node, name)) != NULL;) {
2645 if (!compat)
2646 break;
2647 if (of_device_is_compatible(node, compat))
2648 break;
2649 }
2650 if (!node)
2651 return;
2652 for(i=0; i<MAX_MACIO_CHIPS; i++) {
2653 if (!macio_chips[i].of_node)
2654 break;
2655 if (macio_chips[i].of_node == node)
2656 return;
2657 }
2658
2659 if (i >= MAX_MACIO_CHIPS) {
2660 printk(KERN_ERR "pmac_feature: Please increase MAX_MACIO_CHIPS !\n");
2661 printk(KERN_ERR "pmac_feature: %s skipped\n", node->full_name);
2662 return;
2663 }
2664 addrp = of_get_pci_address(node, 0, &size, NULL);
2665 if (addrp == NULL) {
2666 printk(KERN_ERR "pmac_feature: %s: can't find base !\n",
2667 node->full_name);
2668 return;
2669 }
2670 addr = of_translate_address(node, addrp);
2671 if (addr == 0) {
2672 printk(KERN_ERR "pmac_feature: %s, can't translate base !\n",
2673 node->full_name);
2674 return;
2675 }
2676 base = ioremap(addr, (unsigned long)size);
2677 if (!base) {
2678 printk(KERN_ERR "pmac_feature: %s, can't map mac-io chip !\n",
2679 node->full_name);
2680 return;
2681 }
2682 if (type == macio_keylargo || type == macio_keylargo2) {
2683 const u32 *did = of_get_property(node, "device-id", NULL);
2684 if (*did == 0x00000025)
2685 type = macio_pangea;
2686 if (*did == 0x0000003e)
2687 type = macio_intrepid;
2688 if (*did == 0x0000004f)
2689 type = macio_shasta;
2690 }
2691 macio_chips[i].of_node = node;
2692 macio_chips[i].type = type;
2693 macio_chips[i].base = base;
2694 macio_chips[i].flags = MACIO_FLAG_SCCA_ON | MACIO_FLAG_SCCB_ON;
2695 macio_chips[i].name = macio_names[type];
2696 revp = of_get_property(node, "revision-id", NULL);
2697 if (revp)
2698 macio_chips[i].rev = *revp;
2699 printk(KERN_INFO "Found a %s mac-io controller, rev: %d, mapped at 0x%p\n",
2700 macio_names[type], macio_chips[i].rev, macio_chips[i].base);
2701}
2702
2703static int __init
2704probe_macios(void)
2705{
2706 /* Warning, ordering is important */
2707 probe_one_macio("gc", NULL, macio_grand_central);
2708 probe_one_macio("ohare", NULL, macio_ohare);
2709 probe_one_macio("pci106b,7", NULL, macio_ohareII);
2710 probe_one_macio("mac-io", "keylargo", macio_keylargo);
2711 probe_one_macio("mac-io", "paddington", macio_paddington);
2712 probe_one_macio("mac-io", "gatwick", macio_gatwick);
2713 probe_one_macio("mac-io", "heathrow", macio_heathrow);
2714 probe_one_macio("mac-io", "K2-Keylargo", macio_keylargo2);
2715
2716 /* Make sure the "main" macio chip appear first */
2717 if (macio_chips[0].type == macio_gatwick
2718 && macio_chips[1].type == macio_heathrow) {
2719 struct macio_chip temp = macio_chips[0];
2720 macio_chips[0] = macio_chips[1];
2721 macio_chips[1] = temp;
2722 }
2723 if (macio_chips[0].type == macio_ohareII
2724 && macio_chips[1].type == macio_ohare) {
2725 struct macio_chip temp = macio_chips[0];
2726 macio_chips[0] = macio_chips[1];
2727 macio_chips[1] = temp;
2728 }
2729 macio_chips[0].lbus.index = 0;
2730 macio_chips[1].lbus.index = 1;
2731
2732 return (macio_chips[0].of_node == NULL) ? -ENODEV : 0;
2733}
2734
2735static void __init
2736initial_serial_shutdown(struct device_node *np)
2737{
2738 int len;
2739 const struct slot_names_prop {
2740 int count;
2741 char name[1];
2742 } *slots;
2743 const char *conn;
2744 int port_type = PMAC_SCC_ASYNC;
2745 int modem = 0;
2746
2747 slots = of_get_property(np, "slot-names", &len);
2748 conn = of_get_property(np, "AAPL,connector", &len);
2749 if (conn && (strcmp(conn, "infrared") == 0))
2750 port_type = PMAC_SCC_IRDA;
2751 else if (of_device_is_compatible(np, "cobalt"))
2752 modem = 1;
2753 else if (slots && slots->count > 0) {
2754 if (strcmp(slots->name, "IrDA") == 0)
2755 port_type = PMAC_SCC_IRDA;
2756 else if (strcmp(slots->name, "Modem") == 0)
2757 modem = 1;
2758 }
2759 if (modem)
2760 pmac_call_feature(PMAC_FTR_MODEM_ENABLE, np, 0, 0);
2761 pmac_call_feature(PMAC_FTR_SCC_ENABLE, np, port_type, 0);
2762}
2763
2764static void __init
2765set_initial_features(void)
2766{
2767 struct device_node *np;
2768
2769 /* That hack appears to be necessary for some StarMax motherboards
2770 * but I'm not too sure it was audited for side-effects on other
2771 * ohare based machines...
2772 * Since I still have difficulties figuring the right way to
2773 * differenciate them all and since that hack was there for a long
2774 * time, I'll keep it around
2775 */
2776 if (macio_chips[0].type == macio_ohare) {
2777 struct macio_chip *macio = &macio_chips[0];
2778 np = of_find_node_by_name(NULL, "via-pmu");
2779 if (np)
2780 MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
2781 else
2782 MACIO_OUT32(OHARE_FCR, STARMAX_FEATURES);
2783 of_node_put(np);
2784 } else if (macio_chips[1].type == macio_ohare) {
2785 struct macio_chip *macio = &macio_chips[1];
2786 MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
2787 }
2788
2789#ifdef CONFIG_POWER4
2790 if (macio_chips[0].type == macio_keylargo2 ||
2791 macio_chips[0].type == macio_shasta) {
2792#ifndef CONFIG_SMP
2793 /* On SMP machines running UP, we have the second CPU eating
2794 * bus cycles. We need to take it off the bus. This is done
2795 * from pmac_smp for SMP kernels running on one CPU
2796 */
2797 np = of_find_node_by_type(NULL, "cpu");
2798 if (np != NULL)
2799 np = of_find_node_by_type(np, "cpu");
2800 if (np != NULL) {
2801 g5_phy_disable_cpu1();
2802 of_node_put(np);
2803 }
2804#endif /* CONFIG_SMP */
2805 /* Enable GMAC for now for PCI probing. It will be disabled
2806 * later on after PCI probe
2807 */
2808 np = of_find_node_by_name(NULL, "ethernet");
2809 while(np) {
2810 if (of_device_is_compatible(np, "K2-GMAC"))
2811 g5_gmac_enable(np, 0, 1);
2812 np = of_find_node_by_name(np, "ethernet");
2813 }
2814
2815 /* Enable FW before PCI probe. Will be disabled later on
2816 * Note: We should have a batter way to check that we are
2817 * dealing with uninorth internal cell and not a PCI cell
2818 * on the external PCI. The code below works though.
2819 */
2820 np = of_find_node_by_name(NULL, "firewire");
2821 while(np) {
2822 if (of_device_is_compatible(np, "pci106b,5811")) {
2823 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
2824 g5_fw_enable(np, 0, 1);
2825 }
2826 np = of_find_node_by_name(np, "firewire");
2827 }
2828 }
2829#else /* CONFIG_POWER4 */
2830
2831 if (macio_chips[0].type == macio_keylargo ||
2832 macio_chips[0].type == macio_pangea ||
2833 macio_chips[0].type == macio_intrepid) {
2834 /* Enable GMAC for now for PCI probing. It will be disabled
2835 * later on after PCI probe
2836 */
2837 np = of_find_node_by_name(NULL, "ethernet");
2838 while(np) {
2839 if (np->parent
2840 && of_device_is_compatible(np->parent, "uni-north")
2841 && of_device_is_compatible(np, "gmac"))
2842 core99_gmac_enable(np, 0, 1);
2843 np = of_find_node_by_name(np, "ethernet");
2844 }
2845
2846 /* Enable FW before PCI probe. Will be disabled later on
2847 * Note: We should have a batter way to check that we are
2848 * dealing with uninorth internal cell and not a PCI cell
2849 * on the external PCI. The code below works though.
2850 */
2851 np = of_find_node_by_name(NULL, "firewire");
2852 while(np) {
2853 if (np->parent
2854 && of_device_is_compatible(np->parent, "uni-north")
2855 && (of_device_is_compatible(np, "pci106b,18") ||
2856 of_device_is_compatible(np, "pci106b,30") ||
2857 of_device_is_compatible(np, "pci11c1,5811"))) {
2858 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
2859 core99_firewire_enable(np, 0, 1);
2860 }
2861 np = of_find_node_by_name(np, "firewire");
2862 }
2863
2864 /* Enable ATA-100 before PCI probe. */
2865 np = of_find_node_by_name(NULL, "ata-6");
2866 while(np) {
2867 if (np->parent
2868 && of_device_is_compatible(np->parent, "uni-north")
2869 && of_device_is_compatible(np, "kauai-ata")) {
2870 core99_ata100_enable(np, 1);
2871 }
2872 np = of_find_node_by_name(np, "ata-6");
2873 }
2874
2875 /* Switch airport off */
2876 for_each_node_by_name(np, "radio") {
2877 if (np->parent == macio_chips[0].of_node) {
2878 macio_chips[0].flags |= MACIO_FLAG_AIRPORT_ON;
2879 core99_airport_enable(np, 0, 0);
2880 }
2881 }
2882 }
2883
2884 /* On all machines that support sound PM, switch sound off */
2885 if (macio_chips[0].of_node)
2886 pmac_do_feature_call(PMAC_FTR_SOUND_CHIP_ENABLE,
2887 macio_chips[0].of_node, 0, 0);
2888
2889 /* While on some desktop G3s, we turn it back on */
2890 if (macio_chips[0].of_node && macio_chips[0].type == macio_heathrow
2891 && (pmac_mb.model_id == PMAC_TYPE_GOSSAMER ||
2892 pmac_mb.model_id == PMAC_TYPE_SILK)) {
2893 struct macio_chip *macio = &macio_chips[0];
2894 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
2895 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
2896 }
2897
2898#endif /* CONFIG_POWER4 */
2899
2900 /* On all machines, switch modem & serial ports off */
2901 for_each_node_by_name(np, "ch-a")
2902 initial_serial_shutdown(np);
2903 of_node_put(np);
2904 for_each_node_by_name(np, "ch-b")
2905 initial_serial_shutdown(np);
2906 of_node_put(np);
2907}
2908
2909void __init
2910pmac_feature_init(void)
2911{
2912 /* Detect the UniNorth memory controller */
2913 probe_uninorth();
2914
2915 /* Probe mac-io controllers */
2916 if (probe_macios()) {
2917 printk(KERN_WARNING "No mac-io chip found\n");
2918 return;
2919 }
2920
2921 /* Probe machine type */
2922 if (probe_motherboard())
2923 printk(KERN_WARNING "Unknown PowerMac !\n");
2924
2925 /* Set some initial features (turn off some chips that will
2926 * be later turned on)
2927 */
2928 set_initial_features();
2929}
2930
2931#if 0
2932static void dump_HT_speeds(char *name, u32 cfg, u32 frq)
2933{
2934 int freqs[16] = { 200,300,400,500,600,800,1000,0,0,0,0,0,0,0,0,0 };
2935 int bits[8] = { 8,16,0,32,2,4,0,0 };
2936 int freq = (frq >> 8) & 0xf;
2937
2938 if (freqs[freq] == 0)
2939 printk("%s: Unknown HT link frequency %x\n", name, freq);
2940 else
2941 printk("%s: %d MHz on main link, (%d in / %d out) bits width\n",
2942 name, freqs[freq],
2943 bits[(cfg >> 28) & 0x7], bits[(cfg >> 24) & 0x7]);
2944}
2945
2946void __init pmac_check_ht_link(void)
2947{
2948 u32 ufreq, freq, ucfg, cfg;
2949 struct device_node *pcix_node;
2950 u8 px_bus, px_devfn;
2951 struct pci_controller *px_hose;
2952
2953 (void)in_be32(u3_ht_base + U3_HT_LINK_COMMAND);
2954 ucfg = cfg = in_be32(u3_ht_base + U3_HT_LINK_CONFIG);
2955 ufreq = freq = in_be32(u3_ht_base + U3_HT_LINK_FREQ);
2956 dump_HT_speeds("U3 HyperTransport", cfg, freq);
2957
2958 pcix_node = of_find_compatible_node(NULL, "pci", "pci-x");
2959 if (pcix_node == NULL) {
2960 printk("No PCI-X bridge found\n");
2961 return;
2962 }
2963 if (pci_device_from_OF_node(pcix_node, &px_bus, &px_devfn) != 0) {
2964 printk("PCI-X bridge found but not matched to pci\n");
2965 return;
2966 }
2967 px_hose = pci_find_hose_for_OF_device(pcix_node);
2968 if (px_hose == NULL) {
2969 printk("PCI-X bridge found but not matched to host\n");
2970 return;
2971 }
2972 early_read_config_dword(px_hose, px_bus, px_devfn, 0xc4, &cfg);
2973 early_read_config_dword(px_hose, px_bus, px_devfn, 0xcc, &freq);
2974 dump_HT_speeds("PCI-X HT Uplink", cfg, freq);
2975 early_read_config_dword(px_hose, px_bus, px_devfn, 0xc8, &cfg);
2976 early_read_config_dword(px_hose, px_bus, px_devfn, 0xd0, &freq);
2977 dump_HT_speeds("PCI-X HT Downlink", cfg, freq);
2978}
2979#endif /* 0 */
2980
2981/*
2982 * Early video resume hook
2983 */
2984
2985static void (*pmac_early_vresume_proc)(void *data);
2986static void *pmac_early_vresume_data;
2987
2988void pmac_set_early_video_resume(void (*proc)(void *data), void *data)
2989{
2990 if (!machine_is(powermac))
2991 return;
2992 preempt_disable();
2993 pmac_early_vresume_proc = proc;
2994 pmac_early_vresume_data = data;
2995 preempt_enable();
2996}
2997EXPORT_SYMBOL(pmac_set_early_video_resume);
2998
2999void pmac_call_early_video_resume(void)
3000{
3001 if (pmac_early_vresume_proc)
3002 pmac_early_vresume_proc(pmac_early_vresume_data);
3003}
3004
3005/*
3006 * AGP related suspend/resume code
3007 */
3008
3009static struct pci_dev *pmac_agp_bridge;
3010static int (*pmac_agp_suspend)(struct pci_dev *bridge);
3011static int (*pmac_agp_resume)(struct pci_dev *bridge);
3012
3013void pmac_register_agp_pm(struct pci_dev *bridge,
3014 int (*suspend)(struct pci_dev *bridge),
3015 int (*resume)(struct pci_dev *bridge))
3016{
3017 if (suspend || resume) {
3018 pmac_agp_bridge = bridge;
3019 pmac_agp_suspend = suspend;
3020 pmac_agp_resume = resume;
3021 return;
3022 }
3023 if (bridge != pmac_agp_bridge)
3024 return;
3025 pmac_agp_suspend = pmac_agp_resume = NULL;
3026 return;
3027}
3028EXPORT_SYMBOL(pmac_register_agp_pm);
3029
3030void pmac_suspend_agp_for_card(struct pci_dev *dev)
3031{
3032 if (pmac_agp_bridge == NULL || pmac_agp_suspend == NULL)
3033 return;
3034 if (pmac_agp_bridge->bus != dev->bus)
3035 return;
3036 pmac_agp_suspend(pmac_agp_bridge);
3037}
3038EXPORT_SYMBOL(pmac_suspend_agp_for_card);
3039
3040void pmac_resume_agp_for_card(struct pci_dev *dev)
3041{
3042 if (pmac_agp_bridge == NULL || pmac_agp_resume == NULL)
3043 return;
3044 if (pmac_agp_bridge->bus != dev->bus)
3045 return;
3046 pmac_agp_resume(pmac_agp_bridge);
3047}
3048EXPORT_SYMBOL(pmac_resume_agp_for_card);
3049
3050int pmac_get_uninorth_variant(void)
3051{
3052 return uninorth_maj;
3053}
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au)
4 * Ben. Herrenschmidt (benh@kernel.crashing.org)
5 *
6 * TODO:
7 *
8 * - Replace mdelay with some schedule loop if possible
9 * - Shorten some obfuscated delays on some routines (like modem
10 * power)
11 * - Refcount some clocks (see darwin)
12 * - Split split split...
13 */
14#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/of.h>
20#include <linux/of_address.h>
21#include <linux/spinlock.h>
22#include <linux/adb.h>
23#include <linux/pmu.h>
24#include <linux/ioport.h>
25#include <linux/export.h>
26#include <linux/pci.h>
27#include <asm/sections.h>
28#include <asm/errno.h>
29#include <asm/ohare.h>
30#include <asm/heathrow.h>
31#include <asm/keylargo.h>
32#include <asm/uninorth.h>
33#include <asm/io.h>
34#include <asm/prom.h>
35#include <asm/machdep.h>
36#include <asm/pmac_feature.h>
37#include <asm/dbdma.h>
38#include <asm/pci-bridge.h>
39#include <asm/pmac_low_i2c.h>
40
41#undef DEBUG_FEATURE
42
43#ifdef DEBUG_FEATURE
44#define DBG(fmt...) printk(KERN_DEBUG fmt)
45#else
46#define DBG(fmt...)
47#endif
48
49#ifdef CONFIG_PPC_BOOK3S_32
50extern int powersave_lowspeed;
51#endif
52
53extern int powersave_nap;
54extern struct device_node *k2_skiplist[2];
55
56/*
57 * We use a single global lock to protect accesses. Each driver has
58 * to take care of its own locking
59 */
60DEFINE_RAW_SPINLOCK(feature_lock);
61
62#define LOCK(flags) raw_spin_lock_irqsave(&feature_lock, flags);
63#define UNLOCK(flags) raw_spin_unlock_irqrestore(&feature_lock, flags);
64
65
66/*
67 * Instance of some macio stuffs
68 */
69struct macio_chip macio_chips[MAX_MACIO_CHIPS];
70
71struct macio_chip *macio_find(struct device_node *child, int type)
72{
73 while(child) {
74 int i;
75
76 for (i=0; i < MAX_MACIO_CHIPS && macio_chips[i].of_node; i++)
77 if (child == macio_chips[i].of_node &&
78 (!type || macio_chips[i].type == type))
79 return &macio_chips[i];
80 child = child->parent;
81 }
82 return NULL;
83}
84EXPORT_SYMBOL_GPL(macio_find);
85
86static const char *macio_names[] =
87{
88 "Unknown",
89 "Grand Central",
90 "OHare",
91 "OHareII",
92 "Heathrow",
93 "Gatwick",
94 "Paddington",
95 "Keylargo",
96 "Pangea",
97 "Intrepid",
98 "K2",
99 "Shasta",
100};
101
102
103struct device_node *uninorth_node;
104u32 __iomem *uninorth_base;
105
106static u32 uninorth_rev;
107static int uninorth_maj;
108static void __iomem *u3_ht_base;
109
110/*
111 * For each motherboard family, we have a table of functions pointers
112 * that handle the various features.
113 */
114
115typedef long (*feature_call)(struct device_node *node, long param, long value);
116
117struct feature_table_entry {
118 unsigned int selector;
119 feature_call function;
120};
121
122struct pmac_mb_def
123{
124 const char* model_string;
125 const char* model_name;
126 int model_id;
127 struct feature_table_entry* features;
128 unsigned long board_flags;
129};
130static struct pmac_mb_def pmac_mb;
131
132/*
133 * Here are the chip specific feature functions
134 */
135
136static inline int simple_feature_tweak(struct device_node *node, int type,
137 int reg, u32 mask, int value)
138{
139 struct macio_chip* macio;
140 unsigned long flags;
141
142 macio = macio_find(node, type);
143 if (!macio)
144 return -ENODEV;
145 LOCK(flags);
146 if (value)
147 MACIO_BIS(reg, mask);
148 else
149 MACIO_BIC(reg, mask);
150 (void)MACIO_IN32(reg);
151 UNLOCK(flags);
152
153 return 0;
154}
155
156#ifndef CONFIG_PPC64
157
158static long ohare_htw_scc_enable(struct device_node *node, long param,
159 long value)
160{
161 struct macio_chip* macio;
162 unsigned long chan_mask;
163 unsigned long fcr;
164 unsigned long flags;
165 int htw, trans;
166 unsigned long rmask;
167
168 macio = macio_find(node, 0);
169 if (!macio)
170 return -ENODEV;
171 if (of_node_name_eq(node, "ch-a"))
172 chan_mask = MACIO_FLAG_SCCA_ON;
173 else if (of_node_name_eq(node, "ch-b"))
174 chan_mask = MACIO_FLAG_SCCB_ON;
175 else
176 return -ENODEV;
177
178 htw = (macio->type == macio_heathrow || macio->type == macio_paddington
179 || macio->type == macio_gatwick);
180 /* On these machines, the HRW_SCC_TRANS_EN_N bit mustn't be touched */
181 trans = (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
182 pmac_mb.model_id != PMAC_TYPE_YIKES);
183 if (value) {
184#ifdef CONFIG_ADB_PMU
185 if ((param & 0xfff) == PMAC_SCC_IRDA)
186 pmu_enable_irled(1);
187#endif /* CONFIG_ADB_PMU */
188 LOCK(flags);
189 fcr = MACIO_IN32(OHARE_FCR);
190 /* Check if scc cell need enabling */
191 if (!(fcr & OH_SCC_ENABLE)) {
192 fcr |= OH_SCC_ENABLE;
193 if (htw) {
194 /* Side effect: this will also power up the
195 * modem, but it's too messy to figure out on which
196 * ports this controls the transceiver and on which
197 * it controls the modem
198 */
199 if (trans)
200 fcr &= ~HRW_SCC_TRANS_EN_N;
201 MACIO_OUT32(OHARE_FCR, fcr);
202 fcr |= (rmask = HRW_RESET_SCC);
203 MACIO_OUT32(OHARE_FCR, fcr);
204 } else {
205 fcr |= (rmask = OH_SCC_RESET);
206 MACIO_OUT32(OHARE_FCR, fcr);
207 }
208 UNLOCK(flags);
209 (void)MACIO_IN32(OHARE_FCR);
210 mdelay(15);
211 LOCK(flags);
212 fcr &= ~rmask;
213 MACIO_OUT32(OHARE_FCR, fcr);
214 }
215 if (chan_mask & MACIO_FLAG_SCCA_ON)
216 fcr |= OH_SCCA_IO;
217 if (chan_mask & MACIO_FLAG_SCCB_ON)
218 fcr |= OH_SCCB_IO;
219 MACIO_OUT32(OHARE_FCR, fcr);
220 macio->flags |= chan_mask;
221 UNLOCK(flags);
222 if (param & PMAC_SCC_FLAG_XMON)
223 macio->flags |= MACIO_FLAG_SCC_LOCKED;
224 } else {
225 if (macio->flags & MACIO_FLAG_SCC_LOCKED)
226 return -EPERM;
227 LOCK(flags);
228 fcr = MACIO_IN32(OHARE_FCR);
229 if (chan_mask & MACIO_FLAG_SCCA_ON)
230 fcr &= ~OH_SCCA_IO;
231 if (chan_mask & MACIO_FLAG_SCCB_ON)
232 fcr &= ~OH_SCCB_IO;
233 MACIO_OUT32(OHARE_FCR, fcr);
234 if ((fcr & (OH_SCCA_IO | OH_SCCB_IO)) == 0) {
235 fcr &= ~OH_SCC_ENABLE;
236 if (htw && trans)
237 fcr |= HRW_SCC_TRANS_EN_N;
238 MACIO_OUT32(OHARE_FCR, fcr);
239 }
240 macio->flags &= ~(chan_mask);
241 UNLOCK(flags);
242 mdelay(10);
243#ifdef CONFIG_ADB_PMU
244 if ((param & 0xfff) == PMAC_SCC_IRDA)
245 pmu_enable_irled(0);
246#endif /* CONFIG_ADB_PMU */
247 }
248 return 0;
249}
250
251static long ohare_floppy_enable(struct device_node *node, long param,
252 long value)
253{
254 return simple_feature_tweak(node, macio_ohare,
255 OHARE_FCR, OH_FLOPPY_ENABLE, value);
256}
257
258static long ohare_mesh_enable(struct device_node *node, long param, long value)
259{
260 return simple_feature_tweak(node, macio_ohare,
261 OHARE_FCR, OH_MESH_ENABLE, value);
262}
263
264static long ohare_ide_enable(struct device_node *node, long param, long value)
265{
266 switch(param) {
267 case 0:
268 /* For some reason, setting the bit in set_initial_features()
269 * doesn't stick. I'm still investigating... --BenH.
270 */
271 if (value)
272 simple_feature_tweak(node, macio_ohare,
273 OHARE_FCR, OH_IOBUS_ENABLE, 1);
274 return simple_feature_tweak(node, macio_ohare,
275 OHARE_FCR, OH_IDE0_ENABLE, value);
276 case 1:
277 return simple_feature_tweak(node, macio_ohare,
278 OHARE_FCR, OH_BAY_IDE_ENABLE, value);
279 default:
280 return -ENODEV;
281 }
282}
283
284static long ohare_ide_reset(struct device_node *node, long param, long value)
285{
286 switch(param) {
287 case 0:
288 return simple_feature_tweak(node, macio_ohare,
289 OHARE_FCR, OH_IDE0_RESET_N, !value);
290 case 1:
291 return simple_feature_tweak(node, macio_ohare,
292 OHARE_FCR, OH_IDE1_RESET_N, !value);
293 default:
294 return -ENODEV;
295 }
296}
297
298static long ohare_sleep_state(struct device_node *node, long param, long value)
299{
300 struct macio_chip* macio = &macio_chips[0];
301
302 if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
303 return -EPERM;
304 if (value == 1) {
305 MACIO_BIC(OHARE_FCR, OH_IOBUS_ENABLE);
306 } else if (value == 0) {
307 MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
308 }
309
310 return 0;
311}
312
313static long heathrow_modem_enable(struct device_node *node, long param,
314 long value)
315{
316 struct macio_chip* macio;
317 u8 gpio;
318 unsigned long flags;
319
320 macio = macio_find(node, macio_unknown);
321 if (!macio)
322 return -ENODEV;
323 gpio = MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1;
324 if (!value) {
325 LOCK(flags);
326 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
327 UNLOCK(flags);
328 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
329 mdelay(250);
330 }
331 if (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
332 pmac_mb.model_id != PMAC_TYPE_YIKES) {
333 LOCK(flags);
334 if (value)
335 MACIO_BIC(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
336 else
337 MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
338 UNLOCK(flags);
339 (void)MACIO_IN32(HEATHROW_FCR);
340 mdelay(250);
341 }
342 if (value) {
343 LOCK(flags);
344 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
345 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
346 UNLOCK(flags); mdelay(250); LOCK(flags);
347 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
348 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
349 UNLOCK(flags); mdelay(250); LOCK(flags);
350 MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
351 (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
352 UNLOCK(flags); mdelay(250);
353 }
354 return 0;
355}
356
357static long heathrow_floppy_enable(struct device_node *node, long param,
358 long value)
359{
360 return simple_feature_tweak(node, macio_unknown,
361 HEATHROW_FCR,
362 HRW_SWIM_ENABLE|HRW_BAY_FLOPPY_ENABLE,
363 value);
364}
365
366static long heathrow_mesh_enable(struct device_node *node, long param,
367 long value)
368{
369 struct macio_chip* macio;
370 unsigned long flags;
371
372 macio = macio_find(node, macio_unknown);
373 if (!macio)
374 return -ENODEV;
375 LOCK(flags);
376 /* Set clear mesh cell enable */
377 if (value)
378 MACIO_BIS(HEATHROW_FCR, HRW_MESH_ENABLE);
379 else
380 MACIO_BIC(HEATHROW_FCR, HRW_MESH_ENABLE);
381 (void)MACIO_IN32(HEATHROW_FCR);
382 udelay(10);
383 /* Set/Clear termination power */
384 if (value)
385 MACIO_BIC(HEATHROW_MBCR, 0x04000000);
386 else
387 MACIO_BIS(HEATHROW_MBCR, 0x04000000);
388 (void)MACIO_IN32(HEATHROW_MBCR);
389 udelay(10);
390 UNLOCK(flags);
391
392 return 0;
393}
394
395static long heathrow_ide_enable(struct device_node *node, long param,
396 long value)
397{
398 switch(param) {
399 case 0:
400 return simple_feature_tweak(node, macio_unknown,
401 HEATHROW_FCR, HRW_IDE0_ENABLE, value);
402 case 1:
403 return simple_feature_tweak(node, macio_unknown,
404 HEATHROW_FCR, HRW_BAY_IDE_ENABLE, value);
405 default:
406 return -ENODEV;
407 }
408}
409
410static long heathrow_ide_reset(struct device_node *node, long param,
411 long value)
412{
413 switch(param) {
414 case 0:
415 return simple_feature_tweak(node, macio_unknown,
416 HEATHROW_FCR, HRW_IDE0_RESET_N, !value);
417 case 1:
418 return simple_feature_tweak(node, macio_unknown,
419 HEATHROW_FCR, HRW_IDE1_RESET_N, !value);
420 default:
421 return -ENODEV;
422 }
423}
424
425static long heathrow_bmac_enable(struct device_node *node, long param,
426 long value)
427{
428 struct macio_chip* macio;
429 unsigned long flags;
430
431 macio = macio_find(node, 0);
432 if (!macio)
433 return -ENODEV;
434 if (value) {
435 LOCK(flags);
436 MACIO_BIS(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
437 MACIO_BIS(HEATHROW_FCR, HRW_BMAC_RESET);
438 UNLOCK(flags);
439 (void)MACIO_IN32(HEATHROW_FCR);
440 mdelay(10);
441 LOCK(flags);
442 MACIO_BIC(HEATHROW_FCR, HRW_BMAC_RESET);
443 UNLOCK(flags);
444 (void)MACIO_IN32(HEATHROW_FCR);
445 mdelay(10);
446 } else {
447 LOCK(flags);
448 MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
449 UNLOCK(flags);
450 }
451 return 0;
452}
453
454static long heathrow_sound_enable(struct device_node *node, long param,
455 long value)
456{
457 struct macio_chip* macio;
458 unsigned long flags;
459
460 /* B&W G3 and Yikes don't support that properly (the
461 * sound appear to never come back after being shut down).
462 */
463 if (pmac_mb.model_id == PMAC_TYPE_YOSEMITE ||
464 pmac_mb.model_id == PMAC_TYPE_YIKES)
465 return 0;
466
467 macio = macio_find(node, 0);
468 if (!macio)
469 return -ENODEV;
470 if (value) {
471 LOCK(flags);
472 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
473 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
474 UNLOCK(flags);
475 (void)MACIO_IN32(HEATHROW_FCR);
476 } else {
477 LOCK(flags);
478 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
479 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
480 UNLOCK(flags);
481 }
482 return 0;
483}
484
485static u32 save_fcr[6];
486static u32 save_mbcr;
487static struct dbdma_regs save_dbdma[13];
488static struct dbdma_regs save_alt_dbdma[13];
489
490static void dbdma_save(struct macio_chip *macio, struct dbdma_regs *save)
491{
492 int i;
493
494 /* Save state & config of DBDMA channels */
495 for (i = 0; i < 13; i++) {
496 volatile struct dbdma_regs __iomem * chan = (void __iomem *)
497 (macio->base + ((0x8000+i*0x100)>>2));
498 save[i].cmdptr_hi = in_le32(&chan->cmdptr_hi);
499 save[i].cmdptr = in_le32(&chan->cmdptr);
500 save[i].intr_sel = in_le32(&chan->intr_sel);
501 save[i].br_sel = in_le32(&chan->br_sel);
502 save[i].wait_sel = in_le32(&chan->wait_sel);
503 }
504}
505
506static void dbdma_restore(struct macio_chip *macio, struct dbdma_regs *save)
507{
508 int i;
509
510 /* Save state & config of DBDMA channels */
511 for (i = 0; i < 13; i++) {
512 volatile struct dbdma_regs __iomem * chan = (void __iomem *)
513 (macio->base + ((0x8000+i*0x100)>>2));
514 out_le32(&chan->control, (ACTIVE|DEAD|WAKE|FLUSH|PAUSE|RUN)<<16);
515 while (in_le32(&chan->status) & ACTIVE)
516 mb();
517 out_le32(&chan->cmdptr_hi, save[i].cmdptr_hi);
518 out_le32(&chan->cmdptr, save[i].cmdptr);
519 out_le32(&chan->intr_sel, save[i].intr_sel);
520 out_le32(&chan->br_sel, save[i].br_sel);
521 out_le32(&chan->wait_sel, save[i].wait_sel);
522 }
523}
524
525static void heathrow_sleep(struct macio_chip *macio, int secondary)
526{
527 if (secondary) {
528 dbdma_save(macio, save_alt_dbdma);
529 save_fcr[2] = MACIO_IN32(0x38);
530 save_fcr[3] = MACIO_IN32(0x3c);
531 } else {
532 dbdma_save(macio, save_dbdma);
533 save_fcr[0] = MACIO_IN32(0x38);
534 save_fcr[1] = MACIO_IN32(0x3c);
535 save_mbcr = MACIO_IN32(0x34);
536 /* Make sure sound is shut down */
537 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
538 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
539 /* This seems to be necessary as well or the fan
540 * keeps coming up and battery drains fast */
541 MACIO_BIC(HEATHROW_FCR, HRW_IOBUS_ENABLE);
542 MACIO_BIC(HEATHROW_FCR, HRW_IDE0_RESET_N);
543 /* Make sure eth is down even if module or sleep
544 * won't work properly */
545 MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE | HRW_BMAC_RESET);
546 }
547 /* Make sure modem is shut down */
548 MACIO_OUT8(HRW_GPIO_MODEM_RESET,
549 MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1);
550 MACIO_BIS(HEATHROW_FCR, HRW_SCC_TRANS_EN_N);
551 MACIO_BIC(HEATHROW_FCR, OH_SCCA_IO|OH_SCCB_IO|HRW_SCC_ENABLE);
552
553 /* Let things settle */
554 (void)MACIO_IN32(HEATHROW_FCR);
555}
556
557static void heathrow_wakeup(struct macio_chip *macio, int secondary)
558{
559 if (secondary) {
560 MACIO_OUT32(0x38, save_fcr[2]);
561 (void)MACIO_IN32(0x38);
562 mdelay(1);
563 MACIO_OUT32(0x3c, save_fcr[3]);
564 (void)MACIO_IN32(0x38);
565 mdelay(10);
566 dbdma_restore(macio, save_alt_dbdma);
567 } else {
568 MACIO_OUT32(0x38, save_fcr[0] | HRW_IOBUS_ENABLE);
569 (void)MACIO_IN32(0x38);
570 mdelay(1);
571 MACIO_OUT32(0x3c, save_fcr[1]);
572 (void)MACIO_IN32(0x38);
573 mdelay(1);
574 MACIO_OUT32(0x34, save_mbcr);
575 (void)MACIO_IN32(0x38);
576 mdelay(10);
577 dbdma_restore(macio, save_dbdma);
578 }
579}
580
581static long heathrow_sleep_state(struct device_node *node, long param,
582 long value)
583{
584 if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
585 return -EPERM;
586 if (value == 1) {
587 if (macio_chips[1].type == macio_gatwick)
588 heathrow_sleep(&macio_chips[0], 1);
589 heathrow_sleep(&macio_chips[0], 0);
590 } else if (value == 0) {
591 heathrow_wakeup(&macio_chips[0], 0);
592 if (macio_chips[1].type == macio_gatwick)
593 heathrow_wakeup(&macio_chips[0], 1);
594 }
595 return 0;
596}
597
598static long core99_scc_enable(struct device_node *node, long param, long value)
599{
600 struct macio_chip* macio;
601 unsigned long flags;
602 unsigned long chan_mask;
603 u32 fcr;
604
605 macio = macio_find(node, 0);
606 if (!macio)
607 return -ENODEV;
608 if (of_node_name_eq(node, "ch-a"))
609 chan_mask = MACIO_FLAG_SCCA_ON;
610 else if (of_node_name_eq(node, "ch-b"))
611 chan_mask = MACIO_FLAG_SCCB_ON;
612 else
613 return -ENODEV;
614
615 if (value) {
616 int need_reset_scc = 0;
617 int need_reset_irda = 0;
618
619 LOCK(flags);
620 fcr = MACIO_IN32(KEYLARGO_FCR0);
621 /* Check if scc cell need enabling */
622 if (!(fcr & KL0_SCC_CELL_ENABLE)) {
623 fcr |= KL0_SCC_CELL_ENABLE;
624 need_reset_scc = 1;
625 }
626 if (chan_mask & MACIO_FLAG_SCCA_ON) {
627 fcr |= KL0_SCCA_ENABLE;
628 /* Don't enable line drivers for I2S modem */
629 if ((param & 0xfff) == PMAC_SCC_I2S1)
630 fcr &= ~KL0_SCC_A_INTF_ENABLE;
631 else
632 fcr |= KL0_SCC_A_INTF_ENABLE;
633 }
634 if (chan_mask & MACIO_FLAG_SCCB_ON) {
635 fcr |= KL0_SCCB_ENABLE;
636 /* Perform irda specific inits */
637 if ((param & 0xfff) == PMAC_SCC_IRDA) {
638 fcr &= ~KL0_SCC_B_INTF_ENABLE;
639 fcr |= KL0_IRDA_ENABLE;
640 fcr |= KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE;
641 fcr |= KL0_IRDA_SOURCE1_SEL;
642 fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
643 fcr &= ~(KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
644 need_reset_irda = 1;
645 } else
646 fcr |= KL0_SCC_B_INTF_ENABLE;
647 }
648 MACIO_OUT32(KEYLARGO_FCR0, fcr);
649 macio->flags |= chan_mask;
650 if (need_reset_scc) {
651 MACIO_BIS(KEYLARGO_FCR0, KL0_SCC_RESET);
652 (void)MACIO_IN32(KEYLARGO_FCR0);
653 UNLOCK(flags);
654 mdelay(15);
655 LOCK(flags);
656 MACIO_BIC(KEYLARGO_FCR0, KL0_SCC_RESET);
657 }
658 if (need_reset_irda) {
659 MACIO_BIS(KEYLARGO_FCR0, KL0_IRDA_RESET);
660 (void)MACIO_IN32(KEYLARGO_FCR0);
661 UNLOCK(flags);
662 mdelay(15);
663 LOCK(flags);
664 MACIO_BIC(KEYLARGO_FCR0, KL0_IRDA_RESET);
665 }
666 UNLOCK(flags);
667 if (param & PMAC_SCC_FLAG_XMON)
668 macio->flags |= MACIO_FLAG_SCC_LOCKED;
669 } else {
670 if (macio->flags & MACIO_FLAG_SCC_LOCKED)
671 return -EPERM;
672 LOCK(flags);
673 fcr = MACIO_IN32(KEYLARGO_FCR0);
674 if (chan_mask & MACIO_FLAG_SCCA_ON)
675 fcr &= ~KL0_SCCA_ENABLE;
676 if (chan_mask & MACIO_FLAG_SCCB_ON) {
677 fcr &= ~KL0_SCCB_ENABLE;
678 /* Perform irda specific clears */
679 if ((param & 0xfff) == PMAC_SCC_IRDA) {
680 fcr &= ~KL0_IRDA_ENABLE;
681 fcr &= ~(KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE);
682 fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
683 fcr &= ~(KL0_IRDA_SOURCE1_SEL|KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
684 }
685 }
686 MACIO_OUT32(KEYLARGO_FCR0, fcr);
687 if ((fcr & (KL0_SCCA_ENABLE | KL0_SCCB_ENABLE)) == 0) {
688 fcr &= ~KL0_SCC_CELL_ENABLE;
689 MACIO_OUT32(KEYLARGO_FCR0, fcr);
690 }
691 macio->flags &= ~(chan_mask);
692 UNLOCK(flags);
693 mdelay(10);
694 }
695 return 0;
696}
697
698static long
699core99_modem_enable(struct device_node *node, long param, long value)
700{
701 struct macio_chip* macio;
702 u8 gpio;
703 unsigned long flags;
704
705 /* Hack for internal USB modem */
706 if (node == NULL) {
707 if (macio_chips[0].type != macio_keylargo)
708 return -ENODEV;
709 node = macio_chips[0].of_node;
710 }
711 macio = macio_find(node, 0);
712 if (!macio)
713 return -ENODEV;
714 gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
715 gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
716 gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
717
718 if (!value) {
719 LOCK(flags);
720 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
721 UNLOCK(flags);
722 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
723 mdelay(250);
724 }
725 LOCK(flags);
726 if (value) {
727 MACIO_BIC(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
728 UNLOCK(flags);
729 (void)MACIO_IN32(KEYLARGO_FCR2);
730 mdelay(250);
731 } else {
732 MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
733 UNLOCK(flags);
734 }
735 if (value) {
736 LOCK(flags);
737 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
738 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
739 UNLOCK(flags); mdelay(250); LOCK(flags);
740 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
741 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
742 UNLOCK(flags); mdelay(250); LOCK(flags);
743 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
744 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
745 UNLOCK(flags); mdelay(250);
746 }
747 return 0;
748}
749
750static long
751pangea_modem_enable(struct device_node *node, long param, long value)
752{
753 struct macio_chip* macio;
754 u8 gpio;
755 unsigned long flags;
756
757 /* Hack for internal USB modem */
758 if (node == NULL) {
759 if (macio_chips[0].type != macio_pangea &&
760 macio_chips[0].type != macio_intrepid)
761 return -ENODEV;
762 node = macio_chips[0].of_node;
763 }
764 macio = macio_find(node, 0);
765 if (!macio)
766 return -ENODEV;
767 gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
768 gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
769 gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
770
771 if (!value) {
772 LOCK(flags);
773 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
774 UNLOCK(flags);
775 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
776 mdelay(250);
777 }
778 LOCK(flags);
779 if (value) {
780 MACIO_OUT8(KL_GPIO_MODEM_POWER,
781 KEYLARGO_GPIO_OUTPUT_ENABLE);
782 UNLOCK(flags);
783 (void)MACIO_IN32(KEYLARGO_FCR2);
784 mdelay(250);
785 } else {
786 MACIO_OUT8(KL_GPIO_MODEM_POWER,
787 KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
788 UNLOCK(flags);
789 }
790 if (value) {
791 LOCK(flags);
792 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
793 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
794 UNLOCK(flags); mdelay(250); LOCK(flags);
795 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
796 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
797 UNLOCK(flags); mdelay(250); LOCK(flags);
798 MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
799 (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
800 UNLOCK(flags); mdelay(250);
801 }
802 return 0;
803}
804
805static long
806core99_ata100_enable(struct device_node *node, long value)
807{
808 unsigned long flags;
809 struct pci_dev *pdev = NULL;
810 u8 pbus, pid;
811 int rc;
812
813 if (uninorth_rev < 0x24)
814 return -ENODEV;
815
816 LOCK(flags);
817 if (value)
818 UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);
819 else
820 UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_ATA100);
821 (void)UN_IN(UNI_N_CLOCK_CNTL);
822 UNLOCK(flags);
823 udelay(20);
824
825 if (value) {
826 if (pci_device_from_OF_node(node, &pbus, &pid) == 0)
827 pdev = pci_get_domain_bus_and_slot(0, pbus, pid);
828 if (pdev == NULL)
829 return 0;
830 rc = pci_enable_device(pdev);
831 if (rc == 0)
832 pci_set_master(pdev);
833 pci_dev_put(pdev);
834 if (rc)
835 return rc;
836 }
837 return 0;
838}
839
840static long
841core99_ide_enable(struct device_node *node, long param, long value)
842{
843 /* Bus ID 0 to 2 are KeyLargo based IDE, busID 3 is U2
844 * based ata-100
845 */
846 switch(param) {
847 case 0:
848 return simple_feature_tweak(node, macio_unknown,
849 KEYLARGO_FCR1, KL1_EIDE0_ENABLE, value);
850 case 1:
851 return simple_feature_tweak(node, macio_unknown,
852 KEYLARGO_FCR1, KL1_EIDE1_ENABLE, value);
853 case 2:
854 return simple_feature_tweak(node, macio_unknown,
855 KEYLARGO_FCR1, KL1_UIDE_ENABLE, value);
856 case 3:
857 return core99_ata100_enable(node, value);
858 default:
859 return -ENODEV;
860 }
861}
862
863static long
864core99_ide_reset(struct device_node *node, long param, long value)
865{
866 switch(param) {
867 case 0:
868 return simple_feature_tweak(node, macio_unknown,
869 KEYLARGO_FCR1, KL1_EIDE0_RESET_N, !value);
870 case 1:
871 return simple_feature_tweak(node, macio_unknown,
872 KEYLARGO_FCR1, KL1_EIDE1_RESET_N, !value);
873 case 2:
874 return simple_feature_tweak(node, macio_unknown,
875 KEYLARGO_FCR1, KL1_UIDE_RESET_N, !value);
876 default:
877 return -ENODEV;
878 }
879}
880
881static long
882core99_gmac_enable(struct device_node *node, long param, long value)
883{
884 unsigned long flags;
885
886 LOCK(flags);
887 if (value)
888 UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
889 else
890 UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
891 (void)UN_IN(UNI_N_CLOCK_CNTL);
892 UNLOCK(flags);
893 udelay(20);
894
895 return 0;
896}
897
898static long
899core99_gmac_phy_reset(struct device_node *node, long param, long value)
900{
901 unsigned long flags;
902 struct macio_chip *macio;
903
904 macio = &macio_chips[0];
905 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
906 macio->type != macio_intrepid)
907 return -ENODEV;
908
909 LOCK(flags);
910 MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE);
911 (void)MACIO_IN8(KL_GPIO_ETH_PHY_RESET);
912 UNLOCK(flags);
913 mdelay(10);
914 LOCK(flags);
915 MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, /*KEYLARGO_GPIO_OUTPUT_ENABLE | */
916 KEYLARGO_GPIO_OUTOUT_DATA);
917 UNLOCK(flags);
918 mdelay(10);
919
920 return 0;
921}
922
923static long
924core99_sound_chip_enable(struct device_node *node, long param, long value)
925{
926 struct macio_chip* macio;
927 unsigned long flags;
928
929 macio = macio_find(node, 0);
930 if (!macio)
931 return -ENODEV;
932
933 /* Do a better probe code, screamer G4 desktops &
934 * iMacs can do that too, add a recalibrate in
935 * the driver as well
936 */
937 if (pmac_mb.model_id == PMAC_TYPE_PISMO ||
938 pmac_mb.model_id == PMAC_TYPE_TITANIUM) {
939 LOCK(flags);
940 if (value)
941 MACIO_OUT8(KL_GPIO_SOUND_POWER,
942 KEYLARGO_GPIO_OUTPUT_ENABLE |
943 KEYLARGO_GPIO_OUTOUT_DATA);
944 else
945 MACIO_OUT8(KL_GPIO_SOUND_POWER,
946 KEYLARGO_GPIO_OUTPUT_ENABLE);
947 (void)MACIO_IN8(KL_GPIO_SOUND_POWER);
948 UNLOCK(flags);
949 }
950 return 0;
951}
952
953static long
954core99_airport_enable(struct device_node *node, long param, long value)
955{
956 struct macio_chip* macio;
957 unsigned long flags;
958 int state;
959
960 macio = macio_find(node, 0);
961 if (!macio)
962 return -ENODEV;
963
964 /* Hint: we allow passing of macio itself for the sake of the
965 * sleep code
966 */
967 if (node != macio->of_node &&
968 (!node->parent || node->parent != macio->of_node))
969 return -ENODEV;
970 state = (macio->flags & MACIO_FLAG_AIRPORT_ON) != 0;
971 if (value == state)
972 return 0;
973 if (value) {
974 /* This code is a reproduction of OF enable-cardslot
975 * and init-wireless methods, slightly hacked until
976 * I got it working.
977 */
978 LOCK(flags);
979 MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 5);
980 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
981 UNLOCK(flags);
982 mdelay(10);
983 LOCK(flags);
984 MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 4);
985 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
986 UNLOCK(flags);
987
988 mdelay(10);
989
990 LOCK(flags);
991 MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
992 (void)MACIO_IN32(KEYLARGO_FCR2);
993 udelay(10);
994 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xb, 0);
995 (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xb);
996 udelay(10);
997 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xa, 0x28);
998 (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xa);
999 udelay(10);
1000 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xd, 0x28);
1001 (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xd);
1002 udelay(10);
1003 MACIO_OUT8(KEYLARGO_GPIO_0+0xd, 0x28);
1004 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xd);
1005 udelay(10);
1006 MACIO_OUT8(KEYLARGO_GPIO_0+0xe, 0x28);
1007 (void)MACIO_IN8(KEYLARGO_GPIO_0+0xe);
1008 UNLOCK(flags);
1009 udelay(10);
1010 MACIO_OUT32(0x1c000, 0);
1011 mdelay(1);
1012 MACIO_OUT8(0x1a3e0, 0x41);
1013 (void)MACIO_IN8(0x1a3e0);
1014 udelay(10);
1015 LOCK(flags);
1016 MACIO_BIS(KEYLARGO_FCR2, KL2_CARDSEL_16);
1017 (void)MACIO_IN32(KEYLARGO_FCR2);
1018 UNLOCK(flags);
1019 mdelay(100);
1020
1021 macio->flags |= MACIO_FLAG_AIRPORT_ON;
1022 } else {
1023 LOCK(flags);
1024 MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
1025 (void)MACIO_IN32(KEYLARGO_FCR2);
1026 MACIO_OUT8(KL_GPIO_AIRPORT_0, 0);
1027 MACIO_OUT8(KL_GPIO_AIRPORT_1, 0);
1028 MACIO_OUT8(KL_GPIO_AIRPORT_2, 0);
1029 MACIO_OUT8(KL_GPIO_AIRPORT_3, 0);
1030 MACIO_OUT8(KL_GPIO_AIRPORT_4, 0);
1031 (void)MACIO_IN8(KL_GPIO_AIRPORT_4);
1032 UNLOCK(flags);
1033
1034 macio->flags &= ~MACIO_FLAG_AIRPORT_ON;
1035 }
1036 return 0;
1037}
1038
1039#ifdef CONFIG_SMP
1040static long
1041core99_reset_cpu(struct device_node *node, long param, long value)
1042{
1043 unsigned int reset_io = 0;
1044 unsigned long flags;
1045 struct macio_chip *macio;
1046 struct device_node *np;
1047 const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0,
1048 KL_GPIO_RESET_CPU1,
1049 KL_GPIO_RESET_CPU2,
1050 KL_GPIO_RESET_CPU3 };
1051
1052 macio = &macio_chips[0];
1053 if (macio->type != macio_keylargo)
1054 return -ENODEV;
1055
1056 for_each_of_cpu_node(np) {
1057 const u32 *num = of_get_property(np, "reg", NULL);
1058 const u32 *rst = of_get_property(np, "soft-reset", NULL);
1059 if (num == NULL || rst == NULL)
1060 continue;
1061 if (param == *num) {
1062 reset_io = *rst;
1063 break;
1064 }
1065 }
1066 if (np == NULL || reset_io == 0)
1067 reset_io = dflt_reset_lines[param];
1068
1069 LOCK(flags);
1070 MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
1071 (void)MACIO_IN8(reset_io);
1072 udelay(1);
1073 MACIO_OUT8(reset_io, 0);
1074 (void)MACIO_IN8(reset_io);
1075 UNLOCK(flags);
1076
1077 return 0;
1078}
1079#endif /* CONFIG_SMP */
1080
1081static long
1082core99_usb_enable(struct device_node *node, long param, long value)
1083{
1084 struct macio_chip *macio;
1085 unsigned long flags;
1086 const char *prop;
1087 int number;
1088 u32 reg;
1089
1090 macio = &macio_chips[0];
1091 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1092 macio->type != macio_intrepid)
1093 return -ENODEV;
1094
1095 prop = of_get_property(node, "AAPL,clock-id", NULL);
1096 if (!prop)
1097 return -ENODEV;
1098 if (strncmp(prop, "usb0u048", 8) == 0)
1099 number = 0;
1100 else if (strncmp(prop, "usb1u148", 8) == 0)
1101 number = 2;
1102 else if (strncmp(prop, "usb2u248", 8) == 0)
1103 number = 4;
1104 else
1105 return -ENODEV;
1106
1107 /* Sorry for the brute-force locking, but this is only used during
1108 * sleep and the timing seem to be critical
1109 */
1110 LOCK(flags);
1111 if (value) {
1112 /* Turn ON */
1113 if (number == 0) {
1114 MACIO_BIC(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
1115 (void)MACIO_IN32(KEYLARGO_FCR0);
1116 UNLOCK(flags);
1117 mdelay(1);
1118 LOCK(flags);
1119 MACIO_BIS(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
1120 } else if (number == 2) {
1121 MACIO_BIC(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
1122 UNLOCK(flags);
1123 (void)MACIO_IN32(KEYLARGO_FCR0);
1124 mdelay(1);
1125 LOCK(flags);
1126 MACIO_BIS(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
1127 } else if (number == 4) {
1128 MACIO_BIC(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
1129 UNLOCK(flags);
1130 (void)MACIO_IN32(KEYLARGO_FCR1);
1131 mdelay(1);
1132 LOCK(flags);
1133 MACIO_BIS(KEYLARGO_FCR1, KL1_USB2_CELL_ENABLE);
1134 }
1135 if (number < 4) {
1136 reg = MACIO_IN32(KEYLARGO_FCR4);
1137 reg &= ~(KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
1138 KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number));
1139 reg &= ~(KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
1140 KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1));
1141 MACIO_OUT32(KEYLARGO_FCR4, reg);
1142 (void)MACIO_IN32(KEYLARGO_FCR4);
1143 udelay(10);
1144 } else {
1145 reg = MACIO_IN32(KEYLARGO_FCR3);
1146 reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
1147 KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0));
1148 reg &= ~(KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
1149 KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1));
1150 MACIO_OUT32(KEYLARGO_FCR3, reg);
1151 (void)MACIO_IN32(KEYLARGO_FCR3);
1152 udelay(10);
1153 }
1154 if (macio->type == macio_intrepid) {
1155 /* wait for clock stopped bits to clear */
1156 u32 test0 = 0, test1 = 0;
1157 u32 status0, status1;
1158 int timeout = 1000;
1159
1160 UNLOCK(flags);
1161 switch (number) {
1162 case 0:
1163 test0 = UNI_N_CLOCK_STOPPED_USB0;
1164 test1 = UNI_N_CLOCK_STOPPED_USB0PCI;
1165 break;
1166 case 2:
1167 test0 = UNI_N_CLOCK_STOPPED_USB1;
1168 test1 = UNI_N_CLOCK_STOPPED_USB1PCI;
1169 break;
1170 case 4:
1171 test0 = UNI_N_CLOCK_STOPPED_USB2;
1172 test1 = UNI_N_CLOCK_STOPPED_USB2PCI;
1173 break;
1174 }
1175 do {
1176 if (--timeout <= 0) {
1177 printk(KERN_ERR "core99_usb_enable: "
1178 "Timeout waiting for clocks\n");
1179 break;
1180 }
1181 mdelay(1);
1182 status0 = UN_IN(UNI_N_CLOCK_STOP_STATUS0);
1183 status1 = UN_IN(UNI_N_CLOCK_STOP_STATUS1);
1184 } while ((status0 & test0) | (status1 & test1));
1185 LOCK(flags);
1186 }
1187 } else {
1188 /* Turn OFF */
1189 if (number < 4) {
1190 reg = MACIO_IN32(KEYLARGO_FCR4);
1191 reg |= KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
1192 KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number);
1193 reg |= KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
1194 KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1);
1195 MACIO_OUT32(KEYLARGO_FCR4, reg);
1196 (void)MACIO_IN32(KEYLARGO_FCR4);
1197 udelay(1);
1198 } else {
1199 reg = MACIO_IN32(KEYLARGO_FCR3);
1200 reg |= KL3_IT_PORT_WAKEUP_ENABLE(0) | KL3_IT_PORT_RESUME_WAKE_EN(0) |
1201 KL3_IT_PORT_CONNECT_WAKE_EN(0) | KL3_IT_PORT_DISCONNECT_WAKE_EN(0);
1202 reg |= KL3_IT_PORT_WAKEUP_ENABLE(1) | KL3_IT_PORT_RESUME_WAKE_EN(1) |
1203 KL3_IT_PORT_CONNECT_WAKE_EN(1) | KL3_IT_PORT_DISCONNECT_WAKE_EN(1);
1204 MACIO_OUT32(KEYLARGO_FCR3, reg);
1205 (void)MACIO_IN32(KEYLARGO_FCR3);
1206 udelay(1);
1207 }
1208 if (number == 0) {
1209 if (macio->type != macio_intrepid)
1210 MACIO_BIC(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
1211 (void)MACIO_IN32(KEYLARGO_FCR0);
1212 udelay(1);
1213 MACIO_BIS(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
1214 (void)MACIO_IN32(KEYLARGO_FCR0);
1215 } else if (number == 2) {
1216 if (macio->type != macio_intrepid)
1217 MACIO_BIC(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
1218 (void)MACIO_IN32(KEYLARGO_FCR0);
1219 udelay(1);
1220 MACIO_BIS(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
1221 (void)MACIO_IN32(KEYLARGO_FCR0);
1222 } else if (number == 4) {
1223 udelay(1);
1224 MACIO_BIS(KEYLARGO_FCR1, (KL1_USB2_PAD_SUSPEND0 | KL1_USB2_PAD_SUSPEND1));
1225 (void)MACIO_IN32(KEYLARGO_FCR1);
1226 }
1227 udelay(1);
1228 }
1229 UNLOCK(flags);
1230
1231 return 0;
1232}
1233
1234static long
1235core99_firewire_enable(struct device_node *node, long param, long value)
1236{
1237 unsigned long flags;
1238 struct macio_chip *macio;
1239
1240 macio = &macio_chips[0];
1241 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1242 macio->type != macio_intrepid)
1243 return -ENODEV;
1244 if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
1245 return -ENODEV;
1246
1247 LOCK(flags);
1248 if (value) {
1249 UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
1250 (void)UN_IN(UNI_N_CLOCK_CNTL);
1251 } else {
1252 UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
1253 (void)UN_IN(UNI_N_CLOCK_CNTL);
1254 }
1255 UNLOCK(flags);
1256 mdelay(1);
1257
1258 return 0;
1259}
1260
1261static long
1262core99_firewire_cable_power(struct device_node *node, long param, long value)
1263{
1264 unsigned long flags;
1265 struct macio_chip *macio;
1266
1267 /* Trick: we allow NULL node */
1268 if ((pmac_mb.board_flags & PMAC_MB_HAS_FW_POWER) == 0)
1269 return -ENODEV;
1270 macio = &macio_chips[0];
1271 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1272 macio->type != macio_intrepid)
1273 return -ENODEV;
1274 if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
1275 return -ENODEV;
1276
1277 LOCK(flags);
1278 if (value) {
1279 MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 0);
1280 MACIO_IN8(KL_GPIO_FW_CABLE_POWER);
1281 udelay(10);
1282 } else {
1283 MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 4);
1284 MACIO_IN8(KL_GPIO_FW_CABLE_POWER); udelay(10);
1285 }
1286 UNLOCK(flags);
1287 mdelay(1);
1288
1289 return 0;
1290}
1291
1292static long
1293intrepid_aack_delay_enable(struct device_node *node, long param, long value)
1294{
1295 unsigned long flags;
1296
1297 if (uninorth_rev < 0xd2)
1298 return -ENODEV;
1299
1300 LOCK(flags);
1301 if (param)
1302 UN_BIS(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
1303 else
1304 UN_BIC(UNI_N_AACK_DELAY, UNI_N_AACK_DELAY_ENABLE);
1305 UNLOCK(flags);
1306
1307 return 0;
1308}
1309
1310
1311#endif /* CONFIG_PPC64 */
1312
1313static long
1314core99_read_gpio(struct device_node *node, long param, long value)
1315{
1316 struct macio_chip *macio = &macio_chips[0];
1317
1318 return MACIO_IN8(param);
1319}
1320
1321
1322static long
1323core99_write_gpio(struct device_node *node, long param, long value)
1324{
1325 struct macio_chip *macio = &macio_chips[0];
1326
1327 MACIO_OUT8(param, (u8)(value & 0xff));
1328 return 0;
1329}
1330
1331#ifdef CONFIG_PPC64
1332static long g5_gmac_enable(struct device_node *node, long param, long value)
1333{
1334 struct macio_chip *macio = &macio_chips[0];
1335 unsigned long flags;
1336
1337 if (node == NULL)
1338 return -ENODEV;
1339
1340 LOCK(flags);
1341 if (value) {
1342 MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
1343 mb();
1344 k2_skiplist[0] = NULL;
1345 } else {
1346 k2_skiplist[0] = node;
1347 mb();
1348 MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_GMAC_CLK_ENABLE);
1349 }
1350
1351 UNLOCK(flags);
1352 mdelay(1);
1353
1354 return 0;
1355}
1356
1357static long g5_fw_enable(struct device_node *node, long param, long value)
1358{
1359 struct macio_chip *macio = &macio_chips[0];
1360 unsigned long flags;
1361
1362 if (node == NULL)
1363 return -ENODEV;
1364
1365 LOCK(flags);
1366 if (value) {
1367 MACIO_BIS(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
1368 mb();
1369 k2_skiplist[1] = NULL;
1370 } else {
1371 k2_skiplist[1] = node;
1372 mb();
1373 MACIO_BIC(KEYLARGO_FCR1, K2_FCR1_FW_CLK_ENABLE);
1374 }
1375
1376 UNLOCK(flags);
1377 mdelay(1);
1378
1379 return 0;
1380}
1381
1382static long g5_mpic_enable(struct device_node *node, long param, long value)
1383{
1384 unsigned long flags;
1385 struct device_node *parent = of_get_parent(node);
1386 int is_u3;
1387
1388 if (parent == NULL)
1389 return 0;
1390 is_u3 = of_node_name_eq(parent, "u3") || of_node_name_eq(parent, "u4");
1391 of_node_put(parent);
1392 if (!is_u3)
1393 return 0;
1394
1395 LOCK(flags);
1396 UN_BIS(U3_TOGGLE_REG, U3_MPIC_RESET | U3_MPIC_OUTPUT_ENABLE);
1397 UNLOCK(flags);
1398
1399 return 0;
1400}
1401
1402static long g5_eth_phy_reset(struct device_node *node, long param, long value)
1403{
1404 struct macio_chip *macio = &macio_chips[0];
1405 struct device_node *phy;
1406 int need_reset;
1407
1408 /*
1409 * We must not reset the combo PHYs, only the BCM5221 found in
1410 * the iMac G5.
1411 */
1412 phy = of_get_next_child(node, NULL);
1413 if (!phy)
1414 return -ENODEV;
1415 need_reset = of_device_is_compatible(phy, "B5221");
1416 of_node_put(phy);
1417 if (!need_reset)
1418 return 0;
1419
1420 /* PHY reset is GPIO 29, not in device-tree unfortunately */
1421 MACIO_OUT8(K2_GPIO_EXTINT_0 + 29,
1422 KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
1423 /* Thankfully, this is now always called at a time when we can
1424 * schedule by sungem.
1425 */
1426 msleep(10);
1427 MACIO_OUT8(K2_GPIO_EXTINT_0 + 29, 0);
1428
1429 return 0;
1430}
1431
1432static long g5_i2s_enable(struct device_node *node, long param, long value)
1433{
1434 /* Very crude implementation for now */
1435 struct macio_chip *macio = &macio_chips[0];
1436 unsigned long flags;
1437 int cell;
1438 u32 fcrs[3][3] = {
1439 { 0,
1440 K2_FCR1_I2S0_CELL_ENABLE |
1441 K2_FCR1_I2S0_CLK_ENABLE_BIT | K2_FCR1_I2S0_ENABLE,
1442 KL3_I2S0_CLK18_ENABLE
1443 },
1444 { KL0_SCC_A_INTF_ENABLE,
1445 K2_FCR1_I2S1_CELL_ENABLE |
1446 K2_FCR1_I2S1_CLK_ENABLE_BIT | K2_FCR1_I2S1_ENABLE,
1447 KL3_I2S1_CLK18_ENABLE
1448 },
1449 { KL0_SCC_B_INTF_ENABLE,
1450 SH_FCR1_I2S2_CELL_ENABLE |
1451 SH_FCR1_I2S2_CLK_ENABLE_BIT | SH_FCR1_I2S2_ENABLE,
1452 SH_FCR3_I2S2_CLK18_ENABLE
1453 },
1454 };
1455
1456 if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
1457 return -ENODEV;
1458 if (strncmp(node->name, "i2s-", 4))
1459 return -ENODEV;
1460 cell = node->name[4] - 'a';
1461 switch(cell) {
1462 case 0:
1463 case 1:
1464 break;
1465 case 2:
1466 if (macio->type == macio_shasta)
1467 break;
1468 /* fall through */
1469 default:
1470 return -ENODEV;
1471 }
1472
1473 LOCK(flags);
1474 if (value) {
1475 MACIO_BIC(KEYLARGO_FCR0, fcrs[cell][0]);
1476 MACIO_BIS(KEYLARGO_FCR1, fcrs[cell][1]);
1477 MACIO_BIS(KEYLARGO_FCR3, fcrs[cell][2]);
1478 } else {
1479 MACIO_BIC(KEYLARGO_FCR3, fcrs[cell][2]);
1480 MACIO_BIC(KEYLARGO_FCR1, fcrs[cell][1]);
1481 MACIO_BIS(KEYLARGO_FCR0, fcrs[cell][0]);
1482 }
1483 udelay(10);
1484 UNLOCK(flags);
1485
1486 return 0;
1487}
1488
1489
1490#ifdef CONFIG_SMP
1491static long g5_reset_cpu(struct device_node *node, long param, long value)
1492{
1493 unsigned int reset_io = 0;
1494 unsigned long flags;
1495 struct macio_chip *macio;
1496 struct device_node *np;
1497
1498 macio = &macio_chips[0];
1499 if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
1500 return -ENODEV;
1501
1502 for_each_of_cpu_node(np) {
1503 const u32 *num = of_get_property(np, "reg", NULL);
1504 const u32 *rst = of_get_property(np, "soft-reset", NULL);
1505 if (num == NULL || rst == NULL)
1506 continue;
1507 if (param == *num) {
1508 reset_io = *rst;
1509 break;
1510 }
1511 }
1512 if (np == NULL || reset_io == 0)
1513 return -ENODEV;
1514
1515 LOCK(flags);
1516 MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
1517 (void)MACIO_IN8(reset_io);
1518 udelay(1);
1519 MACIO_OUT8(reset_io, 0);
1520 (void)MACIO_IN8(reset_io);
1521 UNLOCK(flags);
1522
1523 return 0;
1524}
1525#endif /* CONFIG_SMP */
1526
1527/*
1528 * This can be called from pmac_smp so isn't static
1529 *
1530 * This takes the second CPU off the bus on dual CPU machines
1531 * running UP
1532 */
1533void g5_phy_disable_cpu1(void)
1534{
1535 if (uninorth_maj == 3)
1536 UN_OUT(U3_API_PHY_CONFIG_1, 0);
1537}
1538#endif /* CONFIG_PPC64 */
1539
1540#ifndef CONFIG_PPC64
1541
1542
1543#ifdef CONFIG_PM
1544static u32 save_gpio_levels[2];
1545static u8 save_gpio_extint[KEYLARGO_GPIO_EXTINT_CNT];
1546static u8 save_gpio_normal[KEYLARGO_GPIO_CNT];
1547static u32 save_unin_clock_ctl;
1548
1549static void keylargo_shutdown(struct macio_chip *macio, int sleep_mode)
1550{
1551 u32 temp;
1552
1553 if (sleep_mode) {
1554 mdelay(1);
1555 MACIO_BIS(KEYLARGO_FCR0, KL0_USB_REF_SUSPEND);
1556 (void)MACIO_IN32(KEYLARGO_FCR0);
1557 mdelay(1);
1558 }
1559
1560 MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
1561 KL0_SCC_CELL_ENABLE |
1562 KL0_IRDA_ENABLE | KL0_IRDA_CLK32_ENABLE |
1563 KL0_IRDA_CLK19_ENABLE);
1564
1565 MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);
1566 MACIO_BIS(KEYLARGO_MBCR, KL_MBCR_MB0_IDE_ENABLE);
1567
1568 MACIO_BIC(KEYLARGO_FCR1,
1569 KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
1570 KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
1571 KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
1572 KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
1573 KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
1574 KL1_EIDE0_ENABLE | KL1_EIDE0_RESET_N |
1575 KL1_EIDE1_ENABLE | KL1_EIDE1_RESET_N |
1576 KL1_UIDE_ENABLE);
1577
1578 MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
1579 MACIO_BIC(KEYLARGO_FCR2, KL2_IOBUS_ENABLE);
1580
1581 temp = MACIO_IN32(KEYLARGO_FCR3);
1582 if (macio->rev >= 2) {
1583 temp |= KL3_SHUTDOWN_PLL2X;
1584 if (sleep_mode)
1585 temp |= KL3_SHUTDOWN_PLL_TOTAL;
1586 }
1587
1588 temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
1589 KL3_SHUTDOWN_PLLKW35;
1590 if (sleep_mode)
1591 temp |= KL3_SHUTDOWN_PLLKW12;
1592 temp &= ~(KL3_CLK66_ENABLE | KL3_CLK49_ENABLE | KL3_CLK45_ENABLE
1593 | KL3_CLK31_ENABLE | KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
1594 if (sleep_mode)
1595 temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);
1596 MACIO_OUT32(KEYLARGO_FCR3, temp);
1597
1598 /* Flush posted writes & wait a bit */
1599 (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
1600}
1601
1602static void pangea_shutdown(struct macio_chip *macio, int sleep_mode)
1603{
1604 u32 temp;
1605
1606 MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
1607 KL0_SCC_CELL_ENABLE |
1608 KL0_USB0_CELL_ENABLE | KL0_USB1_CELL_ENABLE);
1609
1610 MACIO_BIC(KEYLARGO_FCR1,
1611 KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
1612 KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
1613 KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
1614 KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
1615 KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
1616 KL1_UIDE_ENABLE);
1617 if (pmac_mb.board_flags & PMAC_MB_MOBILE)
1618 MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
1619
1620 MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
1621
1622 temp = MACIO_IN32(KEYLARGO_FCR3);
1623 temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
1624 KL3_SHUTDOWN_PLLKW35;
1625 temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE | KL3_CLK31_ENABLE
1626 | KL3_I2S0_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE);
1627 if (sleep_mode)
1628 temp &= ~(KL3_VIA_CLK16_ENABLE | KL3_TIMER_CLK18_ENABLE);
1629 MACIO_OUT32(KEYLARGO_FCR3, temp);
1630
1631 /* Flush posted writes & wait a bit */
1632 (void)MACIO_IN32(KEYLARGO_FCR0); mdelay(1);
1633}
1634
1635static void intrepid_shutdown(struct macio_chip *macio, int sleep_mode)
1636{
1637 u32 temp;
1638
1639 MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
1640 KL0_SCC_CELL_ENABLE);
1641
1642 MACIO_BIC(KEYLARGO_FCR1,
1643 KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
1644 KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
1645 KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
1646 KL1_EIDE0_ENABLE);
1647 if (pmac_mb.board_flags & PMAC_MB_MOBILE)
1648 MACIO_BIC(KEYLARGO_FCR1, KL1_UIDE_RESET_N);
1649
1650 temp = MACIO_IN32(KEYLARGO_FCR3);
1651 temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE |
1652 KL3_I2S1_CLK18_ENABLE | KL3_I2S0_CLK18_ENABLE);
1653 if (sleep_mode)
1654 temp &= ~(KL3_TIMER_CLK18_ENABLE | KL3_IT_VIA_CLK32_ENABLE);
1655 MACIO_OUT32(KEYLARGO_FCR3, temp);
1656
1657 /* Flush posted writes & wait a bit */
1658 (void)MACIO_IN32(KEYLARGO_FCR0);
1659 mdelay(10);
1660}
1661
1662
1663static int
1664core99_sleep(void)
1665{
1666 struct macio_chip *macio;
1667 int i;
1668
1669 macio = &macio_chips[0];
1670 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1671 macio->type != macio_intrepid)
1672 return -ENODEV;
1673
1674 /* We power off the wireless slot in case it was not done
1675 * by the driver. We don't power it on automatically however
1676 */
1677 if (macio->flags & MACIO_FLAG_AIRPORT_ON)
1678 core99_airport_enable(macio->of_node, 0, 0);
1679
1680 /* We power off the FW cable. Should be done by the driver... */
1681 if (macio->flags & MACIO_FLAG_FW_SUPPORTED) {
1682 core99_firewire_enable(NULL, 0, 0);
1683 core99_firewire_cable_power(NULL, 0, 0);
1684 }
1685
1686 /* We make sure int. modem is off (in case driver lost it) */
1687 if (macio->type == macio_keylargo)
1688 core99_modem_enable(macio->of_node, 0, 0);
1689 else
1690 pangea_modem_enable(macio->of_node, 0, 0);
1691
1692 /* We make sure the sound is off as well */
1693 core99_sound_chip_enable(macio->of_node, 0, 0);
1694
1695 /*
1696 * Save various bits of KeyLargo
1697 */
1698
1699 /* Save the state of the various GPIOs */
1700 save_gpio_levels[0] = MACIO_IN32(KEYLARGO_GPIO_LEVELS0);
1701 save_gpio_levels[1] = MACIO_IN32(KEYLARGO_GPIO_LEVELS1);
1702 for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
1703 save_gpio_extint[i] = MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+i);
1704 for (i=0; i<KEYLARGO_GPIO_CNT; i++)
1705 save_gpio_normal[i] = MACIO_IN8(KEYLARGO_GPIO_0+i);
1706
1707 /* Save the FCRs */
1708 if (macio->type == macio_keylargo)
1709 save_mbcr = MACIO_IN32(KEYLARGO_MBCR);
1710 save_fcr[0] = MACIO_IN32(KEYLARGO_FCR0);
1711 save_fcr[1] = MACIO_IN32(KEYLARGO_FCR1);
1712 save_fcr[2] = MACIO_IN32(KEYLARGO_FCR2);
1713 save_fcr[3] = MACIO_IN32(KEYLARGO_FCR3);
1714 save_fcr[4] = MACIO_IN32(KEYLARGO_FCR4);
1715 if (macio->type == macio_pangea || macio->type == macio_intrepid)
1716 save_fcr[5] = MACIO_IN32(KEYLARGO_FCR5);
1717
1718 /* Save state & config of DBDMA channels */
1719 dbdma_save(macio, save_dbdma);
1720
1721 /*
1722 * Turn off as much as we can
1723 */
1724 if (macio->type == macio_pangea)
1725 pangea_shutdown(macio, 1);
1726 else if (macio->type == macio_intrepid)
1727 intrepid_shutdown(macio, 1);
1728 else if (macio->type == macio_keylargo)
1729 keylargo_shutdown(macio, 1);
1730
1731 /*
1732 * Put the host bridge to sleep
1733 */
1734
1735 save_unin_clock_ctl = UN_IN(UNI_N_CLOCK_CNTL);
1736 /* Note: do not switch GMAC off, driver does it when necessary, WOL must keep it
1737 * enabled !
1738 */
1739 UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl &
1740 ~(/*UNI_N_CLOCK_CNTL_GMAC|*/UNI_N_CLOCK_CNTL_FW/*|UNI_N_CLOCK_CNTL_PCI*/));
1741 udelay(100);
1742 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
1743 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_SLEEP);
1744 mdelay(10);
1745
1746 /*
1747 * FIXME: A bit of black magic with OpenPIC (don't ask me why)
1748 */
1749 if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
1750 MACIO_BIS(0x506e0, 0x00400000);
1751 MACIO_BIS(0x506e0, 0x80000000);
1752 }
1753 return 0;
1754}
1755
1756static int
1757core99_wake_up(void)
1758{
1759 struct macio_chip *macio;
1760 int i;
1761
1762 macio = &macio_chips[0];
1763 if (macio->type != macio_keylargo && macio->type != macio_pangea &&
1764 macio->type != macio_intrepid)
1765 return -ENODEV;
1766
1767 /*
1768 * Wakeup the host bridge
1769 */
1770 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
1771 udelay(10);
1772 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
1773 udelay(10);
1774
1775 /*
1776 * Restore KeyLargo
1777 */
1778
1779 if (macio->type == macio_keylargo) {
1780 MACIO_OUT32(KEYLARGO_MBCR, save_mbcr);
1781 (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
1782 }
1783 MACIO_OUT32(KEYLARGO_FCR0, save_fcr[0]);
1784 (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
1785 MACIO_OUT32(KEYLARGO_FCR1, save_fcr[1]);
1786 (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
1787 MACIO_OUT32(KEYLARGO_FCR2, save_fcr[2]);
1788 (void)MACIO_IN32(KEYLARGO_FCR2); udelay(10);
1789 MACIO_OUT32(KEYLARGO_FCR3, save_fcr[3]);
1790 (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
1791 MACIO_OUT32(KEYLARGO_FCR4, save_fcr[4]);
1792 (void)MACIO_IN32(KEYLARGO_FCR4); udelay(10);
1793 if (macio->type == macio_pangea || macio->type == macio_intrepid) {
1794 MACIO_OUT32(KEYLARGO_FCR5, save_fcr[5]);
1795 (void)MACIO_IN32(KEYLARGO_FCR5); udelay(10);
1796 }
1797
1798 dbdma_restore(macio, save_dbdma);
1799
1800 MACIO_OUT32(KEYLARGO_GPIO_LEVELS0, save_gpio_levels[0]);
1801 MACIO_OUT32(KEYLARGO_GPIO_LEVELS1, save_gpio_levels[1]);
1802 for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
1803 MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+i, save_gpio_extint[i]);
1804 for (i=0; i<KEYLARGO_GPIO_CNT; i++)
1805 MACIO_OUT8(KEYLARGO_GPIO_0+i, save_gpio_normal[i]);
1806
1807 /* FIXME more black magic with OpenPIC ... */
1808 if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
1809 MACIO_BIC(0x506e0, 0x00400000);
1810 MACIO_BIC(0x506e0, 0x80000000);
1811 }
1812
1813 UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl);
1814 udelay(100);
1815
1816 return 0;
1817}
1818
1819#endif /* CONFIG_PM */
1820
1821static long
1822core99_sleep_state(struct device_node *node, long param, long value)
1823{
1824 /* Param == 1 means to enter the "fake sleep" mode that is
1825 * used for CPU speed switch
1826 */
1827 if (param == 1) {
1828 if (value == 1) {
1829 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
1830 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_IDLE2);
1831 } else {
1832 UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
1833 udelay(10);
1834 UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
1835 udelay(10);
1836 }
1837 return 0;
1838 }
1839 if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
1840 return -EPERM;
1841
1842#ifdef CONFIG_PM
1843 if (value == 1)
1844 return core99_sleep();
1845 else if (value == 0)
1846 return core99_wake_up();
1847
1848#endif /* CONFIG_PM */
1849 return 0;
1850}
1851
1852#endif /* CONFIG_PPC64 */
1853
1854static long
1855generic_dev_can_wake(struct device_node *node, long param, long value)
1856{
1857 /* Todo: eventually check we are really dealing with on-board
1858 * video device ...
1859 */
1860
1861 if (pmac_mb.board_flags & PMAC_MB_MAY_SLEEP)
1862 pmac_mb.board_flags |= PMAC_MB_CAN_SLEEP;
1863 return 0;
1864}
1865
1866static long generic_get_mb_info(struct device_node *node, long param, long value)
1867{
1868 switch(param) {
1869 case PMAC_MB_INFO_MODEL:
1870 return pmac_mb.model_id;
1871 case PMAC_MB_INFO_FLAGS:
1872 return pmac_mb.board_flags;
1873 case PMAC_MB_INFO_NAME:
1874 /* hack hack hack... but should work */
1875 *((const char **)value) = pmac_mb.model_name;
1876 return 0;
1877 }
1878 return -EINVAL;
1879}
1880
1881
1882/*
1883 * Table definitions
1884 */
1885
1886/* Used on any machine
1887 */
1888static struct feature_table_entry any_features[] = {
1889 { PMAC_FTR_GET_MB_INFO, generic_get_mb_info },
1890 { PMAC_FTR_DEVICE_CAN_WAKE, generic_dev_can_wake },
1891 { 0, NULL }
1892};
1893
1894#ifndef CONFIG_PPC64
1895
1896/* OHare based motherboards. Currently, we only use these on the
1897 * 2400,3400 and 3500 series powerbooks. Some older desktops seem
1898 * to have issues with turning on/off those asic cells
1899 */
1900static struct feature_table_entry ohare_features[] = {
1901 { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
1902 { PMAC_FTR_SWIM3_ENABLE, ohare_floppy_enable },
1903 { PMAC_FTR_MESH_ENABLE, ohare_mesh_enable },
1904 { PMAC_FTR_IDE_ENABLE, ohare_ide_enable},
1905 { PMAC_FTR_IDE_RESET, ohare_ide_reset},
1906 { PMAC_FTR_SLEEP_STATE, ohare_sleep_state },
1907 { 0, NULL }
1908};
1909
1910/* Heathrow desktop machines (Beige G3).
1911 * Separated as some features couldn't be properly tested
1912 * and the serial port control bits appear to confuse it.
1913 */
1914static struct feature_table_entry heathrow_desktop_features[] = {
1915 { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
1916 { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
1917 { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
1918 { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
1919 { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
1920 { 0, NULL }
1921};
1922
1923/* Heathrow based laptop, that is the Wallstreet and mainstreet
1924 * powerbooks.
1925 */
1926static struct feature_table_entry heathrow_laptop_features[] = {
1927 { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
1928 { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
1929 { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
1930 { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
1931 { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
1932 { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
1933 { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
1934 { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
1935 { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
1936 { 0, NULL }
1937};
1938
1939/* Paddington based machines
1940 * The lombard (101) powerbook, first iMac models, B&W G3 and Yikes G4.
1941 */
1942static struct feature_table_entry paddington_features[] = {
1943 { PMAC_FTR_SCC_ENABLE, ohare_htw_scc_enable },
1944 { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
1945 { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
1946 { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
1947 { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
1948 { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
1949 { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
1950 { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
1951 { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
1952 { 0, NULL }
1953};
1954
1955/* Core99 & MacRISC 2 machines (all machines released since the
1956 * iBook (included), that is all AGP machines, except pangea
1957 * chipset. The pangea chipset is the "combo" UniNorth/KeyLargo
1958 * used on iBook2 & iMac "flow power".
1959 */
1960static struct feature_table_entry core99_features[] = {
1961 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
1962 { PMAC_FTR_MODEM_ENABLE, core99_modem_enable },
1963 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
1964 { PMAC_FTR_IDE_RESET, core99_ide_reset },
1965 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
1966 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
1967 { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
1968 { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
1969 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
1970 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
1971 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
1972#ifdef CONFIG_PM
1973 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
1974#endif
1975#ifdef CONFIG_SMP
1976 { PMAC_FTR_RESET_CPU, core99_reset_cpu },
1977#endif /* CONFIG_SMP */
1978 { PMAC_FTR_READ_GPIO, core99_read_gpio },
1979 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
1980 { 0, NULL }
1981};
1982
1983/* RackMac
1984 */
1985static struct feature_table_entry rackmac_features[] = {
1986 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
1987 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
1988 { PMAC_FTR_IDE_RESET, core99_ide_reset },
1989 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
1990 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
1991 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
1992 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
1993 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
1994 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
1995#ifdef CONFIG_SMP
1996 { PMAC_FTR_RESET_CPU, core99_reset_cpu },
1997#endif /* CONFIG_SMP */
1998 { PMAC_FTR_READ_GPIO, core99_read_gpio },
1999 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2000 { 0, NULL }
2001};
2002
2003/* Pangea features
2004 */
2005static struct feature_table_entry pangea_features[] = {
2006 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
2007 { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
2008 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
2009 { PMAC_FTR_IDE_RESET, core99_ide_reset },
2010 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
2011 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
2012 { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
2013 { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
2014 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
2015 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
2016 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
2017 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
2018 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2019 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2020 { 0, NULL }
2021};
2022
2023/* Intrepid features
2024 */
2025static struct feature_table_entry intrepid_features[] = {
2026 { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
2027 { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
2028 { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
2029 { PMAC_FTR_IDE_RESET, core99_ide_reset },
2030 { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
2031 { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
2032 { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
2033 { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
2034 { PMAC_FTR_USB_ENABLE, core99_usb_enable },
2035 { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
2036 { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
2037 { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
2038 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2039 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2040 { PMAC_FTR_AACK_DELAY_ENABLE, intrepid_aack_delay_enable },
2041 { 0, NULL }
2042};
2043
2044#else /* CONFIG_PPC64 */
2045
2046/* G5 features
2047 */
2048static struct feature_table_entry g5_features[] = {
2049 { PMAC_FTR_GMAC_ENABLE, g5_gmac_enable },
2050 { PMAC_FTR_1394_ENABLE, g5_fw_enable },
2051 { PMAC_FTR_ENABLE_MPIC, g5_mpic_enable },
2052 { PMAC_FTR_GMAC_PHY_RESET, g5_eth_phy_reset },
2053 { PMAC_FTR_SOUND_CHIP_ENABLE, g5_i2s_enable },
2054#ifdef CONFIG_SMP
2055 { PMAC_FTR_RESET_CPU, g5_reset_cpu },
2056#endif /* CONFIG_SMP */
2057 { PMAC_FTR_READ_GPIO, core99_read_gpio },
2058 { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
2059 { 0, NULL }
2060};
2061
2062#endif /* CONFIG_PPC64 */
2063
2064static struct pmac_mb_def pmac_mb_defs[] = {
2065#ifndef CONFIG_PPC64
2066 /*
2067 * Desktops
2068 */
2069
2070 { "AAPL,8500", "PowerMac 8500/8600",
2071 PMAC_TYPE_PSURGE, NULL,
2072 0
2073 },
2074 { "AAPL,9500", "PowerMac 9500/9600",
2075 PMAC_TYPE_PSURGE, NULL,
2076 0
2077 },
2078 { "AAPL,7200", "PowerMac 7200",
2079 PMAC_TYPE_PSURGE, NULL,
2080 0
2081 },
2082 { "AAPL,7300", "PowerMac 7200/7300",
2083 PMAC_TYPE_PSURGE, NULL,
2084 0
2085 },
2086 { "AAPL,7500", "PowerMac 7500",
2087 PMAC_TYPE_PSURGE, NULL,
2088 0
2089 },
2090 { "AAPL,ShinerESB", "Apple Network Server",
2091 PMAC_TYPE_ANS, NULL,
2092 0
2093 },
2094 { "AAPL,e407", "Alchemy",
2095 PMAC_TYPE_ALCHEMY, NULL,
2096 0
2097 },
2098 { "AAPL,e411", "Gazelle",
2099 PMAC_TYPE_GAZELLE, NULL,
2100 0
2101 },
2102 { "AAPL,Gossamer", "PowerMac G3 (Gossamer)",
2103 PMAC_TYPE_GOSSAMER, heathrow_desktop_features,
2104 0
2105 },
2106 { "AAPL,PowerMac G3", "PowerMac G3 (Silk)",
2107 PMAC_TYPE_SILK, heathrow_desktop_features,
2108 0
2109 },
2110 { "PowerMac1,1", "Blue&White G3",
2111 PMAC_TYPE_YOSEMITE, paddington_features,
2112 0
2113 },
2114 { "PowerMac1,2", "PowerMac G4 PCI Graphics",
2115 PMAC_TYPE_YIKES, paddington_features,
2116 0
2117 },
2118 { "PowerMac2,1", "iMac FireWire",
2119 PMAC_TYPE_FW_IMAC, core99_features,
2120 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2121 },
2122 { "PowerMac2,2", "iMac FireWire",
2123 PMAC_TYPE_FW_IMAC, core99_features,
2124 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2125 },
2126 { "PowerMac3,1", "PowerMac G4 AGP Graphics",
2127 PMAC_TYPE_SAWTOOTH, core99_features,
2128 PMAC_MB_OLD_CORE99
2129 },
2130 { "PowerMac3,2", "PowerMac G4 AGP Graphics",
2131 PMAC_TYPE_SAWTOOTH, core99_features,
2132 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2133 },
2134 { "PowerMac3,3", "PowerMac G4 AGP Graphics",
2135 PMAC_TYPE_SAWTOOTH, core99_features,
2136 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2137 },
2138 { "PowerMac3,4", "PowerMac G4 Silver",
2139 PMAC_TYPE_QUICKSILVER, core99_features,
2140 PMAC_MB_MAY_SLEEP
2141 },
2142 { "PowerMac3,5", "PowerMac G4 Silver",
2143 PMAC_TYPE_QUICKSILVER, core99_features,
2144 PMAC_MB_MAY_SLEEP
2145 },
2146 { "PowerMac3,6", "PowerMac G4 Windtunnel",
2147 PMAC_TYPE_WINDTUNNEL, core99_features,
2148 PMAC_MB_MAY_SLEEP,
2149 },
2150 { "PowerMac4,1", "iMac \"Flower Power\"",
2151 PMAC_TYPE_PANGEA_IMAC, pangea_features,
2152 PMAC_MB_MAY_SLEEP
2153 },
2154 { "PowerMac4,2", "Flat panel iMac",
2155 PMAC_TYPE_FLAT_PANEL_IMAC, pangea_features,
2156 PMAC_MB_CAN_SLEEP
2157 },
2158 { "PowerMac4,4", "eMac",
2159 PMAC_TYPE_EMAC, core99_features,
2160 PMAC_MB_MAY_SLEEP
2161 },
2162 { "PowerMac5,1", "PowerMac G4 Cube",
2163 PMAC_TYPE_CUBE, core99_features,
2164 PMAC_MB_MAY_SLEEP | PMAC_MB_OLD_CORE99
2165 },
2166 { "PowerMac6,1", "Flat panel iMac",
2167 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2168 PMAC_MB_MAY_SLEEP,
2169 },
2170 { "PowerMac6,3", "Flat panel iMac",
2171 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2172 PMAC_MB_MAY_SLEEP,
2173 },
2174 { "PowerMac6,4", "eMac",
2175 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2176 PMAC_MB_MAY_SLEEP,
2177 },
2178 { "PowerMac10,1", "Mac mini",
2179 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2180 PMAC_MB_MAY_SLEEP,
2181 },
2182 { "PowerMac10,2", "Mac mini (Late 2005)",
2183 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2184 PMAC_MB_MAY_SLEEP,
2185 },
2186 { "iMac,1", "iMac (first generation)",
2187 PMAC_TYPE_ORIG_IMAC, paddington_features,
2188 0
2189 },
2190
2191 /*
2192 * Xserve's
2193 */
2194
2195 { "RackMac1,1", "XServe",
2196 PMAC_TYPE_RACKMAC, rackmac_features,
2197 0,
2198 },
2199 { "RackMac1,2", "XServe rev. 2",
2200 PMAC_TYPE_RACKMAC, rackmac_features,
2201 0,
2202 },
2203
2204 /*
2205 * Laptops
2206 */
2207
2208 { "AAPL,3400/2400", "PowerBook 3400",
2209 PMAC_TYPE_HOOPER, ohare_features,
2210 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2211 },
2212 { "AAPL,3500", "PowerBook 3500",
2213 PMAC_TYPE_KANGA, ohare_features,
2214 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2215 },
2216 { "AAPL,PowerBook1998", "PowerBook Wallstreet",
2217 PMAC_TYPE_WALLSTREET, heathrow_laptop_features,
2218 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2219 },
2220 { "PowerBook1,1", "PowerBook 101 (Lombard)",
2221 PMAC_TYPE_101_PBOOK, paddington_features,
2222 PMAC_MB_CAN_SLEEP | PMAC_MB_MOBILE
2223 },
2224 { "PowerBook2,1", "iBook (first generation)",
2225 PMAC_TYPE_ORIG_IBOOK, core99_features,
2226 PMAC_MB_CAN_SLEEP | PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
2227 },
2228 { "PowerBook2,2", "iBook FireWire",
2229 PMAC_TYPE_FW_IBOOK, core99_features,
2230 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
2231 PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
2232 },
2233 { "PowerBook3,1", "PowerBook Pismo",
2234 PMAC_TYPE_PISMO, core99_features,
2235 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER |
2236 PMAC_MB_OLD_CORE99 | PMAC_MB_MOBILE
2237 },
2238 { "PowerBook3,2", "PowerBook Titanium",
2239 PMAC_TYPE_TITANIUM, core99_features,
2240 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2241 },
2242 { "PowerBook3,3", "PowerBook Titanium II",
2243 PMAC_TYPE_TITANIUM2, core99_features,
2244 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2245 },
2246 { "PowerBook3,4", "PowerBook Titanium III",
2247 PMAC_TYPE_TITANIUM3, core99_features,
2248 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2249 },
2250 { "PowerBook3,5", "PowerBook Titanium IV",
2251 PMAC_TYPE_TITANIUM4, core99_features,
2252 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2253 },
2254 { "PowerBook4,1", "iBook 2",
2255 PMAC_TYPE_IBOOK2, pangea_features,
2256 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2257 },
2258 { "PowerBook4,2", "iBook 2",
2259 PMAC_TYPE_IBOOK2, pangea_features,
2260 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2261 },
2262 { "PowerBook4,3", "iBook 2 rev. 2",
2263 PMAC_TYPE_IBOOK2, pangea_features,
2264 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE
2265 },
2266 { "PowerBook5,1", "PowerBook G4 17\"",
2267 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2268 PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2269 },
2270 { "PowerBook5,2", "PowerBook G4 15\"",
2271 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2272 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2273 },
2274 { "PowerBook5,3", "PowerBook G4 17\"",
2275 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2276 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2277 },
2278 { "PowerBook5,4", "PowerBook G4 15\"",
2279 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2280 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2281 },
2282 { "PowerBook5,5", "PowerBook G4 17\"",
2283 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2284 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2285 },
2286 { "PowerBook5,6", "PowerBook G4 15\"",
2287 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2288 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2289 },
2290 { "PowerBook5,7", "PowerBook G4 17\"",
2291 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2292 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2293 },
2294 { "PowerBook5,8", "PowerBook G4 15\"",
2295 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2296 PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
2297 },
2298 { "PowerBook5,9", "PowerBook G4 17\"",
2299 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2300 PMAC_MB_MAY_SLEEP | PMAC_MB_MOBILE,
2301 },
2302 { "PowerBook6,1", "PowerBook G4 12\"",
2303 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2304 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2305 },
2306 { "PowerBook6,2", "PowerBook G4",
2307 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2308 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2309 },
2310 { "PowerBook6,3", "iBook G4",
2311 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2312 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2313 },
2314 { "PowerBook6,4", "PowerBook G4 12\"",
2315 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2316 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2317 },
2318 { "PowerBook6,5", "iBook G4",
2319 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2320 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2321 },
2322 { "PowerBook6,7", "iBook G4",
2323 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2324 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2325 },
2326 { "PowerBook6,8", "PowerBook G4 12\"",
2327 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2328 PMAC_MB_MAY_SLEEP | PMAC_MB_HAS_FW_POWER | PMAC_MB_MOBILE,
2329 },
2330#else /* CONFIG_PPC64 */
2331 { "PowerMac7,2", "PowerMac G5",
2332 PMAC_TYPE_POWERMAC_G5, g5_features,
2333 0,
2334 },
2335#ifdef CONFIG_PPC64
2336 { "PowerMac7,3", "PowerMac G5",
2337 PMAC_TYPE_POWERMAC_G5, g5_features,
2338 0,
2339 },
2340 { "PowerMac8,1", "iMac G5",
2341 PMAC_TYPE_IMAC_G5, g5_features,
2342 0,
2343 },
2344 { "PowerMac9,1", "PowerMac G5",
2345 PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
2346 0,
2347 },
2348 { "PowerMac11,2", "PowerMac G5 Dual Core",
2349 PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
2350 0,
2351 },
2352 { "PowerMac12,1", "iMac G5 (iSight)",
2353 PMAC_TYPE_POWERMAC_G5_U3L, g5_features,
2354 0,
2355 },
2356 { "RackMac3,1", "XServe G5",
2357 PMAC_TYPE_XSERVE_G5, g5_features,
2358 0,
2359 },
2360#endif /* CONFIG_PPC64 */
2361#endif /* CONFIG_PPC64 */
2362};
2363
2364/*
2365 * The toplevel feature_call callback
2366 */
2367long pmac_do_feature_call(unsigned int selector, ...)
2368{
2369 struct device_node *node;
2370 long param, value;
2371 int i;
2372 feature_call func = NULL;
2373 va_list args;
2374
2375 if (pmac_mb.features)
2376 for (i=0; pmac_mb.features[i].function; i++)
2377 if (pmac_mb.features[i].selector == selector) {
2378 func = pmac_mb.features[i].function;
2379 break;
2380 }
2381 if (!func)
2382 for (i=0; any_features[i].function; i++)
2383 if (any_features[i].selector == selector) {
2384 func = any_features[i].function;
2385 break;
2386 }
2387 if (!func)
2388 return -ENODEV;
2389
2390 va_start(args, selector);
2391 node = (struct device_node*)va_arg(args, void*);
2392 param = va_arg(args, long);
2393 value = va_arg(args, long);
2394 va_end(args);
2395
2396 return func(node, param, value);
2397}
2398
2399static int __init probe_motherboard(void)
2400{
2401 int i;
2402 struct macio_chip *macio = &macio_chips[0];
2403 const char *model = NULL;
2404 struct device_node *dt;
2405 int ret = 0;
2406
2407 /* Lookup known motherboard type in device-tree. First try an
2408 * exact match on the "model" property, then try a "compatible"
2409 * match is none is found.
2410 */
2411 dt = of_find_node_by_name(NULL, "device-tree");
2412 if (dt != NULL)
2413 model = of_get_property(dt, "model", NULL);
2414 for(i=0; model && i<ARRAY_SIZE(pmac_mb_defs); i++) {
2415 if (strcmp(model, pmac_mb_defs[i].model_string) == 0) {
2416 pmac_mb = pmac_mb_defs[i];
2417 goto found;
2418 }
2419 }
2420 for(i=0; i<ARRAY_SIZE(pmac_mb_defs); i++) {
2421 if (of_machine_is_compatible(pmac_mb_defs[i].model_string)) {
2422 pmac_mb = pmac_mb_defs[i];
2423 goto found;
2424 }
2425 }
2426
2427 /* Fallback to selection depending on mac-io chip type */
2428 switch(macio->type) {
2429#ifndef CONFIG_PPC64
2430 case macio_grand_central:
2431 pmac_mb.model_id = PMAC_TYPE_PSURGE;
2432 pmac_mb.model_name = "Unknown PowerSurge";
2433 break;
2434 case macio_ohare:
2435 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_OHARE;
2436 pmac_mb.model_name = "Unknown OHare-based";
2437 break;
2438 case macio_heathrow:
2439 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_HEATHROW;
2440 pmac_mb.model_name = "Unknown Heathrow-based";
2441 pmac_mb.features = heathrow_desktop_features;
2442 break;
2443 case macio_paddington:
2444 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PADDINGTON;
2445 pmac_mb.model_name = "Unknown Paddington-based";
2446 pmac_mb.features = paddington_features;
2447 break;
2448 case macio_keylargo:
2449 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_CORE99;
2450 pmac_mb.model_name = "Unknown Keylargo-based";
2451 pmac_mb.features = core99_features;
2452 break;
2453 case macio_pangea:
2454 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PANGEA;
2455 pmac_mb.model_name = "Unknown Pangea-based";
2456 pmac_mb.features = pangea_features;
2457 break;
2458 case macio_intrepid:
2459 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_INTREPID;
2460 pmac_mb.model_name = "Unknown Intrepid-based";
2461 pmac_mb.features = intrepid_features;
2462 break;
2463#else /* CONFIG_PPC64 */
2464 case macio_keylargo2:
2465 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_K2;
2466 pmac_mb.model_name = "Unknown K2-based";
2467 pmac_mb.features = g5_features;
2468 break;
2469 case macio_shasta:
2470 pmac_mb.model_id = PMAC_TYPE_UNKNOWN_SHASTA;
2471 pmac_mb.model_name = "Unknown Shasta-based";
2472 pmac_mb.features = g5_features;
2473 break;
2474#endif /* CONFIG_PPC64 */
2475 default:
2476 ret = -ENODEV;
2477 goto done;
2478 }
2479found:
2480#ifndef CONFIG_PPC64
2481 /* Fixup Hooper vs. Comet */
2482 if (pmac_mb.model_id == PMAC_TYPE_HOOPER) {
2483 u32 __iomem * mach_id_ptr = ioremap(0xf3000034, 4);
2484 if (!mach_id_ptr) {
2485 ret = -ENODEV;
2486 goto done;
2487 }
2488 /* Here, I used to disable the media-bay on comet. It
2489 * appears this is wrong, the floppy connector is actually
2490 * a kind of media-bay and works with the current driver.
2491 */
2492 if (__raw_readl(mach_id_ptr) & 0x20000000UL)
2493 pmac_mb.model_id = PMAC_TYPE_COMET;
2494 iounmap(mach_id_ptr);
2495 }
2496
2497 /* Set default value of powersave_nap on machines that support it.
2498 * It appears that uninorth rev 3 has a problem with it, we don't
2499 * enable it on those. In theory, the flush-on-lock property is
2500 * supposed to be set when not supported, but I'm not very confident
2501 * that all Apple OF revs did it properly, I do it the paranoid way.
2502 */
2503 if (uninorth_base && uninorth_rev > 3) {
2504 struct device_node *np;
2505
2506 for_each_of_cpu_node(np) {
2507 int cpu_count = 1;
2508
2509 /* Nap mode not supported on SMP */
2510 if (of_get_property(np, "flush-on-lock", NULL) ||
2511 (cpu_count > 1)) {
2512 powersave_nap = 0;
2513 of_node_put(np);
2514 break;
2515 }
2516
2517 cpu_count++;
2518 powersave_nap = 1;
2519 }
2520 }
2521 if (powersave_nap)
2522 printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n");
2523
2524 /* On CPUs that support it (750FX), lowspeed by default during
2525 * NAP mode
2526 */
2527 powersave_lowspeed = 1;
2528
2529#else /* CONFIG_PPC64 */
2530 powersave_nap = 1;
2531#endif /* CONFIG_PPC64 */
2532
2533 /* Check for "mobile" machine */
2534 if (model && (strncmp(model, "PowerBook", 9) == 0
2535 || strncmp(model, "iBook", 5) == 0))
2536 pmac_mb.board_flags |= PMAC_MB_MOBILE;
2537
2538
2539 printk(KERN_INFO "PowerMac motherboard: %s\n", pmac_mb.model_name);
2540done:
2541 of_node_put(dt);
2542 return ret;
2543}
2544
2545/* Initialize the Core99 UniNorth host bridge and memory controller
2546 */
2547static void __init probe_uninorth(void)
2548{
2549 const u32 *addrp;
2550 phys_addr_t address;
2551 unsigned long actrl;
2552
2553 /* Locate core99 Uni-N */
2554 uninorth_node = of_find_node_by_name(NULL, "uni-n");
2555 uninorth_maj = 1;
2556
2557 /* Locate G5 u3 */
2558 if (uninorth_node == NULL) {
2559 uninorth_node = of_find_node_by_name(NULL, "u3");
2560 uninorth_maj = 3;
2561 }
2562 /* Locate G5 u4 */
2563 if (uninorth_node == NULL) {
2564 uninorth_node = of_find_node_by_name(NULL, "u4");
2565 uninorth_maj = 4;
2566 }
2567 if (uninorth_node == NULL) {
2568 uninorth_maj = 0;
2569 return;
2570 }
2571
2572 addrp = of_get_property(uninorth_node, "reg", NULL);
2573 if (addrp == NULL)
2574 return;
2575 address = of_translate_address(uninorth_node, addrp);
2576 if (address == 0)
2577 return;
2578 uninorth_base = ioremap(address, 0x40000);
2579 if (uninorth_base == NULL)
2580 return;
2581 uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
2582 if (uninorth_maj == 3 || uninorth_maj == 4) {
2583 u3_ht_base = ioremap(address + U3_HT_CONFIG_BASE, 0x1000);
2584 if (u3_ht_base == NULL) {
2585 iounmap(uninorth_base);
2586 return;
2587 }
2588 }
2589
2590 printk(KERN_INFO "Found %s memory controller & host bridge"
2591 " @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :
2592 uninorth_maj == 4 ? "U4" : "UniNorth",
2593 (unsigned int)address, uninorth_rev);
2594 printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);
2595
2596 /* Set the arbitrer QAck delay according to what Apple does
2597 */
2598 if (uninorth_rev < 0x11) {
2599 actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;
2600 actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :
2601 UNI_N_ARB_CTRL_QACK_DELAY) <<
2602 UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
2603 UN_OUT(UNI_N_ARB_CTRL, actrl);
2604 }
2605
2606 /* Some more magic as done by them in recent MacOS X on UniNorth
2607 * revs 1.5 to 2.O and Pangea. Seem to toggle the UniN Maxbus/PCI
2608 * memory timeout
2609 */
2610 if ((uninorth_rev >= 0x11 && uninorth_rev <= 0x24) ||
2611 uninorth_rev == 0xc0)
2612 UN_OUT(0x2160, UN_IN(0x2160) & 0x00ffffff);
2613}
2614
2615static void __init probe_one_macio(const char *name, const char *compat, int type)
2616{
2617 struct device_node* node;
2618 int i;
2619 volatile u32 __iomem *base;
2620 const u32 *addrp, *revp;
2621 phys_addr_t addr;
2622 u64 size;
2623
2624 for_each_node_by_name(node, name) {
2625 if (!compat)
2626 break;
2627 if (of_device_is_compatible(node, compat))
2628 break;
2629 }
2630 if (!node)
2631 return;
2632 for(i=0; i<MAX_MACIO_CHIPS; i++) {
2633 if (!macio_chips[i].of_node)
2634 break;
2635 if (macio_chips[i].of_node == node)
2636 return;
2637 }
2638
2639 if (i >= MAX_MACIO_CHIPS) {
2640 printk(KERN_ERR "pmac_feature: Please increase MAX_MACIO_CHIPS !\n");
2641 printk(KERN_ERR "pmac_feature: %pOF skipped\n", node);
2642 return;
2643 }
2644 addrp = of_get_pci_address(node, 0, &size, NULL);
2645 if (addrp == NULL) {
2646 printk(KERN_ERR "pmac_feature: %pOF: can't find base !\n",
2647 node);
2648 return;
2649 }
2650 addr = of_translate_address(node, addrp);
2651 if (addr == 0) {
2652 printk(KERN_ERR "pmac_feature: %pOF, can't translate base !\n",
2653 node);
2654 return;
2655 }
2656 base = ioremap(addr, (unsigned long)size);
2657 if (!base) {
2658 printk(KERN_ERR "pmac_feature: %pOF, can't map mac-io chip !\n",
2659 node);
2660 return;
2661 }
2662 if (type == macio_keylargo || type == macio_keylargo2) {
2663 const u32 *did = of_get_property(node, "device-id", NULL);
2664 if (*did == 0x00000025)
2665 type = macio_pangea;
2666 if (*did == 0x0000003e)
2667 type = macio_intrepid;
2668 if (*did == 0x0000004f)
2669 type = macio_shasta;
2670 }
2671 macio_chips[i].of_node = node;
2672 macio_chips[i].type = type;
2673 macio_chips[i].base = base;
2674 macio_chips[i].flags = MACIO_FLAG_SCCA_ON | MACIO_FLAG_SCCB_ON;
2675 macio_chips[i].name = macio_names[type];
2676 revp = of_get_property(node, "revision-id", NULL);
2677 if (revp)
2678 macio_chips[i].rev = *revp;
2679 printk(KERN_INFO "Found a %s mac-io controller, rev: %d, mapped at 0x%p\n",
2680 macio_names[type], macio_chips[i].rev, macio_chips[i].base);
2681}
2682
2683static int __init
2684probe_macios(void)
2685{
2686 /* Warning, ordering is important */
2687 probe_one_macio("gc", NULL, macio_grand_central);
2688 probe_one_macio("ohare", NULL, macio_ohare);
2689 probe_one_macio("pci106b,7", NULL, macio_ohareII);
2690 probe_one_macio("mac-io", "keylargo", macio_keylargo);
2691 probe_one_macio("mac-io", "paddington", macio_paddington);
2692 probe_one_macio("mac-io", "gatwick", macio_gatwick);
2693 probe_one_macio("mac-io", "heathrow", macio_heathrow);
2694 probe_one_macio("mac-io", "K2-Keylargo", macio_keylargo2);
2695
2696 /* Make sure the "main" macio chip appear first */
2697 if (macio_chips[0].type == macio_gatwick
2698 && macio_chips[1].type == macio_heathrow) {
2699 struct macio_chip temp = macio_chips[0];
2700 macio_chips[0] = macio_chips[1];
2701 macio_chips[1] = temp;
2702 }
2703 if (macio_chips[0].type == macio_ohareII
2704 && macio_chips[1].type == macio_ohare) {
2705 struct macio_chip temp = macio_chips[0];
2706 macio_chips[0] = macio_chips[1];
2707 macio_chips[1] = temp;
2708 }
2709 macio_chips[0].lbus.index = 0;
2710 macio_chips[1].lbus.index = 1;
2711
2712 return (macio_chips[0].of_node == NULL) ? -ENODEV : 0;
2713}
2714
2715static void __init
2716initial_serial_shutdown(struct device_node *np)
2717{
2718 int len;
2719 const struct slot_names_prop {
2720 int count;
2721 char name[1];
2722 } *slots;
2723 const char *conn;
2724 int port_type = PMAC_SCC_ASYNC;
2725 int modem = 0;
2726
2727 slots = of_get_property(np, "slot-names", &len);
2728 conn = of_get_property(np, "AAPL,connector", &len);
2729 if (conn && (strcmp(conn, "infrared") == 0))
2730 port_type = PMAC_SCC_IRDA;
2731 else if (of_device_is_compatible(np, "cobalt"))
2732 modem = 1;
2733 else if (slots && slots->count > 0) {
2734 if (strcmp(slots->name, "IrDA") == 0)
2735 port_type = PMAC_SCC_IRDA;
2736 else if (strcmp(slots->name, "Modem") == 0)
2737 modem = 1;
2738 }
2739 if (modem)
2740 pmac_call_feature(PMAC_FTR_MODEM_ENABLE, np, 0, 0);
2741 pmac_call_feature(PMAC_FTR_SCC_ENABLE, np, port_type, 0);
2742}
2743
2744static void __init
2745set_initial_features(void)
2746{
2747 struct device_node *np;
2748
2749 /* That hack appears to be necessary for some StarMax motherboards
2750 * but I'm not too sure it was audited for side-effects on other
2751 * ohare based machines...
2752 * Since I still have difficulties figuring the right way to
2753 * differentiate them all and since that hack was there for a long
2754 * time, I'll keep it around
2755 */
2756 if (macio_chips[0].type == macio_ohare) {
2757 struct macio_chip *macio = &macio_chips[0];
2758 np = of_find_node_by_name(NULL, "via-pmu");
2759 if (np)
2760 MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
2761 else
2762 MACIO_OUT32(OHARE_FCR, STARMAX_FEATURES);
2763 of_node_put(np);
2764 } else if (macio_chips[1].type == macio_ohare) {
2765 struct macio_chip *macio = &macio_chips[1];
2766 MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
2767 }
2768
2769#ifdef CONFIG_PPC64
2770 if (macio_chips[0].type == macio_keylargo2 ||
2771 macio_chips[0].type == macio_shasta) {
2772#ifndef CONFIG_SMP
2773 /* On SMP machines running UP, we have the second CPU eating
2774 * bus cycles. We need to take it off the bus. This is done
2775 * from pmac_smp for SMP kernels running on one CPU
2776 */
2777 np = of_find_node_by_type(NULL, "cpu");
2778 if (np != NULL)
2779 np = of_find_node_by_type(np, "cpu");
2780 if (np != NULL) {
2781 g5_phy_disable_cpu1();
2782 of_node_put(np);
2783 }
2784#endif /* CONFIG_SMP */
2785 /* Enable GMAC for now for PCI probing. It will be disabled
2786 * later on after PCI probe
2787 */
2788 for_each_node_by_name(np, "ethernet")
2789 if (of_device_is_compatible(np, "K2-GMAC"))
2790 g5_gmac_enable(np, 0, 1);
2791
2792 /* Enable FW before PCI probe. Will be disabled later on
2793 * Note: We should have a batter way to check that we are
2794 * dealing with uninorth internal cell and not a PCI cell
2795 * on the external PCI. The code below works though.
2796 */
2797 for_each_node_by_name(np, "firewire") {
2798 if (of_device_is_compatible(np, "pci106b,5811")) {
2799 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
2800 g5_fw_enable(np, 0, 1);
2801 }
2802 }
2803 }
2804#else /* CONFIG_PPC64 */
2805
2806 if (macio_chips[0].type == macio_keylargo ||
2807 macio_chips[0].type == macio_pangea ||
2808 macio_chips[0].type == macio_intrepid) {
2809 /* Enable GMAC for now for PCI probing. It will be disabled
2810 * later on after PCI probe
2811 */
2812 for_each_node_by_name(np, "ethernet") {
2813 if (np->parent
2814 && of_device_is_compatible(np->parent, "uni-north")
2815 && of_device_is_compatible(np, "gmac"))
2816 core99_gmac_enable(np, 0, 1);
2817 }
2818
2819 /* Enable FW before PCI probe. Will be disabled later on
2820 * Note: We should have a batter way to check that we are
2821 * dealing with uninorth internal cell and not a PCI cell
2822 * on the external PCI. The code below works though.
2823 */
2824 for_each_node_by_name(np, "firewire") {
2825 if (np->parent
2826 && of_device_is_compatible(np->parent, "uni-north")
2827 && (of_device_is_compatible(np, "pci106b,18") ||
2828 of_device_is_compatible(np, "pci106b,30") ||
2829 of_device_is_compatible(np, "pci11c1,5811"))) {
2830 macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
2831 core99_firewire_enable(np, 0, 1);
2832 }
2833 }
2834
2835 /* Enable ATA-100 before PCI probe. */
2836 for_each_node_by_name(np, "ata-6") {
2837 if (np->parent
2838 && of_device_is_compatible(np->parent, "uni-north")
2839 && of_device_is_compatible(np, "kauai-ata")) {
2840 core99_ata100_enable(np, 1);
2841 }
2842 }
2843
2844 /* Switch airport off */
2845 for_each_node_by_name(np, "radio") {
2846 if (np->parent == macio_chips[0].of_node) {
2847 macio_chips[0].flags |= MACIO_FLAG_AIRPORT_ON;
2848 core99_airport_enable(np, 0, 0);
2849 }
2850 }
2851 }
2852
2853 /* On all machines that support sound PM, switch sound off */
2854 if (macio_chips[0].of_node)
2855 pmac_do_feature_call(PMAC_FTR_SOUND_CHIP_ENABLE,
2856 macio_chips[0].of_node, 0, 0);
2857
2858 /* While on some desktop G3s, we turn it back on */
2859 if (macio_chips[0].of_node && macio_chips[0].type == macio_heathrow
2860 && (pmac_mb.model_id == PMAC_TYPE_GOSSAMER ||
2861 pmac_mb.model_id == PMAC_TYPE_SILK)) {
2862 struct macio_chip *macio = &macio_chips[0];
2863 MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
2864 MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
2865 }
2866
2867#endif /* CONFIG_PPC64 */
2868
2869 /* On all machines, switch modem & serial ports off */
2870 for_each_node_by_name(np, "ch-a")
2871 initial_serial_shutdown(np);
2872 for_each_node_by_name(np, "ch-b")
2873 initial_serial_shutdown(np);
2874}
2875
2876void __init
2877pmac_feature_init(void)
2878{
2879 /* Detect the UniNorth memory controller */
2880 probe_uninorth();
2881
2882 /* Probe mac-io controllers */
2883 if (probe_macios()) {
2884 printk(KERN_WARNING "No mac-io chip found\n");
2885 return;
2886 }
2887
2888 /* Probe machine type */
2889 if (probe_motherboard())
2890 printk(KERN_WARNING "Unknown PowerMac !\n");
2891
2892 /* Set some initial features (turn off some chips that will
2893 * be later turned on)
2894 */
2895 set_initial_features();
2896}
2897
2898#if 0
2899static void dump_HT_speeds(char *name, u32 cfg, u32 frq)
2900{
2901 int freqs[16] = { 200,300,400,500,600,800,1000,0,0,0,0,0,0,0,0,0 };
2902 int bits[8] = { 8,16,0,32,2,4,0,0 };
2903 int freq = (frq >> 8) & 0xf;
2904
2905 if (freqs[freq] == 0)
2906 printk("%s: Unknown HT link frequency %x\n", name, freq);
2907 else
2908 printk("%s: %d MHz on main link, (%d in / %d out) bits width\n",
2909 name, freqs[freq],
2910 bits[(cfg >> 28) & 0x7], bits[(cfg >> 24) & 0x7]);
2911}
2912
2913void __init pmac_check_ht_link(void)
2914{
2915 u32 ufreq, freq, ucfg, cfg;
2916 struct device_node *pcix_node;
2917 u8 px_bus, px_devfn;
2918 struct pci_controller *px_hose;
2919
2920 (void)in_be32(u3_ht_base + U3_HT_LINK_COMMAND);
2921 ucfg = cfg = in_be32(u3_ht_base + U3_HT_LINK_CONFIG);
2922 ufreq = freq = in_be32(u3_ht_base + U3_HT_LINK_FREQ);
2923 dump_HT_speeds("U3 HyperTransport", cfg, freq);
2924
2925 pcix_node = of_find_compatible_node(NULL, "pci", "pci-x");
2926 if (pcix_node == NULL) {
2927 printk("No PCI-X bridge found\n");
2928 return;
2929 }
2930 if (pci_device_from_OF_node(pcix_node, &px_bus, &px_devfn) != 0) {
2931 printk("PCI-X bridge found but not matched to pci\n");
2932 return;
2933 }
2934 px_hose = pci_find_hose_for_OF_device(pcix_node);
2935 if (px_hose == NULL) {
2936 printk("PCI-X bridge found but not matched to host\n");
2937 return;
2938 }
2939 early_read_config_dword(px_hose, px_bus, px_devfn, 0xc4, &cfg);
2940 early_read_config_dword(px_hose, px_bus, px_devfn, 0xcc, &freq);
2941 dump_HT_speeds("PCI-X HT Uplink", cfg, freq);
2942 early_read_config_dword(px_hose, px_bus, px_devfn, 0xc8, &cfg);
2943 early_read_config_dword(px_hose, px_bus, px_devfn, 0xd0, &freq);
2944 dump_HT_speeds("PCI-X HT Downlink", cfg, freq);
2945}
2946#endif /* 0 */
2947
2948/*
2949 * Early video resume hook
2950 */
2951
2952static void (*pmac_early_vresume_proc)(void *data);
2953static void *pmac_early_vresume_data;
2954
2955void pmac_set_early_video_resume(void (*proc)(void *data), void *data)
2956{
2957 if (!machine_is(powermac))
2958 return;
2959 preempt_disable();
2960 pmac_early_vresume_proc = proc;
2961 pmac_early_vresume_data = data;
2962 preempt_enable();
2963}
2964EXPORT_SYMBOL(pmac_set_early_video_resume);
2965
2966void pmac_call_early_video_resume(void)
2967{
2968 if (pmac_early_vresume_proc)
2969 pmac_early_vresume_proc(pmac_early_vresume_data);
2970}
2971
2972/*
2973 * AGP related suspend/resume code
2974 */
2975
2976static struct pci_dev *pmac_agp_bridge;
2977static int (*pmac_agp_suspend)(struct pci_dev *bridge);
2978static int (*pmac_agp_resume)(struct pci_dev *bridge);
2979
2980void pmac_register_agp_pm(struct pci_dev *bridge,
2981 int (*suspend)(struct pci_dev *bridge),
2982 int (*resume)(struct pci_dev *bridge))
2983{
2984 if (suspend || resume) {
2985 pmac_agp_bridge = bridge;
2986 pmac_agp_suspend = suspend;
2987 pmac_agp_resume = resume;
2988 return;
2989 }
2990 if (bridge != pmac_agp_bridge)
2991 return;
2992 pmac_agp_suspend = pmac_agp_resume = NULL;
2993 return;
2994}
2995EXPORT_SYMBOL(pmac_register_agp_pm);
2996
2997void pmac_suspend_agp_for_card(struct pci_dev *dev)
2998{
2999 if (pmac_agp_bridge == NULL || pmac_agp_suspend == NULL)
3000 return;
3001 if (pmac_agp_bridge->bus != dev->bus)
3002 return;
3003 pmac_agp_suspend(pmac_agp_bridge);
3004}
3005EXPORT_SYMBOL(pmac_suspend_agp_for_card);
3006
3007void pmac_resume_agp_for_card(struct pci_dev *dev)
3008{
3009 if (pmac_agp_bridge == NULL || pmac_agp_resume == NULL)
3010 return;
3011 if (pmac_agp_bridge->bus != dev->bus)
3012 return;
3013 pmac_agp_resume(pmac_agp_bridge);
3014}
3015EXPORT_SYMBOL(pmac_resume_agp_for_card);
3016
3017int pmac_get_uninorth_variant(void)
3018{
3019 return uninorth_maj;
3020}