aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1672.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-ds1672.c')
-rw-r--r--drivers/rtc/rtc-ds1672.c72
1 files changed, 58 insertions, 14 deletions
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 358695a416f3..9be81fd4737c 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * An rtc/i2c driver for the Dallas DS1672 2 * An rtc/i2c driver for the Dallas DS1672
3 * Copyright 2005 Alessandro Zummo 3 * Copyright 2005-06 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
4 * 6 *
5 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -11,7 +13,7 @@
11#include <linux/i2c.h> 13#include <linux/i2c.h>
12#include <linux/rtc.h> 14#include <linux/rtc.h>
13 15
14#define DRV_VERSION "0.2" 16#define DRV_VERSION "0.3"
15 17
16/* Addresses to scan: none. This chip cannot be detected. */ 18/* Addresses to scan: none. This chip cannot be detected. */
17static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 19static unsigned short normal_i2c[] = { I2C_CLIENT_END };
@@ -25,6 +27,7 @@ I2C_CLIENT_INSMOD;
25#define DS1672_REG_CONTROL 4 27#define DS1672_REG_CONTROL 4
26#define DS1672_REG_TRICKLE 5 28#define DS1672_REG_TRICKLE 5
27 29
30#define DS1672_REG_CONTROL_EOSC 0x80
28 31
29/* Prototypes */ 32/* Prototypes */
30static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind); 33static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind);
@@ -53,8 +56,7 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
53 56
54 dev_dbg(&client->dev, 57 dev_dbg(&client->dev,
55 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n" 58 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n"
56 __FUNCTION__, 59 __FUNCTION__, buf[0], buf[1], buf[2], buf[3]);
57 buf[0], buf[1], buf[2], buf[3]);
58 60
59 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; 61 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
60 62
@@ -62,8 +64,7 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
62 64
63 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 65 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
64 "mday=%d, mon=%d, year=%d, wday=%d\n", 66 "mday=%d, mon=%d, year=%d, wday=%d\n",
65 __FUNCTION__, 67 __FUNCTION__, tm->tm_sec, tm->tm_min, tm->tm_hour,
66 tm->tm_sec, tm->tm_min, tm->tm_hour,
67 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 68 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
68 69
69 return 0; 70 return 0;
@@ -72,16 +73,17 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
72static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs) 73static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
73{ 74{
74 int xfer; 75 int xfer;
75 unsigned char buf[5]; 76 unsigned char buf[6];
76 77
77 buf[0] = DS1672_REG_CNT_BASE; 78 buf[0] = DS1672_REG_CNT_BASE;
78 buf[1] = secs & 0x000000FF; 79 buf[1] = secs & 0x000000FF;
79 buf[2] = (secs & 0x0000FF00) >> 8; 80 buf[2] = (secs & 0x0000FF00) >> 8;
80 buf[3] = (secs & 0x00FF0000) >> 16; 81 buf[3] = (secs & 0x00FF0000) >> 16;
81 buf[4] = (secs & 0xFF000000) >> 24; 82 buf[4] = (secs & 0xFF000000) >> 24;
83 buf[5] = 0; /* set control reg to enable counting */
82 84
83 xfer = i2c_master_send(client, buf, 5); 85 xfer = i2c_master_send(client, buf, 6);
84 if (xfer != 5) { 86 if (xfer != 6) {
85 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer); 87 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer);
86 return -EIO; 88 return -EIO;
87 } 89 }
@@ -120,6 +122,40 @@ static int ds1672_rtc_set_mmss(struct device *dev, unsigned long secs)
120 return ds1672_set_mmss(to_i2c_client(dev), secs); 122 return ds1672_set_mmss(to_i2c_client(dev), secs);
121} 123}
122 124
125static int ds1672_get_control(struct i2c_client *client, u8 *status)
126{
127 unsigned char addr = DS1672_REG_CONTROL;
128
129 struct i2c_msg msgs[] = {
130 { client->addr, 0, 1, &addr }, /* setup read ptr */
131 { client->addr, I2C_M_RD, 1, status }, /* read control */
132 };
133
134 /* read control register */
135 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
136 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
137 return -EIO;
138 }
139
140 return 0;
141}
142
143/* following are the sysfs callback functions */
144static ssize_t show_control(struct device *dev, struct device_attribute *attr, char *buf)
145{
146 struct i2c_client *client = to_i2c_client(dev);
147 u8 control;
148 int err;
149
150 err = ds1672_get_control(client, &control);
151 if (err)
152 return err;
153
154 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
155 ? "disabled" : "enabled");
156}
157static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
158
123static struct rtc_class_ops ds1672_rtc_ops = { 159static struct rtc_class_ops ds1672_rtc_ops = {
124 .read_time = ds1672_rtc_read_time, 160 .read_time = ds1672_rtc_read_time,
125 .set_time = ds1672_rtc_set_time, 161 .set_time = ds1672_rtc_set_time,
@@ -128,7 +164,6 @@ static struct rtc_class_ops ds1672_rtc_ops = {
128 164
129static int ds1672_attach(struct i2c_adapter *adapter) 165static int ds1672_attach(struct i2c_adapter *adapter)
130{ 166{
131 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
132 return i2c_probe(adapter, &addr_data, ds1672_probe); 167 return i2c_probe(adapter, &addr_data, ds1672_probe);
133} 168}
134 169
@@ -137,8 +172,6 @@ static int ds1672_detach(struct i2c_client *client)
137 int err; 172 int err;
138 struct rtc_device *rtc = i2c_get_clientdata(client); 173 struct rtc_device *rtc = i2c_get_clientdata(client);
139 174
140 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
141
142 if (rtc) 175 if (rtc)
143 rtc_device_unregister(rtc); 176 rtc_device_unregister(rtc);
144 177
@@ -162,6 +195,7 @@ static struct i2c_driver ds1672_driver = {
162static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind) 195static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
163{ 196{
164 int err = 0; 197 int err = 0;
198 u8 control;
165 struct i2c_client *client; 199 struct i2c_client *client;
166 struct rtc_device *rtc; 200 struct rtc_device *rtc;
167 201
@@ -195,13 +229,23 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
195 229
196 if (IS_ERR(rtc)) { 230 if (IS_ERR(rtc)) {
197 err = PTR_ERR(rtc); 231 err = PTR_ERR(rtc);
198 dev_err(&client->dev,
199 "unable to register the class device\n");
200 goto exit_detach; 232 goto exit_detach;
201 } 233 }
202 234
203 i2c_set_clientdata(client, rtc); 235 i2c_set_clientdata(client, rtc);
204 236
237 /* read control register */
238 err = ds1672_get_control(client, &control);
239 if (err)
240 goto exit_detach;
241
242 if (control & DS1672_REG_CONTROL_EOSC)
243 dev_warn(&client->dev, "Oscillator not enabled. "
244 "Set time to enable.\n");
245
246 /* Register sysfs hooks */
247 device_create_file(&client->dev, &dev_attr_control);
248
205 return 0; 249 return 0;
206 250
207exit_detach: 251exit_detach: