123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/sched.h>
- #include <linux/errno.h>
- #include <linux/interrupt.h>
- #include <linux/ioport.h>
- #include <linux/init.h>
- #include <linux/io.h>
- #include <mach/hardware.h>
- #include <mach/irqs.h>
- #include <asm/hardware/ssp.h>
- #define TIMEOUT 100000
- static irqreturn_t ssp_interrupt(int irq, void *dev_id)
- {
- unsigned int status = Ser4SSSR;
- if (status & SSSR_ROR)
- printk(KERN_WARNING "SSP: receiver overrun\n");
- Ser4SSSR = SSSR_ROR;
- return status ? IRQ_HANDLED : IRQ_NONE;
- }
- int ssp_write_word(u16 data)
- {
- int timeout = TIMEOUT;
- while (!(Ser4SSSR & SSSR_TNF)) {
- if (!--timeout)
- return -ETIMEDOUT;
- cpu_relax();
- }
- Ser4SSDR = data;
- timeout = TIMEOUT;
- while (!(Ser4SSSR & SSSR_BSY)) {
- if (!--timeout)
- return -ETIMEDOUT;
- cpu_relax();
- }
- return 0;
- }
- int ssp_read_word(u16 *data)
- {
- int timeout = TIMEOUT;
- while (!(Ser4SSSR & SSSR_RNE)) {
- if (!--timeout)
- return -ETIMEDOUT;
- cpu_relax();
- }
- *data = (u16)Ser4SSDR;
- return 0;
- }
- int ssp_flush(void)
- {
- int timeout = TIMEOUT * 2;
- do {
- while (Ser4SSSR & SSSR_RNE) {
- if (!--timeout)
- return -ETIMEDOUT;
- (void) Ser4SSDR;
- }
- if (!--timeout)
- return -ETIMEDOUT;
- } while (Ser4SSSR & SSSR_BSY);
- return 0;
- }
- void ssp_enable(void)
- {
- Ser4SSCR0 |= SSCR0_SSE;
- }
- void ssp_disable(void)
- {
- Ser4SSCR0 &= ~SSCR0_SSE;
- }
- void ssp_save_state(struct ssp_state *ssp)
- {
- ssp->cr0 = Ser4SSCR0;
- ssp->cr1 = Ser4SSCR1;
- Ser4SSCR0 &= ~SSCR0_SSE;
- }
- void ssp_restore_state(struct ssp_state *ssp)
- {
- Ser4SSSR = SSSR_ROR;
- Ser4SSCR0 = ssp->cr0 & ~SSCR0_SSE;
- Ser4SSCR1 = ssp->cr1;
- Ser4SSCR0 = ssp->cr0;
- }
- int ssp_init(void)
- {
- int ret;
- if (!(PPAR & PPAR_SPR) && (Ser4MCCR0 & MCCR0_MCE))
- return -ENODEV;
- if (!request_mem_region(__PREG(Ser4SSCR0), 0x18, "SSP")) {
- return -EBUSY;
- }
- Ser4SSSR = SSSR_ROR;
- ret = request_irq(IRQ_Ser4SSP, ssp_interrupt, 0, "SSP", NULL);
- if (ret)
- goto out_region;
- return 0;
- out_region:
- release_mem_region(__PREG(Ser4SSCR0), 0x18);
- return ret;
- }
- void ssp_exit(void)
- {
- Ser4SSCR0 &= ~SSCR0_SSE;
- free_irq(IRQ_Ser4SSP, NULL);
- release_mem_region(__PREG(Ser4SSCR0), 0x18);
- }
- MODULE_AUTHOR("Russell King");
- MODULE_DESCRIPTION("SA11x0 SSP PIO driver");
- MODULE_LICENSE("GPL");
- EXPORT_SYMBOL(ssp_write_word);
- EXPORT_SYMBOL(ssp_read_word);
- EXPORT_SYMBOL(ssp_flush);
- EXPORT_SYMBOL(ssp_enable);
- EXPORT_SYMBOL(ssp_disable);
- EXPORT_SYMBOL(ssp_save_state);
- EXPORT_SYMBOL(ssp_restore_state);
- EXPORT_SYMBOL(ssp_init);
- EXPORT_SYMBOL(ssp_exit);
|