hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/sound/soc/sunxi/sun8i-codec-analog.c
....@@ -1,18 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * This driver supports the analog controls for the internal codec
34 * found in Allwinner's A31s, A23, A33 and H3 SoCs.
45 *
56 * Copyright 2016 Chen-Yu Tsai <wens@csie.org>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
167 */
178
189 #include <linux/io.h>
....@@ -26,6 +17,8 @@
2617 #include <sound/soc.h>
2718 #include <sound/soc-dapm.h>
2819 #include <sound/tlv.h>
20
+
21
+#include "sun8i-adda-pr-regmap.h"
2922
3023 /* Codec analog control register offsets and bit fields */
3124 #define SUN8I_ADDA_HP_VOLC 0x00
....@@ -119,81 +112,6 @@
119112 #define SUN8I_ADDA_ADC_AP_EN_ADCREN 7
120113 #define SUN8I_ADDA_ADC_AP_EN_ADCLEN 6
121114 #define SUN8I_ADDA_ADC_AP_EN_ADCG 0
122
-
123
-/* Analog control register access bits */
124
-#define ADDA_PR 0x0 /* PRCM base + 0x1c0 */
125
-#define ADDA_PR_RESET BIT(28)
126
-#define ADDA_PR_WRITE BIT(24)
127
-#define ADDA_PR_ADDR_SHIFT 16
128
-#define ADDA_PR_ADDR_MASK GENMASK(4, 0)
129
-#define ADDA_PR_DATA_IN_SHIFT 8
130
-#define ADDA_PR_DATA_IN_MASK GENMASK(7, 0)
131
-#define ADDA_PR_DATA_OUT_SHIFT 0
132
-#define ADDA_PR_DATA_OUT_MASK GENMASK(7, 0)
133
-
134
-/* regmap access bits */
135
-static int adda_reg_read(void *context, unsigned int reg, unsigned int *val)
136
-{
137
- void __iomem *base = (void __iomem *)context;
138
- u32 tmp;
139
-
140
- /* De-assert reset */
141
- writel(readl(base) | ADDA_PR_RESET, base);
142
-
143
- /* Clear write bit */
144
- writel(readl(base) & ~ADDA_PR_WRITE, base);
145
-
146
- /* Set register address */
147
- tmp = readl(base);
148
- tmp &= ~(ADDA_PR_ADDR_MASK << ADDA_PR_ADDR_SHIFT);
149
- tmp |= (reg & ADDA_PR_ADDR_MASK) << ADDA_PR_ADDR_SHIFT;
150
- writel(tmp, base);
151
-
152
- /* Read back value */
153
- *val = readl(base) & ADDA_PR_DATA_OUT_MASK;
154
-
155
- return 0;
156
-}
157
-
158
-static int adda_reg_write(void *context, unsigned int reg, unsigned int val)
159
-{
160
- void __iomem *base = (void __iomem *)context;
161
- u32 tmp;
162
-
163
- /* De-assert reset */
164
- writel(readl(base) | ADDA_PR_RESET, base);
165
-
166
- /* Set register address */
167
- tmp = readl(base);
168
- tmp &= ~(ADDA_PR_ADDR_MASK << ADDA_PR_ADDR_SHIFT);
169
- tmp |= (reg & ADDA_PR_ADDR_MASK) << ADDA_PR_ADDR_SHIFT;
170
- writel(tmp, base);
171
-
172
- /* Set data to write */
173
- tmp = readl(base);
174
- tmp &= ~(ADDA_PR_DATA_IN_MASK << ADDA_PR_DATA_IN_SHIFT);
175
- tmp |= (val & ADDA_PR_DATA_IN_MASK) << ADDA_PR_DATA_IN_SHIFT;
176
- writel(tmp, base);
177
-
178
- /* Set write bit to signal a write */
179
- writel(readl(base) | ADDA_PR_WRITE, base);
180
-
181
- /* Clear write bit */
182
- writel(readl(base) & ~ADDA_PR_WRITE, base);
183
-
184
- return 0;
185
-}
186
-
187
-static const struct regmap_config adda_pr_regmap_cfg = {
188
- .name = "adda-pr",
189
- .reg_bits = 5,
190
- .reg_stride = 1,
191
- .val_bits = 8,
192
- .reg_read = adda_reg_read,
193
- .reg_write = adda_reg_write,
194
- .fast_io = true,
195
- .max_register = 24,
196
-};
197115
198116 /* mixer controls */
199117 static const struct snd_kcontrol_new sun8i_codec_mixer_controls[] = {
....@@ -901,18 +819,16 @@
901819
902820 static int sun8i_codec_analog_probe(struct platform_device *pdev)
903821 {
904
- struct resource *res;
905822 struct regmap *regmap;
906823 void __iomem *base;
907824
908
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
909
- base = devm_ioremap_resource(&pdev->dev, res);
825
+ base = devm_platform_ioremap_resource(pdev, 0);
910826 if (IS_ERR(base)) {
911827 dev_err(&pdev->dev, "Failed to map the registers\n");
912828 return PTR_ERR(base);
913829 }
914830
915
- regmap = devm_regmap_init(&pdev->dev, NULL, base, &adda_pr_regmap_cfg);
831
+ regmap = sun8i_adda_pr_regmap_init(&pdev->dev, base);
916832 if (IS_ERR(regmap)) {
917833 dev_err(&pdev->dev, "Failed to create regmap\n");
918834 return PTR_ERR(regmap);