aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig3
-rw-r--r--drivers/rtc/rtc-ds1390.c72
2 files changed, 24 insertions, 51 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 74bd6160dfb1..fe1d7a2c27e4 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -317,7 +317,8 @@ config RTC_DRV_DS1305
317config RTC_DRV_DS1390 317config RTC_DRV_DS1390
318 tristate "Dallas/Maxim DS1390/93/94" 318 tristate "Dallas/Maxim DS1390/93/94"
319 help 319 help
320 If you say yes here you get support for the DS1390/93/94 chips. 320 If you say yes here you get support for the
321 Dallas/Maxim DS1390/93/94 chips.
321 322
322 This driver only supports the RTC feature, and not other chip 323 This driver only supports the RTC feature, and not other chip
323 features such as alarms and trickle charging. 324 features such as alarms and trickle charging.
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index 599e976bf014..e54b5c619bdf 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * rtc-ds1390.c -- driver for DS1390/93/94 2 * rtc-ds1390.c -- driver for the Dallas/Maxim DS1390/93/94 SPI RTC
3 * 3 *
4 * Copyright (C) 2008 Mercury IMC Ltd 4 * Copyright (C) 2008 Mercury IMC Ltd
5 * Written by Mark Jackson <mpfj@mimc.co.uk> 5 * Written by Mark Jackson <mpfj@mimc.co.uk>
@@ -8,11 +8,13 @@
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 * 10 *
11 * NOTE : Currently this driver only supports the bare minimum for read 11 * NOTE: Currently this driver only supports the bare minimum for read
12 * and write the RTC. The extra features provided by the chip family 12 * and write the RTC. The extra features provided by the chip family
13 * (alarms, trickle charger, different control registers) are unavailable. 13 * (alarms, trickle charger, different control registers) are unavailable.
14 */ 14 */
15 15
16#include <linux/init.h>
17#include <linux/module.h>
16#include <linux/platform_device.h> 18#include <linux/platform_device.h>
17#include <linux/rtc.h> 19#include <linux/rtc.h>
18#include <linux/spi/spi.h> 20#include <linux/spi/spi.h>
@@ -42,20 +44,6 @@ struct ds1390 {
42 u8 txrx_buf[9]; /* cmd + 8 registers */ 44 u8 txrx_buf[9]; /* cmd + 8 registers */
43}; 45};
44 46
45static void ds1390_set_reg(struct device *dev, unsigned char address,
46 unsigned char data)
47{
48 struct spi_device *spi = to_spi_device(dev);
49 struct ds1390 *chip = dev_get_drvdata(dev);
50
51 /* Set MSB to indicate write */
52 chip->txrx_buf[0] = address | 0x80;
53 chip->txrx_buf[1] = data;
54
55 /* do the i/o */
56 spi_write_then_read(spi, chip->txrx_buf, 2, NULL, 0);
57}
58
59static int ds1390_get_reg(struct device *dev, unsigned char address, 47static int ds1390_get_reg(struct device *dev, unsigned char address,
60 unsigned char *data) 48 unsigned char *data)
61{ 49{
@@ -78,7 +66,7 @@ static int ds1390_get_reg(struct device *dev, unsigned char address,
78 return 0; 66 return 0;
79} 67}
80 68
81static int ds1390_get_datetime(struct device *dev, struct rtc_time *dt) 69static int ds1390_read_time(struct device *dev, struct rtc_time *dt)
82{ 70{
83 struct spi_device *spi = to_spi_device(dev); 71 struct spi_device *spi = to_spi_device(dev);
84 struct ds1390 *chip = dev_get_drvdata(dev); 72 struct ds1390 *chip = dev_get_drvdata(dev);
@@ -107,7 +95,7 @@ static int ds1390_get_datetime(struct device *dev, struct rtc_time *dt)
107 return rtc_valid_tm(dt); 95 return rtc_valid_tm(dt);
108} 96}
109 97
110static int ds1390_set_datetime(struct device *dev, struct rtc_time *dt) 98static int ds1390_set_time(struct device *dev, struct rtc_time *dt)
111{ 99{
112 struct spi_device *spi = to_spi_device(dev); 100 struct spi_device *spi = to_spi_device(dev);
113 struct ds1390 *chip = dev_get_drvdata(dev); 101 struct ds1390 *chip = dev_get_drvdata(dev);
@@ -127,16 +115,6 @@ static int ds1390_set_datetime(struct device *dev, struct rtc_time *dt)
127 return spi_write_then_read(spi, chip->txrx_buf, 8, NULL, 0); 115 return spi_write_then_read(spi, chip->txrx_buf, 8, NULL, 0);
128} 116}
129 117
130static int ds1390_read_time(struct device *dev, struct rtc_time *tm)
131{
132 return ds1390_get_datetime(dev, tm);
133}
134
135static int ds1390_set_time(struct device *dev, struct rtc_time *tm)
136{
137 return ds1390_set_datetime(dev, tm);
138}
139
140static const struct rtc_class_ops ds1390_rtc_ops = { 118static const struct rtc_class_ops ds1390_rtc_ops = {
141 .read_time = ds1390_read_time, 119 .read_time = ds1390_read_time,
142 .set_time = ds1390_set_time, 120 .set_time = ds1390_set_time,
@@ -149,46 +127,40 @@ static int __devinit ds1390_probe(struct spi_device *spi)
149 struct ds1390 *chip; 127 struct ds1390 *chip;
150 int res; 128 int res;
151 129
152 printk(KERN_DEBUG "DS1390 SPI RTC driver\n");
153
154 rtc = rtc_device_register("ds1390",
155 &spi->dev, &ds1390_rtc_ops, THIS_MODULE);
156 if (IS_ERR(rtc)) {
157 printk(KERN_ALERT "RTC : unable to register device\n");
158 return PTR_ERR(rtc);
159 }
160
161 spi->mode = SPI_MODE_3; 130 spi->mode = SPI_MODE_3;
162 spi->bits_per_word = 8; 131 spi->bits_per_word = 8;
163 spi_setup(spi); 132 spi_setup(spi);
164 133
165 chip = kzalloc(sizeof *chip, GFP_KERNEL); 134 chip = kzalloc(sizeof *chip, GFP_KERNEL);
166 if (!chip) { 135 if (!chip) {
167 printk(KERN_ALERT "RTC : unable to allocate device memory\n"); 136 dev_err(&spi->dev, "unable to allocate device memory\n");
168 rtc_device_unregister(rtc);
169 return -ENOMEM; 137 return -ENOMEM;
170 } 138 }
171 chip->rtc = rtc;
172 dev_set_drvdata(&spi->dev, chip); 139 dev_set_drvdata(&spi->dev, chip);
173 140
174 res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp); 141 res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp);
175 if (res) { 142 if (res != 0) {
176 printk(KERN_ALERT "RTC : unable to read device\n"); 143 dev_err(&spi->dev, "unable to read device\n");
177 rtc_device_unregister(rtc); 144 kfree(chip);
178 return res; 145 return res;
179 } 146 }
180 147
181 return 0; 148 chip->rtc = rtc_device_register("ds1390",
149 &spi->dev, &ds1390_rtc_ops, THIS_MODULE);
150 if (IS_ERR(chip->rtc)) {
151 dev_err(&spi->dev, "unable to register device\n");
152 res = PTR_ERR(chip->rtc);
153 kfree(chip);
154 }
155
156 return res;
182} 157}
183 158
184static int __devexit ds1390_remove(struct spi_device *spi) 159static int __devexit ds1390_remove(struct spi_device *spi)
185{ 160{
186 struct ds1390 *chip = platform_get_drvdata(spi); 161 struct ds1390 *chip = platform_get_drvdata(spi);
187 struct rtc_device *rtc = chip->rtc;
188
189 if (rtc)
190 rtc_device_unregister(rtc);
191 162
163 rtc_device_unregister(chip->rtc);
192 kfree(chip); 164 kfree(chip);
193 165
194 return 0; 166 return 0;
@@ -215,6 +187,6 @@ static __exit void ds1390_exit(void)
215} 187}
216module_exit(ds1390_exit); 188module_exit(ds1390_exit);
217 189
218MODULE_DESCRIPTION("DS1390/93/94 SPI RTC driver"); 190MODULE_DESCRIPTION("Dallas/Maxim DS1390/93/94 SPI RTC driver");
219MODULE_AUTHOR("Mark Jackson <mpfj@mimc.co.uk>"); 191MODULE_AUTHOR("Mark Jackson <mpfj@mimc.co.uk>");
220MODULE_LICENSE("GPL"); 192MODULE_LICENSE("GPL");