tegra20_das.c (ef280d3907cea21b6093802398bbe4193e221a64) | tegra20_das.c (896637ac1be95a239b68dbe61c12a8a9bc00a9a3) |
---|---|
1/* 2 * tegra20_das.c - Tegra20 DAS driver 3 * 4 * Author: Stephen Warren <swarren@nvidia.com> 5 * Copyright (C) 2010 - NVIDIA, Inc. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License --- 17 unchanged lines hidden (view full) --- 26#include <linux/platform_device.h> 27#include <linux/seq_file.h> 28#include <linux/slab.h> 29#include <linux/io.h> 30#include <mach/iomap.h> 31#include <sound/soc.h> 32#include "tegra20_das.h" 33 | 1/* 2 * tegra20_das.c - Tegra20 DAS driver 3 * 4 * Author: Stephen Warren <swarren@nvidia.com> 5 * Copyright (C) 2010 - NVIDIA, Inc. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License --- 17 unchanged lines hidden (view full) --- 26#include <linux/platform_device.h> 27#include <linux/seq_file.h> 28#include <linux/slab.h> 29#include <linux/io.h> 30#include <mach/iomap.h> 31#include <sound/soc.h> 32#include "tegra20_das.h" 33 |
34#define DRV_NAME "tegra-das" | 34#define DRV_NAME "tegra20-das" |
35 | 35 |
36static struct tegra_das *das; | 36static struct tegra20_das *das; |
37 | 37 |
38static inline void tegra_das_write(u32 reg, u32 val) | 38static inline void tegra20_das_write(u32 reg, u32 val) |
39{ 40 __raw_writel(val, das->regs + reg); 41} 42 | 39{ 40 __raw_writel(val, das->regs + reg); 41} 42 |
43static inline u32 tegra_das_read(u32 reg) | 43static inline u32 tegra20_das_read(u32 reg) |
44{ 45 return __raw_readl(das->regs + reg); 46} 47 | 44{ 45 return __raw_readl(das->regs + reg); 46} 47 |
48int tegra_das_connect_dap_to_dac(int dap, int dac) | 48int tegra20_das_connect_dap_to_dac(int dap, int dac) |
49{ 50 u32 addr; 51 u32 reg; 52 53 if (!das) 54 return -ENODEV; 55 | 49{ 50 u32 addr; 51 u32 reg; 52 53 if (!das) 54 return -ENODEV; 55 |
56 addr = TEGRA_DAS_DAP_CTRL_SEL + 57 (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE); 58 reg = dac << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P; | 56 addr = TEGRA20_DAS_DAP_CTRL_SEL + 57 (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE); 58 reg = dac << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P; |
59 | 59 |
60 tegra_das_write(addr, reg); | 60 tegra20_das_write(addr, reg); |
61 62 return 0; 63} | 61 62 return 0; 63} |
64EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dac); | 64EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dac); |
65 | 65 |
66int tegra_das_connect_dap_to_dap(int dap, int otherdap, int master, 67 int sdata1rx, int sdata2rx) | 66int tegra20_das_connect_dap_to_dap(int dap, int otherdap, int master, 67 int sdata1rx, int sdata2rx) |
68{ 69 u32 addr; 70 u32 reg; 71 72 if (!das) 73 return -ENODEV; 74 | 68{ 69 u32 addr; 70 u32 reg; 71 72 if (!das) 73 return -ENODEV; 74 |
75 addr = TEGRA_DAS_DAP_CTRL_SEL + 76 (dap * TEGRA_DAS_DAP_CTRL_SEL_STRIDE); 77 reg = otherdap << TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P | 78 !!sdata2rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P | 79 !!sdata1rx << TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P | 80 !!master << TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P; | 75 addr = TEGRA20_DAS_DAP_CTRL_SEL + 76 (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE); 77 reg = otherdap << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P | 78 !!sdata2rx << TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P | 79 !!sdata1rx << TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P | 80 !!master << TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P; |
81 | 81 |
82 tegra_das_write(addr, reg); | 82 tegra20_das_write(addr, reg); |
83 84 return 0; 85} | 83 84 return 0; 85} |
86EXPORT_SYMBOL_GPL(tegra_das_connect_dap_to_dap); | 86EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dap); |
87 | 87 |
88int tegra_das_connect_dac_to_dap(int dac, int dap) | 88int tegra20_das_connect_dac_to_dap(int dac, int dap) |
89{ 90 u32 addr; 91 u32 reg; 92 93 if (!das) 94 return -ENODEV; 95 | 89{ 90 u32 addr; 91 u32 reg; 92 93 if (!das) 94 return -ENODEV; 95 |
96 addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL + 97 (dac * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); 98 reg = dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P | 99 dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P | 100 dap << TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P; | 96 addr = TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL + 97 (dac * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); 98 reg = dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P | 99 dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P | 100 dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P; |
101 | 101 |
102 tegra_das_write(addr, reg); | 102 tegra20_das_write(addr, reg); |
103 104 return 0; 105} | 103 104 return 0; 105} |
106EXPORT_SYMBOL_GPL(tegra_das_connect_dac_to_dap); | 106EXPORT_SYMBOL_GPL(tegra20_das_connect_dac_to_dap); |
107 108#ifdef CONFIG_DEBUG_FS | 107 108#ifdef CONFIG_DEBUG_FS |
109static int tegra_das_show(struct seq_file *s, void *unused) | 109static int tegra20_das_show(struct seq_file *s, void *unused) |
110{ 111 int i; 112 u32 addr; 113 u32 reg; 114 | 110{ 111 int i; 112 u32 addr; 113 u32 reg; 114 |
115 for (i = 0; i < TEGRA_DAS_DAP_CTRL_SEL_COUNT; i++) { 116 addr = TEGRA_DAS_DAP_CTRL_SEL + 117 (i * TEGRA_DAS_DAP_CTRL_SEL_STRIDE); 118 reg = tegra_das_read(addr); 119 seq_printf(s, "TEGRA_DAS_DAP_CTRL_SEL[%d] = %08x\n", i, reg); | 115 for (i = 0; i < TEGRA20_DAS_DAP_CTRL_SEL_COUNT; i++) { 116 addr = TEGRA20_DAS_DAP_CTRL_SEL + 117 (i * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE); 118 reg = tegra20_das_read(addr); 119 seq_printf(s, "TEGRA20_DAS_DAP_CTRL_SEL[%d] = %08x\n", i, reg); |
120 } 121 | 120 } 121 |
122 for (i = 0; i < TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT; i++) { 123 addr = TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL + 124 (i * TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); 125 reg = tegra_das_read(addr); 126 seq_printf(s, "TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL[%d] = %08x\n", 127 i, reg); | 122 for (i = 0; i < TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT; i++) { 123 addr = TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL + 124 (i * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE); 125 reg = tegra20_das_read(addr); 126 seq_printf(s, "TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL[%d] = %08x\n", 127 i, reg); |
128 } 129 130 return 0; 131} 132 | 128 } 129 130 return 0; 131} 132 |
133static int tegra_das_debug_open(struct inode *inode, struct file *file) | 133static int tegra20_das_debug_open(struct inode *inode, struct file *file) |
134{ | 134{ |
135 return single_open(file, tegra_das_show, inode->i_private); | 135 return single_open(file, tegra20_das_show, inode->i_private); |
136} 137 | 136} 137 |
138static const struct file_operations tegra_das_debug_fops = { 139 .open = tegra_das_debug_open, | 138static const struct file_operations tegra20_das_debug_fops = { 139 .open = tegra20_das_debug_open, |
140 .read = seq_read, 141 .llseek = seq_lseek, 142 .release = single_release, 143}; 144 | 140 .read = seq_read, 141 .llseek = seq_lseek, 142 .release = single_release, 143}; 144 |
145static void tegra_das_debug_add(struct tegra_das *das) | 145static void tegra20_das_debug_add(struct tegra20_das *das) |
146{ 147 das->debug = debugfs_create_file(DRV_NAME, S_IRUGO, 148 snd_soc_debugfs_root, das, | 146{ 147 das->debug = debugfs_create_file(DRV_NAME, S_IRUGO, 148 snd_soc_debugfs_root, das, |
149 &tegra_das_debug_fops); | 149 &tegra20_das_debug_fops); |
150} 151 | 150} 151 |
152static void tegra_das_debug_remove(struct tegra_das *das) | 152static void tegra20_das_debug_remove(struct tegra20_das *das) |
153{ 154 if (das->debug) 155 debugfs_remove(das->debug); 156} 157#else | 153{ 154 if (das->debug) 155 debugfs_remove(das->debug); 156} 157#else |
158static inline void tegra_das_debug_add(struct tegra_das *das) | 158static inline void tegra20_das_debug_add(struct tegra20_das *das) |
159{ 160} 161 | 159{ 160} 161 |
162static inline void tegra_das_debug_remove(struct tegra_das *das) | 162static inline void tegra20_das_debug_remove(struct tegra20_das *das) |
163{ 164} 165#endif 166 | 163{ 164} 165#endif 166 |
167static int __devinit tegra_das_probe(struct platform_device *pdev) | 167static int __devinit tegra20_das_probe(struct platform_device *pdev) |
168{ 169 struct resource *res, *region; 170 int ret = 0; 171 172 if (das) 173 return -ENODEV; 174 | 168{ 169 struct resource *res, *region; 170 int ret = 0; 171 172 if (das) 173 return -ENODEV; 174 |
175 das = devm_kzalloc(&pdev->dev, sizeof(struct tegra_das), GFP_KERNEL); | 175 das = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_das), GFP_KERNEL); |
176 if (!das) { | 176 if (!das) { |
177 dev_err(&pdev->dev, "Can't allocate tegra_das\n"); | 177 dev_err(&pdev->dev, "Can't allocate tegra20_das\n"); |
178 ret = -ENOMEM; 179 goto err; 180 } 181 das->dev = &pdev->dev; 182 183 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 184 if (!res) { 185 dev_err(&pdev->dev, "No memory resource\n"); --- 11 unchanged lines hidden (view full) --- 197 198 das->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 199 if (!das->regs) { 200 dev_err(&pdev->dev, "ioremap failed\n"); 201 ret = -ENOMEM; 202 goto err; 203 } 204 | 178 ret = -ENOMEM; 179 goto err; 180 } 181 das->dev = &pdev->dev; 182 183 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 184 if (!res) { 185 dev_err(&pdev->dev, "No memory resource\n"); --- 11 unchanged lines hidden (view full) --- 197 198 das->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 199 if (!das->regs) { 200 dev_err(&pdev->dev, "ioremap failed\n"); 201 ret = -ENOMEM; 202 goto err; 203 } 204 |
205 ret = tegra_das_connect_dap_to_dac(TEGRA_DAS_DAP_ID_1, 206 TEGRA_DAS_DAP_SEL_DAC1); | 205 ret = tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_1, 206 TEGRA20_DAS_DAP_SEL_DAC1); |
207 if (ret) { 208 dev_err(&pdev->dev, "Can't set up DAS DAP connection\n"); 209 goto err; 210 } | 207 if (ret) { 208 dev_err(&pdev->dev, "Can't set up DAS DAP connection\n"); 209 goto err; 210 } |
211 ret = tegra_das_connect_dac_to_dap(TEGRA_DAS_DAC_ID_1, 212 TEGRA_DAS_DAC_SEL_DAP1); | 211 ret = tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAC_ID_1, 212 TEGRA20_DAS_DAC_SEL_DAP1); |
213 if (ret) { 214 dev_err(&pdev->dev, "Can't set up DAS DAC connection\n"); 215 goto err; 216 } 217 | 213 if (ret) { 214 dev_err(&pdev->dev, "Can't set up DAS DAC connection\n"); 215 goto err; 216 } 217 |
218 tegra_das_debug_add(das); | 218 tegra20_das_debug_add(das); |
219 220 platform_set_drvdata(pdev, das); 221 222 return 0; 223 224err: 225 das = NULL; 226 return ret; 227} 228 | 219 220 platform_set_drvdata(pdev, das); 221 222 return 0; 223 224err: 225 das = NULL; 226 return ret; 227} 228 |
229static int __devexit tegra_das_remove(struct platform_device *pdev) | 229static int __devexit tegra20_das_remove(struct platform_device *pdev) |
230{ 231 if (!das) 232 return -ENODEV; 233 | 230{ 231 if (!das) 232 return -ENODEV; 233 |
234 tegra_das_debug_remove(das); | 234 tegra20_das_debug_remove(das); |
235 236 das = NULL; 237 238 return 0; 239} 240 | 235 236 das = NULL; 237 238 return 0; 239} 240 |
241static const struct of_device_id tegra_das_of_match[] __devinitconst = { | 241static const struct of_device_id tegra20_das_of_match[] __devinitconst = { |
242 { .compatible = "nvidia,tegra20-das", }, 243 {}, 244}; 245 | 242 { .compatible = "nvidia,tegra20-das", }, 243 {}, 244}; 245 |
246static struct platform_driver tegra_das_driver = { 247 .probe = tegra_das_probe, 248 .remove = __devexit_p(tegra_das_remove), | 246static struct platform_driver tegra20_das_driver = { 247 .probe = tegra20_das_probe, 248 .remove = __devexit_p(tegra20_das_remove), |
249 .driver = { 250 .name = DRV_NAME, 251 .owner = THIS_MODULE, | 249 .driver = { 250 .name = DRV_NAME, 251 .owner = THIS_MODULE, |
252 .of_match_table = tegra_das_of_match, | 252 .of_match_table = tegra20_das_of_match, |
253 }, 254}; | 253 }, 254}; |
255module_platform_driver(tegra_das_driver); | 255module_platform_driver(tegra20_das_driver); |
256 257MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); | 256 257MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); |
258MODULE_DESCRIPTION("Tegra DAS driver"); | 258MODULE_DESCRIPTION("Tegra20 DAS driver"); |
259MODULE_LICENSE("GPL"); 260MODULE_ALIAS("platform:" DRV_NAME); | 259MODULE_LICENSE("GPL"); 260MODULE_ALIAS("platform:" DRV_NAME); |
261MODULE_DEVICE_TABLE(of, tegra_das_of_match); | 261MODULE_DEVICE_TABLE(of, tegra20_das_of_match); |