Lines Matching refs:ds1307
106 struct ds1307 { struct
318 struct ds1307 *ds1307; in ds1307_work() local
323 ds1307 = container_of(work, struct ds1307, work); in ds1307_work()
324 client = ds1307->client; in ds1307_work()
325 lock = &ds1307->rtc->ops_lock; in ds1307_work()
343 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in ds1307_work()
347 if (test_bit(HAS_ALARM, &ds1307->flags)) in ds1307_work()
355 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1307_irq() local
358 schedule_work(&ds1307->work); in ds1307_irq()
366 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_get_time() local
370 tmp = ds1307->read_block_data(ds1307->client, in ds1307_get_time()
371 ds1307->offset, 7, ds1307->regs); in ds1307_get_time()
377 dev_dbg(dev, "%s: %7ph\n", "read", ds1307->regs); in ds1307_get_time()
379 t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f); in ds1307_get_time()
380 t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f); in ds1307_get_time()
381 tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f; in ds1307_get_time()
383 t->tm_wday = bcd2bin(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1; in ds1307_get_time()
384 t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f); in ds1307_get_time()
385 tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f; in ds1307_get_time()
389 t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100; in ds1307_get_time()
403 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_set_time() local
406 u8 *buf = ds1307->regs; in ds1307_set_time()
425 switch (ds1307->type) { in ds1307_set_time()
450 result = ds1307->write_block_data(ds1307->client, in ds1307_set_time()
451 ds1307->offset, 7, buf); in ds1307_set_time()
462 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1337_read_alarm() local
465 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1337_read_alarm()
469 ret = ds1307->read_block_data(client, in ds1337_read_alarm()
470 DS1339_REG_ALARM1_SECS, 9, ds1307->regs); in ds1337_read_alarm()
478 ds1307->regs[0], ds1307->regs[1], in ds1337_read_alarm()
479 ds1307->regs[2], ds1307->regs[3], in ds1337_read_alarm()
480 ds1307->regs[4], ds1307->regs[5], in ds1337_read_alarm()
481 ds1307->regs[6], ds1307->regs[7], in ds1337_read_alarm()
482 ds1307->regs[8]); in ds1337_read_alarm()
488 t->time.tm_sec = bcd2bin(ds1307->regs[0] & 0x7f); in ds1337_read_alarm()
489 t->time.tm_min = bcd2bin(ds1307->regs[1] & 0x7f); in ds1337_read_alarm()
490 t->time.tm_hour = bcd2bin(ds1307->regs[2] & 0x3f); in ds1337_read_alarm()
491 t->time.tm_mday = bcd2bin(ds1307->regs[3] & 0x3f); in ds1337_read_alarm()
499 t->enabled = !!(ds1307->regs[7] & DS1337_BIT_A1IE); in ds1337_read_alarm()
500 t->pending = !!(ds1307->regs[8] & DS1337_BIT_A1I); in ds1337_read_alarm()
514 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1337_set_alarm() local
515 unsigned char *buf = ds1307->regs; in ds1337_set_alarm()
519 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1337_set_alarm()
529 ret = ds1307->read_block_data(client, in ds1337_set_alarm()
535 control = ds1307->regs[7]; in ds1337_set_alarm()
536 status = ds1307->regs[8]; in ds1337_set_alarm()
540 ds1307->regs[0], ds1307->regs[1], in ds1337_set_alarm()
541 ds1307->regs[2], ds1307->regs[3], in ds1337_set_alarm()
542 ds1307->regs[4], ds1307->regs[5], in ds1337_set_alarm()
543 ds1307->regs[6], control, status); in ds1337_set_alarm()
564 ret = ds1307->write_block_data(client, in ds1337_set_alarm()
577 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1307_alarm_irq_enable() local
580 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1307_alarm_irq_enable()
615 struct ds1307 *ds1307; in ds1307_nvram_read() local
619 ds1307 = i2c_get_clientdata(client); in ds1307_nvram_read()
621 if (unlikely(off >= ds1307->nvram->size)) in ds1307_nvram_read()
623 if ((off + count) > ds1307->nvram->size) in ds1307_nvram_read()
624 count = ds1307->nvram->size - off; in ds1307_nvram_read()
628 result = ds1307->read_block_data(client, ds1307->nvram_offset + off, in ds1307_nvram_read()
641 struct ds1307 *ds1307; in ds1307_nvram_write() local
645 ds1307 = i2c_get_clientdata(client); in ds1307_nvram_write()
647 if (unlikely(off >= ds1307->nvram->size)) in ds1307_nvram_write()
649 if ((off + count) > ds1307->nvram->size) in ds1307_nvram_write()
650 count = ds1307->nvram->size - off; in ds1307_nvram_write()
654 result = ds1307->write_block_data(client, ds1307->nvram_offset + off, in ds1307_nvram_write()
668 struct ds1307 *ds1307; in ds1307_probe() local
686 ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL); in ds1307_probe()
687 if (!ds1307) in ds1307_probe()
690 i2c_set_clientdata(client, ds1307); in ds1307_probe()
692 ds1307->client = client; in ds1307_probe()
693 ds1307->type = id->driver_data; in ds1307_probe()
699 buf = ds1307->regs; in ds1307_probe()
701 ds1307->read_block_data = ds1307_native_smbus_read_block_data; in ds1307_probe()
702 ds1307->write_block_data = ds1307_native_smbus_write_block_data; in ds1307_probe()
704 ds1307->read_block_data = ds1307_read_block_data; in ds1307_probe()
705 ds1307->write_block_data = ds1307_write_block_data; in ds1307_probe()
708 switch (ds1307->type) { in ds1307_probe()
713 tmp = ds1307->read_block_data(ds1307->client, in ds1307_probe()
722 if (ds1307->regs[0] & DS1337_BIT_nEOSC) in ds1307_probe()
723 ds1307->regs[0] &= ~DS1337_BIT_nEOSC; in ds1307_probe()
730 if (ds1307->client->irq > 0 && chip->alarm) { in ds1307_probe()
731 INIT_WORK(&ds1307->work, ds1307_work); in ds1307_probe()
733 ds1307->regs[0] |= DS1337_BIT_INTCN in ds1307_probe()
734 | bbsqi_bitpos[ds1307->type]; in ds1307_probe()
735 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); in ds1307_probe()
741 ds1307->regs[0]); in ds1307_probe()
744 if (ds1307->regs[1] & DS1337_BIT_OSF) { in ds1307_probe()
746 ds1307->regs[1] & ~DS1337_BIT_OSF); in ds1307_probe()
752 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, in ds1307_probe()
761 if (!(ds1307->regs[1] & RX8025_BIT_XST)) { in ds1307_probe()
762 ds1307->regs[1] |= RX8025_BIT_XST; in ds1307_probe()
765 ds1307->regs[1]); in ds1307_probe()
770 if (ds1307->regs[1] & RX8025_BIT_PON) { in ds1307_probe()
771 ds1307->regs[1] &= ~RX8025_BIT_PON; in ds1307_probe()
774 ds1307->regs[1]); in ds1307_probe()
778 if (ds1307->regs[1] & RX8025_BIT_VDET) { in ds1307_probe()
779 ds1307->regs[1] &= ~RX8025_BIT_VDET; in ds1307_probe()
782 ds1307->regs[1]); in ds1307_probe()
787 if (!(ds1307->regs[0] & RX8025_BIT_2412)) { in ds1307_probe()
793 ds1307->regs[0] | in ds1307_probe()
796 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, in ds1307_probe()
805 hour = bcd2bin(ds1307->regs[DS1307_REG_HOUR]); in ds1307_probe()
808 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) in ds1307_probe()
817 ds1307->offset = 1; /* Seconds starts at 1 */ in ds1307_probe()
825 tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf); in ds1307_probe()
837 tmp = ds1307->regs[DS1307_REG_SECS]; in ds1307_probe()
838 switch (ds1307->type) { in ds1307_probe()
854 if (ds1307->regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) { in ds1307_probe()
856 ds1307->regs[DS1307_REG_CONTROL] in ds1307_probe()
882 if (!(ds1307->regs[DS1307_REG_WDAY] & MCP7941X_BIT_VBATEN)) { in ds1307_probe()
884 ds1307->regs[DS1307_REG_WDAY] in ds1307_probe()
901 tmp = ds1307->regs[DS1307_REG_HOUR]; in ds1307_probe()
902 switch (ds1307->type) { in ds1307_probe()
923 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) in ds1307_probe()
926 ds1307->offset + DS1307_REG_HOUR, in ds1307_probe()
930 ds1307->rtc = rtc_device_register(client->name, &client->dev, in ds1307_probe()
932 if (IS_ERR(ds1307->rtc)) { in ds1307_probe()
933 err = PTR_ERR(ds1307->rtc); in ds1307_probe()
941 ds1307->rtc->name, client); in ds1307_probe()
949 set_bit(HAS_ALARM, &ds1307->flags); in ds1307_probe()
954 ds1307->nvram = kzalloc(sizeof(struct bin_attribute), in ds1307_probe()
956 if (!ds1307->nvram) { in ds1307_probe()
960 ds1307->nvram->attr.name = "nvram"; in ds1307_probe()
961 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; in ds1307_probe()
962 sysfs_bin_attr_init(ds1307->nvram); in ds1307_probe()
963 ds1307->nvram->read = ds1307_nvram_read; in ds1307_probe()
964 ds1307->nvram->write = ds1307_nvram_write; in ds1307_probe()
965 ds1307->nvram->size = chip->nvram_size; in ds1307_probe()
966 ds1307->nvram_offset = chip->nvram_offset; in ds1307_probe()
967 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); in ds1307_probe()
969 kfree(ds1307->nvram); in ds1307_probe()
972 set_bit(HAS_NVRAM, &ds1307->flags); in ds1307_probe()
973 dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size); in ds1307_probe()
980 rtc_device_unregister(ds1307->rtc); in ds1307_probe()
982 kfree(ds1307); in ds1307_probe()
988 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1307_remove() local
990 if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) { in ds1307_remove()
992 cancel_work_sync(&ds1307->work); in ds1307_remove()
995 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) { in ds1307_remove()
996 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); in ds1307_remove()
997 kfree(ds1307->nvram); in ds1307_remove()
1000 rtc_device_unregister(ds1307->rtc); in ds1307_remove()
1001 kfree(ds1307); in ds1307_remove()