drivers: i2c: Add dts support for i2c slaves.
Adding i2c slave requires overlay with node definitions and proper aliases depending on driver implementation. Modified i2c_slave_api test to use information from dts. Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
This commit is contained in:
parent
66192618a7
commit
1dd5dc63c1
|
@ -17,46 +17,6 @@ config I2C_EEPROM_SLAVE_0
|
|||
depends on I2C_EEPROM_SLAVE
|
||||
default y
|
||||
|
||||
config I2C_EEPROM_SLAVE_0_SIZE
|
||||
int "I2C Slave EEPROM 0 Size in KiB"
|
||||
depends on I2C_EEPROM_SLAVE_0
|
||||
default 1
|
||||
|
||||
config I2C_EEPROM_SLAVE_0_NAME
|
||||
string "I2C Slave EEPROM 0 device name"
|
||||
depends on I2C_EEPROM_SLAVE_0
|
||||
default "EEPROM_SLAVE_0"
|
||||
|
||||
config I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME
|
||||
string "I2C Slave EEPROM 0 Controller device name"
|
||||
depends on I2C_EEPROM_SLAVE_0
|
||||
default "I2C_0"
|
||||
|
||||
config I2C_EEPROM_SLAVE_0_ADDRESS
|
||||
hex "I2C Slave EEPROM 0 address"
|
||||
depends on I2C_EEPROM_SLAVE_0
|
||||
default 0x54
|
||||
|
||||
config I2C_EEPROM_SLAVE_1
|
||||
bool "Enable I2C Slave EEPROM driver instance 1"
|
||||
depends on I2C_EEPROM_SLAVE
|
||||
|
||||
config I2C_EEPROM_SLAVE_1_SIZE
|
||||
int "I2C Slave EEPROM 1 Size in KiB"
|
||||
depends on I2C_EEPROM_SLAVE_1
|
||||
default 1
|
||||
|
||||
config I2C_EEPROM_SLAVE_1_NAME
|
||||
string "I2C Slave EEPROM 1 device name"
|
||||
depends on I2C_EEPROM_SLAVE_1
|
||||
default "EEPROM_SLAVE_1"
|
||||
|
||||
config I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME
|
||||
string "I2C Slave EEPROM 1 Controller device name"
|
||||
depends on I2C_EEPROM_SLAVE_1
|
||||
default "I2C_1"
|
||||
|
||||
config I2C_EEPROM_SLAVE_1_ADDRESS
|
||||
hex "I2C Slave EEPROM 1 address"
|
||||
depends on I2C_EEPROM_SLAVE_1
|
||||
default 0x56
|
||||
|
|
|
@ -206,16 +206,16 @@ static int i2c_eeprom_slave_init(struct device *dev)
|
|||
|
||||
static struct i2c_eeprom_slave_data i2c_eeprom_slave_0_dev_data;
|
||||
|
||||
static u8_t i2c_eeprom_slave_0_buffer[(CONFIG_I2C_EEPROM_SLAVE_0_SIZE * 1024)];
|
||||
static u8_t i2c_eeprom_slave_0_buffer[(EEPROM_SLAVE_0_SIZE * 1024)];
|
||||
|
||||
static const struct i2c_eeprom_slave_config i2c_eeprom_slave_0_cfg = {
|
||||
.controller_dev_name = CONFIG_I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME,
|
||||
.address = CONFIG_I2C_EEPROM_SLAVE_0_ADDRESS,
|
||||
.buffer_size = (CONFIG_I2C_EEPROM_SLAVE_0_SIZE * 1024),
|
||||
.controller_dev_name = EEPROM_SLAVE_0_BUS_NAME,
|
||||
.address = EEPROM_SLAVE_0_BASE_ADDRESS,
|
||||
.buffer_size = (EEPROM_SLAVE_0_SIZE * 1024),
|
||||
.buffer = i2c_eeprom_slave_0_buffer
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(i2c_eeprom_slave_0, CONFIG_I2C_EEPROM_SLAVE_0_NAME,
|
||||
DEVICE_AND_API_INIT(i2c_eeprom_slave_0, EEPROM_SLAVE_0_LABEL,
|
||||
&i2c_eeprom_slave_init,
|
||||
&i2c_eeprom_slave_0_dev_data, &i2c_eeprom_slave_0_cfg,
|
||||
POST_KERNEL, CONFIG_I2C_SLAVE_INIT_PRIORITY,
|
||||
|
@ -227,16 +227,16 @@ DEVICE_AND_API_INIT(i2c_eeprom_slave_0, CONFIG_I2C_EEPROM_SLAVE_0_NAME,
|
|||
|
||||
static struct i2c_eeprom_slave_data i2c_eeprom_slave_1_dev_data;
|
||||
|
||||
static u8_t i2c_eeprom_slave_1_buffer[(CONFIG_I2C_EEPROM_SLAVE_1_SIZE * 1024)];
|
||||
static u8_t i2c_eeprom_slave_1_buffer[(EEPROM_SLAVE_1_SIZE * 1024)];
|
||||
|
||||
static const struct i2c_eeprom_slave_config i2c_eeprom_slave_1_cfg = {
|
||||
.controller_dev_name = CONFIG_I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME,
|
||||
.address = CONFIG_I2C_EEPROM_SLAVE_1_ADDRESS,
|
||||
.buffer_size = (CONFIG_I2C_EEPROM_SLAVE_1_SIZE * 1024),
|
||||
.controller_dev_name = EEPROM_SLAVE_1_BUS_NAME,
|
||||
.address = EEPROM_SLAVE_1_BASE_ADDRESS,
|
||||
.buffer_size = (EEPROM_SLAVE_1_SIZE * 1024),
|
||||
.buffer = i2c_eeprom_slave_1_buffer
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(i2c_eeprom_slave_1, CONFIG_I2C_EEPROM_SLAVE_1_NAME,
|
||||
DEVICE_AND_API_INIT(i2c_eeprom_slave_1, EEPROM_SLAVE_1_LABEL,
|
||||
&i2c_eeprom_slave_init,
|
||||
&i2c_eeprom_slave_1_dev_data, &i2c_eeprom_slave_1_cfg,
|
||||
POST_KERNEL, CONFIG_I2C_SLAVE_INIT_PRIORITY,
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright (c) 2018, Nordic Semiconductor
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
---
|
||||
title: Virtual I2C slave eeprom
|
||||
id: i2c,eeprom
|
||||
version: 0.1
|
||||
|
||||
description: >
|
||||
This binding gives a base representation of I2C slave eeprom
|
||||
|
||||
inherits:
|
||||
!include i2c-device.yaml
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
constraint: "i2c,eeprom"
|
||||
size:
|
||||
type: int
|
||||
category: required
|
||||
description: I2C Slave EEPROM Size in KiB
|
||||
generation: define
|
||||
|
||||
...
|
|
@ -1,6 +1,4 @@
|
|||
CONFIG_I2C_STM32_V2=y
|
||||
CONFIG_I2C_STM32_INTERRUPT=y
|
||||
CONFIG_I2C_1=y
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME="I2C_1"
|
||||
CONFIG_I2C_2=y
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME="I2C_2"
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
CONFIG_I2C_STM32_V2=y
|
||||
CONFIG_I2C_STM32_INTERRUPT=y
|
||||
CONFIG_I2C_1=y
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME="I2C_1"
|
||||
CONFIG_I2C_2=y
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME="I2C_2"
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/ {
|
||||
aliases {
|
||||
eeprom-slave-0 = &ep_0;
|
||||
eeprom-slave-1 = &ep_1;
|
||||
};
|
||||
};
|
||||
|
||||
&i2c1 {
|
||||
ep_0: eeprom@54 {
|
||||
compatible = "i2c,eeprom";
|
||||
reg = <0x54>;
|
||||
label = "EEPROM_SLAVE_0";
|
||||
size = <1>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
&i2c2 {
|
||||
ep_1: eeprom@56 {
|
||||
compatible = "i2c,eeprom";
|
||||
reg = <0x56>;
|
||||
label = "EEPROM_SLAVE_1";
|
||||
size = <1>;
|
||||
};
|
||||
};
|
|
@ -137,76 +137,76 @@ void test_eeprom_slave(void)
|
|||
int ret, offset;
|
||||
|
||||
i2c_0 = device_get_binding(
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME);
|
||||
EEPROM_SLAVE_0_BUS_NAME);
|
||||
zassert_not_null(i2c_0, "I2C device %s not found",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME);
|
||||
EEPROM_SLAVE_0_BUS_NAME);
|
||||
|
||||
SYS_LOG_INF("Found I2C Master device %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_CONTROLLER_DEV_NAME);
|
||||
EEPROM_SLAVE_0_BUS_NAME);
|
||||
|
||||
i2c_1 = device_get_binding(
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME);
|
||||
EEPROM_SLAVE_1_BUS_NAME);
|
||||
zassert_not_null(i2c_1, "I2C device %s not found",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME);
|
||||
EEPROM_SLAVE_1_BUS_NAME);
|
||||
|
||||
SYS_LOG_INF("Found I2C Master device %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_CONTROLLER_DEV_NAME);
|
||||
EEPROM_SLAVE_1_BUS_NAME);
|
||||
|
||||
eeprom_0 = device_get_binding(CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
eeprom_0 = device_get_binding(EEPROM_SLAVE_0_LABEL);
|
||||
zassert_not_null(eeprom_0, "EEPROM device %s not found",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
SYS_LOG_INF("Found EEPROM device %s", CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
SYS_LOG_INF("Found EEPROM device %s", EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
eeprom_1 = device_get_binding(CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
eeprom_1 = device_get_binding(EEPROM_SLAVE_1_LABEL);
|
||||
zassert_not_null(eeprom_1, "EEPROM device %s not found",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
EEPROM_SLAVE_1_LABEL);
|
||||
|
||||
SYS_LOG_INF("Found EEPROM device %s", CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
SYS_LOG_INF("Found EEPROM device %s", EEPROM_SLAVE_1_LABEL);
|
||||
|
||||
/* Program dummy bytes */
|
||||
ret = eeprom_slave_program(eeprom_0, eeprom_0_data, TEST_DATA_SIZE);
|
||||
zassert_equal(ret, 0, "Failed to program EEPROM %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
ret = eeprom_slave_program(eeprom_1, eeprom_1_data, TEST_DATA_SIZE);
|
||||
zassert_equal(ret, 0, "Failed to program EEPROM %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
EEPROM_SLAVE_1_LABEL);
|
||||
|
||||
/* Attach EEPROM */
|
||||
ret = i2c_slave_driver_register(eeprom_0);
|
||||
zassert_equal(ret, 0, "Failed to register EEPROM %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
SYS_LOG_INF("EEPROM %s Attached !", CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
SYS_LOG_INF("EEPROM %s Attached !", EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
ret = i2c_slave_driver_register(eeprom_1);
|
||||
zassert_equal(ret, 0, "Failed to register EEPROM %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
EEPROM_SLAVE_1_LABEL);
|
||||
|
||||
SYS_LOG_INF("EEPROM %s Attached !", CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
SYS_LOG_INF("EEPROM %s Attached !", EEPROM_SLAVE_1_LABEL);
|
||||
|
||||
/* Run Tests without bus access conflicts */
|
||||
run_full_read(i2c_0, CONFIG_I2C_EEPROM_SLAVE_1_ADDRESS, eeprom_1_data);
|
||||
run_full_read(i2c_1, CONFIG_I2C_EEPROM_SLAVE_0_ADDRESS, eeprom_0_data);
|
||||
run_full_read(i2c_0, EEPROM_SLAVE_1_BASE_ADDRESS, eeprom_1_data);
|
||||
run_full_read(i2c_1, EEPROM_SLAVE_0_BASE_ADDRESS, eeprom_0_data);
|
||||
|
||||
for (offset = 0 ; offset < TEST_DATA_SIZE-1 ; ++offset) {
|
||||
run_partial_read(i2c_0, CONFIG_I2C_EEPROM_SLAVE_1_ADDRESS,
|
||||
run_partial_read(i2c_0, EEPROM_SLAVE_1_BASE_ADDRESS,
|
||||
eeprom_1_data, offset);
|
||||
}
|
||||
|
||||
for (offset = 0 ; offset < TEST_DATA_SIZE-1 ; ++offset) {
|
||||
run_partial_read(i2c_1, CONFIG_I2C_EEPROM_SLAVE_0_ADDRESS,
|
||||
run_partial_read(i2c_1, EEPROM_SLAVE_0_BASE_ADDRESS,
|
||||
eeprom_0_data, offset);
|
||||
}
|
||||
|
||||
for (offset = 0 ; offset < TEST_DATA_SIZE-1 ; ++offset) {
|
||||
run_program_read(i2c_0, CONFIG_I2C_EEPROM_SLAVE_1_ADDRESS,
|
||||
run_program_read(i2c_0, EEPROM_SLAVE_1_BASE_ADDRESS,
|
||||
offset);
|
||||
}
|
||||
|
||||
for (offset = 0 ; offset < TEST_DATA_SIZE-1 ; ++offset) {
|
||||
run_program_read(i2c_1, CONFIG_I2C_EEPROM_SLAVE_0_ADDRESS,
|
||||
run_program_read(i2c_1, EEPROM_SLAVE_0_BASE_ADDRESS,
|
||||
offset);
|
||||
}
|
||||
|
||||
|
@ -215,17 +215,17 @@ void test_eeprom_slave(void)
|
|||
/* Detach EEPROM */
|
||||
ret = i2c_slave_driver_unregister(eeprom_0);
|
||||
zassert_equal(ret, 0, "Failed to unregister EEPROM %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
SYS_LOG_INF("EEPROM %s Detached !",
|
||||
CONFIG_I2C_EEPROM_SLAVE_0_NAME);
|
||||
EEPROM_SLAVE_0_LABEL);
|
||||
|
||||
ret = i2c_slave_driver_unregister(eeprom_1);
|
||||
zassert_equal(ret, 0, "Failed to unregister EEPROM %s",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
EEPROM_SLAVE_1_LABEL);
|
||||
|
||||
SYS_LOG_INF("EEPROM %s Detached !",
|
||||
CONFIG_I2C_EEPROM_SLAVE_1_NAME);
|
||||
EEPROM_SLAVE_1_LABEL);
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/ {
|
||||
aliases {
|
||||
eeprom-slave-0 = &ep_0;
|
||||
eeprom-slave-1 = &ep_1;
|
||||
};
|
||||
};
|
||||
|
||||
&i2c1 {
|
||||
ep_0: eeprom@54 {
|
||||
compatible = "i2c,eeprom";
|
||||
reg = <0x54>;
|
||||
label = "EEPROM_SLAVE_0";
|
||||
size = <1>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
&i2c2 {
|
||||
ep_1: eeprom@56 {
|
||||
compatible = "i2c,eeprom";
|
||||
reg = <0x56>;
|
||||
label = "EEPROM_SLAVE_1";
|
||||
size = <1>;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue