1#ifndef _ASM_ARCH_CRIS_IO_H
2#define _ASM_ARCH_CRIS_IO_H
3
4#include <asm/arch/hwregs/reg_map.h>
5#include <asm/arch/hwregs/reg_rdwr.h>
6#include <asm/arch/hwregs/gio_defs.h>
7
8enum crisv32_io_dir
9{
10  crisv32_io_dir_in = 0,
11  crisv32_io_dir_out = 1
12};
13
14struct crisv32_ioport
15{
16  unsigned long* oe;
17  unsigned long* data;
18  unsigned long* data_in;
19  unsigned int pin_count;
20};
21
22struct crisv32_iopin
23{
24  struct crisv32_ioport* port;
25  int bit;
26};
27
28extern struct crisv32_ioport crisv32_ioports[];
29
30extern struct crisv32_iopin crisv32_led1_green;
31extern struct crisv32_iopin crisv32_led1_red;
32extern struct crisv32_iopin crisv32_led2_green;
33extern struct crisv32_iopin crisv32_led2_red;
34extern struct crisv32_iopin crisv32_led3_green;
35extern struct crisv32_iopin crisv32_led3_red;
36
37static inline void crisv32_io_set(struct crisv32_iopin* iopin,
38			   int val)
39{
40	if (val)
41		*iopin->port->data |= iopin->bit;
42	else
43		*iopin->port->data &= ~iopin->bit;
44}
45
46static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
47			       enum crisv32_io_dir dir)
48{
49	if (dir == crisv32_io_dir_in)
50		*iopin->port->oe &= ~iopin->bit;
51	else
52		*iopin->port->oe |= iopin->bit;
53}
54
55static inline int crisv32_io_rd(struct crisv32_iopin* iopin)
56{
57	return ((*iopin->port->data_in & iopin->bit) ? 1 : 0);
58}
59
60int crisv32_io_get(struct crisv32_iopin* iopin,
61                   unsigned int port, unsigned int pin);
62int crisv32_io_get_name(struct crisv32_iopin* iopin,
63                         char* name);
64
65#define LED_OFF    0x00
66#define LED_GREEN  0x01
67#define LED_RED    0x02
68#define LED_ORANGE (LED_GREEN | LED_RED)
69
70#define LED_NETWORK_SET(x)                          \
71	do {                                        \
72		LED_NETWORK_SET_G((x) & LED_GREEN); \
73		LED_NETWORK_SET_R((x) & LED_RED);   \
74	} while (0)
75#define LED_ACTIVE_SET(x)                           \
76	do {                                        \
77		LED_ACTIVE_SET_G((x) & LED_GREEN);  \
78		LED_ACTIVE_SET_R((x) & LED_RED);    \
79	} while (0)
80
81#define LED_NETWORK_SET_G(x) \
82	crisv32_io_set(&crisv32_led1_green, !(x));
83#define LED_NETWORK_SET_R(x) \
84	crisv32_io_set(&crisv32_led1_red, !(x));
85#define LED_ACTIVE_SET_G(x) \
86	crisv32_io_set(&crisv32_led2_green, !(x));
87#define LED_ACTIVE_SET_R(x) \
88	crisv32_io_set(&crisv32_led2_red, !(x));
89#define LED_DISK_WRITE(x) \
90         do{\
91		crisv32_io_set(&crisv32_led3_green, !(x)); \
92		crisv32_io_set(&crisv32_led3_red, !(x));   \
93        }while(0)
94#define LED_DISK_READ(x) \
95	crisv32_io_set(&crisv32_led3_green, !(x));
96
97#endif
98