diff options
| author | Baruch Siach <baruch@tkos.co.il> | 2015-04-16 15:45:40 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:04:01 -0400 |
| commit | ba17220878bf74b95ea24de568939e7b9e1b02db (patch) | |
| tree | 6e825fc5b30a3a161b8cdd4b6bc4f1603d399d80 /drivers/rtc | |
| parent | 71b800b628570ce315a3f820b79969e460cd297f (diff) | |
rtc: driver for Conexant Digicolor CX92755 on-chip RTC
Add driver for the RTC hardware block on the Conexant CX92755 SoC, from
the Digicolor series of SoCs. Tested on the Equinox evaluation board for
the CX92755 chip.
[akpm@linux-foundation.org: build command arrays at compile-time]
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
| -rw-r--r-- | drivers/rtc/Kconfig | 10 | ||||
| -rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
| -rw-r--r-- | drivers/rtc/rtc-digicolor.c | 227 |
3 files changed, 238 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index b5b5c3d485d6..faeee2d2550b 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
| @@ -1111,6 +1111,16 @@ config RTC_DRV_DAVINCI | |||
| 1111 | This driver can also be built as a module. If so, the module | 1111 | This driver can also be built as a module. If so, the module |
| 1112 | will be called rtc-davinci. | 1112 | will be called rtc-davinci. |
| 1113 | 1113 | ||
| 1114 | config RTC_DRV_DIGICOLOR | ||
| 1115 | tristate "Conexant Digicolor RTC" | ||
| 1116 | depends on ARCH_DIGICOLOR | ||
| 1117 | help | ||
| 1118 | If you say yes here you get support for the RTC on Conexant | ||
| 1119 | Digicolor platforms. This currently includes the CX92755 SoC. | ||
| 1120 | |||
| 1121 | This driver can also be built as a module. If so, the module | ||
| 1122 | will be called rtc-digicolor. | ||
| 1123 | |||
| 1114 | config RTC_DRV_IMXDI | 1124 | config RTC_DRV_IMXDI |
| 1115 | tristate "Freescale IMX DryIce Real Time Clock" | 1125 | tristate "Freescale IMX DryIce Real Time Clock" |
| 1116 | depends on ARCH_MXC | 1126 | depends on ARCH_MXC |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 69c87062b098..c31731c29762 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
| @@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_DA9052) += rtc-da9052.o | |||
| 40 | obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o | 40 | obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o |
| 41 | obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o | 41 | obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o |
| 42 | obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o | 42 | obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o |
| 43 | obj-$(CONFIG_RTC_DRV_DIGICOLOR) += rtc-digicolor.o | ||
| 43 | obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o | 44 | obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o |
| 44 | obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o | 45 | obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o |
| 45 | obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o | 46 | obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o |
diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c new file mode 100644 index 000000000000..8d05596a6765 --- /dev/null +++ b/drivers/rtc/rtc-digicolor.c | |||
| @@ -0,0 +1,227 @@ | |||
| 1 | /* | ||
| 2 | * Real Time Clock driver for Conexant Digicolor | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 Paradox Innovation Ltd. | ||
| 5 | * | ||
| 6 | * Author: Baruch Siach <baruch@tkos.co.il> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License as published by the | ||
| 10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 11 | * option) any later version. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/io.h> | ||
| 15 | #include <linux/iopoll.h> | ||
| 16 | #include <linux/delay.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/platform_device.h> | ||
| 19 | #include <linux/rtc.h> | ||
| 20 | #include <linux/of.h> | ||
| 21 | |||
| 22 | #define DC_RTC_CONTROL 0x0 | ||
| 23 | #define DC_RTC_TIME 0x8 | ||
| 24 | #define DC_RTC_REFERENCE 0xc | ||
| 25 | #define DC_RTC_ALARM 0x10 | ||
| 26 | #define DC_RTC_INTFLAG_CLEAR 0x14 | ||
| 27 | #define DC_RTC_INTENABLE 0x16 | ||
| 28 | |||
| 29 | #define DC_RTC_CMD_MASK 0xf | ||
| 30 | #define DC_RTC_GO_BUSY BIT(7) | ||
| 31 | |||
| 32 | #define CMD_NOP 0 | ||
| 33 | #define CMD_RESET 1 | ||
| 34 | #define CMD_WRITE 3 | ||
| 35 | #define CMD_READ 4 | ||
| 36 | |||
| 37 | #define CMD_DELAY_US (10*1000) | ||
| 38 | #define CMD_TIMEOUT_US (500*CMD_DELAY_US) | ||
| 39 | |||
| 40 | struct dc_rtc { | ||
| 41 | struct rtc_device *rtc_dev; | ||
| 42 | void __iomem *regs; | ||
| 43 | }; | ||
| 44 | |||
| 45 | static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len) | ||
| 46 | { | ||
| 47 | u8 val; | ||
| 48 | int i, ret; | ||
| 49 | |||
| 50 | for (i = 0; i < len; i++) { | ||
| 51 | writeb_relaxed((cmds[i] & DC_RTC_CMD_MASK) | DC_RTC_GO_BUSY, | ||
| 52 | rtc->regs + DC_RTC_CONTROL); | ||
| 53 | ret = readb_relaxed_poll_timeout( | ||
| 54 | rtc->regs + DC_RTC_CONTROL, val, | ||
| 55 | !(val & DC_RTC_GO_BUSY), CMD_DELAY_US, CMD_TIMEOUT_US); | ||
| 56 | if (ret < 0) | ||
| 57 | return ret; | ||
| 58 | } | ||
| 59 | |||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val) | ||
| 64 | { | ||
| 65 | static const u8 read_cmds[] = {CMD_READ, CMD_NOP}; | ||
| 66 | u32 reference, time1, time2; | ||
| 67 | int ret; | ||
| 68 | |||
| 69 | ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds)); | ||
| 70 | if (ret < 0) | ||
| 71 | return ret; | ||
| 72 | |||
| 73 | reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); | ||
| 74 | time1 = readl_relaxed(rtc->regs + DC_RTC_TIME); | ||
| 75 | /* Read twice to ensure consistency */ | ||
| 76 | while (1) { | ||
| 77 | time2 = readl_relaxed(rtc->regs + DC_RTC_TIME); | ||
| 78 | if (time1 == time2) | ||
| 79 | break; | ||
| 80 | time1 = time2; | ||
| 81 | } | ||
| 82 | |||
| 83 | *val = reference + time1; | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int dc_rtc_write(struct dc_rtc *rtc, u32 val) | ||
| 88 | { | ||
| 89 | static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP}; | ||
| 90 | |||
| 91 | writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE); | ||
| 92 | return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds)); | ||
| 93 | } | ||
| 94 | |||
| 95 | static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
| 96 | { | ||
| 97 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 98 | unsigned long now; | ||
| 99 | int ret; | ||
| 100 | |||
| 101 | ret = dc_rtc_read(rtc, &now); | ||
| 102 | if (ret < 0) | ||
| 103 | return ret; | ||
| 104 | rtc_time64_to_tm(now, tm); | ||
| 105 | |||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | |||
| 109 | static int dc_rtc_set_mmss(struct device *dev, unsigned long secs) | ||
| 110 | { | ||
| 111 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 112 | |||
| 113 | return dc_rtc_write(rtc, secs); | ||
| 114 | } | ||
| 115 | |||
| 116 | static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 117 | { | ||
| 118 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 119 | u32 alarm_reg, reference; | ||
| 120 | unsigned long now; | ||
| 121 | int ret; | ||
| 122 | |||
| 123 | alarm_reg = readl_relaxed(rtc->regs + DC_RTC_ALARM); | ||
| 124 | reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); | ||
| 125 | rtc_time64_to_tm(reference + alarm_reg, &alarm->time); | ||
| 126 | |||
| 127 | ret = dc_rtc_read(rtc, &now); | ||
| 128 | if (ret < 0) | ||
| 129 | return ret; | ||
| 130 | |||
| 131 | alarm->pending = alarm_reg + reference > now; | ||
| 132 | alarm->enabled = readl_relaxed(rtc->regs + DC_RTC_INTENABLE); | ||
| 133 | |||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | static int dc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | ||
| 138 | { | ||
| 139 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 140 | time64_t alarm_time; | ||
| 141 | u32 reference; | ||
| 142 | |||
| 143 | alarm_time = rtc_tm_to_time64(&alarm->time); | ||
| 144 | |||
| 145 | reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE); | ||
| 146 | writel_relaxed(alarm_time - reference, rtc->regs + DC_RTC_ALARM); | ||
| 147 | |||
| 148 | writeb_relaxed(!!alarm->enabled, rtc->regs + DC_RTC_INTENABLE); | ||
| 149 | |||
| 150 | return 0; | ||
| 151 | } | ||
| 152 | |||
| 153 | static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | ||
| 154 | { | ||
| 155 | struct dc_rtc *rtc = dev_get_drvdata(dev); | ||
| 156 | |||
| 157 | writeb_relaxed(!!enabled, rtc->regs + DC_RTC_INTENABLE); | ||
| 158 | |||
| 159 | return 0; | ||
