// SPDX-License-Identifier: GPL-2.0-or-later /* Honeywell HIH-6130/HIH-6131 humidity and temperature sensor driver * * Copyright (C) 2012 Iain Paton <[email protected]> * * heavily based on the sht21 driver * Copyright (C) 2010 Urs Fleisch <[email protected]> * * Data sheets available (2012-06-22) at * http://sensing.honeywell.com/index.php?ci_id=3106&la_id=1&defId=44872 */ #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> #include <linux/device.h> #include <linux/delay.h> #include <linux/jiffies.h> /** * struct hih6130 - HIH-6130 device specific data * @client: pointer to I2C client device * @lock: mutex to protect measurement values * @valid: only false before first measurement is taken * @last_update: time of last update (jiffies) * @temperature: cached temperature measurement value * @humidity: cached humidity measurement value * @write_length: length for I2C measurement request */ struct hih6130 { … }; /** * hih6130_temp_ticks_to_millicelsius() - convert raw temperature ticks to * milli celsius * @ticks: temperature ticks value received from sensor */ static inline int hih6130_temp_ticks_to_millicelsius(int ticks) { … } /** * hih6130_rh_ticks_to_per_cent_mille() - convert raw humidity ticks to * one-thousandths of a percent relative humidity * @ticks: humidity ticks value received from sensor */ static inline int hih6130_rh_ticks_to_per_cent_mille(int ticks) { … } /** * hih6130_update_measurements() - get updated measurements from device * @dev: device * * Returns 0 on success, else negative errno. */ static int hih6130_update_measurements(struct device *dev) { … } /** * hih6130_temperature_show() - show temperature measurement value in sysfs * @dev: device * @attr: device attribute * @buf: sysfs buffer (PAGE_SIZE) where measurement values are written to * * Will be called on read access to temp1_input sysfs attribute. * Returns number of bytes written into buffer, negative errno on error. */ static ssize_t hih6130_temperature_show(struct device *dev, struct device_attribute *attr, char *buf) { … } /** * hih6130_humidity_show() - show humidity measurement value in sysfs * @dev: device * @attr: device attribute * @buf: sysfs buffer (PAGE_SIZE) where measurement values are written to * * Will be called on read access to humidity1_input sysfs attribute. * Returns number of bytes written into buffer, negative errno on error. */ static ssize_t hih6130_humidity_show(struct device *dev, struct device_attribute *attr, char *buf) { … } /* sysfs attributes */ static SENSOR_DEVICE_ATTR_RO(temp1_input, hih6130_temperature, 0); static SENSOR_DEVICE_ATTR_RO(humidity1_input, hih6130_humidity, 0); static struct attribute *hih6130_attrs[] = …; ATTRIBUTE_GROUPS(…); static int hih6130_probe(struct i2c_client *client) { … } /* Device ID table */ static const struct i2c_device_id hih6130_id[] = …; MODULE_DEVICE_TABLE(i2c, hih6130_id); static const struct of_device_id __maybe_unused hih6130_of_match[] = …; MODULE_DEVICE_TABLE(of, hih6130_of_match); static struct i2c_driver hih6130_driver = …; module_i2c_driver(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;