diff --git a/samples/drivers/smbus/CMakeLists.txt b/samples/drivers/smbus/CMakeLists.txt new file mode 100644 index 00000000000..5fa4d8718cb --- /dev/null +++ b/samples/drivers/smbus/CMakeLists.txt @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +if(BOARD STREQUAL qemu_x86_64) + LIST(APPEND QEMU_EXTRA_FLAGS -machine q35) +endif() + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(smbus) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/drivers/smbus/README.rst b/samples/drivers/smbus/README.rst new file mode 100644 index 00000000000..e1f8fec8db9 --- /dev/null +++ b/samples/drivers/smbus/README.rst @@ -0,0 +1,71 @@ +.. _samples_smbus_shell: + +SMBus Shell Sample +################## + +Overview +******** + +This is a simple SMBus shell sample that allows arbitrary boards with SMBus +driver supported exploring the SMBus communication with peripheral devices. + +Building and Running +******************** + +This project can be built and executed on as follows: + +.. zephyr-app-commands:: + :zephyr-app: zephyr/samples/drivers/smbus + :host-os: unix + :board: qemu_x86_64 + :goals: run + :compact: + +Sample Output +============= + +Output from console when application started:: + + *** Booting Zephyr OS build zephyr-v3.2.0-804-gfedd72615e82 *** + Start SMBUS shell sample qemu_x86_64 + uart:~$ + +List avaibalbe SMBus shell commands with:: + + uart:~$ smbus + smbus - smbus commands + Subcommands: + quick :SMBus Quick command + Usage: quick + scan :Scan SMBus peripheral devices command + Usage: scan + byte_read :SMBus: byte read command + Usage: byte_read + byte_write :SMBus: byte write command + Usage: byte_write + byte_data_read :SMBus: byte data read command + Usage: byte_data_read + byte_data_write :SMBus: byte data write command + Usage: byte_data_write + word_data_read :SMBus: word data read command + Usage: word_data_read + word_data_write :SMBus: word data write command + Usage: word_data_write + block_write :SMBus: Block Write command + Usage: block_write [, ...] + block_read :SMBus: Block Read command + Usage: block_read + +Scan for available SMBus devices with command:: + + uart:~$ smbus scan smbus@fb00 + 0 1 2 3 4 5 6 7 8 9 a b c d e f + 00: -- -- -- -- -- -- -- -- -- -- -- -- + 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- + 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 70: -- -- -- -- -- -- -- -- + 8 devices found on smbus@fb00 diff --git a/samples/drivers/smbus/boards/qemu_x86_64.conf b/samples/drivers/smbus/boards/qemu_x86_64.conf new file mode 100644 index 00000000000..844c7c51a6f --- /dev/null +++ b/samples/drivers/smbus/boards/qemu_x86_64.conf @@ -0,0 +1,3 @@ +CONFIG_DYNAMIC_INTERRUPTS=y + +CONFIG_PCIE=y diff --git a/samples/drivers/smbus/prj.conf b/samples/drivers/smbus/prj.conf new file mode 100644 index 00000000000..a02baae7ec9 --- /dev/null +++ b/samples/drivers/smbus/prj.conf @@ -0,0 +1,10 @@ +CONFIG_SMBUS=y +CONFIG_SMBUS_INTEL_PCH=y +CONFIG_SMBUS_LOG_LEVEL_DBG=y +CONFIG_USERSPACE=y +CONFIG_SHELL=y +CONFIG_LOG=y + +CONFIG_EEPROM=y +CONFIG_EEPROM_EMULATOR=n +CONFIG_EEPROM_SIMULATOR=n diff --git a/samples/drivers/smbus/qemu_x86_64.overlay b/samples/drivers/smbus/qemu_x86_64.overlay new file mode 100644 index 00000000000..408695b795f --- /dev/null +++ b/samples/drivers/smbus/qemu_x86_64.overlay @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&smbus0 { + eeprom2: smbus_eeprom@50 { + compatible = "jedec,smbus-eeprom"; + reg = <0x50>; + size = <0x100>; + + status = "okay"; + }; +}; diff --git a/samples/drivers/smbus/sample.yaml b/samples/drivers/smbus/sample.yaml new file mode 100644 index 00000000000..b129ddae415 --- /dev/null +++ b/samples/drivers/smbus/sample.yaml @@ -0,0 +1,13 @@ +sample: + description: SMBus sample + name: smbus sample +common: + platform_allow: qemu_x86_64 ehl_crb rpl_crb + harness: console + harness_config: + type: one_line + regex: + - "Start SMBUS shell sample" +tests: + sample.drivers.smbus.shell: + tags: smbus diff --git a/samples/drivers/smbus/src/main.c b/samples/drivers/smbus/src/main.c new file mode 100644 index 00000000000..8a8f48a4d13 --- /dev/null +++ b/samples/drivers/smbus/src/main.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +void main(void) +{ + printk("Start SMBUS shell sample %s\n", CONFIG_BOARD); +}