musb_io.h 2.8 KB

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