// SPDX-License-Identifier: GPL-2.0-only /* * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver * * Written by: Grant Likely <grant.likely@secretlab.ca> * * Copyright (C) 2007 Secret Lab Technologies Ltd.
*/
/* * The DS1682 elapsed timer recorder is a simple device that implements * one elapsed time counter, one event counter, an alarm signal and 10 * bytes of general purpose EEPROM. * * This driver provides access to the DS1682 counters and user data via * the sysfs. The following attributes are added to the device node: * elapsed_time (u32): Total elapsed event time in ms resolution * alarm_time (u32): When elapsed time exceeds the value in alarm_time, * then the alarm pin is asserted. * event_count (u16): number of times the event pin has gone low. * eeprom (u8[10]): general purpose EEPROM * * Counter registers and user data are both read/write unless the device * has been write protected. This driver does not support turning off write * protection. Once write protection is turned on, it is impossible to * turn it off again, so I have left the feature out of this driver to avoid * accidental enabling, but it is trivial to add write protect support. *
*/
dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
/* Read the register */
rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
(u8 *)&val_le); if (rc < 0) return -EIO;
val = le32_to_cpu(val_le);
if (sattr->index == DS1682_REG_ELAPSED) { int retries = 5;
/* Detect and retry when a tick occurs mid-read */ do {
rc = i2c_smbus_read_i2c_block_data(client, sattr->index,
sattr->nr,
(u8 *)&val_le); if (rc < 0 || retries <= 0) return -EIO;
check = val;
val = le32_to_cpu(val_le);
retries--;
} while (val != check && val != (check + 1));
}
/* Format the output string and return # of bytes * Special case: the 32 bit regs are time values with 1/4s * resolution, scale them up to milliseconds
*/ return sprintf(buf, "%llu\n", (sattr->nr == 4) ? (val * 250) : val);
}
ret = i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + offset,
bytes, val); return ret < 0 ? ret : 0;
}
/* * Called when a ds1682 device is matched with this driver
*/ staticint ds1682_probe(struct i2c_client *client)
{ struct nvmem_config config = {
.dev = &client->dev,
.owner = THIS_MODULE,
.type = NVMEM_TYPE_EEPROM,
.reg_read = ds1682_nvmem_read,
.reg_write = ds1682_nvmem_write,
.size = DS1682_EEPROM_SIZE,
.priv = client,
}; struct nvmem_device *nvmem; int rc;
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_I2C_BLOCK)) {
dev_err(&client->dev, "i2c bus does not support the ds1682\n");
rc = -ENODEV; gotoexit;
}
nvmem = devm_nvmem_register(&client->dev, &config); if (IS_ENABLED(CONFIG_NVMEM) && IS_ERR(nvmem)) return PTR_ERR(nvmem);
rc = sysfs_create_group(&client->dev.kobj, &ds1682_group); if (rc) gotoexit;
rc = sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr); if (rc) goto exit_bin_attr;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.