diff options
author | Nicolin Chen <Guangyu.Chen@freescale.com> | 2014-03-27 07:06:59 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-03-27 09:21:07 -0400 |
commit | e2681a1bf5ae053426a6c5c1daaed17b2f95efe6 (patch) | |
tree | 96bef034175448df0c3ea21042b5767cca941035 /sound | |
parent | a3f7dcc9cc0392528bff75b17adfcd74fb8a0ecd (diff) |
ASoC: fsl_sai: Add isr to deal with error flag
It's quite cricial to clear error flags because SAI might hang if getting
FIFO underrun during playback (I haven't confirmed the same issue on Rx
overflow though).
So this patch enables those irq and adds isr() to clear the flags so as to
keep playback entirely safe.
Signed-off-by: Nicolin Chen <Guangyu.Chen@freescale.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/fsl/fsl_sai.c | 85 | ||||
-rw-r--r-- | sound/soc/fsl/fsl_sai.h | 15 |
2 files changed, 97 insertions, 3 deletions
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c index c4a423111673..0bc98bb21810 100644 --- a/sound/soc/fsl/fsl_sai.c +++ b/sound/soc/fsl/fsl_sai.c | |||
@@ -23,6 +23,71 @@ | |||
23 | 23 | ||
24 | #include "fsl_sai.h" | 24 | #include "fsl_sai.h" |
25 | 25 | ||
26 | #define FSL_SAI_FLAGS (FSL_SAI_CSR_SEIE |\ | ||
27 | FSL_SAI_CSR_FEIE) | ||
28 | |||
29 | static irqreturn_t fsl_sai_isr(int irq, void *devid) | ||
30 | { | ||
31 | struct fsl_sai *sai = (struct fsl_sai *)devid; | ||
32 | struct device *dev = &sai->pdev->dev; | ||
33 | u32 xcsr, mask; | ||
34 | |||
35 | /* Only handle those what we enabled */ | ||
36 | mask = (FSL_SAI_FLAGS >> FSL_SAI_CSR_xIE_SHIFT) << FSL_SAI_CSR_xF_SHIFT; | ||
37 | |||
38 | /* Tx IRQ */ | ||
39 | regmap_read(sai->regmap, FSL_SAI_TCSR, &xcsr); | ||
40 | xcsr &= mask; | ||
41 | |||
42 | if (xcsr & FSL_SAI_CSR_WSF) | ||
43 | dev_dbg(dev, "isr: Start of Tx word detected\n"); | ||
44 | |||
45 | if (xcsr & FSL_SAI_CSR_SEF) | ||
46 | dev_warn(dev, "isr: Tx Frame sync error detected\n"); | ||
47 | |||
48 | if (xcsr & FSL_SAI_CSR_FEF) { | ||
49 | dev_warn(dev, "isr: Transmit underrun detected\n"); | ||
50 | /* FIFO reset for safety */ | ||
51 | xcsr |= FSL_SAI_CSR_FR; | ||
52 | } | ||
53 | |||
54 | if (xcsr & FSL_SAI_CSR_FWF) | ||
55 | dev_dbg(dev, "isr: Enabled transmit FIFO is empty\n"); | ||
56 | |||
57 | if (xcsr & FSL_SAI_CSR_FRF) | ||
58 | dev_dbg(dev, "isr: Transmit FIFO watermark has been reached\n"); | ||
59 | |||
60 | regmap_update_bits(sai->regmap, FSL_SAI_TCSR, | ||
61 | FSL_SAI_CSR_xF_W_MASK | FSL_SAI_CSR_FR, xcsr); | ||
62 | |||
63 | /* Rx IRQ */ | ||
64 | regmap_read(sai->regmap, FSL_SAI_RCSR, &xcsr); | ||
65 | xcsr &= mask; | ||
66 | |||
67 | if (xcsr & FSL_SAI_CSR_WSF) | ||
68 | dev_dbg(dev, "isr: Start of Rx word detected\n"); | ||
69 | |||
70 | if (xcsr & FSL_SAI_CSR_SEF) | ||
71 | dev_warn(dev, "isr: Rx Frame sync error detected\n"); | ||
72 | |||
73 | if (xcsr & FSL_SAI_CSR_FEF) { | ||
74 | dev_warn(dev, "isr: Receive overflow detected\n"); | ||
75 | /* FIFO reset for safety */ | ||
76 | xcsr |= FSL_SAI_CSR_FR; | ||
77 | } | ||
78 | |||
79 | if (xcsr & FSL_SAI_CSR_FWF) | ||
80 | dev_dbg(dev, "isr: Enabled receive FIFO is full\n"); | ||
81 | |||
82 | if (xcsr & FSL_SAI_CSR_FRF) | ||
83 | dev_dbg(dev, "isr: Receive FIFO watermark has been reached\n"); | ||
84 | |||
85 | regmap_update_bits(sai->regmap, FSL_SAI_RCSR, | ||
86 | FSL_SAI_CSR_xF_W_MASK | FSL_SAI_CSR_FR, xcsr); | ||
87 | |||
88 | return IRQ_HANDLED; | ||
89 | } | ||
90 | |||
26 | static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai, | 91 | static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai, |
27 | int clk_id, unsigned int freq, int fsl_dir) | 92 | int clk_id, unsigned int freq, int fsl_dir) |
28 | { | 93 | { |
@@ -373,8 +438,8 @@ static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai) | |||
373 | { | 438 | { |
374 | struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); | 439 | struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); |
375 | 440 | ||
376 | regmap_update_bits(sai->regmap, FSL_SAI_TCSR, 0xffffffff, 0x0); | 441 | regmap_update_bits(sai->regmap, FSL_SAI_TCSR, 0xffffffff, FSL_SAI_FLAGS); |
377 | regmap_update_bits(sai->regmap, FSL_SAI_RCSR, 0xffffffff, 0x0); | 442 | regmap_update_bits(sai->regmap, FSL_SAI_RCSR, 0xffffffff, FSL_SAI_FLAGS); |
378 | regmap_update_bits(sai->regmap, FSL_SAI_TCR1, FSL_SAI_CR1_RFW_MASK, | 443 | regmap_update_bits(sai->regmap, FSL_SAI_TCR1, FSL_SAI_CR1_RFW_MASK, |
379 | FSL_SAI_MAXBURST_TX * 2); | 444 | FSL_SAI_MAXBURST_TX * 2); |
380 | regmap_update_bits(sai->regmap, FSL_SAI_RCR1, FSL_SAI_CR1_RFW_MASK, | 445 | regmap_update_bits(sai->regmap, FSL_SAI_RCR1, FSL_SAI_CR1_RFW_MASK, |
@@ -490,12 +555,14 @@ static int fsl_sai_probe(struct platform_device *pdev) | |||
490 | struct fsl_sai *sai; | 555 | struct fsl_sai *sai; |
491 | struct resource *res; | 556 | struct resource *res; |
492 | void __iomem *base; | 557 | void __iomem *base; |
493 | int ret; | 558 | int irq, ret; |
494 | 559 | ||
495 | sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); | 560 | sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); |
496 | if (!sai) | 561 | if (!sai) |
497 | return -ENOMEM; | 562 | return -ENOMEM; |
498 | 563 | ||
564 | sai->pdev = pdev; | ||
565 | |||
499 | sai->big_endian_regs = of_property_read_bool(np, "big-endian-regs"); | 566 | sai->big_endian_regs = of_property_read_bool(np, "big-endian-regs"); |
500 | if (sai->big_endian_regs) | 567 | if (sai->big_endian_regs) |
501 | fsl_sai_regmap_config.val_format_endian = REGMAP_ENDIAN_BIG; | 568 | fsl_sai_regmap_config.val_format_endian = REGMAP_ENDIAN_BIG; |
@@ -514,6 +581,18 @@ static int fsl_sai_probe(struct platform_device *pdev) | |||
514 | return PTR_ERR(sai->regmap); | 581 | return PTR_ERR(sai->regmap); |
515 | } | 582 | } |
516 | 583 | ||
584 | irq = platform_get_irq(pdev, 0); | ||
585 | if (irq < 0) { | ||
586 | dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); | ||
587 | return irq; | ||
588 | } | ||
589 | |||
590 | ret = devm_request_irq(&pdev->dev, irq, fsl_sai_isr, 0, np->name, sai); | ||
591 | if (ret) { | ||
592 | dev_err(&pdev->dev, "failed to claim irq %u\n", irq); | ||
593 | return ret; | ||
594 | } | ||
595 | |||
517 | sai->dma_params_rx.addr = res->start + FSL_SAI_RDR; | 596 | sai->dma_params_rx.addr = res->start + FSL_SAI_RDR; |
518 | sai->dma_params_tx.addr = res->start + FSL_SAI_TDR; | 597 | sai->dma_params_tx.addr = res->start + FSL_SAI_TDR; |
519 | sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; | 598 | sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; |
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h index e432260be598..a264185c7138 100644 --- a/sound/soc/fsl/fsl_sai.h +++ b/sound/soc/fsl/fsl_sai.h | |||
@@ -37,7 +37,21 @@ | |||
37 | 37 | ||
38 | /* SAI Transmit/Recieve Control Register */ | 38 | /* SAI Transmit/Recieve Control Register */ |
39 | #define FSL_SAI_CSR_TERE BIT(31) | 39 | #define FSL_SAI_CSR_TERE BIT(31) |
40 | #define FSL_SAI_CSR_FR BIT(25) | ||
41 | #define FSL_SAI_CSR_xF_SHIFT 16 | ||
42 | #define FSL_SAI_CSR_xF_W_SHIFT 18 | ||
43 | #define FSL_SAI_CSR_xF_MASK (0x1f << FSL_SAI_CSR_xF_SHIFT) | ||
44 | #define FSL_SAI_CSR_xF_W_MASK (0x7 << FSL_SAI_CSR_xF_W_SHIFT) | ||
45 | #define FSL_SAI_CSR_WSF BIT(20) | ||
46 | #define FSL_SAI_CSR_SEF BIT(19) | ||
47 | #define FSL_SAI_CSR_FEF BIT(18) | ||
40 | #define FSL_SAI_CSR_FWF BIT(17) | 48 | #define FSL_SAI_CSR_FWF BIT(17) |
49 | #define FSL_SAI_CSR_FRF BIT(16) | ||
50 | #define FSL_SAI_CSR_xIE_SHIFT 8 | ||
51 | #define FSL_SAI_CSR_WSIE BIT(12) | ||
52 | #define FSL_SAI_CSR_SEIE BIT(11) | ||
53 | #define FSL_SAI_CSR_FEIE BIT(10) | ||
54 | #define FSL_SAI_CSR_FWIE BIT(9) | ||
41 | #define FSL_SAI_CSR_FRIE BIT(8) | 55 | #define FSL_SAI_CSR_FRIE BIT(8) |
42 | #define FSL_SAI_CSR_FRDE BIT(0) | 56 | #define FSL_SAI_CSR_FRDE BIT(0) |
43 | 57 | ||
@@ -99,6 +113,7 @@ | |||
99 | #define FSL_SAI_MAXBURST_RX 6 | 113 | #define FSL_SAI_MAXBURST_RX 6 |
100 | 114 | ||
101 | struct fsl_sai { | 115 | struct fsl_sai { |
116 | struct platform_device *pdev; | ||
102 | struct regmap *regmap; | 117 | struct regmap *regmap; |
103 | 118 | ||
104 | bool big_endian_regs; | 119 | bool big_endian_regs; |