Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp29845lfe; Fri, 15 Apr 2022 17:57:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH+YyBSdbzKNUjddOYFSJYL6TOTFXP5mTN+giSUOOPa3jrq9+FV/DdNKUQO0ULv+JswDcC X-Received: by 2002:a17:902:7e85:b0:158:c12f:d662 with SMTP id z5-20020a1709027e8500b00158c12fd662mr1298780pla.141.1650070650077; Fri, 15 Apr 2022 17:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650070650; cv=none; d=google.com; s=arc-20160816; b=okiN899oxVl7Jg8hXQ/wdKvtx6iDxPcnMZ0qSQQlpwH/onuZGzsMYKcXjx7sPHpt+i XA+B3pagfjN88XpZJjgJ+Bh098vXgF5DV9g0Vdb2Q3Nc9WfyuOIImh+V2yDaD0aXXZaz nCX7gcMgGM3IyksrR44NOuzqrCuulIbwxEiKIPIx4ooz87qN+c+geHW9U7NYboQA3fVZ 1ekLLEuRrULdej/ZkN4hs1NEDjLQrFvfvDqyKQJgh9W8TCQLNcoNg4Vmqy5WqgzGBika 9k2ZIt4z+PumVvltBOCUbNe/g0ZIK+L9xy/ZxKu5VUMZRwKOh8Ys4L6Jtyc8DIfvLrCE 3d4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=NTy+10/rvDVv3oXf+hx+iRizmeAw7E8r66BdzQEdhq4=; b=sglj5Rlu+Y4RnJ6kcHphnV8fruXpjXI6XXzUL1pKdNjyGMrgoHmEOoI/KtjmCCUwkh LBAxfkNaFvIbkwan1As/ZBAFmzLfFSCH3kq9BLsxTALriXIGKbuKxOI75WYQe1Lf/o7M A1sW4yEltVdc5n5S2ljh/2fGixH0VgyAkyJy2PgtJSK6qrXbnEIESWf7AHbgp5maQBJI 1+WIGSZKb3E1ZHXu6R+GFzrG/ytceeVj0wJrTM+PDFq55Yk4Ze/v59KPbwpUtZqciG3C Neq/hw/gDvHgjjc3KtIIFjaaoz0wviHUwDc/FjwhbsH6C685fIjQMiqgZ7fwpg3XPqFJ KkxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=lsgpdF1F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s205-20020a632cd6000000b0039e0b605012si2948765pgs.19.2022.04.15.17.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:57:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=lsgpdF1F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C00B2DD78; Fri, 15 Apr 2022 17:43:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351293AbiDOIGL (ORCPT + 99 others); Fri, 15 Apr 2022 04:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244921AbiDOIGJ (ORCPT ); Fri, 15 Apr 2022 04:06:09 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A0159A61; Fri, 15 Apr 2022 01:03:40 -0700 (PDT) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 23F83J9P130367; Fri, 15 Apr 2022 03:03:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1650009799; bh=NTy+10/rvDVv3oXf+hx+iRizmeAw7E8r66BdzQEdhq4=; h=Date:Subject:To:CC:References:From:In-Reply-To; b=lsgpdF1FJ4rrxua3gRmJL4ijFC0xjqwg+yoeNRIs7RAZg7aCcKfkFLO+rKrxvK3jZ pCCSHj1sbaeeuTEvQbhDXS5kBoaxp+4lMVDtD5UKa0XQr1Nw22H2SVTD/98dPFF7cI uZ1W7QA7Gv4Zv+e8s/Eo3mNXBigRf3xqzicj7G80= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 23F83J0n002373 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 15 Apr 2022 03:03:19 -0500 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Fri, 15 Apr 2022 03:03:19 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Fri, 15 Apr 2022 03:03:19 -0500 Received: from [10.250.235.115] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 23F83Fn4088810; Fri, 15 Apr 2022 03:03:16 -0500 Message-ID: Date: Fri, 15 Apr 2022 13:33:14 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH 2/2] rtc: Introduce ti-k3-rtc Content-Language: en-US To: Nishanth Menon , Krzysztof Kozlowski , Rob Herring , Alexandre Belloni , Alessandro Zummo CC: , , , References: <20220412073138.25027-1-nm@ti.com> <20220412073138.25027-3-nm@ti.com> From: Vignesh Raghavendra In-Reply-To: <20220412073138.25027-3-nm@ti.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 12/04/22 1:01 pm, Nishanth Menon wrote: > +/** > + * k3rtc_fence - Ensure a register sync took place between the two domains > + * @priv: pointer to priv data > + * > + * Return: 0 if the sync took place, else returns -ETIMEDOUT > + */ > +static int k3rtc_fence(struct ti_k3_rtc *priv) > +{ > + u32 timeout = priv->sync_timeout_us; > + u32 mask = K3RTC_RD_PEND_BIT | K3RTC_WR_PEND_BIT; > + u32 val = 0; > + > + while (timeout--) { > + val = k3rtc_readl(priv, REG_K3RTC_SYNCPEND); > + if (!(val & mask)) > + return 0; > + usleep_range(1, 2); > + } readl_poll_timeout() ? > + > + pr_err("RTC Fence timeout: 0x%08x\n", val); Can we use dev_err()? Provides better indication of the driver throwing error. > + return -ETIMEDOUT; > +} > + > +static inline int k3rtc_check_unlocked(struct ti_k3_rtc *priv) > +{ > + u32 val; > + > + val = k3rtc_readl(priv, REG_K3RTC_GENERAL_CTL); > + return (val & K3RTC_UNLOCK_BIT) ? 0 : 1; > +} > + > +static int k3rtc_unlock_rtc(struct ti_k3_rtc *priv) > +{ > + u32 timeout = priv->sync_timeout_us; > + int ret; > + > + ret = k3rtc_check_unlocked(priv); > + if (!ret) > + return ret; > + > + k3rtc_writel(priv, REG_K3RTC_KICK0, K3RTC_KICK0_UNLOCK_VALUE); > + k3rtc_writel(priv, REG_K3RTC_KICK1, K3RTC_KICK1_UNLOCK_VALUE); > + > + /* Skip fence since we are going to check the unlock bit as fence */ > + while (timeout--) { > + ret = k3rtc_check_unlocked(priv); > + if (!ret) > + return ret; > + usleep_range(1, 2); > + } readl_poll_timeout() ? > + > + return -ETIMEDOUT; > +} > + > +static int k3rtc_configure(struct device *dev) > +{ > + int ret; > + u32 ctl; > + struct ti_k3_rtc *priv = dev_get_drvdata(dev); > + > + /* > + * HWBUG: The compare statemachine is broken if the RTC module > + * is NOT unlocked in under one second of boot - which is pretty long > + * time from the perspective of Linux driver (module load, u-boot > + * shell all can take much longer than this. > + * > + * In such occurrence, it is assumed that the RTC module is un-usable > + */ > + if (priv->soc->unlock_irq_erratum) { > + ret = k3rtc_check_unlocked(priv); > + /* If there is an error OR if we are locked, return error */ > + if (ret) { > + dev_err(dev, HW_ERR "Erratum i2327 unlock QUIRK! Cannot operate!!\n"); > + return -EFAULT; > + } > + } else { > + /* May Need to explicitly unlock first time */ > + ret = k3rtc_unlock_rtc(priv); > + if (ret) { > + dev_err(dev, "Failed to unlock(%d)!\n", ret); > + return ret; > + } > + } > + > + /* Enable Shadow register sync on 32k clk boundary */ > + ctl = k3rtc_readl(priv, REG_K3RTC_GENERAL_CTL); > + ctl |= K3RTC_O32K_OSC_DEP_EN_BIT; > + k3rtc_writel(priv, REG_K3RTC_GENERAL_CTL, ctl); > + > + /* > + * Wait at least 2 clk sync time before proceeding further programming. > + * This ensures that the 32k based sync is active. > + */ > + usleep_range(priv->sync_timeout_us, priv->sync_timeout_us + 5); > + > + /* We need to ensure fence here to make sure sync here */ > + ret = k3rtc_fence(priv); > + if (ret) { > + dev_err(dev, "Failed fence osc_dep enable(%d) - is 32k clk working?!\n", > + ret); > + return ret; > + } > + > + /* Lets just make sure we get consistent time value */ > + ctl &= ~K3RTC_CNT_FMODE_MASK; > + /* > + * FMODE setting: Reading lower seconds will freeze value on higher > + * seconds. This also implies that we must *ALWAYS* read lower seconds > + * prior to reading higher seconds > + */ > + ctl |= K3RTC_CNT_FMODE_S_CNT_VALUE; > + k3rtc_writel(priv, REG_K3RTC_GENERAL_CTL, ctl); > + > + /* Clear any spurious IRQ sources if any */ > + k3rtc_writel(priv, REG_K3RTC_IRQSTATUS_SYS, > + K3RTC_EVENT_ON_OFF_BIT | K3RTC_EVENT_OFF_ON_BIT); > + /* Disable all IRQs */ > + k3rtc_writel(priv, REG_K3RTC_IRQENABLE_CLR_SYS, > + K3RTC_EVENT_ON_OFF_BIT | K3RTC_EVENT_OFF_ON_BIT); > + > + /* And.. Let us Sync the writes in */ > + ret = k3rtc_fence(priv); > + if (ret) { > + dev_err(dev, "Failed to fence(%d)!\n", ret); > + return ret; nit: this can be dropped as next statement will return error code anyway > + } > + > + return ret; > +} > + [...] > + > +static const struct ti_k3_rtc_soc_data ti_k3_am62_data = { > + .unlock_irq_erratum = true, > +}; > + > +static const struct of_device_id ti_k3_rtc_of_match_table[] = { > + {.compatible = "ti,am62-rtc", .data = &ti_k3_am62_data}, > + {} > +}; > +MODULE_DEVICE_TABLE(of, ti_k3_rtc_of_match_table); > + > +#ifdef CONFIG_PM_SLEEP > +static int ti_k3_rtc_suspend(struct device *dev) __maybe_unused preferred instead of #ifdef for better compile coverage but upto you. > +{ > + struct ti_k3_rtc *priv = dev_get_drvdata(dev); > + > + if (device_may_wakeup(dev)) > + enable_irq_wake(priv->irq); > + return 0; > +} > + > +static int ti_k3_rtc_resume(struct device *dev) > +{ > + struct ti_k3_rtc *priv = dev_get_drvdata(dev); > + > + if (device_may_wakeup(dev)) > + disable_irq_wake(priv->irq); > + return 0; > +} > +#endif > + > +static SIMPLE_DEV_PM_OPS(ti_k3_rtc_pm_ops, ti_k3_rtc_suspend, ti_k3_rtc_resume); > + > +static struct platform_driver ti_k3_rtc_driver = { > + .probe = ti_k3_rtc_probe, > + .driver = { > + .name = "rtc-ti-k3", > + .of_match_table = ti_k3_rtc_of_match_table, > + .pm = &ti_k3_rtc_pm_ops, > + }, Extra tab? > +}; > +module_platform_driver(ti_k3_rtc_driver); > + > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("TI K3 RTC driver"); > +MODULE_AUTHOR("Nishanth Menon"); > +MODULE_ALIAS("platform:rtc-ti-k3"); > -- 2.31.1