aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Six2018-10-15 02:24:10 -0500
committerSimon Glass2018-11-14 11:16:27 -0600
commit84ff8f622d2e2aeb67c1cec1c2c814895648fca8 (patch)
treefb70da06172352bae28ed26ecf5872e38d050d88 /drivers
parent4d9ada54a269c4ded01d60f7c231fd1a3a436a25 (diff)
downloadu-boot-84ff8f622d2e2aeb67c1cec1c2c814895648fca8.tar.gz
u-boot-84ff8f622d2e2aeb67c1cec1c2c814895648fca8.tar.xz
u-boot-84ff8f622d2e2aeb67c1cec1c2c814895648fca8.zip
regmap: Add raw read/write functions
The regmap functions currently assume that all register map accesses have a data width of 32 bits, but there are maps that have different widths. To rectify this, implement the regmap_raw_read and regmap_raw_write functions from the Linux kernel API that specify the width of a desired read or write operation on a regmap. Implement the regmap_read and regmap_write functions using these raw functions in a backwards-compatible manner. Reviewed-by: Anatolij Gustschin <agust@denx.de> Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/core/regmap.c64
1 files changed, 57 insertions, 7 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 154426269d..916d9272ea 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -188,22 +188,72 @@ int regmap_uninit(struct regmap *map)
188 return 0; 188 return 0;
189} 189}
190 190
191int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
192{
193 void *ptr;
194
195 ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
196
197 switch (val_len) {
198 case REGMAP_SIZE_8:
199 *((u8 *)valp) = readb((u8 *)ptr);
200 break;
201 case REGMAP_SIZE_16:
202 *((u16 *)valp) = readw((u16 *)ptr);
203 break;
204 case REGMAP_SIZE_32:
205 *((u32 *)valp) = readl((u32 *)ptr);
206 break;
207#if defined(readq)
208 case REGMAP_SIZE_64:
209 *((u64 *)valp) = readq((u64 *)ptr);
210 break;
211#endif
212 default:
213 debug("%s: regmap size %zu unknown\n", __func__, val_len);
214 return -EINVAL;
215 }
216 return 0;
217}
218
191int regmap_read(struct regmap *map, uint offset, uint *valp) 219int regmap_read(struct regmap *map, uint offset, uint *valp)
192{ 220{
193 u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); 221 return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
222}
194 223
195 *valp = le32_to_cpu(readl(ptr)); 224int regmap_raw_write(struct regmap *map, uint offset, const void *val,
225 size_t val_len)
226{
227 void *ptr;
228
229 ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
230
231 switch (val_len) {
232 case REGMAP_SIZE_8:
233 writeb(*((u8 *)val), (u8 *)ptr);
234 break;
235 case REGMAP_SIZE_16:
236 writew(*((u16 *)val), (u16 *)ptr);
237 break;
238 case REGMAP_SIZE_32:
239 writel(*((u32 *)val), (u32 *)ptr);
240 break;
241#if defined(writeq)
242 case REGMAP_SIZE_64:
243 writeq(*((u64 *)val), (u64 *)ptr);
244 break;
245#endif
246 default:
247 debug("%s: regmap size %zu unknown\n", __func__, val_len);
248 return -EINVAL;
249 }
196 250
197 return 0; 251 return 0;
198} 252}
199 253
200int regmap_write(struct regmap *map, uint offset, uint val) 254int regmap_write(struct regmap *map, uint offset, uint val)
201{ 255{
202 u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); 256 return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);
203
204 writel(cpu_to_le32(val), ptr);
205
206 return 0;
207} 257}
208 258
209int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val) 259int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)