Skip to content

codec: phytium: update phytium codec driver support to 6.6.0.4#1668

Open
Chengyulai wants to merge 5 commits intodeepin-community:linux-6.6.yfrom
Chengyulai:codec-6.6.y
Open

codec: phytium: update phytium codec driver support to 6.6.0.4#1668
Chengyulai wants to merge 5 commits intodeepin-community:linux-6.6.yfrom
Chengyulai:codec-6.6.y

Conversation

@Chengyulai
Copy link
Copy Markdown

@Chengyulai Chengyulai commented May 7, 2026

This patches updates the support for phytium codec driver.
1.Use different clocks for playback and recording
2.Add Kconfig option dependency
3.Add controller status code
4.initialize share memory and channels
5.Fix probe bug without judgment of return value

Summary by Sourcery

Update Phytium and ES8388 codec drivers for improved status handling, initialization, and robustness.

New Features:

  • Introduce explicit codec status/error codes for Phytium codec driver.

Bug Fixes:

  • Ensure Phytium shared memory command structures are cleared before codec lifecycle and DAI operations.
  • Fix Phytium codec channel configuration by caching the channel count and applying it consistently to playback and capture paths.
  • Handle failures from ES8388 register writes during component probe to avoid incomplete initialization.

Enhancements:

  • Refine Phytium codec status logging messages for clearer hardware and initialization error reporting.
  • Adjust ES8388 default control register values and bump driver version to 1.0.1 for updated behavior.

Chengyulai added 5 commits May 7, 2026 17:41
Recording immediately after playing music will result in the
latter part of the recording have no sound. the reason as follows:

Playback and recording share the same clock. After playback stops,
the audio framework will shutdown clock after 5-second. if recording
within this 5-second period, the recording clock will be turned off.

Therefore, the CONTROL1 register should be modified so that
playback and recording use different clocks.

Signed-off-by: Cheng Yulai <chengyulai1490@phytium.com.cn>
Signed-off-by: Zhou Zheng <zhouzheng2069@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
This driver is exclusively for the PHYTIUM platform and is not
compatible with other SoCs. This restriction avoids compiling
this driver on other platforms.

Signed-off-by: Cheng Yulai <chengyulai1490@phytium.com.cn>
Signed-off-by: Zhou Zheng <zhouzheng2069@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Add a controller status code for no initialzation error.

Signed-off-by: Cheng Yulai <chengyulai1490@phytium.com.cn>
Signed-off-by: Zhou Zheng <zhouzheng2069@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Initialize channels and share memory before sending
command to prevent unknown errors.

Signed-off-by: Cheng Yulai <chengyulai1490@phytium.com.cn>
Signed-off-by: Zhou Zheng <zhouzheng2069@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
When executing the probe interface, the driver shound return actual
error code instead of zero to avoid creating sound card successfully
when hardware is not present.

Signed-off-by: Dai Jingtao <daijingtao1503@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's Guide

Updates the Phytium codec and ES8388 drivers to use structured status codes, properly initialize shared memory and channel counts, and handle probe/control errors, along with a minor version bump and Kconfig updates.

Sequence diagram for phytium codec probe and command initialization

sequenceDiagram
    participant Kernel
    participant snd_soc_component as snd_soc_component
    participant phytium_codec as phytium_codec
    participant phytcodec_cmd as phytcodec_cmd

    Kernel->>snd_soc_component: phyt_probe()
    snd_soc_component->>phytium_codec: snd_soc_component_get_drvdata(component)
    activate phytium_codec
    phytium_codec->>phytcodec_cmd: msg = sharemem_base
    activate phytcodec_cmd
    phytium_codec->>phytcodec_cmd: memset(msg, 0, sizeof(struct_phytcodec_cmd))
    deactivate phytcodec_cmd
    phytium_codec->>phytium_codec: phyt_set_cmd(priv, PHYTCODEC_MSG_CMD_SET_PROBE)
    deactivate phytium_codec
Loading

Sequence diagram for phytium codec startup with shared memory reset

sequenceDiagram
    participant App
    participant ALSA
    participant snd_soc_dai as snd_soc_dai
    participant phytium_codec as phytium_codec
    participant phytcodec_cmd as phytcodec_cmd

    App->>ALSA: open_pcm_substream()
    ALSA->>snd_soc_dai: phyt_startup(substream, dai)
    snd_soc_dai->>phytium_codec: snd_soc_component_get_drvdata(component)
    activate phytium_codec
    phytium_codec->>phytcodec_cmd: msg = sharemem_base
    activate phytcodec_cmd
    phytium_codec->>phytcodec_cmd: memset(msg, 0, sizeof(struct_phytcodec_cmd))
    deactivate phytcodec_cmd
    alt playback_stream
        phytium_codec->>phytium_codec: phyt_set_cmd(priv, PHYTCODEC_MSG_CMD_SET_STARTUP)
    else capture_stream
        phytium_codec->>phytium_codec: phyt_set_cmd(priv, PHYTCODEC_MSG_CMD_SET_STARTUP_REC)
    end
    deactivate phytium_codec
Loading

Class diagram for updated phytium codec status and initialization

classDiagram
    class phytium_codec {
        void~void*~ sharemem_base
        unsigned_int channels
        void~void*~ regfile_base
        void~struct_device*~ dev
        int phyt_set_cmd(priv, cmd)
        int phyt_pm_cmd(priv, cmd)
    }

    class phytcodec_cmd {
        uint8_t addr
        uint8_t reg
        uint8_t value
        uint8_t reserved
    }

    class phytcodec_status {
        <<enum>>
        ERR_CODEC_SUCCESS
        ERR_CODEC_BUS_BUSY
        ERR_CODEC_DEV_BUSY
        ERR_CODEC_RW_ERROR
        ERR_CODEC_NODEV
        ERR_CODEC_NO_INIT
    }

    class snd_soc_component {
        phytium_codec* drvdata
    }

    class snd_soc_dai_driver {
        snd_soc_pcm_stream playback
        snd_soc_pcm_stream capture
    }

    class snd_soc_pcm_stream {
        unsigned_int channels_max
    }

    phytium_codec --> phytcodec_cmd : sharemem_base
    phytium_codec --> phytcodec_status : uses
    snd_soc_component --> phytium_codec : get_drvdata
    snd_soc_dai_driver --> snd_soc_pcm_stream : has
    phytium_codec --> snd_soc_dai_driver : configures_channels
Loading

Flow diagram for es8388 component probe with error handling

flowchart TD
    A["es8388_component_probe"] --> B["write ES8388_ADCPOWER 0xf0"]
    B --> C{ret != 0?}
    C -- yes --> D["return ret"]
    C -- no --> E["write ES8388_CONTROL1 0x20"]
    E --> F["write ES8388_DACCONTROL21 0x80"]
    F --> G["write ES8388_ADCCONTROL10 0xda"]
    G --> H["return 0"]
Loading

File-Level Changes

Change Details Files
Introduce explicit codec status codes and use them in status reporting
  • Added a phytcodec_status enum defining named status codes for codec operations
  • Replaced hard-coded numeric cases in the codec status switch with the new enum constants and refined log messages
sound/soc/codecs/phytium-codec-v2.h
sound/soc/codecs/phytium-codec-v2.c
Ensure shared memory command structures are zeroed before use across lifecycle events
  • In component probe/remove, suspend/resume, startup/shutdown, and DAI format setup paths, obtain the shared-memory command struct from priv->sharemem_base and memset it to zero before issuing codec commands
  • In the debug sysfs handler, clear the shared-memory command area before issuing the dump-all-registers command
sound/soc/codecs/phytium-codec-v2.c
Track codec channel count in the driver struct and use it for both playback and capture
  • Store the channel count returned by phyt_get_channels(priv) into priv->channels
  • Set both playback and capture channels_max from priv->channels instead of directly from phyt_get_channels
sound/soc/codecs/phytium-codec-v2.c
Improve ES8388 component probe robustness and adjust default control settings
  • Bumped ES8388_V1_VERSION from 1.0.0 to 1.0.1
  • Changed es8388_component_probe to check and propagate the return value of the initial register write to ES8388_ADCPOWER
  • Adjusted the default ES8388_CONTROL1 register value from 0x30 to 0x20 to match the new driver behavior
sound/soc/codecs/es8388.c
Add/update Kconfig options for Phytium codec support
  • Updated sound/soc/codecs Kconfig to reflect new/adjusted dependencies for the Phytium codec driver (exact options not shown in the diff snippet)
sound/soc/codecs/Kconfig

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign opsiff for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Copy Markdown

Hi @Chengyulai. Thanks for your PR. 😃

@deepin-ci-robot
Copy link
Copy Markdown

Hi @Chengyulai. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The repeated memset(priv->sharemem_base, 0, sizeof(struct phytcodec_cmd)) patterns across probe/remove/PM/DAI/debug paths could be factored into a small helper (e.g. phyt_clear_cmd(priv)) to avoid duplication and keep any future changes to shared memory initialization centralized.
  • ERR_CODEC_BUS_BUSY is added to enum phytcodec_status but not used in phyt_codec_show_status() or elsewhere; either handle this status explicitly or drop it to avoid confusion about unimplemented error reporting.
  • In es8388_component_probe() you now check the return value of the first snd_soc_component_write() but not the subsequent writes; consider handling or at least explicitly ignoring errors for the later writes to keep error handling consistent and intentional.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The repeated `memset(priv->sharemem_base, 0, sizeof(struct phytcodec_cmd))` patterns across probe/remove/PM/DAI/debug paths could be factored into a small helper (e.g. `phyt_clear_cmd(priv)`) to avoid duplication and keep any future changes to shared memory initialization centralized.
- `ERR_CODEC_BUS_BUSY` is added to `enum phytcodec_status` but not used in `phyt_codec_show_status()` or elsewhere; either handle this status explicitly or drop it to avoid confusion about unimplemented error reporting.
- In `es8388_component_probe()` you now check the return value of the first `snd_soc_component_write()` but not the subsequent writes; consider handling or at least explicitly ignoring errors for the later writes to keep error handling consistent and intentional.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Phytium Codec V2 and ES8388 ASoC codec drivers to improve controller status handling, shared-memory initialization behavior, and probe robustness, along with a Kconfig dependency change.

Changes:

  • Add controller/codec status codes and improve status logging paths in the Phytium Codec V2 driver.
  • Clear the shared-memory command structure at additional lifecycle/DAI entry points; cache and reuse detected channel count.
  • Update ES8388 driver version/default init values and begin checking probe-time register write failures.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.

File Description
sound/soc/codecs/phytium-codec-v2.h Adds new codec/controller status enum.
sound/soc/codecs/phytium-codec-v2.c Adds shared-memory clearing at more entry points; updates status reporting; caches channel count.
sound/soc/codecs/Kconfig Adds an architecture dependency for the Phytium Codec V2 driver.
sound/soc/codecs/es8388.c Bumps version and adds partial error handling for probe-time register writes.
Comments suppressed due to low confidence (1)

sound/soc/codecs/phytium-codec-v2.c:121

  • ERR_CODEC_BUS_BUSY was added to the status enum but isn’t handled here, so a bus-busy condition will currently be logged as an "unknown error". Add an explicit switch case for this status (and a clear message) so status reporting remains accurate.
static void phyt_codec_show_status(uint8_t status)
{
	switch (status) {
	case ERR_CODEC_SUCCESS:
		pr_err("success\n");
		break;
	case ERR_CODEC_DEV_BUSY:
		pr_err("device busy\n");
		break;
	case ERR_CODEC_RW_ERROR:
		pr_err("read/write error\n");
		break;
	case ERR_CODEC_NODEV:
		pr_err("no hw device\n");
		break;
	case ERR_CODEC_NO_INIT:
		pr_err("no init\n");
		break;
	default:
		pr_err("unknown error: %d\n", status);
		break;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +99 to +104
ERR_CODEC_SUCCESS = 0,
ERR_CODEC_BUS_BUSY,
ERR_CODEC_DEV_BUSY,
ERR_CODEC_RW_ERROR,
ERR_CODEC_NODEV, //HW
ERR_CODEC_NO_INIT, //SW
Comment on lines 328 to 334
static int phyt_probe(struct snd_soc_component *component)
{
struct phytium_codec *priv = snd_soc_component_get_drvdata(component);
struct phytcodec_cmd *msg = priv->sharemem_base;

memset(msg, 0, sizeof(struct phytcodec_cmd));

Comment on lines 338 to 344
static void phyt_remove(struct snd_soc_component *component)
{
struct phytium_codec *priv = snd_soc_component_get_drvdata(component);
struct phytcodec_cmd *msg = priv->sharemem_base;

memset(msg, 0, sizeof(struct phytcodec_cmd));

Comment on lines 348 to 354
static int phyt_suspend(struct snd_soc_component *component)
{
struct phytium_codec *priv = snd_soc_component_get_drvdata(component);
struct phytcodec_cmd *msg = priv->sharemem_base;

memset(msg, 0, sizeof(struct phytcodec_cmd));

Comment on lines 358 to 364
static int phyt_resume(struct snd_soc_component *component)
{
struct phytium_codec *priv = snd_soc_component_get_drvdata(component);
struct phytcodec_cmd *msg = priv->sharemem_base;

memset(msg, 0, sizeof(struct phytcodec_cmd));

Comment on lines 455 to 464
static void phyt_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
int ret;
struct snd_soc_component *component = dai->component;
struct phytium_codec *priv = snd_soc_component_get_drvdata(component);
struct phytcodec_cmd *msg = priv->sharemem_base;

memset(msg, 0, sizeof(struct phytcodec_cmd));

Comment on lines +516 to +518
struct phytcodec_cmd *msg = priv->sharemem_base;

memset(msg, 0, sizeof(struct phytcodec_cmd));
dev_err(dev, "dump command requires one argument\n");
goto error;
}
memset(priv->sharemem_base, 0, sizeof(struct phytcodec_cmd));
Comment thread sound/soc/codecs/Kconfig

config SND_SOC_PHYTIUM_CODEC_V2
tristate "Phytium Codec V2 driver"
depends on ARCH_PHYTIUM
Comment thread sound/soc/codecs/es8388.c
Comment on lines 721 to 732
static int es8388_component_probe(struct snd_soc_component *component)
{
snd_soc_component_write(component, ES8388_ADCPOWER, 0xf0);
snd_soc_component_write(component, ES8388_CONTROL1, 0x30);
int ret = 0;

ret = snd_soc_component_write(component, ES8388_ADCPOWER, 0xf0);
if (ret)
return ret;

snd_soc_component_write(component, ES8388_CONTROL1, 0x20);
snd_soc_component_write(component, ES8388_DACCONTROL21, 0x80);
snd_soc_component_write(component, ES8388_ADCCONTROL10, 0xda);

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants