* [PATCH] regulator: da9210: Add optional interrupt support
@ 2015-06-24 12:14 Geert Uytterhoeven
[not found] ` <1435148061-11844-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2015-06-24 12:14 UTC (permalink / raw)
To: Support Opensource, Liam Girdwood, Mark Brown, Steve Twiss
Cc: linux-sh, linux-kernel, Geert Uytterhoeven, devicetree
Add optional interrupt support to the da9210 regulator driver, to handle
over-current, under- and over-voltage, and over-temperature events.
Only the interrupt sources for which we handle events are unmasked, to
avoid interrupts we cannot handle.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: devicetree@vger.kernel.org
---
I do not have access to the da9210 datasheet, but looked at the da9211
driver.
v2:
- Only acknowledge unmasked sources,
- Handle DA9210_E_VMAX using REGULATOR_EVENT_REGULATION_OUT.
---
.../devicetree/bindings/regulator/da9210.txt | 4 ++
drivers/regulator/da9210-regulator.c | 75 ++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/Documentation/devicetree/bindings/regulator/da9210.txt b/Documentation/devicetree/bindings/regulator/da9210.txt
index 3297c53cb9152395..7aa9b1fa6b21ca18 100644
--- a/Documentation/devicetree/bindings/regulator/da9210.txt
+++ b/Documentation/devicetree/bindings/regulator/da9210.txt
@@ -5,6 +5,10 @@ Required properties:
- compatible: must be "dlg,da9210"
- reg: the i2c slave address of the regulator. It should be 0x68.
+Optional properties:
+
+- interrupts: a reference to the DA9210 interrupt, if available.
+
Any standard regulator properties can be used to configure the single da9210
DCDC.
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
index f0489cb9018b4e78..8e39f7457bc36a07 100644
--- a/drivers/regulator/da9210-regulator.c
+++ b/drivers/regulator/da9210-regulator.c
@@ -22,6 +22,8 @@
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
#include <linux/slab.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
@@ -120,6 +122,55 @@ static int da9210_get_current_limit(struct regulator_dev *rdev)
return da9210_buck_limits[sel];
}
+static irqreturn_t da9210_irq_handler(int irq, void *data)
+{
+ struct da9210 *chip = data;
+ unsigned int val, handled = 0;
+ int error, ret = IRQ_NONE;
+
+ error = regmap_read(chip->regmap, DA9210_REG_EVENT_B, &val);
+ if (error < 0)
+ goto error_i2c;
+
+ if (val & DA9210_E_OVCURR) {
+ regulator_notifier_call_chain(chip->rdev,
+ REGULATOR_EVENT_OVER_CURRENT,
+ NULL);
+ handled |= DA9210_E_OVCURR;
+ }
+ if (val & DA9210_E_NPWRGOOD) {
+ regulator_notifier_call_chain(chip->rdev,
+ REGULATOR_EVENT_UNDER_VOLTAGE,
+ NULL);
+ handled |= DA9210_E_NPWRGOOD;
+ }
+ if (val & (DA9210_E_TEMP_WARN | DA9210_E_TEMP_CRIT)) {
+ regulator_notifier_call_chain(chip->rdev,
+ REGULATOR_EVENT_OVER_TEMP, NULL);
+ handled |= val & (DA9210_E_TEMP_WARN | DA9210_E_TEMP_CRIT);
+ }
+ if (val & DA9210_E_VMAX) {
+ regulator_notifier_call_chain(chip->rdev,
+ REGULATOR_EVENT_REGULATION_OUT,
+ NULL);
+ handled |= DA9210_E_VMAX;
+ }
+ if (handled) {
+ /* Clear handled events */
+ error = regmap_write(chip->regmap, DA9210_REG_EVENT_B, handled);
+ if (error < 0)
+ goto error_i2c;
+
+ ret = IRQ_HANDLED;
+ }
+
+ return ret;
+
+error_i2c:
+ dev_err(regmap_get_device(chip->regmap), "I2C error : %d\n", error);
+ return ret;
+}
+
/*
* I2C driver interface functions
*/
@@ -168,6 +219,30 @@ static int da9210_i2c_probe(struct i2c_client *i2c,
}
chip->rdev = rdev;
+ if (i2c->irq) {
+ error = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
+ da9210_irq_handler,
+ IRQF_TRIGGER_LOW |
+ IRQF_ONESHOT | IRQF_SHARED,
+ "da9210", chip);
+ if (error) {
+ dev_err(&i2c->dev, "Failed to request IRQ%u: %d\n",
+ i2c->irq, error);
+ return error;
+ }
+
+ error = regmap_update_bits(chip->regmap, DA9210_REG_MASK_B,
+ DA9210_M_OVCURR | DA9210_M_NPWRGOOD |
+ DA9210_M_TEMP_WARN |
+ DA9210_M_TEMP_CRIT | DA9210_M_VMAX, 0);
+ if (error < 0) {
+ dev_err(&i2c->dev, "Failed to update mask reg: %d\n",
+ error);
+ return error;
+ }
+ } else {
+ dev_warn(&i2c->dev, "No IRQ configured\n");
+ }
i2c_set_clientdata(i2c, chip);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH] regulator: da9210: Add optional interrupt support
[not found] ` <1435148061-11844-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
@ 2015-06-25 10:58 ` Opensource [Steve Twiss]
0 siblings, 0 replies; 2+ messages in thread
From: Opensource [Steve Twiss] @ 2015-06-25 10:58 UTC (permalink / raw)
To: Geert Uytterhoeven, Support Opensource, Liam Girdwood, Mark Brown,
Opensource [Steve Twiss]
Cc: linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On 24 June 2015 13:14, Geert Uytterhoeven wrote:
> To: Support Opensource; Liam Girdwood; Mark Brown; Opensource [Steve Twiss]
> Subject: [PATCH] regulator: da9210: Add optional interrupt support
>
> Add optional interrupt support to the da9210 regulator driver, to handle
> over-current, under- and over-voltage, and over-temperature events.
>
> Only the interrupt sources for which we handle events are unmasked, to
> avoid interrupts we cannot handle.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> ---
> I do not have access to the da9210 datasheet, but looked at the da9211 driver.
>
> v2:
> - Only acknowledge unmasked sources,
> - Handle DA9210_E_VMAX using REGULATOR_EVENT_REGULATION_OUT.
> ---
Hi Geert,
https://lkml.org/lkml/2015/2/17/358
I got side-tracked with other things and this one got forgotten ...
I'll take another look at this. A cursory glance from me -- it seems fair and
consistent with the DA9210 data sheet. I'll check with the engineers here.
Regards,
Steve
> .../devicetree/bindings/regulator/da9210.txt | 4 ++
> drivers/regulator/da9210-regulator.c | 75
> ++++++++++++++++++++++
> 2 files changed, 79 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/regulator/da9210.txt
> b/Documentation/devicetree/bindings/regulator/da9210.txt
> index 3297c53cb9152395..7aa9b1fa6b21ca18 100644
> --- a/Documentation/devicetree/bindings/regulator/da9210.txt
> +++ b/Documentation/devicetree/bindings/regulator/da9210.txt
> @@ -5,6 +5,10 @@ Required properties:
> - compatible: must be "dlg,da9210"
> - reg: the i2c slave address of the regulator. It should be 0x68.
>
> +Optional properties:
> +
> +- interrupts: a reference to the DA9210 interrupt, if available.
> +
> Any standard regulator properties can be used to configure the single
> da9210
> DCDC.
>
> diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-
> regulator.c
> index f0489cb9018b4e78..8e39f7457bc36a07 100644
> --- a/drivers/regulator/da9210-regulator.c
> +++ b/drivers/regulator/da9210-regulator.c
> @@ -22,6 +22,8 @@
> #include <linux/i2c.h>
> #include <linux/module.h>
> #include <linux/init.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>
> #include <linux/slab.h>
> #include <linux/regulator/driver.h>
> #include <linux/regulator/machine.h>
> @@ -120,6 +122,55 @@ static int da9210_get_current_limit(struct
> regulator_dev *rdev)
> return da9210_buck_limits[sel];
> }
>
> +static irqreturn_t da9210_irq_handler(int irq, void *data)
> +{
> + struct da9210 *chip = data;
> + unsigned int val, handled = 0;
> + int error, ret = IRQ_NONE;
> +
> + error = regmap_read(chip->regmap, DA9210_REG_EVENT_B, &val);
> + if (error < 0)
> + goto error_i2c;
> +
> + if (val & DA9210_E_OVCURR) {
> + regulator_notifier_call_chain(chip->rdev,
> +
> REGULATOR_EVENT_OVER_CURRENT,
> + NULL);
> + handled |= DA9210_E_OVCURR;
> + }
> + if (val & DA9210_E_NPWRGOOD) {
> + regulator_notifier_call_chain(chip->rdev,
> +
> REGULATOR_EVENT_UNDER_VOLTAGE,
> + NULL);
> + handled |= DA9210_E_NPWRGOOD;
> + }
> + if (val & (DA9210_E_TEMP_WARN | DA9210_E_TEMP_CRIT)) {
> + regulator_notifier_call_chain(chip->rdev,
> + REGULATOR_EVENT_OVER_TEMP,
> NULL);
> + handled |= val & (DA9210_E_TEMP_WARN |
> DA9210_E_TEMP_CRIT);
> + }
> + if (val & DA9210_E_VMAX) {
> + regulator_notifier_call_chain(chip->rdev,
> +
> REGULATOR_EVENT_REGULATION_OUT,
> + NULL);
> + handled |= DA9210_E_VMAX;
> + }
> + if (handled) {
> + /* Clear handled events */
> + error = regmap_write(chip->regmap,
> DA9210_REG_EVENT_B, handled);
> + if (error < 0)
> + goto error_i2c;
> +
> + ret = IRQ_HANDLED;
> + }
> +
> + return ret;
> +
> +error_i2c:
> + dev_err(regmap_get_device(chip->regmap), "I2C error : %d\n",
> error);
> + return ret;
> +}
> +
> /*
> * I2C driver interface functions
> */
> @@ -168,6 +219,30 @@ static int da9210_i2c_probe(struct i2c_client *i2c,
> }
>
> chip->rdev = rdev;
> + if (i2c->irq) {
> + error = devm_request_threaded_irq(&i2c->dev, i2c->irq,
> NULL,
> + da9210_irq_handler,
> + IRQF_TRIGGER_LOW |
> + IRQF_ONESHOT |
> IRQF_SHARED,
> + "da9210", chip);
> + if (error) {
> + dev_err(&i2c->dev, "Failed to request IRQ%u: %d\n",
> + i2c->irq, error);
> + return error;
> + }
> +
> + error = regmap_update_bits(chip->regmap,
> DA9210_REG_MASK_B,
> + DA9210_M_OVCURR |
> DA9210_M_NPWRGOOD |
> + DA9210_M_TEMP_WARN |
> + DA9210_M_TEMP_CRIT |
> DA9210_M_VMAX, 0);
> + if (error < 0) {
> + dev_err(&i2c->dev, "Failed to update mask reg:
> %d\n",
> + error);
> + return error;
> + }
> + } else {
> + dev_warn(&i2c->dev, "No IRQ configured\n");
> + }
>
> i2c_set_clientdata(i2c, chip);
>
> --
> 1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-06-25 10:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-24 12:14 [PATCH] regulator: da9210: Add optional interrupt support Geert Uytterhoeven
[not found] ` <1435148061-11844-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2015-06-25 10:58 ` Opensource [Steve Twiss]
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).