Lines Matching refs:ds1305

3  * rtc-ds1305.c -- driver for DS1305 and DS1306 SPI RTC chips
15 #include <linux/spi/ds1305.h>
76 /* trickle bits are defined in <linux/spi/ds1305.h> */
84 struct ds1305 {
141 struct ds1305 *ds1305 = dev_get_drvdata(dev);
146 buf[1] = ds1305->ctrl[0];
149 if (ds1305->ctrl[0] & DS1305_AEI0)
157 err = spi_write_then_read(ds1305->spi, buf, sizeof(buf), NULL, 0);
159 ds1305->ctrl[0] = buf[1];
172 struct ds1305 *ds1305 = dev_get_drvdata(dev);
180 status = spi_write_then_read(ds1305->spi, &addr, sizeof(addr),
207 struct ds1305 *ds1305 = dev_get_drvdata(dev);
222 *bp++ = hour2bcd(ds1305->hr12, time->tm_hour);
231 return spi_write_then_read(ds1305->spi, buf, sizeof(buf),
264 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
268 struct ds1305 *ds1305 = dev_get_drvdata(dev);
269 struct spi_device *spi = ds1305->spi;
281 ds1305->ctrl, sizeof(ds1305->ctrl));
285 alm->enabled = !!(ds1305->ctrl[0] & DS1305_AEI0);
286 alm->pending = !!(ds1305->ctrl[1] & DS1305_AEI0);
316 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
320 struct ds1305 *ds1305 = dev_get_drvdata(dev);
321 struct spi_device *spi = ds1305->spi;
343 if (ds1305->ctrl[0] & DS1305_AEI0) {
344 ds1305->ctrl[0] &= ~DS1305_AEI0;
347 buf[1] = ds1305->ctrl[0];
348 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
357 buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour);
370 ds1305->ctrl[0] |= DS1305_AEI0;
373 buf[1] = ds1305->ctrl[0];
374 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
384 struct ds1305 *ds1305 = dev_get_drvdata(dev);
389 if ((ds1305->ctrl[2] & 0xf0) == DS1305_TRICKLE_MAGIC) {
390 switch (ds1305->ctrl[2] & 0x0c) {
400 switch (ds1305->ctrl[2] & 0x03) {
437 struct ds1305 *ds1305 = container_of(work, struct ds1305, work);
438 struct mutex *lock = &ds1305->rtc->ops_lock;
439 struct spi_device *spi = ds1305->spi;
443 /* lock to protect ds1305->ctrl */
450 ds1305->ctrl[0] &= ~(DS1305_AEI1 | DS1305_AEI0);
451 ds1305->ctrl[1] = 0;
454 buf[1] = ds1305->ctrl[0];
464 if (!test_bit(FLAG_EXITING, &ds1305->flags))
467 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
472 * mutex locking for ds1305->ctrl ... unlike I2C, we could issue async
477 struct ds1305 *ds1305 = p;
480 schedule_work(&ds1305->work);
511 struct ds1305 *ds1305 = priv;
512 struct spi_device *spi = ds1305->spi;
526 struct ds1305 *ds1305 = priv;
527 struct spi_device *spi = ds1305->spi;
546 struct ds1305 *ds1305;
570 ds1305 = devm_kzalloc(&spi->dev, sizeof(*ds1305), GFP_KERNEL);
571 if (!ds1305)
573 ds1305->spi = spi;
574 spi_set_drvdata(spi, ds1305);
579 ds1305->ctrl, sizeof(ds1305->ctrl));
586 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl);
593 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) {
597 if (ds1305->ctrl[2] == 0)
603 if (ds1305->ctrl[0] & DS1305_WP) {
606 ds1305->ctrl[0] &= ~DS1305_WP;
609 buf[1] = ds1305->ctrl[0];
620 if (ds1305->ctrl[0] & DS1305_nEOSC) {
621 ds1305->ctrl[0] &= ~DS1305_nEOSC;
627 if (ds1305->ctrl[1]) {
628 ds1305->ctrl[1] = 0;
635 if (((ds1305->ctrl[2] & 0xf0) != DS1305_TRICKLE_MAGIC)) {
636 ds1305->ctrl[2] = DS1305_TRICKLE_MAGIC
644 if (!(ds1305->ctrl[0] & DS1306_1HZ)) {
645 ds1305->ctrl[0] |= DS1306_1HZ;
649 if (ds1305->ctrl[0] & DS1306_1HZ) {
650 ds1305->ctrl[0] &= ~DS1306_1HZ;
661 buf[1] = ds1305->ctrl[0];
662 buf[2] = ds1305->ctrl[1];
663 buf[3] = ds1305->ctrl[2];
671 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl);
683 ds1305->hr12 = (DS1305_HR_12 & value) != 0;
684 if (ds1305->hr12)
687 /* register RTC ... from here on, ds1305->ctrl needs locking */
688 ds1305->rtc = devm_rtc_allocate_device(&spi->dev);
689 if (IS_ERR(ds1305->rtc))
690 return PTR_ERR(ds1305->rtc);
692 ds1305->rtc->ops = &ds1305_ops;
693 ds1305->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
694 ds1305->rtc->range_max = RTC_TIMESTAMP_END_2099;
696 ds1305_nvmem_cfg.priv = ds1305;
697 ds1305->rtc->nvram_old_abi = true;
698 status = rtc_register_device(ds1305->rtc);
702 rtc_nvmem_register(ds1305->rtc, &ds1305_nvmem_cfg);
711 INIT_WORK(&ds1305->work, ds1305_work);
713 0, dev_name(&ds1305->rtc->dev), ds1305);
727 struct ds1305 *ds1305 = spi_get_drvdata(spi);
731 set_bit(FLAG_EXITING, &ds1305->flags);
732 devm_free_irq(&spi->dev, spi->irq, ds1305);
733 cancel_work_sync(&ds1305->work);
740 .driver.name = "rtc-ds1305",
750 MODULE_ALIAS("spi:rtc-ds1305");