19c636342SDmitry Baryshkov /* 29c636342SDmitry Baryshkov * Based on sound/arm/pxa2xx-ac97.c and sound/soc/pxa/pxa2xx-ac97.c 39c636342SDmitry Baryshkov * which contain: 49c636342SDmitry Baryshkov * 59c636342SDmitry Baryshkov * Author: Nicolas Pitre 69c636342SDmitry Baryshkov * Created: Dec 02, 2004 79c636342SDmitry Baryshkov * Copyright: MontaVista Software Inc. 89c636342SDmitry Baryshkov * 99c636342SDmitry Baryshkov * This program is free software; you can redistribute it and/or modify 109c636342SDmitry Baryshkov * it under the terms of the GNU General Public License version 2 as 119c636342SDmitry Baryshkov * published by the Free Software Foundation. 129c636342SDmitry Baryshkov */ 139c636342SDmitry Baryshkov 149c636342SDmitry Baryshkov #include <linux/kernel.h> 159c636342SDmitry Baryshkov #include <linux/platform_device.h> 169c636342SDmitry Baryshkov #include <linux/interrupt.h> 179c636342SDmitry Baryshkov #include <linux/clk.h> 189c636342SDmitry Baryshkov #include <linux/delay.h> 19da155d5bSPaul Gortmaker #include <linux/module.h> 2023019a73SRob Herring #include <linux/io.h> 213b4bc7bcSMike Dunn #include <linux/gpio.h> 22*a4519526SRobert Jarzmik #include <linux/of_gpio.h> 239c636342SDmitry Baryshkov 249c636342SDmitry Baryshkov #include <sound/pxa2xx-lib.h> 259c636342SDmitry Baryshkov 269482ee71SRob Herring #include <mach/irqs.h> 271f017a99SEric Miao #include <mach/regs-ac97.h> 289c636342SDmitry Baryshkov #include <mach/audio.h> 299c636342SDmitry Baryshkov 309c636342SDmitry Baryshkov static DEFINE_MUTEX(car_mutex); 319c636342SDmitry Baryshkov static DECLARE_WAIT_QUEUE_HEAD(gsr_wq); 329c636342SDmitry Baryshkov static volatile long gsr_bits; 339c636342SDmitry Baryshkov static struct clk *ac97_clk; 349c636342SDmitry Baryshkov static struct clk *ac97conf_clk; 3526ade896SRobert Jarzmik static int reset_gpio; 369c636342SDmitry Baryshkov 37053fe0f1SMike Dunn extern void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio); 38fb1bf8cdSEric Miao 399c636342SDmitry Baryshkov /* 409c636342SDmitry Baryshkov * Beware PXA27x bugs: 419c636342SDmitry Baryshkov * 429c636342SDmitry Baryshkov * o Slot 12 read from modem space will hang controller. 439c636342SDmitry Baryshkov * o CDONE, SDONE interrupt fails after any slot 12 IO. 449c636342SDmitry Baryshkov * 459c636342SDmitry Baryshkov * We therefore have an hybrid approach for waiting on SDONE (interrupt or 469c636342SDmitry Baryshkov * 1 jiffy timeout if interrupt never comes). 479c636342SDmitry Baryshkov */ 489c636342SDmitry Baryshkov 496f8acad6SRobert Jarzmik int pxa2xx_ac97_read(int slot, unsigned short reg) 509c636342SDmitry Baryshkov { 516f8acad6SRobert Jarzmik int val = -ENODEV; 529c636342SDmitry Baryshkov volatile u32 *reg_addr; 539c636342SDmitry Baryshkov 546f8acad6SRobert Jarzmik if (slot > 0) 556f8acad6SRobert Jarzmik return -ENODEV; 566f8acad6SRobert Jarzmik 579c636342SDmitry Baryshkov mutex_lock(&car_mutex); 589c636342SDmitry Baryshkov 599c636342SDmitry Baryshkov /* set up primary or secondary codec space */ 608825e8e8SMarc Zyngier if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS) 616f8acad6SRobert Jarzmik reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE; 629c636342SDmitry Baryshkov else 636f8acad6SRobert Jarzmik reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE; 649c636342SDmitry Baryshkov reg_addr += (reg >> 1); 659c636342SDmitry Baryshkov 669c636342SDmitry Baryshkov /* start read access across the ac97 link */ 679c636342SDmitry Baryshkov GSR = GSR_CDONE | GSR_SDONE; 689c636342SDmitry Baryshkov gsr_bits = 0; 696f8acad6SRobert Jarzmik val = (*reg_addr & 0xffff); 709c636342SDmitry Baryshkov if (reg == AC97_GPIO_STATUS) 719c636342SDmitry Baryshkov goto out; 729c636342SDmitry Baryshkov if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && 739c636342SDmitry Baryshkov !((GSR | gsr_bits) & GSR_SDONE)) { 749c636342SDmitry Baryshkov printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", 759c636342SDmitry Baryshkov __func__, reg, GSR | gsr_bits); 766f8acad6SRobert Jarzmik val = -ETIMEDOUT; 779c636342SDmitry Baryshkov goto out; 789c636342SDmitry Baryshkov } 799c636342SDmitry Baryshkov 809c636342SDmitry Baryshkov /* valid data now */ 819c636342SDmitry Baryshkov GSR = GSR_CDONE | GSR_SDONE; 829c636342SDmitry Baryshkov gsr_bits = 0; 836f8acad6SRobert Jarzmik val = (*reg_addr & 0xffff); 849c636342SDmitry Baryshkov /* but we've just started another cycle... */ 859c636342SDmitry Baryshkov wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); 869c636342SDmitry Baryshkov 879c636342SDmitry Baryshkov out: mutex_unlock(&car_mutex); 889c636342SDmitry Baryshkov return val; 899c636342SDmitry Baryshkov } 909c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_read); 919c636342SDmitry Baryshkov 926f8acad6SRobert Jarzmik int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val) 939c636342SDmitry Baryshkov { 949c636342SDmitry Baryshkov volatile u32 *reg_addr; 956f8acad6SRobert Jarzmik int ret = 0; 969c636342SDmitry Baryshkov 979c636342SDmitry Baryshkov mutex_lock(&car_mutex); 989c636342SDmitry Baryshkov 999c636342SDmitry Baryshkov /* set up primary or secondary codec space */ 1008825e8e8SMarc Zyngier if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS) 1016f8acad6SRobert Jarzmik reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE; 1029c636342SDmitry Baryshkov else 1036f8acad6SRobert Jarzmik reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE; 1049c636342SDmitry Baryshkov reg_addr += (reg >> 1); 1059c636342SDmitry Baryshkov 1069c636342SDmitry Baryshkov GSR = GSR_CDONE | GSR_SDONE; 1079c636342SDmitry Baryshkov gsr_bits = 0; 1089c636342SDmitry Baryshkov *reg_addr = val; 1099c636342SDmitry Baryshkov if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && 1106f8acad6SRobert Jarzmik !((GSR | gsr_bits) & GSR_CDONE)) { 1119c636342SDmitry Baryshkov printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", 1129c636342SDmitry Baryshkov __func__, reg, GSR | gsr_bits); 1136f8acad6SRobert Jarzmik ret = -EIO; 1146f8acad6SRobert Jarzmik } 1159c636342SDmitry Baryshkov 1169c636342SDmitry Baryshkov mutex_unlock(&car_mutex); 1176f8acad6SRobert Jarzmik return ret; 1189c636342SDmitry Baryshkov } 1199c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_write); 1209c636342SDmitry Baryshkov 1219d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA25x 1229d1cf39bSDmitry Baryshkov static inline void pxa_ac97_warm_pxa25x(void) 1239c636342SDmitry Baryshkov { 1249c636342SDmitry Baryshkov gsr_bits = 0; 1259c636342SDmitry Baryshkov 126beb02cddSDmitry Eremin-Solenikov GCR |= GCR_WARM_RST; 1279d1cf39bSDmitry Baryshkov } 1289d1cf39bSDmitry Baryshkov 1299d1cf39bSDmitry Baryshkov static inline void pxa_ac97_cold_pxa25x(void) 1309d1cf39bSDmitry Baryshkov { 1319d1cf39bSDmitry Baryshkov GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 1329d1cf39bSDmitry Baryshkov GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 1339d1cf39bSDmitry Baryshkov 1349d1cf39bSDmitry Baryshkov gsr_bits = 0; 1359d1cf39bSDmitry Baryshkov 1369d1cf39bSDmitry Baryshkov GCR = GCR_COLD_RST; 1379d1cf39bSDmitry Baryshkov } 1389d1cf39bSDmitry Baryshkov #endif 1399d1cf39bSDmitry Baryshkov 1409c636342SDmitry Baryshkov #ifdef CONFIG_PXA27x 1419d1cf39bSDmitry Baryshkov static inline void pxa_ac97_warm_pxa27x(void) 1429d1cf39bSDmitry Baryshkov { 1439d1cf39bSDmitry Baryshkov gsr_bits = 0; 1449d1cf39bSDmitry Baryshkov 145fb1bf8cdSEric Miao /* warm reset broken on Bulverde, so manually keep AC97 reset high */ 146053fe0f1SMike Dunn pxa27x_configure_ac97reset(reset_gpio, true); 1479c636342SDmitry Baryshkov udelay(10); 1489c636342SDmitry Baryshkov GCR |= GCR_WARM_RST; 149053fe0f1SMike Dunn pxa27x_configure_ac97reset(reset_gpio, false); 1509c636342SDmitry Baryshkov udelay(500); 1519d1cf39bSDmitry Baryshkov } 1529d1cf39bSDmitry Baryshkov 1539d1cf39bSDmitry Baryshkov static inline void pxa_ac97_cold_pxa27x(void) 1549d1cf39bSDmitry Baryshkov { 1559d1cf39bSDmitry Baryshkov GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 1569d1cf39bSDmitry Baryshkov GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 1579d1cf39bSDmitry Baryshkov 1589d1cf39bSDmitry Baryshkov gsr_bits = 0; 1599d1cf39bSDmitry Baryshkov 1609d1cf39bSDmitry Baryshkov /* PXA27x Developers Manual section 13.5.2.2.1 */ 1614091d342SRobert Jarzmik clk_prepare_enable(ac97conf_clk); 1629d1cf39bSDmitry Baryshkov udelay(5); 1634091d342SRobert Jarzmik clk_disable_unprepare(ac97conf_clk); 16441b645c8SMike Dunn GCR = GCR_COLD_RST | GCR_WARM_RST; 1659d1cf39bSDmitry Baryshkov } 1669d1cf39bSDmitry Baryshkov #endif 1679d1cf39bSDmitry Baryshkov 1689d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA3xx 1699d1cf39bSDmitry Baryshkov static inline void pxa_ac97_warm_pxa3xx(void) 1709d1cf39bSDmitry Baryshkov { 1719d1cf39bSDmitry Baryshkov gsr_bits = 0; 1729d1cf39bSDmitry Baryshkov 1739c636342SDmitry Baryshkov /* Can't use interrupts */ 1749c636342SDmitry Baryshkov GCR |= GCR_WARM_RST; 1759d1cf39bSDmitry Baryshkov } 1769d1cf39bSDmitry Baryshkov 1779d1cf39bSDmitry Baryshkov static inline void pxa_ac97_cold_pxa3xx(void) 1789d1cf39bSDmitry Baryshkov { 1799d1cf39bSDmitry Baryshkov /* Hold CLKBPB for 100us */ 1809d1cf39bSDmitry Baryshkov GCR = 0; 1819d1cf39bSDmitry Baryshkov GCR = GCR_CLKBPB; 1829d1cf39bSDmitry Baryshkov udelay(100); 1839d1cf39bSDmitry Baryshkov GCR = 0; 1849d1cf39bSDmitry Baryshkov 1859d1cf39bSDmitry Baryshkov GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 1869d1cf39bSDmitry Baryshkov GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 1879d1cf39bSDmitry Baryshkov 1889d1cf39bSDmitry Baryshkov gsr_bits = 0; 1899d1cf39bSDmitry Baryshkov 1909d1cf39bSDmitry Baryshkov /* Can't use interrupts on PXA3xx */ 1919d1cf39bSDmitry Baryshkov GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 1929d1cf39bSDmitry Baryshkov 1939d1cf39bSDmitry Baryshkov GCR = GCR_WARM_RST | GCR_COLD_RST; 1949d1cf39bSDmitry Baryshkov } 1959c636342SDmitry Baryshkov #endif 1969c636342SDmitry Baryshkov 1976f8acad6SRobert Jarzmik bool pxa2xx_ac97_try_warm_reset(void) 1989d1cf39bSDmitry Baryshkov { 199057de50cSLuotao Fu unsigned long gsr; 200beb02cddSDmitry Eremin-Solenikov unsigned int timeout = 100; 201057de50cSLuotao Fu 2029d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA25x 2038825e8e8SMarc Zyngier if (cpu_is_pxa25x()) 2049d1cf39bSDmitry Baryshkov pxa_ac97_warm_pxa25x(); 2059d1cf39bSDmitry Baryshkov else 2069d1cf39bSDmitry Baryshkov #endif 2079d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA27x 2089d1cf39bSDmitry Baryshkov if (cpu_is_pxa27x()) 2099d1cf39bSDmitry Baryshkov pxa_ac97_warm_pxa27x(); 2109d1cf39bSDmitry Baryshkov else 2119d1cf39bSDmitry Baryshkov #endif 2129d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA3xx 2139d1cf39bSDmitry Baryshkov if (cpu_is_pxa3xx()) 2149d1cf39bSDmitry Baryshkov pxa_ac97_warm_pxa3xx(); 2159d1cf39bSDmitry Baryshkov else 2169d1cf39bSDmitry Baryshkov #endif 21788ec7ae8STakashi Iwai snd_BUG(); 218beb02cddSDmitry Eremin-Solenikov 219beb02cddSDmitry Eremin-Solenikov while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--) 220beb02cddSDmitry Eremin-Solenikov mdelay(1); 221beb02cddSDmitry Eremin-Solenikov 222057de50cSLuotao Fu gsr = GSR | gsr_bits; 223057de50cSLuotao Fu if (!(gsr & (GSR_PCR | GSR_SCR))) { 2249c636342SDmitry Baryshkov printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 225057de50cSLuotao Fu __func__, gsr); 2269c636342SDmitry Baryshkov 2279c636342SDmitry Baryshkov return false; 2289c636342SDmitry Baryshkov } 2299c636342SDmitry Baryshkov 2309c636342SDmitry Baryshkov return true; 2319c636342SDmitry Baryshkov } 2329c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset); 2339c636342SDmitry Baryshkov 2346f8acad6SRobert Jarzmik bool pxa2xx_ac97_try_cold_reset(void) 2359c636342SDmitry Baryshkov { 236057de50cSLuotao Fu unsigned long gsr; 237beb02cddSDmitry Eremin-Solenikov unsigned int timeout = 1000; 238057de50cSLuotao Fu 2399d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA25x 2408825e8e8SMarc Zyngier if (cpu_is_pxa25x()) 2419d1cf39bSDmitry Baryshkov pxa_ac97_cold_pxa25x(); 2429d1cf39bSDmitry Baryshkov else 2439c636342SDmitry Baryshkov #endif 2449c636342SDmitry Baryshkov #ifdef CONFIG_PXA27x 2459d1cf39bSDmitry Baryshkov if (cpu_is_pxa27x()) 2469d1cf39bSDmitry Baryshkov pxa_ac97_cold_pxa27x(); 2479d1cf39bSDmitry Baryshkov else 2489c636342SDmitry Baryshkov #endif 2499d1cf39bSDmitry Baryshkov #ifdef CONFIG_PXA3xx 2509d1cf39bSDmitry Baryshkov if (cpu_is_pxa3xx()) 2519d1cf39bSDmitry Baryshkov pxa_ac97_cold_pxa3xx(); 2529d1cf39bSDmitry Baryshkov else 2539d1cf39bSDmitry Baryshkov #endif 25488ec7ae8STakashi Iwai snd_BUG(); 2559c636342SDmitry Baryshkov 256beb02cddSDmitry Eremin-Solenikov while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--) 257beb02cddSDmitry Eremin-Solenikov mdelay(1); 258beb02cddSDmitry Eremin-Solenikov 259057de50cSLuotao Fu gsr = GSR | gsr_bits; 260057de50cSLuotao Fu if (!(gsr & (GSR_PCR | GSR_SCR))) { 2619c636342SDmitry Baryshkov printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 262057de50cSLuotao Fu __func__, gsr); 2639c636342SDmitry Baryshkov 2649c636342SDmitry Baryshkov return false; 2659c636342SDmitry Baryshkov } 2669c636342SDmitry Baryshkov 2679c636342SDmitry Baryshkov return true; 2689c636342SDmitry Baryshkov } 2699c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset); 2709c636342SDmitry Baryshkov 2719c636342SDmitry Baryshkov 2726f8acad6SRobert Jarzmik void pxa2xx_ac97_finish_reset(void) 2739c636342SDmitry Baryshkov { 2749c636342SDmitry Baryshkov GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 2759c636342SDmitry Baryshkov GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 2769c636342SDmitry Baryshkov } 2779c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_finish_reset); 2789c636342SDmitry Baryshkov 2799c636342SDmitry Baryshkov static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id) 2809c636342SDmitry Baryshkov { 2819c636342SDmitry Baryshkov long status; 2829c636342SDmitry Baryshkov 2839c636342SDmitry Baryshkov status = GSR; 2849c636342SDmitry Baryshkov if (status) { 2859c636342SDmitry Baryshkov GSR = status; 2869c636342SDmitry Baryshkov gsr_bits |= status; 2879c636342SDmitry Baryshkov wake_up(&gsr_wq); 2889c636342SDmitry Baryshkov 2899c636342SDmitry Baryshkov /* Although we don't use those we still need to clear them 2909c636342SDmitry Baryshkov since they tend to spuriously trigger when MMC is used 2919c636342SDmitry Baryshkov (hardware bug? go figure)... */ 2929d1cf39bSDmitry Baryshkov if (cpu_is_pxa27x()) { 2939c636342SDmitry Baryshkov MISR = MISR_EOC; 2949c636342SDmitry Baryshkov PISR = PISR_EOC; 2959c636342SDmitry Baryshkov MCSR = MCSR_EOC; 2969d1cf39bSDmitry Baryshkov } 2979c636342SDmitry Baryshkov 2989c636342SDmitry Baryshkov return IRQ_HANDLED; 2999c636342SDmitry Baryshkov } 3009c636342SDmitry Baryshkov 3019c636342SDmitry Baryshkov return IRQ_NONE; 3029c636342SDmitry Baryshkov } 3039c636342SDmitry Baryshkov 3049c636342SDmitry Baryshkov #ifdef CONFIG_PM 3059c636342SDmitry Baryshkov int pxa2xx_ac97_hw_suspend(void) 3069c636342SDmitry Baryshkov { 3079c636342SDmitry Baryshkov GCR |= GCR_ACLINK_OFF; 3084091d342SRobert Jarzmik clk_disable_unprepare(ac97_clk); 3099c636342SDmitry Baryshkov return 0; 3109c636342SDmitry Baryshkov } 3119c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_suspend); 3129c636342SDmitry Baryshkov 3139c636342SDmitry Baryshkov int pxa2xx_ac97_hw_resume(void) 3149c636342SDmitry Baryshkov { 3154091d342SRobert Jarzmik clk_prepare_enable(ac97_clk); 3169c636342SDmitry Baryshkov return 0; 3179c636342SDmitry Baryshkov } 3189c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_resume); 3199c636342SDmitry Baryshkov #endif 3209c636342SDmitry Baryshkov 321e21596bbSBill Pemberton int pxa2xx_ac97_hw_probe(struct platform_device *dev) 3229c636342SDmitry Baryshkov { 3239c636342SDmitry Baryshkov int ret; 324eae17754SMark Brown pxa2xx_audio_ops_t *pdata = dev->dev.platform_data; 32526ade896SRobert Jarzmik 32626ade896SRobert Jarzmik if (pdata) { 32726ade896SRobert Jarzmik switch (pdata->reset_gpio) { 32826ade896SRobert Jarzmik case 95: 32926ade896SRobert Jarzmik case 113: 33026ade896SRobert Jarzmik reset_gpio = pdata->reset_gpio; 33126ade896SRobert Jarzmik break; 33226ade896SRobert Jarzmik case 0: 33326ade896SRobert Jarzmik reset_gpio = 113; 33426ade896SRobert Jarzmik break; 33526ade896SRobert Jarzmik case -1: 33626ade896SRobert Jarzmik break; 33726ade896SRobert Jarzmik default: 3381f218695STakashi Iwai dev_err(&dev->dev, "Invalid reset GPIO %d\n", 33926ade896SRobert Jarzmik pdata->reset_gpio); 34026ade896SRobert Jarzmik } 341*a4519526SRobert Jarzmik } else if (!pdata && dev->dev.of_node) { 342*a4519526SRobert Jarzmik pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); 343*a4519526SRobert Jarzmik if (!pdata) 344*a4519526SRobert Jarzmik return -ENOMEM; 345*a4519526SRobert Jarzmik pdata->reset_gpio = of_get_named_gpio(dev->dev.of_node, 346*a4519526SRobert Jarzmik "reset-gpios", 0); 347*a4519526SRobert Jarzmik if (pdata->reset_gpio == -ENOENT) 348*a4519526SRobert Jarzmik pdata->reset_gpio = -1; 349*a4519526SRobert Jarzmik else if (pdata->reset_gpio < 0) 350*a4519526SRobert Jarzmik return pdata->reset_gpio; 351*a4519526SRobert Jarzmik reset_gpio = pdata->reset_gpio; 35226ade896SRobert Jarzmik } else { 35326ade896SRobert Jarzmik if (cpu_is_pxa27x()) 35426ade896SRobert Jarzmik reset_gpio = 113; 35526ade896SRobert Jarzmik } 3569c636342SDmitry Baryshkov 3579d1cf39bSDmitry Baryshkov if (cpu_is_pxa27x()) { 3583b4bc7bcSMike Dunn /* 3593b4bc7bcSMike Dunn * This gpio is needed for a work-around to a bug in the ac97 3603b4bc7bcSMike Dunn * controller during warm reset. The direction and level is set 3613b4bc7bcSMike Dunn * here so that it is an output driven high when switching from 3623b4bc7bcSMike Dunn * AC97_nRESET alt function to generic gpio. 3633b4bc7bcSMike Dunn */ 3643b4bc7bcSMike Dunn ret = gpio_request_one(reset_gpio, GPIOF_OUT_INIT_HIGH, 3653b4bc7bcSMike Dunn "pxa27x ac97 reset"); 3663b4bc7bcSMike Dunn if (ret < 0) { 3673b4bc7bcSMike Dunn pr_err("%s: gpio_request_one() failed: %d\n", 3683b4bc7bcSMike Dunn __func__, ret); 3693b4bc7bcSMike Dunn goto err_conf; 3703b4bc7bcSMike Dunn } 371053fe0f1SMike Dunn pxa27x_configure_ac97reset(reset_gpio, false); 3723b4bc7bcSMike Dunn 3739c636342SDmitry Baryshkov ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK"); 3749c636342SDmitry Baryshkov if (IS_ERR(ac97conf_clk)) { 3759c636342SDmitry Baryshkov ret = PTR_ERR(ac97conf_clk); 3769c636342SDmitry Baryshkov ac97conf_clk = NULL; 37779612336SDmitry Baryshkov goto err_conf; 3789c636342SDmitry Baryshkov } 3799d1cf39bSDmitry Baryshkov } 3809c636342SDmitry Baryshkov 3819c636342SDmitry Baryshkov ac97_clk = clk_get(&dev->dev, "AC97CLK"); 3829c636342SDmitry Baryshkov if (IS_ERR(ac97_clk)) { 3839c636342SDmitry Baryshkov ret = PTR_ERR(ac97_clk); 3849c636342SDmitry Baryshkov ac97_clk = NULL; 38579612336SDmitry Baryshkov goto err_clk; 3869c636342SDmitry Baryshkov } 3879c636342SDmitry Baryshkov 3884091d342SRobert Jarzmik ret = clk_prepare_enable(ac97_clk); 38979612336SDmitry Baryshkov if (ret) 39079612336SDmitry Baryshkov goto err_clk2; 39179612336SDmitry Baryshkov 39288e24c3aSYong Zhang ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL); 39379612336SDmitry Baryshkov if (ret < 0) 39479612336SDmitry Baryshkov goto err_irq; 39579612336SDmitry Baryshkov 39679612336SDmitry Baryshkov return 0; 3979c636342SDmitry Baryshkov 3989c636342SDmitry Baryshkov err_irq: 3999c636342SDmitry Baryshkov GCR |= GCR_ACLINK_OFF; 40079612336SDmitry Baryshkov err_clk2: 40179612336SDmitry Baryshkov clk_put(ac97_clk); 40279612336SDmitry Baryshkov ac97_clk = NULL; 40379612336SDmitry Baryshkov err_clk: 4049c636342SDmitry Baryshkov if (ac97conf_clk) { 4059c636342SDmitry Baryshkov clk_put(ac97conf_clk); 4069c636342SDmitry Baryshkov ac97conf_clk = NULL; 4079c636342SDmitry Baryshkov } 40879612336SDmitry Baryshkov err_conf: 4099c636342SDmitry Baryshkov return ret; 4109c636342SDmitry Baryshkov } 4119c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_probe); 4129c636342SDmitry Baryshkov 4139c636342SDmitry Baryshkov void pxa2xx_ac97_hw_remove(struct platform_device *dev) 4149c636342SDmitry Baryshkov { 4153b4bc7bcSMike Dunn if (cpu_is_pxa27x()) 4163b4bc7bcSMike Dunn gpio_free(reset_gpio); 4179c636342SDmitry Baryshkov GCR |= GCR_ACLINK_OFF; 4189c636342SDmitry Baryshkov free_irq(IRQ_AC97, NULL); 4199d1cf39bSDmitry Baryshkov if (ac97conf_clk) { 4209c636342SDmitry Baryshkov clk_put(ac97conf_clk); 4219c636342SDmitry Baryshkov ac97conf_clk = NULL; 4229d1cf39bSDmitry Baryshkov } 4234091d342SRobert Jarzmik clk_disable_unprepare(ac97_clk); 4249c636342SDmitry Baryshkov clk_put(ac97_clk); 4259c636342SDmitry Baryshkov ac97_clk = NULL; 4269c636342SDmitry Baryshkov } 4279c636342SDmitry Baryshkov EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_remove); 4289c636342SDmitry Baryshkov 4299c636342SDmitry Baryshkov MODULE_AUTHOR("Nicolas Pitre"); 4309c636342SDmitry Baryshkov MODULE_DESCRIPTION("Intel/Marvell PXA sound library"); 4319c636342SDmitry Baryshkov MODULE_LICENSE("GPL"); 4329c636342SDmitry Baryshkov 433