diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/rtc/rtc-tps6586x.c | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'drivers/rtc/rtc-tps6586x.c')
-rw-r--r-- | drivers/rtc/rtc-tps6586x.c | 363 |
1 files changed, 197 insertions, 166 deletions
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c index 70f61b8e9e6..c41edabf0b2 100644 --- a/drivers/rtc/rtc-tps6586x.c +++ b/drivers/rtc/rtc-tps6586x.c | |||
@@ -1,23 +1,23 @@ | |||
1 | /* | 1 | /* |
2 | * rtc-tps6586x.c: RTC driver for TI PMIC TPS6586X | 2 | * drivers/rtc/rtc-tps6586x.c |
3 | * | 3 | * |
4 | * Copyright (c) 2012, NVIDIA Corporation. | 4 | * RTC driver for TI TPS6586x |
5 | * | 5 | * |
6 | * Author: Laxman Dewangan <ldewangan@nvidia.com> | 6 | * Copyright (c) 2010, NVIDIA Corporation. |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * modify it under the terms of the GNU General Public License as | 9 | * it under the terms of the GNU General Public License as published by |
10 | * published by the Free Software Foundation version 2. | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | ||
11 | * | 12 | * |
12 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | * whether express or implied; without even the implied warranty of | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15 | * General Public License for more details. | 16 | * more details. |
16 | * | 17 | * |
17 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License along |
18 | * along with this program; if not, write to the Free Software | 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * 02111-1307, USA | ||
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/device.h> | 23 | #include <linux/device.h> |
@@ -25,40 +25,28 @@ | |||
25 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/mfd/tps6586x.h> | 27 | #include <linux/mfd/tps6586x.h> |
28 | #include <linux/module.h> | ||
29 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
30 | #include <linux/pm_runtime.h> | ||
31 | #include <linux/rtc.h> | 29 | #include <linux/rtc.h> |
32 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
33 | 31 | ||
34 | #define RTC_CTRL 0xc0 | 32 | #define RTC_CTRL 0xc0 |
35 | #define POR_RESET_N BIT(7) | 33 | #define POR_RESET_N BIT(7) |
36 | #define OSC_SRC_SEL BIT(6) | 34 | #define OSC_SRC_SEL BIT(6) |
37 | #define RTC_ENABLE BIT(5) /* enables alarm */ | 35 | #define RTC_ENABLE BIT(5) /* enables alarm */ |
38 | #define RTC_BUF_ENABLE BIT(4) /* 32 KHz buffer enable */ | 36 | #define RTC_BUF_ENABLE BIT(4) /* 32 KHz buffer enable */ |
39 | #define PRE_BYPASS BIT(3) /* 0=1KHz or 1=32KHz updates */ | 37 | #define PRE_BYPASS BIT(3) /* 0=1KHz or 1=32KHz updates */ |
40 | #define CL_SEL_MASK (BIT(2)|BIT(1)) | 38 | #define CL_SEL_MASK (BIT(2)|BIT(1)) |
41 | #define CL_SEL_POS 1 | 39 | #define CL_SEL_POS 1 |
42 | #define RTC_ALARM1_HI 0xc1 | 40 | #define RTC_ALARM1_HI 0xc1 |
43 | #define RTC_COUNT4 0xc6 | 41 | #define RTC_COUNT4 0xc6 |
44 | 42 | #define RTC_COUNT4_DUMMYREAD 0xc5 /* start a PMU RTC access by reading the register prior to the RTC_COUNT4 */ | |
45 | /* start a PMU RTC access by reading the register prior to the RTC_COUNT4 */ | 43 | #define ALM1_VALID_RANGE_IN_SEC 0x3FFF /*only 14-bits width in second*/ |
46 | #define RTC_COUNT4_DUMMYREAD 0xc5 | ||
47 | |||
48 | /*only 14-bits width in second*/ | ||
49 | #define ALM1_VALID_RANGE_IN_SEC 0x3FFF | ||
50 | |||
51 | #define TPS6586X_RTC_CL_SEL_1_5PF 0x0 | ||
52 | #define TPS6586X_RTC_CL_SEL_6_5PF 0x1 | ||
53 | #define TPS6586X_RTC_CL_SEL_7_5PF 0x2 | ||
54 | #define TPS6586X_RTC_CL_SEL_12_5PF 0x3 | ||
55 | 44 | ||
56 | struct tps6586x_rtc { | 45 | struct tps6586x_rtc { |
57 | struct device *dev; | 46 | unsigned long epoch_start; |
58 | struct rtc_device *rtc; | ||
59 | int irq; | 47 | int irq; |
48 | struct rtc_device *rtc; | ||
60 | bool irq_en; | 49 | bool irq_en; |
61 | unsigned long long epoch_start; | ||
62 | }; | 50 | }; |
63 | 51 | ||
64 | static inline struct device *to_tps6586x_dev(struct device *dev) | 52 | static inline struct device *to_tps6586x_dev(struct device *dev) |
@@ -73,13 +61,13 @@ static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
73 | unsigned long long ticks = 0; | 61 | unsigned long long ticks = 0; |
74 | unsigned long seconds; | 62 | unsigned long seconds; |
75 | u8 buff[6]; | 63 | u8 buff[6]; |
76 | int ret; | 64 | int err; |
77 | int i; | 65 | int i; |
78 | 66 | ||
79 | ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(buff), buff); | 67 | err = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(buff), buff); |
80 | if (ret < 0) { | 68 | if (err < 0) { |
81 | dev_err(dev, "read counter failed with err %d\n", ret); | 69 | dev_err(dev, "failed to read counter\n"); |
82 | return ret; | 70 | return err; |
83 | } | 71 | } |
84 | 72 | ||
85 | for (i = 1; i < sizeof(buff); i++) { | 73 | for (i = 1; i < sizeof(buff); i++) { |
@@ -88,6 +76,7 @@ static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
88 | } | 76 | } |
89 | 77 | ||
90 | seconds = ticks >> 10; | 78 | seconds = ticks >> 10; |
79 | |||
91 | seconds += rtc->epoch_start; | 80 | seconds += rtc->epoch_start; |
92 | rtc_time_to_tm(seconds, tm); | 81 | rtc_time_to_tm(seconds, tm); |
93 | return rtc_valid_tm(tm); | 82 | return rtc_valid_tm(tm); |
@@ -100,13 +89,15 @@ static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
100 | unsigned long long ticks; | 89 | unsigned long long ticks; |
101 | unsigned long seconds; | 90 | unsigned long seconds; |
102 | u8 buff[5]; | 91 | u8 buff[5]; |
103 | int ret; | 92 | int err; |
104 | 93 | ||
105 | rtc_tm_to_time(tm, &seconds); | 94 | rtc_tm_to_time(tm, &seconds); |
106 | if (seconds < rtc->epoch_start) { | 95 | |
96 | if (WARN_ON(seconds < rtc->epoch_start)) { | ||
107 | dev_err(dev, "requested time unsupported\n"); | 97 | dev_err(dev, "requested time unsupported\n"); |
108 | return -EINVAL; | 98 | return -EINVAL; |
109 | } | 99 | } |
100 | |||
110 | seconds -= rtc->epoch_start; | 101 | seconds -= rtc->epoch_start; |
111 | 102 | ||
112 | ticks = (unsigned long long)seconds << 10; | 103 | ticks = (unsigned long long)seconds << 10; |
@@ -116,40 +107,24 @@ static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
116 | buff[3] = (ticks >> 8) & 0xff; | 107 | buff[3] = (ticks >> 8) & 0xff; |
117 | buff[4] = ticks & 0xff; | 108 | buff[4] = ticks & 0xff; |
118 | 109 | ||
119 | /* Disable RTC before changing time */ | 110 | err = tps6586x_clr_bits(tps_dev, RTC_CTRL, RTC_ENABLE); |
120 | ret = tps6586x_clr_bits(tps_dev, RTC_CTRL, RTC_ENABLE); | 111 | if (err < 0) { |
121 | if (ret < 0) { | ||
122 | dev_err(dev, "failed to clear RTC_ENABLE\n"); | 112 | dev_err(dev, "failed to clear RTC_ENABLE\n"); |
123 | return ret; | 113 | return err; |
124 | } | 114 | } |
125 | 115 | ||
126 | ret = tps6586x_writes(tps_dev, RTC_COUNT4, sizeof(buff), buff); | 116 | err = tps6586x_writes(tps_dev, RTC_COUNT4, sizeof(buff), buff); |
127 | if (ret < 0) { | 117 | if (err < 0) { |
128 | dev_err(dev, "failed to program new time\n"); | 118 | dev_err(dev, "failed to program new time\n"); |
129 | return ret; | 119 | return err; |
130 | } | 120 | } |
131 | 121 | ||
132 | /* Enable RTC */ | 122 | err = tps6586x_set_bits(tps_dev, RTC_CTRL, RTC_ENABLE); |
133 | ret = tps6586x_set_bits(tps_dev, RTC_CTRL, RTC_ENABLE); | 123 | if (err < 0) { |
134 | if (ret < 0) { | ||
135 | dev_err(dev, "failed to set RTC_ENABLE\n"); | 124 | dev_err(dev, "failed to set RTC_ENABLE\n"); |
136 | return ret; | 125 | return err; |
137 | } | 126 | } |
138 | return 0; | ||
139 | } | ||
140 | 127 | ||
141 | static int tps6586x_rtc_alarm_irq_enable(struct device *dev, | ||
142 | unsigned int enabled) | ||
143 | { | ||
144 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
145 | |||
146 | if (enabled && !rtc->irq_en) { | ||
147 | enable_irq(rtc->irq); | ||
148 | rtc->irq_en = true; | ||
149 | } else if (!enabled && rtc->irq_en) { | ||
150 | disable_irq(rtc->irq); | ||
151 | rtc->irq_en = false; | ||
152 | } | ||
153 | return 0; | 128 | return 0; |
154 | } | 129 | } |
155 | 130 | ||
@@ -163,28 +138,33 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
163 | unsigned long long rticks = 0; | 138 | unsigned long long rticks = 0; |
164 | u8 buff[3]; | 139 | u8 buff[3]; |
165 | u8 rbuff[6]; | 140 | u8 rbuff[6]; |
166 | int ret; | 141 | int err; |
167 | int i; | 142 | int i; |
168 | 143 | ||
144 | if (rtc->irq == -1) | ||
145 | return -EIO; | ||
146 | |||
169 | rtc_tm_to_time(&alrm->time, &seconds); | 147 | rtc_tm_to_time(&alrm->time, &seconds); |
170 | 148 | ||
171 | if (alrm->enabled && (seconds < rtc->epoch_start)) { | 149 | if (WARN_ON(alrm->enabled && (seconds < rtc->epoch_start))) { |
172 | dev_err(dev, "can't set alarm to requested time\n"); | 150 | dev_err(dev, "can't set alarm to requested time\n"); |
173 | return -EINVAL; | 151 | return -EINVAL; |
174 | } | 152 | } |
175 | 153 | ||
176 | ret = tps6586x_rtc_alarm_irq_enable(dev, alrm->enabled); | 154 | if (alrm->enabled && !rtc->irq_en) { |
177 | if (ret < 0) { | 155 | enable_irq(rtc->irq); |
178 | dev_err(dev, "can't set alarm irq, err %d\n", ret); | 156 | rtc->irq_en = true; |
179 | return ret; | 157 | } else if (!alrm->enabled && rtc->irq_en) { |
158 | disable_irq(rtc->irq); | ||
159 | rtc->irq_en = false; | ||
180 | } | 160 | } |
181 | 161 | ||
182 | seconds -= rtc->epoch_start; | 162 | seconds -= rtc->epoch_start; |
183 | ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, | 163 | |
184 | sizeof(rbuff), rbuff); | 164 | err = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(rbuff), rbuff); |
185 | if (ret < 0) { | 165 | if (err < 0) { |
186 | dev_err(dev, "read counter failed with err %d\n", ret); | 166 | dev_err(dev, "failed to read counter\n"); |
187 | return ret; | 167 | return err; |
188 | } | 168 | } |
189 | 169 | ||
190 | for (i = 1; i < sizeof(rbuff); i++) { | 170 | for (i = 1; i < sizeof(rbuff); i++) { |
@@ -197,15 +177,16 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
197 | seconds = rtc_current_time - 1; | 177 | seconds = rtc_current_time - 1; |
198 | 178 | ||
199 | ticks = (unsigned long long)seconds << 10; | 179 | ticks = (unsigned long long)seconds << 10; |
180 | |||
200 | buff[0] = (ticks >> 16) & 0xff; | 181 | buff[0] = (ticks >> 16) & 0xff; |
201 | buff[1] = (ticks >> 8) & 0xff; | 182 | buff[1] = (ticks >> 8) & 0xff; |
202 | buff[2] = ticks & 0xff; | 183 | buff[2] = ticks & 0xff; |
203 | 184 | ||
204 | ret = tps6586x_writes(tps_dev, RTC_ALARM1_HI, sizeof(buff), buff); | 185 | err = tps6586x_writes(tps_dev, RTC_ALARM1_HI, sizeof(buff), buff); |
205 | if (ret) | 186 | if (err) |
206 | dev_err(dev, "programming alarm failed with err %d\n", ret); | 187 | dev_err(tps_dev, "unable to program alarm\n"); |
207 | 188 | ||
208 | return ret; | 189 | return err; |
209 | } | 190 | } |
210 | 191 | ||
211 | static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 192 | static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
@@ -215,19 +196,66 @@ static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
215 | unsigned long ticks; | 196 | unsigned long ticks; |
216 | unsigned long seconds; | 197 | unsigned long seconds; |
217 | u8 buff[3]; | 198 | u8 buff[3]; |
218 | int ret; | 199 | int err; |
219 | 200 | ||
220 | ret = tps6586x_reads(tps_dev, RTC_ALARM1_HI, sizeof(buff), buff); | 201 | err = tps6586x_reads(tps_dev, RTC_ALARM1_HI, sizeof(buff), buff); |
221 | if (ret) { | 202 | if (err) |
222 | dev_err(dev, "read RTC_ALARM1_HI failed with err %d\n", ret); | 203 | return err; |
223 | return ret; | ||
224 | } | ||
225 | 204 | ||
226 | ticks = (buff[0] << 16) | (buff[1] << 8) | buff[2]; | 205 | ticks = (buff[0] << 16) | (buff[1] << 8) | buff[2]; |
227 | seconds = ticks >> 10; | 206 | seconds = ticks >> 10; |
228 | seconds += rtc->epoch_start; | 207 | seconds += rtc->epoch_start; |
229 | 208 | ||
230 | rtc_time_to_tm(seconds, &alrm->time); | 209 | rtc_time_to_tm(seconds, &alrm->time); |
210 | |||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | static int tps6586x_rtc_alarm_irq_enable(struct device *dev, | ||
215 | unsigned int enabled) | ||
216 | { | ||
217 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
218 | struct device *tps_dev = to_tps6586x_dev(dev); | ||
219 | u8 buff; | ||
220 | int err; | ||
221 | |||
222 | if (rtc->irq == -1) | ||
223 | return -EIO; | ||
224 | |||
225 | err = tps6586x_read(tps_dev, RTC_CTRL, &buff); | ||
226 | if (err < 0) { | ||
227 | dev_err(dev, "failed to read RTC_CTRL\n"); | ||
228 | return err; | ||
229 | } | ||
230 | |||
231 | if ((enabled && (buff & RTC_ENABLE)) || | ||
232 | (!enabled && !(buff & RTC_ENABLE))) | ||
233 | return 0; | ||
234 | |||
235 | if (enabled) { | ||
236 | err = tps6586x_set_bits(tps_dev, RTC_CTRL, RTC_ENABLE); | ||
237 | if (err < 0) { | ||
238 | dev_err(dev, "failed to set RTC_ENABLE\n"); | ||
239 | return err; | ||
240 | } | ||
241 | |||
242 | if (!rtc->irq_en) { | ||
243 | enable_irq(rtc->irq); | ||
244 | rtc->irq_en = true; | ||
245 | } | ||
246 | } else { | ||
247 | err = tps6586x_clr_bits(tps_dev, RTC_CTRL, RTC_ENABLE); | ||
248 | if (err < 0) { | ||
249 | dev_err(dev, "failed to clear RTC_ENABLE\n"); | ||
250 | return err; | ||
251 | } | ||
252 | |||
253 | if (rtc->irq_en) { | ||
254 | disable_irq(rtc->irq); | ||
255 | rtc->irq_en = false; | ||
256 | } | ||
257 | } | ||
258 | |||
231 | return 0; | 259 | return 0; |
232 | } | 260 | } |
233 | 261 | ||
@@ -241,116 +269,119 @@ static const struct rtc_class_ops tps6586x_rtc_ops = { | |||
241 | 269 | ||
242 | static irqreturn_t tps6586x_rtc_irq(int irq, void *data) | 270 | static irqreturn_t tps6586x_rtc_irq(int irq, void *data) |
243 | { | 271 | { |
244 | struct tps6586x_rtc *rtc = data; | 272 | struct device *dev = data; |
273 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
245 | 274 | ||
246 | rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); | 275 | rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); |
247 | return IRQ_HANDLED; | 276 | return IRQ_HANDLED; |
248 | } | 277 | } |
249 | 278 | ||
250 | static int tps6586x_rtc_probe(struct platform_device *pdev) | 279 | static int __devinit tps6586x_rtc_probe(struct platform_device *pdev) |
251 | { | 280 | { |
281 | struct tps6586x_rtc_platform_data *pdata = pdev->dev.platform_data; | ||
252 | struct device *tps_dev = to_tps6586x_dev(&pdev->dev); | 282 | struct device *tps_dev = to_tps6586x_dev(&pdev->dev); |
253 | struct tps6586x_rtc *rtc; | 283 | struct tps6586x_rtc *rtc; |
254 | int ret; | 284 | int err; |
285 | struct tps6586x_epoch_start *epoch; | ||
286 | |||
287 | if (!pdata) { | ||
288 | dev_err(&pdev->dev, "no platform_data specified\n"); | ||
289 | return -EINVAL; | ||
290 | } | ||
291 | |||
292 | rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); | ||
255 | 293 | ||
256 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); | ||
257 | if (!rtc) | 294 | if (!rtc) |
258 | return -ENOMEM; | 295 | return -ENOMEM; |
259 | 296 | ||
260 | rtc->dev = &pdev->dev; | 297 | rtc->irq = -1; |
261 | rtc->irq = platform_get_irq(pdev, 0); | ||
262 | 298 | ||
263 | /* Set epoch start as 00:00:00:01:01:2009 */ | 299 | if (pdata->irq < 0) |
264 | rtc->epoch_start = mktime(2009, 1, 1, 0, 0, 0); | 300 | dev_warn(&pdev->dev, "no IRQ specified, wakeup is disabled\n"); |
265 | 301 | ||
266 | /* 1 kHz tick mode, enable tick counting */ | 302 | epoch = &pdata->start; |
267 | ret = tps6586x_update(tps_dev, RTC_CTRL, | 303 | rtc->epoch_start = mktime(epoch->year, epoch->month, epoch->day, |
268 | RTC_ENABLE | OSC_SRC_SEL | | 304 | epoch->hour, epoch->min, epoch->sec); |
269 | ((TPS6586X_RTC_CL_SEL_1_5PF << CL_SEL_POS) & CL_SEL_MASK), | 305 | |
270 | RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); | 306 | dev_set_drvdata(&pdev->dev, rtc); |
271 | if (ret < 0) { | ||
272 | dev_err(&pdev->dev, "unable to start counter\n"); | ||
273 | return ret; | ||
274 | } | ||
275 | 307 | ||
276 | platform_set_drvdata(pdev, rtc); | 308 | device_init_wakeup(&pdev->dev, 1); |
277 | rtc->rtc = rtc_device_register(dev_name(&pdev->dev), &pdev->dev, | 309 | |
310 | rtc->rtc = rtc_device_register("tps6586x-rtc", &pdev->dev, | ||
278 | &tps6586x_rtc_ops, THIS_MODULE); | 311 | &tps6586x_rtc_ops, THIS_MODULE); |
279 | if (IS_ERR(rtc->rtc)) { | ||
280 | ret = PTR_ERR(rtc->rtc); | ||
281 | dev_err(&pdev->dev, "RTC device register: ret %d\n", ret); | ||
282 | goto fail_rtc_register; | ||
283 | } | ||
284 | 312 | ||
285 | ret = request_threaded_irq(rtc->irq, NULL, tps6586x_rtc_irq, | 313 | if (IS_ERR(rtc->rtc)) { |
286 | IRQF_ONESHOT | IRQF_EARLY_RESUME, | 314 | err = PTR_ERR(rtc->rtc); |
287 | dev_name(&pdev->dev), rtc); | 315 | goto fail; |
288 | if (ret < 0) { | ||
289 | dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n", | ||
290 | rtc->irq, ret); | ||
291 | goto fail_req_irq; | ||
292 | } | 316 | } |
293 | disable_irq(rtc->irq); | ||
294 | device_set_wakeup_capable(&pdev->dev, 1); | ||
295 | return 0; | ||
296 | |||
297 | fail_req_irq: | ||
298 | rtc_device_unregister(rtc->rtc); | ||
299 | 317 | ||
300 | fail_rtc_register: | 318 | /* 1 kHz tick mode, enable tick counting */ |
301 | tps6586x_update(tps_dev, RTC_CTRL, 0, | 319 | err = tps6586x_update(tps_dev, RTC_CTRL, |
320 | RTC_ENABLE | OSC_SRC_SEL | ((pdata->cl_sel << CL_SEL_POS) & | ||
321 | CL_SEL_MASK), | ||
302 | RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); | 322 | RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); |
303 | return ret; | 323 | if (err < 0) { |
304 | }; | 324 | dev_err(&pdev->dev, "unable to start counter\n"); |
325 | goto fail; | ||
326 | } | ||
305 | 327 | ||
306 | static int tps6586x_rtc_remove(struct platform_device *pdev) | 328 | if (pdata && (pdata->irq >= 0)) { |
307 | { | 329 | rtc->irq = pdata->irq; |
308 | struct tps6586x_rtc *rtc = platform_get_drvdata(pdev); | 330 | err = request_threaded_irq(pdata->irq, NULL, tps6586x_rtc_irq, |
309 | struct device *tps_dev = to_tps6586x_dev(&pdev->dev); | 331 | IRQF_ONESHOT, "tps6586x-rtc", |
332 | &pdev->dev); | ||
333 | if (err) { | ||
334 | dev_warn(&pdev->dev, "unable to request IRQ(%d)\n", rtc->irq); | ||
335 | rtc->irq = -1; | ||
336 | } else { | ||
337 | enable_irq_wake(rtc->irq); | ||
338 | disable_irq(rtc->irq); | ||
339 | } | ||
340 | } | ||
310 | 341 | ||
311 | tps6586x_update(tps_dev, RTC_CTRL, 0, | ||
312 | RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); | ||
313 | rtc_device_unregister(rtc->rtc); | ||
314 | free_irq(rtc->irq, rtc); | ||
315 | return 0; | 342 | return 0; |
316 | } | ||
317 | 343 | ||
318 | #ifdef CONFIG_PM_SLEEP | 344 | fail: |
319 | static int tps6586x_rtc_suspend(struct device *dev) | 345 | if (!IS_ERR_OR_NULL(rtc->rtc)) |
320 | { | 346 | rtc_device_unregister(rtc->rtc); |
321 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | 347 | device_init_wakeup(&pdev->dev, 0); |
322 | 348 | kfree(rtc); | |
323 | if (device_may_wakeup(dev)) | 349 | return err; |
324 | enable_irq_wake(rtc->irq); | ||
325 | return 0; | ||
326 | } | 350 | } |
327 | 351 | ||
328 | static int tps6586x_rtc_resume(struct device *dev) | 352 | static int __devexit tps6586x_rtc_remove(struct platform_device *pdev) |
329 | { | 353 | { |
330 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | 354 | struct tps6586x_rtc *rtc = dev_get_drvdata(&pdev->dev); |
331 | 355 | ||
332 | if (device_may_wakeup(dev)) | 356 | if (rtc->irq != -1) |
333 | disable_irq_wake(rtc->irq); | 357 | free_irq(rtc->irq, rtc); |
358 | rtc_device_unregister(rtc->rtc); | ||
359 | kfree(rtc); | ||
334 | return 0; | 360 | return 0; |
335 | } | 361 | } |
336 | #endif | ||
337 | |||
338 | static const struct dev_pm_ops tps6586x_pm_ops = { | ||
339 | SET_SYSTEM_SLEEP_PM_OPS(tps6586x_rtc_suspend, tps6586x_rtc_resume) | ||
340 | }; | ||
341 | 362 | ||
342 | static struct platform_driver tps6586x_rtc_driver = { | 363 | static struct platform_driver tps6586x_rtc_driver = { |
343 | .driver = { | 364 | .driver = { |
344 | .name = "tps6586x-rtc", | 365 | .name = "tps6586x-rtc", |
345 | .owner = THIS_MODULE, | 366 | .owner = THIS_MODULE, |
346 | .pm = &tps6586x_pm_ops, | ||
347 | }, | 367 | }, |
348 | .probe = tps6586x_rtc_probe, | 368 | .probe = tps6586x_rtc_probe, |
349 | .remove = tps6586x_rtc_remove, | 369 | .remove = __devexit_p(tps6586x_rtc_remove), |
350 | }; | 370 | }; |
351 | module_platform_driver(tps6586x_rtc_driver); | ||
352 | 371 | ||
353 | MODULE_ALIAS("platform:rtc-tps6586x"); | 372 | static int __init tps6586x_rtc_init(void) |
373 | { | ||
374 | return platform_driver_register(&tps6586x_rtc_driver); | ||
375 | } | ||
376 | module_init(tps6586x_rtc_init); | ||
377 | |||
378 | static void __exit tps6586x_rtc_exit(void) | ||
379 | { | ||
380 | platform_driver_unregister(&tps6586x_rtc_driver); | ||
381 | } | ||
382 | module_exit(tps6586x_rtc_exit); | ||
383 | |||
354 | MODULE_DESCRIPTION("TI TPS6586x RTC driver"); | 384 | MODULE_DESCRIPTION("TI TPS6586x RTC driver"); |
355 | MODULE_AUTHOR("Laxman dewangan <ldewangan@nvidia.com>"); | 385 | MODULE_AUTHOR("NVIDIA Corporation"); |
356 | MODULE_LICENSE("GPL v2"); | 386 | MODULE_LICENSE("GPL"); |
387 | MODULE_ALIAS("platform:rtc-tps6586x"); | ||