From patchwork Wed Mar 5 19:29:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Cartwright X-Patchwork-Id: 327137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ob0-x239.google.com (mail-ob0-x239.google.com [IPv6:2607:f8b0:4003:c01::239]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BAFD62C00D2 for ; Thu, 6 Mar 2014 06:32:29 +1100 (EST) Received: by mail-ob0-f185.google.com with SMTP id wp18sf333507obc.2 for ; Wed, 05 Mar 2014 11:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:sender:list-subscribe:list-unsubscribe:content-type; bh=ESLBFFRjYLEdEztL6d8eZd+3qI3nrD0MHdWEaTbzS7Y=; b=XeLOTeSmWE+VZ0QFugcIHm6lLxO3bzFDuLdDCg2lq9Xhk8P8uhEdv7V2psGwm9QKwi PypclMaB1uWn8LJK4baXOzVVN7xvJlvSJw1oYbkCF5o/euVIQcVVDvHSETSzIt/34FyC FdRTAEs/dP7IVM4m3/kT/abk+yRLEHKEDPEDgikjz0chgK17d9x0lNarJceYfzGSs2gJ 7iDeQ1wUPKZDf3IkwoXlocPr/7hufCGHLZUxw2HfJ1exGIRTEYNuN8dRgO1jBuQbligF eopP0fweLQzEzH7NMTYbofhBbWjLwHWI57yTQm3iJsw836jNcmxWgHcH/3CIKNW5XXkZ GG2A== X-Received: by 10.140.39.145 with SMTP id v17mr41692qgv.36.1394047946347; Wed, 05 Mar 2014 11:32:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.140.51.130 with SMTP id u2ls423173qga.34.gmail; Wed, 05 Mar 2014 11:32:26 -0800 (PST) X-Received: by 10.58.218.40 with SMTP id pd8mr1083948vec.39.1394047946090; Wed, 05 Mar 2014 11:32:26 -0800 (PST) Received: from smtp.codeaurora.org (smtp.codeaurora.org. [198.145.11.231]) by gmr-mx.google.com with ESMTPS id g1si1320563pbw.2.2014.03.05.11.32.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Mar 2014 11:32:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of joshc@codeaurora.org designates 198.145.11.231 as permitted sender) client-ip=198.145.11.231; Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id D2F1F13F12D; Wed, 5 Mar 2014 19:32:25 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id C16AD13F142; Wed, 5 Mar 2014 19:32:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-caf-smtp.dmz.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=0.1 required=2.0 tests=ALL_TRUSTED,BAYES_00, KHOP_BIG_TO_CC autolearn=no version=3.3.1 Received: from joshc.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com [67.52.129.61]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: joshc@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3F97B13EF20; Wed, 5 Mar 2014 19:32:25 +0000 (UTC) Received: by joshc.qualcomm.com (Postfix, from userid 1000) id C3DE763550; Wed, 5 Mar 2014 13:29:37 -0600 (CST) From: Josh Cartwright To: Alessandro Zummo , David Brown , Daniel Walker , Bryan Huntsman , Grant Likely , Rob Herring Cc: linux-arm-msm@vger.kernel.org, Stephen Boyd , Samuel Ortiz , Lee Jones , linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com, devicetree@vger.kernel.org Subject: [rtc-linux] [PATCH 4/6] rtc: pm8xxx: add support for devicetree Date: Wed, 5 Mar 2014 13:29:34 -0600 Message-Id: <1394047776-13827-5-git-send-email-joshc@codeaurora.org> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394047776-13827-1-git-send-email-joshc@codeaurora.org> References: <1394047776-13827-1-git-send-email-joshc@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP X-Original-Sender: joshc@codeaurora.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of joshc@codeaurora.org designates 198.145.11.231 as permitted sender) smtp.mail=joshc@codeaurora.org Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Add support for describing the PM8921/PM8058 RTC in device tree. Additionally: - drop support for describing the RTC using platform data, as there are no current in tree users who do so. - make allow_set_time a device-specific flag, instead of mucking with the rtc_ops Signed-off-by: Josh Cartwright Reviewed-by: Stephen Boyd --- drivers/rtc/rtc-pm8xxx.c | 54 +++++++++++++++++++++++------------------- include/linux/mfd/pm8xxx/rtc.h | 25 ------------------- 2 files changed, 30 insertions(+), 49 deletions(-) delete mode 100644 include/linux/mfd/pm8xxx/rtc.h diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c index ed3fe83..cb5576f 100644 --- a/drivers/rtc/rtc-pm8xxx.c +++ b/drivers/rtc/rtc-pm8xxx.c @@ -9,7 +9,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ - +#include #include #include #include @@ -19,9 +19,6 @@ #include #include -#include - - /* RTC Register offsets from RTC CTRL REG */ #define PM8XXX_ALARM_CTRL_OFFSET 0x01 #define PM8XXX_RTC_WRITE_OFFSET 0x02 @@ -39,6 +36,7 @@ * struct pm8xxx_rtc - rtc driver internal structure * @rtc: rtc device for this driver. * @regmap: regmap used to access RTC registers + * @allow_set_time: indicates whether writing to the RTC is allowed * @rtc_alarm_irq: rtc alarm irq number. * @rtc_base: address of rtc control register. * @rtc_read_base: base address of read registers. @@ -51,6 +49,7 @@ struct pm8xxx_rtc { struct rtc_device *rtc; struct regmap *regmap; + bool allow_set_time; int rtc_alarm_irq; int rtc_base; int rtc_read_base; @@ -75,6 +74,9 @@ static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) u8 value[NUM_8_BIT_RTC_REGS], alarm_enabled = 0, ctrl_reg; struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); + if (!rtc_dd->allow_set_time) + return -EACCES; + rtc_tm_to_time(tm, &secs); for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) { @@ -291,8 +293,9 @@ rtc_rw_fail: return rc; } -static struct rtc_class_ops pm8xxx_rtc_ops = { +static const struct rtc_class_ops pm8xxx_rtc_ops = { .read_time = pm8xxx_rtc_read_time, + .set_time = pm8xxx_rtc_set_time, .set_alarm = pm8xxx_rtc_set_alarm, .read_alarm = pm8xxx_rtc_read_alarm, .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable, @@ -346,18 +349,26 @@ rtc_alarm_handled: return IRQ_HANDLED; } +/* + * Hardcoded RTC bases until IORESOURCE_REG mapping is figured out + */ +static const struct of_device_id pm8xxx_id_table[] = { + { .compatible = "qcom,pm8921-rtc", .data = (void *) 0x11D }, + { .compatible = "qcom,pm8058-rtc", .data = (void *) 0x1E8 }, + { }, +}; +MODULE_DEVICE_TABLE(of, pm8xxx_id_table); + static int pm8xxx_rtc_probe(struct platform_device *pdev) { int rc; unsigned int ctrl_reg; - bool rtc_write_enable = false; struct pm8xxx_rtc *rtc_dd; - struct resource *rtc_resource; - const struct pm8xxx_rtc_platform_data *pdata = - dev_get_platdata(&pdev->dev); + const struct of_device_id *match; - if (pdata != NULL) - rtc_write_enable = pdata->rtc_write_enable; + match = of_match_node(pm8xxx_id_table, pdev->dev.of_node); + if (!match) + return -ENXIO; rtc_dd = devm_kzalloc(&pdev->dev, sizeof(*rtc_dd), GFP_KERNEL); if (rtc_dd == NULL) @@ -372,20 +383,16 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev) return -ENXIO; } - rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0); + rtc_dd->rtc_alarm_irq = platform_get_irq_byname(pdev, "alarm"); if (rtc_dd->rtc_alarm_irq < 0) { dev_err(&pdev->dev, "Alarm IRQ resource absent!\n"); return -ENXIO; } - rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO, - "pmic_rtc_base"); - if (!(rtc_resource && rtc_resource->start)) { - dev_err(&pdev->dev, "RTC IO resource absent!\n"); - return -ENXIO; - } + rtc_dd->allow_set_time = of_property_read_bool(pdev->dev.of_node, + "linux,allow-set-time"); - rtc_dd->rtc_base = rtc_resource->start; + rtc_dd->rtc_base = (long) match->data; /* Setup RTC register addresses */ rtc_dd->rtc_write_base = rtc_dd->rtc_base + PM8XXX_RTC_WRITE_OFFSET; @@ -412,8 +419,6 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev) } rtc_dd->ctrl_reg = ctrl_reg; - if (rtc_write_enable) - pm8xxx_rtc_ops.set_time = pm8xxx_rtc_set_time; platform_set_drvdata(pdev, rtc_dd); @@ -472,9 +477,10 @@ static SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, static struct platform_driver pm8xxx_rtc_driver = { .probe = pm8xxx_rtc_probe, .driver = { - .name = PM8XXX_RTC_DEV_NAME, - .owner = THIS_MODULE, - .pm = &pm8xxx_rtc_pm_ops, + .name = "rtc-pm8xxx", + .owner = THIS_MODULE, + .pm = &pm8xxx_rtc_pm_ops, + .of_match_table = pm8xxx_id_table, }, }; diff --git a/include/linux/mfd/pm8xxx/rtc.h b/include/linux/mfd/pm8xxx/rtc.h deleted file mode 100644 index 14f1983..0000000 --- a/include/linux/mfd/pm8xxx/rtc.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef __RTC_PM8XXX_H__ -#define __RTC_PM8XXX_H__ - -#define PM8XXX_RTC_DEV_NAME "rtc-pm8xxx" -/** - * struct pm8xxx_rtc_pdata - RTC driver platform data - * @rtc_write_enable: variable stating RTC write capability - */ -struct pm8xxx_rtc_platform_data { - bool rtc_write_enable; -}; - -#endif /* __RTC_PM8XXX_H__ */