| @@ -26,28 +26,52 @@ | | | @@ -26,28 +26,52 @@ |
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | * POSSIBILITY OF SUCH DAMAGE. | | 27 | * POSSIBILITY OF SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | /* | | 30 | /* |
31 | * IST-AG P14 calibrated Hygro-/Temperature sensor module | | 31 | * IST-AG P14 calibrated Hygro-/Temperature sensor module |
32 | * Devices: HYT-271, HYT-221 and HYT-939 | | 32 | * Devices: HYT-271, HYT-221 and HYT-939 |
33 | * | | 33 | * |
34 | * see: | | 34 | * see: |
35 | * http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.1.pdf/ | | 35 | * http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.1.pdf/ |
36 | * $FILE/AHHYTM_E2.1.pdf | | 36 | * $FILE/AHHYTM_E2.1.pdf |
37 | */ | | 37 | */ |
38 | | | 38 | |
| | | 39 | /* |
| | | 40 | * FDT direct configuration fragment to be added to i2cX definition in dtsi file |
| | | 41 | * like in bcm2835-rpi.dtsi or another specific file. |
| | | 42 | * |
| | | 43 | * &i2c1 { |
| | | 44 | * pinctrl-names = "default"; |
| | | 45 | * pinctrl-0 = <&i2c1_gpio2>; |
| | | 46 | * status = "okay"; |
| | | 47 | * clock-frequency = <100000>; |
| | | 48 | * #address-cells = <1>; |
| | | 49 | * #size-cells = <0>; |
| | | 50 | * hythygtemp@28 { |
| | | 51 | * compatible = "ist-ag,i2c-hytp14"; |
| | | 52 | * reg = <0x28>; |
| | | 53 | * status = "okay"; |
| | | 54 | * }; |
| | | 55 | * hythygtemp@29 { |
| | | 56 | * compatible = "ist-ag,i2c-hytp14"; |
| | | 57 | * reg = <0x29>; |
| | | 58 | * status = "okay"; |
| | | 59 | * }; |
| | | 60 | * }; |
| | | 61 | */ |
| | | 62 | |
39 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
40 | __KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.8 2018/06/16 21:24:36 thorpej Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.9 2019/10/08 21:16:11 kardel Exp $"); |
41 | | | 65 | |
42 | #include <sys/param.h> | | 66 | #include <sys/param.h> |
43 | #include <sys/systm.h> | | 67 | #include <sys/systm.h> |
44 | #include <sys/kernel.h> | | 68 | #include <sys/kernel.h> |
45 | #include <sys/device.h> | | 69 | #include <sys/device.h> |
46 | #include <sys/module.h> | | 70 | #include <sys/module.h> |
47 | #include <sys/sysctl.h> | | 71 | #include <sys/sysctl.h> |
48 | #include <sys/mutex.h> | | 72 | #include <sys/mutex.h> |
49 | #include <sys/condvar.h> | | 73 | #include <sys/condvar.h> |
50 | #include <sys/kthread.h> | | 74 | #include <sys/kthread.h> |
51 | | | 75 | |
52 | #include <dev/sysmon/sysmonvar.h> | | 76 | #include <dev/sysmon/sysmonvar.h> |
53 | #include <dev/i2c/i2cvar.h> | | 77 | #include <dev/i2c/i2cvar.h> |
| @@ -85,49 +109,50 @@ CFATTACH_DECL_NEW(hythygtemp, sizeof(str | | | @@ -85,49 +109,50 @@ CFATTACH_DECL_NEW(hythygtemp, sizeof(str |
85 | static struct hytp14_sensor hytp14_sensors[] = { | | 109 | static struct hytp14_sensor hytp14_sensors[] = { |
86 | { | | 110 | { |
87 | .desc = "humidity", | | 111 | .desc = "humidity", |
88 | .type = ENVSYS_SRELHUMIDITY, | | 112 | .type = ENVSYS_SRELHUMIDITY, |
89 | .refresh = hytp14_refresh_humidity | | 113 | .refresh = hytp14_refresh_humidity |
90 | }, | | 114 | }, |
91 | { | | 115 | { |
92 | .desc = "temperature", | | 116 | .desc = "temperature", |
93 | .type = ENVSYS_STEMP, | | 117 | .type = ENVSYS_STEMP, |
94 | .refresh = hytp14_refresh_temp | | 118 | .refresh = hytp14_refresh_temp |
95 | } | | 119 | } |
96 | }; | | 120 | }; |
97 | | | 121 | |
| | | 122 | static const struct device_compatible_entry compat_data[] = { |
| | | 123 | { "i2c-hytp14", 0 }, |
| | | 124 | { NULL, 0 } |
| | | 125 | }; |
| | | 126 | |
98 | static int | | 127 | static int |
99 | hytp14_match(device_t parent, cfdata_t match, void *aux) | | 128 | hytp14_match(device_t parent, cfdata_t match, void *aux) |
100 | { | | 129 | { |
101 | struct i2c_attach_args *ia = aux; | | 130 | struct i2c_attach_args *ia = aux; |
102 | int match_result; | | 131 | int match_result; |
103 | | | 132 | |
104 | if (iic_use_direct_match(ia, match, NULL, &match_result)) | | 133 | if (iic_use_direct_match(ia, match, compat_data, &match_result)) |
105 | return match_result; | | 134 | return match_result; |
106 | | | 135 | |
107 | if (ia->ia_addr == 0x28) | | | |
108 | return I2C_MATCH_ADDRESS_ONLY; | | | |
109 | | | | |
110 | /* | | 136 | /* |
111 | * XXXJRT | | 137 | * This device can be reprogrammed to use a different |
112 | * This device is an odd-ball; the i2c address can be changed | | 138 | * I2C address, thus checking for specific addresses |
113 | * at run-time using a command sequence documented in the | | 139 | * is not helpful here. |
114 | * application note, but the timing is critical (within 10ms | | 140 | * reprogramming is done via setting new values in |
115 | * after power-on of the device), and the device always starts | | 141 | * the device EEPROM via the hytctl utility and |
116 | * up at address 0x28. | | 142 | * a special GPIO setup - see hythygtemp(4) for more |
117 | * | | 143 | * information. |
118 | * How should we handle this? | | | |
119 | */ | | 144 | */ |
120 | return 0; | | 145 | return I2C_MATCH_ADDRESS_ONLY; |
121 | } | | 146 | } |
122 | | | 147 | |
123 | static void | | 148 | static void |
124 | hytp14_attach(device_t parent, device_t self, void *aux) | | 149 | hytp14_attach(device_t parent, device_t self, void *aux) |
125 | { | | 150 | { |
126 | const struct sysctlnode *rnode, *node; | | 151 | const struct sysctlnode *rnode, *node; |
127 | struct hytp14_sc *sc; | | 152 | struct hytp14_sc *sc; |
128 | struct i2c_attach_args *ia; | | 153 | struct i2c_attach_args *ia; |
129 | int i, rv; | | 154 | int i, rv; |
130 | | | 155 | |
131 | ia = aux; | | 156 | ia = aux; |
132 | sc = device_private(self); | | 157 | sc = device_private(self); |
133 | | | 158 | |