e94199288b7bb181543cb8cd57dcbfca70213564
[openwrt/staging/noltari.git] /
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
5 prepared state (#2345)
6
7 commit 8d5737a5f53902a916ee1e1cb248c9b8b883b2ea upstream.
8
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.
12
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
16 fails with EBUSY.
17
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
20 clock.
21
22 Signed-off-by: Matthias Reichl <hias@horus.com>
23 ---
24 sound/soc/bcm/bcm2835-i2s.c | 20 ++++++++++++++------
25 1 file changed, 14 insertions(+), 6 deletions(-)
26
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;
31 struct clk *clk;
32 bool clk_prepared;
33 + int clk_rate;
34 };
35
36 static void bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev)
37 @@ -419,10 +420,19 @@ static int bcm2835_i2s_hw_params(struct
38 }
39
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);
43 - if (ret)
44 - return ret;
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);
49 +
50 + if (dev->clk_rate != bclk_rate) {
51 + ret = clk_set_rate(dev->clk, bclk_rate);
52 + if (ret)
53 + return ret;
54 + dev->clk_rate = bclk_rate;
55 + }
56 +
57 + bcm2835_i2s_start_clock(dev);
58 }
59
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);
63 uint32_t cs_reg;
64
65 - bcm2835_i2s_start_clock(dev);
66 -
67 /*
68 * Clear both FIFOs if the one that should be started
69 * is not empty at the moment. This should only happen