Skip to content

bcm2835-i2s: Changes for allowing asymmetric sample formats. #1783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions sound/soc/bcm/bcm2835-i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
unsigned int sampling_rate = params_rate(params);
unsigned int data_length, data_delay, bclk_ratio;
unsigned int ch1pos, ch2pos, mode, format;
unsigned int previous_ftxp, previous_frxp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still unnecessary.

unsigned int mash = BCM2835_CLK_MASH_1;
unsigned int divi, divf, target_frequency;
int clk_src = -1;
Expand All @@ -320,6 +321,7 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
|| master == SND_SOC_DAIFMT_CBM_CFS);
uint32_t csreg;
bool packed;

/*
* If a stream is already enabled,
Expand Down Expand Up @@ -465,26 +467,46 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}

/*
* Set format for both streams.
* We cannot set another frame length
* (and therefore word length) anyway,
* so the format will be the same.
*/
regmap_write(dev->i2s_regmap, BCM2835_I2S_RXC_A_REG, format);
regmap_write(dev->i2s_regmap, BCM2835_I2S_TXC_A_REG, format);
/* Set the format for the matching stream direction. */
switch (substream->stream) {
case SNDRV_PCM_STREAM_PLAYBACK:
regmap_write(dev->i2s_regmap, BCM2835_I2S_TXC_A_REG, format);
break;
case SNDRV_PCM_STREAM_CAPTURE:
regmap_write(dev->i2s_regmap, BCM2835_I2S_RXC_A_REG, format);
break;
default:
return -EINVAL;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is the same, why split ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hw_params is called once for each direction (playback, capture), depending on what the user software wants to do. The substream->stream stores the requested direction. So the whole idea of this pull request is to react and change only the state that is relevant to the requested direction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK seems good.


/* Setup the I2S mode */
/* Keep existing FTXP and FRXP values. */
regmap_read(dev->i2s_regmap, BCM2835_I2S_MODE_A_REG, &mode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implications of restoring the mode are quite large and risky! Why not let the file set it up from scratch ?
All the lines which treat mode in the file do "mode |=" to alter mode. They all assume that mode starts as : mode = 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the stream direction specific state is kept, not the whole mode.

There's mode = 0 line still there, see below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I see it now.


previous_ftxp = mode & BCM2835_I2S_FTXP;
previous_frxp = mode & BCM2835_I2S_FRXP;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these previous variables aren't used, they should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used, see below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can still be removed, see my new comment for line number 502


mode = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the mode is reset.

Copy link
Contributor

@flatmax flatmax Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I see, but you can get rid of this for simplification because of changes suggested from line 502


if (data_length <= 16) {
/*
* Use frame packed mode (2 channels per 32 bit word)
* We cannot set another frame length in the second stream
* (and therefore word length) anyway,
* so the format will be the same.
*/
mode |= BCM2835_I2S_FTXP | BCM2835_I2S_FRXP;
/*
* Retain the frame packed mode (2 channels per 32 bit word)
* of the other direction stream intact. The formats of each
* direction can be different as long as the frame length is
* shared for both.
*/
packed = data_length <= 16;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is good practice, but the packed variable can also be removed and this can be inline below.


switch (substream->stream) {
case SNDRV_PCM_STREAM_PLAYBACK:
mode |= previous_frxp;
Copy link
Contributor Author

@gtrainavicius gtrainavicius Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the location where previous_... variables are used.

Copy link
Contributor

@flatmax flatmax Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yep, however you can remove this line, not necessary.

mode |= packed ? BCM2835_I2S_FTXP : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with : mode &= packed ? BCM2835_I2S_FTXP : 0;

break;
case SNDRV_PCM_STREAM_CAPTURE:
mode |= previous_ftxp;
Copy link
Contributor

@flatmax flatmax Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

mode |= packed ? BCM2835_I2S_FRXP : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with : mode &= packed ? BCM2835_I2S_FRXP : 0;

break;
default:
return -EINVAL;
}

mode |= BCM2835_I2S_FLEN(bclk_ratio - 1);
Expand Down