Re: [PATCH v5 2/2] rtc: support for the Amlogic Meson RTC
From: Neil Armstrong
Date: Wed Dec 05 2018 - 10:02:25 EST
Hi Ben,
On 05/12/2018 14:36, Ben Dooks wrote:
> On 02/12/2018 22:08, Martin Blumenstingl wrote:
>> Add support for the RTC block on the 32-bit Amlogic Meson6, Meson8,
>> Meson8b and Meson8m2 SoCs.
>>
>> The RTC is split in to two parts, which are both managed by this driver:
>> - the AHB front end
>> - and a simple serial connection to the actual registers
>>
>> The RTC_COUNTER register which holds the time is 32-bits wide.
>>
>> There are four 32-bit wide (in total: 16 bytes) "regmem" registers which
>> are exposed using nvmem. On Amlogic's 3.10 kernel this is used to store
>> data which needs to survive a suspend / resume cycle.
>>
>> Signed-off-by: Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx>
>> [resurrected Ben's patches after 2 years]
>> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>
>
> Just checking if the change of author is deliberate?
> not sure how to do >1 author on patches like this.
Martin has been very explicit about that in the cover letter :
https://patchwork.kernel.org/cover/10708427/
Neil
>
>> ---
>> Â drivers/rtc/KconfigÂÂÂÂ |Â 11 ++
>> Â drivers/rtc/MakefileÂÂÂ |ÂÂ 1 +
>> Â drivers/rtc/rtc-meson.c | 409 ++++++++++++++++++++++++++++++++++++++++
>> Â 3 files changed, 421 insertions(+)
>> Â create mode 100644 drivers/rtc/rtc-meson.c
>>
>> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
>> index a819ef07b7ec..d5d0e3affdc6 100644
>> --- a/drivers/rtc/Kconfig
>> +++ b/drivers/rtc/Kconfig
>> @@ -1285,6 +1285,17 @@ config RTC_DRV_IMXDI
>> ÂÂÂÂÂÂÂÂ This driver can also be built as a module, if so, the module
>> ÂÂÂÂÂÂÂÂ will be called "rtc-imxdi".
>> Â +config RTC_DRV_MESON
>> +ÂÂÂ tristate "Amlogic Meson RTC"
>> +ÂÂÂ depends on (ARM && ARCH_MESON) || COMPILE_TEST
>> +ÂÂÂ select REGMAP_MMIO
>> +ÂÂÂ help
>> +ÂÂÂÂÂÂ Support for the RTC block on the Amlogic Meson6, Meson8, Meson8b
>> +ÂÂÂÂÂÂ and Meson8m2 SoCs.
>> +
>> +ÂÂÂÂÂÂ This driver can also be built as a module, if so, the module
>> +ÂÂÂÂÂÂ will be called "rtc-meson".
>> +
>> Â config RTC_DRV_OMAP
>> ÂÂÂÂÂ tristate "TI OMAP Real Time Clock"
>> ÂÂÂÂÂ depends on ARCH_OMAP || ARCH_DAVINCI || COMPILE_TEST
>> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
>> index 290c1730fb0a..3b088e75149d 100644
>> --- a/drivers/rtc/Makefile
>> +++ b/drivers/rtc/Makefile
>> @@ -99,6 +99,7 @@ obj-$(CONFIG_RTC_DRV_MAX8997)ÂÂÂ += rtc-max8997.o
>> Â obj-$(CONFIG_RTC_DRV_MAX8998)ÂÂÂ += rtc-max8998.o
>> Â obj-$(CONFIG_RTC_DRV_MC13XXX)ÂÂÂ += rtc-mc13xxx.o
>> Â obj-$(CONFIG_RTC_DRV_MCP795)ÂÂÂ += rtc-mcp795.o
>> +obj-$(CONFIG_RTC_DRV_MESON)ÂÂÂ += rtc-meson.o
>> Â obj-$(CONFIG_RTC_DRV_MOXART)ÂÂÂ += rtc-moxart.o
>> Â obj-$(CONFIG_RTC_DRV_MPC5121)ÂÂÂ += rtc-mpc5121.o
>> Â obj-$(CONFIG_RTC_DRV_MSM6242)ÂÂÂ += rtc-msm6242.o
>> diff --git a/drivers/rtc/rtc-meson.c b/drivers/rtc/rtc-meson.c
>> new file mode 100644
>> index 000000000000..09d6849b804a
>> --- /dev/null
>> +++ b/drivers/rtc/rtc-meson.c
>> @@ -0,0 +1,409 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * RTC driver for the interal RTC block in the Amlogic Meson6, Meson8,
>> + * Meson8b and Meson8m2 SoCs.
>> + *
>> + * The RTC is split in to two parts, the AHB front end and a simple serial
>> + * connection to the actual registers. This driver manages both parts.
>> + *
>> + * Copyright (c) 2018 Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>
>> + * Copyright (c) 2015 Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx> for Codethink Ltd
>> + * Based on origin by Carlo Caione <carlo@xxxxxxxxxxxx>
>> + */
>> +
>> +#include <linux/bitfield.h>
>> +#include <linux/delay.h>
>> +#include <linux/io.h>
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/nvmem-provider.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/regmap.h>
>> +#include <linux/regulator/consumer.h>
>> +#include <linux/reset.h>
>> +#include <linux/rtc.h>
>> +
>> +/* registers accessed from cpu bus */
>> +#define RTC_ADDR0ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x00
>> +ÂÂÂ #define RTC_ADDR0_LINE_SCLKÂÂÂÂÂÂÂ BIT(0)
>> +ÂÂÂ #define RTC_ADDR0_LINE_SENÂÂÂÂÂÂÂ BIT(1)
>> +ÂÂÂ #define RTC_ADDR0_LINE_SDIÂÂÂÂÂÂÂ BIT(2)
>> +ÂÂÂ #define RTC_ADDR0_START_SERÂÂÂÂÂÂÂ BIT(17)
>> +ÂÂÂ #define RTC_ADDR0_WAIT_SERÂÂÂÂÂÂÂ BIT(22)
>> +ÂÂÂ #define RTC_ADDR0_DATAÂÂÂÂÂÂÂÂÂÂÂ GENMASK(31, 24)
>> +
>> +#define RTC_ADDR1ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x04
>> +ÂÂÂ #define RTC_ADDR1_SDOÂÂÂÂÂÂÂÂÂÂÂ BIT(0)
>> +ÂÂÂ #define RTC_ADDR1_S_READYÂÂÂÂÂÂÂ BIT(1)
>> +
>> +#define RTC_ADDR2ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x08
>> +#define RTC_ADDR3ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x0c
>> +
>> +#define RTC_REG4ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x10
>> +ÂÂÂ #define RTC_REG4_STATIC_VALUEÂÂÂÂÂÂÂ GENMASK(7, 0)
>> +
>> +/* rtc registers accessed via rtc-serial interface */
>> +#define RTC_COUNTERÂÂÂÂÂÂÂ (0)
>> +#define RTC_SEC_ADJÂÂÂÂÂÂÂ (2)
>> +#define RTC_REGMEM_0ÂÂÂÂÂÂÂ (4)
>> +#define RTC_REGMEM_1ÂÂÂÂÂÂÂ (5)
>> +#define RTC_REGMEM_2ÂÂÂÂÂÂÂ (6)
>> +#define RTC_REGMEM_3ÂÂÂÂÂÂÂ (7)
>> +
>> +#define RTC_ADDR_BITSÂÂÂÂÂÂÂ (3)ÂÂÂ /* number of address bits to send */
>> +#define RTC_DATA_BITSÂÂÂÂÂÂÂ (32)ÂÂÂ /* number of data bits to tx/rx */
>> +
>> +#define MESON_STATIC_BIAS_CURÂÂÂ (0x5 << 1)
>> +#define MESON_STATIC_VOLTAGEÂÂÂ (0x3 << 11)
>> +#define MESON_STATIC_DEFAULTÂÂÂ (MESON_STATIC_BIAS_CUR | MESON_STATIC_VOLTAGE)
>> +
>> +struct meson_rtc {
>> +ÂÂÂ struct rtc_deviceÂÂÂ *rtc;ÂÂÂÂÂÂÂ /* rtc device we created */
>> +ÂÂÂ struct deviceÂÂÂÂÂÂÂ *dev;ÂÂÂÂÂÂÂ /* device we bound from */
>> +ÂÂÂ struct reset_controlÂÂÂ *reset;ÂÂÂÂÂÂÂ /* reset source */
>> +ÂÂÂ struct regulatorÂÂÂ *vdd;ÂÂÂÂÂÂÂ /* voltage input */
>> +ÂÂÂ struct regmapÂÂÂÂÂÂÂ *peripheral;ÂÂÂ /* peripheral registers */
>> +ÂÂÂ struct regmapÂÂÂÂÂÂÂ *serial;ÂÂÂ /* serial registers */
>> +};
>> +
>> +static const struct regmap_config meson_rtc_peripheral_regmap_config = {
>> +ÂÂÂ .nameÂÂÂÂÂÂÂ = "peripheral-registers",
>> +ÂÂÂ .reg_bitsÂÂÂ = 8,
>> +ÂÂÂ .val_bitsÂÂÂ = 32,
>> +ÂÂÂ .reg_strideÂÂÂ = 4,
>> +ÂÂÂ .max_registerÂÂÂ = RTC_REG4,
>> +ÂÂÂ .fast_ioÂÂÂ = true,
>> +};
>> +
>> +/* RTC front-end serialiser controls */
>> +
>> +static void meson_rtc_sclk_pulse(struct meson_rtc *rtc)
>> +{
>> +ÂÂÂ udelay(5);
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SCLK, 0);
>> +ÂÂÂ udelay(5);
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SCLK,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ RTC_ADDR0_LINE_SCLK);
>> +}
>> +
>> +static void meson_rtc_send_bit(struct meson_rtc *rtc, unsigned int bit)
>> +{
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SDI,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ bit ? RTC_ADDR0_LINE_SDI : 0);
>> +ÂÂÂ meson_rtc_sclk_pulse(rtc);
>> +}
>> +
>> +static void meson_rtc_send_bits(struct meson_rtc *rtc, u32 data,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int nr)
>> +{
>> +ÂÂÂ u32 bit = 1 << (nr - 1);
>> +
>> +ÂÂÂ while (bit) {
>> +ÂÂÂÂÂÂÂ meson_rtc_send_bit(rtc, data & bit);
>> +ÂÂÂÂÂÂÂ bit >>= 1;
>> +ÂÂÂ }
>> +}
>> +
>> +static void meson_rtc_set_dir(struct meson_rtc *rtc, u32 mode)
>> +{
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SEN, 0);
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SDI, 0);
>> +ÂÂÂ meson_rtc_send_bit(rtc, mode);
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SDI, 0);
>> +}
>> +
>> +static u32 meson_rtc_get_data(struct meson_rtc *rtc)
>> +{
>> +ÂÂÂ u32 tmp, val = 0;
>> +ÂÂÂ int bit;
>> +
>> +ÂÂÂ for (bit = 0; bit < RTC_DATA_BITS; bit++) {
>> +ÂÂÂÂÂÂÂ meson_rtc_sclk_pulse(rtc);
>> +ÂÂÂÂÂÂÂ val <<= 1;
>> +
>> +ÂÂÂÂÂÂÂ regmap_read(rtc->peripheral, RTC_ADDR1, &tmp);
>> +ÂÂÂÂÂÂÂ val |= tmp & RTC_ADDR1_SDO;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ return val;
>> +}
>> +
>> +static int meson_rtc_get_bus(struct meson_rtc *rtc)
>> +{
>> +ÂÂÂ int ret, retries = 3;
>> +ÂÂÂ u32 val;
>> +
>> +ÂÂÂ /* prepare bus for transfers, set all lines low */
>> +ÂÂÂ val = RTC_ADDR0_LINE_SDI | RTC_ADDR0_LINE_SEN | RTC_ADDR0_LINE_SCLK;
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, val, 0);
>> +
>> +ÂÂÂ for (retries = 0; retries < 3; retries++) {
>> +ÂÂÂÂÂÂÂ /* wait for the bus to be ready */
>> +ÂÂÂÂÂÂÂ if (!regmap_read_poll_timeout(rtc->peripheral, RTC_ADDR1, val,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ val & RTC_ADDR1_S_READY, 10,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 10000))
>> +ÂÂÂÂÂÂÂÂÂÂÂ return 0;
>> +
>> +ÂÂÂÂÂÂÂ dev_warn(rtc->dev, "failed to get bus, resetting RTC\n");
>> +
>> +ÂÂÂÂÂÂÂ ret = reset_control_reset(rtc->reset);
>> +ÂÂÂÂÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ dev_err(rtc->dev, "bus is not ready\n");
>> +ÂÂÂ return -ETIMEDOUT;
>> +}
>> +
>> +static int meson_rtc_serial_bus_reg_read(void *context, unsigned int reg,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int *data)
>> +{
>> +ÂÂÂ struct meson_rtc *rtc = context;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ret = meson_rtc_get_bus(rtc);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SEN,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ RTC_ADDR0_LINE_SEN);
>> +ÂÂÂ meson_rtc_send_bits(rtc, reg, RTC_ADDR_BITS);
>> +ÂÂÂ meson_rtc_set_dir(rtc, 0);
>> +ÂÂÂ *data = meson_rtc_get_data(rtc);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static int meson_rtc_serial_bus_reg_write(void *context, unsigned int reg,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int data)
>> +{
>> +ÂÂÂ struct meson_rtc *rtc = context;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ret = meson_rtc_get_bus(rtc);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SEN,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ RTC_ADDR0_LINE_SEN);
>> +ÂÂÂ meson_rtc_send_bits(rtc, data, RTC_DATA_BITS);
>> +ÂÂÂ meson_rtc_send_bits(rtc, reg, RTC_ADDR_BITS);
>> +ÂÂÂ meson_rtc_set_dir(rtc, 1);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static const struct regmap_bus meson_rtc_serial_bus = {
>> +ÂÂÂ .reg_readÂÂÂ = meson_rtc_serial_bus_reg_read,
>> +ÂÂÂ .reg_writeÂÂÂ = meson_rtc_serial_bus_reg_write,
>> +};
>> +
>> +static const struct regmap_config meson_rtc_serial_regmap_config = {
>> +ÂÂÂ .nameÂÂÂÂÂÂÂ = "serial-registers",
>> +ÂÂÂ .reg_bitsÂÂÂ = 4,
>> +ÂÂÂ .reg_strideÂÂÂ = 1,
>> +ÂÂÂ .val_bitsÂÂÂ = 32,
>> +ÂÂÂ .max_registerÂÂÂ = RTC_REGMEM_3,
>> +ÂÂÂ .fast_ioÂÂÂ = false,
>> +};
>> +
>> +static int meson_rtc_write_static(struct meson_rtc *rtc, u32 data)
>> +{
>> +ÂÂÂ u32 tmp;
>> +
>> +ÂÂÂ regmap_write(rtc->peripheral, RTC_REG4,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂ FIELD_PREP(RTC_REG4_STATIC_VALUE, (data >> 8)));
>> +
>> +ÂÂÂ /* write the static value and start the auto serializer */
>> +ÂÂÂ tmp = FIELD_PREP(RTC_ADDR0_DATA, (data & 0xff)) | RTC_ADDR0_START_SER;
>> +ÂÂÂ regmap_update_bits(rtc->peripheral, RTC_ADDR0,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ RTC_ADDR0_DATA | RTC_ADDR0_START_SER, tmp);
>> +
>> +ÂÂÂ /* wait for the auto serializer to complete */
>> +ÂÂÂ return regmap_read_poll_timeout(rtc->peripheral, RTC_REG4, tmp,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ !(tmp & RTC_ADDR0_WAIT_SER), 10,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 10000);
>> +}
>> +
>> +/* RTC interface layer functions */
>> +
>> +static int meson_rtc_gettime(struct device *dev, struct rtc_time *tm)
>> +{
>> +ÂÂÂ struct meson_rtc *rtc = dev_get_drvdata(dev);
>> +ÂÂÂ u32 time;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ret = regmap_read(rtc->serial, RTC_COUNTER, &time);
>> +ÂÂÂ if (!ret)
>> +ÂÂÂÂÂÂÂ rtc_time64_to_tm(time, tm);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static int meson_rtc_settime(struct device *dev, struct rtc_time *tm)
>> +{
>> +ÂÂÂ struct meson_rtc *rtc = dev_get_drvdata(dev);
>> +
>> +ÂÂÂ return regmap_write(rtc->serial, RTC_COUNTER, rtc_tm_to_time64(tm));
>> +}
>> +
>> +static const struct rtc_class_ops meson_rtc_ops = {
>> +ÂÂÂ .read_timeÂÂÂ = meson_rtc_gettime,
>> +ÂÂÂ .set_timeÂÂÂ = meson_rtc_settime,
>> +};
>> +
>> +/* NVMEM interface layer functions */
>> +
>> +static int meson_rtc_regmem_read(void *context, unsigned int offset,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ void *buf, size_t bytes)
>> +{
>> +ÂÂÂ struct meson_rtc *rtc = context;
>> +ÂÂÂ unsigned int read_offset, read_size;
>> +
>> +ÂÂÂ read_offset = RTC_REGMEM_0 + (offset / 4);
>> +ÂÂÂ read_size = bytes / 4;
>> +
>> +ÂÂÂ return regmap_bulk_read(rtc->serial, read_offset, buf, read_size);
>> +}
>> +
>> +static int meson_rtc_regmem_write(void *context, unsigned int offset,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ void *buf, size_t bytes)
>> +{
>> +ÂÂÂ struct meson_rtc *rtc = context;
>> +ÂÂÂ unsigned int write_offset, write_size;
>> +
>> +ÂÂÂ write_offset = RTC_REGMEM_0 + (offset / 4);
>> +ÂÂÂ write_size = bytes / 4;
>> +
>> +ÂÂÂ return regmap_bulk_write(rtc->serial, write_offset, buf, write_size);
>> +}
>> +
>> +static int meson_rtc_probe(struct platform_device *pdev)
>> +{
>> +ÂÂÂ struct nvmem_config meson_rtc_nvmem_config = {
>> +ÂÂÂÂÂÂÂ .name = "meson-rtc-regmem",
>> +ÂÂÂÂÂÂÂ .word_size = 4,
>> +ÂÂÂÂÂÂÂ .stride = 4,
>> +ÂÂÂÂÂÂÂ .size = SZ_16,
>> +ÂÂÂÂÂÂÂ .reg_read = meson_rtc_regmem_read,
>> +ÂÂÂÂÂÂÂ .reg_write = meson_rtc_regmem_write,
>> +ÂÂÂ };
>> +ÂÂÂ struct device *dev = &pdev->dev;
>> +ÂÂÂ struct meson_rtc *rtc;
>> +ÂÂÂ struct resource *res;
>> +ÂÂÂ void __iomem *base;
>> +ÂÂÂ int ret;
>> +ÂÂÂ u32 tm;
>> +
>> +ÂÂÂ rtc = devm_kzalloc(dev, sizeof(struct meson_rtc), GFP_KERNEL);
>> +ÂÂÂ if (!rtc)
>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>> +
>> +ÂÂÂ rtc->rtc = devm_rtc_allocate_device(dev);
>> +ÂÂÂ if (IS_ERR(rtc->rtc))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(rtc->rtc);
>> +
>> +ÂÂÂ platform_set_drvdata(pdev, rtc);
>> +
>> +ÂÂÂ rtc->dev = dev;
>> +
>> +ÂÂÂ rtc->rtc->ops = &meson_rtc_ops;
>> +ÂÂÂ rtc->rtc->range_max = U32_MAX;
>> +
>> +ÂÂÂ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> +ÂÂÂ base = devm_ioremap_resource(dev, res);
>> +ÂÂÂ if (IS_ERR(base))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(base);
>> +
>> +ÂÂÂ rtc->peripheral = devm_regmap_init_mmio(dev, base,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &meson_rtc_peripheral_regmap_config);
>> +ÂÂÂ if (IS_ERR(rtc->peripheral)) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "failed to create peripheral regmap\n");
>> +ÂÂÂÂÂÂÂ return PTR_ERR(rtc->peripheral);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ rtc->reset = devm_reset_control_get(dev, NULL);
>> +ÂÂÂ if (IS_ERR(rtc->reset)) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "missing reset line\n");
>> +ÂÂÂÂÂÂÂ return PTR_ERR(rtc->reset);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ rtc->vdd = devm_regulator_get(dev, "vdd");
>> +ÂÂÂ if (IS_ERR(rtc->vdd)) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "failed to get the vdd-supply\n");
>> +ÂÂÂÂÂÂÂ return PTR_ERR(rtc->vdd);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = regulator_enable(rtc->vdd);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "failed to enable vdd-supply\n");
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = meson_rtc_write_static(rtc, MESON_STATIC_DEFAULT);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "failed to set static values\n");
>> +ÂÂÂÂÂÂÂ goto out_disable_vdd;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ rtc->serial = devm_regmap_init(dev, &meson_rtc_serial_bus, rtc,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &meson_rtc_serial_regmap_config);
>> +ÂÂÂ if (IS_ERR(rtc->serial)) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "failed to create serial regmap\n");
>> +ÂÂÂÂÂÂÂ ret = PTR_ERR(rtc->serial);
>> +ÂÂÂÂÂÂÂ goto out_disable_vdd;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ /*
>> +ÂÂÂÂ * check if we can read RTC counter, if not then the RTC is probably
>> +ÂÂÂÂ * not functional. If it isn't probably best to not bind.
>> +ÂÂÂÂ */
>> +ÂÂÂ ret = regmap_read(rtc->serial, RTC_COUNTER, &tm);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "cannot read RTC counter, RTC not functional\n");
>> +ÂÂÂÂÂÂÂ goto out_disable_vdd;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ meson_rtc_nvmem_config.priv = rtc;
>> +ÂÂÂ ret = rtc_nvmem_register(rtc->rtc, &meson_rtc_nvmem_config);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ goto out_disable_vdd;
>> +
>> +ÂÂÂ ret = rtc_register_device(rtc->rtc);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ goto out_unregister_nvmem;
>> +
>> +ÂÂÂ return 0;
>> +
>> +out_unregister_nvmem:
>> +ÂÂÂ rtc_nvmem_unregister(rtc->rtc);
>> +
>> +out_disable_vdd:
>> +ÂÂÂ regulator_disable(rtc->vdd);
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static const struct of_device_id meson_rtc_dt_match[] = {
>> +ÂÂÂ { .compatible = "amlogic,meson6-rtc", },
>> +ÂÂÂ { .compatible = "amlogic,meson8-rtc", },
>> +ÂÂÂ { .compatible = "amlogic,meson8b-rtc", },
>> +ÂÂÂ { .compatible = "amlogic,meson8m2-rtc", },
>> +ÂÂÂ { },
>> +};
>> +MODULE_DEVICE_TABLE(of, meson_rtc_dt_match);
>> +
>> +static struct platform_driver meson_rtc_driver = {
>> +ÂÂÂ .probeÂÂÂÂÂÂÂ = meson_rtc_probe,
>> +ÂÂÂ .driverÂÂÂÂÂÂÂ = {
>> +ÂÂÂÂÂÂÂ .nameÂÂÂ = "meson-rtc",
>> +ÂÂÂÂÂÂÂ .of_match_tableÂÂÂ = of_match_ptr(meson_rtc_dt_match),
>> +ÂÂÂ },
>> +};
>> +module_platform_driver(meson_rtc_driver);
>> +
>> +MODULE_DESCRIPTION("Amlogic Meson RTC Driver");
>> +MODULE_AUTHOR("Ben Dooks <ben.doosk@xxxxxxxxxxxxxxx>");
>> +MODULE_AUTHOR("Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>");
>> +MODULE_LICENSE("GPL v2");
>> +MODULE_ALIAS("platform:meson-rtc");
>>
>
>