1 // SPDX-License-Identifier: GPL-2.0-only
3 * tegra20_das.c - Tegra20 DAS driver
5 * Author: Stephen Warren <swarren@nvidia.com>
6 * Copyright (C) 2010 - NVIDIA, Inc.
9 #include <linux/device.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/regmap.h>
14 #include <linux/slab.h>
15 #include <sound/soc.h>
16 #include "tegra20_das.h"
18 #define DRV_NAME "tegra20-das"
20 static struct tegra20_das
*das
;
22 static inline void tegra20_das_write(u32 reg
, u32 val
)
24 regmap_write(das
->regmap
, reg
, val
);
27 static inline u32
tegra20_das_read(u32 reg
)
31 regmap_read(das
->regmap
, reg
, &val
);
35 int tegra20_das_connect_dap_to_dac(int dap
, int dac
)
43 addr
= TEGRA20_DAS_DAP_CTRL_SEL
+
44 (dap
* TEGRA20_DAS_DAP_CTRL_SEL_STRIDE
);
45 reg
= dac
<< TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P
;
47 tegra20_das_write(addr
, reg
);
51 EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dac
);
53 int tegra20_das_connect_dap_to_dap(int dap
, int otherdap
, int master
,
54 int sdata1rx
, int sdata2rx
)
62 addr
= TEGRA20_DAS_DAP_CTRL_SEL
+
63 (dap
* TEGRA20_DAS_DAP_CTRL_SEL_STRIDE
);
64 reg
= otherdap
<< TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P
|
65 !!sdata2rx
<< TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P
|
66 !!sdata1rx
<< TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P
|
67 !!master
<< TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P
;
69 tegra20_das_write(addr
, reg
);
73 EXPORT_SYMBOL_GPL(tegra20_das_connect_dap_to_dap
);
75 int tegra20_das_connect_dac_to_dap(int dac
, int dap
)
83 addr
= TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL
+
84 (dac
* TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE
);
85 reg
= dap
<< TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P
|
86 dap
<< TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P
|
87 dap
<< TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P
;
89 tegra20_das_write(addr
, reg
);
93 EXPORT_SYMBOL_GPL(tegra20_das_connect_dac_to_dap
);
95 #define LAST_REG(name) \
96 (TEGRA20_DAS_##name + \
97 (TEGRA20_DAS_##name##_STRIDE * (TEGRA20_DAS_##name##_COUNT - 1)))
99 static bool tegra20_das_wr_rd_reg(struct device
*dev
, unsigned int reg
)
101 if (reg
<= LAST_REG(DAP_CTRL_SEL
))
103 if ((reg
>= TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL
) &&
104 (reg
<= LAST_REG(DAC_INPUT_DATA_CLK_SEL
)))
110 static const struct regmap_config tegra20_das_regmap_config
= {
114 .max_register
= LAST_REG(DAC_INPUT_DATA_CLK_SEL
),
115 .writeable_reg
= tegra20_das_wr_rd_reg
,
116 .readable_reg
= tegra20_das_wr_rd_reg
,
117 .cache_type
= REGCACHE_FLAT
,
120 static int tegra20_das_probe(struct platform_device
*pdev
)
128 das
= devm_kzalloc(&pdev
->dev
, sizeof(struct tegra20_das
), GFP_KERNEL
);
133 das
->dev
= &pdev
->dev
;
135 regs
= devm_platform_ioremap_resource(pdev
, 0);
141 das
->regmap
= devm_regmap_init_mmio(&pdev
->dev
, regs
,
142 &tegra20_das_regmap_config
);
143 if (IS_ERR(das
->regmap
)) {
144 dev_err(&pdev
->dev
, "regmap init failed\n");
145 ret
= PTR_ERR(das
->regmap
);
149 ret
= tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_1
,
150 TEGRA20_DAS_DAP_SEL_DAC1
);
152 dev_err(&pdev
->dev
, "Can't set up DAS DAP connection\n");
155 ret
= tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAC_ID_1
,
156 TEGRA20_DAS_DAC_SEL_DAP1
);
158 dev_err(&pdev
->dev
, "Can't set up DAS DAC connection\n");
162 ret
= tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_3
,
163 TEGRA20_DAS_DAP_SEL_DAC3
);
165 dev_err(&pdev
->dev
, "Can't set up DAS DAP connection\n");
168 ret
= tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAC_ID_3
,
169 TEGRA20_DAS_DAC_SEL_DAP3
);
171 dev_err(&pdev
->dev
, "Can't set up DAS DAC connection\n");
175 platform_set_drvdata(pdev
, das
);
184 static int tegra20_das_remove(struct platform_device
*pdev
)
194 static const struct of_device_id tegra20_das_of_match
[] = {
195 { .compatible
= "nvidia,tegra20-das", },
199 static struct platform_driver tegra20_das_driver
= {
200 .probe
= tegra20_das_probe
,
201 .remove
= tegra20_das_remove
,
204 .of_match_table
= tegra20_das_of_match
,
207 module_platform_driver(tegra20_das_driver
);
209 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
210 MODULE_DESCRIPTION("Tegra20 DAS driver");
211 MODULE_LICENSE("GPL");
212 MODULE_ALIAS("platform:" DRV_NAME
);
213 MODULE_DEVICE_TABLE(of
, tegra20_das_of_match
);