Lines Matching +full:- +full:- +full:trim +full:- +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
116 * - we're in the 21st century, so it's safe to ignore the century
118 * - we should use ALARM_A not ALARM_B (may be wrong on some boards)
133 struct i2c_client *client = rs5c->client; in rs5c_get_regs()
136 .addr = client->addr, in rs5c_get_regs()
138 .len = sizeof(rs5c->buf), in rs5c_get_regs()
139 .buf = rs5c->buf in rs5c_get_regs()
150 * The third method on the other hand doesn't work for the SMBus-only in rs5c_get_regs()
154 if (rs5c->smbus) { in rs5c_get_regs()
156 int size = sizeof(rs5c->buf) - 1; in rs5c_get_regs()
159 rs5c->buf + 1) != size) { in rs5c_get_regs()
160 dev_warn(&client->dev, "can't read registers\n"); in rs5c_get_regs()
161 return -EIO; in rs5c_get_regs()
164 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) { in rs5c_get_regs()
165 dev_warn(&client->dev, "can't read registers\n"); in rs5c_get_regs()
166 return -EIO; in rs5c_get_regs()
170 dev_dbg(&client->dev, in rs5c_get_regs()
172 rs5c->regs + 0, rs5c->regs[3], in rs5c_get_regs()
173 rs5c->regs + 4, rs5c->regs[7], in rs5c_get_regs()
174 rs5c->regs + 8, rs5c->regs + 11, in rs5c_get_regs()
175 rs5c->regs[14], rs5c->regs[15]); in rs5c_get_regs()
184 if (rs5c->time24) in rs5c_reg2hr()
197 if (rs5c->time24) in rs5c_hr2reg()
201 return 0x20 | bin2bcd(hour - 12); in rs5c_hr2reg()
214 unsigned char ctrl2 = rs5c->regs[RS5C_REG_CTRL2]; in rs5c372_rtc_read_time()
219 switch (rs5c->type) { in rs5c372_rtc_read_time()
222 if ((rs5c->type == rtc_r2025sd && !(ctrl2 & R2x2x_CTRL2_XSTP)) || in rs5c372_rtc_read_time()
223 (rs5c->type == rtc_r2221tl && (ctrl2 & R2x2x_CTRL2_XSTP))) { in rs5c372_rtc_read_time()
224 dev_warn(&client->dev, "rtc oscillator interruption detected. Please reset the rtc clock.\n"); in rs5c372_rtc_read_time()
225 return -EINVAL; in rs5c372_rtc_read_time()
230 dev_warn(&client->dev, "rtc oscillator interruption detected. Please reset the rtc clock.\n"); in rs5c372_rtc_read_time()
231 return -EINVAL; in rs5c372_rtc_read_time()
235 tm->tm_sec = bcd2bin(rs5c->regs[RS5C372_REG_SECS] & 0x7f); in rs5c372_rtc_read_time()
236 tm->tm_min = bcd2bin(rs5c->regs[RS5C372_REG_MINS] & 0x7f); in rs5c372_rtc_read_time()
237 tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]); in rs5c372_rtc_read_time()
239 tm->tm_wday = bcd2bin(rs5c->regs[RS5C372_REG_WDAY] & 0x07); in rs5c372_rtc_read_time()
240 tm->tm_mday = bcd2bin(rs5c->regs[RS5C372_REG_DAY] & 0x3f); in rs5c372_rtc_read_time()
242 /* tm->tm_mon is zero-based */ in rs5c372_rtc_read_time()
243 tm->tm_mon = bcd2bin(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; in rs5c372_rtc_read_time()
245 /* year is 1900 + tm->tm_year */ in rs5c372_rtc_read_time()
246 tm->tm_year = bcd2bin(rs5c->regs[RS5C372_REG_YEAR]) + 100; in rs5c372_rtc_read_time()
248 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " in rs5c372_rtc_read_time()
251 tm->tm_sec, tm->tm_min, tm->tm_hour, in rs5c372_rtc_read_time()
252 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); in rs5c372_rtc_read_time()
265 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " in rs5c372_rtc_set_time()
268 tm->tm_sec, tm->tm_min, tm->tm_hour, in rs5c372_rtc_set_time()
269 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); in rs5c372_rtc_set_time()
272 buf[0] = bin2bcd(tm->tm_sec); in rs5c372_rtc_set_time()
273 buf[1] = bin2bcd(tm->tm_min); in rs5c372_rtc_set_time()
274 buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour); in rs5c372_rtc_set_time()
275 buf[3] = bin2bcd(tm->tm_wday); in rs5c372_rtc_set_time()
276 buf[4] = bin2bcd(tm->tm_mday); in rs5c372_rtc_set_time()
277 buf[5] = bin2bcd(tm->tm_mon + 1); in rs5c372_rtc_set_time()
278 buf[6] = bin2bcd(tm->tm_year - 100); in rs5c372_rtc_set_time()
281 dev_dbg(&client->dev, "%s: write error in line %i\n", in rs5c372_rtc_set_time()
283 return -EIO; in rs5c372_rtc_set_time()
290 switch (rs5c->type) { in rs5c372_rtc_set_time()
294 if (rs5c->type == rtc_r2025sd) in rs5c372_rtc_set_time()
305 dev_dbg(&client->dev, "%s: write error in line %i\n", in rs5c372_rtc_set_time()
307 return -EIO; in rs5c372_rtc_set_time()
322 static int rs5c372_get_trim(struct i2c_client *client, int *osc, int *trim) in rs5c372_get_trim() argument
325 u8 tmp = rs5c372->regs[RS5C372_REG_TRIM]; in rs5c372_get_trim()
330 if (trim) { in rs5c372_get_trim()
331 dev_dbg(&client->dev, "%s: raw trim=%x\n", __func__, tmp); in rs5c372_get_trim()
339 t = t - 1; in rs5c372_get_trim()
344 *trim = tmp; in rs5c372_get_trim()
358 buf = rs5c->regs[RS5C_REG_CTRL1]; in rs5c_rtc_alarm_irq_enable()
360 if (!rs5c->has_irq) in rs5c_rtc_alarm_irq_enable()
361 return -EINVAL; in rs5c_rtc_alarm_irq_enable()
375 status = -EIO; in rs5c_rtc_alarm_irq_enable()
377 rs5c->regs[RS5C_REG_CTRL1] = buf; in rs5c_rtc_alarm_irq_enable()
403 t->time.tm_sec = 0; in rs5c_read_alarm()
404 t->time.tm_min = bcd2bin(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f); in rs5c_read_alarm()
405 t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]); in rs5c_read_alarm()
408 t->enabled = !!(rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE); in rs5c_read_alarm()
409 t->pending = !!(rs5c->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_AAFG); in rs5c_read_alarm()
422 if (t->time.tm_mday != -1 in rs5c_set_alarm()
423 || t->time.tm_mon != -1 in rs5c_set_alarm()
424 || t->time.tm_year != -1) in rs5c_set_alarm()
425 return -EINVAL; in rs5c_set_alarm()
433 if (rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE) { in rs5c_set_alarm()
435 buf[0] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE; in rs5c_set_alarm()
438 return -EIO; in rs5c_set_alarm()
440 rs5c->regs[RS5C_REG_CTRL1] = buf[0]; in rs5c_set_alarm()
444 buf[0] = bin2bcd(t->time.tm_min); in rs5c_set_alarm()
445 buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour); in rs5c_set_alarm()
452 return -EIO; in rs5c_set_alarm()
457 if (t->enabled) { in rs5c_set_alarm()
459 buf[0] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE; in rs5c_set_alarm()
462 rs5c->regs[RS5C_REG_CTRL1] = buf[0]; in rs5c_set_alarm()
472 int err, osc, trim; in rs5c372_rtc_proc() local
474 err = rs5c372_get_trim(to_i2c_client(dev), &osc, &trim); in rs5c372_rtc_proc()
478 seq_printf(seq, "trim\t\t: %d\n", trim); in rs5c372_rtc_proc()
502 int err, trim; in rs5c372_sysfs_show_trim() local
504 err = rs5c372_get_trim(to_i2c_client(dev), NULL, &trim); in rs5c372_sysfs_show_trim()
508 return sprintf(buf, "%d\n", trim); in rs5c372_sysfs_show_trim()
510 static DEVICE_ATTR(trim, S_IRUGO, rs5c372_sysfs_show_trim, NULL);
565 buf[0] = rs5c372->regs[RS5C_REG_CTRL1]; in rs5c_oscillator_setup()
566 buf[1] = rs5c372->regs[RS5C_REG_CTRL2]; in rs5c_oscillator_setup()
568 switch (rs5c372->type) { in rs5c_oscillator_setup()
584 switch (rs5c372->type) { in rs5c_oscillator_setup()
588 rs5c372->time24 = 1; in rs5c_oscillator_setup()
595 rs5c372->time24 = 1; in rs5c_oscillator_setup()
604 ret = i2c_smbus_write_byte_data(rs5c372->client, addr, buf[i]); in rs5c_oscillator_setup()
609 rs5c372->regs[RS5C_REG_CTRL1] = buf[0]; in rs5c_oscillator_setup()
610 rs5c372->regs[RS5C_REG_CTRL2] = buf[1]; in rs5c_oscillator_setup()
622 dev_dbg(&client->dev, "%s\n", __func__); in rs5c372_probe()
624 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | in rs5c372_probe()
630 if (i2c_check_functionality(client->adapter, in rs5c372_probe()
636 err = -ENODEV; in rs5c372_probe()
641 rs5c372 = devm_kzalloc(&client->dev, sizeof(struct rs5c372), in rs5c372_probe()
644 err = -ENOMEM; in rs5c372_probe()
648 rs5c372->client = client; in rs5c372_probe()
650 if (client->dev.of_node) in rs5c372_probe()
651 rs5c372->type = (enum rtc_type) in rs5c372_probe()
652 of_device_get_match_data(&client->dev); in rs5c372_probe()
654 rs5c372->type = id->driver_data; in rs5c372_probe()
656 /* we read registers 0x0f then 0x00-0x0f; skip the first one */ in rs5c372_probe()
657 rs5c372->regs = &rs5c372->buf[1]; in rs5c372_probe()
658 rs5c372->smbus = smbus_mode; in rs5c372_probe()
665 switch (rs5c372->type) { in rs5c372_probe()
671 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C372_CTRL2_24) in rs5c372_probe()
672 rs5c372->time24 = 1; in rs5c372_probe()
678 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24) in rs5c372_probe()
679 rs5c372->time24 = 1; in rs5c372_probe()
685 dev_err(&client->dev, "unknown RTC type\n"); in rs5c372_probe()
697 dev_err(&client->dev, "setup error\n"); in rs5c372_probe()
701 dev_info(&client->dev, "%s found, %s\n", in rs5c372_probe()
702 ({ char *s; switch (rs5c372->type) { in rs5c372_probe()
711 rs5c372->time24 ? "24hr" : "am/pm" in rs5c372_probe()
714 /* REVISIT use client->irq to register alarm irq ... */ in rs5c372_probe()
715 rs5c372->rtc = devm_rtc_device_register(&client->dev, in rs5c372_probe()
719 if (IS_ERR(rs5c372->rtc)) { in rs5c372_probe()
720 err = PTR_ERR(rs5c372->rtc); in rs5c372_probe()
724 err = rs5c_sysfs_register(&client->dev); in rs5c372_probe()
736 rs5c_sysfs_unregister(&client->dev); in rs5c372_remove()
742 .name = "rtc-rs5c372",
755 "Paul Mundt <lethal@linux-sh.org>");