sound/soc/loongson/loongson_i2s_plat.c
Source file repositories/reference/linux-study-clean/sound/soc/loongson/loongson_i2s_plat.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/loongson/loongson_i2s_plat.c- Extension
.c- Size
- 3494 bytes
- Lines
- 123
- Domain
- Driver Families
- Bucket
- sound/soc
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/dma-mapping.hlinux/module.hlinux/of_dma.hlinux/platform_device.hlinux/pm_runtime.hsound/dmaengine_pcm.hsound/pcm.hsound/pcm_params.hsound/soc.hloongson_i2s.hloongson_dma.h
Detected Declarations
function loongson_i2s_apbdma_configfunction loongson_i2s_plat_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
//
// Loongson I2S controller master mode dirver(platform device)
//
// Copyright (C) 2023-2024 Loongson Technology Corporation Limited
//
// Author: Yingkun Meng <mengyingkun@loongson.cn>
// Binbin Zhou <zhoubinbin@loongson.cn>
#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/module.h>
#include <linux/of_dma.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <sound/dmaengine_pcm.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include "loongson_i2s.h"
#include "loongson_dma.h"
#define LOONGSON_I2S_RX_DMA_OFFSET 21
#define LOONGSON_I2S_TX_DMA_OFFSET 18
#define LOONGSON_DMA0_CONF 0x0
#define LOONGSON_DMA1_CONF 0x1
#define LOONGSON_DMA2_CONF 0x2
#define LOONGSON_DMA3_CONF 0x3
#define LOONGSON_DMA4_CONF 0x4
static int loongson_i2s_apbdma_config(struct platform_device *pdev)
{
int val;
void __iomem *regs;
regs = devm_platform_ioremap_resource(pdev, 1);
if (IS_ERR(regs))
return PTR_ERR(regs);
val = readl(regs);
val |= LOONGSON_DMA2_CONF << LOONGSON_I2S_TX_DMA_OFFSET;
val |= LOONGSON_DMA3_CONF << LOONGSON_I2S_RX_DMA_OFFSET;
writel(val, regs);
return 0;
}
static int loongson_i2s_plat_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct loongson_i2s *i2s;
struct resource *res;
struct clk *i2s_clk;
int ret;
i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL);
if (!i2s)
return -ENOMEM;
ret = loongson_i2s_apbdma_config(pdev);
if (ret)
return ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
i2s->reg_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(i2s->reg_base))
return dev_err_probe(dev, PTR_ERR(i2s->reg_base),
"devm_ioremap_resource failed\n");
i2s->regmap = devm_regmap_init_mmio(dev, i2s->reg_base,
&loongson_i2s_regmap_config);
if (IS_ERR(i2s->regmap))
return dev_err_probe(dev, PTR_ERR(i2s->regmap),
"devm_regmap_init_mmio failed\n");
i2s->playback_dma_data.addr = res->start + LS_I2S_TX_DATA;
i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
i2s->playback_dma_data.maxburst = 4;
i2s->capture_dma_data.addr = res->start + LS_I2S_RX_DATA;
i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
i2s->capture_dma_data.maxburst = 4;
i2s_clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(i2s_clk))
return dev_err_probe(dev, PTR_ERR(i2s_clk), "clock property invalid\n");
i2s->clk_rate = clk_get_rate(i2s_clk);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/dma-mapping.h`, `linux/module.h`, `linux/of_dma.h`, `linux/platform_device.h`, `linux/pm_runtime.h`, `sound/dmaengine_pcm.h`, `sound/pcm.h`.
- Detected declarations: `function loongson_i2s_apbdma_config`, `function loongson_i2s_plat_probe`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.