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 13*7889a7daSLad 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 60ca7d8b98SSergei Shtylyov struct rpcif { 61ca7d8b98SSergei Shtylyov struct device *dev; 62ca7d8b98SSergei Shtylyov void __iomem *dirmap; 63ca7d8b98SSergei Shtylyov struct regmap *regmap; 64ca7d8b98SSergei Shtylyov struct reset_control *rstc; 65ca7d8b98SSergei Shtylyov size_t size; 66ca7d8b98SSergei Shtylyov enum rpcif_data_dir dir; 67ca7d8b98SSergei Shtylyov u8 bus_size; 68ca7d8b98SSergei Shtylyov void *buffer; 69ca7d8b98SSergei Shtylyov u32 xferlen; 70ca7d8b98SSergei Shtylyov u32 smcr; 71ca7d8b98SSergei Shtylyov u32 smadr; 72ca7d8b98SSergei Shtylyov u32 command; /* DRCMR or SMCMR */ 73ca7d8b98SSergei Shtylyov u32 option; /* DROPR or SMOPR */ 74ca7d8b98SSergei Shtylyov u32 enable; /* DRENR or SMENR */ 75ca7d8b98SSergei Shtylyov u32 dummy; /* DRDMCR or SMDMCR */ 76ca7d8b98SSergei Shtylyov u32 ddr; /* DRDRENR or SMDRENR */ 77ca7d8b98SSergei Shtylyov }; 78ca7d8b98SSergei Shtylyov 79ca7d8b98SSergei Shtylyov int rpcif_sw_init(struct rpcif *rpc, struct device *dev); 80ca7d8b98SSergei Shtylyov void rpcif_hw_init(struct rpcif *rpc, bool hyperflash); 81ca7d8b98SSergei Shtylyov void rpcif_prepare(struct rpcif *rpc, const struct rpcif_op *op, u64 *offs, 82ca7d8b98SSergei Shtylyov size_t *len); 83ca7d8b98SSergei Shtylyov int rpcif_manual_xfer(struct rpcif *rpc); 84ca7d8b98SSergei Shtylyov ssize_t rpcif_dirmap_read(struct rpcif *rpc, u64 offs, size_t len, void *buf); 85ca7d8b98SSergei Shtylyov 86*7889a7daSLad Prabhakar static inline void rpcif_enable_rpm(struct rpcif *rpc) 87*7889a7daSLad Prabhakar { 88*7889a7daSLad Prabhakar pm_runtime_enable(rpc->dev); 89*7889a7daSLad Prabhakar } 90*7889a7daSLad Prabhakar 91*7889a7daSLad Prabhakar static inline void rpcif_disable_rpm(struct rpcif *rpc) 92*7889a7daSLad Prabhakar { 93*7889a7daSLad Prabhakar pm_runtime_disable(rpc->dev); 94*7889a7daSLad Prabhakar } 95*7889a7daSLad Prabhakar 96ca7d8b98SSergei Shtylyov #endif // __RENESAS_RPC_IF_H 97