aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:04:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:04:38 -0400
commit54e514b91b95d6441c12a7955addfb9f9d2afc65 (patch)
tree8b73d901bd2a6ec5a31f34a8954e5ea92216dd6c /drivers
parent4fc8adcfec3da639da76e8314c9ccefe5bf9a045 (diff)
parent6c8c90319c0bb1c9e0b68e721359b89ae4f28465 (diff)
Merge branch 'akpm' (patches from Andrew)
Merge third patchbomb from Andrew Morton: - various misc things - a couple of lib/ optimisations - provide DIV_ROUND_CLOSEST_ULL() - checkpatch updates - rtc tree - befs, nilfs2, hfs, hfsplus, fatfs, adfs, affs, bfs - ptrace fixes - fork() fixes - seccomp cleanups - more mmap_sem hold time reductions from Davidlohr * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (138 commits) proc: show locks in /proc/pid/fdinfo/X docs: add missing and new /proc/PID/status file entries, fix typos drivers/rtc/rtc-at91rm9200.c: make IO endian agnostic Documentation/spi/spidev_test.c: fix warning drivers/rtc/rtc-s5m.c: allow usage on device type different than main MFD type .gitignore: ignore *.tar MAINTAINERS: add Mediatek SoC mailing list tomoyo: reduce mmap_sem hold for mm->exe_file powerpc/oprofile: reduce mmap_sem hold for exe_file oprofile: reduce mmap_sem hold for mm->exe_file mips: ip32: add platform data hooks to use DS1685 driver lib/Kconfig: fix up HAVE_ARCH_BITREVERSE help text x86: switch to using asm-generic for seccomp.h sparc: switch to using asm-generic for seccomp.h powerpc: switch to using asm-generic for seccomp.h parisc: switch to using asm-generic for seccomp.h mips: switch to using asm-generic for seccomp.h microblaze: use asm-generic for seccomp.h arm: use asm-generic for seccomp.h seccomp: allow COMPAT sigreturn overrides ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/clk/bcm/clk-kona.c28
-rw-r--r--drivers/clk/bcm/clk-kona.h1
-rw-r--r--drivers/cpuidle/governors/menu.c8
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h3
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c1
-rw-r--r--drivers/hwmon/ina2xx.c17
-rw-r--r--drivers/hwmon/lm85.c26
-rw-r--r--drivers/hwmon/w83795.c8
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_c.c2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_core.c6
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_priv.h2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_t.c2
-rw-r--r--drivers/media/dvb-frontends/cxd2820r_t2.c2
-rw-r--r--drivers/memstick/core/mspro_block.c3
-rw-r--r--drivers/oprofile/buffer_sync.c30
-rw-r--r--drivers/rtc/Kconfig16
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/class.c6
-rw-r--r--drivers/rtc/hctosys.c6
-rw-r--r--drivers/rtc/interface.c5
-rw-r--r--drivers/rtc/rtc-ab-b5ze-s3.c2
-rw-r--r--drivers/rtc/rtc-at91rm9200.c4
-rw-r--r--drivers/rtc/rtc-cmos.c6
-rw-r--r--drivers/rtc/rtc-da9052.c97
-rw-r--r--drivers/rtc/rtc-digicolor.c227
-rw-r--r--drivers/rtc/rtc-ds1374.c8
-rw-r--r--drivers/rtc/rtc-ds1685.c9
-rw-r--r--drivers/rtc/rtc-ds3232.c6
-rw-r--r--drivers/rtc/rtc-efi-platform.c3
-rw-r--r--drivers/rtc/rtc-em3027.c11
-rw-r--r--drivers/rtc/rtc-hym8563.c12
-rw-r--r--drivers/rtc/rtc-m41t80.c6
-rw-r--r--drivers/rtc/rtc-max77686.c6
-rw-r--r--drivers/rtc/rtc-max8997.c8
-rw-r--r--drivers/rtc/rtc-msm6242.c4
-rw-r--r--drivers/rtc/rtc-omap.c68
-rw-r--r--drivers/rtc/rtc-opal.c3
-rw-r--r--drivers/rtc/rtc-pcf8563.c7
-rw-r--r--drivers/rtc/rtc-s3c.c193
-rw-r--r--drivers/rtc/rtc-s5m.c34
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c66
-rw-r--r--drivers/rtc/rtc-twl.c9
-rw-r--r--drivers/rtc/rtc-x1205.c4
-rw-r--r--drivers/scsi/bfa/bfad.c22
44 files changed, 643 insertions, 345 deletions
diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c
index 05abae89262e..a0ef4f75d457 100644
--- a/drivers/clk/bcm/clk-kona.c
+++ b/drivers/clk/bcm/clk-kona.c
@@ -15,6 +15,7 @@
15#include "clk-kona.h" 15#include "clk-kona.h"
16 16
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/kernel.h>
18 19
19/* 20/*
20 * "Policies" affect the frequencies of bus clocks provided by a 21 * "Policies" affect the frequencies of bus clocks provided by a
@@ -51,21 +52,6 @@ static inline u32 bitfield_replace(u32 reg_val, u32 shift, u32 width, u32 val)
51 52
52/* Divider and scaling helpers */ 53/* Divider and scaling helpers */
53 54
54/*
55 * Implement DIV_ROUND_CLOSEST() for 64-bit dividend and both values
56 * unsigned. Note that unlike do_div(), the remainder is discarded
57 * and the return value is the quotient (not the remainder).
58 */
59u64 do_div_round_closest(u64 dividend, unsigned long divisor)
60{
61 u64 result;
62
63 result = dividend + ((u64)divisor >> 1);
64 (void)do_div(result, divisor);
65
66 return result;
67}
68
69/* Convert a divider into the scaled divisor value it represents. */ 55/* Convert a divider into the scaled divisor value it represents. */
70static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) 56static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div)
71{ 57{
@@ -87,7 +73,7 @@ u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, u32 billionths)
87 combined = (u64)div_value * BILLION + billionths; 73 combined = (u64)div_value * BILLION + billionths;
88 combined <<= div->u.s.frac_width; 74 combined <<= div->u.s.frac_width;
89 75
90 return do_div_round_closest(combined, BILLION); 76 return DIV_ROUND_CLOSEST_ULL(combined, BILLION);
91} 77}
92 78
93/* The scaled minimum divisor representable by a divider */ 79/* The scaled minimum divisor representable by a divider */
@@ -731,7 +717,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu,
731 scaled_rate = scale_rate(pre_div, parent_rate); 717 scaled_rate = scale_rate(pre_div, parent_rate);
732 scaled_rate = scale_rate(div, scaled_rate); 718 scaled_rate = scale_rate(div, scaled_rate);
733 scaled_div = divider_read_scaled(ccu, pre_div); 719 scaled_div = divider_read_scaled(ccu, pre_div);
734 scaled_parent_rate = do_div_round_closest(scaled_rate, 720 scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate,
735 scaled_div); 721 scaled_div);
736 } else { 722 } else {
737 scaled_parent_rate = scale_rate(div, parent_rate); 723 scaled_parent_rate = scale_rate(div, parent_rate);
@@ -743,7 +729,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu,
743 * rate. 729 * rate.
744 */ 730 */
745 scaled_div = divider_read_scaled(ccu, div); 731 scaled_div = divider_read_scaled(ccu, div);
746 result = do_div_round_closest(scaled_parent_rate, scaled_div); 732 result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, scaled_div);
747 733
748 return (unsigned long)result; 734 return (unsigned long)result;
749} 735}
@@ -790,7 +776,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
790 scaled_rate = scale_rate(pre_div, parent_rate); 776 scaled_rate = scale_rate(pre_div, parent_rate);
791 scaled_rate = scale_rate(div, scaled_rate); 777 scaled_rate = scale_rate(div, scaled_rate);
792 scaled_pre_div = divider_read_scaled(ccu, pre_div); 778 scaled_pre_div = divider_read_scaled(ccu, pre_div);
793 scaled_parent_rate = do_div_round_closest(scaled_rate, 779 scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate,
794 scaled_pre_div); 780 scaled_pre_div);
795 } else { 781 } else {
796 scaled_parent_rate = scale_rate(div, parent_rate); 782 scaled_parent_rate = scale_rate(div, parent_rate);
@@ -802,7 +788,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
802 * the best we can do. 788 * the best we can do.
803 */ 789 */
804 if (!divider_is_fixed(div)) { 790 if (!divider_is_fixed(div)) {
805 best_scaled_div = do_div_round_closest(scaled_parent_rate, 791 best_scaled_div = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate,
806 rate); 792 rate);
807 min_scaled_div = scaled_div_min(div); 793 min_scaled_div = scaled_div_min(div);
808 max_scaled_div = scaled_div_max(div); 794 max_scaled_div = scaled_div_max(div);
@@ -815,7 +801,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
815 } 801 }
816 802
817 /* OK, figure out the resulting rate */ 803 /* OK, figure out the resulting rate */
818 result = do_div_round_closest(scaled_parent_rate, best_scaled_div); 804 result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, best_scaled_div);
819 805
820 if (scaled_div) 806 if (scaled_div)
821 *scaled_div = best_scaled_div; 807 *scaled_div = best_scaled_div;
diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h
index 2537b3072910..6849a64baf6d 100644
--- a/drivers/clk/bcm/clk-kona.h
+++ b/drivers/clk/bcm/clk-kona.h
@@ -503,7 +503,6 @@ extern struct clk_ops kona_peri_clk_ops;
503 503
504/* Externally visible functions */ 504/* Externally visible functions */
505 505
506extern u64 do_div_round_closest(u64 dividend, unsigned long divisor);
507extern u64 scaled_div_max(struct bcm_clk_div *div); 506extern u64 scaled_div_max(struct bcm_clk_div *div);
508extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, 507extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value,
509 u32 billionths); 508 u32 billionths);
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 40580794e23d..b8a5fa15ca24 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -190,12 +190,6 @@ static DEFINE_PER_CPU(struct menu_device, menu_devices);
190 190
191static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev); 191static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
192 192
193/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */
194static u64 div_round64(u64 dividend, u32 divisor)
195{
196 return div_u64(dividend + (divisor / 2), divisor);
197}
198
199/* 193/*
200 * Try detecting repeating patterns by keeping track of the last 8 194 * Try detecting repeating patterns by keeping track of the last 8
201 * intervals, and checking if the standard deviation of that set 195 * intervals, and checking if the standard deviation of that set
@@ -317,7 +311,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
317 * operands are 32 bits. 311 * operands are 32 bits.
318 * Make sure to round up for half microseconds. 312 * Make sure to round up for half microseconds.
319 */ 313 */
320 data->predicted_us = div_round64((uint64_t)data->next_timer_us * 314 data->predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us *
321 data->correction_factor[data->bucket], 315 data->correction_factor[data->bucket],
322 RESOLUTION * DECAY); 316 RESOLUTION * DECAY);
323 317
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index eef79ccd0b7c..ba243db35840 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -36,9 +36,6 @@
36#include <drm/drm_dp_mst_helper.h> 36#include <drm/drm_dp_mst_helper.h>
37#include <drm/drm_rect.h> 37#include <drm/drm_rect.h>
38 38
39#define DIV_ROUND_CLOSEST_ULL(ll, d) \
40({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
41
42/** 39/**
43 * _wait_for - magic (register) wait macro 40 * _wait_for - magic (register) wait macro
44 * 41 *
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index d8686ce89160..08532d4ffe0a 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -30,6 +30,7 @@
30 30
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 32
33#include <linux/kernel.h>
33#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
34#include "intel_drv.h" 35#include "intel_drv.h"
35 36
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index d1542b7d4bc3..4d2815079fc2 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -36,6 +36,7 @@
36#include <linux/jiffies.h> 36#include <linux/jiffies.h>
37#include <linux/of.h> 37#include <linux/of.h>
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/util_macros.h>
39 40
40#include <linux/platform_data/ina2xx.h> 41#include <linux/platform_data/ina2xx.h>
41 42
@@ -141,19 +142,6 @@ static const struct ina2xx_config ina2xx_config[] = {
141 */ 142 */
142static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 }; 143static const int ina226_avg_tab[] = { 1, 4, 16, 64, 128, 256, 512, 1024 };
143 144
144static int ina226_avg_bits(int avg)
145{
146 int i;
147
148 /* Get the closest average from the tab. */
149 for (i = 0; i < ARRAY_SIZE(ina226_avg_tab) - 1; i++) {
150 if (avg <= (ina226_avg_tab[i] + ina226_avg_tab[i + 1]) / 2)
151 break;
152 }
153
154 return i; /* Return 0b0111 for values greater than 1024. */
155}
156
157static int ina226_reg_to_interval(u16 config) 145static int ina226_reg_to_interval(u16 config)
158{ 146{
159 int avg = ina226_avg_tab[INA226_READ_AVG(config)]; 147 int avg = ina226_avg_tab[INA226_READ_AVG(config)];
@@ -171,7 +159,8 @@ static u16 ina226_interval_to_reg(int interval, u16 config)
171 159
172 avg = DIV_ROUND_CLOSEST(interval * 1000, 160 avg = DIV_ROUND_CLOSEST(interval * 1000,
173 INA226_TOTAL_CONV_TIME_DEFAULT); 161 INA226_TOTAL_CONV_TIME_DEFAULT);
174 avg_bits = ina226_avg_bits(avg); 162 avg_bits = find_closest(avg, ina226_avg_tab,
163 ARRAY_SIZE(ina226_avg_tab));
175 164
176 return (config & ~INA226_AVG_RD_MASK) | INA226_SHIFT_AVG(avg_bits); 165 return (config & ~INA226_AVG_RD_MASK) | INA226_SHIFT_AVG(avg_bits);
177} 166}
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 2b4b419273fe..6ff773fcaefb 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon-sysfs.h> 34#include <linux/hwmon-sysfs.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/util_macros.h>
37 38
38/* Addresses to scan */ 39/* Addresses to scan */
39static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 40static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
@@ -190,15 +191,7 @@ static const int lm85_range_map[] = {
190 191
191static int RANGE_TO_REG(long range) 192static int RANGE_TO_REG(long range)
192{ 193{
193 int i; 194 return find_closest(range, lm85_range_map, ARRAY_SIZE(lm85_range_map));
194
195 /* Find the closest match */
196 for (i = 0; i < 15; ++i) {
197 if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
198 break;
199 }
200
201 return i;
202} 195}
203#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 196#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
204 197
@@ -209,16 +202,12 @@ static const int lm85_freq_map[8] = { /* 1 Hz */
209static const int adm1027_freq_map[8] = { /* 1 Hz */ 202static const int adm1027_freq_map[8] = { /* 1 Hz */
210 11, 15, 22, 29, 35, 44, 59, 88 203 11, 15, 22, 29, 35, 44, 59, 88
211}; 204};
205#define FREQ_MAP_LEN 8
212 206
213static int FREQ_TO_REG(const int *map, unsigned long freq) 207static int FREQ_TO_REG(const int *map,
208 unsigned int map_size, unsigned long freq)
214{ 209{
215 int i; 210 return find_closest(freq, map, map_size);
216
217 /* Find the closest match */
218 for (i = 0; i < 7; ++i)
219 if (freq <= (map[i] + map[i + 1]) / 2)
220 break;
221 return i;
222} 211}
223 212
224static int FREQ_FROM_REG(const int *map, u8 reg) 213static int FREQ_FROM_REG(const int *map, u8 reg)
@@ -828,7 +817,8 @@ static ssize_t set_pwm_freq(struct device *dev,
828 data->cfg5 &= ~ADT7468_HFPWM; 817 data->cfg5 &= ~ADT7468_HFPWM;
829 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); 818 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
830 } else { /* Low freq. mode */ 819 } else { /* Low freq. mode */
831 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); 820 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map,
821 FREQ_MAP_LEN, val);
832 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 822 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
833 (data->zone[nr].range << 4) 823 (data->zone[nr].range << 4)
834 | data->pwm_freq[nr]); 824 | data->pwm_freq[nr]);
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 21894131190f..49276bbdac3d 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -35,6 +35,7 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/util_macros.h>
38 39
39/* Addresses to scan */ 40/* Addresses to scan */
40static const unsigned short normal_i2c[] = { 41static const unsigned short normal_i2c[] = {
@@ -308,11 +309,8 @@ static u8 pwm_freq_to_reg(unsigned long val, u16 clkin)
308 unsigned long best0, best1; 309 unsigned long best0, best1;
309 310
310 /* Best fit for cksel = 0 */ 311 /* Best fit for cksel = 0 */
311 for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { 312 reg0 = find_closest_descending(val, pwm_freq_cksel0,
312 if (val > (pwm_freq_cksel0[reg0] + 313 ARRAY_SIZE(pwm_freq_cksel0));
313 pwm_freq_cksel0[reg0 + 1]) / 2)
314 break;
315 }
316 if (val < 375) /* cksel = 1 can't beat this */ 314 if (val < 375) /* cksel = 1 can't beat this */
317 return reg0; 315 return reg0;
318 best0 = pwm_freq_cksel0[reg0]; 316 best0 = pwm_freq_cksel0[reg0];
diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c b/drivers/media/dvb-frontends/cxd2820r_c.c
index 149fdca3fb44..72b0e2db3aab 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -79,7 +79,7 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
79 79
80 num = if_freq / 1000; /* Hz => kHz */ 80 num = if_freq / 1000; /* Hz => kHz */
81 num *= 0x4000; 81 num *= 0x4000;
82 if_ctl = 0x4000 - cxd2820r_div_u64_round_closest(num, 41000); 82 if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000);
83 buf[0] = (if_ctl >> 8) & 0x3f; 83 buf[0] = (if_ctl >> 8) & 0x3f;
84 buf[1] = (if_ctl >> 0) & 0xff; 84 buf[1] = (if_ctl >> 0) & 0xff;
85 85
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
index 422e84bbb008..490e090048ef 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -244,12 +244,6 @@ error:
244 return ret; 244 return ret;
245} 245}
246 246
247/* 64 bit div with round closest, like DIV_ROUND_CLOSEST but 64 bit */
248u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor)
249{
250 return div_u64(dividend + (divisor / 2), divisor);
251}
252
253static int cxd2820r_set_frontend(struct dvb_frontend *fe) 247static int cxd2820r_set_frontend(struct dvb_frontend *fe)
254{ 248{
255 struct cxd2820r_priv *priv = fe->demodulator_priv; 249 struct cxd2820r_priv *priv = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h b/drivers/media/dvb-frontends/cxd2820r_priv.h
index 7ff5f60c83e1..4b428959b16e 100644
--- a/drivers/media/dvb-frontends/cxd2820r_priv.h
+++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
@@ -64,8 +64,6 @@ int cxd2820r_wr_reg_mask(struct cxd2820r_priv *priv, u32 reg, u8 val,
64int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 64int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
65 int len); 65 int len);
66 66
67u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor);
68
69int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, 67int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
70 int len); 68 int len);
71 69
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c b/drivers/media/dvb-frontends/cxd2820r_t.c
index 51401d036530..008cb2ac8480 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
@@ -103,7 +103,7 @@ int cxd2820r_set_frontend_t(struct dvb_frontend *fe)
103 103
104 num = if_freq / 1000; /* Hz => kHz */ 104 num = if_freq / 1000; /* Hz => kHz */
105 num *= 0x1000000; 105 num *= 0x1000000;
106 if_ctl = cxd2820r_div_u64_round_closest(num, 41000); 106 if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
107 buf[0] = ((if_ctl >> 16) & 0xff); 107 buf[0] = ((if_ctl >> 16) & 0xff);
108 buf[1] = ((if_ctl >> 8) & 0xff); 108 buf[1] = ((if_ctl >> 8) & 0xff);
109 buf[2] = ((if_ctl >> 0) & 0xff); 109 buf[2] = ((if_ctl >> 0) & 0xff);
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c b/drivers/media/dvb-frontends/cxd2820r_t2.c
index 9c0c4f42175c..35fe364c7182 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ -120,7 +120,7 @@ int cxd2820r_set_frontend_t2(struct dvb_frontend *fe)
120 120
121 num = if_freq / 1000; /* Hz => kHz */ 121 num = if_freq / 1000; /* Hz => kHz */
122 num *= 0x1000000; 122 num *= 0x1000000;
123 if_ctl = cxd2820r_div_u64_round_closest(num, 41000); 123 if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
124 buf[0] = ((if_ctl >> 16) & 0xff); 124 buf[0] = ((if_ctl >> 16) & 0xff);
125 buf[1] = ((if_ctl >> 8) & 0xff); 125 buf[1] = ((if_ctl >> 8) & 0xff);
126 buf[2] = ((if_ctl >> 0) & 0xff); 126 buf[2] = ((if_ctl >> 0) & 0xff);
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index fc145d202c46..922a750640e8 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -758,7 +758,7 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error)
758 758
759 if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) { 759 if (error || (card->current_mrq.tpc == MSPRO_CMD_STOP)) {
760 if (msb->data_dir == READ) { 760 if (msb->data_dir == READ) {
761 for (cnt = 0; cnt < msb->current_seg; cnt++) 761 for (cnt = 0; cnt < msb->current_seg; cnt++) {
762 t_len += msb->req_sg[cnt].length 762 t_len += msb->req_sg[cnt].length
763 / msb->page_size; 763 / msb->page_size;
764 764
@@ -766,6 +766,7 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error)
766 t_len += msb->current_page - 1; 766 t_len += msb->current_page - 1;
767 767
768 t_len *= msb->page_size; 768 t_len *= msb->page_size;
769 }
769 } 770 }
770 } else 771 } else
771 t_len = blk_rq_bytes(msb->block_req); 772 t_len = blk_rq_bytes(msb->block_req);
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index d93b2b6b1f7a..82f7000a285d 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -21,6 +21,7 @@
21 * objects. 21 * objects.
22 */ 22 */
23 23
24#include <linux/file.h>
24#include <linux/mm.h> 25#include <linux/mm.h>
25#include <linux/workqueue.h> 26#include <linux/workqueue.h>
26#include <linux/notifier.h> 27#include <linux/notifier.h>
@@ -224,10 +225,18 @@ static inline unsigned long fast_get_dcookie(struct path *path)
224static unsigned long get_exec_dcookie(struct mm_struct *mm) 225static unsigned long get_exec_dcookie(struct mm_struct *mm)
225{ 226{
226 unsigned long cookie = NO_COOKIE; 227 unsigned long cookie = NO_COOKIE;
228 struct file *exe_file;
227 229
228 if (mm && mm->exe_file) 230 if (!mm)
229 cookie = fast_get_dcookie(&mm->exe_file->f_path); 231 goto done;
232
233 exe_file = get_mm_exe_file(mm);
234 if (!exe_file)
235 goto done;
230 236
237 cookie = fast_get_dcookie(&exe_file->f_path);
238 fput(exe_file);
239done:
231 return cookie; 240 return cookie;
232} 241}
233 242
@@ -236,6 +245,8 @@ static unsigned long get_exec_dcookie(struct mm_struct *mm)
236 * pair that can then be added to the global event buffer. We make 245 * pair that can then be added to the global event buffer. We make
237 * sure to do this lookup before a mm->mmap modification happens so 246 * sure to do this lookup before a mm->mmap modification happens so
238 * we don't lose track. 247 * we don't lose track.
248 *
249 * The caller must ensure the mm is not nil (ie: not a kernel thread).
239 */ 250 */
240static unsigned long 251static unsigned long
241lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset) 252lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset)
@@ -243,6 +254,7 @@ lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset)
243 unsigned long cookie = NO_COOKIE; 254 unsigned long cookie = NO_COOKIE;
244 struct vm_area_struct *vma; 255 struct vm_area_struct *vma;
245 256
257 down_read(&mm->mmap_sem);
246 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { 258 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) {
247 259
248 if (addr < vma->vm_start || addr >= vma->vm_end) 260 if (addr < vma->vm_start || addr >= vma->vm_end)
@@ -262,6 +274,7 @@ lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset)
262 274
263 if (!vma) 275 if (!vma)
264 cookie = INVALID_COOKIE; 276 cookie = INVALID_COOKIE;
277 up_read(&mm->mmap_sem);
265 278
266 return cookie; 279 return cookie;
267} 280}
@@ -402,20 +415,9 @@ static void release_mm(struct mm_struct *mm)
402{ 415{
403 if (!mm) 416 if (!mm)
404 return; 417 return;
405 up_read(&mm->mmap_sem);
406 mmput(mm); 418 mmput(mm);
407} 419}
408 420
409
410static struct mm_struct *take_tasks_mm(struct task_struct *task)
411{
412 struct mm_struct *mm = get_task_mm(task);
413 if (mm)
414 down_read(&mm->mmap_sem);
415 return mm;
416}
417
418
419static inline int is_code(unsigned long val) 421static inline int is_code(unsigned long val)
420{ 422{
421 return val == ESCAPE_CODE; 423 return val == ESCAPE_CODE;
@@ -532,7 +534,7 @@ void sync_buffer(int cpu)
532 new = (struct task_struct *)val; 534 new = (struct task_struct *)val;
533 oldmm = mm; 535 oldmm = mm;
534 release_mm(oldmm); 536 release_mm(oldmm);
535 mm = take_tasks_mm(new); 537 mm = get_task_mm(new);
536 if (mm != oldmm) 538 if (mm != oldmm)
537 cookie = get_exec_dcookie(mm); 539 cookie = get_exec_dcookie(mm);
538 add_user_ctx_switch(new, cookie); 540 add_user_ctx_switch(new, cookie);
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b5b5c3d485d6..6149ae01e11f 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
1114config 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
1114config RTC_DRV_IMXDI 1124config 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
@@ -1121,11 +1131,11 @@ config RTC_DRV_IMXDI
1121 will be called "rtc-imxdi". 1131 will be called "rtc-imxdi".
1122 1132
1123config RTC_DRV_OMAP 1133config RTC_DRV_OMAP
1124 tristate "TI OMAP1" 1134 tristate "TI OMAP Real Time Clock"
1125 depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX || SOC_AM33XX 1135 depends on ARCH_OMAP || ARCH_DAVINCI
1126 help 1136 help
1127 Say "yes" here to support the on chip real time clock 1137 Say "yes" here to support the on chip real time clock
1128 present on TI OMAP1, AM33xx and DA8xx/OMAP-L13x. 1138 present on TI OMAP1, AM33xx, DA8xx/OMAP-L13x, AM43xx and DRA7xx.
1129 1139
1130 This driver can also be built as a module, if so, module 1140 This driver can also be built as a module, if so, module
1131 will be called rtc-omap. 1141 will be called rtc-omap.
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
40obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o 40obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o
41obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o 41obj-$(CONFIG_RTC_DRV_DA9063) += rtc-da9063.o
42obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o 42obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o
43obj-$(CONFIG_RTC_DRV_DIGICOLOR) += rtc-digicolor.o
43obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o 44obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o
44obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 45obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o
45obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o 46obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index c29ba7e14304..ea2a315df6b7 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -221,15 +221,15 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
221 rtc->pie_timer.function = rtc_pie_update_irq; 221 rtc->pie_timer.function = rtc_pie_update_irq;
222 rtc->pie_enabled = 0; 222 rtc->pie_enabled = 0;
223 223
224 strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
225 dev_set_name(&rtc->dev, "rtc%d", id);
226
224 /* Check to see if there is an ALARM already set in hw */ 227 /* Check to see if there is an ALARM already set in hw */
225 err = __rtc_read_alarm(rtc, &alrm); 228 err = __rtc_read_alarm(rtc, &alrm);
226 229
227 if (!err && !rtc_valid_tm(&alrm.time)) 230 if (!err && !rtc_valid_tm(&alrm.time))
228 rtc_initialize_alarm(rtc, &alrm); 231 rtc_initialize_alarm(rtc, &alrm);
229 232
230 strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
231 dev_set_name(&rtc->dev, "rtc%d", id);
232
233 rtc_dev_prepare(rtc); 233 rtc_dev_prepare(rtc);
234 234
235 err = device_register(&rtc->dev); 235 err = device_register(&rtc->dev);
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index 6c719f23520a..e1cfa06810ef 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -9,6 +9,8 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10*/ 10*/
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
12#include <linux/rtc.h> 14#include <linux/rtc.h>
13 15
14/* IMPORTANT: the RTC only stores whole seconds. It is arbitrary 16/* IMPORTANT: the RTC only stores whole seconds. It is arbitrary
@@ -32,8 +34,8 @@ static int __init rtc_hctosys(void)
32 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 34 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
33 35
34 if (rtc == NULL) { 36 if (rtc == NULL) {
35 pr_err("%s: unable to open rtc device (%s)\n", 37 pr_info("unable to open rtc device (%s)\n",
36 __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); 38 CONFIG_RTC_HCTOSYS_DEVICE);
37 goto err_open; 39 goto err_open;
38 } 40 }
39 41
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index d43ee409a5f2..166fc60d8b55 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -31,13 +31,14 @@ static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
31 memset(tm, 0, sizeof(struct rtc_time)); 31 memset(tm, 0, sizeof(struct rtc_time));
32 err = rtc->ops->read_time(rtc->dev.parent, tm); 32 err = rtc->ops->read_time(rtc->dev.parent, tm);
33 if (err < 0) { 33 if (err < 0) {
34 dev_err(&rtc->dev, "read_time: fail to read\n"); 34 dev_dbg(&rtc->dev, "read_time: fail to read: %d\n",
35 err);
35 return err; 36 return err;
36 } 37 }
37 38
38 err = rtc_valid_tm(tm); 39 err = rtc_valid_tm(tm);
39 if (err < 0) 40 if (err < 0)
40 dev_err(&rtc->dev, "read_time: rtc_time isn't valid\n"); 41 dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n");
41 } 42 }
42 return err; 43 return err;
43} 44}
diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c
index cfc2ef98d393..b5cbc1bf5a3e 100644
--- a/drivers/rtc/rtc-ab-b5ze-s3.c
+++ b/drivers/rtc/rtc-ab-b5ze-s3.c
@@ -881,7 +881,7 @@ static const struct rtc_class_ops rtc_ops = {
881 .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable, 881 .alarm_irq_enable = abb5zes3_rtc_alarm_irq_enable,
882}; 882};
883 883
884static struct regmap_config abb5zes3_rtc_regmap_config = { 884static const struct regmap_config abb5zes3_rtc_regmap_config = {
885 .reg_bits = 8, 885 .reg_bits = 8,
886 .val_bits = 8, 886 .val_bits = 8,
887}; 887};
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index b283a1a573b3..35efd3f75b18 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -37,9 +37,9 @@
37#include "rtc-at91rm9200.h" 37#include "rtc-at91rm9200.h"
38 38
39#define at91_rtc_read(field) \ 39#define at91_rtc_read(field) \
40 __raw_readl(at91_rtc_regs + field) 40 readl_relaxed(at91_rtc_regs + field)
41#define at91_rtc_write(field, val) \ 41#define at91_rtc_write(field, val) \
42 __raw_writel((val), at91_rtc_regs + field) 42 writel_relaxed((val), at91_rtc_regs + field)
43 43
44#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 44#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */
45 45
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 87647f459198..a82556a0757a 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -28,6 +28,9 @@
28 * interrupts disabled, holding the global rtc_lock, to exclude those 28 * interrupts disabled, holding the global rtc_lock, to exclude those
29 * other drivers and utilities on correctly configured systems. 29 * other drivers and utilities on correctly configured systems.
30 */ 30 */
31
32#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
31#include <linux/kernel.h> 34#include <linux/kernel.h>
32#include <linux/module.h> 35#include <linux/module.h>
33#include <linux/init.h> 36#include <linux/init.h>
@@ -385,8 +388,7 @@ static bool alarm_disable_quirk;
385static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) 388static int __init set_alarm_disable_quirk(const struct dmi_system_id *id)
386{ 389{
387 alarm_disable_quirk = true; 390 alarm_disable_quirk = true;
388 pr_info("rtc-cmos: BIOS has alarm-disable quirk. "); 391 pr_info("BIOS has alarm-disable quirk - RTC alarms disabled\n");
389 pr_info("RTC alarms disabled\n");
390 return 0; 392 return 0;
391} 393}
392 394
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 613c43b7e9ae..1ba4371cbc2d 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/rtc.h> 17#include <linux/rtc.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/delay.h>
19 20
20#include <linux/mfd/da9052/da9052.h> 21#include <linux/mfd/da9052/da9052.h>
21#include <linux/mfd/da9052/reg.h> 22#include <linux/mfd/da9052/reg.h>
@@ -23,6 +24,8 @@
23#define rtc_err(rtc, fmt, ...) \ 24#define rtc_err(rtc, fmt, ...) \
24 dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) 25 dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__)
25 26
27#define DA9052_GET_TIME_RETRIES 5
28
26struct da9052_rtc { 29struct da9052_rtc {
27 struct rtc_device *rtc; 30 struct rtc_device *rtc;
28 struct da9052 *da9052; 31 struct da9052 *da9052;
@@ -58,22 +61,43 @@ static irqreturn_t da9052_rtc_irq(int irq, void *data)
58static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) 61static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm)
59{ 62{
60 int ret; 63 int ret;
61 uint8_t v[5]; 64 uint8_t v[2][5];
65 int idx = 1;
66 int timeout = DA9052_GET_TIME_RETRIES;
62 67
63 ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, v); 68 ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, &v[0][0]);
64 if (ret != 0) { 69 if (ret) {
65 rtc_err(rtc, "Failed to group read ALM: %d\n", ret); 70 rtc_err(rtc, "Failed to group read ALM: %d\n", ret);
66 return ret; 71 return ret;
67 } 72 }
68 73
69 rtc_tm->tm_year = (v[4] & DA9052_RTC_YEAR) + 100; 74 do {
70 rtc_tm->tm_mon = (v[3] & DA9052_RTC_MONTH) - 1; 75 ret = da9052_group_read(rtc->da9052,
71 rtc_tm->tm_mday = v[2] & DA9052_RTC_DAY; 76 DA9052_ALARM_MI_REG, 5, &v[idx][0]);
72 rtc_tm->tm_hour = v[1] & DA9052_RTC_HOUR; 77 if (ret) {
73 rtc_tm->tm_min = v[0] & DA9052_RTC_MIN; 78 rtc_err(rtc, "Failed to group read ALM: %d\n", ret);
79 return ret;
80 }
74 81
75 ret = rtc_valid_tm(rtc_tm); 82 if (memcmp(&v[0][0], &v[1][0], 5) == 0) {
76 return ret; 83 rtc_tm->tm_year = (v[0][4] & DA9052_RTC_YEAR) + 100;
84 rtc_tm->tm_mon = (v[0][3] & DA9052_RTC_MONTH) - 1;
85 rtc_tm->tm_mday = v[0][2] & DA9052_RTC_DAY;
86 rtc_tm->tm_hour = v[0][1] & DA9052_RTC_HOUR;
87 rtc_tm->tm_min = v[0][0] & DA9052_RTC_MIN;
88
89 ret = rtc_valid_tm(rtc_tm);
90 return ret;
91 }
92
93 idx = (1-idx);
94 msleep(20);
95
96 } while (timeout--);
97
98 rtc_err(rtc, "Timed out reading alarm time\n");
99
100 return -EIO;
77} 101}
78 102
79static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) 103static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm)
@@ -135,24 +159,45 @@ static int da9052_rtc_get_alarm_status(struct da9052_rtc *rtc)
135static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) 159static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
136{ 160{
137 struct da9052_rtc *rtc = dev_get_drvdata(dev); 161 struct da9052_rtc *rtc = dev_get_drvdata(dev);
138 uint8_t v[6];
139 int ret; 162 int ret;
163 uint8_t v[2][6];
164 int idx = 1;
165 int timeout = DA9052_GET_TIME_RETRIES;
140 166
141 ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, v); 167 ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, &v[0][0]);
142 if (ret < 0) { 168 if (ret) {
143 rtc_err(rtc, "Failed to read RTC time : %d\n", ret); 169 rtc_err(rtc, "Failed to read RTC time : %d\n", ret);
144 return ret; 170 return ret;
145 } 171 }
146 172
147 rtc_tm->tm_year = (v[5] & DA9052_RTC_YEAR) + 100; 173 do {
148 rtc_tm->tm_mon = (v[4] & DA9052_RTC_MONTH) - 1; 174 ret = da9052_group_read(rtc->da9052,
149 rtc_tm->tm_mday = v[3] & DA9052_RTC_DAY; 175 DA9052_COUNT_S_REG, 6, &v[idx][0]);
150 rtc_tm->tm_hour = v[2] & DA9052_RTC_HOUR; 176 if (ret) {
151 rtc_tm->tm_min = v[1] & DA9052_RTC_MIN; 177 rtc_err(rtc, "Failed to read RTC time : %d\n", ret);
152 rtc_tm->tm_sec = v[0] & DA9052_RTC_SEC; 178 return ret;
179 }
153 180
154 ret = rtc_valid_tm(rtc_tm); 181 if (memcmp(&v[0][0], &v[1][0], 6) == 0) {
155 return ret; 182 rtc_tm->tm_year = (v[0][5] & DA9052_RTC_YEAR) + 100;
183 rtc_tm->tm_mon = (v[0][4] & DA9052_RTC_MONTH) - 1;
184 rtc_tm->tm_mday = v[0][3] & DA9052_RTC_DAY;
185 rtc_tm->tm_hour = v[0][2] & DA9052_RTC_HOUR;
186 rtc_tm->tm_min = v[0][1] & DA9052_RTC_MIN;
187 rtc_tm->tm_sec = v[0][0] & DA9052_RTC_SEC;
188
189 ret = rtc_valid_tm(rtc_tm);
190 return ret;
191 }
192
193 idx = (1-idx);
194 msleep(20);
195
196 } while (timeout--);
197
198 rtc_err(rtc, "Timed out reading time\n");
199
200 return -EIO;
156} 201}
157 202
158static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) 203static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -161,6 +206,10 @@ static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm)
161 uint8_t v[6]; 206 uint8_t v[6];
162 int ret; 207 int ret;
163 208
209 /* DA9052 only has 6 bits for year - to represent 2000-2063 */
210 if ((tm->tm_year < 100) || (tm->tm_year > 163))
211 return -EINVAL;
212
164 rtc = dev_get_drvdata(dev); 213 rtc = dev_get_drvdata(dev);
165 214
166 v[0] = tm->tm_sec; 215 v[0] = tm->tm_sec;
@@ -198,6 +247,10 @@ static int da9052_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
198 struct rtc_time *tm = &alrm->time; 247 struct rtc_time *tm = &alrm->time;
199 struct da9052_rtc *rtc = dev_get_drvdata(dev); 248 struct da9052_rtc *rtc = dev_get_drvdata(dev);
200 249
250 /* DA9052 only has 6 bits for year - to represent 2000-2063 */
251 if ((tm->tm_year < 100) || (tm->tm_year > 163))
252 return -EINVAL;
253
201 ret = da9052_rtc_enable_alarm(rtc, 0); 254 ret = da9052_rtc_enable_alarm(rtc, 0);
202 if (ret < 0) 255 if (ret < 0)
203 return ret; 256 return ret;
@@ -256,6 +309,8 @@ static int da9052_rtc_probe(struct platform_device *pdev)
256 return ret; 309 return ret;
257 } 310 }
258 311
312 device_init_wakeup(&pdev->dev, true);
313
259 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 314 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
260 &da9052_rtc_ops, THIS_MODULE); 315 &da9052_rtc_ops, THIS_MODULE);
261 return PTR_ERR_OR_ZERO(rtc->rtc); 316 return PTR_ERR_OR_ZERO(rtc->rtc);
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
40struct dc_rtc {
41 struct rtc_device *rtc_dev;
42 void __iomem *regs;
43};
44
45static 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
63static 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
87static 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
95static 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
109static 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
116static 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
137static 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
153static 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;
160}
161
162static struct rtc_class_ops dc_rtc_ops = {
163 .read_time = dc_rtc_read_time,
164 .set_mmss = dc_rtc_set_mmss,
165 .read_alarm = dc_rtc_read_alarm,
166 .set_alarm = dc_rtc_set_alarm,
167 .alarm_irq_enable = dc_rtc_alarm_irq_enable,
168};
169
170static irqreturn_t dc_rtc_irq(int irq, void *dev_id)
171{
172 struct dc_rtc *rtc = dev_id;
173
174 writeb_relaxed(1, rtc->regs + DC_RTC_INTFLAG_CLEAR);
175 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
176
177 return IRQ_HANDLED;
178}
179
180static int __init dc_rtc_probe(struct platform_device *pdev)
181{
182 struct resource *res;
183 struct dc_rtc *rtc;
184 int irq, ret;
185
186 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
187 if (!rtc)
188 return -ENOMEM;
189
190 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
191 rtc->regs = devm_ioremap_resource(&pdev->dev, res);
192 if (IS_ERR(rtc->regs))
193 return PTR_ERR(rtc->regs);
194
195 irq = platform_get_irq(pdev, 0);
196 if (irq < 0)
197 return irq;
198 ret = devm_request_irq(&pdev->dev, irq, dc_rtc_irq, 0, pdev->name, rtc);
199 if (ret < 0)
200 return ret;
201
202 platform_set_drvdata(pdev, rtc);
203 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
204 &dc_rtc_ops, THIS_MODULE);
205 if (IS_ERR(rtc->rtc_dev))
206 return PTR_ERR(rtc->rtc_dev);
207
208 return 0;
209}
210
211static const struct of_device_id dc_dt_ids[] = {
212 { .compatible = "cnxt,cx92755-rtc" },
213 { /* sentinel */ }
214};
215MODULE_DEVICE_TABLE(of, dc_dt_ids);
216
217static struct platform_driver dc_rtc_driver = {
218 .driver = {
219 .name = "digicolor_rtc",
220 .of_match_table = of_match_ptr(dc_dt_ids),
221 },
222};
223module_platform_driver_probe(dc_rtc_driver, dc_rtc_probe);
224
225MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
226MODULE_DESCRIPTION("Conexant Digicolor Realtime Clock Driver (RTC)");
227MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 8605fde394b2..167783fa7ac1 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -18,6 +18,8 @@
18 * "Sending and receiving", using SMBus level communication is preferred. 18 * "Sending and receiving", using SMBus level communication is preferred.
19 */ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/kernel.h> 23#include <linux/kernel.h>
22#include <linux/module.h> 24#include <linux/module.h>
23#include <linux/interrupt.h> 25#include <linux/interrupt.h>
@@ -406,7 +408,7 @@ static int ds1374_wdt_settimeout(unsigned int timeout)
406 /* Set new watchdog time */ 408 /* Set new watchdog time */
407 ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); 409 ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3);
408 if (ret) { 410 if (ret) {
409 pr_info("rtc-ds1374 - couldn't set new watchdog time\n"); 411 pr_info("couldn't set new watchdog time\n");
410 goto out; 412 goto out;
411 } 413 }
412 414
@@ -539,12 +541,12 @@ static long ds1374_wdt_ioctl(struct file *file, unsigned int cmd,
539 return -EFAULT; 541 return -EFAULT;
540 542
541 if (options & WDIOS_DISABLECARD) { 543 if (options & WDIOS_DISABLECARD) {
542 pr_info("rtc-ds1374: disable watchdog\n"); 544 pr_info("disable watchdog\n");
543 ds1374_wdt_disable(); 545 ds1374_wdt_disable();
544 } 546 }
545 547
546 if (options & WDIOS_ENABLECARD) { 548 if (options & WDIOS_ENABLECARD) {
547 pr_info("rtc-ds1374: enable watchdog\n"); 549 pr_info("enable watchdog\n");
548 ds1374_wdt_settimeout(wdt_margin); 550 ds1374_wdt_settimeout(wdt_margin);
549 ds1374_wdt_ping(); 551 ds1374_wdt_ping();
550 } 552 }
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 803869c7d7c2..818a3635a8c8 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -16,6 +16,8 @@
16 * published by the Free Software Foundation. 16 * published by the Free Software Foundation.
17 */ 17 */
18 18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
19#include <linux/bcd.h> 21#include <linux/bcd.h>
20#include <linux/delay.h> 22#include <linux/delay.h>
21#include <linux/io.h> 23#include <linux/io.h>
@@ -799,7 +801,7 @@ ds1685_rtc_proc(struct device *dev, struct seq_file *seq)
799 struct platform_device *pdev = to_platform_device(dev); 801 struct platform_device *pdev = to_platform_device(dev);
800 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 802 struct ds1685_priv *rtc = platform_get_drvdata(pdev);
801 u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; 803 u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8];
802 char *model = '\0'; 804 char *model;
803#ifdef CONFIG_RTC_DS1685_PROC_REGS 805#ifdef CONFIG_RTC_DS1685_PROC_REGS
804 char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; 806 char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1];
805#endif 807#endif
@@ -2139,7 +2141,6 @@ ds1685_rtc_remove(struct platform_device *pdev)
2139static struct platform_driver ds1685_rtc_driver = { 2141static struct platform_driver ds1685_rtc_driver = {
2140 .driver = { 2142 .driver = {
2141 .name = "rtc-ds1685", 2143 .name = "rtc-ds1685",
2142 .owner = THIS_MODULE,
2143 }, 2144 },
2144 .probe = ds1685_rtc_probe, 2145 .probe = ds1685_rtc_probe,
2145 .remove = ds1685_rtc_remove, 2146 .remove = ds1685_rtc_remove,
@@ -2175,7 +2176,7 @@ module_exit(ds1685_rtc_exit);
2175 * ds1685_rtc_poweroff - uses the RTC chip to power the system off. 2176 * ds1685_rtc_poweroff - uses the RTC chip to power the system off.
2176 * @pdev: pointer to platform_device structure. 2177 * @pdev: pointer to platform_device structure.
2177 */ 2178 */
2178extern void __noreturn 2179void __noreturn
2179ds1685_rtc_poweroff(struct platform_device *pdev) 2180ds1685_rtc_poweroff(struct platform_device *pdev)
2180{ 2181{
2181 u8 ctrla, ctrl4a, ctrl4b; 2182 u8 ctrla, ctrl4a, ctrl4b;
@@ -2183,7 +2184,7 @@ ds1685_rtc_poweroff(struct platform_device *pdev)
2183 2184
2184 /* Check for valid RTC data, else, spin forever. */ 2185 /* Check for valid RTC data, else, spin forever. */
2185 if (unlikely(!pdev)) { 2186 if (unlikely(!pdev)) {
2186 pr_emerg("rtc-ds1685: platform device data not available, spinning forever ...\n"); 2187 pr_emerg("platform device data not available, spinning forever ...\n");
2187 unreachable(); 2188 unreachable();
2188 } else { 2189 } else {
2189 /* Get the rtc data. */ 2190 /* Get the rtc data. */
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index adaf06c41479..7e48e532214f 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -15,6 +15,8 @@
15 * "Sending and receiving", using SMBus level communication is preferred. 15 * "Sending and receiving", using SMBus level communication is preferred.
16 */ 16 */
17 17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
18#include <linux/kernel.h> 20#include <linux/kernel.h>
19#include <linux/module.h> 21#include <linux/module.h>
20#include <linux/interrupt.h> 22#include <linux/interrupt.h>
@@ -373,8 +375,8 @@ static void ds3232_work(struct work_struct *work)
373 if (stat & DS3232_REG_SR_A1F) { 375 if (stat & DS3232_REG_SR_A1F) {
374 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 376 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
375 if (control < 0) { 377 if (control < 0) {
376 pr_warn("Read DS3232 Control Register error." 378 pr_warn("Read Control Register error - Disable IRQ%d\n",
377 "Disable IRQ%d.\n", client->irq); 379 client->irq);
378 } else { 380 } else {
379 /* disable alarm1 interrupt */ 381 /* disable alarm1 interrupt */
380 control &= ~(DS3232_REG_CR_A1IE); 382 control &= ~(DS3232_REG_CR_A1IE);
diff --git a/drivers/rtc/rtc-efi-platform.c b/drivers/rtc/rtc-efi-platform.c
index b40fbe332af4..1a7f1d1bc174 100644
--- a/drivers/rtc/rtc-efi-platform.c
+++ b/drivers/rtc/rtc-efi-platform.c
@@ -8,6 +8,9 @@
8 * Copyright (C) 1999-2000 VA Linux Systems 8 * Copyright (C) 1999-2000 VA Linux Systems
9 * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com> 9 * Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com>
10 */ 10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
11#include <linux/init.h> 14#include <linux/init.h>
12#include <linux/kernel.h> 15#include <linux/kernel.h>
13#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index fccf36699245..4f4930a2004c 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -15,6 +15,7 @@
15#include <linux/rtc.h> 15#include <linux/rtc.h>
16#include <linux/bcd.h> 16#include <linux/bcd.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of.h>
18 19
19/* Registers */ 20/* Registers */
20#define EM3027_REG_ON_OFF_CTRL 0x00 21#define EM3027_REG_ON_OFF_CTRL 0x00
@@ -135,10 +136,20 @@ static struct i2c_device_id em3027_id[] = {
135 { "em3027", 0 }, 136 { "em3027", 0 },
136 { } 137 { }
137}; 138};
139MODULE_DEVICE_TABLE(i2c, em3027_id);
140
141#ifdef CONFIG_OF
142static const struct of_device_id em3027_of_match[] = {
143 { .compatible = "emmicro,em3027", },
144 {}
145};
146MODULE_DEVICE_TABLE(of, em3027_of_match);
147#endif
138 148
139static struct i2c_driver em3027_driver = { 149static struct i2c_driver em3027_driver = {
140 .driver = { 150 .driver = {
141 .name = "rtc-em3027", 151 .name = "rtc-em3027",
152 .of_match_table = of_match_ptr(em3027_of_match),
142 }, 153 },
143 .probe = &em3027_probe, 154 .probe = &em3027_probe,
144 .id_table = em3027_id, 155 .id_table = em3027_id,
diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c
index b936bb4096b5..0f710e98538f 100644
--- a/drivers/rtc/rtc-hym8563.c
+++ b/drivers/rtc/rtc-hym8563.c
@@ -66,7 +66,7 @@
66#define HYM8563_ALM_BIT_DISABLE BIT(7) 66#define HYM8563_ALM_BIT_DISABLE BIT(7)
67 67
68#define HYM8563_CLKOUT 0x0d 68#define HYM8563_CLKOUT 0x0d
69#define HYM8563_CLKOUT_DISABLE BIT(7) 69#define HYM8563_CLKOUT_ENABLE BIT(7)
70#define HYM8563_CLKOUT_32768 0 70#define HYM8563_CLKOUT_32768 0
71#define HYM8563_CLKOUT_1024 1 71#define HYM8563_CLKOUT_1024 1
72#define HYM8563_CLKOUT_32 2 72#define HYM8563_CLKOUT_32 2
@@ -309,7 +309,7 @@ static unsigned long hym8563_clkout_recalc_rate(struct clk_hw *hw,
309 struct i2c_client *client = hym8563->client; 309 struct i2c_client *client = hym8563->client;
310 int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT); 310 int ret = i2c_smbus_read_byte_data(client, HYM8563_CLKOUT);
311 311
312 if (ret < 0 || ret & HYM8563_CLKOUT_DISABLE) 312 if (ret < 0)
313 return 0; 313 return 0;
314 314
315 ret &= HYM8563_CLKOUT_MASK; 315 ret &= HYM8563_CLKOUT_MASK;
@@ -360,9 +360,9 @@ static int hym8563_clkout_control(struct clk_hw *hw, bool enable)
360 return ret; 360 return ret;
361 361
362 if (enable) 362 if (enable)
363 ret &= ~HYM8563_CLKOUT_DISABLE; 363 ret |= HYM8563_CLKOUT_ENABLE;
364 else 364 else
365 ret |= HYM8563_CLKOUT_DISABLE; 365 ret &= ~HYM8563_CLKOUT_ENABLE;
366 366
367 return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret); 367 return i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, ret);
368} 368}
@@ -386,7 +386,7 @@ static int hym8563_clkout_is_prepared(struct clk_hw *hw)
386 if (ret < 0) 386 if (ret < 0)
387 return ret; 387 return ret;
388 388
389 return !(ret & HYM8563_CLKOUT_DISABLE); 389 return !!(ret & HYM8563_CLKOUT_ENABLE);
390} 390}
391 391
392static const struct clk_ops hym8563_clkout_ops = { 392static const struct clk_ops hym8563_clkout_ops = {
@@ -407,7 +407,7 @@ static struct clk *hym8563_clkout_register_clk(struct hym8563 *hym8563)
407 int ret; 407 int ret;
408 408
409 ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT, 409 ret = i2c_smbus_write_byte_data(client, HYM8563_CLKOUT,
410 HYM8563_CLKOUT_DISABLE); 410 0);
411 if (ret < 0) 411 if (ret < 0)
412 return ERR_PTR(ret); 412 return ERR_PTR(ret);
413 413
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 7ff7427c2e6a..a82937e2f824 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -13,6 +13,8 @@
13 * 13 *
14 */ 14 */
15 15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
16#include <linux/bcd.h> 18#include <linux/bcd.h>
17#include <linux/i2c.h> 19#include <linux/i2c.h>
18#include <linux/init.h> 20#include <linux/init.h>
@@ -513,12 +515,12 @@ static int wdt_ioctl(struct file *file, unsigned int cmd,
513 return -EFAULT; 515 return -EFAULT;
514 516
515 if (rv & WDIOS_DISABLECARD) { 517 if (rv & WDIOS_DISABLECARD) {
516 pr_info("rtc-m41t80: disable watchdog\n"); 518 pr_info("disable watchdog\n");
517 wdt_disable(); 519 wdt_disable();
518 } 520 }
519 521
520 if (rv & WDIOS_ENABLECARD) { 522 if (rv & WDIOS_ENABLECARD) {
521 pr_info("rtc-m41t80: enable watchdog\n"); 523 pr_info("enable watchdog\n");
522 wdt_ping(); 524 wdt_ping();
523 } 525 }
524 526
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 9d71328e59b9..7632a87784c3 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -12,6 +12,8 @@
12 * 12 *
13 */ 13 */
14 14
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
15#include <linux/slab.h> 17#include <linux/slab.h>
16#include <linux/rtc.h> 18#include <linux/rtc.h>
17#include <linux/delay.h> 19#include <linux/delay.h>
@@ -103,8 +105,8 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
103 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 105 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
104 106
105 if (tm->tm_year < 100) { 107 if (tm->tm_year < 100) {
106 pr_warn("%s: MAX77686 RTC cannot handle the year %d." 108 pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n",
107 "Assume it's 2000.\n", __func__, 1900 + tm->tm_year); 109 1900 + tm->tm_year);
108 return -EINVAL; 110 return -EINVAL;
109 } 111 }
110 return 0; 112 return 0;
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index 67fbe559d535..9e02bcda0c09 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -12,6 +12,8 @@
12 * 12 *
13 */ 13 */
14 14
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
15#include <linux/slab.h> 17#include <linux/slab.h>
16#include <linux/rtc.h> 18#include <linux/rtc.h>
17#include <linux/delay.h> 19#include <linux/delay.h>
@@ -107,8 +109,8 @@ static int max8997_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
107 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 109 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
108 110
109 if (tm->tm_year < 100) { 111 if (tm->tm_year < 100) {
110 pr_warn("%s: MAX8997 RTC cannot handle the year %d." 112 pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n",
111 "Assume it's 2000.\n", __func__, 1900 + tm->tm_year); 113 1900 + tm->tm_year);
112 return -EINVAL; 114 return -EINVAL;
113 } 115 }
114 return 0; 116 return 0;
@@ -424,7 +426,7 @@ static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
424 426
425 val = 0; 427 val = 0;
426 max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val); 428 max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val);
427 pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val); 429 pr_info("WTSR_SMPL(0x%02x)\n", val);
428} 430}
429 431
430static int max8997_rtc_init_reg(struct max8997_rtc_info *info) 432static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c
index 9bf877bdf836..c1c5c4e3b3b4 100644
--- a/drivers/rtc/rtc-msm6242.c
+++ b/drivers/rtc/rtc-msm6242.c
@@ -7,6 +7,8 @@
7 * Copyright (C) 1993 Hamish Macdonald 7 * Copyright (C) 1993 Hamish Macdonald
8 */ 8 */
9 9
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
10#include <linux/delay.h> 12#include <linux/delay.h>
11#include <linux/io.h> 13#include <linux/io.h>
12#include <linux/kernel.h> 14#include <linux/kernel.h>
@@ -111,7 +113,7 @@ static void msm6242_lock(struct msm6242_priv *priv)
111 } 113 }
112 114
113 if (!cnt) 115 if (!cnt)
114 pr_warn("msm6242: timed out waiting for RTC (0x%x)\n", 116 pr_warn("timed out waiting for RTC (0x%x)\n",
115 msm6242_read(priv, MSM6242_CD)); 117 msm6242_read(priv, MSM6242_CD));
116} 118}
117 119
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 8e5851aa4369..8b6355ffaff9 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -118,12 +118,15 @@
118#define KICK0_VALUE 0x83e70b13 118#define KICK0_VALUE 0x83e70b13
119#define KICK1_VALUE 0x95a4f1e0 119#define KICK1_VALUE 0x95a4f1e0
120 120
121struct omap_rtc;
122
121struct omap_rtc_device_type { 123struct omap_rtc_device_type {
122 bool has_32kclk_en; 124 bool has_32kclk_en;
123 bool has_kicker;
124 bool has_irqwakeen; 125 bool has_irqwakeen;
125 bool has_pmic_mode; 126 bool has_pmic_mode;
126 bool has_power_up_reset; 127 bool has_power_up_reset;
128 void (*lock)(struct omap_rtc *rtc);
129 void (*unlock)(struct omap_rtc *rtc);
127}; 130};
128 131
129struct omap_rtc { 132struct omap_rtc {
@@ -156,6 +159,26 @@ static inline void rtc_writel(struct omap_rtc *rtc, unsigned int reg, u32 val)
156 writel(val, rtc->base + reg); 159 writel(val, rtc->base + reg);
157} 160}
158 161
162static void am3352_rtc_unlock(struct omap_rtc *rtc)
163{
164 rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE);
165 rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE);
166}
167
168static void am3352_rtc_lock(struct omap_rtc *rtc)
169{
170 rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0);
171 rtc_writel(rtc, OMAP_RTC_KICK1_REG, 0);
172}
173
174static void default_rtc_unlock(struct omap_rtc *rtc)
175{
176}
177
178static void default_rtc_lock(struct omap_rtc *rtc)
179{
180}
181
159/* 182/*
160 * We rely on the rtc framework to handle locking (rtc->ops_lock), 183 * We rely on the rtc framework to handle locking (rtc->ops_lock),
161 * so the only other requirement is that register accesses which 184 * so the only other requirement is that register accesses which
@@ -186,7 +209,9 @@ static irqreturn_t rtc_irq(int irq, void *dev_id)
186 209
187 /* alarm irq? */ 210 /* alarm irq? */
188 if (irq_data & OMAP_RTC_STATUS_ALARM) { 211 if (irq_data & OMAP_RTC_STATUS_ALARM) {
212 rtc->type->unlock(rtc);
189 rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); 213 rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM);
214 rtc->type->lock(rtc);
190 events |= RTC_IRQF | RTC_AF; 215 events |= RTC_IRQF | RTC_AF;
191 } 216 }
192 217
@@ -218,9 +243,11 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
218 irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; 243 irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
219 } 244 }
220 rtc_wait_not_busy(rtc); 245 rtc_wait_not_busy(rtc);
246 rtc->type->unlock(rtc);
221 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 247 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg);
222 if (rtc->type->has_irqwakeen) 248 if (rtc->type->has_irqwakeen)
223 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 249 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg);
250 rtc->type->lock(rtc);
224 local_irq_enable(); 251 local_irq_enable();
225 252
226 return 0; 253 return 0;
@@ -293,12 +320,14 @@ static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm)
293 local_irq_disable(); 320 local_irq_disable();
294 rtc_wait_not_busy(rtc); 321 rtc_wait_not_busy(rtc);
295 322
323 rtc->type->unlock(rtc);
296 rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); 324 rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year);
297 rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); 325 rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon);
298 rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); 326 rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday);
299 rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); 327 rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour);
300 rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); 328 rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min);
301 rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); 329 rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec);
330 rtc->type->lock(rtc);
302 331
303 local_irq_enable(); 332 local_irq_enable();
304 333
@@ -341,6 +370,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
341 local_irq_disable(); 370 local_irq_disable();
342 rtc_wait_not_busy(rtc); 371 rtc_wait_not_busy(rtc);
343 372
373 rtc->type->unlock(rtc);
344 rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); 374 rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year);
345 rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); 375 rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon);
346 rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); 376 rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday);
@@ -362,6 +392,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
362 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); 392 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg);
363 if (rtc->type->has_irqwakeen) 393 if (rtc->type->has_irqwakeen)
364 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); 394 rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg);
395 rtc->type->lock(rtc);
365 396
366 local_irq_enable(); 397 local_irq_enable();
367 398
@@ -391,6 +422,7 @@ static void omap_rtc_power_off(void)
391 unsigned long now; 422 unsigned long now;
392 u32 val; 423 u32 val;
393 424
425 rtc->type->unlock(rtc);
394 /* enable pmic_power_en control */ 426 /* enable pmic_power_en control */
395 val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); 427 val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
396 rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); 428 rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN);
@@ -423,6 +455,7 @@ static void omap_rtc_power_off(void)
423 val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 455 val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
424 rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 456 rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG,
425 val | OMAP_RTC_INTERRUPTS_IT_ALARM2); 457 val | OMAP_RTC_INTERRUPTS_IT_ALARM2);
458 rtc->type->lock(rtc);
426 459
427 /* 460 /*
428 * Wait for alarm to trigger (within two seconds) and external PMIC to 461 * Wait for alarm to trigger (within two seconds) and external PMIC to
@@ -442,17 +475,21 @@ static struct rtc_class_ops omap_rtc_ops = {
442 475
443static const struct omap_rtc_device_type omap_rtc_default_type = { 476static const struct omap_rtc_device_type omap_rtc_default_type = {
444 .has_power_up_reset = true, 477 .has_power_up_reset = true,
478 .lock = default_rtc_lock,
479 .unlock = default_rtc_unlock,
445}; 480};
446 481
447static const struct omap_rtc_device_type omap_rtc_am3352_type = { 482static const struct omap_rtc_device_type omap_rtc_am3352_type = {
448 .has_32kclk_en = true, 483 .has_32kclk_en = true,
449 .has_kicker = true,
450 .has_irqwakeen = true, 484 .has_irqwakeen = true,
451 .has_pmic_mode = true, 485 .has_pmic_mode = true,
486 .lock = am3352_rtc_lock,
487 .unlock = am3352_rtc_unlock,
452}; 488};
453 489
454static const struct omap_rtc_device_type omap_rtc_da830_type = { 490static const struct omap_rtc_device_type omap_rtc_da830_type = {
455 .has_kicker = true, 491 .lock = am3352_rtc_lock,
492 .unlock = am3352_rtc_unlock,
456}; 493};
457 494
458static const struct platform_device_id omap_rtc_id_table[] = { 495static const struct platform_device_id omap_rtc_id_table[] = {
@@ -484,7 +521,7 @@ static const struct of_device_id omap_rtc_of_match[] = {
484}; 521};
485MODULE_DEVICE_TABLE(of, omap_rtc_of_match); 522MODULE_DEVICE_TABLE(of, omap_rtc_of_match);
486 523
487static int __init omap_rtc_probe(struct platform_device *pdev) 524static int omap_rtc_probe(struct platform_device *pdev)
488{ 525{
489 struct omap_rtc *rtc; 526 struct omap_rtc *rtc;
490 struct resource *res; 527 struct resource *res;
@@ -527,10 +564,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
527 pm_runtime_enable(&pdev->dev); 564 pm_runtime_enable(&pdev->dev);
528 pm_runtime_get_sync(&pdev->dev); 565 pm_runtime_get_sync(&pdev->dev);
529 566
530 if (rtc->type->has_kicker) { 567 rtc->type->unlock(rtc);
531 rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE);
532 rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE);
533 }
534 568
535 /* 569 /*
536 * disable interrupts 570 * disable interrupts
@@ -593,6 +627,8 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
593 if (reg != new_ctrl) 627 if (reg != new_ctrl)
594 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); 628 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl);
595 629
630 rtc->type->lock(rtc);
631
596 device_init_wakeup(&pdev->dev, true); 632 device_init_wakeup(&pdev->dev, true);
597 633
598 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 634 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
@@ -626,8 +662,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
626 662
627err: 663err:
628 device_init_wakeup(&pdev->dev, false); 664 device_init_wakeup(&pdev->dev, false);
629 if (rtc->type->has_kicker) 665 rtc->type->lock(rtc);
630 rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0);
631 pm_runtime_put_sync(&pdev->dev); 666 pm_runtime_put_sync(&pdev->dev);
632 pm_runtime_disable(&pdev->dev); 667 pm_runtime_disable(&pdev->dev);
633 668
@@ -646,11 +681,11 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
646 681
647 device_init_wakeup(&pdev->dev, 0); 682 device_init_wakeup(&pdev->dev, 0);
648 683
684 rtc->type->unlock(rtc);
649 /* leave rtc running, but disable irqs */ 685 /* leave rtc running, but disable irqs */
650 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 686 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
651 687
652 if (rtc->type->has_kicker) 688 rtc->type->lock(rtc);
653 rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0);
654 689
655 /* Disable the clock/module */ 690 /* Disable the clock/module */
656 pm_runtime_put_sync(&pdev->dev); 691 pm_runtime_put_sync(&pdev->dev);
@@ -666,6 +701,7 @@ static int omap_rtc_suspend(struct device *dev)
666 701
667 rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 702 rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
668 703
704 rtc->type->unlock(rtc);
669 /* 705 /*
670 * FIXME: the RTC alarm is not currently acting as a wakeup event 706 * FIXME: the RTC alarm is not currently acting as a wakeup event
671 * source on some platforms, and in fact this enable() call is just 707 * source on some platforms, and in fact this enable() call is just
@@ -675,6 +711,7 @@ static int omap_rtc_suspend(struct device *dev)
675 enable_irq_wake(rtc->irq_alarm); 711 enable_irq_wake(rtc->irq_alarm);
676 else 712 else
677 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 713 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
714 rtc->type->lock(rtc);
678 715
679 /* Disable the clock/module */ 716 /* Disable the clock/module */
680 pm_runtime_put_sync(dev); 717 pm_runtime_put_sync(dev);
@@ -689,10 +726,12 @@ static int omap_rtc_resume(struct device *dev)
689 /* Enable the clock/module so that we can access the registers */ 726 /* Enable the clock/module so that we can access the registers */
690 pm_runtime_get_sync(dev); 727 pm_runtime_get_sync(dev);
691 728
729 rtc->type->unlock(rtc);
692 if (device_may_wakeup(dev)) 730 if (device_may_wakeup(dev))
693 disable_irq_wake(rtc->irq_alarm); 731 disable_irq_wake(rtc->irq_alarm);
694 else 732 else
695 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); 733 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg);
734 rtc->type->lock(rtc);
696 735
697 return 0; 736 return 0;
698} 737}
@@ -709,12 +748,15 @@ static void omap_rtc_shutdown(struct platform_device *pdev)
709 * Keep the ALARM interrupt enabled to allow the system to power up on 748 * Keep the ALARM interrupt enabled to allow the system to power up on
710 * alarm events. 749 * alarm events.
711 */ 750 */
751 rtc->type->unlock(rtc);
712 mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 752 mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
713 mask &= OMAP_RTC_INTERRUPTS_IT_ALARM; 753 mask &= OMAP_RTC_INTERRUPTS_IT_ALARM;
714 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask); 754 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask);
755 rtc->type->lock(rtc);
715} 756}
716 757
717static struct platform_driver omap_rtc_driver = { 758static struct platform_driver omap_rtc_driver = {
759 .probe = omap_rtc_probe,
718 .remove = __exit_p(omap_rtc_remove), 760 .remove = __exit_p(omap_rtc_remove),
719 .shutdown = omap_rtc_shutdown, 761 .shutdown = omap_rtc_shutdown,
720 .driver = { 762 .driver = {
@@ -725,7 +767,7 @@ static struct platform_driver omap_rtc_driver = {
725 .id_table = omap_rtc_id_table, 767 .id_table = omap_rtc_id_table,
726}; 768};
727 769
728module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); 770module_platform_driver(omap_rtc_driver);
729 771
730MODULE_ALIAS("platform:omap_rtc"); 772MODULE_ALIAS("platform:omap_rtc");
731MODULE_AUTHOR("George G. Davis (and others)"); 773MODULE_AUTHOR("George G. Davis (and others)");
diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c
index 95f652165fe9..7061dcae2b09 100644
--- a/drivers/rtc/rtc-opal.c
+++ b/drivers/rtc/rtc-opal.c
@@ -16,8 +16,9 @@
16 * along with this program. 16 * along with this program.
17 */ 17 */
18 18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
19#define DRVNAME "rtc-opal" 21#define DRVNAME "rtc-opal"
20#define pr_fmt(fmt) DRVNAME ": " fmt
21 22
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/err.h> 24#include <linux/err.h>
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 96fb32e7d6f8..0ba7e59929be 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -246,7 +246,6 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
246static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) 246static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
247{ 247{
248 struct pcf8563 *pcf8563 = i2c_get_clientdata(client); 248 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
249 int err;
250 unsigned char buf[9]; 249 unsigned char buf[9];
251 250
252 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " 251 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
@@ -272,12 +271,8 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
272 271
273 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07; 272 buf[PCF8563_REG_DW] = tm->tm_wday & 0x07;
274 273
275 err = pcf8563_write_block_data(client, PCF8563_REG_SC, 274 return pcf8563_write_block_data(client, PCF8563_REG_SC,
276 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); 275 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC);
277 if (err)
278 return err;
279
280 return 0;
281} 276}
282 277
283#ifdef CONFIG_RTC_INTF_DEV 278#ifdef CONFIG_RTC_INTF_DEV
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index f4cf6851fae9..76cbad7a99d3 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -39,7 +39,6 @@ struct s3c_rtc {
39 void __iomem *base; 39 void __iomem *base;
40 struct clk *rtc_clk; 40 struct clk *rtc_clk;
41 struct clk *rtc_src_clk; 41 struct clk *rtc_src_clk;
42 bool enabled;
43 42
44 struct s3c_rtc_data *data; 43 struct s3c_rtc_data *data;
45 44
@@ -67,26 +66,25 @@ struct s3c_rtc_data {
67 void (*disable) (struct s3c_rtc *info); 66 void (*disable) (struct s3c_rtc *info);
68}; 67};
69 68
70static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable) 69static void s3c_rtc_enable_clk(struct s3c_rtc *info)
71{ 70{
72 unsigned long irq_flags; 71 unsigned long irq_flags;
73 72
74 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 73 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
75 if (enable) { 74 clk_enable(info->rtc_clk);
76 if (!info->enabled) { 75 if (info->data->needs_src_clk)
77 clk_enable(info->rtc_clk); 76 clk_enable(info->rtc_src_clk);
78 if (info->data->needs_src_clk) 77 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
79 clk_enable(info->rtc_src_clk); 78}
80 info->enabled = true; 79
81 } 80static void s3c_rtc_disable_clk(struct s3c_rtc *info)
82 } else { 81{
83 if (info->enabled) { 82 unsigned long irq_flags;
84 if (info->data->needs_src_clk) 83
85 clk_disable(info->rtc_src_clk); 84 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
86 clk_disable(info->rtc_clk); 85 if (info->data->needs_src_clk)
87 info->enabled = false; 86 clk_disable(info->rtc_src_clk);
88 } 87 clk_disable(info->rtc_clk);
89 }
90 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 88 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
91} 89}
92 90
@@ -119,20 +117,16 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
119 117
120 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); 118 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled);
121 119
122 clk_enable(info->rtc_clk); 120 s3c_rtc_enable_clk(info);
123 if (info->data->needs_src_clk) 121
124 clk_enable(info->rtc_src_clk);
125 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 122 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
126 123
127 if (enabled) 124 if (enabled)
128 tmp |= S3C2410_RTCALM_ALMEN; 125 tmp |= S3C2410_RTCALM_ALMEN;
129 126
130 writeb(tmp, info->base + S3C2410_RTCALM); 127 writeb(tmp, info->base + S3C2410_RTCALM);
131 if (info->data->needs_src_clk)
132 clk_disable(info->rtc_src_clk);
133 clk_disable(info->rtc_clk);
134 128
135 s3c_rtc_alarm_clk_enable(info, enabled); 129 s3c_rtc_disable_clk(info);
136 130
137 return 0; 131 return 0;
138} 132}
@@ -143,18 +137,12 @@ static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
143 if (!is_power_of_2(freq)) 137 if (!is_power_of_2(freq))
144 return -EINVAL; 138 return -EINVAL;
145 139
146 clk_enable(info->rtc_clk);
147 if (info->data->needs_src_clk)
148 clk_enable(info->rtc_src_clk);
149 spin_lock_irq(&info->pie_lock); 140 spin_lock_irq(&info->pie_lock);
150 141
151 if (info->data->set_freq) 142 if (info->data->set_freq)
152 info->data->set_freq(info, freq); 143 info->data->set_freq(info, freq);
153 144
154 spin_unlock_irq(&info->pie_lock); 145 spin_unlock_irq(&info->pie_lock);
155 if (info->data->needs_src_clk)
156 clk_disable(info->rtc_src_clk);
157 clk_disable(info->rtc_clk);
158 146
159 return 0; 147 return 0;
160} 148}
@@ -165,9 +153,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
165 struct s3c_rtc *info = dev_get_drvdata(dev); 153 struct s3c_rtc *info = dev_get_drvdata(dev);
166 unsigned int have_retried = 0; 154 unsigned int have_retried = 0;
167 155
168 clk_enable(info->rtc_clk); 156 s3c_rtc_enable_clk(info);
169 if (info->data->needs_src_clk)
170 clk_enable(info->rtc_src_clk);
171 157
172 retry_get_time: 158 retry_get_time:
173 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); 159 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN);
@@ -194,6 +180,8 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
194 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); 180 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
195 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); 181 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
196 182
183 s3c_rtc_disable_clk(info);
184
197 rtc_tm->tm_year += 100; 185 rtc_tm->tm_year += 100;
198 186
199 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", 187 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
@@ -202,10 +190,6 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
202 190
203 rtc_tm->tm_mon -= 1; 191 rtc_tm->tm_mon -= 1;
204 192
205 if (info->data->needs_src_clk)
206 clk_disable(info->rtc_src_clk);
207 clk_disable(info->rtc_clk);
208
209 return rtc_valid_tm(rtc_tm); 193 return rtc_valid_tm(rtc_tm);
210} 194}
211 195
@@ -225,9 +209,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
225 return -EINVAL; 209 return -EINVAL;
226 } 210 }
227 211
228 clk_enable(info->rtc_clk); 212 s3c_rtc_enable_clk(info);
229 if (info->data->needs_src_clk)
230 clk_enable(info->rtc_src_clk);
231 213
232 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); 214 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC);
233 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); 215 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN);
@@ -236,9 +218,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
236 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON); 218 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON);
237 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR); 219 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR);
238 220
239 if (info->data->needs_src_clk) 221 s3c_rtc_disable_clk(info);
240 clk_disable(info->rtc_src_clk);
241 clk_disable(info->rtc_clk);
242 222
243 return 0; 223 return 0;
244} 224}
@@ -249,9 +229,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
249 struct rtc_time *alm_tm = &alrm->time; 229 struct rtc_time *alm_tm = &alrm->time;
250 unsigned int alm_en; 230 unsigned int alm_en;
251 231
252 clk_enable(info->rtc_clk); 232 s3c_rtc_enable_clk(info);
253 if (info->data->needs_src_clk)
254 clk_enable(info->rtc_src_clk);
255 233
256 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); 234 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC);
257 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); 235 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN);
@@ -262,6 +240,8 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
262 240
263 alm_en = readb(info->base + S3C2410_RTCALM); 241 alm_en = readb(info->base + S3C2410_RTCALM);
264 242
243 s3c_rtc_disable_clk(info);
244
265 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 245 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
266 246
267 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", 247 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
@@ -269,9 +249,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
269 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 249 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
270 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 250 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
271 251
272
273 /* decode the alarm enable field */ 252 /* decode the alarm enable field */
274
275 if (alm_en & S3C2410_RTCALM_SECEN) 253 if (alm_en & S3C2410_RTCALM_SECEN)
276 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 254 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
277 else 255 else
@@ -304,10 +282,6 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
304 else 282 else
305 alm_tm->tm_year = -1; 283 alm_tm->tm_year = -1;
306 284
307 if (info->data->needs_src_clk)
308 clk_disable(info->rtc_src_clk);
309 clk_disable(info->rtc_clk);
310
311 return 0; 285 return 0;
312} 286}
313 287
@@ -317,15 +291,13 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
317 struct rtc_time *tm = &alrm->time; 291 struct rtc_time *tm = &alrm->time;
318 unsigned int alrm_en; 292 unsigned int alrm_en;
319 293
320 clk_enable(info->rtc_clk);
321 if (info->data->needs_src_clk)
322 clk_enable(info->rtc_src_clk);
323
324 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 294 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
325 alrm->enabled, 295 alrm->enabled,
326 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 296 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
327 tm->tm_hour, tm->tm_min, tm->tm_sec); 297 tm->tm_hour, tm->tm_min, tm->tm_sec);
328 298
299 s3c_rtc_enable_clk(info);
300
329 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 301 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
330 writeb(0x00, info->base + S3C2410_RTCALM); 302 writeb(0x00, info->base + S3C2410_RTCALM);
331 303
@@ -348,11 +320,9 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
348 320
349 writeb(alrm_en, info->base + S3C2410_RTCALM); 321 writeb(alrm_en, info->base + S3C2410_RTCALM);
350 322
351 s3c_rtc_setaie(dev, alrm->enabled); 323 s3c_rtc_disable_clk(info);
352 324
353 if (info->data->needs_src_clk) 325 s3c_rtc_setaie(dev, alrm->enabled);
354 clk_disable(info->rtc_src_clk);
355 clk_disable(info->rtc_clk);
356 326
357 return 0; 327 return 0;
358} 328}
@@ -361,16 +331,12 @@ static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
361{ 331{
362 struct s3c_rtc *info = dev_get_drvdata(dev); 332 struct s3c_rtc *info = dev_get_drvdata(dev);
363 333
364 clk_enable(info->rtc_clk); 334 s3c_rtc_enable_clk(info);
365 if (info->data->needs_src_clk)
366 clk_enable(info->rtc_src_clk);
367 335
368 if (info->data->enable_tick) 336 if (info->data->enable_tick)
369 info->data->enable_tick(info, seq); 337 info->data->enable_tick(info, seq);
370 338
371 if (info->data->needs_src_clk) 339 s3c_rtc_disable_clk(info);
372 clk_disable(info->rtc_src_clk);
373 clk_disable(info->rtc_clk);
374 340
375 return 0; 341 return 0;
376} 342}
@@ -388,10 +354,6 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info)
388{ 354{
389 unsigned int con, tmp; 355 unsigned int con, tmp;
390 356
391 clk_enable(info->rtc_clk);
392 if (info->data->needs_src_clk)
393 clk_enable(info->rtc_src_clk);
394
395 con = readw(info->base + S3C2410_RTCCON); 357 con = readw(info->base + S3C2410_RTCCON);
396 /* re-enable the device, and check it is ok */ 358 /* re-enable the device, and check it is ok */
397 if ((con & S3C2410_RTCCON_RTCEN) == 0) { 359 if ((con & S3C2410_RTCCON_RTCEN) == 0) {
@@ -417,20 +379,12 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info)
417 writew(tmp & ~S3C2410_RTCCON_CLKRST, 379 writew(tmp & ~S3C2410_RTCCON_CLKRST,
418 info->base + S3C2410_RTCCON); 380 info->base + S3C2410_RTCCON);
419 } 381 }
420
421 if (info->data->needs_src_clk)
422 clk_disable(info->rtc_src_clk);
423 clk_disable(info->rtc_clk);
424} 382}
425 383
426static void s3c24xx_rtc_disable(struct s3c_rtc *info) 384static void s3c24xx_rtc_disable(struct s3c_rtc *info)
427{ 385{
428 unsigned int con; 386 unsigned int con;
429 387
430 clk_enable(info->rtc_clk);
431 if (info->data->needs_src_clk)
432 clk_enable(info->rtc_src_clk);
433
434 con = readw(info->base + S3C2410_RTCCON); 388 con = readw(info->base + S3C2410_RTCCON);
435 con &= ~S3C2410_RTCCON_RTCEN; 389 con &= ~S3C2410_RTCCON_RTCEN;
436 writew(con, info->base + S3C2410_RTCCON); 390 writew(con, info->base + S3C2410_RTCCON);
@@ -438,28 +392,16 @@ static void s3c24xx_rtc_disable(struct s3c_rtc *info)
438 con = readb(info->base + S3C2410_TICNT); 392 con = readb(info->base + S3C2410_TICNT);
439 con &= ~S3C2410_TICNT_ENABLE; 393 con &= ~S3C2410_TICNT_ENABLE;
440 writeb(con, info->base + S3C2410_TICNT); 394 writeb(con, info->base + S3C2410_TICNT);
441
442 if (info->data->needs_src_clk)
443 clk_disable(info->rtc_src_clk);
444 clk_disable(info->rtc_clk);
445} 395}
446 396
447static void s3c6410_rtc_disable(struct s3c_rtc *info) 397static void s3c6410_rtc_disable(struct s3c_rtc *info)
448{ 398{
449 unsigned int con; 399 unsigned int con;
450 400
451 clk_enable(info->rtc_clk);
452 if (info->data->needs_src_clk)
453 clk_enable(info->rtc_src_clk);
454
455 con = readw(info->base + S3C2410_RTCCON); 401 con = readw(info->base + S3C2410_RTCCON);
456 con &= ~S3C64XX_RTCCON_TICEN; 402 con &= ~S3C64XX_RTCCON_TICEN;
457 con &= ~S3C2410_RTCCON_RTCEN; 403 con &= ~S3C2410_RTCCON_RTCEN;
458 writew(con, info->base + S3C2410_RTCCON); 404 writew(con, info->base + S3C2410_RTCCON);
459
460 if (info->data->needs_src_clk)
461 clk_disable(info->rtc_src_clk);
462 clk_disable(info->rtc_clk);
463} 405}
464 406
465static int s3c_rtc_remove(struct platform_device *pdev) 407static int s3c_rtc_remove(struct platform_device *pdev)
@@ -554,6 +496,20 @@ static int s3c_rtc_probe(struct platform_device *pdev)
554 496
555 device_init_wakeup(&pdev->dev, 1); 497 device_init_wakeup(&pdev->dev, 1);
556 498
499 /* Check RTC Time */
500 if (s3c_rtc_gettime(&pdev->dev, &rtc_tm)) {
501 rtc_tm.tm_year = 100;
502 rtc_tm.tm_mon = 0;
503 rtc_tm.tm_mday = 1;
504 rtc_tm.tm_hour = 0;
505 rtc_tm.tm_min = 0;
506 rtc_tm.tm_sec = 0;
507
508 s3c_rtc_settime(&pdev->dev, &rtc_tm);
509
510 dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
511 }
512
557 /* register RTC and exit */ 513 /* register RTC and exit */
558 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, 514 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops,
559 THIS_MODULE); 515 THIS_MODULE);
@@ -577,36 +533,21 @@ static int s3c_rtc_probe(struct platform_device *pdev)
577 goto err_nortc; 533 goto err_nortc;
578 } 534 }
579 535
580 /* Check RTC Time */
581 s3c_rtc_gettime(&pdev->dev, &rtc_tm);
582
583 if (rtc_valid_tm(&rtc_tm)) {
584 rtc_tm.tm_year = 100;
585 rtc_tm.tm_mon = 0;
586 rtc_tm.tm_mday = 1;
587 rtc_tm.tm_hour = 0;
588 rtc_tm.tm_min = 0;
589 rtc_tm.tm_sec = 0;
590
591 s3c_rtc_settime(&pdev->dev, &rtc_tm);
592
593 dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
594 }
595
596 if (info->data->select_tick_clk) 536 if (info->data->select_tick_clk)
597 info->data->select_tick_clk(info); 537 info->data->select_tick_clk(info);
598 538
599 s3c_rtc_setfreq(info, 1); 539 s3c_rtc_setfreq(info, 1);
600 540
601 if (info->data->needs_src_clk) 541 s3c_rtc_disable_clk(info);
602 clk_disable(info->rtc_src_clk);
603 clk_disable(info->rtc_clk);
604 542
605 return 0; 543 return 0;
606 544
607 err_nortc: 545 err_nortc:
608 if (info->data->disable) 546 if (info->data->disable)
609 info->data->disable(info); 547 info->data->disable(info);
548
549 if (info->data->needs_src_clk)
550 clk_disable_unprepare(info->rtc_src_clk);
610 clk_disable_unprepare(info->rtc_clk); 551 clk_disable_unprepare(info->rtc_clk);
611 552
612 return ret; 553 return ret;
@@ -618,9 +559,7 @@ static int s3c_rtc_suspend(struct device *dev)
618{ 559{
619 struct s3c_rtc *info = dev_get_drvdata(dev); 560 struct s3c_rtc *info = dev_get_drvdata(dev);
620 561
621 clk_enable(info->rtc_clk); 562 s3c_rtc_enable_clk(info);
622 if (info->data->needs_src_clk)
623 clk_enable(info->rtc_src_clk);
624 563
625 /* save TICNT for anyone using periodic interrupts */ 564 /* save TICNT for anyone using periodic interrupts */
626 if (info->data->save_tick_cnt) 565 if (info->data->save_tick_cnt)
@@ -636,10 +575,6 @@ static int s3c_rtc_suspend(struct device *dev)
636 dev_err(dev, "enable_irq_wake failed\n"); 575 dev_err(dev, "enable_irq_wake failed\n");
637 } 576 }
638 577
639 if (info->data->needs_src_clk)
640 clk_disable(info->rtc_src_clk);
641 clk_disable(info->rtc_clk);
642
643 return 0; 578 return 0;
644} 579}
645 580
@@ -647,25 +582,19 @@ static int s3c_rtc_resume(struct device *dev)
647{ 582{
648 struct s3c_rtc *info = dev_get_drvdata(dev); 583 struct s3c_rtc *info = dev_get_drvdata(dev);
649 584
650 clk_enable(info->rtc_clk);
651 if (info->data->needs_src_clk)
652 clk_enable(info->rtc_src_clk);
653
654 if (info->data->enable) 585 if (info->data->enable)
655 info->data->enable(info); 586 info->data->enable(info);
656 587
657 if (info->data->restore_tick_cnt) 588 if (info->data->restore_tick_cnt)
658 info->data->restore_tick_cnt(info); 589 info->data->restore_tick_cnt(info);
659 590
591 s3c_rtc_disable_clk(info);
592
660 if (device_may_wakeup(dev) && info->wake_en) { 593 if (device_may_wakeup(dev) && info->wake_en) {
661 disable_irq_wake(info->irq_alarm); 594 disable_irq_wake(info->irq_alarm);
662 info->wake_en = false; 595 info->wake_en = false;
663 } 596 }
664 597
665 if (info->data->needs_src_clk)
666 clk_disable(info->rtc_src_clk);
667 clk_disable(info->rtc_clk);
668
669 return 0; 598 return 0;
670} 599}
671#endif 600#endif
@@ -673,29 +602,13 @@ static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume);
673 602
674static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) 603static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask)
675{ 604{
676 clk_enable(info->rtc_clk);
677 if (info->data->needs_src_clk)
678 clk_enable(info->rtc_src_clk);
679 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 605 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF);
680 if (info->data->needs_src_clk)
681 clk_disable(info->rtc_src_clk);
682 clk_disable(info->rtc_clk);
683
684 s3c_rtc_alarm_clk_enable(info, false);
685} 606}
686 607
687static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) 608static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask)
688{ 609{
689 clk_enable(info->rtc_clk);
690 if (info->data->needs_src_clk)
691 clk_enable(info->rtc_src_clk);
692 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 610 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF);
693 writeb(mask, info->base + S3C2410_INTP); 611 writeb(mask, info->base + S3C2410_INTP);
694 if (info->data->needs_src_clk)
695 clk_disable(info->rtc_src_clk);
696 clk_disable(info->rtc_clk);
697
698 s3c_rtc_alarm_clk_enable(info, false);
699} 612}
700 613
701static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq) 614static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq)
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 4008b84246ca..8c70d785ba73 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -15,6 +15,8 @@
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 */ 16 */
17 17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
18#include <linux/module.h> 20#include <linux/module.h>
19#include <linux/i2c.h> 21#include <linux/i2c.h>
20#include <linux/bcd.h> 22#include <linux/bcd.h>
@@ -90,7 +92,7 @@ struct s5m_rtc_info {
90 struct regmap *regmap; 92 struct regmap *regmap;
91 struct rtc_device *rtc_dev; 93 struct rtc_device *rtc_dev;
92 int irq; 94 int irq;
93 int device_type; 95 enum sec_device_type device_type;
94 int rtc_24hr_mode; 96 int rtc_24hr_mode;
95 const struct s5m_rtc_reg_config *regs; 97 const struct s5m_rtc_reg_config *regs;
96}; 98};
@@ -146,7 +148,7 @@ static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data)
146 data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 148 data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
147 149
148 if (tm->tm_year < 100) { 150 if (tm->tm_year < 100) {
149 pr_err("s5m8767 RTC cannot handle the year %d.\n", 151 pr_err("RTC cannot handle the year %d\n",
150 1900 + tm->tm_year); 152 1900 + tm->tm_year);
151 return -EINVAL; 153 return -EINVAL;
152 } else { 154 } else {
@@ -187,6 +189,7 @@ static inline int s5m_check_peding_alarm_interrupt(struct s5m_rtc_info *info,
187 val &= S5M_ALARM0_STATUS; 189 val &= S5M_ALARM0_STATUS;
188 break; 190 break;
189 case S2MPS14X: 191 case S2MPS14X:
192 case S2MPS13X:
190 ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2, 193 ret = regmap_read(info->s5m87xx->regmap_pmic, S2MPS14_REG_ST2,
191 &val); 194 &val);
192 val &= S2MPS_ALARM0_STATUS; 195 val &= S2MPS_ALARM0_STATUS;
@@ -252,6 +255,9 @@ static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info)
252 case S2MPS14X: 255 case S2MPS14X:
253 data |= S2MPS_RTC_RUDR_MASK; 256 data |= S2MPS_RTC_RUDR_MASK;
254 break; 257 break;
258 case S2MPS13X:
259 data |= S2MPS13_RTC_AUDR_MASK;
260 break;
255 default: 261 default:
256 return -EINVAL; 262 return -EINVAL;
257 } 263 }
@@ -265,6 +271,11 @@ static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info)
265 271
266 ret = s5m8767_wait_for_udr_update(info); 272 ret = s5m8767_wait_for_udr_update(info);
267 273
274 /* On S2MPS13 the AUDR is not auto-cleared */
275 if (info->device_type == S2MPS13X)
276 regmap_update_bits(info->regmap, info->regs->rtc_udr_update,
277 S2MPS13_RTC_AUDR_MASK, 0);
278
268 return ret; 279 return ret;
269} 280}
270 281
@@ -306,7 +317,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)
306 u8 data[info->regs->regs_count]; 317 u8 data[info->regs->regs_count];
307 int ret; 318 int ret;
308 319
309 if (info->device_type == S2MPS14X) { 320 if (info->device_type == S2MPS14X || info->device_type == S2MPS13X) {
310 ret = regmap_update_bits(info->regmap, 321 ret = regmap_update_bits(info->regmap,
311 info->regs->rtc_udr_update, 322 info->regs->rtc_udr_update,
312 S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK); 323 S2MPS_RTC_RUDR_MASK, S2MPS_RTC_RUDR_MASK);
@@ -329,6 +340,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)
329 340
330 case S5M8767X: 341 case S5M8767X:
331 case S2MPS14X: 342 case S2MPS14X:
343 case S2MPS13X:
332 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode); 344 s5m8767_data_to_tm(data, tm, info->rtc_24hr_mode);
333 break; 345 break;
334 346
@@ -355,6 +367,7 @@ static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm)
355 break; 367 break;
356 case S5M8767X: 368 case S5M8767X:
357 case S2MPS14X: 369 case S2MPS14X:
370 case S2MPS13X:
358 ret = s5m8767_tm_to_data(tm, data); 371 ret = s5m8767_tm_to_data(tm, data);
359 break; 372 break;
360 default: 373 default:
@@ -402,6 +415,7 @@ static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
402 415
403 case S5M8767X: 416 case S5M8767X:
404 case S2MPS14X: 417 case S2MPS14X:
418 case S2MPS13X:
405 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); 419 s5m8767_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
406 alrm->enabled = 0; 420 alrm->enabled = 0;
407 for (i = 0; i < info->regs->regs_count; i++) { 421 for (i = 0; i < info->regs->regs_count; i++) {
@@ -450,6 +464,7 @@ static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info)
450 464
451 case S5M8767X: 465 case S5M8767X:
452 case S2MPS14X: 466 case S2MPS14X:
467 case S2MPS13X:
453 for (i = 0; i < info->regs->regs_count; i++) 468 for (i = 0; i < info->regs->regs_count; i++)
454 data[i] &= ~ALARM_ENABLE_MASK; 469 data[i] &= ~ALARM_ENABLE_MASK;
455 470
@@ -494,6 +509,7 @@ static int s5m_rtc_start_alarm(struct s5m_rtc_info *info)
494 509
495 case S5M8767X: 510 case S5M8767X:
496 case S2MPS14X: 511 case S2MPS14X:
512 case S2MPS13X:
497 data[RTC_SEC] |= ALARM_ENABLE_MASK; 513 data[RTC_SEC] |= ALARM_ENABLE_MASK;
498 data[RTC_MIN] |= ALARM_ENABLE_MASK; 514 data[RTC_MIN] |= ALARM_ENABLE_MASK;
499 data[RTC_HOUR] |= ALARM_ENABLE_MASK; 515 data[RTC_HOUR] |= ALARM_ENABLE_MASK;
@@ -533,6 +549,7 @@ static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
533 549
534 case S5M8767X: 550 case S5M8767X:
535 case S2MPS14X: 551 case S2MPS14X:
552 case S2MPS13X:
536 s5m8767_tm_to_data(&alrm->time, data); 553 s5m8767_tm_to_data(&alrm->time, data);
537 break; 554 break;
538 555
@@ -615,6 +632,7 @@ static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info)
615 break; 632 break;
616 633
617 case S2MPS14X: 634 case S2MPS14X:
635 case S2MPS13X:
618 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 636 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
619 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); 637 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]);
620 break; 638 break;
@@ -650,8 +668,9 @@ static int s5m_rtc_probe(struct platform_device *pdev)
650 if (!info) 668 if (!info)
651 return -ENOMEM; 669 return -ENOMEM;
652 670
653 switch (pdata->device_type) { 671 switch (platform_get_device_id(pdev)->driver_data) {
654 case S2MPS14X: 672 case S2MPS14X:
673 case S2MPS13X:
655 regmap_cfg = &s2mps14_rtc_regmap_config; 674 regmap_cfg = &s2mps14_rtc_regmap_config;
656 info->regs = &s2mps_rtc_regs; 675 info->regs = &s2mps_rtc_regs;
657 alarm_irq = S2MPS14_IRQ_RTCA0; 676 alarm_irq = S2MPS14_IRQ_RTCA0;
@@ -667,7 +686,9 @@ static int s5m_rtc_probe(struct platform_device *pdev)
667 alarm_irq = S5M8767_IRQ_RTCA1; 686 alarm_irq = S5M8767_IRQ_RTCA1;
668 break; 687 break;
669 default: 688 default:
670 dev_err(&pdev->dev, "Device type is not supported by RTC driver\n"); 689 dev_err(&pdev->dev,
690 "Device type %lu is not supported by RTC driver\n",
691 platform_get_device_id(pdev)->driver_data);
671 return -ENODEV; 692 return -ENODEV;
672 } 693 }
673 694
@@ -687,7 +708,7 @@ static int s5m_rtc_probe(struct platform_device *pdev)
687 708
688 info->dev = &pdev->dev; 709 info->dev = &pdev->dev;
689 info->s5m87xx = s5m87xx; 710 info->s5m87xx = s5m87xx;
690 info->device_type = s5m87xx->device_type; 711 info->device_type = platform_get_device_id(pdev)->driver_data;
691 712
692 if (s5m87xx->irq_data) { 713 if (s5m87xx->irq_data) {
693 info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq); 714 info->irq = regmap_irq_get_virq(s5m87xx->irq_data, alarm_irq);
@@ -772,6 +793,7 @@ static SIMPLE_DEV_PM_OPS(s5m_rtc_pm_ops, s5m_rtc_suspend, s5m_rtc_resume);
772 793
773static const struct platform_device_id s5m_rtc_id[] = { 794static const struct platform_device_id s5m_rtc_id[] = {
774 { "s5m-rtc", S5M8767X }, 795 { "s5m-rtc", S5M8767X },
796 { "s2mps13-rtc", S2MPS13X },
775 { "s2mps14-rtc", S2MPS14X }, 797 { "s2mps14-rtc", S2MPS14X },
776 { }, 798 { },
777}; 799};
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 2939cdcb2688..eb09eddf39b8 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -42,6 +42,8 @@
42#define STMP3XXX_RTC_STAT 0x10 42#define STMP3XXX_RTC_STAT 0x10
43#define STMP3XXX_RTC_STAT_STALE_SHIFT 16 43#define STMP3XXX_RTC_STAT_STALE_SHIFT 16
44#define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 44#define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000
45#define STMP3XXX_RTC_STAT_XTAL32000_PRESENT 0x10000000
46#define STMP3XXX_RTC_STAT_XTAL32768_PRESENT 0x08000000
45 47
46#define STMP3XXX_RTC_SECONDS 0x30 48#define STMP3XXX_RTC_SECONDS 0x30
47 49
@@ -52,9 +54,13 @@
52#define STMP3XXX_RTC_PERSISTENT0 0x60 54#define STMP3XXX_RTC_PERSISTENT0 0x60
53#define STMP3XXX_RTC_PERSISTENT0_SET 0x64 55#define STMP3XXX_RTC_PERSISTENT0_SET 0x64
54#define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 56#define STMP3XXX_RTC_PERSISTENT0_CLR 0x68
55#define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN 0x00000002 57#define STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE (1 << 0)
56#define STMP3XXX_RTC_PERSISTENT0_ALARM_EN 0x00000004 58#define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN (1 << 1)
57#define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE 0x00000080 59#define STMP3XXX_RTC_PERSISTENT0_ALARM_EN (1 << 2)
60#define STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP (1 << 4)
61#define STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP (1 << 5)
62#define STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ (1 << 6)
63#define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE (1 << 7)
58 64
59#define STMP3XXX_RTC_PERSISTENT1 0x70 65#define STMP3XXX_RTC_PERSISTENT1 0x70
60/* missing bitmask in headers */ 66/* missing bitmask in headers */
@@ -248,6 +254,9 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
248{ 254{
249 struct stmp3xxx_rtc_data *rtc_data; 255 struct stmp3xxx_rtc_data *rtc_data;
250 struct resource *r; 256 struct resource *r;
257 u32 rtc_stat;
258 u32 pers0_set, pers0_clr;
259 u32 crystalfreq = 0;
251 int err; 260 int err;
252 261
253 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); 262 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL);
@@ -268,8 +277,8 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
268 277
269 rtc_data->irq_alarm = platform_get_irq(pdev, 0); 278 rtc_data->irq_alarm = platform_get_irq(pdev, 0);
270 279
271 if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & 280 rtc_stat = readl(rtc_data->io + STMP3XXX_RTC_STAT);
272 STMP3XXX_RTC_STAT_RTC_PRESENT)) { 281 if (!(rtc_stat & STMP3XXX_RTC_STAT_RTC_PRESENT)) {
273 dev_err(&pdev->dev, "no device onboard\n"); 282 dev_err(&pdev->dev, "no device onboard\n");
274 return -ENODEV; 283 return -ENODEV;
275 } 284 }
@@ -282,9 +291,54 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
282 return err; 291 return err;
283 } 292 }
284 293
294 /*
295 * Obviously the rtc needs a clock input to be able to run.
296 * This clock can be provided by an external 32k crystal. If that one is
297 * missing XTAL must not be disabled in suspend which consumes a
298 * lot of power. Normally the presence and exact frequency (supported
299 * are 32000 Hz and 32768 Hz) is detectable from fuses, but as reality
300 * proves these fuses are not blown correctly on all machines, so the
301 * frequency can be overridden in the device tree.
302 */
303 if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32000_PRESENT)
304 crystalfreq = 32000;
305 else if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32768_PRESENT)
306 crystalfreq = 32768;
307
308 of_property_read_u32(pdev->dev.of_node, "stmp,crystal-freq",
309 &crystalfreq);
310
311 switch (crystalfreq) {
312 case 32000:
313 /* keep 32kHz crystal running in low-power mode */
314 pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ |
315 STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP |
316 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE;
317 pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP;
318 break;
319 case 32768:
320 /* keep 32.768kHz crystal running in low-power mode */
321 pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP |
322 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE;
323 pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP |
324 STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ;
325 break;
326 default:
327 dev_warn(&pdev->dev,
328 "invalid crystal-freq specified in device-tree. Assuming no crystal\n");
329 /* fall-through */
330 case 0:
331 /* keep XTAL on in low-power mode */
332 pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP;
333 pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP |
334 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE;
335 }
336
337 writel(pers0_set, rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET);
338
285 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 339 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
286 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 340 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN |
287 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, 341 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE | pers0_clr,
288 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 342 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR);
289 343
290 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN | 344 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN |
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 5baea3f54926..2dc787dc06c1 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -18,6 +18,8 @@
18 * 2 of the License, or (at your option) any later version. 18 * 2 of the License, or (at your option) any later version.
19 */ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/kernel.h> 23#include <linux/kernel.h>
22#include <linux/errno.h> 24#include <linux/errno.h>
23#include <linux/init.h> 25#include <linux/init.h>
@@ -145,8 +147,7 @@ static int twl_rtc_read_u8(u8 *data, u8 reg)
145 147
146 ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 148 ret = twl_i2c_read_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg]));
147 if (ret < 0) 149 if (ret < 0)
148 pr_err("twl_rtc: Could not read TWL" 150 pr_err("Could not read TWL register %X - error %d\n", reg, ret);
149 "register %X - error %d\n", reg, ret);
150 return ret; 151 return ret;
151} 152}
152 153
@@ -159,8 +160,8 @@ static int twl_rtc_write_u8(u8 data, u8 reg)
159 160
160 ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg])); 161 ret = twl_i2c_write_u8(TWL_MODULE_RTC, data, (rtc_reg_map[reg]));
161 if (ret < 0) 162 if (ret < 0)
162 pr_err("twl_rtc: Could not write TWL" 163 pr_err("Could not write TWL register %X - error %d\n",
163 "register %X - error %d\n", reg, ret); 164 reg, ret);
164 return ret; 165 return ret;
165} 166}
166 167
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index b1de58e0b3d0..5638b7ba8b06 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -22,6 +22,7 @@
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/bitops.h>
25 26
26#define DRV_VERSION "1.0.8" 27#define DRV_VERSION "1.0.8"
27 28
@@ -366,8 +367,7 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
366 * perform sign extension. The formula is 367 * perform sign extension. The formula is
367 * Catr = (atr * 0.25pF) + 11.00pF. 368 * Catr = (atr * 0.25pF) + 11.00pF.
368 */ 369 */
369 if (atr & 0x20) 370 atr = sign_extend32(atr, 5);
370 atr |= 0xC0;
371 371
372 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr); 372 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __func__, atr, atr);
373 373
diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index e90a3742f09d..cc3b9d3d6d40 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -1079,22 +1079,18 @@ bfad_start_ops(struct bfad_s *bfad) {
1079int 1079int
1080bfad_worker(void *ptr) 1080bfad_worker(void *ptr)
1081{ 1081{
1082 struct bfad_s *bfad; 1082 struct bfad_s *bfad = ptr;
1083 unsigned long flags; 1083 unsigned long flags;
1084
1085 bfad = (struct bfad_s *)ptr;
1086
1087 while (!kthread_should_stop()) {
1088 1084
1089 /* Send event BFAD_E_INIT_SUCCESS */ 1085 if (kthread_should_stop())
1090 bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS); 1086 return 0;
1091 1087
1092 spin_lock_irqsave(&bfad->bfad_lock, flags); 1088 /* Send event BFAD_E_INIT_SUCCESS */
1093 bfad->bfad_tsk = NULL; 1089 bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS);
1094 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1095 1090
1096 break; 1091 spin_lock_irqsave(&bfad->bfad_lock, flags);
1097 } 1092 bfad->bfad_tsk = NULL;
1093 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1098 1094
1099 return 0; 1095 return 0;
1100} 1096}