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