Browse Source

consolidate set_time function and remove write function again

Helmut Pozimski 5 years ago
parent
commit
3e5d944d40
1 changed files with 12 additions and 35 deletions
  1. 12 35
      rtc-ds13307.c

+ 12 - 35
rtc-ds13307.c

@@ -61,19 +61,6 @@ static int ds13307_read_bytes(struct i2c_client *client,
 	}
 }
 
-/* Writes a single byte to a specified address on the device */
-static int ds13307_write_single_byte(struct i2c_client *client, u8 *addr, u8 *byte) {
-	int r;
-	u8 buf[2];
-	buf[0] = (*addr);
-	buf[1] = (*byte);
-	r = i2c_master_send(client, buf, 2);
-	if (r != 2) {
-		return -EIO;
-	}
-	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.
  */
@@ -154,36 +141,26 @@ static int ds13307_read_time(struct device *dev, struct rtc_time *time) {
 
 static int ds13307_set_time(struct device *dev, struct rtc_time *time) {
 	struct i2c_client *client;
-	int r = 0, i;
-	u8 buf[7], addrs[7];
+	u8 buf[8];
 	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);
-	buf[3] = bin2bcd(time->tm_mday);
+	buf[0] = COMMON_SEC;
+	buf[1] = bin2bcd(time->tm_sec);
+	buf[2] = bin2bcd(time->tm_min);
+	buf[3] = bin2bcd(time->tm_hour);
+	buf[4] = bin2bcd(time->tm_wday);
+	buf[5] = bin2bcd(time->tm_mday);
 	if ((model_detected == DEVICE_DS1337) && (time->tm_year >= 100)) {
-		buf[4] = bin2bcd(time->tm_mon + 1) | COMMON_HIGH_BIT;
+		buf[6] = bin2bcd(time->tm_mon + 1) | COMMON_HIGH_BIT;
 	} else {
-		buf[4] = bin2bcd(time->tm_mon + 1);
+		buf[6] = bin2bcd(time->tm_mon + 1);
 	}
-	buf[5] = bin2bcd(time->tm_year % 100);
-	buf[6] = bin2bcd(time->tm_wday);
-	addrs[0] = COMMON_SEC;
-	addrs[1] = COMMON_MIN;
-	addrs[2] = COMMON_HOUR;
-	addrs[3] = COMMON_DATE;
-	addrs[4] = COMMON_MONTH;
-	addrs[5] = COMMON_YEAR;
-	addrs[6] = COMMON_DAY;
-	for (i=0; i<6; i++) {
-		r = ds13307_write_single_byte(client, &addrs[i], &buf[i]);
-		if (r) {
-			return -EIO;
-		}
+	buf[7] = bin2bcd(time->tm_year % 100);
+	if (i2c_master_send(client, buf, 8) != 8) {
+		return -EIO;
 	}
 	return 0;