Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-pxa/ssp.c |
| 3 | * |
| 4 | * based on linux/arch/arm/mach-sa1100/ssp.c by Russell King |
| 5 | * |
| 6 | * Copyright (C) 2003 Russell King. |
| 7 | * Copyright (C) 2003 Wolfson Microelectronics PLC |
| 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 | * PXA2xx SSP driver. This provides the generic core for simple |
| 14 | * IO-based SSP applications and allows easy port setup for DMA access. |
| 15 | * |
| 16 | * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> |
| 17 | * |
| 18 | * Revision history: |
| 19 | * 22nd Aug 2003 Initial version. |
| 20 | * 20th Dec 2004 Added ssp_config for changing port config without |
| 21 | * closing the port. |
Liam Girdwood | b216c01 | 2005-11-10 17:45:39 +0000 | [diff] [blame] | 22 | * 4th Aug 2005 Added option to disable irq handler registration and |
| 23 | * cleaned up irq and clock detection. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/sched.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/errno.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/ioport.h> |
| 33 | #include <linux/init.h> |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 34 | #include <linux/mutex.h> |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 35 | #include <linux/clk.h> |
| 36 | #include <linux/err.h> |
| 37 | #include <linux/platform_device.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/io.h> |
| 40 | #include <asm/irq.h> |
| 41 | #include <asm/hardware.h> |
| 42 | #include <asm/arch/ssp.h> |
| 43 | #include <asm/arch/pxa-regs.h> |
eric miao | 0aea1fd | 2007-11-21 16:57:12 +0800 | [diff] [blame] | 44 | #include <asm/arch/regs-ssp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 46 | #define TIMEOUT 100000 |
| 47 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 48 | static irqreturn_t ssp_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | struct ssp_dev *dev = (struct ssp_dev*) dev_id; |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 51 | struct ssp_device *ssp = dev->ssp; |
| 52 | unsigned int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 54 | status = __raw_readl(ssp->mmio_base + SSSR); |
| 55 | __raw_writel(status, ssp->mmio_base + SSSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | if (status & SSSR_ROR) |
| 58 | printk(KERN_WARNING "SSP(%d): receiver overrun\n", dev->port); |
| 59 | |
| 60 | if (status & SSSR_TUR) |
| 61 | printk(KERN_WARNING "SSP(%d): transmitter underrun\n", dev->port); |
| 62 | |
| 63 | if (status & SSSR_BCE) |
| 64 | printk(KERN_WARNING "SSP(%d): bit count error\n", dev->port); |
| 65 | |
| 66 | return IRQ_HANDLED; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * ssp_write_word - write a word to the SSP port |
| 71 | * @data: 32-bit, MSB justified data to write. |
| 72 | * |
| 73 | * Wait for a free entry in the SSP transmit FIFO, and write a data |
| 74 | * word to the SSP port. |
| 75 | * |
| 76 | * The caller is expected to perform the necessary locking. |
| 77 | * |
| 78 | * Returns: |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 79 | * %-ETIMEDOUT timeout occurred |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * 0 success |
| 81 | */ |
| 82 | int ssp_write_word(struct ssp_dev *dev, u32 data) |
| 83 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 84 | struct ssp_device *ssp = dev->ssp; |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 85 | int timeout = TIMEOUT; |
| 86 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 87 | while (!(__raw_readl(ssp->mmio_base + SSSR) & SSSR_TNF)) { |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 88 | if (!--timeout) |
| 89 | return -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | cpu_relax(); |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 91 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 93 | __raw_writel(data, ssp->mmio_base + SSDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * ssp_read_word - read a word from the SSP port |
| 100 | * |
| 101 | * Wait for a data word in the SSP receive FIFO, and return the |
| 102 | * received data. Data is LSB justified. |
| 103 | * |
| 104 | * Note: Currently, if data is not expected to be received, this |
| 105 | * function will wait for ever. |
| 106 | * |
| 107 | * The caller is expected to perform the necessary locking. |
| 108 | * |
| 109 | * Returns: |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 110 | * %-ETIMEDOUT timeout occurred |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * 32-bit data success |
| 112 | */ |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 113 | int ssp_read_word(struct ssp_dev *dev, u32 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 115 | struct ssp_device *ssp = dev->ssp; |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 116 | int timeout = TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 118 | while (!(__raw_readl(ssp->mmio_base + SSSR) & SSSR_RNE)) { |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 119 | if (!--timeout) |
| 120 | return -ETIMEDOUT; |
| 121 | cpu_relax(); |
| 122 | } |
| 123 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 124 | *data = __raw_readl(ssp->mmio_base + SSDR); |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 125 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
| 129 | * ssp_flush - flush the transmit and receive FIFOs |
| 130 | * |
| 131 | * Wait for the SSP to idle, and ensure that the receive FIFO |
| 132 | * is empty. |
| 133 | * |
| 134 | * The caller is expected to perform the necessary locking. |
| 135 | */ |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 136 | int ssp_flush(struct ssp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 138 | struct ssp_device *ssp = dev->ssp; |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 139 | int timeout = TIMEOUT * 2; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | do { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 142 | while (__raw_readl(ssp->mmio_base + SSSR) & SSSR_RNE) { |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 143 | if (!--timeout) |
| 144 | return -ETIMEDOUT; |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 145 | (void)__raw_readl(ssp->mmio_base + SSDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 147 | if (!--timeout) |
| 148 | return -ETIMEDOUT; |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 149 | } while (__raw_readl(ssp->mmio_base + SSSR) & SSSR_BSY); |
Paul Sokolovsky | 8f1bf87 | 2006-08-27 12:54:56 +0100 | [diff] [blame] | 150 | |
| 151 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * ssp_enable - enable the SSP port |
| 156 | * |
| 157 | * Turn on the SSP port. |
| 158 | */ |
| 159 | void ssp_enable(struct ssp_dev *dev) |
| 160 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 161 | struct ssp_device *ssp = dev->ssp; |
| 162 | uint32_t sscr0; |
| 163 | |
| 164 | sscr0 = __raw_readl(ssp->mmio_base + SSCR0); |
| 165 | sscr0 |= SSCR0_SSE; |
| 166 | __raw_writel(sscr0, ssp->mmio_base + SSCR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
| 170 | * ssp_disable - shut down the SSP port |
| 171 | * |
| 172 | * Turn off the SSP port, optionally powering it down. |
| 173 | */ |
| 174 | void ssp_disable(struct ssp_dev *dev) |
| 175 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 176 | struct ssp_device *ssp = dev->ssp; |
| 177 | uint32_t sscr0; |
| 178 | |
| 179 | sscr0 = __raw_readl(ssp->mmio_base + SSCR0); |
| 180 | sscr0 &= ~SSCR0_SSE; |
| 181 | __raw_writel(sscr0, ssp->mmio_base + SSCR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
| 185 | * ssp_save_state - save the SSP configuration |
| 186 | * @ssp: pointer to structure to save SSP configuration |
| 187 | * |
| 188 | * Save the configured SSP state for suspend. |
| 189 | */ |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 190 | void ssp_save_state(struct ssp_dev *dev, struct ssp_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 192 | struct ssp_device *ssp = dev->ssp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 194 | state->cr0 = __raw_readl(ssp->mmio_base + SSCR0); |
| 195 | state->cr1 = __raw_readl(ssp->mmio_base + SSCR1); |
| 196 | state->to = __raw_readl(ssp->mmio_base + SSTO); |
| 197 | state->psp = __raw_readl(ssp->mmio_base + SSPSP); |
| 198 | |
| 199 | ssp_disable(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /** |
| 203 | * ssp_restore_state - restore a previously saved SSP configuration |
| 204 | * @ssp: pointer to configuration saved by ssp_save_state |
| 205 | * |
| 206 | * Restore the SSP configuration saved previously by ssp_save_state. |
| 207 | */ |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 208 | void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 210 | struct ssp_device *ssp = dev->ssp; |
| 211 | uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 213 | __raw_writel(sssr, ssp->mmio_base + SSSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 215 | __raw_writel(state->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0); |
| 216 | __raw_writel(state->cr1, ssp->mmio_base + SSCR1); |
| 217 | __raw_writel(state->to, ssp->mmio_base + SSTO); |
| 218 | __raw_writel(state->psp, ssp->mmio_base + SSPSP); |
| 219 | __raw_writel(state->cr0, ssp->mmio_base + SSCR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
| 223 | * ssp_config - configure SSP port settings |
| 224 | * @mode: port operating mode |
| 225 | * @flags: port config flags |
| 226 | * @psp_flags: port PSP config flags |
| 227 | * @speed: port speed |
| 228 | * |
| 229 | * Port MUST be disabled by ssp_disable before making any config changes. |
| 230 | */ |
| 231 | int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed) |
| 232 | { |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 233 | struct ssp_device *ssp = dev->ssp; |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | dev->mode = mode; |
| 236 | dev->flags = flags; |
| 237 | dev->psp_flags = psp_flags; |
| 238 | dev->speed = speed; |
| 239 | |
| 240 | /* set up port type, speed, port settings */ |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 241 | __raw_writel((dev->speed | dev->mode), ssp->mmio_base + SSCR0); |
| 242 | __raw_writel(dev->flags, ssp->mmio_base + SSCR1); |
| 243 | __raw_writel(dev->psp_flags, ssp->mmio_base + SSPSP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * ssp_init - setup the SSP port |
| 250 | * |
| 251 | * initialise and claim resources for the SSP port. |
| 252 | * |
| 253 | * Returns: |
| 254 | * %-ENODEV if the SSP port is unavailable |
| 255 | * %-EBUSY if the resources are already in use |
| 256 | * %0 on success |
| 257 | */ |
Liam Girdwood | b216c01 | 2005-11-10 17:45:39 +0000 | [diff] [blame] | 258 | int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 260 | struct ssp_device *ssp; |
Liam Girdwood | b216c01 | 2005-11-10 17:45:39 +0000 | [diff] [blame] | 261 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 263 | ssp = ssp_request(port, "SSP"); |
| 264 | if (ssp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return -ENODEV; |
| 266 | |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 267 | dev->ssp = ssp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | dev->port = port; |
| 269 | |
Liam Girdwood | b216c01 | 2005-11-10 17:45:39 +0000 | [diff] [blame] | 270 | /* do we need to get irq */ |
| 271 | if (!(init_flags & SSP_NO_IRQ)) { |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 272 | ret = request_irq(ssp->irq, ssp_interrupt, |
Liam Girdwood | b216c01 | 2005-11-10 17:45:39 +0000 | [diff] [blame] | 273 | 0, "SSP", dev); |
| 274 | if (ret) |
| 275 | goto out_region; |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 276 | dev->irq = ssp->irq; |
Liam Girdwood | b216c01 | 2005-11-10 17:45:39 +0000 | [diff] [blame] | 277 | } else |
| 278 | dev->irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* turn on SSP port clock */ |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 281 | clk_enable(ssp->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return 0; |
| 283 | |
| 284 | out_region: |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 285 | ssp_free(ssp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * ssp_exit - undo the effects of ssp_init |
| 291 | * |
| 292 | * release and free resources for the SSP port. |
| 293 | */ |
| 294 | void ssp_exit(struct ssp_dev *dev) |
| 295 | { |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 296 | struct ssp_device *ssp = dev->ssp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
eric miao | 3dcb00e | 2007-11-30 18:26:56 +0800 | [diff] [blame^] | 298 | ssp_disable(dev); |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 299 | free_irq(dev->irq, dev); |
| 300 | clk_disable(ssp->clk); |
| 301 | ssp_free(ssp); |
| 302 | } |
| 303 | |
| 304 | static DEFINE_MUTEX(ssp_lock); |
| 305 | static LIST_HEAD(ssp_list); |
| 306 | |
| 307 | struct ssp_device *ssp_request(int port, const char *label) |
| 308 | { |
| 309 | struct ssp_device *ssp = NULL; |
| 310 | |
| 311 | mutex_lock(&ssp_lock); |
| 312 | |
| 313 | list_for_each_entry(ssp, &ssp_list, node) { |
| 314 | if (ssp->port_id == port && ssp->use_count == 0) { |
| 315 | ssp->use_count++; |
| 316 | ssp->label = label; |
| 317 | break; |
| 318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 321 | mutex_unlock(&ssp_lock); |
| 322 | |
| 323 | if (ssp->port_id != port) |
| 324 | return NULL; |
| 325 | |
| 326 | return ssp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
eric miao | 8828645 | 2007-12-06 17:56:42 +0800 | [diff] [blame] | 328 | EXPORT_SYMBOL(ssp_request); |
| 329 | |
| 330 | void ssp_free(struct ssp_device *ssp) |
| 331 | { |
| 332 | mutex_lock(&ssp_lock); |
| 333 | if (ssp->use_count) { |
| 334 | ssp->use_count--; |
| 335 | ssp->label = NULL; |
| 336 | } else |
| 337 | dev_err(&ssp->pdev->dev, "device already free\n"); |
| 338 | mutex_unlock(&ssp_lock); |
| 339 | } |
| 340 | EXPORT_SYMBOL(ssp_free); |
| 341 | |
| 342 | static int __devinit ssp_probe(struct platform_device *pdev, int type) |
| 343 | { |
| 344 | struct resource *res; |
| 345 | struct ssp_device *ssp; |
| 346 | int ret = 0; |
| 347 | |
| 348 | ssp = kzalloc(sizeof(struct ssp_device), GFP_KERNEL); |
| 349 | if (ssp == NULL) { |
| 350 | dev_err(&pdev->dev, "failed to allocate memory"); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | ssp->clk = clk_get(&pdev->dev, "SSPCLK"); |
| 355 | if (IS_ERR(ssp->clk)) { |
| 356 | ret = PTR_ERR(ssp->clk); |
| 357 | goto err_free; |
| 358 | } |
| 359 | |
| 360 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 361 | if (res == NULL) { |
| 362 | dev_err(&pdev->dev, "no memory resource defined\n"); |
| 363 | ret = -ENODEV; |
| 364 | goto err_free_clk; |
| 365 | } |
| 366 | |
| 367 | res = request_mem_region(res->start, res->end - res->start + 1, |
| 368 | pdev->name); |
| 369 | if (res == NULL) { |
| 370 | dev_err(&pdev->dev, "failed to request memory resource\n"); |
| 371 | ret = -EBUSY; |
| 372 | goto err_free_clk; |
| 373 | } |
| 374 | |
| 375 | ssp->phys_base = res->start; |
| 376 | |
| 377 | ssp->mmio_base = ioremap(res->start, res->end - res->start + 1); |
| 378 | if (ssp->mmio_base == NULL) { |
| 379 | dev_err(&pdev->dev, "failed to ioremap() registers\n"); |
| 380 | ret = -ENODEV; |
| 381 | goto err_free_mem; |
| 382 | } |
| 383 | |
| 384 | ssp->irq = platform_get_irq(pdev, 0); |
| 385 | if (ssp->irq < 0) { |
| 386 | dev_err(&pdev->dev, "no IRQ resource defined\n"); |
| 387 | ret = -ENODEV; |
| 388 | goto err_free_io; |
| 389 | } |
| 390 | |
| 391 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 392 | if (res == NULL) { |
| 393 | dev_err(&pdev->dev, "no SSP RX DRCMR defined\n"); |
| 394 | ret = -ENODEV; |
| 395 | goto err_free_io; |
| 396 | } |
| 397 | ssp->drcmr_rx = res->start; |
| 398 | |
| 399 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 400 | if (res == NULL) { |
| 401 | dev_err(&pdev->dev, "no SSP TX DRCMR defined\n"); |
| 402 | ret = -ENODEV; |
| 403 | goto err_free_io; |
| 404 | } |
| 405 | ssp->drcmr_tx = res->start; |
| 406 | |
| 407 | /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id |
| 408 | * starts from 0, do a translation here |
| 409 | */ |
| 410 | ssp->port_id = pdev->id + 1; |
| 411 | ssp->use_count = 0; |
| 412 | ssp->type = type; |
| 413 | |
| 414 | mutex_lock(&ssp_lock); |
| 415 | list_add(&ssp->node, &ssp_list); |
| 416 | mutex_unlock(&ssp_lock); |
| 417 | |
| 418 | platform_set_drvdata(pdev, ssp); |
| 419 | return 0; |
| 420 | |
| 421 | err_free_io: |
| 422 | iounmap(ssp->mmio_base); |
| 423 | err_free_mem: |
| 424 | release_mem_region(res->start, res->end - res->start + 1); |
| 425 | err_free_clk: |
| 426 | clk_put(ssp->clk); |
| 427 | err_free: |
| 428 | kfree(ssp); |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | static int __devexit ssp_remove(struct platform_device *pdev) |
| 433 | { |
| 434 | struct resource *res; |
| 435 | struct ssp_device *ssp; |
| 436 | |
| 437 | ssp = platform_get_drvdata(pdev); |
| 438 | if (ssp == NULL) |
| 439 | return -ENODEV; |
| 440 | |
| 441 | iounmap(ssp->mmio_base); |
| 442 | |
| 443 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 444 | release_mem_region(res->start, res->end - res->start + 1); |
| 445 | |
| 446 | clk_put(ssp->clk); |
| 447 | |
| 448 | mutex_lock(&ssp_lock); |
| 449 | list_del(&ssp->node); |
| 450 | mutex_unlock(&ssp_lock); |
| 451 | |
| 452 | kfree(ssp); |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | static int __devinit pxa25x_ssp_probe(struct platform_device *pdev) |
| 457 | { |
| 458 | return ssp_probe(pdev, PXA25x_SSP); |
| 459 | } |
| 460 | |
| 461 | static int __devinit pxa25x_nssp_probe(struct platform_device *pdev) |
| 462 | { |
| 463 | return ssp_probe(pdev, PXA25x_NSSP); |
| 464 | } |
| 465 | |
| 466 | static int __devinit pxa27x_ssp_probe(struct platform_device *pdev) |
| 467 | { |
| 468 | return ssp_probe(pdev, PXA27x_SSP); |
| 469 | } |
| 470 | |
| 471 | static struct platform_driver pxa25x_ssp_driver = { |
| 472 | .driver = { |
| 473 | .name = "pxa25x-ssp", |
| 474 | }, |
| 475 | .probe = pxa25x_ssp_probe, |
| 476 | .remove = __devexit_p(ssp_remove), |
| 477 | }; |
| 478 | |
| 479 | static struct platform_driver pxa25x_nssp_driver = { |
| 480 | .driver = { |
| 481 | .name = "pxa25x-nssp", |
| 482 | }, |
| 483 | .probe = pxa25x_nssp_probe, |
| 484 | .remove = __devexit_p(ssp_remove), |
| 485 | }; |
| 486 | |
| 487 | static struct platform_driver pxa27x_ssp_driver = { |
| 488 | .driver = { |
| 489 | .name = "pxa27x-ssp", |
| 490 | }, |
| 491 | .probe = pxa27x_ssp_probe, |
| 492 | .remove = __devexit_p(ssp_remove), |
| 493 | }; |
| 494 | |
| 495 | static int __init pxa_ssp_init(void) |
| 496 | { |
| 497 | int ret = 0; |
| 498 | |
| 499 | ret = platform_driver_register(&pxa25x_ssp_driver); |
| 500 | if (ret) { |
| 501 | printk(KERN_ERR "failed to register pxa25x_ssp_driver"); |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | ret = platform_driver_register(&pxa25x_nssp_driver); |
| 506 | if (ret) { |
| 507 | printk(KERN_ERR "failed to register pxa25x_nssp_driver"); |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | ret = platform_driver_register(&pxa27x_ssp_driver); |
| 512 | if (ret) { |
| 513 | printk(KERN_ERR "failed to register pxa27x_ssp_driver"); |
| 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | static void __exit pxa_ssp_exit(void) |
| 521 | { |
| 522 | platform_driver_unregister(&pxa25x_ssp_driver); |
| 523 | platform_driver_unregister(&pxa25x_nssp_driver); |
| 524 | platform_driver_unregister(&pxa27x_ssp_driver); |
| 525 | } |
| 526 | |
| 527 | module_init(pxa_ssp_init); |
| 528 | module_exit(pxa_ssp_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | EXPORT_SYMBOL(ssp_write_word); |
| 531 | EXPORT_SYMBOL(ssp_read_word); |
| 532 | EXPORT_SYMBOL(ssp_flush); |
| 533 | EXPORT_SYMBOL(ssp_enable); |
| 534 | EXPORT_SYMBOL(ssp_disable); |
| 535 | EXPORT_SYMBOL(ssp_save_state); |
| 536 | EXPORT_SYMBOL(ssp_restore_state); |
| 537 | EXPORT_SYMBOL(ssp_init); |
| 538 | EXPORT_SYMBOL(ssp_exit); |
| 539 | EXPORT_SYMBOL(ssp_config); |
| 540 | |
| 541 | MODULE_DESCRIPTION("PXA SSP driver"); |
| 542 | MODULE_AUTHOR("Liam Girdwood"); |
| 543 | MODULE_LICENSE("GPL"); |
| 544 | |