musb_io.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * MUSB OTG driver register I/O
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * SPDX-License-Identifier: GPL-2.0
  13. */
  14. #ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
  15. #define __MUSB_LINUX_PLATFORM_ARCH_H__
  16. #ifndef __UBOOT__
  17. #include <linux/io.h>
  18. #else
  19. #include <asm/io.h>
  20. #endif
  21. #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \
  22. && !defined(CONFIG_PPC32) \
  23. && !defined(CONFIG_PPC64) && !defined(CONFIG_MIPS) \
  24. && !defined(CONFIG_M68K)
  25. static inline void readsl(const void __iomem *addr, void *buf, int len)
  26. { insl((unsigned long)addr, buf, len); }
  27. static inline void readsw(const void __iomem *addr, void *buf, int len)
  28. { insw((unsigned long)addr, buf, len); }
  29. static inline void readsb(const void __iomem *addr, void *buf, int len)
  30. { insb((unsigned long)addr, buf, len); }
  31. static inline void writesl(const void __iomem *addr, const void *buf, int len)
  32. { outsl((unsigned long)addr, buf, len); }
  33. static inline void writesw(const void __iomem *addr, const void *buf, int len)
  34. { outsw((unsigned long)addr, buf, len); }
  35. static inline void writesb(const void __iomem *addr, const void *buf, int len)
  36. { outsb((unsigned long)addr, buf, len); }
  37. #endif
  38. /* NOTE: these offsets are all in bytes */
  39. static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
  40. { return __raw_readw(addr + offset); }
  41. static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
  42. { return __raw_readl(addr + offset); }
  43. static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
  44. { __raw_writew(data, addr + offset); }
  45. static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
  46. { __raw_writel(data, addr + offset); }
  47. #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
  48. /*
  49. * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
  50. */
  51. static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
  52. {
  53. u16 tmp;
  54. u8 val;
  55. tmp = __raw_readw(addr + (offset & ~1));
  56. if (offset & 1)
  57. val = (tmp >> 8);
  58. else
  59. val = tmp & 0xff;
  60. return val;
  61. }
  62. static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
  63. {
  64. u16 tmp;
  65. tmp = __raw_readw(addr + (offset & ~1));
  66. if (offset & 1)
  67. tmp = (data << 8) | (tmp & 0xff);
  68. else
  69. tmp = (tmp & 0xff00) | data;
  70. __raw_writew(tmp, addr + (offset & ~1));
  71. }
  72. #else
  73. static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
  74. { return __raw_readb(addr + offset); }
  75. static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
  76. { __raw_writeb(data, addr + offset); }
  77. #endif /* CONFIG_USB_MUSB_TUSB6010 */
  78. #endif