Blame view

sound/soc/soc-devres.c 3.93 KB
a0b03a616   Mark Brown   ASoC: core: Imple...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * soc-devres.c  --  ALSA SoC Audio Layer devres functions
   *
   * Copyright (C) 2013 Linaro Ltd
   *
   *  This program is free software; you can redistribute  it and/or modify it
   *  under  the terms of  the GNU General  Public License as published by the
   *  Free Software Foundation;  either version 2 of the  License, or (at your
   *  option) any later version.
   */
  
  #include <linux/module.h>
  #include <linux/moduleparam.h>
  #include <sound/soc.h>
21585ee84   Lars-Peter Clausen   ASoC: Add resourc...
15
  #include <sound/dmaengine_pcm.h>
a0b03a616   Mark Brown   ASoC: core: Imple...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  
  static void devm_component_release(struct device *dev, void *res)
  {
  	snd_soc_unregister_component(*(struct device **)res);
  }
  
  /**
   * devm_snd_soc_register_component - resource managed component registration
   * @dev: Device used to manage component
   * @cmpnt_drv: Component driver
   * @dai_drv: DAI driver
   * @num_dai: Number of DAIs to register
   *
   * Register a component with automatic unregistration when the device is
   * unregistered.
   */
  int devm_snd_soc_register_component(struct device *dev,
  			 const struct snd_soc_component_driver *cmpnt_drv,
  			 struct snd_soc_dai_driver *dai_drv, int num_dai)
  {
  	struct device **ptr;
  	int ret;
  
  	ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
  	if (!ptr)
  		return -ENOMEM;
  
  	ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
  	if (ret == 0) {
  		*ptr = dev;
  		devres_add(dev, ptr);
  	} else {
  		devres_free(ptr);
  	}
  
  	return ret;
  }
  EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
0e4ff5c80   Mark Brown   ASoC: core: Add d...
54

8931bf620   Peter Ujfalusi   ASoC: Add resourc...
55
56
57
58
59
60
61
62
  static void devm_platform_release(struct device *dev, void *res)
  {
  	snd_soc_unregister_platform(*(struct device **)res);
  }
  
  /**
   * devm_snd_soc_register_platform - resource managed platform registration
   * @dev: Device used to manage platform
2f1a11e62   Masanari Iida   ASoC: Fix warning...
63
   * @platform_drv: platform to register
8931bf620   Peter Ujfalusi   ASoC: Add resourc...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
   *
   * Register a platform driver with automatic unregistration when the device is
   * unregistered.
   */
  int devm_snd_soc_register_platform(struct device *dev,
  			const struct snd_soc_platform_driver *platform_drv)
  {
  	struct device **ptr;
  	int ret;
  
  	ptr = devres_alloc(devm_platform_release, sizeof(*ptr), GFP_KERNEL);
  	if (!ptr)
  		return -ENOMEM;
  
  	ret = snd_soc_register_platform(dev, platform_drv);
  	if (ret == 0) {
  		*ptr = dev;
  		devres_add(dev, ptr);
  	} else {
  		devres_free(ptr);
  	}
  
  	return ret;
  }
1f23380b8   Lars-Peter Clausen   ASoC: Export devm...
88
  EXPORT_SYMBOL_GPL(devm_snd_soc_register_platform);
8931bf620   Peter Ujfalusi   ASoC: Add resourc...
89

0e4ff5c80   Mark Brown   ASoC: core: Add d...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  static void devm_card_release(struct device *dev, void *res)
  {
  	snd_soc_unregister_card(*(struct snd_soc_card **)res);
  }
  
  /**
   * devm_snd_soc_register_card - resource managed card registration
   * @dev: Device used to manage card
   * @card: Card to register
   *
   * Register a card with automatic unregistration when the device is
   * unregistered.
   */
  int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
  {
ebff65473   Shawn Guo   ASoC: core: fix d...
105
  	struct snd_soc_card **ptr;
0e4ff5c80   Mark Brown   ASoC: core: Add d...
106
107
108
109
110
111
112
113
  	int ret;
  
  	ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
  	if (!ptr)
  		return -ENOMEM;
  
  	ret = snd_soc_register_card(card);
  	if (ret == 0) {
ebff65473   Shawn Guo   ASoC: core: fix d...
114
  		*ptr = card;
0e4ff5c80   Mark Brown   ASoC: core: Add d...
115
116
117
118
119
120
121
122
  		devres_add(dev, ptr);
  	} else {
  		devres_free(ptr);
  	}
  
  	return ret;
  }
  EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
21585ee84   Lars-Peter Clausen   ASoC: Add resourc...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
  
  #ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
  
  static void devm_dmaengine_pcm_release(struct device *dev, void *res)
  {
  	snd_dmaengine_pcm_unregister(*(struct device **)res);
  }
  
  /**
   * devm_snd_dmaengine_pcm_register - resource managed dmaengine PCM registration
   * @dev: The parent device for the PCM device
   * @config: Platform specific PCM configuration
   * @flags: Platform specific quirks
   *
   * Register a dmaengine based PCM device with automatic unregistration when the
   * device is unregistered.
   */
  int devm_snd_dmaengine_pcm_register(struct device *dev,
  	const struct snd_dmaengine_pcm_config *config, unsigned int flags)
  {
  	struct device **ptr;
  	int ret;
  
  	ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
  	if (!ptr)
  		return -ENOMEM;
  
  	ret = snd_dmaengine_pcm_register(dev, config, flags);
  	if (ret == 0) {
  		*ptr = dev;
  		devres_add(dev, ptr);
  	} else {
  		devres_free(ptr);
  	}
  
  	return ret;
  }
  EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);
  
  #endif