[PATCH 06/14] mmc: bcm2835: Use local device ptr to make code more compact

Stefan Wahren stefan.wahren at i2se.com
Sat Jan 7 04:51:06 PST 2017


Using a local device ptr makes the code more compact and easier to
read.

Signed-off-by: Stefan Wahren <stefan.wahren at i2se.com>
---
 drivers/mmc/host/bcm2835.c |  135 +++++++++++++++++++-------------------------
 1 file changed, 59 insertions(+), 76 deletions(-)

diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c
index ac64b69..b8ef0b3 100644
--- a/drivers/mmc/host/bcm2835.c
+++ b/drivers/mmc/host/bcm2835.c
@@ -187,11 +187,12 @@ static void bcm2835_dumpcmd(struct bcm2835_host *host,
 			    struct mmc_command *cmd,
 			    const char *label)
 {
+	struct device *dev = &host->pdev->dev;
+
 	if (!cmd)
 		return;
 
-	dev_dbg(&host->pdev->dev,
-		"%c%s op %d arg 0x%x flags 0x%x - resp %08x %08x %08x %08x, err %d\n",
+	dev_dbg(dev, "%c%s op %d arg 0x%x flags 0x%x - resp %08x %08x %08x %08x, err %d\n",
 		(cmd == host->cmd) ? '>' : ' ',
 		label, cmd->opcode, cmd->arg, cmd->flags,
 		cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3],
@@ -200,12 +201,13 @@ static void bcm2835_dumpcmd(struct bcm2835_host *host,
 
 static void bcm2835_dumpregs(struct bcm2835_host *host)
 {
+	struct device *dev = &host->pdev->dev;
+
 	if (host->mrq) {
 		bcm2835_dumpcmd(host, host->mrq->sbc, "sbc");
 		bcm2835_dumpcmd(host, host->mrq->cmd, "cmd");
 		if (host->mrq->data) {
-			dev_dbg(&host->pdev->dev,
-				"data blocks %x blksz %x - err %d\n",
+			dev_dbg(dev, "data blocks %x blksz %x - err %d\n",
 				host->mrq->data->blocks,
 				host->mrq->data->blksz,
 				host->mrq->data->error);
@@ -213,38 +215,22 @@ static void bcm2835_dumpregs(struct bcm2835_host *host)
 		bcm2835_dumpcmd(host, host->mrq->stop, "stop");
 	}
 
-	dev_dbg(&host->pdev->dev, "=========== REGISTER DUMP ===========\n");
-
-	dev_dbg(&host->pdev->dev, "SDCMD  0x%08x\n",
-		readl(host->ioaddr + SDCMD));
-	dev_dbg(&host->pdev->dev, "SDARG  0x%08x\n",
-		readl(host->ioaddr + SDARG));
-	dev_dbg(&host->pdev->dev, "SDTOUT 0x%08x\n",
-		readl(host->ioaddr + SDTOUT));
-	dev_dbg(&host->pdev->dev, "SDCDIV 0x%08x\n",
-		readl(host->ioaddr + SDCDIV));
-	dev_dbg(&host->pdev->dev, "SDRSP0 0x%08x\n",
-		readl(host->ioaddr + SDRSP0));
-	dev_dbg(&host->pdev->dev, "SDRSP1 0x%08x\n",
-		readl(host->ioaddr + SDRSP1));
-	dev_dbg(&host->pdev->dev, "SDRSP2 0x%08x\n",
-		readl(host->ioaddr + SDRSP2));
-	dev_dbg(&host->pdev->dev, "SDRSP3 0x%08x\n",
-		readl(host->ioaddr + SDRSP3));
-	dev_dbg(&host->pdev->dev, "SDHSTS 0x%08x\n",
-		readl(host->ioaddr + SDHSTS));
-	dev_dbg(&host->pdev->dev, "SDVDD  0x%08x\n",
-		readl(host->ioaddr + SDVDD));
-	dev_dbg(&host->pdev->dev, "SDEDM  0x%08x\n",
-		readl(host->ioaddr + SDEDM));
-	dev_dbg(&host->pdev->dev, "SDHCFG 0x%08x\n",
-		readl(host->ioaddr + SDHCFG));
-	dev_dbg(&host->pdev->dev, "SDHBCT 0x%08x\n",
-		readl(host->ioaddr + SDHBCT));
-	dev_dbg(&host->pdev->dev, "SDHBLC 0x%08x\n",
-		readl(host->ioaddr + SDHBLC));
-
-	dev_dbg(&host->pdev->dev, "===========================================\n");
+	dev_dbg(dev, "=========== REGISTER DUMP ===========\n");
+	dev_dbg(dev, "SDCMD  0x%08x\n", readl(host->ioaddr + SDCMD));
+	dev_dbg(dev, "SDARG  0x%08x\n", readl(host->ioaddr + SDARG));
+	dev_dbg(dev, "SDTOUT 0x%08x\n", readl(host->ioaddr + SDTOUT));
+	dev_dbg(dev, "SDCDIV 0x%08x\n", readl(host->ioaddr + SDCDIV));
+	dev_dbg(dev, "SDRSP0 0x%08x\n", readl(host->ioaddr + SDRSP0));
+	dev_dbg(dev, "SDRSP1 0x%08x\n", readl(host->ioaddr + SDRSP1));
+	dev_dbg(dev, "SDRSP2 0x%08x\n", readl(host->ioaddr + SDRSP2));
+	dev_dbg(dev, "SDRSP3 0x%08x\n", readl(host->ioaddr + SDRSP3));
+	dev_dbg(dev, "SDHSTS 0x%08x\n", readl(host->ioaddr + SDHSTS));
+	dev_dbg(dev, "SDVDD  0x%08x\n", readl(host->ioaddr + SDVDD));
+	dev_dbg(dev, "SDEDM  0x%08x\n", readl(host->ioaddr + SDEDM));
+	dev_dbg(dev, "SDHCFG 0x%08x\n", readl(host->ioaddr + SDHCFG));
+	dev_dbg(dev, "SDHBCT 0x%08x\n", readl(host->ioaddr + SDHBCT));
+	dev_dbg(dev, "SDHBLC 0x%08x\n", readl(host->ioaddr + SDHBLC));
+	dev_dbg(dev, "===========================================\n");
 }
 
 static void bcm2835_reset_internal(struct bcm2835_host *host)
@@ -420,6 +406,7 @@ static void bcm2835_transfer_block_pio(struct bcm2835_host *host,
 
 			if (words < burst_words) {
 				int fsm_state = (edm & SDEDM_FSM_MASK);
+				struct device *dev = &host->pdev->dev;
 
 				if ((is_read &&
 				     (fsm_state != SDEDM_FSM_READDATA &&
@@ -430,16 +417,14 @@ static void bcm2835_transfer_block_pio(struct bcm2835_host *host,
 				      fsm_state != SDEDM_FSM_WRITESTART1 &&
 				      fsm_state != SDEDM_FSM_WRITESTART2))) {
 					hsts = readl(host->ioaddr + SDHSTS);
-					dev_err(&host->pdev->dev,
-						"fsm %x, hsts %x\n",
+					dev_err(dev, "fsm %x, hsts %x\n",
 						fsm_state, hsts);
 					if (hsts & SDHSTS_ERROR_MASK)
 						break;
 				}
 
 				if (time_after(jiffies, wait_max)) {
-					dev_err(&host->pdev->dev,
-						"PIO %s timeout - EDM %x\n",
+					dev_err(dev, "PIO %s timeout - EDM %x\n",
 						is_read ? "read" : "write",
 						edm);
 					hsts = SDHSTS_REW_TIME_OUT;
@@ -474,6 +459,7 @@ static void bcm2835_transfer_block_pio(struct bcm2835_host *host,
 
 static void bcm2835_transfer_pio(struct bcm2835_host *host)
 {
+	struct device *dev = &host->pdev->dev;
 	u32 sdhsts;
 	bool is_read;
 
@@ -484,13 +470,13 @@ static void bcm2835_transfer_pio(struct bcm2835_host *host)
 	if (sdhsts & (SDHSTS_CRC16_ERROR |
 		      SDHSTS_CRC7_ERROR |
 		      SDHSTS_FIFO_ERROR)) {
-		dev_err(&host->pdev->dev, "%s transfer error - HSTS %x\n",
+		dev_err(dev, "%s transfer error - HSTS %x\n",
 			is_read ? "read" : "write",
 			sdhsts);
 		host->data->error = -EILSEQ;
 	} else if ((sdhsts & (SDHSTS_CMD_TIME_OUT |
 			      SDHSTS_REW_TIME_OUT))) {
-		dev_err(&host->pdev->dev, "%s timeout error - HSTS %x\n",
+		dev_err(dev, "%s timeout error - HSTS %x\n",
 			is_read ? "read" : "write",
 			sdhsts);
 		host->data->error = -ETIMEDOUT;
@@ -626,6 +612,7 @@ static void bcm2835_prepare_data(struct bcm2835_host *host,
 bool bcm2835_send_command(struct bcm2835_host *host,
 			  struct mmc_command *cmd)
 {
+	struct device *dev = &host->pdev->dev;
 	u32 sdcmd, sdhsts;
 	unsigned long timeout;
 	int delay;
@@ -633,15 +620,13 @@ bool bcm2835_send_command(struct bcm2835_host *host,
 	WARN_ON(host->cmd);
 
 	if (cmd->data) {
-		dev_dbg(&host->pdev->dev,
-			"send_command %d 0x%x (flags 0x%x) - %s %d*%d\n",
+		dev_dbg(dev, "send_command %d 0x%x (flags 0x%x) - %s %d*%d\n",
 			cmd->opcode, cmd->arg, cmd->flags,
 			(cmd->data->flags & MMC_DATA_READ) ?
 			"read" : "write", cmd->data->blocks,
 			cmd->data->blksz);
 	} else {
-		dev_dbg(&host->pdev->dev,
-			"send_command %d 0x%x (flags 0x%x)\n",
+		dev_dbg(dev, "send_command %d 0x%x (flags 0x%x)\n",
 			cmd->opcode, cmd->arg, cmd->flags);
 	}
 
@@ -650,8 +635,7 @@ bool bcm2835_send_command(struct bcm2835_host *host,
 
 	while (readl(host->ioaddr + SDCMD) & SDCMD_NEW_FLAG) {
 		if (timeout == 0) {
-			dev_err(&host->pdev->dev,
-				"previous command never completed.\n");
+			dev_err(dev, "previous command never completed.\n");
 			bcm2835_dumpregs(host);
 			cmd->error = -EILSEQ;
 			tasklet_schedule(&host->finish_tasklet);
@@ -664,7 +648,7 @@ bool bcm2835_send_command(struct bcm2835_host *host,
 	delay = (10000 - timeout) / 100;
 	if (delay > host->max_delay) {
 		host->max_delay = delay;
-		dev_warn(&host->pdev->dev, "controller hung for %d ms\n",
+		dev_warn(dev, "controller hung for %d ms\n",
 			 host->max_delay);
 	}
 
@@ -683,7 +667,7 @@ bool bcm2835_send_command(struct bcm2835_host *host,
 		writel(sdhsts, host->ioaddr + SDHSTS);
 
 	if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
-		dev_err(&host->pdev->dev, "unsupported response type!\n");
+		dev_err(dev, "unsupported response type!\n");
 		cmd->error = -EINVAL;
 		tasklet_schedule(&host->finish_tasklet);
 		return false;
@@ -749,11 +733,12 @@ static void bcm2835_transfer_complete(struct bcm2835_host *host)
 
 static void bcm2835_finish_data(struct bcm2835_host *host)
 {
+	struct device *dev = &host->pdev->dev;
 	struct mmc_data *data;
 
 	data = host->data;
 
-	dev_dbg(&host->pdev->dev, "finish_data(error %d, stop %d, sbc %d)\n",
+	dev_dbg(dev, "finish_data(error %d, stop %d, sbc %d)\n",
 		data->error, data->stop ? 1 : 0,
 		host->mrq->sbc ? 1 : 0);
 
@@ -769,7 +754,7 @@ static void bcm2835_finish_data(struct bcm2835_host *host)
 		 * command completed. Make sure we do
 		 * things in the proper order.
 		 */
-		dev_dbg(&host->pdev->dev, "Finished early - HSTS %x\n",
+		dev_dbg(dev, "Finished early - HSTS %x\n",
 			readl(host->ioaddr + SDHSTS));
 	} else {
 		bcm2835_transfer_complete(host);
@@ -782,11 +767,11 @@ static void bcm2835_finish_data(struct bcm2835_host *host)
 static void bcm2835_finish_command(struct bcm2835_host *host,
 				   unsigned long *irq_flags)
 {
+	struct device *dev = &host->pdev->dev;
 	u32 sdcmd;
 	u32 retries;
 
-	dev_dbg(&host->pdev->dev, "finish_command(%x)\n",
-		readl(host->ioaddr + SDCMD));
+	dev_dbg(dev, "finish_command(%x)\n", readl(host->ioaddr + SDCMD));
 
 	/* Poll quickly at first */
 
@@ -851,7 +836,7 @@ static void bcm2835_finish_command(struct bcm2835_host *host,
 
 	/* Check for errors */
 	if (sdcmd & SDCMD_NEW_FLAG) {
-		dev_err(&host->pdev->dev, "command never completed.\n");
+		dev_err(dev, "command never completed.\n");
 		bcm2835_dumpregs(host);
 		host->cmd->error = -EIO;
 		tasklet_schedule(&host->finish_tasklet);
@@ -867,8 +852,7 @@ static void bcm2835_finish_command(struct bcm2835_host *host,
 			if (sdhsts & SDHSTS_CMD_TIME_OUT) {
 				host->cmd->error = -ETIMEDOUT;
 			} else {
-				dev_err(&host->pdev->dev,
-					"unexpected command %d error\n",
+				dev_err(dev, "unexpected command %d error\n",
 					host->cmd->opcode);
 				bcm2835_dumpregs(host);
 				host->cmd->error = -EILSEQ;
@@ -887,13 +871,12 @@ static void bcm2835_finish_command(struct bcm2835_host *host,
 					readl(host->ioaddr + SDRSP0 + i * 4);
 			}
 
-			dev_dbg(&host->pdev->dev,
-				"finish_command %08x %08x %08x %08x\n",
+			dev_dbg(dev, "finish_command %08x %08x %08x %08x\n",
 				host->cmd->resp[0], host->cmd->resp[1],
 				host->cmd->resp[2], host->cmd->resp[3]);
 		} else {
 			host->cmd->resp[0] = readl(host->ioaddr + SDRSP0);
-			dev_dbg(&host->pdev->dev, "finish_command %08x\n",
+			dev_dbg(dev, "finish_command %08x\n",
 				host->cmd->resp[0]);
 		}
 	}
@@ -927,13 +910,13 @@ static void bcm2835_finish_command(struct bcm2835_host *host,
 static void bcm2835_timeout(unsigned long data)
 {
 	struct bcm2835_host *host = (struct bcm2835_host *)data;
+	struct device *dev = &host->pdev->dev;
 	unsigned long flags;
 
 	spin_lock_irqsave(&host->lock, flags);
 
 	if (host->mrq) {
-		dev_err(&host->pdev->dev,
-			"timeout waiting for hardware interrupt.\n");
+		dev_err(dev, "timeout waiting for hardware interrupt.\n");
 		bcm2835_dumpregs(host);
 
 		if (host->data) {
@@ -945,7 +928,7 @@ static void bcm2835_timeout(unsigned long data)
 			else
 				host->mrq->cmd->error = -ETIMEDOUT;
 
-			dev_dbg(&host->pdev->dev, "timeout_timer tasklet_schedule\n");
+			dev_dbg(dev, "timeout_timer tasklet_schedule\n");
 			tasklet_schedule(&host->finish_tasklet);
 		}
 	}
@@ -954,17 +937,17 @@ static void bcm2835_timeout(unsigned long data)
 
 static void bcm2835_busy_irq(struct bcm2835_host *host, u32 intmask)
 {
+	struct device *dev = &host->pdev->dev;
+
 	if (!host->cmd) {
-		dev_err(&host->pdev->dev,
-			"got command busy interrupt 0x%08x even though no command operation was in progress.\n",
+		dev_err(dev, "got command busy interrupt 0x%08x even though no command operation was in progress.\n",
 			(unsigned int)intmask);
 		bcm2835_dumpregs(host);
 		return;
 	}
 
 	if (!host->use_busy) {
-		dev_err(&host->pdev->dev,
-			"got command busy interrupt 0x%08x even though not expecting one.\n",
+		dev_err(dev, "got command busy interrupt 0x%08x even though not expecting one.\n",
 			(unsigned int)intmask);
 		bcm2835_dumpregs(host);
 		return;
@@ -972,7 +955,7 @@ static void bcm2835_busy_irq(struct bcm2835_host *host, u32 intmask)
 	host->use_busy = false;
 
 	if (intmask & SDHSTS_ERROR_MASK) {
-		dev_err(&host->pdev->dev, "sdhost_busy_irq: intmask %x, data %p\n",
+		dev_err(dev, "sdhost_busy_irq: intmask %x, data %p\n",
 			intmask, host->mrq->data);
 		if (intmask & SDHSTS_CRC7_ERROR) {
 			host->cmd->error = -EILSEQ;
@@ -1171,6 +1154,7 @@ static void bcm2835_request(struct mmc_host *mmc,
 			    struct mmc_request *mrq)
 {
 	struct bcm2835_host *host = mmc_priv(mmc);
+	struct device *dev = &host->pdev->dev;
 	unsigned long flags;
 	u32 edm, fsm;
 
@@ -1185,7 +1169,7 @@ static void bcm2835_request(struct mmc_host *mmc,
 		mrq->stop->error = 0;
 
 	if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
-		dev_err(&host->pdev->dev, "unsupported block size (%d bytes)\n",
+		dev_err(dev, "unsupported block size (%d bytes)\n",
 			mrq->data->blksz);
 		mrq->cmd->error = -EINVAL;
 		mmc_request_done(mmc, mrq);
@@ -1206,8 +1190,7 @@ static void bcm2835_request(struct mmc_host *mmc,
 
 	if ((fsm != SDEDM_FSM_IDENTMODE) &&
 	    (fsm != SDEDM_FSM_DATAMODE)) {
-		dev_err(&host->pdev->dev,
-			"previous command (%d) not complete (EDM %x)\n",
+		dev_err(dev, "previous command (%d) not complete (EDM %x)\n",
 			readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK,
 			edm);
 		bcm2835_dumpregs(host);
@@ -1336,6 +1319,7 @@ static void bcm2835_tasklet_finish(unsigned long param)
 int bcm2835_add_host(struct bcm2835_host *host)
 {
 	struct mmc_host *mmc = host->mmc;
+	struct device *dev = &host->pdev->dev;
 	struct dma_slave_config cfg;
 	char pio_limit_string[20];
 	int ret;
@@ -1347,7 +1331,7 @@ int bcm2835_add_host(struct bcm2835_host *host)
 
 	mmc->max_busy_timeout = ~0 / (mmc->f_max / 1000);
 
-	dev_dbg(&host->pdev->dev, "f_max %d, f_min %d, max_busy_timeout %d\n",
+	dev_dbg(dev, "f_max %d, f_min %d, max_busy_timeout %d\n",
 		mmc->f_max, mmc->f_min, mmc->max_busy_timeout);
 
 	/* host controller capabilities */
@@ -1360,8 +1344,7 @@ int bcm2835_add_host(struct bcm2835_host *host)
 
 	if (IS_ERR_OR_NULL(host->dma_chan_tx) ||
 	    IS_ERR_OR_NULL(host->dma_chan_rx)) {
-		dev_err(&host->pdev->dev,
-			"unable to initialise DMA channels. Falling back to PIO\n");
+		dev_err(dev, "unable to initialise DMA channels. Falling back to PIO\n");
 		host->use_dma = false;
 	} else {
 		host->use_dma = true;
@@ -1410,7 +1393,7 @@ int bcm2835_add_host(struct bcm2835_host *host)
 	ret = request_irq(host->irq, bcm2835_irq, 0 /*IRQF_SHARED*/,
 			  mmc_hostname(mmc), host);
 	if (ret) {
-		dev_err(&host->pdev->dev, "failed to request IRQ %d: %d\n",
+		dev_err(dev, "failed to request IRQ %d: %d\n",
 			host->irq, ret);
 		goto untasklet;
 	}
@@ -1420,7 +1403,7 @@ int bcm2835_add_host(struct bcm2835_host *host)
 	pio_limit_string[0] = '\0';
 	if (host->use_dma && (host->pio_limit > 0))
 		sprintf(pio_limit_string, " (>%d)", host->pio_limit);
-	dev_info(&host->pdev->dev, "loaded - DMA %s%s\n",
+	dev_info(dev, "loaded - DMA %s%s\n",
 		 host->use_dma ? "enabled" : "disabled",
 		 pio_limit_string);
 
-- 
1.7.9.5




More information about the linux-rpi-kernel mailing list