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+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Azoteq IQS624/625 Angular Position Sensors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2019 Jeff LaBundy <jeff@labundy.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/iio/events.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/iio/iio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mfd/iqs62x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define IQS624_POS_DEG_OUT			0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define IQS624_POS_SCALE1			(314159 / 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define IQS624_POS_SCALE2			100000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct iqs624_pos_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct iqs62x_core *iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct notifier_block notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	bool angle_en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u16 angle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int iqs624_pos_angle_en(struct iqs62x_core *iqs62x, bool angle_en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned int event_mask = IQS624_HALL_UI_WHL_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	 * The IQS625 reports angular position in the form of coarse intervals,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 * so only interval change events are unmasked. Conversely, the IQS624
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	 * reports angular position down to one degree of resolution, so wheel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	 * movement events are unmasked instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (iqs62x->dev_desc->prod_num == IQS625_PROD_NUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		event_mask = IQS624_HALL_UI_INT_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return regmap_update_bits(iqs62x->regmap, IQS624_HALL_UI, event_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 				  angle_en ? 0 : 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int iqs624_pos_notifier(struct notifier_block *notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			       unsigned long event_flags, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct iqs62x_event_data *event_data = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct iqs624_pos_private *iqs624_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct iqs62x_core *iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u16 angle = event_data->ui_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	s64 timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	iqs624_pos = container_of(notifier, struct iqs624_pos_private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				  notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	indio_dev = iqs624_pos->indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	timestamp = iio_get_time_ns(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	iqs62x = iqs624_pos->iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (iqs62x->dev_desc->prod_num == IQS625_PROD_NUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		angle = event_data->interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	mutex_lock(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (event_flags & BIT(IQS62X_EVENT_SYS_RESET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		ret = iqs624_pos_angle_en(iqs62x, iqs624_pos->angle_en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			dev_err(indio_dev->dev.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				"Failed to re-initialize device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			ret = NOTIFY_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			ret = NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	} else if (iqs624_pos->angle_en && (angle != iqs624_pos->angle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		iio_push_event(indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			       IIO_UNMOD_EVENT_CODE(IIO_ANGL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 						    IIO_EV_TYPE_CHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 						    IIO_EV_DIR_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			       timestamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		iqs624_pos->angle = angle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		ret = NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		ret = NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	mutex_unlock(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static void iqs624_pos_notifier_unregister(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct iqs624_pos_private *iqs624_pos = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct iio_dev *indio_dev = iqs624_pos->indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ret = blocking_notifier_chain_unregister(&iqs624_pos->iqs62x->nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 						 &iqs624_pos->notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		dev_err(indio_dev->dev.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			"Failed to unregister notifier: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int iqs624_pos_angle_get(struct iqs62x_core *iqs62x, unsigned int *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	__le16 val_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (iqs62x->dev_desc->prod_num == IQS625_PROD_NUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return regmap_read(iqs62x->regmap, iqs62x->dev_desc->interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				   val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	ret = regmap_raw_read(iqs62x->regmap, IQS624_POS_DEG_OUT, &val_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			      sizeof(val_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	*val = le16_to_cpu(val_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int iqs624_pos_read_raw(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			       struct iio_chan_spec const *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			       int *val, int *val2, long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct iqs624_pos_private *iqs624_pos = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct iqs62x_core *iqs62x = iqs624_pos->iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	unsigned int scale = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	switch (mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	case IIO_CHAN_INFO_RAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		ret = iqs624_pos_angle_get(iqs62x, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return IIO_VAL_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	case IIO_CHAN_INFO_SCALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (iqs62x->dev_desc->prod_num == IQS625_PROD_NUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			ret = regmap_read(iqs62x->regmap, IQS624_INTERVAL_DIV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					  &scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		*val = scale * IQS624_POS_SCALE1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		*val2 = IQS624_POS_SCALE2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return IIO_VAL_FRACTIONAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int iqs624_pos_read_event_config(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 					const struct iio_chan_spec *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 					enum iio_event_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 					enum iio_event_direction dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct iqs624_pos_private *iqs624_pos = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	mutex_lock(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ret = iqs624_pos->angle_en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	mutex_unlock(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int iqs624_pos_write_event_config(struct iio_dev *indio_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 					 const struct iio_chan_spec *chan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 					 enum iio_event_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 					 enum iio_event_direction dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 					 int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct iqs624_pos_private *iqs624_pos = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct iqs62x_core *iqs62x = iqs624_pos->iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	mutex_lock(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	ret = iqs624_pos_angle_get(iqs62x, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		goto err_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	ret = iqs624_pos_angle_en(iqs62x, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		goto err_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	iqs624_pos->angle = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	iqs624_pos->angle_en = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) err_mutex:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	mutex_unlock(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static const struct iio_info iqs624_pos_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.read_raw = &iqs624_pos_read_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	.read_event_config = iqs624_pos_read_event_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	.write_event_config = iqs624_pos_write_event_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static const struct iio_event_spec iqs624_pos_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		.type = IIO_EV_TYPE_CHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		.dir = IIO_EV_DIR_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static const struct iio_chan_spec iqs624_pos_channels[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		.type = IIO_ANGL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				      BIT(IIO_CHAN_INFO_SCALE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		.event_spec = iqs624_pos_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		.num_event_specs = ARRAY_SIZE(iqs624_pos_events),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int iqs624_pos_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct iqs62x_core *iqs62x = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct iqs624_pos_private *iqs624_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct iio_dev *indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*iqs624_pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (!indio_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	iqs624_pos = iio_priv(indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	iqs624_pos->iqs62x = iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	iqs624_pos->indio_dev = indio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	indio_dev->modes = INDIO_DIRECT_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	indio_dev->channels = iqs624_pos_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	indio_dev->num_channels = ARRAY_SIZE(iqs624_pos_channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	indio_dev->name = iqs62x->dev_desc->dev_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	indio_dev->info = &iqs624_pos_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	mutex_init(&iqs624_pos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	iqs624_pos->notifier.notifier_call = iqs624_pos_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	ret = blocking_notifier_chain_register(&iqs624_pos->iqs62x->nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					       &iqs624_pos->notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	ret = devm_add_action_or_reset(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				       iqs624_pos_notifier_unregister,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				       iqs624_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return devm_iio_device_register(&pdev->dev, indio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static struct platform_driver iqs624_pos_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		.name = "iqs624-pos",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	.probe = iqs624_pos_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) module_platform_driver(iqs624_pos_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_DESCRIPTION("Azoteq IQS624/625 Angular Position Sensors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_ALIAS("platform:iqs624-pos");