Lines Matching full:rtc
3 * RTC driver for the interal RTC block in the Amlogic Meson6, Meson8,
6 * The RTC is split in to two parts, the AHB front end and a simple serial
25 #include <linux/rtc.h>
46 /* rtc registers accessed via rtc-serial interface */
62 struct rtc_device *rtc; /* rtc device we created */ member
79 /* RTC front-end serialiser controls */
81 static void meson_rtc_sclk_pulse(struct meson_rtc *rtc) in meson_rtc_sclk_pulse() argument
84 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SCLK, 0); in meson_rtc_sclk_pulse()
86 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SCLK, in meson_rtc_sclk_pulse()
90 static void meson_rtc_send_bit(struct meson_rtc *rtc, unsigned int bit) in meson_rtc_send_bit() argument
92 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SDI, in meson_rtc_send_bit()
94 meson_rtc_sclk_pulse(rtc); in meson_rtc_send_bit()
97 static void meson_rtc_send_bits(struct meson_rtc *rtc, u32 data, in meson_rtc_send_bits() argument
103 meson_rtc_send_bit(rtc, data & bit); in meson_rtc_send_bits()
108 static void meson_rtc_set_dir(struct meson_rtc *rtc, u32 mode) in meson_rtc_set_dir() argument
110 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SEN, 0); in meson_rtc_set_dir()
111 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SDI, 0); in meson_rtc_set_dir()
112 meson_rtc_send_bit(rtc, mode); in meson_rtc_set_dir()
113 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SDI, 0); in meson_rtc_set_dir()
116 static u32 meson_rtc_get_data(struct meson_rtc *rtc) in meson_rtc_get_data() argument
122 meson_rtc_sclk_pulse(rtc); in meson_rtc_get_data()
125 regmap_read(rtc->peripheral, RTC_ADDR1, &tmp); in meson_rtc_get_data()
132 static int meson_rtc_get_bus(struct meson_rtc *rtc) in meson_rtc_get_bus() argument
139 regmap_update_bits(rtc->peripheral, RTC_ADDR0, val, 0); in meson_rtc_get_bus()
143 if (!regmap_read_poll_timeout(rtc->peripheral, RTC_ADDR1, val, in meson_rtc_get_bus()
148 dev_warn(rtc->dev, "failed to get bus, resetting RTC\n"); in meson_rtc_get_bus()
150 ret = reset_control_reset(rtc->reset); in meson_rtc_get_bus()
155 dev_err(rtc->dev, "bus is not ready\n"); in meson_rtc_get_bus()
162 struct meson_rtc *rtc = context; in meson_rtc_serial_bus_reg_read() local
165 ret = meson_rtc_get_bus(rtc); in meson_rtc_serial_bus_reg_read()
169 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SEN, in meson_rtc_serial_bus_reg_read()
171 meson_rtc_send_bits(rtc, reg, RTC_ADDR_BITS); in meson_rtc_serial_bus_reg_read()
172 meson_rtc_set_dir(rtc, 0); in meson_rtc_serial_bus_reg_read()
173 *data = meson_rtc_get_data(rtc); in meson_rtc_serial_bus_reg_read()
181 struct meson_rtc *rtc = context; in meson_rtc_serial_bus_reg_write() local
184 ret = meson_rtc_get_bus(rtc); in meson_rtc_serial_bus_reg_write()
188 regmap_update_bits(rtc->peripheral, RTC_ADDR0, RTC_ADDR0_LINE_SEN, in meson_rtc_serial_bus_reg_write()
190 meson_rtc_send_bits(rtc, data, RTC_DATA_BITS); in meson_rtc_serial_bus_reg_write()
191 meson_rtc_send_bits(rtc, reg, RTC_ADDR_BITS); in meson_rtc_serial_bus_reg_write()
192 meson_rtc_set_dir(rtc, 1); in meson_rtc_serial_bus_reg_write()
211 static int meson_rtc_write_static(struct meson_rtc *rtc, u32 data) in meson_rtc_write_static() argument
215 regmap_write(rtc->peripheral, RTC_REG4, in meson_rtc_write_static()
220 regmap_update_bits(rtc->peripheral, RTC_ADDR0, in meson_rtc_write_static()
224 return regmap_read_poll_timeout(rtc->peripheral, RTC_REG4, tmp, in meson_rtc_write_static()
229 /* RTC interface layer functions */
233 struct meson_rtc *rtc = dev_get_drvdata(dev); in meson_rtc_gettime() local
237 ret = regmap_read(rtc->serial, RTC_COUNTER, &time); in meson_rtc_gettime()
246 struct meson_rtc *rtc = dev_get_drvdata(dev); in meson_rtc_settime() local
248 return regmap_write(rtc->serial, RTC_COUNTER, rtc_tm_to_time64(tm)); in meson_rtc_settime()
261 struct meson_rtc *rtc = context; in meson_rtc_regmem_read() local
267 return regmap_bulk_read(rtc->serial, read_offset, buf, read_size); in meson_rtc_regmem_read()
273 struct meson_rtc *rtc = context; in meson_rtc_regmem_write() local
279 return regmap_bulk_write(rtc->serial, write_offset, buf, write_size); in meson_rtc_regmem_write()
285 .name = "meson-rtc-regmem", in meson_rtc_probe()
294 struct meson_rtc *rtc; in meson_rtc_probe() local
299 rtc = devm_kzalloc(dev, sizeof(struct meson_rtc), GFP_KERNEL); in meson_rtc_probe()
300 if (!rtc) in meson_rtc_probe()
303 rtc->rtc = devm_rtc_allocate_device(dev); in meson_rtc_probe()
304 if (IS_ERR(rtc->rtc)) in meson_rtc_probe()
305 return PTR_ERR(rtc->rtc); in meson_rtc_probe()
307 platform_set_drvdata(pdev, rtc); in meson_rtc_probe()
309 rtc->dev = dev; in meson_rtc_probe()
311 rtc->rtc->ops = &meson_rtc_ops; in meson_rtc_probe()
312 rtc->rtc->range_max = U32_MAX; in meson_rtc_probe()
318 rtc->peripheral = devm_regmap_init_mmio(dev, base, in meson_rtc_probe()
320 if (IS_ERR(rtc->peripheral)) { in meson_rtc_probe()
322 return PTR_ERR(rtc->peripheral); in meson_rtc_probe()
325 rtc->reset = devm_reset_control_get(dev, NULL); in meson_rtc_probe()
326 if (IS_ERR(rtc->reset)) { in meson_rtc_probe()
328 return PTR_ERR(rtc->reset); in meson_rtc_probe()
331 rtc->vdd = devm_regulator_get(dev, "vdd"); in meson_rtc_probe()
332 if (IS_ERR(rtc->vdd)) { in meson_rtc_probe()
334 return PTR_ERR(rtc->vdd); in meson_rtc_probe()
337 ret = regulator_enable(rtc->vdd); in meson_rtc_probe()
343 ret = meson_rtc_write_static(rtc, MESON_STATIC_DEFAULT); in meson_rtc_probe()
349 rtc->serial = devm_regmap_init(dev, &meson_rtc_serial_bus, rtc, in meson_rtc_probe()
351 if (IS_ERR(rtc->serial)) { in meson_rtc_probe()
353 ret = PTR_ERR(rtc->serial); in meson_rtc_probe()
358 * check if we can read RTC counter, if not then the RTC is probably in meson_rtc_probe()
361 ret = regmap_read(rtc->serial, RTC_COUNTER, &tm); in meson_rtc_probe()
363 dev_err(dev, "cannot read RTC counter, RTC not functional\n"); in meson_rtc_probe()
367 meson_rtc_nvmem_config.priv = rtc; in meson_rtc_probe()
368 ret = devm_rtc_nvmem_register(rtc->rtc, &meson_rtc_nvmem_config); in meson_rtc_probe()
372 ret = devm_rtc_register_device(rtc->rtc); in meson_rtc_probe()
379 regulator_disable(rtc->vdd); in meson_rtc_probe()
384 { .compatible = "amlogic,meson6-rtc", },
385 { .compatible = "amlogic,meson8-rtc", },
386 { .compatible = "amlogic,meson8b-rtc", },
387 { .compatible = "amlogic,meson8m2-rtc", },
395 .name = "meson-rtc",
401 MODULE_DESCRIPTION("Amlogic Meson RTC Driver");
405 MODULE_ALIAS("platform:meson-rtc");