From patchwork Tue Oct 21 17:37:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 5127401 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E4C9A9F387 for ; Tue, 21 Oct 2014 17:58:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C9F3F2021F for ; Tue, 21 Oct 2014 17:58:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CAE8E200E8 for ; Tue, 21 Oct 2014 17:58:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XgdeW-0005Yc-03; Tue, 21 Oct 2014 17:55:24 +0000 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XgdXj-0004gy-6A for linux-arm-kernel@lists.infradead.org; Tue, 21 Oct 2014 17:48:24 +0000 Received: by mail-la0-f51.google.com with SMTP id ge10so1498228lab.10 for ; Tue, 21 Oct 2014 10:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gXTnB5JF40dPxfQAHbp1ipFwiteExkCwnBo/Su9/Bjo=; b=IHtRGiv7a1yV/WaQBlLToJrh68Z9PGeVfSLDSChy7+uVja5M+F3EZHsNPVGUx2/Pdi Mfn3Yrufh53erBnivgHxSgoDDERSiAeUubf0FP+IDXJliQ5HNatSS0alz5hD/FFG1vjn SXb70NNhkIDTdTUN4qaTT2qrg9i1Yu38gqXwEHadhjOB5bGm/aCFoW3GknhLDI+55I6X yeoB59XEAbSpbhdPKmX/tUwN8VjSOWIB6Y+zHmDvscNDRCiGApayE/yxPaH7jdKgZtlY AzJO4/N3JWznScFGkDkDv5UllMHEVibiPWQ45Tb8jzpYWgtooHpSQfV9q45OtSvvSqzc F0Ag== X-Received: by 10.112.73.37 with SMTP id i5mr833838lbv.83.1413913680459; Tue, 21 Oct 2014 10:48:00 -0700 (PDT) Received: from xi.terra (s83-177-171-8.cust.tele2.se. [83.177.171.8]) by mx.google.com with ESMTPSA id qg4sm4807007lbb.36.2014.10.21.10.47.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2014 10:47:59 -0700 (PDT) X-Google-Original-Sender: Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1XgdRO-0003Nf-1x; Tue, 21 Oct 2014 19:41:50 +0200 From: Johan Hovold To: Alessandro Zummo , Tony Lindgren , =?UTF-8?q?Beno=C3=AEt=20Cousson?= , Felipe Balbi Subject: [PATCH v2 11/20] rtc: omap: add structured device-type info Date: Tue, 21 Oct 2014 19:37:57 +0200 Message-Id: <1413913086-12730-12-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1413913086-12730-1-git-send-email-johan@kernel.org> References: <1412881594-25678-1-git-send-email-johan@kernel.org> <1413913086-12730-1-git-send-email-johan@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141021_104823_707263_6C1925F8 X-CRM114-Status: GOOD ( 19.82 ) X-Spam-Score: -0.7 (/) Cc: devicetree@vger.kernel.org, rtc-linux@googlegroups.com, Lokesh Vutla , j-keerthy@ti.com, nsekhar@ti.com, linux-kernel@vger.kernel.org, Johan Hovold , t-kristo@ti.com, linux-arm-kernel@lists.infradead.org, Andrew Morton , linux-omap@vger.kernel.org, Guenter Roeck X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add structured device-type info to encode IP-block revision differences. Signed-off-by: Johan Hovold --- drivers/rtc/rtc-omap.c | 103 ++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index f70ae660368b..1abd88e24c22 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c @@ -102,19 +102,11 @@ #define KICK0_VALUE 0x83e70b13 #define KICK1_VALUE 0x95a4f1e0 -#define OMAP_RTC_HAS_KICKER BIT(0) - -/* - * Few RTC IP revisions has special WAKE-EN Register to enable Wakeup - * generation for event Alarm. - */ -#define OMAP_RTC_HAS_IRQWAKEEN BIT(1) - -/* - * Some RTC IP revisions (like those in AM335x and DRA7x) need - * the 32KHz clock to be explicitly enabled. - */ -#define OMAP_RTC_HAS_32KCLK_EN BIT(2) +struct omap_rtc_device_type { + bool has_32kclk_en; + bool has_kicker; + bool has_irqwakeen; +}; struct omap_rtc { struct rtc_device *rtc; @@ -122,7 +114,7 @@ struct omap_rtc { int irq_alarm; int irq_timer; u8 interrupts_reg; - unsigned long flags; + const struct omap_rtc_device_type *type; }; static inline u8 rtc_read(struct omap_rtc *rtc, unsigned int reg) @@ -190,7 +182,7 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) local_irq_disable(); rtc_wait_not_busy(rtc); reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); - if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) + if (rtc->type->has_irqwakeen) irqwake_reg = rtc_read(rtc, OMAP_RTC_IRQWAKEEN); if (enabled) { @@ -202,7 +194,7 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) } rtc_wait_not_busy(rtc); rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); - if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) + if (rtc->type->has_irqwakeen) rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); local_irq_enable(); @@ -326,7 +318,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) rtc_write(rtc, OMAP_RTC_ALARM_SECONDS_REG, alm->time.tm_sec); reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); - if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) + if (rtc->type->has_irqwakeen) irqwake_reg = rtc_read(rtc, OMAP_RTC_IRQWAKEEN); if (alm->enabled) { @@ -337,7 +329,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; } rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); - if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) + if (rtc->type->has_irqwakeen) rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); local_irq_enable(); @@ -353,34 +345,45 @@ static struct rtc_class_ops omap_rtc_ops = { .alarm_irq_enable = omap_rtc_alarm_irq_enable, }; -#define OMAP_RTC_DATA_AM3352_IDX 1 -#define OMAP_RTC_DATA_DA830_IDX 2 +static const struct omap_rtc_device_type omap_rtc_default_type = { +}; + +static const struct omap_rtc_device_type omap_rtc_am3352_type = { + .has_32kclk_en = true, + .has_kicker = true, + .has_irqwakeen = true, +}; + +static const struct omap_rtc_device_type omap_rtc_da830_type = { + .has_kicker = true, +}; -static const struct platform_device_id omap_rtc_devtype[] = { +static const struct platform_device_id omap_rtc_id_table[] = { { .name = "omap_rtc", - }, - [OMAP_RTC_DATA_AM3352_IDX] = { + .driver_data = (kernel_ulong_t)&omap_rtc_default_type, + }, { .name = "am3352-rtc", - .driver_data = OMAP_RTC_HAS_KICKER | OMAP_RTC_HAS_IRQWAKEEN | - OMAP_RTC_HAS_32KCLK_EN, - }, - [OMAP_RTC_DATA_DA830_IDX] = { + .driver_data = (kernel_ulong_t)&omap_rtc_am3352_type, + }, { .name = "da830-rtc", - .driver_data = OMAP_RTC_HAS_KICKER, - }, - {}, + .driver_data = (kernel_ulong_t)&omap_rtc_da830_type, + }, { + /* sentinel */ + } }; -MODULE_DEVICE_TABLE(platform, omap_rtc_devtype); +MODULE_DEVICE_TABLE(platform, omap_rtc_id_table); static const struct of_device_id omap_rtc_of_match[] = { - { .compatible = "ti,da830-rtc", - .data = &omap_rtc_devtype[OMAP_RTC_DATA_DA830_IDX], - }, - { .compatible = "ti,am3352-rtc", - .data = &omap_rtc_devtype[OMAP_RTC_DATA_AM3352_IDX], - }, - {}, + { + .compatible = "ti,am3352-rtc", + .data = &omap_rtc_am3352_type, + }, { + .compatible = "ti,da830-rtc", + .data = &omap_rtc_da830_type, + }, { + /* sentinel */ + } }; MODULE_DEVICE_TABLE(of, omap_rtc_of_match); @@ -398,17 +401,13 @@ static int __init omap_rtc_probe(struct platform_device *pdev) return -ENOMEM; of_id = of_match_device(omap_rtc_of_match, &pdev->dev); - if (of_id) - pdev->id_entry = of_id->data; - - id_entry = platform_get_device_id(pdev); - if (!id_entry) { - dev_err(&pdev->dev, "no matching device entry\n"); - return -ENODEV; + if (of_id) { + rtc->type = of_id->data; + } else { + id_entry = platform_get_device_id(pdev); + rtc->type = (void *)id_entry->driver_data; } - rtc->flags = id_entry->driver_data; - rtc->irq_timer = platform_get_irq(pdev, 0); if (rtc->irq_timer <= 0) return -ENOENT; @@ -428,7 +427,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev); - if (rtc->flags & OMAP_RTC_HAS_KICKER) { + if (rtc->type->has_kicker) { rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE); rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE); } @@ -441,7 +440,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev) rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 0); /* enable RTC functional clock */ - if (rtc->flags & OMAP_RTC_HAS_32KCLK_EN) { + if (rtc->type->has_32kclk_en) { reg = rtc_read(rtc, OMAP_RTC_OSC_REG); rtc_writel(rtc, OMAP_RTC_OSC_REG, reg | OMAP_RTC_OSC_32KCLK_EN); @@ -511,7 +510,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev) err: device_init_wakeup(&pdev->dev, false); - if (rtc->flags & OMAP_RTC_HAS_KICKER) + if (rtc->type->has_kicker) rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); @@ -528,7 +527,7 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) /* leave rtc running, but disable irqs */ rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); - if (rtc->flags & OMAP_RTC_HAS_KICKER) + if (rtc->type->has_kicker) rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); /* Disable the clock/module */ @@ -594,7 +593,7 @@ static struct platform_driver omap_rtc_driver = { .pm = &omap_rtc_pm_ops, .of_match_table = omap_rtc_of_match, }, - .id_table = omap_rtc_devtype, + .id_table = omap_rtc_id_table, }; module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe);