Lines Matching +full:bus +full:- +full:idle +full:- +full:timeout
4 * SPDX-License-Identifier: Apache-2.0
32 #define EEPROM_AT25_STATUS_WIP BIT(0) /* Write-In-Process (RO) */
49 } bus; member
57 uint16_t timeout; member
70 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_write_protect()
72 if (!config->wp_gpio.port) { in eeprom_at2x_write_protect()
76 return gpio_pin_set_dt(&config->wp_gpio, 1); in eeprom_at2x_write_protect()
81 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_write_enable()
83 if (!config->wp_gpio.port) { in eeprom_at2x_write_enable()
87 return gpio_pin_set_dt(&config->wp_gpio, 0); in eeprom_at2x_write_enable()
94 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_read()
95 struct eeprom_at2x_data *data = dev->data; in eeprom_at2x_read()
103 if ((offset + len) > config->size) { in eeprom_at2x_read()
105 return -EINVAL; in eeprom_at2x_read()
108 k_mutex_lock(&data->lock, K_FOREVER); in eeprom_at2x_read()
110 ret = config->read_fn(dev, offset, pbuf, len); in eeprom_at2x_read()
113 k_mutex_unlock(&data->lock); in eeprom_at2x_read()
119 len -= ret; in eeprom_at2x_read()
122 k_mutex_unlock(&data->lock); in eeprom_at2x_read()
131 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_limit_write_count()
136 if (count > config->pagesize) { in eeprom_at2x_limit_write_count()
137 count = config->pagesize; in eeprom_at2x_limit_write_count()
141 page_boundary = ROUND_UP(offset + 1, config->pagesize); in eeprom_at2x_limit_write_count()
143 count = page_boundary - offset; in eeprom_at2x_limit_write_count()
153 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_write()
154 struct eeprom_at2x_data *data = dev->data; in eeprom_at2x_write()
158 if (config->readonly) { in eeprom_at2x_write()
159 LOG_WRN("attempt to write to read-only device"); in eeprom_at2x_write()
160 return -EACCES; in eeprom_at2x_write()
167 if ((offset + len) > config->size) { in eeprom_at2x_write()
169 return -EINVAL; in eeprom_at2x_write()
172 k_mutex_lock(&data->lock, K_FOREVER); in eeprom_at2x_write()
177 LOG_ERR("failed to write-enable EEPROM (err %d)", ret); in eeprom_at2x_write()
178 k_mutex_unlock(&data->lock); in eeprom_at2x_write()
184 ret = config->write_fn(dev, offset, pbuf, len); in eeprom_at2x_write()
190 k_mutex_unlock(&data->lock); in eeprom_at2x_write()
196 len -= ret; in eeprom_at2x_write()
202 LOG_ERR("failed to write-protect EEPROM (err %d)", ret); in eeprom_at2x_write()
208 k_mutex_unlock(&data->lock); in eeprom_at2x_write()
215 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_size()
217 return config->size; in eeprom_at2x_size()
224 const struct eeprom_at2x_config *config = dev->config; in eeprom_at24_bus_is_ready()
226 return device_is_ready(config->bus.i2c.bus); in eeprom_at24_bus_is_ready()
239 const struct eeprom_at2x_config *config = dev->config; in eeprom_at24_translate_offset()
241 const uint16_t addr_incr = *offset >> config->addr_width; in eeprom_at24_translate_offset()
242 *offset &= BIT_MASK(config->addr_width); in eeprom_at24_translate_offset()
244 return config->bus.i2c.addr + addr_incr; in eeprom_at24_translate_offset()
250 const struct eeprom_at2x_config *config = dev->config; in eeprom_at24_adjust_read_count()
251 const size_t remainder = BIT(config->addr_width) - offset; in eeprom_at24_adjust_read_count()
263 const struct eeprom_at2x_config *config = dev->config; in eeprom_at24_read()
264 int64_t timeout; in eeprom_at24_read() local
271 if (config->addr_width == 16) { in eeprom_at24_read()
283 timeout = k_uptime_get() + config->timeout; in eeprom_at24_read()
286 err = i2c_write_read(config->bus.i2c.bus, bus_addr, in eeprom_at24_read()
287 addr, config->addr_width / 8, in eeprom_at24_read()
289 if (!err || now > timeout) { in eeprom_at24_read()
305 const struct eeprom_at2x_config *config = dev->config; in eeprom_at24_write()
307 uint8_t block[config->addr_width / 8 + count]; in eeprom_at24_write()
308 int64_t timeout; in eeprom_at24_write() local
320 if (config->addr_width == 16) { in eeprom_at24_write()
331 timeout = k_uptime_get() + config->timeout; in eeprom_at24_write()
334 err = i2c_write(config->bus.i2c.bus, block, sizeof(block), in eeprom_at24_write()
336 if (!err || now > timeout) { in eeprom_at24_write()
354 const struct eeprom_at2x_config *config = dev->config; in eeprom_at25_bus_is_ready()
356 return spi_is_ready_dt(&config->bus.spi); in eeprom_at25_bus_is_ready()
361 const struct eeprom_at2x_config *config = dev->config; in eeprom_at25_rdsr()
382 err = spi_transceive_dt(&config->bus.spi, &tx, &rx); in eeprom_at25_rdsr()
392 const struct eeprom_at2x_config *config = dev->config; in eeprom_at25_wait_for_idle()
393 int64_t timeout; in eeprom_at25_wait_for_idle() local
397 timeout = k_uptime_get() + config->timeout; in eeprom_at25_wait_for_idle()
409 if (now > timeout) { in eeprom_at25_wait_for_idle()
415 return -EBUSY; in eeprom_at25_wait_for_idle()
421 const struct eeprom_at2x_config *config = dev->config; in eeprom_at25_read()
422 size_t cmd_len = 1 + config->addr_width / 8; in eeprom_at25_read()
453 if ((offset + len) > config->size) { in eeprom_at25_read()
455 return -EINVAL; in eeprom_at25_read()
459 switch (config->addr_width) { in eeprom_at25_read()
475 LOG_ERR("EEPROM idle wait failed (err %d)", err); in eeprom_at25_read()
479 err = spi_transceive_dt(&config->bus.spi, &tx, &rx); in eeprom_at25_read()
489 const struct eeprom_at2x_config *config = dev->config; in eeprom_at25_wren()
500 return spi_write_dt(&config->bus.spi, &tx); in eeprom_at25_wren()
506 const struct eeprom_at2x_config *config = dev->config; in eeprom_at25_write()
509 size_t cmd_len = 1 + config->addr_width / 8; in eeprom_at25_write()
528 switch (config->addr_width) { in eeprom_at25_write()
544 LOG_ERR("EEPROM idle wait failed (err %d)", err); in eeprom_at25_write()
554 err = spi_transceive_dt(&config->bus.spi, &tx, NULL); in eeprom_at25_write()
565 const struct eeprom_at2x_config *config = dev->config; in eeprom_at2x_init()
566 struct eeprom_at2x_data *data = dev->data; in eeprom_at2x_init()
568 k_mutex_init(&data->lock); in eeprom_at2x_init()
570 if (!config->bus_is_ready(dev)) { in eeprom_at2x_init()
571 LOG_ERR("parent bus device not ready"); in eeprom_at2x_init()
572 return -EINVAL; in eeprom_at2x_init()
576 if (config->wp_gpio.port) { in eeprom_at2x_init()
578 if (!gpio_is_ready_dt(&config->wp_gpio)) { in eeprom_at2x_init()
580 return -EINVAL; in eeprom_at2x_init()
583 err = gpio_pin_configure_dt(&config->wp_gpio, GPIO_OUTPUT_ACTIVE); in eeprom_at2x_init()
609 BUILD_ASSERT((page != 0U) && ((page & (page - 1)) == 0U), \
637 .bus = EEPROM_AT##t##_BUS(n, t), \
643 .timeout = DT_PROP(INST_DT_AT2X(n, t), timeout), \