Skip to content

Common: add patch to support dynamic I2C bus speed configuration - #2787

Open
S-J-Tang wants to merge 1 commit into
facebook:mainfrom
S-J-Tang:common-i2c-driver-20261014
Open

S-J-Tang wants to merge 1 commit into
facebook:mainfrom
S-J-Tang:common-i2c-driver-20261014

Conversation

@S-J-Tang

@S-J-Tang S-J-Tang commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Description

  • Add Nuvoton patch 0035 for the NPCM4xx I2C driver (Zephyr tag v2.6.0.0).
  • Support independent SCL low/high timing for fast mode (400 kHz) and fast-plus mode (1 MHz).
  • Add an i2c speed shell command to change the bus speed at runtime.

Motivation

  • The driver only has one scllt/sclht pair, and it is applied to both 400 kHz and 1 MHz.

Design

  • Add two optional DTS properties, scllt_fp and sclht_fp, for fast-plus mode.
  • i2c_npcm4xx_set_baudrate() selects the timing pair by the requested speed:
    • bus_freq > 400 kHz: scllt_fp / sclht_fp
    • otherwise: scllt / sclht
  • Add shell command i2c speed <device> <freq_hz>, which calls i2c_configure() with the matching speed.
  • Compatibility: 100 kHz and 400 kHz behavior is unchanged. A 1 MHz bus no longer uses scllt/sclht; it uses scllt_fp/sclht_fp, or the computed value if they are not set. All buses that set scllt/sclht in this repo (sb-el, sb-rb) run at 400 kHz, so no existing platform is affected.

Usage

  1. DTS (optional, only needed when 1 MHz requires special timing):

    &i2c1a {
        clock-frequency = <I2C_BITRATE_FAST>;
        scllt = <65>;       /* 400 kHz SCL low time */
        sclht = <60>;       /* 400 kHz SCL high time */
        scllt_fp = <xx>;    /* 1 MHz SCL low time, 5 to 255 */
        sclht_fp = <xx>;    /* 1 MHz SCL high time, 5 to 255 */
    };
    
  2. Shell:

    uart:~$ i2c speed <device> <freq_hz>
    e.g.
    uart:~$ i2c speed I2C_0 100000
    uart:~$ i2c speed I2C_0 400000
    uart:~$ i2c speed I2C_0 1000000
    
    • freq_hz <= 100000 selects standard mode, <= 400000 fast mode, <= 1000000 fast-plus mode.
    • A value above 1000000 is rejected with "Unsupported speed".
  3. Code:

    i2c_configure(dev, I2C_MODE_MASTER | I2C_SPEED_SET(I2C_SPEED_FAST_PLUS));

Test Plan

  • Build code: Pass
  • Switch bus speed with the shell command and measure SCL with a scope:
    • 100 kHz: <measured frequency>
    • 400 kHz: <measured frequency / SCL low / SCL high>
    • 1 MHz: <measured frequency / SCL low / SCL high>

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D125125901. (Because this pull request was imported automatically, there will not be any future comments.)

Summary:
- add patch to support dynamic I2C bus speed configuration
Test Plan:
- Build code:Pass

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant