2 * linux/arch/arm/mach-sa1100/ssp.c
4 * Copyright (C) 2003 Russell King.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Generic SSP driver. This provides the generic core for simple
11 * IO-based SSP applications.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/errno.h>
17 #include <linux/interrupt.h>
18 #include <linux/ioport.h>
19 #include <linux/init.h>
23 #include <asm/hardware.h>
24 #include <asm/hardware/ssp.h>
26 #define TIMEOUT 100000
28 static irqreturn_t ssp_interrupt(int irq, void *dev_id)
30 unsigned int status = Ser4SSSR;
32 if (status & SSSR_ROR)
33 printk(KERN_WARNING "SSP: receiver overrun\n");
37 return status ? IRQ_HANDLED : IRQ_NONE;
41 * ssp_write_word - write a word to the SSP port
42 * @data: 16-bit, MSB justified data to write.
44 * Wait for a free entry in the SSP transmit FIFO, and write a data
45 * word to the SSP port. Wait for the SSP port to start sending
48 * The caller is expected to perform the necessary locking.
51 * %-ETIMEDOUT timeout occurred
54 int ssp_write_word(u16 data)
56 int timeout = TIMEOUT;
58 while (!(Ser4SSSR & SSSR_TNF)) {
67 while (!(Ser4SSSR & SSSR_BSY)) {
77 * ssp_read_word - read a word from the SSP port
79 * Wait for a data word in the SSP receive FIFO, and return the
80 * received data. Data is LSB justified.
82 * Note: Currently, if data is not expected to be received, this
83 * function will wait for ever.
85 * The caller is expected to perform the necessary locking.
88 * %-ETIMEDOUT timeout occurred
91 int ssp_read_word(u16 *data)
93 int timeout = TIMEOUT;
95 while (!(Ser4SSSR & SSSR_RNE)) {
101 *data = (u16)Ser4SSDR;
107 * ssp_flush - flush the transmit and receive FIFOs
109 * Wait for the SSP to idle, and ensure that the receive FIFO
112 * The caller is expected to perform the necessary locking.
115 * %-ETIMEDOUT timeout occurred
120 int timeout = TIMEOUT * 2;
123 while (Ser4SSSR & SSSR_RNE) {
130 } while (Ser4SSSR & SSSR_BSY);
136 * ssp_enable - enable the SSP port
138 * Turn on the SSP port.
140 void ssp_enable(void)
142 Ser4SSCR0 |= SSCR0_SSE;
146 * ssp_disable - shut down the SSP port
148 * Turn off the SSP port, optionally powering it down.
150 void ssp_disable(void)
152 Ser4SSCR0 &= ~SSCR0_SSE;
156 * ssp_save_state - save the SSP configuration
157 * @ssp: pointer to structure to save SSP configuration
159 * Save the configured SSP state for suspend.
161 void ssp_save_state(struct ssp_state *ssp)
163 ssp->cr0 = Ser4SSCR0;
164 ssp->cr1 = Ser4SSCR1;
166 Ser4SSCR0 &= ~SSCR0_SSE;
170 * ssp_restore_state - restore a previously saved SSP configuration
171 * @ssp: pointer to configuration saved by ssp_save_state
173 * Restore the SSP configuration saved previously by ssp_save_state.
175 void ssp_restore_state(struct ssp_state *ssp)
179 Ser4SSCR0 = ssp->cr0 & ~SSCR0_SSE;
180 Ser4SSCR1 = ssp->cr1;
181 Ser4SSCR0 = ssp->cr0;
185 * ssp_init - setup the SSP port
187 * initialise and claim resources for the SSP port.
190 * %-ENODEV if the SSP port is unavailable
191 * %-EBUSY if the resources are already in use
198 if (!(PPAR & PPAR_SPR) && (Ser4MCCR0 & MCCR0_MCE))
201 if (!request_mem_region(__PREG(Ser4SSCR0), 0x18, "SSP")) {
207 ret = request_irq(IRQ_Ser4SSP, ssp_interrupt, 0, "SSP", NULL);
214 release_mem_region(__PREG(Ser4SSCR0), 0x18);
219 * ssp_exit - undo the effects of ssp_init
221 * release and free resources for the SSP port.
225 Ser4SSCR0 &= ~SSCR0_SSE;
227 free_irq(IRQ_Ser4SSP, NULL);
228 release_mem_region(__PREG(Ser4SSCR0), 0x18);
231 MODULE_AUTHOR("Russell King");
232 MODULE_DESCRIPTION("SA11x0 SSP PIO driver");
233 MODULE_LICENSE("GPL");
235 EXPORT_SYMBOL(ssp_write_word);
236 EXPORT_SYMBOL(ssp_read_word);
237 EXPORT_SYMBOL(ssp_flush);
238 EXPORT_SYMBOL(ssp_enable);
239 EXPORT_SYMBOL(ssp_disable);
240 EXPORT_SYMBOL(ssp_save_state);
241 EXPORT_SYMBOL(ssp_restore_state);
242 EXPORT_SYMBOL(ssp_init);
243 EXPORT_SYMBOL(ssp_exit);