1/* 2 * arch/sh/kernel/io_generic.c 3 * 4 * Copyright (C) 2000 Niibe Yutaka 5 * Copyright (C) 2005 - 2007 Paul Mundt 6 * 7 * Generic I/O routine. These can be used where a machine specific version 8 * is not required. 9 * 10 * This file is subject to the terms and conditions of the GNU General Public 11 * License. See the file "COPYING" in the main directory of this archive 12 * for more details. 13 */ 14#include <linux/module.h> 15#include <linux/io.h> 16#include <asm/machvec.h> 17 18#ifdef CONFIG_CPU_SH3 19/* I'm not sure SH7709 has this kind of bug */ 20#define dummy_read() __raw_readb(0xba000000) 21#else 22#define dummy_read() 23#endif 24 25unsigned long generic_io_base = 0; 26 27u8 generic_inb(unsigned long port) 28{ 29 return __raw_readb(__ioport_map(port, 1)); 30} 31 32u16 generic_inw(unsigned long port) 33{ 34 return __raw_readw(__ioport_map(port, 2)); 35} 36 37u32 generic_inl(unsigned long port) 38{ 39 return __raw_readl(__ioport_map(port, 4)); 40} 41 42u8 generic_inb_p(unsigned long port) 43{ 44 unsigned long v = generic_inb(port); 45 46 ctrl_delay(); 47 return v; 48} 49 50u16 generic_inw_p(unsigned long port) 51{ 52 unsigned long v = generic_inw(port); 53 54 ctrl_delay(); 55 return v; 56} 57 58u32 generic_inl_p(unsigned long port) 59{ 60 unsigned long v = generic_inl(port); 61 62 ctrl_delay(); 63 return v; 64} 65 66/* 67 * insb/w/l all read a series of bytes/words/longs from a fixed port 68 * address. However as the port address doesn't change we only need to 69 * convert the port address to real address once. 70 */ 71 72void generic_insb(unsigned long port, void *dst, unsigned long count) 73{ 74 __raw_readsb(__ioport_map(port, 1), dst, count); 75 dummy_read(); 76} 77 78void generic_insw(unsigned long port, void *dst, unsigned long count) 79{ 80 __raw_readsw(__ioport_map(port, 2), dst, count); 81 dummy_read(); 82} 83 84void generic_insl(unsigned long port, void *dst, unsigned long count) 85{ 86 __raw_readsl(__ioport_map(port, 4), dst, count); 87 dummy_read(); 88} 89 90void generic_outb(u8 b, unsigned long port) 91{ 92 __raw_writeb(b, __ioport_map(port, 1)); 93} 94 95void generic_outw(u16 b, unsigned long port) 96{ 97 __raw_writew(b, __ioport_map(port, 2)); 98} 99 100void generic_outl(u32 b, unsigned long port) 101{ 102 __raw_writel(b, __ioport_map(port, 4)); 103} 104 105void generic_outb_p(u8 b, unsigned long port) 106{ 107 generic_outb(b, port); 108 ctrl_delay(); 109} 110 111void generic_outw_p(u16 b, unsigned long port) 112{ 113 generic_outw(b, port); 114 ctrl_delay(); 115} 116 117void generic_outl_p(u32 b, unsigned long port) 118{ 119 generic_outl(b, port); 120 ctrl_delay(); 121} 122 123/* 124 * outsb/w/l all write a series of bytes/words/longs to a fixed port 125 * address. However as the port address doesn't change we only need to 126 * convert the port address to real address once. 127 */ 128void generic_outsb(unsigned long port, const void *src, unsigned long count) 129{ 130 __raw_writesb(__ioport_map(port, 1), src, count); 131 dummy_read(); 132} 133 134void generic_outsw(unsigned long port, const void *src, unsigned long count) 135{ 136 __raw_writesw(__ioport_map(port, 2), src, count); 137 dummy_read(); 138} 139 140void generic_outsl(unsigned long port, const void *src, unsigned long count) 141{ 142 __raw_writesl(__ioport_map(port, 4), src, count); 143 dummy_read(); 144} 145 146void __iomem *generic_ioport_map(unsigned long addr, unsigned int size) 147{ 148#ifdef P1SEG 149 if (PXSEG(addr) >= P1SEG) 150 return (void __iomem *)addr; 151#endif 152 153 return (void __iomem *)(addr + generic_io_base); 154} 155 156void generic_ioport_unmap(void __iomem *addr) 157{ 158} 159 160#ifndef CONFIG_GENERIC_IOMAP 161void __iomem *ioport_map(unsigned long port, unsigned int nr) 162{ 163 void __iomem *ret; 164 165 ret = __ioport_map_trapped(port, nr); 166 if (ret) 167 return ret; 168 169 return __ioport_map(port, nr); 170} 171EXPORT_SYMBOL(ioport_map); 172 173void ioport_unmap(void __iomem *addr) 174{ 175 sh_mv.mv_ioport_unmap(addr); 176} 177EXPORT_SYMBOL(ioport_unmap); 178#endif /* CONFIG_GENERIC_IOMAP */ 179