1 From 0f409e6c30a04eb85792a6883e81ad2af118c7bd Mon Sep 17 00:00:00 2001
2 From: Matthias Reichl <github@hias.horus.com>
3 Date: Thu, 18 Jan 2018 12:36:44 +0100
4 Subject: [PATCH 161/454] ASoC: bcm2835: fix hw_params error when device is in
7 commit 8d5737a5f53902a916ee1e1cb248c9b8b883b2ea upstream.
9 If bcm2835 is configured as bitclock master calling hw_params()
10 after prepare() fails with EBUSY. This also makes it impossible to
11 use bcm2835 in full duplex mode.
13 The error is caused by the split clock setup: clk_set_rate
14 is called in hw_params, clk_prepare_enable in prepare. As hw_params
15 doesn't check if the clock was already enabled clk_set_rate
18 Fix this by moving clock startup from prepare to hw_params and
19 let hw_params properly deal with an already set up or enabled
22 Signed-off-by: Matthias Reichl <hias@horus.com>
24 sound/soc/bcm/bcm2835-i2s.c | 20 ++++++++++++++------
25 1 file changed, 14 insertions(+), 6 deletions(-)
27 --- a/sound/soc/bcm/bcm2835-i2s.c
28 +++ b/sound/soc/bcm/bcm2835-i2s.c
29 @@ -130,6 +130,7 @@ struct bcm2835_i2s_dev {
30 struct regmap *i2s_regmap;
36 static void bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev)
37 @@ -419,10 +420,19 @@ static int bcm2835_i2s_hw_params(struct
40 /* Clock should only be set up here if CPU is clock master */
41 - if (bit_clock_master) {
42 - ret = clk_set_rate(dev->clk, bclk_rate);
45 + if (bit_clock_master &&
46 + (!dev->clk_prepared || dev->clk_rate != bclk_rate)) {
47 + if (dev->clk_prepared)
48 + bcm2835_i2s_stop_clock(dev);
50 + if (dev->clk_rate != bclk_rate) {
51 + ret = clk_set_rate(dev->clk, bclk_rate);
54 + dev->clk_rate = bclk_rate;
57 + bcm2835_i2s_start_clock(dev);
60 /* Setup the frame format */
61 @@ -618,8 +628,6 @@ static int bcm2835_i2s_prepare(struct sn
62 struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
65 - bcm2835_i2s_start_clock(dev);
68 * Clear both FIFOs if the one that should be started
69 * is not empty at the moment. This should only happen