• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 #ifndef __OAL_SDIO_IF_H__
19 #define __OAL_SDIO_IF_H__
20 
21 /* ****************************************************************************
22   1 其他头文件包含
23 **************************************************************************** */
24 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
25 #ifndef HAVE_PCLINT_CHECK
26 #include <linux/mmc/host.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/mmc/sdio.h>
29 
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/device.h>
33 #include <linux/slab.h>
34 #include <linux/types.h>
35 #include <linux/err.h>
36 #include <linux/workqueue.h>
37 #include <linux/sched.h>
38 #include <linux/delay.h>
39 #include <linux/kthread.h>
40 #include <linux/mmc/card.h>
41 #include <linux/mmc/sdio_func.h>
42 #include <linux/mmc/sdio_ids.h>
43 #include <linux/mmc/sdio_func.h>
44 #include <linux/mmc/host.h>
45 #include <linux/pm_runtime.h>
46 #include <linux/random.h>
47 #endif
48 #include "oal_time.h"
49 
50 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
51 
52 #include <linux/module.h>
53 #include <linux/kernel.h>
54 #include <linux/device.h>
55 #include <linux/slab.h>
56 #include <linux/types.h>
57 #include <linux/workqueue.h>
58 #include <linux/sched.h>
59 #include <linux/delay.h>
60 #endif
61 #include "hdf_ibus_intf.h"
62 
63 #ifdef __cplusplus
64 #if __cplusplus
65 extern "C" {
66 #endif
67 #endif
68 
69 /* ****************************************************************************
70   2 宏定义
71 **************************************************************************** */
72 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
73 #define sdio_get_max_block_count(func)  ((func)->card->host->max_blk_count)
74 #define sdio_get_max_req_size(func)     ((func)->card->host->max_req_size)
75 #define sdio_get_max_blk_size(func)     ((func)->card->host->max_blk_size)
76 #define sdio_get_max_seg_size(func)     ((func)->card->host->max_seg_size)
77 #define sdio_get_max_segs(func)         ((func)->card->host->max_segs)
78 
79 /* *
80  * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
81  * @func: SDIO function to access
82  * @dst: buffer to store the data
83  * @addr: address to begin reading from
84  * @count: number of bytes to read
85  *
86  * Reads from the address space of a given SDIO function. Return
87  * value indicates if the transfer succeeded or not.
88  */
oal_sdio_memcpy_fromio(struct BusDev * bus,hi_void * dst,hi_u32 addr,hi_s32 count)89 static inline hi_s32 oal_sdio_memcpy_fromio(struct BusDev *bus, hi_void *dst, hi_u32 addr, hi_s32 count)
90 {
91     hi_s32 ret;
92 #ifdef CONFIG_HISI_SDIO_TIME_DEBUG
93     oal_time_t_stru time_start;
94     time_start = oal_ktime_get();
95 #endif
96     ret = bus->ops.readData(bus, addr, count, (hi_u8 *)dst);
97 #ifdef CONFIG_HISI_SDIO_TIME_DEBUG
98     if (oal_unlikely(ret)) {
99         /* If sdio transfer failed, dump the sdio info */
100         hi_u64 trans_us;
101         oal_time_t_stru time_stop = oal_ktime_get();
102         trans_us = (hi_u64)oal_ktime_to_us(oal_ktime_sub(time_stop, time_start));
103         printk(KERN_WARNING "[E]sdio_memcpy_fromio fail=%d, time cost:%llu us,[dst:%p,addr:%u,count:%d]\n", ret,
104             trans_us, dst, addr, count);
105     }
106 #endif
107     return ret;
108 }
109 
110 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
111 
112 #ifdef CONFIG_MMC
113 #define sdio_get_max_block_count(func) (func->card->host->max_blk_num)
114 #define sdio_get_max_req_size(func)    (func->card->host->max_request_size)
115 #define sdio_get_max_blk_size(func)    (func->card->host->max_blk_size)
116 #define sdio_en_timeout(func)          (func->en_timeout_ms)
117 
118 #define sdio_func_num(func) (func->func_num)
119 
120 #define SDIO_ANY_ID (~0)
121 
122 #define SDIO_DEVICE(vend, dev) .class = SDIO_ANY_ID,      \
123                                .vendor = (vend),          \
124                                .device = (dev)
125 
126 struct sdio_device_id {
127     unsigned char class;       /* Standard interface or SDIO_ANY_ID */
128     unsigned short int vendor; /* Vendor or SDIO_ANY_ID */
129     unsigned short int device; /* Device ID or SDIO_ANY_ID */
130 };
131 
132 #define sdio_get_drvdata(func) (func->data)
133 #define sdio_set_drvdata(func, priv) (func->data = (void *)priv)
134 
135 /*
136  * SDIO function device driver
137  */
138 struct sdio_driver {
139     char *name;
140     const struct sdio_device_id *id_table;
141 };
142 
143 static inline hi_s32 sdio_register_driver(struct sdio_driver *driver)
144 {
145     hi_unref_param(driver);
146     return HI_SUCCESS;
147 }
148 
149 /* *
150  * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
151  * @func: SDIO function to access
152  * @dst: buffer to store the data
153  * @addr: address to begin reading from
154  * @count: number of bytes to read
155  *
156  * Reads from the address space of a given SDIO function. Return
157  * value indicates if the transfer succeeded or not.
158  */
159 static inline hi_s32 oal_sdio_memcpy_fromio(struct BusDev *bus, hi_void *dst, hi_u32 addr, hi_s32 count)
160 {
161     hi_s32 ret;
162 #ifdef CONFIG_HISI_SDIO_TIME_DEBUG
163     oal_time_t_stru time_start;
164     time_start = oal_ktime_get();
165 #endif
166     ret = bus->ops.readData(bus, addr, count, (hi_u8 *)dst);
167 #ifdef CONFIG_HISI_SDIO_TIME_DEBUG
168     if (oal_unlikely(ret)) {
169         /* If sdio transfer failed, dump the sdio info */
170         hi_u64 trans_us;
171         oal_time_t_stru time_stop = oal_ktime_get();
172         trans_us = (hi_u64)oal_ktime_to_us(oal_ktime_sub(time_stop, time_start));
173         printk(KERN_WARNING"[E]sdio_memcpy_fromio fail=%d, time cost:%llu us,[dst:%p,addr:%u,count:%d]\n",
174                ret, trans_us, dst, addr, count);
175     }
176 #endif
177     return ret;
178 }
179 
180 #else /* CONFIG_MMC */
181 
182 #define sdio_get_max_block_count(func) (func->card->host->max_blk_count)
183 #define sdio_get_max_req_size(func) (func->card->host->max_req_size)
184 #define sdio_get_max_blk_size(func) (func->card->host->max_blk_size)
185 #define sdio_en_timeout(func) (func->enable_timeout)
186 #define sdio_func_num(func) (func->num)
187 
188 /* *
189  * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
190  * @func: SDIO function to access
191  * @dst: buffer to store the data
192  * @addr: address to begin reading from
193  * @count: number of bytes to read
194  *
195  * Reads from the address space of a given SDIO function. Return
196  * value indicates if the transfer succeeded or not.
197  */
198 static inline hi_s32 oal_sdio_memcpy_fromio(struct sdio_func *func, hi_void *dst, hi_u32 addr, hi_s32 count)
199 {
200     hi_s32 ret;
201 #ifdef CONFIG_HISI_SDIO_TIME_DEBUG
202     oal_time_t_stru time_start;
203     time_start = oal_ktime_get();
204 #endif
205     ret = sdio_memcpy_fromio(func, dst, addr, count);
206 #ifdef CONFIG_HISI_SDIO_TIME_DEBUG
207     if (oal_unlikely(ret)) {
208         /* If sdio transfer failed, dump the sdio info */
209         hi_u64 trans_us;
210         oal_time_t_stru time_stop = oal_ktime_get();
211         trans_us = (hi_u64)oal_ktime_to_us(oal_ktime_sub(time_stop, time_start));
212         printk(KERN_WARNING"[E]sdio_memcpy_fromio fail=%d, time cost:%llu us,[dst:%p,addr:%u,count:%d]\n",
213                ret, trans_us, dst, addr, count);
214     }
215 #endif
216     return ret;
217 }
218 
219 static inline hi_s32 sdio_register_driver(struct sdio_driver *driver)
220 {
221     return HI_SUCCESS;
222 }
223 
224 static inline hi_void sdio_claim_host(struct sdio_func *func)
225 {
226     return;
227 }
228 
229 static inline hi_void sdio_release_host(struct sdio_func *func)
230 {
231     return;
232 }
233 
234 static inline int sdio_require_irq(struct sdio_func *func, sdio_irq_handler_t *handler)
235 {
236     return sdio_claim_irq(func, handler);
237 }
238 #endif /* end of CONFIG_MMC */
239 
240 #endif /* end of (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) */
241 
242 #ifdef __cplusplus
243 #if __cplusplus
244 }
245 #endif
246 #endif
247 
248 #endif /* end of oal_sdio_if.h */
249