xref: /openbmc/linux/arch/sh/kernel/iomap.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
15933f6d2SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
237b7a978SPaul Mundt /*
337b7a978SPaul Mundt  * arch/sh/kernel/iomap.c
437b7a978SPaul Mundt  *
537b7a978SPaul Mundt  * Copyright (C) 2000  Niibe Yutaka
637b7a978SPaul Mundt  * Copyright (C) 2005 - 2007 Paul Mundt
737b7a978SPaul Mundt  */
837b7a978SPaul Mundt #include <linux/module.h>
937b7a978SPaul Mundt #include <linux/io.h>
1037b7a978SPaul Mundt 
ioread8(const void __iomem * addr)11*8f28ca6bSKrzysztof Kozlowski unsigned int ioread8(const void __iomem *addr)
1237b7a978SPaul Mundt {
1337b7a978SPaul Mundt 	return readb(addr);
1437b7a978SPaul Mundt }
1537b7a978SPaul Mundt EXPORT_SYMBOL(ioread8);
1637b7a978SPaul Mundt 
ioread16(const void __iomem * addr)17*8f28ca6bSKrzysztof Kozlowski unsigned int ioread16(const void __iomem *addr)
1837b7a978SPaul Mundt {
1937b7a978SPaul Mundt 	return readw(addr);
2037b7a978SPaul Mundt }
2137b7a978SPaul Mundt EXPORT_SYMBOL(ioread16);
2237b7a978SPaul Mundt 
ioread16be(const void __iomem * addr)23*8f28ca6bSKrzysztof Kozlowski unsigned int ioread16be(const void __iomem *addr)
2437b7a978SPaul Mundt {
2537b7a978SPaul Mundt 	return be16_to_cpu(__raw_readw(addr));
2637b7a978SPaul Mundt }
2737b7a978SPaul Mundt EXPORT_SYMBOL(ioread16be);
2837b7a978SPaul Mundt 
ioread32(const void __iomem * addr)29*8f28ca6bSKrzysztof Kozlowski unsigned int ioread32(const void __iomem *addr)
3037b7a978SPaul Mundt {
3137b7a978SPaul Mundt 	return readl(addr);
3237b7a978SPaul Mundt }
3337b7a978SPaul Mundt EXPORT_SYMBOL(ioread32);
3437b7a978SPaul Mundt 
ioread32be(const void __iomem * addr)35*8f28ca6bSKrzysztof Kozlowski unsigned int ioread32be(const void __iomem *addr)
3637b7a978SPaul Mundt {
3737b7a978SPaul Mundt 	return be32_to_cpu(__raw_readl(addr));
3837b7a978SPaul Mundt }
3937b7a978SPaul Mundt EXPORT_SYMBOL(ioread32be);
4037b7a978SPaul Mundt 
iowrite8(u8 val,void __iomem * addr)4137b7a978SPaul Mundt void iowrite8(u8 val, void __iomem *addr)
4237b7a978SPaul Mundt {
4337b7a978SPaul Mundt 	writeb(val, addr);
4437b7a978SPaul Mundt }
4537b7a978SPaul Mundt EXPORT_SYMBOL(iowrite8);
4637b7a978SPaul Mundt 
iowrite16(u16 val,void __iomem * addr)4737b7a978SPaul Mundt void iowrite16(u16 val, void __iomem *addr)
4837b7a978SPaul Mundt {
4937b7a978SPaul Mundt 	writew(val, addr);
5037b7a978SPaul Mundt }
5137b7a978SPaul Mundt EXPORT_SYMBOL(iowrite16);
5237b7a978SPaul Mundt 
iowrite16be(u16 val,void __iomem * addr)5337b7a978SPaul Mundt void iowrite16be(u16 val, void __iomem *addr)
5437b7a978SPaul Mundt {
5537b7a978SPaul Mundt 	__raw_writew(cpu_to_be16(val), addr);
5637b7a978SPaul Mundt }
5737b7a978SPaul Mundt EXPORT_SYMBOL(iowrite16be);
5837b7a978SPaul Mundt 
iowrite32(u32 val,void __iomem * addr)5937b7a978SPaul Mundt void iowrite32(u32 val, void __iomem *addr)
6037b7a978SPaul Mundt {
6137b7a978SPaul Mundt 	writel(val, addr);
6237b7a978SPaul Mundt }
6337b7a978SPaul Mundt EXPORT_SYMBOL(iowrite32);
6437b7a978SPaul Mundt 
iowrite32be(u32 val,void __iomem * addr)6537b7a978SPaul Mundt void iowrite32be(u32 val, void __iomem *addr)
6637b7a978SPaul Mundt {
6737b7a978SPaul Mundt 	__raw_writel(cpu_to_be32(val), addr);
6837b7a978SPaul Mundt }
6937b7a978SPaul Mundt EXPORT_SYMBOL(iowrite32be);
7037b7a978SPaul Mundt 
7137b7a978SPaul Mundt /*
7237b7a978SPaul Mundt  * These are the "repeat MMIO read/write" functions.
7337b7a978SPaul Mundt  * Note the "__raw" accesses, since we don't want to
7437b7a978SPaul Mundt  * convert to CPU byte order. We write in "IO byte
7537b7a978SPaul Mundt  * order" (we also don't have IO barriers).
7637b7a978SPaul Mundt  */
mmio_insb(const void __iomem * addr,u8 * dst,int count)77*8f28ca6bSKrzysztof Kozlowski static inline void mmio_insb(const void __iomem *addr, u8 *dst, int count)
7837b7a978SPaul Mundt {
7937b7a978SPaul Mundt 	while (--count >= 0) {
8037b7a978SPaul Mundt 		u8 data = __raw_readb(addr);
8137b7a978SPaul Mundt 		*dst = data;
8237b7a978SPaul Mundt 		dst++;
8337b7a978SPaul Mundt 	}
8437b7a978SPaul Mundt }
8537b7a978SPaul Mundt 
mmio_insw(const void __iomem * addr,u16 * dst,int count)86*8f28ca6bSKrzysztof Kozlowski static inline void mmio_insw(const void __iomem *addr, u16 *dst, int count)
8737b7a978SPaul Mundt {
8837b7a978SPaul Mundt 	while (--count >= 0) {
8937b7a978SPaul Mundt 		u16 data = __raw_readw(addr);
9037b7a978SPaul Mundt 		*dst = data;
9137b7a978SPaul Mundt 		dst++;
9237b7a978SPaul Mundt 	}
9337b7a978SPaul Mundt }
9437b7a978SPaul Mundt 
mmio_insl(const void __iomem * addr,u32 * dst,int count)95*8f28ca6bSKrzysztof Kozlowski static inline void mmio_insl(const void __iomem *addr, u32 *dst, int count)
9637b7a978SPaul Mundt {
9737b7a978SPaul Mundt 	while (--count >= 0) {
9837b7a978SPaul Mundt 		u32 data = __raw_readl(addr);
9937b7a978SPaul Mundt 		*dst = data;
10037b7a978SPaul Mundt 		dst++;
10137b7a978SPaul Mundt 	}
10237b7a978SPaul Mundt }
10337b7a978SPaul Mundt 
mmio_outsb(void __iomem * addr,const u8 * src,int count)10437b7a978SPaul Mundt static inline void mmio_outsb(void __iomem *addr, const u8 *src, int count)
10537b7a978SPaul Mundt {
10637b7a978SPaul Mundt 	while (--count >= 0) {
10737b7a978SPaul Mundt 		__raw_writeb(*src, addr);
10837b7a978SPaul Mundt 		src++;
10937b7a978SPaul Mundt 	}
11037b7a978SPaul Mundt }
11137b7a978SPaul Mundt 
mmio_outsw(void __iomem * addr,const u16 * src,int count)11237b7a978SPaul Mundt static inline void mmio_outsw(void __iomem *addr, const u16 *src, int count)
11337b7a978SPaul Mundt {
11437b7a978SPaul Mundt 	while (--count >= 0) {
11537b7a978SPaul Mundt 		__raw_writew(*src, addr);
11637b7a978SPaul Mundt 		src++;
11737b7a978SPaul Mundt 	}
11837b7a978SPaul Mundt }
11937b7a978SPaul Mundt 
mmio_outsl(void __iomem * addr,const u32 * src,int count)12037b7a978SPaul Mundt static inline void mmio_outsl(void __iomem *addr, const u32 *src, int count)
12137b7a978SPaul Mundt {
12237b7a978SPaul Mundt 	while (--count >= 0) {
12337b7a978SPaul Mundt 		__raw_writel(*src, addr);
12437b7a978SPaul Mundt 		src++;
12537b7a978SPaul Mundt 	}
12637b7a978SPaul Mundt }
12737b7a978SPaul Mundt 
ioread8_rep(const void __iomem * addr,void * dst,unsigned long count)128*8f28ca6bSKrzysztof Kozlowski void ioread8_rep(const void __iomem *addr, void *dst, unsigned long count)
12937b7a978SPaul Mundt {
13037b7a978SPaul Mundt 	mmio_insb(addr, dst, count);
13137b7a978SPaul Mundt }
13237b7a978SPaul Mundt EXPORT_SYMBOL(ioread8_rep);
13337b7a978SPaul Mundt 
ioread16_rep(const void __iomem * addr,void * dst,unsigned long count)134*8f28ca6bSKrzysztof Kozlowski void ioread16_rep(const void __iomem *addr, void *dst, unsigned long count)
13537b7a978SPaul Mundt {
13637b7a978SPaul Mundt 	mmio_insw(addr, dst, count);
13737b7a978SPaul Mundt }
13837b7a978SPaul Mundt EXPORT_SYMBOL(ioread16_rep);
13937b7a978SPaul Mundt 
ioread32_rep(const void __iomem * addr,void * dst,unsigned long count)140*8f28ca6bSKrzysztof Kozlowski void ioread32_rep(const void __iomem *addr, void *dst, unsigned long count)
14137b7a978SPaul Mundt {
14237b7a978SPaul Mundt 	mmio_insl(addr, dst, count);
14337b7a978SPaul Mundt }
14437b7a978SPaul Mundt EXPORT_SYMBOL(ioread32_rep);
14537b7a978SPaul Mundt 
iowrite8_rep(void __iomem * addr,const void * src,unsigned long count)14637b7a978SPaul Mundt void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
14737b7a978SPaul Mundt {
14837b7a978SPaul Mundt 	mmio_outsb(addr, src, count);
14937b7a978SPaul Mundt }
15037b7a978SPaul Mundt EXPORT_SYMBOL(iowrite8_rep);
15137b7a978SPaul Mundt 
iowrite16_rep(void __iomem * addr,const void * src,unsigned long count)15237b7a978SPaul Mundt void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
15337b7a978SPaul Mundt {
15437b7a978SPaul Mundt 	mmio_outsw(addr, src, count);
15537b7a978SPaul Mundt }
15637b7a978SPaul Mundt EXPORT_SYMBOL(iowrite16_rep);
15737b7a978SPaul Mundt 
iowrite32_rep(void __iomem * addr,const void * src,unsigned long count)15837b7a978SPaul Mundt void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
15937b7a978SPaul Mundt {
16037b7a978SPaul Mundt 	mmio_outsl(addr, src, count);
16137b7a978SPaul Mundt }
16237b7a978SPaul Mundt EXPORT_SYMBOL(iowrite32_rep);
163