Lines Matching +full:resource +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-only
21 #include <linux/mfd/twl4030-audio.h>
36 struct twl4030_audio_resource resource[TWL4030_AUDIO_RES_MAX]; member
41 * Modify the resource, the function returns the content of the register
44 static int twl4030_audio_set_resource(enum twl4030_audio_res id, int enable) in twl4030_audio_set_resource() argument
50 audio->resource[id].reg); in twl4030_audio_set_resource()
53 val |= audio->resource[id].mask; in twl4030_audio_set_resource()
55 val &= ~audio->resource[id].mask; in twl4030_audio_set_resource()
58 val, audio->resource[id].reg); in twl4030_audio_set_resource()
63 static inline int twl4030_audio_get_resource(enum twl4030_audio_res id) in twl4030_audio_get_resource() argument
69 audio->resource[id].reg); in twl4030_audio_get_resource()
75 * Enable the resource.
78 int twl4030_audio_enable_resource(enum twl4030_audio_res id) in twl4030_audio_enable_resource() argument
83 if (id >= TWL4030_AUDIO_RES_MAX) { in twl4030_audio_enable_resource()
84 dev_err(&twl4030_audio_dev->dev, in twl4030_audio_enable_resource()
85 "Invalid resource ID (%u)\n", id); in twl4030_audio_enable_resource()
86 return -EINVAL; in twl4030_audio_enable_resource()
89 mutex_lock(&audio->mutex); in twl4030_audio_enable_resource()
90 if (!audio->resource[id].request_count) in twl4030_audio_enable_resource()
91 /* Resource was disabled, enable it */ in twl4030_audio_enable_resource()
92 val = twl4030_audio_set_resource(id, 1); in twl4030_audio_enable_resource()
94 val = twl4030_audio_get_resource(id); in twl4030_audio_enable_resource()
96 audio->resource[id].request_count++; in twl4030_audio_enable_resource()
97 mutex_unlock(&audio->mutex); in twl4030_audio_enable_resource()
104 * Disable the resource.
107 int twl4030_audio_disable_resource(enum twl4030_audio_res id) in twl4030_audio_disable_resource() argument
112 if (id >= TWL4030_AUDIO_RES_MAX) { in twl4030_audio_disable_resource()
113 dev_err(&twl4030_audio_dev->dev, in twl4030_audio_disable_resource()
114 "Invalid resource ID (%u)\n", id); in twl4030_audio_disable_resource()
115 return -EINVAL; in twl4030_audio_disable_resource()
118 mutex_lock(&audio->mutex); in twl4030_audio_disable_resource()
119 if (!audio->resource[id].request_count) { in twl4030_audio_disable_resource()
120 dev_err(&twl4030_audio_dev->dev, in twl4030_audio_disable_resource()
121 "Resource has been disabled already (%u)\n", id); in twl4030_audio_disable_resource()
122 mutex_unlock(&audio->mutex); in twl4030_audio_disable_resource()
123 return -EPERM; in twl4030_audio_disable_resource()
125 audio->resource[id].request_count--; in twl4030_audio_disable_resource()
127 if (!audio->resource[id].request_count) in twl4030_audio_disable_resource()
128 /* Resource can be disabled now */ in twl4030_audio_disable_resource()
129 val = twl4030_audio_set_resource(id, 0); in twl4030_audio_disable_resource()
131 val = twl4030_audio_get_resource(id); in twl4030_audio_disable_resource()
133 mutex_unlock(&audio->mutex); in twl4030_audio_disable_resource()
143 return audio->audio_mclk; in twl4030_audio_get_mclk()
152 if (pdata && pdata->codec) in twl4030_audio_has_codec()
169 if (pdata && pdata->vibra) in twl4030_audio_has_vibra()
172 if (!of_property_read_u32(node, "ti,enable-vibra", &vibra) && vibra) in twl4030_audio_has_vibra()
181 struct twl4030_audio_data *pdata = dev_get_platdata(&pdev->dev); in twl4030_audio_probe()
182 struct device_node *node = pdev->dev.of_node; in twl4030_audio_probe()
188 dev_err(&pdev->dev, "Platform data is missing\n"); in twl4030_audio_probe()
189 return -EINVAL; in twl4030_audio_probe()
192 audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio), in twl4030_audio_probe()
195 return -ENOMEM; in twl4030_audio_probe()
197 mutex_init(&audio->mutex); in twl4030_audio_probe()
198 audio->audio_mclk = twl_get_hfclk_rate(); in twl4030_audio_probe()
201 switch (audio->audio_mclk) { in twl4030_audio_probe()
212 dev_err(&pdev->dev, "Invalid audio_mclk\n"); in twl4030_audio_probe()
213 return -EINVAL; in twl4030_audio_probe()
218 audio->resource[TWL4030_AUDIO_RES_POWER].reg = TWL4030_REG_CODEC_MODE; in twl4030_audio_probe()
219 audio->resource[TWL4030_AUDIO_RES_POWER].mask = TWL4030_CODECPDZ; in twl4030_audio_probe()
222 audio->resource[TWL4030_AUDIO_RES_APLL].reg = TWL4030_REG_APLL_CTL; in twl4030_audio_probe()
223 audio->resource[TWL4030_AUDIO_RES_APLL].mask = TWL4030_APLL_EN; in twl4030_audio_probe()
226 cell = &audio->cells[childs]; in twl4030_audio_probe()
227 cell->name = "twl4030-codec"; in twl4030_audio_probe()
229 cell->platform_data = pdata->codec; in twl4030_audio_probe()
230 cell->pdata_size = sizeof(*pdata->codec); in twl4030_audio_probe()
235 cell = &audio->cells[childs]; in twl4030_audio_probe()
236 cell->name = "twl4030-vibra"; in twl4030_audio_probe()
238 cell->platform_data = pdata->vibra; in twl4030_audio_probe()
239 cell->pdata_size = sizeof(*pdata->vibra); in twl4030_audio_probe()
248 ret = mfd_add_devices(&pdev->dev, pdev->id, audio->cells, in twl4030_audio_probe()
251 dev_err(&pdev->dev, "No platform data found for childs\n"); in twl4030_audio_probe()
252 ret = -ENODEV; in twl4030_audio_probe()
263 mfd_remove_devices(&pdev->dev); in twl4030_audio_remove()
268 {.compatible = "ti,twl4030-audio", },
275 .name = "twl4030-audio",
286 MODULE_ALIAS("platform:twl4030-audio");