All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] staging: iio: tsl2x7x: staging cleanups
@ 2017-09-30  1:09 Brian Masney
  2017-09-30  1:09 ` [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings Brian Masney
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Brian Masney @ 2017-09-30  1:09 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: gregkh, devel, knaack.h, lars, pmeerw, linux-kernel, Jon.Brenner

This patch set converts several sysfs attributes from directly being
created by the driver to be created by iio_chan_spec and iio_event_spec.
There is also a patch to shorten the length of a variable to fix an
issue that I encountered with some lines that were over 80 characters
with this refactoring.

Driver tested using a TSL2771 hooked up to a Raspberry Pi 2.

List of sysfs attributes before and after my changes:

raspberrypi:/sys/bus/iio/devices/iio:device0$ find . -type f | sort
./dev
./events/in_intensity0_thresh_falling_en
./events/in_intensity0_thresh_falling_value
./events/in_intensity0_thresh_period
./events/in_intensity0_thresh_rising_en
./events/in_intensity0_thresh_rising_value
./events/in_proximity0_thresh_falling_en
./events/in_proximity0_thresh_falling_value
./events/in_proximity0_thresh_period
./events/in_proximity0_thresh_rising_en
./events/in_proximity0_thresh_rising_value
./in_illuminance0_calibrate
./in_illuminance0_calibscale_available
./in_illuminance0_input
./in_illuminance0_integration_time
./in_illuminance0_integration_time_available
./in_illuminance0_lux_table
./in_illuminance0_target_input
./in_intensity0_calibbias
./in_intensity0_calibscale
./in_intensity0_raw
./in_intensity1_raw
./in_proximity0_calibrate
./in_proximity0_raw
./name
./power/autosuspend_delay_ms
./power/control
./power/runtime_active_time
./power/runtime_status
./power/runtime_suspended_time
./uevent

Brian Masney (3):
  staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings
  staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs
    attribute to iio_chan_spec
  staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to
    iio_event_spec

 drivers/staging/iio/light/tsl2x7x.c | 418 ++++++++++++------------------------
 1 file changed, 141 insertions(+), 277 deletions(-)

-- 
2.13.5

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings
  2017-09-30  1:09 [PATCH 0/3] staging: iio: tsl2x7x: staging cleanups Brian Masney
@ 2017-09-30  1:09 ` Brian Masney
  2017-10-01 10:08   ` Jonathan Cameron
  2017-09-30  1:09 ` [PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec Brian Masney
  2017-09-30  1:09 ` [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec Brian Masney
  2 siblings, 1 reply; 8+ messages in thread
From: Brian Masney @ 2017-09-30  1:09 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: gregkh, devel, knaack.h, lars, pmeerw, linux-kernel, Jon.Brenner

The length of the 'tsl2x7x_settings' variable within the tsl2X7X_chip
structure makes some of the line lengths greater than 80 characters for
upcoming patches. This patch shortens the name of the 'tsl2x7x_settings'
variable in this structure to just 'settings' to improve code
readability.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2x7x.c | 183 +++++++++++++++++-------------------
 1 file changed, 85 insertions(+), 98 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index d9defc8ece83..e340ea624e5c 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -174,7 +174,7 @@ struct tsl2X7X_chip {
 	struct i2c_client *client;
 	u16 prox_data;
 	struct tsl2x7x_als_info als_cur_info;
-	struct tsl2x7x_settings tsl2x7x_settings;
+	struct tsl2x7x_settings settings;
 	struct tsl2X7X_platform_data *pdata;
 	int als_time_scale;
 	int als_saturation;
@@ -390,9 +390,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 		lux = 0;
 	} else {
 		ch0lux = DIV_ROUND_UP(ch0 * p->ch0,
-			tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
+			tsl2X7X_als_gainadj[chip->settings.als_gain]);
 		ch1lux = DIV_ROUND_UP(ch1 * p->ch1,
-			tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
+			tsl2X7X_als_gainadj[chip->settings.als_gain]);
 		lux = ch0lux - ch1lux;
 	}
 
@@ -419,7 +419,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 	 */
 
 	lux64 = lux;
-	lux64 = lux64 * chip->tsl2x7x_settings.als_gain_trim;
+	lux64 = lux64 * chip->settings.als_gain_trim;
 	lux64 >>= 8;
 	lux = lux64;
 	lux = (lux + 500) / 1000;
@@ -514,12 +514,10 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
 {
 	/* If Operational settings defined elsewhere.. */
 	if (chip->pdata && chip->pdata->platform_default_settings)
-		memcpy(&chip->tsl2x7x_settings,
-		       chip->pdata->platform_default_settings,
+		memcpy(&chip->settings, chip->pdata->platform_default_settings,
 		       sizeof(tsl2x7x_default_settings));
 	else
-		memcpy(&chip->tsl2x7x_settings,
-		       &tsl2x7x_default_settings,
+		memcpy(&chip->settings, &tsl2x7x_default_settings,
 		       sizeof(tsl2x7x_default_settings));
 
 	/* Load up the proper lux table. */
@@ -542,9 +540,7 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
 static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int gain_trim_val;
-	int ret;
-	int lux_val;
+	int ret, lux_val;
 
 	ret = i2c_smbus_read_byte_data(chip->client,
 				       TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
@@ -575,16 +571,16 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
 		return lux_val;
 	}
 
-	gain_trim_val =  ((chip->tsl2x7x_settings.als_cal_target)
-			* chip->tsl2x7x_settings.als_gain_trim) / lux_val;
-	if ((gain_trim_val < 250) || (gain_trim_val > 4000))
+	ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
+			lux_val;
+	if (ret < 250 || ret > 4000)
 		return -ERANGE;
 
-	chip->tsl2x7x_settings.als_gain_trim = gain_trim_val;
+	chip->settings.als_gain_trim = ret;
 	dev_info(&chip->client->dev,
 		 "%s als_calibrate completed\n", chip->client->name);
 
-	return (int)gain_trim_val;
+	return ret;
 }
 
 static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
@@ -602,34 +598,30 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 		chip->pdata->power_on(indio_dev);
 
 	/* Non calculated parameters */
-	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] =
-			chip->tsl2x7x_settings.prx_time;
-	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] =
-			chip->tsl2x7x_settings.wait_time;
-	chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] =
-			chip->tsl2x7x_settings.prox_config;
+	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prx_time;
+	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time;
+	chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = chip->settings.prox_config;
 
 	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] =
-		(chip->tsl2x7x_settings.als_thresh_low) & 0xFF;
+		(chip->settings.als_thresh_low) & 0xFF;
 	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI] =
-		(chip->tsl2x7x_settings.als_thresh_low >> 8) & 0xFF;
+		(chip->settings.als_thresh_low >> 8) & 0xFF;
 	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO] =
-		(chip->tsl2x7x_settings.als_thresh_high) & 0xFF;
+		(chip->settings.als_thresh_high) & 0xFF;
 	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
-		(chip->tsl2x7x_settings.als_thresh_high >> 8) & 0xFF;
-	chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] =
-		chip->tsl2x7x_settings.persistence;
+		(chip->settings.als_thresh_high >> 8) & 0xFF;
+	chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] = chip->settings.persistence;
 
 	chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] =
-			chip->tsl2x7x_settings.prox_pulse_count;
+			chip->settings.prox_pulse_count;
 	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO] =
-			(chip->tsl2x7x_settings.prox_thres_low) & 0xFF;
+			(chip->settings.prox_thres_low) & 0xFF;
 	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHHI] =
-			(chip->tsl2x7x_settings.prox_thres_low >> 8) & 0xFF;
+			(chip->settings.prox_thres_low >> 8) & 0xFF;
 	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO] =
-			(chip->tsl2x7x_settings.prox_thres_high) & 0xFF;
+			(chip->settings.prox_thres_high) & 0xFF;
 	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHHI] =
-			(chip->tsl2x7x_settings.prox_thres_high >> 8) & 0xFF;
+			(chip->settings.prox_thres_high >> 8) & 0xFF;
 
 	/* and make sure we're not already on */
 	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
@@ -639,7 +631,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 	}
 
 	/* determine als integration register */
-	als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270;
+	als_count = (chip->settings.als_time * 100 + 135) / 270;
 	if (!als_count)
 		als_count = 1; /* ensure at least one cycle */
 
@@ -649,9 +641,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
 	/* Set the gain based on tsl2x7x_settings struct */
 	chip->tsl2x7x_config[TSL2X7X_GAIN] =
-		chip->tsl2x7x_settings.als_gain |
-			(TSL2X7X_mA100 | TSL2X7X_DIODE1)
-			| ((chip->tsl2x7x_settings.prox_gain) << 2);
+		chip->settings.als_gain |
+			(TSL2X7X_mA100 | TSL2X7X_DIODE1) |
+			(chip->settings.prox_gain << 2);
 
 	/* set chip struct re scaling and saturation */
 	chip->als_saturation = als_count * 922; /* 90% of full scale */
@@ -706,15 +698,15 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
 	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING;
 
-	if (chip->tsl2x7x_settings.interrupts_en != 0) {
+	if (chip->settings.interrupts_en != 0) {
 		dev_info(&chip->client->dev, "Setting Up Interrupt(s)\n");
 
 		reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL;
-		if ((chip->tsl2x7x_settings.interrupts_en == 0x20) ||
-		    (chip->tsl2x7x_settings.interrupts_en == 0x30))
+		if ((chip->settings.interrupts_en == 0x20) ||
+		    (chip->settings.interrupts_en == 0x30))
 			reg_val |= TSL2X7X_CNTL_PROX_DET_ENBL;
 
-		reg_val |= chip->tsl2x7x_settings.interrupts_en;
+		reg_val |= chip->settings.interrupts_en;
 		ret = i2c_smbus_write_byte_data(chip->client,
 						(TSL2X7X_CMD_REG |
 						TSL2X7X_CNTRL), reg_val);
@@ -837,25 +829,25 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
 	u8 tmp_irq_settings;
 	u8 current_state = chip->tsl2x7x_chip_status;
 
-	if (chip->tsl2x7x_settings.prox_max_samples_cal > MAX_SAMPLES_CAL) {
+	if (chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL) {
 		dev_err(&chip->client->dev,
 			"max prox samples cal is too big: %d\n",
-			chip->tsl2x7x_settings.prox_max_samples_cal);
-		chip->tsl2x7x_settings.prox_max_samples_cal = MAX_SAMPLES_CAL;
+			chip->settings.prox_max_samples_cal);
+		chip->settings.prox_max_samples_cal = MAX_SAMPLES_CAL;
 	}
 
 	/* have to stop to change settings */
 	tsl2x7x_chip_off(indio_dev);
 
 	/* Enable proximity detection save just in case prox not wanted yet*/
-	tmp_irq_settings = chip->tsl2x7x_settings.interrupts_en;
-	chip->tsl2x7x_settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
+	tmp_irq_settings = chip->settings.interrupts_en;
+	chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
 
 	/*turn on device if not already on*/
 	tsl2x7x_chip_on(indio_dev);
 
 	/*gather the samples*/
-	for (i = 0; i < chip->tsl2x7x_settings.prox_max_samples_cal; i++) {
+	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
 		usleep_range(15000, 17500);
 		tsl2x7x_get_prox(indio_dev);
 		prox_history[i] = chip->prox_data;
@@ -866,18 +858,17 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
 	tsl2x7x_chip_off(indio_dev);
 	calP = &prox_stat_data[PROX_STAT_CAL];
 	tsl2x7x_prox_calculate(prox_history,
-			       chip->tsl2x7x_settings.prox_max_samples_cal,
-			       calP);
-	chip->tsl2x7x_settings.prox_thres_high = (calP->max << 1) - calP->mean;
+			       chip->settings.prox_max_samples_cal, calP);
+	chip->settings.prox_thres_high = (calP->max << 1) - calP->mean;
 
 	dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n",
 		 calP->min, calP->mean, calP->max);
 	dev_info(&chip->client->dev,
 		 "%s proximity threshold set to %d\n",
-		 chip->client->name, chip->tsl2x7x_settings.prox_thres_high);
+		 chip->client->name, chip->settings.prox_thres_high);
 
 	/* back to the way they were */
-	chip->tsl2x7x_settings.interrupts_en = tmp_irq_settings;
+	chip->settings.interrupts_en = tmp_irq_settings;
 	if (current_state == TSL2X7X_CHIP_WORKING)
 		tsl2x7x_chip_on(indio_dev);
 }
@@ -914,7 +905,7 @@ static ssize_t in_illuminance0_integration_time_show(struct device *dev,
 	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
 	int y, z;
 
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
+	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
 	z = y * TSL2X7X_MIN_ITIME;
 	y /= 1000;
 	z %= 1000;
@@ -936,11 +927,10 @@ static ssize_t in_illuminance0_integration_time_store(struct device *dev,
 		return ret;
 
 	result.fract /= 3;
-	chip->tsl2x7x_settings.als_time =
-			TSL2X7X_MAX_TIMER_CNT - (u8)result.fract;
+	chip->settings.als_time = TSL2X7X_MAX_TIMER_CNT - (u8)result.fract;
 
 	dev_info(&chip->client->dev, "%s: als time = %d",
-		 __func__, chip->tsl2x7x_settings.als_time);
+		 __func__, chip->settings.als_time);
 
 	tsl2x7x_invoke_change(indio_dev);
 
@@ -956,8 +946,7 @@ static ssize_t in_illuminance0_target_input_show(struct device *dev,
 {
 	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
 
-	return snprintf(buf, PAGE_SIZE, "%d\n",
-			chip->tsl2x7x_settings.als_cal_target);
+	return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
 }
 
 static ssize_t in_illuminance0_target_input_store(struct device *dev,
@@ -973,7 +962,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 		return -EINVAL;
 
 	if (value)
-		chip->tsl2x7x_settings.als_cal_target = value;
+		chip->settings.als_cal_target = value;
 
 	ret = tsl2x7x_invoke_change(indio_dev);
 	if (ret < 0)
@@ -991,9 +980,9 @@ static ssize_t in_intensity0_thresh_period_show(struct device *dev,
 	int y, z, filter_delay;
 
 	/* Determine integration time */
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
+	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
 	z = y * TSL2X7X_MIN_ITIME;
-	filter_delay = z * (chip->tsl2x7x_settings.persistence & 0x0F);
+	filter_delay = z * (chip->settings.persistence & 0x0F);
 	y = filter_delay / 1000;
 	z = filter_delay % 1000;
 
@@ -1014,14 +1003,14 @@ static ssize_t in_intensity0_thresh_period_store(struct device *dev,
 	if (ret)
 		return ret;
 
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
+	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
 	z = y * TSL2X7X_MIN_ITIME;
 
 	filter_delay =
 		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
 
-	chip->tsl2x7x_settings.persistence &= 0xF0;
-	chip->tsl2x7x_settings.persistence |= (filter_delay & 0x0F);
+	chip->settings.persistence &= 0xF0;
+	chip->settings.persistence |= (filter_delay & 0x0F);
 
 	dev_info(&chip->client->dev, "%s: als persistence = %d",
 		 __func__, filter_delay);
@@ -1041,9 +1030,9 @@ static ssize_t in_proximity0_thresh_period_show(struct device *dev,
 	int y, z, filter_delay;
 
 	/* Determine integration time */
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
+	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
 	z = y * TSL2X7X_MIN_ITIME;
-	filter_delay = z * ((chip->tsl2x7x_settings.persistence & 0xF0) >> 4);
+	filter_delay = z * ((chip->settings.persistence & 0xF0) >> 4);
 	y = filter_delay / 1000;
 	z = filter_delay % 1000;
 
@@ -1064,14 +1053,14 @@ static ssize_t in_proximity0_thresh_period_store(struct device *dev,
 	if (ret)
 		return ret;
 
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
+	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
 	z = y * TSL2X7X_MIN_ITIME;
 
 	filter_delay =
 		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
 
-	chip->tsl2x7x_settings.persistence &= 0x0F;
-	chip->tsl2x7x_settings.persistence |= ((filter_delay << 4) & 0xF0);
+	chip->settings.persistence &= 0x0F;
+	chip->settings.persistence |= ((filter_delay << 4) & 0xF0);
 
 	dev_info(&chip->client->dev, "%s: prox persistence = %d",
 		 __func__, filter_delay);
@@ -1205,9 +1194,9 @@ static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
 	int ret;
 
 	if (chan->type == IIO_INTENSITY)
-		ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x10);
+		ret = !!(chip->settings.interrupts_en & 0x10);
 	else
-		ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x20);
+		ret = !!(chip->settings.interrupts_en & 0x20);
 
 	return ret;
 }
@@ -1223,14 +1212,14 @@ static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
 
 	if (chan->type == IIO_INTENSITY) {
 		if (val)
-			chip->tsl2x7x_settings.interrupts_en |= 0x10;
+			chip->settings.interrupts_en |= 0x10;
 		else
-			chip->tsl2x7x_settings.interrupts_en &= 0x20;
+			chip->settings.interrupts_en &= 0x20;
 	} else {
 		if (val)
-			chip->tsl2x7x_settings.interrupts_en |= 0x20;
+			chip->settings.interrupts_en |= 0x20;
 		else
-			chip->tsl2x7x_settings.interrupts_en &= 0x10;
+			chip->settings.interrupts_en &= 0x10;
 	}
 
 	ret = tsl2x7x_invoke_change(indio_dev);
@@ -1255,11 +1244,11 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 		if (chan->type == IIO_INTENSITY) {
 			switch (dir) {
 			case IIO_EV_DIR_RISING:
-				chip->tsl2x7x_settings.als_thresh_high = val;
+				chip->settings.als_thresh_high = val;
 				ret = 0;
 				break;
 			case IIO_EV_DIR_FALLING:
-				chip->tsl2x7x_settings.als_thresh_low = val;
+				chip->settings.als_thresh_low = val;
 				ret = 0;
 				break;
 			default:
@@ -1268,11 +1257,11 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 		} else {
 			switch (dir) {
 			case IIO_EV_DIR_RISING:
-				chip->tsl2x7x_settings.prox_thres_high = val;
+				chip->settings.prox_thres_high = val;
 				ret = 0;
 				break;
 			case IIO_EV_DIR_FALLING:
-				chip->tsl2x7x_settings.prox_thres_low = val;
+				chip->settings.prox_thres_low = val;
 				ret = 0;
 				break;
 			default:
@@ -1305,11 +1294,11 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 		if (chan->type == IIO_INTENSITY) {
 			switch (dir) {
 			case IIO_EV_DIR_RISING:
-				*val = chip->tsl2x7x_settings.als_thresh_high;
+				*val = chip->settings.als_thresh_high;
 				ret = IIO_VAL_INT;
 				break;
 			case IIO_EV_DIR_FALLING:
-				*val = chip->tsl2x7x_settings.als_thresh_low;
+				*val = chip->settings.als_thresh_low;
 				ret = IIO_VAL_INT;
 				break;
 			default:
@@ -1318,11 +1307,11 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 		} else {
 			switch (dir) {
 			case IIO_EV_DIR_RISING:
-				*val = chip->tsl2x7x_settings.prox_thres_high;
+				*val = chip->settings.prox_thres_high;
 				ret = IIO_VAL_INT;
 				break;
 			case IIO_EV_DIR_FALLING:
-				*val = chip->tsl2x7x_settings.prox_thres_low;
+				*val = chip->settings.prox_thres_low;
 				ret = IIO_VAL_INT;
 				break;
 			default:
@@ -1379,15 +1368,13 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_CALIBSCALE:
 		if (chan->type == IIO_LIGHT)
-			*val =
-			tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain];
+			*val = tsl2X7X_als_gainadj[chip->settings.als_gain];
 		else
-			*val =
-			tsl2X7X_prx_gainadj[chip->tsl2x7x_settings.prox_gain];
+			*val = tsl2X7X_prx_gainadj[chip->settings.prox_gain];
 		ret = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_CALIBBIAS:
-		*val = chip->tsl2x7x_settings.als_gain_trim;
+		*val = chip->settings.als_gain_trim;
 		ret = IIO_VAL_INT;
 		break;
 
@@ -1411,13 +1398,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 		if (chan->type == IIO_INTENSITY) {
 			switch (val) {
 			case 1:
-				chip->tsl2x7x_settings.als_gain = 0;
+				chip->settings.als_gain = 0;
 				break;
 			case 8:
-				chip->tsl2x7x_settings.als_gain = 1;
+				chip->settings.als_gain = 1;
 				break;
 			case 16:
-				chip->tsl2x7x_settings.als_gain = 2;
+				chip->settings.als_gain = 2;
 				break;
 			case 120:
 				switch (chip->id) {
@@ -1428,7 +1415,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 				case tmd2772:
 					return -EINVAL;
 				}
-				chip->tsl2x7x_settings.als_gain = 3;
+				chip->settings.als_gain = 3;
 				break;
 			case 128:
 				switch (chip->id) {
@@ -1439,7 +1426,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 				case tmd2771:
 					return -EINVAL;
 				}
-				chip->tsl2x7x_settings.als_gain = 3;
+				chip->settings.als_gain = 3;
 				break;
 			default:
 				return -EINVAL;
@@ -1447,16 +1434,16 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 		} else {
 			switch (val) {
 			case 1:
-				chip->tsl2x7x_settings.prox_gain = 0;
+				chip->settings.prox_gain = 0;
 				break;
 			case 2:
-				chip->tsl2x7x_settings.prox_gain = 1;
+				chip->settings.prox_gain = 1;
 				break;
 			case 4:
-				chip->tsl2x7x_settings.prox_gain = 2;
+				chip->settings.prox_gain = 2;
 				break;
 			case 8:
-				chip->tsl2x7x_settings.prox_gain = 3;
+				chip->settings.prox_gain = 3;
 				break;
 			default:
 				return -EINVAL;
@@ -1464,7 +1451,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 		}
 		break;
 	case IIO_CHAN_INFO_CALIBBIAS:
-		chip->tsl2x7x_settings.als_gain_trim = val;
+		chip->settings.als_gain_trim = val;
 		break;
 
 	default:
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec
  2017-09-30  1:09 [PATCH 0/3] staging: iio: tsl2x7x: staging cleanups Brian Masney
  2017-09-30  1:09 ` [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings Brian Masney
@ 2017-09-30  1:09 ` Brian Masney
  2017-10-01 10:10   ` Jonathan Cameron
  2017-09-30  1:09 ` [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec Brian Masney
  2 siblings, 1 reply; 8+ messages in thread
From: Brian Masney @ 2017-09-30  1:09 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: gregkh, devel, knaack.h, lars, pmeerw, linux-kernel, Jon.Brenner

The driver explicitly creates the in_illuminance0_integration_time sysfs
attribute outside the IIO core. This attribute is available in the IIO
core so this patches migrates the attribute to be created by
the iio_chan_spec.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
Changes since v1 (Jul 9 2017):
- Use MIN_ITIME instead of hardcoded 3 in tsl2x7x_write_raw()

 drivers/staging/iio/light/tsl2x7x.c | 65 ++++++++++---------------------------
 1 file changed, 17 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index e340ea624e5c..e6a71f5fc9cb 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -898,45 +898,6 @@ static ssize_t in_proximity0_calibscale_available_show(struct device *dev,
 		return snprintf(buf, PAGE_SIZE, "%s\n", "1 2 4 8");
 }
 
-static ssize_t in_illuminance0_integration_time_show(struct device *dev,
-				     struct device_attribute *attr,
-				     char *buf)
-{
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
-	int y, z;
-
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
-	z = y * TSL2X7X_MIN_ITIME;
-	y /= 1000;
-	z %= 1000;
-
-	return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
-}
-
-static ssize_t in_illuminance0_integration_time_store(struct device *dev,
-				      struct device_attribute *attr,
-				      const char *buf, size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	struct tsl2x7x_parse_result result;
-	int ret;
-
-	ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
-	if (ret)
-		return ret;
-
-	result.fract /= 3;
-	chip->settings.als_time = TSL2X7X_MAX_TIMER_CNT - (u8)result.fract;
-
-	dev_info(&chip->client->dev, "%s: als time = %d",
-		 __func__, chip->settings.als_time);
-
-	tsl2x7x_invoke_change(indio_dev);
-
-	return IIO_VAL_INT_PLUS_MICRO;
-}
-
 static IIO_CONST_ATTR(in_illuminance0_integration_time_available,
 		".00272 - .696");
 
@@ -1377,7 +1338,11 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
 		*val = chip->settings.als_gain_trim;
 		ret = IIO_VAL_INT;
 		break;
-
+	case IIO_CHAN_INFO_INT_TIME:
+		*val = (TSL2X7X_MAX_TIMER_CNT - chip->settings.als_time) + 1;
+		*val2 = ((*val * TSL2X7X_MIN_ITIME) % 1000) / 1000;
+		ret = IIO_VAL_INT_PLUS_MICRO;
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1453,7 +1418,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_CALIBBIAS:
 		chip->settings.als_gain_trim = val;
 		break;
+	case IIO_CHAN_INFO_INT_TIME:
+		chip->settings.als_time =
+			TSL2X7X_MAX_TIMER_CNT - (val2 / TSL2X7X_MIN_ITIME);
 
+		dev_info(&chip->client->dev, "%s: als time = %d",
+			 __func__, chip->settings.als_time);
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -1465,8 +1436,6 @@ static DEVICE_ATTR_RO(in_proximity0_calibscale_available);
 
 static DEVICE_ATTR_RO(in_illuminance0_calibscale_available);
 
-static DEVICE_ATTR_RW(in_illuminance0_integration_time);
-
 static DEVICE_ATTR_RW(in_illuminance0_target_input);
 
 static DEVICE_ATTR_WO(in_illuminance0_calibrate);
@@ -1546,7 +1515,6 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
 
 static struct attribute *tsl2x7x_ALS_device_attrs[] = {
 	&dev_attr_in_illuminance0_calibscale_available.attr,
-	&dev_attr_in_illuminance0_integration_time.attr,
 	&iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
@@ -1561,7 +1529,6 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
 
 static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
 	&dev_attr_in_illuminance0_calibscale_available.attr,
-	&dev_attr_in_illuminance0_integration_time.attr,
 	&iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
@@ -1578,7 +1545,6 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
 
 static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
 	&dev_attr_in_illuminance0_calibscale_available.attr,
-	&dev_attr_in_illuminance0_integration_time.attr,
 	&iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
 	&dev_attr_in_illuminance0_target_input.attr,
 	&dev_attr_in_illuminance0_calibrate.attr,
@@ -1711,7 +1677,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.type = IIO_LIGHT,
 			.indexed = 1,
 			.channel = 0,
-			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
+					      BIT(IIO_CHAN_INFO_INT_TIME),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1750,7 +1717,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.type = IIO_LIGHT,
 			.indexed = 1,
 			.channel = 0,
-			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED)
+			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
+					      BIT(IIO_CHAN_INFO_INT_TIME),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1798,7 +1766,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.type = IIO_LIGHT,
 			.indexed = 1,
 			.channel = 0,
-			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
+					      BIT(IIO_CHAN_INFO_INT_TIME),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec
  2017-09-30  1:09 [PATCH 0/3] staging: iio: tsl2x7x: staging cleanups Brian Masney
  2017-09-30  1:09 ` [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings Brian Masney
  2017-09-30  1:09 ` [PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec Brian Masney
@ 2017-09-30  1:09 ` Brian Masney
  2017-10-01 10:14   ` Jonathan Cameron
  2 siblings, 1 reply; 8+ messages in thread
From: Brian Masney @ 2017-09-30  1:09 UTC (permalink / raw)
  To: jic23, linux-iio
  Cc: gregkh, devel, knaack.h, lars, pmeerw, linux-kernel, Jon.Brenner

The sysfs attributes in_intensity0_thresh_period and
in_proximity0_thresh_period are currently directly created by the driver.
This patch migrates the creation of these sysfs attributes from the driver
to using the IIO core via iio_event_spec.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2x7x.c | 196 ++++++++++--------------------------
 1 file changed, 52 insertions(+), 144 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
index e6a71f5fc9cb..be2806593e59 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -932,108 +932,6 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
 	return len;
 }
 
-/* persistence settings */
-static ssize_t in_intensity0_thresh_period_show(struct device *dev,
-					    struct device_attribute *attr,
-					    char *buf)
-{
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
-	int y, z, filter_delay;
-
-	/* Determine integration time */
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
-	z = y * TSL2X7X_MIN_ITIME;
-	filter_delay = z * (chip->settings.persistence & 0x0F);
-	y = filter_delay / 1000;
-	z = filter_delay % 1000;
-
-	return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
-}
-
-static ssize_t in_intensity0_thresh_period_store(struct device *dev,
-					     struct device_attribute *attr,
-					     const char *buf, size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	struct tsl2x7x_parse_result result;
-	int y, z, filter_delay;
-	int ret;
-
-	ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
-	if (ret)
-		return ret;
-
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
-	z = y * TSL2X7X_MIN_ITIME;
-
-	filter_delay =
-		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
-
-	chip->settings.persistence &= 0xF0;
-	chip->settings.persistence |= (filter_delay & 0x0F);
-
-	dev_info(&chip->client->dev, "%s: als persistence = %d",
-		 __func__, filter_delay);
-
-	ret = tsl2x7x_invoke_change(indio_dev);
-	if (ret < 0)
-		return ret;
-
-	return IIO_VAL_INT_PLUS_MICRO;
-}
-
-static ssize_t in_proximity0_thresh_period_show(struct device *dev,
-					     struct device_attribute *attr,
-					     char *buf)
-{
-	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
-	int y, z, filter_delay;
-
-	/* Determine integration time */
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
-	z = y * TSL2X7X_MIN_ITIME;
-	filter_delay = z * ((chip->settings.persistence & 0xF0) >> 4);
-	y = filter_delay / 1000;
-	z = filter_delay % 1000;
-
-	return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
-}
-
-static ssize_t in_proximity0_thresh_period_store(struct device *dev,
-					      struct device_attribute *attr,
-					      const char *buf, size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	struct tsl2x7x_parse_result result;
-	int y, z, filter_delay;
-	int ret;
-
-	ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
-	if (ret)
-		return ret;
-
-	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
-	z = y * TSL2X7X_MIN_ITIME;
-
-	filter_delay =
-		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
-
-	chip->settings.persistence &= 0x0F;
-	chip->settings.persistence |= ((filter_delay << 4) & 0xF0);
-
-	dev_info(&chip->client->dev, "%s: prox persistence = %d",
-		 __func__, filter_delay);
-
-	ret = tsl2x7x_invoke_change(indio_dev);
-	if (ret < 0)
-		return ret;
-
-
-	return IIO_VAL_INT_PLUS_MICRO;
-}
-
 static ssize_t in_illuminance0_calibrate_store(struct device *dev,
 				    struct device_attribute *attr,
 				    const char *buf, size_t len)
@@ -1198,7 +1096,8 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 				     int val, int val2)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL;
+	int ret = -EINVAL, y, z, filter_delay;
+	u8 time;
 
 	switch (info) {
 	case IIO_EV_INFO_VALUE:
@@ -1230,6 +1129,33 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
 			}
 		}
 		break;
+	case IIO_EV_INFO_PERIOD:
+		if (chan->type == IIO_INTENSITY)
+			time = chip->settings.als_time;
+		else
+			time = chip->settings.prx_time;
+
+		y = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
+		z = y * TSL2X7X_MIN_ITIME;
+
+		filter_delay = DIV_ROUND_UP((val * 1000) + val2, z);
+
+		if (chan->type == IIO_INTENSITY) {
+			chip->settings.persistence &= 0xF0;
+			chip->settings.persistence |=
+				(filter_delay & 0x0F);
+			dev_info(&chip->client->dev, "%s: ALS persistence = %d",
+				 __func__, filter_delay);
+		} else {
+			chip->settings.persistence &= 0x0F;
+			chip->settings.persistence |=
+				((filter_delay << 4) & 0xF0);
+			dev_info(&chip->client->dev,
+				 "%s: Proximity persistence = %d",
+				 __func__, filter_delay);
+		}
+		ret = 0;
+		break;
 	default:
 		break;
 	}
@@ -1248,7 +1174,8 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 				    int *val, int *val2)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
-	int ret = -EINVAL;
+	int ret = -EINVAL, filter_delay, mult;
+	u8 time;
 
 	switch (info) {
 	case IIO_EV_INFO_VALUE:
@@ -1280,6 +1207,23 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
 			}
 		}
 		break;
+	case IIO_EV_INFO_PERIOD:
+		if (chan->type == IIO_INTENSITY) {
+			time = chip->settings.als_time;
+			mult = chip->settings.persistence & 0x0F;
+		} else {
+			time = chip->settings.prx_time;
+			mult = (chip->settings.persistence & 0xF0) >> 4;
+		}
+
+		/* Determine integration time */
+		*val = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
+		*val2 = *val * TSL2X7X_MIN_ITIME;
+		filter_delay = *val2 * mult;
+		*val = filter_delay / 1000;
+		*val2 = filter_delay % 1000;
+		ret = IIO_VAL_INT_PLUS_MICRO;
+		break;
 	default:
 		break;
 	}
@@ -1444,10 +1388,6 @@ static DEVICE_ATTR_WO(in_proximity0_calibrate);
 
 static DEVICE_ATTR_RW(in_illuminance0_lux_table);
 
-static DEVICE_ATTR_RW(in_intensity0_thresh_period);
-
-static DEVICE_ATTR_RW(in_proximity0_thresh_period);
-
 /* Use the default register values to identify the Taos device */
 static int tsl2x7x_device_id(int *id, int target)
 {
@@ -1554,22 +1494,6 @@ static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
 	NULL
 };
 
-static struct attribute *tsl2X7X_ALS_event_attrs[] = {
-	&dev_attr_in_intensity0_thresh_period.attr,
-	NULL,
-};
-
-static struct attribute *tsl2X7X_PRX_event_attrs[] = {
-	&dev_attr_in_proximity0_thresh_period.attr,
-	NULL,
-};
-
-static struct attribute *tsl2X7X_ALSPRX_event_attrs[] = {
-	&dev_attr_in_intensity0_thresh_period.attr,
-	&dev_attr_in_proximity0_thresh_period.attr,
-	NULL,
-};
-
 static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
 	[ALS] = {
 		.attrs = tsl2x7x_ALS_device_attrs,
@@ -1588,25 +1512,9 @@ static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
 	},
 };
 
-static const struct attribute_group tsl2X7X_event_attr_group_tbl[] = {
-	[ALS] = {
-		.attrs = tsl2X7X_ALS_event_attrs,
-		.name = "events",
-	},
-	[PRX] = {
-		.attrs = tsl2X7X_PRX_event_attrs,
-		.name = "events",
-	},
-	[ALSPRX] = {
-		.attrs = tsl2X7X_ALSPRX_event_attrs,
-		.name = "events",
-	},
-};
-
 static const struct iio_info tsl2X7X_device_info[] = {
 	[ALS] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALS],
-		.event_attrs = &tsl2X7X_event_attr_group_tbl[ALS],
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
 		.read_event_value = &tsl2x7x_read_event_value,
@@ -1616,7 +1524,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
 	},
 	[PRX] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
-		.event_attrs = &tsl2X7X_event_attr_group_tbl[PRX],
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
 		.read_event_value = &tsl2x7x_read_event_value,
@@ -1626,7 +1533,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
 	},
 	[ALSPRX] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
-		.event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX],
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
 		.read_event_value = &tsl2x7x_read_event_value,
@@ -1636,7 +1542,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
 	},
 	[PRX2] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
-		.event_attrs = &tsl2X7X_event_attr_group_tbl[PRX],
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
 		.read_event_value = &tsl2x7x_read_event_value,
@@ -1646,7 +1551,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
 	},
 	[ALSPRX2] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
-		.event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX],
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
 		.read_event_value = &tsl2x7x_read_event_value,
@@ -1667,6 +1571,10 @@ static const struct iio_event_spec tsl2x7x_events[] = {
 		.dir = IIO_EV_DIR_FALLING,
 		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
 			BIT(IIO_EV_INFO_ENABLE),
+	}, {
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_NONE,
+		.mask_separate = BIT(IIO_EV_INFO_PERIOD),
 	},
 };
 
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings
  2017-09-30  1:09 ` [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings Brian Masney
@ 2017-10-01 10:08   ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:08 UTC (permalink / raw)
  To: Brian Masney
  Cc: linux-iio, gregkh, devel, knaack.h, lars, pmeerw, linux-kernel,
	Jon.Brenner

On Fri, 29 Sep 2017 21:09:19 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The length of the 'tsl2x7x_settings' variable within the tsl2X7X_chip
> structure makes some of the line lengths greater than 80 characters for
> upcoming patches. This patch shortens the name of the 'tsl2x7x_settings'
> variable in this structure to just 'settings' to improve code
> readability.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>

Hi Brian,

A few things have sneaked in here that aren't technically part of
the described change.  Should have been mentioned in the description
however trivial they are.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/staging/iio/light/tsl2x7x.c | 183 +++++++++++++++++-------------------
>  1 file changed, 85 insertions(+), 98 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index d9defc8ece83..e340ea624e5c 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -174,7 +174,7 @@ struct tsl2X7X_chip {
>  	struct i2c_client *client;
>  	u16 prox_data;
>  	struct tsl2x7x_als_info als_cur_info;
> -	struct tsl2x7x_settings tsl2x7x_settings;
> +	struct tsl2x7x_settings settings;
>  	struct tsl2X7X_platform_data *pdata;
>  	int als_time_scale;
>  	int als_saturation;
> @@ -390,9 +390,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  		lux = 0;
>  	} else {
>  		ch0lux = DIV_ROUND_UP(ch0 * p->ch0,
> -			tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
> +			tsl2X7X_als_gainadj[chip->settings.als_gain]);
>  		ch1lux = DIV_ROUND_UP(ch1 * p->ch1,
> -			tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
> +			tsl2X7X_als_gainadj[chip->settings.als_gain]);
>  		lux = ch0lux - ch1lux;
>  	}
>  
> @@ -419,7 +419,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
>  	 */
>  
>  	lux64 = lux;
> -	lux64 = lux64 * chip->tsl2x7x_settings.als_gain_trim;
> +	lux64 = lux64 * chip->settings.als_gain_trim;
>  	lux64 >>= 8;
>  	lux = lux64;
>  	lux = (lux + 500) / 1000;
> @@ -514,12 +514,10 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
>  {
>  	/* If Operational settings defined elsewhere.. */
>  	if (chip->pdata && chip->pdata->platform_default_settings)
> -		memcpy(&chip->tsl2x7x_settings,
> -		       chip->pdata->platform_default_settings,
> +		memcpy(&chip->settings, chip->pdata->platform_default_settings,
>  		       sizeof(tsl2x7x_default_settings));
>  	else
> -		memcpy(&chip->tsl2x7x_settings,
> -		       &tsl2x7x_default_settings,
> +		memcpy(&chip->settings, &tsl2x7x_default_settings,
>  		       sizeof(tsl2x7x_default_settings));
>  
>  	/* Load up the proper lux table. */
> @@ -542,9 +540,7 @@ static void tsl2x7x_defaults(struct tsl2X7X_chip *chip)
>  static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int gain_trim_val;

This change doesn't have much to do with the rename..

> -	int ret;
> -	int lux_val;
> +	int ret, lux_val;
>  
>  	ret = i2c_smbus_read_byte_data(chip->client,
>  				       TSL2X7X_CMD_REG | TSL2X7X_CNTRL);
> @@ -575,16 +571,16 @@ static int tsl2x7x_als_calibrate(struct iio_dev *indio_dev)
>  		return lux_val;
>  	}
>  
> -	gain_trim_val =  ((chip->tsl2x7x_settings.als_cal_target)
> -			* chip->tsl2x7x_settings.als_gain_trim) / lux_val;
> -	if ((gain_trim_val < 250) || (gain_trim_val > 4000))
> +	ret = (chip->settings.als_cal_target * chip->settings.als_gain_trim) /
> +			lux_val;
> +	if (ret < 250 || ret > 4000)
>  		return -ERANGE;
>  
> -	chip->tsl2x7x_settings.als_gain_trim = gain_trim_val;
> +	chip->settings.als_gain_trim = ret;
>  	dev_info(&chip->client->dev,
>  		 "%s als_calibrate completed\n", chip->client->name);
>  
> -	return (int)gain_trim_val;
> +	return ret;
>  }
>  
>  static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
> @@ -602,34 +598,30 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  		chip->pdata->power_on(indio_dev);
>  
>  	/* Non calculated parameters */
> -	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] =
> -			chip->tsl2x7x_settings.prx_time;
> -	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] =
> -			chip->tsl2x7x_settings.wait_time;
> -	chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] =
> -			chip->tsl2x7x_settings.prox_config;
> +	chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prx_time;
> +	chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time;
> +	chip->tsl2x7x_config[TSL2X7X_PRX_CONFIG] = chip->settings.prox_config;
>  
>  	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHLO] =
> -		(chip->tsl2x7x_settings.als_thresh_low) & 0xFF;
> +		(chip->settings.als_thresh_low) & 0xFF;
>  	chip->tsl2x7x_config[TSL2X7X_ALS_MINTHRESHHI] =
> -		(chip->tsl2x7x_settings.als_thresh_low >> 8) & 0xFF;
> +		(chip->settings.als_thresh_low >> 8) & 0xFF;
>  	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHLO] =
> -		(chip->tsl2x7x_settings.als_thresh_high) & 0xFF;
> +		(chip->settings.als_thresh_high) & 0xFF;
>  	chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
> -		(chip->tsl2x7x_settings.als_thresh_high >> 8) & 0xFF;
> -	chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] =
> -		chip->tsl2x7x_settings.persistence;
> +		(chip->settings.als_thresh_high >> 8) & 0xFF;
> +	chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] = chip->settings.persistence;
>  
>  	chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] =
> -			chip->tsl2x7x_settings.prox_pulse_count;
> +			chip->settings.prox_pulse_count;
>  	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHLO] =
> -			(chip->tsl2x7x_settings.prox_thres_low) & 0xFF;
> +			(chip->settings.prox_thres_low) & 0xFF;
>  	chip->tsl2x7x_config[TSL2X7X_PRX_MINTHRESHHI] =
> -			(chip->tsl2x7x_settings.prox_thres_low >> 8) & 0xFF;
> +			(chip->settings.prox_thres_low >> 8) & 0xFF;
>  	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHLO] =
> -			(chip->tsl2x7x_settings.prox_thres_high) & 0xFF;
> +			(chip->settings.prox_thres_high) & 0xFF;
>  	chip->tsl2x7x_config[TSL2X7X_PRX_MAXTHRESHHI] =
> -			(chip->tsl2x7x_settings.prox_thres_high >> 8) & 0xFF;
> +			(chip->settings.prox_thres_high >> 8) & 0xFF;
>  
>  	/* and make sure we're not already on */
>  	if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) {
> @@ -639,7 +631,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  	}
>  
>  	/* determine als integration register */
> -	als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270;
> +	als_count = (chip->settings.als_time * 100 + 135) / 270;
>  	if (!als_count)
>  		als_count = 1; /* ensure at least one cycle */
>  
> @@ -649,9 +641,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  
>  	/* Set the gain based on tsl2x7x_settings struct */
>  	chip->tsl2x7x_config[TSL2X7X_GAIN] =
> -		chip->tsl2x7x_settings.als_gain |
> -			(TSL2X7X_mA100 | TSL2X7X_DIODE1)
> -			| ((chip->tsl2x7x_settings.prox_gain) << 2);
> +		chip->settings.als_gain |
> +			(TSL2X7X_mA100 | TSL2X7X_DIODE1) |
> +			(chip->settings.prox_gain << 2);
>  
>  	/* set chip struct re scaling and saturation */
>  	chip->als_saturation = als_count * 922; /* 90% of full scale */
> @@ -706,15 +698,15 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
>  
>  	chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING;
>  
> -	if (chip->tsl2x7x_settings.interrupts_en != 0) {
> +	if (chip->settings.interrupts_en != 0) {
>  		dev_info(&chip->client->dev, "Setting Up Interrupt(s)\n");
>  
>  		reg_val = TSL2X7X_CNTL_PWR_ON | TSL2X7X_CNTL_ADC_ENBL;
> -		if ((chip->tsl2x7x_settings.interrupts_en == 0x20) ||
> -		    (chip->tsl2x7x_settings.interrupts_en == 0x30))
> +		if ((chip->settings.interrupts_en == 0x20) ||
> +		    (chip->settings.interrupts_en == 0x30))
>  			reg_val |= TSL2X7X_CNTL_PROX_DET_ENBL;
>  
> -		reg_val |= chip->tsl2x7x_settings.interrupts_en;
> +		reg_val |= chip->settings.interrupts_en;
>  		ret = i2c_smbus_write_byte_data(chip->client,
>  						(TSL2X7X_CMD_REG |
>  						TSL2X7X_CNTRL), reg_val);
> @@ -837,25 +829,25 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  	u8 tmp_irq_settings;
>  	u8 current_state = chip->tsl2x7x_chip_status;
>  
> -	if (chip->tsl2x7x_settings.prox_max_samples_cal > MAX_SAMPLES_CAL) {
> +	if (chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL) {
>  		dev_err(&chip->client->dev,
>  			"max prox samples cal is too big: %d\n",
> -			chip->tsl2x7x_settings.prox_max_samples_cal);
> -		chip->tsl2x7x_settings.prox_max_samples_cal = MAX_SAMPLES_CAL;
> +			chip->settings.prox_max_samples_cal);
> +		chip->settings.prox_max_samples_cal = MAX_SAMPLES_CAL;
>  	}
>  
>  	/* have to stop to change settings */
>  	tsl2x7x_chip_off(indio_dev);
>  
>  	/* Enable proximity detection save just in case prox not wanted yet*/
> -	tmp_irq_settings = chip->tsl2x7x_settings.interrupts_en;
> -	chip->tsl2x7x_settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
> +	tmp_irq_settings = chip->settings.interrupts_en;
> +	chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL;
>  
>  	/*turn on device if not already on*/
>  	tsl2x7x_chip_on(indio_dev);
>  
>  	/*gather the samples*/
> -	for (i = 0; i < chip->tsl2x7x_settings.prox_max_samples_cal; i++) {
> +	for (i = 0; i < chip->settings.prox_max_samples_cal; i++) {
>  		usleep_range(15000, 17500);
>  		tsl2x7x_get_prox(indio_dev);
>  		prox_history[i] = chip->prox_data;
> @@ -866,18 +858,17 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev)
>  	tsl2x7x_chip_off(indio_dev);
>  	calP = &prox_stat_data[PROX_STAT_CAL];
>  	tsl2x7x_prox_calculate(prox_history,
> -			       chip->tsl2x7x_settings.prox_max_samples_cal,
> -			       calP);
> -	chip->tsl2x7x_settings.prox_thres_high = (calP->max << 1) - calP->mean;
> +			       chip->settings.prox_max_samples_cal, calP);
> +	chip->settings.prox_thres_high = (calP->max << 1) - calP->mean;
>  
>  	dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n",
>  		 calP->min, calP->mean, calP->max);
>  	dev_info(&chip->client->dev,
>  		 "%s proximity threshold set to %d\n",
> -		 chip->client->name, chip->tsl2x7x_settings.prox_thres_high);
> +		 chip->client->name, chip->settings.prox_thres_high);
>  
>  	/* back to the way they were */
> -	chip->tsl2x7x_settings.interrupts_en = tmp_irq_settings;
> +	chip->settings.interrupts_en = tmp_irq_settings;
>  	if (current_state == TSL2X7X_CHIP_WORKING)
>  		tsl2x7x_chip_on(indio_dev);
>  }
> @@ -914,7 +905,7 @@ static ssize_t in_illuminance0_integration_time_show(struct device *dev,
>  	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
>  	int y, z;
>  
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
> +	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
>  	z = y * TSL2X7X_MIN_ITIME;
>  	y /= 1000;
>  	z %= 1000;
> @@ -936,11 +927,10 @@ static ssize_t in_illuminance0_integration_time_store(struct device *dev,
>  		return ret;
>  
>  	result.fract /= 3;
> -	chip->tsl2x7x_settings.als_time =
> -			TSL2X7X_MAX_TIMER_CNT - (u8)result.fract;
> +	chip->settings.als_time = TSL2X7X_MAX_TIMER_CNT - (u8)result.fract;
>  
>  	dev_info(&chip->client->dev, "%s: als time = %d",
> -		 __func__, chip->tsl2x7x_settings.als_time);
> +		 __func__, chip->settings.als_time);
>  
>  	tsl2x7x_invoke_change(indio_dev);
>  
> @@ -956,8 +946,7 @@ static ssize_t in_illuminance0_target_input_show(struct device *dev,
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
>  
> -	return snprintf(buf, PAGE_SIZE, "%d\n",
> -			chip->tsl2x7x_settings.als_cal_target);
> +	return snprintf(buf, PAGE_SIZE, "%d\n", chip->settings.als_cal_target);
>  }
>  
>  static ssize_t in_illuminance0_target_input_store(struct device *dev,
> @@ -973,7 +962,7 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
>  		return -EINVAL;
>  
>  	if (value)
> -		chip->tsl2x7x_settings.als_cal_target = value;
> +		chip->settings.als_cal_target = value;
>  
>  	ret = tsl2x7x_invoke_change(indio_dev);
>  	if (ret < 0)
> @@ -991,9 +980,9 @@ static ssize_t in_intensity0_thresh_period_show(struct device *dev,
>  	int y, z, filter_delay;
>  
>  	/* Determine integration time */
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
> +	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
>  	z = y * TSL2X7X_MIN_ITIME;
> -	filter_delay = z * (chip->tsl2x7x_settings.persistence & 0x0F);
> +	filter_delay = z * (chip->settings.persistence & 0x0F);
>  	y = filter_delay / 1000;
>  	z = filter_delay % 1000;
>  
> @@ -1014,14 +1003,14 @@ static ssize_t in_intensity0_thresh_period_store(struct device *dev,
>  	if (ret)
>  		return ret;
>  
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
> +	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
>  	z = y * TSL2X7X_MIN_ITIME;
>  
>  	filter_delay =
>  		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
>  
> -	chip->tsl2x7x_settings.persistence &= 0xF0;
> -	chip->tsl2x7x_settings.persistence |= (filter_delay & 0x0F);
> +	chip->settings.persistence &= 0xF0;
> +	chip->settings.persistence |= (filter_delay & 0x0F);
>  
>  	dev_info(&chip->client->dev, "%s: als persistence = %d",
>  		 __func__, filter_delay);
> @@ -1041,9 +1030,9 @@ static ssize_t in_proximity0_thresh_period_show(struct device *dev,
>  	int y, z, filter_delay;
>  
>  	/* Determine integration time */
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
> +	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
>  	z = y * TSL2X7X_MIN_ITIME;
> -	filter_delay = z * ((chip->tsl2x7x_settings.persistence & 0xF0) >> 4);
> +	filter_delay = z * ((chip->settings.persistence & 0xF0) >> 4);
>  	y = filter_delay / 1000;
>  	z = filter_delay % 1000;
>  
> @@ -1064,14 +1053,14 @@ static ssize_t in_proximity0_thresh_period_store(struct device *dev,
>  	if (ret)
>  		return ret;
>  
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
> +	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
>  	z = y * TSL2X7X_MIN_ITIME;
>  
>  	filter_delay =
>  		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
>  
> -	chip->tsl2x7x_settings.persistence &= 0x0F;
> -	chip->tsl2x7x_settings.persistence |= ((filter_delay << 4) & 0xF0);
> +	chip->settings.persistence &= 0x0F;
> +	chip->settings.persistence |= ((filter_delay << 4) & 0xF0);
>  
>  	dev_info(&chip->client->dev, "%s: prox persistence = %d",
>  		 __func__, filter_delay);
> @@ -1205,9 +1194,9 @@ static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
>  	int ret;
>  
>  	if (chan->type == IIO_INTENSITY)
> -		ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x10);
> +		ret = !!(chip->settings.interrupts_en & 0x10);
>  	else
> -		ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x20);
> +		ret = !!(chip->settings.interrupts_en & 0x20);
>  
>  	return ret;
>  }
> @@ -1223,14 +1212,14 @@ static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
>  
>  	if (chan->type == IIO_INTENSITY) {
>  		if (val)
> -			chip->tsl2x7x_settings.interrupts_en |= 0x10;
> +			chip->settings.interrupts_en |= 0x10;
>  		else
> -			chip->tsl2x7x_settings.interrupts_en &= 0x20;
> +			chip->settings.interrupts_en &= 0x20;
>  	} else {
>  		if (val)
> -			chip->tsl2x7x_settings.interrupts_en |= 0x20;
> +			chip->settings.interrupts_en |= 0x20;
>  		else
> -			chip->tsl2x7x_settings.interrupts_en &= 0x10;
> +			chip->settings.interrupts_en &= 0x10;
>  	}
>  
>  	ret = tsl2x7x_invoke_change(indio_dev);
> @@ -1255,11 +1244,11 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  		if (chan->type == IIO_INTENSITY) {
>  			switch (dir) {
>  			case IIO_EV_DIR_RISING:
> -				chip->tsl2x7x_settings.als_thresh_high = val;
> +				chip->settings.als_thresh_high = val;
>  				ret = 0;
>  				break;
>  			case IIO_EV_DIR_FALLING:
> -				chip->tsl2x7x_settings.als_thresh_low = val;
> +				chip->settings.als_thresh_low = val;
>  				ret = 0;
>  				break;
>  			default:
> @@ -1268,11 +1257,11 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  		} else {
>  			switch (dir) {
>  			case IIO_EV_DIR_RISING:
> -				chip->tsl2x7x_settings.prox_thres_high = val;
> +				chip->settings.prox_thres_high = val;
>  				ret = 0;
>  				break;
>  			case IIO_EV_DIR_FALLING:
> -				chip->tsl2x7x_settings.prox_thres_low = val;
> +				chip->settings.prox_thres_low = val;
>  				ret = 0;
>  				break;
>  			default:
> @@ -1305,11 +1294,11 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  		if (chan->type == IIO_INTENSITY) {
>  			switch (dir) {
>  			case IIO_EV_DIR_RISING:
> -				*val = chip->tsl2x7x_settings.als_thresh_high;
> +				*val = chip->settings.als_thresh_high;
>  				ret = IIO_VAL_INT;
>  				break;
>  			case IIO_EV_DIR_FALLING:
> -				*val = chip->tsl2x7x_settings.als_thresh_low;
> +				*val = chip->settings.als_thresh_low;
>  				ret = IIO_VAL_INT;
>  				break;
>  			default:
> @@ -1318,11 +1307,11 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  		} else {
>  			switch (dir) {
>  			case IIO_EV_DIR_RISING:
> -				*val = chip->tsl2x7x_settings.prox_thres_high;
> +				*val = chip->settings.prox_thres_high;
>  				ret = IIO_VAL_INT;
>  				break;
>  			case IIO_EV_DIR_FALLING:
> -				*val = chip->tsl2x7x_settings.prox_thres_low;
> +				*val = chip->settings.prox_thres_low;
>  				ret = IIO_VAL_INT;
>  				break;
>  			default:
> @@ -1379,15 +1368,13 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  		break;
>  	case IIO_CHAN_INFO_CALIBSCALE:
>  		if (chan->type == IIO_LIGHT)
> -			*val =
> -			tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain];
> +			*val = tsl2X7X_als_gainadj[chip->settings.als_gain];
>  		else
> -			*val =
> -			tsl2X7X_prx_gainadj[chip->tsl2x7x_settings.prox_gain];
> +			*val = tsl2X7X_prx_gainadj[chip->settings.prox_gain];
>  		ret = IIO_VAL_INT;
>  		break;
>  	case IIO_CHAN_INFO_CALIBBIAS:
> -		*val = chip->tsl2x7x_settings.als_gain_trim;
> +		*val = chip->settings.als_gain_trim;
>  		ret = IIO_VAL_INT;
>  		break;
>  
> @@ -1411,13 +1398,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		if (chan->type == IIO_INTENSITY) {
>  			switch (val) {
>  			case 1:
> -				chip->tsl2x7x_settings.als_gain = 0;
> +				chip->settings.als_gain = 0;
>  				break;
>  			case 8:
> -				chip->tsl2x7x_settings.als_gain = 1;
> +				chip->settings.als_gain = 1;
>  				break;
>  			case 16:
> -				chip->tsl2x7x_settings.als_gain = 2;
> +				chip->settings.als_gain = 2;
>  				break;
>  			case 120:
>  				switch (chip->id) {
> @@ -1428,7 +1415,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  				case tmd2772:
>  					return -EINVAL;
>  				}
> -				chip->tsl2x7x_settings.als_gain = 3;
> +				chip->settings.als_gain = 3;
>  				break;
>  			case 128:
>  				switch (chip->id) {
> @@ -1439,7 +1426,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  				case tmd2771:
>  					return -EINVAL;
>  				}
> -				chip->tsl2x7x_settings.als_gain = 3;
> +				chip->settings.als_gain = 3;
>  				break;
>  			default:
>  				return -EINVAL;
> @@ -1447,16 +1434,16 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		} else {
>  			switch (val) {
>  			case 1:
> -				chip->tsl2x7x_settings.prox_gain = 0;
> +				chip->settings.prox_gain = 0;
>  				break;
>  			case 2:
> -				chip->tsl2x7x_settings.prox_gain = 1;
> +				chip->settings.prox_gain = 1;
>  				break;
>  			case 4:
> -				chip->tsl2x7x_settings.prox_gain = 2;
> +				chip->settings.prox_gain = 2;
>  				break;
>  			case 8:
> -				chip->tsl2x7x_settings.prox_gain = 3;
> +				chip->settings.prox_gain = 3;
>  				break;
>  			default:
>  				return -EINVAL;
> @@ -1464,7 +1451,7 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  		}
>  		break;
>  	case IIO_CHAN_INFO_CALIBBIAS:
> -		chip->tsl2x7x_settings.als_gain_trim = val;
> +		chip->settings.als_gain_trim = val;
>  		break;
>  
>  	default:

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec
  2017-09-30  1:09 ` [PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec Brian Masney
@ 2017-10-01 10:10   ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:10 UTC (permalink / raw)
  To: Brian Masney
  Cc: linux-iio, gregkh, devel, knaack.h, lars, pmeerw, linux-kernel,
	Jon.Brenner

On Fri, 29 Sep 2017 21:09:20 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The driver explicitly creates the in_illuminance0_integration_time sysfs
> attribute outside the IIO core. This attribute is available in the IIO
> core so this patches migrates the attribute to be created by
> the iio_chan_spec.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>

One comment inline, but a general observation rather than about this
patch so applied to the togreg branch of iio.git and pushed out as
testing.

Thanks,

Jonathan
> ---
> Changes since v1 (Jul 9 2017):
> - Use MIN_ITIME instead of hardcoded 3 in tsl2x7x_write_raw()
> 
>  drivers/staging/iio/light/tsl2x7x.c | 65 ++++++++++---------------------------
>  1 file changed, 17 insertions(+), 48 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index e340ea624e5c..e6a71f5fc9cb 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -898,45 +898,6 @@ static ssize_t in_proximity0_calibscale_available_show(struct device *dev,
>  		return snprintf(buf, PAGE_SIZE, "%s\n", "1 2 4 8");
>  }
>  
> -static ssize_t in_illuminance0_integration_time_show(struct device *dev,
> -				     struct device_attribute *attr,
> -				     char *buf)
> -{
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> -	int y, z;
> -
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
> -	z = y * TSL2X7X_MIN_ITIME;
> -	y /= 1000;
> -	z %= 1000;
> -
> -	return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
> -}
> -
> -static ssize_t in_illuminance0_integration_time_store(struct device *dev,
> -				      struct device_attribute *attr,
> -				      const char *buf, size_t len)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	struct tsl2x7x_parse_result result;
> -	int ret;
> -
> -	ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
> -	if (ret)
> -		return ret;
> -
> -	result.fract /= 3;
> -	chip->settings.als_time = TSL2X7X_MAX_TIMER_CNT - (u8)result.fract;
> -
> -	dev_info(&chip->client->dev, "%s: als time = %d",
> -		 __func__, chip->settings.als_time);
> -
> -	tsl2x7x_invoke_change(indio_dev);
> -
> -	return IIO_VAL_INT_PLUS_MICRO;
> -}
> -
>  static IIO_CONST_ATTR(in_illuminance0_integration_time_available,
>  		".00272 - .696");
>  
> @@ -1377,7 +1338,11 @@ static int tsl2x7x_read_raw(struct iio_dev *indio_dev,
>  		*val = chip->settings.als_gain_trim;
>  		ret = IIO_VAL_INT;
>  		break;
> -
> +	case IIO_CHAN_INFO_INT_TIME:
> +		*val = (TSL2X7X_MAX_TIMER_CNT - chip->settings.als_time) + 1;
> +		*val2 = ((*val * TSL2X7X_MIN_ITIME) % 1000) / 1000;
> +		ret = IIO_VAL_INT_PLUS_MICRO;
> +		break;
>  	default:
>  		ret = -EINVAL;
>  	}
> @@ -1453,7 +1418,13 @@ static int tsl2x7x_write_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		chip->settings.als_gain_trim = val;
>  		break;
> +	case IIO_CHAN_INFO_INT_TIME:
> +		chip->settings.als_time =
> +			TSL2X7X_MAX_TIMER_CNT - (val2 / TSL2X7X_MIN_ITIME);
>  
> +		dev_info(&chip->client->dev, "%s: als time = %d",
> +			 __func__, chip->settings.als_time);
> +		break;

I'm not sure this dev_info is terribly useful for anything - however
not an issue with this patch as you have simply moved it..

>  	default:
>  		return -EINVAL;
>  	}
> @@ -1465,8 +1436,6 @@ static DEVICE_ATTR_RO(in_proximity0_calibscale_available);
>  
>  static DEVICE_ATTR_RO(in_illuminance0_calibscale_available);
>  
> -static DEVICE_ATTR_RW(in_illuminance0_integration_time);
> -
>  static DEVICE_ATTR_RW(in_illuminance0_target_input);
>  
>  static DEVICE_ATTR_WO(in_illuminance0_calibrate);
> @@ -1546,7 +1515,6 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private)
>  
>  static struct attribute *tsl2x7x_ALS_device_attrs[] = {
>  	&dev_attr_in_illuminance0_calibscale_available.attr,
> -	&dev_attr_in_illuminance0_integration_time.attr,
>  	&iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
> @@ -1561,7 +1529,6 @@ static struct attribute *tsl2x7x_PRX_device_attrs[] = {
>  
>  static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
>  	&dev_attr_in_illuminance0_calibscale_available.attr,
> -	&dev_attr_in_illuminance0_integration_time.attr,
>  	&iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
> @@ -1578,7 +1545,6 @@ static struct attribute *tsl2x7x_PRX2_device_attrs[] = {
>  
>  static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
>  	&dev_attr_in_illuminance0_calibscale_available.attr,
> -	&dev_attr_in_illuminance0_integration_time.attr,
>  	&iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
>  	&dev_attr_in_illuminance0_target_input.attr,
>  	&dev_attr_in_illuminance0_calibrate.attr,
> @@ -1711,7 +1677,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.type = IIO_LIGHT,
>  			.indexed = 1,
>  			.channel = 0,
> -			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> +					      BIT(IIO_CHAN_INFO_INT_TIME),
>  			}, {
>  			.type = IIO_INTENSITY,
>  			.indexed = 1,
> @@ -1750,7 +1717,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.type = IIO_LIGHT,
>  			.indexed = 1,
>  			.channel = 0,
> -			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED)
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> +					      BIT(IIO_CHAN_INFO_INT_TIME),
>  			}, {
>  			.type = IIO_INTENSITY,
>  			.indexed = 1,
> @@ -1798,7 +1766,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
>  			.type = IIO_LIGHT,
>  			.indexed = 1,
>  			.channel = 0,
> -			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> +					      BIT(IIO_CHAN_INFO_INT_TIME),
>  			}, {
>  			.type = IIO_INTENSITY,
>  			.indexed = 1,

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec
  2017-09-30  1:09 ` [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec Brian Masney
@ 2017-10-01 10:14   ` Jonathan Cameron
  2017-10-01 10:58     ` Brian Masney
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-01 10:14 UTC (permalink / raw)
  To: Brian Masney
  Cc: linux-iio, gregkh, devel, knaack.h, lars, pmeerw, linux-kernel,
	Jon.Brenner

On Fri, 29 Sep 2017 21:09:21 -0400
Brian Masney <masneyb@onstation.org> wrote:

> The sysfs attributes in_intensity0_thresh_period and
> in_proximity0_thresh_period are currently directly created by the driver.
> This patch migrates the creation of these sysfs attributes from the driver
> to using the IIO core via iio_event_spec.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>

One question down the end about whether we should be using IIO_EV_DIR_EITHER
rather than IIO_EV_DIR_NONE

NONE is only really for thing where a direction makes not sense rather
than to remove the direction be specified for a particular element.

Otherwise looks good.  I'd just have changed this, but wasn't sure if
there was deeper logic behind your choice that I was missing!

Jonathan

> ---
>  drivers/staging/iio/light/tsl2x7x.c | 196 ++++++++++--------------------------
>  1 file changed, 52 insertions(+), 144 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index e6a71f5fc9cb..be2806593e59 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -932,108 +932,6 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
>  	return len;
>  }
>  
> -/* persistence settings */
> -static ssize_t in_intensity0_thresh_period_show(struct device *dev,
> -					    struct device_attribute *attr,
> -					    char *buf)
> -{
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> -	int y, z, filter_delay;
> -
> -	/* Determine integration time */
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
> -	z = y * TSL2X7X_MIN_ITIME;
> -	filter_delay = z * (chip->settings.persistence & 0x0F);
> -	y = filter_delay / 1000;
> -	z = filter_delay % 1000;
> -
> -	return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
> -}
> -
> -static ssize_t in_intensity0_thresh_period_store(struct device *dev,
> -					     struct device_attribute *attr,
> -					     const char *buf, size_t len)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	struct tsl2x7x_parse_result result;
> -	int y, z, filter_delay;
> -	int ret;
> -
> -	ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
> -	if (ret)
> -		return ret;
> -
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.als_time) + 1;
> -	z = y * TSL2X7X_MIN_ITIME;
> -
> -	filter_delay =
> -		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
> -
> -	chip->settings.persistence &= 0xF0;
> -	chip->settings.persistence |= (filter_delay & 0x0F);
> -
> -	dev_info(&chip->client->dev, "%s: als persistence = %d",
> -		 __func__, filter_delay);
> -
> -	ret = tsl2x7x_invoke_change(indio_dev);
> -	if (ret < 0)
> -		return ret;
> -
> -	return IIO_VAL_INT_PLUS_MICRO;
> -}
> -
> -static ssize_t in_proximity0_thresh_period_show(struct device *dev,
> -					     struct device_attribute *attr,
> -					     char *buf)
> -{
> -	struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
> -	int y, z, filter_delay;
> -
> -	/* Determine integration time */
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
> -	z = y * TSL2X7X_MIN_ITIME;
> -	filter_delay = z * ((chip->settings.persistence & 0xF0) >> 4);
> -	y = filter_delay / 1000;
> -	z = filter_delay % 1000;
> -
> -	return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
> -}
> -
> -static ssize_t in_proximity0_thresh_period_store(struct device *dev,
> -					      struct device_attribute *attr,
> -					      const char *buf, size_t len)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	struct tsl2x7x_parse_result result;
> -	int y, z, filter_delay;
> -	int ret;
> -
> -	ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
> -	if (ret)
> -		return ret;
> -
> -	y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->settings.prx_time) + 1;
> -	z = y * TSL2X7X_MIN_ITIME;
> -
> -	filter_delay =
> -		DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
> -
> -	chip->settings.persistence &= 0x0F;
> -	chip->settings.persistence |= ((filter_delay << 4) & 0xF0);
> -
> -	dev_info(&chip->client->dev, "%s: prox persistence = %d",
> -		 __func__, filter_delay);
> -
> -	ret = tsl2x7x_invoke_change(indio_dev);
> -	if (ret < 0)
> -		return ret;
> -
> -
> -	return IIO_VAL_INT_PLUS_MICRO;
> -}
> -
>  static ssize_t in_illuminance0_calibrate_store(struct device *dev,
>  				    struct device_attribute *attr,
>  				    const char *buf, size_t len)
> @@ -1198,7 +1096,8 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  				     int val, int val2)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int ret = -EINVAL;
> +	int ret = -EINVAL, y, z, filter_delay;
> +	u8 time;
>  
>  	switch (info) {
>  	case IIO_EV_INFO_VALUE:
> @@ -1230,6 +1129,33 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
>  			}
>  		}
>  		break;
> +	case IIO_EV_INFO_PERIOD:
> +		if (chan->type == IIO_INTENSITY)
> +			time = chip->settings.als_time;
> +		else
> +			time = chip->settings.prx_time;
> +
> +		y = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
> +		z = y * TSL2X7X_MIN_ITIME;
> +
> +		filter_delay = DIV_ROUND_UP((val * 1000) + val2, z);
> +
> +		if (chan->type == IIO_INTENSITY) {
> +			chip->settings.persistence &= 0xF0;
> +			chip->settings.persistence |=
> +				(filter_delay & 0x0F);
> +			dev_info(&chip->client->dev, "%s: ALS persistence = %d",
> +				 __func__, filter_delay);
> +		} else {
> +			chip->settings.persistence &= 0x0F;
> +			chip->settings.persistence |=
> +				((filter_delay << 4) & 0xF0);
> +			dev_info(&chip->client->dev,
> +				 "%s: Proximity persistence = %d",
> +				 __func__, filter_delay);
> +		}
> +		ret = 0;
> +		break;
>  	default:
>  		break;
>  	}
> @@ -1248,7 +1174,8 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  				    int *val, int *val2)
>  {
>  	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
> -	int ret = -EINVAL;
> +	int ret = -EINVAL, filter_delay, mult;
> +	u8 time;
>  
>  	switch (info) {
>  	case IIO_EV_INFO_VALUE:
> @@ -1280,6 +1207,23 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
>  			}
>  		}
>  		break;
> +	case IIO_EV_INFO_PERIOD:
> +		if (chan->type == IIO_INTENSITY) {
> +			time = chip->settings.als_time;
> +			mult = chip->settings.persistence & 0x0F;
> +		} else {
> +			time = chip->settings.prx_time;
> +			mult = (chip->settings.persistence & 0xF0) >> 4;
> +		}
> +
> +		/* Determine integration time */
> +		*val = (TSL2X7X_MAX_TIMER_CNT - time) + 1;
> +		*val2 = *val * TSL2X7X_MIN_ITIME;
> +		filter_delay = *val2 * mult;
> +		*val = filter_delay / 1000;
> +		*val2 = filter_delay % 1000;
> +		ret = IIO_VAL_INT_PLUS_MICRO;
> +		break;
>  	default:
>  		break;
>  	}
> @@ -1444,10 +1388,6 @@ static DEVICE_ATTR_WO(in_proximity0_calibrate);
>  
>  static DEVICE_ATTR_RW(in_illuminance0_lux_table);
>  
> -static DEVICE_ATTR_RW(in_intensity0_thresh_period);
> -
> -static DEVICE_ATTR_RW(in_proximity0_thresh_period);
> -
>  /* Use the default register values to identify the Taos device */
>  static int tsl2x7x_device_id(int *id, int target)
>  {
> @@ -1554,22 +1494,6 @@ static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
>  	NULL
>  };
>  
> -static struct attribute *tsl2X7X_ALS_event_attrs[] = {
> -	&dev_attr_in_intensity0_thresh_period.attr,
> -	NULL,
> -};
> -
> -static struct attribute *tsl2X7X_PRX_event_attrs[] = {
> -	&dev_attr_in_proximity0_thresh_period.attr,
> -	NULL,
> -};
> -
> -static struct attribute *tsl2X7X_ALSPRX_event_attrs[] = {
> -	&dev_attr_in_intensity0_thresh_period.attr,
> -	&dev_attr_in_proximity0_thresh_period.attr,
> -	NULL,
> -};
> -
>  static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
>  	[ALS] = {
>  		.attrs = tsl2x7x_ALS_device_attrs,
> @@ -1588,25 +1512,9 @@ static const struct attribute_group tsl2X7X_device_attr_group_tbl[] = {
>  	},
>  };
>  
> -static const struct attribute_group tsl2X7X_event_attr_group_tbl[] = {
> -	[ALS] = {
> -		.attrs = tsl2X7X_ALS_event_attrs,
> -		.name = "events",
> -	},
> -	[PRX] = {
> -		.attrs = tsl2X7X_PRX_event_attrs,
> -		.name = "events",
> -	},
> -	[ALSPRX] = {
> -		.attrs = tsl2X7X_ALSPRX_event_attrs,
> -		.name = "events",
> -	},
> -};
> -
>  static const struct iio_info tsl2X7X_device_info[] = {
>  	[ALS] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALS],
> -		.event_attrs = &tsl2X7X_event_attr_group_tbl[ALS],
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
>  		.read_event_value = &tsl2x7x_read_event_value,
> @@ -1616,7 +1524,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  	},
>  	[PRX] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
> -		.event_attrs = &tsl2X7X_event_attr_group_tbl[PRX],
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
>  		.read_event_value = &tsl2x7x_read_event_value,
> @@ -1626,7 +1533,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  	},
>  	[ALSPRX] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
> -		.event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX],
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
>  		.read_event_value = &tsl2x7x_read_event_value,
> @@ -1636,7 +1542,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  	},
>  	[PRX2] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
> -		.event_attrs = &tsl2X7X_event_attr_group_tbl[PRX],
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
>  		.read_event_value = &tsl2x7x_read_event_value,
> @@ -1646,7 +1551,6 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  	},
>  	[ALSPRX2] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
> -		.event_attrs = &tsl2X7X_event_attr_group_tbl[ALSPRX],
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
>  		.read_event_value = &tsl2x7x_read_event_value,
> @@ -1667,6 +1571,10 @@ static const struct iio_event_spec tsl2x7x_events[] = {
>  		.dir = IIO_EV_DIR_FALLING,
>  		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
>  			BIT(IIO_EV_INFO_ENABLE),
> +	}, {
> +		.type = IIO_EV_TYPE_THRESH,
> +		.dir = IIO_EV_DIR_NONE,

Hmm.  Should this not be _EITHER rather than _NONE?

> +		.mask_separate = BIT(IIO_EV_INFO_PERIOD),
>  	},
>  };
>  

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec
  2017-10-01 10:14   ` Jonathan Cameron
@ 2017-10-01 10:58     ` Brian Masney
  0 siblings, 0 replies; 8+ messages in thread
From: Brian Masney @ 2017-10-01 10:58 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-iio, gregkh, devel, knaack.h, lars, pmeerw, linux-kernel,
	Jon.Brenner

On Sun, Oct 01, 2017 at 11:14:46AM +0100, Jonathan Cameron wrote:
> On Fri, 29 Sep 2017 21:09:21 -0400
> Brian Masney <masneyb@onstation.org> wrote:
> 
> > The sysfs attributes in_intensity0_thresh_period and
> > in_proximity0_thresh_period are currently directly created by the driver.
> > This patch migrates the creation of these sysfs attributes from the driver
> > to using the IIO core via iio_event_spec.
> > 
> > Signed-off-by: Brian Masney <masneyb@onstation.org>
> 
> One question down the end about whether we should be using IIO_EV_DIR_EITHER
> rather than IIO_EV_DIR_NONE
> 
> NONE is only really for thing where a direction makes not sense rather
> than to remove the direction be specified for a particular element.
> 
> Otherwise looks good.  I'd just have changed this, but wasn't sure if
> there was deeper logic behind your choice that I was missing!

There wasn't any deeper logic to this. :) I'll test it with
IIO_EV_DIR_EITHER and send v2 with my next batch of cleanups unless you
change it before then.

Thanks,

Brian

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-10-01 10:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-30  1:09 [PATCH 0/3] staging: iio: tsl2x7x: staging cleanups Brian Masney
2017-09-30  1:09 ` [PATCH 1/3] staging: iio: tsl2x7x: rename tsl2x7x_settings variable to settings Brian Masney
2017-10-01 10:08   ` Jonathan Cameron
2017-09-30  1:09 ` [PATCH 2/3] staging: iio: tsl2x7x: migrate in_illuminance0_integration_time sysfs attribute to iio_chan_spec Brian Masney
2017-10-01 10:10   ` Jonathan Cameron
2017-09-30  1:09 ` [PATCH 3/3] staging: iio: tsl2x7x: migrate *_thresh_period sysfs attributes to iio_event_spec Brian Masney
2017-10-01 10:14   ` Jonathan Cameron
2017-10-01 10:58     ` Brian Masney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.