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.
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
28 #include <linux/interrupt.h>
29 #include <linux/ioport.h>
30 #include <linux/init.h>
33 #include <asm/hardware.h>
34 #include <asm/arch/ssp.h>
35 #include <asm/arch/pxa-regs.h>
37 static irqreturn_t ssp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
39 struct ssp_dev *dev = (struct ssp_dev*) dev_id;
40 unsigned int status = SSSR_P(dev->port);
42 SSSR_P(dev->port) = status; /* clear status bits */
44 if (status & SSSR_ROR)
45 printk(KERN_WARNING "SSP(%d): receiver overrun\n", dev->port);
47 if (status & SSSR_TUR)
48 printk(KERN_WARNING "SSP(%d): transmitter underrun\n", dev->port);
50 if (status & SSSR_BCE)
51 printk(KERN_WARNING "SSP(%d): bit count error\n", dev->port);
57 * ssp_write_word - write a word to the SSP port
58 * @data: 32-bit, MSB justified data to write.
60 * Wait for a free entry in the SSP transmit FIFO, and write a data
61 * word to the SSP port.
63 * The caller is expected to perform the necessary locking.
66 * %-ETIMEDOUT timeout occurred (for future)
69 int ssp_write_word(struct ssp_dev *dev, u32 data)
71 while (!(SSSR_P(dev->port) & SSSR_TNF))
74 SSDR_P(dev->port) = data;
80 * ssp_read_word - read a word from the SSP port
82 * Wait for a data word in the SSP receive FIFO, and return the
83 * received data. Data is LSB justified.
85 * Note: Currently, if data is not expected to be received, this
86 * function will wait for ever.
88 * The caller is expected to perform the necessary locking.
91 * %-ETIMEDOUT timeout occurred (for future)
94 int ssp_read_word(struct ssp_dev *dev)
96 while (!(SSSR_P(dev->port) & SSSR_RNE))
99 return SSDR_P(dev->port);
103 * ssp_flush - flush the transmit and receive FIFOs
105 * Wait for the SSP to idle, and ensure that the receive FIFO
108 * The caller is expected to perform the necessary locking.
110 void ssp_flush(struct ssp_dev *dev)
113 while (SSSR_P(dev->port) & SSSR_RNE) {
114 (void) SSDR_P(dev->port);
116 } while (SSSR_P(dev->port) & SSSR_BSY);
120 * ssp_enable - enable the SSP port
122 * Turn on the SSP port.
124 void ssp_enable(struct ssp_dev *dev)
126 SSCR0_P(dev->port) |= SSCR0_SSE;
130 * ssp_disable - shut down the SSP port
132 * Turn off the SSP port, optionally powering it down.
134 void ssp_disable(struct ssp_dev *dev)
136 SSCR0_P(dev->port) &= ~SSCR0_SSE;
140 * ssp_save_state - save the SSP configuration
141 * @ssp: pointer to structure to save SSP configuration
143 * Save the configured SSP state for suspend.
145 void ssp_save_state(struct ssp_dev *dev, struct ssp_state *ssp)
147 ssp->cr0 = SSCR0_P(dev->port);
148 ssp->cr1 = SSCR1_P(dev->port);
149 ssp->to = SSTO_P(dev->port);
150 ssp->psp = SSPSP_P(dev->port);
152 SSCR0_P(dev->port) &= ~SSCR0_SSE;
156 * ssp_restore_state - restore a previously saved SSP configuration
157 * @ssp: pointer to configuration saved by ssp_save_state
159 * Restore the SSP configuration saved previously by ssp_save_state.
161 void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *ssp)
163 SSSR_P(dev->port) = SSSR_ROR | SSSR_TUR | SSSR_BCE;
165 SSCR0_P(dev->port) = ssp->cr0 & ~SSCR0_SSE;
166 SSCR1_P(dev->port) = ssp->cr1;
167 SSTO_P(dev->port) = ssp->to;
168 SSPSP_P(dev->port) = ssp->psp;
170 SSCR0_P(dev->port) = ssp->cr0;
174 * ssp_init - setup the SSP port
176 * initialise and claim resources for the SSP port.
179 * %-ENODEV if the SSP port is unavailable
180 * %-EBUSY if the resources are already in use
183 int ssp_init(struct ssp_dev *dev, u32 port, u32 mode, u32 flags, u32 psp_flags,
188 if (!request_mem_region(__PREG(SSCR0_P(port)), 0x2c, "SSP")) {
196 #if defined (CONFIG_PXA27x)
218 dev->psp_flags = psp_flags;
221 /* set up port type, speed, port settings */
222 SSCR0_P(dev->port) = (dev->speed | dev->mode);
223 SSCR1_P(dev->port) = dev->flags;
224 SSPSP_P(dev->port) = dev->psp_flags;
226 ret = request_irq(irq, ssp_interrupt, 0, "SSP", dev);
230 /* turn on SSP port clock */
232 #if defined (CONFIG_PXA27x)
234 pxa_set_cken(CKEN23_SSP1, 1);
237 pxa_set_cken(CKEN3_SSP2, 1);
240 pxa_set_cken(CKEN4_SSP3, 1);
244 pxa_set_cken(CKEN3_SSP, 1);
247 pxa_set_cken(CKEN9_NSSP, 1);
250 pxa_set_cken(CKEN10_ASSP, 1);
258 release_mem_region(__PREG(SSCR0_P(dev->port)), 0x2c);
263 * ssp_exit - undo the effects of ssp_init
265 * release and free resources for the SSP port.
267 void ssp_exit(struct ssp_dev *dev)
271 SSCR0_P(dev->port) &= ~SSCR0_SSE;
273 /* find irq, save power and turn off SSP port clock */
275 #if defined (CONFIG_PXA27x)
278 pxa_set_cken(CKEN23_SSP1, 0);
282 pxa_set_cken(CKEN3_SSP2, 0);
286 pxa_set_cken(CKEN4_SSP3, 0);
291 pxa_set_cken(CKEN3_SSP, 0);
295 pxa_set_cken(CKEN9_NSSP, 0);
299 pxa_set_cken(CKEN10_ASSP, 0);
303 printk(KERN_WARNING "SSP: tried to close invalid port\n");
308 release_mem_region(__PREG(SSCR0_P(dev->port)), 0x2c);
311 EXPORT_SYMBOL(ssp_write_word);
312 EXPORT_SYMBOL(ssp_read_word);
313 EXPORT_SYMBOL(ssp_flush);
314 EXPORT_SYMBOL(ssp_enable);
315 EXPORT_SYMBOL(ssp_disable);
316 EXPORT_SYMBOL(ssp_save_state);
317 EXPORT_SYMBOL(ssp_restore_state);
318 EXPORT_SYMBOL(ssp_init);
319 EXPORT_SYMBOL(ssp_exit);