From patchwork Wed Jan 20 12:29:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lothar_Wa=C3=9Fmann?= X-Patchwork-Id: 8071601 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 524A19F1CC for ; Wed, 20 Jan 2016 12:32:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67A8920456 for ; Wed, 20 Jan 2016 12:32:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62BCD20452 for ; Wed, 20 Jan 2016 12:32:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLruY-00034O-Lh; Wed, 20 Jan 2016 12:30:54 +0000 Received: from mail.karo-electronics.de ([81.173.242.67]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLruP-0002z3-2a for linux-arm-kernel@lists.infradead.org; Wed, 20 Jan 2016 12:30:46 +0000 From: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= To: =?UTF-8?q?Beno=C3=AEt=20Cousson?= , Ian Campbell , Kumar Gala , Liam Girdwood , Mark Brown , Mark Rutland , Pawel Moll , Rob Herring , Russell King , Tony Lindgren , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Subject: [PATCH 1/2] regulator: ltc3589: make IRQ optional Date: Wed, 20 Jan 2016 13:29:51 +0100 Message-Id: <1453292992-1788-2-git-send-email-LW@KARO-electronics.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453292992-1788-1-git-send-email-LW@KARO-electronics.de> References: <1453292992-1788-1-git-send-email-LW@KARO-electronics.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160120_043045_574282_D5624490 X-CRM114-Status: GOOD ( 16.00 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Lothar=20Wa=C3=9Fmann?= Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On the AM335x SoC rev. <= 1.0 the "Input Function of the EXTINTn Terminal is Inverted", for which the only remedy is to "Use an active high interrupt source or use an external inverter to change the polarity of any active low interrupt source." This pin is used as IRQ pin for the LTC3589 PMIC on the Ka-Ro electronics TX48 module. Make the IRQ optional in the driver and use a polling routine instead if no IRQ is specified in DT. Otherwise the driver will continuously generate interrupts and make the system unusable. Signed-off-by: Lothar Waßmann --- drivers/regulator/ltc3589.c | 49 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c index 972c386..fff90cd 100644 --- a/drivers/regulator/ltc3589.c +++ b/drivers/regulator/ltc3589.c @@ -65,6 +65,8 @@ #define LTC3589_VCCR_SW3_GO BIT(4) #define LTC3589_VCCR_LDO2_GO BIT(6) +#define POLL_PERIOD 1000 + enum ltc3589_variant { LTC3589, LTC3589_1, @@ -97,6 +99,7 @@ struct ltc3589 { enum ltc3589_variant variant; struct ltc3589_regulator regulator_descs[LTC3589_NUM_REGULATORS]; struct regulator_dev *regulators[LTC3589_NUM_REGULATORS]; + struct delayed_work poll_timer; }; static const int ltc3589_ldo4[] = { @@ -407,11 +410,10 @@ static const struct regmap_config ltc3589_regmap_config = { .cache_type = REGCACHE_RBTREE, }; - -static irqreturn_t ltc3589_isr(int irq, void *dev_id) +static inline void ltc3589_handle_irq(struct ltc3589 *ltc3589) { - struct ltc3589 *ltc3589 = dev_id; - unsigned int i, irqstat, event; + u32 irqstat, event; + int i; regmap_read(ltc3589->regmap, LTC3589_IRQSTAT, &irqstat); @@ -431,6 +433,24 @@ static irqreturn_t ltc3589_isr(int irq, void *dev_id) /* Clear warning condition */ regmap_write(ltc3589->regmap, LTC3589_CLIRQ, 0); +} + +static void ltc3589_poll_func(struct work_struct *work) +{ + struct ltc3589 *ltc3589 = container_of(work, struct ltc3589, + poll_timer.work); + unsigned long timeout = msecs_to_jiffies(POLL_PERIOD); + + ltc3589_handle_irq(ltc3589); + + schedule_delayed_work(<c3589->poll_timer, timeout); +} + +static irqreturn_t ltc3589_isr(int irq, void *dev_id) +{ + struct ltc3589 *ltc3589 = dev_id; + + ltc3589_handle_irq(ltc3589); return IRQ_HANDLED; } @@ -519,6 +539,16 @@ static int ltc3589_probe(struct i2c_client *client, return ret; } } + if (client->irq <= 0) { + dev_warn(dev, + "No interrupt configured; poll for thermal shutdown and undervoltage events\n"); + + INIT_DELAYED_WORK(<c3589->poll_timer, ltc3589_poll_func); + schedule_delayed_work(<c3589->poll_timer, + msecs_to_jiffies(POLL_PERIOD)); + + return 0; + } ret = devm_request_threaded_irq(dev, client->irq, NULL, ltc3589_isr, IRQF_TRIGGER_LOW | IRQF_ONESHOT, @@ -531,6 +561,16 @@ static int ltc3589_probe(struct i2c_client *client, return 0; } +static int ltc3589_remove(struct i2c_client *client) +{ + struct ltc3589 *ltc3589 = i2c_get_clientdata(client); + + if (client->irq <= 0) + cancel_delayed_work(<c3589->poll_timer); + + return 0; +} + static struct i2c_device_id ltc3589_i2c_id[] = { { "ltc3589", LTC3589 }, { "ltc3589-1", LTC3589_1 }, @@ -544,6 +584,7 @@ static struct i2c_driver ltc3589_driver = { .name = DRIVER_NAME, }, .probe = ltc3589_probe, + .remove = ltc3589_remove, .id_table = ltc3589_i2c_id, }; module_i2c_driver(ltc3589_driver);