blob: e5c8bc998eb4e4fb558a2437408f7d491077c42f [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Miguel Aguilarca263082010-03-11 09:32:21 -06002/*
3 * DaVinci Voice Codec Core Interface for TI platforms
4 *
5 * Copyright (C) 2010 Texas Instruments, Inc
6 *
7 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
Miguel Aguilarca263082010-03-11 09:32:21 -06008 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/device.h>
Tejun Heo8c0d8fa2010-03-30 02:52:40 +090013#include <linux/slab.h>
Miguel Aguilarca263082010-03-11 09:32:21 -060014#include <linux/delay.h>
15#include <linux/io.h>
16#include <linux/clk.h>
Mark Brown921a2c82013-08-31 14:08:56 +010017#include <linux/regmap.h>
Miguel Aguilarca263082010-03-11 09:32:21 -060018
19#include <sound/pcm.h>
20
21#include <linux/mfd/davinci_voicecodec.h>
22
Krzysztof Kozlowskib8d12ea2015-01-05 10:01:23 +010023static const struct regmap_config davinci_vc_regmap = {
Mark Brown921a2c82013-08-31 14:08:56 +010024 .reg_bits = 32,
25 .val_bits = 32,
26};
27
Miguel Aguilarca263082010-03-11 09:32:21 -060028static int __init davinci_vc_probe(struct platform_device *pdev)
29{
30 struct davinci_vc *davinci_vc;
Sachin Kamatc8eaed42013-06-18 15:35:40 +053031 struct resource *res;
Miguel Aguilarca263082010-03-11 09:32:21 -060032 struct mfd_cell *cell = NULL;
Arnd Bergmannb5e29aa2019-07-22 13:47:13 +020033 dma_addr_t fifo_base;
Miguel Aguilarca263082010-03-11 09:32:21 -060034 int ret;
35
Lee Jones099053a2013-05-23 16:25:11 +010036 davinci_vc = devm_kzalloc(&pdev->dev,
37 sizeof(struct davinci_vc), GFP_KERNEL);
Lee Jones9fb41162015-10-28 16:54:29 +000038 if (!davinci_vc)
Miguel Aguilarca263082010-03-11 09:32:21 -060039 return -ENOMEM;
Miguel Aguilarca263082010-03-11 09:32:21 -060040
Sachin Kamatc8eaed42013-06-18 15:35:40 +053041 davinci_vc->clk = devm_clk_get(&pdev->dev, NULL);
Miguel Aguilarca263082010-03-11 09:32:21 -060042 if (IS_ERR(davinci_vc->clk)) {
43 dev_dbg(&pdev->dev,
44 "could not get the clock for voice codec\n");
Lee Jones099053a2013-05-23 16:25:11 +010045 return -ENODEV;
Miguel Aguilarca263082010-03-11 09:32:21 -060046 }
47 clk_enable(davinci_vc->clk);
48
49 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Miguel Aguilarca263082010-03-11 09:32:21 -060050
Arnd Bergmannb5e29aa2019-07-22 13:47:13 +020051 fifo_base = (dma_addr_t)res->start;
Sachin Kamatc8eaed42013-06-18 15:35:40 +053052 davinci_vc->base = devm_ioremap_resource(&pdev->dev, res);
53 if (IS_ERR(davinci_vc->base)) {
54 ret = PTR_ERR(davinci_vc->base);
55 goto fail;
Miguel Aguilarca263082010-03-11 09:32:21 -060056 }
57
Mark Brown921a2c82013-08-31 14:08:56 +010058 davinci_vc->regmap = devm_regmap_init_mmio(&pdev->dev,
59 davinci_vc->base,
60 &davinci_vc_regmap);
61 if (IS_ERR(davinci_vc->regmap)) {
62 ret = PTR_ERR(davinci_vc->regmap);
63 goto fail;
64 }
65
Miguel Aguilarca263082010-03-11 09:32:21 -060066 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
67 if (!res) {
68 dev_err(&pdev->dev, "no DMA resource\n");
Julia Lawalle2bde7872010-06-01 16:34:38 +020069 ret = -ENXIO;
Sachin Kamatc8eaed42013-06-18 15:35:40 +053070 goto fail;
Miguel Aguilarca263082010-03-11 09:32:21 -060071 }
72
73 davinci_vc->davinci_vcif.dma_tx_channel = res->start;
Arnd Bergmannb5e29aa2019-07-22 13:47:13 +020074 davinci_vc->davinci_vcif.dma_tx_addr = fifo_base + DAVINCI_VC_WFIFO;
Miguel Aguilarca263082010-03-11 09:32:21 -060075
76 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
77 if (!res) {
78 dev_err(&pdev->dev, "no DMA resource\n");
Julia Lawalle2bde7872010-06-01 16:34:38 +020079 ret = -ENXIO;
Sachin Kamatc8eaed42013-06-18 15:35:40 +053080 goto fail;
Miguel Aguilarca263082010-03-11 09:32:21 -060081 }
82
83 davinci_vc->davinci_vcif.dma_rx_channel = res->start;
Arnd Bergmannb5e29aa2019-07-22 13:47:13 +020084 davinci_vc->davinci_vcif.dma_rx_addr = fifo_base + DAVINCI_VC_RFIFO;
Miguel Aguilarca263082010-03-11 09:32:21 -060085
86 davinci_vc->dev = &pdev->dev;
87 davinci_vc->pdev = pdev;
88
89 /* Voice codec interface client */
90 cell = &davinci_vc->cells[DAVINCI_VC_VCIF_CELL];
Manjunathappa, Prakash73ee6522011-01-27 18:58:36 +053091 cell->name = "davinci-vcif";
Samuel Ortizcb5811c2011-04-06 16:39:45 +020092 cell->platform_data = davinci_vc;
93 cell->pdata_size = sizeof(*davinci_vc);
Miguel Aguilarca263082010-03-11 09:32:21 -060094
95 /* Voice codec CQ93VC client */
96 cell = &davinci_vc->cells[DAVINCI_VC_CQ93VC_CELL];
Manjunathappa, Prakash73ee6522011-01-27 18:58:36 +053097 cell->name = "cq93vc-codec";
Samuel Ortizcb5811c2011-04-06 16:39:45 +020098 cell->platform_data = davinci_vc;
99 cell->pdata_size = sizeof(*davinci_vc);
Miguel Aguilarca263082010-03-11 09:32:21 -0600100
101 ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells,
Mark Brown0848c942012-09-11 15:16:36 +0800102 DAVINCI_VC_CELLS, NULL, 0, NULL);
Miguel Aguilarca263082010-03-11 09:32:21 -0600103 if (ret != 0) {
104 dev_err(&pdev->dev, "fail to register client devices\n");
Sachin Kamatc8eaed42013-06-18 15:35:40 +0530105 goto fail;
Miguel Aguilarca263082010-03-11 09:32:21 -0600106 }
107
108 return 0;
109
Sachin Kamatc8eaed42013-06-18 15:35:40 +0530110fail:
Miguel Aguilarca263082010-03-11 09:32:21 -0600111 clk_disable(davinci_vc->clk);
Miguel Aguilarca263082010-03-11 09:32:21 -0600112
113 return ret;
114}
115
Bill Pemberton4740f732012-11-19 13:26:01 -0500116static int davinci_vc_remove(struct platform_device *pdev)
Miguel Aguilarca263082010-03-11 09:32:21 -0600117{
118 struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
119
120 mfd_remove_devices(&pdev->dev);
121
Miguel Aguilarca263082010-03-11 09:32:21 -0600122 clk_disable(davinci_vc->clk);
Miguel Aguilarca263082010-03-11 09:32:21 -0600123
Miguel Aguilarca263082010-03-11 09:32:21 -0600124 return 0;
125}
126
127static struct platform_driver davinci_vc_driver = {
128 .driver = {
129 .name = "davinci_voicecodec",
Miguel Aguilarca263082010-03-11 09:32:21 -0600130 },
Bill Pemberton84449212012-11-19 13:20:24 -0500131 .remove = davinci_vc_remove,
Miguel Aguilarca263082010-03-11 09:32:21 -0600132};
133
Jingoo Han3de764d2013-03-05 13:48:28 +0900134module_platform_driver_probe(davinci_vc_driver, davinci_vc_probe);
Miguel Aguilarca263082010-03-11 09:32:21 -0600135
136MODULE_AUTHOR("Miguel Aguilar");
137MODULE_DESCRIPTION("Texas Instruments DaVinci Voice Codec Core Interface");
138MODULE_LICENSE("GPL");