Brian Norris | 27c5b17 | 2015-03-06 11:38:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Broadcom Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #ifndef __BRCMNAND_H__ |
| 15 | #define __BRCMNAND_H__ |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/io.h> |
| 19 | |
| 20 | struct platform_device; |
| 21 | struct dev_pm_ops; |
| 22 | |
| 23 | struct brcmnand_soc { |
| 24 | struct platform_device *pdev; |
| 25 | void *priv; |
Brian Norris | c26211d | 2015-05-12 12:09:28 -0700 | [diff] [blame] | 26 | bool (*ctlrdy_ack)(struct brcmnand_soc *soc); |
| 27 | void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en); |
| 28 | void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare); |
Brian Norris | 27c5b17 | 2015-03-06 11:38:08 -0800 | [diff] [blame] | 29 | }; |
| 30 | |
Brian Norris | c26211d | 2015-05-12 12:09:28 -0700 | [diff] [blame] | 31 | static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc) |
| 32 | { |
| 33 | if (soc && soc->prepare_data_bus) |
| 34 | soc->prepare_data_bus(soc, true); |
| 35 | } |
| 36 | |
| 37 | static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc) |
| 38 | { |
| 39 | if (soc && soc->prepare_data_bus) |
| 40 | soc->prepare_data_bus(soc, false); |
| 41 | } |
| 42 | |
Brian Norris | 27c5b17 | 2015-03-06 11:38:08 -0800 | [diff] [blame] | 43 | static inline u32 brcmnand_readl(void __iomem *addr) |
| 44 | { |
| 45 | /* |
| 46 | * MIPS endianness is configured by boot strap, which also reverses all |
| 47 | * bus endianness (i.e., big-endian CPU + big endian bus ==> native |
| 48 | * endian I/O). |
| 49 | * |
| 50 | * Other architectures (e.g., ARM) either do not support big endian, or |
| 51 | * else leave I/O in little endian mode. |
| 52 | */ |
Axel Lin | ddb2c42 | 2015-08-06 12:29:37 +0800 | [diff] [blame] | 53 | if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) |
Brian Norris | 27c5b17 | 2015-03-06 11:38:08 -0800 | [diff] [blame] | 54 | return __raw_readl(addr); |
| 55 | else |
| 56 | return readl_relaxed(addr); |
| 57 | } |
| 58 | |
| 59 | static inline void brcmnand_writel(u32 val, void __iomem *addr) |
| 60 | { |
| 61 | /* See brcmnand_readl() comments */ |
Axel Lin | ddb2c42 | 2015-08-06 12:29:37 +0800 | [diff] [blame] | 62 | if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) |
Brian Norris | 27c5b17 | 2015-03-06 11:38:08 -0800 | [diff] [blame] | 63 | __raw_writel(val, addr); |
| 64 | else |
| 65 | writel_relaxed(val, addr); |
| 66 | } |
| 67 | |
| 68 | int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc); |
| 69 | int brcmnand_remove(struct platform_device *pdev); |
| 70 | |
| 71 | extern const struct dev_pm_ops brcmnand_pm_ops; |
| 72 | |
| 73 | #endif /* __BRCMNAND_H__ */ |