netwinder-hw.c 12 KB

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