1
2#ifndef __LINUX_REGMAP_H
3#define __LINUX_REGMAP_H
4
5
6
7
8
9
10
11
12
13#include <linux/list.h>
14#include <linux/rbtree.h>
15#include <linux/ktime.h>
16#include <linux/delay.h>
17#include <linux/err.h>
18#include <linux/bug.h>
19#include <linux/lockdep.h>
20#include <linux/iopoll.h>
21#include <linux/fwnode.h>
22
23struct module;
24struct clk;
25struct device;
26struct device_node;
27struct i2c_client;
28struct i3c_device;
29struct irq_domain;
30struct slim_device;
31struct spi_device;
32struct spmi_device;
33struct regmap;
34struct regmap_range_cfg;
35struct regmap_field;
36struct snd_ac97;
37struct sdw_slave;
38
39
40enum regcache_type {
41 REGCACHE_NONE,
42 REGCACHE_RBTREE,
43 REGCACHE_COMPRESSED,
44 REGCACHE_FLAT,
45};
46
47
48
49
50
51
52
53
54
55
56struct reg_default {
57 unsigned int reg;
58 unsigned int def;
59};
60
61
62
63
64
65
66
67
68
69
70
71struct reg_sequence {
72 unsigned int reg;
73 unsigned int def;
74 unsigned int delay_us;
75};
76
77#define REG_SEQ(_reg, _def, _delay_us) { \
78 .reg = _reg, \
79 .def = _def, \
80 .delay_us = _delay_us, \
81 }
82#define REG_SEQ0(_reg, _def) REG_SEQ(_reg, _def, 0)
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
104({ \
105 int __ret, __tmp; \
106 __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
107 sleep_us, timeout_us, false, (map), (addr), &(val)); \
108 __ret ?: __tmp; \
109})
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133#define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
134({ \
135 u64 __timeout_us = (timeout_us); \
136 unsigned long __delay_us = (delay_us); \
137 ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
138 int __ret; \
139 for (;;) { \
140 __ret = regmap_read((map), (addr), &(val)); \
141 if (__ret) \
142 break; \
143 if (cond) \
144 break; \
145 if ((__timeout_us) && \
146 ktime_compare(ktime_get(), __timeout) > 0) { \
147 __ret = regmap_read((map), (addr), &(val)); \
148 break; \
149 } \
150 if (__delay_us) \
151 udelay(__delay_us); \
152 } \
153 __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
154})
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
175({ \
176 int __ret, __tmp; \
177 __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
178 sleep_us, timeout_us, false, (field), &(val)); \
179 __ret ?: __tmp; \
180})
181
182#ifdef CONFIG_REGMAP
183
184enum regmap_endian {
185
186 REGMAP_ENDIAN_DEFAULT = 0,
187 REGMAP_ENDIAN_BIG,
188 REGMAP_ENDIAN_LITTLE,
189 REGMAP_ENDIAN_NATIVE,
190};
191
192
193
194
195
196
197
198
199struct regmap_range {
200 unsigned int range_min;
201 unsigned int range_max;
202};
203
204#define regmap_reg_range(low, high) { .range_min = low, .range_max = high, }
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219struct regmap_access_table {
220 const struct regmap_range *yes_ranges;
221 unsigned int n_yes_ranges;
222 const struct regmap_range *no_ranges;
223 unsigned int n_no_ranges;
224};
225
226typedef void (*regmap_lock)(void *);
227typedef void (*regmap_unlock)(void *);
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347struct regmap_config {
348 const char *name;
349
350 int reg_bits;
351 int reg_stride;
352 int pad_bits;
353 int val_bits;
354
355 bool (*writeable_reg)(struct device *dev, unsigned int reg);
356 bool (*readable_reg)(struct device *dev, unsigned int reg);
357 bool (*volatile_reg)(struct device *dev, unsigned int reg);
358 bool (*precious_reg)(struct device *dev, unsigned int reg);
359 bool (*writeable_noinc_reg)(struct device *dev, unsigned int reg);
360 bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
361
362 bool disable_locking;
363 regmap_lock lock;
364 regmap_unlock unlock;
365 void *lock_arg;
366
367 int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
368 int (*reg_write)(void *context, unsigned int reg, unsigned int val);
369
370 bool fast_io;
371
372 unsigned int max_register;
373 const struct regmap_access_table *wr_table;
374 const struct regmap_access_table *rd_table;
375 const struct regmap_access_table *volatile_table;
376 const struct regmap_access_table *precious_table;
377 const struct regmap_access_table *wr_noinc_table;
378 const struct regmap_access_table *rd_noinc_table;
379 const struct reg_default *reg_defaults;
380 unsigned int num_reg_defaults;
381 enum regcache_type cache_type;
382 const void *reg_defaults_raw;
383 unsigned int num_reg_defaults_raw;
384
385 unsigned long read_flag_mask;
386 unsigned long write_flag_mask;
387 bool zero_flag_mask;
388
389 bool use_single_read;
390 bool use_single_write;
391 bool can_multi_write;
392
393 enum regmap_endian reg_format_endian;
394 enum regmap_endian val_format_endian;
395
396 const struct regmap_range_cfg *ranges;
397 unsigned int num_ranges;
398
399 bool use_hwlock;
400 unsigned int hwlock_id;
401 unsigned int hwlock_mode;
402
403 bool can_sleep;
404};
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426struct regmap_range_cfg {
427 const char *name;
428
429
430 unsigned int range_min;
431 unsigned int range_max;
432
433
434 unsigned int selector_reg;
435 unsigned int selector_mask;
436 int selector_shift;
437
438
439 unsigned int window_start;
440 unsigned int window_len;
441};
442
443struct regmap_async;
444
445typedef int (*regmap_hw_write)(void *context, const void *data,
446 size_t count);
447typedef int (*regmap_hw_gather_write)(void *context,
448 const void *reg, size_t reg_len,
449 const void *val, size_t val_len);
450typedef int (*regmap_hw_async_write)(void *context,
451 const void *reg, size_t reg_len,
452 const void *val, size_t val_len,
453 struct regmap_async *async);
454typedef int (*regmap_hw_read)(void *context,
455 const void *reg_buf, size_t reg_size,
456 void *val_buf, size_t val_size);
457typedef int (*regmap_hw_reg_read)(void *context, unsigned int reg,
458 unsigned int *val);
459typedef int (*regmap_hw_reg_write)(void *context, unsigned int reg,
460 unsigned int val);
461typedef int (*regmap_hw_reg_update_bits)(void *context, unsigned int reg,
462 unsigned int mask, unsigned int val);
463typedef struct regmap_async *(*regmap_hw_async_alloc)(void);
464typedef void (*regmap_hw_free_context)(void *context);
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501struct regmap_bus {
502 bool fast_io;
503 regmap_hw_write write;
504 regmap_hw_gather_write gather_write;
505 regmap_hw_async_write async_write;
506 regmap_hw_reg_write reg_write;
507 regmap_hw_reg_update_bits reg_update_bits;
508 regmap_hw_read read;
509 regmap_hw_reg_read reg_read;
510 regmap_hw_free_context free_context;
511 regmap_hw_async_alloc async_alloc;
512 u8 read_flag_mask;
513 enum regmap_endian reg_format_endian_default;
514 enum regmap_endian val_format_endian_default;
515 size_t max_raw_read;
516 size_t max_raw_write;
517};
518
519
520
521
522
523
524
525
526struct regmap *__regmap_init(struct device *dev,
527 const struct regmap_bus *bus,
528 void *bus_context,
529 const struct regmap_config *config,
530 struct lock_class_key *lock_key,
531 const char *lock_name);
532struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
533 const struct regmap_config *config,
534 struct lock_class_key *lock_key,
535 const char *lock_name);
536struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
537 const struct regmap_config *config,
538 struct lock_class_key *lock_key,
539 const char *lock_name);
540struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
541 const struct regmap_config *config,
542 struct lock_class_key *lock_key,
543 const char *lock_name);
544struct regmap *__regmap_init_spi(struct spi_device *dev,
545 const struct regmap_config *config,
546 struct lock_class_key *lock_key,
547 const char *lock_name);
548struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
549 const struct regmap_config *config,
550 struct lock_class_key *lock_key,
551 const char *lock_name);
552struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
553 const struct regmap_config *config,
554 struct lock_class_key *lock_key,
555 const char *lock_name);
556struct regmap *__regmap_init_w1(struct device *w1_dev,
557 const struct regmap_config *config,
558 struct lock_class_key *lock_key,
559 const char *lock_name);
560struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
561 void __iomem *regs,
562 const struct regmap_config *config,
563 struct lock_class_key *lock_key,
564 const char *lock_name);
565struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
566 const struct regmap_config *config,
567 struct lock_class_key *lock_key,
568 const char *lock_name);
569struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
570 const struct regmap_config *config,
571 struct lock_class_key *lock_key,
572 const char *lock_name);
573struct regmap *__regmap_init_spi_avmm(struct spi_device *spi,
574 const struct regmap_config *config,
575 struct lock_class_key *lock_key,
576 const char *lock_name);
577
578struct regmap *__devm_regmap_init(struct device *dev,
579 const struct regmap_bus *bus,
580 void *bus_context,
581 const struct regmap_config *config,
582 struct lock_class_key *lock_key,
583 const char *lock_name);
584struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
585 const struct regmap_config *config,
586 struct lock_class_key *lock_key,
587 const char *lock_name);
588struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
589 const struct regmap_config *config,
590 struct lock_class_key *lock_key,
591 const char *lock_name);
592struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
593 const struct regmap_config *config,
594 struct lock_class_key *lock_key,
595 const char *lock_name);
596struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
597 const struct regmap_config *config,
598 struct lock_class_key *lock_key,
599 const char *lock_name);
600struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
601 const struct regmap_config *config,
602 struct lock_class_key *lock_key,
603 const char *lock_name);
604struct regmap *__devm_regmap_init_w1(struct device *w1_dev,
605 const struct regmap_config *config,
606 struct lock_class_key *lock_key,
607 const char *lock_name);
608struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
609 const char *clk_id,
610 void __iomem *regs,
611 const struct regmap_config *config,
612 struct lock_class_key *lock_key,
613 const char *lock_name);
614struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
615 const struct regmap_config *config,
616 struct lock_class_key *lock_key,
617 const char *lock_name);
618struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
619 const struct regmap_config *config,
620 struct lock_class_key *lock_key,
621 const char *lock_name);
622struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
623 const struct regmap_config *config,
624 struct lock_class_key *lock_key,
625 const char *lock_name);
626struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
627 const struct regmap_config *config,
628 struct lock_class_key *lock_key,
629 const char *lock_name);
630struct regmap *__devm_regmap_init_spi_avmm(struct spi_device *spi,
631 const struct regmap_config *config,
632 struct lock_class_key *lock_key,
633 const char *lock_name);
634
635
636
637
638
639
640
641#ifdef CONFIG_LOCKDEP
642#define __regmap_lockdep_wrapper(fn, name, ...) \
643( \
644 ({ \
645 static struct lock_class_key _key; \
646 fn(__VA_ARGS__, &_key, \
647 KBUILD_BASENAME ":" \
648 __stringify(__LINE__) ":" \
649 "(" name ")->lock"); \
650 }) \
651)
652#else
653#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
654#endif
655
656
657
658
659
660
661
662
663
664
665
666
667
668#define regmap_init(dev, bus, bus_context, config) \
669 __regmap_lockdep_wrapper(__regmap_init, #config, \
670 dev, bus, bus_context, config)
671int regmap_attach_dev(struct device *dev, struct regmap *map,
672 const struct regmap_config *config);
673
674
675
676
677
678
679
680
681
682
683#define regmap_init_i2c(i2c, config) \
684 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
685 i2c, config)
686
687
688
689
690
691
692
693
694
695
696#define regmap_init_sccb(i2c, config) \
697 __regmap_lockdep_wrapper(__regmap_init_sccb, #config, \
698 i2c, config)
699
700
701
702
703
704
705
706
707
708
709#define regmap_init_slimbus(slimbus, config) \
710 __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
711 slimbus, config)
712
713
714
715
716
717
718
719
720
721
722#define regmap_init_spi(dev, config) \
723 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
724 dev, config)
725
726
727
728
729
730
731
732
733
734
735#define regmap_init_spmi_base(dev, config) \
736 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
737 dev, config)
738
739
740
741
742
743
744
745
746
747
748#define regmap_init_spmi_ext(dev, config) \
749 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
750 dev, config)
751
752
753
754
755
756
757
758
759
760
761#define regmap_init_w1(w1_dev, config) \
762 __regmap_lockdep_wrapper(__regmap_init_w1, #config, \
763 w1_dev, config)
764
765
766
767
768
769
770
771
772
773
774
775
776#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
777 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
778 dev, clk_id, regs, config)
779
780
781
782
783
784
785
786
787
788
789
790#define regmap_init_mmio(dev, regs, config) \
791 regmap_init_mmio_clk(dev, NULL, regs, config)
792
793
794
795
796
797
798
799
800
801
802#define regmap_init_ac97(ac97, config) \
803 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
804 ac97, config)
805bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
806
807
808
809
810
811
812
813
814
815
816#define regmap_init_sdw(sdw, config) \
817 __regmap_lockdep_wrapper(__regmap_init_sdw, #config, \
818 sdw, config)
819
820
821
822
823
824
825
826
827
828
829
830#define regmap_init_spi_avmm(spi, config) \
831 __regmap_lockdep_wrapper(__regmap_init_spi_avmm, #config, \
832 spi, config)
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847#define devm_regmap_init(dev, bus, bus_context, config) \
848 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
849 dev, bus, bus_context, config)
850
851
852
853
854
855
856
857
858
859
860
861#define devm_regmap_init_i2c(i2c, config) \
862 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
863 i2c, config)
864
865
866
867
868
869
870
871
872
873
874
875#define devm_regmap_init_sccb(i2c, config) \
876 __regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config, \
877 i2c, config)
878
879
880
881
882
883
884
885
886
887
888
889#define devm_regmap_init_spi(dev, config) \
890 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
891 dev, config)
892
893
894
895
896
897
898
899
900
901
902
903#define devm_regmap_init_spmi_base(dev, config) \
904 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
905 dev, config)
906
907
908
909
910
911
912
913
914
915
916
917#define devm_regmap_init_spmi_ext(dev, config) \
918 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
919 dev, config)
920
921
922
923
924
925
926
927
928
929
930
931#define devm_regmap_init_w1(w1_dev, config) \
932 __regmap_lockdep_wrapper(__devm_regmap_init_w1, #config, \
933 w1_dev, config)
934
935
936
937
938
939
940
941
942
943
944
945
946#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
947 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
948 dev, clk_id, regs, config)
949
950
951
952
953
954
955
956
957
958
959
960
961#define devm_regmap_init_mmio(dev, regs, config) \
962 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
963
964
965
966
967
968
969
970
971
972
973
974#define devm_regmap_init_ac97(ac97, config) \
975 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
976 ac97, config)
977
978
979
980
981
982
983
984
985
986
987
988#define devm_regmap_init_sdw(sdw, config) \
989 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
990 sdw, config)
991
992
993
994
995
996
997
998
999
1000
1001
1002#define devm_regmap_init_slimbus(slimbus, config) \
1003 __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \
1004 slimbus, config)
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016#define devm_regmap_init_i3c(i3c, config) \
1017 __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \
1018 i3c, config)
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031#define devm_regmap_init_spi_avmm(spi, config) \
1032 __regmap_lockdep_wrapper(__devm_regmap_init_spi_avmm, #config, \
1033 spi, config)
1034
1035int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
1036void regmap_mmio_detach_clk(struct regmap *map);
1037void regmap_exit(struct regmap *map);
1038int regmap_reinit_cache(struct regmap *map,
1039 const struct regmap_config *config);
1040struct regmap *dev_get_regmap(struct device *dev, const char *name);
1041struct device *regmap_get_device(struct regmap *map);
1042int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
1043int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val);
1044int regmap_raw_write(struct regmap *map, unsigned int reg,
1045 const void *val, size_t val_len);
1046int regmap_noinc_write(struct regmap *map, unsigned int reg,
1047 const void *val, size_t val_len);
1048int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
1049 size_t val_count);
1050int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
1051 int num_regs);
1052int regmap_multi_reg_write_bypassed(struct regmap *map,
1053 const struct reg_sequence *regs,
1054 int num_regs);
1055int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1056 const void *val, size_t val_len);
1057int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
1058int regmap_raw_read(struct regmap *map, unsigned int reg,
1059 void *val, size_t val_len);
1060int regmap_noinc_read(struct regmap *map, unsigned int reg,
1061 void *val, size_t val_len);
1062int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
1063 size_t val_count);
1064int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1065 unsigned int mask, unsigned int val,
1066 bool *change, bool async, bool force);
1067
1068static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1069 unsigned int mask, unsigned int val)
1070{
1071 return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
1072}
1073
1074static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1075 unsigned int mask, unsigned int val)
1076{
1077 return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
1078}
1079
1080static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1081 unsigned int mask, unsigned int val,
1082 bool *change)
1083{
1084 return regmap_update_bits_base(map, reg, mask, val,
1085 change, false, false);
1086}
1087
1088static inline int
1089regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1090 unsigned int mask, unsigned int val,
1091 bool *change)
1092{
1093 return regmap_update_bits_base(map, reg, mask, val,
1094 change, true, false);
1095}
1096
1097static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1098 unsigned int mask, unsigned int val)
1099{
1100 return regmap_update_bits_base(map, reg, mask, val, NULL, false, true);
1101}
1102
1103int regmap_get_val_bytes(struct regmap *map);
1104int regmap_get_max_register(struct regmap *map);
1105int regmap_get_reg_stride(struct regmap *map);
1106int regmap_async_complete(struct regmap *map);
1107bool regmap_can_raw_write(struct regmap *map);
1108size_t regmap_get_raw_read_max(struct regmap *map);
1109size_t regmap_get_raw_write_max(struct regmap *map);
1110
1111int regcache_sync(struct regmap *map);
1112int regcache_sync_region(struct regmap *map, unsigned int min,
1113 unsigned int max);
1114int regcache_drop_region(struct regmap *map, unsigned int min,
1115 unsigned int max);
1116void regcache_cache_only(struct regmap *map, bool enable);
1117void regcache_cache_bypass(struct regmap *map, bool enable);
1118void regcache_mark_dirty(struct regmap *map);
1119
1120bool regmap_check_range_table(struct regmap *map, unsigned int reg,
1121 const struct regmap_access_table *table);
1122
1123int regmap_register_patch(struct regmap *map, const struct reg_sequence *regs,
1124 int num_regs);
1125int regmap_parse_val(struct regmap *map, const void *buf,
1126 unsigned int *val);
1127
1128static inline bool regmap_reg_in_range(unsigned int reg,
1129 const struct regmap_range *range)
1130{
1131 return reg >= range->range_min && reg <= range->range_max;
1132}
1133
1134bool regmap_reg_in_ranges(unsigned int reg,
1135 const struct regmap_range *ranges,
1136 unsigned int nranges);
1137
1138static inline int regmap_set_bits(struct regmap *map,
1139 unsigned int reg, unsigned int bits)
1140{
1141 return regmap_update_bits_base(map, reg, bits, bits,
1142 NULL, false, false);
1143}
1144
1145static inline int regmap_clear_bits(struct regmap *map,
1146 unsigned int reg, unsigned int bits)
1147{
1148 return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
1149}
1150
1151int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162struct reg_field {
1163 unsigned int reg;
1164 unsigned int lsb;
1165 unsigned int msb;
1166 unsigned int id_size;
1167 unsigned int id_offset;
1168};
1169
1170#define REG_FIELD(_reg, _lsb, _msb) { \
1171 .reg = _reg, \
1172 .lsb = _lsb, \
1173 .msb = _msb, \
1174 }
1175
1176#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \
1177 .reg = _reg, \
1178 .lsb = _lsb, \
1179 .msb = _msb, \
1180 .id_size = _size, \
1181 .id_offset = _offset, \
1182 }
1183
1184struct regmap_field *regmap_field_alloc(struct regmap *regmap,
1185 struct reg_field reg_field);
1186void regmap_field_free(struct regmap_field *field);
1187
1188struct regmap_field *devm_regmap_field_alloc(struct device *dev,
1189 struct regmap *regmap, struct reg_field reg_field);
1190void devm_regmap_field_free(struct device *dev, struct regmap_field *field);
1191
1192int regmap_field_bulk_alloc(struct regmap *regmap,
1193 struct regmap_field **rm_field,
1194 struct reg_field *reg_field,
1195 int num_fields);
1196void regmap_field_bulk_free(struct regmap_field *field);
1197int devm_regmap_field_bulk_alloc(struct device *dev, struct regmap *regmap,
1198 struct regmap_field **field,
1199 struct reg_field *reg_field, int num_fields);
1200void devm_regmap_field_bulk_free(struct device *dev,
1201 struct regmap_field *field);
1202
1203int regmap_field_read(struct regmap_field *field, unsigned int *val);
1204int regmap_field_update_bits_base(struct regmap_field *field,
1205 unsigned int mask, unsigned int val,
1206 bool *change, bool async, bool force);
1207int regmap_fields_read(struct regmap_field *field, unsigned int id,
1208 unsigned int *val);
1209int regmap_fields_update_bits_base(struct regmap_field *field, unsigned int id,
1210 unsigned int mask, unsigned int val,
1211 bool *change, bool async, bool force);
1212
1213static inline int regmap_field_write(struct regmap_field *field,
1214 unsigned int val)
1215{
1216 return regmap_field_update_bits_base(field, ~0, val,
1217 NULL, false, false);
1218}
1219
1220static inline int regmap_field_force_write(struct regmap_field *field,
1221 unsigned int val)
1222{
1223 return regmap_field_update_bits_base(field, ~0, val, NULL, false, true);
1224}
1225
1226static inline int regmap_field_update_bits(struct regmap_field *field,
1227 unsigned int mask, unsigned int val)
1228{
1229 return regmap_field_update_bits_base(field, mask, val,
1230 NULL, false, false);
1231}
1232
1233static inline int
1234regmap_field_force_update_bits(struct regmap_field *field,
1235 unsigned int mask, unsigned int val)
1236{
1237 return regmap_field_update_bits_base(field, mask, val,
1238 NULL, false, true);
1239}
1240
1241static inline int regmap_fields_write(struct regmap_field *field,
1242 unsigned int id, unsigned int val)
1243{
1244 return regmap_fields_update_bits_base(field, id, ~0, val,
1245 NULL, false, false);
1246}
1247
1248static inline int regmap_fields_force_write(struct regmap_field *field,
1249 unsigned int id, unsigned int val)
1250{
1251 return regmap_fields_update_bits_base(field, id, ~0, val,
1252 NULL, false, true);
1253}
1254
1255static inline int
1256regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1257 unsigned int mask, unsigned int val)
1258{
1259 return regmap_fields_update_bits_base(field, id, mask, val,
1260 NULL, false, false);
1261}
1262
1263static inline int
1264regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1265 unsigned int mask, unsigned int val)
1266{
1267 return regmap_fields_update_bits_base(field, id, mask, val,
1268 NULL, false, true);
1269}
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281struct regmap_irq_type {
1282 unsigned int type_reg_offset;
1283 unsigned int type_reg_mask;
1284 unsigned int type_rising_val;
1285 unsigned int type_falling_val;
1286 unsigned int type_level_low_val;
1287 unsigned int type_level_high_val;
1288 unsigned int types_supported;
1289};
1290
1291
1292
1293
1294
1295
1296
1297
1298struct regmap_irq {
1299 unsigned int reg_offset;
1300 unsigned int mask;
1301 struct regmap_irq_type type;
1302};
1303
1304#define REGMAP_IRQ_REG(_irq, _off, _mask) \
1305 [_irq] = { .reg_offset = (_off), .mask = (_mask) }
1306
1307#define REGMAP_IRQ_REG_LINE(_id, _reg_bits) \
1308 [_id] = { \
1309 .mask = BIT((_id) % (_reg_bits)), \
1310 .reg_offset = (_id) / (_reg_bits), \
1311 }
1312
1313#define REGMAP_IRQ_MAIN_REG_OFFSET(arr) \
1314 { .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
1315
1316struct regmap_irq_sub_irq_map {
1317 unsigned int num_regs;
1318 unsigned int *offset;
1319};
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387struct regmap_irq_chip {
1388 const char *name;
1389
1390 unsigned int main_status;
1391 unsigned int num_main_status_bits;
1392 struct regmap_irq_sub_irq_map *sub_reg_offsets;
1393 int num_main_regs;
1394
1395 unsigned int status_base;
1396 unsigned int mask_base;
1397 unsigned int unmask_base;
1398 unsigned int ack_base;
1399 unsigned int wake_base;
1400 unsigned int type_base;
1401 unsigned int irq_reg_stride;
1402 bool mask_writeonly:1;
1403 bool init_ack_masked:1;
1404 bool mask_invert:1;
1405 bool use_ack:1;
1406 bool ack_invert:1;
1407 bool clear_ack:1;
1408 bool wake_invert:1;
1409 bool runtime_pm:1;
1410 bool type_invert:1;
1411 bool type_in_mask:1;
1412 bool clear_on_unmask:1;
1413
1414 int num_regs;
1415
1416 const struct regmap_irq *irqs;
1417 int num_irqs;
1418
1419 int num_type_reg;
1420 unsigned int type_reg_stride;
1421
1422 int (*handle_pre_irq)(void *irq_drv_data);
1423 int (*handle_post_irq)(void *irq_drv_data);
1424 void *irq_drv_data;
1425};
1426
1427struct regmap_irq_chip_data;
1428
1429int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
1430 int irq_base, const struct regmap_irq_chip *chip,
1431 struct regmap_irq_chip_data **data);
1432int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
1433 struct regmap *map, int irq,
1434 int irq_flags, int irq_base,
1435 const struct regmap_irq_chip *chip,
1436 struct regmap_irq_chip_data **data);
1437void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
1438
1439int devm_regmap_add_irq_chip(struct device *dev, struct regmap *map, int irq,
1440 int irq_flags, int irq_base,
1441 const struct regmap_irq_chip *chip,
1442 struct regmap_irq_chip_data **data);
1443int devm_regmap_add_irq_chip_fwnode(struct device *dev,
1444 struct fwnode_handle *fwnode,
1445 struct regmap *map, int irq,
1446 int irq_flags, int irq_base,
1447 const struct regmap_irq_chip *chip,
1448 struct regmap_irq_chip_data **data);
1449void devm_regmap_del_irq_chip(struct device *dev, int irq,
1450 struct regmap_irq_chip_data *data);
1451
1452int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
1453int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
1454struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
1455
1456#else
1457
1458
1459
1460
1461
1462
1463
1464
1465static inline int regmap_write(struct regmap *map, unsigned int reg,
1466 unsigned int val)
1467{
1468 WARN_ONCE(1, "regmap API is disabled");
1469 return -EINVAL;
1470}
1471
1472static inline int regmap_write_async(struct regmap *map, unsigned int reg,
1473 unsigned int val)
1474{
1475 WARN_ONCE(1, "regmap API is disabled");
1476 return -EINVAL;
1477}
1478
1479static inline int regmap_raw_write(struct regmap *map, unsigned int reg,
1480 const void *val, size_t val_len)
1481{
1482 WARN_ONCE(1, "regmap API is disabled");
1483 return -EINVAL;
1484}
1485
1486static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg,
1487 const void *val, size_t val_len)
1488{
1489 WARN_ONCE(1, "regmap API is disabled");
1490 return -EINVAL;
1491}
1492
1493static inline int regmap_noinc_write(struct regmap *map, unsigned int reg,
1494 const void *val, size_t val_len)
1495{
1496 WARN_ONCE(1, "regmap API is disabled");
1497 return -EINVAL;
1498}
1499
1500static inline int regmap_bulk_write(struct regmap *map, unsigned int reg,
1501 const void *val, size_t val_count)
1502{
1503 WARN_ONCE(1, "regmap API is disabled");
1504 return -EINVAL;
1505}
1506
1507static inline int regmap_read(struct regmap *map, unsigned int reg,
1508 unsigned int *val)
1509{
1510 WARN_ONCE(1, "regmap API is disabled");
1511 return -EINVAL;
1512}
1513
1514static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
1515 void *val, size_t val_len)
1516{
1517 WARN_ONCE(1, "regmap API is disabled");
1518 return -EINVAL;
1519}
1520
1521static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
1522 void *val, size_t val_len)
1523{
1524 WARN_ONCE(1, "regmap API is disabled");
1525 return -EINVAL;
1526}
1527
1528static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
1529 void *val, size_t val_count)
1530{
1531 WARN_ONCE(1, "regmap API is disabled");
1532 return -EINVAL;
1533}
1534
1535static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,
1536 unsigned int mask, unsigned int val,
1537 bool *change, bool async, bool force)
1538{
1539 WARN_ONCE(1, "regmap API is disabled");
1540 return -EINVAL;
1541}
1542
1543static inline int regmap_set_bits(struct regmap *map,
1544 unsigned int reg, unsigned int bits)
1545{
1546 WARN_ONCE(1, "regmap API is disabled");
1547 return -EINVAL;
1548}
1549
1550static inline int regmap_clear_bits(struct regmap *map,
1551 unsigned int reg, unsigned int bits)
1552{
1553 WARN_ONCE(1, "regmap API is disabled");
1554 return -EINVAL;
1555}
1556
1557static inline int regmap_test_bits(struct regmap *map,
1558 unsigned int reg, unsigned int bits)
1559{
1560 WARN_ONCE(1, "regmap API is disabled");
1561 return -EINVAL;
1562}
1563
1564static inline int regmap_field_update_bits_base(struct regmap_field *field,
1565 unsigned int mask, unsigned int val,
1566 bool *change, bool async, bool force)
1567{
1568 WARN_ONCE(1, "regmap API is disabled");
1569 return -EINVAL;
1570}
1571
1572static inline int regmap_fields_update_bits_base(struct regmap_field *field,
1573 unsigned int id,
1574 unsigned int mask, unsigned int val,
1575 bool *change, bool async, bool force)
1576{
1577 WARN_ONCE(1, "regmap API is disabled");
1578 return -EINVAL;
1579}
1580
1581static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
1582 unsigned int mask, unsigned int val)
1583{
1584 WARN_ONCE(1, "regmap API is disabled");
1585 return -EINVAL;
1586}
1587
1588static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
1589 unsigned int mask, unsigned int val)
1590{
1591 WARN_ONCE(1, "regmap API is disabled");
1592 return -EINVAL;
1593}
1594
1595static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
1596 unsigned int mask, unsigned int val,
1597 bool *change)
1598{
1599 WARN_ONCE(1, "regmap API is disabled");
1600 return -EINVAL;
1601}
1602
1603static inline int
1604regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
1605 unsigned int mask, unsigned int val,
1606 bool *change)
1607{
1608 WARN_ONCE(1, "regmap API is disabled");
1609 return -EINVAL;
1610}
1611
1612static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
1613 unsigned int mask, unsigned int val)
1614{
1615 WARN_ONCE(1, "regmap API is disabled");
1616 return -EINVAL;
1617}
1618
1619static inline int regmap_field_write(struct regmap_field *field,
1620 unsigned int val)
1621{
1622 WARN_ONCE(1, "regmap API is disabled");
1623 return -EINVAL;
1624}
1625
1626static inline int regmap_field_force_write(struct regmap_field *field,
1627 unsigned int val)
1628{
1629 WARN_ONCE(1, "regmap API is disabled");
1630 return -EINVAL;
1631}
1632
1633static inline int regmap_field_update_bits(struct regmap_field *field,
1634 unsigned int mask, unsigned int val)
1635{
1636 WARN_ONCE(1, "regmap API is disabled");
1637 return -EINVAL;
1638}
1639
1640static inline int
1641regmap_field_force_update_bits(struct regmap_field *field,
1642 unsigned int mask, unsigned int val)
1643{
1644 WARN_ONCE(1, "regmap API is disabled");
1645 return -EINVAL;
1646}
1647
1648static inline int regmap_fields_write(struct regmap_field *field,
1649 unsigned int id, unsigned int val)
1650{
1651 WARN_ONCE(1, "regmap API is disabled");
1652 return -EINVAL;
1653}
1654
1655static inline int regmap_fields_force_write(struct regmap_field *field,
1656 unsigned int id, unsigned int val)
1657{
1658 WARN_ONCE(1, "regmap API is disabled");
1659 return -EINVAL;
1660}
1661
1662static inline int
1663regmap_fields_update_bits(struct regmap_field *field, unsigned int id,
1664 unsigned int mask, unsigned int val)
1665{
1666 WARN_ONCE(1, "regmap API is disabled");
1667 return -EINVAL;
1668}
1669
1670static inline int
1671regmap_fields_force_update_bits(struct regmap_field *field, unsigned int id,
1672 unsigned int mask, unsigned int val)
1673{
1674 WARN_ONCE(1, "regmap API is disabled");
1675 return -EINVAL;
1676}
1677
1678static inline int regmap_get_val_bytes(struct regmap *map)
1679{
1680 WARN_ONCE(1, "regmap API is disabled");
1681 return -EINVAL;
1682}
1683
1684static inline int regmap_get_max_register(struct regmap *map)
1685{
1686 WARN_ONCE(1, "regmap API is disabled");
1687 return -EINVAL;
1688}
1689
1690static inline int regmap_get_reg_stride(struct regmap *map)
1691{
1692 WARN_ONCE(1, "regmap API is disabled");
1693 return -EINVAL;
1694}
1695
1696static inline int regcache_sync(struct regmap *map)
1697{
1698 WARN_ONCE(1, "regmap API is disabled");
1699 return -EINVAL;
1700}
1701
1702static inline int regcache_sync_region(struct regmap *map, unsigned int min,
1703 unsigned int max)
1704{
1705 WARN_ONCE(1, "regmap API is disabled");
1706 return -EINVAL;
1707}
1708
1709static inline int regcache_drop_region(struct regmap *map, unsigned int min,
1710 unsigned int max)
1711{
1712 WARN_ONCE(1, "regmap API is disabled");
1713 return -EINVAL;
1714}
1715
1716static inline void regcache_cache_only(struct regmap *map, bool enable)
1717{
1718 WARN_ONCE(1, "regmap API is disabled");
1719}
1720
1721static inline void regcache_cache_bypass(struct regmap *map, bool enable)
1722{
1723 WARN_ONCE(1, "regmap API is disabled");
1724}
1725
1726static inline void regcache_mark_dirty(struct regmap *map)
1727{
1728 WARN_ONCE(1, "regmap API is disabled");
1729}
1730
1731static inline void regmap_async_complete(struct regmap *map)
1732{
1733 WARN_ONCE(1, "regmap API is disabled");
1734}
1735
1736static inline int regmap_register_patch(struct regmap *map,
1737 const struct reg_sequence *regs,
1738 int num_regs)
1739{
1740 WARN_ONCE(1, "regmap API is disabled");
1741 return -EINVAL;
1742}
1743
1744static inline int regmap_parse_val(struct regmap *map, const void *buf,
1745 unsigned int *val)
1746{
1747 WARN_ONCE(1, "regmap API is disabled");
1748 return -EINVAL;
1749}
1750
1751static inline struct regmap *dev_get_regmap(struct device *dev,
1752 const char *name)
1753{
1754 return NULL;
1755}
1756
1757static inline struct device *regmap_get_device(struct regmap *map)
1758{
1759 WARN_ONCE(1, "regmap API is disabled");
1760 return NULL;
1761}
1762
1763#endif
1764
1765#endif
1766