Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1847874imj; Fri, 8 Feb 2019 08:18:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IbR6bOvN0oZpdAFO4aQxEojIVi1tnpAkrMQrsibgWO+ai5SM93IGkf47urr0HRb2HLANI2l X-Received: by 2002:a63:db08:: with SMTP id e8mr2172392pgg.293.1549642691073; Fri, 08 Feb 2019 08:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549642691; cv=none; d=google.com; s=arc-20160816; b=blAWgnPsnJkNedG9hDkjlPOYYcwlG83aY+Eaor8MRFwA/nBnUlbvsTDgW9RgVrdmCY Zt98cV2lFUY9y6DeH983V/r2RRc7/VsX5dvCMWnTkZj6B2SYypjGfXl2jS2rlP2IDMPw oSvTwXOy9pmcSMAr6VDX6YTRVl9yQzDTtIsMQS12A8R89eA/HRnTC+PPlYJDVXUMS7L5 d/ZYFc+mqjHlAjaOTyksjaJj1AtlGXP6oQhOzMPafh1nmQoBIKd1qUGGoTfeoCzMzS6z mF/qqfjN8SqD96RS5oYTxfrNY9tB3JeSVIVB4P+oKjEtFftu4R3dfflj2Y7cET2JzAJV fqGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=jhZtSJAcBhmE7YasiOEJ15FKE8+gEUK/fd/qP/8duyQ=; b=R0kWcQqPbyXXru9glEqr2qBeoPyMl6o1R1/2fqphW/ee6ko0V+ymnz9jaODxTqMMp+ KB7288t3T3kblL24m8B7gEMRp2od9aVOsjJew1PqHmAEaaloAs1NbeJ7JIg8aVcpvmqP 9OYGfK+8INhiXsg1E8MLe2imcgzqej7Q4DyScSg5WWEW0CwCIxCgxtjnNHuZEv17oJ90 ni3Eux4xZOcG/4n81WbjdNsn1Othn0vMLYjgSCXgDqFH8pTu8bOAFduX2mtRUNmfNyRO tbtl8VosKMrEHNw93Ah7XroGnDnIvkhyortdv2IBu6Uf/a3wX7TwAhwYqeSBla1GRB2D PfkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si2714869plm.3.2019.02.08.08.17.55; Fri, 08 Feb 2019 08:18:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727669AbfBHQQL (ORCPT + 99 others); Fri, 8 Feb 2019 11:16:11 -0500 Received: from relay10.mail.gandi.net ([217.70.178.230]:49295 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726522AbfBHQQL (ORCPT ); Fri, 8 Feb 2019 11:16:11 -0500 Received: from localhost (alyon-652-1-53-40.w109-213.abo.wanadoo.fr [109.213.164.40]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 7F31B240003; Fri, 8 Feb 2019 16:16:06 +0000 (UTC) Date: Fri, 8 Feb 2019 17:16:05 +0100 From: Alexandre Belloni To: Enric Balletbo i Serra Cc: Nick Crews , linux-kernel@vger.kernel.org, eballetbo@gmail.com, sjg@chromium.org, dmitry.torokhov@gmail.com, groeck@chromium.org, dlaurie@chromium.org, Duncan Laurie , linux-rtc@vger.kernel.org, Alessandro Zummo , Benson Leung Subject: Re: [PATCH v6 4/4] platform/chrome: rtc: Add RTC driver Message-ID: <20190208161605.GD23062@piout.net> References: <20190208012312.105259-1-ncrews@chromium.org> <20190208012312.105259-5-ncrews@chromium.org> <4620e71f-9579-0d4e-2cf8-7851e77e81fc@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4620e71f-9579-0d4e-2cf8-7851e77e81fc@collabora.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/02/2019 13:18:38+0100, Enric Balletbo i Serra wrote: > > Changes in v6: > > - In the core, actually unregister the RTC child platform_device. > > > > Changes in v5: None > > Changes in v4: > > - Change me email to @chromium.org from @google.com > > - Move "Add RTC driver" before "Add sysfs attributes" so that > > it could get accepted earlier, since it is less contentious > > > > Changes in v3: > > - rm #define for driver name > > - Don't compute weekday when reading from RTC. > > Still set weekday when writing, as RTC needs this > > to control advanced power scheduling > > - rm check for invalid month data > > - Set range_min and range_max on rtc_device > > > > Changes in v2: > > - rm license boiler plate > > - rm "wilco_ec_rtc -" prefix in docstring > > - Make rtc driver its own module within the drivers/rtc/ directory > > - Register a rtc device from core.c that is picked up by this driver > > > > drivers/platform/chrome/wilco_ec/core.c | 22 ++- > > Alexandre, this specific patch depends on the patches of the series to apply, > and the first patches of the series also conflicts/depends on some patches > queued in chrome-platform-5.1 branch [1]. Is it fine with you if I create an > immutable branch and all go via your tree? Or what do you think? I am new here > and I am not sure how to manage that. > The series should probably go through the chrome tree. The only possible conflict would be in drivers/rtc/Makefile and it should be easy enough for Linus to solve. > Thanks, > Enric > > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git/log/?h=chrome-platform-5.1 > > > drivers/rtc/Kconfig | 11 ++ > > drivers/rtc/Makefile | 1 + > > drivers/rtc/rtc-wilco-ec.c | 177 ++++++++++++++++++++++++ > > include/linux/platform_data/wilco-ec.h | 2 + > > 5 files changed, 211 insertions(+), 2 deletions(-) > > create mode 100644 drivers/rtc/rtc-wilco-ec.c > > > > diff --git a/drivers/platform/chrome/wilco_ec/core.c b/drivers/platform/chrome/wilco_ec/core.c > > index ae86cae216fd..e67385ec5103 100644 > > --- a/drivers/platform/chrome/wilco_ec/core.c > > +++ b/drivers/platform/chrome/wilco_ec/core.c > > @@ -42,6 +42,7 @@ static int wilco_ec_probe(struct platform_device *pdev) > > { > > struct device *dev = &pdev->dev; > > struct wilco_ec_device *ec; > > + int ret; > > > > ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); > > if (!ec) > > @@ -70,21 +71,38 @@ static int wilco_ec_probe(struct platform_device *pdev) > > ec->io_packet->start + EC_MAILBOX_DATA_SIZE); > > > > /* > > - * Register a debugfs platform device that will get picked up by the > > - * debugfs driver. Ignore failure. > > + * Register a child device that will be found by the RTC driver. > > + * Ignore failure. > > */ > > ec->debugfs_pdev = platform_device_register_data(dev, > > "wilco-ec-debugfs", > > PLATFORM_DEVID_AUTO, > > NULL, 0); > > > > + /* Register a child device that will be found by the RTC driver. */ > > + ec->rtc_pdev = platform_device_register_data(dev, "rtc-wilco-ec", > > + PLATFORM_DEVID_AUTO, > > + NULL, 0); > > + if (IS_ERR(ec->rtc_pdev)) { > > + dev_err(dev, "Failed to create RTC platform device\n"); > > + ret = PTR_ERR(ec->rtc_pdev); > > + goto unregister_debugfs; > > + } > > + > > return 0; > > + > > +unregister_debugfs: > > + if (ec->debugfs_pdev) > > + platform_device_unregister(ec->debugfs_pdev); > > + cros_ec_lpc_mec_destroy(); > > + return ret; > > } > > > > static int wilco_ec_remove(struct platform_device *pdev) > > { > > struct wilco_ec_device *ec = platform_get_drvdata(pdev); > > > > + platform_device_unregister(ec->rtc_pdev); > > if (ec->debugfs_pdev) > > platform_device_unregister(ec->debugfs_pdev); > > > > diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig > > index 225b0b8516f3..d5063c791515 100644 > > --- a/drivers/rtc/Kconfig > > +++ b/drivers/rtc/Kconfig > > @@ -1814,4 +1814,15 @@ config RTC_DRV_GOLDFISH > > Goldfish is a code name for the virtual platform developed by Google > > for Android emulation. > > > > +config RTC_DRV_WILCO_EC > > + tristate "Wilco EC RTC" > > + depends on WILCO_EC > > + default m > > + help > > + If you say yes here, you get read/write support for the Real Time > > + Clock on the Wilco Embedded Controller (Wilco is a kind of Chromebook) > > + > > + This can also be built as a module. If so, the module will > > + be named "rtc_wilco_ec". > > + > > endif # RTC_CLASS > > diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile > > index df022d820bee..6255ea78da25 100644 > > --- a/drivers/rtc/Makefile > > +++ b/drivers/rtc/Makefile > > @@ -172,6 +172,7 @@ obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o > > obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o > > obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o > > obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o > > +obj-$(CONFIG_RTC_DRV_WILCO_EC) += rtc-wilco-ec.o > > obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o > > obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o > > obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o > > diff --git a/drivers/rtc/rtc-wilco-ec.c b/drivers/rtc/rtc-wilco-ec.c > > new file mode 100644 > > index 000000000000..35cc56114c1c > > --- /dev/null > > +++ b/drivers/rtc/rtc-wilco-ec.c > > @@ -0,0 +1,177 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * RTC interface for Wilco Embedded Controller with R/W abilities > > + * > > + * Copyright 2018 Google LLC > > + * > > + * The corresponding platform device is typically registered in > > + * drivers/platform/chrome/wilco_ec/core.c > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define EC_COMMAND_CMOS 0x7c > > +#define EC_CMOS_TOD_WRITE 0x02 > > +#define EC_CMOS_TOD_READ 0x08 > > + > > +/** > > + * struct ec_rtc_read - Format of RTC returned by EC. > > + * @second: Second value (0..59) > > + * @minute: Minute value (0..59) > > + * @hour: Hour value (0..23) > > + * @day: Day value (1..31) > > + * @month: Month value (1..12) > > + * @year: Year value (full year % 100) > > + * @century: Century value (full year / 100) > > + * > > + * All values are presented in binary (not BCD). > > + */ > > +struct ec_rtc_read { > > + u8 second; > > + u8 minute; > > + u8 hour; > > + u8 day; > > + u8 month; > > + u8 year; > > + u8 century; > > +} __packed; > > + > > +/** > > + * struct ec_rtc_write - Format of RTC sent to the EC. > > + * @param: EC_CMOS_TOD_WRITE > > + * @century: Century value (full year / 100) > > + * @year: Year value (full year % 100) > > + * @month: Month value (1..12) > > + * @day: Day value (1..31) > > + * @hour: Hour value (0..23) > > + * @minute: Minute value (0..59) > > + * @second: Second value (0..59) > > + * @weekday: Day of the week (0=Saturday) > > + * > > + * All values are presented in BCD. > > + */ > > +struct ec_rtc_write { > > + u8 param; > > + u8 century; > > + u8 year; > > + u8 month; > > + u8 day; > > + u8 hour; > > + u8 minute; > > + u8 second; > > + u8 weekday; > > +} __packed; > > + > > +int wilco_ec_rtc_read(struct device *dev, struct rtc_time *tm) > > +{ > > + struct wilco_ec_device *ec = dev_get_drvdata(dev->parent); > > + u8 param = EC_CMOS_TOD_READ; > > + struct ec_rtc_read rtc; > > + struct wilco_ec_message msg = { > > + .type = WILCO_EC_MSG_LEGACY, > > + .flags = WILCO_EC_FLAG_RAW_RESPONSE, > > + .command = EC_COMMAND_CMOS, > > + .request_data = ¶m, > > + .request_size = sizeof(param), > > + .response_data = &rtc, > > + .response_size = sizeof(rtc), > > + }; > > + int ret; > > + > > + ret = wilco_ec_mailbox(ec, &msg); > > + if (ret < 0) > > + return ret; > > + > > + tm->tm_sec = rtc.second; > > + tm->tm_min = rtc.minute; > > + tm->tm_hour = rtc.hour; > > + tm->tm_mday = rtc.day; > > + tm->tm_mon = rtc.month - 1; > > + tm->tm_year = rtc.year + (rtc.century * 100) - 1900; > > + tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); > > + > > + /* Don't compute day of week, we don't need it. */ > > + tm->tm_wday = -1; > > + > > + return 0; > > +} > > + > > +int wilco_ec_rtc_write(struct device *dev, struct rtc_time *tm) > > +{ > > + struct wilco_ec_device *ec = dev_get_drvdata(dev->parent); > > + struct ec_rtc_write rtc; > > + struct wilco_ec_message msg = { > > + .type = WILCO_EC_MSG_LEGACY, > > + .flags = WILCO_EC_FLAG_RAW_RESPONSE, > > + .command = EC_COMMAND_CMOS, > > + .request_data = &rtc, > > + .request_size = sizeof(rtc), > > + }; > > + int year = tm->tm_year + 1900; > > + /* > > + * Convert from 0=Sunday to 0=Saturday for the EC > > + * We DO need to set weekday because the EC controls battery charging > > + * schedules that depend on the day of the week. > > + */ > > + int wday = tm->tm_wday == 6 ? 0 : tm->tm_wday + 1; > > + int ret; > > + > > + rtc.param = EC_CMOS_TOD_WRITE; > > + rtc.century = bin2bcd(year / 100); > > + rtc.year = bin2bcd(year % 100); > > + rtc.month = bin2bcd(tm->tm_mon + 1); > > + rtc.day = bin2bcd(tm->tm_mday); > > + rtc.hour = bin2bcd(tm->tm_hour); > > + rtc.minute = bin2bcd(tm->tm_min); > > + rtc.second = bin2bcd(tm->tm_sec); > > + rtc.weekday = bin2bcd(wday); > > + > > + ret = wilco_ec_mailbox(ec, &msg); > > + if (ret < 0) > > + return ret; > > + > > + return 0; > > +} > > + > > +static const struct rtc_class_ops wilco_ec_rtc_ops = { > > + .read_time = wilco_ec_rtc_read, > > + .set_time = wilco_ec_rtc_write, > > +}; > > + > > +static int wilco_ec_rtc_probe(struct platform_device *pdev) > > +{ > > + struct rtc_device *rtc; > > + > > + rtc = devm_rtc_allocate_device(&pdev->dev); > > + if (IS_ERR(rtc)) > > + return PTR_ERR(rtc); > > + > > + rtc->ops = &wilco_ec_rtc_ops; > > + /* EC only supports this century */ > > + rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; > > + rtc->range_max = RTC_TIMESTAMP_END_2099; > > + rtc->owner = THIS_MODULE; > > + > > + return rtc_register_device(rtc); > > +} > > + > > +static struct platform_driver wilco_ec_rtc_driver = { > > + .driver = { > > + .name = "rtc-wilco-ec", > > + }, > > + .probe = wilco_ec_rtc_probe, > > +}; > > + > > +module_platform_driver(wilco_ec_rtc_driver); > > + > > +MODULE_ALIAS("platform:rtc-wilco-ec"); > > +MODULE_AUTHOR("Nick Crews "); > > +MODULE_LICENSE("GPL v2"); > > +MODULE_DESCRIPTION("Wilco EC RTC driver"); > > diff --git a/include/linux/platform_data/wilco-ec.h b/include/linux/platform_data/wilco-ec.h > > index 5344975afa1a..446473a46b88 100644 > > --- a/include/linux/platform_data/wilco-ec.h > > +++ b/include/linux/platform_data/wilco-ec.h > > @@ -35,6 +35,7 @@ > > * is used to hold the request and the response. > > * @data_size: Size of the data buffer used for EC communication. > > * @debugfs_pdev: The child platform_device used by the debugfs sub-driver. > > + * @rtc_pdev: The child platform_device used by the RTC sub-driver. > > */ > > struct wilco_ec_device { > > struct device *dev; > > @@ -45,6 +46,7 @@ struct wilco_ec_device { > > void *data_buffer; > > size_t data_size; > > struct platform_device *debugfs_pdev; > > + struct platform_device *rtc_pdev; > > }; > > > > /** > > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com