From patchwork Wed Jul 12 02:52:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony O'Brien X-Patchwork-Id: 9835815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2629B602BD for ; Wed, 12 Jul 2017 02:53:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F31E285BD for ; Wed, 12 Jul 2017 02:53:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13ED7285CE; Wed, 12 Jul 2017 02:53:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47E2E285BD for ; Wed, 12 Jul 2017 02:53:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933002AbdGLCwr (ORCPT ); Tue, 11 Jul 2017 22:52:47 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:44178 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932973AbdGLCwq (ORCPT ); Tue, 11 Jul 2017 22:52:46 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 07BBB803EC; Wed, 12 Jul 2017 14:52:43 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1499827963; bh=D2Zm1MKHiGCjDWjE07JDomrUntI8bZFKPZ6fltggocQ=; h=From:To:Subject:Date; b=gf6hCGpM1IOPzmoU/J7Ohfb6Q5IaiUpU9JTdJtPbtm3/3RHqcz+TxbP+Q+IPtDrVc nNZ7c/ZK3Xm2oyCs0Y7qW3SufrcoazrGmq+DcCMS7wanqR+wqKxu+Wu13gId6hYeK6 snXvsKWcorQ/EkwlmwLenTtOh6YJm7dkKaNR9G1I= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 7, 8900) id ; Wed, 12 Jul 2017 14:52:42 +1200 Received: from tonyo-dl.atlnz.lc (tonyo-dl.ws.atlnz.lc [10.33.24.33]) by smtp (Postfix) with ESMTP id CD20013ED17; Wed, 12 Jul 2017 14:52:43 +1200 (NZST) Received: by tonyo-dl.atlnz.lc (Postfix, from userid 1161) id E391BA37AB; Wed, 12 Jul 2017 14:52:37 +1200 (NZST) From: Tony O'Brien To: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (lm75) Add a basic interrupt handler Date: Wed, 12 Jul 2017 14:52:37 +1200 Message-Id: <20170712025237.24163-1-tony.obrien@alliedtelesis.co.nz> X-Mailer: git-send-email 2.13.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The LM75 interrupt cannot be masked in the device so an over-temperature event can cause an interrupt that cannot be cleared. Add an interrupt handler if an interrupt node exists in the DTS for an LM75. The handler simply reads a device register to clear the interrupt and returns. Signed-off-by: Tony O'Brien Reviewed-by: Chris Packham --- drivers/hwmon/lm75.c | 28 ++++++++++++++++++++++++++++ drivers/hwmon/lm75.h | 1 + 2 files changed, 29 insertions(+) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 005ffb5ffa92..08a833e960aa 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -265,6 +266,17 @@ static void lm75_remove(void *data) i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf); } +static irqreturn_t lm75_process_interrupt(int irq, void *data) +{ + struct i2c_client *client = (struct i2c_client *)data; + int val; + + /* Do a read to clear the interrupt */ + val = i2c_smbus_read_byte_data(client, LM75_REG_CONF); + + return IRQ_HANDLED; +} + static int lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -275,6 +287,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) u8 set_mask, clr_mask; int new; enum lm75_type kind; + int ret; if (client->dev.of_node) kind = (enum lm75_type)of_device_get_match_data(&client->dev); @@ -375,6 +388,21 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) break; } + if (client->irq) { + /* If requesting an interrupt then set to interrupt mode */ + set_mask |= LM75_MODE_INTERRUPT; + ret = devm_request_threaded_irq(dev, client->irq, NULL, + lm75_process_interrupt, + IRQF_TRIGGER_LOW | IRQF_ONESHOT | + IRQF_SHARED, + dev_name(dev), + client); + if (ret) { + dev_err(dev, "Error requesting irq\n"); + return ret; + } + } + /* configure as specified */ status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); if (status < 0) { diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h index 5cde94e56f17..82a71d870331 100644 --- a/drivers/hwmon/lm75.h +++ b/drivers/hwmon/lm75.h @@ -31,6 +31,7 @@ #define LM75_TEMP_MIN (-55000) #define LM75_TEMP_MAX 125000 #define LM75_SHUTDOWN 0x01 +#define LM75_MODE_INTERRUPT 0x02 /* TEMP: 0.001C/bit (-55C to +125C) REG: (0.5C/bit, two's complement) << 7 */