aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Jarzmik <robert.jarzmik@free.fr>2017-09-02 15:54:06 -0400
committerMark Brown <broonie@kernel.org>2017-09-04 13:24:56 -0400
commit6f8acad646d29fbf5665a6e0c9adae71c3c2131e (patch)
tree872fbd3a3e4c81e523424eecb68ba94cc03285f2
parent8d43344108c9945456128b75b69beee594b64ed6 (diff)
ASoC: arm: make pxa2xx-ac97-lib ac97 codec agnostic
All pxa library functions don't use the input parameters for nothing but slot number. This simplifies their prototypes, and makes them usable by both the legacy ac97 bus and the new ac97 bus. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--include/sound/pxa2xx-lib.h15
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c37
-rw-r--r--sound/arm/pxa2xx-ac97.c35
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c32
4 files changed, 83 insertions, 36 deletions
diff --git a/include/sound/pxa2xx-lib.h b/include/sound/pxa2xx-lib.h
index 6ef629bde164..85352becec7c 100644
--- a/include/sound/pxa2xx-lib.h
+++ b/include/sound/pxa2xx-lib.h
@@ -1,10 +1,13 @@
1#ifndef PXA2XX_LIB_H 1#ifndef PXA2XX_LIB_H
2#define PXA2XX_LIB_H 2#define PXA2XX_LIB_H
3 3
4#include <uapi/sound/asound.h>
4#include <linux/platform_device.h> 5#include <linux/platform_device.h>
5#include <sound/ac97_codec.h>
6 6
7/* PCM */ 7/* PCM */
8struct snd_pcm_substream;
9struct snd_pcm_hw_params;
10struct snd_pcm;
8 11
9extern int __pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream, 12extern int __pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
10 struct snd_pcm_hw_params *params); 13 struct snd_pcm_hw_params *params);
@@ -21,12 +24,12 @@ extern void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm);
21 24
22/* AC97 */ 25/* AC97 */
23 26
24extern unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg); 27extern int pxa2xx_ac97_read(int slot, unsigned short reg);
25extern void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val); 28extern int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val);
26 29
27extern bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97); 30extern bool pxa2xx_ac97_try_warm_reset(void);
28extern bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97); 31extern bool pxa2xx_ac97_try_cold_reset(void);
29extern void pxa2xx_ac97_finish_reset(struct snd_ac97 *ac97); 32extern void pxa2xx_ac97_finish_reset(void);
30 33
31extern int pxa2xx_ac97_hw_suspend(void); 34extern int pxa2xx_ac97_hw_suspend(void);
32extern int pxa2xx_ac97_hw_resume(void); 35extern int pxa2xx_ac97_hw_resume(void);
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index 39c3969ac1c7..5950a9e218d9 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -20,7 +20,6 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22 22
23#include <sound/ac97_codec.h>
24#include <sound/pxa2xx-lib.h> 23#include <sound/pxa2xx-lib.h>
25 24
26#include <mach/irqs.h> 25#include <mach/irqs.h>
@@ -46,38 +45,41 @@ extern void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio);
46 * 1 jiffy timeout if interrupt never comes). 45 * 1 jiffy timeout if interrupt never comes).
47 */ 46 */
48 47
49unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 48int pxa2xx_ac97_read(int slot, unsigned short reg)
50{ 49{
51 unsigned short val = -1; 50 int val = -ENODEV;
52 volatile u32 *reg_addr; 51 volatile u32 *reg_addr;
53 52
53 if (slot > 0)
54 return -ENODEV;
55
54 mutex_lock(&car_mutex); 56 mutex_lock(&car_mutex);
55 57
56 /* set up primary or secondary codec space */ 58 /* set up primary or secondary codec space */
57 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS) 59 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
58 reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE; 60 reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE;
59 else 61 else
60 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 62 reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE;
61 reg_addr += (reg >> 1); 63 reg_addr += (reg >> 1);
62 64
63 /* start read access across the ac97 link */ 65 /* start read access across the ac97 link */
64 GSR = GSR_CDONE | GSR_SDONE; 66 GSR = GSR_CDONE | GSR_SDONE;
65 gsr_bits = 0; 67 gsr_bits = 0;
66 val = *reg_addr; 68 val = (*reg_addr & 0xffff);
67 if (reg == AC97_GPIO_STATUS) 69 if (reg == AC97_GPIO_STATUS)
68 goto out; 70 goto out;
69 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && 71 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
70 !((GSR | gsr_bits) & GSR_SDONE)) { 72 !((GSR | gsr_bits) & GSR_SDONE)) {
71 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", 73 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
72 __func__, reg, GSR | gsr_bits); 74 __func__, reg, GSR | gsr_bits);
73 val = -1; 75 val = -ETIMEDOUT;
74 goto out; 76 goto out;
75 } 77 }
76 78
77 /* valid data now */ 79 /* valid data now */
78 GSR = GSR_CDONE | GSR_SDONE; 80 GSR = GSR_CDONE | GSR_SDONE;
79 gsr_bits = 0; 81 gsr_bits = 0;
80 val = *reg_addr; 82 val = (*reg_addr & 0xffff);
81 /* but we've just started another cycle... */ 83 /* but we've just started another cycle... */
82 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); 84 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
83 85
@@ -86,29 +88,32 @@ out: mutex_unlock(&car_mutex);
86} 88}
87EXPORT_SYMBOL_GPL(pxa2xx_ac97_read); 89EXPORT_SYMBOL_GPL(pxa2xx_ac97_read);
88 90
89void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, 91int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val)
90 unsigned short val)
91{ 92{
92 volatile u32 *reg_addr; 93 volatile u32 *reg_addr;
94 int ret = 0;
93 95
94 mutex_lock(&car_mutex); 96 mutex_lock(&car_mutex);
95 97
96 /* set up primary or secondary codec space */ 98 /* set up primary or secondary codec space */
97 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS) 99 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
98 reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE; 100 reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE;
99 else 101 else
100 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 102 reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE;
101 reg_addr += (reg >> 1); 103 reg_addr += (reg >> 1);
102 104
103 GSR = GSR_CDONE | GSR_SDONE; 105 GSR = GSR_CDONE | GSR_SDONE;
104 gsr_bits = 0; 106 gsr_bits = 0;
105 *reg_addr = val; 107 *reg_addr = val;
106 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && 108 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
107 !((GSR | gsr_bits) & GSR_CDONE)) 109 !((GSR | gsr_bits) & GSR_CDONE)) {
108 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", 110 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
109 __func__, reg, GSR | gsr_bits); 111 __func__, reg, GSR | gsr_bits);
112 ret = -EIO;
113 }
110 114
111 mutex_unlock(&car_mutex); 115 mutex_unlock(&car_mutex);
116 return ret;
112} 117}
113EXPORT_SYMBOL_GPL(pxa2xx_ac97_write); 118EXPORT_SYMBOL_GPL(pxa2xx_ac97_write);
114 119
@@ -188,7 +193,7 @@ static inline void pxa_ac97_cold_pxa3xx(void)
188} 193}
189#endif 194#endif
190 195
191bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97) 196bool pxa2xx_ac97_try_warm_reset(void)
192{ 197{
193 unsigned long gsr; 198 unsigned long gsr;
194 unsigned int timeout = 100; 199 unsigned int timeout = 100;
@@ -225,7 +230,7 @@ bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
225} 230}
226EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset); 231EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
227 232
228bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97) 233bool pxa2xx_ac97_try_cold_reset(void)
229{ 234{
230 unsigned long gsr; 235 unsigned long gsr;
231 unsigned int timeout = 1000; 236 unsigned int timeout = 1000;
@@ -263,7 +268,7 @@ bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
263EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset); 268EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset);
264 269
265 270
266void pxa2xx_ac97_finish_reset(struct snd_ac97 *ac97) 271void pxa2xx_ac97_finish_reset(void)
267{ 272{
268 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 273 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
269 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 274 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index fbd5dad0c484..4bc244c40f80 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -29,19 +29,38 @@
29 29
30#include "pxa2xx-pcm.h" 30#include "pxa2xx-pcm.h"
31 31
32static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) 32static void pxa2xx_ac97_legacy_reset(struct snd_ac97 *ac97)
33{ 33{
34 if (!pxa2xx_ac97_try_cold_reset(ac97)) { 34 if (!pxa2xx_ac97_try_cold_reset())
35 pxa2xx_ac97_try_warm_reset(ac97); 35 pxa2xx_ac97_try_warm_reset();
36 } 36
37 pxa2xx_ac97_finish_reset();
38}
39
40static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97 *ac97,
41 unsigned short reg)
42{
43 int ret;
44
45 ret = pxa2xx_ac97_read(ac97->num, reg);
46 if (ret < 0)
47 return 0;
48 else
49 return (unsigned short)(ret & 0xffff);
50}
51
52static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
53 unsigned short reg, unsigned short val)
54{
55 int __always_unused ret;
37 56
38 pxa2xx_ac97_finish_reset(ac97); 57 ret = pxa2xx_ac97_write(ac97->num, reg, val);
39} 58}
40 59
41static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 60static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
42 .read = pxa2xx_ac97_read, 61 .read = pxa2xx_ac97_legacy_read,
43 .write = pxa2xx_ac97_write, 62 .write = pxa2xx_ac97_legacy_write,
44 .reset = pxa2xx_ac97_reset, 63 .reset = pxa2xx_ac97_legacy_reset,
45}; 64};
46 65
47static struct pxad_param pxa2xx_ac97_pcm_out_req = { 66static struct pxad_param pxa2xx_ac97_pcm_out_req = {
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index f49bf02e5ec2..803818aabee9 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -29,21 +29,41 @@
29 29
30static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 30static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
31{ 31{
32 pxa2xx_ac97_try_warm_reset(ac97); 32 pxa2xx_ac97_try_warm_reset();
33 33
34 pxa2xx_ac97_finish_reset(ac97); 34 pxa2xx_ac97_finish_reset();
35} 35}
36 36
37static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 37static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
38{ 38{
39 pxa2xx_ac97_try_cold_reset(ac97); 39 pxa2xx_ac97_try_cold_reset();
40 40
41 pxa2xx_ac97_finish_reset(ac97); 41 pxa2xx_ac97_finish_reset();
42}
43
44static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97 *ac97,
45 unsigned short reg)
46{
47 int ret;
48
49 ret = pxa2xx_ac97_read(ac97->num, reg);
50 if (ret < 0)
51 return 0;
52 else
53 return (unsigned short)(ret & 0xffff);
54}
55
56static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
57 unsigned short reg, unsigned short val)
58{
59 int ret;
60
61 ret = pxa2xx_ac97_write(ac97->num, reg, val);
42} 62}
43 63
44static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 64static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
45 .read = pxa2xx_ac97_read, 65 .read = pxa2xx_ac97_legacy_read,
46 .write = pxa2xx_ac97_write, 66 .write = pxa2xx_ac97_legacy_write,
47 .warm_reset = pxa2xx_ac97_warm_reset, 67 .warm_reset = pxa2xx_ac97_warm_reset,
48 .reset = pxa2xx_ac97_cold_reset, 68 .reset = pxa2xx_ac97_cold_reset,
49}; 69};