Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 2 | /* |
| 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 Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/device.h> |
Tejun Heo | 8c0d8fa | 2010-03-30 02:52:40 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/clk.h> |
Mark Brown | 921a2c8 | 2013-08-31 14:08:56 +0100 | [diff] [blame] | 17 | #include <linux/regmap.h> |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 18 | |
| 19 | #include <sound/pcm.h> |
| 20 | |
| 21 | #include <linux/mfd/davinci_voicecodec.h> |
| 22 | |
Krzysztof Kozlowski | b8d12ea | 2015-01-05 10:01:23 +0100 | [diff] [blame] | 23 | static const struct regmap_config davinci_vc_regmap = { |
Mark Brown | 921a2c8 | 2013-08-31 14:08:56 +0100 | [diff] [blame] | 24 | .reg_bits = 32, |
| 25 | .val_bits = 32, |
| 26 | }; |
| 27 | |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 28 | static int __init davinci_vc_probe(struct platform_device *pdev) |
| 29 | { |
| 30 | struct davinci_vc *davinci_vc; |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 31 | struct resource *res; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 32 | struct mfd_cell *cell = NULL; |
Arnd Bergmann | b5e29aa | 2019-07-22 13:47:13 +0200 | [diff] [blame] | 33 | dma_addr_t fifo_base; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 34 | int ret; |
| 35 | |
Lee Jones | 099053a | 2013-05-23 16:25:11 +0100 | [diff] [blame] | 36 | davinci_vc = devm_kzalloc(&pdev->dev, |
| 37 | sizeof(struct davinci_vc), GFP_KERNEL); |
Lee Jones | 9fb4116 | 2015-10-28 16:54:29 +0000 | [diff] [blame] | 38 | if (!davinci_vc) |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 39 | return -ENOMEM; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 40 | |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 41 | davinci_vc->clk = devm_clk_get(&pdev->dev, NULL); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 42 | if (IS_ERR(davinci_vc->clk)) { |
| 43 | dev_dbg(&pdev->dev, |
| 44 | "could not get the clock for voice codec\n"); |
Lee Jones | 099053a | 2013-05-23 16:25:11 +0100 | [diff] [blame] | 45 | return -ENODEV; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 46 | } |
| 47 | clk_enable(davinci_vc->clk); |
| 48 | |
| 49 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 50 | |
Arnd Bergmann | b5e29aa | 2019-07-22 13:47:13 +0200 | [diff] [blame] | 51 | fifo_base = (dma_addr_t)res->start; |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 52 | 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 Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 56 | } |
| 57 | |
Mark Brown | 921a2c8 | 2013-08-31 14:08:56 +0100 | [diff] [blame] | 58 | 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 Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 66 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 67 | if (!res) { |
| 68 | dev_err(&pdev->dev, "no DMA resource\n"); |
Julia Lawall | e2bde787 | 2010-06-01 16:34:38 +0200 | [diff] [blame] | 69 | ret = -ENXIO; |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 70 | goto fail; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | davinci_vc->davinci_vcif.dma_tx_channel = res->start; |
Arnd Bergmann | b5e29aa | 2019-07-22 13:47:13 +0200 | [diff] [blame] | 74 | davinci_vc->davinci_vcif.dma_tx_addr = fifo_base + DAVINCI_VC_WFIFO; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 75 | |
| 76 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 77 | if (!res) { |
| 78 | dev_err(&pdev->dev, "no DMA resource\n"); |
Julia Lawall | e2bde787 | 2010-06-01 16:34:38 +0200 | [diff] [blame] | 79 | ret = -ENXIO; |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 80 | goto fail; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | davinci_vc->davinci_vcif.dma_rx_channel = res->start; |
Arnd Bergmann | b5e29aa | 2019-07-22 13:47:13 +0200 | [diff] [blame] | 84 | davinci_vc->davinci_vcif.dma_rx_addr = fifo_base + DAVINCI_VC_RFIFO; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 85 | |
| 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, Prakash | 73ee652 | 2011-01-27 18:58:36 +0530 | [diff] [blame] | 91 | cell->name = "davinci-vcif"; |
Samuel Ortiz | cb5811c | 2011-04-06 16:39:45 +0200 | [diff] [blame] | 92 | cell->platform_data = davinci_vc; |
| 93 | cell->pdata_size = sizeof(*davinci_vc); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 94 | |
| 95 | /* Voice codec CQ93VC client */ |
| 96 | cell = &davinci_vc->cells[DAVINCI_VC_CQ93VC_CELL]; |
Manjunathappa, Prakash | 73ee652 | 2011-01-27 18:58:36 +0530 | [diff] [blame] | 97 | cell->name = "cq93vc-codec"; |
Samuel Ortiz | cb5811c | 2011-04-06 16:39:45 +0200 | [diff] [blame] | 98 | cell->platform_data = davinci_vc; |
| 99 | cell->pdata_size = sizeof(*davinci_vc); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 100 | |
| 101 | ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 102 | DAVINCI_VC_CELLS, NULL, 0, NULL); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 103 | if (ret != 0) { |
| 104 | dev_err(&pdev->dev, "fail to register client devices\n"); |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 105 | goto fail; |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | |
Sachin Kamat | c8eaed4 | 2013-06-18 15:35:40 +0530 | [diff] [blame] | 110 | fail: |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 111 | clk_disable(davinci_vc->clk); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 112 | |
| 113 | return ret; |
| 114 | } |
| 115 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 116 | static int davinci_vc_remove(struct platform_device *pdev) |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 117 | { |
| 118 | struct davinci_vc *davinci_vc = platform_get_drvdata(pdev); |
| 119 | |
| 120 | mfd_remove_devices(&pdev->dev); |
| 121 | |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 122 | clk_disable(davinci_vc->clk); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 123 | |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static struct platform_driver davinci_vc_driver = { |
| 128 | .driver = { |
| 129 | .name = "davinci_voicecodec", |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 130 | }, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 131 | .remove = davinci_vc_remove, |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 132 | }; |
| 133 | |
Jingoo Han | 3de764d | 2013-03-05 13:48:28 +0900 | [diff] [blame] | 134 | module_platform_driver_probe(davinci_vc_driver, davinci_vc_probe); |
Miguel Aguilar | ca26308 | 2010-03-11 09:32:21 -0600 | [diff] [blame] | 135 | |
| 136 | MODULE_AUTHOR("Miguel Aguilar"); |
| 137 | MODULE_DESCRIPTION("Texas Instruments DaVinci Voice Codec Core Interface"); |
| 138 | MODULE_LICENSE("GPL"); |