1 /* SPDX-License-Identifier: GPL-2.0+ */
2 
3 #ifndef __BRCMNAND_H__
4 #define __BRCMNAND_H__
5 
6 #include <linux/types.h>
7 #include <linux/io.h>
8 
9 struct brcmnand_soc {
10 	bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
11 	void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
12 	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
13 				 bool is_param);
14 	void (*read_data_bus)(struct brcmnand_soc *soc, void __iomem *flash_cache,
15 			      u32 *buffer, int fc_words);
16 	void *ctrl;
17 };
18 
brcmnand_soc_data_bus_prepare(struct brcmnand_soc * soc,bool is_param)19 static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
20 						 bool is_param)
21 {
22 	if (soc && soc->prepare_data_bus)
23 		soc->prepare_data_bus(soc, true, is_param);
24 }
25 
brcmnand_soc_data_bus_unprepare(struct brcmnand_soc * soc,bool is_param)26 static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
27 						   bool is_param)
28 {
29 	if (soc && soc->prepare_data_bus)
30 		soc->prepare_data_bus(soc, false, is_param);
31 }
32 
brcmnand_readl(void __iomem * addr)33 static inline u32 brcmnand_readl(void __iomem *addr)
34 {
35 	/*
36 	 * MIPS endianness is configured by boot strap, which also reverses all
37 	 * bus endianness (i.e., big-endian CPU + big endian bus ==> native
38 	 * endian I/O).
39 	 *
40 	 * Other architectures (e.g., ARM) either do not support big endian, or
41 	 * else leave I/O in little endian mode.
42 	 */
43 	if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_SYS_BIG_ENDIAN))
44 		return __raw_readl(addr);
45 	else
46 		return readl_relaxed(addr);
47 }
48 
brcmnand_writel(u32 val,void __iomem * addr)49 static inline void brcmnand_writel(u32 val, void __iomem *addr)
50 {
51 	/* See brcmnand_readl() comments */
52 	if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_SYS_BIG_ENDIAN))
53 		__raw_writel(val, addr);
54 	else
55 		writel_relaxed(val, addr);
56 }
57 
58 int brcmnand_probe(struct udevice *dev, struct brcmnand_soc *soc);
59 int brcmnand_remove(struct udevice *dev);
60 
61 #ifndef __UBOOT__
62 extern const struct dev_pm_ops brcmnand_pm_ops;
63 #endif /* __UBOOT__ */
64 
65 #endif /* __BRCMNAND_H__ */
66