Skip to content

Commit

Permalink
gpio: max3191x: Allow in-kernel retrieval of chip status
Browse files Browse the repository at this point in the history
KUNBUS' out-of-tree picontrol.ko module polls all available max3191x
chips and stores their input values as well as status bits in the
process image.  While the input values are retrievable using the GPIO
consumer API, the status bits are inaccessible outside the max3191x
driver.  Add an in-kernel API to facilitate their retrieval.

Cc: Mathias Duckeck <m.duckeck@kunbus.de>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
  • Loading branch information
l1k committed Aug 31, 2020
1 parent 1be300f commit ecf6085
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions drivers/gpio/gpio-max3191x.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,39 @@ int max3191x_set_mode(struct device *dev, enum max3191x_mode mode)
}
EXPORT_SYMBOL(max3191x_set_mode);

/**
* max3191x_get_status - retrieve chip status
* @dev: device
*
* Return 0 if chip is healthy, or a bitmask indicating fault conditions.
* Currently only the first chip in a daisy chain is considered, which is
* sufficient for the RevPi Compact.
*/
u8 max3191x_get_status(struct device *dev)
{
struct max3191x_chip *max3191x;
struct spi_device *spi;
u8 ret;

device_lock(dev);
if (!device_is_bound(dev)) {
ret = 0;
goto out_unlock;
}

spi = to_spi_device(dev);
max3191x = spi_get_drvdata(spi);

ret = test_bit(0, max3191x->crc_error) << 7 |
test_bit(0, max3191x->overtemp) << 4 |
test_bit(0, max3191x->fault);

out_unlock:
device_unlock(dev);
return ret;
}
EXPORT_SYMBOL(max3191x_get_status);

static struct gpio_descs *devm_gpiod_get_array_optional_count(
struct device *dev, const char *con_id,
enum gpiod_flags flags, unsigned int expected)
Expand Down
1 change: 1 addition & 0 deletions include/linux/spi/max3191x.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ enum max3191x_mode {
};

int max3191x_set_mode(struct device *dev, enum max3191x_mode mode);
u8 max3191x_get_status(struct device *dev);

#endif

0 comments on commit ecf6085

Please # to comment.