rtc: ds1307: factor out bbsqi bit to struct chip_desc
[linux-2.6-microblaze.git] / drivers / rtc / rtc-ds1307.c
index 4fac49e..eecf6b2 100644 (file)
@@ -126,7 +126,6 @@ struct ds1307 {
        struct device           *dev;
        struct regmap           *regmap;
        const char              *name;
-       int                     irq;
        struct rtc_device       *rtc;
 #ifdef CONFIG_COMMON_CLK
        struct clk_hw           clks[2];
@@ -140,6 +139,7 @@ struct chip_desc {
        u8                      century_reg;
        u8                      century_enable_bit;
        u8                      century_bit;
+       u8                      bbsqi_bit;
        u16                     trickle_charger_reg;
        u8                      trickle_charger_setup;
        u8                      (*do_trickle_setup)(struct ds1307 *, uint32_t,
@@ -170,6 +170,7 @@ static struct chip_desc chips[last_ds_type] = {
                .alarm          = 1,
                .century_reg    = DS1307_REG_MONTH,
                .century_bit    = DS1337_BIT_CENTURY,
+               .bbsqi_bit      = DS1339_BIT_BBSQI,
                .trickle_charger_reg = 0x10,
                .do_trickle_setup = &do_trickle_setup_ds1339,
        },
@@ -186,6 +187,7 @@ static struct chip_desc chips[last_ds_type] = {
                .alarm          = 1,
                .century_reg    = DS1307_REG_MONTH,
                .century_bit    = DS1337_BIT_CENTURY,
+               .bbsqi_bit      = DS3231_BIT_BBSQW,
        },
        [rx_8130] = {
                .alarm          = 1,
@@ -1320,11 +1322,6 @@ static int ds1307_probe(struct i2c_client *client,
 
        irq_handler_t   irq_handler = ds1307_irq;
 
-       static const int        bbsqi_bitpos[] = {
-               [ds_1337] = 0,
-               [ds_1339] = DS1339_BIT_BBSQI,
-               [ds_3231] = DS3231_BIT_BBSQW,
-       };
        const struct rtc_class_ops *rtc_ops = &ds13xx_rtc_ops;
 
        ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL);
@@ -1334,7 +1331,6 @@ static int ds1307_probe(struct i2c_client *client,
        dev_set_drvdata(&client->dev, ds1307);
        ds1307->dev = &client->dev;
        ds1307->name = client->name;
-       ds1307->irq = client->irq;
 
        ds1307->regmap = devm_regmap_init_i2c(client, &regmap_config);
        if (IS_ERR(ds1307->regmap)) {
@@ -1388,14 +1384,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 (of_property_read_bool(client->dev.of_node, "wakeup-source"))
                ds1307_can_wakeup_device = true;
-       }
-       /* Intersil ISL12057 DT backward compatibility */
-       if (of_property_read_bool(client->dev.of_node,
-                                 "isil,irq2-can-wakeup-machine")) {
-               ds1307_can_wakeup_device = true;
-       }
 #endif
 
        switch (ds1307->type) {
@@ -1420,10 +1410,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 && (ds1307->irq > 0 ||
+               if (chip->alarm && (client->irq > 0 ||
                                    ds1307_can_wakeup_device)) {
-                       ds1307->regs[0] |= DS1337_BIT_INTCN
-                                       | bbsqi_bitpos[ds1307->type];
+                       ds1307->regs[0] |= DS1337_BIT_INTCN | chip->bbsqi_bit;
                        ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
 
                        want_irq = true;
@@ -1505,7 +1494,7 @@ 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 && ds1307->irq > 0) {
+               if (chip->alarm && client->irq > 0) {
                        irq_handler = rx8130_irq;
                        want_irq = true;
                }
@@ -1515,7 +1504,7 @@ static int ds1307_probe(struct i2c_client *client,
                break;
        case mcp794xx:
                rtc_ops = &mcp794xx_rtc_ops;
-               if (chip->alarm && (ds1307->irq > 0 ||
+               if (chip->alarm && (client->irq > 0 ||
                                    ds1307_can_wakeup_device)) {
                        irq_handler = mcp794xx_irq;
                        want_irq = true;
@@ -1661,7 +1650,7 @@ read_rtc:
                return PTR_ERR(ds1307->rtc);
        }
 
-       if (ds1307_can_wakeup_device && ds1307->irq <= 0) {
+       if (ds1307_can_wakeup_device && client->irq <= 0) {
                /* Disable request for an IRQ */
                want_irq = false;
                dev_info(ds1307->dev,
@@ -1672,7 +1661,7 @@ read_rtc:
 
        if (want_irq) {
                err = devm_request_threaded_irq(ds1307->dev,
-                                               ds1307->irq, NULL, irq_handler,
+                                               client->irq, NULL, irq_handler,
                                                IRQF_SHARED | IRQF_ONESHOT,
                                                ds1307->name, ds1307);
                if (err) {