^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by: Grant Likely <grant.likely@secretlab.ca>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2007 Secret Lab Technologies Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * The DS1682 elapsed timer recorder is a simple device that implements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * one elapsed time counter, one event counter, an alarm signal and 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * bytes of general purpose EEPROM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * This driver provides access to the DS1682 counters and user data via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * the sysfs. The following attributes are added to the device node:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * elapsed_time (u32): Total elapsed event time in ms resolution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * alarm_time (u32): When elapsed time exceeds the value in alarm_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * then the alarm pin is asserted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * event_count (u16): number of times the event pin has gone low.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * eeprom (u8[10]): general purpose EEPROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Counter registers and user data are both read/write unless the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * has been write protected. This driver does not support turning off write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * protection. Once write protection is turned on, it is impossible to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * turn it off again, so I have left the feature out of this driver to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * accidental enabling, but it is trivial to add write protect support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Device registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DS1682_REG_CONFIG 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DS1682_REG_ALARM 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define DS1682_REG_ELAPSED 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define DS1682_REG_EVT_CNTR 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define DS1682_REG_EEPROM 0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define DS1682_REG_RESET 0x1d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define DS1682_REG_WRITE_DISABLE 0x1e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define DS1682_REG_WRITE_MEM_DISABLE 0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define DS1682_EEPROM_SIZE 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Generic counter attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned long long val, check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) __le32 val_le = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* Read the register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) (u8 *)&val_le);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) val = le32_to_cpu(val_le);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (sattr->index == DS1682_REG_ELAPSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int retries = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Detect and retry when a tick occurs mid-read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) rc = i2c_smbus_read_i2c_block_data(client, sattr->index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) sattr->nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) (u8 *)&val_le);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (rc < 0 || retries <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) check = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) val = le32_to_cpu(val_le);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) retries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) } while (val != check && val != (check + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Format the output string and return # of bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Special case: the 32 bit regs are time values with 1/4s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * resolution, scale them up to milliseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return sprintf(buf, "%llu\n", (sattr->nr == 4) ? (val * 250) : val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u64 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) __le32 val_le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* Decode input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) rc = kstrtoull(buf, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) dev_dbg(dev, "input string not a number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Special case: the 32 bit regs are time values with 1/4s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * resolution, scale input down to quarter-seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (sattr->nr == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) do_div(val, 250);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* write out the value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) val_le = cpu_to_le32(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) (u8 *) & val_le);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) sattr->index, sattr->nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Simple register attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ds1682_store, 4, DS1682_REG_ELAPSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ds1682_store, 4, DS1682_REG_ALARM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ds1682_store, 2, DS1682_REG_EVT_CNTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static const struct attribute_group ds1682_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .attrs = (struct attribute *[]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) &sensor_dev_attr_elapsed_time.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) &sensor_dev_attr_alarm_time.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) &sensor_dev_attr_event_count.dev_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * User data attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static ssize_t ds1682_eeprom_read(struct file *filp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct bin_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) char *buf, loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct i2c_client *client = kobj_to_i2c_client(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) buf, off, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) count, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static ssize_t ds1682_eeprom_write(struct file *filp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct bin_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) char *buf, loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct i2c_client *client = kobj_to_i2c_client(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) buf, off, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Write out to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) count, buf) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static const struct bin_attribute ds1682_eeprom_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .name = "eeprom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .mode = S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) .size = DS1682_EEPROM_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .read = ds1682_eeprom_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .write = ds1682_eeprom_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * Called when a ds1682 device is matched with this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int ds1682_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (!i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) I2C_FUNC_SMBUS_I2C_BLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) dev_err(&client->dev, "i2c bus does not support the ds1682\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) rc = sysfs_create_group(&client->dev.kobj, &ds1682_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) rc = sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) goto exit_bin_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) exit_bin_attr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) sysfs_remove_group(&client->dev.kobj, &ds1682_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int ds1682_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sysfs_remove_group(&client->dev.kobj, &ds1682_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static const struct i2c_device_id ds1682_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) { "ds1682", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) MODULE_DEVICE_TABLE(i2c, ds1682_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static const struct of_device_id ds1682_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) { .compatible = "dallas,ds1682", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) MODULE_DEVICE_TABLE(of, ds1682_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static struct i2c_driver ds1682_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .name = "ds1682",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .of_match_table = ds1682_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .probe = ds1682_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .remove = ds1682_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .id_table = ds1682_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) module_i2c_driver(ds1682_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_LICENSE("GPL");