/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to dma/nwl_irq.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-27 00:28:57 UTC
  • Revision ID: csa@suren.me-20150427002857-82fk6r3e8rfgy4wr
First stand-alone ipecamera implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
#include <unistd.h>
5
 
#include <sys/time.h>
6
 
 
7
 
#include "pcilib.h"
8
 
 
9
 
#include "pci.h"
10
 
#include "error.h"
11
 
#include "tools.h"
12
 
 
13
 
#include "nwl_private.h"
14
 
#include "nwl_defines.h"
15
 
 
16
 
int dma_nwl_init_irq(nwl_dma_t *ctx, uint32_t val) {
17
 
    if (val&(DMA_INT_ENABLE|DMA_USER_INT_ENABLE)) {
18
 
        if (val&DMA_INT_ENABLE) ctx->irq_preserve |= PCILIB_DMA_IRQ;
19
 
        if (val&DMA_USER_INT_ENABLE) ctx->irq_preserve |= PCILIB_EVENT_IRQ;
20
 
    }
21
 
    
22
 
    ctx->irq_started = 1;
23
 
    return 0;
24
 
}
25
 
 
26
 
int dma_nwl_free_irq(nwl_dma_t *ctx) {
27
 
    if (ctx->irq_started) {
28
 
        dma_nwl_disable_irq((pcilib_dma_context_t*)ctx, 0);
29
 
        if (ctx->irq_preserve) dma_nwl_enable_irq((pcilib_dma_context_t*)ctx, ctx->irq_preserve, 0);
30
 
        ctx->irq_enabled = 0;
31
 
        ctx->irq_started = 0;
32
 
    }
33
 
    return 0;
34
 
}
35
 
 
36
 
int dma_nwl_enable_irq(pcilib_dma_context_t *vctx, pcilib_irq_type_t type, pcilib_dma_flags_t flags) {
37
 
    uint32_t val;
38
 
    nwl_dma_t *ctx = (nwl_dma_t*)vctx;
39
 
    
40
 
    if (flags&PCILIB_DMA_FLAG_PERSISTENT) ctx->irq_preserve |= type;
41
 
 
42
 
    if ((ctx->irq_enabled&type) == type) return 0;
43
 
    
44
 
    type |= ctx->irq_enabled;
45
 
    
46
 
    nwl_read_register(val, ctx, ctx->base_addr, REG_DMA_CTRL_STATUS);
47
 
    if (!ctx->irq_started) dma_nwl_init_irq(ctx, val);
48
 
 
49
 
    val &= ~(DMA_INT_ENABLE|DMA_USER_INT_ENABLE);
50
 
    nwl_write_register(val, ctx, ctx->base_addr, REG_DMA_CTRL_STATUS);
51
 
    
52
 
    pcilib_clear_irq(ctx->pcilib, NWL_DMA_IRQ_SOURCE);
53
 
 
54
 
    if (type & PCILIB_DMA_IRQ) val |= DMA_INT_ENABLE;
55
 
    if (type & PCILIB_EVENT_IRQ) val |= DMA_USER_INT_ENABLE;
56
 
    nwl_write_register(val, ctx, ctx->base_addr, REG_DMA_CTRL_STATUS);
57
 
    
58
 
    ctx->irq_enabled = type;
59
 
 
60
 
    return 0;
61
 
}
62
 
 
63
 
 
64
 
int dma_nwl_disable_irq(pcilib_dma_context_t *vctx, pcilib_dma_flags_t flags) {
65
 
    uint32_t val;
66
 
    nwl_dma_t *ctx = (nwl_dma_t*)vctx;
67
 
    
68
 
    ctx->irq_enabled = 0;
69
 
    
70
 
    nwl_read_register(val, ctx, ctx->base_addr, REG_DMA_CTRL_STATUS);
71
 
    if (!ctx->irq_started) dma_nwl_init_irq(ctx, val);
72
 
    val &= ~(DMA_INT_ENABLE|DMA_USER_INT_ENABLE);
73
 
    nwl_write_register(val, ctx, ctx->base_addr, REG_DMA_CTRL_STATUS);
74
 
    
75
 
    if (flags&PCILIB_DMA_FLAG_PERSISTENT) ctx->irq_preserve = 0;
76
 
 
77
 
    return 0;
78
 
}
79
 
 
80
 
 
81
 
int dma_nwl_enable_engine_irq(nwl_dma_t *ctx, pcilib_dma_engine_t dma) {
82
 
    uint32_t val;
83
 
    
84
 
    dma_nwl_enable_irq((pcilib_dma_context_t*)ctx, PCILIB_DMA_IRQ, 0);
85
 
 
86
 
    nwl_read_register(val, ctx, ctx->engines[dma].base_addr, REG_DMA_ENG_CTRL_STATUS);
87
 
    val |= (DMA_ENG_INT_ENABLE);
88
 
    nwl_write_register(val, ctx, ctx->engines[dma].base_addr, REG_DMA_ENG_CTRL_STATUS);
89
 
    
90
 
    return 0;
91
 
}
92
 
 
93
 
int dma_nwl_disable_engine_irq(nwl_dma_t *ctx, pcilib_dma_engine_t dma) {
94
 
    uint32_t val;
95
 
 
96
 
    nwl_read_register(val, ctx, ctx->engines[dma].base_addr, REG_DMA_ENG_CTRL_STATUS);
97
 
    val &= ~(DMA_ENG_INT_ENABLE);
98
 
    nwl_write_register(val, ctx, ctx->engines[dma].base_addr, REG_DMA_ENG_CTRL_STATUS);
99
 
 
100
 
    return 0;
101
 
}
102
 
 
103
 
int dma_nwl_acknowledge_irq(pcilib_dma_context_t *vctx, pcilib_irq_type_t irq_type, pcilib_irq_source_t irq_source) {
104
 
    uint32_t val;
105
 
    
106
 
    nwl_dma_t *ctx = (nwl_dma_t*)vctx;
107
 
    pcilib_nwl_engine_description_t *info = ctx->engines + irq_source;
108
 
 
109
 
    if (irq_type != PCILIB_DMA_IRQ) return PCILIB_ERROR_NOTSUPPORTED;
110
 
    if (irq_source >= ctx->n_engines) return PCILIB_ERROR_NOTAVAILABLE;
111
 
 
112
 
    nwl_read_register(val, ctx, info->base_addr, REG_DMA_ENG_CTRL_STATUS);
113
 
    if (val & DMA_ENG_INT_ACTIVE_MASK) {
114
 
        val |= DMA_ENG_ALLINT_MASK;
115
 
        nwl_write_register(val, ctx, info->base_addr, REG_DMA_ENG_CTRL_STATUS);
116
 
    }
117
 
    
118
 
    return 0;
119
 
}