From patchwork Tue May 19 19:23:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1293697 X-Patchwork-Delegate: jagannadh.teki@gmail.com 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=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=Kqjk1duo; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49RQpY1HFRz9sT4 for ; Wed, 20 May 2020 05:25:57 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C112181E35; Tue, 19 May 2020 21:24:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="Kqjk1duo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1F81581E2C; Tue, 19 May 2020 21:24:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7B62781DFE for ; Tue, 19 May 2020 21:24:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jagan@amarulasolutions.com Received: by mail-pj1-x1041.google.com with SMTP id 5so117836pjd.0 for ; Tue, 19 May 2020 12:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m6tHTWPu33s92LiU+iJcaJyzN2BnUnszfQVO3bujTUk=; b=Kqjk1duoDZzuUqmzHyurxBo3bWP0QPkDnCUrCUey02Ko7OxOQ4n9M/QgL1GOUULWRB cbbq3I4aBFIs1dIV9pU2rvrdfnCtZp2U181ibfXI3dQvidbWhYeHkujLu7sS0M0cda/j EnW0fvvqqBswDcT1pQZ9XEfifuiRP7iMiVizc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m6tHTWPu33s92LiU+iJcaJyzN2BnUnszfQVO3bujTUk=; b=W92fGahRFf3hzuJR/sc3fvhvPQpZx/FF/W+GVXME8v3JgA4KFtkYGquIouD+LzU5p+ lTn8rLsqCUh3opJbTXcYe3XJDRH7AfDrp4BWQ0NBNbyt5x+BAN7UcB9ON/NAleXVL8cb oXfvZv+QA3JUPgZR8s+CftkqewRefE1O4YyOwoiiH4+vA3yhB6D5+UI0P1Pbo3apHD9V KZtdHYcCvuPwH0zKsVHuBlmfl3B/Um5IiININNdZj4dzrVz1I9GYJg0Gixtm95SSij9f 24WpzAYEZpPrYtidu9u2wh3naVPvZWzMCvFy7K81N6kuQp5x8XNkkTV67oAMchF54gJ/ I+pA== X-Gm-Message-State: AOAM53388mnP5ymc/W4t/fQa6ks/GHqr30BHKYh0N58WcS9RetgGzusp lRnpQCLchhKi3RtLQohq2JqUzQ== X-Google-Smtp-Source: ABdhPJza0FMe1NM4Xj2GC/MT+ftxAhJCWZSRS4j7rwJ9jzsg/FIXmZWOaKhnZfNmguojPb/qfE+a6A== X-Received: by 2002:a17:902:bc42:: with SMTP id t2mr954438plz.233.1589916281000; Tue, 19 May 2020 12:24:41 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:713c:4a0a:47eb:ffcd]) by smtp.gmail.com with ESMTPSA id w192sm222553pff.126.2020.05.19.12.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 12:24:40 -0700 (PDT) From: Jagan Teki To: Rick Chen , Atish Patra , Palmer Dabbelt , Bin Meng , Paul Walmsley , Anup Patel , Sagar Kadam Cc: u-boot@lists.denx.de, linux-amarula@amarulasolutions.com, Jagan Teki , Mario Six , Tom Rini , Simon Glass , Jean-Jacques Hiblot Subject: [PATCH v2 4/9] drivers: Add fu540 board driver Date: Wed, 20 May 2020 00:53:35 +0530 Message-Id: <20200519192340.16624-5-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200519192340.16624-1-jagan@amarulasolutions.com> References: <20200519192340.16624-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean Add fu540 board driver, which is used to get runtime boot mode of fu540 boards. Cc: Mario Six Cc: Tom Rini Cc: Simon Glass Cc: Jean-Jacques Hiblot Signed-off-by: Jagan Teki --- Changes for v2: - new patch drivers/board/Kconfig | 8 ++++ drivers/board/Makefile | 1 + drivers/board/fu540.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 drivers/board/fu540.c diff --git a/drivers/board/Kconfig b/drivers/board/Kconfig index 254f657049..306ee76bbd 100644 --- a/drivers/board/Kconfig +++ b/drivers/board/Kconfig @@ -12,6 +12,14 @@ config SPL_BOARD depends on SPL_DM bool "Enable board driver support in SPL" +config BOARD_FU540 + bool "Enable board driver for the FU540 boards" + depends on RISCV + select SPL_BOARD + help + Support querying board information for the fu540 boards, like + get soc mode select, get SPL boot device and etc. + config BOARD_GAZERBEAM bool "Enable board driver for the Gazerbeam board" help diff --git a/drivers/board/Makefile b/drivers/board/Makefile index cc16361755..e924472779 100644 --- a/drivers/board/Makefile +++ b/drivers/board/Makefile @@ -3,5 +3,6 @@ # (C) Copyright 2017 # Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc obj-y += board-uclass.o +obj-$(CONFIG_BOARD_FU540) += fu540.o obj-$(CONFIG_BOARD_GAZERBEAM) += gazerbeam.o obj-$(CONFIG_BOARD_SANDBOX) += sandbox.o diff --git a/drivers/board/fu540.c b/drivers/board/fu540.c new file mode 100644 index 0000000000..68d356df6b --- /dev/null +++ b/drivers/board/fu540.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Amarula Solutions(India) + */ + +#include +#include +#include +#include +#include +#include + +#define MODE_SELECT_QSPI 0x6 +#define MODE_SELECT_SD 0xb +#define MODE_SELECT_MASK GENMASK(3, 0) + +struct fu540_board { + void __iomem *regs; +}; + +static int fu540_get_boot_device(struct udevice *dev) +{ + struct fu540_board *priv = dev_get_priv(dev); + u8 boot_device = BOOT_DEVICE_MMC1; + u32 reg; + + reg = readl(priv->regs); + switch (reg & MODE_SELECT_MASK) { + case MODE_SELECT_QSPI: + boot_device = BOOT_DEVICE_SPI; + break; + case MODE_SELECT_SD: + boot_device = BOOT_DEVICE_MMC1; + break; + default: + dev_err(dev, + "Unsupported boot device 0x%x but trying MMC1\n", + boot_device); + break; + } + + return boot_device; +} + +static int fu540_board_get_int(struct udevice *dev, int id, int *val) +{ + switch (id) { + case BOARD_SPL_BOOT_DEVICE: + *val = fu540_get_boot_device(dev); + break; + default: + dev_err(dev, "%s: Integer value %d unknown\n", dev->name, id); + return -EINVAL; + } + + return 0; +} + +static const struct board_ops fu540_board_ops = { + .get_int = fu540_board_get_int, +}; + +static int fu540_board_probe(struct udevice *dev) +{ + struct fu540_board *priv = dev_get_priv(dev); + + priv->regs = (void __iomem *)dev_read_addr(dev); + if (IS_ERR(priv->regs)) + return PTR_ERR(priv->regs); + + return 0; +} + +static const struct udevice_id fu540_board_ids[] = { + { .compatible = "sifive,fu540-modeselect", }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(fu540_board) = { + .id = UCLASS_BOARD, + .name = "fu540_board", + .of_match = fu540_board_ids, + .ops = &fu540_board_ops, + .priv_auto_alloc_size = sizeof(struct fu540_board), + .probe = fu540_board_probe, +};