This source file includes following definitions.
- adda_reg_read
- adda_reg_write
- sun8i_adda_pr_regmap_init
1
2
3
4
5
6
7
8
9
10 #include <linux/io.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14
15 #include "sun8i-adda-pr-regmap.h"
16
17
18 #define ADDA_PR 0x0
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)
27
28
29 static int adda_reg_read(void *context, unsigned int reg, unsigned int *val)
30 {
31 void __iomem *base = (void __iomem *)context;
32 u32 tmp;
33
34
35 writel(readl(base) | ADDA_PR_RESET, base);
36
37
38 writel(readl(base) & ~ADDA_PR_WRITE, base);
39
40
41 tmp = readl(base);
42 tmp &= ~(ADDA_PR_ADDR_MASK << ADDA_PR_ADDR_SHIFT);
43 tmp |= (reg & ADDA_PR_ADDR_MASK) << ADDA_PR_ADDR_SHIFT;
44 writel(tmp, base);
45
46
47 *val = readl(base) & ADDA_PR_DATA_OUT_MASK;
48
49 return 0;
50 }
51
52 static int adda_reg_write(void *context, unsigned int reg, unsigned int val)
53 {
54 void __iomem *base = (void __iomem *)context;
55 u32 tmp;
56
57
58 writel(readl(base) | ADDA_PR_RESET, base);
59
60
61 tmp = readl(base);
62 tmp &= ~(ADDA_PR_ADDR_MASK << ADDA_PR_ADDR_SHIFT);
63 tmp |= (reg & ADDA_PR_ADDR_MASK) << ADDA_PR_ADDR_SHIFT;
64 writel(tmp, base);
65
66
67 tmp = readl(base);
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;
70 writel(tmp, base);
71
72
73 writel(readl(base) | ADDA_PR_WRITE, base);
74
75
76 writel(readl(base) & ~ADDA_PR_WRITE, base);
77
78 return 0;
79 }
80
81 static const struct regmap_config adda_pr_regmap_cfg = {
82 .name = "adda-pr",
83 .reg_bits = 5,
84 .reg_stride = 1,
85 .val_bits = 8,
86 .reg_read = adda_reg_read,
87 .reg_write = adda_reg_write,
88 .fast_io = true,
89 .max_register = 31,
90 };
91
92 struct regmap *sun8i_adda_pr_regmap_init(struct device *dev,
93 void __iomem *base)
94 {
95 return devm_regmap_init(dev, NULL, base, &adda_pr_regmap_cfg);
96 }
97 EXPORT_SYMBOL_GPL(sun8i_adda_pr_regmap_init);
98
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");