Browse Source

move clearing of the oscillator bit to the time set function

Helmut Pozimski 5 years ago
parent
commit
05f7427d14
1 changed files with 34 additions and 34 deletions
  1. 34 34
      rtc-ds13307.c

+ 34 - 34
rtc-ds13307.c

@@ -74,6 +74,36 @@ static int ds13307_write_single_byte(struct i2c_client *client, u8 *addr, u8 *by
 	return 0;
 }
 
+/* The oscillator is stopped for both chips when power is first applied,
+ * therefore this function checks its status and clears the stop bit.
+ */
+static int ds13307_start_oscillator(struct i2c_client *client) {
+	u8 data;
+	int r, v;
+	unsigned char addr;
+	char buf[2];
+	if (model_detected == DEVICE_DS1307) {
+		addr = COMMON_SEC;
+	} else {
+		addr = DS1337_STAT;
+	}
+	r = ds13307_read_bytes(client, &addr, &data, 1);
+	if (data & COMMON_HIGH_BIT) {
+		buf[0] = addr;
+		buf[1] = data ^ COMMON_HIGH_BIT;
+		v = i2c_master_send(client, buf, 2);
+		if (v == 2) {
+			printk(KERN_DEBUG "%s: oscillator stop bit successfully cleared\n", M_NAME);
+		}
+	} else {
+		v = 2;
+	}
+	if ((r<0) || (v!=2)) {
+		return -EIO;
+	}
+	return 0;
+}
+
 static int ds13307_read_time(struct device *dev, struct rtc_time *time) {
 	struct i2c_client *client;
 	int r;
@@ -125,6 +155,10 @@ static int ds13307_set_time(struct device *dev, struct rtc_time *time) {
 	int r = 0, i;
 	u8 buf[7], addrs[7];
 	client = to_i2c_client(dev);
+	if (ds13307_start_oscillator(client)) {
+		printk(KERN_ERR "%s: failed to initialize the oscillator\n", M_NAME);
+		return -EIO;
+	}
 	buf[0] = bin2bcd(time->tm_sec);
 	buf[1] = bin2bcd(time->tm_min);
 	buf[2] = bin2bcd(time->tm_hour);
@@ -182,36 +216,6 @@ static int ds13307_detect_device(struct i2c_client *client) {
 	return -1;
 }
 
-/* The oscillator is stopped for both chips when power is first applied,
- * therefore this function checks its status and clears the stop bit.
- */
-static int ds13307_start_oscillator(struct i2c_client *client) {
-	u8 data;
-	int r, v;
-       	unsigned char addr;
-	char buf[2];
-	if (model_detected == DEVICE_DS1307) {
-		addr = COMMON_SEC;
-	} else {
-		addr = DS1337_STAT;
-	}
-	r = ds13307_read_bytes(client, &addr, &data, 1);
-	if (data & COMMON_HIGH_BIT) {
-		buf[0] = addr;
-		buf[1] = data ^ COMMON_HIGH_BIT;
-		v = i2c_master_send(client, buf, 2);
-		if (v == 2) {
-			printk(KERN_DEBUG "%s: oscillator stop bit successfully cleared\n", M_NAME);
-		}
-	} else {
-		v = 2;
-	}
-	if ((r<0) || (v!=2)) {
-		return -EIO;
-	} 
-	return 0;	
-}
-
 static int ds13307_probe(struct i2c_client *client,
 		const struct i2c_device_id *id) {
 	struct rtc_device *rtc;
@@ -219,10 +223,6 @@ static int ds13307_probe(struct i2c_client *client,
 	if ((model_detected != DEVICE_DS1307) && (model_detected != DEVICE_DS1337)) {
 		return -EIO;
 	}
-	if (ds13307_start_oscillator(client)) {
-		printk(KERN_ERR "%s: failed to initialize the oscillator\n", M_NAME);
-		return -EIO;
-	} 
 	rtc = devm_rtc_device_register(&client->dev, ds13307_driver.driver.name,
 		&ds13307_rtc_ops, THIS_MODULE);