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