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