| // SPDX-License-Identifier: GPL-2.0 |
| /* |
| * only test for VAD_toddr to SRAM |
| * |
| * Copyright (C) 2019 Amlogic,inc |
| * |
| */ |
| |
| #include <linux/of.h> |
| #include <linux/io.h> |
| #include <linux/of_address.h> |
| #include <linux/platform_device.h> |
| #include <linux/debugfs.h> |
| #include <linux/regmap.h> |
| #include <linux/module.h> |
| #include <sound/memalloc.h> |
| |
| #define DEV_NAME "aud_sram" |
| |
| void __iomem *aud_sram_iomap; |
| struct resource *aud_sram_res; |
| |
| void aud_buffer_force2sram(struct snd_dma_buffer *buf) |
| { |
| buf->area = (unsigned char *)aud_sram_res->start; |
| buf->bytes = resource_size(aud_sram_res); |
| buf->addr = aud_sram_res->start; |
| } |
| |
| static int aud_sram_iomap_probe(struct platform_device *pdev) |
| { |
| struct device *dev = &pdev->dev; |
| struct device_node *node = dev->of_node; |
| struct resource *res; |
| void __iomem *regs; |
| struct regmap *map; |
| struct regmap_config regmap_cfg = { |
| .reg_bits = 32, |
| .val_bits = 32, |
| .reg_stride = 4, |
| }; |
| |
| res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| regs = devm_ioremap_resource(dev, res); |
| if (IS_ERR(regs)) |
| return PTR_ERR(regs); |
| |
| aud_sram_res = res; |
| aud_sram_iomap = |
| ioremap_nocache(res->start, resource_size(res)); |
| pr_info("%s reg:%x, size:%x\n", |
| __func__, (u32)res->start, (u32)resource_size(res)); |
| |
| regmap_cfg.max_register = resource_size(res) - 4; |
| regmap_cfg.name = |
| devm_kasprintf(dev, GFP_KERNEL, "%s-%s", node->name, "sram"); |
| if (!regmap_cfg.name) |
| return -ENOMEM; |
| |
| map = devm_regmap_init_mmio(dev, regs, ®map_cfg); |
| if (IS_ERR(map)) { |
| dev_err(dev, "failed to init regmap: %ld\n", |
| PTR_ERR(map)); |
| return PTR_ERR(map); |
| } |
| |
| return 0; |
| } |
| |
| static const struct of_device_id aud_sram_iomap_dt_match[] = { |
| { .compatible = "amlogic, audio-sram" }, |
| {}, |
| }; |
| |
| static struct platform_driver aud_sram_iomap_platform_driver = { |
| .driver = { |
| .owner = THIS_MODULE, |
| .name = DEV_NAME, |
| .of_match_table = aud_sram_iomap_dt_match, |
| }, |
| .probe = aud_sram_iomap_probe, |
| }; |
| module_platform_driver(aud_sram_iomap_platform_driver); |
| |
| MODULE_AUTHOR("AMLogic, Inc."); |
| MODULE_DESCRIPTION("Amlogic Ram driver"); |
| MODULE_LICENSE("GPL"); |
| MODULE_ALIAS("platform:" DRV_NAME); |