diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 12 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1672.c | 9 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1742.c | 67 | ||||
-rw-r--r-- | drivers/rtc/rtc-omap.c | 572 | ||||
-rw-r--r-- | drivers/rtc/rtc-rs5c372.c | 90 | ||||
-rw-r--r-- | drivers/rtc/rtc-test.c | 9 | ||||
-rw-r--r-- | drivers/rtc/rtc-x1205.c | 12 |
8 files changed, 698 insertions, 74 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index fc766a7a611e..2a63ab2b47f4 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -154,15 +154,23 @@ config RTC_DRV_DS1672 | |||
154 | will be called rtc-ds1672. | 154 | will be called rtc-ds1672. |
155 | 155 | ||
156 | config RTC_DRV_DS1742 | 156 | config RTC_DRV_DS1742 |
157 | tristate "Dallas DS1742" | 157 | tristate "Dallas DS1742/1743" |
158 | depends on RTC_CLASS | 158 | depends on RTC_CLASS |
159 | help | 159 | help |
160 | If you say yes here you get support for the | 160 | If you say yes here you get support for the |
161 | Dallas DS1742 timekeeping chip. | 161 | Dallas DS1742/1743 timekeeping chip. |
162 | 162 | ||
163 | This driver can also be built as a module. If so, the module | 163 | This driver can also be built as a module. If so, the module |
164 | will be called rtc-ds1742. | 164 | will be called rtc-ds1742. |
165 | 165 | ||
166 | config RTC_DRV_OMAP | ||
167 | tristate "TI OMAP1" | ||
168 | depends on RTC_CLASS && ( \ | ||
169 | ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 ) | ||
170 | help | ||
171 | Say "yes" here to support the real time clock on TI OMAP1 chips. | ||
172 | This driver can also be built as a module called rtc-omap. | ||
173 | |||
166 | config RTC_DRV_PCF8563 | 174 | config RTC_DRV_PCF8563 |
167 | tristate "Philips PCF8563/Epson RTC8564" | 175 | tristate "Philips PCF8563/Epson RTC8564" |
168 | depends on RTC_CLASS && I2C | 176 | depends on RTC_CLASS && I2C |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 3ba5ff6e6800..bd4c45d333f0 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -21,6 +21,7 @@ obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o | |||
21 | obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o | 21 | obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o |
22 | obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o | 22 | obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o |
23 | obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o | 23 | obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o |
24 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o | ||
24 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o | 25 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o |
25 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o | 26 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o |
26 | obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o | 27 | obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o |
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c index 67e816a9a39f..dfef1637bfb8 100644 --- a/drivers/rtc/rtc-ds1672.c +++ b/drivers/rtc/rtc-ds1672.c | |||
@@ -237,17 +237,22 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind) | |||
237 | /* read control register */ | 237 | /* read control register */ |
238 | err = ds1672_get_control(client, &control); | 238 | err = ds1672_get_control(client, &control); |
239 | if (err) | 239 | if (err) |
240 | goto exit_detach; | 240 | goto exit_devreg; |
241 | 241 | ||
242 | if (control & DS1672_REG_CONTROL_EOSC) | 242 | if (control & DS1672_REG_CONTROL_EOSC) |
243 | dev_warn(&client->dev, "Oscillator not enabled. " | 243 | dev_warn(&client->dev, "Oscillator not enabled. " |
244 | "Set time to enable.\n"); | 244 | "Set time to enable.\n"); |
245 | 245 | ||
246 | /* Register sysfs hooks */ | 246 | /* Register sysfs hooks */ |
247 | device_create_file(&client->dev, &dev_attr_control); | 247 | err = device_create_file(&client->dev, &dev_attr_control); |
248 | if (err) | ||
249 | goto exit_devreg; | ||
248 | 250 | ||
249 | return 0; | 251 | return 0; |
250 | 252 | ||
253 | exit_devreg: | ||
254 | rtc_device_unregister(rtc); | ||
255 | |||
251 | exit_detach: | 256 | exit_detach: |
252 | i2c_detach_client(client); | 257 | i2c_detach_client(client); |
253 | 258 | ||
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c index 6273a3d240a2..17633bfa8480 100644 --- a/drivers/rtc/rtc-ds1742.c +++ b/drivers/rtc/rtc-ds1742.c | |||
@@ -6,6 +6,10 @@ | |||
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License version 2 as | 7 | * it under the terms of the GNU General Public License version 2 as |
8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
9 | * | ||
10 | * Copyright (C) 2006 Torsten Ertbjerg Rasmussen <tr@newtec.dk> | ||
11 | * - nvram size determined from resource | ||
12 | * - this ds1742 driver now supports ds1743. | ||
9 | */ | 13 | */ |
10 | 14 | ||
11 | #include <linux/bcd.h> | 15 | #include <linux/bcd.h> |
@@ -17,20 +21,19 @@ | |||
17 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
18 | #include <linux/io.h> | 22 | #include <linux/io.h> |
19 | 23 | ||
20 | #define DRV_VERSION "0.2" | 24 | #define DRV_VERSION "0.3" |
21 | 25 | ||
22 | #define RTC_REG_SIZE 0x800 | 26 | #define RTC_SIZE 8 |
23 | #define RTC_OFFSET 0x7f8 | ||
24 | 27 | ||
25 | #define RTC_CONTROL (RTC_OFFSET + 0) | 28 | #define RTC_CONTROL 0 |
26 | #define RTC_CENTURY (RTC_OFFSET + 0) | 29 | #define RTC_CENTURY 0 |
27 | #define RTC_SECONDS (RTC_OFFSET + 1) | 30 | #define RTC_SECONDS 1 |
28 | #define RTC_MINUTES (RTC_OFFSET + 2) | 31 | #define RTC_MINUTES 2 |
29 | #define RTC_HOURS (RTC_OFFSET + 3) | 32 | #define RTC_HOURS 3 |
30 | #define RTC_DAY (RTC_OFFSET + 4) | 33 | #define RTC_DAY 4 |
31 | #define RTC_DATE (RTC_OFFSET + 5) | 34 | #define RTC_DATE 5 |
32 | #define RTC_MONTH (RTC_OFFSET + 6) | 35 | #define RTC_MONTH 6 |
33 | #define RTC_YEAR (RTC_OFFSET + 7) | 36 | #define RTC_YEAR 7 |
34 | 37 | ||
35 | #define RTC_CENTURY_MASK 0x3f | 38 | #define RTC_CENTURY_MASK 0x3f |
36 | #define RTC_SECONDS_MASK 0x7f | 39 | #define RTC_SECONDS_MASK 0x7f |
@@ -48,7 +51,10 @@ | |||
48 | 51 | ||
49 | struct rtc_plat_data { | 52 | struct rtc_plat_data { |
50 | struct rtc_device *rtc; | 53 | struct rtc_device *rtc; |
51 | void __iomem *ioaddr; | 54 | void __iomem *ioaddr_nvram; |
55 | void __iomem *ioaddr_rtc; | ||
56 | size_t size_nvram; | ||
57 | size_t size; | ||
52 | unsigned long baseaddr; | 58 | unsigned long baseaddr; |
53 | unsigned long last_jiffies; | 59 | unsigned long last_jiffies; |
54 | }; | 60 | }; |
@@ -57,7 +63,7 @@ static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
57 | { | 63 | { |
58 | struct platform_device *pdev = to_platform_device(dev); | 64 | struct platform_device *pdev = to_platform_device(dev); |
59 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 65 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
60 | void __iomem *ioaddr = pdata->ioaddr; | 66 | void __iomem *ioaddr = pdata->ioaddr_rtc; |
61 | u8 century; | 67 | u8 century; |
62 | 68 | ||
63 | century = BIN2BCD((tm->tm_year + 1900) / 100); | 69 | century = BIN2BCD((tm->tm_year + 1900) / 100); |
@@ -82,7 +88,7 @@ static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
82 | { | 88 | { |
83 | struct platform_device *pdev = to_platform_device(dev); | 89 | struct platform_device *pdev = to_platform_device(dev); |
84 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 90 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
85 | void __iomem *ioaddr = pdata->ioaddr; | 91 | void __iomem *ioaddr = pdata->ioaddr_rtc; |
86 | unsigned int year, month, day, hour, minute, second, week; | 92 | unsigned int year, month, day, hour, minute, second, week; |
87 | unsigned int century; | 93 | unsigned int century; |
88 | 94 | ||
@@ -127,10 +133,10 @@ static ssize_t ds1742_nvram_read(struct kobject *kobj, char *buf, | |||
127 | struct platform_device *pdev = | 133 | struct platform_device *pdev = |
128 | to_platform_device(container_of(kobj, struct device, kobj)); | 134 | to_platform_device(container_of(kobj, struct device, kobj)); |
129 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 135 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
130 | void __iomem *ioaddr = pdata->ioaddr; | 136 | void __iomem *ioaddr = pdata->ioaddr_nvram; |
131 | ssize_t count; | 137 | ssize_t count; |
132 | 138 | ||
133 | for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) | 139 | for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--) |
134 | *buf++ = readb(ioaddr + pos++); | 140 | *buf++ = readb(ioaddr + pos++); |
135 | return count; | 141 | return count; |
136 | } | 142 | } |
@@ -141,10 +147,10 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj, char *buf, | |||
141 | struct platform_device *pdev = | 147 | struct platform_device *pdev = |
142 | to_platform_device(container_of(kobj, struct device, kobj)); | 148 | to_platform_device(container_of(kobj, struct device, kobj)); |
143 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | 149 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
144 | void __iomem *ioaddr = pdata->ioaddr; | 150 | void __iomem *ioaddr = pdata->ioaddr_nvram; |
145 | ssize_t count; | 151 | ssize_t count; |
146 | 152 | ||
147 | for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) | 153 | for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--) |
148 | writeb(*buf++, ioaddr + pos++); | 154 | writeb(*buf++, ioaddr + pos++); |
149 | return count; | 155 | return count; |
150 | } | 156 | } |
@@ -155,7 +161,6 @@ static struct bin_attribute ds1742_nvram_attr = { | |||
155 | .mode = S_IRUGO | S_IWUGO, | 161 | .mode = S_IRUGO | S_IWUGO, |
156 | .owner = THIS_MODULE, | 162 | .owner = THIS_MODULE, |
157 | }, | 163 | }, |
158 | .size = RTC_OFFSET, | ||
159 | .read = ds1742_nvram_read, | 164 | .read = ds1742_nvram_read, |
160 | .write = ds1742_nvram_write, | 165 | .write = ds1742_nvram_write, |
161 | }; | 166 | }; |
@@ -175,19 +180,23 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev) | |||
175 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); | 180 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
176 | if (!pdata) | 181 | if (!pdata) |
177 | return -ENOMEM; | 182 | return -ENOMEM; |
178 | if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) { | 183 | pdata->size = res->end - res->start + 1; |
184 | if (!request_mem_region(res->start, pdata->size, pdev->name)) { | ||
179 | ret = -EBUSY; | 185 | ret = -EBUSY; |
180 | goto out; | 186 | goto out; |
181 | } | 187 | } |
182 | pdata->baseaddr = res->start; | 188 | pdata->baseaddr = res->start; |
183 | ioaddr = ioremap(pdata->baseaddr, RTC_REG_SIZE); | 189 | ioaddr = ioremap(pdata->baseaddr, pdata->size); |
184 | if (!ioaddr) { | 190 | if (!ioaddr) { |
185 | ret = -ENOMEM; | 191 | ret = -ENOMEM; |
186 | goto out; | 192 | goto out; |
187 | } | 193 | } |
188 | pdata->ioaddr = ioaddr; | 194 | pdata->ioaddr_nvram = ioaddr; |
195 | pdata->size_nvram = pdata->size - RTC_SIZE; | ||
196 | pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; | ||
189 | 197 | ||
190 | /* turn RTC on if it was not on */ | 198 | /* turn RTC on if it was not on */ |
199 | ioaddr = pdata->ioaddr_rtc; | ||
191 | sec = readb(ioaddr + RTC_SECONDS); | 200 | sec = readb(ioaddr + RTC_SECONDS); |
192 | if (sec & RTC_STOP) { | 201 | if (sec & RTC_STOP) { |
193 | sec &= RTC_SECONDS_MASK; | 202 | sec &= RTC_SECONDS_MASK; |
@@ -208,6 +217,8 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev) | |||
208 | pdata->rtc = rtc; | 217 | pdata->rtc = rtc; |
209 | pdata->last_jiffies = jiffies; | 218 | pdata->last_jiffies = jiffies; |
210 | platform_set_drvdata(pdev, pdata); | 219 | platform_set_drvdata(pdev, pdata); |
220 | ds1742_nvram_attr.size = max(ds1742_nvram_attr.size, | ||
221 | pdata->size_nvram); | ||
211 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); | 222 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); |
212 | if (ret) | 223 | if (ret) |
213 | goto out; | 224 | goto out; |
@@ -215,10 +226,10 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev) | |||
215 | out: | 226 | out: |
216 | if (pdata->rtc) | 227 | if (pdata->rtc) |
217 | rtc_device_unregister(pdata->rtc); | 228 | rtc_device_unregister(pdata->rtc); |
218 | if (ioaddr) | 229 | if (pdata->ioaddr_nvram) |
219 | iounmap(ioaddr); | 230 | iounmap(pdata->ioaddr_nvram); |
220 | if (pdata->baseaddr) | 231 | if (pdata->baseaddr) |
221 | release_mem_region(pdata->baseaddr, RTC_REG_SIZE); | 232 | release_mem_region(pdata->baseaddr, pdata->size); |
222 | kfree(pdata); | 233 | kfree(pdata); |
223 | return ret; | 234 | return ret; |
224 | } | 235 | } |
@@ -229,8 +240,8 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev) | |||
229 | 240 | ||
230 | sysfs_remove_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); | 241 | sysfs_remove_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); |
231 | rtc_device_unregister(pdata->rtc); | 242 | rtc_device_unregister(pdata->rtc); |
232 | iounmap(pdata->ioaddr); | 243 | iounmap(pdata->ioaddr_nvram); |
233 | release_mem_region(pdata->baseaddr, RTC_REG_SIZE); | 244 | release_mem_region(pdata->baseaddr, pdata->size); |
234 | kfree(pdata); | 245 | kfree(pdata); |
235 | return 0; | 246 | return 0; |
236 | } | 247 | } |
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c new file mode 100644 index 000000000000..eac5fb1fc02f --- /dev/null +++ b/drivers/rtc/rtc-omap.c | |||
@@ -0,0 +1,572 @@ | |||
1 | /* | ||
2 | * TI OMAP1 Real Time Clock interface for Linux | ||
3 | * | ||
4 | * Copyright (C) 2003 MontaVista Software, Inc. | ||
5 | * Author: George G. Davis <gdavis@mvista.com> or <source@mvista.com> | ||
6 | * | ||
7 | * Copyright (C) 2006 David Brownell (new RTC framework) | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version | ||
12 | * 2 of the License, or (at your option) any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/ioport.h> | ||
19 | #include <linux/delay.h> | ||
20 | #include <linux/rtc.h> | ||
21 | #include <linux/bcd.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | |||
24 | #include <asm/io.h> | ||
25 | #include <asm/mach/time.h> | ||
26 | |||
27 | |||
28 | /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock | ||
29 | * with century-range alarm matching, driven by the 32kHz clock. | ||
30 | * | ||
31 | * The main user-visible ways it differs from PC RTCs are by omitting | ||
32 | * "don't care" alarm fields and sub-second periodic IRQs, and having | ||
33 | * an autoadjust mechanism to calibrate to the true oscillator rate. | ||
34 | * | ||
35 | * Board-specific wiring options include using split power mode with | ||
36 | * RTC_OFF_NOFF used as the reset signal (so the RTC won't be reset), | ||
37 | * and wiring RTC_WAKE_INT (so the RTC alarm can wake the system from | ||
38 | * low power modes). See the BOARD-SPECIFIC CUSTOMIZATION comment. | ||
39 | */ | ||
40 | |||
41 | #define OMAP_RTC_BASE 0xfffb4800 | ||
42 | |||
43 | /* RTC registers */ | ||
44 | #define OMAP_RTC_SECONDS_REG 0x00 | ||
45 | #define OMAP_RTC_MINUTES_REG 0x04 | ||
46 | #define OMAP_RTC_HOURS_REG 0x08 | ||
47 | #define OMAP_RTC_DAYS_REG 0x0C | ||
48 | #define OMAP_RTC_MONTHS_REG 0x10 | ||
49 | #define OMAP_RTC_YEARS_REG 0x14 | ||
50 | #define OMAP_RTC_WEEKS_REG 0x18 | ||
51 | |||
52 | #define OMAP_RTC_ALARM_SECONDS_REG 0x20 | ||
53 | #define OMAP_RTC_ALARM_MINUTES_REG 0x24 | ||
54 | #define OMAP_RTC_ALARM_HOURS_REG 0x28 | ||
55 | #define OMAP_RTC_ALARM_DAYS_REG 0x2c | ||
56 | #define OMAP_RTC_ALARM_MONTHS_REG 0x30 | ||
57 | #define OMAP_RTC_ALARM_YEARS_REG 0x34 | ||
58 | |||
59 | #define OMAP_RTC_CTRL_REG 0x40 | ||
60 | #define OMAP_RTC_STATUS_REG 0x44 | ||
61 | #define OMAP_RTC_INTERRUPTS_REG 0x48 | ||
62 | |||
63 | #define OMAP_RTC_COMP_LSB_REG 0x4c | ||
64 | #define OMAP_RTC_COMP_MSB_REG 0x50 | ||
65 | #define OMAP_RTC_OSC_REG 0x54 | ||
66 | |||
67 | /* OMAP_RTC_CTRL_REG bit fields: */ | ||
68 | #define OMAP_RTC_CTRL_SPLIT (1<<7) | ||
69 | #define OMAP_RTC_CTRL_DISABLE (1<<6) | ||
70 | #define OMAP_RTC_CTRL_SET_32_COUNTER (1<<5) | ||
71 | #define OMAP_RTC_CTRL_TEST (1<<4) | ||
72 | #define OMAP_RTC_CTRL_MODE_12_24 (1<<3) | ||
73 | #define OMAP_RTC_CTRL_AUTO_COMP (1<<2) | ||
74 | #define OMAP_RTC_CTRL_ROUND_30S (1<<1) | ||
75 | #define OMAP_RTC_CTRL_STOP (1<<0) | ||
76 | |||
77 | /* OMAP_RTC_STATUS_REG bit fields: */ | ||
78 | #define OMAP_RTC_STATUS_POWER_UP (1<<7) | ||
79 | #define OMAP_RTC_STATUS_ALARM (1<<6) | ||
80 | #define OMAP_RTC_STATUS_1D_EVENT (1<<5) | ||
81 | #define OMAP_RTC_STATUS_1H_EVENT (1<<4) | ||
82 | #define OMAP_RTC_STATUS_1M_EVENT (1<<3) | ||
83 | #define OMAP_RTC_STATUS_1S_EVENT (1<<2) | ||
84 | #define OMAP_RTC_STATUS_RUN (1<<1) | ||
85 | #define OMAP_RTC_STATUS_BUSY (1<<0) | ||
86 | |||
87 | /* OMAP_RTC_INTERRUPTS_REG bit fields: */ | ||
88 | #define OMAP_RTC_INTERRUPTS_IT_ALARM (1<<3) | ||
89 | #define OMAP_RTC_INTERRUPTS_IT_TIMER (1<<2) | ||
90 | |||
91 | |||
92 | #define rtc_read(addr) omap_readb(OMAP_RTC_BASE + (addr)) | ||
93 | #define rtc_write(val, addr) omap_writeb(val, OMAP_RTC_BASE + (addr)) | ||
94 | |||
95 | |||
96 | /* platform_bus isn't hotpluggable, so for static linkage it'd be safe | ||
97 | * to get rid of probe() and remove() code ... too bad the driver struct | ||
98 | * remembers probe(), that's about 25% of the runtime footprint!! | ||
99 | */ | ||
100 | #ifndef MODULE | ||
101 | #undef __devexit | ||
102 | #undef __devexit_p | ||
103 | #define __devexit __exit | ||
104 | #define __devexit_p __exit_p | ||
105 | #endif | ||
106 | |||
107 | |||
108 | /* we rely on the rtc framework to handle locking (rtc->ops_lock), | ||
109 | * so the only other requirement is that register accesses which | ||
110 | * require BUSY to be clear are made with IRQs locally disabled | ||
111 | */ | ||
112 | static void rtc_wait_not_busy(void) | ||
113 | { | ||
114 | int count = 0; | ||
115 | u8 status; | ||
116 | |||
117 | /* BUSY may stay active for 1/32768 second (~30 usec) */ | ||
118 | for (count = 0; count < 50; count++) { | ||
119 | status = rtc_read(OMAP_RTC_STATUS_REG); | ||
120 | if ((status & (u8)OMAP_RTC_STATUS_BUSY) == 0) | ||
121 | break; | ||
122 | udelay(1); | ||
123 | } | ||
124 | /* now we have ~15 usec to read/write various registers */ | ||
125 | } | ||
126 | |||
127 | static irqreturn_t rtc_irq(int irq, void *class_dev) | ||
128 | { | ||
129 | unsigned long events = 0; | ||
130 | u8 irq_data; | ||
131 | |||
132 | irq_data = rtc_read(OMAP_RTC_STATUS_REG); | ||
133 | |||
134 | /* alarm irq? */ | ||
135 | if (irq_data & OMAP_RTC_STATUS_ALARM) { | ||
136 | rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG); | ||
137 | events |= RTC_IRQF | RTC_AF; | ||
138 | } | ||
139 | |||
140 | /* 1/sec periodic/update irq? */ | ||
141 | if (irq_data & OMAP_RTC_STATUS_1S_EVENT) | ||
142 | events |= RTC_IRQF | RTC_UF; | ||
143 | |||
144 | rtc_update_irq(class_dev, 1, events); | ||
145 | |||
146 | return IRQ_HANDLED; | ||
147 | } | ||
148 | |||
149 | #ifdef CONFIG_RTC_INTF_DEV | ||
150 | |||
151 | static int | ||
152 | omap_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | ||
153 | { | ||
154 | u8 reg; | ||
155 | |||
156 | switch (cmd) { | ||
157 | case RTC_AIE_OFF: | ||
158 | case RTC_AIE_ON: | ||
159 | case RTC_UIE_OFF: | ||
160 | case RTC_UIE_ON: | ||
161 | break; | ||
162 | default: | ||
163 | return -ENOIOCTLCMD; | ||
164 | } | ||
165 | |||
166 | local_irq_disable(); | ||
167 | rtc_wait_not_busy(); | ||
168 | reg = rtc_read(OMAP_RTC_INTERRUPTS_REG); | ||
169 | switch (cmd) { | ||
170 | /* AIE = Alarm Interrupt Enable */ | ||
171 | case RTC_AIE_OFF: | ||
172 | reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM; | ||
173 | break; | ||
174 | case RTC_AIE_ON: | ||
175 | reg |= OMAP_RTC_INTERRUPTS_IT_ALARM; | ||
176 | break; | ||
177 | /* UIE = Update Interrupt Enable (1/second) */ | ||
178 | case RTC_UIE_OFF: | ||
179 | reg &= ~OMAP_RTC_INTERRUPTS_IT_TIMER; | ||
180 | break; | ||
181 | case RTC_UIE_ON: | ||
182 | reg |= OMAP_RTC_INTERRUPTS_IT_TIMER; | ||
183 | break; | ||
184 | } | ||
185 | rtc_wait_not_busy(); | ||
186 | rtc_write(reg, OMAP_RTC_INTERRUPTS_REG); | ||
187 | local_irq_enable(); | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | #else | ||
193 | #define omap_rtc_ioctl NULL | ||
194 | #endif | ||
195 | |||
196 | /* this hardware doesn't support "don't care" alarm fields */ | ||
197 | static int tm2bcd(struct rtc_time *tm) | ||
198 | { | ||
199 | if (rtc_valid_tm(tm) != 0) | ||
200 | return -EINVAL; | ||
201 | |||
202 | tm->tm_sec = BIN2BCD(tm->tm_sec); | ||
203 | tm->tm_min = BIN2BCD(tm->tm_min); | ||
204 | tm->tm_hour = BIN2BCD(tm->tm_hour); | ||
205 | tm->tm_mday = BIN2BCD(tm->tm_mday); | ||
206 | |||
207 | tm->tm_mon = BIN2BCD(tm->tm_mon + 1); | ||
208 | |||
209 | /* epoch == 1900 */ | ||
210 | if (tm->tm_year < 100 || tm->tm_year > 199) | ||
211 | return -EINVAL; | ||
212 | tm->tm_year = BIN2BCD(tm->tm_year - 100); | ||
213 | |||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | static void bcd2tm(struct rtc_time *tm) | ||
218 | { | ||
219 | tm->tm_sec = BCD2BIN(tm->tm_sec); | ||
220 | tm->tm_min = BCD2BIN(tm->tm_min); | ||
221 | tm->tm_hour = BCD2BIN(tm->tm_hour); | ||
222 | tm->tm_mday = BCD2BIN(tm->tm_mday); | ||
223 | tm->tm_mon = BCD2BIN(tm->tm_mon) - 1; | ||
224 | /* epoch == 1900 */ | ||
225 | tm->tm_year = BCD2BIN(tm->tm_year) + 100; | ||
226 | } | ||
227 | |||
228 | |||
229 | static int omap_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
230 | { | ||
231 | /* we don't report wday/yday/isdst ... */ | ||
232 | local_irq_disable(); | ||
233 | rtc_wait_not_busy(); | ||
234 | |||
235 | tm->tm_sec = rtc_read(OMAP_RTC_SECONDS_REG); | ||
236 | tm->tm_min = rtc_read(OMAP_RTC_MINUTES_REG); | ||
237 | tm->tm_hour = rtc_read(OMAP_RTC_HOURS_REG); | ||
238 | tm->tm_mday = rtc_read(OMAP_RTC_DAYS_REG); | ||
239 | tm->tm_mon = rtc_read(OMAP_RTC_MONTHS_REG); | ||
240 | tm->tm_year = rtc_read(OMAP_RTC_YEARS_REG); | ||
241 | |||
242 | local_irq_enable(); | ||
243 | |||
244 | bcd2tm(tm); | ||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
249 | { | ||
250 | if (tm2bcd(tm) < 0) | ||
251 | return -EINVAL; | ||
252 | local_irq_disable(); | ||
253 | rtc_wait_not_busy(); | ||
254 | |||
255 | rtc_write(tm->tm_year, OMAP_RTC_YEARS_REG); | ||
256 | rtc_write(tm->tm_mon, OMAP_RTC_MONTHS_REG); | ||
257 | rtc_write(tm->tm_mday, OMAP_RTC_DAYS_REG); | ||
258 | rtc_write(tm->tm_hour, OMAP_RTC_HOURS_REG); | ||
259 | rtc_write(tm->tm_min, OMAP_RTC_MINUTES_REG); | ||
260 | rtc_write(tm->tm_sec, OMAP_RTC_SECONDS_REG); | ||
261 | |||
262 | local_irq_enable(); | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static int omap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) | ||
268 | { | ||
269 | local_irq_disable(); | ||
270 | rtc_wait_not_busy(); | ||
271 | |||
272 | alm->time.tm_sec = rtc_read(OMAP_RTC_ALARM_SECONDS_REG); | ||
273 | alm->time.tm_min = rtc_read(OMAP_RTC_ALARM_MINUTES_REG); | ||
274 | alm->time.tm_hour = rtc_read(OMAP_RTC_ALARM_HOURS_REG); | ||
275 | alm->time.tm_mday = rtc_read(OMAP_RTC_ALARM_DAYS_REG); | ||
276 | alm->time.tm_mon = rtc_read(OMAP_RTC_ALARM_MONTHS_REG); | ||
277 | alm->time.tm_year = rtc_read(OMAP_RTC_ALARM_YEARS_REG); | ||
278 | |||
279 | local_irq_enable(); | ||
280 | |||
281 | bcd2tm(&alm->time); | ||
282 | alm->pending = !!(rtc_read(OMAP_RTC_INTERRUPTS_REG) | ||
283 | & OMAP_RTC_INTERRUPTS_IT_ALARM); | ||
284 | alm->enabled = alm->pending && device_may_wakeup(dev); | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) | ||
290 | { | ||
291 | u8 reg; | ||
292 | |||
293 | /* Much userspace code uses RTC_ALM_SET, thus "don't care" for | ||
294 | * day/month/year specifies alarms up to 24 hours in the future. | ||
295 | * So we need to handle that ... but let's ignore the "don't care" | ||
296 | * values for hours/minutes/seconds. | ||
297 | */ | ||
298 | if (alm->time.tm_mday <= 0 | ||
299 | && alm->time.tm_mon < 0 | ||
300 | && alm->time.tm_year < 0) { | ||
301 | struct rtc_time tm; | ||
302 | unsigned long now, then; | ||
303 | |||
304 | omap_rtc_read_time(dev, &tm); | ||
305 | rtc_tm_to_time(&tm, &now); | ||
306 | |||
307 | alm->time.tm_mday = tm.tm_mday; | ||
308 | alm->time.tm_mon = tm.tm_mon; | ||
309 | alm->time.tm_year = tm.tm_year; | ||
310 | rtc_tm_to_time(&alm->time, &then); | ||
311 | |||
312 | /* sometimes the alarm wraps into tomorrow */ | ||
313 | if (then < now) { | ||
314 | rtc_time_to_tm(now + 24 * 60 * 60, &tm); | ||
315 | alm->time.tm_mday = tm.tm_mday; | ||
316 | alm->time.tm_mon = tm.tm_mon; | ||
317 | alm->time.tm_year = tm.tm_year; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | if (tm2bcd(&alm->time) < 0) | ||
322 | return -EINVAL; | ||
323 | |||
324 | local_irq_disable(); | ||
325 | rtc_wait_not_busy(); | ||
326 | |||
327 | rtc_write(alm->time.tm_year, OMAP_RTC_ALARM_YEARS_REG); | ||
328 | rtc_write(alm->time.tm_mon, OMAP_RTC_ALARM_MONTHS_REG); | ||
329 | rtc_write(alm->time.tm_mday, OMAP_RTC_ALARM_DAYS_REG); | ||
330 | rtc_write(alm->time.tm_hour, OMAP_RTC_ALARM_HOURS_REG); | ||
331 | rtc_write(alm->time.tm_min, OMAP_RTC_ALARM_MINUTES_REG); | ||
332 | rtc_write(alm->time.tm_sec, OMAP_RTC_ALARM_SECONDS_REG); | ||
333 | |||
334 | reg = rtc_read(OMAP_RTC_INTERRUPTS_REG); | ||
335 | if (alm->enabled) | ||
336 | reg |= OMAP_RTC_INTERRUPTS_IT_ALARM; | ||
337 | else | ||
338 | reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM; | ||
339 | rtc_write(reg, OMAP_RTC_INTERRUPTS_REG); | ||
340 | |||
341 | local_irq_enable(); | ||
342 | |||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | static struct rtc_class_ops omap_rtc_ops = { | ||
347 | .ioctl = omap_rtc_ioctl, | ||
348 | .read_time = omap_rtc_read_time, | ||
349 | .set_time = omap_rtc_set_time, | ||
350 | .read_alarm = omap_rtc_read_alarm, | ||
351 | .set_alarm = omap_rtc_set_alarm, | ||
352 | }; | ||
353 | |||
354 | static int omap_rtc_alarm; | ||
355 | static int omap_rtc_timer; | ||
356 | |||
357 | static int __devinit omap_rtc_probe(struct platform_device *pdev) | ||
358 | { | ||
359 | struct resource *res, *mem; | ||
360 | struct rtc_device *rtc; | ||
361 | u8 reg, new_ctrl; | ||
362 | |||
363 | omap_rtc_timer = platform_get_irq(pdev, 0); | ||
364 | if (omap_rtc_timer <= 0) { | ||
365 | pr_debug("%s: no update irq?\n", pdev->name); | ||
366 | return -ENOENT; | ||
367 | } | ||
368 | |||
369 | omap_rtc_alarm = platform_get_irq(pdev, 1); | ||
370 | if (omap_rtc_alarm <= 0) { | ||
371 | pr_debug("%s: no alarm irq?\n", pdev->name); | ||
372 | return -ENOENT; | ||
373 | } | ||
374 | |||
375 | /* NOTE: using static mapping for RTC registers */ | ||
376 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
377 | if (res && res->start != OMAP_RTC_BASE) { | ||
378 | pr_debug("%s: RTC registers at %08x, expected %08x\n", | ||
379 | pdev->name, (unsigned) res->start, OMAP_RTC_BASE); | ||
380 | return -ENOENT; | ||
381 | } | ||
382 | |||
383 | if (res) | ||
384 | mem = request_mem_region(res->start, | ||
385 | res->end - res->start + 1, | ||
386 | pdev->name); | ||
387 | else | ||
388 | mem = NULL; | ||
389 | if (!mem) { | ||
390 | pr_debug("%s: RTC registers at %08x are not free\n", | ||
391 | pdev->name, OMAP_RTC_BASE); | ||
392 | return -EBUSY; | ||
393 | } | ||
394 | |||
395 | rtc = rtc_device_register(pdev->name, &pdev->dev, | ||
396 | &omap_rtc_ops, THIS_MODULE); | ||
397 | if (IS_ERR(rtc)) { | ||
398 | pr_debug("%s: can't register RTC device, err %ld\n", | ||
399 | pdev->name, PTR_ERR(rtc)); | ||
400 | goto fail; | ||
401 | } | ||
402 | platform_set_drvdata(pdev, rtc); | ||
403 | class_set_devdata(&rtc->class_dev, mem); | ||
404 | |||
405 | /* clear pending irqs, and set 1/second periodic, | ||
406 | * which we'll use instead of update irqs | ||
407 | */ | ||
408 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | ||
409 | |||
410 | /* clear old status */ | ||
411 | reg = rtc_read(OMAP_RTC_STATUS_REG); | ||
412 | if (reg & (u8) OMAP_RTC_STATUS_POWER_UP) { | ||
413 | pr_info("%s: RTC power up reset detected\n", | ||
414 | pdev->name); | ||
415 | rtc_write(OMAP_RTC_STATUS_POWER_UP, OMAP_RTC_STATUS_REG); | ||
416 | } | ||
417 | if (reg & (u8) OMAP_RTC_STATUS_ALARM) | ||
418 | rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG); | ||
419 | |||
420 | /* handle periodic and alarm irqs */ | ||
421 | if (request_irq(omap_rtc_timer, rtc_irq, SA_INTERRUPT, | ||
422 | rtc->class_dev.class_id, &rtc->class_dev)) { | ||
423 | pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", | ||
424 | pdev->name, omap_rtc_timer); | ||
425 | goto fail0; | ||
426 | } | ||
427 | if (request_irq(omap_rtc_alarm, rtc_irq, SA_INTERRUPT, | ||
428 | rtc->class_dev.class_id, &rtc->class_dev)) { | ||
429 | pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", | ||
430 | pdev->name, omap_rtc_alarm); | ||
431 | goto fail1; | ||
432 | } | ||
433 | |||
434 | /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ | ||
435 | reg = rtc_read(OMAP_RTC_CTRL_REG); | ||
436 | if (reg & (u8) OMAP_RTC_CTRL_STOP) | ||
437 | pr_info("%s: already running\n", pdev->name); | ||
438 | |||
439 | /* force to 24 hour mode */ | ||
440 | new_ctrl = reg & ~(OMAP_RTC_CTRL_SPLIT|OMAP_RTC_CTRL_AUTO_COMP); | ||
441 | new_ctrl |= OMAP_RTC_CTRL_STOP; | ||
442 | |||
443 | /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE: | ||
444 | * | ||
445 | * - Boards wired so that RTC_WAKE_INT does something, and muxed | ||
446 | * right (W13_1610_RTC_WAKE_INT is the default after chip reset), | ||
447 | * should initialize the device wakeup flag appropriately. | ||
448 | * | ||
449 | * - Boards wired so RTC_ON_nOFF is used as the reset signal, | ||
450 | * rather than nPWRON_RESET, should forcibly enable split | ||
451 | * power mode. (Some chip errata report that RTC_CTRL_SPLIT | ||
452 | * is write-only, and always reads as zero...) | ||
453 | */ | ||
454 | device_init_wakeup(&pdev->dev, 0); | ||
455 | |||
456 | if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT) | ||
457 | pr_info("%s: split power mode\n", pdev->name); | ||
458 | |||
459 | if (reg != new_ctrl) | ||
460 | rtc_write(new_ctrl, OMAP_RTC_CTRL_REG); | ||
461 | |||
462 | return 0; | ||
463 | |||
464 | fail1: | ||
465 | free_irq(omap_rtc_timer, NULL); | ||
466 | fail0: | ||
467 | rtc_device_unregister(rtc); | ||
468 | fail: | ||
469 | release_resource(mem); | ||
470 | return -EIO; | ||
471 | } | ||
472 | |||
473 | static int __devexit omap_rtc_remove(struct platform_device *pdev) | ||
474 | { | ||
475 | struct rtc_device *rtc = platform_get_drvdata(pdev);; | ||
476 | |||
477 | device_init_wakeup(&pdev->dev, 0); | ||
478 | |||
479 | /* leave rtc running, but disable irqs */ | ||
480 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | ||
481 | |||
482 | free_irq(omap_rtc_timer, rtc); | ||
483 | free_irq(omap_rtc_alarm, rtc); | ||
484 | |||
485 | release_resource(class_get_devdata(&rtc->class_dev)); | ||
486 | rtc_device_unregister(rtc); | ||
487 | return 0; | ||
488 | } | ||
489 | |||
490 | #ifdef CONFIG_PM | ||
491 | |||
492 | static struct timespec rtc_delta; | ||
493 | static u8 irqstat; | ||
494 | |||
495 | static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state) | ||
496 | { | ||
497 | struct rtc_time rtc_tm; | ||
498 | struct timespec time; | ||
499 | |||
500 | time.tv_nsec = 0; | ||
501 | omap_rtc_read_time(NULL, &rtc_tm); | ||
502 | rtc_tm_to_time(&rtc_tm, &time.tv_sec); | ||
503 | |||
504 | save_time_delta(&rtc_delta, &time); | ||
505 | irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG); | ||
506 | |||
507 | /* FIXME the RTC alarm is not currently acting as a wakeup event | ||
508 | * source, and in fact this enable() call is just saving a flag | ||
509 | * that's never used... | ||
510 | */ | ||
511 | if (device_may_wakeup(&pdev->dev)) | ||
512 | enable_irq_wake(omap_rtc_alarm); | ||
513 | else | ||
514 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | ||
515 | |||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | static int omap_rtc_resume(struct platform_device *pdev) | ||
520 | { | ||
521 | struct rtc_time rtc_tm; | ||
522 | struct timespec time; | ||
523 | |||
524 | time.tv_nsec = 0; | ||
525 | omap_rtc_read_time(NULL, &rtc_tm); | ||
526 | rtc_tm_to_time(&rtc_tm, &time.tv_sec); | ||
527 | |||
528 | restore_time_delta(&rtc_delta, &time); | ||
529 | if (device_may_wakeup(&pdev->dev)) | ||
530 | disable_irq_wake(omap_rtc_alarm); | ||
531 | else | ||
532 | rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG); | ||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | #else | ||
537 | #define omap_rtc_suspend NULL | ||
538 | #define omap_rtc_resume NULL | ||
539 | #endif | ||
540 | |||
541 | static void omap_rtc_shutdown(struct platform_device *pdev) | ||
542 | { | ||
543 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | ||
544 | } | ||
545 | |||
546 | MODULE_ALIAS("omap_rtc"); | ||
547 | static struct platform_driver omap_rtc_driver = { | ||
548 | .probe = omap_rtc_probe, | ||
549 | .remove = __devexit_p(omap_rtc_remove), | ||
550 | .suspend = omap_rtc_suspend, | ||
551 | .resume = omap_rtc_resume, | ||
552 | .shutdown = omap_rtc_shutdown, | ||
553 | .driver = { | ||
554 | .name = "omap_rtc", | ||
555 | .owner = THIS_MODULE, | ||
556 | }, | ||
557 | }; | ||
558 | |||
559 | static int __init rtc_init(void) | ||
560 | { | ||
561 | return platform_driver_register(&omap_rtc_driver); | ||
562 | } | ||
563 | module_init(rtc_init); | ||
564 | |||
565 | static void __exit rtc_exit(void) | ||
566 | { | ||
567 | platform_driver_unregister(&omap_rtc_driver); | ||
568 | } | ||
569 | module_exit(rtc_exit); | ||
570 | |||
571 | MODULE_AUTHOR("George G. Davis (and others)"); | ||
572 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c index a44fe4efa216..e2c7698fdba3 100644 --- a/drivers/rtc/rtc-rs5c372.c +++ b/drivers/rtc/rtc-rs5c372.c | |||
@@ -13,7 +13,7 @@ | |||
13 | #include <linux/rtc.h> | 13 | #include <linux/rtc.h> |
14 | #include <linux/bcd.h> | 14 | #include <linux/bcd.h> |
15 | 15 | ||
16 | #define DRV_VERSION "0.2" | 16 | #define DRV_VERSION "0.3" |
17 | 17 | ||
18 | /* Addresses to scan */ | 18 | /* Addresses to scan */ |
19 | static unsigned short normal_i2c[] = { /* 0x32,*/ I2C_CLIENT_END }; | 19 | static unsigned short normal_i2c[] = { /* 0x32,*/ I2C_CLIENT_END }; |
@@ -39,6 +39,14 @@ static int rs5c372_attach(struct i2c_adapter *adapter); | |||
39 | static int rs5c372_detach(struct i2c_client *client); | 39 | static int rs5c372_detach(struct i2c_client *client); |
40 | static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind); | 40 | static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind); |
41 | 41 | ||
42 | struct rs5c372 { | ||
43 | u8 reg_addr; | ||
44 | u8 regs[17]; | ||
45 | struct i2c_msg msg[1]; | ||
46 | struct i2c_client client; | ||
47 | struct rtc_device *rtc; | ||
48 | }; | ||
49 | |||
42 | static struct i2c_driver rs5c372_driver = { | 50 | static struct i2c_driver rs5c372_driver = { |
43 | .driver = { | 51 | .driver = { |
44 | .name = "rs5c372", | 52 | .name = "rs5c372", |
@@ -49,18 +57,16 @@ static struct i2c_driver rs5c372_driver = { | |||
49 | 57 | ||
50 | static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) | 58 | static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) |
51 | { | 59 | { |
52 | unsigned char buf[7] = { RS5C372_REG_BASE }; | ||
53 | 60 | ||
54 | /* this implements the 1st reading method, according | 61 | struct rs5c372 *rs5c372 = i2c_get_clientdata(client); |
55 | * to the datasheet. buf[0] is initialized with | 62 | u8 *buf = &(rs5c372->regs[1]); |
56 | * address ptr and transmission format register. | 63 | |
64 | /* this implements the 3rd reading method, according | ||
65 | * to the datasheet. rs5c372 defaults to internal | ||
66 | * address 0xF, so 0x0 is in regs[1] | ||
57 | */ | 67 | */ |
58 | struct i2c_msg msgs[] = { | ||
59 | { client->addr, 0, 1, buf }, | ||
60 | { client->addr, I2C_M_RD, 7, buf }, | ||
61 | }; | ||
62 | 68 | ||
63 | if ((i2c_transfer(client->adapter, msgs, 2)) != 2) { | 69 | if ((i2c_transfer(client->adapter, rs5c372->msg, 1)) != 1) { |
64 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | 70 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); |
65 | return -EIO; | 71 | return -EIO; |
66 | } | 72 | } |
@@ -114,23 +120,14 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
114 | 120 | ||
115 | static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim) | 121 | static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim) |
116 | { | 122 | { |
117 | unsigned char buf = RS5C372_REG_TRIM; | 123 | struct rs5c372 *rs5c372 = i2c_get_clientdata(client); |
118 | 124 | u8 tmp = rs5c372->regs[RS5C372_REG_TRIM + 1]; | |
119 | struct i2c_msg msgs[] = { | ||
120 | { client->addr, 0, 1, &buf }, | ||
121 | { client->addr, I2C_M_RD, 1, &buf }, | ||
122 | }; | ||
123 | |||
124 | if ((i2c_transfer(client->adapter, msgs, 2)) != 2) { | ||
125 | dev_err(&client->dev, "%s: read error\n", __FUNCTION__); | ||
126 | return -EIO; | ||
127 | } | ||
128 | 125 | ||
129 | if (osc) | 126 | if (osc) |
130 | *osc = (buf & RS5C372_TRIM_XSL) ? 32000 : 32768; | 127 | *osc = (tmp & RS5C372_TRIM_XSL) ? 32000 : 32768; |
131 | 128 | ||
132 | if (trim) { | 129 | if (trim) { |
133 | *trim = buf & RS5C372_TRIM_MASK; | 130 | *trim = tmp & RS5C372_TRIM_MASK; |
134 | dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, *trim); | 131 | dev_dbg(&client->dev, "%s: raw trim=%x\n", __FUNCTION__, *trim); |
135 | } | 132 | } |
136 | 133 | ||
@@ -201,7 +198,7 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind) | |||
201 | { | 198 | { |
202 | int err = 0; | 199 | int err = 0; |
203 | struct i2c_client *client; | 200 | struct i2c_client *client; |
204 | struct rtc_device *rtc; | 201 | struct rs5c372 *rs5c372; |
205 | 202 | ||
206 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); | 203 | dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); |
207 | 204 | ||
@@ -210,10 +207,11 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind) | |||
210 | goto exit; | 207 | goto exit; |
211 | } | 208 | } |
212 | 209 | ||
213 | if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) { | 210 | if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { |
214 | err = -ENOMEM; | 211 | err = -ENOMEM; |
215 | goto exit; | 212 | goto exit; |
216 | } | 213 | } |
214 | client = &rs5c372->client; | ||
217 | 215 | ||
218 | /* I2C client */ | 216 | /* I2C client */ |
219 | client->addr = address; | 217 | client->addr = address; |
@@ -222,32 +220,47 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind) | |||
222 | 220 | ||
223 | strlcpy(client->name, rs5c372_driver.driver.name, I2C_NAME_SIZE); | 221 | strlcpy(client->name, rs5c372_driver.driver.name, I2C_NAME_SIZE); |
224 | 222 | ||
223 | i2c_set_clientdata(client, rs5c372); | ||
224 | |||
225 | rs5c372->msg[0].addr = address; | ||
226 | rs5c372->msg[0].flags = I2C_M_RD; | ||
227 | rs5c372->msg[0].len = sizeof(rs5c372->regs); | ||
228 | rs5c372->msg[0].buf = rs5c372->regs; | ||
229 | |||
225 | /* Inform the i2c layer */ | 230 | /* Inform the i2c layer */ |
226 | if ((err = i2c_attach_client(client))) | 231 | if ((err = i2c_attach_client(client))) |
227 | goto exit_kfree; | 232 | goto exit_kfree; |
228 | 233 | ||
229 | dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); | 234 | dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); |
230 | 235 | ||
231 | rtc = rtc_device_register(rs5c372_driver.driver.name, &client->dev, | 236 | rs5c372->rtc = rtc_device_register(rs5c372_driver.driver.name, |
232 | &rs5c372_rtc_ops, THIS_MODULE); | 237 | &client->dev, &rs5c372_rtc_ops, THIS_MODULE); |
233 | 238 | ||
234 | if (IS_ERR(rtc)) { | 239 | if (IS_ERR(rs5c372->rtc)) { |
235 | err = PTR_ERR(rtc); | 240 | err = PTR_ERR(rs5c372->rtc); |
236 | goto exit_detach; | 241 | goto exit_detach; |
237 | } | 242 | } |
238 | 243 | ||
239 | i2c_set_clientdata(client, rtc); | 244 | err = device_create_file(&client->dev, &dev_attr_trim); |
240 | 245 | if (err) | |
241 | device_create_file(&client->dev, &dev_attr_trim); | 246 | goto exit_devreg; |
242 | device_create_file(&client->dev, &dev_attr_osc); | 247 | err = device_create_file(&client->dev, &dev_attr_osc); |
248 | if (err) | ||
249 | goto exit_trim; | ||
243 | 250 | ||
244 | return 0; | 251 | return 0; |
245 | 252 | ||
253 | exit_trim: | ||
254 | device_remove_file(&client->dev, &dev_attr_trim); | ||
255 | |||
256 | exit_devreg: | ||
257 | rtc_device_unregister(rs5c372->rtc); | ||
258 | |||
246 | exit_detach: | 259 | exit_detach: |
247 | i2c_detach_client(client); | 260 | i2c_detach_client(client); |
248 | 261 | ||
249 | exit_kfree: | 262 | exit_kfree: |
250 | kfree(client); | 263 | kfree(rs5c372); |
251 | 264 | ||
252 | exit: | 265 | exit: |
253 | return err; | 266 | return err; |
@@ -256,16 +269,15 @@ exit: | |||
256 | static int rs5c372_detach(struct i2c_client *client) | 269 | static int rs5c372_detach(struct i2c_client *client) |
257 | { | 270 | { |
258 | int err; | 271 | int err; |
259 | struct rtc_device *rtc = i2c_get_clientdata(client); | 272 | struct rs5c372 *rs5c372 = i2c_get_clientdata(client); |
260 | 273 | ||
261 | if (rtc) | 274 | if (rs5c372->rtc) |
262 | rtc_device_unregister(rtc); | 275 | rtc_device_unregister(rs5c372->rtc); |
263 | 276 | ||
264 | if ((err = i2c_detach_client(client))) | 277 | if ((err = i2c_detach_client(client))) |
265 | return err; | 278 | return err; |
266 | 279 | ||
267 | kfree(client); | 280 | kfree(rs5c372); |
268 | |||
269 | return 0; | 281 | return 0; |
270 | } | 282 | } |
271 | 283 | ||
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c index 6ef9c62d5032..f50a1b8e1607 100644 --- a/drivers/rtc/rtc-test.c +++ b/drivers/rtc/rtc-test.c | |||
@@ -123,11 +123,18 @@ static int test_probe(struct platform_device *plat_dev) | |||
123 | err = PTR_ERR(rtc); | 123 | err = PTR_ERR(rtc); |
124 | return err; | 124 | return err; |
125 | } | 125 | } |
126 | device_create_file(&plat_dev->dev, &dev_attr_irq); | 126 | |
127 | err = device_create_file(&plat_dev->dev, &dev_attr_irq); | ||
128 | if (err) | ||
129 | goto err; | ||
127 | 130 | ||
128 | platform_set_drvdata(plat_dev, rtc); | 131 | platform_set_drvdata(plat_dev, rtc); |
129 | 132 | ||
130 | return 0; | 133 | return 0; |
134 | |||
135 | err: | ||
136 | rtc_device_unregister(rtc); | ||
137 | return err; | ||
131 | } | 138 | } |
132 | 139 | ||
133 | static int __devexit test_remove(struct platform_device *plat_dev) | 140 | static int __devexit test_remove(struct platform_device *plat_dev) |
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index 522c69753bbf..9a67487d086b 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
@@ -562,11 +562,19 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind) | |||
562 | else | 562 | else |
563 | dev_err(&client->dev, "couldn't read status\n"); | 563 | dev_err(&client->dev, "couldn't read status\n"); |
564 | 564 | ||
565 | device_create_file(&client->dev, &dev_attr_atrim); | 565 | err = device_create_file(&client->dev, &dev_attr_atrim); |
566 | device_create_file(&client->dev, &dev_attr_dtrim); | 566 | if (err) goto exit_devreg; |
567 | err = device_create_file(&client->dev, &dev_attr_dtrim); | ||
568 | if (err) goto exit_atrim; | ||
567 | 569 | ||
568 | return 0; | 570 | return 0; |
569 | 571 | ||
572 | exit_atrim: | ||
573 | device_remove_file(&client->dev, &dev_attr_atrim); | ||
574 | |||
575 | exit_devreg: | ||
576 | rtc_device_unregister(rtc); | ||
577 | |||
570 | exit_detach: | 578 | exit_detach: |
571 | i2c_detach_client(client); | 579 | i2c_detach_client(client); |
572 | 580 | ||