rtc: ds1307: factor out rtc_ops to struct chip_desc

Factor out rtc_ops to struct chip_desc and use ds13xx_rtc_ops as default.

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
1efb98ba 45947127

+28 -23
+28 -23
drivers/rtc/rtc-ds1307.c
··· 141 141 u8 century_bit; 142 142 u8 bbsqi_bit; 143 143 irq_handler_t irq_handler; 144 + const struct rtc_class_ops *rtc_ops; 144 145 u16 trickle_charger_reg; 145 146 u8 (*do_trickle_setup)(struct ds1307 *, uint32_t, 146 147 bool); 147 148 }; 148 149 150 + static int ds1307_get_time(struct device *dev, struct rtc_time *t); 151 + static int ds1307_set_time(struct device *dev, struct rtc_time *t); 149 152 static u8 do_trickle_setup_ds1339(struct ds1307 *, uint32_t ohms, bool diode); 150 153 static irqreturn_t rx8130_irq(int irq, void *dev_id); 154 + static int rx8130_read_alarm(struct device *dev, struct rtc_wkalrm *t); 155 + static int rx8130_set_alarm(struct device *dev, struct rtc_wkalrm *t); 156 + static int rx8130_alarm_irq_enable(struct device *dev, unsigned int enabled); 151 157 static irqreturn_t mcp794xx_irq(int irq, void *dev_id); 158 + static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t); 159 + static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t); 160 + static int mcp794xx_alarm_irq_enable(struct device *dev, unsigned int enabled); 161 + 162 + static const struct rtc_class_ops rx8130_rtc_ops = { 163 + .read_time = ds1307_get_time, 164 + .set_time = ds1307_set_time, 165 + .read_alarm = rx8130_read_alarm, 166 + .set_alarm = rx8130_set_alarm, 167 + .alarm_irq_enable = rx8130_alarm_irq_enable, 168 + }; 169 + 170 + static const struct rtc_class_ops mcp794xx_rtc_ops = { 171 + .read_time = ds1307_get_time, 172 + .set_time = ds1307_set_time, 173 + .read_alarm = mcp794xx_read_alarm, 174 + .set_alarm = mcp794xx_set_alarm, 175 + .alarm_irq_enable = mcp794xx_alarm_irq_enable, 176 + }; 152 177 153 178 static const struct chip_desc chips[last_ds_type] = { 154 179 [ds_1307] = { ··· 222 197 .nvram_offset = 0x20, 223 198 .nvram_size = 4, /* 32bit (4 word x 8 bit) */ 224 199 .irq_handler = rx8130_irq, 200 + .rtc_ops = &rx8130_rtc_ops, 225 201 }, 226 202 [mcp794xx] = { 227 203 .alarm = 1, ··· 230 204 .nvram_offset = 0x20, 231 205 .nvram_size = 0x40, 232 206 .irq_handler = mcp794xx_irq, 207 + .rtc_ops = &mcp794xx_rtc_ops, 233 208 }, 234 209 }; 235 210 ··· 758 731 return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg); 759 732 } 760 733 761 - static const struct rtc_class_ops rx8130_rtc_ops = { 762 - .read_time = ds1307_get_time, 763 - .set_time = ds1307_set_time, 764 - .read_alarm = rx8130_read_alarm, 765 - .set_alarm = rx8130_set_alarm, 766 - .alarm_irq_enable = rx8130_alarm_irq_enable, 767 - }; 768 - 769 734 /*----------------------------------------------------------------------*/ 770 735 771 736 /* ··· 909 890 MCP794XX_BIT_ALM0_EN, 910 891 enabled ? MCP794XX_BIT_ALM0_EN : 0); 911 892 } 912 - 913 - static const struct rtc_class_ops mcp794xx_rtc_ops = { 914 - .read_time = ds1307_get_time, 915 - .set_time = ds1307_set_time, 916 - .read_alarm = mcp794xx_read_alarm, 917 - .set_alarm = mcp794xx_set_alarm, 918 - .alarm_irq_enable = mcp794xx_alarm_irq_enable, 919 - }; 920 893 921 894 /*----------------------------------------------------------------------*/ 922 895 ··· 1336 1325 unsigned long timestamp; 1337 1326 u8 trickle_charger_setup = 0; 1338 1327 1339 - const struct rtc_class_ops *rtc_ops = &ds13xx_rtc_ops; 1340 - 1341 1328 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); 1342 1329 if (!ds1307) 1343 1330 return -ENOMEM; ··· 1504 1495 break; 1505 1496 case rx_8130: 1506 1497 ds1307->offset = 0x10; /* Seconds starts at 0x10 */ 1507 - rtc_ops = &rx8130_rtc_ops; 1508 1498 break; 1509 1499 case ds_1388: 1510 1500 ds1307->offset = 1; /* Seconds starts at 1 */ 1511 - break; 1512 - case mcp794xx: 1513 - rtc_ops = &mcp794xx_rtc_ops; 1514 1501 break; 1515 1502 default: 1516 1503 break; ··· 1683 1678 ds1307->rtc->nvram_old_abi = true; 1684 1679 } 1685 1680 1686 - ds1307->rtc->ops = rtc_ops; 1681 + ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; 1687 1682 err = rtc_register_device(ds1307->rtc); 1688 1683 if (err) 1689 1684 return err;