Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Renesas RPC-IF core driver |
| 4 | * |
| 5 | * Copyright (C) 2018~2019 Renesas Solutions Corp. |
| 6 | * Copyright (C) 2019 Macronix International Co., Ltd. |
| 7 | * Copyright (C) 2019-2020 Cogent Embedded, Inc. |
| 8 | */ |
| 9 | |
| 10 | #ifndef __RENESAS_RPC_IF_H |
| 11 | #define __RENESAS_RPC_IF_H |
| 12 | |
Lad Prabhakar | 7889a7d | 2020-11-26 19:11:45 +0000 | [diff] [blame] | 13 | #include <linux/pm_runtime.h> |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | |
| 16 | enum rpcif_data_dir { |
| 17 | RPCIF_NO_DATA, |
| 18 | RPCIF_DATA_IN, |
| 19 | RPCIF_DATA_OUT, |
| 20 | }; |
| 21 | |
Krzysztof Kozlowski | 8c84a73 | 2021-06-01 18:06:07 +0200 | [diff] [blame] | 22 | struct rpcif_op { |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 23 | struct { |
| 24 | u8 buswidth; |
| 25 | u8 opcode; |
| 26 | bool ddr; |
| 27 | } cmd, ocmd; |
| 28 | |
| 29 | struct { |
| 30 | u8 nbytes; |
| 31 | u8 buswidth; |
| 32 | bool ddr; |
| 33 | u64 val; |
| 34 | } addr; |
| 35 | |
| 36 | struct { |
| 37 | u8 ncycles; |
| 38 | u8 buswidth; |
| 39 | } dummy; |
| 40 | |
| 41 | struct { |
| 42 | u8 nbytes; |
| 43 | u8 buswidth; |
| 44 | bool ddr; |
| 45 | u32 val; |
| 46 | } option; |
| 47 | |
| 48 | struct { |
| 49 | u8 buswidth; |
| 50 | unsigned int nbytes; |
| 51 | enum rpcif_data_dir dir; |
| 52 | bool ddr; |
| 53 | union { |
| 54 | void *in; |
| 55 | const void *out; |
| 56 | } buf; |
| 57 | } data; |
| 58 | }; |
| 59 | |
Lad Prabhakar | b04cc0d | 2021-10-25 21:56:31 +0100 | [diff] [blame] | 60 | enum rpcif_type { |
| 61 | RPCIF_RCAR_GEN3, |
| 62 | RPCIF_RZ_G2L, |
| 63 | }; |
| 64 | |
Krzysztof Kozlowski | 8c84a73 | 2021-06-01 18:06:07 +0200 | [diff] [blame] | 65 | struct rpcif { |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 66 | struct device *dev; |
Wolfram Sang | fff53a5 | 2021-09-22 11:10:06 +0200 | [diff] [blame] | 67 | void __iomem *base; |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 68 | void __iomem *dirmap; |
| 69 | struct regmap *regmap; |
| 70 | struct reset_control *rstc; |
| 71 | size_t size; |
Lad Prabhakar | b04cc0d | 2021-10-25 21:56:31 +0100 | [diff] [blame] | 72 | enum rpcif_type type; |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 73 | enum rpcif_data_dir dir; |
| 74 | u8 bus_size; |
| 75 | void *buffer; |
| 76 | u32 xferlen; |
| 77 | u32 smcr; |
| 78 | u32 smadr; |
| 79 | u32 command; /* DRCMR or SMCMR */ |
| 80 | u32 option; /* DROPR or SMOPR */ |
| 81 | u32 enable; /* DRENR or SMENR */ |
| 82 | u32 dummy; /* DRDMCR or SMDMCR */ |
| 83 | u32 ddr; /* DRDRENR or SMDRENR */ |
| 84 | }; |
| 85 | |
Krzysztof Kozlowski | 8c84a73 | 2021-06-01 18:06:07 +0200 | [diff] [blame] | 86 | int rpcif_sw_init(struct rpcif *rpc, struct device *dev); |
Lad Prabhakar | b04cc0d | 2021-10-25 21:56:31 +0100 | [diff] [blame] | 87 | int rpcif_hw_init(struct rpcif *rpc, bool hyperflash); |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 88 | void rpcif_prepare(struct rpcif *rpc, const struct rpcif_op *op, u64 *offs, |
| 89 | size_t *len); |
| 90 | int rpcif_manual_xfer(struct rpcif *rpc); |
| 91 | ssize_t rpcif_dirmap_read(struct rpcif *rpc, u64 offs, size_t len, void *buf); |
| 92 | |
Lad Prabhakar | 7889a7d | 2020-11-26 19:11:45 +0000 | [diff] [blame] | 93 | static inline void rpcif_enable_rpm(struct rpcif *rpc) |
| 94 | { |
| 95 | pm_runtime_enable(rpc->dev); |
| 96 | } |
| 97 | |
| 98 | static inline void rpcif_disable_rpm(struct rpcif *rpc) |
| 99 | { |
| 100 | pm_runtime_disable(rpc->dev); |
| 101 | } |
| 102 | |
Sergei Shtylyov | ca7d8b9 | 2020-06-16 23:03:48 +0300 | [diff] [blame] | 103 | #endif // __RENESAS_RPC_IF_H |