From patchwork Fri Oct 18 15:06:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1179454 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=greensocs.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.b="2Hgo1smB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46vqfn0DCyz9sNw for ; Sat, 19 Oct 2019 02:27:59 +1100 (AEDT) Received: from localhost ([::1]:41764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLUAV-0004Ro-8u for incoming@patchwork.ozlabs.org; Fri, 18 Oct 2019 11:27:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39405) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLTrk-0007LO-RZ for qemu-devel@nongnu.org; Fri, 18 Oct 2019 11:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLTrj-0000V6-9h for qemu-devel@nongnu.org; Fri, 18 Oct 2019 11:08:32 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:38770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iLTrg-0000IJ-2c; Fri, 18 Oct 2019 11:08:28 -0400 Received: from crumble.bar.greensocs.com (crumble.bar.greensocs.com [172.16.11.102]) by beetle.greensocs.com (Postfix) with ESMTPS id 5EA0096F5B; Fri, 18 Oct 2019 15:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1571411276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gw/9OjOWVXESU4gXuWgq3cSpDZKHiW1A6Qa07223tS4=; b=2Hgo1smBHJKc8hH1+ddEvD6r9ON4YMMnIVarKOxj5L3+p9n8LsJpDwTCW8tV7YcBhWdoT7 fRQHyZFS0PC7HNsmdFu/FssYrIWa021IECzz8t0sLIqbSjxb8piqkdp8J+DH8GY9Fq1ROr YY4O6nEYrA8sdhACNYqDxVX59xoQIDo= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [PATCH v5 12/13] hw/gpio/bcm2835_gpio: Isolate sdbus reparenting Date: Fri, 18 Oct 2019 17:06:29 +0200 Message-Id: <20191018150630.31099-13-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191018150630.31099-1-damien.hedde@greensocs.com> References: <20191018150630.31099-1-damien.hedde@greensocs.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1571411277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gw/9OjOWVXESU4gXuWgq3cSpDZKHiW1A6Qa07223tS4=; b=vILmcuKtWURTOiXgVhIc1DaAORRjIFoK9qFn3iDtt0S/mAqbB6zFxQ338K4E9Z8unl3vJH SaPC4M28azmE93QjNljLUvn2KqT8Fim33dwpwqv0MEscKBYWAK35KY204tP4UXD2Rtl0na Sjwpf+NILNZV8thpW71rJaCc7qgVdEs= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1571411277; a=rsa-sha256; cv=none; b=GG+rbZ0BOnJ8bWGzctqkp1pKCEFjSDCOtoYm24cvnreOkmGm5oSQkizw9t/Rc8mx5aq9kq srRtgIf86jy1deNJRkbk4UMtVIYRj1voUcuHpc+RerBXJd/r6E08AD2cKK+NwXJkIB1WAn B5sypCqfQmlP6Fku5vKY/yIQSvtp3Po= ARC-Authentication-Results: i=1; beetle.greensocs.com; none X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 5.135.226.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Damien Hedde , peter.maydell@linaro.org, berrange@redhat.com, ehabkost@redhat.com, cohuck@redhat.com, mark.burton@greensocs.com, qemu-s390x@nongnu.org, Andrew Baumann , edgari@xilinx.com, qemu-arm@nongnu.org, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Split gpfsel_set() in 2 so that the sdbus reparenting is done in a dedicated function. Signed-off-by: Damien Hedde --- Cc: Peter Maydell Cc: Andrew Baumann Cc: Philippe Mathieu-Daudé Cc: qemu-arm@nongnu.org --- hw/gpio/bcm2835_gpio.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/gpio/bcm2835_gpio.c b/hw/gpio/bcm2835_gpio.c index 91ce3d10cc..81fe07132f 100644 --- a/hw/gpio/bcm2835_gpio.c +++ b/hw/gpio/bcm2835_gpio.c @@ -75,7 +75,10 @@ static void gpfsel_set(BCM2835GpioState *s, uint8_t reg, uint32_t value) s->fsel[index] = fsel; } } +} +static void gpfsel_update_sdbus(BCM2835GpioState *s) +{ /* SD controller selection (48-53) */ if (s->sd_fsel != 0 && (s->fsel[48] == 0) /* SD_CLK_R */ @@ -86,6 +89,7 @@ static void gpfsel_set(BCM2835GpioState *s, uint8_t reg, uint32_t value) && (s->fsel[53] == 0) /* SD_DATA3_R */ ) { /* SDHCI controller selected */ + sdbus_reparent_card(&s->sdbus, s->sdbus_sdhci); sdbus_reparent_card(s->sdbus_sdhost, s->sdbus_sdhci); s->sd_fsel = 0; } else if (s->sd_fsel != 4 @@ -97,6 +101,7 @@ static void gpfsel_set(BCM2835GpioState *s, uint8_t reg, uint32_t value) && (s->fsel[53] == 4) /* SD_DATA3_R */ ) { /* SDHost controller selected */ + sdbus_reparent_card(&s->sdbus, s->sdbus_sdhost); sdbus_reparent_card(s->sdbus_sdhci, s->sdbus_sdhost); s->sd_fsel = 4; } @@ -210,6 +215,7 @@ static void bcm2835_gpio_write(void *opaque, hwaddr offset, case GPFSEL4: case GPFSEL5: gpfsel_set(s, offset / 4, value); + gpfsel_update_sdbus(s); break; case GPSET0: gpset(s, value, 0, 32, &s->lev0); @@ -265,10 +271,12 @@ static void bcm2835_gpio_reset(DeviceState *dev) gpfsel_set(s, i, 0); } - s->sd_fsel = 0; - - /* SDHCI is selected by default */ - sdbus_reparent_card(&s->sdbus, s->sdbus_sdhci); + /* + * Setup the right sdbus (put 1 in sd_fsel to force reparenting + * the sd). It will be SDHCI because of the gpfsel_set() above. + */ + s->sd_fsel = 1; + gpfsel_update_sdbus(s); s->lev0 = 0; s->lev1 = 0;