Lines Matching +full:buffer +full:- +full:size
4 * SPDX-License-Identifier: Apache-2.0
36 const struct microchip_mcp7940n_bbram_config *config = dev->config; in microchip_mcp7940n_bbram_init()
37 struct microchip_mcp7940n_bbram_data *data = dev->data; in microchip_mcp7940n_bbram_init()
39 uint8_t buffer; in microchip_mcp7940n_bbram_init() local
41 if (!device_is_ready(config->i2c.bus)) { in microchip_mcp7940n_bbram_init()
42 LOG_ERR("I2C device %s is not ready", config->i2c.bus->name); in microchip_mcp7940n_bbram_init()
43 return -ENODEV; in microchip_mcp7940n_bbram_init()
46 k_mutex_init(&data->lock); in microchip_mcp7940n_bbram_init()
48 rc = i2c_reg_read_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_init()
50 &buffer); in microchip_mcp7940n_bbram_init()
59 static int microchip_mcp7940n_bbram_size(const struct device *dev, size_t *size) in microchip_mcp7940n_bbram_size() argument
61 *size = MICROCHIP_MCP7940N_SRAM_SIZE; in microchip_mcp7940n_bbram_size()
68 const struct microchip_mcp7940n_bbram_config *config = dev->config; in microchip_mcp7940n_bbram_is_invalid()
69 struct microchip_mcp7940n_bbram_data *data = dev->data; in microchip_mcp7940n_bbram_is_invalid()
71 uint8_t buffer; in microchip_mcp7940n_bbram_is_invalid() local
74 k_mutex_lock(&data->lock, K_FOREVER); in microchip_mcp7940n_bbram_is_invalid()
76 rc = i2c_reg_read_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_is_invalid()
78 &buffer); in microchip_mcp7940n_bbram_is_invalid()
81 if ((buffer & MICROCHIP_MCP7940N_RTCWKDAY_PWRFAIL_BIT)) { in microchip_mcp7940n_bbram_is_invalid()
84 buffer &= (buffer ^ MICROCHIP_MCP7940N_RTCWKDAY_PWRFAIL_BIT); in microchip_mcp7940n_bbram_is_invalid()
86 rc = i2c_reg_write_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_is_invalid()
88 buffer); in microchip_mcp7940n_bbram_is_invalid()
98 k_mutex_unlock(&data->lock); in microchip_mcp7940n_bbram_is_invalid()
109 const struct microchip_mcp7940n_bbram_config *config = dev->config; in microchip_mcp7940n_bbram_check_standby_power()
110 struct microchip_mcp7940n_bbram_data *data = dev->data; in microchip_mcp7940n_bbram_check_standby_power()
112 uint8_t buffer; in microchip_mcp7940n_bbram_check_standby_power() local
115 k_mutex_lock(&data->lock, K_FOREVER); in microchip_mcp7940n_bbram_check_standby_power()
117 rc = i2c_reg_read_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_check_standby_power()
119 &buffer); in microchip_mcp7940n_bbram_check_standby_power()
122 if (!(buffer & MICROCHIP_MCP7940N_RTCWKDAY_VBATEN_BIT)) { in microchip_mcp7940n_bbram_check_standby_power()
125 buffer |= MICROCHIP_MCP7940N_RTCWKDAY_VBATEN_BIT; in microchip_mcp7940n_bbram_check_standby_power()
127 rc = i2c_reg_write_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_check_standby_power()
129 buffer); in microchip_mcp7940n_bbram_check_standby_power()
139 k_mutex_unlock(&data->lock); in microchip_mcp7940n_bbram_check_standby_power()
148 static int microchip_mcp7940n_bbram_read(const struct device *dev, size_t offset, size_t size, in microchip_mcp7940n_bbram_read() argument
149 uint8_t *buffer) in microchip_mcp7940n_bbram_read() argument
151 const struct microchip_mcp7940n_bbram_config *config = dev->config; in microchip_mcp7940n_bbram_read()
152 struct microchip_mcp7940n_bbram_data *data = dev->data; in microchip_mcp7940n_bbram_read()
156 if (size == 0 || (offset + size) > MICROCHIP_MCP7940N_SRAM_SIZE) { in microchip_mcp7940n_bbram_read()
157 return -EINVAL; in microchip_mcp7940n_bbram_read()
160 k_mutex_lock(&data->lock, K_FOREVER); in microchip_mcp7940n_bbram_read()
162 while (i < size) { in microchip_mcp7940n_bbram_read()
164 rc = i2c_reg_read_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_read()
166 &buffer[i]); in microchip_mcp7940n_bbram_read()
176 k_mutex_unlock(&data->lock); in microchip_mcp7940n_bbram_read()
181 static int microchip_mcp7940n_bbram_write(const struct device *dev, size_t offset, size_t size, in microchip_mcp7940n_bbram_write() argument
182 const uint8_t *buffer) in microchip_mcp7940n_bbram_write() argument
184 const struct microchip_mcp7940n_bbram_config *config = dev->config; in microchip_mcp7940n_bbram_write()
185 struct microchip_mcp7940n_bbram_data *data = dev->data; in microchip_mcp7940n_bbram_write()
189 if (size == 0 || (offset + size) > MICROCHIP_MCP7940N_SRAM_SIZE) { in microchip_mcp7940n_bbram_write()
190 return -EINVAL; in microchip_mcp7940n_bbram_write()
193 k_mutex_lock(&data->lock, K_FOREVER); in microchip_mcp7940n_bbram_write()
195 while (i < size) { in microchip_mcp7940n_bbram_write()
196 LOG_DBG("Write 0x%x to 0x%x", buffer[i], in microchip_mcp7940n_bbram_write()
198 rc = i2c_reg_write_byte_dt(&config->i2c, in microchip_mcp7940n_bbram_write()
200 buffer[i]); in microchip_mcp7940n_bbram_write()
210 k_mutex_unlock(&data->lock); in microchip_mcp7940n_bbram_write()