From patchwork Fri Aug 14 11:07:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 11714367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A5AE14F6 for ; Fri, 14 Aug 2020 11:07:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69E8A2078D for ; Fri, 14 Aug 2020 11:07:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbgHNLHk (ORCPT ); Fri, 14 Aug 2020 07:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726576AbgHNLHi (ORCPT ); Fri, 14 Aug 2020 07:07:38 -0400 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DECFC061389 for ; Fri, 14 Aug 2020 04:07:37 -0700 (PDT) Received: from ramsan ([84.195.186.194]) by albert.telenet-ops.be with bizsmtp id FP7Y2300P4C55Sk06P7YYG; Fri, 14 Aug 2020 13:07:33 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1k6XYa-0003r9-Cb; Fri, 14 Aug 2020 13:07:32 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1k6XYa-0007Z4-Bj; Fri, 14 Aug 2020 13:07:32 +0200 From: Geert Uytterhoeven To: Alessandro Zummo , Alexandre Belloni Cc: Nobuhiro Iwamatsu , kogiidena , Adrian Glaubitz , linux-rtc@vger.kernel.org, linux-sh@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/3] rtc: rtc-rs5c313: Fix late hardware init Date: Fri, 14 Aug 2020 13:07:30 +0200 Message-Id: <20200814110731.29029-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200814110731.29029-1-geert+renesas@glider.be> References: <20200814110731.29029-1-geert+renesas@glider.be> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org rs5c313_rtc_init() calls platform_driver_register(), and initializes the hardware. This is wrong because of two reasons: 1. As soon as the driver has been registered, the device may be probed. If devm_rtc_device_register() is called before hardware initialization, reading the current time will fail: rs5c313 rs5c313: rs5c313_rtc_read_time: timeout error rs5c313 rs5c313: registered as rtc0 rs5c313 rs5c313: rs5c313_rtc_read_time: timeout error rs5c313 rs5c313: hctosys: unable to read the hardware clock 2. If the platform device does not exist, the driver will still write to a hardware device that may not be present. Fix this by moving the hardware initialization sequence to the driver's .probe() method. Signed-off-by: Geert Uytterhoeven --- drivers/rtc/rtc-rs5c313.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c index 00b5ef753935ec8a..af72e428b218173e 100644 --- a/drivers/rtc/rtc-rs5c313.c +++ b/drivers/rtc/rtc-rs5c313.c @@ -366,8 +366,13 @@ static const struct rtc_class_ops rs5c313_rtc_ops = { static int rs5c313_rtc_probe(struct platform_device *pdev) { - struct rtc_device *rtc = devm_rtc_device_register(&pdev->dev, "rs5c313", - &rs5c313_rtc_ops, THIS_MODULE); + struct rtc_device *rtc; + + rs5c313_init_port(); + rs5c313_check_xstp_bit(); + + rtc = devm_rtc_device_register(&pdev->dev, "rs5c313", &rs5c313_rtc_ops, + THIS_MODULE); return PTR_ERR_OR_ZERO(rtc); } @@ -381,16 +386,7 @@ static struct platform_driver rs5c313_rtc_platform_driver = { static int __init rs5c313_rtc_init(void) { - int err; - - err = platform_driver_register(&rs5c313_rtc_platform_driver); - if (err) - return err; - - rs5c313_init_port(); - rs5c313_check_xstp_bit(); - - return 0; + return platform_driver_register(&rs5c313_rtc_platform_driver); } static void __exit rs5c313_rtc_exit(void)