diff options
author | Mark A. Greer <mgreer@mvista.com> | 2006-03-31 16:06:46 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-06-22 14:10:32 -0400 |
commit | e931b8d8a428f87e6ea488d2fd80007bb66b3ea8 (patch) | |
tree | 709992bdc7dee30f2eefd4b8481b09cb7dc4b670 /drivers/i2c/chips/m41t00.c | |
parent | 02e0c5d5c2e00374b6808a42f8eea4ea9baaa216 (diff) |
[PATCH] i2c: cleanup m41t00
This patch does some cleanup to the m41t00 i2c/rtc driver including:
- use BCD2BIN/BIN2BCD instead of BCD_TO_BIN/BIN_TO_BCD
- use strlcpy instead of strncpy
- some whitespace cleanup
Signed-off-by: Mark A. Greer <mgreer@mvista.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c/chips/m41t00.c')
-rw-r--r-- | drivers/i2c/chips/m41t00.c | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c index 99ab4ec34390..eb2be3e4416c 100644 --- a/drivers/i2c/chips/m41t00.c +++ b/drivers/i2c/chips/m41t00.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * drivers/i2c/chips/m41t00.c | ||
3 | * | ||
4 | * I2C client/driver for the ST M41T00 Real-Time Clock chip. | 2 | * I2C client/driver for the ST M41T00 Real-Time Clock chip. |
5 | * | 3 | * |
6 | * Author: Mark A. Greer <mgreer@mvista.com> | 4 | * Author: Mark A. Greer <mgreer@mvista.com> |
@@ -13,9 +11,6 @@ | |||
13 | /* | 11 | /* |
14 | * This i2c client/driver wedges between the drivers/char/genrtc.c RTC | 12 | * This i2c client/driver wedges between the drivers/char/genrtc.c RTC |
15 | * interface and the SMBus interface of the i2c subsystem. | 13 | * interface and the SMBus interface of the i2c subsystem. |
16 | * It would be more efficient to use i2c msgs/i2c_transfer directly but, as | ||
17 | * recommened in .../Documentation/i2c/writing-clients section | ||
18 | * "Sending and receiving", using SMBus level communication is preferred. | ||
19 | */ | 14 | */ |
20 | 15 | ||
21 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
@@ -41,17 +36,17 @@ static unsigned short ignore[] = { I2C_CLIENT_END }; | |||
41 | static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END }; | 36 | static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END }; |
42 | 37 | ||
43 | static struct i2c_client_address_data addr_data = { | 38 | static struct i2c_client_address_data addr_data = { |
44 | .normal_i2c = normal_addr, | 39 | .normal_i2c = normal_addr, |
45 | .probe = ignore, | 40 | .probe = ignore, |
46 | .ignore = ignore, | 41 | .ignore = ignore, |
47 | }; | 42 | }; |
48 | 43 | ||
49 | ulong | 44 | ulong |
50 | m41t00_get_rtc_time(void) | 45 | m41t00_get_rtc_time(void) |
51 | { | 46 | { |
52 | s32 sec, min, hour, day, mon, year; | 47 | s32 sec, min, hour, day, mon, year; |
53 | s32 sec1, min1, hour1, day1, mon1, year1; | 48 | s32 sec1, min1, hour1, day1, mon1, year1; |
54 | ulong limit = 10; | 49 | ulong limit = 10; |
55 | 50 | ||
56 | sec = min = hour = day = mon = year = 0; | 51 | sec = min = hour = day = mon = year = 0; |
57 | sec1 = min1 = hour1 = day1 = mon1 = year1 = 0; | 52 | sec1 = min1 = hour1 = day1 = mon1 = year1 = 0; |
@@ -97,12 +92,12 @@ m41t00_get_rtc_time(void) | |||
97 | mon &= 0x1f; | 92 | mon &= 0x1f; |
98 | year &= 0xff; | 93 | year &= 0xff; |
99 | 94 | ||
100 | BCD_TO_BIN(sec); | 95 | sec = BCD2BIN(sec); |
101 | BCD_TO_BIN(min); | 96 | min = BCD2BIN(min); |
102 | BCD_TO_BIN(hour); | 97 | hour = BCD2BIN(hour); |
103 | BCD_TO_BIN(day); | 98 | day = BCD2BIN(day); |
104 | BCD_TO_BIN(mon); | 99 | mon = BCD2BIN(mon); |
105 | BCD_TO_BIN(year); | 100 | year = BCD2BIN(year); |
106 | 101 | ||
107 | year += 1900; | 102 | year += 1900; |
108 | if (year < 1970) | 103 | if (year < 1970) |
@@ -115,17 +110,17 @@ static void | |||
115 | m41t00_set(void *arg) | 110 | m41t00_set(void *arg) |
116 | { | 111 | { |
117 | struct rtc_time tm; | 112 | struct rtc_time tm; |
118 | ulong nowtime = *(ulong *)arg; | 113 | ulong nowtime = *(ulong *)arg; |
119 | 114 | ||
120 | to_tm(nowtime, &tm); | 115 | to_tm(nowtime, &tm); |
121 | tm.tm_year = (tm.tm_year - 1900) % 100; | 116 | tm.tm_year = (tm.tm_year - 1900) % 100; |
122 | 117 | ||
123 | BIN_TO_BCD(tm.tm_sec); | 118 | tm.tm_sec = BIN2BCD(tm.tm_sec); |
124 | BIN_TO_BCD(tm.tm_min); | 119 | tm.tm_min = BIN2BCD(tm.tm_min); |
125 | BIN_TO_BCD(tm.tm_hour); | 120 | tm.tm_hour = BIN2BCD(tm.tm_hour); |
126 | BIN_TO_BCD(tm.tm_mon); | 121 | tm.tm_mon = BIN2BCD(tm.tm_mon); |
127 | BIN_TO_BCD(tm.tm_mday); | 122 | tm.tm_mday = BIN2BCD(tm.tm_mday); |
128 | BIN_TO_BCD(tm.tm_year); | 123 | tm.tm_year = BIN2BCD(tm.tm_year); |
129 | 124 | ||
130 | mutex_lock(&m41t00_mutex); | 125 | mutex_lock(&m41t00_mutex); |
131 | if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0) | 126 | if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0) |
@@ -143,7 +138,6 @@ m41t00_set(void *arg) | |||
143 | dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n"); | 138 | dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n"); |
144 | 139 | ||
145 | mutex_unlock(&m41t00_mutex); | 140 | mutex_unlock(&m41t00_mutex); |
146 | return; | ||
147 | } | 141 | } |
148 | 142 | ||
149 | static ulong new_time; | 143 | static ulong new_time; |
@@ -180,7 +174,7 @@ m41t00_probe(struct i2c_adapter *adap, int addr, int kind) | |||
180 | if (!client) | 174 | if (!client) |
181 | return -ENOMEM; | 175 | return -ENOMEM; |
182 | 176 | ||
183 | strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); | 177 | strlcpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); |
184 | client->addr = addr; | 178 | client->addr = addr; |
185 | client->adapter = adap; | 179 | client->adapter = adap; |
186 | client->driver = &m41t00_driver; | 180 | client->driver = &m41t00_driver; |
@@ -204,7 +198,7 @@ m41t00_attach(struct i2c_adapter *adap) | |||
204 | static int | 198 | static int |
205 | m41t00_detach(struct i2c_client *client) | 199 | m41t00_detach(struct i2c_client *client) |
206 | { | 200 | { |
207 | int rc; | 201 | int rc; |
208 | 202 | ||
209 | if ((rc = i2c_detach_client(client)) == 0) { | 203 | if ((rc = i2c_detach_client(client)) == 0) { |
210 | kfree(client); | 204 | kfree(client); |
@@ -232,7 +226,6 @@ static void __exit | |||
232 | m41t00_exit(void) | 226 | m41t00_exit(void) |
233 | { | 227 | { |
234 | i2c_del_driver(&m41t00_driver); | 228 | i2c_del_driver(&m41t00_driver); |
235 | return; | ||
236 | } | 229 | } |
237 | 230 | ||
238 | module_init(m41t00_init); | 231 | module_init(m41t00_init); |