Lines Matching +full:3 +full:base +full:- +full:x

1 // SPDX-License-Identifier: GPL-2.0-only
49 #define ALARM_EN (1 << 3)
62 pm860x_set_bits(info->i2c, PM8607_RTC1, mask | ALARM_EN, mask); in rtc_update_handler()
63 rtc_update_irq(info->rtc_dev, 1, RTC_AF); in rtc_update_handler()
72 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM_EN, ALARM_EN); in pm860x_rtc_alarm_irq_enable()
74 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM_EN, 0); in pm860x_rtc_alarm_irq_enable()
82 unsigned long ticks, base, data; in pm860x_rtc_read_time() local
84 pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf); in pm860x_rtc_read_time()
85 dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1], in pm860x_rtc_read_time()
86 buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); in pm860x_rtc_read_time()
87 base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | in pm860x_rtc_read_time()
90 /* load 32-bit read-only counter */ in pm860x_rtc_read_time()
91 pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); in pm860x_rtc_read_time()
92 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm860x_rtc_read_time()
94 ticks = base + data; in pm860x_rtc_read_time()
95 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm860x_rtc_read_time()
96 base, data, ticks); in pm860x_rtc_read_time()
107 unsigned long ticks, base, data; in pm860x_rtc_set_time() local
111 /* load 32-bit read-only counter */ in pm860x_rtc_set_time()
112 pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); in pm860x_rtc_set_time()
113 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm860x_rtc_set_time()
115 base = ticks - data; in pm860x_rtc_set_time()
116 dev_dbg(info->dev, "set base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm860x_rtc_set_time()
117 base, data, ticks); in pm860x_rtc_set_time()
119 pm860x_page_reg_write(info->i2c, REG0_DATA, (base >> 24) & 0xFF); in pm860x_rtc_set_time()
120 pm860x_page_reg_write(info->i2c, REG1_DATA, (base >> 16) & 0xFF); in pm860x_rtc_set_time()
121 pm860x_page_reg_write(info->i2c, REG2_DATA, (base >> 8) & 0xFF); in pm860x_rtc_set_time()
122 pm860x_page_reg_write(info->i2c, REG3_DATA, base & 0xFF); in pm860x_rtc_set_time()
131 unsigned long ticks, base, data; in pm860x_rtc_read_alarm() local
134 pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf); in pm860x_rtc_read_alarm()
135 dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1], in pm860x_rtc_read_alarm()
136 buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); in pm860x_rtc_read_alarm()
137 base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | in pm860x_rtc_read_alarm()
140 pm860x_bulk_read(info->i2c, PM8607_RTC_EXPIRE1, 4, buf); in pm860x_rtc_read_alarm()
141 data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | in pm860x_rtc_read_alarm()
143 ticks = base + data; in pm860x_rtc_read_alarm()
144 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", in pm860x_rtc_read_alarm()
145 base, data, ticks); in pm860x_rtc_read_alarm()
147 rtc_time64_to_tm(ticks, &alrm->time); in pm860x_rtc_read_alarm()
148 ret = pm860x_reg_read(info->i2c, PM8607_RTC1); in pm860x_rtc_read_alarm()
149 alrm->enabled = (ret & ALARM_EN) ? 1 : 0; in pm860x_rtc_read_alarm()
150 alrm->pending = (ret & (ALARM | ALARM_WAKEUP)) ? 1 : 0; in pm860x_rtc_read_alarm()
157 unsigned long ticks, base, data; in pm860x_rtc_set_alarm() local
161 pm860x_set_bits(info->i2c, PM8607_RTC1, ALARM_EN, 0); in pm860x_rtc_set_alarm()
163 pm860x_page_bulk_read(info->i2c, REG0_ADDR, 8, buf); in pm860x_rtc_set_alarm()
164 dev_dbg(info->dev, "%x-%x-%x-%x-%x-%x-%x-%x\n", buf[0], buf[1], in pm860x_rtc_set_alarm()
165 buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); in pm860x_rtc_set_alarm()
166 base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | in pm860x_rtc_set_alarm()
169 ticks = rtc_tm_to_time64(&alrm->time); in pm860x_rtc_set_alarm()
170 data = ticks - base; in pm860x_rtc_set_alarm()
175 buf[3] = (data >> 24) & 0xff; in pm860x_rtc_set_alarm()
176 pm860x_bulk_write(info->i2c, PM8607_RTC_EXPIRE1, 4, buf); in pm860x_rtc_set_alarm()
177 if (alrm->enabled) { in pm860x_rtc_set_alarm()
179 pm860x_set_bits(info->i2c, PM8607_RTC1, mask, mask); in pm860x_rtc_set_alarm()
182 pm860x_set_bits(info->i2c, PM8607_RTC1, mask, in pm860x_rtc_set_alarm()
207 pm860x_bulk_read(info->i2c, REG_VRTC_MEAS1, 2, buf); in calibrate_vrtc_work()
213 vrtc_set = 2700 + (info->vrtc & 0x3) * 200; in calibrate_vrtc_work()
214 dev_dbg(info->dev, "mean:%d, vrtc_set:%d\n", mean, vrtc_set); in calibrate_vrtc_work()
216 sum = pm860x_reg_read(info->i2c, PM8607_RTC_MISC1); in calibrate_vrtc_work()
223 pm860x_reg_write(info->i2c, PM8607_RTC_MISC1, data); in calibrate_vrtc_work()
224 } else if ((mean - 200) > vrtc_set) { in calibrate_vrtc_work()
226 if (data-- == 0) in calibrate_vrtc_work()
229 pm860x_reg_write(info->i2c, PM8607_RTC_MISC1, data); in calibrate_vrtc_work()
232 dev_dbg(info->dev, "set 0x%x to RTC_MISC1\n", data); in calibrate_vrtc_work()
234 schedule_delayed_work(&info->calib_work, VRTC_CALIB_INTERVAL); in calibrate_vrtc_work()
238 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0); in calibrate_vrtc_work()
239 dev_dbg(info->dev, "finish VRTC calibration\n"); in calibrate_vrtc_work()
248 struct device_node *np = pdev->dev.parent->of_node; in pm860x_rtc_dt_init()
251 return -ENODEV; in pm860x_rtc_dt_init()
254 dev_err(&pdev->dev, "failed to find rtc node\n"); in pm860x_rtc_dt_init()
255 return -ENODEV; in pm860x_rtc_dt_init()
257 ret = of_property_read_u32(np, "marvell,88pm860x-vrtc", &info->vrtc); in pm860x_rtc_dt_init()
259 info->vrtc = 0; in pm860x_rtc_dt_init()
264 #define pm860x_rtc_dt_init(x, y) do { } while (0) argument
269 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); in pm860x_rtc_probe()
273 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info), in pm860x_rtc_probe()
276 return -ENOMEM; in pm860x_rtc_probe()
277 info->irq = platform_get_irq(pdev, 0); in pm860x_rtc_probe()
278 if (info->irq < 0) in pm860x_rtc_probe()
279 return info->irq; in pm860x_rtc_probe()
281 info->chip = chip; in pm860x_rtc_probe()
282 info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; in pm860x_rtc_probe()
283 info->dev = &pdev->dev; in pm860x_rtc_probe()
284 dev_set_drvdata(&pdev->dev, info); in pm860x_rtc_probe()
286 info->rtc_dev = devm_rtc_allocate_device(&pdev->dev); in pm860x_rtc_probe()
287 if (IS_ERR(info->rtc_dev)) in pm860x_rtc_probe()
288 return PTR_ERR(info->rtc_dev); in pm860x_rtc_probe()
290 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, in pm860x_rtc_probe()
294 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", in pm860x_rtc_probe()
295 info->irq, ret); in pm860x_rtc_probe()
299 /* set addresses of 32-bit base value for RTC time */ in pm860x_rtc_probe()
300 pm860x_page_reg_write(info->i2c, REG0_ADDR, REG0_DATA); in pm860x_rtc_probe()
301 pm860x_page_reg_write(info->i2c, REG1_ADDR, REG1_DATA); in pm860x_rtc_probe()
302 pm860x_page_reg_write(info->i2c, REG2_ADDR, REG2_DATA); in pm860x_rtc_probe()
303 pm860x_page_reg_write(info->i2c, REG3_ADDR, REG3_DATA); in pm860x_rtc_probe()
307 info->rtc_dev->ops = &pm860x_rtc_ops; in pm860x_rtc_probe()
308 info->rtc_dev->range_max = U32_MAX; in pm860x_rtc_probe()
310 ret = devm_rtc_register_device(info->rtc_dev); in pm860x_rtc_probe()
316 * free running in PMIC power-down state. in pm860x_rtc_probe()
318 pm860x_set_bits(info->i2c, PM8607_RTC1, RTC1_USE_XO, RTC1_USE_XO); in pm860x_rtc_probe()
321 /* <00> -- 2.7V, <01> -- 2.9V, <10> -- 3.1V, <11> -- 3.3V */ in pm860x_rtc_probe()
322 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC); in pm860x_rtc_probe()
325 INIT_DELAYED_WORK(&info->calib_work, calibrate_vrtc_work); in pm860x_rtc_probe()
326 schedule_delayed_work(&info->calib_work, VRTC_CALIB_INTERVAL); in pm860x_rtc_probe()
329 device_init_wakeup(&pdev->dev, 1); in pm860x_rtc_probe()
339 cancel_delayed_work_sync(&info->calib_work); in pm860x_rtc_remove()
341 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0); in pm860x_rtc_remove()
349 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); in pm860x_rtc_suspend()
352 chip->wakeup_flag |= 1 << PM8607_IRQ_RTC; in pm860x_rtc_suspend()
358 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); in pm860x_rtc_resume()
361 chip->wakeup_flag &= ~(1 << PM8607_IRQ_RTC); in pm860x_rtc_resume()
370 .name = "88pm860x-rtc",