1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright © 2015 Broadcom Corporation
9 #include <linux/types.h>
12 struct platform_device;
14 struct brcmnand_io_ops;
16 /* Special register offset constant to intercept a non-MMIO access
17 * to the flash cache register space. This is intentionally large
18 * not to overlap with an existing offset.
20 #define BRCMNAND_NON_MMIO_FC_ADDR 0xffffffff
23 bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
24 void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
25 void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
27 const struct brcmnand_io_ops *ops;
30 struct brcmnand_io_ops {
31 u32 (*read_reg)(struct brcmnand_soc *soc, u32 offset);
32 void (*write_reg)(struct brcmnand_soc *soc, u32 val, u32 offset);
35 static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
38 if (soc && soc->prepare_data_bus)
39 soc->prepare_data_bus(soc, true, is_param);
42 static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
45 if (soc && soc->prepare_data_bus)
46 soc->prepare_data_bus(soc, false, is_param);
49 static inline u32 brcmnand_readl(void __iomem *addr)
52 * MIPS endianness is configured by boot strap, which also reverses all
53 * bus endianness (i.e., big-endian CPU + big endian bus ==> native
56 * Other architectures (e.g., ARM) either do not support big endian, or
57 * else leave I/O in little endian mode.
59 if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
60 return __raw_readl(addr);
62 return readl_relaxed(addr);
65 static inline void brcmnand_writel(u32 val, void __iomem *addr)
67 /* See brcmnand_readl() comments */
68 if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
69 __raw_writel(val, addr);
71 writel_relaxed(val, addr);
74 static inline bool brcmnand_soc_has_ops(struct brcmnand_soc *soc)
76 return soc && soc->ops && soc->ops->read_reg && soc->ops->write_reg;
79 static inline u32 brcmnand_soc_read(struct brcmnand_soc *soc, u32 offset)
81 return soc->ops->read_reg(soc, offset);
84 static inline void brcmnand_soc_write(struct brcmnand_soc *soc, u32 val,
87 soc->ops->write_reg(soc, val, offset);
90 int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc);
91 int brcmnand_remove(struct platform_device *pdev);
93 extern const struct dev_pm_ops brcmnand_pm_ops;
95 #endif /* __BRCMNAND_H__ */