pmac_feature.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:56k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * BK Id: %F% %I% %G% %U% %#%
  3.  */
  4. /*
  5.  *  arch/ppc/kernel/pmac_feature.c
  6.  *
  7.  *  Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au)
  8.  *                          Ben. Herrenschmidt (benh@kernel.crashing.org)
  9.  *
  10.  *  This program is free software; you can redistribute it and/or
  11.  *  modify it under the terms of the GNU General Public License
  12.  *  as published by the Free Software Foundation; either version
  13.  *  2 of the License, or (at your option) any later version.
  14.  *  
  15.  *  TODO: 
  16.  *  
  17.  *   - Replace mdelay with some schedule loop if possible
  18.  *   - Shorten some obfuscated delays on some routines (like modem
  19.  *     power)
  20.  *
  21.  */
  22. #include <linux/config.h>
  23. #include <linux/types.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/kernel.h>
  27. #include <linux/sched.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/adb.h>
  30. #include <linux/pmu.h>
  31. #include <asm/sections.h>
  32. #include <asm/errno.h>
  33. #include <asm/ohare.h>
  34. #include <asm/heathrow.h>
  35. #include <asm/keylargo.h>
  36. #include <asm/uninorth.h>
  37. #include <asm/io.h>
  38. #include <asm/prom.h>
  39. #include <asm/machdep.h>
  40. #include <asm/pmac_feature.h>
  41. #include <asm/dbdma.h>
  42. #undef DEBUG_FEATURE
  43. #ifdef DEBUG_FEATURE
  44. #define DBG(fmt,...) printk(KERN_DEBUG fmt)
  45. #else
  46. #define DBG(fmt,...)
  47. #endif
  48. /* Exported from arch/ppc/kernel/idle.c */
  49. extern unsigned long powersave_nap;
  50. /*
  51.  * We use a single global lock to protect accesses. Each driver has
  52.  * to take care of it's own locking
  53.  */
  54. static spinlock_t feature_lock  __pmacdata = SPIN_LOCK_UNLOCKED;
  55. #define LOCK(flags) spin_lock_irqsave(&feature_lock, flags);
  56. #define UNLOCK(flags) spin_unlock_irqrestore(&feature_lock, flags);
  57. /*
  58.  * Helper functions regarding the various flavors of mac-io
  59.  */
  60.  
  61. #define MAX_MACIO_CHIPS 2
  62. enum {
  63. macio_unknown = 0,
  64. macio_grand_central,
  65. macio_ohare,
  66. macio_ohareII,
  67. macio_heathrow,
  68. macio_gatwick,
  69. macio_paddington,
  70. macio_keylargo,
  71. macio_pangea
  72. };
  73. static const char* macio_names[] __pmacdata = 
  74. {
  75. "Unknown",
  76. "Grand Central",
  77. "OHare",
  78. "OHareII",
  79. "Heathrow",
  80. "Gatwick",
  81. "Paddington",
  82. "Keylargo",
  83. "Pangea"
  84. };
  85. static struct macio_chip
  86. {
  87. struct device_node* of_node;
  88. int type;
  89. int rev;
  90. volatile u32* base;
  91. unsigned long flags;
  92. } macio_chips[MAX_MACIO_CHIPS]  __pmacdata;
  93. #define MACIO_FLAG_SCCA_ON 0x00000001
  94. #define MACIO_FLAG_SCCB_ON 0x00000002
  95. #define MACIO_FLAG_SCC_LOCKED 0x00000004
  96. #define MACIO_FLAG_AIRPORT_ON 0x00000010
  97. #define MACIO_FLAG_FW_SUPPORTED 0x00000020
  98. static struct macio_chip* __pmac
  99. macio_find(struct device_node* child, int type)
  100. {
  101. while(child) {
  102. int i;
  103. for (i=0; i < MAX_MACIO_CHIPS && macio_chips[i].of_node; i++)
  104. if (child == macio_chips[i].of_node &&
  105.     (!type || macio_chips[i].type == type))
  106. return &macio_chips[i];
  107. child = child->parent;
  108. }
  109. return NULL;
  110. }
  111. #define MACIO_FCR32(macio, r) ((macio)->base + ((r) >> 2))
  112. #define MACIO_FCR8(macio, r) (((volatile u8*)((macio)->base)) + (r))
  113. #define MACIO_IN32(r) (in_le32(MACIO_FCR32(macio,r)))
  114. #define MACIO_OUT32(r,v) (out_le32(MACIO_FCR32(macio,r), (v)))
  115. #define MACIO_BIS(r,v) (MACIO_OUT32((r), MACIO_IN32(r) | (v)))
  116. #define MACIO_BIC(r,v) (MACIO_OUT32((r), MACIO_IN32(r) & ~(v)))
  117. #define MACIO_IN8(r) (in_8(MACIO_FCR8(macio,r)))
  118. #define MACIO_OUT8(r,v) (out_8(MACIO_FCR8(macio,r), (v)))
  119. /*
  120.  * Uninorth reg. access. Note that Uni-N regs are big endian
  121.  */
  122.  
  123. #define UN_REG(r) (uninorth_base + ((r) >> 2))
  124. #define UN_IN(r) (in_be32(UN_REG(r)))
  125. #define UN_OUT(r,v) (out_be32(UN_REG(r), (v)))
  126. #define UN_BIS(r,v) (UN_OUT((r), UN_IN(r) | (v)))
  127. #define UN_BIC(r,v) (UN_OUT((r), UN_IN(r) & ~(v)))
  128. static struct device_node* uninorth_node __pmacdata;
  129. static u32* uninorth_base __pmacdata;
  130. static u32 uninorth_rev __pmacdata;
  131. /*
  132.  * For each motherboard family, we have a table of functions pointers
  133.  * that handle the various features.
  134.  */
  135. typedef int (*feature_call)(struct device_node* node, int param, int value);
  136. struct feature_table_entry {
  137. unsigned int selector;
  138. feature_call function;
  139. };
  140. struct pmac_mb_def
  141. {
  142. const char* model_string;
  143. const char* model_name;
  144. int model_id;
  145. struct feature_table_entry*  features;
  146. unsigned long board_flags;
  147. };
  148. static struct pmac_mb_def pmac_mb __pmacdata;
  149. /*
  150.  * Here are the chip specific feature functions
  151.  */
  152. static inline int __pmac
  153. simple_feature_tweak(struct device_node* node, int type, int reg, u32 mask, int value)
  154. {
  155. struct macio_chip* macio;
  156. unsigned long flags;
  157. macio = macio_find(node, type);
  158. if (!macio)
  159. return -ENODEV;
  160. LOCK(flags);
  161. if (value)
  162. MACIO_BIS(reg, mask);
  163. else
  164. MACIO_BIC(reg, mask);
  165. (void)MACIO_IN32(reg);
  166. UNLOCK(flags);
  167. return 0;
  168. }
  169. static int __pmac
  170. generic_scc_enable(struct device_node* node, u32 enable_mask, u32 reset_mask,
  171. int param, int value)
  172. {
  173. struct macio_chip* macio;
  174. unsigned long chan_mask;
  175. unsigned long fcr;
  176. unsigned long flags;
  177. macio = macio_find(node, 0);
  178. if (!macio)
  179. return -ENODEV;
  180. if (!strcmp(node->name, "ch-a"))
  181. chan_mask = MACIO_FLAG_SCCA_ON;
  182. else if (!strcmp(node->name, "ch-b"))
  183. chan_mask = MACIO_FLAG_SCCB_ON;
  184. else
  185. return -ENODEV;
  186. if (value) {
  187. LOCK(flags);
  188. fcr = MACIO_IN32(OHARE_FCR);
  189. /* Check if scc cell need enabling */
  190. if (!(fcr & OH_SCC_ENABLE)) {
  191. fcr |= enable_mask;
  192. MACIO_OUT32(OHARE_FCR, fcr);
  193. fcr |= reset_mask;
  194. MACIO_OUT32(OHARE_FCR, fcr);
  195. UNLOCK(flags);
  196. (void)MACIO_IN32(OHARE_FCR);
  197. mdelay(15);
  198. LOCK(flags);
  199. fcr &= ~reset_mask;
  200. MACIO_OUT32(OHARE_FCR, fcr);
  201. }
  202. if (chan_mask & MACIO_FLAG_SCCA_ON)
  203. fcr |= OH_SCCA_IO;
  204. if (chan_mask & MACIO_FLAG_SCCB_ON)
  205. fcr |= OH_SCCB_IO;
  206. MACIO_OUT32(OHARE_FCR, fcr);
  207. macio->flags |= chan_mask;
  208. UNLOCK(flags);
  209. if (param & PMAC_SCC_FLAG_XMON)
  210. macio->flags |= MACIO_FLAG_SCC_LOCKED;
  211. } else {
  212. if (macio->flags & MACIO_FLAG_SCC_LOCKED)
  213. return -EPERM;
  214. LOCK(flags);
  215. fcr = MACIO_IN32(OHARE_FCR);
  216. if (chan_mask & MACIO_FLAG_SCCA_ON)
  217. fcr &= ~OH_SCCA_IO;
  218. if (chan_mask & MACIO_FLAG_SCCB_ON)
  219. fcr &= ~OH_SCCB_IO;
  220. MACIO_OUT32(OHARE_FCR, fcr);
  221. if ((fcr & (OH_SCCA_IO | OH_SCCB_IO)) == 0) {
  222. fcr &= ~enable_mask;
  223. MACIO_OUT32(OHARE_FCR, fcr);
  224. }
  225. macio->flags &= ~(chan_mask);
  226. UNLOCK(flags);
  227. mdelay(10);
  228. }
  229. return 0;
  230. }
  231. static int __pmac
  232. ohare_scc_enable(struct device_node* node, int param, int value)
  233. {
  234. int rc;
  235. #ifdef CONFIG_ADB_PMU
  236. if (value && (param & 0xfff) == PMAC_SCC_IRDA)
  237. pmu_enable_irled(1);
  238. #endif /* CONFIG_ADB_PMU */
  239. rc = generic_scc_enable(node, OH_SCC_ENABLE, OH_SCC_RESET, param, value);
  240. #ifdef CONFIG_ADB_PMU
  241. if ((param & 0xfff) == PMAC_SCC_IRDA && (rc || !value))
  242. pmu_enable_irled(0);
  243. #endif /* CONFIG_ADB_PMU */
  244. return rc;
  245. }
  246. static int __pmac
  247. ohare_floppy_enable(struct device_node* node, int param, int value)
  248. {
  249. return simple_feature_tweak(node, macio_ohare,
  250. OHARE_FCR, OH_FLOPPY_ENABLE, value);
  251. }
  252. static int __pmac
  253. ohare_mesh_enable(struct device_node* node, int param, int value)
  254. {
  255. return simple_feature_tweak(node, macio_ohare,
  256. OHARE_FCR, OH_MESH_ENABLE, value);
  257. }
  258. static int __pmac
  259. ohare_ide_enable(struct device_node* node, int param, int value)
  260. {
  261. switch(param) {
  262.     case 0:
  263.      /* For some reason, setting the bit in set_initial_features()
  264.       * doesn't stick. I'm still investigating... --BenH.
  265.       */
  266.      if (value)
  267.      simple_feature_tweak(node, macio_ohare,
  268. OHARE_FCR, OH_IOBUS_ENABLE, 1);
  269. return simple_feature_tweak(node, macio_ohare,
  270. OHARE_FCR, OH_IDE0_ENABLE, value);
  271.     case 1:
  272. return simple_feature_tweak(node, macio_ohare,
  273. OHARE_FCR, OH_BAY_IDE_ENABLE, value);
  274.     default:
  275.      return -ENODEV;
  276. }
  277. }
  278. static int __pmac
  279. ohare_ide_reset(struct device_node* node, int param, int value)
  280. {
  281. switch(param) {
  282.     case 0:
  283. return simple_feature_tweak(node, macio_ohare,
  284. OHARE_FCR, OH_IDE0_RESET_N, !value);
  285.     case 1:
  286. return simple_feature_tweak(node, macio_ohare,
  287. OHARE_FCR, OH_IDE1_RESET_N, !value);
  288.     default:
  289.      return -ENODEV;
  290. }
  291. }
  292. static int __pmac
  293. ohare_sleep_state(struct device_node* node, int param, int value)
  294. {
  295. struct macio_chip* macio = &macio_chips[0];
  296. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  297. return -EPERM;
  298. if (value) {
  299. MACIO_BIC(OHARE_FCR, OH_IOBUS_ENABLE);
  300. } else {
  301. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  302. }
  303. return 0;
  304. }
  305. static int __pmac
  306. heathrow_scc_enable(struct device_node* node, int param, int value)
  307. {
  308. int rc;
  309. #ifdef CONFIG_ADB_PMU
  310. if (value && param == PMAC_SCC_IRDA)
  311. pmu_enable_irled(1);
  312. #endif /* CONFIG_ADB_PMU */
  313. /* Fixme: It's possible that wallstreet (heathrow) is different
  314.  * than other paddington machines. I still have to figure that
  315.  * out exactly, for now, the paddington values are used
  316.  */
  317. rc = generic_scc_enable(node, HRW_SCC_ENABLE, PADD_RESET_SCC, param, value);
  318. #ifdef CONFIG_ADB_PMU
  319. if (param == PMAC_SCC_IRDA && (rc || !value))
  320. pmu_enable_irled(0);
  321. #endif /* CONFIG_ADB_PMU */
  322. return rc;
  323. }
  324. static int __pmac
  325. heathrow_modem_enable(struct device_node* node, int param, int value)
  326. {
  327. struct macio_chip* macio;
  328. u8 gpio;
  329. unsigned long flags;
  330. macio = macio_find(node, macio_unknown);
  331. if (!macio)
  332. return -ENODEV;
  333. gpio = MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1;
  334. if (!value) {
  335. LOCK(flags);
  336. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
  337. UNLOCK(flags);
  338. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  339. mdelay(250);
  340. }
  341. if (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
  342.     pmac_mb.model_id != PMAC_TYPE_YIKES) {
  343.      LOCK(flags);
  344.      /* We use the paddington values as they seem to work properly
  345.       * on the wallstreet (heathrow) as well. I can't tell why we
  346.       * had to flip them on older feature.c, the fact is that new
  347.       * code uses the paddington values which are also the ones used
  348.       * in Darwin, and that works on wallstreet !
  349.       */
  350.      if (value)
  351.      MACIO_BIC(HEATHROW_FCR, PADD_MODEM_POWER_N);
  352.      else
  353.      MACIO_BIS(HEATHROW_FCR, PADD_MODEM_POWER_N);
  354.      UNLOCK(flags);
  355.      (void)MACIO_IN32(HEATHROW_FCR);
  356. mdelay(250);
  357. }
  358. if (value) {
  359. LOCK(flags);
  360. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
  361. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  362.      UNLOCK(flags); mdelay(250); LOCK(flags);
  363. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio);
  364. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  365.      UNLOCK(flags); mdelay(250); LOCK(flags);
  366. MACIO_OUT8(HRW_GPIO_MODEM_RESET, gpio | 1);
  367. (void)MACIO_IN8(HRW_GPIO_MODEM_RESET);
  368.      UNLOCK(flags); mdelay(250); LOCK(flags);
  369. }
  370. return 0;
  371. }
  372. static int __pmac
  373. heathrow_floppy_enable(struct device_node* node, int param, int value)
  374. {
  375. return simple_feature_tweak(node, macio_unknown,
  376. HEATHROW_FCR,
  377. HRW_SWIM_ENABLE|HRW_BAY_FLOPPY_ENABLE,
  378. value);
  379. }
  380. static int __pmac
  381. heathrow_mesh_enable(struct device_node* node, int param, int value)
  382. {
  383. struct macio_chip* macio;
  384. unsigned long flags;
  385. macio = macio_find(node, macio_unknown);
  386. if (!macio)
  387. return -ENODEV;
  388. LOCK(flags);
  389. /* Set clear mesh cell enable */
  390. if (value)
  391. MACIO_BIS(HEATHROW_FCR, HRW_MESH_ENABLE);
  392. else
  393. MACIO_BIC(HEATHROW_FCR, HRW_MESH_ENABLE);
  394. (void)MACIO_IN32(HEATHROW_FCR);
  395. udelay(10);
  396. /* Set/Clear termination power (todo: test ! the bit value
  397.  * used by Darwin doesn't seem to match what we used so
  398.  * far. If you experience problems, turn #if 1 into #if 0
  399.  * and tell me about it --BenH.
  400.  */
  401. #if 1
  402. if (value)
  403. MACIO_BIC(HEATHROW_MBCR, 0x00000004);
  404. else
  405. MACIO_BIS(HEATHROW_MBCR, 0x00000004);
  406. #else
  407. if (value)
  408. MACIO_BIC(HEATHROW_MBCR, 0x00040000);
  409. else
  410. MACIO_BIS(HEATHROW_MBCR, 0x00040000);
  411. #endif
  412. (void)MACIO_IN32(HEATHROW_MBCR);
  413. udelay(10);
  414. UNLOCK(flags);
  415. return 0;
  416. }
  417. static int __pmac
  418. heathrow_ide_enable(struct device_node* node, int param, int value)
  419. {
  420. switch(param) {
  421.     case 0:
  422. return simple_feature_tweak(node, macio_unknown,
  423. HEATHROW_FCR, HRW_IDE0_ENABLE, value);
  424.     case 1:
  425. return simple_feature_tweak(node, macio_unknown,
  426. HEATHROW_FCR, HRW_BAY_IDE_ENABLE, value);
  427.     default:
  428.      return -ENODEV;
  429. }
  430. }
  431. static int __pmac
  432. heathrow_ide_reset(struct device_node* node, int param, int value)
  433. {
  434. switch(param) {
  435.     case 0:
  436. return simple_feature_tweak(node, macio_unknown,
  437. HEATHROW_FCR, HRW_IDE0_RESET_N, !value);
  438.     case 1:
  439. return simple_feature_tweak(node, macio_unknown,
  440. HEATHROW_FCR, HRW_IDE1_RESET_N, !value);
  441.     default:
  442.      return -ENODEV;
  443. }
  444. }
  445. static int __pmac
  446. heathrow_bmac_enable(struct device_node* node, int param, int value)
  447. {
  448. struct macio_chip* macio;
  449. unsigned long flags;
  450. macio = macio_find(node, 0);
  451. if (!macio)
  452. return -ENODEV;
  453. if (value) {
  454. LOCK(flags);
  455. MACIO_BIS(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
  456. MACIO_BIS(HEATHROW_FCR, HRW_BMAC_RESET);
  457. UNLOCK(flags);
  458. (void)MACIO_IN32(HEATHROW_FCR);
  459. mdelay(10);
  460. LOCK(flags);
  461. MACIO_BIC(HEATHROW_FCR, HRW_BMAC_RESET);
  462. UNLOCK(flags);
  463. (void)MACIO_IN32(HEATHROW_FCR);
  464. mdelay(10);
  465. } else {
  466. LOCK(flags);
  467. MACIO_BIC(HEATHROW_FCR, HRW_BMAC_IO_ENABLE);
  468. UNLOCK(flags);
  469. }
  470. return 0;
  471. }
  472. static int __pmac
  473. heathrow_sound_enable(struct device_node* node, int param, int value)
  474. {
  475. struct macio_chip* macio;
  476. unsigned long flags;
  477. /* B&W G3 and Yikes don't support that properly (the
  478.  * sound appear to never come back after beeing shut down).
  479.  */
  480. if (pmac_mb.model_id == PMAC_TYPE_YOSEMITE ||
  481.     pmac_mb.model_id == PMAC_TYPE_YIKES)
  482. return 0;
  483. macio = macio_find(node, 0);
  484. if (!macio)
  485. return -ENODEV;
  486. if (value) {
  487. LOCK(flags);
  488. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  489. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_POWER_N);
  490. UNLOCK(flags);
  491. (void)MACIO_IN32(HEATHROW_FCR);
  492. } else {
  493. LOCK(flags);
  494. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
  495. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  496. UNLOCK(flags);
  497. }
  498. return 0;
  499. }
  500. static u32 save_fcr[5] __pmacdata;
  501. static u32 save_mbcr __pmacdata;
  502. static u32 save_gpio_levels[2] __pmacdata;
  503. static u8 save_gpio_extint[KEYLARGO_GPIO_EXTINT_CNT] __pmacdata;
  504. static u8 save_gpio_normal[KEYLARGO_GPIO_CNT] __pmacdata;
  505. static u32 save_unin_clock_ctl __pmacdata;
  506. static struct dbdma_regs save_dbdma[13] __pmacdata;
  507. static struct dbdma_regs save_alt_dbdma[13] __pmacdata;
  508. static void __pmac
  509. dbdma_save(struct macio_chip* macio, struct dbdma_regs* save)
  510. {
  511. int i;
  512. /* Save state & config of DBDMA channels */
  513. for (i=0; i<13; i++) {
  514. volatile struct dbdma_regs* chan = (volatile struct dbdma_regs*)
  515. (macio->base + ((0x8000+i*0x100)>>2));
  516. save[i].cmdptr_hi = in_le32(&chan->cmdptr_hi);
  517. save[i].cmdptr = in_le32(&chan->cmdptr);
  518. save[i].intr_sel = in_le32(&chan->intr_sel);
  519. save[i].br_sel = in_le32(&chan->br_sel);
  520. save[i].wait_sel = in_le32(&chan->wait_sel);
  521. }
  522. }
  523. static void __pmac
  524. dbdma_restore(struct macio_chip* macio, struct dbdma_regs* save)
  525. {
  526. int i;
  527. /* Save state & config of DBDMA channels */
  528. for (i=0; i<13; i++) {
  529. volatile struct dbdma_regs* chan = (volatile struct dbdma_regs*)
  530. (macio->base + ((0x8000+i*0x100)>>2));
  531. out_le32(&chan->control, (ACTIVE|DEAD|WAKE|FLUSH|PAUSE|RUN)<<16);
  532. while (in_le32(&chan->status) & ACTIVE)
  533. mb();
  534. out_le32(&chan->cmdptr_hi, save[i].cmdptr_hi);
  535. out_le32(&chan->cmdptr, save[i].cmdptr);
  536. out_le32(&chan->intr_sel, save[i].intr_sel);
  537. out_le32(&chan->br_sel, save[i].br_sel);
  538. out_le32(&chan->wait_sel, save[i].wait_sel);
  539. }
  540. }
  541. static void __pmac
  542. heathrow_sleep(struct macio_chip* macio, int secondary)
  543. {
  544. if (secondary) {
  545. dbdma_save(macio, save_alt_dbdma);
  546. save_fcr[2] = MACIO_IN32(0x38);
  547. save_fcr[3] = MACIO_IN32(0x3c);
  548. } else {
  549. dbdma_save(macio, save_dbdma);
  550. save_fcr[0] = MACIO_IN32(0x38);
  551. save_fcr[1] = MACIO_IN32(0x3c);
  552. save_mbcr = MACIO_IN32(0x34);
  553. /* Make sure sound is shut down */
  554. MACIO_BIS(HEATHROW_FCR, HRW_SOUND_POWER_N);
  555. MACIO_BIC(HEATHROW_FCR, HRW_SOUND_CLK_ENABLE);
  556. /* This seems to be necessary as well or the fan
  557.  * keeps coming up and battery drains fast */
  558. MACIO_BIC(HEATHROW_FCR, HRW_IOBUS_ENABLE);
  559. }
  560. /* Make sure modem is shut down */
  561. MACIO_OUT8(HRW_GPIO_MODEM_RESET,
  562. MACIO_IN8(HRW_GPIO_MODEM_RESET) & ~1);
  563. MACIO_BIS(HEATHROW_FCR, PADD_MODEM_POWER_N);
  564. MACIO_BIC(HEATHROW_FCR, OH_SCCA_IO|OH_SCCB_IO|HRW_SCC_ENABLE);
  565. /* Let things settle */
  566. (void)MACIO_IN32(HEATHROW_FCR);
  567. mdelay(1);
  568. }
  569. static void __pmac
  570. heathrow_wakeup(struct macio_chip* macio, int secondary)
  571. {
  572. if (secondary) {
  573. MACIO_OUT32(0x38, save_fcr[2]);
  574. (void)MACIO_IN32(0x38);
  575. mdelay(1);
  576. MACIO_OUT32(0x3c, save_fcr[3]);
  577. (void)MACIO_IN32(0x38);
  578. mdelay(10);
  579. dbdma_restore(macio, save_alt_dbdma);
  580. } else {
  581. MACIO_OUT32(0x38, save_fcr[0] | HRW_IOBUS_ENABLE);
  582. (void)MACIO_IN32(0x38);
  583. mdelay(1);
  584. MACIO_OUT32(0x3c, save_fcr[1]);
  585. (void)MACIO_IN32(0x38);
  586. mdelay(1);
  587. MACIO_OUT32(0x34, save_mbcr);
  588. (void)MACIO_IN32(0x38);
  589. mdelay(10);
  590. dbdma_restore(macio, save_dbdma);
  591. }
  592. }
  593. static int __pmac
  594. heathrow_sleep_state(struct device_node* node, int param, int value)
  595. {
  596. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  597. return -EPERM;
  598. if (value == 1) {
  599. if (macio_chips[1].type == macio_gatwick)
  600. heathrow_sleep(&macio_chips[0], 1);
  601. heathrow_sleep(&macio_chips[0], 0);
  602. } else if (value == 0) {
  603. heathrow_wakeup(&macio_chips[0], 0);
  604. if (macio_chips[1].type == macio_gatwick)
  605. heathrow_wakeup(&macio_chips[0], 1);
  606. }
  607. return 0;
  608. }
  609. static int __pmac
  610. core99_scc_enable(struct device_node* node, int param, int value)
  611. {
  612. struct macio_chip* macio;
  613. unsigned long flags;
  614. unsigned long chan_mask;
  615. u32 fcr;
  616. macio = macio_find(node, 0);
  617. if (!macio)
  618. return -ENODEV;
  619. if (!strcmp(node->name, "ch-a"))
  620. chan_mask = MACIO_FLAG_SCCA_ON;
  621. else if (!strcmp(node->name, "ch-b"))
  622. chan_mask = MACIO_FLAG_SCCB_ON;
  623. else
  624. return -ENODEV;
  625. if (value) {
  626. int need_reset_scc = 0;
  627. int need_reset_irda = 0;
  628. LOCK(flags);
  629. fcr = MACIO_IN32(KEYLARGO_FCR0);
  630. /* Check if scc cell need enabling */
  631. if (!(fcr & KL0_SCC_CELL_ENABLE)) {
  632. fcr |= KL0_SCC_CELL_ENABLE;
  633. need_reset_scc = 1;
  634. }
  635. if (chan_mask & MACIO_FLAG_SCCA_ON) {
  636. fcr |= KL0_SCCA_ENABLE;
  637. /* Don't enable line drivers for I2S modem */
  638. if ((param & 0xfff) == PMAC_SCC_I2S1)
  639. fcr &= ~KL0_SCC_A_INTF_ENABLE;
  640. else
  641. fcr |= KL0_SCC_A_INTF_ENABLE;
  642. }
  643. if (chan_mask & MACIO_FLAG_SCCB_ON) {
  644. fcr |= KL0_SCCB_ENABLE;
  645. /* Perform irda specific inits */
  646. if ((param & 0xfff) == PMAC_SCC_IRDA) {
  647. fcr &= ~KL0_SCC_B_INTF_ENABLE;
  648. fcr |= KL0_IRDA_ENABLE;
  649. fcr |= KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE;
  650. fcr |= KL0_IRDA_SOURCE1_SEL;
  651. fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
  652. fcr &= ~(KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
  653. need_reset_irda = 1;
  654. } else
  655. fcr |= KL0_SCC_B_INTF_ENABLE;
  656. }
  657. MACIO_OUT32(KEYLARGO_FCR0, fcr);
  658. macio->flags |= chan_mask;
  659. if (need_reset_scc)  {
  660. MACIO_BIS(KEYLARGO_FCR0, KL0_SCC_RESET);
  661. (void)MACIO_IN32(KEYLARGO_FCR0);
  662. UNLOCK(flags);
  663. mdelay(15);
  664. LOCK(flags);
  665. MACIO_BIC(KEYLARGO_FCR0, KL0_SCC_RESET);
  666. }
  667. if (need_reset_irda)  {
  668. MACIO_BIS(KEYLARGO_FCR0, KL0_IRDA_RESET);
  669. (void)MACIO_IN32(KEYLARGO_FCR0);
  670. UNLOCK(flags);
  671. mdelay(15);
  672. LOCK(flags);
  673. MACIO_BIC(KEYLARGO_FCR0, KL0_IRDA_RESET);
  674. }
  675. UNLOCK(flags);
  676. if (param & PMAC_SCC_FLAG_XMON)
  677. macio->flags |= MACIO_FLAG_SCC_LOCKED;
  678. } else {
  679. if (macio->flags & MACIO_FLAG_SCC_LOCKED)
  680. return -EPERM;
  681. LOCK(flags);
  682. fcr = MACIO_IN32(KEYLARGO_FCR0);
  683. if (chan_mask & MACIO_FLAG_SCCA_ON)
  684. fcr &= ~KL0_SCCA_ENABLE;
  685. if (chan_mask & MACIO_FLAG_SCCB_ON) {
  686. fcr &= ~KL0_SCCB_ENABLE;
  687. /* Perform irda specific clears */
  688. if ((param & 0xfff) == PMAC_SCC_IRDA) {
  689. fcr &= ~KL0_IRDA_ENABLE;
  690. fcr &= ~(KL0_IRDA_CLK32_ENABLE | KL0_IRDA_CLK19_ENABLE);
  691. fcr &= ~(KL0_IRDA_FAST_CONNECT|KL0_IRDA_DEFAULT1|KL0_IRDA_DEFAULT0);
  692. fcr &= ~(KL0_IRDA_SOURCE1_SEL|KL0_IRDA_SOURCE2_SEL|KL0_IRDA_HIGH_BAND);
  693. }
  694. }
  695. MACIO_OUT32(KEYLARGO_FCR0, fcr);
  696. if ((fcr & (KL0_SCCA_ENABLE | KL0_SCCB_ENABLE)) == 0) {
  697. fcr &= ~KL0_SCC_CELL_ENABLE;
  698. MACIO_OUT32(KEYLARGO_FCR0, fcr);
  699. }
  700. macio->flags &= ~(chan_mask);
  701. UNLOCK(flags);
  702. mdelay(10);
  703. }
  704. return 0;
  705. }
  706. static int __pmac
  707. core99_modem_enable(struct device_node* node, int param, int value)
  708. {
  709. struct macio_chip* macio;
  710. u8 gpio;
  711. unsigned long flags;
  712. macio = macio_find(node, 0);
  713. if (!macio)
  714. return -ENODEV;
  715. gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
  716. gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
  717. gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
  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); LOCK(flags);
  746. }
  747. return 0;
  748. }
  749. static int __pmac
  750. core99_ide_enable(struct device_node* node, int param, int value)
  751. {
  752. switch(param) {
  753.     case 0:
  754. return simple_feature_tweak(node, macio_unknown,
  755. KEYLARGO_FCR1, KL1_EIDE0_ENABLE, value);
  756.     case 1:
  757. return simple_feature_tweak(node, macio_unknown,
  758. KEYLARGO_FCR1, KL1_EIDE1_ENABLE, value);
  759.     case 2:
  760. return simple_feature_tweak(node, macio_unknown,
  761. KEYLARGO_FCR1, KL1_UIDE_ENABLE, value);
  762.     default:
  763.      return -ENODEV;
  764. }
  765. }
  766. static int __pmac
  767. core99_ide_reset(struct device_node* node, int param, int value)
  768. {
  769. switch(param) {
  770.     case 0:
  771. return simple_feature_tweak(node, macio_unknown,
  772. KEYLARGO_FCR1, KL1_EIDE0_RESET_N, !value);
  773.     case 1:
  774. return simple_feature_tweak(node, macio_unknown,
  775. KEYLARGO_FCR1, KL1_EIDE1_RESET_N, !value);
  776.     case 2:
  777. return simple_feature_tweak(node, macio_unknown,
  778. KEYLARGO_FCR1, KL1_UIDE_RESET_N, !value);
  779.     default:
  780.      return -ENODEV;
  781. }
  782. }
  783. static int __pmac
  784. core99_gmac_enable(struct device_node* node, int param, int value)
  785. {
  786. unsigned long flags;
  787. LOCK(flags);
  788. if (value)
  789. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
  790. else
  791. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_GMAC);
  792. (void)UN_IN(UNI_N_CLOCK_CNTL);
  793. UNLOCK(flags);
  794. udelay(20);
  795. return 0;
  796. }
  797. static int __pmac
  798. core99_gmac_phy_reset(struct device_node* node, int param, int value)
  799. {
  800. unsigned long flags;
  801. struct macio_chip* macio;
  802. macio = &macio_chips[0];
  803. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  804. return -ENODEV;
  805. LOCK(flags);
  806. MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE);
  807. (void)MACIO_IN8(KL_GPIO_ETH_PHY_RESET);
  808. UNLOCK(flags);
  809. mdelay(10);
  810. LOCK(flags);
  811. MACIO_OUT8(KL_GPIO_ETH_PHY_RESET, KEYLARGO_GPIO_OUTPUT_ENABLE
  812. | KEYLARGO_GPIO_OUTOUT_DATA);
  813. UNLOCK(flags);
  814. mdelay(10);
  815. return 0;
  816. }
  817. static int __pmac
  818. core99_sound_chip_enable(struct device_node* node, int param, int value)
  819. {
  820. struct macio_chip* macio;
  821. unsigned long flags;
  822. macio = macio_find(node, 0);
  823. if (!macio)
  824. return -ENODEV;
  825. /* Do a better probe code, screamer G4 desktops &
  826.  * iMacs can do that too, add a recalibrate  in
  827.  * the driver as well
  828.  */
  829. if (pmac_mb.model_id == PMAC_TYPE_PISMO ||
  830.     pmac_mb.model_id == PMAC_TYPE_TITANIUM) {
  831. LOCK(flags);
  832. if (value)
  833.      MACIO_OUT8(KL_GPIO_SOUND_POWER,
  834.      KEYLARGO_GPIO_OUTPUT_ENABLE |
  835.      KEYLARGO_GPIO_OUTOUT_DATA);
  836.      else
  837.      MACIO_OUT8(KL_GPIO_SOUND_POWER,
  838.      KEYLARGO_GPIO_OUTPUT_ENABLE);
  839.      (void)MACIO_IN8(KL_GPIO_SOUND_POWER);
  840.      UNLOCK(flags);
  841. }
  842. return 0;
  843. }
  844. static int __pmac
  845. core99_airport_enable(struct device_node* node, int param, int value)
  846. {
  847. struct macio_chip* macio;
  848. unsigned long flags;
  849. int state;
  850. macio = macio_find(node, 0);
  851. if (!macio)
  852. return -ENODEV;
  853. /* Hint: we allow passing of macio itself for the sake of the
  854.  * sleep code
  855.  */
  856. if (node != macio->of_node &&
  857.     (!node->parent || node->parent != macio->of_node))
  858. return -ENODEV;
  859. state = (macio->flags & MACIO_FLAG_AIRPORT_ON) != 0;
  860. if (value == state)
  861. return 0;
  862. if (value) {
  863. /* This code is a reproduction of OF enable-cardslot
  864.  * and init-wireless methods, slightly hacked until
  865.  * I got it working.
  866.  */
  867. LOCK(flags);
  868. MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 5);
  869. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
  870. UNLOCK(flags);
  871. mdelay(10);
  872. LOCK(flags);
  873. MACIO_OUT8(KEYLARGO_GPIO_0+0xf, 4);
  874. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xf);
  875. UNLOCK(flags);
  876. mdelay(10);
  877. LOCK(flags);
  878. MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
  879. (void)MACIO_IN32(KEYLARGO_FCR2);
  880. udelay(10);
  881. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xb, 0);
  882. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xb);
  883. udelay(10);
  884. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xa, 0x28);
  885. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xa);
  886. udelay(10);
  887. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+0xd, 0x28);
  888. (void)MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+0xd);
  889. udelay(10);
  890. MACIO_OUT8(KEYLARGO_GPIO_0+0xd, 0x28);
  891. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xd);
  892. udelay(10);
  893. MACIO_OUT8(KEYLARGO_GPIO_0+0xe, 0x28);
  894. (void)MACIO_IN8(KEYLARGO_GPIO_0+0xe);
  895. UNLOCK(flags);
  896. udelay(10);
  897. MACIO_OUT32(0x1c000, 0);
  898. mdelay(1);
  899. MACIO_OUT8(0x1a3e0, 0x41);
  900. (void)MACIO_IN8(0x1a3e0);
  901. udelay(10);
  902. LOCK(flags);
  903. MACIO_BIS(KEYLARGO_FCR2, KL2_CARDSEL_16);
  904. (void)MACIO_IN32(KEYLARGO_FCR2);
  905. UNLOCK(flags);
  906. mdelay(100);
  907. macio->flags |= MACIO_FLAG_AIRPORT_ON;
  908. } else {
  909. LOCK(flags);
  910. MACIO_BIC(KEYLARGO_FCR2, KL2_CARDSEL_16);
  911. (void)MACIO_IN32(KEYLARGO_FCR2);
  912. MACIO_OUT8(KL_GPIO_AIRPORT_0, 0);
  913. MACIO_OUT8(KL_GPIO_AIRPORT_1, 0);
  914. MACIO_OUT8(KL_GPIO_AIRPORT_2, 0);
  915. MACIO_OUT8(KL_GPIO_AIRPORT_3, 0);
  916. MACIO_OUT8(KL_GPIO_AIRPORT_4, 0);
  917. (void)MACIO_IN8(KL_GPIO_AIRPORT_4);
  918. UNLOCK(flags);
  919. macio->flags &= ~MACIO_FLAG_AIRPORT_ON;
  920. }
  921. return 0;
  922. }
  923. #ifdef CONFIG_SMP
  924. static int __pmac
  925. core99_reset_cpu(struct device_node* node, int param, int value)
  926. {
  927. const int reset_lines[] = { KL_GPIO_RESET_CPU0,
  928. KL_GPIO_RESET_CPU1,
  929. KL_GPIO_RESET_CPU2,
  930. KL_GPIO_RESET_CPU3 };
  931. int reset_io;
  932. unsigned long flags;
  933. struct macio_chip* macio;
  934. macio = &macio_chips[0];
  935. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  936. return -ENODEV;
  937. if (param > 3 || param < 0)
  938. return -ENODEV;
  939. reset_io = reset_lines[param];
  940. LOCK(flags);
  941. MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE);
  942. (void)MACIO_IN8(reset_io);
  943. udelay(1);
  944. MACIO_OUT8(reset_io, KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
  945. (void)MACIO_IN8(reset_io);
  946. UNLOCK(flags);
  947. return 0;
  948. }
  949. #endif /* CONFIG_SMP */
  950. static int __pmac
  951. core99_usb_enable(struct device_node* node, int param, int value)
  952. {
  953. struct macio_chip* macio;
  954. unsigned long flags;
  955. char* prop;
  956. int number;
  957. u32 reg;
  958. macio = &macio_chips[0];
  959. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  960. return -ENODEV;
  961. prop = (char *)get_property(node, "AAPL,clock-id", NULL);
  962. if (!prop)
  963. return -ENODEV;
  964. if (strncmp(prop, "usb0u048", strlen("usb0u048")) == 0)
  965. number = 0;
  966. else if (strncmp(prop, "usb1u148", strlen("usb1u148")) == 0)
  967. number = 2;
  968. else
  969. return -ENODEV;
  970. /* Sorry for the brute-force locking, but this is only used during
  971.  * sleep and the timing seem to be critical
  972.  */
  973. LOCK(flags);
  974. if (value) {
  975. /* Turn ON */
  976. if (number == 0) {
  977. MACIO_BIC(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
  978. (void)MACIO_IN32(KEYLARGO_FCR0);
  979. UNLOCK(flags);
  980. mdelay(1);
  981. LOCK(flags);
  982. MACIO_BIS(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
  983. } else {
  984. MACIO_BIC(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
  985. UNLOCK(flags);
  986. (void)MACIO_IN32(KEYLARGO_FCR0);
  987. mdelay(1);
  988. LOCK(flags);
  989. MACIO_BIS(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
  990. }
  991. reg = MACIO_IN32(KEYLARGO_FCR4);
  992. reg &= ~(KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
  993. KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number));
  994. reg &= ~(KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
  995. KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1));
  996. MACIO_OUT32(KEYLARGO_FCR4, reg);
  997. (void)MACIO_IN32(KEYLARGO_FCR4);
  998. udelay(10);
  999. } else {
  1000. /* Turn OFF */
  1001. reg = MACIO_IN32(KEYLARGO_FCR4);
  1002. reg |= KL4_PORT_WAKEUP_ENABLE(number) | KL4_PORT_RESUME_WAKE_EN(number) |
  1003. KL4_PORT_CONNECT_WAKE_EN(number) | KL4_PORT_DISCONNECT_WAKE_EN(number);
  1004. reg |= KL4_PORT_WAKEUP_ENABLE(number+1) | KL4_PORT_RESUME_WAKE_EN(number+1) |
  1005. KL4_PORT_CONNECT_WAKE_EN(number+1) | KL4_PORT_DISCONNECT_WAKE_EN(number+1);
  1006. MACIO_OUT32(KEYLARGO_FCR4, reg);
  1007. (void)MACIO_IN32(KEYLARGO_FCR4);
  1008. udelay(1);
  1009. if (number == 0) {
  1010. MACIO_BIC(KEYLARGO_FCR0, KL0_USB0_CELL_ENABLE);
  1011. (void)MACIO_IN32(KEYLARGO_FCR0);
  1012. udelay(1);
  1013. MACIO_BIS(KEYLARGO_FCR0, (KL0_USB0_PAD_SUSPEND0 | KL0_USB0_PAD_SUSPEND1));
  1014. (void)MACIO_IN32(KEYLARGO_FCR0);
  1015. } else {
  1016. MACIO_BIC(KEYLARGO_FCR0, KL0_USB1_CELL_ENABLE);
  1017. (void)MACIO_IN32(KEYLARGO_FCR0);
  1018. udelay(1);
  1019. MACIO_BIS(KEYLARGO_FCR0, (KL0_USB1_PAD_SUSPEND0 | KL0_USB1_PAD_SUSPEND1));
  1020. (void)MACIO_IN32(KEYLARGO_FCR0);
  1021. }
  1022. udelay(1);
  1023. }
  1024. UNLOCK(flags);
  1025. return 0;
  1026. }
  1027. static int __pmac
  1028. core99_firewire_enable(struct device_node* node, int param, int value)
  1029. {
  1030. unsigned long flags;
  1031. struct macio_chip* macio;
  1032. macio = &macio_chips[0];
  1033. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  1034. return -ENODEV;
  1035. if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
  1036. return -ENODEV;
  1037. LOCK(flags);
  1038. if (value) {
  1039. UN_BIS(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
  1040. (void)UN_IN(UNI_N_CLOCK_CNTL);
  1041. } else {
  1042. UN_BIC(UNI_N_CLOCK_CNTL, UNI_N_CLOCK_CNTL_FW);
  1043. (void)UN_IN(UNI_N_CLOCK_CNTL);
  1044. }
  1045. UNLOCK(flags);
  1046. mdelay(1);
  1047. return 0;
  1048. }
  1049. static int __pmac
  1050. core99_firewire_cable_power(struct device_node* node, int param, int value)
  1051. {
  1052. unsigned long flags;
  1053. struct macio_chip* macio;
  1054. /* Trick: we allow NULL node */
  1055. if ((pmac_mb.board_flags & PMAC_MB_HAS_FW_POWER) == 0)
  1056.      return -ENODEV;
  1057. macio = &macio_chips[0];
  1058. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  1059. return -ENODEV;
  1060. if (!(macio->flags & MACIO_FLAG_FW_SUPPORTED))
  1061. return -ENODEV;
  1062. LOCK(flags);
  1063. if (value) {
  1064. MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 0);
  1065. MACIO_IN8(KL_GPIO_FW_CABLE_POWER);
  1066. udelay(10);
  1067. } else {
  1068. MACIO_OUT8(KL_GPIO_FW_CABLE_POWER , 4);
  1069. MACIO_IN8(KL_GPIO_FW_CABLE_POWER); udelay(10);
  1070. }
  1071. UNLOCK(flags);
  1072. mdelay(1);
  1073. return 0;
  1074. }
  1075. static int __pmac
  1076. core99_read_gpio(struct device_node* node, int param, int value)
  1077. {
  1078. struct macio_chip* macio = &macio_chips[0];
  1079. return MACIO_IN8(param);
  1080. }
  1081. static int __pmac
  1082. core99_write_gpio(struct device_node* node, int param, int value)
  1083. {
  1084. struct macio_chip* macio = &macio_chips[0];
  1085. MACIO_OUT8(param, (u8)(value & 0xff));
  1086. return 0;
  1087. }
  1088. static void __pmac
  1089. keylargo_shutdown(struct macio_chip* macio, int restart)
  1090. {
  1091. u32 temp;
  1092. mdelay(1);
  1093. MACIO_BIS(KEYLARGO_FCR0, KL0_USB_REF_SUSPEND);
  1094. (void)MACIO_IN32(KEYLARGO_FCR0);
  1095. mdelay(100);
  1096. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1097. KL0_SCC_CELL_ENABLE |
  1098.        KL0_IRDA_ENABLE | KL0_IRDA_CLK32_ENABLE |
  1099.        KL0_IRDA_CLK19_ENABLE);
  1100. (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
  1101. MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);
  1102. (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
  1103. MACIO_BIC(KEYLARGO_FCR1,
  1104. KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
  1105. KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
  1106. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1107. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1108. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1109. KL1_EIDE0_ENABLE | KL1_EIDE0_RESET_N |
  1110. KL1_EIDE1_ENABLE | KL1_EIDE1_RESET_N |
  1111. KL1_UIDE_ENABLE);
  1112. (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
  1113. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  1114.   udelay(10);
  1115.   MACIO_BIC(KEYLARGO_FCR2, KL2_IOBUS_ENABLE);
  1116.   udelay(10);
  1117. temp = MACIO_IN32(KEYLARGO_FCR3);
  1118. if (macio->rev >= 2)
  1119. temp |= (KL3_SHUTDOWN_PLL2X | KL3_SHUTDOWN_PLL_TOTAL);
  1120. temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
  1121. KL3_SHUTDOWN_PLLKW35 | KL3_SHUTDOWN_PLLKW12;
  1122. temp &= ~(KL3_CLK66_ENABLE | KL3_CLK49_ENABLE | KL3_CLK45_ENABLE
  1123. | KL3_CLK31_ENABLE | KL3_TIMER_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE
  1124. | KL3_I2S0_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);
  1125. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1126. (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
  1127. }
  1128. static void __pmac
  1129. pangea_shutdown(struct macio_chip* macio, int restart)
  1130. {
  1131. u32 temp;
  1132. MACIO_BIC(KEYLARGO_FCR0,KL0_SCCA_ENABLE | KL0_SCCB_ENABLE |
  1133. KL0_SCC_CELL_ENABLE |
  1134. KL0_USB0_CELL_ENABLE | KL0_USB1_CELL_ENABLE);
  1135. (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
  1136. MACIO_BIC(KEYLARGO_MBCR, KL_MBCR_MB0_DEV_MASK);
  1137. (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
  1138. MACIO_BIC(KEYLARGO_FCR1,
  1139. KL1_AUDIO_SEL_22MCLK | KL1_AUDIO_CLK_ENABLE_BIT |
  1140. KL1_AUDIO_CLK_OUT_ENABLE | KL1_AUDIO_CELL_ENABLE |
  1141. KL1_I2S0_CELL_ENABLE | KL1_I2S0_CLK_ENABLE_BIT |
  1142. KL1_I2S0_ENABLE | KL1_I2S1_CELL_ENABLE |
  1143. KL1_I2S1_CLK_ENABLE_BIT | KL1_I2S1_ENABLE |
  1144. KL1_UIDE_ENABLE);
  1145. (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
  1146. MACIO_BIS(KEYLARGO_FCR2, KL2_ALT_DATA_OUT);
  1147.   udelay(10);
  1148. temp = MACIO_IN32(KEYLARGO_FCR3);
  1149. temp |= KL3_SHUTDOWN_PLLKW6 | KL3_SHUTDOWN_PLLKW4 |
  1150. KL3_SHUTDOWN_PLLKW35;
  1151. temp &= ~(KL3_CLK49_ENABLE | KL3_CLK45_ENABLE
  1152. | KL3_CLK31_ENABLE | KL3_TIMER_CLK18_ENABLE | KL3_I2S1_CLK18_ENABLE
  1153. | KL3_I2S0_CLK18_ENABLE | KL3_VIA_CLK16_ENABLE);
  1154. MACIO_OUT32(KEYLARGO_FCR3, temp);
  1155. (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
  1156. }
  1157. static int __pmac
  1158. core99_sleep(void)
  1159. {
  1160. struct macio_chip* macio;
  1161. int i;
  1162. macio = &macio_chips[0];
  1163. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  1164. return -ENODEV;
  1165. /* We power off the wireless slot in case it was not done
  1166.  * by the driver. We don't power it on automatically however
  1167.  */
  1168. if (macio->flags & MACIO_FLAG_AIRPORT_ON)
  1169. core99_airport_enable(macio->of_node, 0, 0);
  1170. /* We power off the FW cable. Should be done by the driver... */
  1171. if (macio->flags & MACIO_FLAG_FW_SUPPORTED) {
  1172. core99_firewire_enable(NULL, 0, 0);
  1173. core99_firewire_cable_power(NULL, 0, 0);
  1174. }
  1175. /* We make sure int. modem is off (in case driver lost it) */
  1176. core99_modem_enable(macio->of_node, 0, 0);
  1177. /* We make sure the sound is off as well */
  1178. core99_sound_chip_enable(macio->of_node, 0, 0);
  1179.  
  1180. /*
  1181.  * Save various bits of KeyLargo
  1182.  */
  1183. /* Save the state of the various GPIOs */
  1184. save_gpio_levels[0] = MACIO_IN32(KEYLARGO_GPIO_LEVELS0);
  1185. save_gpio_levels[1] = MACIO_IN32(KEYLARGO_GPIO_LEVELS1);
  1186. for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
  1187. save_gpio_extint[i] = MACIO_IN8(KEYLARGO_GPIO_EXTINT_0+i);
  1188. for (i=0; i<KEYLARGO_GPIO_CNT; i++)
  1189. save_gpio_normal[i] = MACIO_IN8(KEYLARGO_GPIO_0+i);
  1190. /* Save the FCRs */
  1191. save_mbcr = MACIO_IN32(KEYLARGO_MBCR);
  1192. save_fcr[0] = MACIO_IN32(KEYLARGO_FCR0);
  1193. save_fcr[1] = MACIO_IN32(KEYLARGO_FCR1);
  1194. save_fcr[2] = MACIO_IN32(KEYLARGO_FCR2);
  1195. save_fcr[3] = MACIO_IN32(KEYLARGO_FCR3);
  1196. save_fcr[4] = MACIO_IN32(KEYLARGO_FCR4);
  1197. /* Save state & config of DBDMA channels */
  1198. dbdma_save(macio, save_dbdma);
  1199. /*
  1200.  * Turn off as much as we can
  1201.  */
  1202. if (macio->type == macio_pangea)
  1203. pangea_shutdown(macio, 0);
  1204. else if (macio->type == macio_keylargo)
  1205. keylargo_shutdown(macio, 0);
  1206. /* 
  1207.  * Put the host bridge to sleep
  1208.  */
  1209. save_unin_clock_ctl = UN_IN(UNI_N_CLOCK_CNTL);
  1210. UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl &
  1211. ~(UNI_N_CLOCK_CNTL_GMAC|UNI_N_CLOCK_CNTL_FW/*|UNI_N_CLOCK_CNTL_PCI*/));
  1212. udelay(100);
  1213. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_SLEEPING);
  1214. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_SLEEP);
  1215. /*
  1216.  * FIXME: A bit of black magic with OpenPIC (don't ask me why)
  1217.  */
  1218. if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
  1219. MACIO_BIS(0x506e0, 0x00400000);
  1220. MACIO_BIS(0x506e0, 0x80000000);
  1221. }
  1222. return 0;
  1223. }
  1224. static int __pmac
  1225. core99_wake_up(void)
  1226. {
  1227. struct macio_chip* macio;
  1228. int i;
  1229. macio = &macio_chips[0];
  1230. if (macio->type != macio_keylargo && macio->type != macio_pangea)
  1231. return -ENODEV;
  1232. /*
  1233.  * Wakeup the host bridge
  1234.  */
  1235. UN_OUT(UNI_N_POWER_MGT, UNI_N_POWER_MGT_NORMAL);
  1236. udelay(10);
  1237. UN_OUT(UNI_N_HWINIT_STATE, UNI_N_HWINIT_STATE_RUNNING);
  1238. udelay(10);
  1239. /*
  1240.  * Restore KeyLargo
  1241.  */
  1242.  
  1243. MACIO_OUT32(KEYLARGO_MBCR, save_mbcr);
  1244. (void)MACIO_IN32(KEYLARGO_MBCR); udelay(10);
  1245. MACIO_OUT32(KEYLARGO_FCR0, save_fcr[0]);
  1246. (void)MACIO_IN32(KEYLARGO_FCR0); udelay(10);
  1247. MACIO_OUT32(KEYLARGO_FCR1, save_fcr[1]);
  1248. (void)MACIO_IN32(KEYLARGO_FCR1); udelay(10);
  1249. MACIO_OUT32(KEYLARGO_FCR2, save_fcr[2]);
  1250. (void)MACIO_IN32(KEYLARGO_FCR2); udelay(10);
  1251. MACIO_OUT32(KEYLARGO_FCR3, save_fcr[3]);
  1252. (void)MACIO_IN32(KEYLARGO_FCR3); udelay(10);
  1253. MACIO_OUT32(KEYLARGO_FCR4, save_fcr[4]);
  1254. (void)MACIO_IN32(KEYLARGO_FCR4); udelay(10);
  1255. dbdma_restore(macio, save_dbdma);
  1256. MACIO_OUT32(KEYLARGO_GPIO_LEVELS0, save_gpio_levels[0]);
  1257. MACIO_OUT32(KEYLARGO_GPIO_LEVELS1, save_gpio_levels[1]);
  1258. for (i=0; i<KEYLARGO_GPIO_EXTINT_CNT; i++)
  1259. MACIO_OUT8(KEYLARGO_GPIO_EXTINT_0+i, save_gpio_extint[i]);
  1260. for (i=0; i<KEYLARGO_GPIO_CNT; i++)
  1261. MACIO_OUT8(KEYLARGO_GPIO_0+i, save_gpio_normal[i]);
  1262. /* FIXME more black magic with OpenPIC ... */
  1263. if (pmac_mb.model_id == PMAC_TYPE_SAWTOOTH) {
  1264. MACIO_BIC(0x506e0, 0x00400000);
  1265. MACIO_BIC(0x506e0, 0x80000000);
  1266. }
  1267. UN_OUT(UNI_N_CLOCK_CNTL, save_unin_clock_ctl);
  1268. udelay(100);
  1269. return 0;
  1270. }
  1271. static int __pmac
  1272. core99_sleep_state(struct device_node* node, int param, int value)
  1273. {
  1274. if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
  1275. return -EPERM;
  1276. if (value == 1)
  1277. return core99_sleep();
  1278. else if (value == 0)
  1279. return core99_wake_up();
  1280. return 0;
  1281. }
  1282. static int __pmac
  1283. pangea_modem_enable(struct device_node* node, int param, int value)
  1284. {
  1285. struct macio_chip* macio;
  1286. u8 gpio;
  1287. unsigned long flags;
  1288. macio = macio_find(node, 0);
  1289. if (!macio)
  1290. return -ENODEV;
  1291. gpio = MACIO_IN8(KL_GPIO_MODEM_RESET);
  1292. gpio |= KEYLARGO_GPIO_OUTPUT_ENABLE;
  1293. gpio &= ~KEYLARGO_GPIO_OUTOUT_DATA;
  1294. if (!value) {
  1295. LOCK(flags);
  1296. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
  1297. UNLOCK(flags);
  1298. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  1299. mdelay(250);
  1300. }
  1301.      LOCK(flags);
  1302. if (value) {
  1303. MACIO_OUT8(KL_GPIO_MODEM_POWER,
  1304. KEYLARGO_GPIO_OUTPUT_ENABLE);
  1305.      UNLOCK(flags);
  1306.      (void)MACIO_IN32(KEYLARGO_FCR2);
  1307. mdelay(250);
  1308. } else {
  1309. MACIO_OUT8(KL_GPIO_MODEM_POWER,
  1310. KEYLARGO_GPIO_OUTPUT_ENABLE | KEYLARGO_GPIO_OUTOUT_DATA);
  1311.      UNLOCK(flags);
  1312. }
  1313. if (value) {
  1314. LOCK(flags);
  1315. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
  1316. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  1317.      UNLOCK(flags); mdelay(250); LOCK(flags);
  1318. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio);
  1319. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  1320.      UNLOCK(flags); mdelay(250); LOCK(flags);
  1321. MACIO_OUT8(KL_GPIO_MODEM_RESET, gpio | KEYLARGO_GPIO_OUTOUT_DATA);
  1322. (void)MACIO_IN8(KL_GPIO_MODEM_RESET);
  1323.      UNLOCK(flags); mdelay(250); LOCK(flags);
  1324. }
  1325. return 0;
  1326. }
  1327. static int __pmac
  1328. generic_get_mb_info(struct device_node* node, int param, int value)
  1329. {
  1330. switch(param) {
  1331. case PMAC_MB_INFO_MODEL:
  1332. return pmac_mb.model_id;
  1333. case PMAC_MB_INFO_FLAGS:
  1334. return pmac_mb.board_flags;
  1335. case PMAC_MB_INFO_NAME:
  1336. /* hack hack hack... but should work */
  1337. return (int)pmac_mb.model_name;
  1338. }
  1339. return 0;
  1340. }
  1341. /* 
  1342.  * Table definitions
  1343.  */
  1344.  
  1345. /* Used on any machine
  1346.  */
  1347. static struct feature_table_entry any_features[]  __pmacdata = {
  1348. { PMAC_FTR_GET_MB_INFO, generic_get_mb_info },
  1349. { 0, NULL }
  1350. };
  1351. /* OHare based motherboards. Currently, we only use these on the
  1352.  * 2400,3400 and 3500 series powerbooks. Some older desktops seem
  1353.  * to have issues with turning on/off those asic cells
  1354.  */
  1355. static struct feature_table_entry ohare_features[]  __pmacdata = {
  1356. { PMAC_FTR_SCC_ENABLE, ohare_scc_enable },
  1357. { PMAC_FTR_SWIM3_ENABLE, ohare_floppy_enable },
  1358. { PMAC_FTR_MESH_ENABLE, ohare_mesh_enable },
  1359. { PMAC_FTR_IDE_ENABLE, ohare_ide_enable},
  1360. { PMAC_FTR_IDE_RESET, ohare_ide_reset},
  1361. { PMAC_FTR_SLEEP_STATE, ohare_sleep_state },
  1362. { 0, NULL }
  1363. };
  1364. /* Heathrow desktop machines (Beige G3).
  1365.  * Separated as some features couldn't be properly tested
  1366.  * and the serial port control bits appear to confuse it.
  1367.  */
  1368. static struct feature_table_entry heathrow_desktop_features[]  __pmacdata = {
  1369. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1370. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1371. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1372. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1373. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1374. { 0, NULL }
  1375. };
  1376. /* Heathrow based laptop, that is the Wallstreet and mainstreet
  1377.  * powerbooks.
  1378.  */
  1379. static struct feature_table_entry heathrow_laptop_features[]  __pmacdata = {
  1380. { PMAC_FTR_SCC_ENABLE, heathrow_scc_enable },
  1381. { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
  1382. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1383. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1384. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1385. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1386. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1387. { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
  1388. { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
  1389. { 0, NULL }
  1390. };
  1391. /* Paddington based machines
  1392.  * The lombard (101) powerbook, first iMac models, B&W G3 and Yikes G4.
  1393.  */
  1394. static struct feature_table_entry paddington_features[]  __pmacdata = {
  1395. { PMAC_FTR_SCC_ENABLE, heathrow_scc_enable },
  1396. { PMAC_FTR_MODEM_ENABLE, heathrow_modem_enable },
  1397. { PMAC_FTR_SWIM3_ENABLE, heathrow_floppy_enable },
  1398. { PMAC_FTR_MESH_ENABLE, heathrow_mesh_enable },
  1399. { PMAC_FTR_IDE_ENABLE, heathrow_ide_enable },
  1400. { PMAC_FTR_IDE_RESET, heathrow_ide_reset },
  1401. { PMAC_FTR_BMAC_ENABLE, heathrow_bmac_enable },
  1402. { PMAC_FTR_SOUND_CHIP_ENABLE, heathrow_sound_enable },
  1403. { PMAC_FTR_SLEEP_STATE, heathrow_sleep_state },
  1404. { 0, NULL }
  1405. };
  1406. /* Core99 & MacRISC 2 machines (all machines released since the
  1407.  * iBook (included), that is all AGP machines, except pangea
  1408.  * chipset. The pangea chipset is the "combo" UniNorth/KeyLargo
  1409.  * used on iBook2 & iMac "flow power".
  1410.  */
  1411. static struct feature_table_entry core99_features[]  __pmacdata = {
  1412. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1413. { PMAC_FTR_MODEM_ENABLE, core99_modem_enable },
  1414. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1415. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1416. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1417. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1418. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1419. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1420. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1421. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1422. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1423. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1424. #ifdef CONFIG_SMP
  1425. { PMAC_FTR_RESET_CPU, core99_reset_cpu },
  1426. #endif /* CONFIG_SMP */
  1427. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1428. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1429. { 0, NULL }
  1430. };
  1431. /* Pangea features
  1432.  */
  1433. static struct feature_table_entry pangea_features[]  __pmacdata = {
  1434. { PMAC_FTR_SCC_ENABLE, core99_scc_enable },
  1435. { PMAC_FTR_MODEM_ENABLE, pangea_modem_enable },
  1436. { PMAC_FTR_IDE_ENABLE, core99_ide_enable },
  1437. { PMAC_FTR_IDE_RESET, core99_ide_reset },
  1438. { PMAC_FTR_GMAC_ENABLE, core99_gmac_enable },
  1439. { PMAC_FTR_GMAC_PHY_RESET, core99_gmac_phy_reset },
  1440. { PMAC_FTR_SOUND_CHIP_ENABLE, core99_sound_chip_enable },
  1441. { PMAC_FTR_AIRPORT_ENABLE, core99_airport_enable },
  1442. { PMAC_FTR_USB_ENABLE, core99_usb_enable },
  1443. { PMAC_FTR_1394_ENABLE, core99_firewire_enable },
  1444. { PMAC_FTR_1394_CABLE_POWER, core99_firewire_cable_power },
  1445. { PMAC_FTR_SLEEP_STATE, core99_sleep_state },
  1446. { PMAC_FTR_READ_GPIO, core99_read_gpio },
  1447. { PMAC_FTR_WRITE_GPIO, core99_write_gpio },
  1448. { 0, NULL }
  1449. };
  1450. static struct pmac_mb_def pmac_mb_defs[] __pmacdata = {
  1451. /* Warning: ordering is important as some models may claim
  1452.  * beeing compatible with several types
  1453.  */
  1454. { "AAPL,8500", "PowerMac 8500/8600",
  1455. PMAC_TYPE_PSURGE, NULL,
  1456. 0
  1457. },
  1458. { "AAPL,9500", "PowerMac 9500/9600",
  1459. PMAC_TYPE_PSURGE, NULL,
  1460. 0
  1461. },
  1462. { "AAPL,7500", "PowerMac 7500",
  1463. PMAC_TYPE_PSURGE, NULL,
  1464. 0
  1465. },
  1466. { "AAPL,e407", "Alchemy",
  1467. PMAC_TYPE_ALCHEMY, NULL,
  1468. 0
  1469. },
  1470. { "AAPL,e411", "Gazelle",
  1471. PMAC_TYPE_GAZELLE, NULL,
  1472. 0
  1473. },
  1474. { "AAPL,3400/2400", "PowerBook 3400",
  1475. PMAC_TYPE_HOOPER, ohare_features,
  1476. PMAC_MB_CAN_SLEEP
  1477. },
  1478. { "AAPL,3500", "PowerBook 3500",
  1479. PMAC_TYPE_KANGA, ohare_features,
  1480. PMAC_MB_CAN_SLEEP
  1481. },
  1482. { "AAPL,Gossamer", "PowerMac G3 (Gossamer)",
  1483. PMAC_TYPE_GOSSAMER, heathrow_desktop_features,
  1484. 0
  1485. },
  1486. { "AAPL,PowerMac G3", "PowerMac G3 (Silk)",
  1487. PMAC_TYPE_SILK, heathrow_desktop_features,
  1488. 0
  1489. },
  1490. { "AAPL,PowerBook1998", "PowerBook Wallstreet",
  1491. PMAC_TYPE_WALLSTREET, heathrow_laptop_features,
  1492. PMAC_MB_CAN_SLEEP
  1493. },
  1494. { "AAPL,PowerBook1,1", "PowerBook 101 (Lombard)",
  1495. PMAC_TYPE_101_PBOOK, paddington_features,
  1496. PMAC_MB_CAN_SLEEP
  1497. },
  1498. { "iMac,1", "iMac (first generation)",
  1499. PMAC_TYPE_ORIG_IMAC, paddington_features,
  1500. 0
  1501. },
  1502. { "PowerMac4,1", "iMac "Flower Power"",
  1503. PMAC_TYPE_PANGEA_IMAC, pangea_features,
  1504. PMAC_MB_CAN_SLEEP
  1505. },
  1506. { "PowerBook4,1", "iBook 2",
  1507. PMAC_TYPE_IBOOK2, pangea_features,
  1508. PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
  1509. },
  1510. { "PowerMac1,1", "Blue&White G3",
  1511. PMAC_TYPE_YOSEMITE, paddington_features,
  1512. 0
  1513. },
  1514. { "PowerMac1,2", "PowerMac G4 PCI Graphics",
  1515. PMAC_TYPE_YIKES, paddington_features,
  1516. 0
  1517. },
  1518. { "PowerBook2,1", "iBook (first generation)",
  1519. PMAC_TYPE_ORIG_IBOOK, core99_features,
  1520. PMAC_MB_CAN_SLEEP
  1521. },
  1522. { "PowerMac3,1", "PowerMac G4 AGP Graphics",
  1523. PMAC_TYPE_SAWTOOTH, core99_features,
  1524. 0
  1525. },
  1526. { "PowerMac3,2", "PowerMac G4 AGP Graphics",
  1527. PMAC_TYPE_SAWTOOTH, core99_features,
  1528. 0
  1529. },
  1530. { "PowerMac3,3", "PowerMac G4 AGP Graphics",
  1531. PMAC_TYPE_SAWTOOTH, core99_features,
  1532. 0
  1533. },
  1534. { "PowerMac2,1", "iMac FireWire",
  1535. PMAC_TYPE_FW_IMAC, core99_features,
  1536. PMAC_MB_CAN_SLEEP
  1537. },
  1538. { "PowerMac2,2", "iMac FireWire",
  1539. PMAC_TYPE_FW_IMAC, core99_features,
  1540. PMAC_MB_CAN_SLEEP
  1541. },
  1542. { "PowerBook2,2", "iBook FireWire",
  1543. PMAC_TYPE_FW_IBOOK, core99_features,
  1544. PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
  1545. },
  1546. { "PowerMac5,1", "PowerMac G4 Cube",
  1547. PMAC_TYPE_CUBE, core99_features,
  1548. },
  1549. { "PowerMac3,4", "PowerMac G4 Silver",
  1550. PMAC_TYPE_QUICKSILVER, core99_features,
  1551. 0
  1552. },
  1553. { "PowerMac3,5", "PowerMac G4 Silver",
  1554. PMAC_TYPE_QUICKSILVER, core99_features,
  1555. 0
  1556. },
  1557. { "PowerBook3,1", "PowerBook Pismo",
  1558. PMAC_TYPE_PISMO, core99_features,
  1559. PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
  1560. },
  1561. { "PowerBook3,2", "PowerBook Titanium",
  1562. PMAC_TYPE_TITANIUM, core99_features,
  1563. PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
  1564. },
  1565. { "PowerBook3,3", "PowerBook Titanium II",
  1566. PMAC_TYPE_TITANIUM2, core99_features,
  1567. PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
  1568. },
  1569. };
  1570. /*
  1571.  * The toplevel feature_call callback
  1572.  */
  1573. int __pmac
  1574. pmac_do_feature_call(unsigned int selector, ...)
  1575. {
  1576. struct device_node* node;
  1577. int param, value, i;
  1578. feature_call func = NULL;
  1579. va_list args;
  1580. if (!pmac_mb.features)
  1581. return -ENODEV;
  1582. for (i=0; pmac_mb.features[i].function; i++)
  1583. if (pmac_mb.features[i].selector == selector) {
  1584. func = pmac_mb.features[i].function;
  1585. break;
  1586. }
  1587. if (!func)
  1588. for (i=0; any_features[i].function; i++)
  1589. if (any_features[i].selector == selector) {
  1590. func = any_features[i].function;
  1591. break;
  1592. }
  1593. if (!func)
  1594. return -ENODEV;
  1595. va_start(args, selector);
  1596. node = (struct device_node*)va_arg(args, void*);
  1597. param = va_arg(args, int);
  1598. value = va_arg(args, int);
  1599. va_end(args);
  1600. return func(node, param, value);
  1601. }
  1602. static int __init
  1603. probe_motherboard(void)
  1604. {
  1605. int i;
  1606. struct macio_chip* macio = &macio_chips[0];
  1607. /* Lookup known motherboard type in device-tree */
  1608. for(i=0; i<(sizeof(pmac_mb_defs)/sizeof(struct pmac_mb_def)); i++) {
  1609.     if (machine_is_compatible(pmac_mb_defs[i].model_string)) {
  1610. pmac_mb = pmac_mb_defs[i];
  1611. goto found;
  1612.     }
  1613. }
  1614. /* Fallback to selection depending on mac-io chip type */
  1615. switch(macio->type) {
  1616.     case macio_grand_central:
  1617. pmac_mb.model_id = PMAC_TYPE_PSURGE;
  1618. pmac_mb.model_name = "Unknown PowerSurge";
  1619. break;
  1620.     case macio_ohare:
  1621. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_OHARE;
  1622. pmac_mb.model_name = "Unknown OHare-based";
  1623.      break;
  1624.     case macio_heathrow:
  1625. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_HEATHROW;
  1626. pmac_mb.model_name = "Unknown Heathrow-based";
  1627. pmac_mb.features = heathrow_desktop_features;
  1628. break;
  1629.     case macio_paddington:
  1630. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PADDINGTON;
  1631. pmac_mb.model_name = "Unknown Paddington-based";
  1632.      pmac_mb.features = paddington_features;
  1633. break;
  1634.     case macio_keylargo:
  1635. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_CORE99;
  1636. pmac_mb.model_name = "Unknown Keylargo-based";
  1637.      pmac_mb.features = core99_features;
  1638. break;
  1639.     case macio_pangea:
  1640. pmac_mb.model_id = PMAC_TYPE_UNKNOWN_PANGEA;
  1641. pmac_mb.model_name = "Unknown Pangea-based";
  1642.      pmac_mb.features = pangea_features;
  1643. break;
  1644.     default:
  1645.      return -ENODEV;
  1646. }
  1647. found:
  1648. /* Fixup Hooper vs. Comet */
  1649. if (pmac_mb.model_id == PMAC_TYPE_HOOPER) {
  1650. u32* mach_id_ptr = (u32*)ioremap(0xf3000034, 4);
  1651. if (!mach_id_ptr)
  1652. return -ENODEV;
  1653. /* Here, I used to disable the media-bay on comet. It
  1654.  * appears this is wrong, the floppy connector is actually
  1655.  * a kind of media-bay and works with the current driver.
  1656.  */
  1657. if ((*mach_id_ptr) & 0x20000000UL)
  1658. pmac_mb.model_id = PMAC_TYPE_COMET;
  1659. iounmap(mach_id_ptr);
  1660. }
  1661. /* Set default value of powersave_nap on machines that support it.
  1662.  * It appears that uninorth rev 3 has a problem with it, we don't
  1663.  * enable it on those. In theory, the flush-on-lock property is
  1664.  * supposed to be set when not supported, but I'm not very confident
  1665.  * that all Apple OF revs did it properly, I do it the paranoid way.
  1666.  */
  1667. while (uninorth_base && uninorth_rev > 3) {
  1668. struct device_node* np = find_path_device("/cpus");
  1669. u32 pvr = mfspr(PVR);
  1670. if (!np || !np->child) {
  1671. printk(KERN_WARNING "Can't find CPU(s) in device tree !n");
  1672. break;
  1673. }
  1674. np = np->child;
  1675. /* Nap mode not supported on SMP */
  1676. if (np->sibling)
  1677. break;
  1678. /* Nap mode not supported if flush-on-lock property is present */
  1679. if (get_property(np, "flush-on-lock", NULL))
  1680. break;
  1681. /* Some 7450 may have problem with NAP mode too ... */
  1682. if (((pvr >> 16) == 0x8000) && ((pvr & 0xffff) < 0x0201))
  1683. break;
  1684. powersave_nap = 1;
  1685. printk(KERN_INFO "Processor NAP mode on idle enabled.n");
  1686. break;
  1687. }
  1688. printk(KERN_INFO "PowerMac motherboard: %sn", pmac_mb.model_name);
  1689. return 0;
  1690. }
  1691. /* Initialize the Core99 UniNorth host bridge and memory controller
  1692.  */
  1693. static void __init
  1694. probe_uninorth(void)
  1695. {
  1696. unsigned long actrl;
  1697. /* Locate core99 Uni-N */
  1698. uninorth_node = find_devices("uni-n");
  1699. if (uninorth_node && uninorth_node->n_addrs > 0) {
  1700. uninorth_base = ioremap(uninorth_node->addrs[0].address, 0x1000);
  1701. uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
  1702. } else
  1703. uninorth_node = NULL;
  1704. if (!uninorth_node)
  1705. return;
  1706. printk(KERN_INFO "Found Uninorth memory controller & host bridge, revision: %dn",
  1707. uninorth_rev);
  1708. /* Set the arbitrer QAck delay according to what Apple does
  1709.  */
  1710. if (uninorth_rev < 0x10) {
  1711. actrl = UN_IN(UNI_N_ARB_CTRL) & ~UNI_N_ARB_CTRL_QACK_DELAY_MASK;
  1712. actrl |= ((uninorth_rev < 3) ? UNI_N_ARB_CTRL_QACK_DELAY105 :
  1713. UNI_N_ARB_CTRL_QACK_DELAY) << UNI_N_ARB_CTRL_QACK_DELAY_SHIFT;
  1714. UN_OUT(UNI_N_ARB_CTRL, actrl);
  1715. }
  1716. }
  1717. static void __init
  1718. probe_one_macio(const char* name, const char* compat, int type)
  1719. {
  1720. struct device_node* node;
  1721. int i;
  1722. volatile u32* base;
  1723. u32* revp;
  1724. node = find_devices(name);
  1725. if (!node || !node->n_addrs)
  1726. return;
  1727. if (compat)
  1728. do {
  1729. if (device_is_compatible(node, compat))
  1730. break;
  1731. node = node->next;
  1732. } while (node);
  1733. if (!node)
  1734. return;
  1735. for(i=0; i<MAX_MACIO_CHIPS; i++) {
  1736. if (!macio_chips[i].of_node)
  1737. break;
  1738. if (macio_chips[i].of_node == node)
  1739. return;
  1740. }
  1741. if (i >= MAX_MACIO_CHIPS) {
  1742. printk(KERN_ERR "pmac_feature: Please increase MAX_MACIO_CHIPS !n");
  1743. printk(KERN_ERR "pmac_feature: %s skippedn", node->full_name);
  1744. return;
  1745. }
  1746. base = (volatile u32*)ioremap(node->addrs[0].address, node->addrs[0].size);
  1747. if (!base) {
  1748. printk(KERN_ERR "pmac_feature: Can't map mac-io chip !n");
  1749. return;
  1750. }
  1751. if (type == macio_keylargo) {
  1752. u32* did = (u32 *)get_property(node, "device-id", NULL);
  1753. if (*did == 0x00000025)
  1754. type = macio_pangea;
  1755. }
  1756. macio_chips[i].of_node = node;
  1757. macio_chips[i].type = type;
  1758. macio_chips[i].base = base;
  1759. macio_chips[i].flags = MACIO_FLAG_SCCB_ON | MACIO_FLAG_SCCB_ON;
  1760. revp = (u32 *)get_property(node, "revision-id", NULL);
  1761. if (revp)
  1762. macio_chips[i].rev = *revp;
  1763. printk(KERN_INFO "Found a %s mac-io controller, rev: %d, mapped at 0x%pn",
  1764. macio_names[type], macio_chips[i].rev, macio_chips[i].base);
  1765. }
  1766. static int __init
  1767. probe_macios(void)
  1768. {
  1769. /* Warning, ordering is important */
  1770. probe_one_macio("gc", NULL, macio_grand_central);
  1771. probe_one_macio("ohare", NULL, macio_ohare);
  1772. probe_one_macio("pci106b,7", NULL, macio_ohareII);
  1773. probe_one_macio("mac-io", "keylargo", macio_keylargo);
  1774. probe_one_macio("mac-io", "paddington", macio_paddington);
  1775. probe_one_macio("mac-io", "gatwick", macio_gatwick);
  1776. probe_one_macio("mac-io", "heathrow", macio_heathrow);
  1777. /* Make sure the "main" macio chip appear first */
  1778. if (macio_chips[0].type == macio_gatwick
  1779.     && macio_chips[1].type == macio_heathrow) {
  1780. struct macio_chip temp = macio_chips[0];
  1781. macio_chips[0] = macio_chips[1];
  1782. macio_chips[1] = temp;
  1783. }
  1784. if (macio_chips[0].type == macio_ohareII
  1785.     && macio_chips[1].type == macio_ohare) {
  1786. struct macio_chip temp = macio_chips[0];
  1787. macio_chips[0] = macio_chips[1];
  1788. macio_chips[1] = temp;
  1789. }
  1790. return (macio_chips[0].of_node == NULL) ? -ENODEV : 0;
  1791. }
  1792. static void __init
  1793. initial_serial_shutdown(struct device_node* np)
  1794. {
  1795. int len;
  1796. struct slot_names_prop {
  1797. int count;
  1798. char name[1];
  1799. } *slots;
  1800. char *conn;
  1801. int port_type = PMAC_SCC_ASYNC;
  1802. int modem = 0;
  1803. slots = (struct slot_names_prop *)get_property(np, "slot-names", &len);
  1804. conn = get_property(np, "AAPL,connector", &len);
  1805. if (conn && (strcmp(conn, "infrared") == 0))
  1806. port_type = PMAC_SCC_IRDA;
  1807. else if (device_is_compatible(np, "cobalt"))
  1808. modem = 1;
  1809. else if (slots && slots->count > 0) {
  1810. if (strcmp(slots->name, "IrDA") == 0)
  1811. port_type = PMAC_SCC_IRDA;
  1812. else if (strcmp(slots->name, "Modem") == 0)
  1813. modem = 1;
  1814. }
  1815. if (modem)
  1816. pmac_call_feature(PMAC_FTR_MODEM_ENABLE, np, 0, 0);
  1817. pmac_call_feature(PMAC_FTR_SCC_ENABLE, np, port_type, 0);
  1818. }
  1819. static void __init
  1820. set_initial_features(void)
  1821. {
  1822. struct device_node* np;
  1823. /* That hack appears to be necessary for some StarMax motherboards
  1824.  * but I'm not too sure it was audited for side-effects on other
  1825.  * ohare based machines...
  1826.  * Since I still have difficulties figuring the right way to
  1827.  * differenciate them all and since that hack was there for a long
  1828.  * time, I'll keep it around
  1829.  */
  1830. if (macio_chips[0].type == macio_ohare && !find_devices("via-pmu")) {
  1831. struct macio_chip* macio = &macio_chips[0];
  1832. MACIO_OUT32(OHARE_FCR, STARMAX_FEATURES);
  1833. } else if (macio_chips[0].type == macio_ohare) {
  1834. struct macio_chip* macio = &macio_chips[0];
  1835. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  1836. } else if (macio_chips[1].type == macio_ohare) {
  1837. struct macio_chip* macio = &macio_chips[1];
  1838. MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
  1839. }
  1840. if (macio_chips[0].type == macio_keylargo ||
  1841.     macio_chips[0].type == macio_pangea) {
  1842. /* Enable GMAC for now for PCI probing. It will be disabled
  1843.  * later on after PCI probe
  1844.  */
  1845. np = find_devices("ethernet");
  1846. while(np) {
  1847. if (np->parent
  1848.     && device_is_compatible(np->parent, "uni-north")
  1849.     && device_is_compatible(np, "gmac"))
  1850. core99_gmac_enable(np, 0, 1);
  1851. np = np->next;
  1852. }
  1853. /* Enable FW before PCI probe. Will be disabled later on
  1854.  * Note: We should have a batter way to check that we are
  1855.  * dealing with uninorth internal cell and not a PCI cell
  1856.  * on the external PCI. The code below works though.
  1857.  */
  1858. np = find_devices("firewire");
  1859. while(np) {
  1860. if (np->parent
  1861.     && device_is_compatible(np->parent, "uni-north")
  1862.     && (device_is_compatible(np, "pci106b,18") || 
  1863.               device_is_compatible(np, "pci106b,30") ||
  1864.               device_is_compatible(np, "pci11c1,5811"))) {
  1865. macio_chips[0].flags |= MACIO_FLAG_FW_SUPPORTED;
  1866. core99_firewire_enable(np, 0, 1);
  1867. }
  1868. np = np->next;
  1869. }
  1870. /* Switch airport off */
  1871. np = find_devices("radio");
  1872. while(np) {
  1873. if (np && np->parent == macio_chips[0].of_node) {
  1874. macio_chips[0].flags |= MACIO_FLAG_AIRPORT_ON;
  1875. core99_airport_enable(np, 0, 0);
  1876. }
  1877. np = np->next;
  1878. }
  1879. }
  1880. /* On all machines, switch sound off */
  1881. if (macio_chips[0].of_node)
  1882. pmac_do_feature_call(PMAC_FTR_SOUND_CHIP_ENABLE,
  1883. macio_chips[0].of_node, 0, 0);
  1884. /* On all machines, switch modem & serial ports off */
  1885. np = find_devices("ch-a");
  1886. while(np) {
  1887. initial_serial_shutdown(np);
  1888. np = np->next;
  1889. }
  1890. np = find_devices("ch-b");
  1891. while(np) {
  1892. initial_serial_shutdown(np);
  1893. np = np->next;
  1894. }
  1895. /* Let hardware settle down */
  1896. mdelay(10);
  1897. }
  1898. void __init
  1899. pmac_feature_init(void)
  1900. {
  1901. /* Detect the UniNorth memory controller */
  1902. probe_uninorth();
  1903. /* Probe mac-io controllers */
  1904. if (probe_macios()) {
  1905. printk(KERN_WARNING "No mac-io chip foundn");
  1906. return;
  1907. }
  1908. /* Probe machine type */
  1909. if (probe_motherboard())
  1910. printk(KERN_WARNING "Unknown PowerMac !n");
  1911. /* Set some initial features (turn off some chips that will
  1912.  * be later turned on)
  1913.  */
  1914. set_initial_features();
  1915. }
  1916. void __init
  1917. pmac_feature_late_init(void)
  1918. {
  1919. struct device_node* np;
  1920. /* Request some resources late */
  1921. if (uninorth_node)
  1922. request_OF_resource(uninorth_node, 0, NULL);
  1923. np = find_devices("hammerhead");
  1924. if (np)
  1925. request_OF_resource(np, 0, NULL);
  1926. np = find_devices("interrupt-controller");
  1927. if (np)
  1928. request_OF_resource(np, 0, NULL);
  1929. }