summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/light/tsl2583.c
AgeCommit message (Collapse)Author
2016-11-13staging: iio: tsl2583: move out of stagingBrian Masney
Move tsl2580, tsl2581, tsl2583 driver out of staging into mainline. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: add copyright and MODULE_AUTHORBrian Masney
Add Brian Masney's copyright to the header and to the MODULE_AUTHOR for all of the staging cleanups that has been done to this driver. The original MODULE_AUTHOR() did not have a space between his name and email address. This patch also adds the missing space. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove unnecessary variable initializationBrian Masney
The ret variable in tsl2583_suspend() and tsl2583_resume() was initialized to 0. This is not necessary so this patch removes the initialization. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove unnecessary memset callBrian Masney
The entries in the lux table (als_device_lux) can be updated via sysfs through the function in_illuminance_lux_table_store(). The last row in the table must be terminated with values that are zero. The sysfs code already ensures that the last row is all zeros. The call to memset to clear out the table is not needed so this patch removes the unnecessary call. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove comment for tsl2583_probe()Brian Masney
The comment for tsl2583_probe() does not provide any useful value. This patch removes the comment. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: clarified comment about clearing interruptsBrian Masney
The comment that describes the code that clears the interrupt bit was vague and didn't provide much value. This patch adds more detail about why that bit needs to be cleared. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: add tsl2583 to list of supported devices in the headerBrian Masney
The header only listed the tsl2580 and tsl2581 devices as supported by this driver. This patch adds the tsl2583 since it is also supported by this driver. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: move from a global to a per device lux tableBrian Masney
The driver contains a global lux table that can be updated via sysfs. Change this to a per device lux table so that multiple devices can be hooked up to the same system with different lux tables. There are 10 entries, plus 1 for the termination segment, set aside for the entries in the lux table. When updating the lux table via sysfs, only 9 entries, plus the terminator, could be added. This changes the code to allow for the 10 entries, plus the terminator. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: don't assume an unsigned int is 32 bitsBrian Masney
in_illuminance_lux_table_store assumes that an unsigned int is 32 bits. Replace this with sizeof(value[1]). Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove unnecessary parenthesesBrian Masney
in_illuminance_lux_table_store() contains some unnecessary parentheses. This patch removes them since they provide no value. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: change tsl2583_als_calibrate() to return 0 on successBrian Masney
tsl2583_als_calibrate() returns the newly computed gain_trim if the calibration was successful. This function is only called by in_illuminance_calibrate_store() and the return value inside that sysfs attribute is only checked to see if an error was returned. This patch changes tsl2583_als_calibrate() to return 0 on success. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: moved code block inside else statementBrian Masney
The check for ch1lux > ch0lux inside tsl2583_get_lux is only valid if the ratio is not equal to zero. Move the code block inside the else statement. This does away with the need to initialize the variables to zero. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: updated code comment to match what the code doesBrian Masney
If channel 0 does not have any data, then the code sets the lux to zero. The corresponding comment says that the last value is returned. This updates the comment to correctly reflect what the code does. It also clarifies the comment about why 0 is returned. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: fix multiline comment syntaxBrian Masney
The definition of the tsl2583_device_lux struct has a series of single line comments. There are two other cases where the multiline comments did not have an initial blank line. Change these comments to use the proper multiline syntax. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: change newlines to improve readabilityBrian Masney
Add and remove newlines to improve code readability in preparation for moving the driver out of staging. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: fix comparison between signed and unsigned integersBrian Masney
Fixed warning found by make W=2: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: fix alignment of #define valuesBrian Masney
Most of the values in the #defines have their values aligned on a single column, but some do not. This changes the remaining defines to use consistent alignment with the majority to improve code readability. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: unify function and variable prefix to tsl2583_Brian Masney
Some functions and variables were prefixed with either taos, tsl258x, taos2583, or tsl2583. Change everything to use the tsl2583 prefix since that is the name of the .c file. The taos_settings member inside the taos_settings struct was renamed to als_settings. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: cleaned up loggingBrian Masney
There are several places in the code where the function name is hardcoded in the log message. Use the __func__ constant string to build the log message. This also clarifies some of the error messages to match the code and ensures that the correct priority is used since the message is already being changed. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove the FSF's mailing addressBrian Masney
Address warning from checkpatch: CHECK: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove redundant write to the control register in ↵Brian Masney
taos_probe() taos_probe() calls i2c_smbus_write_byte() to select the control register, however there are no subsequent calls to i2c_smbus_read_byte(). The write call is unnecessary and is removed by this patch. Verified that the driver still functions correctly using a TSL2581 hooked up to a Raspberry Pi 2. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: change current chip state from a tristate to a boolBrian Masney
The current chip state is represented as a tristate (working, suspended, and unknown). The unknown state was not used. This patch changes the chip state so that it is now represented as a single boolean value (suspended). Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove unnecessary chip status checks in suspend/resumeBrian Masney
The device probing and the suspend/resume code checks a flag internal to the driver that determines whether or not the chip is in a working state. These checks are not needed. This patch removes the unnecessary checks. It will do no harm to the hardware if the chip is reinitialized if it is already powered on. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: remove unnecessary chip status check in taos_get_luxBrian Masney
taos_get_lux checks to see if the chip is in a working state. This check is not necessary since it is only called from tsl2583_read_raw and in_illuminance_calibrate_store (via taos_als_calibrate). The chip state is already checked by these functions. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-13staging: iio: tsl2583: check if chip is in a working state in ↵Brian Masney
in_illuminance_calibrate_store in_illuminance_calibrate_store() did not check to see if the chip is in a working state. This patch adds the proper check. The return value from taos_als_calibrate() was also not checked in this function, so the proper check was also added while changes are being made here. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12staging: iio: tsl2583: fix issue with changes to calibscale and int_time not ↵Brian Masney
being set on the chip When updating the in_illuminance_calibscale and in_illuminance_integration_time sysfs attributes, these values were not actually written to the chip. The chip would continue to use the old parameters. Extracted out tsl2583_set_als_gain() and tsl2583_set_als_time() functions that are now called when these sysfs attributes are updated. The chip initialization also calls these these new functions. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-12staging: iio: tsl2583: split out functionality of taos_chip_on()Brian Masney
taos_chip_on() reads an eight member array called taos_config that contains the desired state of the chip's registers. Only four of the registers actually need to be written to. The four that do not need to be written to are for the {low,high} byte of the lower interrupt threshold and the {low,high} byte of the upper interrupt threshold. Interrupts are currently not supported by this driver so there is no need to write to these registers. This patch removes the taos_config array and separates out the i2c calls that write to the CONTROL, TIMING, INTERRUPT and ANALOG registers. This is part of a larger refactor that was split up to make the code review easier. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-08staging: iio: tsl2583: fix unused function warningArnd Bergmann
Removing a call to the taos_chip_off() makes it unused when CONFIG_PM is disabled: drivers/staging/iio/light/tsl2583.c:438:12: error: ‘taos_chip_off’ defined but not used [-Werror=unused-function] This removes all the #ifdef in this file, and marks the PM functions as __maybe_unused instead, which is more reliable and gives us better compile time coverage. Fixes: 0561155f6fc5 ("staging: iio: tsl2583: don't shutdown chip when updating the lux table") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-06staging: iio: tsl2583: remove redudant i2c call in taos_als_calibrate()Brian Masney
taos_als_calibrate() queries the control register to determine if the unit is powered on and has the ADC enabled. It then queries the same register a second time to determine if the ADC reading is valid. This patch removes the redundant i2c_smbus_read_byte_data() call. Verified that the driver still functions correctly using a TSL2581 hooked up to a Raspberry Pi 2. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-06staging: iio: tsl2583: don't shutdown chip when updating the lux tableBrian Masney
in_illuminance_lux_table_store() shuts down the chip, updates the contents of the lux table, and then turns the chip back on. The values in lux table are not used by the chip and are only used internally by the driver. It is not necessary to change the power state on the chip. This patch removes the calls to taos_chip_off() and taos_chip_on() in in_illuminance_lux_table_store(). Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-06staging: iio: tsl2583: remove redundant power off sequence in taos_chip_on()Brian Masney
taos_chip_on() explicitly turns the sensor power on and then writes the 8 registers that are stored in taos_config. The first register in taos_config is the CONTROL register and the configuration is set to turn the power off. The existing state sequence in taos_chip_on() is: - Turn device power on - Turn device power off (via taos_config) - Configure other 7 registers (via taos_config) - Turn device power on, enable ADC This patch changes the code so that the device is not powered off via taos_config. Verified that the driver still functions correctly using a TSL2581 hooked up to a Raspberry Pi 2. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-06staging: iio: tsl2583: fixed ordering of commentsBrian Masney
in taos_defaults() The comments in taos_defaults() appear after the line of code that they apply to. This patch moves the comments so that they appear before the code. Some of the comments were updated to be more informative. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-06staging: iio: tsl2583: removed unused code from device probingBrian Masney
taos_probe() queries the all of the sensor's registers and loads all of the values into a buffer stored on the stack. Only the chip ID register was actually used. Change the probe function to just query the chip ID register on the device. Verified that the driver still functions correctly using a TSL2581 hooked up to a Raspberry Pi 2. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-06staging: iio: tsl2583: i2c_smbus_write_byte() / i2c_smbus_read_byte() migrationBrian Masney
There were several places where the driver would first call i2c_smbus_write_byte() to select the register on the device, and then call i2c_smbus_read_byte() to get the contents of that register. The code would look roughly like: /* Select register */ i2c_smbus_write_byte(client, REGISTER); /* Read the the last register that was written to */ int data = i2c_smbus_read_byte(client); Rewrite this to use i2c_smbus_read_byte_data() to combine the two calls into one: int data = i2c_smbus_read_byte_data(chip->client, REGISTER); Verified that the driver still functions correctly using a TSL2581 hooked up to a Raspberry Pi 2. This fixes the following warnings that were found by the kbuild test robot that were introduced by commit 8ba355cce3c6 ("staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()"). drivers/staging/iio/light/tsl2583.c:365:5-12: WARNING: Unsigned expression compared with zero: reg_val < 0 drivers/staging/iio/light/tsl2583.c:388:5-12: WARNING: Unsigned expression compared with zero: reg_val < 0 This also removes the need for the taos_i2c_read() function since all callers were only calling the function with a length of 1. Signed-off-by: Brian Masney <masneyb@onstation.org> Cc: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: add locking to sysfs attributesBrian Masney
in_illuminance_input_target_show(), in_illuminance_input_target_store(), in_illuminance_calibrate_store(), and in_illuminance_lux_table_store() accesses data from the tsl2583_chip struct. Some of these fields can be modified by other parts of the driver concurrently. This patch adds the mutex locking to these sysfs attributes. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: add error code to sysfs store functionsBrian Masney
in_illuminance_input_target_store() and in_illuminance_calibrate_store() validated the data from userspace, however it would not return an error code to userspace if an invalid value was passed in. This patch changes these functions so that they return -EINVAL if invalid data is passed in. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: use IIO_*_ATTR* macros to create sysfs entriesBrian Masney
Use the IIO_CONST_ATTR, IIO_DEVICE_ATTR_RW, and IIO_DEVICE_ATTR_WO macros for creating the in_illuminance_calibscale_available, in_illuminance_integration_time_available, in_illuminance_input_target, in_illuminance_calibrate, and in_illuminance_lux_table sysfs entries. Previously these sysfs entries were prefixed with illuminance0_, however they are now prefixed with in_illuminance_ to make these sysfs entries consistent with how the IIO core is creating the other sysfs entries. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: convert illuminance0_calibscale sysfs attr to use ↵Brian Masney
iio_chan_spec The illuminance0_calibscale sysfs attribute is not currently created by the IIO core. This patch adds the appropriate mask to iio_chan_spec, along with the appropriate data handling in the read_raw() and write_raw() functions, so that the sysfs attribute is created by the IIO core. With this change, this sysfs entry will have its prefix changed from illuminance0_ to in_illuminance_. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: convert to use iio_chan_spec and {read,write}_rawBrian Masney
The tsl2583 driver directly creates sysfs attributes that should instead be created by the IIO core on behalf of the driver. This patch adds the iio_chan_spec array, the relevant info_mask elements and the read_raw() and write_raw() functions to take advantage of features provided by the IIO core. These sysfs attributes were migrated with this patch: illuminance0_input, illuminance0_calibbias, illuminance0_integration_time. This also exposes the raw values read from the two channels on the sensor. With this change, these four sysfs entries have their prefix changed from illuminance0_ to in_illuminance_. This is deemed to be acceptable since none of the IIO light drivers in mainline use the illuminance0_ prefix, however 8 of the IIO light drivers in mainline use the in_illuminance_ prefix. Also fix the units of integration_time to meet with the ABI. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: check return values from taos_chip_{on,off}Brian Masney
The return value from taos_chip_on() and taos_chip_off() was not checked in taos_luxtable_store() and taos_probe(). This patch adds proper error checking to these function calls. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: remove redundant power_state sysfs attributeBrian Masney
IIO devices have a /sys/bus/iio/devices/iio:deviceX/power/ directory that allows viewing and controling various power parameters. The tsl2583 driver also has an additional custom sysfs attribute named power_state that is not needed. This patch removes the redundant power_state sysfs attribute. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: return proper error code instead of -1Brian Masney
taos_als_calibrate() has a code path where -1 is returned. This patch changes the code so that a proper error code is returned. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()Brian Masney
taos_i2c_read() and taos_als_calibrate() does not check to see if the value returned by i2c_smbus_read_byte() was an error code. This patch adds the appropriate error handling. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-11-01staging: iio: tsl2583: add of_match table for device tree supportBrian Masney
Add device tree support for the tsl2583 IIO driver with no custom properties. Signed-off-by: Brian Masney <masneyb@onstation.org> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-27Staging: iio: light: constify attribute_group structuresBhumika Goyal
Check for attribute_group structures that are only stored in the attrs filed of iio_info structure. As the attrs field of iio_info structures is constant, so these attribute_group structures can also be declared constant. Done using coccinelle @r1 disable optional_qualifier @ identifier i; position p; @@ static struct attribute_group i@p = {...}; @ok1@ identifier r1.i; position p; struct iio_info x; @@ x.attrs=&i@p; @bad@ position p!={r1.p,ok1.p}; identifier r1.i; @@ i@p @depends on !bad disable optional_qualifier@ identifier r1.i; @@ static +const struct attribute_group i={...}; @depends on !bad disable optional_qualifier@ identifier r1.i; @@ +const struct attribute_group i; File size before: drivers/staging/iio/light/tsl2583.o text data bss dec hex filename 6529 1052 0 7581 1d9d drivers/staging/iio/light/tsl2583.o File size after: drivers/staging/iio/light/tsl2583.o text data bss dec hex filename 6593 988 0 7581 1d9d drivers/staging/iio/light/tsl2583.o Signed-off-by: Bhumika Goyal <bhumirks@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-20staging: iio: light: fix multiple assignments in a single lineEva Rachel Retuya
Rewrite the multiple assignments to clear checkpatch check: CHECK: multiple assignments should be avoided Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-20staging: iio: light: add space around '*"Eva Rachel Retuya
Address checkpatch check pointing out the lack of space around the operator '*'. Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-20staging: iio: light: fix block comments according to kernel coding styleEva Rachel Retuya
Add the trailing */ accordingly to suit the preferred way of placing block comments. Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-20staging: iio: light: omit space after a castEva Rachel Retuya
Remove the unneeded space as pointed out by checkpatch: CHECK: No space is necessary after a cast Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-02-20staging: iio: light: indent to match open parenthesisEva Rachel Retuya
Indent the parameters to match open parenthesis as suggested by checkpatch. Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>