summaryrefslogtreecommitdiff
path: root/target/linux/s3c24xx/patches/0165-fix-pcf50633-rtc-i2c-bulk-autoincrement-simplify.pat.patch
blob: 064dee074bdbf75d562ef51f082ab60b8f247398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
From 03469473733ccb461781e091233bb337f70417f1 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@openmoko.com>
Date: Fri, 25 Jul 2008 23:06:12 +0100
Subject: [PATCH] fix-pcf50633-rtc-i2c-bulk-autoincrement-simplify.patch

More pcf50633 major time saving by using i2c bulk autoincrement.  Code
reduction too by using array for time elements.

Signed-off-by: Andy Green <andy@openmoko.com>
---
 drivers/i2c/chips/pcf50633.c |  134 ++++++++++++++++++++++++------------------
 1 files changed, 77 insertions(+), 57 deletions(-)

diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
index 5c9d209..0406767 100644
--- a/drivers/i2c/chips/pcf50633.c
+++ b/drivers/i2c/chips/pcf50633.c
@@ -1504,37 +1504,42 @@ static void pcf50633_get_power_status(struct apm_power_info *info)
 /***********************************************************************
  * RTC
  ***********************************************************************/
+enum pcf50633_time_indexes {
+	PCF50633_TI_SEC = 0,
+	PCF50633_TI_MIN,
+	PCF50633_TI_HOUR,
+	PCF50633_TI_WKDAY,
+	PCF50633_TI_DAY,
+	PCF50633_TI_MONTH,
+	PCF50633_TI_YEAR,
+	PCF50633_TI_EXTENT /* always last */
+};
+
 
 struct pcf50633_time {
-	u_int8_t sec;
-	u_int8_t min;
-	u_int8_t hour;
-	u_int8_t wkday;
-	u_int8_t day;
-	u_int8_t month;
-	u_int8_t year;
+	u_int8_t time[PCF50633_TI_EXTENT];
 };
 
 static void pcf2rtc_time(struct rtc_time *rtc, struct pcf50633_time *pcf)
 {
-	rtc->tm_sec = BCD2BIN(pcf->sec);
-	rtc->tm_min = BCD2BIN(pcf->min);
-	rtc->tm_hour = BCD2BIN(pcf->hour);
-	rtc->tm_wday = BCD2BIN(pcf->wkday);
-	rtc->tm_mday = BCD2BIN(pcf->day);
-	rtc->tm_mon = BCD2BIN(pcf->month);
-	rtc->tm_year = BCD2BIN(pcf->year) + 100;
+	rtc->tm_sec = BCD2BIN(pcf->time[PCF50633_TI_SEC]);
+	rtc->tm_min = BCD2BIN(pcf->time[PCF50633_TI_MIN]);
+	rtc->tm_hour = BCD2BIN(pcf->time[PCF50633_TI_HOUR]);
+	rtc->tm_wday = BCD2BIN(pcf->time[PCF50633_TI_WKDAY]);
+	rtc->tm_mday = BCD2BIN(pcf->time[PCF50633_TI_DAY]);
+	rtc->tm_mon = BCD2BIN(pcf->time[PCF50633_TI_MONTH]);
+	rtc->tm_year = BCD2BIN(pcf->time[PCF50633_TI_YEAR]) + 100;
 }
 
 static void rtc2pcf_time(struct pcf50633_time *pcf, struct rtc_time *rtc)
 {
-	pcf->sec = BIN2BCD(rtc->tm_sec);
-	pcf->min = BIN2BCD(rtc->tm_min);
-	pcf->hour = BIN2BCD(rtc->tm_hour);
-	pcf->wkday = BIN2BCD(rtc->tm_wday);
-	pcf->day = BIN2BCD(rtc->tm_mday);
-	pcf->month = BIN2BCD(rtc->tm_mon);
-	pcf->year = BIN2BCD(rtc->tm_year - 100);
+	pcf->time[PCF50633_TI_SEC] = BIN2BCD(rtc->tm_sec);
+	pcf->time[PCF50633_TI_MIN] = BIN2BCD(rtc->tm_min);
+	pcf->time[PCF50633_TI_HOUR] = BIN2BCD(rtc->tm_hour);
+	pcf->time[PCF50633_TI_WKDAY] = BIN2BCD(rtc->tm_wday);
+	pcf->time[PCF50633_TI_DAY] = BIN2BCD(rtc->tm_mday);
+	pcf->time[PCF50633_TI_MONTH] = BIN2BCD(rtc->tm_mon);
+	pcf->time[PCF50633_TI_YEAR] = BIN2BCD(rtc->tm_year - 100);
 }
 
 static int pcf50633_rtc_ioctl(struct device *dev, unsigned int cmd,
@@ -1573,24 +1578,30 @@ static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct pcf50633_data *pcf = i2c_get_clientdata(client);
 	struct pcf50633_time pcf_tm;
+	int ret;
 
 	mutex_lock(&pcf->lock);
-	pcf_tm.sec = __reg_read(pcf, PCF50633_REG_RTCSC);
-	pcf_tm.min = __reg_read(pcf, PCF50633_REG_RTCMN);
-	pcf_tm.hour = __reg_read(pcf, PCF50633_REG_RTCHR);
-	pcf_tm.wkday = __reg_read(pcf, PCF50633_REG_RTCWD);
-	pcf_tm.day = __reg_read(pcf, PCF50633_REG_RTCDT);
-	pcf_tm.month = __reg_read(pcf, PCF50633_REG_RTCMT);
-	pcf_tm.year = __reg_read(pcf, PCF50633_REG_RTCYR);
+
+	ret = i2c_smbus_read_i2c_block_data(&pcf->client,
+					    PCF50633_REG_RTCSC,
+					    PCF50633_TI_EXTENT,
+					    &pcf_tm.time[0]);
+	if (ret != PCF50633_TI_EXTENT)
+		dev_err(dev, "Failed to read time :-(\n");
+
 	mutex_unlock(&pcf->lock);
 
-	DEBUGP("PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
-		pcf_tm.day, pcf_tm.month, pcf_tm.year,
-		pcf_tm.hour, pcf_tm.min, pcf_tm.sec);
+	dev_info(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
+		pcf_tm.time[PCF50633_TI_DAY],
+		pcf_tm.time[PCF50633_TI_MONTH],
+		pcf_tm.time[PCF50633_TI_YEAR],
+		pcf_tm.time[PCF50633_TI_HOUR],
+		pcf_tm.time[PCF50633_TI_MIN],
+		pcf_tm.time[PCF50633_TI_SEC]);
 
 	pcf2rtc_time(tm, &pcf_tm);
 
-	DEBUGP("RTC_TIME: %u.%u.%u %u:%u:%u\n",
+	dev_info(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
 		tm->tm_mday, tm->tm_mon, tm->tm_year,
 		tm->tm_hour, tm->tm_min, tm->tm_sec);
 
@@ -1602,24 +1613,30 @@ static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct pcf50633_data *pcf = i2c_get_clientdata(client);
 	struct pcf50633_time pcf_tm;
+	int ret;
 
-	DEBUGP("RTC_TIME: %u.%u.%u %u:%u:%u\n",
+	dev_info(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
 		tm->tm_mday, tm->tm_mon, tm->tm_year,
 		tm->tm_hour, tm->tm_min, tm->tm_sec);
 	rtc2pcf_time(&pcf_tm, tm);
-	DEBUGP("PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
-		pcf_tm.day, pcf_tm.month, pcf_tm.year,
-		pcf_tm.hour, pcf_tm.min, pcf_tm.sec);
+	dev_info(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
+		pcf_tm.time[PCF50633_TI_DAY],
+		pcf_tm.time[PCF50633_TI_MONTH],
+		pcf_tm.time[PCF50633_TI_YEAR],
+		pcf_tm.time[PCF50633_TI_HOUR],
+		pcf_tm.time[PCF50633_TI_MIN],
+		pcf_tm.time[PCF50633_TI_SEC]);
 
 	mutex_lock(&pcf->lock);
 	/* FIXME: disable second interrupt */
-	__reg_write(pcf, PCF50633_REG_RTCSC, pcf_tm.sec);
-	__reg_write(pcf, PCF50633_REG_RTCMN, pcf_tm.min);
-	__reg_write(pcf, PCF50633_REG_RTCHR, pcf_tm.hour);
-	__reg_write(pcf, PCF50633_REG_RTCWD, pcf_tm.wkday);
-	__reg_write(pcf, PCF50633_REG_RTCDT, pcf_tm.day);
-	__reg_write(pcf, PCF50633_REG_RTCMT, pcf_tm.month);
-	__reg_write(pcf, PCF50633_REG_RTCYR, pcf_tm.year);
+
+	ret = i2c_smbus_write_i2c_block_data(&pcf->client,
+					     PCF50633_REG_RTCSC,
+					     PCF50633_TI_EXTENT,
+					     &pcf_tm.time[0]);
+	if (ret)
+		dev_err(dev, "Failed to set time %d\n", ret);
+
 	/* FIXME: re-enable second interrupt */
 	mutex_unlock(&pcf->lock);
 
@@ -1631,17 +1648,20 @@ static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct pcf50633_data *pcf = i2c_get_clientdata(client);
 	struct pcf50633_time pcf_tm;
+	int ret;
 
 	mutex_lock(&pcf->lock);
+
 	alrm->enabled =
 	     __reg_read(pcf, PCF50633_REG_INT1M) & PCF50633_INT1_ALARM ? 0 : 1;
-	pcf_tm.sec = __reg_read(pcf, PCF50633_REG_RTCSCA);
-	pcf_tm.min = __reg_read(pcf, PCF50633_REG_RTCMNA);
-	pcf_tm.hour = __reg_read(pcf, PCF50633_REG_RTCHRA);
-	pcf_tm.wkday = __reg_read(pcf, PCF50633_REG_RTCWDA);
-	pcf_tm.day = __reg_read(pcf, PCF50633_REG_RTCDTA);
-	pcf_tm.month = __reg_read(pcf, PCF50633_REG_RTCMTA);
-	pcf_tm.year = __reg_read(pcf, PCF50633_REG_RTCYRA);
+
+	ret = i2c_smbus_read_i2c_block_data(&pcf->client,
+					    PCF50633_REG_RTCSCA,
+					    PCF50633_TI_EXTENT,
+					    &pcf_tm.time[0]);
+	if (ret != PCF50633_TI_EXTENT)
+		dev_err(dev, "Failed to read Alarm time :-(\n");
+
 	mutex_unlock(&pcf->lock);
 
 	pcf2rtc_time(&alrm->time, &pcf_tm);
@@ -1655,6 +1675,7 @@ static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	struct pcf50633_data *pcf = i2c_get_clientdata(client);
 	struct pcf50633_time pcf_tm;
 	u_int8_t irqmask;
+	int ret;
 
 	rtc2pcf_time(&pcf_tm, &alrm->time);
 
@@ -1665,13 +1686,12 @@ static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	irqmask |= PCF50633_INT1_ALARM;
 	__reg_write(pcf, PCF50633_REG_INT1M, irqmask);
 
-	__reg_write(pcf, PCF50633_REG_RTCSCA, pcf_tm.sec);
-	__reg_write(pcf, PCF50633_REG_RTCMNA, pcf_tm.min);
-	__reg_write(pcf, PCF50633_REG_RTCHRA, pcf_tm.hour);
-	__reg_write(pcf, PCF50633_REG_RTCWDA, pcf_tm.wkday);
-	__reg_write(pcf, PCF50633_REG_RTCDTA, pcf_tm.day);
-	__reg_write(pcf, PCF50633_REG_RTCMTA, pcf_tm.month);
-	__reg_write(pcf, PCF50633_REG_RTCYRA, pcf_tm.year);
+	ret = i2c_smbus_write_i2c_block_data(&pcf->client,
+					     PCF50633_REG_RTCSCA,
+					     PCF50633_TI_EXTENT,
+					     &pcf_tm.time[0]);
+	if (ret)
+		dev_err(dev, "Failed to write alarm time :-( %d\n", ret);
 
 	if (alrm->enabled) {
 		/* (re-)enaable alarm interrupt */
-- 
1.5.6.3