Lines Matching defs:ds1305

2  * rtc-ds1305.c -- driver for DS1305 and DS1306 SPI RTC chips
19 #include <linux/spi/ds1305.h>
80 /* trickle bits are defined in <linux/spi/ds1305.h> */
88 struct ds1305 {
145 struct ds1305 *ds1305 = dev_get_drvdata(dev);
150 buf[1] = ds1305->ctrl[0];
153 if (ds1305->ctrl[0] & DS1305_AEI0)
161 err = spi_write_then_read(ds1305->spi, buf, sizeof(buf), NULL, 0);
163 ds1305->ctrl[0] = buf[1];
176 struct ds1305 *ds1305 = dev_get_drvdata(dev);
184 status = spi_write_then_read(ds1305->spi, &addr, sizeof(addr),
214 struct ds1305 *ds1305 = dev_get_drvdata(dev);
229 *bp++ = hour2bcd(ds1305->hr12, time->tm_hour);
240 return spi_write_then_read(ds1305->spi, buf, sizeof(buf),
273 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
277 struct ds1305 *ds1305 = dev_get_drvdata(dev);
278 struct spi_device *spi = ds1305->spi;
290 ds1305->ctrl, sizeof(ds1305->ctrl));
294 alm->enabled = !!(ds1305->ctrl[0] & DS1305_AEI0);
295 alm->pending = !!(ds1305->ctrl[1] & DS1305_AEI0);
332 * Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
336 struct ds1305 *ds1305 = dev_get_drvdata(dev);
337 struct spi_device *spi = ds1305->spi;
363 if (ds1305->ctrl[0] & DS1305_AEI0) {
364 ds1305->ctrl[0] &= ~DS1305_AEI0;
367 buf[1] = ds1305->ctrl[0];
368 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
377 buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour);
390 ds1305->ctrl[0] |= DS1305_AEI0;
393 buf[1] = ds1305->ctrl[0];
394 status = spi_write_then_read(ds1305->spi, buf, 2, NULL, 0);
404 struct ds1305 *ds1305 = dev_get_drvdata(dev);
409 if ((ds1305->ctrl[2] & 0xf0) == DS1305_TRICKLE_MAGIC) {
410 switch (ds1305->ctrl[2] & 0x0c) {
420 switch (ds1305->ctrl[2] & 0x03) {
457 struct ds1305 *ds1305 = container_of(work, struct ds1305, work);
458 struct mutex *lock = &ds1305->rtc->ops_lock;
459 struct spi_device *spi = ds1305->spi;
463 /* lock to protect ds1305->ctrl */
470 ds1305->ctrl[0] &= ~(DS1305_AEI1 | DS1305_AEI0);
471 ds1305->ctrl[1] = 0;
474 buf[1] = ds1305->ctrl[0];
484 if (!test_bit(FLAG_EXITING, &ds1305->flags))
487 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
492 * mutex locking for ds1305->ctrl ... unlike I2C, we could issue async
497 struct ds1305 *ds1305 = p;
500 schedule_work(&ds1305->work);
606 struct ds1305 *ds1305;
622 ds1305 = devm_kzalloc(&spi->dev, sizeof(*ds1305), GFP_KERNEL);
623 if (!ds1305)
625 ds1305->spi = spi;
626 spi_set_drvdata(spi, ds1305);
631 ds1305->ctrl, sizeof(ds1305->ctrl));
638 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl);
645 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) {
649 if (ds1305->ctrl[2] == 0)
655 if (ds1305->ctrl[0] & DS1305_WP) {
658 ds1305->ctrl[0] &= ~DS1305_WP;
661 buf[1] = ds1305->ctrl[0];
672 if (ds1305->ctrl[0] & DS1305_nEOSC) {
673 ds1305->ctrl[0] &= ~DS1305_nEOSC;
679 if (ds1305->ctrl[1]) {
680 ds1305->ctrl[1] = 0;
687 if (((ds1305->ctrl[2] & 0xf0) != DS1305_TRICKLE_MAGIC)) {
688 ds1305->ctrl[2] = DS1305_TRICKLE_MAGIC
696 if (!(ds1305->ctrl[0] & DS1306_1HZ)) {
697 ds1305->ctrl[0] |= DS1306_1HZ;
701 if (ds1305->ctrl[0] & DS1306_1HZ) {
702 ds1305->ctrl[0] &= ~DS1306_1HZ;
713 buf[1] = ds1305->ctrl[0];
714 buf[2] = ds1305->ctrl[1];
715 buf[3] = ds1305->ctrl[2];
723 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl);
735 ds1305->hr12 = (DS1305_HR_12 & value) != 0;
736 if (ds1305->hr12)
739 /* register RTC ... from here on, ds1305->ctrl needs locking */
740 ds1305->rtc = devm_rtc_device_register(&spi->dev, "ds1305",
742 if (IS_ERR(ds1305->rtc)) {
743 status = PTR_ERR(ds1305->rtc);
755 INIT_WORK(&ds1305->work, ds1305_work);
757 0, dev_name(&ds1305->rtc->dev), ds1305);
777 struct ds1305 *ds1305 = spi_get_drvdata(spi);
783 set_bit(FLAG_EXITING, &ds1305->flags);
784 devm_free_irq(&spi->dev, spi->irq, ds1305);
785 cancel_work_sync(&ds1305->work);
792 .driver.name = "rtc-ds1305",
803 MODULE_ALIAS("spi:rtc-ds1305");