@@ -196,3 +196,187 @@ void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
196196}
197197EXPORT_SYMBOL_GPL (sdio_writeb );
198198
199+ /**
200+ * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
201+ * @func: SDIO function to access
202+ * @dst: buffer to store the data
203+ * @addr: address to begin reading from
204+ * @count: number of bytes to read
205+ *
206+ * Reads up to 512 bytes from the address space of a given SDIO
207+ * function. Return value indicates if the transfer succeeded or
208+ * not.
209+ */
210+ int sdio_memcpy_fromio (struct sdio_func * func , void * dst ,
211+ unsigned int addr , int count )
212+ {
213+ return mmc_io_rw_extended (func -> card , 0 , func -> num , addr , 0 , dst ,
214+ count );
215+ }
216+ EXPORT_SYMBOL_GPL (sdio_memcpy_fromio );
217+
218+ /**
219+ * sdio_memcpy_toio - write a chunk of memory to a SDIO function
220+ * @func: SDIO function to access
221+ * @addr: address to start writing to
222+ * @src: buffer that contains the data to write
223+ * @count: number of bytes to write
224+ *
225+ * Writes up to 512 bytes to the address space of a given SDIO
226+ * function. Return value indicates if the transfer succeeded or
227+ * not.
228+ */
229+ int sdio_memcpy_toio (struct sdio_func * func , unsigned int addr ,
230+ void * src , int count )
231+ {
232+ return mmc_io_rw_extended (func -> card , 1 , func -> num , addr , 0 , src ,
233+ count );
234+ }
235+ EXPORT_SYMBOL_GPL (sdio_memcpy_toio );
236+
237+ /**
238+ * sdio_readsb - read from a FIFO on a SDIO function
239+ * @func: SDIO function to access
240+ * @dst: buffer to store the data
241+ * @addr: address of (single byte) FIFO
242+ * @count: number of bytes to read
243+ *
244+ * Reads up to 512 bytes from the specified FIFO of a given SDIO
245+ * function. Return value indicates if the transfer succeeded or
246+ * not.
247+ */
248+ int sdio_readsb (struct sdio_func * func , void * dst , unsigned int addr ,
249+ int count )
250+ {
251+ return mmc_io_rw_extended (func -> card , 0 , func -> num , addr , 1 , dst ,
252+ count );
253+ }
254+
255+ EXPORT_SYMBOL_GPL (sdio_readsb );
256+
257+ /**
258+ * sdio_writesb - write to a FIFO of a SDIO function
259+ * @func: SDIO function to access
260+ * @addr: address of (single byte) FIFO
261+ * @src: buffer that contains the data to write
262+ * @count: number of bytes to write
263+ *
264+ * Writes up to 512 bytes to the specified FIFO of a given SDIO
265+ * function. Return value indicates if the transfer succeeded or
266+ * not.
267+ */
268+ int sdio_writesb (struct sdio_func * func , unsigned int addr , void * src ,
269+ int count )
270+ {
271+ return mmc_io_rw_extended (func -> card , 1 , func -> num , addr , 1 , src ,
272+ count );
273+ }
274+ EXPORT_SYMBOL_GPL (sdio_writesb );
275+
276+ /**
277+ * sdio_readw - read a 16 bit integer from a SDIO function
278+ * @func: SDIO function to access
279+ * @addr: address to read
280+ * @err_ret: optional status value from transfer
281+ *
282+ * Reads a 16 bit integer from the address space of a given SDIO
283+ * function. If there is a problem reading the address, 0xffff
284+ * is returned and @err_ret will contain the error code.
285+ */
286+ unsigned short sdio_readw (struct sdio_func * func , unsigned int addr ,
287+ int * err_ret )
288+ {
289+ int ret ;
290+
291+ if (err_ret )
292+ * err_ret = 0 ;
293+
294+ ret = sdio_memcpy_fromio (func , func -> tmpbuf , addr , 2 );
295+ if (ret ) {
296+ if (err_ret )
297+ * err_ret = ret ;
298+ return 0xFFFF ;
299+ }
300+
301+ return le16_to_cpu (* (u16 * )func -> tmpbuf );
302+ }
303+ EXPORT_SYMBOL_GPL (sdio_readw );
304+
305+ /**
306+ * sdio_writew - write a 16 bit integer to a SDIO function
307+ * @func: SDIO function to access
308+ * @b: integer to write
309+ * @addr: address to write to
310+ * @err_ret: optional status value from transfer
311+ *
312+ * Writes a 16 bit integer to the address space of a given SDIO
313+ * function. @err_ret will contain the status of the actual
314+ * transfer.
315+ */
316+ void sdio_writew (struct sdio_func * func , unsigned short b , unsigned int addr ,
317+ int * err_ret )
318+ {
319+ int ret ;
320+
321+ * (u16 * )func -> tmpbuf = cpu_to_le16 (b );
322+
323+ ret = sdio_memcpy_toio (func , addr , func -> tmpbuf , 2 );
324+ if (err_ret )
325+ * err_ret = ret ;
326+ }
327+ EXPORT_SYMBOL_GPL (sdio_writew );
328+
329+ /**
330+ * sdio_readl - read a 32 bit integer from a SDIO function
331+ * @func: SDIO function to access
332+ * @addr: address to read
333+ * @err_ret: optional status value from transfer
334+ *
335+ * Reads a 32 bit integer from the address space of a given SDIO
336+ * function. If there is a problem reading the address,
337+ * 0xffffffff is returned and @err_ret will contain the error
338+ * code.
339+ */
340+ unsigned long sdio_readl (struct sdio_func * func , unsigned int addr ,
341+ int * err_ret )
342+ {
343+ int ret ;
344+
345+ if (err_ret )
346+ * err_ret = 0 ;
347+
348+ ret = sdio_memcpy_fromio (func , func -> tmpbuf , addr , 4 );
349+ if (ret ) {
350+ if (err_ret )
351+ * err_ret = ret ;
352+ return 0xFFFFFFFF ;
353+ }
354+
355+ return le32_to_cpu (* (u32 * )func -> tmpbuf );
356+ }
357+ EXPORT_SYMBOL_GPL (sdio_readl );
358+
359+ /**
360+ * sdio_writel - write a 32 bit integer to a SDIO function
361+ * @func: SDIO function to access
362+ * @b: integer to write
363+ * @addr: address to write to
364+ * @err_ret: optional status value from transfer
365+ *
366+ * Writes a 32 bit integer to the address space of a given SDIO
367+ * function. @err_ret will contain the status of the actual
368+ * transfer.
369+ */
370+ void sdio_writel (struct sdio_func * func , unsigned long b , unsigned int addr ,
371+ int * err_ret )
372+ {
373+ int ret ;
374+
375+ * (u32 * )func -> tmpbuf = cpu_to_le32 (b );
376+
377+ ret = sdio_memcpy_toio (func , addr , func -> tmpbuf , 4 );
378+ if (err_ret )
379+ * err_ret = ret ;
380+ }
381+ EXPORT_SYMBOL_GPL (sdio_writel );
382+
0 commit comments