From patchwork Sun Aug 20 01:36:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 110469 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2677358qge; Sat, 19 Aug 2017 18:37:53 -0700 (PDT) X-Received: by 10.84.214.137 with SMTP id j9mr14474969pli.457.1503193073224; Sat, 19 Aug 2017 18:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503193073; cv=none; d=google.com; s=arc-20160816; b=p/GfUCZycv2iuu/o0bhTUfDKNEl/rvdhyrOXei0fH/TIZlB3snE1yzwNOpHIMiXfH6 CQteQbEOVfzvE5PNbAf9Qlr3xED54B27O+MDvwgMs/f2fizSHyQ5Rytl27JGypmdwuku U8VCpF/xZxGOGHhJ3c4RVBJjTPJ054k19vxfCsp6GE3/nGZ1R0jwsfCUw5Hie/dCSWEV 67qqMqvNoM/r0iYdgKlOU+ExmZ07D6DaNMmBOME/RH9aOnUjAHt9yDBr6xcIRYPQCAxU KQp9nC/Hgs9H0dwTd+rtfvEi8U68bQ6AVlWN6Vi4czzMK1/c0rAdA3H8bXI9/Lw99Trk REYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rfoHuV3brPQWIT2p0NvlcJnV189a3knB3WTqwGic3OY=; b=MiMDvOqAvtXzaeouVqL54ADe9RJm6xhOwignbYMmT92h6nSZSFQuTJ9rko5NMhJpX3 5jqBhTLUd4nt/8Xd7YRqzZR7eSh86L9Rxtwhn516mCWXZPY/7452PzvjZW5dGHtHBrjI 4/YPxJYwBbrUHQcJvnky4oAB9RWQpyveEifPBXlZv7NDu3ciTLTWskw8tXTzN3vbOzWa GbojmbaXswj+lRBnPHhRmzmR6eJpCuxqsra6EQkXyDpNtxcgx0nsl7X8JVWs50uKRnTA /zUBQh45fVNC+6te+YtANAARoAF1MLTu8zBCwYh3Wmfkbfq35Yt5TQWt5vba0LP/it43 hF8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s72si5526842pfa.411.2017.08.19.18.37.52; Sat, 19 Aug 2017 18:37:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752583AbdHTBhg (ORCPT + 26 others); Sat, 19 Aug 2017 21:37:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:33178 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752480AbdHTBhc (ORCPT ); Sat, 19 Aug 2017 21:37:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C9304ABC3; Sun, 20 Aug 2017 01:37:30 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: Alessandro Zummo , Alexandre Belloni , linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Roc He , =?utf-8?b?6JKL?= =?utf-8?b?5Li955C0?= , =?utf-8?q?Andreas_F=C3=A4rber?= , Rob Herring , Mark Rutland , devicetree@vger.kernel.org Subject: [RFC 1/3] dt-bindings: rtc: Add Realtek RTD1295 Date: Sun, 20 Aug 2017 03:36:29 +0200 Message-Id: <20170820013632.18375-2-afaerber@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170820013632.18375-1-afaerber@suse.de> References: <20170820013632.18375-1-afaerber@suse.de> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a binding for the RTC on the Realtek RTD119x/RTD129x SoC families. Signed-off-by: Andreas Färber --- .../devicetree/bindings/rtc/realtek,rtd119x.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt -- 2.12.3 diff --git a/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt b/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt new file mode 100644 index 000000000000..bbf1ccb5df31 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/realtek,rtd119x.txt @@ -0,0 +1,16 @@ +Realtek RTD129x Real-Time Clock +=============================== + +Required properties: +- compatible : Should be "realtek,rtd1295-rtc" +- reg : Specifies the physical base address and size +- clocks : Specifies the clock gate + + +Example: + + rtc@9801b600 { + compatible = "realtek,rtd1295-clk"; + reg = <0x9801b600 0x100>; + clocks = <&clkc RTD1295_CLK_EN_MISC_RTC>; + }; From patchwork Sun Aug 20 01:36:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 110468 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2677224qge; Sat, 19 Aug 2017 18:37:41 -0700 (PDT) X-Received: by 10.84.231.199 with SMTP id g7mr14850430pln.258.1503193061388; Sat, 19 Aug 2017 18:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503193061; cv=none; d=google.com; s=arc-20160816; b=vs9nUnWT97Pj0isp7E3Q4jrBNS8LOf9LVQNAA4iD3EqUt7+70qIJS6tSeMYwcPQNKG oOfZDNmLkYz3KywUEQuHTJ/yaaeEVedDSq90slFEbFHfT44YXq6aRs22/bmGxReOaqNJ VJPA4uSRrNS1sOrnYtM18xUBSOHwv2oEvQP/gFibOiDAJNjZ3+dVkLxJWjW6wmA4Q7ex k3U5oy368xZZnPXhMrGLEMYCRzVIFzQxEomM55UN3dxoRZIgxqtKegKLH30jPjPdpTUX zUvTBph4uqAtJro09ZzXxJLfl3Cev7APRxERR3G6vc9VTXrXgsPNDN2MrpCwV5RUw7fv x2Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=iWRCZWwugekL/+msM6102iyz+nQ887lEx1bib3GcDO4=; b=glvFNNYnTkE5XaXkMiKrg4RBR5z2bN4weo26eV5Txnnuz43qhAVyNN4p1XULUkIZrT Q9Cj53TsZ5VqRWyz/TYH0vjkOaRzPe6hd/v6v9yP7cpfvmxOi0B4F8EFomkhT7oL5CVx BMwbd5EUw1Egp6sQEddi4qLMVHBPBhy0T02fF2m8c2y4brImlI6YygONA705u2FENAe2 MV39IehMRglUg+IUf8JBajMhEYXbC614MH83PlHnbJeFZAi3W8dKQTj5yeZMKAwDZPGm sJE9kg7W8mqkF8pfFCx9dD2eEnUxbZ51N7q67FzNjEMWO2kxKUBZfZdkbhZV24KQkZ5N YJFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h132si5624407pfe.209.2017.08.19.18.37.40; Sat, 19 Aug 2017 18:37:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752614AbdHTBhh (ORCPT + 26 others); Sat, 19 Aug 2017 21:37:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:33183 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752509AbdHTBhc (ORCPT ); Sat, 19 Aug 2017 21:37:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0684FABED; Sun, 20 Aug 2017 01:37:31 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: Alessandro Zummo , Alexandre Belloni , linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Roc He , =?utf-8?b?6JKL?= =?utf-8?b?5Li955C0?= , =?utf-8?q?Andreas_F=C3=A4rber?= Subject: [RFC 2/3] rtc: Add Realtek RTD1295 Date: Sun, 20 Aug 2017 03:36:30 +0200 Message-Id: <20170820013632.18375-3-afaerber@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170820013632.18375-1-afaerber@suse.de> References: <20170820013632.18375-1-afaerber@suse.de> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on QNAP's mach-rtk119x/driver/rtk_rtc_drv.c code. Signed-off-by: Andreas Färber --- drivers/rtc/Kconfig | 8 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-rtd119x.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 drivers/rtc/rtc-rtd119x.c -- 2.12.3 diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 72419ac2c52a..882828b1b351 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1765,6 +1765,14 @@ config RTC_DRV_CPCAP Say y here for CPCAP rtc found on some Motorola phones and tablets such as Droid 4. +config RTC_DRV_RTD119X + bool "Realtek RTD129x RTC" + depends on ARCH_REALTEK || COMPILE_TEST + default ARCH_REALTEK + help + If you say yes here, you get support for the RTD1295 SoC + Real Time Clock. + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index acd366b41c85..55a0a5ca45b0 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -131,6 +131,7 @@ obj-$(CONFIG_RTC_DRV_RP5C01) += rtc-rp5c01.o obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o +obj-$(CONFIG_RTC_DRV_RTD119X) += rtc-rtd119x.o obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o obj-$(CONFIG_RTC_DRV_RV8803) += rtc-rv8803.o obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o diff --git a/drivers/rtc/rtc-rtd119x.c b/drivers/rtc/rtc-rtd119x.c new file mode 100644 index 000000000000..b532e127b56e --- /dev/null +++ b/drivers/rtc/rtc-rtd119x.c @@ -0,0 +1,175 @@ +/* + * Realtek RTD129x RTC + * + * Copyright (c) 2017 Andreas Färber + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include + +#define RTD_RTCSEC 0x00 +#define RTD_RTCMIN 0x04 +#define RTD_RTCHR 0x08 +#define RTD_RTCDATE_LOW 0x0c +#define RTD_RTCDATE_HIGH 0x10 +#define RTD_RTCACR 0x28 +#define RTD_RTCEN 0x2c + +struct rtd119x_rtc { + void __iomem *base; + struct clk *clk; + struct rtc_device *rtcdev; + unsigned base_year; +}; + +static void rtd119x_rtc_set_enabled(struct device *dev, bool enable) +{ + struct rtd119x_rtc *data = dev_get_drvdata(dev); + u32 val; + + val = readl_relaxed(data->base + RTD_RTCEN); + dev_info(dev, "%s: rtcen = 0x%08x\n", __func__, val); + if (enable) { + if ((val & 0xff) == 0x5a) + return; + writel_relaxed(0x5a, data->base + RTD_RTCEN); + } else { + writel_relaxed(0, data->base + RTD_RTCEN); + } +} + +static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct rtd119x_rtc *data = dev_get_drvdata(dev); + time64_t t; + u32 day; + + day = readl_relaxed(data->base + RTD_RTCDATE_LOW); + day |= readl_relaxed(data->base + RTD_RTCDATE_HIGH) << 8; + t = mktime64(data->base_year, 1, 1, 0, 0, 0); + t += day * 24 * 60 * 60; + rtc_time64_to_tm(t, tm); + tm->tm_sec = readl_relaxed(data->base + RTD_RTCSEC) >> 1; + tm->tm_min = readl_relaxed(data->base + RTD_RTCMIN); + tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR); + + return rtc_valid_tm(tm); +} + +static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct rtd119x_rtc *data = dev_get_drvdata(dev); + time64_t time_base, new_time, time_delta; + unsigned long day; + + if (tm->tm_year < data->base_year) + return -EINVAL; + + time_base = mktime64(data->base_year, 1, 1, 0, 0, 0); + new_time = rtc_tm_to_time64(tm); + time_delta = new_time - time_base; + day = time_delta / (24 * 60 * 60); + if (day > 0x7fff) + return -EINVAL; + + rtd119x_rtc_set_enabled(dev, false); + + writel_relaxed(tm->tm_sec, data->base + RTD_RTCSEC); + writel_relaxed(tm->tm_min, data->base + RTD_RTCMIN); + writel_relaxed(tm->tm_hour, data->base + RTD_RTCHR); + writel_relaxed(day & 0xff, data->base + RTD_RTCDATE_LOW); + writel_relaxed((day >> 8) & 0x7f, data->base + RTD_RTCDATE_HIGH); + + rtd119x_rtc_set_enabled(dev, true); + + return 0; +} + +static int rtd119x_rtc_open(struct device *dev) +{ + struct rtd119x_rtc *data = dev_get_drvdata(dev); + u32 val; + int ret; + + ret = clk_prepare_enable(data->clk); + if (ret) + return ret; + + val = readl_relaxed(data->base + RTD_RTCACR); + dev_info(dev, "rtcacr = 0x%08x\n", val); + if (!(val & BIT(7))) { + } + + rtd119x_rtc_set_enabled(dev, true); + + return 0; +} + +static void rtd119x_rtc_release(struct device *dev) +{ + struct rtd119x_rtc *data = dev_get_drvdata(dev); + + rtd119x_rtc_set_enabled(dev, false); + + clk_disable_unprepare(data->clk); +} + +static const struct rtc_class_ops rtd119x_rtc_ops = { + .open = rtd119x_rtc_open, + .release = rtd119x_rtc_release, + .read_time = rtd119x_rtc_read_time, + .set_time = rtd119x_rtc_set_time, +}; + +static const struct of_device_id rtd119x_rtc_dt_ids[] = { + { .compatible = "realtek,rtd1295-rtc" }, + { } +}; + +static int rtd119x_rtc_probe(struct platform_device *pdev) +{ + struct rtd119x_rtc *data; + struct resource *res; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + platform_set_drvdata(pdev, data); + data->base_year = 2014; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(data->base)) + return PTR_ERR(data->base); + + data->clk = of_clk_get(pdev->dev.of_node, 0); + if (IS_ERR(data->clk)) + return PTR_ERR(data->clk); + + data->rtcdev = devm_rtc_device_register(&pdev->dev, "rtc", + &rtd119x_rtc_ops, THIS_MODULE); + if (IS_ERR(data->rtcdev)) { + dev_err(&pdev->dev, "failed to register rtc device"); + clk_put(data->clk); + return PTR_ERR(data->rtcdev); + } + + return 0; +} + +static struct platform_driver rtd119x_rtc_driver = { + .probe = rtd119x_rtc_probe, + .driver = { + .name = "rtd1295-rtc", + .of_match_table = rtd119x_rtc_dt_ids, + }, +}; +builtin_platform_driver(rtd119x_rtc_driver);