2 * omap_cf.c -- OMAP 16xx CompactFlash controller driver
4 * Copyright (c) 2005 David Brownell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/platform_device.h>
15 #include <linux/errno.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <linux/interrupt.h>
20 #include <pcmcia/ss.h>
22 #include <asm/hardware.h>
24 #include <asm/sizes.h>
26 #include <asm/arch/mux.h>
27 #include <asm/arch/tc.h>
30 /* NOTE: don't expect this to support many I/O cards. The 16xx chips have
31 * hard-wired timings to support Compact Flash memory cards; they won't work
32 * with various other devices (like WLAN adapters) without some external
35 * NOTE: CF controller docs disagree with address space docs as to where
36 * CF_BASE really lives; this is a doc erratum.
38 #define CF_BASE 0xfffe2800
40 /* status; read after IRQ */
41 #define CF_STATUS_REG __REG16(CF_BASE + 0x00)
42 # define CF_STATUS_BAD_READ (1 << 2)
43 # define CF_STATUS_BAD_WRITE (1 << 1)
44 # define CF_STATUS_CARD_DETECT (1 << 0)
46 /* which chipselect (CS0..CS3) is used for CF (active low) */
47 #define CF_CFG_REG __REG16(CF_BASE + 0x02)
50 #define CF_CONTROL_REG __REG16(CF_BASE + 0x04)
51 # define CF_CONTROL_RESET (1 << 0)
53 #define omap_cf_present() (!(CF_STATUS_REG & CF_STATUS_CARD_DETECT))
55 /*--------------------------------------------------------------------------*/
57 static const char driver_name[] = "omap_cf";
59 struct omap_cf_socket {
60 struct pcmcia_socket socket;
62 struct timer_list timer;
66 struct platform_device *pdev;
67 unsigned long phys_cf;
69 struct resource iomem;
72 #define POLL_INTERVAL (2 * HZ)
74 #define SZ_2K (2 * SZ_1K)
76 /*--------------------------------------------------------------------------*/
78 static int omap_cf_ss_init(struct pcmcia_socket *s)
83 /* the timer is primarily to kick this socket's pccardd */
84 static void omap_cf_timer(unsigned long _cf)
86 struct omap_cf_socket *cf = (void *) _cf;
87 unsigned present = omap_cf_present();
89 if (present != cf->present) {
90 cf->present = present;
91 pr_debug("%s: card %s\n", driver_name,
92 present ? "present" : "gone");
93 pcmcia_parse_events(&cf->socket, SS_DETECT);
97 mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
100 /* This irq handler prevents "irqNNN: nobody cared" messages as drivers
101 * claim the card's IRQ. It may also detect some card insertions, but
102 * not removals; it can't always eliminate timer irqs.
104 static irqreturn_t omap_cf_irq(int irq, void *_cf)
106 omap_cf_timer((unsigned long)_cf);
110 static int omap_cf_get_status(struct pcmcia_socket *s, u_int *sp)
115 /* NOTE CF is always 3VCARD */
116 if (omap_cf_present()) {
117 struct omap_cf_socket *cf;
119 *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD;
120 cf = container_of(s, struct omap_cf_socket, socket);
121 s->irq.AssignedIRQ = 0;
122 s->pci_irq = cf->irq;
129 omap_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
133 /* REVISIT some non-OSK boards may support power switching */
142 control = CF_CONTROL_REG;
143 if (s->flags & SS_RESET)
144 CF_CONTROL_REG = CF_CONTROL_RESET;
148 pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n",
149 driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask);
154 static int omap_cf_ss_suspend(struct pcmcia_socket *s)
156 pr_debug("%s: %s\n", driver_name, __FUNCTION__);
157 return omap_cf_set_socket(s, &dead_socket);
160 /* regions are 2K each: mem, attrib, io (and reserved-for-ide) */
163 omap_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
165 struct omap_cf_socket *cf;
167 cf = container_of(s, struct omap_cf_socket, socket);
168 io->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT;
169 io->start = cf->phys_cf + SZ_4K;
170 io->stop = io->start + SZ_2K - 1;
175 omap_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map)
177 struct omap_cf_socket *cf;
181 cf = container_of(s, struct omap_cf_socket, socket);
182 map->static_start = cf->phys_cf;
183 map->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT;
184 if (map->flags & MAP_ATTRIB)
185 map->static_start += SZ_2K;
189 static struct pccard_operations omap_cf_ops = {
190 .init = omap_cf_ss_init,
191 .suspend = omap_cf_ss_suspend,
192 .get_status = omap_cf_get_status,
193 .set_socket = omap_cf_set_socket,
194 .set_io_map = omap_cf_set_io_map,
195 .set_mem_map = omap_cf_set_mem_map,
198 /*--------------------------------------------------------------------------*/
201 * NOTE: right now the only board-specific platform_data is
202 * "what chipselect is used". Boards could want more.
205 static int __devinit omap_cf_probe(struct device *dev)
208 struct omap_cf_socket *cf;
209 struct platform_device *pdev = to_platform_device(dev);
213 seg = (int) dev->platform_data;
214 if (seg == 0 || seg > 3)
217 /* either CFLASH.IREQ (INT_1610_CF) or some GPIO */
218 irq = platform_get_irq(pdev, 0);
222 cf = kzalloc(sizeof *cf, GFP_KERNEL);
225 init_timer(&cf->timer);
226 cf->timer.function = omap_cf_timer;
227 cf->timer.data = (unsigned long) cf;
230 dev_set_drvdata(dev, cf);
232 /* this primarily just shuts up irq handling noise */
233 status = request_irq(irq, omap_cf_irq, IRQF_SHARED,
238 cf->socket.pci_irq = irq;
241 /* NOTE: CS0 could be configured too ... */
243 cf->phys_cf = OMAP_CS1_PHYS;
246 cf->phys_cf = OMAP_CS2_PHYS;
249 cf->phys_cf = omap_cs3_phys();
254 cf->iomem.start = cf->phys_cf;
255 cf->iomem.end = cf->iomem.end + SZ_8K - 1;
256 cf->iomem.flags = IORESOURCE_MEM;
258 /* pcmcia layer only remaps "real" memory */
259 cf->socket.io_offset = (unsigned long)
260 ioremap(cf->phys_cf + SZ_4K, SZ_2K);
261 if (!cf->socket.io_offset)
264 if (!request_mem_region(cf->phys_cf, SZ_8K, driver_name))
267 /* NOTE: CF conflicts with MMC1 */
268 omap_cfg_reg(W11_1610_CF_CD1);
269 omap_cfg_reg(P11_1610_CF_CD2);
270 omap_cfg_reg(R11_1610_CF_IOIS16);
271 omap_cfg_reg(V10_1610_CF_IREQ);
272 omap_cfg_reg(W10_1610_CF_RESET);
274 CF_CFG_REG = ~(1 << seg);
276 pr_info("%s: cs%d on irq %d\n", driver_name, seg, irq);
278 /* NOTE: better EMIFS setup might support more cards; but the
279 * TRM only shows how to affect regular flash signals, not their
280 * CF/PCMCIA variants...
282 pr_debug("%s: cs%d, previous ccs %08x acs %08x\n", driver_name,
283 seg, EMIFS_CCS(seg), EMIFS_ACS(seg));
284 EMIFS_CCS(seg) = 0x0004a1b3; /* synch mode 4 etc */
285 EMIFS_ACS(seg) = 0x00000000; /* OE hold/setup */
287 /* CF uses armxor_ck, which is "always" available */
289 pr_debug("%s: sts %04x cfg %04x control %04x %s\n", driver_name,
290 CF_STATUS_REG, CF_CFG_REG, CF_CONTROL_REG,
291 omap_cf_present() ? "present" : "(not present)");
293 cf->socket.owner = THIS_MODULE;
294 cf->socket.dev.parent = dev;
295 cf->socket.ops = &omap_cf_ops;
296 cf->socket.resource_ops = &pccard_static_ops;
297 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
299 cf->socket.map_size = SZ_2K;
300 cf->socket.io[0].res = &cf->iomem;
302 status = pcmcia_register_socket(&cf->socket);
307 mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
311 release_mem_region(cf->phys_cf, SZ_8K);
313 if (cf->socket.io_offset)
314 iounmap((void __iomem *) cf->socket.io_offset);
321 static int __devexit omap_cf_remove(struct device *dev)
323 struct omap_cf_socket *cf = dev_get_drvdata(dev);
326 pcmcia_unregister_socket(&cf->socket);
327 del_timer_sync(&cf->timer);
328 iounmap((void __iomem *) cf->socket.io_offset);
329 release_mem_region(cf->phys_cf, SZ_8K);
330 free_irq(cf->irq, cf);
335 static struct device_driver omap_cf_driver = {
336 .name = (char *) driver_name,
337 .bus = &platform_bus_type,
338 .probe = omap_cf_probe,
339 .remove = __devexit_p(omap_cf_remove),
340 .suspend = pcmcia_socket_dev_suspend,
341 .resume = pcmcia_socket_dev_resume,
344 static int __init omap_cf_init(void)
346 if (cpu_is_omap16xx())
347 return driver_register(&omap_cf_driver);
351 static void __exit omap_cf_exit(void)
353 if (cpu_is_omap16xx())
354 driver_unregister(&omap_cf_driver);
357 module_init(omap_cf_init);
358 module_exit(omap_cf_exit);
360 MODULE_DESCRIPTION("OMAP CF Driver");
361 MODULE_LICENSE("GPL");