aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAndreas Werner <andreas.werner@men.de>2014-01-23 18:55:20 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-23 19:37:00 -0500
commitd643a49ae16c755b3dc2ef897438b7d9c6dd488b (patch)
treed42119aac86d8ef8a9410620a57bd10eccff2c6c /drivers/rtc
parent11ba5a1eeb5406c58ffda0fc07360b2ef5c4f176 (diff)
drivers/rtc/rtc-rx8581.c: add SMBus-only adapters support
Add support for SMBus-only adapters (e.g. i2c-piix4). The driver has implemented only support for I2C adapters which implement the I2C_FUNC_SMBUS_I2C_BLOCK functionality before. With this patch it is possible to load and use the RTC driver with I2C and SMBUS adapters like the rtc-ds1307 does. Tested on AMD G Series Platform (i2c-piix4 adapter driver). Signed-off-by: Andreas Werner <andreas.werner@men.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-rx8581.c81
1 files changed, 68 insertions, 13 deletions
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
index 00b0eb7fe166..de8d9c427782 100644
--- a/drivers/rtc/rtc-rx8581.c
+++ b/drivers/rtc/rtc-rx8581.c
@@ -52,8 +52,45 @@
52#define RX8581_CTRL_STOP 0x02 /* STOP bit */ 52#define RX8581_CTRL_STOP 0x02 /* STOP bit */
53#define RX8581_CTRL_RESET 0x01 /* RESET bit */ 53#define RX8581_CTRL_RESET 0x01 /* RESET bit */
54 54
55struct rx8581 {
56 struct i2c_client *client;
57 struct rtc_device *rtc;
58 s32 (*read_block_data)(const struct i2c_client *client, u8 command,
59 u8 length, u8 *values);
60 s32 (*write_block_data)(const struct i2c_client *client, u8 command,
61 u8 length, const u8 *values);
62};
63
55static struct i2c_driver rx8581_driver; 64static struct i2c_driver rx8581_driver;
56 65
66static int rx8581_read_block_data(const struct i2c_client *client, u8 command,
67 u8 length, u8 *values)
68{
69 s32 i, data;
70
71 for (i = 0; i < length; i++) {
72 data = i2c_smbus_read_byte_data(client, command + i);
73 if (data < 0)
74 return data;
75 values[i] = data;
76 }
77 return i;
78}
79
80static int rx8581_write_block_data(const struct i2c_client *client, u8 command,
81 u8 length, const u8 *values)
82{
83 s32 i, ret;
84
85 for (i = 0; i < length; i++) {
86 ret = i2c_smbus_write_byte_data(client, command + i,
87 values[i]);
88 if (ret < 0)
89 return ret;
90 }
91 return length;
92}
93
57/* 94/*
58 * In the routines that deal directly with the rx8581 hardware, we use 95 * In the routines that deal directly with the rx8581 hardware, we use
59 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 96 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
@@ -62,6 +99,7 @@ static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm)
62{ 99{
63 unsigned char date[7]; 100 unsigned char date[7];
64 int data, err; 101 int data, err;
102 struct rx8581 *rx8581 = i2c_get_clientdata(client);
65 103
66 /* First we ensure that the "update flag" is not set, we read the 104 /* First we ensure that the "update flag" is not set, we read the
67 * time and date then re-read the "update flag". If the update flag 105 * time and date then re-read the "update flag". If the update flag
@@ -80,14 +118,13 @@ static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm)
80 err = i2c_smbus_write_byte_data(client, 118 err = i2c_smbus_write_byte_data(client,
81 RX8581_REG_FLAG, (data & ~RX8581_FLAG_UF)); 119 RX8581_REG_FLAG, (data & ~RX8581_FLAG_UF));
82 if (err != 0) { 120 if (err != 0) {
83 dev_err(&client->dev, "Unable to write device " 121 dev_err(&client->dev, "Unable to write device flags\n");
84 "flags\n");
85 return -EIO; 122 return -EIO;
86 } 123 }
87 } 124 }
88 125
89 /* Now read time and date */ 126 /* Now read time and date */
90 err = i2c_smbus_read_i2c_block_data(client, RX8581_REG_SC, 127 err = rx8581->read_block_data(client, RX8581_REG_SC,
91 7, date); 128 7, date);
92 if (err < 0) { 129 if (err < 0) {
93 dev_err(&client->dev, "Unable to read date\n"); 130 dev_err(&client->dev, "Unable to read date\n");
@@ -140,6 +177,7 @@ static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm)
140{ 177{
141 int data, err; 178 int data, err;
142 unsigned char buf[7]; 179 unsigned char buf[7];
180 struct rx8581 *rx8581 = i2c_get_clientdata(client);
143 181
144 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " 182 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
145 "mday=%d, mon=%d, year=%d, wday=%d\n", 183 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -176,7 +214,7 @@ static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm)
176 } 214 }
177 215
178 /* write register's data */ 216 /* write register's data */
179 err = i2c_smbus_write_i2c_block_data(client, RX8581_REG_SC, 7, buf); 217 err = rx8581->write_block_data(client, RX8581_REG_SC, 7, buf);
180 if (err < 0) { 218 if (err < 0) {
181 dev_err(&client->dev, "Unable to write to date registers\n"); 219 dev_err(&client->dev, "Unable to write to date registers\n");
182 return -EIO; 220 return -EIO;
@@ -231,22 +269,39 @@ static const struct rtc_class_ops rx8581_rtc_ops = {
231static int rx8581_probe(struct i2c_client *client, 269static int rx8581_probe(struct i2c_client *client,
232 const struct i2c_device_id *id) 270 const struct i2c_device_id *id)
233{ 271{
234 struct rtc_device *rtc; 272 struct rx8581 *rx8581;
235 273
236 dev_dbg(&client->dev, "%s\n", __func__); 274 dev_dbg(&client->dev, "%s\n", __func__);
237 275
238 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 276 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)
239 return -ENODEV; 277 && !i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
278 return -EIO;
240 279
241 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 280 rx8581 = devm_kzalloc(&client->dev, sizeof(struct rx8581), GFP_KERNEL);
281 if (!rx8581)
282 return -ENOMEM;
242 283
243 rtc = devm_rtc_device_register(&client->dev, rx8581_driver.driver.name, 284 i2c_set_clientdata(client, rx8581);
244 &rx8581_rtc_ops, THIS_MODULE); 285 rx8581->client = client;
245 286
246 if (IS_ERR(rtc)) 287 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
247 return PTR_ERR(rtc); 288 rx8581->read_block_data = i2c_smbus_read_i2c_block_data;
289 rx8581->write_block_data = i2c_smbus_write_i2c_block_data;
290 } else {
291 rx8581->read_block_data = rx8581_read_block_data;
292 rx8581->write_block_data = rx8581_write_block_data;
293 }
248 294
249 i2c_set_clientdata(client, rtc); 295 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
296
297 rx8581->rtc = devm_rtc_device_register(&client->dev,
298 rx8581_driver.driver.name, &rx8581_rtc_ops, THIS_MODULE);
299
300 if (IS_ERR(rx8581->rtc)) {
301 dev_err(&client->dev,
302 "unable to register the class device\n");
303 return PTR_ERR(rx8581->rtc);
304 }
250 305
251 return 0; 306 return 0;
252} 307}