xref: /OK3568_Linux_fs/kernel/sound/arm/pxa2xx-ac97-lib.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Based on sound/arm/pxa2xx-ac97.c and sound/soc/pxa/pxa2xx-ac97.c
4*4882a593Smuzhiyun  * which contain:
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Author:	Nicolas Pitre
7*4882a593Smuzhiyun  * Created:	Dec 02, 2004
8*4882a593Smuzhiyun  * Copyright:	MontaVista Software Inc.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/kernel.h>
12*4882a593Smuzhiyun #include <linux/platform_device.h>
13*4882a593Smuzhiyun #include <linux/interrupt.h>
14*4882a593Smuzhiyun #include <linux/clk.h>
15*4882a593Smuzhiyun #include <linux/delay.h>
16*4882a593Smuzhiyun #include <linux/module.h>
17*4882a593Smuzhiyun #include <linux/io.h>
18*4882a593Smuzhiyun #include <linux/gpio.h>
19*4882a593Smuzhiyun #include <linux/of_gpio.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include <sound/pxa2xx-lib.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include <mach/irqs.h>
24*4882a593Smuzhiyun #include <mach/regs-ac97.h>
25*4882a593Smuzhiyun #include <mach/audio.h>
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun static DEFINE_MUTEX(car_mutex);
28*4882a593Smuzhiyun static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
29*4882a593Smuzhiyun static volatile long gsr_bits;
30*4882a593Smuzhiyun static struct clk *ac97_clk;
31*4882a593Smuzhiyun static struct clk *ac97conf_clk;
32*4882a593Smuzhiyun static int reset_gpio;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun extern void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun  * Beware PXA27x bugs:
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  *   o Slot 12 read from modem space will hang controller.
40*4882a593Smuzhiyun  *   o CDONE, SDONE interrupt fails after any slot 12 IO.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * We therefore have an hybrid approach for waiting on SDONE (interrupt or
43*4882a593Smuzhiyun  * 1 jiffy timeout if interrupt never comes).
44*4882a593Smuzhiyun  */
45*4882a593Smuzhiyun 
pxa2xx_ac97_read(int slot,unsigned short reg)46*4882a593Smuzhiyun int pxa2xx_ac97_read(int slot, unsigned short reg)
47*4882a593Smuzhiyun {
48*4882a593Smuzhiyun 	int val = -ENODEV;
49*4882a593Smuzhiyun 	volatile u32 *reg_addr;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	if (slot > 0)
52*4882a593Smuzhiyun 		return -ENODEV;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	mutex_lock(&car_mutex);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	/* set up primary or secondary codec space */
57*4882a593Smuzhiyun 	if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
58*4882a593Smuzhiyun 		reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE;
59*4882a593Smuzhiyun 	else
60*4882a593Smuzhiyun 		reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE;
61*4882a593Smuzhiyun 	reg_addr += (reg >> 1);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	/* start read access across the ac97 link */
64*4882a593Smuzhiyun 	GSR = GSR_CDONE | GSR_SDONE;
65*4882a593Smuzhiyun 	gsr_bits = 0;
66*4882a593Smuzhiyun 	val = (*reg_addr & 0xffff);
67*4882a593Smuzhiyun 	if (reg == AC97_GPIO_STATUS)
68*4882a593Smuzhiyun 		goto out;
69*4882a593Smuzhiyun 	if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
70*4882a593Smuzhiyun 	    !((GSR | gsr_bits) & GSR_SDONE)) {
71*4882a593Smuzhiyun 		printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
72*4882a593Smuzhiyun 				__func__, reg, GSR | gsr_bits);
73*4882a593Smuzhiyun 		val = -ETIMEDOUT;
74*4882a593Smuzhiyun 		goto out;
75*4882a593Smuzhiyun 	}
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	/* valid data now */
78*4882a593Smuzhiyun 	GSR = GSR_CDONE | GSR_SDONE;
79*4882a593Smuzhiyun 	gsr_bits = 0;
80*4882a593Smuzhiyun 	val = (*reg_addr & 0xffff);
81*4882a593Smuzhiyun 	/* but we've just started another cycle... */
82*4882a593Smuzhiyun 	wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun out:	mutex_unlock(&car_mutex);
85*4882a593Smuzhiyun 	return val;
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_read);
88*4882a593Smuzhiyun 
pxa2xx_ac97_write(int slot,unsigned short reg,unsigned short val)89*4882a593Smuzhiyun int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun 	volatile u32 *reg_addr;
92*4882a593Smuzhiyun 	int ret = 0;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	mutex_lock(&car_mutex);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	/* set up primary or secondary codec space */
97*4882a593Smuzhiyun 	if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
98*4882a593Smuzhiyun 		reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE;
99*4882a593Smuzhiyun 	else
100*4882a593Smuzhiyun 		reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE;
101*4882a593Smuzhiyun 	reg_addr += (reg >> 1);
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	GSR = GSR_CDONE | GSR_SDONE;
104*4882a593Smuzhiyun 	gsr_bits = 0;
105*4882a593Smuzhiyun 	*reg_addr = val;
106*4882a593Smuzhiyun 	if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
107*4882a593Smuzhiyun 	    !((GSR | gsr_bits) & GSR_CDONE)) {
108*4882a593Smuzhiyun 		printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
109*4882a593Smuzhiyun 				__func__, reg, GSR | gsr_bits);
110*4882a593Smuzhiyun 		ret = -EIO;
111*4882a593Smuzhiyun 	}
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	mutex_unlock(&car_mutex);
114*4882a593Smuzhiyun 	return ret;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_write);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun #ifdef CONFIG_PXA25x
pxa_ac97_warm_pxa25x(void)119*4882a593Smuzhiyun static inline void pxa_ac97_warm_pxa25x(void)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	gsr_bits = 0;
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	GCR |= GCR_WARM_RST;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun 
pxa_ac97_cold_pxa25x(void)126*4882a593Smuzhiyun static inline void pxa_ac97_cold_pxa25x(void)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun 	GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
129*4882a593Smuzhiyun 	GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	gsr_bits = 0;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	GCR = GCR_COLD_RST;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun #endif
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun #ifdef CONFIG_PXA27x
pxa_ac97_warm_pxa27x(void)138*4882a593Smuzhiyun static inline void pxa_ac97_warm_pxa27x(void)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun 	gsr_bits = 0;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun 	/* warm reset broken on Bulverde, so manually keep AC97 reset high */
143*4882a593Smuzhiyun 	pxa27x_configure_ac97reset(reset_gpio, true);
144*4882a593Smuzhiyun 	udelay(10);
145*4882a593Smuzhiyun 	GCR |= GCR_WARM_RST;
146*4882a593Smuzhiyun 	pxa27x_configure_ac97reset(reset_gpio, false);
147*4882a593Smuzhiyun 	udelay(500);
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun 
pxa_ac97_cold_pxa27x(void)150*4882a593Smuzhiyun static inline void pxa_ac97_cold_pxa27x(void)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun 	GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
153*4882a593Smuzhiyun 	GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	gsr_bits = 0;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	/* PXA27x Developers Manual section 13.5.2.2.1 */
158*4882a593Smuzhiyun 	clk_prepare_enable(ac97conf_clk);
159*4882a593Smuzhiyun 	udelay(5);
160*4882a593Smuzhiyun 	clk_disable_unprepare(ac97conf_clk);
161*4882a593Smuzhiyun 	GCR = GCR_COLD_RST | GCR_WARM_RST;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun #endif
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun #ifdef CONFIG_PXA3xx
pxa_ac97_warm_pxa3xx(void)166*4882a593Smuzhiyun static inline void pxa_ac97_warm_pxa3xx(void)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun 	gsr_bits = 0;
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	/* Can't use interrupts */
171*4882a593Smuzhiyun 	GCR |= GCR_WARM_RST;
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun 
pxa_ac97_cold_pxa3xx(void)174*4882a593Smuzhiyun static inline void pxa_ac97_cold_pxa3xx(void)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun 	/* Hold CLKBPB for 100us */
177*4882a593Smuzhiyun 	GCR = 0;
178*4882a593Smuzhiyun 	GCR = GCR_CLKBPB;
179*4882a593Smuzhiyun 	udelay(100);
180*4882a593Smuzhiyun 	GCR = 0;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
183*4882a593Smuzhiyun 	GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	gsr_bits = 0;
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	/* Can't use interrupts on PXA3xx */
188*4882a593Smuzhiyun 	GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun 	GCR = GCR_WARM_RST | GCR_COLD_RST;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun #endif
193*4882a593Smuzhiyun 
pxa2xx_ac97_try_warm_reset(void)194*4882a593Smuzhiyun bool pxa2xx_ac97_try_warm_reset(void)
195*4882a593Smuzhiyun {
196*4882a593Smuzhiyun 	unsigned long gsr;
197*4882a593Smuzhiyun 	unsigned int timeout = 100;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun #ifdef CONFIG_PXA25x
200*4882a593Smuzhiyun 	if (cpu_is_pxa25x())
201*4882a593Smuzhiyun 		pxa_ac97_warm_pxa25x();
202*4882a593Smuzhiyun 	else
203*4882a593Smuzhiyun #endif
204*4882a593Smuzhiyun #ifdef CONFIG_PXA27x
205*4882a593Smuzhiyun 	if (cpu_is_pxa27x())
206*4882a593Smuzhiyun 		pxa_ac97_warm_pxa27x();
207*4882a593Smuzhiyun 	else
208*4882a593Smuzhiyun #endif
209*4882a593Smuzhiyun #ifdef CONFIG_PXA3xx
210*4882a593Smuzhiyun 	if (cpu_is_pxa3xx())
211*4882a593Smuzhiyun 		pxa_ac97_warm_pxa3xx();
212*4882a593Smuzhiyun 	else
213*4882a593Smuzhiyun #endif
214*4882a593Smuzhiyun 		snd_BUG();
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
217*4882a593Smuzhiyun 		mdelay(1);
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	gsr = GSR | gsr_bits;
220*4882a593Smuzhiyun 	if (!(gsr & (GSR_PCR | GSR_SCR))) {
221*4882a593Smuzhiyun 		printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
222*4882a593Smuzhiyun 				 __func__, gsr);
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 		return false;
225*4882a593Smuzhiyun 	}
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun 	return true;
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
230*4882a593Smuzhiyun 
pxa2xx_ac97_try_cold_reset(void)231*4882a593Smuzhiyun bool pxa2xx_ac97_try_cold_reset(void)
232*4882a593Smuzhiyun {
233*4882a593Smuzhiyun 	unsigned long gsr;
234*4882a593Smuzhiyun 	unsigned int timeout = 1000;
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun #ifdef CONFIG_PXA25x
237*4882a593Smuzhiyun 	if (cpu_is_pxa25x())
238*4882a593Smuzhiyun 		pxa_ac97_cold_pxa25x();
239*4882a593Smuzhiyun 	else
240*4882a593Smuzhiyun #endif
241*4882a593Smuzhiyun #ifdef CONFIG_PXA27x
242*4882a593Smuzhiyun 	if (cpu_is_pxa27x())
243*4882a593Smuzhiyun 		pxa_ac97_cold_pxa27x();
244*4882a593Smuzhiyun 	else
245*4882a593Smuzhiyun #endif
246*4882a593Smuzhiyun #ifdef CONFIG_PXA3xx
247*4882a593Smuzhiyun 	if (cpu_is_pxa3xx())
248*4882a593Smuzhiyun 		pxa_ac97_cold_pxa3xx();
249*4882a593Smuzhiyun 	else
250*4882a593Smuzhiyun #endif
251*4882a593Smuzhiyun 		snd_BUG();
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
254*4882a593Smuzhiyun 		mdelay(1);
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun 	gsr = GSR | gsr_bits;
257*4882a593Smuzhiyun 	if (!(gsr & (GSR_PCR | GSR_SCR))) {
258*4882a593Smuzhiyun 		printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
259*4882a593Smuzhiyun 				 __func__, gsr);
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 		return false;
262*4882a593Smuzhiyun 	}
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	return true;
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 
pxa2xx_ac97_finish_reset(void)269*4882a593Smuzhiyun void pxa2xx_ac97_finish_reset(void)
270*4882a593Smuzhiyun {
271*4882a593Smuzhiyun 	GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
272*4882a593Smuzhiyun 	GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_finish_reset);
275*4882a593Smuzhiyun 
pxa2xx_ac97_irq(int irq,void * dev_id)276*4882a593Smuzhiyun static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun 	long status;
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 	status = GSR;
281*4882a593Smuzhiyun 	if (status) {
282*4882a593Smuzhiyun 		GSR = status;
283*4882a593Smuzhiyun 		gsr_bits |= status;
284*4882a593Smuzhiyun 		wake_up(&gsr_wq);
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 		/* Although we don't use those we still need to clear them
287*4882a593Smuzhiyun 		   since they tend to spuriously trigger when MMC is used
288*4882a593Smuzhiyun 		   (hardware bug? go figure)... */
289*4882a593Smuzhiyun 		if (cpu_is_pxa27x()) {
290*4882a593Smuzhiyun 			MISR = MISR_EOC;
291*4882a593Smuzhiyun 			PISR = PISR_EOC;
292*4882a593Smuzhiyun 			MCSR = MCSR_EOC;
293*4882a593Smuzhiyun 		}
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun 		return IRQ_HANDLED;
296*4882a593Smuzhiyun 	}
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	return IRQ_NONE;
299*4882a593Smuzhiyun }
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun #ifdef CONFIG_PM
pxa2xx_ac97_hw_suspend(void)302*4882a593Smuzhiyun int pxa2xx_ac97_hw_suspend(void)
303*4882a593Smuzhiyun {
304*4882a593Smuzhiyun 	GCR |= GCR_ACLINK_OFF;
305*4882a593Smuzhiyun 	clk_disable_unprepare(ac97_clk);
306*4882a593Smuzhiyun 	return 0;
307*4882a593Smuzhiyun }
308*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_suspend);
309*4882a593Smuzhiyun 
pxa2xx_ac97_hw_resume(void)310*4882a593Smuzhiyun int pxa2xx_ac97_hw_resume(void)
311*4882a593Smuzhiyun {
312*4882a593Smuzhiyun 	clk_prepare_enable(ac97_clk);
313*4882a593Smuzhiyun 	return 0;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_resume);
316*4882a593Smuzhiyun #endif
317*4882a593Smuzhiyun 
pxa2xx_ac97_hw_probe(struct platform_device * dev)318*4882a593Smuzhiyun int pxa2xx_ac97_hw_probe(struct platform_device *dev)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun 	int ret;
321*4882a593Smuzhiyun 	pxa2xx_audio_ops_t *pdata = dev->dev.platform_data;
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 	if (pdata) {
324*4882a593Smuzhiyun 		switch (pdata->reset_gpio) {
325*4882a593Smuzhiyun 		case 95:
326*4882a593Smuzhiyun 		case 113:
327*4882a593Smuzhiyun 			reset_gpio = pdata->reset_gpio;
328*4882a593Smuzhiyun 			break;
329*4882a593Smuzhiyun 		case 0:
330*4882a593Smuzhiyun 			reset_gpio = 113;
331*4882a593Smuzhiyun 			break;
332*4882a593Smuzhiyun 		case -1:
333*4882a593Smuzhiyun 			break;
334*4882a593Smuzhiyun 		default:
335*4882a593Smuzhiyun 			dev_err(&dev->dev, "Invalid reset GPIO %d\n",
336*4882a593Smuzhiyun 				pdata->reset_gpio);
337*4882a593Smuzhiyun 		}
338*4882a593Smuzhiyun 	} else if (!pdata && dev->dev.of_node) {
339*4882a593Smuzhiyun 		pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL);
340*4882a593Smuzhiyun 		if (!pdata)
341*4882a593Smuzhiyun 			return -ENOMEM;
342*4882a593Smuzhiyun 		pdata->reset_gpio = of_get_named_gpio(dev->dev.of_node,
343*4882a593Smuzhiyun 						      "reset-gpios", 0);
344*4882a593Smuzhiyun 		if (pdata->reset_gpio == -ENOENT)
345*4882a593Smuzhiyun 			pdata->reset_gpio = -1;
346*4882a593Smuzhiyun 		else if (pdata->reset_gpio < 0)
347*4882a593Smuzhiyun 			return pdata->reset_gpio;
348*4882a593Smuzhiyun 		reset_gpio = pdata->reset_gpio;
349*4882a593Smuzhiyun 	} else {
350*4882a593Smuzhiyun 		if (cpu_is_pxa27x())
351*4882a593Smuzhiyun 			reset_gpio = 113;
352*4882a593Smuzhiyun 	}
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 	if (cpu_is_pxa27x()) {
355*4882a593Smuzhiyun 		/*
356*4882a593Smuzhiyun 		 * This gpio is needed for a work-around to a bug in the ac97
357*4882a593Smuzhiyun 		 * controller during warm reset.  The direction and level is set
358*4882a593Smuzhiyun 		 * here so that it is an output driven high when switching from
359*4882a593Smuzhiyun 		 * AC97_nRESET alt function to generic gpio.
360*4882a593Smuzhiyun 		 */
361*4882a593Smuzhiyun 		ret = gpio_request_one(reset_gpio, GPIOF_OUT_INIT_HIGH,
362*4882a593Smuzhiyun 				       "pxa27x ac97 reset");
363*4882a593Smuzhiyun 		if (ret < 0) {
364*4882a593Smuzhiyun 			pr_err("%s: gpio_request_one() failed: %d\n",
365*4882a593Smuzhiyun 			       __func__, ret);
366*4882a593Smuzhiyun 			goto err_conf;
367*4882a593Smuzhiyun 		}
368*4882a593Smuzhiyun 		pxa27x_configure_ac97reset(reset_gpio, false);
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun 		ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
371*4882a593Smuzhiyun 		if (IS_ERR(ac97conf_clk)) {
372*4882a593Smuzhiyun 			ret = PTR_ERR(ac97conf_clk);
373*4882a593Smuzhiyun 			ac97conf_clk = NULL;
374*4882a593Smuzhiyun 			goto err_conf;
375*4882a593Smuzhiyun 		}
376*4882a593Smuzhiyun 	}
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun 	ac97_clk = clk_get(&dev->dev, "AC97CLK");
379*4882a593Smuzhiyun 	if (IS_ERR(ac97_clk)) {
380*4882a593Smuzhiyun 		ret = PTR_ERR(ac97_clk);
381*4882a593Smuzhiyun 		ac97_clk = NULL;
382*4882a593Smuzhiyun 		goto err_clk;
383*4882a593Smuzhiyun 	}
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun 	ret = clk_prepare_enable(ac97_clk);
386*4882a593Smuzhiyun 	if (ret)
387*4882a593Smuzhiyun 		goto err_clk2;
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL);
390*4882a593Smuzhiyun 	if (ret < 0)
391*4882a593Smuzhiyun 		goto err_irq;
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 	return 0;
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun err_irq:
396*4882a593Smuzhiyun 	GCR |= GCR_ACLINK_OFF;
397*4882a593Smuzhiyun err_clk2:
398*4882a593Smuzhiyun 	clk_put(ac97_clk);
399*4882a593Smuzhiyun 	ac97_clk = NULL;
400*4882a593Smuzhiyun err_clk:
401*4882a593Smuzhiyun 	if (ac97conf_clk) {
402*4882a593Smuzhiyun 		clk_put(ac97conf_clk);
403*4882a593Smuzhiyun 		ac97conf_clk = NULL;
404*4882a593Smuzhiyun 	}
405*4882a593Smuzhiyun err_conf:
406*4882a593Smuzhiyun 	return ret;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_probe);
409*4882a593Smuzhiyun 
pxa2xx_ac97_hw_remove(struct platform_device * dev)410*4882a593Smuzhiyun void pxa2xx_ac97_hw_remove(struct platform_device *dev)
411*4882a593Smuzhiyun {
412*4882a593Smuzhiyun 	if (cpu_is_pxa27x())
413*4882a593Smuzhiyun 		gpio_free(reset_gpio);
414*4882a593Smuzhiyun 	GCR |= GCR_ACLINK_OFF;
415*4882a593Smuzhiyun 	free_irq(IRQ_AC97, NULL);
416*4882a593Smuzhiyun 	if (ac97conf_clk) {
417*4882a593Smuzhiyun 		clk_put(ac97conf_clk);
418*4882a593Smuzhiyun 		ac97conf_clk = NULL;
419*4882a593Smuzhiyun 	}
420*4882a593Smuzhiyun 	clk_disable_unprepare(ac97_clk);
421*4882a593Smuzhiyun 	clk_put(ac97_clk);
422*4882a593Smuzhiyun 	ac97_clk = NULL;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_remove);
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun MODULE_AUTHOR("Nicolas Pitre");
427*4882a593Smuzhiyun MODULE_DESCRIPTION("Intel/Marvell PXA sound library");
428*4882a593Smuzhiyun MODULE_LICENSE("GPL");
429*4882a593Smuzhiyun 
430