root / hw / pxa2xx_pcmcia.c @ 4118a970
History | View | Annotate | Download (5.7 kB)
1 | a171fe39 | balrog | /*
|
---|---|---|---|
2 | a171fe39 | balrog | * Intel XScale PXA255/270 PC Card and CompactFlash Interface.
|
3 | a171fe39 | balrog | *
|
4 | a171fe39 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | a171fe39 | balrog | * Written by Andrzej Zaborowski <balrog@zabor.org>
|
6 | a171fe39 | balrog | *
|
7 | a171fe39 | balrog | * This code is licensed under the GPLv2.
|
8 | a171fe39 | balrog | */
|
9 | a171fe39 | balrog | |
10 | a171fe39 | balrog | #include "vl.h" |
11 | a171fe39 | balrog | |
12 | a171fe39 | balrog | struct pxa2xx_pcmcia_s {
|
13 | a171fe39 | balrog | struct pcmcia_socket_s slot;
|
14 | a171fe39 | balrog | struct pcmcia_card_s *card;
|
15 | a171fe39 | balrog | target_phys_addr_t common_base; |
16 | a171fe39 | balrog | target_phys_addr_t attr_base; |
17 | a171fe39 | balrog | target_phys_addr_t io_base; |
18 | a171fe39 | balrog | |
19 | a171fe39 | balrog | qemu_irq irq; |
20 | a171fe39 | balrog | qemu_irq cd_irq; |
21 | a171fe39 | balrog | }; |
22 | a171fe39 | balrog | |
23 | a171fe39 | balrog | static uint32_t pxa2xx_pcmcia_common_read(void *opaque, |
24 | a171fe39 | balrog | target_phys_addr_t offset) |
25 | a171fe39 | balrog | { |
26 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
27 | a171fe39 | balrog | |
28 | a171fe39 | balrog | if (s->slot.attached) {
|
29 | a171fe39 | balrog | offset -= s->common_base; |
30 | a171fe39 | balrog | return s->card->common_read(s->card->state, offset);
|
31 | a171fe39 | balrog | } |
32 | a171fe39 | balrog | |
33 | a171fe39 | balrog | return 0; |
34 | a171fe39 | balrog | } |
35 | a171fe39 | balrog | |
36 | a171fe39 | balrog | static void pxa2xx_pcmcia_common_write(void *opaque, |
37 | a171fe39 | balrog | target_phys_addr_t offset, uint32_t value) |
38 | a171fe39 | balrog | { |
39 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
40 | a171fe39 | balrog | |
41 | a171fe39 | balrog | if (s->slot.attached) {
|
42 | a171fe39 | balrog | offset -= s->common_base; |
43 | a171fe39 | balrog | s->card->common_write(s->card->state, offset, value); |
44 | a171fe39 | balrog | } |
45 | a171fe39 | balrog | } |
46 | a171fe39 | balrog | |
47 | a171fe39 | balrog | static uint32_t pxa2xx_pcmcia_attr_read(void *opaque, |
48 | a171fe39 | balrog | target_phys_addr_t offset) |
49 | a171fe39 | balrog | { |
50 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
51 | a171fe39 | balrog | |
52 | a171fe39 | balrog | if (s->slot.attached) {
|
53 | a171fe39 | balrog | offset -= s->attr_base; |
54 | a171fe39 | balrog | return s->card->attr_read(s->card->state, offset);
|
55 | a171fe39 | balrog | } |
56 | a171fe39 | balrog | |
57 | a171fe39 | balrog | return 0; |
58 | a171fe39 | balrog | } |
59 | a171fe39 | balrog | |
60 | a171fe39 | balrog | static void pxa2xx_pcmcia_attr_write(void *opaque, |
61 | a171fe39 | balrog | target_phys_addr_t offset, uint32_t value) |
62 | a171fe39 | balrog | { |
63 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
64 | a171fe39 | balrog | |
65 | a171fe39 | balrog | if (s->slot.attached) {
|
66 | a171fe39 | balrog | offset -= s->attr_base; |
67 | a171fe39 | balrog | s->card->attr_write(s->card->state, offset, value); |
68 | a171fe39 | balrog | } |
69 | a171fe39 | balrog | } |
70 | a171fe39 | balrog | |
71 | a171fe39 | balrog | static uint32_t pxa2xx_pcmcia_io_read(void *opaque, |
72 | a171fe39 | balrog | target_phys_addr_t offset) |
73 | a171fe39 | balrog | { |
74 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
75 | a171fe39 | balrog | |
76 | a171fe39 | balrog | if (s->slot.attached) {
|
77 | a171fe39 | balrog | offset -= s->io_base; |
78 | a171fe39 | balrog | return s->card->io_read(s->card->state, offset);
|
79 | a171fe39 | balrog | } |
80 | a171fe39 | balrog | |
81 | a171fe39 | balrog | return 0; |
82 | a171fe39 | balrog | } |
83 | a171fe39 | balrog | |
84 | a171fe39 | balrog | static void pxa2xx_pcmcia_io_write(void *opaque, |
85 | a171fe39 | balrog | target_phys_addr_t offset, uint32_t value) |
86 | a171fe39 | balrog | { |
87 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
88 | a171fe39 | balrog | |
89 | a171fe39 | balrog | if (s->slot.attached) {
|
90 | a171fe39 | balrog | offset -= s->io_base; |
91 | a171fe39 | balrog | s->card->io_write(s->card->state, offset, value); |
92 | a171fe39 | balrog | } |
93 | a171fe39 | balrog | } |
94 | a171fe39 | balrog | |
95 | a171fe39 | balrog | static CPUReadMemoryFunc *pxa2xx_pcmcia_common_readfn[] = {
|
96 | a171fe39 | balrog | pxa2xx_pcmcia_common_read, |
97 | a171fe39 | balrog | pxa2xx_pcmcia_common_read, |
98 | a171fe39 | balrog | pxa2xx_pcmcia_common_read, |
99 | a171fe39 | balrog | }; |
100 | a171fe39 | balrog | |
101 | a171fe39 | balrog | static CPUWriteMemoryFunc *pxa2xx_pcmcia_common_writefn[] = {
|
102 | a171fe39 | balrog | pxa2xx_pcmcia_common_write, |
103 | a171fe39 | balrog | pxa2xx_pcmcia_common_write, |
104 | a171fe39 | balrog | pxa2xx_pcmcia_common_write, |
105 | a171fe39 | balrog | }; |
106 | a171fe39 | balrog | |
107 | a171fe39 | balrog | static CPUReadMemoryFunc *pxa2xx_pcmcia_attr_readfn[] = {
|
108 | a171fe39 | balrog | pxa2xx_pcmcia_attr_read, |
109 | a171fe39 | balrog | pxa2xx_pcmcia_attr_read, |
110 | a171fe39 | balrog | pxa2xx_pcmcia_attr_read, |
111 | a171fe39 | balrog | }; |
112 | a171fe39 | balrog | |
113 | a171fe39 | balrog | static CPUWriteMemoryFunc *pxa2xx_pcmcia_attr_writefn[] = {
|
114 | a171fe39 | balrog | pxa2xx_pcmcia_attr_write, |
115 | a171fe39 | balrog | pxa2xx_pcmcia_attr_write, |
116 | a171fe39 | balrog | pxa2xx_pcmcia_attr_write, |
117 | a171fe39 | balrog | }; |
118 | a171fe39 | balrog | |
119 | a171fe39 | balrog | static CPUReadMemoryFunc *pxa2xx_pcmcia_io_readfn[] = {
|
120 | a171fe39 | balrog | pxa2xx_pcmcia_io_read, |
121 | a171fe39 | balrog | pxa2xx_pcmcia_io_read, |
122 | a171fe39 | balrog | pxa2xx_pcmcia_io_read, |
123 | a171fe39 | balrog | }; |
124 | a171fe39 | balrog | |
125 | a171fe39 | balrog | static CPUWriteMemoryFunc *pxa2xx_pcmcia_io_writefn[] = {
|
126 | a171fe39 | balrog | pxa2xx_pcmcia_io_write, |
127 | a171fe39 | balrog | pxa2xx_pcmcia_io_write, |
128 | a171fe39 | balrog | pxa2xx_pcmcia_io_write, |
129 | a171fe39 | balrog | }; |
130 | a171fe39 | balrog | |
131 | a171fe39 | balrog | static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level) |
132 | a171fe39 | balrog | { |
133 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
134 | a171fe39 | balrog | if (!s->irq)
|
135 | a171fe39 | balrog | return;
|
136 | a171fe39 | balrog | |
137 | a171fe39 | balrog | qemu_set_irq(s->irq, level); |
138 | a171fe39 | balrog | } |
139 | a171fe39 | balrog | |
140 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *pxa2xx_pcmcia_init(target_phys_addr_t base)
|
141 | a171fe39 | balrog | { |
142 | a171fe39 | balrog | int iomemtype;
|
143 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s;
|
144 | a171fe39 | balrog | |
145 | a171fe39 | balrog | s = (struct pxa2xx_pcmcia_s *)
|
146 | a171fe39 | balrog | qemu_mallocz(sizeof(struct pxa2xx_pcmcia_s)); |
147 | a171fe39 | balrog | |
148 | a171fe39 | balrog | /* Socket I/O Memory Space */
|
149 | a171fe39 | balrog | s->io_base = base | 0x00000000;
|
150 | a171fe39 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_pcmcia_io_readfn,
|
151 | a171fe39 | balrog | pxa2xx_pcmcia_io_writefn, s); |
152 | 187337f8 | pbrook | cpu_register_physical_memory(s->io_base, 0x04000000, iomemtype);
|
153 | a171fe39 | balrog | |
154 | a171fe39 | balrog | /* Then next 64 MB is reserved */
|
155 | a171fe39 | balrog | |
156 | a171fe39 | balrog | /* Socket Attribute Memory Space */
|
157 | a171fe39 | balrog | s->attr_base = base | 0x08000000;
|
158 | a171fe39 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_pcmcia_attr_readfn,
|
159 | a171fe39 | balrog | pxa2xx_pcmcia_attr_writefn, s); |
160 | 187337f8 | pbrook | cpu_register_physical_memory(s->attr_base, 0x04000000, iomemtype);
|
161 | a171fe39 | balrog | |
162 | a171fe39 | balrog | /* Socket Common Memory Space */
|
163 | a171fe39 | balrog | s->common_base = base | 0x0c000000;
|
164 | a171fe39 | balrog | iomemtype = cpu_register_io_memory(0, pxa2xx_pcmcia_common_readfn,
|
165 | a171fe39 | balrog | pxa2xx_pcmcia_common_writefn, s); |
166 | 187337f8 | pbrook | cpu_register_physical_memory(s->common_base, 0x04000000, iomemtype);
|
167 | a171fe39 | balrog | |
168 | a171fe39 | balrog | if (base == 0x30000000) |
169 | a171fe39 | balrog | s->slot.slot_string = "PXA PC Card Socket 1";
|
170 | a171fe39 | balrog | else
|
171 | a171fe39 | balrog | s->slot.slot_string = "PXA PC Card Socket 0";
|
172 | a171fe39 | balrog | s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0]; |
173 | a171fe39 | balrog | pcmcia_socket_register(&s->slot); |
174 | 3f582262 | balrog | |
175 | a171fe39 | balrog | return s;
|
176 | a171fe39 | balrog | } |
177 | a171fe39 | balrog | |
178 | a171fe39 | balrog | /* Insert a new card into a slot */
|
179 | a171fe39 | balrog | int pxa2xx_pcmcia_attach(void *opaque, struct pcmcia_card_s *card) |
180 | a171fe39 | balrog | { |
181 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
182 | a171fe39 | balrog | if (s->slot.attached)
|
183 | a171fe39 | balrog | return -EEXIST;
|
184 | a171fe39 | balrog | |
185 | a171fe39 | balrog | if (s->cd_irq) {
|
186 | a171fe39 | balrog | qemu_irq_raise(s->cd_irq); |
187 | a171fe39 | balrog | } |
188 | a171fe39 | balrog | |
189 | a171fe39 | balrog | s->card = card; |
190 | a171fe39 | balrog | |
191 | a171fe39 | balrog | s->slot.attached = 1;
|
192 | a171fe39 | balrog | s->card->slot = &s->slot; |
193 | a171fe39 | balrog | s->card->attach(s->card->state); |
194 | a171fe39 | balrog | |
195 | a171fe39 | balrog | return 0; |
196 | a171fe39 | balrog | } |
197 | a171fe39 | balrog | |
198 | a171fe39 | balrog | /* Eject card from the slot */
|
199 | a171fe39 | balrog | int pxa2xx_pcmcia_dettach(void *opaque) |
200 | a171fe39 | balrog | { |
201 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
202 | a171fe39 | balrog | if (!s->slot.attached)
|
203 | a171fe39 | balrog | return -ENOENT;
|
204 | a171fe39 | balrog | |
205 | a171fe39 | balrog | s->card->detach(s->card->state); |
206 | a171fe39 | balrog | s->card->slot = 0;
|
207 | a171fe39 | balrog | s->card = 0;
|
208 | a171fe39 | balrog | |
209 | a171fe39 | balrog | s->slot.attached = 0;
|
210 | a171fe39 | balrog | |
211 | a171fe39 | balrog | if (s->irq)
|
212 | a171fe39 | balrog | qemu_irq_lower(s->irq); |
213 | a171fe39 | balrog | if (s->cd_irq)
|
214 | a171fe39 | balrog | qemu_irq_lower(s->cd_irq); |
215 | a171fe39 | balrog | |
216 | a171fe39 | balrog | return 0; |
217 | a171fe39 | balrog | } |
218 | a171fe39 | balrog | |
219 | a171fe39 | balrog | /* Who to notify on card events */
|
220 | a171fe39 | balrog | void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq) |
221 | a171fe39 | balrog | { |
222 | a171fe39 | balrog | struct pxa2xx_pcmcia_s *s = (struct pxa2xx_pcmcia_s *) opaque; |
223 | a171fe39 | balrog | s->irq = irq; |
224 | a171fe39 | balrog | s->cd_irq = cd_irq; |
225 | a171fe39 | balrog | } |