Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp937181pxb; Wed, 27 Oct 2021 15:36:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjGMRS5XJ13WsL3bq9Pk/oWhyb/xgH2a7V1OWixGOVsP4sPGWQ2gxtdct66w7O23GDLhTC X-Received: by 2002:a17:90b:4a8d:: with SMTP id lp13mr8733374pjb.240.1635374213126; Wed, 27 Oct 2021 15:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635374213; cv=none; d=google.com; s=arc-20160816; b=UXdfuSxyOC93vRrpNK2ptndixnCfRGu/egO4CflSud6CpVcGSamV7Hsu14/7tQON6r FrNtLEdtPZAK9GkXpe8DDYW2dgNM94QBG7KnCtMxKwvgJOad/uJa613KlxiHGXZvgugd cXQIy43jflGc8uO3u+Bw55PXzctbjuOvrZpriqB71PTIyfaZav59dKZTgF1VhIRZtqaj bb9TON96aSqKI3A3JAE9gFD5ZCpZItCCCTJlF9iRF1eXlvVvzAftQNNcuxmYJsqG3QAi j+8lvrI0IYmq9WykqhjgvAxsKEDkPfQE2EHYOLadhxZl4YuePDtAu+LNT4iC84eEAp81 JzYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ZOr7bYo69LekIML9Lu/GalT6JdIu+9sWHItg35lBKvc=; b=jnImoIJwe2lcYptm6kbufqgm5jPQ0vXbKA4guUpUXn9rf5oFM3sc+o6OhIrA+EyHo2 xJPag0mmBxZ6nnMimWFeN4VEiNrfXaMTW5pZzVjqWn54Vk2g6JP/8VW5sJT/vhzzKfNT WETetafT3Gww5Sg9SvEFCWhZWvwmLtQUH2XvUX7PF1W/46VOWOdwmgZtkpwNF8Nd7NDV qIK1GY02xngVWYHhjVU3Whx7AmCW/NPyrXW0So2DJ+HXvbw2VhMO0gR1ScvLSk9jM2yk JeOTTWSj3YOYsLFLPc3KH/kci2a4YORbK81yDpmnctxgluBc9NYM2uAacicgpP0noPx+ 6MRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si2063160pgj.102.2021.10.27.15.36.41; Wed, 27 Oct 2021 15:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbhJ0Wh7 (ORCPT + 99 others); Wed, 27 Oct 2021 18:37:59 -0400 Received: from 82-65-109-163.subs.proxad.net ([82.65.109.163]:57426 "EHLO luna.linkmauve.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbhJ0Whz (ORCPT ); Wed, 27 Oct 2021 18:37:55 -0400 Received: by luna.linkmauve.fr (Postfix, from userid 1000) id 0C0E3F40CA3; Thu, 28 Oct 2021 00:35:23 +0200 (CEST) From: Emmanuel Gil Peyrot To: Alexandre Belloni , Alessandro Zummo Cc: Emmanuel Gil Peyrot , rw-r-r-0644 , Ash Logan , =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= , Rob Herring , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org Subject: [PATCH v2 2/5] rtc: gamecube: Report low battery as invalid data Date: Thu, 28 Oct 2021 00:35:12 +0200 Message-Id: <20211027223516.2031-3-linkmauve@linkmauve.fr> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211027223516.2031-1-linkmauve@linkmauve.fr> References: <20211014220524.9988-1-linkmauve@linkmauve.fr> <20211027223516.2031-1-linkmauve@linkmauve.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I haven’t been able to test this patch as all of my consoles have a working RTC battery, but according to the documentation it should work like that. Signed-off-by: Emmanuel Gil Peyrot --- drivers/rtc/rtc-gamecube.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c index e8260c82c07d..1932c6fe1301 100644 --- a/drivers/rtc/rtc-gamecube.c +++ b/drivers/rtc/rtc-gamecube.c @@ -83,6 +83,10 @@ #define RTC_CONTROL0 0x21000c #define RTC_CONTROL1 0x21000d +/* RTC flags */ +#define RTC_CONTROL0_UNSTABLE_POWER 0x00000800 +#define RTC_CONTROL0_LOW_BATTERY 0x00000200 + struct priv { struct regmap *regmap; void __iomem *iob; @@ -182,9 +186,35 @@ static int gamecube_rtc_set_time(struct device *dev, struct rtc_time *t) return regmap_write(d->regmap, RTC_COUNTER, timestamp - d->rtc_bias); } +static int gamecube_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) +{ + struct priv *d = dev_get_drvdata(dev); + int value; + int control0; + int ret; + + switch (cmd) { + case RTC_VL_READ: + ret = regmap_read(d->regmap, RTC_CONTROL0, &control0); + if (ret) + return ret; + + value = 0; + if (control0 & RTC_CONTROL0_UNSTABLE_POWER) + value |= RTC_VL_DATA_INVALID; + if (control0 & RTC_CONTROL0_LOW_BATTERY) + value |= RTC_VL_DATA_INVALID; + return put_user(value, (unsigned int __user *)arg); + + default: + return -ENOIOCTLCMD; + } +} + static const struct rtc_class_ops gamecube_rtc_ops = { .read_time = gamecube_rtc_read_time, .set_time = gamecube_rtc_set_time, + .ioctl = gamecube_rtc_ioctl, }; static int gamecube_rtc_read_offset_from_sram(struct priv *d) -- 2.33.1