1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Register map access API - AC'97 support
4 //
5 // Copyright 2013 Linaro Ltd. All rights reserved.
6
7 #include <linux/clk.h>
8 #include <linux/err.h>
9 #include <linux/init.h>
10 #include <linux/io.h>
11 #include <linux/module.h>
12 #include <linux/regmap.h>
13 #include <linux/slab.h>
14
15 #include <sound/ac97_codec.h>
16
regmap_ac97_default_volatile(struct device * dev,unsigned int reg)17 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg)
18 {
19 switch (reg) {
20 case AC97_RESET:
21 case AC97_POWERDOWN:
22 case AC97_INT_PAGING:
23 case AC97_EXTENDED_ID:
24 case AC97_EXTENDED_STATUS:
25 case AC97_EXTENDED_MID:
26 case AC97_EXTENDED_MSTATUS:
27 case AC97_GPIO_STATUS:
28 case AC97_MISC_AFE:
29 case AC97_VENDOR_ID1:
30 case AC97_VENDOR_ID2:
31 case AC97_CODEC_CLASS_REV:
32 case AC97_PCI_SVID:
33 case AC97_PCI_SID:
34 case AC97_FUNC_SELECT:
35 case AC97_FUNC_INFO:
36 case AC97_SENSE_INFO:
37 return true;
38 default:
39 return false;
40 }
41 }
42 EXPORT_SYMBOL_GPL(regmap_ac97_default_volatile);
43
regmap_ac97_reg_read(void * context,unsigned int reg,unsigned int * val)44 static int regmap_ac97_reg_read(void *context, unsigned int reg,
45 unsigned int *val)
46 {
47 struct snd_ac97 *ac97 = context;
48
49 *val = ac97->bus->ops->read(ac97, reg);
50
51 return 0;
52 }
53
regmap_ac97_reg_write(void * context,unsigned int reg,unsigned int val)54 static int regmap_ac97_reg_write(void *context, unsigned int reg,
55 unsigned int val)
56 {
57 struct snd_ac97 *ac97 = context;
58
59 ac97->bus->ops->write(ac97, reg, val);
60
61 return 0;
62 }
63
64 static const struct regmap_bus ac97_regmap_bus = {
65 .reg_write = regmap_ac97_reg_write,
66 .reg_read = regmap_ac97_reg_read,
67 };
68
__regmap_init_ac97(struct snd_ac97 * ac97,const struct regmap_config * config,struct lock_class_key * lock_key,const char * lock_name)69 struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
70 const struct regmap_config *config,
71 struct lock_class_key *lock_key,
72 const char *lock_name)
73 {
74 return __regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config,
75 lock_key, lock_name);
76 }
77 EXPORT_SYMBOL_GPL(__regmap_init_ac97);
78
__devm_regmap_init_ac97(struct snd_ac97 * ac97,const struct regmap_config * config,struct lock_class_key * lock_key,const char * lock_name)79 struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
80 const struct regmap_config *config,
81 struct lock_class_key *lock_key,
82 const char *lock_name)
83 {
84 return __devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config,
85 lock_key, lock_name);
86 }
87 EXPORT_SYMBOL_GPL(__devm_regmap_init_ac97);
88
89 MODULE_DESCRIPTION("Register map access API - AC'97 support");
90 MODULE_LICENSE("GPL v2");
91