From: Grygorii Strashko <grygorii.strashko@ti.com>
To: Marcin Niestroj <m.niestroj@grinn-global.com>,
Lee Jones <lee.jones@linaro.org>
Cc: Tony Lindgren <tony@atomide.com>,
Sebastian Reichel <sre@kernel.org>,
Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
linux-omap@vger.kernel.org, linux-pm@vger.kernel.org,
linux-input@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 1/5] mfd: tps65217: Add support for IRQs
Date: Thu, 16 Jun 2016 16:03:40 +0300 [thread overview]
Message-ID: <5762A3AC.9010409@ti.com> (raw)
In-Reply-To: <20160616114110.23455-2-m.niestroj@grinn-global.com>
On 06/16/2016 02:41 PM, Marcin Niestroj wrote:
> Add support for handling IRQs: power button, AC and USB power state
> changes. Mask and interrupt bits are shared within one register, which
> prevents us to use regmap_irq implementation. New irq_domain is created in
> order to add interrupt handling for each tps65217's subsystem. IRQ
> resources have been added for charger subsystem to be able to notify about
> AC and USB state changes.
>
> Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
> ---
> drivers/mfd/Kconfig | 1 +
> drivers/mfd/tps65217.c | 194 +++++++++++++++++++++++++++++++++++++++++--
> include/linux/mfd/tps65217.h | 11 +++
> 3 files changed, 198 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 1bcf601..f8c9580 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1200,6 +1200,7 @@ config MFD_TPS65217
> depends on I2C
> select MFD_CORE
> select REGMAP_I2C
> + select IRQ_DOMAIN
> help
> If you say yes here you get support for the TPS65217 series of
> Power Management / White LED chips.
> diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c
> index 049a6fc..7763dbc 100644
> --- a/drivers/mfd/tps65217.c
> +++ b/drivers/mfd/tps65217.c
> @@ -15,22 +15,99 @@
> * GNU General Public License for more details.
> */
>
> -#include <linux/kernel.h>
> #include <linux/device.h>
> -#include <linux/module.h>
> -#include <linux/platform_device.h>
> +#include <linux/err.h>
> #include <linux/init.h>
> +#include <linux/interrupt.h>
> #include <linux/i2c.h>
> -#include <linux/slab.h>
> -#include <linux/regmap.h>
> -#include <linux/err.h>
> +#include <linux/irq.h>
> +#include <linux/irqdomain.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/slab.h>
>
> #include <linux/mfd/core.h>
> #include <linux/mfd/tps65217.h>
>
> -static const struct mfd_cell tps65217s[] = {
> +static struct resource charger_resources[] = {
> + DEFINE_RES_IRQ_NAMED(TPS65217_IRQ_AC, "AC"),
> + DEFINE_RES_IRQ_NAMED(TPS65217_IRQ_USB, "USB"),
> +};
> +
> +struct tps65217_irq {
> + int mask;
> + int interrupt;
> +};
> +
> +static const struct tps65217_irq tps65217_irqs[] = {
> + [TPS65217_IRQ_PB] = {
> + .mask = TPS65217_INT_PBM,
> + .interrupt = TPS65217_INT_PBI,
> + },
> + [TPS65217_IRQ_AC] = {
> + .mask = TPS65217_INT_ACM,
> + .interrupt = TPS65217_INT_ACI,
> + },
> + [TPS65217_IRQ_USB] = {
> + .mask = TPS65217_INT_USBM,
> + .interrupt = TPS65217_INT_USBI,
> + },
> +};
> +
> +static void tps65217_irq_lock(struct irq_data *data)
> +{
> + struct tps65217 *tps = irq_data_get_irq_chip_data(data);
> +
> + mutex_lock(&tps->irq_lock);
> +}
> +
> +static void tps65217_irq_sync_unlock(struct irq_data *data)
> +{
> + struct tps65217 *tps = irq_data_get_irq_chip_data(data);
> + int ret;
> +
> + ret = tps65217_reg_write(tps, TPS65217_REG_INT, tps->irq_mask,
> + TPS65217_PROTECT_NONE);
> + if (ret != 0)
> + dev_err(tps->dev, "Failed to sync IRQ masks\n");
> +
> + mutex_unlock(&tps->irq_lock);
> +}
> +
> +static const inline struct tps65217_irq *
> +irq_to_tps65217_irq(struct tps65217 *tps, struct irq_data *data)
> +{
> + return &tps65217_irqs[data->hwirq];
> +}
> +
> +static void tps65217_irq_enable(struct irq_data *data)
> +{
> + struct tps65217 *tps = irq_data_get_irq_chip_data(data);
> + const struct tps65217_irq *irq_data = irq_to_tps65217_irq(tps, data);
> +
> + tps->irq_mask &= ~irq_data->mask;
> +}
> +
> +static void tps65217_irq_disable(struct irq_data *data)
> +{
> + struct tps65217 *tps = irq_data_get_irq_chip_data(data);
> + const struct tps65217_irq *irq_data = irq_to_tps65217_irq(tps, data);
> +
> + tps->irq_mask |= irq_data->mask;
> +}
> +
> +static struct irq_chip tps65217_irq_chip = {
> + .irq_bus_lock = tps65217_irq_lock,
> + .irq_bus_sync_unlock = tps65217_irq_sync_unlock,
> + .irq_enable = tps65217_irq_enable,
> + .irq_disable = tps65217_irq_disable,
> +};
> +
> +static struct mfd_cell tps65217s[] = {
> {
> .name = "tps65217-pmic",
> .of_compatible = "ti,tps65217-pmic",
> @@ -41,10 +118,89 @@ static const struct mfd_cell tps65217s[] = {
> },
> {
> .name = "tps65217-charger",
> + .num_resources = ARRAY_SIZE(charger_resources),
> + .resources = charger_resources,
> .of_compatible = "ti,tps65217-charger",
> },
> };
>
> +static irqreturn_t tps65217_irq_thread(int irq, void *data)
> +{
> + struct tps65217 *tps = data;
> + unsigned int status;
> + bool handled = false;
> + int i;
> + int ret;
> +
> + ret = tps65217_reg_read(tps, TPS65217_REG_INT, &status);
> + if (ret < 0) {
> + dev_err(tps->dev, "Failed to read IRQ status: %d\n",
> + ret);
> + return IRQ_NONE;
> + }
> +
> + for (i = 0; i < ARRAY_SIZE(tps65217_irqs); i++) {
> + if (status & tps65217_irqs[i].interrupt) {
> + handle_nested_irq(irq_find_mapping(tps->irq_domain, i));
> + handled = true;
> + }
> + }
> +
> + if (handled)
> + return IRQ_HANDLED;
> +
> + return IRQ_NONE;
> +}
> +
> +static int tps65217_irq_map(struct irq_domain *h, unsigned int virq,
> + irq_hw_number_t hw)
> +{
> + struct tps65217 *tps = h->host_data;
> +
> + irq_set_chip_data(virq, tps);
> + irq_set_chip_and_handler(virq, &tps65217_irq_chip, handle_edge_irq);
> + irq_set_nested_thread(virq, 1);
> + irq_set_noprobe(virq);
irq_set_parent()?
> +
> + return 0;
> +}
> +
> +static const struct irq_domain_ops tps65217_irq_domain_ops = {
> + .map = tps65217_irq_map,
> +};
> +
> +static int tps65217_irq_init(struct tps65217 *tps, int irq)
> +{
> + int ret;
> +
> + mutex_init(&tps->irq_lock);
> +
> + /* Mask all interrupt sources */
> + tps->irq_mask = (TPS65217_INT_RESERVEDM | TPS65217_INT_PBM
> + | TPS65217_INT_ACM | TPS65217_INT_USBM);
> + tps65217_reg_write(tps, TPS65217_REG_INT, tps->irq_mask,
> + TPS65217_PROTECT_NONE);
> +
> + tps->irq_domain = irq_domain_add_linear(tps->dev->of_node,
> + TPS65217_NUM_IRQ, &tps65217_irq_domain_ops, tps);
> + if (!tps->irq_domain) {
> + dev_err(tps->dev, "Could not create IRQ domain\n");
> + return -ENOMEM;
> + }
> +
> + ret = devm_request_threaded_irq(tps->dev, irq, NULL,
> + tps65217_irq_thread,
> + IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Are there any reasons why IRQ trigger type specified here explicitly?
> + "tps65217-irq", tps);
> + if (ret) {
> + dev_err(tps->dev, "Failed to request IRQ %d: %d\n",
> + irq, ret);
> + return ret;
> + }
> +
> + return 0;
> +}
--
regards,
-grygorii
next prev parent reply other threads:[~2016-06-16 13:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 11:41 [PATCH v3 0/5] mfd: tps65217: Add power-button and IRQ support Marcin Niestroj
2016-06-16 11:41 ` [PATCH v3 1/5] mfd: tps65217: Add support for IRQs Marcin Niestroj
2016-06-16 13:03 ` Grygorii Strashko [this message]
2016-06-17 14:05 ` Marcin Niestroj
2016-06-17 14:42 ` Grygorii Strashko
[not found] ` <57640C3C.1070001-l0cyMroinI0@public.gmane.org>
2016-06-17 15:31 ` Marcin Niestroj
2016-06-17 16:09 ` Grygorii Strashko
2016-06-20 10:56 ` Marcin Niestroj
2016-06-16 14:30 ` Lee Jones
2016-06-16 11:41 ` [PATCH v3 2/5] power_supply: tps65217-charger: Fix NULL deref during property export Marcin Niestroj
2016-06-16 11:41 ` [PATCH v3 3/5] power_supply: tps65217-charger: Add support for IRQs Marcin Niestroj
2016-06-16 11:41 ` [PATCH v3 4/5] mfd: tps65217: Add power button as subdevice Marcin Niestroj
2016-06-16 14:30 ` Lee Jones
2016-06-16 11:41 ` [PATCH v3 5/5] Input: Add tps65217 power button driver Marcin Niestroj
[not found] ` <20160616114110.23455-6-m.niestroj-z3quKL4iOrmQ6ZAhV5LmOA@public.gmane.org>
2016-06-20 13:06 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5762A3AC.9010409@ti.com \
--to=grygorii.strashko@ti.com \
--cc=dbaryshkov@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dwmw2@infradead.org \
--cc=lee.jones@linaro.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=m.niestroj@grinn-global.com \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).