[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1465970379-14703-6-git-send-email-andrew.smirnov@gmail.com>
Date: Tue, 14 Jun 2016 22:59:31 -0700
From: Andrey Smirnov <andrew.smirnov@...il.com>
To: rtc-linux@...glegroups.com
Cc: Alessandro Zummo <a.zummo@...ertech.it>,
Alexandre Belloni <alexandre.belloni@...e-electrons.com>,
linux-kernel@...r.kernel.org,
Andrey Smirnov <andrew.smirnov@...il.com>
Subject: [PATCH 05/13] RTC: ds1307: Convert want_irq into a predicate
Convert want_irq variable into a predicate in order to detangle various
independent chunks of ds1307_probe().
Signed-off-by: Andrey Smirnov <andrew.smirnov@...il.com>
---
drivers/rtc/rtc-ds1307.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index c482d8b..81967c1 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1247,6 +1247,30 @@ static bool ds1307_can_wakeup_device(const struct ds1307 *ds1307)
"wakeup-source");
}
+static bool ds1307_want_irq(const struct ds1307 *ds1307,
+ const struct chip_desc *chip)
+{
+
+
+ if (chip->alarm) {
+ switch (ds1307->type) {
+ case ds_1337:
+ case ds_1339:
+ case ds_3231:
+ case ds_1341:
+ return (ds1307->client->irq > 0 ||
+ ds1307_can_wakeup_device(ds1307));
+
+ case mcp794xx:
+ return (ds1307->client->irq > 0);
+ default:
+ break;
+ }
+ }
+
+ return false;
+}
+
static int ds1307_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -1255,7 +1279,6 @@ static int ds1307_probe(struct i2c_client *client,
int tmp;
struct chip_desc *chip = &chips[id->driver_data];
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
- bool want_irq = false;
unsigned char *buf;
struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);
irq_handler_t irq_handler = ds1307_irq;
@@ -1356,10 +1379,6 @@ static int ds1307_probe(struct i2c_client *client,
| bbsqi_bitpos[ds1307->type];
ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
- if (chip->alarm && (ds1307->client->irq > 0 ||
- ds1307_can_wakeup_device(ds1307)))
- want_irq = true;
-
i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL,
ds1307->regs[0]);
@@ -1441,10 +1460,7 @@ static int ds1307_probe(struct i2c_client *client,
break;
case mcp794xx:
rtc_ops = &mcp794xx_rtc_ops;
- if (ds1307->client->irq > 0 && chip->alarm) {
- irq_handler = mcp794xx_irq;
- want_irq = true;
- }
+ irq_handler = mcp794xx_irq;
break;
default:
break;
@@ -1557,7 +1573,7 @@ read_rtc:
bin2bcd(tmp));
}
- if (want_irq) {
+ if (ds1307_want_irq(ds1307, chip)) {
device_set_wakeup_capable(&client->dev, true);
set_bit(HAS_ALARM, &ds1307->flags);
}
@@ -1570,13 +1586,11 @@ read_rtc:
if (ds1307_can_wakeup_device(ds1307) &&
ds1307->client->irq <= 0) {
/* Disable request for an IRQ */
- want_irq = false;
- dev_info(&client->dev, "'wakeup-source' is set, request for an IRQ is disabled!\n");
+ dev_info(&client->dev,
+ "'wakeup-source' is set, request for an IRQ is disabled!\n");
/* We cannot support UIE mode if we do not have an IRQ line */
ds1307->rtc->uie_unsupported = 1;
- }
-
- if (want_irq) {
+ } else if (ds1307_want_irq(ds1307, chip)) {
err = devm_request_threaded_irq(&client->dev,
client->irq, NULL, irq_handler,
IRQF_SHARED | IRQF_ONESHOT,
--
2.5.5
Powered by blists - more mailing lists