2 * smssdio.c - Siano 1xxx SDIO interface driver
4 * Copyright 2008 Pierre Ossman
6 * Based on code by Siano Mobile Silicon, Inc.,
7 * Copyright (C) 2006-2008, Uri Shkolnik
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
15 * This hardware is a bit odd in that all transfers should be done
16 * to/from the SMSSDIO_DATA register, yet the "increase address" bit
17 * always needs to be set.
19 * Also, buffers from the card are always aligned to 128 byte
24 * General cleanup notes:
26 * - only typedefs should be name *_t
28 * - use ERR_PTR and friends for smscore_register_device()
30 * - smscore_getbuffer should zero fields
35 #include <linux/moduleparam.h>
36 #include <linux/slab.h>
37 #include <linux/firmware.h>
38 #include <linux/delay.h>
39 #include <linux/mmc/card.h>
40 #include <linux/mmc/sdio_func.h>
41 #include <linux/mmc/sdio_ids.h>
42 #include <linux/module.h>
44 #include "smscoreapi.h"
45 #include "sms-cards.h"
49 #define SMSSDIO_DATA 0x00
50 #define SMSSDIO_INT 0x04
51 #define SMSSDIO_BLOCK_SIZE 128
53 static const struct sdio_device_id smssdio_ids
[] __devinitconst
= {
54 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO
, SDIO_DEVICE_ID_SIANO_STELLAR
),
55 .driver_data
= SMS1XXX_BOARD_SIANO_STELLAR
},
56 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO
, SDIO_DEVICE_ID_SIANO_NOVA_A0
),
57 .driver_data
= SMS1XXX_BOARD_SIANO_NOVA_A
},
58 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO
, SDIO_DEVICE_ID_SIANO_NOVA_B0
),
59 .driver_data
= SMS1XXX_BOARD_SIANO_NOVA_B
},
60 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO
, SDIO_DEVICE_ID_SIANO_VEGA_A0
),
61 .driver_data
= SMS1XXX_BOARD_SIANO_VEGA
},
62 {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO
, SDIO_DEVICE_ID_SIANO_VENICE
),
63 .driver_data
= SMS1XXX_BOARD_SIANO_VEGA
},
64 { /* end: all zeroes */ },
67 MODULE_DEVICE_TABLE(sdio
, smssdio_ids
);
69 struct smssdio_device
{
70 struct sdio_func
*func
;
72 struct smscore_device_t
*coredev
;
74 struct smscore_buffer_t
*split_cb
;
77 /*******************************************************************/
78 /* Siano core callbacks */
79 /*******************************************************************/
81 static int smssdio_sendrequest(void *context
, void *buffer
, size_t size
)
84 struct smssdio_device
*smsdev
;
88 sdio_claim_host(smsdev
->func
);
90 while (size
>= smsdev
->func
->cur_blksize
) {
91 ret
= sdio_memcpy_toio(smsdev
->func
, SMSSDIO_DATA
,
92 buffer
, smsdev
->func
->cur_blksize
);
96 buffer
+= smsdev
->func
->cur_blksize
;
97 size
-= smsdev
->func
->cur_blksize
;
101 ret
= sdio_memcpy_toio(smsdev
->func
, SMSSDIO_DATA
,
106 sdio_release_host(smsdev
->func
);
111 /*******************************************************************/
113 /*******************************************************************/
115 static void smssdio_interrupt(struct sdio_func
*func
)
119 struct smssdio_device
*smsdev
;
120 struct smscore_buffer_t
*cb
;
121 struct SmsMsgHdr_ST
*hdr
;
124 smsdev
= sdio_get_drvdata(func
);
127 * The interrupt register has no defined meaning. It is just
128 * a way of turning of the level triggered interrupt.
130 isr
= sdio_readb(func
, SMSSDIO_INT
, &ret
);
132 sms_err("Unable to read interrupt register!\n");
136 if (smsdev
->split_cb
== NULL
) {
137 cb
= smscore_getbuffer(smsdev
->coredev
);
139 sms_err("Unable to allocate data buffer!\n");
143 ret
= sdio_memcpy_fromio(smsdev
->func
,
148 sms_err("Error %d reading initial block!\n", ret
);
154 if (hdr
->msgFlags
& MSG_HDR_FLAG_SPLIT_MSG
) {
155 smsdev
->split_cb
= cb
;
159 if (hdr
->msgLength
> smsdev
->func
->cur_blksize
)
160 size
= hdr
->msgLength
- smsdev
->func
->cur_blksize
;
164 cb
= smsdev
->split_cb
;
167 size
= hdr
->msgLength
- sizeof(struct SmsMsgHdr_ST
);
169 smsdev
->split_cb
= NULL
;
175 buffer
= cb
->p
+ (hdr
->msgLength
- size
);
176 size
= ALIGN(size
, SMSSDIO_BLOCK_SIZE
);
178 BUG_ON(smsdev
->func
->cur_blksize
!= SMSSDIO_BLOCK_SIZE
);
181 * First attempt to transfer all of it in one go...
183 ret
= sdio_memcpy_fromio(smsdev
->func
,
187 if (ret
&& ret
!= -EINVAL
) {
188 smscore_putbuffer(smsdev
->coredev
, cb
);
189 sms_err("Error %d reading data from card!\n", ret
);
194 * ..then fall back to one block at a time if that is
197 * (we have to do this manually because of the
198 * problem with the "increase address" bit)
200 if (ret
== -EINVAL
) {
202 ret
= sdio_memcpy_fromio(smsdev
->func
,
203 buffer
, SMSSDIO_DATA
,
204 smsdev
->func
->cur_blksize
);
206 smscore_putbuffer(smsdev
->coredev
, cb
);
207 sms_err("Error %d reading "
208 "data from card!\n", ret
);
212 buffer
+= smsdev
->func
->cur_blksize
;
213 if (size
> smsdev
->func
->cur_blksize
)
214 size
-= smsdev
->func
->cur_blksize
;
221 cb
->size
= hdr
->msgLength
;
224 smscore_onresponse(smsdev
->coredev
, cb
);
227 static int __devinit
smssdio_probe(struct sdio_func
*func
,
228 const struct sdio_device_id
*id
)
233 struct smssdio_device
*smsdev
;
234 struct smsdevice_params_t params
;
236 board_id
= id
->driver_data
;
238 smsdev
= kzalloc(sizeof(struct smssdio_device
), GFP_KERNEL
);
244 memset(¶ms
, 0, sizeof(struct smsdevice_params_t
));
246 params
.device
= &func
->dev
;
247 params
.buffer_size
= 0x5000; /* ?? */
248 params
.num_buffers
= 22; /* ?? */
249 params
.context
= smsdev
;
251 snprintf(params
.devpath
, sizeof(params
.devpath
),
252 "sdio\\%s", sdio_func_id(func
));
254 params
.sendrequest_handler
= smssdio_sendrequest
;
256 params
.device_type
= sms_get_board(board_id
)->type
;
258 if (params
.device_type
!= SMS_STELLAR
)
259 params
.flags
|= SMS_DEVICE_FAMILY2
;
262 * FIXME: Stellar needs special handling...
268 ret
= smscore_register_device(¶ms
, &smsdev
->coredev
);
272 smscore_set_board_id(smsdev
->coredev
, board_id
);
274 sdio_claim_host(func
);
276 ret
= sdio_enable_func(func
);
280 ret
= sdio_set_block_size(func
, SMSSDIO_BLOCK_SIZE
);
284 ret
= sdio_claim_irq(func
, smssdio_interrupt
);
288 sdio_set_drvdata(func
, smsdev
);
290 sdio_release_host(func
);
292 ret
= smscore_start_device(smsdev
->coredev
);
299 sdio_claim_host(func
);
300 sdio_release_irq(func
);
302 sdio_disable_func(func
);
304 sdio_release_host(func
);
305 smscore_unregister_device(smsdev
->coredev
);
312 static void smssdio_remove(struct sdio_func
*func
)
314 struct smssdio_device
*smsdev
;
316 smsdev
= sdio_get_drvdata(func
);
319 if (smsdev
->split_cb
)
320 smscore_putbuffer(smsdev
->coredev
, smsdev
->split_cb
);
322 smscore_unregister_device(smsdev
->coredev
);
324 sdio_claim_host(func
);
325 sdio_release_irq(func
);
326 sdio_disable_func(func
);
327 sdio_release_host(func
);
332 static struct sdio_driver smssdio_driver
= {
334 .id_table
= smssdio_ids
,
335 .probe
= smssdio_probe
,
336 .remove
= smssdio_remove
,
339 /*******************************************************************/
340 /* Module functions */
341 /*******************************************************************/
343 static int __init
smssdio_module_init(void)
347 printk(KERN_INFO
"smssdio: Siano SMS1xxx SDIO driver\n");
348 printk(KERN_INFO
"smssdio: Copyright Pierre Ossman\n");
350 ret
= sdio_register_driver(&smssdio_driver
);
355 static void __exit
smssdio_module_exit(void)
357 sdio_unregister_driver(&smssdio_driver
);
360 module_init(smssdio_module_init
);
361 module_exit(smssdio_module_exit
);
363 MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver");
364 MODULE_AUTHOR("Pierre Ossman");
365 MODULE_LICENSE("GPL");