From patchwork Mon Feb 21 20:57:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 83875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7138BB7178 for ; Tue, 22 Feb 2011 08:05:24 +1100 (EST) Received: from localhost ([127.0.0.1]:46655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Prcwb-0003ls-Gu for incoming@patchwork.ozlabs.org; Mon, 21 Feb 2011 16:05:21 -0500 Received: from [140.186.70.92] (port=38985 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrcpS-000897-Uh for qemu-devel@nongnu.org; Mon, 21 Feb 2011 15:58:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrcpR-0001jN-W8 for qemu-devel@nongnu.org; Mon, 21 Feb 2011 15:57:59 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:60890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrcpR-0001i9-Nk for qemu-devel@nongnu.org; Mon, 21 Feb 2011 15:57:57 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1PrcpN-0004Rj-O1; Mon, 21 Feb 2011 20:57:53 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 21 Feb 2011 20:57:50 +0000 Message-Id: <1298321873-17064-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1298321873-17064-1-git-send-email-peter.maydell@linaro.org> References: <1298321873-17064-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: patches@linaro.org Subject: [Qemu-devel] [PATCH 2/5] hw/arm_sysctl.c: Wire MCI register MMC card status bits to GPIO inputs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Implement some GPIO inputs which a board can connect up to set the MMC card status bits in the MCI register. Signed-off-by: Peter Maydell --- hw/arm_sysctl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- hw/primecell.h | 4 ++++ 2 files changed, 50 insertions(+), 1 deletions(-) diff --git a/hw/arm_sysctl.c b/hw/arm_sysctl.c index d8b062c..799b007 100644 --- a/hw/arm_sysctl.c +++ b/hw/arm_sysctl.c @@ -26,6 +26,7 @@ typedef struct { uint32_t nvflags; uint32_t resetlevel; uint32_t proc_id; + uint32_t sys_mci; } arm_sysctl_state; static const VMStateDescription vmstate_arm_sysctl = { @@ -44,6 +45,21 @@ static const VMStateDescription vmstate_arm_sysctl = { } }; +/* The PB926 actually uses a different format for + * its SYS_ID register. Fortunately the bits which are + * board type on later boards are distinct. + */ +#define BOARD_ID_PB926 0x100 +#define BOARD_ID_EB 0x140 +#define BOARD_ID_PBA8 0x178 +#define BOARD_ID_PBX 0x182 + +static int board_id(arm_sysctl_state *s) +{ + /* Extract the board ID field from the SYS_ID register value */ + return (s->sys_id >> 16) & 0xfff; +} + static void arm_sysctl_reset(DeviceState *d) { arm_sysctl_state *s = FROM_SYSBUS(arm_sysctl_state, sysbus_from_qdev(d)); @@ -92,7 +108,7 @@ static uint32_t arm_sysctl_read(void *opaque, target_phys_addr_t offset) case 0x44: /* PCICTL */ return 1; case 0x48: /* MCI */ - return 0; + return s->sys_mci; case 0x4c: /* FLASH */ return 0; case 0x50: /* CLCD */ @@ -218,6 +234,34 @@ static CPUWriteMemoryFunc * const arm_sysctl_writefn[] = { arm_sysctl_write }; +static void arm_sysctl_gpio_set(void *opaque, int line, int level) +{ + arm_sysctl_state *s = (arm_sysctl_state *)opaque; + switch (line) { + case ARM_SYSCTL_GPIO_MMC_WPROT: + { + /* For PB926 and EB write-protect is bit 2 of SYS_MCI; + * for all later boards it is bit 1. + */ + int bit = 2; + if ((board_id(s) == BOARD_ID_PB926) || (board_id(s) == BOARD_ID_EB)) { + bit = 4; + } + s->sys_mci &= ~bit; + if (level) { + s->sys_mci |= bit; + } + break; + } + case ARM_SYSCTL_GPIO_MMC_CARDIN: + s->sys_mci &= ~1; + if (level) { + s->sys_mci |= 1; + } + break; + } +} + static int arm_sysctl_init1(SysBusDevice *dev) { arm_sysctl_state *s = FROM_SYSBUS(arm_sysctl_state, dev); @@ -227,6 +271,7 @@ static int arm_sysctl_init1(SysBusDevice *dev) arm_sysctl_writefn, s, DEVICE_NATIVE_ENDIAN); sysbus_init_mmio(dev, 0x1000, iomemtype); + qdev_init_gpio_in(&s->busdev.qdev, arm_sysctl_gpio_set, 2); /* ??? Save/restore. */ return 0; } diff --git a/hw/primecell.h b/hw/primecell.h index fb456ad..de7d6f2 100644 --- a/hw/primecell.h +++ b/hw/primecell.h @@ -11,4 +11,8 @@ void *pl080_init(uint32_t base, qemu_irq irq, int nchannels); /* arm_sysctl.c */ void arm_sysctl_init(uint32_t base, uint32_t sys_id, uint32_t proc_id); +/* arm_sysctl GPIO lines */ +#define ARM_SYSCTL_GPIO_MMC_WPROT 0 +#define ARM_SYSCTL_GPIO_MMC_CARDIN 1 + #endif