Skip to content

Commit

Permalink
i2c: target: eeprom_target: add read-only property
Browse files Browse the repository at this point in the history
In case the EEPROM data stored in the buffer shall be not writable from the
I2C interface, the read-only property can now be set in the device tree.

Signed-off-by: Manuel Aebischer <[email protected]>
  • Loading branch information
Manuel Aebischer committed Jul 11, 2024
1 parent 24773a1 commit 0aa34cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/i2c/target/eeprom_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct i2c_eeprom_target_data {
uint32_t buffer_idx;
uint32_t idx_write_cnt;
uint8_t address_width;
bool read_only;
};

struct i2c_eeprom_target_config {
Expand Down Expand Up @@ -129,7 +130,7 @@ static int eeprom_target_write_received(struct i2c_target_config *config,

data->buffer_idx = val | (data->buffer_idx << 8);
data->idx_write_cnt++;
} else {
} else if (!data->read_only) {
data->buffer[data->buffer_idx++] = val;
}

Expand Down Expand Up @@ -254,6 +255,8 @@ static int i2c_eeprom_target_init(const struct device *dev)
i2c_eeprom_target_##inst##_dev_data = { \
.address_width = DT_INST_PROP_OR(inst, \
address_width, 8), \
.read_only = DT_INST_PROP_OR(inst, \
read_only, 8), \
}; \
\
static uint8_t \
Expand Down
3 changes: 3 additions & 0 deletions dts/bindings/mtd/zephyr,i2c-target-eeprom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ properties:
description: |
Number of address bits used to address the EEPROM. If not specified
the EEPROM is assumed to have a 8-bit address.
read-only:
type: boolean
description: set this property if the EERPOM is read-only.

0 comments on commit 0aa34cf

Please sign in to comment.