1 From: Haavard Skinnemoen <hskinnemoen@atmel.com>
2 Subject: [PATCH 1/2] atmel_mci: Minor fixes and cleanups
4 * Use ios->clock to define when to enable the controller instead of
6 * Send initialization command (74 idle clock cycles) when power_mode
7 is set to MMC_POWER_ON.
8 * Use dev_dbg() and friends instead of pr_debug() and printk().
9 * Don't print data- or probe errors when debugging is not enabled.
10 * Adjust ocr_avail range to 3.2V-3.4V using proper constants.
12 Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
14 drivers/mmc/host/atmel-mci.c | 120 ++++++++++++++++++++++-------------------
15 1 files changed, 64 insertions(+), 56 deletions(-)
17 diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
18 index 74d343f..1dc91b4 100644
19 --- a/drivers/mmc/host/atmel-mci.c
20 +++ b/drivers/mmc/host/atmel-mci.c
21 @@ -464,9 +464,8 @@ static void atmci_set_timeout(struct atmel_mci *host,
25 - pr_debug("%s: setting timeout to %u cycles\n",
26 - mmc_hostname(host->mmc),
27 - dtocyc << dtomul_to_shift[dtomul]);
28 + dev_dbg(&host->mmc->class_dev, "setting timeout to %u cycles\n",
29 + dtocyc << dtomul_to_shift[dtomul]);
30 mci_writel(host, DTOR, (MCI_BF(DTOMUL, dtomul)
31 | MCI_BF(DTOCYC, dtocyc)));
33 @@ -508,9 +507,9 @@ static u32 atmci_prepare_command(struct mmc_host *mmc,
34 if (!(cmd->flags & MMC_RSP_CRC))
35 iflags &= ~MCI_BIT(RCRCE);
37 - pr_debug("%s: cmd: op %02x arg %08x flags %08x, cmdflags %08lx\n",
38 - mmc_hostname(mmc), cmd->opcode, cmd->arg, cmd->flags,
39 - (unsigned long)cmdr);
40 + dev_dbg(&mmc->class_dev,
41 + "cmd: op %02x arg %08x flags %08x, cmdflags %08lx\n",
42 + cmd->opcode, cmd->arg, cmd->flags, (unsigned long)cmdr);
46 @@ -589,7 +588,8 @@ static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
48 iflags = mci_readl(host, IMR);
50 - printk("WARNING: IMR=0x%08x\n", mci_readl(host, IMR));
51 + dev_warn(&mmc->class_dev, "WARNING: IMR=0x%08x\n",
52 + mci_readl(host, IMR));
54 WARN_ON(host->mrq != NULL);
56 @@ -623,16 +623,30 @@ static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
57 static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
59 struct atmel_mci *host = mmc_priv(mmc);
65 + /* Set clock rate */
66 clkdiv = host->bus_hz / (2 * ios->clock) - 1;
69 + dev_warn(&mmc->class_dev,
70 + "clock %u too slow; using %lu\n",
71 + ios->clock, host->bus_hz / (2 * 256));
73 - mci_writel(host, MR, (clkdiv
75 - | MCI_BIT(RDPROOF)));
78 + mr = mci_readl(host, MR);
79 + mr = MCI_BFINS(CLKDIV, clkdiv, mr)
80 + | MCI_BIT(WRPROOF) | MCI_BIT(RDPROOF);
81 + mci_writel(host, MR, mr);
83 + /* Enable the MCI controller */
84 + mci_writel(host, CR, MCI_BIT(MCIEN));
86 + /* Disable the MCI controller */
87 + mci_writel(host, CR, MCI_BIT(MCIDIS));
90 switch (ios->bus_width) {
91 @@ -645,14 +659,19 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
94 switch (ios->power_mode) {
96 - mci_writel(host, CR, MCI_BIT(MCIDIS));
99 - mci_writel(host, CR, MCI_BIT(SWRST));
102 - mci_writel(host, CR, MCI_BIT(MCIEN));
103 + /* Send init sequence (74 clock cycles) */
104 + mci_writel(host, IDR, ~0UL);
105 + mci_writel(host, CMDR, MCI_BF(SPCMD, MCI_SPCMD_INIT_CMD));
106 + while (!(mci_readl(host, SR) & MCI_BIT(CMDRDY)))
111 + * TODO: None of the currently available AVR32-based
112 + * boards allow MMC power to be turned off. Implement
113 + * power control when this can be tested properly.
118 @@ -664,11 +683,12 @@ static int atmci_get_ro(struct mmc_host *mmc)
120 if (host->wp_pin >= 0) {
121 read_only = gpio_get_value(host->wp_pin);
122 - pr_debug("%s: card is %s\n", mmc_hostname(mmc),
123 - read_only ? "read-only" : "read-write");
124 + dev_dbg(&mmc->class_dev, "card is %s\n",
125 + read_only ? "read-only" : "read-write");
127 - pr_debug("%s: no pin for checking read-only switch."
128 - " Assuming write-enable.\n", mmc_hostname(mmc));
129 + dev_dbg(&mmc->class_dev,
130 + "no pin for checking read-only switch."
131 + " Assuming write-enable.\n");
135 @@ -719,8 +739,7 @@ static void atmci_command_error(struct mmc_host *mmc,
136 struct mmc_command *cmd,
139 - pr_debug("%s: command error: status=0x%08x\n",
140 - mmc_hostname(mmc), status);
141 + dev_dbg(&mmc->class_dev, "command error: status=0x%08x\n", status);
143 if (status & MCI_BIT(RTOE))
144 cmd->error = MMC_ERR_TIMEOUT;
145 @@ -737,7 +756,8 @@ static void atmci_tasklet_func(unsigned long priv)
146 struct mmc_request *mrq = host->mrq;
147 struct mmc_data *data = host->data;
149 - pr_debug("atmci_tasklet: pending/completed/mask %lx/%lx/%x\n",
150 + dev_dbg(&mmc->class_dev,
151 + "tasklet: pending/completed/mask %lx/%lx/%x\n",
152 host->pending_events, host->completed_events,
153 mci_readl(host, IMR));
155 @@ -784,8 +804,8 @@ static void atmci_tasklet_func(unsigned long priv)
156 /* DMA controller got bus error => invalid address */
157 data->error = MMC_ERR_INVALID;
159 - printk(KERN_DEBUG "%s: dma error after %u bytes xfered\n",
160 - mmc_hostname(mmc), host->data->bytes_xfered);
161 + dev_dbg(&mmc->class_dev, "dma error after %u bytes xfered\n",
162 + host->data->bytes_xfered);
165 && !mci_set_stop_sent_is_completed(host))
166 @@ -803,24 +823,18 @@ static void atmci_tasklet_func(unsigned long priv)
167 dma_stop_request(host->dma.req.req.dmac,
168 host->dma.req.req.channel);
170 - printk(KERN_DEBUG "%s: data error: status=0x%08x\n",
171 - mmc_hostname(host->mmc), status);
173 if (status & MCI_BIT(DCRCE)) {
174 - printk(KERN_DEBUG "%s: Data CRC error\n",
175 - mmc_hostname(host->mmc));
176 + dev_dbg(&mmc->class_dev, "data CRC error\n");
177 data->error = MMC_ERR_BADCRC;
178 } else if (status & MCI_BIT(DTOE)) {
179 - printk(KERN_DEBUG "%s: Data Timeout error\n",
180 - mmc_hostname(host->mmc));
181 + dev_dbg(&mmc->class_dev, "data timeout error\n");
182 data->error = MMC_ERR_TIMEOUT;
184 - printk(KERN_DEBUG "%s: Data FIFO error\n",
185 - mmc_hostname(host->mmc));
186 + dev_dbg(&mmc->class_dev, "data FIFO error\n");
187 data->error = MMC_ERR_FIFO;
189 - printk(KERN_DEBUG "%s: Bytes xfered: %u\n",
190 - mmc_hostname(host->mmc), data->bytes_xfered);
191 + dev_dbg(&mmc->class_dev, "bytes xfered: %u\n",
192 + data->bytes_xfered);
195 && !mci_set_stop_sent_is_completed(host))
196 @@ -998,8 +1012,8 @@ static irqreturn_t atmci_detect_change(int irq, void *dev_id)
197 int present = !gpio_get_value(irq_to_gpio(irq));
199 if (present != host->present) {
200 - pr_debug("%s: card %s\n", mmc_hostname(host->mmc),
201 - present ? "inserted" : "removed");
202 + dev_dbg(&mmc->class_dev, "card %s\n",
203 + present ? "inserted" : "removed");
204 host->present = present;
205 mci_set_card_detect_pending(host);
206 tasklet_schedule(&host->tasklet);
207 @@ -1058,7 +1072,7 @@ static int __devinit atmci_probe(struct platform_device *pdev)
208 mmc->ops = &atmci_ops;
209 mmc->f_min = (host->bus_hz + 511) / 512;
210 mmc->f_max = min((unsigned int)(host->bus_hz / 2), fmax);
211 - mmc->ocr_avail = 0x00100000;
212 + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
213 mmc->caps |= MMC_CAP_4_BIT_DATA;
215 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
216 @@ -1071,8 +1085,7 @@ static int __devinit atmci_probe(struct platform_device *pdev)
218 if (host->detect_pin >= 0) {
219 if (gpio_request(host->detect_pin, "mmc_detect")) {
220 - printk(KERN_WARNING "%s: no detect pin available\n",
221 - mmc_hostname(host->mmc));
222 + dev_dbg(&mmc->class_dev, "no detect pin available\n");
223 host->detect_pin = -1;
225 host->present = !gpio_get_value(host->detect_pin);
226 @@ -1080,8 +1093,7 @@ static int __devinit atmci_probe(struct platform_device *pdev)
228 if (host->wp_pin >= 0) {
229 if (gpio_request(host->wp_pin, "mmc_wp")) {
230 - printk(KERN_WARNING "%s: no WP pin available\n",
231 - mmc_hostname(host->mmc));
232 + dev_dbg(&mmc->class_dev, "no WP pin available\n");
236 @@ -1090,14 +1102,12 @@ static int __devinit atmci_probe(struct platform_device *pdev)
238 host->dma.req.req.dmac = find_dma_controller(0);
239 if (!host->dma.req.req.dmac) {
241 - "mmci: No DMA controller available, aborting\n");
242 + dev_dbg(&mmc->class_dev, "no DMA controller available\n");
245 ret = dma_alloc_channel(host->dma.req.req.dmac);
248 - "mmci: Unable to allocate DMA channel, aborting\n");
249 + dev_dbg(&mmc->class_dev, "unable to allocate DMA channel\n");
252 host->dma.req.req.channel = ret;
253 @@ -1110,7 +1120,6 @@ static int __devinit atmci_probe(struct platform_device *pdev)
255 mci_writel(host, CR, MCI_BIT(SWRST));
256 mci_writel(host, IDR, ~0UL);
257 - mci_writel(host, CR, MCI_BIT(MCIEN));
259 platform_set_drvdata(pdev, host);
261 @@ -1122,17 +1131,16 @@ static int __devinit atmci_probe(struct platform_device *pdev)
262 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
266 - "%s: could not request IRQ %d for detect pin\n",
268 - gpio_to_irq(host->detect_pin));
269 + dev_dbg(&mmc->class_dev,
270 + "could not request IRQ %d for detect pin\n",
271 + gpio_to_irq(host->detect_pin));
272 gpio_free(host->detect_pin);
273 host->detect_pin = -1;
277 - printk(KERN_INFO "%s: Atmel MCI controller at 0x%08lx irq %d\n",
278 - mmc_hostname(mmc), host->mapbase, irq);
279 + dev_info(&mmc->class_dev, "Atmel MCI controller at 0x%08lx irq %d\n",
280 + host->mapbase, irq);
282 atmci_init_debugfs(host);
287 _______________________________________________
289 Kernel@avr32linux.org
290 http://duppen.flaskehals.net/cgi-bin/mailman/listinfo/kernel