Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * HID Sensors Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2017, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/hid-sensor-hub.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/iio/buffer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/iio/iio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "hid-sensor-trigger.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) struct hid_humidity_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct hid_sensor_common common_attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct hid_sensor_hub_attribute_info humidity_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		s32 humidity_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		u64 timestamp __aligned(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	} scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int scale_pre_decml;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int scale_post_decml;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int scale_precision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int value_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* Channel definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const struct iio_chan_spec humidity_channels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		.type = IIO_HUMIDITYRELATIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			BIT(IIO_CHAN_INFO_SCALE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			BIT(IIO_CHAN_INFO_SAMP_FREQ) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			BIT(IIO_CHAN_INFO_HYSTERESIS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	IIO_CHAN_SOFT_TIMESTAMP(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* Adjust channel real bits based on report descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void humidity_adjust_channel_bit_mask(struct iio_chan_spec *channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 					int channel, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	channels[channel].scan_type.sign = 's';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* Real storage bits will change based on the report desc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	channels[channel].scan_type.realbits = size * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* Maximum size of a sample to capture is s32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	channels[channel].scan_type.storagebits = sizeof(s32) * 8;
^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) static int humidity_read_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 				struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				int *val, int *val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	case IIO_CHAN_INFO_RAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		if (chan->type != IIO_HUMIDITYRELATIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		hid_sensor_power_state(&humid_st->common_attributes, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		*val = sensor_hub_input_attr_get_raw_value(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				humid_st->common_attributes.hsdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				HID_USAGE_SENSOR_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				humid_st->humidity_attr.report_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				SENSOR_HUB_SYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				humid_st->humidity_attr.logical_minimum < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		hid_sensor_power_state(&humid_st->common_attributes, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	case IIO_CHAN_INFO_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		*val = humid_st->scale_pre_decml;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		*val2 = humid_st->scale_post_decml;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return humid_st->scale_precision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	case IIO_CHAN_INFO_OFFSET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		*val = humid_st->value_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	case IIO_CHAN_INFO_SAMP_FREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return hid_sensor_read_samp_freq_value(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				&humid_st->common_attributes, val, val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	case IIO_CHAN_INFO_HYSTERESIS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return hid_sensor_read_raw_hyst_value(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				&humid_st->common_attributes, val, val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EINVAL;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int humidity_write_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				int val, int val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	case IIO_CHAN_INFO_SAMP_FREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return hid_sensor_write_samp_freq_value(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				&humid_st->common_attributes, val, val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	case IIO_CHAN_INFO_HYSTERESIS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return hid_sensor_write_raw_hyst_value(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				&humid_st->common_attributes, val, val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct iio_info humidity_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.read_raw = &humidity_read_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.write_raw = &humidity_write_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Callback handler to send event after all samples are received and captured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int humidity_proc_event(struct hid_sensor_hub_device *hsdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				unsigned int usage_id, void *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (atomic_read(&humid_st->common_attributes.data_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		iio_push_to_buffers_with_timestamp(indio_dev, &humid_st->scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 						   iio_get_time_ns(indio_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* Capture samples in local storage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				unsigned int usage_id, size_t raw_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				char *raw_data, void *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	switch (usage_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	case HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		humid_st->scan.humidity_data = *(s32 *)raw_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* Parse report which is specific to an usage id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static int humidity_parse_report(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				struct hid_sensor_hub_device *hsdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				struct iio_chan_spec *channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				unsigned int usage_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				struct hid_humidity_state *st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	ret = sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 					usage_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 					HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 					&st->humidity_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	humidity_adjust_channel_bit_mask(channels, 0, st->humidity_attr.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	st->scale_precision = hid_sensor_format_scale(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 						HID_USAGE_SENSOR_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 						&st->humidity_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 						&st->scale_pre_decml,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 						&st->scale_post_decml);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* Set Sensitivity field ids, when there is no individual modifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (st->common_attributes.sensitivity.index < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		sensor_hub_input_get_attribute_info(hsdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			HID_FEATURE_REPORT, usage_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			&st->common_attributes.sensitivity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return ret;
^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 struct hid_sensor_hub_callbacks humidity_callbacks = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.send_event = &humidity_proc_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.capture_sample = &humidity_capture_sample,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* Function to initialize the processing for usage id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int hid_humidity_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	static const char *name = "humidity";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct hid_humidity_state *humid_st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct iio_chan_spec *humid_chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*humid_st));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (!indio_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	humid_st = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	humid_st->common_attributes.hsdev = hsdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	humid_st->common_attributes.pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	ret = hid_sensor_parse_common_attributes(hsdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					HID_USAGE_SENSOR_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					&humid_st->common_attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	humid_chans = devm_kmemdup(&indio_dev->dev, humidity_channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 					sizeof(humidity_channels), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!humid_chans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	ret = humidity_parse_report(pdev, hsdev, humid_chans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				HID_USAGE_SENSOR_HUMIDITY, humid_st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	indio_dev->channels = humid_chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	indio_dev->num_channels = ARRAY_SIZE(humidity_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	indio_dev->info = &humidity_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	indio_dev->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	indio_dev->modes = INDIO_DIRECT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	atomic_set(&humid_st->common_attributes.data_ready, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	ret = hid_sensor_setup_trigger(indio_dev, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				&humid_st->common_attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	platform_set_drvdata(pdev, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	humidity_callbacks.pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_HUMIDITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 					&humidity_callbacks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto error_remove_trigger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	ret = iio_device_register(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		goto error_remove_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) error_remove_callback:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_HUMIDITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) error_remove_trigger:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	hid_sensor_remove_trigger(indio_dev, &humid_st->common_attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* Function to deinitialize the processing for usage id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static int hid_humidity_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	iio_device_unregister(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_HUMIDITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	hid_sensor_remove_trigger(indio_dev, &humid_st->common_attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static const struct platform_device_id hid_humidity_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		.name = "HID-SENSOR-200032",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_DEVICE_TABLE(platform, hid_humidity_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static struct platform_driver hid_humidity_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	.id_table = hid_humidity_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		.name	= KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		.pm	= &hid_sensor_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	.probe		= hid_humidity_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	.remove		= hid_humidity_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) module_platform_driver(hid_humidity_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) MODULE_DESCRIPTION("HID Environmental humidity sensor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) MODULE_AUTHOR("Song Hongyan <hongyan.song@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MODULE_LICENSE("GPL v2");