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