Commit 5211070c authored by Michael Hennerich's avatar Michael Hennerich Committed by Mark Brown

spi: xcomm: add gpiochip support

The hardware can expose one pin as a GPO. Hence, register a simple
gpiochip to support it.
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Co-developed-by: default avatarNuno Sa <nuno.sa@analog.com>
Signed-off-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240705-dev-spi-xcomm-gpiochip-v2-1-b10842fc9636@analog.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 6c387fb2
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/gpio/driver.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
...@@ -26,12 +27,15 @@ ...@@ -26,12 +27,15 @@
#define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03 #define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03
#define SPI_XCOMM_CMD_WRITE 0x04 #define SPI_XCOMM_CMD_WRITE 0x04
#define SPI_XCOMM_CMD_GPIO_SET 0x05
#define SPI_XCOMM_CLOCK 48000000 #define SPI_XCOMM_CLOCK 48000000
struct spi_xcomm { struct spi_xcomm {
struct i2c_client *i2c; struct i2c_client *i2c;
struct gpio_chip gc;
uint16_t settings; uint16_t settings;
uint16_t chipselect; uint16_t chipselect;
...@@ -40,6 +44,42 @@ struct spi_xcomm { ...@@ -40,6 +44,42 @@ struct spi_xcomm {
uint8_t buf[63]; uint8_t buf[63];
}; };
static void spi_xcomm_gpio_set_value(struct gpio_chip *chip,
unsigned int offset, int val)
{
struct spi_xcomm *spi_xcomm = gpiochip_get_data(chip);
unsigned char buf[2];
buf[0] = SPI_XCOMM_CMD_GPIO_SET;
buf[1] = !!val;
i2c_master_send(spi_xcomm->i2c, buf, 2);
}
static int spi_xcomm_gpio_get_direction(struct gpio_chip *chip,
unsigned int offset)
{
return GPIO_LINE_DIRECTION_OUT;
}
static int spi_xcomm_gpio_add(struct spi_xcomm *spi_xcomm)
{
struct device *dev = &spi_xcomm->i2c->dev;
if (!IS_ENABLED(CONFIG_GPIOLIB))
return 0;
spi_xcomm->gc.get_direction = spi_xcomm_gpio_get_direction;
spi_xcomm->gc.set = spi_xcomm_gpio_set_value;
spi_xcomm->gc.can_sleep = 1;
spi_xcomm->gc.base = -1;
spi_xcomm->gc.ngpio = 1;
spi_xcomm->gc.label = spi_xcomm->i2c->name;
spi_xcomm->gc.owner = THIS_MODULE;
return devm_gpiochip_add_data(dev, &spi_xcomm->gc, spi_xcomm);
}
static int spi_xcomm_sync_config(struct spi_xcomm *spi_xcomm, unsigned int len) static int spi_xcomm_sync_config(struct spi_xcomm *spi_xcomm, unsigned int len)
{ {
uint16_t settings; uint16_t settings;
...@@ -227,7 +267,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c) ...@@ -227,7 +267,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c)
if (ret < 0) if (ret < 0)
spi_controller_put(host); spi_controller_put(host);
return ret; return spi_xcomm_gpio_add(spi_xcomm);
} }
static const struct i2c_device_id spi_xcomm_ids[] = { static const struct i2c_device_id spi_xcomm_ids[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment