Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * MFD driver for twl4030 audio submodule, which contains an audio codec, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * the vibra control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright:   (C) 2009 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/twl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mfd/twl4030-audio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define TWL4030_AUDIO_CELLS	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct platform_device *twl4030_audio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct twl4030_audio_resource {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u8 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) struct twl4030_audio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned int audio_mclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct twl4030_audio_resource resource[TWL4030_AUDIO_RES_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct mfd_cell cells[TWL4030_AUDIO_CELLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * Modify the resource, the function returns the content of the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * after the modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int twl4030_audio_set_resource(enum twl4030_audio_res id, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			audio->resource[id].reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		val |= audio->resource[id].mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		val &= ~audio->resource[id].mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 					val, audio->resource[id].reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static inline int twl4030_audio_get_resource(enum twl4030_audio_res id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			audio->resource[id].reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * Enable the resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * The function returns with error or the content of the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) int twl4030_audio_enable_resource(enum twl4030_audio_res id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (id >= TWL4030_AUDIO_RES_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		dev_err(&twl4030_audio_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				"Invalid resource ID (%u)\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	mutex_lock(&audio->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!audio->resource[id].request_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		/* Resource was disabled, enable it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		val = twl4030_audio_set_resource(id, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		val = twl4030_audio_get_resource(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	audio->resource[id].request_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	mutex_unlock(&audio->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) EXPORT_SYMBOL_GPL(twl4030_audio_enable_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * Disable the resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * The function returns with error or the content of the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int twl4030_audio_disable_resource(enum twl4030_audio_res id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (id >= TWL4030_AUDIO_RES_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		dev_err(&twl4030_audio_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				"Invalid resource ID (%u)\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	mutex_lock(&audio->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!audio->resource[id].request_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		dev_err(&twl4030_audio_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			"Resource has been disabled already (%u)\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		mutex_unlock(&audio->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	audio->resource[id].request_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!audio->resource[id].request_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		/* Resource can be disabled now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		val = twl4030_audio_set_resource(id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		val = twl4030_audio_get_resource(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	mutex_unlock(&audio->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) EXPORT_SYMBOL_GPL(twl4030_audio_disable_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned int twl4030_audio_get_mclk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct twl4030_audio *audio = platform_get_drvdata(twl4030_audio_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return audio->audio_mclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) EXPORT_SYMBOL_GPL(twl4030_audio_get_mclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static bool twl4030_audio_has_codec(struct twl4030_audio_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			      struct device_node *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (pdata && pdata->codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	node = of_get_child_by_name(parent, "codec");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static bool twl4030_audio_has_vibra(struct twl4030_audio_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			      struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int vibra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (pdata && pdata->vibra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (!of_property_read_u32(node, "ti,enable-vibra", &vibra) && vibra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int twl4030_audio_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct twl4030_audio *audio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct twl4030_audio_data *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct device_node *node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct mfd_cell *cell = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int ret, childs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!pdata && !node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		dev_err(&pdev->dev, "Platform data is missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	audio = devm_kzalloc(&pdev->dev, sizeof(struct twl4030_audio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (!audio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	mutex_init(&audio->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	audio->audio_mclk = twl_get_hfclk_rate();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/* Configure APLL_INFREQ and disable APLL if enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	switch (audio->audio_mclk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	case 19200000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		val = TWL4030_APLL_INFREQ_19200KHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	case 26000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		val = TWL4030_APLL_INFREQ_26000KHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	case 38400000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		val = TWL4030_APLL_INFREQ_38400KHZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		dev_err(&pdev->dev, "Invalid audio_mclk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, val, TWL4030_REG_APLL_CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* Codec power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	audio->resource[TWL4030_AUDIO_RES_POWER].reg = TWL4030_REG_CODEC_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	audio->resource[TWL4030_AUDIO_RES_POWER].mask = TWL4030_CODECPDZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* PLL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	audio->resource[TWL4030_AUDIO_RES_APLL].reg = TWL4030_REG_APLL_CTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	audio->resource[TWL4030_AUDIO_RES_APLL].mask = TWL4030_APLL_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (twl4030_audio_has_codec(pdata, node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		cell = &audio->cells[childs];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		cell->name = "twl4030-codec";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			cell->platform_data = pdata->codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			cell->pdata_size = sizeof(*pdata->codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		childs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (twl4030_audio_has_vibra(pdata, node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		cell = &audio->cells[childs];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		cell->name = "twl4030-vibra";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			cell->platform_data = pdata->vibra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			cell->pdata_size = sizeof(*pdata->vibra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		childs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	platform_set_drvdata(pdev, audio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	twl4030_audio_dev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (childs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		ret = mfd_add_devices(&pdev->dev, pdev->id, audio->cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				      childs, NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		dev_err(&pdev->dev, "No platform data found for childs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		twl4030_audio_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int twl4030_audio_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	mfd_remove_devices(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	twl4030_audio_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static const struct of_device_id twl4030_audio_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	{.compatible = "ti,twl4030-audio", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_DEVICE_TABLE(of, twl4030_audio_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static struct platform_driver twl4030_audio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		.name	= "twl4030-audio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		.of_match_table = twl4030_audio_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	.probe		= twl4030_audio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	.remove		= twl4030_audio_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) module_platform_driver(twl4030_audio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_DESCRIPTION("TWL4030 audio block MFD driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) MODULE_ALIAS("platform:twl4030-audio");