Yocto enable i2c and pwm

I am very new to yocto&device tree world. I’m really having trouble understanding and implementing some concepts.
I use following layers. When i update the MACHINE to beaglebone. it is working as expected. I can use my beaglebone black.

 .../meta-arm/meta-arm-toolchain \
 .../meta-arm/meta-arm \
 .../meta-ti/meta-ti-bsp \

Now i want to enable pwm and i2c. I dont know anything about how to do that. I also want to write a driver to control my i2c chip. Also i will connect a servo motor to my pwm pin so i want to write a driver for it as well.

Considering that I am using yocto, how can I access the dts file and what should I write there to enable pwm and i2c.(Should i make some pinmux configuration also?)

How should I write the driver after activating PWM and i2c? Can you provide a tutorial for this?


You have pulled the arm and ti layers, but have you created your own layer yet? i.e. basedir/meta-your-layer/?
If so, one way to customize the device tree is to create your own .dtsi file and deploy it in a kernel recipe using bbappend.
An example might be to create a kernel recipe in your layer, say
mkdir -p /meta-your-layer/recipes-kernel/linux-yocto/files/
cd to your recipe dir
cd /meta-your-layer/recipes-kernel/linux-yocto/
Put your custom device tree .dtsi file in the “files” subdir. For example
vi ./files/am335x-boneblack-my-stuff.dtsi

&am33xx_pinmux {
                                                                                /* I2C-1: My i2c and muxing it for my needs */
        my_i2c1_pins: my_i2c1_pins {
                pinctrl-single,pins = <                                         /* My device: i2c addr 0x22, 0x23 */
                        AM33XX_IOPAD(0x95c, PIN_INPUT | MUX_MODE2)              /* (A16)/(Pin 50)  spi0_cs0.I2C1_SCL   */
                        AM33XX_IOPAD(0x958, PIN_INPUT | MUX_MODE2)              /* (B16)/(Pin 49)  spi0_d1.I2C1_SDA    */

&i2c1 {                                                                         /* My i2c device 0x22, 0x23 */
        status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <&my_i2c1_pins>;

        clock-frequency = <100000>;

Then create your kernel bbappend file,
vi linux-yocto_%.bbappend (or if you use a specific kernel, say 5.15: linux-yocto_5.15%.bbappend)

PR = "r0"

FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

SRC_URI:append = " \
        file://am335x-boneblack-my-stuff.dtsi \

do_configure:append() {
        cp ${WORKDIR}/am335x-boneblack-my-stuff.dtsi ${B}/source/arch/${ARCH}/boot/dts
        echo '#include "am335x-boneblack-my-stuff.dtsi"' >> ${B}/source/arch/${ARCH}/boot/dts/am335x-boneblack.dts
        echo '#include "am335x-boneblack-my-stuff.dtsi"' >> ${B}/source/arch/${ARCH}/boot/dts/am335x-bonegreen.dts

These files are just examples. I have no idea how you need to mux your i2c device, or if you need to disable current pin assignments in the ocp node to make room for your device, or…