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