Skip to content

Commit a0e9f88

Browse files
Gordon Hollingworthpopcornmix
Gordon Hollingworth
authored andcommitted
Move GPIO setup to hw_params.
This is used to stop the I2S driver from breaking the GPIO setup for other uses of the PCM interface
1 parent 972756f commit a0e9f88

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

sound/soc/bcm/bcm2708-i2s.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,31 @@ static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
305305
return 0;
306306
}
307307

308+
309+
static void bcm2708_i2s_setup_gpio(void)
310+
{
311+
/*
312+
* This is the common way to handle the GPIO pins for
313+
* the Raspberry Pi.
314+
* TODO Better way would be to handle
315+
* this in the device tree!
316+
*/
317+
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
318+
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
319+
320+
unsigned int *gpio;
321+
int pin;
322+
gpio = ioremap(GPIO_BASE, SZ_16K);
323+
324+
/* SPI is on GPIO 7..11 */
325+
for (pin = 28; pin <= 31; pin++) {
326+
INP_GPIO(pin); /* set mode to GPIO input first */
327+
SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
328+
}
329+
#undef INP_GPIO
330+
#undef SET_GPIO_ALT
331+
}
332+
308333
static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
309334
struct snd_pcm_hw_params *params,
310335
struct snd_soc_dai *dai)
@@ -334,6 +359,9 @@ static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
334359
if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
335360
return 0;
336361

362+
363+
bcm2708_i2s_setup_gpio();
364+
337365
/*
338366
* Adjust the data length according to the format.
339367
* We prefill the half frame length with an integer
@@ -790,31 +818,6 @@ static const struct snd_soc_component_driver bcm2708_i2s_component = {
790818
.name = "bcm2708-i2s-comp",
791819
};
792820

793-
794-
static void bcm2708_i2s_setup_gpio(void)
795-
{
796-
/*
797-
* This is the common way to handle the GPIO pins for
798-
* the Raspberry Pi.
799-
* TODO Better way would be to handle
800-
* this in the device tree!
801-
*/
802-
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
803-
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
804-
805-
unsigned int *gpio;
806-
int pin;
807-
gpio = ioremap(GPIO_BASE, SZ_16K);
808-
809-
/* SPI is on GPIO 7..11 */
810-
for (pin = 28; pin <= 31; pin++) {
811-
INP_GPIO(pin); /* set mode to GPIO input first */
812-
SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
813-
}
814-
#undef INP_GPIO
815-
#undef SET_GPIO_ALT
816-
}
817-
818821
static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
819822
.info = SNDRV_PCM_INFO_INTERLEAVED |
820823
SNDRV_PCM_INFO_JOINT_DUPLEX,
@@ -865,8 +868,6 @@ static int bcm2708_i2s_probe(struct platform_device *pdev)
865868
if (IS_ERR(dev))
866869
return PTR_ERR(dev);
867870

868-
bcm2708_i2s_setup_gpio();
869-
870871
dev->i2s_regmap = regmap[0];
871872
dev->clk_regmap = regmap[1];
872873

0 commit comments

Comments
 (0)