Greg Kroah-Hartman | 37613fa | 2019-04-25 20:06:18 +0200 | [diff] [blame] | 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. |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 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 | |
| 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 | |
| 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 | |
| 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 = { |
Mark Brown | 927db287 | 2015-02-02 12:13:31 +0000 | [diff] [blame] | 65 | .reg_write = regmap_ac97_reg_write, |
| 66 | .reg_read = regmap_ac97_reg_read, |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 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) |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 73 | { |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 74 | return __regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config, |
| 75 | lock_key, lock_name); |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 76 | } |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 77 | EXPORT_SYMBOL_GPL(__regmap_init_ac97); |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 78 | |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 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) |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 83 | { |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 84 | return __devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config, |
| 85 | lock_key, lock_name); |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 86 | } |
Nicolas Boichat | 3cfe7a7 | 2015-07-08 14:30:18 +0800 | [diff] [blame] | 87 | EXPORT_SYMBOL_GPL(__devm_regmap_init_ac97); |
Mark Brown | 2285322 | 2014-11-18 19:45:51 +0100 | [diff] [blame] | 88 | |
| 89 | MODULE_LICENSE("GPL v2"); |