Skip to content

Commit

Permalink
rtc: ds1307: improve irq setup
Browse files Browse the repository at this point in the history
Change the usage of variable want_irq to reflect its name. Don't set
it to true in case wakeup is enabled but no interrupt number is given.
In addition set variable ds1307_can_wakeup_device if chip->alarm
is set only.
This allows to simplify the code and make it better understandable.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
  • Loading branch information
Heiner Kallweit authored and Alexandre Belloni committed Aug 31, 2017
1 parent 7624df4 commit 82e2d43
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions drivers/rtc/rtc-ds1307.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ static int ds1307_probe(struct i2c_client *client,
int err = -ENODEV;
int tmp, wday;
const struct chip_desc *chip;
bool want_irq = false;
bool want_irq;
bool ds1307_can_wakeup_device = false;
unsigned char *buf;
struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);
Expand Down Expand Up @@ -1358,6 +1358,8 @@ static int ds1307_probe(struct i2c_client *client,
ds1307->type = acpi_id->driver_data;
}

want_irq = client->irq > 0 && chip->alarm;

if (!pdata)
trickle_charger_setup = ds1307_trickle_init(ds1307, chip);
else if (pdata->trickle_charger_setup)
Expand All @@ -1383,7 +1385,8 @@ static int ds1307_probe(struct i2c_client *client,
* This will guarantee the 'wakealarm' sysfs entry is available on the device,
* if supported by the RTC.
*/
if (of_property_read_bool(client->dev.of_node, "wakeup-source"))
if (chip->alarm && of_property_read_bool(client->dev.of_node,
"wakeup-source"))
ds1307_can_wakeup_device = true;
#endif

Expand All @@ -1409,12 +1412,9 @@ static int ds1307_probe(struct i2c_client *client,
* For some variants, be sure alarms can trigger when we're
* running on Vbackup (BBSQI/BBSQW)
*/
if (chip->alarm && (client->irq > 0 ||
ds1307_can_wakeup_device)) {
if (want_irq || ds1307_can_wakeup_device) {
ds1307->regs[0] |= DS1337_BIT_INTCN | chip->bbsqi_bit;
ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);

want_irq = true;
}

regmap_write(ds1307->regmap, DS1337_REG_CONTROL,
Expand Down Expand Up @@ -1493,21 +1493,16 @@ static int ds1307_probe(struct i2c_client *client,
case rx_8130:
ds1307->offset = 0x10; /* Seconds starts at 0x10 */
rtc_ops = &rx8130_rtc_ops;
if (chip->alarm && client->irq > 0) {
if (want_irq)
irq_handler = rx8130_irq;
want_irq = true;
}
break;
case ds_1388:
ds1307->offset = 1; /* Seconds starts at 1 */
break;
case mcp794xx:
rtc_ops = &mcp794xx_rtc_ops;
if (chip->alarm && (client->irq > 0 ||
ds1307_can_wakeup_device)) {
if (want_irq || ds1307_can_wakeup_device)
irq_handler = mcp794xx_irq;
want_irq = true;
}
break;
default:
break;
Expand Down Expand Up @@ -1639,7 +1634,7 @@ static int ds1307_probe(struct i2c_client *client,
MCP794XX_REG_WEEKDAY_WDAY_MASK,
tm.tm_wday + 1);

if (want_irq) {
if (want_irq || ds1307_can_wakeup_device) {
device_set_wakeup_capable(ds1307->dev, true);
set_bit(HAS_ALARM, &ds1307->flags);
}
Expand All @@ -1649,9 +1644,7 @@ static int ds1307_probe(struct i2c_client *client,
return PTR_ERR(ds1307->rtc);
}

if (ds1307_can_wakeup_device && client->irq <= 0) {
/* Disable request for an IRQ */
want_irq = false;
if (ds1307_can_wakeup_device && !want_irq) {
dev_info(ds1307->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 */
Expand Down

0 comments on commit 82e2d43

Please sign in to comment.