| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (c) 2019 MediaTek Inc. |
| 4 | */ |
| 5 | |
| 6 | #ifndef MT_SYNC_WRITE_H |
| 7 | #define MT_SYNC_WRITE_H |
| 8 | |
| 9 | #if defined(__KERNEL__) |
| 10 | |
| 11 | #include <linux/io.h> |
| 12 | #include <asm/cacheflush.h> |
| 13 | |
| 14 | /* |
| 15 | * Define macros. |
| 16 | */ |
| 17 | #define mt_reg_sync_writel(v, a) \ |
| 18 | do { \ |
| 19 | __raw_writel((v), (void __force __iomem *)((a))); \ |
| 20 | dsb(sy); \ |
| 21 | } while (0) |
| 22 | |
| 23 | #define mt_reg_sync_writew(v, a) \ |
| 24 | do { \ |
| 25 | __raw_writew((v), (void __force __iomem *)((a))); \ |
| 26 | dsb(sy); \ |
| 27 | } while (0) |
| 28 | |
| 29 | #define mt_reg_sync_writeb(v, a) \ |
| 30 | do { \ |
| 31 | __raw_writeb((v), (void __force __iomem *)((a))); \ |
| 32 | dsb(sy); \ |
| 33 | } while (0) |
| 34 | |
| 35 | #if IS_ENABLED(CONFIG_64BIT) |
| 36 | #define mt_reg_sync_writeq(v, a) \ |
| 37 | do { \ |
| 38 | __raw_writeq((v), (void __force __iomem *)((a))); \ |
| 39 | dsb(sy); \ |
| 40 | } while (0) |
| 41 | #endif |
| 42 | |
| 43 | #else /* __KERNEL__ */ |
| 44 | |
| 45 | #include <sys/types.h> |
| 46 | #include <sys/stat.h> |
| 47 | #include <fcntl.h> |
| 48 | #include <unistd.h> |
| 49 | #include <string.h> |
| 50 | |
| 51 | #define mt_reg_sync_writel(v, a) mt65xx_reg_sync_writel(v, a) |
| 52 | #define mt_reg_sync_writew(v, a) mt65xx_reg_sync_writew(v, a) |
| 53 | #define mt_reg_sync_writeb(v, a) mt65xx_reg_sync_writeb(v, a) |
| 54 | |
| 55 | #define dsb() \ |
| 56 | { \ |
| 57 | __asm__ __volatile__("dsb sy" : : : "memory"); \ |
| 58 | } |
| 59 | |
| 60 | #define mt65xx_reg_sync_writel(v, a) \ |
| 61 | do { \ |
| 62 | *(volatile unsigned int *)(a) = (v); \ |
| 63 | dsb(); \ |
| 64 | } while (0) |
| 65 | |
| 66 | #define mt65xx_reg_sync_writew(v, a) \ |
| 67 | do { \ |
| 68 | *(volatile unsigned short *)(a) = (v); \ |
| 69 | dsb(); \ |
| 70 | } while (0) |
| 71 | |
| 72 | #define mt65xx_reg_sync_writeb(v, a) \ |
| 73 | do { \ |
| 74 | *(volatile unsigned char *)(a) = (v); \ |
| 75 | dsb(); \ |
| 76 | } while (0) |
| 77 | |
| 78 | #endif /* __KERNEL__ */ |
| 79 | |
| 80 | #endif /* !MT_SYNC_WRITE_H */ |