From 944ed452eb1b4241c8bd693b8b689fe8b888c445 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Sun, 5 Apr 2020 17:30:15 +0200 Subject: rtc: remove unnecessary error message after platform_get_irq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function “platform_get_irq” can log an error already. Thus omit redundant messages for the exception handling in the calling functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Acked-by: Vladimir Zapolskiy Link: https://lore.kernel.org/r/04116352-b464-041c-1939-96440133aa6f@web.de Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-fsl-ftm-alarm.c | 4 +--- drivers/rtc/rtc-lpc24xx.c | 4 +--- drivers/rtc/rtc-mt2712.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c index 756af62b0486..23c811da4801 100644 --- a/drivers/rtc/rtc-fsl-ftm-alarm.c +++ b/drivers/rtc/rtc-fsl-ftm-alarm.c @@ -268,10 +268,8 @@ static int ftm_rtc_probe(struct platform_device *pdev) } irq = platform_get_irq(pdev, 0); - if (irq < 0) { - dev_err(&pdev->dev, "can't get irq number\n"); + if (irq < 0) return irq; - } ret = devm_request_irq(&pdev->dev, irq, ftm_rtc_alarm_interrupt, IRQF_NO_SUSPEND, dev_name(&pdev->dev), rtc); diff --git a/drivers/rtc/rtc-lpc24xx.c b/drivers/rtc/rtc-lpc24xx.c index 00ef16ba9480..eec881a81067 100644 --- a/drivers/rtc/rtc-lpc24xx.c +++ b/drivers/rtc/rtc-lpc24xx.c @@ -205,10 +205,8 @@ static int lpc24xx_rtc_probe(struct platform_device *pdev) return PTR_ERR(rtc->rtc_base); irq = platform_get_irq(pdev, 0); - if (irq < 0) { - dev_warn(&pdev->dev, "can't get interrupt resource\n"); + if (irq < 0) return irq; - } rtc->clk_rtc = devm_clk_get(&pdev->dev, "rtc"); if (IS_ERR(rtc->clk_rtc)) { diff --git a/drivers/rtc/rtc-mt2712.c b/drivers/rtc/rtc-mt2712.c index 581b8731fb8a..f6bdbabd7202 100644 --- a/drivers/rtc/rtc-mt2712.c +++ b/drivers/rtc/rtc-mt2712.c @@ -328,10 +328,8 @@ static int mt2712_rtc_probe(struct platform_device *pdev) mt2712_rtc_hw_init(mt2712_rtc); mt2712_rtc->irq = platform_get_irq(pdev, 0); - if (mt2712_rtc->irq < 0) { - dev_err(&pdev->dev, "No IRQ resource\n"); + if (mt2712_rtc->irq < 0) return mt2712_rtc->irq; - } platform_set_drvdata(pdev, mt2712_rtc); -- cgit v1.2.3 From 11ddbdfb68e4f9791e4bd4f8d7c87d3f19670967 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 7 Apr 2020 12:28:52 +0300 Subject: rtc: rc5t619: Fix an ERR_PTR vs NULL check The devm_kzalloc() function returns NULL on error, it doesn't return error pointers so this check doesn't work. Fixes: 540d1e15393d ("rtc: rc5t619: Add Ricoh RC5T619 RTC driver") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/20200407092852.GI68494@mwanda Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-rc5t619.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-rc5t619.c b/drivers/rtc/rtc-rc5t619.c index 24e386ecbc7e..dd1a20977478 100644 --- a/drivers/rtc/rtc-rc5t619.c +++ b/drivers/rtc/rtc-rc5t619.c @@ -356,10 +356,8 @@ static int rc5t619_rtc_probe(struct platform_device *pdev) int err; rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); - if (IS_ERR(rtc)) { - err = PTR_ERR(rtc); + if (!rtc) return -ENOMEM; - } rtc->rn5t618 = rn5t618; -- cgit v1.2.3 From 3642b17e9a8d32ddf8d74cd033de7efcd0a15aec Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Wed, 15 Apr 2020 22:00:20 +0200 Subject: rtc: mt2712: remove unnecessary error string Remove the unnecessary error string as the core will already display error messages when registration fails (i.e. never). Link: https://lore.kernel.org/r/20200415200021.157118-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-mt2712.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-mt2712.c b/drivers/rtc/rtc-mt2712.c index f6bdbabd7202..9868d98f397c 100644 --- a/drivers/rtc/rtc-mt2712.c +++ b/drivers/rtc/rtc-mt2712.c @@ -354,13 +354,7 @@ static int mt2712_rtc_probe(struct platform_device *pdev) mt2712_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; mt2712_rtc->rtc->range_max = MT2712_RTC_TIMESTAMP_END_2127; - ret = rtc_register_device(mt2712_rtc->rtc); - if (ret) { - dev_err(&pdev->dev, "register rtc device failed\n"); - return ret; - } - - return 0; + return rtc_register_device(mt2712_rtc->rtc); } #ifdef CONFIG_PM_SLEEP -- cgit v1.2.3 From 06030d5001494f67fe2dee65c49c2f0e54e34eba Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Wed, 15 Apr 2020 22:00:21 +0200 Subject: rtc: mt2712: switch to devm_platform_ioremap_resource Using devm_platform_ioremap_resource instead of open coding it reduces the size of the binary. text data bss dec hex filename 3728 216 0 3944 f68 drivers/rtc/rtc-mt2712.o 3744 216 0 3960 f78 drivers/rtc/rtc-mt2712.o.old Link: https://lore.kernel.org/r/20200415200021.157118-2-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-mt2712.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-mt2712.c b/drivers/rtc/rtc-mt2712.c index 9868d98f397c..d5f691c8a035 100644 --- a/drivers/rtc/rtc-mt2712.c +++ b/drivers/rtc/rtc-mt2712.c @@ -310,7 +310,6 @@ static const struct rtc_class_ops mt2712_rtc_ops = { static int mt2712_rtc_probe(struct platform_device *pdev) { - struct resource *res; struct mt2712_rtc *mt2712_rtc; int ret; @@ -319,8 +318,7 @@ static int mt2712_rtc_probe(struct platform_device *pdev) if (!mt2712_rtc) return -ENOMEM; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - mt2712_rtc->base = devm_ioremap_resource(&pdev->dev, res); + mt2712_rtc->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(mt2712_rtc->base)) return PTR_ERR(mt2712_rtc->base); -- cgit v1.2.3 From 9f210ec65acc525db49de3223b935f9dd4c2f5b5 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Wed, 15 Apr 2020 22:02:26 +0200 Subject: rtc: 88pm860x: remove useless range check Because the core is now checking the RTC range, it is unnecessary to check it again in .set_time/ Link: https://lore.kernel.org/r/20200415200226.157361-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-88pm860x.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c index cc9b14ef90f1..c90457d001e9 100644 --- a/drivers/rtc/rtc-88pm860x.c +++ b/drivers/rtc/rtc-88pm860x.c @@ -106,12 +106,6 @@ static int pm860x_rtc_set_time(struct device *dev, struct rtc_time *tm) unsigned char buf[4]; unsigned long ticks, base, data; - if (tm->tm_year > 206) { - dev_dbg(info->dev, "Set time %d out of range. " - "Please set time between 1970 to 2106.\n", - 1900 + tm->tm_year); - return -EINVAL; - } ticks = rtc_tm_to_time64(tm); /* load 32-bit read-only counter */ -- cgit v1.2.3 From b139bb5c262bb0d152d541a1715792364ad121ce Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 5 May 2020 22:13:07 +0200 Subject: rtc: pcf2127: let the core handle rtc range Let the core handle offsetting and windowing the RTC range. Link: https://lore.kernel.org/r/20200505201310.255145-2-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-pcf2127.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 4e50d6768f13..136709baaa88 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -137,8 +137,7 @@ static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm) tm->tm_wday = buf[PCF2127_REG_DW] & 0x07; tm->tm_mon = bcd2bin(buf[PCF2127_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ tm->tm_year = bcd2bin(buf[PCF2127_REG_YR]); - if (tm->tm_year < 70) - tm->tm_year += 100; /* assume we are in 1970...2069 */ + tm->tm_year += 100; dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " "mday=%d, mon=%d, year=%d, wday=%d\n", @@ -172,7 +171,7 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) buf[i++] = bin2bcd(tm->tm_mon + 1); /* year */ - buf[i++] = bin2bcd(tm->tm_year % 100); + buf[i++] = bin2bcd(tm->tm_year - 100); /* write register's data */ err = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_SC, buf, i); @@ -433,6 +432,9 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, return PTR_ERR(pcf2127->rtc); pcf2127->rtc->ops = &pcf2127_rtc_ops; + pcf2127->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; + pcf2127->rtc->range_max = RTC_TIMESTAMP_END_2099; + pcf2127->rtc->set_start_time = true; /* Sets actual start to 1970 */ pcf2127->wdd.parent = dev; pcf2127->wdd.info = &pcf2127_wdt_info; -- cgit v1.2.3 From 664eaf033f9f85d67cb9b9e4b1584bd12e4ed20e Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 5 May 2020 22:13:08 +0200 Subject: rtc: pcf2127: remove unnecessary #ifdef There is not point in setting .ioctl to NULL when CONFIG_RTC_INTF_DEV is not defined because it would not be called anyway. Link: https://lore.kernel.org/r/20200505201310.255145-3-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-pcf2127.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 136709baaa88..5ac996578523 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -184,7 +184,6 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) return 0; } -#ifdef CONFIG_RTC_INTF_DEV static int pcf2127_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) { @@ -205,9 +204,6 @@ static int pcf2127_rtc_ioctl(struct device *dev, return -ENOIOCTLCMD; } } -#else -#define pcf2127_rtc_ioctl NULL -#endif static const struct rtc_class_ops pcf2127_rtc_ops = { .ioctl = pcf2127_rtc_ioctl, -- cgit v1.2.3 From 040e6dc0911c86add1ec3140432672e626b9d4ae Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Tue, 5 May 2020 22:13:09 +0200 Subject: rtc: pcf2127: set regmap max_register Set regmap max_register to ease debugging and enforce the register range. Link: https://lore.kernel.org/r/20200505201310.255145-4-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-pcf2127.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 5ac996578523..039078029bd4 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -634,6 +634,7 @@ static int pcf2127_i2c_probe(struct i2c_client *client, static const struct regmap_config config = { .reg_bits = 8, .val_bits = 8, + .max_register = 0x1d, }; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) @@ -701,6 +702,7 @@ static int pcf2127_spi_probe(struct spi_device *spi) .val_bits = 8, .read_flag_mask = 0xa0, .write_flag_mask = 0x20, + .max_register = 0x1d, }; struct regmap *regmap; -- cgit v1.2.3 From 7d65cf8c1f0ae59ef87e88067379188b46509538 Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Mon, 11 May 2020 16:03:35 +0200 Subject: rtc: pcf2127: report battery switch over Add support for the RTC_VL_BACKUP_SWITCH flag to report battery switch over events. Link: https://lore.kernel.org/r/20200511140335.799133-1-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-pcf2127.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 039078029bd4..e5e3cd128476 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -188,18 +188,27 @@ static int pcf2127_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev); - int touser; + int val, touser = 0; int ret; switch (cmd) { case RTC_VL_READ: - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &touser); + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &val); if (ret) return ret; - touser = touser & PCF2127_BIT_CTRL3_BLF ? RTC_VL_BACKUP_LOW : 0; + if (val & PCF2127_BIT_CTRL3_BLF) + touser |= RTC_VL_BACKUP_LOW; + + if (val & PCF2127_BIT_CTRL3_BF) + touser |= RTC_VL_BACKUP_SWITCH; return put_user(touser, (unsigned int __user *)arg); + + case RTC_VL_CLR: + return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3, + PCF2127_BIT_CTRL3_BF, 0); + default: return -ENOIOCTLCMD; } @@ -493,7 +502,6 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, */ ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3, PCF2127_BIT_CTRL3_BTSE | - PCF2127_BIT_CTRL3_BF | PCF2127_BIT_CTRL3_BIE | PCF2127_BIT_CTRL3_BLIE, 0); if (ret) { -- cgit v1.2.3 From 63a52f63886ab7fa1a28cc7fde08b23682f8fba1 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Fri, 17 Apr 2020 19:08:25 +0200 Subject: rtc: max77686: Use single-byte writes on MAX77620 The MAX77620 doesn't support bulk writes, so make sure the regmap code breaks bulk writes into multiple single-byte writes. Signed-off-by: Thierry Reding Acked-by: Jon Hunter Tested-by: Jon Hunter Link: https://lore.kernel.org/r/20200417170825.2551367-3-thierry.reding@gmail.com Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-max77686.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c index d5a0e27dd0a0..03ebcf1c0f3d 100644 --- a/drivers/rtc/rtc-max77686.c +++ b/drivers/rtc/rtc-max77686.c @@ -78,6 +78,8 @@ struct max77686_rtc_driver_data { int alarm_pending_status_reg; /* RTC IRQ CHIP for regmap */ const struct regmap_irq_chip *rtc_irq_chip; + /* regmap configuration for the chip */ + const struct regmap_config *regmap_config; }; struct max77686_rtc_info { @@ -182,6 +184,11 @@ static const struct regmap_irq_chip max77686_rtc_irq_chip = { .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), }; +static const struct regmap_config max77686_rtc_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + static const struct max77686_rtc_driver_data max77686_drv_data = { .delay = 16000, .mask = 0x7f, @@ -191,6 +198,13 @@ static const struct max77686_rtc_driver_data max77686_drv_data = { .alarm_pending_status_reg = MAX77686_REG_STATUS2, .rtc_i2c_addr = MAX77686_I2C_ADDR_RTC, .rtc_irq_chip = &max77686_rtc_irq_chip, + .regmap_config = &max77686_rtc_regmap_config, +}; + +static const struct regmap_config max77620_rtc_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .use_single_write = true, }; static const struct max77686_rtc_driver_data max77620_drv_data = { @@ -202,6 +216,7 @@ static const struct max77686_rtc_driver_data max77620_drv_data = { .alarm_pending_status_reg = MAX77686_INVALID_REG, .rtc_i2c_addr = MAX77620_I2C_ADDR_RTC, .rtc_irq_chip = &max77686_rtc_irq_chip, + .regmap_config = &max77620_rtc_regmap_config, }; static const unsigned int max77802_map[REG_RTC_END] = { @@ -658,11 +673,6 @@ static int max77686_rtc_init_reg(struct max77686_rtc_info *info) return ret; } -static const struct regmap_config max77686_rtc_regmap_config = { - .reg_bits = 8, - .val_bits = 8, -}; - static int max77686_init_rtc_regmap(struct max77686_rtc_info *info) { struct device *parent = info->dev->parent; @@ -698,7 +708,7 @@ static int max77686_init_rtc_regmap(struct max77686_rtc_info *info) } info->rtc_regmap = devm_regmap_init_i2c(info->rtc, - &max77686_rtc_regmap_config); + info->drv_data->regmap_config); if (IS_ERR(info->rtc_regmap)) { ret = PTR_ERR(info->rtc_regmap); dev_err(info->dev, "Failed to allocate RTC regmap: %d\n", ret); -- cgit v1.2.3 From 32271efded6ca4e92d8f0647dce7fbd94f684a16 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Sat, 2 May 2020 16:27:04 +0200 Subject: rtc: stmp3xxx: update contact email The 'pengutronix' address is defunct for years. Use the proper contact address. Signed-off-by: Wolfram Sang Link: https://lore.kernel.org/r/20200502142704.19308-1-wsa@kernel.org Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-stmp3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c index ff6488be385f..c9bc3d4a1e66 100644 --- a/drivers/rtc/rtc-stmp3xxx.c +++ b/drivers/rtc/rtc-stmp3xxx.c @@ -416,5 +416,5 @@ module_platform_driver(stmp3xxx_rtcdrv); MODULE_DESCRIPTION("STMP3xxx RTC Driver"); MODULE_AUTHOR("dmitry pervushin and " - "Wolfram Sang "); + "Wolfram Sang "); MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 8816cd726a4fee197af2d851cbe25991ae19ea14 Mon Sep 17 00:00:00 2001 From: Qiushi Wu Date: Sun, 3 May 2020 13:22:35 -0500 Subject: rtc: mc13xxx: fix a double-unlock issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In function mc13xxx_rtc_probe, the mc13xxx_unlock() is called before rtc_register_device(). But in the error path of rtc_register_device(), the mc13xxx_unlock() is called again, which causes a double-unlock problem. Thus add a call of the function “mc13xxx_lock” in an if branch for the completion of the exception handling. Fixes: e4ae7023e182a ("rtc: mc13xxx: set range") Signed-off-by: Qiushi Wu Link: https://lore.kernel.org/r/20200503182235.1652-1-wu000273@umn.edu Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-mc13xxx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c index afce2c0b4bd6..d6802e6191cb 100644 --- a/drivers/rtc/rtc-mc13xxx.c +++ b/drivers/rtc/rtc-mc13xxx.c @@ -308,8 +308,10 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev) mc13xxx_unlock(mc13xxx); ret = rtc_register_device(priv->rtc); - if (ret) + if (ret) { + mc13xxx_lock(mc13xxx); goto err_irq_request; + } return 0; -- cgit v1.2.3 From 24e1f2c9383e324bac74ee2a78d8450d4d0a1b6f Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:30 +0200 Subject: rtc: ingenic: Only support probing from devicetree With the recent work on supporting Device Tree on Ingenic SoCs, no driver ever probes from platform code anymore, so we can clean a bit this driver by removing the non-devicetree paths. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-1-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/Kconfig | 1 + drivers/rtc/rtc-jz4740.c | 20 +++----------------- 2 files changed, 4 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index ec873f09c763..82a210920c1d 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1680,6 +1680,7 @@ config RTC_DRV_MPC5121 config RTC_DRV_JZ4740 tristate "Ingenic JZ4740 SoC" depends on MIPS || COMPILE_TEST + depends on OF help If you say yes here you get support for the Ingenic JZ47xx SoCs RTC controllers. diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index e4c719085c31..949d395066e2 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -309,19 +309,13 @@ static int jz4740_rtc_probe(struct platform_device *pdev) { int ret; struct jz4740_rtc *rtc; - const struct platform_device_id *id = platform_get_device_id(pdev); - const struct of_device_id *of_id = of_match_device( - jz4740_rtc_of_match, &pdev->dev); struct device_node *np = pdev->dev.of_node; rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); if (!rtc) return -ENOMEM; - if (of_id) - rtc->type = (enum jz4740_rtc_type)of_id->data; - else - rtc->type = id->driver_data; + rtc->type = (enum jz4740_rtc_type)device_get_match_data(dev); rtc->irq = platform_get_irq(pdev, 0); if (rtc->irq < 0) @@ -370,7 +364,7 @@ static int jz4740_rtc_probe(struct platform_device *pdev) return ret; } - if (np && of_device_is_system_power_controller(np)) { + if (of_device_is_system_power_controller(np)) { if (!pm_power_off) { /* Default: 60ms */ rtc->reset_pin_assert_time = 60; @@ -395,20 +389,12 @@ static int jz4740_rtc_probe(struct platform_device *pdev) return 0; } -static const struct platform_device_id jz4740_rtc_ids[] = { - { "jz4740-rtc", ID_JZ4740 }, - { "jz4780-rtc", ID_JZ4780 }, - {} -}; -MODULE_DEVICE_TABLE(platform, jz4740_rtc_ids); - static struct platform_driver jz4740_rtc_driver = { .probe = jz4740_rtc_probe, .driver = { .name = "jz4740-rtc", - .of_match_table = of_match_ptr(jz4740_rtc_of_match), + .of_match_table = jz4740_rtc_of_match, }, - .id_table = jz4740_rtc_ids, }; module_platform_driver(jz4740_rtc_driver); -- cgit v1.2.3 From c61293f147738b4438639ef81124d5ea6246e610 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:31 +0200 Subject: rtc: ingenic: Use local 'dev' variable in probe Clean a bit the probe function by adding a local struct device *dev variable. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-2-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 949d395066e2..06ee08089815 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -307,11 +307,12 @@ MODULE_DEVICE_TABLE(of, jz4740_rtc_of_match); static int jz4740_rtc_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; int ret; struct jz4740_rtc *rtc; - struct device_node *np = pdev->dev.of_node; - rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); if (!rtc) return -ENOMEM; @@ -325,9 +326,9 @@ static int jz4740_rtc_probe(struct platform_device *pdev) if (IS_ERR(rtc->base)) return PTR_ERR(rtc->base); - rtc->clk = devm_clk_get(&pdev->dev, "rtc"); + rtc->clk = devm_clk_get(dev, "rtc"); if (IS_ERR(rtc->clk)) { - dev_err(&pdev->dev, "Failed to get RTC clock\n"); + dev_err(dev, "Failed to get RTC clock\n"); return PTR_ERR(rtc->clk); } @@ -335,18 +336,18 @@ static int jz4740_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc); - device_init_wakeup(&pdev->dev, 1); + device_init_wakeup(dev, 1); - ret = dev_pm_set_wake_irq(&pdev->dev, rtc->irq); + ret = dev_pm_set_wake_irq(dev, rtc->irq); if (ret) { - dev_err(&pdev->dev, "Failed to set wake irq: %d\n", ret); + dev_err(dev, "Failed to set wake irq: %d\n", ret); return ret; } - rtc->rtc = devm_rtc_allocate_device(&pdev->dev); + rtc->rtc = devm_rtc_allocate_device(dev); if (IS_ERR(rtc->rtc)) { ret = PTR_ERR(rtc->rtc); - dev_err(&pdev->dev, "Failed to allocate rtc device: %d\n", ret); + dev_err(dev, "Failed to allocate rtc device: %d\n", ret); return ret; } @@ -357,10 +358,10 @@ static int jz4740_rtc_probe(struct platform_device *pdev) if (ret) return ret; - ret = devm_request_irq(&pdev->dev, rtc->irq, jz4740_rtc_irq, 0, - pdev->name, rtc); + ret = devm_request_irq(dev, rtc->irq, jz4740_rtc_irq, 0, + pdev->name, rtc); if (ret) { - dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret); + dev_err(dev, "Failed to request rtc irq: %d\n", ret); return ret; } @@ -378,11 +379,10 @@ static int jz4740_rtc_probe(struct platform_device *pdev) "ingenic,min-wakeup-pin-assert-time-ms", &rtc->min_wakeup_pin_assert_time); - dev_for_power_off = &pdev->dev; + dev_for_power_off = dev; pm_power_off = jz4740_rtc_power_off; } else { - dev_warn(&pdev->dev, - "Poweroff handler already present!\n"); + dev_warn(dev, "Poweroff handler already present!\n"); } } -- cgit v1.2.3 From 796be8b59dec3efe840a251e2ecc0734408c5ff3 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:32 +0200 Subject: rtc: ingenic: Enable clock in probe It makes no sense to request a clock and not enable it even though the hardware is being used. So the driver now enables the clock in the probe. Besides, now we can properly handle errors. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-3-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 06ee08089815..129c68cebb92 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -264,8 +264,6 @@ static void jz4740_rtc_power_off(void) unsigned long wakeup_filter_ticks; unsigned long reset_counter_ticks; - clk_prepare_enable(rtc->clk); - rtc_rate = clk_get_rate(rtc->clk); /* @@ -297,6 +295,11 @@ static void jz4740_rtc_power_off(void) kernel_halt(); } +static void jz4740_rtc_clk_disable(void *data) +{ + clk_disable_unprepare(data); +} + static const struct of_device_id jz4740_rtc_of_match[] = { { .compatible = "ingenic,jz4740-rtc", .data = (void *)ID_JZ4740 }, { .compatible = "ingenic,jz4760-rtc", .data = (void *)ID_JZ4760 }, @@ -332,6 +335,18 @@ static int jz4740_rtc_probe(struct platform_device *pdev) return PTR_ERR(rtc->clk); } + ret = clk_prepare_enable(rtc->clk); + if (ret) { + dev_err(dev, "Failed to enable clock\n"); + return ret; + } + + ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, rtc->clk); + if (ret) { + dev_err(dev, "Failed to register devm action\n"); + return ret; + } + spin_lock_init(&rtc->lock); platform_set_drvdata(pdev, rtc); -- cgit v1.2.3 From fe0557f4dbd8cab3fd3a410212157d1a4b67de8b Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:33 +0200 Subject: rtc: ingenic: Set wakeup params in probe We can write the wakeup timing parameters as soon as the driver probes, there's no need to wait the very last moment. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-4-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 95 ++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 51 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 129c68cebb92..8927fd0fb086 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -60,9 +60,6 @@ struct jz4740_rtc { int irq; spinlock_t lock; - - unsigned int min_wakeup_pin_assert_time; - unsigned int reset_pin_assert_time; }; static struct device *dev_for_power_off; @@ -259,38 +256,6 @@ static void jz4740_rtc_poweroff(struct device *dev) static void jz4740_rtc_power_off(void) { - struct jz4740_rtc *rtc = dev_get_drvdata(dev_for_power_off); - unsigned long rtc_rate; - unsigned long wakeup_filter_ticks; - unsigned long reset_counter_ticks; - - rtc_rate = clk_get_rate(rtc->clk); - - /* - * Set minimum wakeup pin assertion time: 100 ms. - * Range is 0 to 2 sec if RTC is clocked at 32 kHz. - */ - wakeup_filter_ticks = - (rtc->min_wakeup_pin_assert_time * rtc_rate) / 1000; - if (wakeup_filter_ticks < JZ_RTC_WAKEUP_FILTER_MASK) - wakeup_filter_ticks &= JZ_RTC_WAKEUP_FILTER_MASK; - else - wakeup_filter_ticks = JZ_RTC_WAKEUP_FILTER_MASK; - jz4740_rtc_reg_write(rtc, - JZ_REG_RTC_WAKEUP_FILTER, wakeup_filter_ticks); - - /* - * Set reset pin low-level assertion time after wakeup: 60 ms. - * Range is 0 to 125 ms if RTC is clocked at 32 kHz. - */ - reset_counter_ticks = (rtc->reset_pin_assert_time * rtc_rate) / 1000; - if (reset_counter_ticks < JZ_RTC_RESET_COUNTER_MASK) - reset_counter_ticks &= JZ_RTC_RESET_COUNTER_MASK; - else - reset_counter_ticks = JZ_RTC_RESET_COUNTER_MASK; - jz4740_rtc_reg_write(rtc, - JZ_REG_RTC_RESET_COUNTER, reset_counter_ticks); - jz4740_rtc_poweroff(dev_for_power_off); kernel_halt(); } @@ -308,12 +273,49 @@ static const struct of_device_id jz4740_rtc_of_match[] = { }; MODULE_DEVICE_TABLE(of, jz4740_rtc_of_match); +static void jz4740_rtc_set_wakeup_params(struct jz4740_rtc *rtc, + struct device_node *np, + unsigned long rate) +{ + unsigned long wakeup_ticks, reset_ticks; + unsigned int min_wakeup_pin_assert_time = 60; /* Default: 60ms */ + unsigned int reset_pin_assert_time = 100; /* Default: 100ms */ + + of_property_read_u32(np, "ingenic,reset-pin-assert-time-ms", + &reset_pin_assert_time); + of_property_read_u32(np, "ingenic,min-wakeup-pin-assert-time-ms", + &min_wakeup_pin_assert_time); + + /* + * Set minimum wakeup pin assertion time: 100 ms. + * Range is 0 to 2 sec if RTC is clocked at 32 kHz. + */ + wakeup_ticks = (min_wakeup_pin_assert_time * rate) / 1000; + if (wakeup_ticks < JZ_RTC_WAKEUP_FILTER_MASK) + wakeup_ticks &= JZ_RTC_WAKEUP_FILTER_MASK; + else + wakeup_ticks = JZ_RTC_WAKEUP_FILTER_MASK; + jz4740_rtc_reg_write(rtc, JZ_REG_RTC_WAKEUP_FILTER, wakeup_ticks); + + /* + * Set reset pin low-level assertion time after wakeup: 60 ms. + * Range is 0 to 125 ms if RTC is clocked at 32 kHz. + */ + reset_ticks = (reset_pin_assert_time * rate) / 1000; + if (reset_ticks < JZ_RTC_RESET_COUNTER_MASK) + reset_ticks &= JZ_RTC_RESET_COUNTER_MASK; + else + reset_ticks = JZ_RTC_RESET_COUNTER_MASK; + jz4740_rtc_reg_write(rtc, JZ_REG_RTC_RESET_COUNTER, reset_ticks); +} + static int jz4740_rtc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; int ret; struct jz4740_rtc *rtc; + unsigned long rate; rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); if (!rtc) @@ -369,6 +371,9 @@ static int jz4740_rtc_probe(struct platform_device *pdev) rtc->rtc->ops = &jz4740_rtc_ops; rtc->rtc->range_max = U32_MAX; + rate = clk_get_rate(rtc->clk); + jz4740_rtc_set_wakeup_params(rtc, np, rate); + ret = rtc_register_device(rtc->rtc); if (ret) return ret; @@ -381,24 +386,12 @@ static int jz4740_rtc_probe(struct platform_device *pdev) } if (of_device_is_system_power_controller(np)) { - if (!pm_power_off) { - /* Default: 60ms */ - rtc->reset_pin_assert_time = 60; - of_property_read_u32(np, - "ingenic,reset-pin-assert-time-ms", - &rtc->reset_pin_assert_time); - - /* Default: 100ms */ - rtc->min_wakeup_pin_assert_time = 100; - of_property_read_u32(np, - "ingenic,min-wakeup-pin-assert-time-ms", - &rtc->min_wakeup_pin_assert_time); - - dev_for_power_off = dev; + dev_for_power_off = dev; + + if (!pm_power_off) pm_power_off = jz4740_rtc_power_off; - } else { + else dev_warn(dev, "Poweroff handler already present!\n"); - } } return 0; -- cgit v1.2.3 From 77d8f3c1226b2ae60b989568a102dd79a8b379f0 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:34 +0200 Subject: rtc: ingenic: Remove unused fields from private structure The 'clk' and 'irq' fields were only ever used in the probe function. Therefore they can be moved to be simple local variables of the probe function. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-5-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 8927fd0fb086..3193eb8bd131 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -55,9 +55,6 @@ struct jz4740_rtc { enum jz4740_rtc_type type; struct rtc_device *rtc; - struct clk *clk; - - int irq; spinlock_t lock; }; @@ -313,9 +310,10 @@ static int jz4740_rtc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - int ret; struct jz4740_rtc *rtc; unsigned long rate; + struct clk *clk; + int ret, irq; rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); if (!rtc) @@ -323,27 +321,27 @@ static int jz4740_rtc_probe(struct platform_device *pdev) rtc->type = (enum jz4740_rtc_type)device_get_match_data(dev); - rtc->irq = platform_get_irq(pdev, 0); - if (rtc->irq < 0) + irq = platform_get_irq(pdev, 0); + if (irq < 0) return -ENOENT; rtc->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(rtc->base)) return PTR_ERR(rtc->base); - rtc->clk = devm_clk_get(dev, "rtc"); - if (IS_ERR(rtc->clk)) { + clk = devm_clk_get(dev, "rtc"); + if (IS_ERR(clk)) { dev_err(dev, "Failed to get RTC clock\n"); - return PTR_ERR(rtc->clk); + return PTR_ERR(clk); } - ret = clk_prepare_enable(rtc->clk); + ret = clk_prepare_enable(clk); if (ret) { dev_err(dev, "Failed to enable clock\n"); return ret; } - ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, rtc->clk); + ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, clk); if (ret) { dev_err(dev, "Failed to register devm action\n"); return ret; @@ -355,7 +353,7 @@ static int jz4740_rtc_probe(struct platform_device *pdev) device_init_wakeup(dev, 1); - ret = dev_pm_set_wake_irq(dev, rtc->irq); + ret = dev_pm_set_wake_irq(dev, irq); if (ret) { dev_err(dev, "Failed to set wake irq: %d\n", ret); return ret; @@ -371,14 +369,14 @@ static int jz4740_rtc_probe(struct platform_device *pdev) rtc->rtc->ops = &jz4740_rtc_ops; rtc->rtc->range_max = U32_MAX; - rate = clk_get_rate(rtc->clk); + rate = clk_get_rate(clk); jz4740_rtc_set_wakeup_params(rtc, np, rate); ret = rtc_register_device(rtc->rtc); if (ret) return ret; - ret = devm_request_irq(dev, rtc->irq, jz4740_rtc_irq, 0, + ret = devm_request_irq(dev, irq, jz4740_rtc_irq, 0, pdev->name, rtc); if (ret) { dev_err(dev, "Failed to request rtc irq: %d\n", ret); -- cgit v1.2.3 From 15eeadd801c0ea65c44c01f243f45097ac5970a8 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:35 +0200 Subject: rtc: ingenic: Fix masking of error code The code was returning -ENOENT on any error of platform_get_irq(), even if it returned a different error. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-6-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 3193eb8bd131..65e130726fc6 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -323,7 +323,7 @@ static int jz4740_rtc_probe(struct platform_device *pdev) irq = platform_get_irq(pdev, 0); if (irq < 0) - return -ENOENT; + return irq; rtc->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(rtc->base)) -- cgit v1.2.3 From 378252b6e24f764a5e41eb4552f1c3989ca12e81 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 6 May 2020 00:13:36 +0200 Subject: rtc: ingenic: Reset regulator register in probe The regulator register specifies how many input clock cycles (minus one) are contained in one tick of the 1 Hz clock. Since this register can contain bogus values after the system boots, it needs to be reset in the probe register, otherwise the RTC may count way to slow or way too fast. Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20200505221336.222313-7-paul@crapouillou.net Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-jz4740.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 65e130726fc6..9607e6b6e0b3 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -372,6 +372,9 @@ static int jz4740_rtc_probe(struct platform_device *pdev) rate = clk_get_rate(clk); jz4740_rtc_set_wakeup_params(rtc, np, rate); + /* Each 1 Hz pulse should happen after (rate) ticks */ + jz4740_rtc_reg_write(rtc, JZ_REG_RTC_REGULATOR, rate - 1); + ret = rtc_register_device(rtc->rtc); if (ret) return ret; -- cgit v1.2.3 From 20af67700bc39bccd838414128f63a72965de6e7 Mon Sep 17 00:00:00 2001 From: Anson Huang Date: Fri, 22 May 2020 10:19:55 +0800 Subject: rtc: snvs: Make SNVS clock always prepared In IRQ handler, ONLY clock enable/disable is called due to clock prepare can NOT be called in interrupt context, but clock enable/disable will return failure if prepare count is 0, to fix this issue, just make SNVS clock always prepared there, the SNVS clock has no prepare function implemented, so it won't impact anything. Signed-off-by: Anson Huang Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/1590113996-31845-1-git-send-email-Anson.Huang@nxp.com --- drivers/rtc/rtc-snvs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index 35ee08aa7584..b9371f471abe 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c @@ -362,7 +362,7 @@ static int __maybe_unused snvs_rtc_suspend_noirq(struct device *dev) struct snvs_rtc_data *data = dev_get_drvdata(dev); if (data->clk) - clk_disable_unprepare(data->clk); + clk_disable(data->clk); return 0; } @@ -372,7 +372,7 @@ static int __maybe_unused snvs_rtc_resume_noirq(struct device *dev) struct snvs_rtc_data *data = dev_get_drvdata(dev); if (data->clk) - return clk_prepare_enable(data->clk); + return clk_enable(data->clk); return 0; } -- cgit v1.2.3 From 4b957bde561f3a56865395be06f1be2c196b0b5e Mon Sep 17 00:00:00 2001 From: Anson Huang Date: Fri, 22 May 2020 10:19:56 +0800 Subject: rtc: snvs: Add necessary clock operations for RTC APIs There could be still RTC registers access after RTC suspend with clock disabled, need to add clock operations for each RTC API to make sure accessing RTC registers is successfully. Signed-off-by: Anson Huang Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/1590113996-31845-2-git-send-email-Anson.Huang@nxp.com --- drivers/rtc/rtc-snvs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index b9371f471abe..0263d996b8a8 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c @@ -148,10 +148,21 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable) static int snvs_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct snvs_rtc_data *data = dev_get_drvdata(dev); - unsigned long time = rtc_read_lp_counter(data); + unsigned long time; + int ret; + + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } + time = rtc_read_lp_counter(data); rtc_time64_to_tm(time, tm); + if (data->clk) + clk_disable(data->clk); + return 0; } @@ -161,6 +172,12 @@ static int snvs_rtc_set_time(struct device *dev, struct rtc_time *tm) unsigned long time = rtc_tm_to_time64(tm); int ret; + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } + /* Disable RTC first */ ret = snvs_rtc_enable(data, false); if (ret) @@ -173,6 +190,9 @@ static int snvs_rtc_set_time(struct device *dev, struct rtc_time *tm) /* Enable RTC again */ ret = snvs_rtc_enable(data, true); + if (data->clk) + clk_disable(data->clk); + return ret; } @@ -180,6 +200,13 @@ static int snvs_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct snvs_rtc_data *data = dev_get_drvdata(dev); u32 lptar, lpsr; + int ret; + + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } regmap_read(data->regmap, data->offset + SNVS_LPTAR, &lptar); rtc_time64_to_tm(lptar, &alrm->time); @@ -187,18 +214,33 @@ static int snvs_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) regmap_read(data->regmap, data->offset + SNVS_LPSR, &lpsr); alrm->pending = (lpsr & SNVS_LPSR_LPTA) ? 1 : 0; + if (data->clk) + clk_disable(data->clk); + return 0; } static int snvs_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) { struct snvs_rtc_data *data = dev_get_drvdata(dev); + int ret; + + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, (SNVS_LPCR_LPTA_EN | SNVS_LPCR_LPWUI_EN), enable ? (SNVS_LPCR_LPTA_EN | SNVS_LPCR_LPWUI_EN) : 0); - return rtc_write_sync_lp(data); + ret = rtc_write_sync_lp(data); + + if (data->clk) + clk_disable(data->clk); + + return ret; } static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) @@ -207,6 +249,12 @@ static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) unsigned long time = rtc_tm_to_time64(&alrm->time); int ret; + if (data->clk) { + ret = clk_enable(data->clk); + if (ret) + return ret; + } + regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, SNVS_LPCR_LPTA_EN, 0); ret = rtc_write_sync_lp(data); if (ret) @@ -216,6 +264,9 @@ static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) /* Clear alarm interrupt status bit */ regmap_write(data->regmap, data->offset + SNVS_LPSR, SNVS_LPSR_LPTA); + if (data->clk) + clk_disable(data->clk); + return snvs_rtc_alarm_irq_enable(dev, alrm->enabled); } -- cgit v1.2.3 From f4c29a09cccb954f027bf0793877fdd42e5db88f Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Mon, 25 May 2020 09:39:47 +0800 Subject: rtc: goldfish: Use correct return value for goldfish_rtc_probe() When call function devm_platform_ioremap_resource(), we should use IS_ERR() to check the return value and return PTR_ERR() if failed. Signed-off-by: Tiezhu Yang Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/1590370788-15136-1-git-send-email-yangtiezhu@loongson.cn --- drivers/rtc/rtc-goldfish.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-goldfish.c b/drivers/rtc/rtc-goldfish.c index cb6b0ad7ec3f..27797157fcb3 100644 --- a/drivers/rtc/rtc-goldfish.c +++ b/drivers/rtc/rtc-goldfish.c @@ -174,7 +174,7 @@ static int goldfish_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtcdrv); rtcdrv->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(rtcdrv->base)) - return -ENODEV; + return PTR_ERR(rtcdrv->base); rtcdrv->irq = platform_get_irq(pdev, 0); if (rtcdrv->irq < 0) -- cgit v1.2.3 From 710e4a82d6f09ce75eb73e6adb8caf2b0d6cf4c6 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Mon, 25 May 2020 09:39:48 +0800 Subject: rtc: mpc5121: Use correct return value for mpc5121_rtc_probe() When call function devm_platform_ioremap_resource(), we should use IS_ERR() to check the return value and return PTR_ERR() if failed. Signed-off-by: Tiezhu Yang Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/1590370788-15136-2-git-send-email-yangtiezhu@loongson.cn --- drivers/rtc/rtc-mpc5121.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c index 3040844129ce..5c2ce71aa044 100644 --- a/drivers/rtc/rtc-mpc5121.c +++ b/drivers/rtc/rtc-mpc5121.c @@ -316,7 +316,7 @@ static int mpc5121_rtc_probe(struct platform_device *op) rtc->regs = devm_platform_ioremap_resource(op, 0); if (IS_ERR(rtc->regs)) { dev_err(&op->dev, "%s: couldn't map io space\n", __func__); - return -ENOSYS; + return PTR_ERR(rtc->regs); } device_init_wakeup(&op->dev, 1); -- cgit v1.2.3 From c3b29bf6f166f6ed5f04f9c125477358e0e25df8 Mon Sep 17 00:00:00 2001 From: Chuhong Yuan Date: Thu, 28 May 2020 18:39:50 +0800 Subject: rtc: rv3028: Add missed check for devm_regmap_init_i2c() rv3028_probe() misses a check for devm_regmap_init_i2c(). Add the missed check to fix it. Fixes: e6e7376cfd7b ("rtc: rv3028: add new driver") Signed-off-by: Chuhong Yuan Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20200528103950.912353-1-hslester96@gmail.com --- drivers/rtc/rtc-rv3028.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/rtc/rtc-rv3028.c b/drivers/rtc/rtc-rv3028.c index a0ddc86c975a..ec84db0b3d7a 100644 --- a/drivers/rtc/rtc-rv3028.c +++ b/drivers/rtc/rtc-rv3028.c @@ -755,6 +755,8 @@ static int rv3028_probe(struct i2c_client *client) return -ENOMEM; rv3028->regmap = devm_regmap_init_i2c(client, ®map_config); + if (IS_ERR(rv3028->regmap)) + return PTR_ERR(rv3028->regmap); i2c_set_clientdata(client, rv3028); -- cgit v1.2.3 From ac363ace16e044cc7a4da38611889091c4d6fecb Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Thu, 28 May 2020 07:46:17 -0400 Subject: rtc: abx80x: Add Device Tree matching table Enable automatic loading of the module when a Device Tree overlay specifies a device supported by this driver. Signed-off-by: Kevin P. Fleming Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20200528114617.166587-1-kevin+linux@km6g.us --- drivers/rtc/rtc-abx80x.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'drivers') diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c index 3521d8e8dc38..67bf3b8cfe65 100644 --- a/drivers/rtc/rtc-abx80x.c +++ b/drivers/rtc/rtc-abx80x.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -863,9 +864,57 @@ static const struct i2c_device_id abx80x_id[] = { }; MODULE_DEVICE_TABLE(i2c, abx80x_id); +#ifdef CONFIG_OF +static const struct of_device_id abx80x_of_match[] = { + { + .compatible = "abracon,abx80x", + .data = (void *)ABX80X + }, + { + .compatible = "abracon,ab0801", + .data = (void *)AB0801 + }, + { + .compatible = "abracon,ab0803", + .data = (void *)AB0803 + }, + { + .compatible = "abracon,ab0804", + .data = (void *)AB0804 + }, + { + .compatible = "abracon,ab0805", + .data = (void *)AB0805 + }, + { + .compatible = "abracon,ab1801", + .data = (void *)AB1801 + }, + { + .compatible = "abracon,ab1803", + .data = (void *)AB1803 + }, + { + .compatible = "abracon,ab1804", + .data = (void *)AB1804 + }, + { + .compatible = "abracon,ab1805", + .data = (void *)AB1805 + }, + { + .compatible = "microcrystal,rv1805", + .data = (void *)RV1805 + }, + { } +}; +MODULE_DEVICE_TABLE(of, abx80x_of_match); +#endif + static struct i2c_driver abx80x_driver = { .driver = { .name = "rtc-abx80x", + .of_match_table = of_match_ptr(abx80x_of_match), }, .probe = abx80x_probe, .id_table = abx80x_id, -- cgit v1.2.3 From 6e429f6b8c6b8f40874c50c1e8485783dd0f97a8 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Sat, 30 May 2020 08:29:56 -0400 Subject: rtc: abx80x: Provide debug feedback for invalid dt properties When the user provides an invalid value for tc-diode or tc-resistor generate a debug message instead of silently ignoring it. Signed-off-by: Kevin P. Fleming Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20200530122956.360689-1-kevin+linux@km6g.us --- drivers/rtc/rtc-abx80x.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c index 67bf3b8cfe65..803725b3a02c 100644 --- a/drivers/rtc/rtc-abx80x.c +++ b/drivers/rtc/rtc-abx80x.c @@ -555,8 +555,9 @@ static const struct rtc_class_ops abx80x_rtc_ops = { .ioctl = abx80x_ioctl, }; -static int abx80x_dt_trickle_cfg(struct device_node *np) +static int abx80x_dt_trickle_cfg(struct i2c_client *client) { + struct device_node *np = client->dev.of_node; const char *diode; int trickle_cfg = 0; int i, ret; @@ -566,12 +567,14 @@ static int abx80x_dt_trickle_cfg(struct device_node *np) if (ret) return ret; - if (!strcmp(diode, "standard")) + if (!strcmp(diode, "standard")) { trickle_cfg |= ABX8XX_TRICKLE_STANDARD_DIODE; - else if (!strcmp(diode, "schottky")) + } else if (!strcmp(diode, "schottky")) { trickle_cfg |= ABX8XX_TRICKLE_SCHOTTKY_DIODE; - else + } else { + dev_dbg(&client->dev, "Invalid tc-diode value: %s\n", diode); return -EINVAL; + } ret = of_property_read_u32(np, "abracon,tc-resistor", &tmp); if (ret) @@ -581,8 +584,10 @@ static int abx80x_dt_trickle_cfg(struct device_node *np) if (trickle_resistors[i] == tmp) break; - if (i == sizeof(trickle_resistors)) + if (i == sizeof(trickle_resistors)) { + dev_dbg(&client->dev, "Invalid tc-resistor value: %u\n", tmp); return -EINVAL; + } return (trickle_cfg | i); } @@ -794,7 +799,7 @@ static int abx80x_probe(struct i2c_client *client, } if (np && abx80x_caps[part].has_tc) - trickle_cfg = abx80x_dt_trickle_cfg(np); + trickle_cfg = abx80x_dt_trickle_cfg(client); if (trickle_cfg > 0) { dev_info(&client->dev, "Enabling trickle charger: %02x\n", -- cgit v1.2.3 From 3a8ce46ce15accad53b39837735c12d886964211 Mon Sep 17 00:00:00 2001 From: Ran Wang Date: Mon, 1 Jun 2020 15:19:14 +0800 Subject: rtc: fsl-ftm-alarm: fix freeze(s2idle) failed to wake Use dev_pm_set_wake_irq() instead of flag IRQF_NO_SUSPEND to enable wakeup system feature for both freeze(s2idle) and mem(deep). Signed-off-by: Ran Wang Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20200601071914.36444-1-ran.wang_1@nxp.com --- drivers/rtc/rtc-fsl-ftm-alarm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c index 23c811da4801..68f0a1801a2e 100644 --- a/drivers/rtc/rtc-fsl-ftm-alarm.c +++ b/drivers/rtc/rtc-fsl-ftm-alarm.c @@ -21,6 +21,7 @@ #include #include #include +#include #define FTM_SC_CLK(c) ((c) << FTM_SC_CLK_MASK_SHIFT) @@ -272,7 +273,7 @@ static int ftm_rtc_probe(struct platform_device *pdev) return irq; ret = devm_request_irq(&pdev->dev, irq, ftm_rtc_alarm_interrupt, - IRQF_NO_SUSPEND, dev_name(&pdev->dev), rtc); + 0, dev_name(&pdev->dev), rtc); if (ret < 0) { dev_err(&pdev->dev, "failed to request irq\n"); return ret; @@ -285,6 +286,9 @@ static int ftm_rtc_probe(struct platform_device *pdev) rtc->rtc_dev->ops = &ftm_rtc_ops; device_init_wakeup(&pdev->dev, true); + ret = dev_pm_set_wake_irq(&pdev->dev, irq); + if (ret) + dev_err(&pdev->dev, "failed to enable irq wake\n"); ret = rtc_register_device(rtc->rtc_dev); if (ret) { -- cgit v1.2.3 From 4601e24a6fb819d38d1156d0f690cbe6a42c6d76 Mon Sep 17 00:00:00 2001 From: Bruno Thomsen Date: Thu, 4 Jun 2020 18:26:02 +0200 Subject: rtc: pcf2127: watchdog: handle nowayout feature Driver does not use module parameter for nowayout, so it need to statically initialize status variable of the watchdog_device based on CONFIG_WATCHDOG_NOWAYOUT. Signed-off-by: Bruno Thomsen Signed-off-by: Alexandre Belloni Acked-by: Guenter Roeck Link: https://lore.kernel.org/r/20200604162602.76524-1-bruno.thomsen@gmail.com --- drivers/rtc/rtc-pcf2127.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index e5e3cd128476..9c5670776c68 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -448,6 +448,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, pcf2127->wdd.max_timeout = PCF2127_WD_VAL_MAX; pcf2127->wdd.timeout = PCF2127_WD_VAL_DEFAULT; pcf2127->wdd.min_hw_heartbeat_ms = 500; + pcf2127->wdd.status = WATCHDOG_NOWAYOUT_INIT_STATUS; watchdog_set_drvdata(&pcf2127->wdd, pcf2127); -- cgit v1.2.3