2016-10-19 16:12:31

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 00/10] Revamp Semtech SX150x driver

Hello everyone,

This is the second version of the patchset originally submitted here:

http://www.spinics.net/lists/devicetree/msg146176.html

The only change since v1 is that, per Rob Herring's recommendation, all
of the changes to bindings documentation were coalesced into a single patch.

Thank you,
Andrey Smirnov

Andrey Smirnov (10):
gpio-sx150x: Remove 'gpio_base' from pdata
gpio-sx150x: Remove 'irq_summary' parameter
gpio-sx150x: Remove 'irq_base' parameter
gpio-sx150x: Replace 'io_polarity' with DT binding
gpio-sx150x: Replace "io_pull*_ena" with DT bindings
gpio-sx150x: Replace 'reset_during_probe" with DT binding
gpio-sx150x: Replace 'oscio_is_gpio' with DT binding
gpio-sx150x: Remove struct sx150x_platform_data
gpio-sx150x: Pass device type in DT match table
bindings: gpio-sx150x: Document new bindings

.../devicetree/bindings/gpio/gpio-sx150x.txt | 29 ++++
drivers/gpio/gpio-sx150x.c | 184 +++++++++------------
2 files changed, 105 insertions(+), 108 deletions(-)

--
2.5.5


2016-10-19 14:16:20

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 02/10] gpio-sx150x: Remove 'irq_summary' parameter

Information conveyed by 'irq_summary' paramter can be obtained from
struct i2c_client's irq field. Remove any uses of the former and replace
it with the latter.

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 19 +++----------------
1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index f9d6bec..e80c115 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -105,12 +105,6 @@ struct sx150x_device_data {
* the polarity of that IO line, while clearing it results
* in normal polarity. For chips with fewer than 16 IO pins,
* high-end bits are ignored.
- * @irq_summary: The 'summary IRQ' line to which the GPIO expander's INT line
- * is connected, via which it reports interrupt events
- * across all GPIO lines. This must be a real,
- * pre-existing IRQ line.
- * Setting this value < 0 disables the irq_chip functionality
- * of the driver.
* @irq_base: The first 'virtual IRQ' line at which our block of GPIO-based
* IRQ lines will appear. Similarly to gpio_base, the expander
* will create a block of irqs beginning at this number.
@@ -124,7 +118,6 @@ struct sx150x_platform_data {
u16 io_pullup_ena;
u16 io_pulldn_ena;
u16 io_polarity;
- int irq_summary;
unsigned irq_base;
bool reset_during_probe;
};
@@ -133,7 +126,6 @@ struct sx150x_chip {
struct gpio_chip gpio_chip;
struct i2c_client *client;
const struct sx150x_device_data *dev_cfg;
- int irq_summary;
int irq_base;
int irq_update;
u32 irq_sense;
@@ -598,7 +590,6 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
chip->irq_chip.irq_set_type = sx150x_irq_set_type;
chip->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
chip->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
- chip->irq_summary = -1;
chip->irq_base = -1;
chip->irq_masked = ~0;
chip->irq_sense = 0;
@@ -699,12 +690,10 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
}

static int sx150x_install_irq_chip(struct sx150x_chip *chip,
- int irq_summary,
- int irq_base)
+ int irq_base)
{
int err;

- chip->irq_summary = irq_summary;
chip->irq_base = irq_base;

/* Add gpio chip to irq subsystem */
@@ -718,11 +707,10 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
}

err = devm_request_threaded_irq(&chip->client->dev,
- irq_summary, NULL, sx150x_irq_thread_fn,
+ chip->client->irq, NULL, sx150x_irq_thread_fn,
IRQF_ONESHOT | IRQF_SHARED | IRQF_TRIGGER_FALLING,
chip->irq_chip.name, chip);
if (err < 0) {
- chip->irq_summary = -1;
chip->irq_base = -1;
}

@@ -759,9 +747,8 @@ static int sx150x_probe(struct i2c_client *client,
if (rc)
return rc;

- if (pdata->irq_summary >= 0) {
+ if (client->irq) {
rc = sx150x_install_irq_chip(chip,
- pdata->irq_summary,
pdata->irq_base);
if (rc < 0)
return rc;
--
2.5.5

2016-10-19 14:16:26

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 04/10] gpio-sx150x: Replace 'io_polarity' with DT binding

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index e01afd8..9b62133 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -100,11 +100,6 @@ struct sx150x_device_data {
* bit at position n will enable the pull-down for the IO at
* the corresponding offset. For chips with fewer than
* 16 IO pins, high-end bits are ignored.
- * @io_polarity: A bit-mask which enables polarity inversion for each IO line
- * in the expander. Setting the bit at position n inverts
- * the polarity of that IO line, while clearing it results
- * in normal polarity. For chips with fewer than 16 IO pins,
- * high-end bits are ignored.
* @reset_during_probe: If set to true, the driver will trigger a full
* reset of the chip at the beginning of the probe
* in order to place it in a known state.
@@ -113,7 +108,6 @@ struct sx150x_platform_data {
bool oscio_is_gpo;
u16 io_pullup_ena;
u16 io_pulldn_ena;
- u16 io_polarity;
bool reset_during_probe;
};

@@ -654,9 +648,15 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
return err;

if (chip->dev_cfg->model == SX150X_789) {
+ u32 io_polarity = 0;
+
+ of_property_read_u32(chip->client->dev.of_node,
+ "semtech,io-polarity",
+ &io_polarity);
+
err = sx150x_init_io(chip,
- chip->dev_cfg->pri.x789.reg_polarity,
- pdata->io_polarity);
+ chip->dev_cfg->pri.x789.reg_polarity,
+ (u16)io_polarity);
if (err < 0)
return err;
} else if (chip->dev_cfg->model == SX150X_456) {
--
2.5.5

2016-10-19 14:18:08

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 10/10] bindings: gpio-sx150x: Document new bindings

This patch documents the conversion of various platform data options
that used to be availible to SX150x driver to device tree/OF form.

Signed-off-by: Andrey Smirnov <[email protected]>
---
.../devicetree/bindings/gpio/gpio-sx150x.txt | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/Documentation/devicetree/bindings/gpio/gpio-sx150x.txt b/Documentation/devicetree/bindings/gpio/gpio-sx150x.txt
index c809acb..e96b554 100644
--- a/Documentation/devicetree/bindings/gpio/gpio-sx150x.txt
+++ b/Documentation/devicetree/bindings/gpio/gpio-sx150x.txt
@@ -26,6 +26,35 @@ The GPIO expander can optionally be used as an interrupt controller, in
which case it uses the default two cell specifier as described in
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt.

+Optional properties:
+
+- semtech,io-polarity: A bit-mask which enables polarity inversion for
+ each IO line in the expander. Setting the bit
+ at position n inverts the polarity of that IO
+ line, while clearing it results in normal
+ polarity. For chips with fewer than 16 IO pins,
+ high-end bits are ignored.
+
+- semtech,io-pullup:
+- semtech,io-pulldown: A bit-mask which enables-or disables the
+ pull-up (pull-down) resistor for each IO line
+ in the expander. Setting the bit at position n
+ will enable the pull-down for the IO at the
+ corresponding offset. For chips with fewer
+ than 16 IO pins, high-end bits are ignored.
+
+- semtech,reset-during-probe: Boolean, if true, the driver will
+ trigger a full reset of the chip at the
+ beginning of the probe in order to place
+ it in a known state.
+
+- semtech,oscio-is-gpo: Boolean, if set to true, the driver will
+ configure OSCIO as a GPO instead of as an
+ oscillator, increasing the size of the GP(I)O
+ pool created by this expander by one. The
+ output-only GPO pin will be added at the end
+ of the block.
+
Example:

i2c_gpio_expander@20{
--
2.5.5

2016-10-19 14:18:46

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 08/10] gpio-sx150x: Remove struct sx150x_platform_data

Remove last vestiges of struct sx150x_platform_data

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 25 ++++---------------------
1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index 044ff3d..bfb1ec3 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -84,16 +84,6 @@ struct sx150x_device_data {
} pri;
};

-/**
- * struct sx150x_platform_data - config data for SX150x driver
- * @oscio_is_gpo: If set to true, the driver will configure OSCIO as a GPO
- * instead of as an oscillator, increasing the size of the
- * GP(I)O pool created by this expander by one. The
- * output-only GPO pin will be added at the end of the block.
- */
-struct sx150x_platform_data {
-};
-
struct sx150x_chip {
struct gpio_chip gpio_chip;
struct i2c_client *client;
@@ -531,8 +521,7 @@ out:

static void sx150x_init_chip(struct sx150x_chip *chip,
struct i2c_client *client,
- kernel_ulong_t driver_data,
- struct sx150x_platform_data *pdata)
+ kernel_ulong_t driver_data)
{
mutex_init(&chip->lock);

@@ -592,8 +581,7 @@ static int sx150x_reset(struct sx150x_chip *chip)
return err;
}

-static int sx150x_init_hw(struct sx150x_chip *chip,
- struct sx150x_platform_data *pdata)
+static int sx150x_init_hw(struct sx150x_chip *chip)
{
u32 io_pulldown = 0;
u32 io_pullup = 0;
@@ -696,15 +684,10 @@ static int sx150x_probe(struct i2c_client *client,
{
static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WRITE_WORD_DATA;
- struct sx150x_platform_data *pdata;
struct sx150x_chip *chip;
int rc;
bool oscio_is_gpo;

- pdata = dev_get_platdata(&client->dev);
- if (!pdata)
- return -EINVAL;
-
if (!i2c_check_functionality(client->adapter, i2c_funcs))
return -ENOSYS;

@@ -716,12 +699,12 @@ static int sx150x_probe(struct i2c_client *client,
oscio_is_gpo = of_property_read_bool(client->dev.of_node,
"semtech,oscio-is-gpo");

- sx150x_init_chip(chip, client, id->driver_data, pdata);
+ sx150x_init_chip(chip, client, id->driver_data);

if (oscio_is_gpo)
chip->gpio_chip.ngpio++;

- rc = sx150x_init_hw(chip, pdata);
+ rc = sx150x_init_hw(chip);
if (rc < 0)
return rc;

--
2.5.5

2016-10-19 14:19:45

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 01/10] gpio-sx150x: Remove 'gpio_base' from pdata

Since struct sx150x_platrfom_data is not accesible to anyone but the
driver itself it seems a bit pointless to have a configurable GPIO
base. Hardcode it to -1 and remove that paramter.

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index a177ebd..f9d6bec 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -86,11 +86,6 @@ struct sx150x_device_data {

/**
* struct sx150x_platform_data - config data for SX150x driver
- * @gpio_base: The index number of the first GPIO assigned to this
- * GPIO expander. The expander will create a block of
- * consecutively numbered gpios beginning at the given base,
- * with the size of the block depending on the model of the
- * expander chip.
* @oscio_is_gpo: If set to true, the driver will configure OSCIO as a GPO
* instead of as an oscillator, increasing the size of the
* GP(I)O pool created by this expander by one. The
@@ -125,7 +120,6 @@ struct sx150x_device_data {
* in order to place it in a known state.
*/
struct sx150x_platform_data {
- unsigned gpio_base;
bool oscio_is_gpo;
u16 io_pullup_ena;
u16 io_pulldn_ena;
@@ -588,7 +582,7 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
chip->gpio_chip.get = sx150x_gpio_get;
chip->gpio_chip.set = sx150x_gpio_set;
chip->gpio_chip.set_single_ended = sx150x_gpio_set_single_ended;
- chip->gpio_chip.base = pdata->gpio_base;
+ chip->gpio_chip.base = -1;
chip->gpio_chip.can_sleep = true;
chip->gpio_chip.ngpio = chip->dev_cfg->ngpios;
#ifdef CONFIG_OF_GPIO
--
2.5.5

2016-10-19 14:21:43

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 07/10] gpio-sx150x: Replace 'oscio_is_gpio' with DT binding

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index a63f6ea..044ff3d 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -92,7 +92,6 @@ struct sx150x_device_data {
* output-only GPO pin will be added at the end of the block.
*/
struct sx150x_platform_data {
- bool oscio_is_gpo;
};

struct sx150x_chip {
@@ -553,8 +552,6 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
chip->gpio_chip.of_node = client->dev.of_node;
chip->gpio_chip.of_gpio_n_cells = 2;
#endif
- if (pdata->oscio_is_gpo)
- ++chip->gpio_chip.ngpio;

chip->irq_chip.name = client->name;
chip->irq_chip.irq_mask = sx150x_irq_mask;
@@ -670,10 +667,6 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
return err;
}

-
- if (pdata->oscio_is_gpo)
- sx150x_set_oscio(chip, 0);
-
return err;
}

@@ -706,6 +699,7 @@ static int sx150x_probe(struct i2c_client *client,
struct sx150x_platform_data *pdata;
struct sx150x_chip *chip;
int rc;
+ bool oscio_is_gpo;

pdata = dev_get_platdata(&client->dev);
if (!pdata)
@@ -719,11 +713,21 @@ static int sx150x_probe(struct i2c_client *client,
if (!chip)
return -ENOMEM;

+ oscio_is_gpo = of_property_read_bool(client->dev.of_node,
+ "semtech,oscio-is-gpo");
+
sx150x_init_chip(chip, client, id->driver_data, pdata);
+
+ if (oscio_is_gpo)
+ chip->gpio_chip.ngpio++;
+
rc = sx150x_init_hw(chip, pdata);
if (rc < 0)
return rc;

+ if (oscio_is_gpo)
+ sx150x_set_oscio(chip, 0);
+
rc = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip);
if (rc)
return rc;
--
2.5.5

2016-10-19 14:22:28

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 06/10] gpio-sx150x: Replace 'reset_during_probe" with DT binding

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index b751ff9..a63f6ea 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -90,13 +90,9 @@ struct sx150x_device_data {
* instead of as an oscillator, increasing the size of the
* GP(I)O pool created by this expander by one. The
* output-only GPO pin will be added at the end of the block.
- * @reset_during_probe: If set to true, the driver will trigger a full
- * reset of the chip at the beginning of the probe
- * in order to place it in a known state.
*/
struct sx150x_platform_data {
bool oscio_is_gpo;
- bool reset_during_probe;
};

struct sx150x_chip {
@@ -606,7 +602,8 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
u32 io_pullup = 0;
int err = 0;

- if (pdata->reset_during_probe) {
+ if (of_property_read_bool(chip->client->dev.of_node,
+ "semtech,reset-during-probe")) {
err = sx150x_reset(chip);
if (err < 0)
return err;
--
2.5.5

2016-10-19 14:23:26

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 09/10] gpio-sx150x: Pass device type in DT match table

Pass the same device type information in DT match table as the one being
passed via i2c_device_id

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 48 ++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index bfb1ec3..9263d25 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -97,8 +97,15 @@ struct sx150x_chip {
struct mutex lock;
};

+enum sx150x_type {
+ SX1508Q = 0,
+ SX1509Q,
+ SX1506Q,
+ SX1502Q,
+};
+
static const struct sx150x_device_data sx150x_devices[] = {
- [0] = { /* sx1508q */
+ [SX1508Q] = {
.model = SX150X_789,
.reg_pullup = 0x03,
.reg_pulldn = 0x04,
@@ -116,7 +123,7 @@ static const struct sx150x_device_data sx150x_devices[] = {
},
.ngpios = 8,
},
- [1] = { /* sx1509q */
+ [SX1509Q] = {
.model = SX150X_789,
.reg_pullup = 0x07,
.reg_pulldn = 0x09,
@@ -134,7 +141,7 @@ static const struct sx150x_device_data sx150x_devices[] = {
},
.ngpios = 16
},
- [2] = { /* sx1506q */
+ [SX1506Q] = {
.model = SX150X_456,
.reg_pullup = 0x05,
.reg_pulldn = 0x07,
@@ -154,7 +161,7 @@ static const struct sx150x_device_data sx150x_devices[] = {
},
.ngpios = 16
},
- [3] = { /* sx1502q */
+ [SX1502Q] = {
.model = SX150X_123,
.reg_pullup = 0x02,
.reg_pulldn = 0x03,
@@ -177,19 +184,19 @@ static const struct sx150x_device_data sx150x_devices[] = {
};

static const struct i2c_device_id sx150x_id[] = {
- {"sx1508q", 0},
- {"sx1509q", 1},
- {"sx1506q", 2},
- {"sx1502q", 3},
+ { "sx1508q", SX1508Q },
+ { "sx1509q", SX1509Q },
+ { "sx1506q", SX1506Q },
+ { "sx1502q", SX1502Q },
{}
};
MODULE_DEVICE_TABLE(i2c, sx150x_id);

static const struct of_device_id sx150x_of_match[] = {
- { .compatible = "semtech,sx1508q" },
- { .compatible = "semtech,sx1509q" },
- { .compatible = "semtech,sx1506q" },
- { .compatible = "semtech,sx1502q" },
+ { .compatible = "semtech,sx1508q", .data = (void *)SX1508Q },
+ { .compatible = "semtech,sx1509q", .data = (void *)SX1509Q },
+ { .compatible = "semtech,sx1506q", .data = (void *)SX1506Q },
+ { .compatible = "semtech,sx1502q", .data = (void *)SX1502Q },
{},
};
MODULE_DEVICE_TABLE(of, sx150x_of_match);
@@ -680,13 +687,14 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip)
}

static int sx150x_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+ const struct i2c_device_id *id)
{
static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WRITE_WORD_DATA;
struct sx150x_chip *chip;
int rc;
bool oscio_is_gpo;
+ kernel_ulong_t driver_data;

if (!i2c_check_functionality(client->adapter, i2c_funcs))
return -ENOSYS;
@@ -699,7 +707,19 @@ static int sx150x_probe(struct i2c_client *client,
oscio_is_gpo = of_property_read_bool(client->dev.of_node,
"semtech,oscio-is-gpo");

- sx150x_init_chip(chip, client, id->driver_data);
+ if (id) {
+ driver_data = id->driver_data;
+ } else {
+ const struct of_device_id *match;
+
+ match = of_match_device(sx150x_of_match, &client->dev);
+ if (!match)
+ return -ENODEV;
+
+ driver_data = (kernel_ulong_t)match->data;
+ }
+
+ sx150x_init_chip(chip, client, driver_data);

if (oscio_is_gpo)
chip->gpio_chip.ngpio++;
--
2.5.5

2016-10-19 16:07:33

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 03/10] gpio-sx150x: Remove 'irq_base' parameter

Remove 'irq_base' parameter and call 'gpiochip_irqchip_add' with '0' as
irq base to automatically assign it.

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index e80c115..e01afd8 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -105,10 +105,6 @@ struct sx150x_device_data {
* the polarity of that IO line, while clearing it results
* in normal polarity. For chips with fewer than 16 IO pins,
* high-end bits are ignored.
- * @irq_base: The first 'virtual IRQ' line at which our block of GPIO-based
- * IRQ lines will appear. Similarly to gpio_base, the expander
- * will create a block of irqs beginning at this number.
- * This value is ignored if irq_summary is < 0.
* @reset_during_probe: If set to true, the driver will trigger a full
* reset of the chip at the beginning of the probe
* in order to place it in a known state.
@@ -118,7 +114,6 @@ struct sx150x_platform_data {
u16 io_pullup_ena;
u16 io_pulldn_ena;
u16 io_polarity;
- unsigned irq_base;
bool reset_during_probe;
};

@@ -126,7 +121,6 @@ struct sx150x_chip {
struct gpio_chip gpio_chip;
struct i2c_client *client;
const struct sx150x_device_data *dev_cfg;
- int irq_base;
int irq_update;
u32 irq_sense;
u32 irq_masked;
@@ -590,7 +584,6 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
chip->irq_chip.irq_set_type = sx150x_irq_set_type;
chip->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
chip->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
- chip->irq_base = -1;
chip->irq_masked = ~0;
chip->irq_sense = 0;
chip->dev_masked = ~0;
@@ -689,16 +682,13 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
return err;
}

-static int sx150x_install_irq_chip(struct sx150x_chip *chip,
- int irq_base)
+static int sx150x_install_irq_chip(struct sx150x_chip *chip)
{
int err;

- chip->irq_base = irq_base;
-
/* Add gpio chip to irq subsystem */
err = gpiochip_irqchip_add(&chip->gpio_chip,
- &chip->irq_chip, chip->irq_base,
+ &chip->irq_chip, 0,
handle_edge_irq, IRQ_TYPE_EDGE_BOTH);
if (err) {
dev_err(&chip->client->dev,
@@ -710,10 +700,6 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
chip->client->irq, NULL, sx150x_irq_thread_fn,
IRQF_ONESHOT | IRQF_SHARED | IRQF_TRIGGER_FALLING,
chip->irq_chip.name, chip);
- if (err < 0) {
- chip->irq_base = -1;
- }
-
return err;
}

@@ -748,8 +734,7 @@ static int sx150x_probe(struct i2c_client *client,
return rc;

if (client->irq) {
- rc = sx150x_install_irq_chip(chip,
- pdata->irq_base);
+ rc = sx150x_install_irq_chip(chip);
if (rc < 0)
return rc;
}
--
2.5.5

2016-10-19 14:16:34

by Andrey Smirnov

[permalink] [raw]
Subject: [PATCH v2 05/10] gpio-sx150x: Replace "io_pull*_ena" with DT bindings

Signed-off-by: Andrey Smirnov <[email protected]>
---
drivers/gpio/gpio-sx150x.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index 9b62133..b751ff9 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -90,24 +90,12 @@ struct sx150x_device_data {
* instead of as an oscillator, increasing the size of the
* GP(I)O pool created by this expander by one. The
* output-only GPO pin will be added at the end of the block.
- * @io_pullup_ena: A bit-mask which enables or disables the pull-up resistor
- * for each IO line in the expander. Setting the bit at
- * position n will enable the pull-up for the IO at
- * the corresponding offset. For chips with fewer than
- * 16 IO pins, high-end bits are ignored.
- * @io_pulldn_ena: A bit-mask which enables-or disables the pull-down
- * resistor for each IO line in the expander. Setting the
- * bit at position n will enable the pull-down for the IO at
- * the corresponding offset. For chips with fewer than
- * 16 IO pins, high-end bits are ignored.
* @reset_during_probe: If set to true, the driver will trigger a full
* reset of the chip at the beginning of the probe
* in order to place it in a known state.
*/
struct sx150x_platform_data {
bool oscio_is_gpo;
- u16 io_pullup_ena;
- u16 io_pulldn_ena;
bool reset_during_probe;
};

@@ -614,6 +602,8 @@ static int sx150x_reset(struct sx150x_chip *chip)
static int sx150x_init_hw(struct sx150x_chip *chip,
struct sx150x_platform_data *pdata)
{
+ u32 io_pulldown = 0;
+ u32 io_pullup = 0;
int err = 0;

if (pdata->reset_during_probe) {
@@ -622,6 +612,14 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
return err;
}

+ of_property_read_u32(chip->client->dev.of_node,
+ "semtech,io-pullup",
+ &io_pullup);
+
+ of_property_read_u32(chip->client->dev.of_node,
+ "semtech,io-pulldown",
+ &io_pulldown);
+
if (chip->dev_cfg->model == SX150X_789)
err = sx150x_i2c_write(chip->client,
chip->dev_cfg->pri.x789.reg_misc,
@@ -638,12 +636,12 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
return err;

err = sx150x_init_io(chip, chip->dev_cfg->reg_pullup,
- pdata->io_pullup_ena);
+ io_pullup);
if (err < 0)
return err;

err = sx150x_init_io(chip, chip->dev_cfg->reg_pulldn,
- pdata->io_pulldn_ena);
+ io_pulldown);
if (err < 0)
return err;

--
2.5.5

2016-10-20 19:09:00

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v2 00/10] Revamp Semtech SX150x driver

On Wed, Oct 19, 2016 at 4:03 PM, Andrey Smirnov
<[email protected]> wrote:

> Hello everyone,
>
> This is the second version of the patchset originally submitted here:
>
> http://www.spinics.net/lists/devicetree/msg146176.html

I'm sorry about your efforts, and sorry for not having had time to
comment earlier, but this driver will be removed and replaced by
a pin control driver by Neil Armstrong:
http://marc.info/?l=linux-gpio&m=147499137422454&w=2

As you can see it arrived some weeks before.

Can you please review Neils patch and make sure it satisfies
your usecases?

The reason we have to make a pin control driver are things you
can see by the quirky things for line driving or biasing etc
that you have to add if it stays in GPIO: pin control is made
to handle this kind of stuff in a generic way.

Yours,
Linus Walleij

2016-10-20 19:34:22

by Andrey Smirnov

[permalink] [raw]
Subject: Re: [PATCH v2 00/10] Revamp Semtech SX150x driver

On Thu, Oct 20, 2016 at 12:08 PM, Linus Walleij
<[email protected]> wrote:
> On Wed, Oct 19, 2016 at 4:03 PM, Andrey Smirnov
> <[email protected]> wrote:
>
>> Hello everyone,
>>
>> This is the second version of the patchset originally submitted here:
>>
>> http://www.spinics.net/lists/devicetree/msg146176.html
>
> I'm sorry about your efforts, and sorry for not having had time to
> comment earlier, but this driver will be removed and replaced by
> a pin control driver by Neil Armstrong:
> http://marc.info/?l=linux-gpio&m=147499137422454&w=2
>
> As you can see it arrived some weeks before.
>
> Can you please review Neils patch and make sure it satisfies
> your usecases?

Sure, I'll grab those patches and provide comments, Tested-by's, etc.

Thanks,
Andrey Smirnov

2016-10-21 09:18:06

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH v2 00/10] Revamp Semtech SX150x driver

On 10/20/2016 09:34 PM, Andrey Smirnov wrote:
> On Thu, Oct 20, 2016 at 12:08 PM, Linus Walleij
> <[email protected]> wrote:
>> On Wed, Oct 19, 2016 at 4:03 PM, Andrey Smirnov
>> <[email protected]> wrote:
>>
>>> Hello everyone,
>>>
>>> This is the second version of the patchset originally submitted here:
>>>
>>> http://www.spinics.net/lists/devicetree/msg146176.html
>>
>> I'm sorry about your efforts, and sorry for not having had time to
>> comment earlier, but this driver will be removed and replaced by
>> a pin control driver by Neil Armstrong:
>> http://marc.info/?l=linux-gpio&m=147499137422454&w=2
>>
>> As you can see it arrived some weeks before.
>>
>> Can you please review Neils patch and make sure it satisfies
>> your usecases?
>
> Sure, I'll grab those patches and provide comments, Tested-by's, etc.
>
> Thanks,
> Andrey Smirnov
>

Hi Andrey,

Please find the v3 patch at https://marc.info/?l=linux-gpio&m=147704101505236&w=2

Maybe it could better to actually add the 1503 support even if it's using the sx1506q_device_data.

Could you try out this driver and report a Tested-by if successful ?

Neil