Make Freescale MPC8610 drivers more dynamic
Subsystems (4)
PATCH v2 1/1 Make Freescale MPC8610 drivers more dynamic
More miscellaneous changes to the Freescale MPC8610 driver set, with the goal of supporting multiple SSIs.
Minor documentation improvements. Allow teh CS4270 registers to be read via sysfs. Create the device names from the device tree, to allow multiple devices. Remove separate Kconfig option for the MPC8610 SOC. Various minor code optimizations. Improve programming of the global utilties registers.
---
My patch, "Add CS4270 i2c data to fsl_soc.c" must be applied for these drivers to work.
sound/soc/codecs/cs4270.c | 85 ++++++---- sound/soc/fsl/Kconfig | 28 +--- sound/soc/fsl/Makefile | 7 +- sound/soc/fsl/fsl_dma.c | 7 +- sound/soc/fsl/fsl_dma.h | 5 - sound/soc/fsl/fsl_ssi.c | 57 +++---- sound/soc/fsl/fsl_ssi.h | 19 ++- sound/soc/fsl/mpc8610_hpcd.c | 350 ++++++++++++++++++++++++++++++------------ 8 files changed, 354 insertions(+), 204 deletions(-)
rewrite sound/soc/fsl/Kconfig (77%)
sound/soc/codecs/cs4270.c +50 -35
@@ -104,18 +104,28 @@#define CS4270_MUTE_DAC_A 0x01#define CS4270_MUTE_DAC_B 0x02 -/* Private data for the CS4270 */ +/** +* struct cs4270_private: per-codec private data for the CS4270 +* @codec: codec structure +* @name: name of this codec +* @mclk: input frequency of the MCLK pin +* @mode: mode (I2S or left-justified) +* @reg_cache: register cache +* +* The register cache is NUMREGS+1 because the hardware registers are +* indexed from 1, not 0. The ASoC function that reads the registers +* assumes it's indexed from 0, so to maintain compatibility we pretend +* there is a register 0. +*/ struct cs4270_private {struct snd_soc_codec codec;char name[16 ]; -unsigned int mclk;/* Input frequency of the MCLK pin */ -unsigned int mode;/* The mode (I2S or left-justified) */ -struct snd_soc_dai_ops dai_ops; +unsigned int mclk; +unsigned int mode;struct snd_soc_dai *dai; -struct snd_soc_dai_new dai_new;struct snd_soc_dai_caps playback;struct snd_soc_dai_caps capture; -u8 reg_cache[CS4270_NUMREGS ]; +u8 reg_cache[CS4270_NUMREGS +1 ]; };/*
@@ -169,8 +179,8 @@ static struct {/* The number of MCLK/LRCK ratios supported by the CS4270 */ #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) -/* -* Determine the CS4270 samples rates. +/** +* cs4270_set_dai_sysclk: determine the CS4270 samples rates. * * 'freq' is the input frequency to MCLK. The other parameters are ignored. *
@@ -284,10 +294,10 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, container_of(codec, struct cs4270_private, codec);u8 *cache = cs4270->reg_cache; -if ((reg <CS4270_FIRSTREG ) || (reg >CS4270_LASTREG )) +if (reg >CS4270_LASTREG )return -EIO ; -return cache[reg -CS4270_FIRSTREG ]; +return cache[reg]; }/*
@@ -311,7 +321,7 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,return -EIO ;/* Only perform an I2C operation if the new value is different */ -if (cache[reg -CS4270_FIRSTREG ] != value) { +if (cache[reg] != value) {struct i2c_client *client = codec->control_data;if (i2c_smbus_write_byte_data (client, reg, value)) {
@@ -320,7 +330,7 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, }/* We've written to the hardware, so update the cache */ - cache[reg -CS4270_FIRSTREG ] = value; + cache[reg] = value; }return 0 ;
@@ -481,6 +491,13 @@ static int cs4270_codec_init(struct snd_soc_codec *codec,return ret; } +static struct snd_soc_dai_ops dai_ops = { + .hw_params = cs4270_hw_params, + .set_sysclk = cs4270_set_dai_sysclk, + .set_fmt = cs4270_set_dai_fmt, + .digital_mute = cs4270_mute, +}; +/* * Initialize the I2C interface of the CS4270 *
@@ -495,8 +512,8 @@ static int cs4270_i2c_probe(struct i2c_client *client, {struct cs4270_private *cs4270;struct snd_soc_codec *codec =NULL ; +struct snd_soc_dai_new dai_new;int ret =0 ; -int registered =0 ;/* 1 == the codec has been registered */ /* Verify that we have a CS4270 */
@@ -515,8 +532,9 @@ static int cs4270_i2c_probe(struct i2c_client *client,return -ENODEV ; } -dev_info (&client->dev,"found device at address %X\n" , client->addr); -dev_info (&client->dev,"hardware revision %X\n" , ret &0xF ); +dev_info (&client->dev, +"found device at address %X, hardware revision %u\n" , + client->addr, ret &0xF );/* * Normally, we'd call snd_soc_new_codec, but that function
@@ -532,15 +550,20 @@ static int cs4270_i2c_probe(struct i2c_client *client,/* The I2C interface is set up, so pre-fill our register cache */ ret =i2c_smbus_read_i2c_block_data (client,CS4270_FIRSTREG |0x80 , -CS4270_NUMREGS , cs4270->reg_cache); +CS4270_NUMREGS , cs4270->reg_cache +1 );if (ret !=CS4270_NUMREGS ) {dev_err (&client->dev,"failed to fill register cache\n" ); ret = -EIO ; goto error; } -strcpy (cs4270->name,"cirrus,cs4270" ); +sprintf (cs4270->name,"%s@%s" ,dev_driver_string (&client->dev), +dev_name (&client->dev)); +/* Initialize the playback and capture stream data. The sample rate +* fields are initialized later when the fabric driver calls +* cs4270_set_dai_sysclk(). Hopefully, this won't cause any problems. +*/ cs4270->playback.stream_name ="Playback" ; cs4270->playback.channels_min =1 ; cs4270->playback.channels_max =2 ;
@@ -551,11 +574,6 @@ static int cs4270_i2c_probe(struct i2c_client *client, cs4270->capture.channels_max =2 ; cs4270->capture.formats =CS4270_FORMATS ; - cs4270->dai_ops.hw_params = cs4270_hw_params; - cs4270->dai_ops.set_sysclk = cs4270_set_dai_sysclk; - cs4270->dai_ops.set_fmt = cs4270_set_dai_fmt; - cs4270->dai_ops.digital_mute = cs4270_mute; - codec = &cs4270->codec;mutex_init (&codec->mutex);
@@ -563,29 +581,29 @@ static int cs4270_i2c_probe(struct i2c_client *client,INIT_LIST_HEAD (&codec->dai_list); codec->name = cs4270->name; - codec->control_data = client; +snd_soc_card_config_codec (codec,NULL ,NULL , client); codec->init = cs4270_codec_init; codec->reg_cache = cs4270->reg_cache; codec->codec_read = cs4270_read_reg_cache; codec->codec_write = cs4270_i2c_write; + codec->reg_cache_size =sizeof (cs4270->reg_cache); ret =snd_soc_register_codec (codec, &client->dev);if (ret <0 ) {dev_err (&client->dev,"failed to register card\n" ); goto error; } - registered =1 ; +memset (&dai_new,0 ,sizeof (dai_new)); + dai_new.name = cs4270->name; + dai_new.playback = &cs4270->playback; + dai_new.capture = &cs4270->capture; + dai_new.ops = &dai_ops; - cs4270->dai_new.name = cs4270->name; - cs4270->dai_new.playback = &cs4270->playback; - cs4270->dai_new.capture = &cs4270->capture; - cs4270->dai_new.ops = &cs4270->dai_ops; - - cs4270->dai = -snd_soc_register_codec_dai (&cs4270->dai_new, &client->dev); + cs4270->dai =snd_soc_register_codec_dai (&dai_new, &client->dev);if (!cs4270->dai) {dev_err (&client->dev,"failed to register DAI\n" ); ret = -EINVAL ; +snd_soc_unregister_codec (codec); goto error; }
@@ -597,9 +615,6 @@ error:if (cs4270->dai)snd_soc_unregister_codec_dai (cs4270->dai); -if (registered) -snd_soc_unregister_codec (codec); -kfree (cs4270);return ret;
@@ -646,7 +661,7 @@ static int __init cs4270_init(void) {int ret; -printk (KERN_INFO "Cirrus Logic CS4270 ASoC codec driver\n" ); +pr_info ("Cirrus Logic CS4270 ASoC codec driver\n" );/* i2c_add_driver() will call cs4270_i2c_probe() */ ret =i2c_add_driver (&cs4270_i2c_driver);
sound/soc/fsl/Kconfig +8 -20
@@ -1,20 +1,8 @@ -menu "ALSA SoC audio for Freescale SOCs" - -config SND_SOC_MPC8610 - bool "ALSA SoC support for the MPC8610 SOC" - depends on SND_SOC && MPC8610_HPCD - default y if MPC8610 - help - Say Y if you want to add support for codecs attached to the SSI - device on an MPC8610. - -config SND_SOC_MPC8610_HPCD - bool "ALSA SoC support for the Freescale MPC8610 HPCD board" - depends on SND_SOC_MPC8610 - select SND_SOC_CS4270 - select SND_SOC_CS4270_VD33_ERRATA - default y if MPC8610_HPCD - help - Say Y if you want to enable audio on the Freescale MPC8610 HPCD. - -endmenu +config SND_SOC_MPC8610_HPCD + tristate "Freescale MPC8610 HPCD support" + depends on SND_SOC && MPC8610_HPCD + select SND_SOC_CS4270 + select SND_SOC_CS4270_VD33_ERRATA + default y if SND_SOC && MPC8610_HPCD + help + Say Y or M if you want to enable audio on the Freescale MPC8610 HPCD.
sound/soc/fsl/Makefile +2 -5
@@ -1,6 +1,3 @@ -# MPC8610 HPCD Machine Support -obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += mpc8610_hpcd.o - -# MPC8610 Platform Support -obj-$(CONFIG_SND_SOC_MPC8610) += fsl_ssi.o fsl_dma.o +# MPC8610 HPCD Support +obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += mpc8610_hpcd.o fsl_ssi.o fsl_dma.o
sound/soc/fsl/fsl_dma.c +3 -4
@@ -794,8 +794,7 @@ static struct snd_pcm_ops fsl_dma_ops = { .pointer = fsl_dma_pointer, }; -const char fsl_platform_id[] ="fsl_pcm" ; -EXPORT_SYMBOL_GPL (fsl_platform_id); +static const char fsl_platform_id[] ="fsl-elo" ;static struct snd_soc_platform_new fsl_dma_platform = { .name = fsl_platform_id,
@@ -852,7 +851,7 @@ static __init int fsl_dma_init(void) {int ret; -printk (KERN_INFO "Freescale Elo DMA ASoC PCM driver\n" ); +pr_info ("Freescale Elo DMA ASoC platform driver\n" ); ret =platform_driver_register (&fsl_dma_driver);if (ret <0 ) {
@@ -880,6 +879,6 @@ module_init(fsl_dma_init);module_exit (fsl_dma_exit);MODULE_AUTHOR ("Timur Tabi <[email protected]>" ); -MODULE_DESCRIPTION ("Freescale Elo DMA ASoC PCM driver" ); +MODULE_DESCRIPTION ("Freescale Elo DMA ASoC platform driver" );MODULE_LICENSE ("GPL" );
sound/soc/fsl/fsl_dma.h +0 -5
@@ -140,9 +140,4 @@ struct fsl_dma_info { unsigned int channel_id; }; -extern const char fsl_platform_id[]; -extern struct snd_soc_dai fsl_ssi;/* TODO: probably not needed */ - -int fsl_dma_configure (struct fsl_dma_info *dma_info); -#endif
sound/soc/fsl/fsl_ssi.c +24 -33
127 lines not on this page · raw message
sound/soc/fsl/fsl_ssi.h +14 -5
@@ -200,14 +200,22 @@ struct ccsr_ssi {* fsl_ssi_info: per-SSI private data * * @name: short name for this device ("SSI0", "SSI1", etc) +* @id: 0=SS1, 1=SSI2, etc * @ssi: pointer to the SSI's registers * @ssi_phys: physical address of the SSI registers * @irq: IRQ of this SSI -* @dev: struct device pointer -* @playback: the number of playback streams opened -* @capture: the number of capture streams opened -* @cpu_dai: the CPU DAI for this device +* @playback: 1=playback stream open, 0 otherwise +* @capture: 1=capture stream open, 0 otherwise +* @lock: spinlock for enabling/disabling the SSI +* @dai: the CPU DAI for this device * @dev_attr: the sysfs device attribute structure +* @pmuxcr: saved value of the PMUXCR register +* @dmcr: saved value of the DMACR register +* @dai_format: the serial protocol format (I2S, left-justified, etc) +* @codec_clk_direction: whether the codec is the clock master or slave +* @cpu_clk_direction: whether the SSI is the clock master or slave +* @clk_frequency: the base frequency of the clock +* @dma_info: information on the two DMA channels used by this SSI * @stats: SSI statistics */ struct fsl_ssi_info {
@@ -216,12 +224,13 @@ struct fsl_ssi_info {struct ccsr_ssi __iomem *ssi;dma_addr_t ssi_phys;unsigned int irq; -struct device *dev;unsigned int playback;unsigned int capture;spinlock_t lock;struct snd_soc_dai *dai;struct device_attribute dev_attr; +u32 pmuxcr; +u32 dmacr;unsigned int dai_format;unsigned int codec_clk_direction;
sound/soc/fsl/mpc8610_hpcd.c +253 -97
451 lines not on this page · raw message
Signature · 1 line
1.5.5
Mark Brown
AppliedQuoted 8 lines · Timur Tabi
More miscellaneous changes to the Freescale MPC8610 driver set, with the goal of supporting multiple SSIs.
Minor documentation improvements. Allow teh CS4270 registers to be read via sysfs. Create the device names from the device tree, to allow multiple devices. Remove separate
Kconfigoption for the MPC8610 SOC. Various minor code optimizations. Improve programming of the global utilties registers.
Applied, thanks. However...
Quoted 16 lines
sound/soc/fsl/Kconfig +0
-16-config SND_SOC_MPC8610 - bool "ALSA SoC support for the MPC8610 SOC" - depends on SND_SOC && MPC8610_HPCD - default y if MPC8610 - help - Say Y if you want to add support for codecs attached to the SSI - device on an MPC8610. - -config SND_SOC_MPC8610_HPCD - bool "ALSA SoC support for the Freescale MPC8610 HPCD board" - depends on SND_SOC_MPC8610 - select SND_SOC_CS4270 - select SND_SOC_CS4270_VD33_ERRATA - default y if MPC8610_HPCD - help - Say Y if you want to enable audio on the Freescale MPC8610 HPCD.
sound/soc/fsl/Kconfig line 8
Quoted 10 lines
sound/soc/fsl/Kconfig +8
-2- -endmenu +config SND_SOC_MPC8610_HPCD + tristate "Freescale MPC8610 HPCD support" + depends on SND_SOC && MPC8610_HPCD + select SND_SOC_CS4270 + select SND_SOC_CS4270_VD33_ERRATA + default y if SND_SOC && MPC8610_HPCD + help + Say Y or M if you want to enable audio on the Freescale MPC8610 HPCD.
This change means that if someone builds another board with the same CPU on it then they'll have to add all the objects for the core CPU support to the Makefile entry for their board. There should at least be a separate Kconfig thing, even if it's not user visible. I've committed a patch backing this bit out for now.
sound/soc/fsl/mpc8610_hpcd.c line 13
Quoted 5 lines
* express or implied.
*/sound/soc/fsl/mpc8610_hpcd.c +2
-0+#define DEBUG +
This probably shouldn't be on by default?
In general, it'd be a bit easier to review the changes you're making if you were able to submit individual changes in separate patches, though I appreciate that at the minute you're making a lot of changes that go over large portions of the code and can't be easily separated out so I wouldn't worry about it too much.
Quoted 3 lines · Mark Brown
This change means that if someone builds another board with the same CPU on it then they'll have to add all the objects for the core CPU support to the
Makefileentry for their board.
They'll need to update Kconfig and the Makefile anyway, so I decided to cut out the "middle man" -- the SOC.
Quoted 3 lines
There should at least be a
separateKconfigthing, even if it's not user visible. I've committed a patch backing this bit out for now.
Grrr...
Quoted 4 lines
sound/soc/fsl/mpc8610_hpcd.c line 13
Quoted 2 lines
sound/soc/fsl/mpc8610_hpcd.c +2
-0+#define DEBUG +This probably shouldn't be on by default?
For now, I want it on.
Quoted 2 lines
In general, it'd be a bit easier to review the changes you're making if you were able to submit individual changes in separate patches,
Yes, that would be nice :-)
Quoted 4 lines
though I
appreciate that at the minute you're making a lot of changes that go over large portions of the code and can't be easily separated out so I wouldn't worry about it too much.
Normally, I would submit everything as one final patch, but I hate hanging on to uncommitted code for too long.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 8 lines · Timur Tabi
Quoted 3 lines · Mark Brown
This change means that if someone builds another board with the same CPU on it then they'll have to add all the objects for the core CPU support to the
Makefileentry for their board.They'll need to update
Kconfigand theMakefileanyway, so I decided to cut out the "middle man" -- the SOC.
[As discussed on IRC, summarising for the list archive.]
For the user-visible menu that's sensible enough - the issue is more with the fact that you've now got the CPU side objects encoded into each individual board entry rather than having the board build machinery say "I need the SSI controller" or similar.
Quoted 7 lines
Quoted 4 lines
though I
appreciate that at the minute you're making a lot of changes that go over large portions of the code and can't be easily separated out so I wouldn't worry about it too much.Normally, I would submit everything as one final patch, but I hate hanging on to uncommitted code for too long.
It's not the submitting individual patches that I was meaning, it's the fact that individual patches cover multiple issues.