2007-04-30 05:48:07 +04:00
|
|
|
/*
|
|
|
|
* Intel XScale PXA255/270 PC Card and CompactFlash Interface.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Openedhand Ltd.
|
|
|
|
* Written by Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
*
|
|
|
|
* This code is licensed under the GPLv2.
|
|
|
|
*/
|
|
|
|
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "hw.h"
|
|
|
|
#include "pcmcia.h"
|
2007-11-18 04:44:38 +03:00
|
|
|
#include "pxa.h"
|
2007-04-30 05:48:07 +04:00
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
struct PXA2xxPCMCIAState {
|
|
|
|
PCMCIASocket slot;
|
|
|
|
PCMCIACardState *card;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
qemu_irq irq;
|
|
|
|
qemu_irq cd_irq;
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint32_t pxa2xx_pcmcia_common_read(void *opaque,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t offset)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (s->slot.attached) {
|
|
|
|
return s->card->common_read(s->card->state, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_pcmcia_common_write(void *opaque,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t offset, uint32_t value)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (s->slot.attached) {
|
|
|
|
s->card->common_write(s->card->state, offset, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t pxa2xx_pcmcia_attr_read(void *opaque,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t offset)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (s->slot.attached) {
|
|
|
|
return s->card->attr_read(s->card->state, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_pcmcia_attr_write(void *opaque,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t offset, uint32_t value)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (s->slot.attached) {
|
|
|
|
s->card->attr_write(s->card->state, offset, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t pxa2xx_pcmcia_io_read(void *opaque,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t offset)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (s->slot.attached) {
|
|
|
|
return s->card->io_read(s->card->state, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_pcmcia_io_write(void *opaque,
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t offset, uint32_t value)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (s->slot.attached) {
|
|
|
|
s->card->io_write(s->card->state, offset, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUReadMemoryFunc * const pxa2xx_pcmcia_common_readfn[] = {
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_common_read,
|
|
|
|
pxa2xx_pcmcia_common_read,
|
|
|
|
pxa2xx_pcmcia_common_read,
|
|
|
|
};
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUWriteMemoryFunc * const pxa2xx_pcmcia_common_writefn[] = {
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_common_write,
|
|
|
|
pxa2xx_pcmcia_common_write,
|
|
|
|
pxa2xx_pcmcia_common_write,
|
|
|
|
};
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUReadMemoryFunc * const pxa2xx_pcmcia_attr_readfn[] = {
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_attr_read,
|
|
|
|
pxa2xx_pcmcia_attr_read,
|
|
|
|
pxa2xx_pcmcia_attr_read,
|
|
|
|
};
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUWriteMemoryFunc * const pxa2xx_pcmcia_attr_writefn[] = {
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_attr_write,
|
|
|
|
pxa2xx_pcmcia_attr_write,
|
|
|
|
pxa2xx_pcmcia_attr_write,
|
|
|
|
};
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUReadMemoryFunc * const pxa2xx_pcmcia_io_readfn[] = {
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_io_read,
|
|
|
|
pxa2xx_pcmcia_io_read,
|
|
|
|
pxa2xx_pcmcia_io_read,
|
|
|
|
};
|
|
|
|
|
2009-08-25 22:29:31 +04:00
|
|
|
static CPUWriteMemoryFunc * const pxa2xx_pcmcia_io_writefn[] = {
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_io_write,
|
|
|
|
pxa2xx_pcmcia_io_write,
|
|
|
|
pxa2xx_pcmcia_io_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level)
|
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
if (!s->irq)
|
|
|
|
return;
|
|
|
|
|
|
|
|
qemu_set_irq(s->irq, level);
|
|
|
|
}
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
PXA2xxPCMCIAState *pxa2xx_pcmcia_init(target_phys_addr_t base)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
|
|
|
int iomemtype;
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
2009-05-10 04:44:56 +04:00
|
|
|
s = (PXA2xxPCMCIAState *)
|
|
|
|
qemu_mallocz(sizeof(PXA2xxPCMCIAState));
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
/* Socket I/O Memory Space */
|
2009-06-14 12:38:51 +04:00
|
|
|
iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_io_readfn,
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_io_writefn, s);
|
2008-12-01 21:59:50 +03:00
|
|
|
cpu_register_physical_memory(base | 0x00000000, 0x04000000, iomemtype);
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
/* Then next 64 MB is reserved */
|
|
|
|
|
|
|
|
/* Socket Attribute Memory Space */
|
2009-06-14 12:38:51 +04:00
|
|
|
iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_attr_readfn,
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_attr_writefn, s);
|
2008-12-01 21:59:50 +03:00
|
|
|
cpu_register_physical_memory(base | 0x08000000, 0x04000000, iomemtype);
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
/* Socket Common Memory Space */
|
2009-06-14 12:38:51 +04:00
|
|
|
iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_common_readfn,
|
2007-04-30 05:48:07 +04:00
|
|
|
pxa2xx_pcmcia_common_writefn, s);
|
2008-12-01 21:59:50 +03:00
|
|
|
cpu_register_physical_memory(base | 0x0c000000, 0x04000000, iomemtype);
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
if (base == 0x30000000)
|
|
|
|
s->slot.slot_string = "PXA PC Card Socket 1";
|
|
|
|
else
|
|
|
|
s->slot.slot_string = "PXA PC Card Socket 0";
|
|
|
|
s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0];
|
|
|
|
pcmcia_socket_register(&s->slot);
|
2007-05-24 01:47:51 +04:00
|
|
|
|
2007-04-30 05:48:07 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert a new card into a slot */
|
2009-05-10 04:44:56 +04:00
|
|
|
int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card)
|
2007-04-30 05:48:07 +04:00
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
if (s->slot.attached)
|
|
|
|
return -EEXIST;
|
|
|
|
|
|
|
|
if (s->cd_irq) {
|
|
|
|
qemu_irq_raise(s->cd_irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->card = card;
|
|
|
|
|
|
|
|
s->slot.attached = 1;
|
|
|
|
s->card->slot = &s->slot;
|
|
|
|
s->card->attach(s->card->state);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Eject card from the slot */
|
|
|
|
int pxa2xx_pcmcia_dettach(void *opaque)
|
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
if (!s->slot.attached)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
s->card->detach(s->card->state);
|
2009-09-21 22:11:34 +04:00
|
|
|
s->card->slot = NULL;
|
|
|
|
s->card = NULL;
|
2007-04-30 05:48:07 +04:00
|
|
|
|
|
|
|
s->slot.attached = 0;
|
|
|
|
|
|
|
|
if (s->irq)
|
|
|
|
qemu_irq_lower(s->irq);
|
|
|
|
if (s->cd_irq)
|
|
|
|
qemu_irq_lower(s->cd_irq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Who to notify on card events */
|
|
|
|
void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq)
|
|
|
|
{
|
2009-05-10 04:44:56 +04:00
|
|
|
PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
|
2007-04-30 05:48:07 +04:00
|
|
|
s->irq = irq;
|
|
|
|
s->cd_irq = cd_irq;
|
|
|
|
}
|