pio.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * include/asm-arm/arch-at91rm9200/pio.h
  3. *
  4. * Copyright (C) 2003 SAN People
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #ifndef __ASM_ARCH_PIO_H
  13. #define __ASM_ARCH_PIO_H
  14. #include <asm/arch/hardware.h>
  15. static inline void AT91_CfgPIO_USART0(void) {
  16. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA17_TXD0 | AT91_PA18_RXD0 | AT91_PA20_CTS0);
  17. /*
  18. * Errata #39 - RTS0 is not internally connected to PA21. We need to drive
  19. * the pin manually. Default is off (RTS is active low).
  20. */
  21. at91_sys_write(AT91_PIOA + PIO_PER, AT91_PA21_RTS0);
  22. at91_sys_write(AT91_PIOA + PIO_OER, AT91_PA21_RTS0);
  23. at91_sys_write(AT91_PIOA + PIO_SODR, AT91_PA21_RTS0);
  24. }
  25. static inline void AT91_CfgPIO_USART1(void) {
  26. at91_sys_write(AT91_PIOB + PIO_PDR, AT91_PB18_RI1 | AT91_PB19_DTR1
  27. | AT91_PB20_TXD1 | AT91_PB21_RXD1 | AT91_PB23_DCD1
  28. | AT91_PB24_CTS1 | AT91_PB25_DSR1 | AT91_PB26_RTS1);
  29. }
  30. static inline void AT91_CfgPIO_USART2(void) {
  31. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA22_RXD2 | AT91_PA23_TXD2);
  32. }
  33. static inline void AT91_CfgPIO_USART3(void) {
  34. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA5_TXD3 | AT91_PA6_RXD3);
  35. at91_sys_write(AT91_PIOA + PIO_BSR, AT91_PA5_TXD3 | AT91_PA6_RXD3);
  36. }
  37. static inline void AT91_CfgPIO_DBGU(void) {
  38. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA31_DTXD | AT91_PA30_DRXD);
  39. }
  40. /*
  41. * Enable the Two-Wire interface.
  42. */
  43. static inline void AT91_CfgPIO_TWI(void) {
  44. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA25_TWD | AT91_PA26_TWCK);
  45. at91_sys_write(AT91_PIOA + PIO_ASR, AT91_PA25_TWD | AT91_PA26_TWCK);
  46. at91_sys_write(AT91_PIOA + PIO_MDER, AT91_PA25_TWD | AT91_PA26_TWCK); /* open drain */
  47. }
  48. /*
  49. * Enable the Serial Peripheral Interface.
  50. */
  51. static inline void AT91_CfgPIO_SPI(void) {
  52. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA0_MISO | AT91_PA1_MOSI | AT91_PA2_SPCK);
  53. }
  54. static inline void AT91_CfgPIO_SPI_CS0(void) {
  55. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA3_NPCS0);
  56. }
  57. static inline void AT91_CfgPIO_SPI_CS1(void) {
  58. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA4_NPCS1);
  59. }
  60. static inline void AT91_CfgPIO_SPI_CS2(void) {
  61. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA5_NPCS2);
  62. }
  63. static inline void AT91_CfgPIO_SPI_CS3(void) {
  64. at91_sys_write(AT91_PIOA + PIO_PDR, AT91_PA6_NPCS3);
  65. }
  66. /*
  67. * Select the DataFlash card.
  68. */
  69. static inline void AT91_CfgPIO_DataFlashCard(void) {
  70. at91_sys_write(AT91_PIOB + PIO_PER, AT91_PIO_P(7));
  71. at91_sys_write(AT91_PIOB + PIO_OER, AT91_PIO_P(7));
  72. at91_sys_write(AT91_PIOB + PIO_CODR, AT91_PIO_P(7));
  73. }
  74. /*
  75. * Enable NAND Flash (SmartMedia) interface.
  76. */
  77. static inline void AT91_CfgPIO_SmartMedia(void) {
  78. /* enable PC0=SMCE, PC1=SMOE, PC3=SMWE, A21=CLE, A22=ALE */
  79. at91_sys_write(AT91_PIOC + PIO_ASR, AT91_PC0_BFCK | AT91_PC1_BFRDY_SMOE | AT91_PC3_BFBAA_SMWE);
  80. at91_sys_write(AT91_PIOC + PIO_PDR, AT91_PC0_BFCK | AT91_PC1_BFRDY_SMOE | AT91_PC3_BFBAA_SMWE);
  81. /* Configure PC2 as input (signal READY of the SmartMedia) */
  82. at91_sys_write(AT91_PIOC + PIO_PER, AT91_PC2_BFAVD); /* enable direct output enable */
  83. at91_sys_write(AT91_PIOC + PIO_ODR, AT91_PC2_BFAVD); /* disable output */
  84. /* Configure PB1 as input (signal Card Detect of the SmartMedia) */
  85. at91_sys_write(AT91_PIOB + PIO_PER, AT91_PIO_P(1)); /* enable direct output enable */
  86. at91_sys_write(AT91_PIOB + PIO_ODR, AT91_PIO_P(1)); /* disable output */
  87. }
  88. static inline int AT91_PIO_SmartMedia_RDY(void) {
  89. return (at91_sys_read(AT91_PIOC + PIO_PDSR) & AT91_PIO_P(2)) ? 1 : 0;
  90. }
  91. static inline int AT91_PIO_SmartMedia_CardDetect(void) {
  92. return (at91_sys_read(AT91_PIOB + PIO_PDSR) & AT91_PIO_P(1)) ? 1 : 0;
  93. }
  94. #endif