From patchwork Wed Jul 4 07:36:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141009 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp490394ljj; Wed, 4 Jul 2018 00:36:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfUH/mbIb6s3WLawjs01ENLIbEceSFxTA+c8qoFSB83ldiiYrDLdUL0HdcGny754op9G5e1 X-Received: by 2002:aa7:da16:: with SMTP id r22-v6mr160476eds.54.1530689807278; Wed, 04 Jul 2018 00:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530689807; cv=none; d=google.com; s=arc-20160816; b=kdYZgmbQP0UDK+/CG6Y0PNUKAr4yZeQr5soi6gHAVyqSrsZhDNImDHwhR9y70V9JWG J8mbr5NnOdb6dbvGIr8EvzEkWCLyaVOLffaIucGYkPt0Var7wwaPuLHeifNiSQYlg5KH WxUXBnR11ssferzl7NO8z2DCnrDa01yIB3g3cHoxoer4p3B/56mYPCypyebqVtCBdjrT Msh/ZD/edqZf4+K55j9vcINZ5dj8mtcIZKLzRFeiRWtFsFXZ80kgfzGsLXgstevpDzet LDarjQAUWsiGwE/IWY37BNGl2POd7nho9vKgvGpRotyLXYM3jc5nyfm+jgMbPrvEkcDx kN8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=OGm6Za6D+cKayyiLH1jyngIKTBhsfeGS2Cja/D/bK3w=; b=R47hPt6+obv4iLwxvAF0ONHXB+/XdCPlqJOHmkeV2gSwPL6E23iVi5xELBPqqfsqKi B9tHFytJ7RypiRBc7Z7MfOutr0oLOeEDgAwnFPYv8c+gDtZ+QUY6Srr7gxiOsPi8K0LE Cw56ErAezMlbwAf29xwQwMQG/uq0uYjGKEkmhLtNOv1OoRbgoVhkrRFUgGuzc29A8XtD Ajk+Hz8FZND/g+3tWUJnQWlLoIqgSMxQZq1fxAN04C/Vdoh02CmWNzbTW5cYtm1d8r2A 3owx1sWgzdlvVCiABHB2fe2Fip0K+8dKZfwhFGB7zeT3zPVOLoPbMag47L0KfANdzuih dFJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Y+HbED9V; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id w13-v6si2125080edk.456.2018.07.04.00.36.47; Wed, 04 Jul 2018 00:36:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Y+HbED9V; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id DC6D8C21C50; Wed, 4 Jul 2018 07:36:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 7433FC21F06; Wed, 4 Jul 2018 07:36:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0B16BC21F84; Wed, 4 Jul 2018 07:36:15 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by lists.denx.de (Postfix) with ESMTPS id A9346C21F3D for ; Wed, 4 Jul 2018 07:36:10 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id s24-v6so2267793plq.6 for ; Wed, 04 Jul 2018 00:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8N9BLHMXKvMXQVQwczfcIg8KKgOY9v5p0m/JShwuOWU=; b=Y+HbED9VwPI/yVB/sqZvuaunrfPOLMVEPieSZ/gQZO2OtdVEgfp2udKWBRrS6j07n9 aaT8XLxr/kV8ydApULlcdCzKOJlM/aJw4RaXc/xxqkwpx9wzVSAr6m3MwHJ9neD+puR2 QGHcMZxTTq5OCW2V52+vidAGO2s5M2ZnLV/S4= 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; bh=8N9BLHMXKvMXQVQwczfcIg8KKgOY9v5p0m/JShwuOWU=; b=n/ffOkKKwdcyzdzchPHomNxDj+HRG+V1/sd/kQurxQwYF/ZOPpvsgpHbxKWXHd+Et4 sjlxitTYVUd6bUvZiuzat4m/Y/YNKuk1UZjhgjBKbS49/D6N1afcIrmOu7iHgKjGZTSb WGccBcnQy8IO3wPp6DUG3pRPC2CmLu9bfz1CpzCDp+wtYHQFrnL0350ZWacMXTeRM3H3 vTer6TNPeRx1oI5jkGjmG9gprh97onCQQF4nS2cGqFGFdjK+X465QaYpsRIHZzgzS00Y GNoM4DHHTyS8HHQwVqHoBhDiy4Z/hqrnCBcBxlY6Tws1FrVizkqaaM6jFSjWsSXrDqx1 gxnQ== X-Gm-Message-State: APt69E2g/H6JisOgKZPccaEhZaTByQ2JHPag4lHXwK/r4KZMNq/Izw+Q ZlYMD7BDa4EuqHW9dhKgI2yXNg== X-Received: by 2002:a17:902:5a3:: with SMTP id f32-v6mr977127plf.109.1530689769313; Wed, 04 Jul 2018 00:36:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g20-v6sm5105756pfo.94.2018.07.04.00.36.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 00:36:08 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, sjg@chromium.org, tuomas.tynkkynen@iki.fi Date: Wed, 4 Jul 2018 16:36:27 +0900 Message-Id: <20180704073628.23596-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180704073628.23596-1-takahiro.akashi@linaro.org> References: <20180704073628.23596-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/2] rtc: pl031: convert the driver to driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Signed-off-by: AKASHI Takahiro --- drivers/rtc/Kconfig | 6 ++ drivers/rtc/pl031.c | 109 +++++++++++++++++---------- include/dm/platform_data/rtc_pl031.h | 12 +++ 3 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 include/dm/platform_data/rtc_pl031.h diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index a3f8c8aecc..96c4cce410 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -55,6 +55,12 @@ config RTC_MV Enable Marvell RTC driver. This driver supports the rtc that is present on some Marvell SoCs. +config RTC_PL031 + bool "Enable ARM PL031 driver" + depends on DM_RTC + help + Enable ARM PL031 driver. + config RTC_S35392A bool "Enable S35392A driver" select BITREVERSE diff --git a/drivers/rtc/pl031.c b/drivers/rtc/pl031.c index 8955805e3b..eecade8374 100644 --- a/drivers/rtc/pl031.c +++ b/drivers/rtc/pl031.c @@ -8,14 +8,10 @@ #include #include +#include +#include #include -#if defined(CONFIG_CMD_DATE) - -#ifndef CONFIG_SYS_RTC_PL031_BASE -#error CONFIG_SYS_RTC_PL031_BASE is not defined! -#endif - /* * Register definitions */ @@ -30,78 +26,111 @@ #define RTC_CR_START (1 << 0) -#define RTC_WRITE_REG(addr, val) \ - (*(volatile unsigned int *)(CONFIG_SYS_RTC_PL031_BASE + (addr)) = (val)) -#define RTC_READ_REG(addr) \ - (*(volatile unsigned int *)(CONFIG_SYS_RTC_PL031_BASE + (addr))) +#define RTC_WRITE_REG(base, addr, val) \ + (*(volatile unsigned int *)((base) + (addr)) = (val)) +#define RTC_READ_REG(base, addr) \ + (*(volatile unsigned int *)((base) + (addr))) static int pl031_initted = 0; /* Enable RTC Start in Control register*/ -void rtc_init(void) +void pl031_rtc_init(struct pl031_rtc_platdata *pdata) { - RTC_WRITE_REG(RTC_CR, RTC_CR_START); + RTC_WRITE_REG(pdata->base, RTC_CR, RTC_CR_START); pl031_initted = 1; } /* - * Reset the RTC. We set the date back to 1970-01-01. + * Get the current time from the RTC */ -void rtc_reset(void) +static int pl031_rtc_get(struct udevice *dev, struct rtc_time *tm) { - RTC_WRITE_REG(RTC_LR, 0x00); - if(!pl031_initted) - rtc_init(); + struct pl031_rtc_platdata *pdata = dev_get_platdata(dev); + ulong tim; + + if (!tm) { + puts("Error getting the date/time\n"); + return -1; + } + + if (!pl031_initted) + pl031_rtc_init(pdata); + + tim = RTC_READ_REG(pdata->base, RTC_DR); + + rtc_to_tm(tim, tm); + + debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", + tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + + return 0; } /* * Set the RTC -*/ -int rtc_set(struct rtc_time *tmp) + */ +static int pl031_rtc_set(struct udevice *dev, const struct rtc_time *tm) { + struct pl031_rtc_platdata *pdata = dev_get_platdata(dev); unsigned long tim; - if(!pl031_initted) - rtc_init(); - - if (tmp == NULL) { + if (!tm) { puts("Error setting the date/time\n"); return -1; } + if (!pl031_initted) + pl031_rtc_init(pdata); + /* Calculate number of seconds this incoming time represents */ - tim = rtc_mktime(tmp); + tim = rtc_mktime(tm); - RTC_WRITE_REG(RTC_LR, tim); + RTC_WRITE_REG(pdata->base, RTC_LR, tim); return -1; } /* - * Get the current time from the RTC + * Reset the RTC. We set the date back to 1970-01-01. */ -int rtc_get(struct rtc_time *tmp) +static int pl031_rtc_reset(struct udevice *dev) { - ulong tim; + struct pl031_rtc_platdata *pdata = dev_get_platdata(dev); - if(!pl031_initted) - rtc_init(); + RTC_WRITE_REG(pdata->base, RTC_LR, 0x00); - if (tmp == NULL) { - puts("Error getting the date/time\n"); - return -1; - } + if (!pl031_initted) + pl031_rtc_init(pdata); - tim = RTC_READ_REG(RTC_DR); + return 0; +} + +static const struct rtc_ops pl031_rtc_ops = { + .get = pl031_rtc_get, + .set = pl031_rtc_set, + .reset = pl031_rtc_reset, +}; - rtc_to_tm(tim, tmp); +static const struct udevice_id pl031_rtc_ids[] = { + { .compatible = "arm,pl031" }, + { } +}; - debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", - tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); +static int pl031_rtc_ofdata_to_platdata(struct udevice *dev) +{ + struct pl031_rtc_platdata *pdata = dev_get_platdata(dev); + pdata->base = devfdt_get_addr(dev); return 0; } -#endif +U_BOOT_DRIVER(rtc_pl031) = { + .name = "rtc-pl031", + .id = UCLASS_RTC, + .of_match = pl031_rtc_ids, + .ofdata_to_platdata = pl031_rtc_ofdata_to_platdata, + .platdata_auto_alloc_size = sizeof(struct pl031_rtc_platdata), + .ops = &pl031_rtc_ops, +}; diff --git a/include/dm/platform_data/rtc_pl031.h b/include/dm/platform_data/rtc_pl031.h new file mode 100644 index 0000000000..8e4ba1ce69 --- /dev/null +++ b/include/dm/platform_data/rtc_pl031.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __rtc_pl031_h +#define __rtc_pl031_h + +#include + +struct pl031_rtc_platdata { + phys_addr_t base; +}; + +#endif