netwinder-hw.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * linux/arch/arm/mach-footbridge/netwinder-hw.c
  3. *
  4. * Netwinder machine fixup
  5. *
  6. * Copyright (C) 1998, 1999 Russell King, Phil Blundell
  7. */
  8. #include <linux/module.h>
  9. #include <linux/ioport.h>
  10. #include <linux/kernel.h>
  11. #include <linux/delay.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/spinlock.h>
  15. #include <asm/hardware/dec21285.h>
  16. #include <asm/leds.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/setup.h>
  19. #include <asm/system_misc.h>
  20. #include <asm/mach/arch.h>
  21. #include "common.h"
  22. #define IRDA_IO_BASE 0x180
  23. #define GP1_IO_BASE 0x338
  24. #define GP2_IO_BASE 0x33a
  25. #ifdef CONFIG_LEDS
  26. #define DEFAULT_LEDS 0
  27. #else
  28. #define DEFAULT_LEDS GPIO_GREEN_LED
  29. #endif
  30. /*
  31. * Winbond WB83977F accessibility stuff
  32. */
  33. static inline void wb977_open(void)
  34. {
  35. outb(0x87, 0x370);
  36. outb(0x87, 0x370);
  37. }
  38. static inline void wb977_close(void)
  39. {
  40. outb(0xaa, 0x370);
  41. }
  42. static inline void wb977_wb(int reg, int val)
  43. {
  44. outb(reg, 0x370);
  45. outb(val, 0x371);
  46. }
  47. static inline void wb977_ww(int reg, int val)
  48. {
  49. outb(reg, 0x370);
  50. outb(val >> 8, 0x371);
  51. outb(reg + 1, 0x370);
  52. outb(val & 255, 0x371);
  53. }
  54. #define wb977_device_select(dev) wb977_wb(0x07, dev)
  55. #define wb977_device_disable() wb977_wb(0x30, 0x00)
  56. #define wb977_device_enable() wb977_wb(0x30, 0x01)
  57. /*
  58. * This is a lock for accessing ports GP1_IO_BASE and GP2_IO_BASE
  59. */
  60. DEFINE_RAW_SPINLOCK(nw_gpio_lock);
  61. EXPORT_SYMBOL(nw_gpio_lock);
  62. static unsigned int current_gpio_op;
  63. static unsigned int current_gpio_io;
  64. static unsigned int current_cpld;
  65. void nw_gpio_modify_op(unsigned int mask, unsigned int set)
  66. {
  67. unsigned int new_gpio, changed;
  68. new_gpio = (current_gpio_op & ~mask) | set;
  69. changed = new_gpio ^ current_gpio_op;
  70. current_gpio_op = new_gpio;
  71. if (changed & 0xff)
  72. outb(new_gpio, GP1_IO_BASE);
  73. if (changed & 0xff00)
  74. outb(new_gpio >> 8, GP2_IO_BASE);
  75. }
  76. EXPORT_SYMBOL(nw_gpio_modify_op);
  77. static inline void __gpio_modify_io(int mask, int in)
  78. {
  79. unsigned int new_gpio, changed;
  80. int port;
  81. new_gpio = (current_gpio_io & ~mask) | in;
  82. changed = new_gpio ^ current_gpio_io;
  83. current_gpio_io = new_gpio;
  84. changed >>= 1;
  85. new_gpio >>= 1;
  86. wb977_device_select(7);
  87. for (port = 0xe1; changed && port < 0xe8; changed >>= 1) {
  88. wb977_wb(port, new_gpio & 1);
  89. port += 1;
  90. new_gpio >>= 1;
  91. }
  92. wb977_device_select(8);
  93. for (port = 0xe8; changed && port < 0xec; changed >>= 1) {
  94. wb977_wb(port, new_gpio & 1);
  95. port += 1;
  96. new_gpio >>= 1;
  97. }
  98. }
  99. void nw_gpio_modify_io(unsigned int mask, unsigned int in)
  100. {
  101. /* Open up the SuperIO chip */
  102. wb977_open();
  103. __gpio_modify_io(mask, in);
  104. /* Close up the EFER gate */
  105. wb977_close();
  106. }
  107. EXPORT_SYMBOL(nw_gpio_modify_io);
  108. unsigned int nw_gpio_read(void)
  109. {
  110. return inb(GP1_IO_BASE) | inb(GP2_IO_BASE) << 8;
  111. }
  112. EXPORT_SYMBOL(nw_gpio_read);
  113. /*
  114. * Initialise the Winbond W83977F global registers
  115. */
  116. static inline void wb977_init_global(void)
  117. {
  118. /*
  119. * Enable R/W config registers
  120. */
  121. wb977_wb(0x26, 0x40);
  122. /*
  123. * Power down FDC (not used)
  124. */
  125. wb977_wb(0x22, 0xfe);
  126. /*
  127. * GP12, GP11, CIRRX, IRRXH, GP10
  128. */
  129. wb977_wb(0x2a, 0xc1);
  130. /*
  131. * GP23, GP22, GP21, GP20, GP13
  132. */
  133. wb977_wb(0x2b, 0x6b);
  134. /*
  135. * GP17, GP16, GP15, GP14
  136. */
  137. wb977_wb(0x2c, 0x55);
  138. }
  139. /*
  140. * Initialise the Winbond W83977F printer port
  141. */
  142. static inline void wb977_init_printer(void)
  143. {
  144. wb977_device_select(1);
  145. /*
  146. * mode 1 == EPP
  147. */
  148. wb977_wb(0xf0, 0x01);
  149. }
  150. /*
  151. * Initialise the Winbond W83977F keyboard controller
  152. */
  153. static inline void wb977_init_keyboard(void)
  154. {
  155. wb977_device_select(5);
  156. /*
  157. * Keyboard controller address
  158. */
  159. wb977_ww(0x60, 0x0060);
  160. wb977_ww(0x62, 0x0064);
  161. /*
  162. * Keyboard IRQ 1, active high, edge trigger
  163. */
  164. wb977_wb(0x70, 1);
  165. wb977_wb(0x71, 0x02);
  166. /*
  167. * Mouse IRQ 5, active high, edge trigger
  168. */
  169. wb977_wb(0x72, 5);
  170. wb977_wb(0x73, 0x02);
  171. /*
  172. * KBC 8MHz
  173. */
  174. wb977_wb(0xf0, 0x40);
  175. /*
  176. * Enable device
  177. */
  178. wb977_device_enable();
  179. }
  180. /*
  181. * Initialise the Winbond W83977F Infra-Red device
  182. */
  183. static inline void wb977_init_irda(void)
  184. {
  185. wb977_device_select(6);
  186. /*
  187. * IR base address
  188. */
  189. wb977_ww(0x60, IRDA_IO_BASE);
  190. /*
  191. * IRDA IRQ 6, active high, edge trigger
  192. */
  193. wb977_wb(0x70, 6);
  194. wb977_wb(0x71, 0x02);
  195. /*
  196. * RX DMA - ISA DMA 0
  197. */
  198. wb977_wb(0x74, 0x00);
  199. /*
  200. * TX DMA - Disable Tx DMA
  201. */
  202. wb977_wb(0x75, 0x04);
  203. /*
  204. * Append CRC, Enable bank selection
  205. */
  206. wb977_wb(0xf0, 0x03);
  207. /*
  208. * Enable device
  209. */
  210. wb977_device_enable();
  211. }
  212. /*
  213. * Initialise Winbond W83977F general purpose IO
  214. */
  215. static inline void wb977_init_gpio(void)
  216. {
  217. unsigned long flags;
  218. /*
  219. * Set up initial I/O definitions
  220. */
  221. current_gpio_io = -1;
  222. __gpio_modify_io(-1, GPIO_DONE | GPIO_WDTIMER);
  223. wb977_device_select(7);
  224. /*
  225. * Group1 base address
  226. */
  227. wb977_ww(0x60, GP1_IO_BASE);
  228. wb977_ww(0x62, 0);
  229. wb977_ww(0x64, 0);
  230. /*
  231. * GP10 (Orage button) IRQ 10, active high, edge trigger
  232. */
  233. wb977_wb(0x70, 10);
  234. wb977_wb(0x71, 0x02);
  235. /*
  236. * GP10: Debounce filter enabled, IRQ, input
  237. */
  238. wb977_wb(0xe0, 0x19);
  239. /*
  240. * Enable Group1
  241. */
  242. wb977_device_enable();
  243. wb977_device_select(8);
  244. /*
  245. * Group2 base address
  246. */
  247. wb977_ww(0x60, GP2_IO_BASE);
  248. /*
  249. * Clear watchdog timer regs
  250. * - timer disable
  251. */
  252. wb977_wb(0xf2, 0x00);
  253. /*
  254. * - disable LED, no mouse nor keyboard IRQ
  255. */
  256. wb977_wb(0xf3, 0x00);
  257. /*
  258. * - timer counting, disable power LED, disable timeouot
  259. */
  260. wb977_wb(0xf4, 0x00);
  261. /*
  262. * Enable group2
  263. */
  264. wb977_device_enable();
  265. /*
  266. * Set Group1/Group2 outputs
  267. */
  268. raw_spin_lock_irqsave(&nw_gpio_lock, flags);
  269. nw_gpio_modify_op(-1, GPIO_RED_LED | GPIO_FAN);
  270. raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
  271. }
  272. /*
  273. * Initialise the Winbond W83977F chip.
  274. */
  275. static void __init wb977_init(void)
  276. {
  277. request_region(0x370, 2, "W83977AF configuration");
  278. /*
  279. * Open up the SuperIO chip
  280. */
  281. wb977_open();
  282. /*
  283. * Initialise the global registers
  284. */
  285. wb977_init_global();
  286. /*
  287. * Initialise the various devices in
  288. * the multi-IO chip.
  289. */
  290. wb977_init_printer();
  291. wb977_init_keyboard();
  292. wb977_init_irda();
  293. wb977_init_gpio();
  294. /*
  295. * Close up the EFER gate
  296. */
  297. wb977_close();
  298. }
  299. void nw_cpld_modify(unsigned int mask, unsigned int set)
  300. {
  301. int msk;
  302. current_cpld = (current_cpld & ~mask) | set;
  303. nw_gpio_modify_io(GPIO_DATA | GPIO_IOCLK | GPIO_IOLOAD, 0);
  304. nw_gpio_modify_op(GPIO_IOLOAD, 0);
  305. for (msk = 8; msk; msk >>= 1) {
  306. int bit = current_cpld & msk;
  307. nw_gpio_modify_op(GPIO_DATA | GPIO_IOCLK, bit ? GPIO_DATA : 0);
  308. nw_gpio_modify_op(GPIO_IOCLK, GPIO_IOCLK);
  309. }
  310. nw_gpio_modify_op(GPIO_IOCLK|GPIO_DATA, 0);
  311. nw_gpio_modify_op(GPIO_IOLOAD|GPIO_DSCLK, GPIO_IOLOAD|GPIO_DSCLK);
  312. nw_gpio_modify_op(GPIO_IOLOAD, 0);
  313. }
  314. EXPORT_SYMBOL(nw_cpld_modify);
  315. static void __init cpld_init(void)
  316. {
  317. unsigned long flags;
  318. raw_spin_lock_irqsave(&nw_gpio_lock, flags);
  319. nw_cpld_modify(-1, CPLD_UNMUTE | CPLD_7111_DISABLE);
  320. raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
  321. }
  322. static unsigned char rwa_unlock[] __initdata =
  323. { 0x00, 0x00, 0x6a, 0xb5, 0xda, 0xed, 0xf6, 0xfb, 0x7d, 0xbe, 0xdf, 0x6f, 0x37, 0x1b,
  324. 0x0d, 0x86, 0xc3, 0x61, 0xb0, 0x58, 0x2c, 0x16, 0x8b, 0x45, 0xa2, 0xd1, 0xe8, 0x74,
  325. 0x3a, 0x9d, 0xce, 0xe7, 0x73, 0x39 };
  326. #ifndef DEBUG
  327. #define dprintk(x...)
  328. #else
  329. #define dprintk(x...) printk(x)
  330. #endif
  331. #define WRITE_RWA(r,v) do { outb((r), 0x279); udelay(10); outb((v), 0xa79); } while (0)
  332. static inline void rwa010_unlock(void)
  333. {
  334. int i;
  335. WRITE_RWA(2, 2);
  336. mdelay(10);
  337. for (i = 0; i < sizeof(rwa_unlock); i++) {
  338. outb(rwa_unlock[i], 0x279);
  339. udelay(10);
  340. }
  341. }
  342. static inline void rwa010_read_ident(void)
  343. {
  344. unsigned char si[9];
  345. int i, j;
  346. WRITE_RWA(3, 0);
  347. WRITE_RWA(0, 128);
  348. outb(1, 0x279);
  349. mdelay(1);
  350. dprintk("Identifier: ");
  351. for (i = 0; i < 9; i++) {
  352. si[i] = 0;
  353. for (j = 0; j < 8; j++) {
  354. int bit;
  355. udelay(250);
  356. inb(0x203);
  357. udelay(250);
  358. bit = inb(0x203);
  359. dprintk("%02X ", bit);
  360. bit = (bit == 0xaa) ? 1 : 0;
  361. si[i] |= bit << j;
  362. }
  363. dprintk("(%02X) ", si[i]);
  364. }
  365. dprintk("\n");
  366. }
  367. static inline void rwa010_global_init(void)
  368. {
  369. WRITE_RWA(6, 2); // Assign a card no = 2
  370. dprintk("Card no = %d\n", inb(0x203));
  371. /* disable the modem section of the chip */
  372. WRITE_RWA(7, 3);
  373. WRITE_RWA(0x30, 0);
  374. /* disable the cdrom section of the chip */
  375. WRITE_RWA(7, 4);
  376. WRITE_RWA(0x30, 0);
  377. /* disable the MPU-401 section of the chip */
  378. WRITE_RWA(7, 2);
  379. WRITE_RWA(0x30, 0);
  380. }
  381. static inline void rwa010_game_port_init(void)
  382. {
  383. int i;
  384. WRITE_RWA(7, 5);
  385. dprintk("Slider base: ");
  386. WRITE_RWA(0x61, 1);
  387. i = inb(0x203);
  388. WRITE_RWA(0x60, 2);
  389. dprintk("%02X%02X (201)\n", inb(0x203), i);
  390. WRITE_RWA(0x30, 1);
  391. }
  392. static inline void rwa010_waveartist_init(int base, int irq, int dma)
  393. {
  394. int i;
  395. WRITE_RWA(7, 0);
  396. dprintk("WaveArtist base: ");
  397. WRITE_RWA(0x61, base & 255);
  398. i = inb(0x203);
  399. WRITE_RWA(0x60, base >> 8);
  400. dprintk("%02X%02X (%X),", inb(0x203), i, base);
  401. WRITE_RWA(0x70, irq);
  402. dprintk(" irq: %d (%d),", inb(0x203), irq);
  403. WRITE_RWA(0x74, dma);
  404. dprintk(" dma: %d (%d)\n", inb(0x203), dma);
  405. WRITE_RWA(0x30, 1);
  406. }
  407. static inline void rwa010_soundblaster_init(int sb_base, int al_base, int irq, int dma)
  408. {
  409. int i;
  410. WRITE_RWA(7, 1);
  411. dprintk("SoundBlaster base: ");
  412. WRITE_RWA(0x61, sb_base & 255);
  413. i = inb(0x203);
  414. WRITE_RWA(0x60, sb_base >> 8);
  415. dprintk("%02X%02X (%X),", inb(0x203), i, sb_base);
  416. dprintk(" irq: ");
  417. WRITE_RWA(0x70, irq);
  418. dprintk("%d (%d),", inb(0x203), irq);
  419. dprintk(" 8-bit DMA: ");
  420. WRITE_RWA(0x74, dma);
  421. dprintk("%d (%d)\n", inb(0x203), dma);
  422. dprintk("AdLib base: ");
  423. WRITE_RWA(0x63, al_base & 255);
  424. i = inb(0x203);
  425. WRITE_RWA(0x62, al_base >> 8);
  426. dprintk("%02X%02X (%X)\n", inb(0x203), i, al_base);
  427. WRITE_RWA(0x30, 1);
  428. }
  429. static void rwa010_soundblaster_reset(void)
  430. {
  431. int i;
  432. outb(1, 0x226);
  433. udelay(3);
  434. outb(0, 0x226);
  435. for (i = 0; i < 5; i++) {
  436. if (inb(0x22e) & 0x80)
  437. break;
  438. mdelay(1);
  439. }
  440. if (i == 5)
  441. printk("SoundBlaster: DSP reset failed\n");
  442. dprintk("SoundBlaster DSP reset: %02X (AA)\n", inb(0x22a));
  443. for (i = 0; i < 5; i++) {
  444. if ((inb(0x22c) & 0x80) == 0)
  445. break;
  446. mdelay(1);
  447. }
  448. if (i == 5)
  449. printk("SoundBlaster: DSP not ready\n");
  450. else {
  451. outb(0xe1, 0x22c);
  452. dprintk("SoundBlaster DSP id: ");
  453. i = inb(0x22a);
  454. udelay(1);
  455. i |= inb(0x22a) << 8;
  456. dprintk("%04X\n", i);
  457. for (i = 0; i < 5; i++) {
  458. if ((inb(0x22c) & 0x80) == 0)
  459. break;
  460. mdelay(1);
  461. }
  462. if (i == 5)
  463. printk("SoundBlaster: could not turn speaker off\n");
  464. outb(0xd3, 0x22c);
  465. }
  466. /* turn on OPL3 */
  467. outb(5, 0x38a);
  468. outb(1, 0x38b);
  469. }
  470. static void __init rwa010_init(void)
  471. {
  472. rwa010_unlock();
  473. rwa010_read_ident();
  474. rwa010_global_init();
  475. rwa010_game_port_init();
  476. rwa010_waveartist_init(0x250, 3, 7);
  477. rwa010_soundblaster_init(0x220, 0x388, 3, 1);
  478. rwa010_soundblaster_reset();
  479. }
  480. /*
  481. * Initialise any other hardware after we've got the PCI bus
  482. * initialised. We may need the PCI bus to talk to this other
  483. * hardware.
  484. */
  485. static int __init nw_hw_init(void)
  486. {
  487. if (machine_is_netwinder()) {
  488. unsigned long flags;
  489. wb977_init();
  490. cpld_init();
  491. rwa010_init();
  492. raw_spin_lock_irqsave(&nw_gpio_lock, flags);
  493. nw_gpio_modify_op(GPIO_RED_LED|GPIO_GREEN_LED, DEFAULT_LEDS);
  494. raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
  495. }
  496. return 0;
  497. }
  498. __initcall(nw_hw_init);
  499. /*
  500. * Older NeTTroms either do not provide a parameters
  501. * page, or they don't supply correct information in
  502. * the parameter page.
  503. */
  504. static void __init
  505. fixup_netwinder(struct tag *tags, char **cmdline, struct meminfo *mi)
  506. {
  507. #ifdef CONFIG_ISAPNP
  508. extern int isapnp_disable;
  509. /*
  510. * We must not use the kernels ISAPnP code
  511. * on the NetWinder - it will reset the settings
  512. * for the WaveArtist chip and render it inoperable.
  513. */
  514. isapnp_disable = 1;
  515. #endif
  516. }
  517. static void netwinder_restart(char mode, const char *cmd)
  518. {
  519. if (mode == 's') {
  520. /* Jump into the ROM */
  521. soft_restart(0x41000000);
  522. } else {
  523. local_irq_disable();
  524. local_fiq_disable();
  525. /* open up the SuperIO chip */
  526. outb(0x87, 0x370);
  527. outb(0x87, 0x370);
  528. /* aux function group 1 (logical device 7) */
  529. outb(0x07, 0x370);
  530. outb(0x07, 0x371);
  531. /* set GP16 for WD-TIMER output */
  532. outb(0xe6, 0x370);
  533. outb(0x00, 0x371);
  534. /* set a RED LED and toggle WD_TIMER for rebooting */
  535. outb(0xc4, 0x338);
  536. }
  537. }
  538. MACHINE_START(NETWINDER, "Rebel-NetWinder")
  539. /* Maintainer: Russell King/Rebel.com */
  540. .atag_offset = 0x100,
  541. .video_start = 0x000a0000,
  542. .video_end = 0x000bffff,
  543. .reserve_lp0 = 1,
  544. .reserve_lp2 = 1,
  545. .fixup = fixup_netwinder,
  546. .map_io = footbridge_map_io,
  547. .init_irq = footbridge_init_irq,
  548. .timer = &isa_timer,
  549. .restart = netwinder_restart,
  550. MACHINE_END