This source file includes following definitions.
- sirfsoc_rtc_iobrg_wait_sync
- sirfsoc_rtc_iobrg_besyncing
- __sirfsoc_rtc_iobrg_readl
- sirfsoc_rtc_iobrg_readl
- sirfsoc_rtc_iobrg_pre_writel
- sirfsoc_rtc_iobrg_writel
- regmap_iobg_regwrite
- regmap_iobg_regread
- devm_regmap_init_iobg
- sirfsoc_rtciobrg_probe
- sirfsoc_rtciobrg_init
1
2
3
4
5
6
7
8
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/io.h>
12 #include <linux/regmap.h>
13 #include <linux/of.h>
14 #include <linux/of_address.h>
15 #include <linux/of_device.h>
16 #include <linux/of_platform.h>
17
18 #define SIRFSOC_CPUIOBRG_CTRL 0x00
19 #define SIRFSOC_CPUIOBRG_WRBE 0x04
20 #define SIRFSOC_CPUIOBRG_ADDR 0x08
21 #define SIRFSOC_CPUIOBRG_DATA 0x0c
22
23
24
25
26
27 void __iomem *sirfsoc_rtciobrg_base;
28 static DEFINE_SPINLOCK(rtciobrg_lock);
29
30
31
32
33
34 void sirfsoc_rtc_iobrg_wait_sync(void)
35 {
36 while (readl_relaxed(sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_CTRL))
37 cpu_relax();
38 }
39
40 void sirfsoc_rtc_iobrg_besyncing(void)
41 {
42 unsigned long flags;
43
44 spin_lock_irqsave(&rtciobrg_lock, flags);
45
46 sirfsoc_rtc_iobrg_wait_sync();
47
48 spin_unlock_irqrestore(&rtciobrg_lock, flags);
49 }
50 EXPORT_SYMBOL_GPL(sirfsoc_rtc_iobrg_besyncing);
51
52 u32 __sirfsoc_rtc_iobrg_readl(u32 addr)
53 {
54 sirfsoc_rtc_iobrg_wait_sync();
55
56 writel_relaxed(0x00, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_WRBE);
57 writel_relaxed(addr, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_ADDR);
58 writel_relaxed(0x01, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_CTRL);
59
60 sirfsoc_rtc_iobrg_wait_sync();
61
62 return readl_relaxed(sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_DATA);
63 }
64
65 u32 sirfsoc_rtc_iobrg_readl(u32 addr)
66 {
67 unsigned long flags, val;
68
69
70 spin_lock_irqsave(&rtciobrg_lock, flags);
71
72 val = __sirfsoc_rtc_iobrg_readl(addr);
73
74 spin_unlock_irqrestore(&rtciobrg_lock, flags);
75
76 return val;
77 }
78 EXPORT_SYMBOL_GPL(sirfsoc_rtc_iobrg_readl);
79
80 void sirfsoc_rtc_iobrg_pre_writel(u32 val, u32 addr)
81 {
82 sirfsoc_rtc_iobrg_wait_sync();
83
84 writel_relaxed(0xf1, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_WRBE);
85 writel_relaxed(addr, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_ADDR);
86
87 writel_relaxed(val, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_DATA);
88 }
89
90 void sirfsoc_rtc_iobrg_writel(u32 val, u32 addr)
91 {
92 unsigned long flags;
93
94
95 spin_lock_irqsave(&rtciobrg_lock, flags);
96
97 sirfsoc_rtc_iobrg_pre_writel(val, addr);
98
99 writel_relaxed(0x01, sirfsoc_rtciobrg_base + SIRFSOC_CPUIOBRG_CTRL);
100
101 sirfsoc_rtc_iobrg_wait_sync();
102
103 spin_unlock_irqrestore(&rtciobrg_lock, flags);
104 }
105 EXPORT_SYMBOL_GPL(sirfsoc_rtc_iobrg_writel);
106
107
108 static int regmap_iobg_regwrite(void *context, unsigned int reg,
109 unsigned int val)
110 {
111 sirfsoc_rtc_iobrg_writel(val, reg);
112 return 0;
113 }
114
115 static int regmap_iobg_regread(void *context, unsigned int reg,
116 unsigned int *val)
117 {
118 *val = (u32)sirfsoc_rtc_iobrg_readl(reg);
119 return 0;
120 }
121
122 static struct regmap_bus regmap_iobg = {
123 .reg_write = regmap_iobg_regwrite,
124 .reg_read = regmap_iobg_regread,
125 };
126
127
128
129
130
131
132
133
134
135
136
137 struct regmap *devm_regmap_init_iobg(struct device *dev,
138 const struct regmap_config *config)
139 {
140 const struct regmap_bus *bus = ®map_iobg;
141
142 return devm_regmap_init(dev, bus, dev, config);
143 }
144 EXPORT_SYMBOL_GPL(devm_regmap_init_iobg);
145
146 static const struct of_device_id rtciobrg_ids[] = {
147 { .compatible = "sirf,prima2-rtciobg" },
148 {}
149 };
150
151 static int sirfsoc_rtciobrg_probe(struct platform_device *op)
152 {
153 struct device_node *np = op->dev.of_node;
154
155 sirfsoc_rtciobrg_base = of_iomap(np, 0);
156 if (!sirfsoc_rtciobrg_base)
157 panic("unable to map rtc iobrg registers\n");
158
159 return 0;
160 }
161
162 static struct platform_driver sirfsoc_rtciobrg_driver = {
163 .probe = sirfsoc_rtciobrg_probe,
164 .driver = {
165 .name = "sirfsoc-rtciobrg",
166 .of_match_table = rtciobrg_ids,
167 },
168 };
169
170 static int __init sirfsoc_rtciobrg_init(void)
171 {
172 return platform_driver_register(&sirfsoc_rtciobrg_driver);
173 }
174 postcore_initcall(sirfsoc_rtciobrg_init);
175
176 MODULE_AUTHOR("Zhiwu Song <zhiwu.song@csr.com>");
177 MODULE_AUTHOR("Barry Song <baohua.song@csr.com>");
178 MODULE_DESCRIPTION("CSR SiRFprimaII rtc io bridge");
179 MODULE_LICENSE("GPL v2");