|
@@ -19,6 +19,8 @@
|
|
#include <linux/rtc.h>
|
|
#include <linux/rtc.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
#include <linux/string.h>
|
|
|
|
+#include <linux/hwmon.h>
|
|
|
|
+#include <linux/hwmon-sysfs.h>
|
|
|
|
|
|
/*
|
|
/*
|
|
* We can't determine type by probing, but if we expect pre-Linux code
|
|
* We can't determine type by probing, but if we expect pre-Linux code
|
|
@@ -842,6 +844,90 @@ out:
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*----------------------------------------------------------------------*/
|
|
|
|
+
|
|
|
|
+#ifdef CONFIG_RTC_DRV_DS1307_HWMON
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * Temperature sensor support for ds3231 devices.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#define DS3231_REG_TEMPERATURE 0x11
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * A user-initiated temperature conversion is not started by this function,
|
|
|
|
+ * so the temperature is updated once every 64 seconds.
|
|
|
|
+ */
|
|
|
|
+static int ds3231_hwmon_read_temp(struct device *dev, s16 *mC)
|
|
|
|
+{
|
|
|
|
+ struct ds1307 *ds1307 = dev_get_drvdata(dev);
|
|
|
|
+ u8 temp_buf[2];
|
|
|
|
+ s16 temp;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ ret = ds1307->read_block_data(ds1307->client, DS3231_REG_TEMPERATURE,
|
|
|
|
+ sizeof(temp_buf), temp_buf);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ return ret;
|
|
|
|
+ if (ret != sizeof(temp_buf))
|
|
|
|
+ return -EIO;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Temperature is represented as a 10-bit code with a resolution of
|
|
|
|
+ * 0.25 degree celsius and encoded in two's complement format.
|
|
|
|
+ */
|
|
|
|
+ temp = (temp_buf[0] << 8) | temp_buf[1];
|
|
|
|
+ temp >>= 6;
|
|
|
|
+ *mC = temp * 250;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static ssize_t ds3231_hwmon_show_temp(struct device *dev,
|
|
|
|
+ struct device_attribute *attr, char *buf)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+ s16 temp;
|
|
|
|
+
|
|
|
|
+ ret = ds3231_hwmon_read_temp(dev, &temp);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+
|
|
|
|
+ return sprintf(buf, "%d\n", temp);
|
|
|
|
+}
|
|
|
|
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, ds3231_hwmon_show_temp,
|
|
|
|
+ NULL, 0);
|
|
|
|
+
|
|
|
|
+static struct attribute *ds3231_hwmon_attrs[] = {
|
|
|
|
+ &sensor_dev_attr_temp1_input.dev_attr.attr,
|
|
|
|
+ NULL,
|
|
|
|
+};
|
|
|
|
+ATTRIBUTE_GROUPS(ds3231_hwmon);
|
|
|
|
+
|
|
|
|
+static void ds1307_hwmon_register(struct ds1307 *ds1307)
|
|
|
|
+{
|
|
|
|
+ struct device *dev;
|
|
|
|
+
|
|
|
|
+ if (ds1307->type != ds_3231)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ dev = devm_hwmon_device_register_with_groups(&ds1307->client->dev,
|
|
|
|
+ ds1307->client->name,
|
|
|
|
+ ds1307, ds3231_hwmon_groups);
|
|
|
|
+ if (IS_ERR(dev)) {
|
|
|
|
+ dev_warn(&ds1307->client->dev,
|
|
|
|
+ "unable to register hwmon device %ld\n", PTR_ERR(dev));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+static void ds1307_hwmon_register(struct ds1307 *ds1307)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
static int ds1307_probe(struct i2c_client *client,
|
|
static int ds1307_probe(struct i2c_client *client,
|
|
const struct i2c_device_id *id)
|
|
const struct i2c_device_id *id)
|
|
{
|
|
{
|
|
@@ -1207,6 +1293,8 @@ read_rtc:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ds1307_hwmon_register(ds1307);
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
exit:
|
|
exit:
|