* [PATCH v2 0/4] spi: xcomm: support GPO pin
@ 2024-07-05 15:12 Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 1/4] spi: xcomm: add gpiochip support Nuno Sa via B4 Relay
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-07-05 15:12 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, Michael Hennerich, Michael Hennerich
Here it goes v2 without get() support.
v1
* https://lore.kernel.org/linux-spi/20240704-dev-spi-xcomm-gpiochip-v1-0-653db6fbef36@analog.com/
v2
* Remove get() from gpiochip ops.
---
Michael Hennerich (1):
spi: xcomm: add gpiochip support
Nuno Sa (3):
spi: xcomm: make use of devm_spi_alloc_host()
spi: xcomm: remove i2c_set_clientdata()
spi: xcomm: fix coding style
drivers/spi/spi-xcomm.c | 75 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 57 insertions(+), 18 deletions(-)
---
base-commit: 56b6e631686eacbaf1970043027aadafea2b8438
change-id: 20240704-dev-spi-xcomm-gpiochip-8114c9894f07
--
Thanks!
- Nuno Sá
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] spi: xcomm: add gpiochip support
2024-07-05 15:12 [PATCH v2 0/4] spi: xcomm: support GPO pin Nuno Sa via B4 Relay
@ 2024-07-05 15:12 ` Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 2/4] spi: xcomm: make use of devm_spi_alloc_host() Nuno Sa via B4 Relay
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-07-05 15:12 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, Michael Hennerich, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
The hardware can expose one pin as a GPO. Hence, register a simple
gpiochip to support it.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Co-developed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
drivers/spi/spi-xcomm.c | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-xcomm.c b/drivers/spi/spi-xcomm.c
index 63354dd3110fc..063ce75af6504 100644
--- a/drivers/spi/spi-xcomm.c
+++ b/drivers/spi/spi-xcomm.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/i2c.h>
+#include <linux/gpio/driver.h>
#include <linux/spi/spi.h>
#include <asm/unaligned.h>
@@ -26,12 +27,15 @@
#define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03
#define SPI_XCOMM_CMD_WRITE 0x04
+#define SPI_XCOMM_CMD_GPIO_SET 0x05
#define SPI_XCOMM_CLOCK 48000000
struct spi_xcomm {
struct i2c_client *i2c;
+ struct gpio_chip gc;
+
uint16_t settings;
uint16_t chipselect;
@@ -40,6 +44,42 @@ struct spi_xcomm {
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)
{
uint16_t settings;
@@ -227,7 +267,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c)
if (ret < 0)
spi_controller_put(host);
- return ret;
+ return spi_xcomm_gpio_add(spi_xcomm);
}
static const struct i2c_device_id spi_xcomm_ids[] = {
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] spi: xcomm: make use of devm_spi_alloc_host()
2024-07-05 15:12 [PATCH v2 0/4] spi: xcomm: support GPO pin Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 1/4] spi: xcomm: add gpiochip support Nuno Sa via B4 Relay
@ 2024-07-05 15:12 ` Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 3/4] spi: xcomm: remove i2c_set_clientdata() Nuno Sa via B4 Relay
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-07-05 15:12 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, Michael Hennerich
From: Nuno Sa <nuno.sa@analog.com>
Use devm_spi_alloc_host() so that there's no need to call
spi_controller_put() in the error path.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
drivers/spi/spi-xcomm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-xcomm.c b/drivers/spi/spi-xcomm.c
index 063ce75af6504..5bbc250bc0534 100644
--- a/drivers/spi/spi-xcomm.c
+++ b/drivers/spi/spi-xcomm.c
@@ -248,7 +248,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c)
struct spi_controller *host;
int ret;
- host = spi_alloc_host(&i2c->dev, sizeof(*spi_xcomm));
+ host = devm_spi_alloc_host(&i2c->dev, sizeof(*spi_xcomm));
if (!host)
return -ENOMEM;
@@ -265,7 +265,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c)
ret = devm_spi_register_controller(&i2c->dev, host);
if (ret < 0)
- spi_controller_put(host);
+ return ret;
return spi_xcomm_gpio_add(spi_xcomm);
}
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] spi: xcomm: remove i2c_set_clientdata()
2024-07-05 15:12 [PATCH v2 0/4] spi: xcomm: support GPO pin Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 1/4] spi: xcomm: add gpiochip support Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 2/4] spi: xcomm: make use of devm_spi_alloc_host() Nuno Sa via B4 Relay
@ 2024-07-05 15:12 ` Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 4/4] spi: xcomm: fix coding style Nuno Sa via B4 Relay
2024-07-05 19:48 ` [PATCH v2 0/4] spi: xcomm: support GPO pin Mark Brown
4 siblings, 0 replies; 6+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-07-05 15:12 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, Michael Hennerich
From: Nuno Sa <nuno.sa@analog.com>
i2c_get_clientdata() is not being called anywhere so that we do not need
to set clientdata.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
drivers/spi/spi-xcomm.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/spi/spi-xcomm.c b/drivers/spi/spi-xcomm.c
index 5bbc250bc0534..1cd7d2b9e11c9 100644
--- a/drivers/spi/spi-xcomm.c
+++ b/drivers/spi/spi-xcomm.c
@@ -261,7 +261,6 @@ static int spi_xcomm_probe(struct i2c_client *i2c)
host->flags = SPI_CONTROLLER_HALF_DUPLEX;
host->transfer_one_message = spi_xcomm_transfer_one;
host->dev.of_node = i2c->dev.of_node;
- i2c_set_clientdata(i2c, host);
ret = devm_spi_register_controller(&i2c->dev, host);
if (ret < 0)
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] spi: xcomm: fix coding style
2024-07-05 15:12 [PATCH v2 0/4] spi: xcomm: support GPO pin Nuno Sa via B4 Relay
` (2 preceding siblings ...)
2024-07-05 15:12 ` [PATCH v2 3/4] spi: xcomm: remove i2c_set_clientdata() Nuno Sa via B4 Relay
@ 2024-07-05 15:12 ` Nuno Sa via B4 Relay
2024-07-05 19:48 ` [PATCH v2 0/4] spi: xcomm: support GPO pin Mark Brown
4 siblings, 0 replies; 6+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-07-05 15:12 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, Michael Hennerich
From: Nuno Sa <nuno.sa@analog.com>
Just cosmetics. No functional change intended.
While at it, removed a couple of redundant else if() statements.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
drivers/spi/spi-xcomm.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/spi/spi-xcomm.c b/drivers/spi/spi-xcomm.c
index 1cd7d2b9e11c9..846f00e23b717 100644
--- a/drivers/spi/spi-xcomm.c
+++ b/drivers/spi/spi-xcomm.c
@@ -36,12 +36,12 @@ struct spi_xcomm {
struct gpio_chip gc;
- uint16_t settings;
- uint16_t chipselect;
+ u16 settings;
+ u16 chipselect;
unsigned int current_speed;
- uint8_t buf[63];
+ u8 buf[63];
};
static void spi_xcomm_gpio_set_value(struct gpio_chip *chip,
@@ -82,8 +82,8 @@ static int spi_xcomm_gpio_add(struct spi_xcomm *spi_xcomm)
static int spi_xcomm_sync_config(struct spi_xcomm *spi_xcomm, unsigned int len)
{
- uint16_t settings;
- uint8_t *buf = spi_xcomm->buf;
+ u16 settings;
+ u8 *buf = spi_xcomm->buf;
settings = spi_xcomm->settings;
settings |= len << SPI_XCOMM_SETTINGS_LEN_OFFSET;
@@ -96,10 +96,10 @@ static int spi_xcomm_sync_config(struct spi_xcomm *spi_xcomm, unsigned int len)
}
static void spi_xcomm_chipselect(struct spi_xcomm *spi_xcomm,
- struct spi_device *spi, int is_active)
+ struct spi_device *spi, int is_active)
{
unsigned long cs = spi_get_chipselect(spi, 0);
- uint16_t chipselect = spi_xcomm->chipselect;
+ u16 chipselect = spi_xcomm->chipselect;
if (is_active)
chipselect |= BIT(cs);
@@ -110,7 +110,8 @@ static void spi_xcomm_chipselect(struct spi_xcomm *spi_xcomm,
}
static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm,
- struct spi_device *spi, struct spi_transfer *t, unsigned int *settings)
+ struct spi_device *spi, struct spi_transfer *t,
+ unsigned int *settings)
{
if (t->len > 62)
return -EINVAL;
@@ -148,7 +149,7 @@ static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm,
}
static int spi_xcomm_txrx_bufs(struct spi_xcomm *spi_xcomm,
- struct spi_device *spi, struct spi_transfer *t)
+ struct spi_device *spi, struct spi_transfer *t)
{
int ret;
@@ -159,13 +160,13 @@ static int spi_xcomm_txrx_bufs(struct spi_xcomm *spi_xcomm,
ret = i2c_master_send(spi_xcomm->i2c, spi_xcomm->buf, t->len + 1);
if (ret < 0)
return ret;
- else if (ret != t->len + 1)
+ if (ret != t->len + 1)
return -EIO;
} else if (t->rx_buf) {
ret = i2c_master_recv(spi_xcomm->i2c, t->rx_buf, t->len);
if (ret < 0)
return ret;
- else if (ret != t->len)
+ if (ret != t->len)
return -EIO;
}
@@ -173,12 +174,12 @@ static int spi_xcomm_txrx_bufs(struct spi_xcomm *spi_xcomm,
}
static int spi_xcomm_transfer_one(struct spi_controller *host,
- struct spi_message *msg)
+ struct spi_message *msg)
{
struct spi_xcomm *spi_xcomm = spi_controller_get_devdata(host);
unsigned int settings = spi_xcomm->settings;
struct spi_device *spi = msg->spi;
- unsigned cs_change = 0;
+ unsigned int cs_change = 0;
struct spi_transfer *t;
bool is_first = true;
int status = 0;
@@ -187,7 +188,6 @@ static int spi_xcomm_transfer_one(struct spi_controller *host,
spi_xcomm_chipselect(spi_xcomm, spi, true);
list_for_each_entry(t, &msg->transfers, transfer_list) {
-
if (!t->tx_buf && !t->rx_buf && t->len) {
status = -EINVAL;
break;
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/4] spi: xcomm: support GPO pin
2024-07-05 15:12 [PATCH v2 0/4] spi: xcomm: support GPO pin Nuno Sa via B4 Relay
` (3 preceding siblings ...)
2024-07-05 15:12 ` [PATCH v2 4/4] spi: xcomm: fix coding style Nuno Sa via B4 Relay
@ 2024-07-05 19:48 ` Mark Brown
4 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2024-07-05 19:48 UTC (permalink / raw)
To: linux-spi, Nuno Sa; +Cc: Michael Hennerich, Michael Hennerich
On Fri, 05 Jul 2024 17:12:38 +0200, Nuno Sa wrote:
> Here it goes v2 without get() support.
>
> v1
> * https://lore.kernel.org/linux-spi/20240704-dev-spi-xcomm-gpiochip-v1-0-653db6fbef36@analog.com/
>
> v2
> * Remove get() from gpiochip ops.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/4] spi: xcomm: add gpiochip support
commit: 5211070c3309bb3679f4522c77b900f551db5739
[2/4] spi: xcomm: make use of devm_spi_alloc_host()
commit: e8ba259764c745e7de20ec517ae920ecd491b687
[3/4] spi: xcomm: remove i2c_set_clientdata()
commit: 5e7d4755c58a347b4fe7663cef9b169b0965d09d
[4/4] spi: xcomm: fix coding style
commit: e2e89f96308add00fed632ecb416d84c9313f6aa
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-07-05 19:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-05 15:12 [PATCH v2 0/4] spi: xcomm: support GPO pin Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 1/4] spi: xcomm: add gpiochip support Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 2/4] spi: xcomm: make use of devm_spi_alloc_host() Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 3/4] spi: xcomm: remove i2c_set_clientdata() Nuno Sa via B4 Relay
2024-07-05 15:12 ` [PATCH v2 4/4] spi: xcomm: fix coding style Nuno Sa via B4 Relay
2024-07-05 19:48 ` [PATCH v2 0/4] spi: xcomm: support GPO pin Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).