Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * DaVinci Voice Codec Core Interface for TI platforms
0004  *
0005  * Copyright (C) 2010 Texas Instruments, Inc
0006  *
0007  * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
0008  */
0009 
0010 #include <linux/init.h>
0011 #include <linux/module.h>
0012 #include <linux/device.h>
0013 #include <linux/slab.h>
0014 #include <linux/delay.h>
0015 #include <linux/io.h>
0016 #include <linux/clk.h>
0017 #include <linux/regmap.h>
0018 
0019 #include <sound/pcm.h>
0020 
0021 #include <linux/mfd/davinci_voicecodec.h>
0022 
0023 static const struct regmap_config davinci_vc_regmap = {
0024     .reg_bits = 32,
0025     .val_bits = 32,
0026 };
0027 
0028 static int __init davinci_vc_probe(struct platform_device *pdev)
0029 {
0030     struct davinci_vc *davinci_vc;
0031     struct resource *res;
0032     struct mfd_cell *cell = NULL;
0033     dma_addr_t fifo_base;
0034     int ret;
0035 
0036     davinci_vc = devm_kzalloc(&pdev->dev,
0037                   sizeof(struct davinci_vc), GFP_KERNEL);
0038     if (!davinci_vc)
0039         return -ENOMEM;
0040 
0041     davinci_vc->clk = devm_clk_get(&pdev->dev, NULL);
0042     if (IS_ERR(davinci_vc->clk)) {
0043         dev_dbg(&pdev->dev,
0044                 "could not get the clock for voice codec\n");
0045         return -ENODEV;
0046     }
0047     clk_enable(davinci_vc->clk);
0048 
0049     davinci_vc->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
0050     if (IS_ERR(davinci_vc->base)) {
0051         ret = PTR_ERR(davinci_vc->base);
0052         goto fail;
0053     }
0054     fifo_base = (dma_addr_t)res->start;
0055 
0056     davinci_vc->regmap = devm_regmap_init_mmio(&pdev->dev,
0057                            davinci_vc->base,
0058                            &davinci_vc_regmap);
0059     if (IS_ERR(davinci_vc->regmap)) {
0060         ret = PTR_ERR(davinci_vc->regmap);
0061         goto fail;
0062     }
0063 
0064     res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
0065     if (!res) {
0066         dev_err(&pdev->dev, "no DMA resource\n");
0067         ret = -ENXIO;
0068         goto fail;
0069     }
0070 
0071     davinci_vc->davinci_vcif.dma_tx_channel = res->start;
0072     davinci_vc->davinci_vcif.dma_tx_addr = fifo_base + DAVINCI_VC_WFIFO;
0073 
0074     res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
0075     if (!res) {
0076         dev_err(&pdev->dev, "no DMA resource\n");
0077         ret = -ENXIO;
0078         goto fail;
0079     }
0080 
0081     davinci_vc->davinci_vcif.dma_rx_channel = res->start;
0082     davinci_vc->davinci_vcif.dma_rx_addr = fifo_base + DAVINCI_VC_RFIFO;
0083 
0084     davinci_vc->dev = &pdev->dev;
0085     davinci_vc->pdev = pdev;
0086 
0087     /* Voice codec interface client */
0088     cell = &davinci_vc->cells[DAVINCI_VC_VCIF_CELL];
0089     cell->name = "davinci-vcif";
0090     cell->platform_data = davinci_vc;
0091     cell->pdata_size = sizeof(*davinci_vc);
0092 
0093     /* Voice codec CQ93VC client */
0094     cell = &davinci_vc->cells[DAVINCI_VC_CQ93VC_CELL];
0095     cell->name = "cq93vc-codec";
0096     cell->platform_data = davinci_vc;
0097     cell->pdata_size = sizeof(*davinci_vc);
0098 
0099     ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells,
0100                   DAVINCI_VC_CELLS, NULL, 0, NULL);
0101     if (ret != 0) {
0102         dev_err(&pdev->dev, "fail to register client devices\n");
0103         goto fail;
0104     }
0105 
0106     return 0;
0107 
0108 fail:
0109     clk_disable(davinci_vc->clk);
0110 
0111     return ret;
0112 }
0113 
0114 static int davinci_vc_remove(struct platform_device *pdev)
0115 {
0116     struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
0117 
0118     mfd_remove_devices(&pdev->dev);
0119 
0120     clk_disable(davinci_vc->clk);
0121 
0122     return 0;
0123 }
0124 
0125 static struct platform_driver davinci_vc_driver = {
0126     .driver = {
0127         .name = "davinci_voicecodec",
0128     },
0129     .remove = davinci_vc_remove,
0130 };
0131 
0132 module_platform_driver_probe(davinci_vc_driver, davinci_vc_probe);
0133 
0134 MODULE_AUTHOR("Miguel Aguilar");
0135 MODULE_DESCRIPTION("Texas Instruments DaVinci Voice Codec Core Interface");
0136 MODULE_LICENSE("GPL");