2 * drivers/mmc/host/ubicom32sd.c
3 * Ubicom32 Secure Digital Host Controller Interface driver
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/delay.h>
27 #include <linux/scatterlist.h>
28 #include <linux/leds.h>
29 #include <linux/gpio.h>
30 #include <linux/mmc/host.h>
32 #include <asm/ubicom32sd.h>
34 #define DRIVER_NAME "ubicom32sd"
36 #define sd_printk(...)
37 //#define sd_printk printk
39 #define SDTIO_VP_VERSION 3
41 #define SDTIO_MAX_SG_BLOCKS 16
46 SDTIO_COMMAND_SETUP_SDIO
,
47 SDTIO_COMMAND_EXECUTE
,
51 #define SDTIO_COMMAND_SHIFT 24
52 #define SDTIO_COMMAND_FLAG_STOP_RSP_CRC (1 << 10)
53 #define SDTIO_COMMAND_FLAG_STOP_RSP_136 (1 << 9)
54 #define SDTIO_COMMAND_FLAG_STOP_RSP (1 << 8)
55 #define SDTIO_COMMAND_FLAG_STOP_CMD (1 << 7)
56 #define SDTIO_COMMAND_FLAG_DATA_STREAM (1 << 6)
57 #define SDTIO_COMMAND_FLAG_DATA_RD (1 << 5)
58 #define SDTIO_COMMAND_FLAG_DATA_WR (1 << 4)
59 #define SDTIO_COMMAND_FLAG_CMD_RSP_CRC (1 << 3)
60 #define SDTIO_COMMAND_FLAG_CMD_RSP_136 (1 << 2)
61 #define SDTIO_COMMAND_FLAG_CMD_RSP (1 << 1)
62 #define SDTIO_COMMAND_FLAG_CMD (1 << 0)
65 * SDTIO_COMMAND_SETUP_SDIO
67 #define SDTIO_COMMAND_FLAG_SDIO_INT_EN (1 << 0)
73 #define SDTIO_COMMAND_FLAG_4BIT (1 << 3)
74 #define SDTIO_COMMAND_FLAG_1BIT (1 << 2)
75 #define SDTIO_COMMAND_FLAG_SET_CLOCK (1 << 1)
76 #define SDTIO_COMMAND_FLAG_SET_WIDTH (1 << 0)
78 #define SDTIO_COMMAND_FLAG_CMD_RSP_MASK (SDTIO_COMMAND_FLAG_CMD_RSP | SDTIO_COMMAND_FLAG_CMD_RSP_136)
79 #define SDTIO_COMMAND_FLAG_STOP_RSP_MASK (SDTIO_COMMAND_FLAG_STOP_RSP | SDTIO_COMMAND_FLAG_STOP_RSP_136)
80 #define SDTIO_COMMAND_FLAG_RSP_MASK (SDTIO_COMMAND_FLAG_CMD_RSP_MASK | SDTIO_COMMAND_FLAG_STOP_RSP_MASK)
87 #define SDTIO_VP_INT_STATUS_DONE (1 << 31)
88 #define SDTIO_VP_INT_STATUS_SDIO_INT (1 << 10)
89 #define SDTIO_VP_INT_STATUS_DATA_CRC_ERR (1 << 9)
90 #define SDTIO_VP_INT_STATUS_DATA_PROG_ERR (1 << 8)
91 #define SDTIO_VP_INT_STATUS_DATA_TIMEOUT (1 << 7)
92 #define SDTIO_VP_INT_STATUS_STOP_RSP_CRC (1 << 6)
93 #define SDTIO_VP_INT_STATUS_STOP_RSP_TIMEOUT (1 << 5)
94 #define SDTIO_VP_INT_STATUS_CMD_RSP_CRC (1 << 4)
95 #define SDTIO_VP_INT_STATUS_CMD_RSP_TIMEOUT (1 << 3)
96 #define SDTIO_VP_INT_STATUS_CMD_TIMEOUT (1 << 2)
97 #define SDTIO_VP_INT_STATUS_CARD1_INSERT (1 << 1)
98 #define SDTIO_VP_INT_STATUS_CARD0_INSERT (1 << 0)
100 struct sdtio_vp_regs
{
105 volatile u32_t int_status
;
107 volatile u32_t command
;
110 volatile u32_t cmd_opcode
;
111 volatile u32_t cmd_arg
;
112 volatile u32_t cmd_rsp0
;
113 volatile u32_t cmd_rsp1
;
114 volatile u32_t cmd_rsp2
;
115 volatile u32_t cmd_rsp3
;
117 volatile u32_t stop_opcode
;
118 volatile u32_t stop_arg
;
119 volatile u32_t stop_rsp0
;
120 volatile u32_t stop_rsp1
;
121 volatile u32_t stop_rsp2
;
122 volatile u32_t stop_rsp3
;
124 volatile u32_t data_timeout_ns
;
125 volatile u16_t data_blksz
;
126 volatile u16_t data_blkct
;
127 volatile u32_t data_bytes_transferred
;
128 volatile u32_t sg_len
;
129 struct sdtio_vp_sg sg
[SDTIO_MAX_SG_BLOCKS
];
132 struct ubicom32sd_data
{
133 const struct ubicom32sd_platform_data
*pdata
;
135 struct mmc_host
*mmc
;
138 * Lock used to protect the data structure
145 * Receive and transmit interrupts used for communicating
152 * Current outstanding mmc request
154 struct mmc_request
*mrq
;
159 struct sdtio_vp_regs
*regs
;
162 /*****************************************************************************\
166 \*****************************************************************************/
170 int ubicom32sd_suspend_host(struct ubicom32sd_host
*host
, pm_message_t state
)
174 ret
= mmc_suspend_host(host
->mmc
, state
);
178 free_irq(host
->irq
, host
);
183 EXPORT_SYMBOL_GPL(ubicom32sd_suspend_host
);
185 int ubicom32sd_resume_host(struct ubicom32sd_host
*host
)
189 if (host
->flags
& UBICOM32SD_USE_DMA
) {
190 if (host
->ops
->enable_dma
)
191 host
->ops
->enable_dma(host
);
194 ret
= request_irq(host
->irq
, ubicom32sd_irq
, IRQF_SHARED
,
195 mmc_hostname(host
->mmc
), host
);
199 ubicom32sd_init(host
);
202 ret
= mmc_resume_host(host
->mmc
);
209 EXPORT_SYMBOL_GPL(ubicom32sd_resume_host
);
211 #endif /* CONFIG_PM */
214 * ubicom32sd_send_command_sync
216 static void ubicom32sd_send_command_sync(struct ubicom32sd_data
*ud
, u32_t command
, u32_t arg
)
218 ud
->regs
->command
= command
;
220 ubicom32_set_interrupt(ud
->irq_tx
);
221 while (ud
->regs
->command
) {
227 * ubicom32sd_send_command
229 static void ubicom32sd_send_command(struct ubicom32sd_data
*ud
, u32_t command
, u32_t arg
)
231 ud
->regs
->command
= command
;
233 ubicom32_set_interrupt(ud
->irq_tx
);
239 static void ubicom32sd_reset(struct ubicom32sd_data
*ud
)
241 ubicom32sd_send_command_sync(ud
, SDTIO_COMMAND_RESET
<< SDTIO_COMMAND_SHIFT
, 0);
242 ud
->regs
->int_status
= 0;
246 * ubicom32sd_mmc_request
248 static void ubicom32sd_mmc_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
250 struct ubicom32sd_data
*ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
251 u32_t command
= SDTIO_COMMAND_EXECUTE
<< SDTIO_COMMAND_SHIFT
;
254 WARN(ud
->mrq
!= NULL
, "ud->mrq still set to %p\n", ud
->mrq
);
255 //pr_debug("send cmd %08x arg %08x flags %08x\n", cmd->opcode, cmd->arg, cmd->flags);
258 struct mmc_command
*cmd
= mrq
->cmd
;
260 sd_printk("%s:\t\t\tsetup cmd %02d arg %08x flags %08x\n", mmc_hostname(mmc
), cmd
->opcode
, cmd
->arg
, cmd
->flags
);
262 ud
->regs
->cmd_opcode
= cmd
->opcode
;
263 ud
->regs
->cmd_arg
= cmd
->arg
;
265 command
|= SDTIO_COMMAND_FLAG_CMD
;
267 if (cmd
->flags
& MMC_RSP_PRESENT
) {
268 command
|= SDTIO_COMMAND_FLAG_CMD_RSP
;
271 if (cmd
->flags
& MMC_RSP_136
) {
272 command
|= SDTIO_COMMAND_FLAG_CMD_RSP_136
;
275 if (cmd
->flags
& MMC_RSP_CRC
) {
276 command
|= SDTIO_COMMAND_FLAG_CMD_RSP_CRC
;
281 struct mmc_data
*data
= mrq
->data
;
282 struct scatterlist
*sg
= data
->sg
;
285 printk("%s:\t\t\tsetup data blksz %d num %d sglen=%d fl=%08x Tns=%u\n", mmc_hostname(mmc
), data
->blksz
, data
->blocks
, data
->sg_len
, data
->flags
, data
->timeout_ns
);
287 sd_printk("%s:\t\t\tsetup data blksz %d num %d sglen=%d fl=%08x Tns=%u\n",
288 mmc_hostname(mmc
), data
->blksz
, data
->blocks
, data
->sg_len
,
289 data
->flags
, data
->timeout_ns
);
291 if (data
->sg_len
> SDTIO_MAX_SG_BLOCKS
) {
293 data
->error
= -EINVAL
;
297 ud
->regs
->data_timeout_ns
= data
->timeout_ns
;
298 ud
->regs
->data_blksz
= data
->blksz
;
299 ud
->regs
->data_blkct
= data
->blocks
;
300 ud
->regs
->sg_len
= data
->sg_len
;
303 * Load all of our sg list into the driver sg buffer
305 for (i
= 0; i
< data
->sg_len
; i
++) {
306 sd_printk("%s: sg %d = %p %d\n", mmc_hostname(mmc
), i
, sg_virt(sg
), sg
->length
);
307 ud
->regs
->sg
[i
].addr
= sg_virt(sg
);
308 ud
->regs
->sg
[i
].len
= sg
->length
;
309 if (((u32_t
)ud
->regs
->sg
[i
].addr
& 0x03) || (sg
->length
& 0x03)) {
310 sd_printk("%s: Need aligned buffers\n", mmc_hostname(mmc
));
312 data
->error
= -EINVAL
;
317 if (data
->flags
& MMC_DATA_READ
) {
318 command
|= SDTIO_COMMAND_FLAG_DATA_RD
;
319 } else if (data
->flags
& MMC_DATA_WRITE
) {
320 command
|= SDTIO_COMMAND_FLAG_DATA_WR
;
321 } else if (data
->flags
& MMC_DATA_STREAM
) {
322 command
|= SDTIO_COMMAND_FLAG_DATA_STREAM
;
327 struct mmc_command
*stop
= mrq
->stop
;
328 sd_printk("%s: \t\t\tsetup stop %02d arg %08x flags %08x\n", mmc_hostname(mmc
), stop
->opcode
, stop
->arg
, stop
->flags
);
330 ud
->regs
->stop_opcode
= stop
->opcode
;
331 ud
->regs
->stop_arg
= stop
->arg
;
333 command
|= SDTIO_COMMAND_FLAG_STOP_CMD
;
335 if (stop
->flags
& MMC_RSP_PRESENT
) {
336 command
|= SDTIO_COMMAND_FLAG_STOP_RSP
;
339 if (stop
->flags
& MMC_RSP_136
) {
340 command
|= SDTIO_COMMAND_FLAG_STOP_RSP_136
;
343 if (stop
->flags
& MMC_RSP_CRC
) {
344 command
|= SDTIO_COMMAND_FLAG_STOP_RSP_CRC
;
350 sd_printk("%s: Sending command %08x\n", mmc_hostname(mmc
), command
);
352 ubicom32sd_send_command(ud
, command
, 0);
356 sd_printk("%s: mmcreq ret = %d\n", mmc_hostname(mmc
), ret
);
357 mrq
->cmd
->error
= ret
;
358 mmc_request_done(mmc
, mrq
);
362 * ubicom32sd_mmc_set_ios
364 static void ubicom32sd_mmc_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
366 struct ubicom32sd_data
*ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
367 u32_t command
= SDTIO_COMMAND_SETUP
<< SDTIO_COMMAND_SHIFT
;
369 sd_printk("%s: ios call bw:%u pm:%u clk:%u\n", mmc_hostname(mmc
), 1 << ios
->bus_width
, ios
->power_mode
, ios
->clock
);
371 switch (ios
->bus_width
) {
372 case MMC_BUS_WIDTH_1
:
373 command
|= SDTIO_COMMAND_FLAG_SET_WIDTH
| SDTIO_COMMAND_FLAG_1BIT
;
376 case MMC_BUS_WIDTH_4
:
377 command
|= SDTIO_COMMAND_FLAG_SET_WIDTH
| SDTIO_COMMAND_FLAG_4BIT
;
383 command
|= SDTIO_COMMAND_FLAG_SET_CLOCK
;
386 switch (ios
->power_mode
) {
389 * Turn off the SD bus (power + clock)
392 gpio_set_value(ud
->pdata
->cards
[0].pin_pwr
, !ud
->pdata
->cards
[0].pwr_polarity
);
393 command
|= SDTIO_COMMAND_FLAG_SET_CLOCK
;
397 * Turn on the power to the SD bus
400 gpio_set_value(ud
->pdata
->cards
[0].pin_pwr
, ud
->pdata
->cards
[0].pwr_polarity
);
404 * Turn on the clock to the SD bus
413 ubicom32sd_send_command_sync(ud
, command
, arg
);
416 * Let the power settle down
422 * ubicom32sd_mmc_get_cd
424 static int ubicom32sd_mmc_get_cd(struct mmc_host
*mmc
)
426 struct ubicom32sd_data
*ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
427 sd_printk("%s: get cd %u %u\n", mmc_hostname(mmc
), ud
->pdata
->cards
[0].pin_cd
, gpio_get_value(ud
->pdata
->cards
[0].pin_cd
));
429 return gpio_get_value(ud
->pdata
->cards
[0].pin_cd
) ?
430 ud
->pdata
->cards
[0].cd_polarity
:
431 !ud
->pdata
->cards
[0].cd_polarity
;
435 * ubicom32sd_mmc_get_ro
437 static int ubicom32sd_mmc_get_ro(struct mmc_host
*mmc
)
439 struct ubicom32sd_data
*ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
440 sd_printk("%s: get ro %u %u\n", mmc_hostname(mmc
), ud
->pdata
->cards
[0].pin_wp
, gpio_get_value(ud
->pdata
->cards
[0].pin_wp
));
442 return gpio_get_value(ud
->pdata
->cards
[0].pin_wp
) ?
443 ud
->pdata
->cards
[0].wp_polarity
:
444 !ud
->pdata
->cards
[0].wp_polarity
;
448 * ubicom32sd_mmc_enable_sdio_irq
450 static void ubicom32sd_mmc_enable_sdio_irq(struct mmc_host
*mmc
, int enable
)
452 struct ubicom32sd_data
*ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
455 if (enable
&& ud
->int_pend
) {
457 mmc_signal_sdio_irq(mmc
);
462 * ubicom32sd_interrupt
464 static irqreturn_t
ubicom32sd_interrupt(int irq
, void *dev
)
466 struct mmc_host
*mmc
= (struct mmc_host
*)dev
;
467 struct mmc_request
*mrq
;
468 struct ubicom32sd_data
*ud
;
475 ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
480 int_status
= ud
->regs
->int_status
;
481 ud
->regs
->int_status
&= ~int_status
;
483 if (int_status
& SDTIO_VP_INT_STATUS_SDIO_INT
) {
486 mmc_signal_sdio_irq(mmc
);
492 if (!(int_status
& SDTIO_VP_INT_STATUS_DONE
)) {
498 sd_printk("%s: Spurious interrupt", mmc_hostname(mmc
));
506 if (mrq
->cmd
->flags
& MMC_RSP_PRESENT
) {
507 struct mmc_command
*cmd
= mrq
->cmd
;
510 if ((cmd
->flags
& MMC_RSP_CRC
) && (int_status
& SDTIO_VP_INT_STATUS_CMD_RSP_CRC
)) {
511 cmd
->error
= -EILSEQ
;
512 } else if (int_status
& SDTIO_VP_INT_STATUS_CMD_RSP_TIMEOUT
) {
513 cmd
->error
= -ETIMEDOUT
;
515 } else if (cmd
->flags
& MMC_RSP_136
) {
516 cmd
->resp
[0] = ud
->regs
->cmd_rsp0
;
517 cmd
->resp
[1] = ud
->regs
->cmd_rsp1
;
518 cmd
->resp
[2] = ud
->regs
->cmd_rsp2
;
519 cmd
->resp
[3] = ud
->regs
->cmd_rsp3
;
521 cmd
->resp
[0] = ud
->regs
->cmd_rsp0
;
523 sd_printk("%s:\t\t\tResponse %08x %08x %08x %08x err=%d\n", mmc_hostname(mmc
), cmd
->resp
[0], cmd
->resp
[1], cmd
->resp
[2], cmd
->resp
[3], cmd
->error
);
527 struct mmc_data
*data
= mrq
->data
;
529 if (int_status
& SDTIO_VP_INT_STATUS_DATA_TIMEOUT
) {
530 data
->error
= -ETIMEDOUT
;
531 sd_printk("%s:\t\t\tData Timeout\n", mmc_hostname(mmc
));
533 } else if (int_status
& SDTIO_VP_INT_STATUS_DATA_CRC_ERR
) {
534 data
->error
= -EILSEQ
;
535 sd_printk("%s:\t\t\tData CRC\n", mmc_hostname(mmc
));
537 } else if (int_status
& SDTIO_VP_INT_STATUS_DATA_PROG_ERR
) {
538 data
->error
= -EILSEQ
;
539 sd_printk("%s:\t\t\tData Program Error\n", mmc_hostname(mmc
));
543 data
->bytes_xfered
= ud
->regs
->data_bytes_transferred
;
547 if (mrq
->stop
&& (mrq
->stop
->flags
& MMC_RSP_PRESENT
)) {
548 struct mmc_command
*stop
= mrq
->stop
;
551 if ((stop
->flags
& MMC_RSP_CRC
) && (int_status
& SDTIO_VP_INT_STATUS_STOP_RSP_CRC
)) {
552 stop
->error
= -EILSEQ
;
553 } else if (int_status
& SDTIO_VP_INT_STATUS_STOP_RSP_TIMEOUT
) {
554 stop
->error
= -ETIMEDOUT
;
556 } else if (stop
->flags
& MMC_RSP_136
) {
557 stop
->resp
[0] = ud
->regs
->stop_rsp0
;
558 stop
->resp
[1] = ud
->regs
->stop_rsp1
;
559 stop
->resp
[2] = ud
->regs
->stop_rsp2
;
560 stop
->resp
[3] = ud
->regs
->stop_rsp3
;
562 stop
->resp
[0] = ud
->regs
->stop_rsp0
;
564 sd_printk("%s:\t\t\tStop Response %08x %08x %08x %08x err=%d\n", mmc_hostname(mmc
), stop
->resp
[0], stop
->resp
[1], stop
->resp
[2], stop
->resp
[3], stop
->error
);
568 mmc_request_done(mmc
, mrq
);
573 static struct mmc_host_ops ubicom32sd_ops
= {
574 .request
= ubicom32sd_mmc_request
,
575 .set_ios
= ubicom32sd_mmc_set_ios
,
576 .get_ro
= ubicom32sd_mmc_get_ro
,
577 .get_cd
= ubicom32sd_mmc_get_cd
,
578 .enable_sdio_irq
= ubicom32sd_mmc_enable_sdio_irq
,
584 static int __devinit
ubicom32sd_probe(struct platform_device
*pdev
)
586 struct ubicom32sd_platform_data
*pdata
= (struct ubicom32sd_platform_data
*)pdev
->dev
.platform_data
;
587 struct mmc_host
*mmc
;
588 struct ubicom32sd_data
*ud
;
589 struct resource
*res_regs
;
590 struct resource
*res_irq_tx
;
591 struct resource
*res_irq_rx
;
595 * Get our resources, regs is the hardware driver base address
596 * and the tx and rx irqs are used to communicate with the
599 res_regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
600 res_irq_tx
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
601 res_irq_rx
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
602 if (!res_regs
|| !res_irq_tx
|| !res_irq_rx
) {
608 * Reserve any gpios we need
610 ret
= gpio_request(pdata
->cards
[0].pin_wp
, "sd-wp");
614 gpio_direction_input(pdata
->cards
[0].pin_wp
);
616 ret
= gpio_request(pdata
->cards
[0].pin_cd
, "sd-cd");
620 gpio_direction_input(pdata
->cards
[0].pin_cd
);
623 * HACK: for the dual port controller on port F, we don't support the second port right now
625 if (pdata
->ncards
> 1) {
626 ret
= gpio_request(pdata
->cards
[1].pin_pwr
, "sd-pwr");
627 gpio_direction_output(pdata
->cards
[1].pin_pwr
, !pdata
->cards
[1].pwr_polarity
);
628 gpio_direction_output(pdata
->cards
[1].pin_pwr
, pdata
->cards
[1].pwr_polarity
);
631 ret
= gpio_request(pdata
->cards
[0].pin_pwr
, "sd-pwr");
635 gpio_direction_output(pdata
->cards
[0].pin_pwr
, !pdata
->cards
[0].pwr_polarity
);
638 * Allocate the MMC driver, it includes memory for our data.
640 mmc
= mmc_alloc_host(sizeof(struct ubicom32sd_data
), &pdev
->dev
);
645 ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
648 ud
->regs
= (struct sdtio_vp_regs
*)res_regs
->start
;
649 ud
->irq_tx
= res_irq_tx
->start
;
650 ud
->irq_rx
= res_irq_rx
->start
;
651 platform_set_drvdata(pdev
, mmc
);
653 ret
= request_irq(ud
->irq_rx
, ubicom32sd_interrupt
, IRQF_DISABLED
, mmc_hostname(mmc
), mmc
);
659 * Fill in the mmc structure
661 mmc
->ops
= &ubicom32sd_ops
;
662 mmc
->caps
= MMC_CAP_4_BIT_DATA
| MMC_CAP_NEEDS_POLL
| MMC_CAP_SDIO_IRQ
|
663 MMC_CAP_MMC_HIGHSPEED
| MMC_CAP_SD_HIGHSPEED
;
665 mmc
->f_min
= ud
->regs
->f_min
;
666 mmc
->f_max
= ud
->regs
->f_max
;
667 mmc
->ocr_avail
= MMC_VDD_32_33
| MMC_VDD_33_34
;
670 * Setup some restrictions on transfers
672 * We allow up to SDTIO_MAX_SG_BLOCKS of data to DMA into, there are
673 * not really any "max_seg_size", "max_req_size", or "max_blk_count"
674 * restrictions (must be less than U32_MAX though), pick
675 * something large?!...
677 * The hardware can do up to 4095 bytes per block, since the spec
678 * only requires 2048, we'll set it to that and not worry about
679 * potential weird blk lengths.
681 mmc
->max_hw_segs
= SDTIO_MAX_SG_BLOCKS
;
682 mmc
->max_phys_segs
= SDTIO_MAX_SG_BLOCKS
;
683 mmc
->max_seg_size
= 1024 * 1024;
684 mmc
->max_req_size
= 1024 * 1024;
685 mmc
->max_blk_count
= 1024;
687 mmc
->max_blk_size
= 2048;
689 ubicom32sd_reset(ud
);
695 ubicom32sd_send_command_sync(ud
, SDTIO_COMMAND_SETUP_SDIO
<< SDTIO_COMMAND_SHIFT
| SDTIO_COMMAND_FLAG_SDIO_INT_EN
, 0);
699 printk(KERN_INFO
"%s at %p, irq %d/%d\n", mmc_hostname(mmc
),
700 ud
->regs
, ud
->irq_tx
, ud
->irq_rx
);
704 gpio_free(pdata
->cards
[0].pin_pwr
);
706 gpio_free(pdata
->cards
[0].pin_cd
);
708 gpio_free(pdata
->cards
[0].pin_wp
);
716 static int __devexit
ubicom32sd_remove(struct platform_device
*pdev
)
718 struct mmc_host
*mmc
= platform_get_drvdata(pdev
);
720 platform_set_drvdata(pdev
, NULL
);
723 struct ubicom32sd_data
*ud
= (struct ubicom32sd_data
*)mmc_priv(mmc
);
725 gpio_free(ud
->pdata
->cards
[0].pin_pwr
);
726 gpio_free(ud
->pdata
->cards
[0].pin_cd
);
727 gpio_free(ud
->pdata
->cards
[0].pin_wp
);
729 mmc_remove_host(mmc
);
734 * Note that our data is allocated as part of the mmc structure
735 * so we don't need to free it.
740 static struct platform_driver ubicom32sd_driver
= {
743 .owner
= THIS_MODULE
,
745 .probe
= ubicom32sd_probe
,
746 .remove
= __devexit_p(ubicom32sd_remove
),
748 .suspend
= ubicom32sd_suspend
,
749 .resume
= ubicom32sd_resume
,
756 static int __init
ubicom32sd_init(void)
758 return platform_driver_register(&ubicom32sd_driver
);
760 module_init(ubicom32sd_init
);
765 static void __exit
ubicom32sd_exit(void)
767 platform_driver_unregister(&ubicom32sd_driver
);
769 module_exit(ubicom32sd_exit
);
771 MODULE_AUTHOR("Patrick Tjin");
772 MODULE_DESCRIPTION("Ubicom32 Secure Digital Host Controller Interface driver");
773 MODULE_LICENSE("GPL");