* [PATCH 1/3] mfd: ti-lmu: switch to gpiod
@ 2018-09-11 21:01 Pavel Machek
2018-09-11 21:03 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Pavel Machek
2018-10-09 8:56 ` [PATCH 1/3] mfd: ti-lmu: switch to gpiod Lee Jones
0 siblings, 2 replies; 6+ messages in thread
From: Pavel Machek @ 2018-09-11 21:01 UTC (permalink / raw)
To: linux-arm-kernel
Use new descriptor based API instead of the legacy one.
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff --git a/drivers/mfd/ti-lmu.c b/drivers/mfd/ti-lmu.c
index 990437e..e14cb9f 100644
--- a/drivers/mfd/ti-lmu.c
+++ b/drivers/mfd/ti-lmu.c
@@ -12,7 +12,7 @@
#include <linux/delay.h>
#include <linux/err.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/kernel.h>
#include <linux/mfd/core.h>
@@ -21,7 +21,6 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
-#include <linux/of_gpio.h>
#include <linux/slab.h>
struct ti_lmu_data {
@@ -32,17 +31,8 @@ struct ti_lmu_data {
static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
{
- int ret;
-
- if (gpio_is_valid(lmu->en_gpio)) {
- ret = devm_gpio_request_one(lmu->dev, lmu->en_gpio,
- GPIOF_OUT_INIT_HIGH, "lmu_hwen");
- if (ret) {
- dev_err(lmu->dev, "Can not request enable GPIO: %d\n",
- ret);
- return ret;
- }
- }
+ if (lmu->en_gpio)
+ gpiod_set_value(lmu->en_gpio, 1);
/* Delay about 1ms after HW enable pin control */
usleep_range(1000, 1500);
@@ -59,8 +49,8 @@ static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id)
static void ti_lmu_disable_hw(struct ti_lmu *lmu)
{
- if (gpio_is_valid(lmu->en_gpio))
- gpio_set_value(lmu->en_gpio, 0);
+ if (lmu->en_gpio)
+ gpiod_set_value(lmu->en_gpio, 0);
}
static const struct mfd_cell lm3532_devices[] = {
@@ -204,7 +194,13 @@ static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id)
return PTR_ERR(lmu->regmap);
/* HW enable pin control and additional power up sequence if required */
- lmu->en_gpio = of_get_named_gpio(dev->of_node, "enable-gpios", 0);
+ lmu->en_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
+ if (IS_ERR(lmu->en_gpio)) {
+ ret = PTR_ERR(lmu->en_gpio);
+ dev_err(dev, "Can not request enable GPIO: %d\n", ret);
+ return ret;
+ }
+
ret = ti_lmu_enable_hw(lmu, id->driver_data);
if (ret)
return ret;
diff --git a/include/linux/mfd/ti-lmu.h b/include/linux/mfd/ti-lmu.h
index 09d5f30..1ef51ed 100644
--- a/include/linux/mfd/ti-lmu.h
+++ b/include/linux/mfd/ti-lmu.h
@@ -16,6 +16,7 @@
#include <linux/gpio.h>
#include <linux/notifier.h>
#include <linux/regmap.h>
+#include <linux/gpio/consumer.h>
/* Notifier event */
#define LMU_EVENT_MONITOR_DONE 0x01
@@ -81,7 +82,7 @@ enum lm363x_regulator_id {
struct ti_lmu {
struct device *dev;
struct regmap *regmap;
- int en_gpio;
+ struct gpio_desc *en_gpio;
struct blocking_notifier_head notifier;
};
#endif
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180911/22c2b6f5/attachment.sig>
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] mfd: ti-lmu: use managed resource for everything 2018-09-11 21:01 [PATCH 1/3] mfd: ti-lmu: switch to gpiod Pavel Machek @ 2018-09-11 21:03 ` Pavel Machek 2018-09-11 21:06 ` [PATCH 3/3] mfd: ti-lmu: use of_device_get_match_data() helper Pavel Machek 2018-10-09 8:56 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Lee Jones 2018-10-09 8:56 ` [PATCH 1/3] mfd: ti-lmu: switch to gpiod Lee Jones 1 sibling, 2 replies; 6+ messages in thread From: Pavel Machek @ 2018-09-11 21:03 UTC (permalink / raw) To: linux-arm-kernel This replaces all remaining unmanaged resources with device managed ones, so that the remove function is no longer needed. This makes the code slightly shorter and fixes two problems: 1. The hardware is disabled after the child devices have been removed. Previously there was a potential race condition. 2. The hardware is disabled when mfd_add_devices fails during probe. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Pavel Machek <pavel@ucw.cz> diff --git a/drivers/mfd/ti-lmu.c b/drivers/mfd/ti-lmu.c index e14cb9f..2ee09d0 100644 --- a/drivers/mfd/ti-lmu.c +++ b/drivers/mfd/ti-lmu.c @@ -47,8 +47,9 @@ static int ti_lmu_enable_hw(struct ti_lmu *lmu, enum ti_lmu_id id) return 0; } -static void ti_lmu_disable_hw(struct ti_lmu *lmu) +static void ti_lmu_disable_hw(void *data) { + struct ti_lmu *lmu = data; if (lmu->en_gpio) gpiod_set_value(lmu->en_gpio, 0); } @@ -205,6 +206,10 @@ static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id) if (ret) return ret; + ret = devm_add_action_or_reset(dev, ti_lmu_disable_hw, lmu); + if (ret) + return ret; + /* * Fault circuit(open/short) can be detected by ti-lmu-fault-monitor. * After fault detection is done, some devices should re-initialize @@ -214,17 +219,8 @@ static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id) i2c_set_clientdata(cl, lmu); - return mfd_add_devices(lmu->dev, 0, data->cells, - data->num_cells, NULL, 0, NULL); -} - -static int ti_lmu_remove(struct i2c_client *cl) -{ - struct ti_lmu *lmu = i2c_get_clientdata(cl); - - ti_lmu_disable_hw(lmu); - mfd_remove_devices(lmu->dev); - return 0; + return devm_mfd_add_devices(lmu->dev, 0, data->cells, + data->num_cells, NULL, 0, NULL); } static const struct i2c_device_id ti_lmu_ids[] = { @@ -240,7 +236,6 @@ MODULE_DEVICE_TABLE(i2c, ti_lmu_ids); static struct i2c_driver ti_lmu_driver = { .probe = ti_lmu_probe, - .remove = ti_lmu_remove, .driver = { .name = "ti-lmu", .of_match_table = ti_lmu_of_match, -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 181 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180911/46051cfa/attachment-0001.sig> ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] mfd: ti-lmu: use of_device_get_match_data() helper 2018-09-11 21:03 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Pavel Machek @ 2018-09-11 21:06 ` Pavel Machek 2018-10-09 8:57 ` Lee Jones 2018-10-09 8:56 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Lee Jones 1 sibling, 1 reply; 6+ messages in thread From: Pavel Machek @ 2018-09-11 21:06 UTC (permalink / raw) To: linux-arm-kernel Replace of_match_device() with of_device_get_match_data(), which slightly decreases lines of code and allows to move the DT table next to the I2C table. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Pavel Machek <pavel@ucw.cz> diff --git a/drivers/mfd/ti-lmu.c b/drivers/mfd/ti-lmu.c index de76298..ce16c89 100644 --- a/drivers/mfd/ti-lmu.c +++ b/drivers/mfd/ti-lmu.c @@ -142,34 +142,21 @@ TI_LMU_DATA(lm3633, LM3633_MAX_REG); TI_LMU_DATA(lm3695, LM3695_MAX_REG); TI_LMU_DATA(lm3697, LM3697_MAX_REG); -static const struct of_device_id ti_lmu_of_match[] = { - { .compatible = "ti,lm3532", .data = &lm3532_data }, - { .compatible = "ti,lm3631", .data = &lm3631_data }, - { .compatible = "ti,lm3632", .data = &lm3632_data }, - { .compatible = "ti,lm3633", .data = &lm3633_data }, - { .compatible = "ti,lm3695", .data = &lm3695_data }, - { .compatible = "ti,lm3697", .data = &lm3697_data }, - { } -}; -MODULE_DEVICE_TABLE(of, ti_lmu_of_match); - static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id) { struct device *dev = &cl->dev; - const struct of_device_id *match; const struct ti_lmu_data *data; struct regmap_config regmap_cfg; struct ti_lmu *lmu; int ret; - match = of_match_device(ti_lmu_of_match, dev); - if (!match) - return -ENODEV; /* * Get device specific data from of_match table. * This data is defined by using TI_LMU_DATA() macro. */ - data = (struct ti_lmu_data *)match->data; + data = of_device_get_match_data(dev); + if (!data) + return -ENODEV; lmu = devm_kzalloc(dev, sizeof(*lmu), GFP_KERNEL); if (!lmu) @@ -217,6 +204,17 @@ static int ti_lmu_probe(struct i2c_client *cl, const struct i2c_device_id *id) data->num_cells, NULL, 0, NULL); } +static const struct of_device_id ti_lmu_of_match[] = { + { .compatible = "ti,lm3532", .data = &lm3532_data }, + { .compatible = "ti,lm3631", .data = &lm3631_data }, + { .compatible = "ti,lm3632", .data = &lm3632_data }, + { .compatible = "ti,lm3633", .data = &lm3633_data }, + { .compatible = "ti,lm3695", .data = &lm3695_data }, + { .compatible = "ti,lm3697", .data = &lm3697_data }, + { } +}; +MODULE_DEVICE_TABLE(of, ti_lmu_of_match); + static const struct i2c_device_id ti_lmu_ids[] = { { "lm3532", LM3532 }, { "lm3631", LM3631 }, -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 181 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180911/a58e887f/attachment.sig> ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] mfd: ti-lmu: use of_device_get_match_data() helper 2018-09-11 21:06 ` [PATCH 3/3] mfd: ti-lmu: use of_device_get_match_data() helper Pavel Machek @ 2018-10-09 8:57 ` Lee Jones 0 siblings, 0 replies; 6+ messages in thread From: Lee Jones @ 2018-10-09 8:57 UTC (permalink / raw) To: linux-arm-kernel On Tue, 11 Sep 2018, Pavel Machek wrote: > Replace of_match_device() with of_device_get_match_data(), which > slightly decreases lines of code and allows to move the DT table > next to the I2C table. > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> > Signed-off-by: Pavel Machek <pavel@ucw.cz> Not sure how you're sending these patches, but for future reference `git send-email` is usually preferred. Applied, thanks. -- Lee Jones [???] Linaro Services Technical Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] mfd: ti-lmu: use managed resource for everything 2018-09-11 21:03 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Pavel Machek 2018-09-11 21:06 ` [PATCH 3/3] mfd: ti-lmu: use of_device_get_match_data() helper Pavel Machek @ 2018-10-09 8:56 ` Lee Jones 1 sibling, 0 replies; 6+ messages in thread From: Lee Jones @ 2018-10-09 8:56 UTC (permalink / raw) To: linux-arm-kernel On Tue, 11 Sep 2018, Pavel Machek wrote: > This replaces all remaining unmanaged resources with device > managed ones, so that the remove function is no longer needed. > This makes the code slightly shorter and fixes two problems: > > 1. The hardware is disabled after the child devices have > been removed. Previously there was a potential race > condition. > 2. The hardware is disabled when mfd_add_devices fails > during probe. > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> > Signed-off-by: Pavel Machek <pavel@ucw.cz> Applied, thanks. -- Lee Jones [???] Linaro Services Technical Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] mfd: ti-lmu: switch to gpiod 2018-09-11 21:01 [PATCH 1/3] mfd: ti-lmu: switch to gpiod Pavel Machek 2018-09-11 21:03 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Pavel Machek @ 2018-10-09 8:56 ` Lee Jones 1 sibling, 0 replies; 6+ messages in thread From: Lee Jones @ 2018-10-09 8:56 UTC (permalink / raw) To: linux-arm-kernel On Tue, 11 Sep 2018, Pavel Machek wrote: > Use new descriptor based API instead of the legacy one. > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> > Signed-off-by: Pavel Machek <pavel@ucw.cz> Applied, thanks. -- Lee Jones [???] Linaro Services Technical Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-10-09 8:57 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-09-11 21:01 [PATCH 1/3] mfd: ti-lmu: switch to gpiod Pavel Machek 2018-09-11 21:03 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Pavel Machek 2018-09-11 21:06 ` [PATCH 3/3] mfd: ti-lmu: use of_device_get_match_data() helper Pavel Machek 2018-10-09 8:57 ` Lee Jones 2018-10-09 8:56 ` [PATCH 2/3] mfd: ti-lmu: use managed resource for everything Lee Jones 2018-10-09 8:56 ` [PATCH 1/3] mfd: ti-lmu: switch to gpiod Lee Jones
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).