0c4c1d0af032dc85a55414c26001db39ae632312
[buildroot.git] /
1 From: Haavard Skinnemoen <hskinnemoen@atmel.com>
2 Subject: [PATCH 1/2] atmel_mci: Minor fixes and cleanups
3
4 * Use ios->clock to define when to enable the controller instead of
5 ios->power_mode.
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.
11
12 Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
13 ---
14 drivers/mmc/host/atmel-mci.c | 120 ++++++++++++++++++++++-------------------
15 1 files changed, 64 insertions(+), 56 deletions(-)
16
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,
22 dtocyc = 15;
23 }
24
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)));
32 }
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);
36
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);
43
44 *cmd_flags = cmdr;
45 return iflags;
46 @@ -589,7 +588,8 @@ static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
47
48 iflags = mci_readl(host, IMR);
49 if (iflags)
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));
53
54 WARN_ON(host->mrq != NULL);
55 host->mrq = mrq;
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)
58 {
59 struct atmel_mci *host = mmc_priv(mmc);
60 + u32 mr;
61
62 if (ios->clock) {
63 u32 clkdiv;
64
65 + /* Set clock rate */
66 clkdiv = host->bus_hz / (2 * ios->clock) - 1;
67 - if (clkdiv > 255)
68 + if (clkdiv > 255) {
69 + dev_warn(&mmc->class_dev,
70 + "clock %u too slow; using %lu\n",
71 + ios->clock, host->bus_hz / (2 * 256));
72 clkdiv = 255;
73 - mci_writel(host, MR, (clkdiv
74 - | MCI_BIT(WRPROOF)
75 - | MCI_BIT(RDPROOF)));
76 + }
77 +
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);
82 +
83 + /* Enable the MCI controller */
84 + mci_writel(host, CR, MCI_BIT(MCIEN));
85 + } else {
86 + /* Disable the MCI controller */
87 + mci_writel(host, CR, MCI_BIT(MCIDIS));
88 }
89
90 switch (ios->bus_width) {
91 @@ -645,14 +659,19 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
92 }
93
94 switch (ios->power_mode) {
95 - case MMC_POWER_OFF:
96 - mci_writel(host, CR, MCI_BIT(MCIDIS));
97 - break;
98 - case MMC_POWER_UP:
99 - mci_writel(host, CR, MCI_BIT(SWRST));
100 - break;
101 case MMC_POWER_ON:
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)))
107 + cpu_relax();
108 + break;
109 + default:
110 + /*
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.
114 + */
115 break;
116 }
117 }
118 @@ -664,11 +683,12 @@ static int atmci_get_ro(struct mmc_host *mmc)
119
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");
126 } else {
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");
132 }
133
134 return read_only;
135 @@ -719,8 +739,7 @@ static void atmci_command_error(struct mmc_host *mmc,
136 struct mmc_command *cmd,
137 u32 status)
138 {
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);
142
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;
148
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));
154
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;
158
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);
163
164 if (data->stop
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);
169
170 - printk(KERN_DEBUG "%s: data error: status=0x%08x\n",
171 - mmc_hostname(host->mmc), status);
172 -
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;
183 } else {
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;
188 }
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);
193
194 if (data->stop
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));
198
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;
214
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)
217 host->present = 1;
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;
224 } else {
225 host->present = !gpio_get_value(host->detect_pin);
226 @@ -1080,8 +1093,7 @@ static int __devinit atmci_probe(struct platform_device *pdev)
227 }
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");
233 host->wp_pin = -1;
234 }
235 }
236 @@ -1090,14 +1102,12 @@ static int __devinit atmci_probe(struct platform_device *pdev)
237 ret = -ENOMEM;
238 host->dma.req.req.dmac = find_dma_controller(0);
239 if (!host->dma.req.req.dmac) {
240 - printk(KERN_ERR
241 - "mmci: No DMA controller available, aborting\n");
242 + dev_dbg(&mmc->class_dev, "no DMA controller available\n");
243 goto out_free_irq;
244 }
245 ret = dma_alloc_channel(host->dma.req.req.dmac);
246 if (ret < 0) {
247 - printk(KERN_ERR
248 - "mmci: Unable to allocate DMA channel, aborting\n");
249 + dev_dbg(&mmc->class_dev, "unable to allocate DMA channel\n");
250 goto out_free_irq;
251 }
252 host->dma.req.req.channel = ret;
253 @@ -1110,7 +1120,6 @@ static int __devinit atmci_probe(struct platform_device *pdev)
254
255 mci_writel(host, CR, MCI_BIT(SWRST));
256 mci_writel(host, IDR, ~0UL);
257 - mci_writel(host, CR, MCI_BIT(MCIEN));
258
259 platform_set_drvdata(pdev, host);
260
261 @@ -1122,17 +1131,16 @@ static int __devinit atmci_probe(struct platform_device *pdev)
262 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
263 DRIVER_NAME, mmc);
264 if (ret) {
265 - printk(KERN_ERR
266 - "%s: could not request IRQ %d for detect pin\n",
267 - mmc_hostname(mmc),
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;
274 }
275 }
276
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);
281
282 atmci_init_debugfs(host);
283
284 --
285 1.5.3.2
286
287 _______________________________________________
288 Kernel mailing list
289 Kernel@avr32linux.org
290 http://duppen.flaskehals.net/cgi-bin/mailman/listinfo/kernel