diff options
| author | Torben Hohn <torbenh@linutronix.de> | 2013-02-21 19:44:40 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-21 20:22:28 -0500 |
| commit | cce2da9a1fc6ef144d830587080476fec283d670 (patch) | |
| tree | 4cb6681a593dc851940caefd44abf8d6dda41ec5 /drivers/rtc | |
| parent | 225ccc28726ca8849e5bfc9148c343e258737f3b (diff) | |
rtc: add support for spi rtc rx4581
[akpm@linux-foundation.org: checkpatch fixes]
Signed-off-by: Torben Hohn <torbenh@linutronix.de>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
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 | 8 | ||||
| -rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
| -rw-r--r-- | drivers/rtc/rtc-rx4581.c | 314 |
3 files changed, 323 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index d52183440691..2e340763ba47 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
| @@ -561,6 +561,14 @@ config RTC_DRV_PCF2123 | |||
| 561 | This driver can also be built as a module. If so, the module | 561 | This driver can also be built as a module. If so, the module |
| 562 | will be called rtc-pcf2123. | 562 | will be called rtc-pcf2123. |
| 563 | 563 | ||
| 564 | config RTC_DRV_RX4581 | ||
| 565 | tristate "Epson RX-4581" | ||
| 566 | help | ||
| 567 | If you say yes here you will get support for the Epson RX-4581. | ||
| 568 | |||
| 569 | This driver can also be built as a module. If so the module | ||
| 570 | will be called rtc-rx4581. | ||
| 571 | |||
| 564 | endif # SPI_MASTER | 572 | endif # SPI_MASTER |
| 565 | 573 | ||
| 566 | comment "Platform RTC drivers" | 574 | comment "Platform RTC drivers" |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index cd03fb33c14c..afd284d33714 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
| @@ -98,6 +98,7 @@ obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o | |||
| 98 | obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o | 98 | obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o |
| 99 | obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o | 99 | obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o |
| 100 | obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o | 100 | obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o |
| 101 | obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o | ||
| 101 | obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o | 102 | obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o |
| 102 | obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o | 103 | obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o |
| 103 | obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o | 104 | obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o |
diff --git a/drivers/rtc/rtc-rx4581.c b/drivers/rtc/rtc-rx4581.c new file mode 100644 index 000000000000..599ec73ec886 --- /dev/null +++ b/drivers/rtc/rtc-rx4581.c | |||
| @@ -0,0 +1,314 @@ | |||
| 1 | /* drivers/rtc/rtc-rx4581.c | ||
| 2 | * | ||
| 3 | * written by Torben Hohn <torbenh@linutronix.de> | ||
| 4 | * | ||
| 5 | * Based on: | ||
| 6 | * drivers/rtc/rtc-max6902.c | ||
| 7 | * | ||
| 8 | * Copyright (C) 2006 8D Technologies inc. | ||
| 9 | * Copyright (C) 2004 Compulab Ltd. | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or modify | ||
| 12 | * it under the terms of the GNU General Public License version 2 as | ||
| 13 | * published by the Free Software Foundation. | ||
| 14 | * | ||
| 15 | * Driver for MAX6902 spi RTC | ||
| 16 | * | ||
| 17 | * and based on: | ||
| 18 | * drivers/rtc/rtc-rx8581.c | ||
| 19 | * | ||
| 20 | * An I2C driver for the Epson RX8581 RTC | ||
| 21 | * | ||
| 22 | * Author: Martyn Welch <martyn.welch@ge.com> | ||
| 23 | * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc. | ||
| 24 | * | ||
| 25 | * This program is free software; you can redistribute it and/or modify | ||
| 26 | * it under the terms of the GNU General Public License version 2 as | ||
| 27 | * published by the Free Software Foundation. | ||
| 28 | * | ||
| 29 | * Based on: rtc-pcf8563.c (An I2C driver for the Philips PCF8563 RTC) | ||
| 30 | * Copyright 2005-06 Tower Technologies | ||
| 31 | * | ||
| 32 | */ | ||
| 33 | |||
| 34 | #include <linux/module.h> | ||
| 35 | #include <linux/kernel.h> | ||
| 36 | #include <linux/platform_device.h> | ||
| 37 | #include <linux/init.h> | ||
| 38 | #include <linux/rtc.h> | ||
| 39 | #include <linux/spi/spi.h> | ||
| 40 | #include <linux/bcd.h> | ||
| 41 | |||
| 42 | #define RX4581_REG_SC 0x00 /* Second in BCD */ | ||
| 43 | #define RX4581_REG_MN 0x01 /* Minute in BCD */ | ||
| 44 | #define RX4581_REG_HR 0x02 /* Hour in BCD */ | ||
| 45 | #define RX4581_REG_DW 0x03 /* Day of Week */ | ||
| 46 | #define RX4581_REG_DM 0x04 /* Day of Month in BCD */ | ||
| 47 | #define RX4581_REG_MO 0x05 /* Month in BCD */ | ||
| 48 | #define RX4581_REG_YR 0x06 /* Year in BCD */ | ||
| 49 | #define RX4581_REG_RAM 0x07 /* RAM */ | ||
| 50 | #define RX4581_REG_AMN 0x08 /* Alarm Min in BCD*/ | ||
| 51 | #define RX4581_REG_AHR 0x09 /* Alarm Hour in BCD */ | ||
| 52 | #define RX4581_REG_ADM 0x0A | ||
| 53 | #define RX4581_REG_ADW 0x0A | ||
| 54 | #define RX4581_REG_TMR0 0x0B | ||
| 55 | #define RX4581_REG_TMR1 0x0C | ||
| 56 | #define RX4581_REG_EXT 0x0D /* Extension Register */ | ||
| 57 | #define RX4581_REG_FLAG 0x0E /* Flag Register */ | ||
| 58 | #define RX4581_REG_CTRL 0x0F /* Control Register */ | ||
| 59 | |||
| 60 | |||
| 61 | /* Flag Register bit definitions */ | ||
| 62 | #define RX4581_FLAG_UF 0x20 /* Update */ | ||
| 63 | #define RX4581_FLAG_TF 0x10 /* Timer */ | ||
| 64 | #define RX4581_FLAG_AF 0x08 /* Alarm */ | ||
| 65 | #define RX4581_FLAG_VLF 0x02 /* Voltage Low */ | ||
| 66 | |||
| 67 | /* Control Register bit definitions */ | ||
| 68 | #define RX4581_CTRL_UIE 0x20 /* Update Interrupt Enable */ | ||
| 69 | #define RX4581_CTRL_TIE 0x10 /* Timer Interrupt Enable */ | ||
| 70 | #define RX4581_CTRL_AIE 0x08 /* Alarm Interrupt Enable */ | ||
| 71 | #define RX4581_CTRL_STOP 0x02 /* STOP bit */ | ||
| 72 | #define RX4581_CTRL_RESET 0x01 /* RESET bit */ | ||
| 73 | |||
| 74 | static int rx4581_set_reg(struct device *dev, unsigned char address, | ||
| 75 | unsigned char data) | ||
| 76 | { | ||
| 77 | struct spi_device *spi = to_spi_device(dev); | ||
| 78 | unsigned char buf[2]; | ||
| 79 | |||
| 80 | /* high nibble must be '0' to write */ | ||
| 81 | buf[0] = address & 0x0f; | ||
| 82 | buf[1] = data; | ||
| 83 | |||
| 84 | return spi_write_then_read(spi, buf, 2, NULL, 0); | ||
| 85 | } | ||
| 86 | |||
| 87 | static int rx4581_get_reg(struct device *dev, unsigned char address, | ||
| 88 | unsigned char *data) | ||
| 89 | { | ||
| 90 | struct spi_device *spi = to_spi_device(dev); | ||
| 91 | |||
| 92 | /* Set MSB to indicate read */ | ||
| 93 | *data = address | 0x80; | ||
| 94 | |||
| 95 | return spi_write_then_read(spi, data, 1, data, 1); | ||
| 96 | } | ||
| 97 | |||
| 98 | /* | ||
| 99 | * In the routines that deal directly with the rx8581 hardware, we use | ||
| 100 | * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. | ||
| 101 | */ | ||
| 102 | static int rx4581_get_datetime(struct device *dev, struct rtc_time *tm) | ||
| 103 | { | ||
| 104 | struct spi_device *spi = to_spi_device(dev); | ||
| 105 | unsigned char date[7]; | ||
| 106 | unsigned char data; | ||
| 107 | int err; | ||
| 108 | |||
| 109 | /* First we ensure that the "update flag" is not set, we read the | ||
| 110 | * time and date then re-read the "update flag". If the update flag | ||
| 111 | * has been set, we know that the time has changed during the read so | ||
| 112 | * we repeat the whole process again. | ||
| 113 | */ | ||
| 114 | err = rx4581_get_reg(dev, RX4581_REG_FLAG, &data); | ||
| 115 | if (err != 0) { | ||
| 116 | dev_err(dev, "Unable to read device flags\n"); | ||
| 117 | return -EIO; | ||
| 118 | } | ||
| 119 | |||
| 120 | do { | ||
| 121 | /* If update flag set, clear it */ | ||
| 122 | if (data & RX4581_FLAG_UF) { | ||
| 123 | err = rx4581_set_reg(dev, | ||
| 124 | RX4581_REG_FLAG, (data & ~RX4581_FLAG_UF)); | ||
| 125 | if (err != 0) { | ||
| 126 | dev_err(dev, "Unable to write device " | ||
| 127 | "flags\n"); | ||
| 128 | return -EIO; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | /* Now read time and date */ | ||
| 133 | date[0] = 0x80; | ||
| 134 | err = spi_write_then_read(spi, date, 1, date, 7); | ||
| 135 | if (err < 0) { | ||
| 136 | dev_err(dev, "Unable to read date\n"); | ||
| 137 | return -EIO; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* Check flag register */ | ||
| 141 | err = rx4581_get_reg(dev, RX4581_REG_FLAG, &data); | ||
| 142 | if (err != 0) { | ||
| 143 | dev_err(dev, "Unable to read device flags\n"); | ||
| 144 | return -EIO; | ||
| 145 | } | ||
| 146 | } while (data & RX4581_FLAG_UF); | ||
| 147 | |||
| 148 | if (data & RX4581_FLAG_VLF) | ||
| 149 | dev_info(dev, | ||
| 150 | "low voltage detected, date/time is not reliable.\n"); | ||
| 151 | |||
| 152 | dev_dbg(dev, | ||
| 153 | "%s: raw data is sec=%02x, min=%02x, hr=%02x, " | ||
| 154 | "wday=%02x, mday=%02x, mon=%02x, year=%02x\n", | ||
| 155 | __func__, | ||
| 156 | date[0], date[1], date[2], date[3], date[4], date[5], date[6]); | ||
| 157 | |||
| 158 | tm->tm_sec = bcd2bin(date[RX4581_REG_SC] & 0x7F); | ||
| 159 | tm->tm_min = bcd2bin(date[RX4581_REG_MN] & 0x7F); | ||
| 160 | tm->tm_hour = bcd2bin(date[RX4581_REG_HR] & 0x3F); /* rtc hr 0-23 */ | ||
