/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 pci.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-03-08 21:46:14 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: csa@dside.dyndns.org-20110308214614-g5v841m61jilcrm2
Initial support of IPECamera protocol

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#define _PCITOOL_PCI_H
3
3
 
4
4
#define PCILIB_MAX_BANKS 6
 
5
#define PCILIB_REGISTER_TIMEOUT 10000           /**< us */
5
6
 
6
7
#include <stdint.h>
7
8
 
8
9
#include "driver/pciDriver.h"
9
10
#include "kernel.h"
10
11
 
11
 
#define pcilib_memcpy memcpy32
12
 
 
13
 
typedef enum {
 
12
#define pcilib_memcpy pcilib_memcpy32
 
13
#define pcilib_datacpy pcilib_datacpy32
 
14
 
 
15
typedef struct pcilib_s pcilib_t;
 
16
 
 
17
typedef uint8_t pcilib_bar_t;                   /**< Type holding the PCI Bar number */
 
18
typedef uint8_t pcilib_register_t;              /**< Type holding the register ID within the Bank */
 
19
typedef uint8_t pcilib_register_addr_t;         /**< Type holding the register ID within the Bank */
 
20
typedef uint8_t pcilib_register_bank_t;         /**< Type holding the register bank number */
 
21
typedef uint8_t pcilib_register_bank_addr_t;    /**< Type holding the register bank number */
 
22
typedef uint8_t pcilib_register_size_t;         /**< Type holding the size in bits of the register */
 
23
typedef uint32_t pcilib_register_value_t;       /**< Type holding the register value */
 
24
 
 
25
typedef enum {
 
26
    PCILIB_LITTLE_ENDIAN = 0,
 
27
    PCILIB_BIG_ENDIAN
 
28
} pcilib_endianess_t;
 
29
 
 
30
typedef enum {
 
31
    PCILIB_MODEL_DETECT,
14
32
    PCILIB_MODEL_PCI,
15
33
    PCILIB_MODEL_IPECAMERA
16
34
} pcilib_model_t;
17
35
 
18
 
 
19
36
typedef enum {
20
37
    PCILIB_REGISTER_R = 1,
21
38
    PCILIB_REGISTER_W = 2,
22
39
    PCILIB_REGISTER_RW = 3
23
40
} pcilib_register_mode_t;
24
41
 
 
42
 
25
43
typedef enum {
26
44
    IPECAMERA_REGISTER_PROTOCOL
27
45
} pcilib_register_protocol_t;
28
46
 
29
 
typedef struct {
30
 
    uint8_t id;
31
 
    uint8_t size;
32
 
    uint32_t defvalue;
 
47
#define PCILIB_BAR_DETECT               ((pcilib_bar_t)-1)
 
48
#define PCILIB_REGISTER_INVALID         ((pcilib_register_t)-1)
 
49
#define PCILIB_ADDRESS_INVALID          ((uintptr_t)-1)
 
50
#define PCILIB_REGISTER_BANK0           0
 
51
 
 
52
typedef struct {
 
53
    pcilib_register_bank_addr_t addr;
 
54
    
 
55
    pcilib_register_protocol_t protocol;
 
56
 
 
57
    uintptr_t read_addr;
 
58
    uintptr_t write_addr;
 
59
    uint8_t raw_endianess;
 
60
 
 
61
    uint8_t access;
 
62
    uint8_t endianess;
 
63
} pcilib_register_bank_description_t;
 
64
 
 
65
typedef struct {
 
66
    pcilib_register_addr_t addr;
 
67
    pcilib_register_size_t bits;
 
68
    pcilib_register_value_t defvalue;
33
69
    pcilib_register_mode_t mode;
34
70
 
 
71
    pcilib_register_bank_t bank;
 
72
    
35
73
    const char *name;
36
 
    
37
 
    pcilib_register_protocol_t protocol;
38
 
    uint64_t read_addr;
39
 
    uint64_t write_addr;
40
 
 
41
74
    const char *description;
42
 
} pcilib_register_t;
 
75
} pcilib_register_description_t;
43
76
 
 
77
/**
 
78
  * Default mappings
 
79
  */
44
80
typedef struct {
45
 
    uint32_t start;
46
 
    uint32_t end;
 
81
    uintptr_t start;
 
82
    uintptr_t end;
 
83
    pcilib_register_bank_t bank;
47
84
} pcilib_register_range_t;
48
85
 
 
86
typedef struct {
 
87
    int (*read)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t *value);
 
88
    int (*write)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t value);
 
89
} pcilib_protocol_description_t;
 
90
 
49
91
#include "ipecamera.h"
50
92
 
51
93
typedef struct {
52
 
    pcilib_register_t *registers;
 
94
    pcilib_register_description_t *registers;
 
95
    pcilib_register_bank_description_t *banks;
53
96
    pcilib_register_range_t *ranges;
54
97
} pcilib_model_description_t;
55
98
 
56
99
#ifdef _PCILIB_PCI_C
57
 
pcilib_model_description_t pcilib_model_description[2] = {
58
 
    { NULL, NULL },
59
 
    { ipecamera_registers, ipecamera_register_range }
 
100
pcilib_model_description_t pcilib_model[3] = {
 
101
    { NULL, NULL, NULL },
 
102
    { NULL, NULL, NULL },
 
103
    { ipecamera_registers, ipecamera_register_banks, ipecamera_register_ranges }
 
104
};
 
105
 
 
106
pcilib_protocol_description_t pcilib_protocol[2] = {
 
107
    { ipecamera_read, ipecamera_write },
 
108
    { NULL, NULL }
60
109
};
61
110
#else
62
 
extern pcilib_model_description_t pcilib_model_description[];
 
111
extern void (*pcilib_error)(const char *msg, ...);
 
112
extern void (*pcilib_warning)(const char *msg, ...);
 
113
 
 
114
extern pcilib_model_description_t pcilib_model[];
 
115
extern pcilib_protocol_description_t pcilib_protocol[];
63
116
#endif /* _PCILIB_PCI_C */
64
117
 
65
 
 
66
 
int pcilib_open(const char *device);
67
 
void pcilib_close(int handle);
68
 
 
69
118
int pcilib_set_error_handler(void (*err)(const char *msg, ...));
70
119
 
71
 
const pci_board_info *pcilib_get_board_info(int handle);
72
 
pcilib_model_t pcilib_detect_model(int handle);
73
 
void *pcilib_map_bar(int handle, int bar);
74
 
void pcilib_unmap_bar(int handle, int bar, void *data);
75
 
 
76
 
int pcilib_read(void *buf, int handle, int bar, unsigned long addr, int size);
77
 
int pcilib_write(void *buf, int handle, int bar, unsigned long addr, int size);
78
 
 
79
 
int pcilib_find_register(pcilib_model_t model, const char *reg);
 
120
 
 
121
pcilib_t *pcilib_open(const char *device, pcilib_model_t model);
 
122
void pcilib_close(pcilib_t *ctx);
 
123
 
 
124
const pci_board_info *pcilib_get_board_info(pcilib_t *ctx);
 
125
pcilib_model_t pcilib_get_model(pcilib_t *ctx);
 
126
 
 
127
void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar);
 
128
void pcilib_unmap_bar(pcilib_t *ctx, pcilib_bar_t bar, void *data);
 
129
 
 
130
pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *reg);
 
131
char  *pcilib_resolve_register_address(pcilib_t *ctx, uintptr_t addr);
 
132
 
 
133
int pcilib_read(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf);
 
134
int pcilib_write(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr, size_t size, void *buf);
 
135
 
80
136
 
81
137
#endif /* _PCITOOL_PCI_H */