1 // SPDX-License-Identifier: GPL-2.0+
3 * This driver provides regmap to access to analog part of audio codec
4 * found on Allwinner A23, A31s, A33, H3 and A64 Socs
6 * Copyright 2016 Chen-Yu Tsai <wens@csie.org>
7 * Copyright (C) 2018 Vasily Khoruzhick <anarsoul@gmail.com>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
15 #include "sun8i-adda-pr-regmap.h"
17 /* Analog control register access bits */
18 #define ADDA_PR 0x0 /* PRCM base + 0x1c0 */
19 #define ADDA_PR_RESET BIT(28)
20 #define ADDA_PR_WRITE BIT(24)
21 #define ADDA_PR_ADDR_SHIFT 16
22 #define ADDA_PR_ADDR_MASK GENMASK(4, 0)
23 #define ADDA_PR_DATA_IN_SHIFT 8
24 #define ADDA_PR_DATA_IN_MASK GENMASK(7, 0)
25 #define ADDA_PR_DATA_OUT_SHIFT 0
26 #define ADDA_PR_DATA_OUT_MASK GENMASK(7, 0)
28 /* regmap access bits */
29 static int adda_reg_read(void *context
, unsigned int reg
, unsigned int *val
)
31 void __iomem
*base
= (void __iomem
*)context
;
35 writel(readl(base
) | ADDA_PR_RESET
, base
);
38 writel(readl(base
) & ~ADDA_PR_WRITE
, base
);
40 /* Set register address */
42 tmp
&= ~(ADDA_PR_ADDR_MASK
<< ADDA_PR_ADDR_SHIFT
);
43 tmp
|= (reg
& ADDA_PR_ADDR_MASK
) << ADDA_PR_ADDR_SHIFT
;
47 *val
= readl(base
) & ADDA_PR_DATA_OUT_MASK
;
52 static int adda_reg_write(void *context
, unsigned int reg
, unsigned int val
)
54 void __iomem
*base
= (void __iomem
*)context
;
58 writel(readl(base
) | ADDA_PR_RESET
, base
);
60 /* Set register address */
62 tmp
&= ~(ADDA_PR_ADDR_MASK
<< ADDA_PR_ADDR_SHIFT
);
63 tmp
|= (reg
& ADDA_PR_ADDR_MASK
) << ADDA_PR_ADDR_SHIFT
;
66 /* Set data to write */
68 tmp
&= ~(ADDA_PR_DATA_IN_MASK
<< ADDA_PR_DATA_IN_SHIFT
);
69 tmp
|= (val
& ADDA_PR_DATA_IN_MASK
) << ADDA_PR_DATA_IN_SHIFT
;
72 /* Set write bit to signal a write */
73 writel(readl(base
) | ADDA_PR_WRITE
, base
);
76 writel(readl(base
) & ~ADDA_PR_WRITE
, base
);
81 static const struct regmap_config adda_pr_regmap_cfg
= {
86 .reg_read
= adda_reg_read
,
87 .reg_write
= adda_reg_write
,
92 struct regmap
*sun8i_adda_pr_regmap_init(struct device
*dev
,
95 return devm_regmap_init(dev
, NULL
, base
, &adda_pr_regmap_cfg
);
97 EXPORT_SYMBOL_GPL(sun8i_adda_pr_regmap_init
);
99 MODULE_DESCRIPTION("Allwinner analog audio codec regmap driver");
100 MODULE_AUTHOR("Vasily Khoruzhick <anarsoul@gmail.com>");
101 MODULE_LICENSE("GPL");
102 MODULE_ALIAS("platform:sunxi-adda-pr");