| /* |
| * Copyright (C) 2018 Synaptics Incorporated. All rights reserved. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation. |
| * |
| * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND |
| * SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, |
| * INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| * A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY |
| * INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE |
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR |
| * CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE |
| * OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND |
| * BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS |
| * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF |
| * COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT |
| * DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY |
| * TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS. |
| */ |
| |
| #include <stdint.h> |
| |
| #ifndef _IMAGE_2_IO_H |
| #define _IMAGE_2_IO_H |
| |
| #define __chk_io_ptr(a) (void)0 |
| |
| #define __raw_writeb(v,a) (__chk_io_ptr(a), *(volatile unsigned char *)((uintmax_t)a) = (v)) |
| #define __raw_writew(v,a) (__chk_io_ptr(a), *(volatile unsigned short *)((uintmax_t)a) = (v)) |
| #define __raw_writel(v,a) (__chk_io_ptr(a), *(volatile unsigned int *)((uintmax_t)a) = (v)) |
| |
| #define __raw_readb(a) (__chk_io_ptr(a), *(volatile unsigned char *)((uintmax_t)a)) |
| #define __raw_readw(a) (__chk_io_ptr(a), *(volatile unsigned short *)((uintmax_t)a)) |
| #define __raw_readl(a) (*(volatile unsigned int *)((uintmax_t)a)) |
| |
| |
| #define writeb __raw_writeb |
| #define writew __raw_writew |
| #define writel __raw_writel |
| |
| #define readb __raw_readb |
| #define readw __raw_readw |
| #define readl __raw_readl |
| |
| #ifndef GA_REG_WORD32_WRITE |
| #define GA_REG_WORD32_WRITE(a, v) (writel(v, a)) |
| #endif |
| |
| #ifndef GA_REG_WORD32_READ |
| #define GA_REG_WORD32_READ(a, h) (*h = readl(a)) |
| #endif |
| |
| #define io32_set_bits(a, v, lsb, bits) \ |
| do { \ |
| uint32_t reg_val, mask; \ |
| mask = ((bits<32) ? ((1<<(bits)) - 1) : ~0) << (lsb); \ |
| reg_val = readl(a); \ |
| reg_val &= ~mask; \ |
| reg_val |= ((v) << (lsb)) & mask; \ |
| writel(reg_val, a); \ |
| } while(0); |
| |
| #ifndef UNUSED |
| #define UNUSED(var) do { (void)(var); } while(0) |
| #endif |
| |
| #ifndef REG_WRITE64 |
| #define REG_WRITE64(a, v) (write64((void *)(uintptr_t)(a), v)) |
| #endif |
| #ifndef REG_READ64 |
| #define REG_READ64(a, h) (*h = read64((void *)(uintptr_t)(a))) |
| #endif |
| #ifndef REG_WRITE32 |
| #define REG_WRITE32(a, v) (write32((void *)(uintptr_t)(a), v)) |
| #endif |
| |
| #ifndef REG_READ32 |
| #define REG_READ32(a, h) (*h = read32((void *)(uintptr_t)(a))) |
| #endif |
| |
| #ifndef REG_WRITE16 |
| #define REG_WRITE16(a, v) (write16((void *)(uintptr_t)(a), v)) |
| #endif |
| |
| #ifndef REG_READ16 |
| #define REG_READ16(a, h) (*h = read16((void *)(uintptr_t)(a))) |
| #endif |
| |
| #ifndef REG_WRITE8 |
| #define REG_WRITE8(a, v) (write8((void *)(uintptr_t)(a), v)) |
| #endif |
| |
| #ifndef REG_READ8 |
| #define REG_READ8(a, h) (*h = read8((void *)(uintptr_t)(a))) |
| #endif |
| |
| #ifndef BFM_HOST_Bus_Write32 |
| #define BFM_HOST_Bus_Write32 REG_WRITE32 |
| #endif |
| |
| #ifndef BFM_HOST_Bus_Read32 |
| #define BFM_HOST_Bus_Read32 REG_READ32 |
| #endif |
| |
| #ifndef GA_REG_WORD32_WRITE |
| #define GA_REG_WORD32_WRITE REG_WRITE32 |
| #endif |
| |
| #ifndef GA_REG_WORD32_READ |
| #define GA_REG_WORD32_READ REG_READ32 |
| #endif |
| |
| |
| static inline uint8_t read8(void *addr) |
| { |
| return *(volatile uint8_t *)(addr); |
| }; |
| static inline void write8(void *addr, uint8_t value) |
| { |
| *(volatile uint8_t *)(addr) = (value); |
| }; |
| static inline uint16_t read16(void *addr) |
| { |
| return *(volatile uint16_t *)(addr); |
| }; |
| static inline void write16(void *addr, uint16_t value) |
| { |
| *(volatile uint16_t *)(addr) = (value); |
| }; |
| static inline uint32_t read32(void *addr) |
| { |
| return *(volatile uint32_t *)(addr); |
| }; |
| static inline void write32(void *addr, uint32_t value) |
| { |
| *(volatile uint32_t *)(addr) = (value); |
| }; |
| static inline uint64_t read64(void *addr) |
| { |
| return *(volatile uint64_t *)(addr); |
| }; |
| static inline void write64(void *addr, uint64_t value) |
| { |
| *(volatile uint64_t *)(addr) = (value); |
| }; |
| |
| #endif |