Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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