io.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* $Id: io.c,v 1.5 2004/02/22 23:08:43 kkojima Exp $
  2. *
  3. * linux/arch/sh/boards/se/7206/io.c
  4. *
  5. * Copyright (C) 2006 Yoshinori Sato
  6. *
  7. * I/O routine for Hitachi 7206 SolutionEngine.
  8. *
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <asm/io.h>
  13. #include <mach-se/mach/se7206.h>
  14. static inline void delay(void)
  15. {
  16. ctrl_inw(0x20000000); /* P2 ROM Area */
  17. }
  18. /* MS7750 requires special versions of in*, out* routines, since
  19. PC-like io ports are located at upper half byte of 16-bit word which
  20. can be accessed only with 16-bit wide. */
  21. static inline volatile __u16 *
  22. port2adr(unsigned int port)
  23. {
  24. if (port >= 0x2000 && port < 0x2020)
  25. return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
  26. else if (port >= 0x300 && port < 0x310)
  27. return (volatile __u16 *) (PA_SMSC + (port - 0x300));
  28. return (volatile __u16 *)port;
  29. }
  30. unsigned char se7206_inb(unsigned long port)
  31. {
  32. return (*port2adr(port)) & 0xff;
  33. }
  34. unsigned char se7206_inb_p(unsigned long port)
  35. {
  36. unsigned long v;
  37. v = (*port2adr(port)) & 0xff;
  38. delay();
  39. return v;
  40. }
  41. unsigned short se7206_inw(unsigned long port)
  42. {
  43. return *port2adr(port);
  44. }
  45. void se7206_outb(unsigned char value, unsigned long port)
  46. {
  47. *(port2adr(port)) = value;
  48. }
  49. void se7206_outb_p(unsigned char value, unsigned long port)
  50. {
  51. *(port2adr(port)) = value;
  52. delay();
  53. }
  54. void se7206_outw(unsigned short value, unsigned long port)
  55. {
  56. *port2adr(port) = value;
  57. }
  58. void se7206_insb(unsigned long port, void *addr, unsigned long count)
  59. {
  60. volatile __u16 *p = port2adr(port);
  61. __u8 *ap = addr;
  62. while (count--)
  63. *ap++ = *p;
  64. }
  65. void se7206_insw(unsigned long port, void *addr, unsigned long count)
  66. {
  67. volatile __u16 *p = port2adr(port);
  68. __u16 *ap = addr;
  69. while (count--)
  70. *ap++ = *p;
  71. }
  72. void se7206_outsb(unsigned long port, const void *addr, unsigned long count)
  73. {
  74. volatile __u16 *p = port2adr(port);
  75. const __u8 *ap = addr;
  76. while (count--)
  77. *p = *ap++;
  78. }
  79. void se7206_outsw(unsigned long port, const void *addr, unsigned long count)
  80. {
  81. volatile __u16 *p = port2adr(port);
  82. const __u16 *ap = addr;
  83. while (count--)
  84. *p = *ap++;
  85. }