2 * linux/arch/arm/mach-pxa/ssp.c
4 * based on linux/arch/arm/mach-sa1100/ssp.c by Russell King
6 * Copyright (C) 2003 Russell King.
7 * Copyright (C) 2003 Wolfson Microelectronics PLC
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.
13 * PXA2xx SSP driver. This provides the generic core for simple
14 * IO-based SSP applications and allows easy port setup for DMA access.
16 * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
19 * 22nd Aug 2003 Initial version.
20 * 20th Dec 2004 Added ssp_config for changing port config without
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/errno.h>
29 #include <linux/interrupt.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
34 #include <asm/hardware.h>
35 #include <asm/arch/ssp.h>
36 #include <asm/arch/pxa-regs.h>
38 #define PXA_SSP_PORTS 3
40 static DECLARE_MUTEX(sem);
41 static int use_count[PXA_SSP_PORTS] = {0, 0, 0};
43 static irqreturn_t ssp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
45 struct ssp_dev *dev = (struct ssp_dev*) dev_id;
46 unsigned int status = SSSR_P(dev->port);
48 SSSR_P(dev->port) = status; /* clear status bits */
50 if (status & SSSR_ROR)
51 printk(KERN_WARNING "SSP(%d): receiver overrun\n", dev->port);
53 if (status & SSSR_TUR)
54 printk(KERN_WARNING "SSP(%d): transmitter underrun\n", dev->port);
56 if (status & SSSR_BCE)
57 printk(KERN_WARNING "SSP(%d): bit count error\n", dev->port);
63 * ssp_write_word - write a word to the SSP port
64 * @data: 32-bit, MSB justified data to write.
66 * Wait for a free entry in the SSP transmit FIFO, and write a data
67 * word to the SSP port.
69 * The caller is expected to perform the necessary locking.
72 * %-ETIMEDOUT timeout occurred (for future)
75 int ssp_write_word(struct ssp_dev *dev, u32 data)
77 while (!(SSSR_P(dev->port) & SSSR_TNF))
80 SSDR_P(dev->port) = data;
86 * ssp_read_word - read a word from the SSP port
88 * Wait for a data word in the SSP receive FIFO, and return the
89 * received data. Data is LSB justified.
91 * Note: Currently, if data is not expected to be received, this
92 * function will wait for ever.
94 * The caller is expected to perform the necessary locking.
97 * %-ETIMEDOUT timeout occurred (for future)
100 int ssp_read_word(struct ssp_dev *dev)
102 while (!(SSSR_P(dev->port) & SSSR_RNE))
105 return SSDR_P(dev->port);
109 * ssp_flush - flush the transmit and receive FIFOs
111 * Wait for the SSP to idle, and ensure that the receive FIFO
114 * The caller is expected to perform the necessary locking.
116 void ssp_flush(struct ssp_dev *dev)
119 while (SSSR_P(dev->port) & SSSR_RNE) {
120 (void) SSDR_P(dev->port);
122 } while (SSSR_P(dev->port) & SSSR_BSY);
126 * ssp_enable - enable the SSP port
128 * Turn on the SSP port.
130 void ssp_enable(struct ssp_dev *dev)
132 SSCR0_P(dev->port) |= SSCR0_SSE;
136 * ssp_disable - shut down the SSP port
138 * Turn off the SSP port, optionally powering it down.
140 void ssp_disable(struct ssp_dev *dev)
142 SSCR0_P(dev->port) &= ~SSCR0_SSE;
146 * ssp_save_state - save the SSP configuration
147 * @ssp: pointer to structure to save SSP configuration
149 * Save the configured SSP state for suspend.
151 void ssp_save_state(struct ssp_dev *dev, struct ssp_state *ssp)
153 ssp->cr0 = SSCR0_P(dev->port);
154 ssp->cr1 = SSCR1_P(dev->port);
155 ssp->to = SSTO_P(dev->port);
156 ssp->psp = SSPSP_P(dev->port);
158 SSCR0_P(dev->port) &= ~SSCR0_SSE;
162 * ssp_restore_state - restore a previously saved SSP configuration
163 * @ssp: pointer to configuration saved by ssp_save_state
165 * Restore the SSP configuration saved previously by ssp_save_state.
167 void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *ssp)
169 SSSR_P(dev->port) = SSSR_ROR | SSSR_TUR | SSSR_BCE;
171 SSCR0_P(dev->port) = ssp->cr0 & ~SSCR0_SSE;
172 SSCR1_P(dev->port) = ssp->cr1;
173 SSTO_P(dev->port) = ssp->to;
174 SSPSP_P(dev->port) = ssp->psp;
176 SSCR0_P(dev->port) = ssp->cr0;
180 * ssp_config - configure SSP port settings
181 * @mode: port operating mode
182 * @flags: port config flags
183 * @psp_flags: port PSP config flags
186 * Port MUST be disabled by ssp_disable before making any config changes.
188 int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed)
192 dev->psp_flags = psp_flags;
195 /* set up port type, speed, port settings */
196 SSCR0_P(dev->port) = (dev->speed | dev->mode);
197 SSCR1_P(dev->port) = dev->flags;
198 SSPSP_P(dev->port) = dev->psp_flags;
204 * ssp_init - setup the SSP port
206 * initialise and claim resources for the SSP port.
209 * %-ENODEV if the SSP port is unavailable
210 * %-EBUSY if the resources are already in use
213 int ssp_init(struct ssp_dev *dev, u32 port)
217 if (port > PXA_SSP_PORTS || port == 0)
221 if (use_count[port - 1]) {
225 use_count[port - 1]++;
227 if (!request_mem_region(__PREG(SSCR0_P(port)), 0x2c, "SSP")) {
228 use_count[port - 1]--;
237 #if defined (CONFIG_PXA27x)
258 ret = request_irq(irq, ssp_interrupt, 0, "SSP", dev);
262 /* turn on SSP port clock */
264 #if defined (CONFIG_PXA27x)
266 pxa_set_cken(CKEN23_SSP1, 1);
269 pxa_set_cken(CKEN3_SSP2, 1);
272 pxa_set_cken(CKEN4_SSP3, 1);
276 pxa_set_cken(CKEN3_SSP, 1);
279 pxa_set_cken(CKEN9_NSSP, 1);
282 pxa_set_cken(CKEN10_ASSP, 1);
291 release_mem_region(__PREG(SSCR0_P(port)), 0x2c);
292 use_count[port - 1]--;
298 * ssp_exit - undo the effects of ssp_init
300 * release and free resources for the SSP port.
302 void ssp_exit(struct ssp_dev *dev)
307 SSCR0_P(dev->port) &= ~SSCR0_SSE;
309 /* find irq, save power and turn off SSP port clock */
311 #if defined (CONFIG_PXA27x)
314 pxa_set_cken(CKEN23_SSP1, 0);
318 pxa_set_cken(CKEN3_SSP2, 0);
322 pxa_set_cken(CKEN4_SSP3, 0);
327 pxa_set_cken(CKEN3_SSP, 0);
331 pxa_set_cken(CKEN9_NSSP, 0);
335 pxa_set_cken(CKEN10_ASSP, 0);
339 printk(KERN_WARNING "SSP: tried to close invalid port\n");
344 release_mem_region(__PREG(SSCR0_P(dev->port)), 0x2c);
345 use_count[dev->port - 1]--;
349 EXPORT_SYMBOL(ssp_write_word);
350 EXPORT_SYMBOL(ssp_read_word);
351 EXPORT_SYMBOL(ssp_flush);
352 EXPORT_SYMBOL(ssp_enable);
353 EXPORT_SYMBOL(ssp_disable);
354 EXPORT_SYMBOL(ssp_save_state);
355 EXPORT_SYMBOL(ssp_restore_state);
356 EXPORT_SYMBOL(ssp_init);
357 EXPORT_SYMBOL(ssp_exit);
358 EXPORT_SYMBOL(ssp_config);
360 MODULE_DESCRIPTION("PXA SSP driver");
361 MODULE_AUTHOR("Liam Girdwood");
362 MODULE_LICENSE("GPL");