-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
unsigned int mash = BCM2835_CLK_MASH_1; | ||
unsigned int divi, divf, target_frequency; | ||
int clk_src = -1; | ||
|
@@ -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, | ||
|
@@ -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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The format is the same, why split ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If these previous variables aren't used, they should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are used, see below. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the mode is reset. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the location where previous_... variables are used. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line. |
||
mode |= packed ? BCM2835_I2S_FRXP : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are still unnecessary.