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