static void ds1374_set_work(struct work_struct *work) { ulong t1, t2; int limit = 10; /* arbitrary retry limit */ t1 = new_time; mutex_lock(&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--); mutex_unlock(&ds1374_mutex); if (t1 != t2) dev_warn(&save_client->dev, "can't confirm time set from rtc chip\n"); }
/* * Reload the watchdog timer. (ie, pat the watchdog) */ static void ds1374_wdt_ping(void) { u32 val; int ret = 0; ret = ds1374_read_rtc(save_client, &val, DS1374_REG_WDALM0, 3); if (ret) pr_info("WD TICK FAIL!!!!!!!!!! %i\n", ret); }
static int ds1374_read_time(struct device *dev, struct rtc_time *time) { struct i2c_client *client = to_i2c_client(dev); u32 itime; int ret; ret = ds1374_read_rtc(client, &itime, DS1374_REG_TOD0, 4); if (!ret) rtc_time_to_tm(itime, time); return ret; }
static int ds1374_read_time(struct device *dev, struct rtc_time *time) { struct ds1374 *ds1374 = dev_get_drvdata(dev); u32 itime; int ret; ret = ds1374_read_rtc(&ds1374->client, &itime, DS1374_REG_TOD0, 4); if (!ret) rtc_time_to_tm(itime, time); return ret; }
/* The ds1374 has a decrementer for an alarm, rather than a comparator. * If the time of day is changed, then the alarm will need to be * reset. */ static int ds1374_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct i2c_client *client = to_i2c_client(dev); struct ds1374 *ds1374 = i2c_get_clientdata(client); u32 now, cur_alarm; int cr, sr; int ret = 0; if (client->irq <= 0) return -EINVAL; mutex_lock(&ds1374->mutex); cr = ret = i2c_smbus_read_byte_data(client, DS1374_REG_CR); if (ret < 0) goto out; sr = ret = i2c_smbus_read_byte_data(client, DS1374_REG_SR); if (ret < 0) goto out; ret = ds1374_read_rtc(client, &now, DS1374_REG_TOD0, 4); if (ret) goto out; ret = ds1374_read_rtc(client, &cur_alarm, DS1374_REG_WDALM0, 3); if (ret) goto out; rtc_time_to_tm(now + cur_alarm, &alarm->time); alarm->enabled = !!(cr & DS1374_REG_CR_WACE); alarm->pending = !!(sr & DS1374_REG_SR_AF); out: mutex_unlock(&ds1374->mutex); return ret; }