1b0104773SPascal Brand /* 2b0104773SPascal Brand * Copyright (c) 2014, Linaro Limited 3b0104773SPascal Brand * All rights reserved. 4b0104773SPascal Brand * 5b0104773SPascal Brand * Redistribution and use in source and binary forms, with or without 6b0104773SPascal Brand * modification, are permitted provided that the following conditions are met: 7b0104773SPascal Brand * 8b0104773SPascal Brand * 1. Redistributions of source code must retain the above copyright notice, 9b0104773SPascal Brand * this list of conditions and the following disclaimer. 10b0104773SPascal Brand * 11b0104773SPascal Brand * 2. Redistributions in binary form must reproduce the above copyright notice, 12b0104773SPascal Brand * this list of conditions and the following disclaimer in the documentation 13b0104773SPascal Brand * and/or other materials provided with the distribution. 14b0104773SPascal Brand * 15b0104773SPascal Brand * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16b0104773SPascal Brand * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17b0104773SPascal Brand * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18b0104773SPascal Brand * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19b0104773SPascal Brand * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20b0104773SPascal Brand * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21b0104773SPascal Brand * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22b0104773SPascal Brand * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23b0104773SPascal Brand * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24b0104773SPascal Brand * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25b0104773SPascal Brand * POSSIBILITY OF SUCH DAMAGE. 26b0104773SPascal Brand */ 27b0104773SPascal Brand #ifndef IO_H 28b0104773SPascal Brand #define IO_H 29b0104773SPascal Brand 30*1f70169dSJoakim Bech #include <stdint.h> 31*1f70169dSJoakim Bech #include <sys/types.h> 32*1f70169dSJoakim Bech 33*1f70169dSJoakim Bech /* 34*1f70169dSJoakim Bech * IO access macro, please avoid using this macro, since it's going to be 35*1f70169dSJoakim Bech * deprecated. 36*1f70169dSJoakim Bech */ 37*1f70169dSJoakim Bech #define IO(addr) (*((volatile unsigned long *)(addr))) 38*1f70169dSJoakim Bech 39b0104773SPascal Brand static inline void write8(uint8_t val, vaddr_t addr) 40b0104773SPascal Brand { 41b0104773SPascal Brand *(volatile uint8_t *)addr = val; 42b0104773SPascal Brand } 43b0104773SPascal Brand 44b0104773SPascal Brand static inline void write16(uint16_t val, vaddr_t addr) 45b0104773SPascal Brand { 46b0104773SPascal Brand *(volatile uint16_t *)addr = val; 47b0104773SPascal Brand } 48b0104773SPascal Brand 49b0104773SPascal Brand static inline void write32(uint32_t val, vaddr_t addr) 50b0104773SPascal Brand { 51b0104773SPascal Brand *(volatile uint32_t *)addr = val; 52b0104773SPascal Brand } 53b0104773SPascal Brand 54b0104773SPascal Brand static inline uint8_t read8(vaddr_t addr) 55b0104773SPascal Brand { 56b0104773SPascal Brand return *(volatile uint8_t *)addr; 57b0104773SPascal Brand } 58b0104773SPascal Brand 59b0104773SPascal Brand static inline uint16_t read16(vaddr_t addr) 60b0104773SPascal Brand { 61b0104773SPascal Brand return *(volatile uint16_t *)addr; 62b0104773SPascal Brand } 63b0104773SPascal Brand 64b0104773SPascal Brand static inline uint32_t read32(vaddr_t addr) 65b0104773SPascal Brand { 66b0104773SPascal Brand return *(volatile uint32_t *)addr; 67b0104773SPascal Brand } 68b0104773SPascal Brand 69b0104773SPascal Brand #endif /*IO_H*/ 70