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