Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Common LiteX header providing
0004  * helper functions for accessing CSRs.
0005  *
0006  * Copyright (C) 2019-2020 Antmicro <www.antmicro.com>
0007  */
0008 
0009 #ifndef _LINUX_LITEX_H
0010 #define _LINUX_LITEX_H
0011 
0012 #include <linux/io.h>
0013 
0014 static inline void _write_litex_subregister(u32 val, void __iomem *addr)
0015 {
0016     writel((u32 __force)cpu_to_le32(val), addr);
0017 }
0018 
0019 static inline u32 _read_litex_subregister(void __iomem *addr)
0020 {
0021     return le32_to_cpu((__le32 __force)readl(addr));
0022 }
0023 
0024 /*
0025  * LiteX SoC Generator, depending on the configuration, can split a single
0026  * logical CSR (Control&Status Register) into a series of consecutive physical
0027  * registers.
0028  *
0029  * For example, in the configuration with 8-bit CSR Bus, a 32-bit aligned,
0030  * 32-bit wide logical CSR will be laid out as four 32-bit physical
0031  * subregisters, each one containing one byte of meaningful data.
0032  *
0033  * For Linux support, upstream LiteX enforces a 32-bit wide CSR bus, which
0034  * means that only larger-than-32-bit CSRs will be split across multiple
0035  * subregisters (e.g., a 64-bit CSR will be spread across two consecutive
0036  * 32-bit subregisters).
0037  *
0038  * For details see: https://github.com/enjoy-digital/litex/wiki/CSR-Bus
0039  */
0040 
0041 static inline void litex_write8(void __iomem *reg, u8 val)
0042 {
0043     _write_litex_subregister(val, reg);
0044 }
0045 
0046 static inline void litex_write16(void __iomem *reg, u16 val)
0047 {
0048     _write_litex_subregister(val, reg);
0049 }
0050 
0051 static inline void litex_write32(void __iomem *reg, u32 val)
0052 {
0053     _write_litex_subregister(val, reg);
0054 }
0055 
0056 static inline void litex_write64(void __iomem *reg, u64 val)
0057 {
0058     _write_litex_subregister(val >> 32, reg);
0059     _write_litex_subregister(val, reg + 4);
0060 }
0061 
0062 static inline u8 litex_read8(void __iomem *reg)
0063 {
0064     return _read_litex_subregister(reg);
0065 }
0066 
0067 static inline u16 litex_read16(void __iomem *reg)
0068 {
0069     return _read_litex_subregister(reg);
0070 }
0071 
0072 static inline u32 litex_read32(void __iomem *reg)
0073 {
0074     return _read_litex_subregister(reg);
0075 }
0076 
0077 static inline u64 litex_read64(void __iomem *reg)
0078 {
0079     return ((u64)_read_litex_subregister(reg) << 32) |
0080         _read_litex_subregister(reg + 4);
0081 }
0082 
0083 #endif /* _LINUX_LITEX_H */