Skip to content

Commit b537f94

Browse files
Russell Kingcjb
authored andcommitted
mmc: sdhci: more efficient interrupt enable register handling
Rather than wasting cycles read-modify-writing the interrupt enable registers, cache the value locally instead. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Tested-by: Markus Pargmann <mpa@pengutronix.de> Tested-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Chris Ball <chris@printf.net>
1 parent be13855 commit b537f94

2 files changed

Lines changed: 50 additions & 51 deletions

File tree

‎drivers/mmc/host/sdhci.c‎

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,6 @@ static void sdhci_dumpregs(struct sdhci_host *host)
131131
* *
132132
\*****************************************************************************/
133133

134-
static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
135-
{
136-
u32 ier;
137-
138-
ier = sdhci_readl(host, SDHCI_INT_ENABLE);
139-
ier &= ~clear;
140-
ier |= set;
141-
sdhci_writel(host, ier, SDHCI_INT_ENABLE);
142-
sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
143-
}
144-
145-
static void sdhci_unmask_irqs(struct sdhci_host *host, u32 irqs)
146-
{
147-
sdhci_clear_set_irqs(host, 0, irqs);
148-
}
149-
150-
static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs)
151-
{
152-
sdhci_clear_set_irqs(host, irqs, 0);
153-
}
154-
155134
static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
156135
{
157136
u32 present, irqs;
@@ -165,9 +144,12 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
165144
irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;
166145

167146
if (enable)
168-
sdhci_unmask_irqs(host, irqs);
147+
host->ier |= irqs;
169148
else
170-
sdhci_mask_irqs(host, irqs);
149+
host->ier &= ~irqs;
150+
151+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
152+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
171153
}
172154

173155
static void sdhci_enable_card_detection(struct sdhci_host *host)
@@ -183,17 +165,12 @@ static void sdhci_disable_card_detection(struct sdhci_host *host)
183165
static void sdhci_reset(struct sdhci_host *host, u8 mask)
184166
{
185167
unsigned long timeout;
186-
u32 uninitialized_var(ier);
187-
188168
if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
189169
if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
190170
SDHCI_CARD_PRESENT))
191171
return;
192172
}
193173

194-
if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET)
195-
ier = sdhci_readl(host, SDHCI_INT_ENABLE);
196-
197174
if (host->ops->platform_reset_enter)
198175
host->ops->platform_reset_enter(host, mask);
199176

@@ -224,8 +201,10 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
224201
if (host->ops->platform_reset_exit)
225202
host->ops->platform_reset_exit(host, mask);
226203

227-
if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET)
228-
sdhci_clear_set_irqs(host, SDHCI_INT_ALL_MASK, ier);
204+
if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET) {
205+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
206+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
207+
}
229208

230209
if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
231210
if ((host->ops->enable_dma) && (mask & SDHCI_RESET_ALL))
@@ -242,11 +221,14 @@ static void sdhci_init(struct sdhci_host *host, int soft)
242221
else
243222
sdhci_reset(host, SDHCI_RESET_ALL);
244223

245-
sdhci_clear_set_irqs(host, SDHCI_INT_ALL_MASK,
246-
SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
247-
SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX |
248-
SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
249-
SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE);
224+
host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
225+
SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
226+
SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC |
227+
SDHCI_INT_TIMEOUT | SDHCI_INT_DATA_END |
228+
SDHCI_INT_RESPONSE;
229+
230+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
231+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
250232

251233
if (soft) {
252234
/* force clock reconfiguration */
@@ -721,9 +703,12 @@ static void sdhci_set_transfer_irqs(struct sdhci_host *host)
721703
u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
722704

723705
if (host->flags & SDHCI_REQ_USE_DMA)
724-
sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
706+
host->ier = (host->ier & ~pio_irqs) | dma_irqs;
725707
else
726-
sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
708+
host->ier = (host->ier & ~dma_irqs) | pio_irqs;
709+
710+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
711+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
727712
}
728713

729714
static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
@@ -1713,9 +1698,12 @@ static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable)
17131698
{
17141699
if (!(host->flags & SDHCI_DEVICE_DEAD)) {
17151700
if (enable)
1716-
sdhci_unmask_irqs(host, SDHCI_INT_CARD_INT);
1701+
host->ier |= SDHCI_INT_CARD_INT;
17171702
else
1718-
sdhci_mask_irqs(host, SDHCI_INT_CARD_INT);
1703+
host->ier &= ~SDHCI_INT_CARD_INT;
1704+
1705+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
1706+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
17191707
mmiowb();
17201708
}
17211709
}
@@ -1857,7 +1845,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
18571845
{
18581846
struct sdhci_host *host;
18591847
u16 ctrl;
1860-
u32 ier;
18611848
int tuning_loop_counter = MAX_TUNING_LOOP;
18621849
unsigned long timeout;
18631850
int err = 0;
@@ -1911,8 +1898,8 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
19111898
* to make sure we don't hit a controller bug, we _only_
19121899
* enable Buffer Read Ready interrupt here.
19131900
*/
1914-
ier = sdhci_readl(host, SDHCI_INT_ENABLE);
1915-
sdhci_clear_set_irqs(host, ier, SDHCI_INT_DATA_AVAIL);
1901+
sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE);
1902+
sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE);
19161903

19171904
/*
19181905
* Issue CMD19 repeatedly till Execute Tuning is set to 0 or the number
@@ -2047,7 +2034,8 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
20472034
if (err && (host->flags & SDHCI_USING_RETUNING_TIMER))
20482035
err = 0;
20492036

2050-
sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
2037+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
2038+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
20512039
spin_unlock_irqrestore(&host->lock, flags);
20522040
sdhci_runtime_pm_put(host);
20532041

@@ -2460,10 +2448,12 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
24602448
* More testing are needed here to ensure it works
24612449
* for other platforms though.
24622450
*/
2463-
sdhci_mask_irqs(host, present ? SDHCI_INT_CARD_INSERT :
2464-
SDHCI_INT_CARD_REMOVE);
2465-
sdhci_unmask_irqs(host, present ? SDHCI_INT_CARD_REMOVE :
2466-
SDHCI_INT_CARD_INSERT);
2451+
host->ier &= ~(SDHCI_INT_CARD_INSERT |
2452+
SDHCI_INT_CARD_REMOVE);
2453+
host->ier |= present ? SDHCI_INT_CARD_REMOVE :
2454+
SDHCI_INT_CARD_INSERT;
2455+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
2456+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
24672457

24682458
sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT |
24692459
SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
@@ -2592,7 +2582,9 @@ int sdhci_suspend_host(struct sdhci_host *host)
25922582
}
25932583

25942584
if (!device_may_wakeup(mmc_dev(host->mmc))) {
2595-
sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
2585+
host->ier = 0;
2586+
sdhci_writel(host, 0, SDHCI_INT_ENABLE);
2587+
sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
25962588
free_irq(host->irq, host);
25972589
} else {
25982590
sdhci_enable_irq_wakeups(host);
@@ -2691,7 +2683,9 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host)
26912683
}
26922684

26932685
spin_lock_irqsave(&host->lock, flags);
2694-
sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK & ~SDHCI_INT_CARD_INT);
2686+
host->ier &= SDHCI_INT_CARD_INT;
2687+
sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
2688+
sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
26952689
spin_unlock_irqrestore(&host->lock, flags);
26962690

26972691
synchronize_hardirq(host->irq);
@@ -3282,7 +3276,8 @@ int sdhci_add_host(struct sdhci_host *host)
32823276
#ifdef SDHCI_USE_LEDS_CLASS
32833277
reset:
32843278
sdhci_reset(host, SDHCI_RESET_ALL);
3285-
sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
3279+
sdhci_writel(host, 0, SDHCI_INT_ENABLE);
3280+
sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
32863281
free_irq(host->irq, host);
32873282
#endif
32883283
untasklet:
@@ -3324,7 +3319,8 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
33243319
if (!dead)
33253320
sdhci_reset(host, SDHCI_RESET_ALL);
33263321

3327-
sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
3322+
sdhci_writel(host, 0, SDHCI_INT_ENABLE);
3323+
sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
33283324
free_irq(host->irq, host);
33293325

33303326
del_timer_sync(&host->timer);

‎include/linux/mmc/sdhci.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ struct sdhci_host {
178178

179179
u32 thread_isr;
180180

181+
/* cached registers */
182+
u32 ier;
183+
181184
wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
182185
unsigned int tuning_done; /* Condition flag set when CMD19 succeeds */
183186

0 commit comments

Comments
 (0)