static int ds1374_wdt_settimeout(unsigned int timeout) { int ret = -ENOIOCTLCMD; int cr; ret = cr = i2c_smbus_read_byte_data(save_client, DS1374_REG_CR); if (ret < 0) goto out; /* Disable any existing watchdog/alarm before setting the new one */ cr &= ~DS1374_REG_CR_WACE; ret = i2c_smbus_write_byte_data(save_client, DS1374_REG_CR, cr); if (ret < 0) goto out; /* Set new watchdog time */ ret = ds1374_write_rtc(save_client, timeout, DS1374_REG_WDALM0, 3); if (ret) { pr_info("couldn't set new watchdog time\n"); goto out; } /* Enable watchdog timer */ cr |= DS1374_REG_CR_WACE | DS1374_REG_CR_WDALM; cr &= ~DS1374_REG_CR_AIE; ret = i2c_smbus_write_byte_data(save_client, DS1374_REG_CR, cr); if (ret < 0) goto out; return 0; out: return ret; }
static void ds1374_set_tlet(ulong arg) { ulong t1, t2; int limit = 10; /* arbitrary retry limit */ t1 = *(ulong *) arg; down(&ds1374_mutex); /* * Since the writes are being performed one byte at a time using * the SMBus vs a 4-byte i2c transfer, there is a chance that a * carry will occur during the write. To detect this, the write * value is read back and compared. */ do { ds1374_write_rtc(t1); t2 = ds1374_read_rtc(); } while (t1 != t2 && limit--); up(&ds1374_mutex); if (t1 != t2) dev_warn(&save_client->dev, "can't confirm time set from rtc chip\n"); }
static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct i2c_client *client = to_i2c_client(dev); struct ds1374 *ds1374 = i2c_get_clientdata(client); struct rtc_time now; unsigned long new_alarm, itime; int cr; int ret = 0; if (client->irq <= 0) return -EINVAL; ret = ds1374_read_time(dev, &now); if (ret < 0) return ret; rtc_tm_to_time(&alarm->time, &new_alarm); rtc_tm_to_time(&now, &itime); /* This can happen due to races, in addition to dates that are * truly in the past. To avoid requiring the caller to check for * races, dates in the past are assumed to be in the recent past * (i.e. not something that we'd rather the caller know about via * an error), and the alarm is set to go off as soon as possible. */ if (time_before_eq(new_alarm, itime)) new_alarm = 1; else new_alarm -= itime; mutex_lock(&ds1374->mutex); ret = cr = i2c_smbus_read_byte_data(client, DS1374_REG_CR); if (ret < 0) goto out; /* Disable any existing alarm before setting the new one * (or lack thereof). */ cr &= ~DS1374_REG_CR_WACE; ret = i2c_smbus_write_byte_data(client, DS1374_REG_CR, cr); if (ret < 0) goto out; ret = ds1374_write_rtc(client, new_alarm, DS1374_REG_WDALM0, 3); if (ret) goto out; if (alarm->enabled) { cr |= DS1374_REG_CR_WACE | DS1374_REG_CR_AIE; cr &= ~DS1374_REG_CR_WDALM; ret = i2c_smbus_write_byte_data(client, DS1374_REG_CR, cr); } out: mutex_unlock(&ds1374->mutex); return ret; }
static int ds1374_set_time(struct device *dev, struct rtc_time *time) { struct i2c_client *client = to_i2c_client(dev); unsigned long itime; rtc_tm_to_time(time, &itime); return ds1374_write_rtc(client, itime, DS1374_REG_TOD0, 4); }
static int ds1374_set_time(struct device *dev, struct rtc_time *time) { struct ds1374 *ds1374 = dev_get_drvdata(dev); unsigned long itime; rtc_tm_to_time(time, &itime); return ds1374_write_rtc(&ds1374->client, itime, DS1374_REG_TOD0, 4); }