| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup genarch
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | * @brief Samsung S3C24xx on-chip interrupt controller.
|
|---|
| 35 | *
|
|---|
| 36 | * This IRQC is present on the Samsung S3C24xx CPU (on the gta02 platform).
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | #include <genarch/drivers/s3c24xx_irqc/s3c24xx_irqc.h>
|
|---|
| 40 | #include <arch/asm.h>
|
|---|
| 41 |
|
|---|
| 42 | /** Correspondence between interrupt sources and sub-sources. */
|
|---|
| 43 | static unsigned s3c24xx_subsrc_src[][2] = {
|
|---|
| 44 | { S3C24XX_SUBINT_CAM_P, S3C24XX_INT_CAM },
|
|---|
| 45 | { S3C24XX_SUBINT_CAM_C, S3C24XX_INT_CAM },
|
|---|
| 46 | { S3C24XX_SUBINT_ADC_S, S3C24XX_INT_ADC },
|
|---|
| 47 | { S3C24XX_SUBINT_TC, S3C24XX_INT_ADC },
|
|---|
| 48 | { S3C24XX_SUBINT_ERR2, S3C24XX_INT_UART2 },
|
|---|
| 49 | { S3C24XX_SUBINT_TXD2, S3C24XX_INT_UART2 },
|
|---|
| 50 | { S3C24XX_SUBINT_RXD2, S3C24XX_INT_UART2 },
|
|---|
| 51 | { S3C24XX_SUBINT_ERR1, S3C24XX_INT_UART1 },
|
|---|
| 52 | { S3C24XX_SUBINT_TXD1, S3C24XX_INT_UART1 },
|
|---|
| 53 | { S3C24XX_SUBINT_RXD1, S3C24XX_INT_UART1 },
|
|---|
| 54 | { S3C24XX_SUBINT_ERR0, S3C24XX_INT_UART0 },
|
|---|
| 55 | { S3C24XX_SUBINT_TXD0, S3C24XX_INT_UART0 },
|
|---|
| 56 | { S3C24XX_SUBINT_RXD0, S3C24XX_INT_UART0 }
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | /** Initialize S3C24xx interrupt controller.
|
|---|
| 60 | *
|
|---|
| 61 | * @param irqc Instance structure
|
|---|
| 62 | * @param regs Register I/O structure
|
|---|
| 63 | */
|
|---|
| 64 | void s3c24xx_irqc_init(s3c24xx_irqc_t *irqc, s3c24xx_irqc_regs_t *regs)
|
|---|
| 65 | {
|
|---|
| 66 | irqc->regs = regs;
|
|---|
| 67 |
|
|---|
| 68 | /* Make all interrupt sources use IRQ mode (not FIQ). */
|
|---|
| 69 | pio_write_32(®s->intmod, 0x00000000);
|
|---|
| 70 |
|
|---|
| 71 | /* Disable all interrupt sources. */
|
|---|
| 72 | pio_write_32(®s->intmsk, 0xffffffff);
|
|---|
| 73 |
|
|---|
| 74 | /* Disable interrupts from all sub-sources. */
|
|---|
| 75 | pio_write_32(®s->intsubmsk, 0xffffffff);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /** Obtain number of pending interrupt. */
|
|---|
| 79 | unsigned s3c24xx_irqc_inum_get(s3c24xx_irqc_t *irqc)
|
|---|
| 80 | {
|
|---|
| 81 | return pio_read_32(&irqc->regs->intoffset);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /** Clear pending interrupt condition including sub-sources.
|
|---|
| 85 | *
|
|---|
| 86 | * Clear source and interrupt pending condition and also automatically clear
|
|---|
| 87 | * any sub-source pending condition pertaining to the source.
|
|---|
| 88 | */
|
|---|
| 89 | void s3c24xx_irqc_clear(s3c24xx_irqc_t *irqc, unsigned inum)
|
|---|
| 90 | {
|
|---|
| 91 | unsigned src, subsrc;
|
|---|
| 92 | unsigned entries, i;
|
|---|
| 93 |
|
|---|
| 94 | entries = sizeof(s3c24xx_subsrc_src) / sizeof(s3c24xx_subsrc_src[0]);
|
|---|
| 95 |
|
|---|
| 96 | for (i = 0; i < entries; i++) {
|
|---|
| 97 | subsrc = s3c24xx_subsrc_src[i][0];
|
|---|
| 98 | src = s3c24xx_subsrc_src[i][1];
|
|---|
| 99 |
|
|---|
| 100 | if (src == inum) {
|
|---|
| 101 | pio_write_32(&irqc->regs->subsrcpnd,
|
|---|
| 102 | S3C24XX_SUBINT_BIT(subsrc));
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | pio_write_32(&irqc->regs->srcpnd, S3C24XX_INT_BIT(inum));
|
|---|
| 107 | pio_write_32(&irqc->regs->intpnd, S3C24XX_INT_BIT(inum));
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | /** Enable interrupts from the specified source. */
|
|---|
| 111 | void s3c24xx_irqc_src_enable(s3c24xx_irqc_t *irqc, unsigned src)
|
|---|
| 112 | {
|
|---|
| 113 | pio_write_32(&irqc->regs->intmsk, pio_read_32(&irqc->regs->intmsk) &
|
|---|
| 114 | ~S3C24XX_INT_BIT(src));
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /** Disable interrupts from the specified source. */
|
|---|
| 118 | void s3c24xx_irqc_src_disable(s3c24xx_irqc_t *irqc, unsigned src)
|
|---|
| 119 | {
|
|---|
| 120 | pio_write_32(&irqc->regs->intmsk, pio_read_32(&irqc->regs->intmsk) |
|
|---|
| 121 | S3C24XX_INT_BIT(src));
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | /** Enable interrupts from the specified sub-source. */
|
|---|
| 125 | void s3c24xx_irqc_subsrc_enable(s3c24xx_irqc_t *irqc, unsigned subsrc)
|
|---|
| 126 | {
|
|---|
| 127 | pio_write_32(&irqc->regs->intsubmsk,
|
|---|
| 128 | pio_read_32(&irqc->regs->intsubmsk) &
|
|---|
| 129 | ~S3C24XX_SUBINT_BIT(subsrc));
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /** Disable interrupts from the specified sub-source. */
|
|---|
| 133 | void s3c24xx_irqc_subsrc_disable(s3c24xx_irqc_t *irqc, unsigned subsrc)
|
|---|
| 134 | {
|
|---|
| 135 | pio_write_32(&irqc->regs->intsubmsk,
|
|---|
| 136 | pio_read_32(&irqc->regs->intsubmsk) |
|
|---|
| 137 | S3C24XX_SUBINT_BIT(subsrc));
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | /** @}
|
|---|
| 141 | */
|
|---|