mirror of https://gitee.com/openkylin/qemu.git
onenand: Handle various ID fields separately
Handle the manufacturer, device and version IDs separately rather than smooshing them all together into a single uint32_t. Note that the ID registers are actually 16 bit, even though typically the top bits are 0 and the Read Identification Data command only returns the bottom 8 bits. Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com> [Riku Voipio: Fixes and restructuring patchset] Signed-off-by: Riku Voipio <riku.voipio@iki.fi> [Peter Maydell: More fixes and cleanups for upstream submission] Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
This commit is contained in:
parent
af5a75f41c
commit
5923ba424b
|
@ -38,7 +38,8 @@ uint32_t nand_getbuswidth(DeviceState *dev);
|
||||||
/* onenand.c */
|
/* onenand.c */
|
||||||
void onenand_base_update(void *opaque, target_phys_addr_t new);
|
void onenand_base_update(void *opaque, target_phys_addr_t new);
|
||||||
void onenand_base_unmap(void *opaque);
|
void onenand_base_unmap(void *opaque);
|
||||||
void *onenand_init(BlockDriverState *bdrv, uint32_t id,
|
void *onenand_init(BlockDriverState *bdrv,
|
||||||
|
uint16_t man_id, uint16_t dev_id, uint16_t ver_id,
|
||||||
int regshift, qemu_irq irq);
|
int regshift, qemu_irq irq);
|
||||||
void *onenand_raw_otp(void *opaque);
|
void *onenand_raw_otp(void *opaque);
|
||||||
|
|
||||||
|
|
|
@ -167,8 +167,9 @@ static void n8x0_nand_setup(struct n800_s *s)
|
||||||
DriveInfo *dinfo;
|
DriveInfo *dinfo;
|
||||||
|
|
||||||
dinfo = drive_get(IF_MTD, 0, 0);
|
dinfo = drive_get(IF_MTD, 0, 0);
|
||||||
/* Either ec40xx or ec48xx are OK for the ID */
|
/* Either 0x40 or 0x48 are OK for the device ID */
|
||||||
s->nand = onenand_init(dinfo ? dinfo->bdrv : 0, 0xec4800, 1,
|
s->nand = onenand_init(dinfo ? dinfo->bdrv : 0,
|
||||||
|
NAND_MFR_SAMSUNG, 0x48, 0, 1,
|
||||||
qdev_get_gpio_in(s->cpu->gpio, N8X0_ONENAND_GPIO));
|
qdev_get_gpio_in(s->cpu->gpio, N8X0_ONENAND_GPIO));
|
||||||
omap_gpmc_attach(s->cpu->gpmc, N8X0_ONENAND_CS, 0, onenand_base_update,
|
omap_gpmc_attach(s->cpu->gpmc, N8X0_ONENAND_CS, 0, onenand_base_update,
|
||||||
onenand_base_unmap, s->nand);
|
onenand_base_unmap, s->nand);
|
||||||
|
|
29
hw/onenand.c
29
hw/onenand.c
|
@ -31,7 +31,11 @@
|
||||||
#define BLOCK_SHIFT (PAGE_SHIFT + 6)
|
#define BLOCK_SHIFT (PAGE_SHIFT + 6)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t id;
|
struct {
|
||||||
|
uint16_t man;
|
||||||
|
uint16_t dev;
|
||||||
|
uint16_t ver;
|
||||||
|
} id;
|
||||||
int shift;
|
int shift;
|
||||||
target_phys_addr_t base;
|
target_phys_addr_t base;
|
||||||
qemu_irq intr;
|
qemu_irq intr;
|
||||||
|
@ -453,12 +457,12 @@ static uint32_t onenand_read(void *opaque, target_phys_addr_t addr)
|
||||||
return lduw_le_p(s->boot[0] + addr);
|
return lduw_le_p(s->boot[0] + addr);
|
||||||
|
|
||||||
case 0xf000: /* Manufacturer ID */
|
case 0xf000: /* Manufacturer ID */
|
||||||
return (s->id >> 16) & 0xff;
|
return s->id.man;
|
||||||
case 0xf001: /* Device ID */
|
case 0xf001: /* Device ID */
|
||||||
return (s->id >> 8) & 0xff;
|
return s->id.dev;
|
||||||
/* TODO: get the following values from a real chip! */
|
|
||||||
case 0xf002: /* Version ID */
|
case 0xf002: /* Version ID */
|
||||||
return (s->id >> 0) & 0xff;
|
return s->id.ver;
|
||||||
|
/* TODO: get the following values from a real chip! */
|
||||||
case 0xf003: /* Data Buffer size */
|
case 0xf003: /* Data Buffer size */
|
||||||
return 1 << PAGE_SHIFT;
|
return 1 << PAGE_SHIFT;
|
||||||
case 0xf004: /* Boot Buffer size */
|
case 0xf004: /* Boot Buffer size */
|
||||||
|
@ -541,8 +545,8 @@ static void onenand_write(void *opaque, target_phys_addr_t addr,
|
||||||
|
|
||||||
case 0x0090: /* Read Identification Data */
|
case 0x0090: /* Read Identification Data */
|
||||||
memset(s->boot[0], 0, 3 << s->shift);
|
memset(s->boot[0], 0, 3 << s->shift);
|
||||||
s->boot[0][0 << s->shift] = (s->id >> 16) & 0xff;
|
s->boot[0][0 << s->shift] = s->id.man & 0xff;
|
||||||
s->boot[0][1 << s->shift] = (s->id >> 8) & 0xff;
|
s->boot[0][1 << s->shift] = s->id.dev & 0xff;
|
||||||
s->boot[0][2 << s->shift] = s->wpstatus & 0xff;
|
s->boot[0][2 << s->shift] = s->wpstatus & 0xff;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -615,21 +619,24 @@ static CPUWriteMemoryFunc * const onenand_writefn[] = {
|
||||||
onenand_write,
|
onenand_write,
|
||||||
};
|
};
|
||||||
|
|
||||||
void *onenand_init(BlockDriverState *bdrv, uint32_t id,
|
void *onenand_init(BlockDriverState *bdrv,
|
||||||
|
uint16_t man_id, uint16_t dev_id, uint16_t ver_id,
|
||||||
int regshift, qemu_irq irq)
|
int regshift, qemu_irq irq)
|
||||||
{
|
{
|
||||||
OneNANDState *s = (OneNANDState *) qemu_mallocz(sizeof(*s));
|
OneNANDState *s = (OneNANDState *) qemu_mallocz(sizeof(*s));
|
||||||
uint32_t size = 1 << (24 + ((id >> 12) & 7));
|
uint32_t size = 1 << (24 + ((dev_id >> 4) & 7));
|
||||||
void *ram;
|
void *ram;
|
||||||
|
|
||||||
s->shift = regshift;
|
s->shift = regshift;
|
||||||
s->intr = irq;
|
s->intr = irq;
|
||||||
s->rdy = NULL;
|
s->rdy = NULL;
|
||||||
s->id = id;
|
s->id.man = man_id;
|
||||||
|
s->id.dev = dev_id;
|
||||||
|
s->id.ver = ver_id;
|
||||||
s->blocks = size >> BLOCK_SHIFT;
|
s->blocks = size >> BLOCK_SHIFT;
|
||||||
s->secs = size >> 9;
|
s->secs = size >> 9;
|
||||||
s->blockwp = qemu_malloc(s->blocks);
|
s->blockwp = qemu_malloc(s->blocks);
|
||||||
s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0;
|
s->density_mask = (dev_id & 0x08) ? (1 << (6 + ((dev_id >> 4) & 7))) : 0;
|
||||||
s->iomemtype = cpu_register_io_memory(onenand_readfn,
|
s->iomemtype = cpu_register_io_memory(onenand_readfn,
|
||||||
onenand_writefn, s, DEVICE_NATIVE_ENDIAN);
|
onenand_writefn, s, DEVICE_NATIVE_ENDIAN);
|
||||||
s->bdrv = bdrv;
|
s->bdrv = bdrv;
|
||||||
|
|
Loading…
Reference in New Issue