xref: /openbmc/linux/drivers/base/regmap/regmap-ac97.c (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
1*37613fa5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2*37613fa5SGreg Kroah-Hartman //
3*37613fa5SGreg Kroah-Hartman // Register map access API - AC'97 support
4*37613fa5SGreg Kroah-Hartman //
5*37613fa5SGreg Kroah-Hartman // Copyright 2013 Linaro Ltd.  All rights reserved.
622853223SMark Brown 
722853223SMark Brown #include <linux/clk.h>
822853223SMark Brown #include <linux/err.h>
922853223SMark Brown #include <linux/init.h>
1022853223SMark Brown #include <linux/io.h>
1122853223SMark Brown #include <linux/module.h>
1222853223SMark Brown #include <linux/regmap.h>
1322853223SMark Brown #include <linux/slab.h>
1422853223SMark Brown 
1522853223SMark Brown #include <sound/ac97_codec.h>
1622853223SMark Brown 
regmap_ac97_default_volatile(struct device * dev,unsigned int reg)1722853223SMark Brown bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg)
1822853223SMark Brown {
1922853223SMark Brown 	switch (reg) {
2022853223SMark Brown 	case AC97_RESET:
2122853223SMark Brown 	case AC97_POWERDOWN:
2222853223SMark Brown 	case AC97_INT_PAGING:
2322853223SMark Brown 	case AC97_EXTENDED_ID:
2422853223SMark Brown 	case AC97_EXTENDED_STATUS:
2522853223SMark Brown 	case AC97_EXTENDED_MID:
2622853223SMark Brown 	case AC97_EXTENDED_MSTATUS:
2722853223SMark Brown 	case AC97_GPIO_STATUS:
2822853223SMark Brown 	case AC97_MISC_AFE:
2922853223SMark Brown 	case AC97_VENDOR_ID1:
3022853223SMark Brown 	case AC97_VENDOR_ID2:
3122853223SMark Brown 	case AC97_CODEC_CLASS_REV:
3222853223SMark Brown 	case AC97_PCI_SVID:
3322853223SMark Brown 	case AC97_PCI_SID:
3422853223SMark Brown 	case AC97_FUNC_SELECT:
3522853223SMark Brown 	case AC97_FUNC_INFO:
3622853223SMark Brown 	case AC97_SENSE_INFO:
3722853223SMark Brown 		return true;
3822853223SMark Brown 	default:
3922853223SMark Brown 		return false;
4022853223SMark Brown 	}
4122853223SMark Brown }
4222853223SMark Brown EXPORT_SYMBOL_GPL(regmap_ac97_default_volatile);
4322853223SMark Brown 
regmap_ac97_reg_read(void * context,unsigned int reg,unsigned int * val)4422853223SMark Brown static int regmap_ac97_reg_read(void *context, unsigned int reg,
4522853223SMark Brown 	unsigned int *val)
4622853223SMark Brown {
4722853223SMark Brown 	struct snd_ac97 *ac97 = context;
4822853223SMark Brown 
4922853223SMark Brown 	*val = ac97->bus->ops->read(ac97, reg);
5022853223SMark Brown 
5122853223SMark Brown 	return 0;
5222853223SMark Brown }
5322853223SMark Brown 
regmap_ac97_reg_write(void * context,unsigned int reg,unsigned int val)5422853223SMark Brown static int regmap_ac97_reg_write(void *context, unsigned int reg,
5522853223SMark Brown 	unsigned int val)
5622853223SMark Brown {
5722853223SMark Brown 	struct snd_ac97 *ac97 = context;
5822853223SMark Brown 
5922853223SMark Brown 	ac97->bus->ops->write(ac97, reg, val);
6022853223SMark Brown 
6122853223SMark Brown 	return 0;
6222853223SMark Brown }
6322853223SMark Brown 
6422853223SMark Brown static const struct regmap_bus ac97_regmap_bus = {
6522853223SMark Brown 	.reg_write = regmap_ac97_reg_write,
6622853223SMark Brown 	.reg_read = regmap_ac97_reg_read,
6722853223SMark Brown };
6822853223SMark Brown 
__regmap_init_ac97(struct snd_ac97 * ac97,const struct regmap_config * config,struct lock_class_key * lock_key,const char * lock_name)693cfe7a74SNicolas Boichat struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
703cfe7a74SNicolas Boichat 				  const struct regmap_config *config,
713cfe7a74SNicolas Boichat 				  struct lock_class_key *lock_key,
723cfe7a74SNicolas Boichat 				  const char *lock_name)
7322853223SMark Brown {
743cfe7a74SNicolas Boichat 	return __regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config,
753cfe7a74SNicolas Boichat 			     lock_key, lock_name);
7622853223SMark Brown }
773cfe7a74SNicolas Boichat EXPORT_SYMBOL_GPL(__regmap_init_ac97);
7822853223SMark Brown 
__devm_regmap_init_ac97(struct snd_ac97 * ac97,const struct regmap_config * config,struct lock_class_key * lock_key,const char * lock_name)793cfe7a74SNicolas Boichat struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
803cfe7a74SNicolas Boichat 				       const struct regmap_config *config,
813cfe7a74SNicolas Boichat 				       struct lock_class_key *lock_key,
823cfe7a74SNicolas Boichat 				       const char *lock_name)
8322853223SMark Brown {
843cfe7a74SNicolas Boichat 	return __devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config,
853cfe7a74SNicolas Boichat 				  lock_key, lock_name);
8622853223SMark Brown }
873cfe7a74SNicolas Boichat EXPORT_SYMBOL_GPL(__devm_regmap_init_ac97);
8822853223SMark Brown 
8922853223SMark Brown MODULE_LICENSE("GPL v2");
90