17
17
#include <linux/delay.h>
18
18
#include <linux/log2.h>
19
19
#include <linux/hwspinlock.h>
20
+ #include <asm/unaligned.h>
20
21
21
22
#define CREATE_TRACE_POINTS
22
23
#include "trace.h"
@@ -249,22 +250,20 @@ static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
249
250
250
251
static void regmap_format_16_be (void * buf , unsigned int val , unsigned int shift )
251
252
{
252
- __be16 * b = buf ;
253
-
254
- b [0 ] = cpu_to_be16 (val << shift );
253
+ put_unaligned_be16 (val << shift , buf );
255
254
}
256
255
257
256
static void regmap_format_16_le (void * buf , unsigned int val , unsigned int shift )
258
257
{
259
- __le16 * b = buf ;
260
-
261
- b [0 ] = cpu_to_le16 (val << shift );
258
+ put_unaligned_le16 (val << shift , buf );
262
259
}
263
260
264
261
static void regmap_format_16_native (void * buf , unsigned int val ,
265
262
unsigned int shift )
266
263
{
267
- * (u16 * )buf = val << shift ;
264
+ u16 v = val << shift ;
265
+
266
+ memcpy (buf , & v , sizeof (v ));
268
267
}
269
268
270
269
static void regmap_format_24 (void * buf , unsigned int val , unsigned int shift )
@@ -280,43 +279,39 @@ static void regmap_format_24(void *buf, unsigned int val, unsigned int shift)
280
279
281
280
static void regmap_format_32_be (void * buf , unsigned int val , unsigned int shift )
282
281
{
283
- __be32 * b = buf ;
284
-
285
- b [0 ] = cpu_to_be32 (val << shift );
282
+ put_unaligned_be32 (val << shift , buf );
286
283
}
287
284
288
285
static void regmap_format_32_le (void * buf , unsigned int val , unsigned int shift )
289
286
{
290
- __le32 * b = buf ;
291
-
292
- b [0 ] = cpu_to_le32 (val << shift );
287
+ put_unaligned_le32 (val << shift , buf );
293
288
}
294
289
295
290
static void regmap_format_32_native (void * buf , unsigned int val ,
296
291
unsigned int shift )
297
292
{
298
- * (u32 * )buf = val << shift ;
293
+ u32 v = val << shift ;
294
+
295
+ memcpy (buf , & v , sizeof (v ));
299
296
}
300
297
301
298
#ifdef CONFIG_64BIT
302
299
static void regmap_format_64_be (void * buf , unsigned int val , unsigned int shift )
303
300
{
304
- __be64 * b = buf ;
305
-
306
- b [0 ] = cpu_to_be64 ((u64 )val << shift );
301
+ put_unaligned_be64 ((u64 ) val << shift , buf );
307
302
}
308
303
309
304
static void regmap_format_64_le (void * buf , unsigned int val , unsigned int shift )
310
305
{
311
- __le64 * b = buf ;
312
-
313
- b [0 ] = cpu_to_le64 ((u64 )val << shift );
306
+ put_unaligned_le64 ((u64 ) val << shift , buf );
314
307
}
315
308
316
309
static void regmap_format_64_native (void * buf , unsigned int val ,
317
310
unsigned int shift )
318
311
{
319
- * (u64 * )buf = (u64 )val << shift ;
312
+ u64 v = (u64 ) val << shift ;
313
+
314
+ memcpy (buf , & v , sizeof (v ));
320
315
}
321
316
#endif
322
317
@@ -333,35 +328,34 @@ static unsigned int regmap_parse_8(const void *buf)
333
328
334
329
static unsigned int regmap_parse_16_be (const void * buf )
335
330
{
336
- const __be16 * b = buf ;
337
-
338
- return be16_to_cpu (b [0 ]);
331
+ return get_unaligned_be16 (buf );
339
332
}
340
333
341
334
static unsigned int regmap_parse_16_le (const void * buf )
342
335
{
343
- const __le16 * b = buf ;
344
-
345
- return le16_to_cpu (b [0 ]);
336
+ return get_unaligned_le16 (buf );
346
337
}
347
338
348
339
static void regmap_parse_16_be_inplace (void * buf )
349
340
{
350
- __be16 * b = buf ;
341
+ u16 v = get_unaligned_be16 ( buf ) ;
351
342
352
- b [ 0 ] = be16_to_cpu ( b [ 0 ] );
343
+ memcpy ( buf , & v , sizeof ( v ) );
353
344
}
354
345
355
346
static void regmap_parse_16_le_inplace (void * buf )
356
347
{
357
- __le16 * b = buf ;
348
+ u16 v = get_unaligned_le16 ( buf ) ;
358
349
359
- b [ 0 ] = le16_to_cpu ( b [ 0 ] );
350
+ memcpy ( buf , & v , sizeof ( v ) );
360
351
}
361
352
362
353
static unsigned int regmap_parse_16_native (const void * buf )
363
354
{
364
- return * (u16 * )buf ;
355
+ u16 v ;
356
+
357
+ memcpy (& v , buf , sizeof (v ));
358
+ return v ;
365
359
}
366
360
367
361
static unsigned int regmap_parse_24 (const void * buf )
@@ -376,69 +370,67 @@ static unsigned int regmap_parse_24(const void *buf)
376
370
377
371
static unsigned int regmap_parse_32_be (const void * buf )
378
372
{
379
- const __be32 * b = buf ;
380
-
381
- return be32_to_cpu (b [0 ]);
373
+ return get_unaligned_be32 (buf );
382
374
}
383
375
384
376
static unsigned int regmap_parse_32_le (const void * buf )
385
377
{
386
- const __le32 * b = buf ;
387
-
388
- return le32_to_cpu (b [0 ]);
378
+ return get_unaligned_le32 (buf );
389
379
}
390
380
391
381
static void regmap_parse_32_be_inplace (void * buf )
392
382
{
393
- __be32 * b = buf ;
383
+ u32 v = get_unaligned_be32 ( buf ) ;
394
384
395
- b [ 0 ] = be32_to_cpu ( b [ 0 ] );
385
+ memcpy ( buf , & v , sizeof ( v ) );
396
386
}
397
387
398
388
static void regmap_parse_32_le_inplace (void * buf )
399
389
{
400
- __le32 * b = buf ;
390
+ u32 v = get_unaligned_le32 ( buf ) ;
401
391
402
- b [ 0 ] = le32_to_cpu ( b [ 0 ] );
392
+ memcpy ( buf , & v , sizeof ( v ) );
403
393
}
404
394
405
395
static unsigned int regmap_parse_32_native (const void * buf )
406
396
{
407
- return * (u32 * )buf ;
397
+ u32 v ;
398
+
399
+ memcpy (& v , buf , sizeof (v ));
400
+ return v ;
408
401
}
409
402
410
403
#ifdef CONFIG_64BIT
411
404
static unsigned int regmap_parse_64_be (const void * buf )
412
405
{
413
- const __be64 * b = buf ;
414
-
415
- return be64_to_cpu (b [0 ]);
406
+ return get_unaligned_be64 (buf );
416
407
}
417
408
418
409
static unsigned int regmap_parse_64_le (const void * buf )
419
410
{
420
- const __le64 * b = buf ;
421
-
422
- return le64_to_cpu (b [0 ]);
411
+ return get_unaligned_le64 (buf );
423
412
}
424
413
425
414
static void regmap_parse_64_be_inplace (void * buf )
426
415
{
427
- __be64 * b = buf ;
416
+ u64 v = get_unaligned_be64 ( buf ) ;
428
417
429
- b [ 0 ] = be64_to_cpu ( b [ 0 ] );
418
+ memcpy ( buf , & v , sizeof ( v ) );
430
419
}
431
420
432
421
static void regmap_parse_64_le_inplace (void * buf )
433
422
{
434
- __le64 * b = buf ;
423
+ u64 v = get_unaligned_le64 ( buf ) ;
435
424
436
- b [ 0 ] = le64_to_cpu ( b [ 0 ] );
425
+ memcpy ( buf , & v , sizeof ( v ) );
437
426
}
438
427
439
428
static unsigned int regmap_parse_64_native (const void * buf )
440
429
{
441
- return * (u64 * )buf ;
430
+ u64 v ;
431
+
432
+ memcpy (& v , buf , sizeof (v ));
433
+ return v ;
442
434
}
443
435
#endif
444
436
@@ -2944,8 +2936,9 @@ EXPORT_SYMBOL_GPL(regmap_update_bits_base);
2944
2936
* @reg: Register to read from
2945
2937
* @bits: Bits to test
2946
2938
*
2947
- * Returns -1 if the underlying regmap_read() fails, 0 if at least one of the
2948
- * tested bits is not set and 1 if all tested bits are set.
2939
+ * Returns 0 if at least one of the tested bits is not set, 1 if all tested
2940
+ * bits are set and a negative error number if the underlying regmap_read()
2941
+ * fails.
2949
2942
*/
2950
2943
int regmap_test_bits (struct regmap * map , unsigned int reg , unsigned int bits )
2951
2944
{
0 commit comments