Lines Matching refs:ds1307
106 struct ds1307 { struct
326 struct ds1307 *ds1307; in ds1307_work() local
331 ds1307 = container_of(work, struct ds1307, work); in ds1307_work()
332 client = ds1307->client; in ds1307_work()
333 lock = &ds1307->rtc->ops_lock; in ds1307_work()
351 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in ds1307_work()
355 if (test_bit(HAS_ALARM, &ds1307->flags)) in ds1307_work()
363 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1307_irq() local
366 schedule_work(&ds1307->work); in ds1307_irq()
374 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_get_time() local
378 tmp = ds1307->read_block_data(ds1307->client, in ds1307_get_time()
379 ds1307->offset, 7, ds1307->regs); in ds1307_get_time()
385 dev_dbg(dev, "%s: %7ph\n", "read", ds1307->regs); in ds1307_get_time()
387 t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f); in ds1307_get_time()
388 t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f); in ds1307_get_time()
389 tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f; in ds1307_get_time()
391 t->tm_wday = bcd2bin(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1; in ds1307_get_time()
392 t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f); in ds1307_get_time()
393 tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f; in ds1307_get_time()
397 t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100; in ds1307_get_time()
411 struct ds1307 *ds1307 = dev_get_drvdata(dev); in ds1307_set_time() local
414 u8 *buf = ds1307->regs; in ds1307_set_time()
433 switch (ds1307->type) { in ds1307_set_time()
458 result = ds1307->write_block_data(ds1307->client, in ds1307_set_time()
459 ds1307->offset, 7, buf); in ds1307_set_time()
470 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1337_read_alarm() local
473 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1337_read_alarm()
477 ret = ds1307->read_block_data(client, in ds1337_read_alarm()
478 DS1339_REG_ALARM1_SECS, 9, ds1307->regs); in ds1337_read_alarm()
486 ds1307->regs[0], ds1307->regs[1], in ds1337_read_alarm()
487 ds1307->regs[2], ds1307->regs[3], in ds1337_read_alarm()
488 ds1307->regs[4], ds1307->regs[5], in ds1337_read_alarm()
489 ds1307->regs[6], ds1307->regs[7], in ds1337_read_alarm()
490 ds1307->regs[8]); in ds1337_read_alarm()
496 t->time.tm_sec = bcd2bin(ds1307->regs[0] & 0x7f); in ds1337_read_alarm()
497 t->time.tm_min = bcd2bin(ds1307->regs[1] & 0x7f); in ds1337_read_alarm()
498 t->time.tm_hour = bcd2bin(ds1307->regs[2] & 0x3f); in ds1337_read_alarm()
499 t->time.tm_mday = bcd2bin(ds1307->regs[3] & 0x3f); in ds1337_read_alarm()
507 t->enabled = !!(ds1307->regs[7] & DS1337_BIT_A1IE); in ds1337_read_alarm()
508 t->pending = !!(ds1307->regs[8] & DS1337_BIT_A1I); in ds1337_read_alarm()
522 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1337_set_alarm() local
523 unsigned char *buf = ds1307->regs; in ds1337_set_alarm()
527 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1337_set_alarm()
537 ret = ds1307->read_block_data(client, in ds1337_set_alarm()
543 control = ds1307->regs[7]; in ds1337_set_alarm()
544 status = ds1307->regs[8]; in ds1337_set_alarm()
548 ds1307->regs[0], ds1307->regs[1], in ds1337_set_alarm()
549 ds1307->regs[2], ds1307->regs[3], in ds1337_set_alarm()
550 ds1307->regs[4], ds1307->regs[5], in ds1337_set_alarm()
551 ds1307->regs[6], control, status); in ds1337_set_alarm()
572 ret = ds1307->write_block_data(client, in ds1337_set_alarm()
585 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1307_alarm_irq_enable() local
588 if (!test_bit(HAS_ALARM, &ds1307->flags)) in ds1307_alarm_irq_enable()
639 struct ds1307 *ds1307 = container_of(work, struct ds1307, work); in mcp794xx_work() local
640 struct i2c_client *client = ds1307->client; in mcp794xx_work()
643 mutex_lock(&ds1307->rtc->ops_lock); in mcp794xx_work()
665 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); in mcp794xx_work()
668 if (test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_work()
670 mutex_unlock(&ds1307->rtc->ops_lock); in mcp794xx_work()
676 struct ds1307 *ds1307 = i2c_get_clientdata(client); in mcp794xx_read_alarm() local
677 u8 *regs = ds1307->regs; in mcp794xx_read_alarm()
680 if (!test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_read_alarm()
684 ret = ds1307->read_block_data(client, MCP794XX_REG_CONTROL, 10, regs); in mcp794xx_read_alarm()
691 t->time.tm_sec = bcd2bin(ds1307->regs[3] & 0x7f); in mcp794xx_read_alarm()
692 t->time.tm_min = bcd2bin(ds1307->regs[4] & 0x7f); in mcp794xx_read_alarm()
693 t->time.tm_hour = bcd2bin(ds1307->regs[5] & 0x3f); in mcp794xx_read_alarm()
694 t->time.tm_wday = bcd2bin(ds1307->regs[6] & 0x7) - 1; in mcp794xx_read_alarm()
695 t->time.tm_mday = bcd2bin(ds1307->regs[7] & 0x3f); in mcp794xx_read_alarm()
696 t->time.tm_mon = bcd2bin(ds1307->regs[8] & 0x1f) - 1; in mcp794xx_read_alarm()
705 !!(ds1307->regs[6] & MCP794XX_BIT_ALMX_POL), in mcp794xx_read_alarm()
706 !!(ds1307->regs[6] & MCP794XX_BIT_ALMX_IF), in mcp794xx_read_alarm()
707 (ds1307->regs[6] & MCP794XX_MSK_ALMX_MATCH) >> 4); in mcp794xx_read_alarm()
715 struct ds1307 *ds1307 = i2c_get_clientdata(client); in mcp794xx_set_alarm() local
716 unsigned char *regs = ds1307->regs; in mcp794xx_set_alarm()
719 if (!test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_set_alarm()
729 ret = ds1307->read_block_data(client, MCP794XX_REG_CONTROL, 10, regs); in mcp794xx_set_alarm()
751 ret = ds1307->write_block_data(client, MCP794XX_REG_CONTROL, 10, regs); in mcp794xx_set_alarm()
761 struct ds1307 *ds1307 = i2c_get_clientdata(client); in mcp794xx_alarm_irq_enable() local
764 if (!test_bit(HAS_ALARM, &ds1307->flags)) in mcp794xx_alarm_irq_enable()
795 struct ds1307 *ds1307; in ds1307_nvram_read() local
799 ds1307 = i2c_get_clientdata(client); in ds1307_nvram_read()
801 if (unlikely(off >= ds1307->nvram->size)) in ds1307_nvram_read()
803 if ((off + count) > ds1307->nvram->size) in ds1307_nvram_read()
804 count = ds1307->nvram->size - off; in ds1307_nvram_read()
808 result = ds1307->read_block_data(client, ds1307->nvram_offset + off, in ds1307_nvram_read()
821 struct ds1307 *ds1307; in ds1307_nvram_write() local
825 ds1307 = i2c_get_clientdata(client); in ds1307_nvram_write()
827 if (unlikely(off >= ds1307->nvram->size)) in ds1307_nvram_write()
829 if ((off + count) > ds1307->nvram->size) in ds1307_nvram_write()
830 count = ds1307->nvram->size - off; in ds1307_nvram_write()
834 result = ds1307->write_block_data(client, ds1307->nvram_offset + off, in ds1307_nvram_write()
891 struct ds1307 *ds1307; in ds1307_probe() local
910 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); in ds1307_probe()
911 if (!ds1307) in ds1307_probe()
914 i2c_set_clientdata(client, ds1307); in ds1307_probe()
916 ds1307->client = client; in ds1307_probe()
917 ds1307->type = id->driver_data; in ds1307_probe()
933 buf = ds1307->regs; in ds1307_probe()
935 ds1307->read_block_data = ds1307_native_smbus_read_block_data; in ds1307_probe()
936 ds1307->write_block_data = ds1307_native_smbus_write_block_data; in ds1307_probe()
938 ds1307->read_block_data = ds1307_read_block_data; in ds1307_probe()
939 ds1307->write_block_data = ds1307_write_block_data; in ds1307_probe()
942 switch (ds1307->type) { in ds1307_probe()
947 tmp = ds1307->read_block_data(ds1307->client, in ds1307_probe()
956 if (ds1307->regs[0] & DS1337_BIT_nEOSC) in ds1307_probe()
957 ds1307->regs[0] &= ~DS1337_BIT_nEOSC; in ds1307_probe()
964 if (ds1307->client->irq > 0 && chip->alarm) { in ds1307_probe()
965 INIT_WORK(&ds1307->work, ds1307_work); in ds1307_probe()
967 ds1307->regs[0] |= DS1337_BIT_INTCN in ds1307_probe()
968 | bbsqi_bitpos[ds1307->type]; in ds1307_probe()
969 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); in ds1307_probe()
975 ds1307->regs[0]); in ds1307_probe()
978 if (ds1307->regs[1] & DS1337_BIT_OSF) { in ds1307_probe()
980 ds1307->regs[1] & ~DS1337_BIT_OSF); in ds1307_probe()
986 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, in ds1307_probe()
995 if (!(ds1307->regs[1] & RX8025_BIT_XST)) { in ds1307_probe()
996 ds1307->regs[1] |= RX8025_BIT_XST; in ds1307_probe()
999 ds1307->regs[1]); in ds1307_probe()
1004 if (ds1307->regs[1] & RX8025_BIT_PON) { in ds1307_probe()
1005 ds1307->regs[1] &= ~RX8025_BIT_PON; in ds1307_probe()
1008 ds1307->regs[1]); in ds1307_probe()
1012 if (ds1307->regs[1] & RX8025_BIT_VDET) { in ds1307_probe()
1013 ds1307->regs[1] &= ~RX8025_BIT_VDET; in ds1307_probe()
1016 ds1307->regs[1]); in ds1307_probe()
1021 if (!(ds1307->regs[0] & RX8025_BIT_2412)) { in ds1307_probe()
1027 ds1307->regs[0] | in ds1307_probe()
1030 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, in ds1307_probe()
1039 hour = bcd2bin(ds1307->regs[DS1307_REG_HOUR]); in ds1307_probe()
1042 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) in ds1307_probe()
1051 ds1307->offset = 1; /* Seconds starts at 1 */ in ds1307_probe()
1055 if (ds1307->client->irq > 0 && chip->alarm) { in ds1307_probe()
1056 INIT_WORK(&ds1307->work, mcp794xx_work); in ds1307_probe()
1066 tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf); in ds1307_probe()
1078 tmp = ds1307->regs[DS1307_REG_SECS]; in ds1307_probe()
1079 switch (ds1307->type) { in ds1307_probe()
1095 if (ds1307->regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) { in ds1307_probe()
1097 ds1307->regs[DS1307_REG_CONTROL] in ds1307_probe()
1123 if (!(ds1307->regs[DS1307_REG_WDAY] & MCP794XX_BIT_VBATEN)) { in ds1307_probe()
1125 ds1307->regs[DS1307_REG_WDAY] in ds1307_probe()
1142 tmp = ds1307->regs[DS1307_REG_HOUR]; in ds1307_probe()
1143 switch (ds1307->type) { in ds1307_probe()
1164 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) in ds1307_probe()
1167 ds1307->offset + DS1307_REG_HOUR, in ds1307_probe()
1172 ds1307->rtc = devm_rtc_device_register(&client->dev, client->name, in ds1307_probe()
1174 if (IS_ERR(ds1307->rtc)) { in ds1307_probe()
1175 return PTR_ERR(ds1307->rtc); in ds1307_probe()
1180 ds1307->rtc->name, client); in ds1307_probe()
1186 set_bit(HAS_ALARM, &ds1307->flags); in ds1307_probe()
1193 ds1307->nvram = devm_kzalloc(&client->dev, in ds1307_probe()
1196 if (!ds1307->nvram) { in ds1307_probe()
1200 ds1307->nvram->attr.name = "nvram"; in ds1307_probe()
1201 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; in ds1307_probe()
1203 sysfs_bin_attr_init(ds1307->nvram); in ds1307_probe()
1205 ds1307->nvram->read = ds1307_nvram_read; in ds1307_probe()
1206 ds1307->nvram->write = ds1307_nvram_write; in ds1307_probe()
1207 ds1307->nvram->size = chip->nvram_size; in ds1307_probe()
1208 ds1307->nvram_offset = chip->nvram_offset; in ds1307_probe()
1211 ds1307->nvram); in ds1307_probe()
1215 ds1307->nvram->attr.name); in ds1307_probe()
1217 set_bit(HAS_NVRAM, &ds1307->flags); in ds1307_probe()
1219 ds1307->nvram->size); in ds1307_probe()
1232 struct ds1307 *ds1307 = i2c_get_clientdata(client); in ds1307_remove() local
1234 if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) { in ds1307_remove()
1236 cancel_work_sync(&ds1307->work); in ds1307_remove()
1239 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) in ds1307_remove()
1240 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); in ds1307_remove()