5353#define CTL_SD_ERROR_DETAIL_STATUS 0x2c
5454#define CTL_SD_DATA_PORT 0x30
5555#define CTL_TRANSACTION_CTL 0x34
56+ #define CTL_SDIO_STATUS 0x36
57+ #define CTL_SDIO_IRQ_MASK 0x38
5658#define CTL_RESET_SD 0xe0
5759#define CTL_SDIO_REGS 0x100
5860#define CTL_CLK_AND_WAIT_CTL 0x138
8183#define TMIO_STAT_CMD_BUSY 0x40000000
8284#define TMIO_STAT_ILL_ACCESS 0x80000000
8385
86+ /* Definitions for values the CTRL_SDIO_STATUS register can take. */
87+ #define TMIO_SDIO_STAT_IOIRQ 0x0001
88+ #define TMIO_SDIO_STAT_EXPUB52 0x4000
89+ #define TMIO_SDIO_STAT_EXWT 0x8000
90+ #define TMIO_SDIO_MASK_ALL 0xc007
91+
8492/* Define some IRQ masks */
8593/* This is the mask used at reset by the chip */
8694#define TMIO_MASK_ALL 0x837f031d
@@ -122,6 +130,7 @@ struct tmio_mmc_host {
122130 struct mmc_data * data ;
123131 struct mmc_host * mmc ;
124132 int irq ;
133+ unsigned int sdio_irq_enabled ;
125134
126135 /* Callbacks for clock / power control */
127136 void (* set_pwr )(struct platform_device * host , int state );
@@ -249,6 +258,22 @@ void pr_debug_status(u32 status)
249258#define pr_debug_status (s ) do { } while (0)
250259#endif
251260
261+ static void tmio_mmc_enable_sdio_irq (struct mmc_host * mmc , int enable )
262+ {
263+ struct tmio_mmc_host * host = mmc_priv (mmc );
264+
265+ if (enable ) {
266+ host -> sdio_irq_enabled = 1 ;
267+ sd_ctrl_write16 (host , CTL_TRANSACTION_CTL , 0x0001 );
268+ sd_ctrl_write16 (host , CTL_SDIO_IRQ_MASK ,
269+ (TMIO_SDIO_MASK_ALL & ~TMIO_SDIO_STAT_IOIRQ ));
270+ } else {
271+ sd_ctrl_write16 (host , CTL_SDIO_IRQ_MASK , TMIO_SDIO_MASK_ALL );
272+ sd_ctrl_write16 (host , CTL_TRANSACTION_CTL , 0x0000 );
273+ host -> sdio_irq_enabled = 0 ;
274+ }
275+ }
276+
252277static void tmio_mmc_set_clock (struct tmio_mmc_host * host , int new_clock )
253278{
254279 u32 clk = 0 , clock ;
@@ -268,20 +293,45 @@ static void tmio_mmc_set_clock(struct tmio_mmc_host *host, int new_clock)
268293
269294static void tmio_mmc_clk_stop (struct tmio_mmc_host * host )
270295{
296+ struct mfd_cell * cell = host -> pdev -> dev .platform_data ;
297+ struct tmio_mmc_data * pdata = cell -> driver_data ;
298+
299+ /*
300+ * Testing on sh-mobile showed that SDIO IRQs are unmasked when
301+ * CTL_CLK_AND_WAIT_CTL gets written, so we have to disable the
302+ * device IRQ here and restore the SDIO IRQ mask before
303+ * re-enabling the device IRQ.
304+ */
305+ if (pdata -> flags & TMIO_MMC_SDIO_IRQ )
306+ disable_irq (host -> irq );
271307 sd_ctrl_write16 (host , CTL_CLK_AND_WAIT_CTL , 0x0000 );
272308 msleep (10 );
309+ if (pdata -> flags & TMIO_MMC_SDIO_IRQ ) {
310+ tmio_mmc_enable_sdio_irq (host -> mmc , host -> sdio_irq_enabled );
311+ enable_irq (host -> irq );
312+ }
273313 sd_ctrl_write16 (host , CTL_SD_CARD_CLK_CTL , ~0x0100 &
274314 sd_ctrl_read16 (host , CTL_SD_CARD_CLK_CTL ));
275315 msleep (10 );
276316}
277317
278318static void tmio_mmc_clk_start (struct tmio_mmc_host * host )
279319{
320+ struct mfd_cell * cell = host -> pdev -> dev .platform_data ;
321+ struct tmio_mmc_data * pdata = cell -> driver_data ;
322+
280323 sd_ctrl_write16 (host , CTL_SD_CARD_CLK_CTL , 0x0100 |
281324 sd_ctrl_read16 (host , CTL_SD_CARD_CLK_CTL ));
282325 msleep (10 );
326+ /* see comment in tmio_mmc_clk_stop above */
327+ if (pdata -> flags & TMIO_MMC_SDIO_IRQ )
328+ disable_irq (host -> irq );
283329 sd_ctrl_write16 (host , CTL_CLK_AND_WAIT_CTL , 0x0100 );
284330 msleep (10 );
331+ if (pdata -> flags & TMIO_MMC_SDIO_IRQ ) {
332+ tmio_mmc_enable_sdio_irq (host -> mmc , host -> sdio_irq_enabled );
333+ enable_irq (host -> irq );
334+ }
285335}
286336
287337static void reset (struct tmio_mmc_host * host )
@@ -554,14 +604,40 @@ static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
554604static irqreturn_t tmio_mmc_irq (int irq , void * devid )
555605{
556606 struct tmio_mmc_host * host = devid ;
607+ struct mfd_cell * cell = host -> pdev -> dev .platform_data ;
608+ struct tmio_mmc_data * pdata = cell -> driver_data ;
557609 unsigned int ireg , irq_mask , status ;
610+ unsigned int sdio_ireg , sdio_irq_mask , sdio_status ;
558611
559612 pr_debug ("MMC IRQ begin\n" );
560613
561614 status = sd_ctrl_read32 (host , CTL_STATUS );
562615 irq_mask = sd_ctrl_read32 (host , CTL_IRQ_MASK );
563616 ireg = status & TMIO_MASK_IRQ & ~irq_mask ;
564617
618+ sdio_ireg = 0 ;
619+ if (!ireg && pdata -> flags & TMIO_MMC_SDIO_IRQ ) {
620+ sdio_status = sd_ctrl_read16 (host , CTL_SDIO_STATUS );
621+ sdio_irq_mask = sd_ctrl_read16 (host , CTL_SDIO_IRQ_MASK );
622+ sdio_ireg = sdio_status & TMIO_SDIO_MASK_ALL & ~sdio_irq_mask ;
623+
624+ sd_ctrl_write16 (host , CTL_SDIO_STATUS , sdio_status & ~TMIO_SDIO_MASK_ALL );
625+
626+ if (sdio_ireg && !host -> sdio_irq_enabled ) {
627+ pr_warning ("tmio_mmc: Spurious SDIO IRQ, disabling! 0x%04x 0x%04x 0x%04x\n" ,
628+ sdio_status , sdio_irq_mask , sdio_ireg );
629+ tmio_mmc_enable_sdio_irq (host -> mmc , 0 );
630+ goto out ;
631+ }
632+
633+ if (host -> mmc -> caps & MMC_CAP_SDIO_IRQ &&
634+ sdio_ireg & TMIO_SDIO_STAT_IOIRQ )
635+ mmc_signal_sdio_irq (host -> mmc );
636+
637+ if (sdio_ireg )
638+ goto out ;
639+ }
640+
565641 pr_debug_status (status );
566642 pr_debug_status (ireg );
567643
@@ -1047,6 +1123,7 @@ static const struct mmc_host_ops tmio_mmc_ops = {
10471123 .set_ios = tmio_mmc_set_ios ,
10481124 .get_ro = tmio_mmc_get_ro ,
10491125 .get_cd = tmio_mmc_get_cd ,
1126+ .enable_sdio_irq = tmio_mmc_enable_sdio_irq ,
10501127};
10511128
10521129#ifdef CONFIG_PM
@@ -1162,6 +1239,8 @@ static int __devinit tmio_mmc_probe(struct platform_device *dev)
11621239 goto cell_disable ;
11631240
11641241 disable_mmc_irqs (host , TMIO_MASK_ALL );
1242+ if (pdata -> flags & TMIO_MMC_SDIO_IRQ )
1243+ tmio_mmc_enable_sdio_irq (mmc , 0 );
11651244
11661245 ret = request_irq (host -> irq , tmio_mmc_irq , IRQF_DISABLED |
11671246 IRQF_TRIGGER_FALLING , dev_name (& dev -> dev ), host );
0 commit comments