[ifxmips] many more code cleanups for checkpatch.pl, most flagged as errors
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1186-fix-pcf50633-rtc-i2c-bulk-autoincrement-simplify.pat.patch
1 From d22227eec7efd4b2f40e51ea3c3bc025299efc93 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Wed, 2 Jul 2008 22:40:04 +0100
4 Subject: [PATCH] fix-pcf50633-rtc-i2c-bulk-autoincrement-simplify.patch
5
6 More pcf50633 major time saving by using i2c bulk autoincrement. Code
7 reduction too by using array for time elements.
8
9 Signed-off-by: Andy Green <andy@openmoko.com>
10 ---
11 drivers/i2c/chips/pcf50633.c | 134 ++++++++++++++++++++++++------------------
12 1 files changed, 77 insertions(+), 57 deletions(-)
13
14 diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
15 index 33e2eaf..1f88c32 100644
16 --- a/drivers/i2c/chips/pcf50633.c
17 +++ b/drivers/i2c/chips/pcf50633.c
18 @@ -1505,37 +1505,42 @@ static void pcf50633_get_power_status(struct apm_power_info *info)
19 /***********************************************************************
20 * RTC
21 ***********************************************************************/
22 +enum pcf50633_time_indexes {
23 + PCF50633_TI_SEC = 0,
24 + PCF50633_TI_MIN,
25 + PCF50633_TI_HOUR,
26 + PCF50633_TI_WKDAY,
27 + PCF50633_TI_DAY,
28 + PCF50633_TI_MONTH,
29 + PCF50633_TI_YEAR,
30 + PCF50633_TI_EXTENT /* always last */
31 +};
32 +
33
34 struct pcf50633_time {
35 - u_int8_t sec;
36 - u_int8_t min;
37 - u_int8_t hour;
38 - u_int8_t wkday;
39 - u_int8_t day;
40 - u_int8_t month;
41 - u_int8_t year;
42 + u_int8_t time[PCF50633_TI_EXTENT];
43 };
44
45 static void pcf2rtc_time(struct rtc_time *rtc, struct pcf50633_time *pcf)
46 {
47 - rtc->tm_sec = BCD2BIN(pcf->sec);
48 - rtc->tm_min = BCD2BIN(pcf->min);
49 - rtc->tm_hour = BCD2BIN(pcf->hour);
50 - rtc->tm_wday = BCD2BIN(pcf->wkday);
51 - rtc->tm_mday = BCD2BIN(pcf->day);
52 - rtc->tm_mon = BCD2BIN(pcf->month);
53 - rtc->tm_year = BCD2BIN(pcf->year) + 100;
54 + rtc->tm_sec = BCD2BIN(pcf->time[PCF50633_TI_SEC]);
55 + rtc->tm_min = BCD2BIN(pcf->time[PCF50633_TI_MIN]);
56 + rtc->tm_hour = BCD2BIN(pcf->time[PCF50633_TI_HOUR]);
57 + rtc->tm_wday = BCD2BIN(pcf->time[PCF50633_TI_WKDAY]);
58 + rtc->tm_mday = BCD2BIN(pcf->time[PCF50633_TI_DAY]);
59 + rtc->tm_mon = BCD2BIN(pcf->time[PCF50633_TI_MONTH]);
60 + rtc->tm_year = BCD2BIN(pcf->time[PCF50633_TI_YEAR]) + 100;
61 }
62
63 static void rtc2pcf_time(struct pcf50633_time *pcf, struct rtc_time *rtc)
64 {
65 - pcf->sec = BIN2BCD(rtc->tm_sec);
66 - pcf->min = BIN2BCD(rtc->tm_min);
67 - pcf->hour = BIN2BCD(rtc->tm_hour);
68 - pcf->wkday = BIN2BCD(rtc->tm_wday);
69 - pcf->day = BIN2BCD(rtc->tm_mday);
70 - pcf->month = BIN2BCD(rtc->tm_mon);
71 - pcf->year = BIN2BCD(rtc->tm_year - 100);
72 + pcf->time[PCF50633_TI_SEC] = BIN2BCD(rtc->tm_sec);
73 + pcf->time[PCF50633_TI_MIN] = BIN2BCD(rtc->tm_min);
74 + pcf->time[PCF50633_TI_HOUR] = BIN2BCD(rtc->tm_hour);
75 + pcf->time[PCF50633_TI_WKDAY] = BIN2BCD(rtc->tm_wday);
76 + pcf->time[PCF50633_TI_DAY] = BIN2BCD(rtc->tm_mday);
77 + pcf->time[PCF50633_TI_MONTH] = BIN2BCD(rtc->tm_mon);
78 + pcf->time[PCF50633_TI_YEAR] = BIN2BCD(rtc->tm_year - 100);
79 }
80
81 static int pcf50633_rtc_ioctl(struct device *dev, unsigned int cmd,
82 @@ -1574,24 +1579,30 @@ static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm)
83 struct i2c_client *client = to_i2c_client(dev);
84 struct pcf50633_data *pcf = i2c_get_clientdata(client);
85 struct pcf50633_time pcf_tm;
86 + int ret;
87
88 mutex_lock(&pcf->lock);
89 - pcf_tm.sec = __reg_read(pcf, PCF50633_REG_RTCSC);
90 - pcf_tm.min = __reg_read(pcf, PCF50633_REG_RTCMN);
91 - pcf_tm.hour = __reg_read(pcf, PCF50633_REG_RTCHR);
92 - pcf_tm.wkday = __reg_read(pcf, PCF50633_REG_RTCWD);
93 - pcf_tm.day = __reg_read(pcf, PCF50633_REG_RTCDT);
94 - pcf_tm.month = __reg_read(pcf, PCF50633_REG_RTCMT);
95 - pcf_tm.year = __reg_read(pcf, PCF50633_REG_RTCYR);
96 +
97 + ret = i2c_smbus_read_i2c_block_data(&pcf->client,
98 + PCF50633_REG_RTCSC,
99 + PCF50633_TI_EXTENT,
100 + &pcf_tm.time[0]);
101 + if (ret != PCF50633_TI_EXTENT)
102 + dev_err(dev, "Failed to read time :-(\n");
103 +
104 mutex_unlock(&pcf->lock);
105
106 - DEBUGP("PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
107 - pcf_tm.day, pcf_tm.month, pcf_tm.year,
108 - pcf_tm.hour, pcf_tm.min, pcf_tm.sec);
109 + dev_info(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
110 + pcf_tm.time[PCF50633_TI_DAY],
111 + pcf_tm.time[PCF50633_TI_MONTH],
112 + pcf_tm.time[PCF50633_TI_YEAR],
113 + pcf_tm.time[PCF50633_TI_HOUR],
114 + pcf_tm.time[PCF50633_TI_MIN],
115 + pcf_tm.time[PCF50633_TI_SEC]);
116
117 pcf2rtc_time(tm, &pcf_tm);
118
119 - DEBUGP("RTC_TIME: %u.%u.%u %u:%u:%u\n",
120 + dev_info(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
121 tm->tm_mday, tm->tm_mon, tm->tm_year,
122 tm->tm_hour, tm->tm_min, tm->tm_sec);
123
124 @@ -1603,24 +1614,30 @@ static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm)
125 struct i2c_client *client = to_i2c_client(dev);
126 struct pcf50633_data *pcf = i2c_get_clientdata(client);
127 struct pcf50633_time pcf_tm;
128 + int ret;
129
130 - DEBUGP("RTC_TIME: %u.%u.%u %u:%u:%u\n",
131 + dev_info(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
132 tm->tm_mday, tm->tm_mon, tm->tm_year,
133 tm->tm_hour, tm->tm_min, tm->tm_sec);
134 rtc2pcf_time(&pcf_tm, tm);
135 - DEBUGP("PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
136 - pcf_tm.day, pcf_tm.month, pcf_tm.year,
137 - pcf_tm.hour, pcf_tm.min, pcf_tm.sec);
138 + dev_info(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
139 + pcf_tm.time[PCF50633_TI_DAY],
140 + pcf_tm.time[PCF50633_TI_MONTH],
141 + pcf_tm.time[PCF50633_TI_YEAR],
142 + pcf_tm.time[PCF50633_TI_HOUR],
143 + pcf_tm.time[PCF50633_TI_MIN],
144 + pcf_tm.time[PCF50633_TI_SEC]);
145
146 mutex_lock(&pcf->lock);
147 /* FIXME: disable second interrupt */
148 - __reg_write(pcf, PCF50633_REG_RTCSC, pcf_tm.sec);
149 - __reg_write(pcf, PCF50633_REG_RTCMN, pcf_tm.min);
150 - __reg_write(pcf, PCF50633_REG_RTCHR, pcf_tm.hour);
151 - __reg_write(pcf, PCF50633_REG_RTCWD, pcf_tm.wkday);
152 - __reg_write(pcf, PCF50633_REG_RTCDT, pcf_tm.day);
153 - __reg_write(pcf, PCF50633_REG_RTCMT, pcf_tm.month);
154 - __reg_write(pcf, PCF50633_REG_RTCYR, pcf_tm.year);
155 +
156 + ret = i2c_smbus_write_i2c_block_data(&pcf->client,
157 + PCF50633_REG_RTCSC,
158 + PCF50633_TI_EXTENT,
159 + &pcf_tm.time[0]);
160 + if (ret)
161 + dev_err(dev, "Failed to set time %d\n", ret);
162 +
163 /* FIXME: re-enable second interrupt */
164 mutex_unlock(&pcf->lock);
165
166 @@ -1632,17 +1649,20 @@ static int pcf50633_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
167 struct i2c_client *client = to_i2c_client(dev);
168 struct pcf50633_data *pcf = i2c_get_clientdata(client);
169 struct pcf50633_time pcf_tm;
170 + int ret;
171
172 mutex_lock(&pcf->lock);
173 +
174 alrm->enabled =
175 __reg_read(pcf, PCF50633_REG_INT1M) & PCF50633_INT1_ALARM ? 0 : 1;
176 - pcf_tm.sec = __reg_read(pcf, PCF50633_REG_RTCSCA);
177 - pcf_tm.min = __reg_read(pcf, PCF50633_REG_RTCMNA);
178 - pcf_tm.hour = __reg_read(pcf, PCF50633_REG_RTCHRA);
179 - pcf_tm.wkday = __reg_read(pcf, PCF50633_REG_RTCWDA);
180 - pcf_tm.day = __reg_read(pcf, PCF50633_REG_RTCDTA);
181 - pcf_tm.month = __reg_read(pcf, PCF50633_REG_RTCMTA);
182 - pcf_tm.year = __reg_read(pcf, PCF50633_REG_RTCYRA);
183 +
184 + ret = i2c_smbus_read_i2c_block_data(&pcf->client,
185 + PCF50633_REG_RTCSCA,
186 + PCF50633_TI_EXTENT,
187 + &pcf_tm.time[0]);
188 + if (ret != PCF50633_TI_EXTENT)
189 + dev_err(dev, "Failed to read Alarm time :-(\n");
190 +
191 mutex_unlock(&pcf->lock);
192
193 pcf2rtc_time(&alrm->time, &pcf_tm);
194 @@ -1656,6 +1676,7 @@ static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
195 struct pcf50633_data *pcf = i2c_get_clientdata(client);
196 struct pcf50633_time pcf_tm;
197 u_int8_t irqmask;
198 + int ret;
199
200 rtc2pcf_time(&pcf_tm, &alrm->time);
201
202 @@ -1666,13 +1687,12 @@ static int pcf50633_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
203 irqmask |= PCF50633_INT1_ALARM;
204 __reg_write(pcf, PCF50633_REG_INT1M, irqmask);
205
206 - __reg_write(pcf, PCF50633_REG_RTCSCA, pcf_tm.sec);
207 - __reg_write(pcf, PCF50633_REG_RTCMNA, pcf_tm.min);
208 - __reg_write(pcf, PCF50633_REG_RTCHRA, pcf_tm.hour);
209 - __reg_write(pcf, PCF50633_REG_RTCWDA, pcf_tm.wkday);
210 - __reg_write(pcf, PCF50633_REG_RTCDTA, pcf_tm.day);
211 - __reg_write(pcf, PCF50633_REG_RTCMTA, pcf_tm.month);
212 - __reg_write(pcf, PCF50633_REG_RTCYRA, pcf_tm.year);
213 + ret = i2c_smbus_write_i2c_block_data(&pcf->client,
214 + PCF50633_REG_RTCSCA,
215 + PCF50633_TI_EXTENT,
216 + &pcf_tm.time[0]);
217 + if (ret)
218 + dev_err(dev, "Failed to write alarm time :-( %d\n", ret);
219
220 if (alrm->enabled) {
221 /* (re-)enaable alarm interrupt */
222 --
223 1.5.6.5
224
This page took 0.060047 seconds and 5 git commands to generate.