rtc: ds1307: improve irq setup

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>

authored by

Heiner Kallweit and committed by
Alexandre Belloni
82e2d43f 7624df48

+10 -17
+10 -17
drivers/rtc/rtc-ds1307.c
··· 1312 1312 int err = -ENODEV; 1313 1313 int tmp, wday; 1314 1314 const struct chip_desc *chip; 1315 - bool want_irq = false; 1315 + bool want_irq; 1316 1316 bool ds1307_can_wakeup_device = false; 1317 1317 unsigned char *buf; 1318 1318 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); ··· 1358 1358 ds1307->type = acpi_id->driver_data; 1359 1359 } 1360 1360 1361 + want_irq = client->irq > 0 && chip->alarm; 1362 + 1361 1363 if (!pdata) 1362 1364 trickle_charger_setup = ds1307_trickle_init(ds1307, chip); 1363 1365 else if (pdata->trickle_charger_setup) ··· 1385 1383 * This will guarantee the 'wakealarm' sysfs entry is available on the device, 1386 1384 * if supported by the RTC. 1387 1385 */ 1388 - if (of_property_read_bool(client->dev.of_node, "wakeup-source")) 1386 + if (chip->alarm && of_property_read_bool(client->dev.of_node, 1387 + "wakeup-source")) 1389 1388 ds1307_can_wakeup_device = true; 1390 1389 #endif 1391 1390 ··· 1412 1409 * For some variants, be sure alarms can trigger when we're 1413 1410 * running on Vbackup (BBSQI/BBSQW) 1414 1411 */ 1415 - if (chip->alarm && (client->irq > 0 || 1416 - ds1307_can_wakeup_device)) { 1412 + if (want_irq || ds1307_can_wakeup_device) { 1417 1413 ds1307->regs[0] |= DS1337_BIT_INTCN | chip->bbsqi_bit; 1418 1414 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); 1419 - 1420 - want_irq = true; 1421 1415 } 1422 1416 1423 1417 regmap_write(ds1307->regmap, DS1337_REG_CONTROL, ··· 1493 1493 case rx_8130: 1494 1494 ds1307->offset = 0x10; /* Seconds starts at 0x10 */ 1495 1495 rtc_ops = &rx8130_rtc_ops; 1496 - if (chip->alarm && client->irq > 0) { 1496 + if (want_irq) 1497 1497 irq_handler = rx8130_irq; 1498 - want_irq = true; 1499 - } 1500 1498 break; 1501 1499 case ds_1388: 1502 1500 ds1307->offset = 1; /* Seconds starts at 1 */ 1503 1501 break; 1504 1502 case mcp794xx: 1505 1503 rtc_ops = &mcp794xx_rtc_ops; 1506 - if (chip->alarm && (client->irq > 0 || 1507 - ds1307_can_wakeup_device)) { 1504 + if (want_irq || ds1307_can_wakeup_device) 1508 1505 irq_handler = mcp794xx_irq; 1509 - want_irq = true; 1510 - } 1511 1506 break; 1512 1507 default: 1513 1508 break; ··· 1634 1639 MCP794XX_REG_WEEKDAY_WDAY_MASK, 1635 1640 tm.tm_wday + 1); 1636 1641 1637 - if (want_irq) { 1642 + if (want_irq || ds1307_can_wakeup_device) { 1638 1643 device_set_wakeup_capable(ds1307->dev, true); 1639 1644 set_bit(HAS_ALARM, &ds1307->flags); 1640 1645 } ··· 1644 1649 return PTR_ERR(ds1307->rtc); 1645 1650 } 1646 1651 1647 - if (ds1307_can_wakeup_device && client->irq <= 0) { 1648 - /* Disable request for an IRQ */ 1649 - want_irq = false; 1652 + if (ds1307_can_wakeup_device && !want_irq) { 1650 1653 dev_info(ds1307->dev, 1651 1654 "'wakeup-source' is set, request for an IRQ is disabled!\n"); 1652 1655 /* We cannot support UIE mode if we do not have an IRQ line */