dm: sound: Complete migration to driver model
All users of sound are converted to use driver model. Drop the old code and the CONFIG_DM_SOUND option. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
		
							parent
							
								
									1e224fef94
								
							
						
					
					
						commit
						f2b25c9bf8
					
				|  | @ -7,7 +7,6 @@ | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| #include <linux/input.h> | #include <linux/input.h> | ||||||
| #include <SDL/SDL.h> | #include <SDL/SDL.h> | ||||||
| #include <sound.h> |  | ||||||
| #include <asm/state.h> | #include <asm/state.h> | ||||||
| 
 | 
 | ||||||
| enum { | enum { | ||||||
|  |  | ||||||
|  | @ -54,12 +54,12 @@ int sandbox_sdl_scan_keys(int key[], int max_keys); | ||||||
| int sandbox_sdl_key_pressed(int keycode); | int sandbox_sdl_key_pressed(int keycode); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * sandbox_sdl_sound_start() - start playing a sound |  * sandbox_sdl_sound_play() - Play a sound | ||||||
|  * |  * | ||||||
|  * @frequency:	Frequency of sounds in Hertz |  * @data:	Data to play (typically 16-bit) | ||||||
|  * @return 0 if OK, -ENODEV if no sound is available |  * @count:	Number of bytes in data | ||||||
|  */ |  */ | ||||||
| int sandbox_sdl_sound_start(uint frequency); | int sandbox_sdl_sound_play(const void *data, uint count); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * sandbox_sdl_sound_stop() - stop playing a sound |  * sandbox_sdl_sound_stop() - stop playing a sound | ||||||
|  | @ -68,14 +68,6 @@ int sandbox_sdl_sound_start(uint frequency); | ||||||
|  */ |  */ | ||||||
| int sandbox_sdl_sound_stop(void); | int sandbox_sdl_sound_stop(void); | ||||||
| 
 | 
 | ||||||
| /**
 |  | ||||||
|  * sandbox_sdl_sound_play() - Play a sound |  | ||||||
|  * |  | ||||||
|  * @data:	Data to play (typically 16-bit) |  | ||||||
|  * @count:	Number of bytes in data |  | ||||||
|  */ |  | ||||||
| int sandbox_sdl_sound_play(const void *data, uint count); |  | ||||||
| 
 |  | ||||||
| /**
 | /**
 | ||||||
|  * sandbox_sdl_sound_init() - set up the sound system |  * sandbox_sdl_sound_init() - set up the sound system | ||||||
|  * |  * | ||||||
|  | @ -110,6 +102,11 @@ static inline int sandbox_sdl_sound_start(uint frequency) | ||||||
| 	return -ENODEV; | 	return -ENODEV; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | int sandbox_sdl_sound_play(const void *data, uint count) | ||||||
|  | { | ||||||
|  | 	return -ENODEV; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static inline int sandbox_sdl_sound_stop(void) | static inline int sandbox_sdl_sound_stop(void) | ||||||
| { | { | ||||||
| 	return -ENODEV; | 	return -ENODEV; | ||||||
|  |  | ||||||
|  | @ -1,13 +0,0 @@ | ||||||
| /* SPDX-License-Identifier: GPL-2.0+ */ |  | ||||||
| /*
 |  | ||||||
|  * Copyright (c) 2013 Google, Inc |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #ifndef __SANDBOX_SOUND_H |  | ||||||
| #define __SANDBOX_SOUND_H |  | ||||||
| 
 |  | ||||||
| int sound_play(unsigned int msec, unsigned int frequency); |  | ||||||
| 
 |  | ||||||
| int sound_init(const void *blob); |  | ||||||
| 
 |  | ||||||
| #endif |  | ||||||
							
								
								
									
										12
									
								
								cmd/sound.c
								
								
								
								
							
							
						
						
									
										12
									
								
								cmd/sound.c
								
								
								
								
							|  | @ -15,18 +15,12 @@ DECLARE_GLOBAL_DATA_PTR; | ||||||
| /* Initilaise sound subsystem */ | /* Initilaise sound subsystem */ | ||||||
| static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | ||||||
| { | { | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| 	struct udevice *dev; | 	struct udevice *dev; | ||||||
| #endif |  | ||||||
| 	int ret; | 	int ret; | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| 	ret = uclass_first_device_err(UCLASS_SOUND, &dev); | 	ret = uclass_first_device_err(UCLASS_SOUND, &dev); | ||||||
| 	if (!ret) | 	if (!ret) | ||||||
| 		ret = sound_setup(dev); | 		ret = sound_setup(dev); | ||||||
| #else |  | ||||||
| 	ret = sound_init(gd->fdt_blob); |  | ||||||
| #endif |  | ||||||
| 	if (ret) { | 	if (ret) { | ||||||
| 		printf("Initialise Audio driver failed (ret=%d)\n", ret); | 		printf("Initialise Audio driver failed (ret=%d)\n", ret); | ||||||
| 		return CMD_RET_FAILURE; | 		return CMD_RET_FAILURE; | ||||||
|  | @ -38,9 +32,7 @@ static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | ||||||
| /* play sound from buffer */ | /* play sound from buffer */ | ||||||
| static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | ||||||
| { | { | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| 	struct udevice *dev; | 	struct udevice *dev; | ||||||
| #endif |  | ||||||
| 	int ret = 0; | 	int ret = 0; | ||||||
| 	int msec = 1000; | 	int msec = 1000; | ||||||
| 	int freq = 400; | 	int freq = 400; | ||||||
|  | @ -50,13 +42,9 @@ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | ||||||
| 	if (argc > 2) | 	if (argc > 2) | ||||||
| 		freq = simple_strtoul(argv[2], NULL, 10); | 		freq = simple_strtoul(argv[2], NULL, 10); | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| 	ret = uclass_first_device_err(UCLASS_SOUND, &dev); | 	ret = uclass_first_device_err(UCLASS_SOUND, &dev); | ||||||
| 	if (!ret) | 	if (!ret) | ||||||
| 		ret = sound_beep(dev, msec, freq); | 		ret = sound_beep(dev, msec, freq); | ||||||
| #else |  | ||||||
| 	ret = sound_play(msec, freq); |  | ||||||
| #endif |  | ||||||
| 	if (ret) { | 	if (ret) { | ||||||
| 		printf("Sound device failed to play (err=%d)\n", ret); | 		printf("Sound device failed to play (err=%d)\n", ret); | ||||||
| 		return CMD_RET_FAILURE; | 		return CMD_RET_FAILURE; | ||||||
|  |  | ||||||
|  | @ -31,7 +31,6 @@ CONFIG_MMC_SDHCI_S5P=y | ||||||
| CONFIG_SMC911X=y | CONFIG_SMC911X=y | ||||||
| CONFIG_SMC911X_BASE=0x5000000 | CONFIG_SMC911X_BASE=0x5000000 | ||||||
| CONFIG_SOUND=y | CONFIG_SOUND=y | ||||||
| CONFIG_DM_SOUND=y |  | ||||||
| CONFIG_I2S=y | CONFIG_I2S=y | ||||||
| CONFIG_I2S_SAMSUNG=y | CONFIG_I2S_SAMSUNG=y | ||||||
| CONFIG_SOUND_MAX98095=y | CONFIG_SOUND_MAX98095=y | ||||||
|  |  | ||||||
|  | @ -50,7 +50,6 @@ CONFIG_REGULATOR_TPS65090=y | ||||||
| CONFIG_DM_PWM=y | CONFIG_DM_PWM=y | ||||||
| CONFIG_PWM_EXYNOS=y | CONFIG_PWM_EXYNOS=y | ||||||
| CONFIG_SOUND=y | CONFIG_SOUND=y | ||||||
| CONFIG_DM_SOUND=y |  | ||||||
| CONFIG_I2S=y | CONFIG_I2S=y | ||||||
| CONFIG_I2S_SAMSUNG=y | CONFIG_I2S_SAMSUNG=y | ||||||
| CONFIG_SOUND_MAX98090=y | CONFIG_SOUND_MAX98090=y | ||||||
|  |  | ||||||
|  | @ -49,7 +49,6 @@ CONFIG_REGULATOR_TPS65090=y | ||||||
| CONFIG_DM_PWM=y | CONFIG_DM_PWM=y | ||||||
| CONFIG_PWM_EXYNOS=y | CONFIG_PWM_EXYNOS=y | ||||||
| CONFIG_SOUND=y | CONFIG_SOUND=y | ||||||
| CONFIG_DM_SOUND=y |  | ||||||
| CONFIG_I2S=y | CONFIG_I2S=y | ||||||
| CONFIG_I2S_SAMSUNG=y | CONFIG_I2S_SAMSUNG=y | ||||||
| CONFIG_SOUND_MAX98090=y | CONFIG_SOUND_MAX98090=y | ||||||
|  |  | ||||||
|  | @ -43,7 +43,6 @@ CONFIG_DM_PMIC_MAX77686=y | ||||||
| CONFIG_DM_REGULATOR=y | CONFIG_DM_REGULATOR=y | ||||||
| CONFIG_DM_REGULATOR_MAX77686=y | CONFIG_DM_REGULATOR_MAX77686=y | ||||||
| CONFIG_SOUND=y | CONFIG_SOUND=y | ||||||
| CONFIG_DM_SOUND=y |  | ||||||
| CONFIG_I2S=y | CONFIG_I2S=y | ||||||
| CONFIG_I2S_SAMSUNG=y | CONFIG_I2S_SAMSUNG=y | ||||||
| CONFIG_SOUND_MAX98095=y | CONFIG_SOUND_MAX98095=y | ||||||
|  |  | ||||||
|  | @ -60,7 +60,6 @@ CONFIG_DM_PWM=y | ||||||
| CONFIG_PWM_EXYNOS=y | CONFIG_PWM_EXYNOS=y | ||||||
| CONFIG_DEBUG_UART_S5P=y | CONFIG_DEBUG_UART_S5P=y | ||||||
| CONFIG_SOUND=y | CONFIG_SOUND=y | ||||||
| CONFIG_DM_SOUND=y |  | ||||||
| CONFIG_I2S=y | CONFIG_I2S=y | ||||||
| CONFIG_I2S_SAMSUNG=y | CONFIG_I2S_SAMSUNG=y | ||||||
| CONFIG_SOUND_MAX98095=y | CONFIG_SOUND_MAX98095=y | ||||||
|  |  | ||||||
|  | @ -60,7 +60,6 @@ CONFIG_DM_PWM=y | ||||||
| CONFIG_PWM_EXYNOS=y | CONFIG_PWM_EXYNOS=y | ||||||
| CONFIG_DEBUG_UART_S5P=y | CONFIG_DEBUG_UART_S5P=y | ||||||
| CONFIG_SOUND=y | CONFIG_SOUND=y | ||||||
| CONFIG_DM_SOUND=y |  | ||||||
| CONFIG_I2S=y | CONFIG_I2S=y | ||||||
| CONFIG_I2S_SAMSUNG=y | CONFIG_I2S_SAMSUNG=y | ||||||
| CONFIG_SOUND_MAX98095=y | CONFIG_SOUND_MAX98095=y | ||||||
|  |  | ||||||
|  | @ -12,12 +12,6 @@ config SOUND | ||||||
| 	  audio codecs are called from the sound-i2s code. This could be | 	  audio codecs are called from the sound-i2s code. This could be | ||||||
| 	  converted to driver model. | 	  converted to driver model. | ||||||
| 
 | 
 | ||||||
| config DM_SOUND |  | ||||||
| 	bool "Use driver model for sound" |  | ||||||
| 	help |  | ||||||
| 	  Enable this option to use driver model for sound devices. This is a |  | ||||||
| 	  migration option and will be removed. |  | ||||||
| 
 |  | ||||||
| config I2S | config I2S | ||||||
| 	bool "Enable I2S support" | 	bool "Enable I2S support" | ||||||
| 	depends on SOUND | 	depends on SOUND | ||||||
|  |  | ||||||
|  | @ -4,16 +4,12 @@ | ||||||
| # R. Chandrasekar <rcsekar@samsung.com>
 | # R. Chandrasekar <rcsekar@samsung.com>
 | ||||||
| 
 | 
 | ||||||
| obj-$(CONFIG_SOUND)	+= sound.o | obj-$(CONFIG_SOUND)	+= sound.o | ||||||
| obj-$(CONFIG_DM_SOUND)	+= codec-uclass.o | obj-$(CONFIG_SOUND)	+= codec-uclass.o | ||||||
| obj-$(CONFIG_DM_SOUND)	+= i2s-uclass.o | obj-$(CONFIG_SOUND)	+= i2s-uclass.o | ||||||
| obj-$(CONFIG_DM_SOUND)	+= sound-uclass.o | obj-$(CONFIG_SOUND)	+= sound-uclass.o | ||||||
| obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o | obj-$(CONFIG_I2S_SAMSUNG)	+= samsung-i2s.o | ||||||
| obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o | obj-$(CONFIG_SOUND_SANDBOX)	+= sandbox.o | ||||||
| ifdef CONFIG_DM_SOUND |  | ||||||
| obj-$(CONFIG_I2S_SAMSUNG)	+= samsung_sound.o | obj-$(CONFIG_I2S_SAMSUNG)	+= samsung_sound.o | ||||||
| else |  | ||||||
| obj-$(CONFIG_I2S)	+= sound-i2s.o |  | ||||||
| endif |  | ||||||
| obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o | obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o | ||||||
| obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o | obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o | ||||||
| obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o | obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o | ||||||
|  |  | ||||||
|  | @ -432,84 +432,6 @@ static int max98095_do_init(struct maxim_priv *priv, | ||||||
| 	return ret; | 	return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifndef CONFIG_DM_SOUND |  | ||||||
| static int get_max98095_codec_values(struct sound_codec_info *pcodec_info, |  | ||||||
| 				const void *blob) |  | ||||||
| { |  | ||||||
| 	int error = 0; |  | ||||||
| 	enum fdt_compat_id compat; |  | ||||||
| 	int node; |  | ||||||
| 	int parent; |  | ||||||
| 
 |  | ||||||
| 	/* Get the node from FDT for codec */ |  | ||||||
| 	node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_98095_CODEC); |  | ||||||
| 	if (node <= 0) { |  | ||||||
| 		debug("EXYNOS_SOUND: No node for codec in device tree\n"); |  | ||||||
| 		debug("node = %d\n", node); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	parent = fdt_parent_offset(blob, node); |  | ||||||
| 	if (parent < 0) { |  | ||||||
| 		debug("%s: Cannot find node parent\n", __func__); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	compat = fdtdec_lookup(blob, parent); |  | ||||||
| 	switch (compat) { |  | ||||||
| 	case COMPAT_SAMSUNG_S3C2440_I2C: |  | ||||||
| 		pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent); |  | ||||||
| 		error |= pcodec_info->i2c_bus; |  | ||||||
| 		debug("i2c bus = %d\n", pcodec_info->i2c_bus); |  | ||||||
| 		pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node, |  | ||||||
| 							"reg", 0); |  | ||||||
| 		error |= pcodec_info->i2c_dev_addr; |  | ||||||
| 		debug("i2c dev addr = %x\n", pcodec_info->i2c_dev_addr); |  | ||||||
| 		break; |  | ||||||
| 	default: |  | ||||||
| 		debug("%s: Unknown compat id %d\n", __func__, compat); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	if (error == -1) { |  | ||||||
| 		debug("fail to get max98095 codec node properties\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /* max98095 Device Initialisation */ |  | ||||||
| int max98095_init(const void *blob, enum en_max_audio_interface aif_id, |  | ||||||
| 		  int sampling_rate, int mclk_freq, |  | ||||||
| 		  int bits_per_sample) |  | ||||||
| { |  | ||||||
| 	int ret; |  | ||||||
| 	int old_bus = i2c_get_bus_num(); |  | ||||||
| 	struct sound_codec_info pcodec_info; |  | ||||||
| 	struct max98095_priv max98095_info; |  | ||||||
| 
 |  | ||||||
| 	if (get_max98095_codec_values(&pcodec_info, blob) < 0) { |  | ||||||
| 		debug("FDT Codec values failed\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	i2c_set_bus_num(pcodec_info.i2c_bus); |  | ||||||
| 
 |  | ||||||
| 	max98095_info.i2c_addr = pcodec_info.i2c_dev_addr; |  | ||||||
| 	ret = max98095_device_init(&max98095_info); |  | ||||||
| 	if (ret < 0) { |  | ||||||
| 		debug("%s: max98095 codec chip init failed\n", __func__); |  | ||||||
| 		return ret; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	ret = max98095_do_init(&max98095_info, aif_id, sampling_rate, mclk_freq, |  | ||||||
| 			       bits_per_sample); |  | ||||||
| 	i2c_set_bus_num(old_bus); |  | ||||||
| 
 |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| static int max98095_set_params(struct udevice *dev, int interface, int rate, | static int max98095_set_params(struct udevice *dev, int interface, int rate, | ||||||
| 			       int mclk_freq, int bits_per_sample, | 			       int mclk_freq, int bits_per_sample, | ||||||
| 			       uint channels) | 			       uint channels) | ||||||
|  |  | ||||||
|  | @ -8,7 +8,6 @@ | ||||||
| #include <dm.h> | #include <dm.h> | ||||||
| #include <i2s.h> | #include <i2s.h> | ||||||
| #include <sound.h> | #include <sound.h> | ||||||
| #include <asm/sound.h> |  | ||||||
| #include <asm/sdl.h> | #include <asm/sdl.h> | ||||||
| 
 | 
 | ||||||
| struct sandbox_codec_priv { | struct sandbox_codec_priv { | ||||||
|  | @ -28,22 +27,6 @@ struct sandbox_sound_priv { | ||||||
| 	int sum;	/* Use to sum the provided audio data */ | 	int sum;	/* Use to sum the provided audio data */ | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #ifndef CONFIG_DM_SOUND |  | ||||||
| int sound_play(uint32_t msec, uint32_t frequency) |  | ||||||
| { |  | ||||||
| 	sandbox_sdl_sound_start(frequency); |  | ||||||
| 	mdelay(msec); |  | ||||||
| 	sandbox_sdl_sound_stop(); |  | ||||||
| 
 |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| #endif /* CONFIG_DM_SOUND */ |  | ||||||
| 
 |  | ||||||
| int sound_init(const void *blob) |  | ||||||
| { |  | ||||||
| 	return sandbox_sdl_sound_init(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, | void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, | ||||||
| 			      int *mclk_freqp, int *bits_per_samplep, | 			      int *mclk_freqp, int *bits_per_samplep, | ||||||
| 			      uint *channelsp) | 			      uint *channelsp) | ||||||
|  | @ -102,7 +85,7 @@ static int sandbox_i2s_tx_data(struct udevice *dev, void *data, | ||||||
| 	for (i = 0; i < data_size; i++) | 	for (i = 0; i < data_size; i++) | ||||||
| 		priv->sum += ((uint8_t *)data)[i]; | 		priv->sum += ((uint8_t *)data)[i]; | ||||||
| 
 | 
 | ||||||
| 	return 0; | 	return sandbox_sdl_sound_play(data, data_size); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int sandbox_i2s_probe(struct udevice *dev) | static int sandbox_i2s_probe(struct udevice *dev) | ||||||
|  |  | ||||||
|  | @ -1,206 +0,0 @@ | ||||||
| // SPDX-License-Identifier: GPL-2.0+
 |  | ||||||
| /*
 |  | ||||||
|  * Copyright (C) 2012 Samsung Electronics |  | ||||||
|  * R. Chandrasekar <rcsekar@samsung.com> |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| #include <malloc.h> |  | ||||||
| #include <common.h> |  | ||||||
| #include <asm/io.h> |  | ||||||
| #include <linux/libfdt.h> |  | ||||||
| #include <fdtdec.h> |  | ||||||
| #include <i2c.h> |  | ||||||
| #include <i2s.h> |  | ||||||
| #include <sound.h> |  | ||||||
| #include <asm/arch/sound.h> |  | ||||||
| #include "wm8994.h" |  | ||||||
| #include "max98095.h" |  | ||||||
| 
 |  | ||||||
| /* defines */ |  | ||||||
| #define SOUND_400_HZ 400 |  | ||||||
| #define SOUND_BITS_IN_BYTE 8 |  | ||||||
| 
 |  | ||||||
| static struct i2s_uc_priv g_i2stx_pri; |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * get_sound_i2s_values gets values for i2s parameters |  | ||||||
|  * |  | ||||||
|  * @param i2s_uc_priv	i2s transmitter transfer param structure |  | ||||||
|  * @param blob		FDT blob if enabled else NULL |  | ||||||
|  */ |  | ||||||
| static int get_sound_i2s_values(struct i2s_uc_priv *i2s, const void *blob) |  | ||||||
| { |  | ||||||
| 	int node; |  | ||||||
| 	int error = 0; |  | ||||||
| 	int base; |  | ||||||
| 
 |  | ||||||
| 	node = fdt_path_offset(blob, "i2s"); |  | ||||||
| 	if (node <= 0) { |  | ||||||
| 		debug("EXYNOS_SOUND: No node for sound in device tree\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/*
 |  | ||||||
| 	 * Get the pre-defined sound specific values from FDT. |  | ||||||
| 	 * All of these are expected to be correct otherwise |  | ||||||
| 	 * wrong register values in i2s setup parameters |  | ||||||
| 	 * may result in no sound play. |  | ||||||
| 	 */ |  | ||||||
| 	base = fdtdec_get_addr(blob, node, "reg"); |  | ||||||
| 	if (base == FDT_ADDR_T_NONE) { |  | ||||||
| 		debug("%s: Missing  i2s base\n", __func__); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	i2s->base_address = base; |  | ||||||
| 
 |  | ||||||
| 	i2s->audio_pll_clk = fdtdec_get_int(blob, |  | ||||||
| 				node, "samsung,i2s-epll-clock-frequency", -1); |  | ||||||
| 	error |= i2s->audio_pll_clk; |  | ||||||
| 	debug("audio_pll_clk = %d\n", i2s->audio_pll_clk); |  | ||||||
| 	i2s->samplingrate = fdtdec_get_int(blob, |  | ||||||
| 				node, "samsung,i2s-sampling-rate", -1); |  | ||||||
| 	error |= i2s->samplingrate; |  | ||||||
| 	debug("samplingrate = %d\n", i2s->samplingrate); |  | ||||||
| 	i2s->bitspersample = fdtdec_get_int(blob, |  | ||||||
| 				node, "samsung,i2s-bits-per-sample", -1); |  | ||||||
| 	error |= i2s->bitspersample; |  | ||||||
| 	debug("bitspersample = %d\n", i2s->bitspersample); |  | ||||||
| 	i2s->channels = fdtdec_get_int(blob, |  | ||||||
| 			node, "samsung,i2s-channels", -1); |  | ||||||
| 	error |= i2s->channels; |  | ||||||
| 	debug("channels = %d\n", i2s->channels); |  | ||||||
| 	i2s->rfs = fdtdec_get_int(blob, |  | ||||||
| 				node, "samsung,i2s-lr-clk-framesize", -1); |  | ||||||
| 	error |= i2s->rfs; |  | ||||||
| 	debug("rfs = %d\n", i2s->rfs); |  | ||||||
| 	i2s->bfs = fdtdec_get_int(blob, |  | ||||||
| 				node, "samsung,i2s-bit-clk-framesize", -1); |  | ||||||
| 	error |= i2s->bfs; |  | ||||||
| 	debug("bfs = %d\n", i2s->bfs); |  | ||||||
| 
 |  | ||||||
| 	i2s->id = fdtdec_get_int(blob, node, "samsung,i2s-id", -1); |  | ||||||
| 	error |= i2s->id; |  | ||||||
| 	debug("id = %d\n", i2s->id); |  | ||||||
| 
 |  | ||||||
| 	if (error == -1) { |  | ||||||
| 		debug("fail to get sound i2s node properties\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 |  | ||||||
|  * Init codec |  | ||||||
|  * |  | ||||||
|  * @param blob          FDT blob |  | ||||||
|  * @param pi2s_tx	i2s parameters required by codec |  | ||||||
|  * @return              int value, 0 for success |  | ||||||
|  */ |  | ||||||
| static int codec_init(const void *blob, struct i2s_uc_priv *pi2s_tx) |  | ||||||
| { |  | ||||||
| 	int ret; |  | ||||||
| 	const char *codectype; |  | ||||||
| 	int node; |  | ||||||
| 
 |  | ||||||
| 	/* Get the node from FDT for sound */ |  | ||||||
| 	node = fdt_path_offset(blob, "i2s"); |  | ||||||
| 	if (node <= 0) { |  | ||||||
| 		debug("EXYNOS_SOUND: No node for sound in device tree\n"); |  | ||||||
| 		debug("node = %d\n", node); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/*
 |  | ||||||
| 	 * Get the pre-defined sound codec specific values from FDT. |  | ||||||
| 	 * All of these are expected to be correct otherwise sound |  | ||||||
| 	 * can not be played |  | ||||||
| 	 */ |  | ||||||
| 	codectype = fdt_getprop(blob, node, "samsung,codec-type", NULL); |  | ||||||
| 	debug("device = %s\n", codectype); |  | ||||||
| 	if (!strcmp(codectype, "wm8994")) { |  | ||||||
| 		/* Check the codec type and initialise the same */ |  | ||||||
| 		ret = wm8994_init(blob, pi2s_tx->id, pi2s_tx->samplingrate, |  | ||||||
| 				  (pi2s_tx->samplingrate * (pi2s_tx->rfs)), |  | ||||||
| 				  pi2s_tx->bitspersample, pi2s_tx->channels); |  | ||||||
| 	} else if (!strcmp(codectype, "max98095")) { |  | ||||||
| 		ret = max98095_init(blob, pi2s_tx->id, pi2s_tx->samplingrate, |  | ||||||
| 				    (pi2s_tx->samplingrate * (pi2s_tx->rfs)), |  | ||||||
| 				    pi2s_tx->bitspersample); |  | ||||||
| 	} else { |  | ||||||
| 		debug("%s: Unknown codec type %s\n", __func__, codectype); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (ret) { |  | ||||||
| 		debug("%s: Codec init failed\n", __func__); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| int sound_init(const void *blob) |  | ||||||
| { |  | ||||||
| 	int ret; |  | ||||||
| 	struct i2s_uc_priv *pi2s_tx = &g_i2stx_pri; |  | ||||||
| 
 |  | ||||||
| 	/* Get the I2S Values */ |  | ||||||
| 	if (get_sound_i2s_values(pi2s_tx, blob) < 0) { |  | ||||||
| 		debug(" FDT I2S values failed\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (codec_init(blob, pi2s_tx) < 0) { |  | ||||||
| 		debug(" Codec init failed\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	ret = i2s_tx_init(pi2s_tx); |  | ||||||
| 	if (ret) { |  | ||||||
| 		debug("%s: Failed to init i2c transmit: ret=%d\n", __func__, |  | ||||||
| 		      ret); |  | ||||||
| 		return ret; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| int sound_play(uint32_t msec, uint32_t frequency) |  | ||||||
| { |  | ||||||
| 	unsigned int *data; |  | ||||||
| 	unsigned long data_size; |  | ||||||
| 	unsigned int ret = 0; |  | ||||||
| 
 |  | ||||||
| 	/*Buffer length computation */ |  | ||||||
| 	data_size = g_i2stx_pri.samplingrate * g_i2stx_pri.channels; |  | ||||||
| 	data_size *= (g_i2stx_pri.bitspersample / SOUND_BITS_IN_BYTE); |  | ||||||
| 	data = malloc(data_size); |  | ||||||
| 
 |  | ||||||
| 	if (data == NULL) { |  | ||||||
| 		debug("%s: malloc failed\n", __func__); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	sound_create_square_wave(g_i2stx_pri.samplingrate, |  | ||||||
| 				 (unsigned short *)data, |  | ||||||
| 				 data_size / sizeof(unsigned short), |  | ||||||
| 				 frequency); |  | ||||||
| 
 |  | ||||||
| 	while (msec >= 1000) { |  | ||||||
| 		ret = i2s_transfer_tx_data(&g_i2stx_pri, data, |  | ||||||
| 					   (data_size / sizeof(int))); |  | ||||||
| 		msec -= 1000; |  | ||||||
| 	} |  | ||||||
| 	if (msec) { |  | ||||||
| 		unsigned long size = |  | ||||||
| 			(data_size * msec) / (sizeof(int) * 1000); |  | ||||||
| 
 |  | ||||||
| 		ret = i2s_transfer_tx_data(&g_i2stx_pri, data, size); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	free(data); |  | ||||||
| 
 |  | ||||||
| 	return ret; |  | ||||||
| } |  | ||||||
|  | @ -40,7 +40,6 @@ struct wm8994_priv { | ||||||
| 	int mclk[WM8994_MAX_AIF];	/* master clock frequency in Hz */ | 	int mclk[WM8994_MAX_AIF];	/* master clock frequency in Hz */ | ||||||
| 	int aifclk[WM8994_MAX_AIF];	/* audio interface clock in Hz   */ | 	int aifclk[WM8994_MAX_AIF];	/* audio interface clock in Hz   */ | ||||||
| 	struct wm8994_fll_config fll[2]; /* fll config to configure fll */ | 	struct wm8994_fll_config fll[2]; /* fll config to configure fll */ | ||||||
| 	int i2c_addr; |  | ||||||
| 	struct udevice *dev; | 	struct udevice *dev; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -82,12 +81,7 @@ static int wm8994_i2c_write(struct wm8994_priv *priv, unsigned int reg, | ||||||
| 	val[1] = (unsigned char)(data & 0xff); | 	val[1] = (unsigned char)(data & 0xff); | ||||||
| 	debug("Write Addr : 0x%04X, Data :  0x%04X\n", reg, data); | 	debug("Write Addr : 0x%04X, Data :  0x%04X\n", reg, data); | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| 	debug("dev = %s\n", priv->dev->name); |  | ||||||
| 	return dm_i2c_write(priv->dev, reg, val, 2); | 	return dm_i2c_write(priv->dev, reg, val, 2); | ||||||
| #else |  | ||||||
| 	return i2c_write(priv->i2c_addr, reg, 2, val, 2); |  | ||||||
| #endif |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  | @ -105,11 +99,7 @@ static unsigned int wm8994_i2c_read(struct wm8994_priv *priv, unsigned int reg, | ||||||
| 	unsigned char val[2]; | 	unsigned char val[2]; | ||||||
| 	int ret; | 	int ret; | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| 	ret = dm_i2c_read(priv->dev, reg, val, 1); | 	ret = dm_i2c_read(priv->dev, reg, val, 1); | ||||||
| #else |  | ||||||
| 	ret = i2c_read(priv->i2c_addr, reg, 2, val, 2); |  | ||||||
| #endif |  | ||||||
| 	if (ret != 0) { | 	if (ret != 0) { | ||||||
| 		debug("%s: Error while reading register %#04x\n", | 		debug("%s: Error while reading register %#04x\n", | ||||||
| 		      __func__, reg); | 		      __func__, reg); | ||||||
|  | @ -819,61 +809,6 @@ err: | ||||||
| 	return -1; | 	return -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifndef CONFIG_DM_SOUND |  | ||||||
| /*
 |  | ||||||
|  * Gets fdt values for wm8994 config parameters |  | ||||||
|  * |  | ||||||
|  * @param pcodec_info	codec information structure |  | ||||||
|  * @param blob		FDT blob |  | ||||||
|  * @return		int value, 0 for success |  | ||||||
|  */ |  | ||||||
| static int get_codec_values(struct sound_codec_info *pcodec_info, |  | ||||||
| 			    const void *blob) |  | ||||||
| { |  | ||||||
| 	int error = 0; |  | ||||||
| 	enum fdt_compat_id compat; |  | ||||||
| 	int node; |  | ||||||
| 	int parent; |  | ||||||
| 
 |  | ||||||
| 	/* Get the node from FDT for codec */ |  | ||||||
| 	node = fdtdec_next_compatible(blob, 0, COMPAT_WOLFSON_WM8994_CODEC); |  | ||||||
| 	if (node <= 0) { |  | ||||||
| 		debug("EXYNOS_SOUND: No node for codec in device tree\n"); |  | ||||||
| 		debug("node = %d\n", node); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	parent = fdt_parent_offset(blob, node); |  | ||||||
| 	if (parent < 0) { |  | ||||||
| 		debug("%s: Cannot find node parent\n", __func__); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	compat = fdtdec_lookup(blob, parent); |  | ||||||
| 	switch (compat) { |  | ||||||
| 	case COMPAT_SAMSUNG_S3C2440_I2C: |  | ||||||
| 		pcodec_info->i2c_bus = i2c_get_bus_num_fdt(parent); |  | ||||||
| 		error |= pcodec_info->i2c_bus; |  | ||||||
| 		debug("i2c bus = %d\n", pcodec_info->i2c_bus); |  | ||||||
| 		pcodec_info->i2c_dev_addr = fdtdec_get_int(blob, node, |  | ||||||
| 							"reg", 0); |  | ||||||
| 		error |= pcodec_info->i2c_dev_addr; |  | ||||||
| 		debug("i2c dev addr = %d\n", pcodec_info->i2c_dev_addr); |  | ||||||
| 		break; |  | ||||||
| 	default: |  | ||||||
| 		debug("%s: Unknown compat id %d\n", __func__, compat); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (error == -1) { |  | ||||||
| 		debug("fail to get wm8994 codec node properties\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| static int _wm8994_init(struct wm8994_priv *priv, | static int _wm8994_init(struct wm8994_priv *priv, | ||||||
| 			enum en_audio_interface aif_id, int sampling_rate, | 			enum en_audio_interface aif_id, int sampling_rate, | ||||||
| 			int mclk_freq, int bits_per_sample, | 			int mclk_freq, int bits_per_sample, | ||||||
|  | @ -905,36 +840,6 @@ static int _wm8994_init(struct wm8994_priv *priv, | ||||||
| 	return ret; | 	return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifndef CONFIG_DM_SOUND |  | ||||||
| /* WM8994 Device Initialisation */ |  | ||||||
| int wm8994_init(const void *blob, enum en_audio_interface aif_id, |  | ||||||
| 		int sampling_rate, int mclk_freq, int bits_per_sample, |  | ||||||
| 		unsigned int channels) |  | ||||||
| { |  | ||||||
| 	struct sound_codec_info pcodec_info; |  | ||||||
| 	struct wm8994_priv wm8994_info; |  | ||||||
| 	int ret; |  | ||||||
| 
 |  | ||||||
| 	/* Get the codec Values */ |  | ||||||
| 	if (get_codec_values(&pcodec_info, blob) < 0) { |  | ||||||
| 		debug("FDT Codec values failed\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/* shift the device address by 1 for 7 bit addressing */ |  | ||||||
| 	wm8994_info.i2c_addr = pcodec_info.i2c_dev_addr; |  | ||||||
| 	i2c_set_bus_num(pcodec_info.i2c_bus); |  | ||||||
| 	ret = wm8994_device_init(&wm8994_info); |  | ||||||
| 	if (ret < 0) { |  | ||||||
| 		debug("%s: wm8994 codec chip init failed\n", __func__); |  | ||||||
| 		return ret; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return _wm8994_init(&wm8994_info, aif_id, sampling_rate, mclk_freq, |  | ||||||
| 			    bits_per_sample, channels); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| static int wm8994_set_params(struct udevice *dev, int interface, int rate, | static int wm8994_set_params(struct udevice *dev, int interface, int rate, | ||||||
| 			     int mclk_freq, int bits_per_sample, uint channels) | 			     int mclk_freq, int bits_per_sample, uint channels) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -45,14 +45,6 @@ struct sound_uc_priv { | ||||||
| void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, | ||||||
| 			      uint freq); | 			      uint freq); | ||||||
| 
 | 
 | ||||||
| /*
 |  | ||||||
|  * Initialises audio sub system |  | ||||||
|  * @param blob	Pointer of device tree node or NULL if none. |  | ||||||
|  * @return	int value 0 for success, -1 for error |  | ||||||
|  */ |  | ||||||
| int sound_init(const void *blob); |  | ||||||
| 
 |  | ||||||
| #ifdef CONFIG_DM_SOUND |  | ||||||
| /*
 | /*
 | ||||||
|  * The sound uclass brings together a data transport (currently only I2C) and a |  * The sound uclass brings together a data transport (currently only I2C) and a | ||||||
|  * codec (currently connected over I2C). |  * codec (currently connected over I2C). | ||||||
|  | @ -101,14 +93,4 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz); | ||||||
|  */ |  */ | ||||||
| int sound_find_codec_i2s(struct udevice *dev); | int sound_find_codec_i2s(struct udevice *dev); | ||||||
| 
 | 
 | ||||||
| #else |  | ||||||
| /*
 |  | ||||||
|  * plays the pcm data buffer in pcm_data.h through i2s1 to make the |  | ||||||
|  * sine wave sound |  | ||||||
|  * |  | ||||||
|  * @return	int 0 for success, -1 for error |  | ||||||
|  */ |  | ||||||
| int sound_play(uint32_t msec, uint32_t frequency); |  | ||||||
| #endif /* CONFIG_DM_SOUND */ |  | ||||||
| 
 |  | ||||||
| #endif  /* __SOUND__H__ */ | #endif  /* __SOUND__H__ */ | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o | ||||||
| # subsystem you must add sandbox tests here.
 | # subsystem you must add sandbox tests here.
 | ||||||
| obj-$(CONFIG_UT_DM) += core.o | obj-$(CONFIG_UT_DM) += core.o | ||||||
| ifneq ($(CONFIG_SANDBOX),) | ifneq ($(CONFIG_SANDBOX),) | ||||||
| obj-$(CONFIG_DM_SOUND) += audio.o | obj-$(CONFIG_SOUND) += audio.o | ||||||
| obj-$(CONFIG_BLK) += blk.o | obj-$(CONFIG_BLK) += blk.o | ||||||
| obj-$(CONFIG_BOARD) += board.o | obj-$(CONFIG_BOARD) += board.o | ||||||
| obj-$(CONFIG_CLK) += clk.o | obj-$(CONFIG_CLK) += clk.o | ||||||
|  | @ -22,7 +22,7 @@ obj-$(CONFIG_FIRMWARE) += firmware.o | ||||||
| obj-$(CONFIG_DM_GPIO) += gpio.o | obj-$(CONFIG_DM_GPIO) += gpio.o | ||||||
| obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o | obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o | ||||||
| obj-$(CONFIG_DM_I2C) += i2c.o | obj-$(CONFIG_DM_I2C) += i2c.o | ||||||
| obj-$(CONFIG_DM_SOUND) += i2s.o | obj-$(CONFIG_SOUND) += i2s.o | ||||||
| obj-$(CONFIG_LED) += led.o | obj-$(CONFIG_LED) += led.o | ||||||
| obj-$(CONFIG_DM_MAILBOX) += mailbox.o | obj-$(CONFIG_DM_MAILBOX) += mailbox.o | ||||||
| obj-$(CONFIG_DM_MMC) += mmc.o | obj-$(CONFIG_DM_MMC) += mmc.o | ||||||
|  | @ -55,7 +55,7 @@ obj-$(CONFIG_AXI) += axi.o | ||||||
| obj-$(CONFIG_MISC) += misc.o | obj-$(CONFIG_MISC) += misc.o | ||||||
| obj-$(CONFIG_DM_SERIAL) += serial.o | obj-$(CONFIG_DM_SERIAL) += serial.o | ||||||
| obj-$(CONFIG_CPU) += cpu.o | obj-$(CONFIG_CPU) += cpu.o | ||||||
| obj-$(CONFIG_DM_SOUND) += sound.o | obj-$(CONFIG_SOUND) += sound.o | ||||||
| obj-$(CONFIG_TEE) += tee.o | obj-$(CONFIG_TEE) += tee.o | ||||||
| obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o | obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o | ||||||
| obj-$(CONFIG_DMA) += dma.o | obj-$(CONFIG_DMA) += dma.o | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue