diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-26 04:55:33 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-26 04:55:33 +0300 |
commit | c13c81006314ad76c2b31824960a900385601b8b (patch) | |
tree | 749f71b07f252960775c42bd1141d21cb35a768d /drivers/rtc/rtc-gemini.c | |
parent | 24867481b8c0a3bc3ab53b634e3cc03680ac3ac6 (diff) | |
parent | 3783055ef4cf096910f670f9a1a32e32db08559b (diff) | |
download | linux-c13c81006314ad76c2b31824960a900385601b8b.tar.xz |
Merge tag 'rtc-v4.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni:
"Core:
- Coding style and whitespace fixes (interface, Makefile and Kconfig)
- New rtc_tm_sub() helper
- New CONFIG_RTC_SYSTOHC_DEVICE option
- Removed rtc_set_mmss()
New drivers:
- Mediatek MT6397
- Cortina Gemini
Drivers:
- Year 2106 fixes for isl1208, pcf8563 and sunxi
- update author email for at32ap700x and efi
- ds1307: alarm fix
- efi: use correct EFI 'epoch'
- hym8563: make irq optional
- imxdi: cleanups and better handling of the security/tamper monitoring
- snvs: fix wakealarm
- Compilation fixes or warning removal for gemini, mt6397, palmas, pfc8563
- Trivial cleanups for ab8500, ds1216, ds1286, ds1672, ep93xx,
hid-sensor-time, max6900, max8998, max77686, max77802, mc13xxx, mv,
mxc, s3c, spear, v3020
- Kconfig fixes for stmp3xxx and xgene"
* tag 'rtc-v4.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (48 commits)
rtc: remove useless I2C dependencies
rtc: whitespace fixes
rtc: Properly sort Makefile
MAINTAINERS: Add RTC subsystem repository
rtc: pfc8563: fix uninitialized variable warning
rtc: ds1307: Enable the mcp794xx alarm after programming time
rtc: hym8563: make the irq optional
rtc: gemini: fix cocci warnings
rtc: mv: correct 24 hour error message
rtc: mv: use BIT()
rtc: efi: use correct EFI 'epoch'
rtc: interface: Remove rtc_set_mmss()
sparc: time: Replace update_persistent_clock() with CONFIG_RTC_SYSTOHC
rtc: NTP: Add CONFIG_RTC_SYSTOHC_DEVICE for NTP synchronization
rtc: sunxi: Replace deprecated rtc_tm_to_time()
rtc: isl1208: Replace deprecated rtc_tm_to_time()
rtc: Introduce rtc_tm_sub() helper function
rtc: pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time()
rtc: palmas: Initialise bb_charging flag before using it
rtc: simplify use of devm_ioremap_resource
...
Diffstat (limited to 'drivers/rtc/rtc-gemini.c')
-rw-r--r-- | drivers/rtc/rtc-gemini.c | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-gemini.c b/drivers/rtc/rtc-gemini.c new file mode 100644 index 000000000000..35f4486738fc --- /dev/null +++ b/drivers/rtc/rtc-gemini.c @@ -0,0 +1,175 @@ +/* + * Gemini OnChip RTC + * + * Copyright (C) 2009 Janos Laube <janos.dev@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Original code for older kernel 2.6.15 are from Stormlinksemi + * first update from Janos Laube for > 2.6.29 kernels + * + * checkpatch fixes and usage of rtc-lib code + * Hans Ulli Kroll <ulli.kroll@googlemail.com> + */ + +#include <linux/rtc.h> +#include <linux/io.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/kernel.h> +#include <linux/module.h> + +#define DRV_NAME "rtc-gemini" +#define DRV_VERSION "0.2" + +MODULE_AUTHOR("Hans Ulli Kroll <ulli.kroll@googlemail.com>"); +MODULE_DESCRIPTION("RTC driver for Gemini SoC"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" DRV_NAME); + +struct gemini_rtc { + struct rtc_device *rtc_dev; + void __iomem *rtc_base; + int rtc_irq; +}; + +enum gemini_rtc_offsets { + GEMINI_RTC_SECOND = 0x00, + GEMINI_RTC_MINUTE = 0x04, + GEMINI_RTC_HOUR = 0x08, + GEMINI_RTC_DAYS = 0x0C, + GEMINI_RTC_ALARM_SECOND = 0x10, + GEMINI_RTC_ALARM_MINUTE = 0x14, + GEMINI_RTC_ALARM_HOUR = 0x18, + GEMINI_RTC_RECORD = 0x1C, + GEMINI_RTC_CR = 0x20 +}; + +static irqreturn_t gemini_rtc_interrupt(int irq, void *dev) +{ + return IRQ_HANDLED; +} + +/* + * Looks like the RTC in the Gemini SoC is (totaly) broken + * We can't read/write directly the time from RTC registers. + * We must do some "offset" calculation to get the real time + * + * This FIX works pretty fine and Stormlinksemi aka Cortina-Networks does + * the same thing, without the rtc-lib.c calls. + */ + +static int gemini_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct gemini_rtc *rtc = dev_get_drvdata(dev); + + unsigned int days, hour, min, sec; + unsigned long offset, time; + + sec = readl(rtc->rtc_base + GEMINI_RTC_SECOND); + min = readl(rtc->rtc_base + GEMINI_RTC_MINUTE); + hour = readl(rtc->rtc_base + GEMINI_RTC_HOUR); + days = readl(rtc->rtc_base + GEMINI_RTC_DAYS); + offset = readl(rtc->rtc_base + GEMINI_RTC_RECORD); + + time = offset + days * 86400 + hour * 3600 + min * 60 + sec; + + rtc_time_to_tm(time, tm); + + return 0; +} + +static int gemini_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct gemini_rtc *rtc = dev_get_drvdata(dev); + unsigned int sec, min, hour, day; + unsigned long offset, time; + + if (tm->tm_year >= 2148) /* EPOCH Year + 179 */ + return -EINVAL; + + rtc_tm_to_time(tm, &time); + + sec = readl(rtc->rtc_base + GEMINI_RTC_SECOND); + min = readl(rtc->rtc_base + GEMINI_RTC_MINUTE); + hour = readl(rtc->rtc_base + GEMINI_RTC_HOUR); + day = readl(rtc->rtc_base + GEMINI_RTC_DAYS); + + offset = time - (day * 86400 + hour * 3600 + min * 60 + sec); + + writel(offset, rtc->rtc_base + GEMINI_RTC_RECORD); + writel(0x01, rtc->rtc_base + GEMINI_RTC_CR); + + return 0; +} + +static struct rtc_class_ops gemini_rtc_ops = { + .read_time = gemini_rtc_read_time, + .set_time = gemini_rtc_set_time, +}; + +static int gemini_rtc_probe(struct platform_device *pdev) +{ + struct gemini_rtc *rtc; + struct device *dev = &pdev->dev; + struct resource *res; + int ret; + + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + if (unlikely(!rtc)) + return -ENOMEM; + platform_set_drvdata(pdev, rtc); + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res) + return -ENODEV; + + rtc->rtc_irq = res->start; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + rtc->rtc_base = devm_ioremap(dev, res->start, + resource_size(res)); + + ret = devm_request_irq(dev, rtc->rtc_irq, gemini_rtc_interrupt, + IRQF_SHARED, pdev->name, dev); + if (unlikely(ret)) + return ret; + + rtc->rtc_dev = rtc_device_register(pdev->name, dev, + &gemini_rtc_ops, THIS_MODULE); + if (likely(IS_ERR(rtc->rtc_dev))) + return PTR_ERR(rtc->rtc_dev); + + return 0; +} + +static int gemini_rtc_remove(struct platform_device *pdev) +{ + struct gemini_rtc *rtc = platform_get_drvdata(pdev); + + rtc_device_unregister(rtc->rtc_dev); + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static struct platform_driver gemini_rtc_driver = { + .driver = { + .name = DRV_NAME, + }, + .probe = gemini_rtc_probe, + .remove = gemini_rtc_remove, +}; + +module_platform_driver_probe(gemini_rtc_driver, gemini_rtc_probe); |