16
16
struct regmap_mmio_context {
17
17
void __iomem * regs ;
18
18
unsigned int val_bytes ;
19
- bool relaxed_mmio ;
20
19
21
20
bool attached_clk ;
22
21
struct clk * clk ;
@@ -33,9 +32,6 @@ static int regmap_mmio_regbits_check(size_t reg_bits)
33
32
case 8 :
34
33
case 16 :
35
34
case 32 :
36
- #ifdef CONFIG_64BIT
37
- case 64 :
38
- #endif
39
35
return 0 ;
40
36
default :
41
37
return - EINVAL ;
@@ -57,11 +53,6 @@ static int regmap_mmio_get_min_stride(size_t val_bits)
57
53
case 32 :
58
54
min_stride = 4 ;
59
55
break ;
60
- #ifdef CONFIG_64BIT
61
- case 64 :
62
- min_stride = 8 ;
63
- break ;
64
- #endif
65
56
default :
66
57
return - EINVAL ;
67
58
}
@@ -83,6 +74,12 @@ static void regmap_mmio_write8_relaxed(struct regmap_mmio_context *ctx,
83
74
writeb_relaxed (val , ctx -> regs + reg );
84
75
}
85
76
77
+ static void regmap_mmio_iowrite8 (struct regmap_mmio_context * ctx ,
78
+ unsigned int reg , unsigned int val )
79
+ {
80
+ iowrite8 (val , ctx -> regs + reg );
81
+ }
82
+
86
83
static void regmap_mmio_write16le (struct regmap_mmio_context * ctx ,
87
84
unsigned int reg ,
88
85
unsigned int val )
@@ -97,9 +94,21 @@ static void regmap_mmio_write16le_relaxed(struct regmap_mmio_context *ctx,
97
94
writew_relaxed (val , ctx -> regs + reg );
98
95
}
99
96
97
+ static void regmap_mmio_iowrite16le (struct regmap_mmio_context * ctx ,
98
+ unsigned int reg , unsigned int val )
99
+ {
100
+ iowrite16 (val , ctx -> regs + reg );
101
+ }
102
+
100
103
static void regmap_mmio_write16be (struct regmap_mmio_context * ctx ,
101
104
unsigned int reg ,
102
105
unsigned int val )
106
+ {
107
+ writew (swab16 (val ), ctx -> regs + reg );
108
+ }
109
+
110
+ static void regmap_mmio_iowrite16be (struct regmap_mmio_context * ctx ,
111
+ unsigned int reg , unsigned int val )
103
112
{
104
113
iowrite16be (val , ctx -> regs + reg );
105
114
}
@@ -118,28 +127,24 @@ static void regmap_mmio_write32le_relaxed(struct regmap_mmio_context *ctx,
118
127
writel_relaxed (val , ctx -> regs + reg );
119
128
}
120
129
121
- static void regmap_mmio_write32be (struct regmap_mmio_context * ctx ,
122
- unsigned int reg ,
123
- unsigned int val )
130
+ static void regmap_mmio_iowrite32le (struct regmap_mmio_context * ctx ,
131
+ unsigned int reg , unsigned int val )
124
132
{
125
- iowrite32be (val , ctx -> regs + reg );
133
+ iowrite32 (val , ctx -> regs + reg );
126
134
}
127
135
128
- #ifdef CONFIG_64BIT
129
- static void regmap_mmio_write64le (struct regmap_mmio_context * ctx ,
136
+ static void regmap_mmio_write32be (struct regmap_mmio_context * ctx ,
130
137
unsigned int reg ,
131
138
unsigned int val )
132
139
{
133
- writeq ( val , ctx -> regs + reg );
140
+ writel ( swab32 ( val ) , ctx -> regs + reg );
134
141
}
135
142
136
- static void regmap_mmio_write64le_relaxed (struct regmap_mmio_context * ctx ,
137
- unsigned int reg ,
138
- unsigned int val )
143
+ static void regmap_mmio_iowrite32be (struct regmap_mmio_context * ctx ,
144
+ unsigned int reg , unsigned int val )
139
145
{
140
- writeq_relaxed (val , ctx -> regs + reg );
146
+ iowrite32be (val , ctx -> regs + reg );
141
147
}
142
- #endif
143
148
144
149
static int regmap_mmio_write (void * context , unsigned int reg , unsigned int val )
145
150
{
@@ -172,6 +177,12 @@ static unsigned int regmap_mmio_read8_relaxed(struct regmap_mmio_context *ctx,
172
177
return readb_relaxed (ctx -> regs + reg );
173
178
}
174
179
180
+ static unsigned int regmap_mmio_ioread8 (struct regmap_mmio_context * ctx ,
181
+ unsigned int reg )
182
+ {
183
+ return ioread8 (ctx -> regs + reg );
184
+ }
185
+
175
186
static unsigned int regmap_mmio_read16le (struct regmap_mmio_context * ctx ,
176
187
unsigned int reg )
177
188
{
@@ -184,8 +195,20 @@ static unsigned int regmap_mmio_read16le_relaxed(struct regmap_mmio_context *ctx
184
195
return readw_relaxed (ctx -> regs + reg );
185
196
}
186
197
198
+ static unsigned int regmap_mmio_ioread16le (struct regmap_mmio_context * ctx ,
199
+ unsigned int reg )
200
+ {
201
+ return ioread16 (ctx -> regs + reg );
202
+ }
203
+
187
204
static unsigned int regmap_mmio_read16be (struct regmap_mmio_context * ctx ,
188
205
unsigned int reg )
206
+ {
207
+ return swab16 (readw (ctx -> regs + reg ));
208
+ }
209
+
210
+ static unsigned int regmap_mmio_ioread16be (struct regmap_mmio_context * ctx ,
211
+ unsigned int reg )
189
212
{
190
213
return ioread16be (ctx -> regs + reg );
191
214
}
@@ -202,25 +225,23 @@ static unsigned int regmap_mmio_read32le_relaxed(struct regmap_mmio_context *ctx
202
225
return readl_relaxed (ctx -> regs + reg );
203
226
}
204
227
205
- static unsigned int regmap_mmio_read32be (struct regmap_mmio_context * ctx ,
206
- unsigned int reg )
228
+ static unsigned int regmap_mmio_ioread32le (struct regmap_mmio_context * ctx ,
229
+ unsigned int reg )
207
230
{
208
- return ioread32be (ctx -> regs + reg );
231
+ return ioread32 (ctx -> regs + reg );
209
232
}
210
233
211
- #ifdef CONFIG_64BIT
212
- static unsigned int regmap_mmio_read64le (struct regmap_mmio_context * ctx ,
234
+ static unsigned int regmap_mmio_read32be (struct regmap_mmio_context * ctx ,
213
235
unsigned int reg )
214
236
{
215
- return readq ( ctx -> regs + reg );
237
+ return swab32 ( readl ( ctx -> regs + reg ) );
216
238
}
217
239
218
- static unsigned int regmap_mmio_read64le_relaxed (struct regmap_mmio_context * ctx ,
219
- unsigned int reg )
240
+ static unsigned int regmap_mmio_ioread32be (struct regmap_mmio_context * ctx ,
241
+ unsigned int reg )
220
242
{
221
- return readq_relaxed (ctx -> regs + reg );
243
+ return ioread32be (ctx -> regs + reg );
222
244
}
223
- #endif
224
245
225
246
static int regmap_mmio_read (void * context , unsigned int reg , unsigned int * val )
226
247
{
@@ -284,13 +305,15 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
284
305
if (config -> reg_stride < min_stride )
285
306
return ERR_PTR (- EINVAL );
286
307
308
+ if (config -> use_relaxed_mmio && config -> io_port )
309
+ return ERR_PTR (- EINVAL );
310
+
287
311
ctx = kzalloc (sizeof (* ctx ), GFP_KERNEL );
288
312
if (!ctx )
289
313
return ERR_PTR (- ENOMEM );
290
314
291
315
ctx -> regs = regs ;
292
316
ctx -> val_bytes = config -> val_bits / 8 ;
293
- ctx -> relaxed_mmio = config -> use_relaxed_mmio ;
294
317
ctx -> clk = ERR_PTR (- ENODEV );
295
318
296
319
switch (regmap_get_val_endian (dev , & regmap_mmio , config )) {
@@ -301,7 +324,10 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
301
324
#endif
302
325
switch (config -> val_bits ) {
303
326
case 8 :
304
- if (ctx -> relaxed_mmio ) {
327
+ if (config -> io_port ) {
328
+ ctx -> reg_read = regmap_mmio_ioread8 ;
329
+ ctx -> reg_write = regmap_mmio_iowrite8 ;
330
+ } else if (config -> use_relaxed_mmio ) {
305
331
ctx -> reg_read = regmap_mmio_read8_relaxed ;
306
332
ctx -> reg_write = regmap_mmio_write8_relaxed ;
307
333
} else {
@@ -310,7 +336,10 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
310
336
}
311
337
break ;
312
338
case 16 :
313
- if (ctx -> relaxed_mmio ) {
339
+ if (config -> io_port ) {
340
+ ctx -> reg_read = regmap_mmio_ioread16le ;
341
+ ctx -> reg_write = regmap_mmio_iowrite16le ;
342
+ } else if (config -> use_relaxed_mmio ) {
314
343
ctx -> reg_read = regmap_mmio_read16le_relaxed ;
315
344
ctx -> reg_write = regmap_mmio_write16le_relaxed ;
316
345
} else {
@@ -319,25 +348,17 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
319
348
}
320
349
break ;
321
350
case 32 :
322
- if (ctx -> relaxed_mmio ) {
351
+ if (config -> io_port ) {
352
+ ctx -> reg_read = regmap_mmio_ioread32le ;
353
+ ctx -> reg_write = regmap_mmio_iowrite32le ;
354
+ } else if (config -> use_relaxed_mmio ) {
323
355
ctx -> reg_read = regmap_mmio_read32le_relaxed ;
324
356
ctx -> reg_write = regmap_mmio_write32le_relaxed ;
325
357
} else {
326
358
ctx -> reg_read = regmap_mmio_read32le ;
327
359
ctx -> reg_write = regmap_mmio_write32le ;
328
360
}
329
361
break ;
330
- #ifdef CONFIG_64BIT
331
- case 64 :
332
- if (ctx -> relaxed_mmio ) {
333
- ctx -> reg_read = regmap_mmio_read64le_relaxed ;
334
- ctx -> reg_write = regmap_mmio_write64le_relaxed ;
335
- } else {
336
- ctx -> reg_read = regmap_mmio_read64le ;
337
- ctx -> reg_write = regmap_mmio_write64le ;
338
- }
339
- break ;
340
- #endif
341
362
default :
342
363
ret = - EINVAL ;
343
364
goto err_free ;
@@ -349,16 +370,31 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
349
370
#endif
350
371
switch (config -> val_bits ) {
351
372
case 8 :
352
- ctx -> reg_read = regmap_mmio_read8 ;
353
- ctx -> reg_write = regmap_mmio_write8 ;
373
+ if (config -> io_port ) {
374
+ ctx -> reg_read = regmap_mmio_ioread8 ;
375
+ ctx -> reg_write = regmap_mmio_iowrite8 ;
376
+ } else {
377
+ ctx -> reg_read = regmap_mmio_read8 ;
378
+ ctx -> reg_write = regmap_mmio_write8 ;
379
+ }
354
380
break ;
355
381
case 16 :
356
- ctx -> reg_read = regmap_mmio_read16be ;
357
- ctx -> reg_write = regmap_mmio_write16be ;
382
+ if (config -> io_port ) {
383
+ ctx -> reg_read = regmap_mmio_ioread16be ;
384
+ ctx -> reg_write = regmap_mmio_iowrite16be ;
385
+ } else {
386
+ ctx -> reg_read = regmap_mmio_read16be ;
387
+ ctx -> reg_write = regmap_mmio_write16be ;
388
+ }
358
389
break ;
359
390
case 32 :
360
- ctx -> reg_read = regmap_mmio_read32be ;
361
- ctx -> reg_write = regmap_mmio_write32be ;
391
+ if (config -> io_port ) {
392
+ ctx -> reg_read = regmap_mmio_ioread32be ;
393
+ ctx -> reg_write = regmap_mmio_iowrite32be ;
394
+ } else {
395
+ ctx -> reg_read = regmap_mmio_read32be ;
396
+ ctx -> reg_write = regmap_mmio_write32be ;
397
+ }
362
398
break ;
363
399
default :
364
400
ret = - EINVAL ;
0 commit comments