Lines Matching +full:gpios +full:- +full:clear +full:- +full:reg
2 * SPDX-License-Identifier: Apache-2.0
88 /* am1805-gpios property must be in the devicetree inorder to use the RTC_ALARM */
90 #error "am1805-gpios" - property not available in devicetree.
106 /* For gpio-interrupt */
121 struct am1805_data *data = dev->data; in am1805_set_time()
122 const struct am1805_config *config = dev->config; in am1805_set_time()
124 k_mutex_lock(&data->lock, K_FOREVER); in am1805_set_time()
126 /* To unlock Stop-bit */ in am1805_set_time()
127 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_CONTROL1_ADDR, in am1805_set_time()
135 tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, tm->tm_hour, tm->tm_min, in am1805_set_time()
136 tm->tm_sec); in am1805_set_time()
138 regs[0] = bin2bcd(tm->tm_sec) & SECONDS_BITS; in am1805_set_time()
139 regs[1] = bin2bcd(tm->tm_min) & MINUTES_BITS; in am1805_set_time()
140 regs[2] = bin2bcd(tm->tm_hour) & HOURS_BITS; in am1805_set_time()
141 regs[3] = bin2bcd(tm->tm_mday) & DATE_BITS; in am1805_set_time()
142 regs[4] = bin2bcd(tm->tm_mon) & MONTHS_BITS; in am1805_set_time()
143 regs[5] = bin2bcd(tm->tm_year) & YEAR_BITS; in am1805_set_time()
144 regs[6] = bin2bcd(tm->tm_wday) & WEEKDAY_BITS; in am1805_set_time()
146 err = i2c_burst_write_dt(&config->int_i2c, REG_SECONDS_ADDR, regs, sizeof(regs)); in am1805_set_time()
151 /* To lock Stop-bit */ in am1805_set_time()
152 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_CONTROL1_ADDR, REG_CONTROL1_STOP, 0); in am1805_set_time()
155 k_mutex_unlock(&data->lock); in am1805_set_time()
167 struct am1805_data *data = dev->data; in am1805_get_time()
168 const struct am1805_config *config = dev->config; in am1805_get_time()
170 k_mutex_lock(&data->lock, K_FOREVER); in am1805_get_time()
172 err = i2c_reg_read_byte_dt(&config->int_i2c, REG_CONTROL1_ADDR, &ctl_reg); in am1805_get_time()
183 err = i2c_burst_read_dt(&config->int_i2c, REG_SECONDS_ADDR, regs, sizeof(regs)); in am1805_get_time()
188 timeptr->tm_sec = bcd2bin(regs[0] & SECONDS_BITS); in am1805_get_time()
189 timeptr->tm_min = bcd2bin(regs[1] & MINUTES_BITS); in am1805_get_time()
190 timeptr->tm_hour = bcd2bin(regs[2] & HOURS_BITS); in am1805_get_time()
191 timeptr->tm_mday = bcd2bin(regs[3] & DATE_BITS); in am1805_get_time()
192 timeptr->tm_mon = bcd2bin(regs[4] & MONTHS_BITS); in am1805_get_time()
193 timeptr->tm_year = bcd2bin(regs[5] & YEAR_BITS); in am1805_get_time()
194 timeptr->tm_wday = bcd2bin(regs[6] & WEEKDAY_BITS); in am1805_get_time()
198 timeptr->tm_year, timeptr->tm_mon, timeptr->tm_mday, timeptr->tm_wday, in am1805_get_time()
199 timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec); in am1805_get_time()
202 k_mutex_unlock(&data->lock); in am1805_get_time()
214 struct am1805_data *data = dev->data; in am1805_set_calibration()
215 const struct am1805_config *config = dev->config; in am1805_set_calibration()
216 uint8_t reg = REG_OSC_STATUS_MASK; in am1805_set_calibration() local
218 if (xt_clock_adj < -320 || xt_clock_adj > 127) { in am1805_set_calibration()
220 return -EINVAL; in am1805_set_calibration()
221 } else if (xt_clock_adj < -256) { in am1805_set_calibration()
223 reg |= REG_OSC_STATUS_ACAL_3; in am1805_set_calibration()
227 } else if (xt_clock_adj < -192) { in am1805_set_calibration()
229 reg |= REG_OSC_STATUS_ACAL_3; in am1805_set_calibration()
232 } else if (xt_clock_adj < -128) { in am1805_set_calibration()
234 reg |= REG_OSC_STATUS_ACAL_2; in am1805_set_calibration()
237 } else if (xt_clock_adj < -64) { in am1805_set_calibration()
239 reg |= REG_OSC_STATUS_ACAL_1; in am1805_set_calibration()
244 reg |= REG_OSC_STATUS_ACAL_0; in am1805_set_calibration()
249 reg |= REG_OSC_STATUS_ACAL_0; in am1805_set_calibration()
255 k_mutex_lock(&data->lock, K_FOREVER); in am1805_set_calibration()
257 err = i2c_reg_write_byte_dt(&config->int_i2c, REG_OSC_STATUS_ADDR, reg); in am1805_set_calibration()
264 reg = xt_calib_value; in am1805_set_calibration()
265 err = i2c_reg_write_byte_dt(&config->int_i2c, REG_XT_CALIB_ADDR, reg); in am1805_set_calibration()
271 k_mutex_unlock(&data->lock); in am1805_set_calibration()
280 uint8_t reg; in am1805_get_calibration() local
283 struct am1805_data *data = dev->data; in am1805_get_calibration()
284 const struct am1805_config *config = dev->config; in am1805_get_calibration()
286 k_mutex_lock(&data->lock, K_FOREVER); in am1805_get_calibration()
288 err = i2c_reg_read_byte_dt(&config->int_i2c, REG_OSC_STATUS_ADDR, ®); in am1805_get_calibration()
293 /* First 2-bits (from MSB) */ in am1805_get_calibration()
294 xtcal = reg >> 6; in am1805_get_calibration()
296 err = i2c_reg_read_byte_dt(&config->int_i2c, REG_XT_CALIB_ADDR, ®); in am1805_get_calibration()
301 *calib = reg; in am1805_get_calibration()
303 cmdx = reg & BIT(7); in am1805_get_calibration()
304 /* Set or Clear the bit-7 based on bit-6, to achieve the given range (in datasheet) */ in am1805_get_calibration()
305 WRITE_BIT(reg, 7, (reg & BIT(6))); in am1805_get_calibration()
306 WRITE_BIT(reg, 6, 0); in am1805_get_calibration()
308 LOG_DBG("XTCAL = %d, CMDX = %d, OFFSETX = %d\n", xtcal, cmdx, (int8_t) reg); in am1805_get_calibration()
311 k_mutex_unlock(&data->lock); in am1805_get_calibration()
326 struct am1805_data *data = dev->data; in am1805_alarm_get_time()
327 const struct am1805_config *config = dev->config; in am1805_alarm_get_time()
331 return -EINVAL; in am1805_alarm_get_time()
334 k_mutex_lock(&data->lock, K_FOREVER); in am1805_alarm_get_time()
336 err = i2c_burst_read_dt(&config->int_i2c, REG_ALM_SECONDS_ADDR, regs, sizeof(regs)); in am1805_alarm_get_time()
341 timeptr->tm_sec = bcd2bin(regs[0] & SECONDS_BITS); in am1805_alarm_get_time()
342 timeptr->tm_min = bcd2bin(regs[1] & MINUTES_BITS); in am1805_alarm_get_time()
343 timeptr->tm_hour = bcd2bin(regs[2] & HOURS_BITS); in am1805_alarm_get_time()
344 timeptr->tm_mday = bcd2bin(regs[3] & DATE_BITS); in am1805_alarm_get_time()
345 timeptr->tm_mon = bcd2bin(regs[4] & MONTHS_BITS); in am1805_alarm_get_time()
346 timeptr->tm_wday = bcd2bin(regs[5] & WEEKDAY_BITS); in am1805_alarm_get_time()
351 "mask = 0x%04x", timeptr->tm_wday, timeptr->tm_mon, timeptr->tm_mday, in am1805_alarm_get_time()
352 timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, *mask); in am1805_alarm_get_time()
355 k_mutex_unlock(&data->lock); in am1805_alarm_get_time()
366 struct am1805_data *data = dev->data; in am1805_alarm_set_time()
367 const struct am1805_config *config = dev->config; in am1805_alarm_set_time()
371 return -EINVAL; in am1805_alarm_set_time()
376 return -EINVAL; in am1805_alarm_set_time()
379 k_mutex_lock(&data->lock, K_FOREVER); in am1805_alarm_set_time()
382 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_TIMER_CTRL_ADDR, in am1805_alarm_set_time()
388 /* Clear the interrupt mask for alarm */ in am1805_alarm_set_time()
389 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_IRQ_MASK_ADDR, in am1805_alarm_set_time()
395 /* Clear the status bit */ in am1805_alarm_set_time()
396 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_STATUS_ADDR, in am1805_alarm_set_time()
408 regs[0] = bin2bcd(timeptr->tm_sec) & SECONDS_BITS; in am1805_alarm_set_time()
409 regs[1] = bin2bcd(timeptr->tm_min) & MINUTES_BITS; in am1805_alarm_set_time()
410 regs[2] = bin2bcd(timeptr->tm_hour) & HOURS_BITS; in am1805_alarm_set_time()
411 regs[3] = bin2bcd(timeptr->tm_mday) & DATE_BITS; in am1805_alarm_set_time()
412 regs[4] = bin2bcd(timeptr->tm_mon) & MONTHS_BITS; in am1805_alarm_set_time()
413 regs[5] = bin2bcd(timeptr->tm_wday) & WEEKDAY_BITS; in am1805_alarm_set_time()
417 timeptr->tm_sec, timeptr->tm_min, timeptr->tm_hour, timeptr->tm_mday, in am1805_alarm_set_time()
418 timeptr->tm_mon, timeptr->tm_wday, mask); in am1805_alarm_set_time()
420 err = i2c_burst_write_dt(&config->int_i2c, REG_ALM_SECONDS_ADDR, regs, sizeof(regs)); in am1805_alarm_set_time()
426 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_IRQ_MASK_ADDR, in am1805_alarm_set_time()
433 err = i2c_reg_update_byte_dt(&config->int_i2c, REG_TIMER_CTRL_ADDR, in am1805_alarm_set_time()
437 k_mutex_unlock(&data->lock); in am1805_alarm_set_time()
448 return -EINVAL; in am1805_alarm_get_supported_fields()
460 struct am1805_data *data = dev->data; in am1805_alarm_set_callback()
461 const struct am1805_config *config = dev->config; in am1805_alarm_set_callback()
463 if (config->int_gpio.port == NULL) { in am1805_alarm_set_callback()
464 return -ENOTSUP; in am1805_alarm_set_callback()
469 return -EINVAL; in am1805_alarm_set_callback()
472 k_mutex_lock(&data->lock, K_FOREVER); in am1805_alarm_set_callback()
475 data->alarm_user_callback = callback; in am1805_alarm_set_callback()
476 data->alarm_user_data = user_data; in am1805_alarm_set_callback()
478 k_mutex_unlock(&data->lock); in am1805_alarm_set_callback()
485 struct am1805_data *data = dev->data; in am1805_interrupt_thread()
488 k_sem_take(&data->int_sem, K_FOREVER); in am1805_interrupt_thread()
490 if (data->alarm_user_callback == NULL) { in am1805_interrupt_thread()
491 LOG_DBG("Interrupt received, But No Alarm-Callback Initilized!!\n"); in am1805_interrupt_thread()
494 data->alarm_user_callback(dev, 0, data->alarm_user_data); in am1805_interrupt_thread()
506 k_sem_give(&data->int_sem); in am1805_gpio_callback_handler()
513 uint8_t reg; in am1805_init() local
515 const struct am1805_config *config = dev->config; in am1805_init()
516 struct am1805_data *data = dev->data; in am1805_init()
518 k_mutex_init(&data->lock); in am1805_init()
520 if (!i2c_is_ready_dt(&config->int_i2c)) { in am1805_init()
522 return -ENODEV; in am1805_init()
525 err = i2c_reg_read_byte_dt(&config->int_i2c, REG_STATUS_ADDR, ®); in am1805_init()
528 return -ENODEV; in am1805_init()
534 k_sem_init(&data->int_sem, 0, INT_MAX); in am1805_init()
536 if (!gpio_is_ready_dt(&config->int_gpio)) { in am1805_init()
538 return -ENODEV; in am1805_init()
541 err = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); in am1805_init()
544 return -ENODEV; in am1805_init()
547 err = gpio_pin_interrupt_configure_dt(&config->int_gpio, in am1805_init()
551 return -ENODEV; in am1805_init()
554 gpio_init_callback(&data->am1805_callback, am1805_gpio_callback_handler, in am1805_init()
555 BIT(config->int_gpio.pin)); in am1805_init()
557 err = gpio_add_callback_dt(&config->int_gpio, &data->am1805_callback); in am1805_init()
560 return -ENODEV; in am1805_init()
563 tid = k_thread_create(&data->am1805_thread, data->am1805_stack, in am1805_init()
564 K_THREAD_STACK_SIZEOF(data->am1805_stack), in am1805_init()
567 k_thread_name_set(tid, dev->name); in am1805_init()