Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
1 | /* |
2 | JZ47xx GPIO at userspace |
3 | |
4 | Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com |
5 | |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
19 | |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
22 | #include <unistd.h> |
23 | |
24 | #include <jz47xx_gpio.h> |
25 | #include <jz47xx_mmap.h> |
26 | |
27 | |
28 | #define JZ_GPIO_BASE 0x10010000 |
29 | |
30 | int |
31 | jz_gpio_as_output (JZ_PIO * pio, unsigned int o) |
32 | { |
33 | pio->PXFUNC = (1 << (o)); |
34 | pio->PXSELC = (1 << (o)); |
35 | pio->PXDIRS = (1 << (o)); |
36 | return 0; |
37 | } |
38 | |
39 | void |
40 | jz_gpio_as_input (JZ_PIO * pio, unsigned int o) |
41 | { |
42 | pio->PXFUNC = (1 << (o)); |
43 | pio->PXSELC = (1 << (o)); |
44 | pio->PXDIRC = (1 << (o)); |
45 | } |
46 | |
47 | void |
48 | jz_gpio_as_irq (JZ_PIO * pio, unsigned int o) |
49 | { |
50 | pio->PXFUNC = (1 << (o)); |
51 | pio->PXSELS = (1 << (o)); |
52 | pio->PXDIRC = (1 << (o)); |
53 | } |
54 | |
55 | int |
56 | jz_gpio_set_pin (JZ_PIO * pio, unsigned int o) |
57 | { |
58 | pio->PXDATS = (1 << (o)); |
59 | return 0; |
60 | } |
61 | |
62 | int |
63 | jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o) |
64 | { |
65 | pio->PXDATC = (1 << (o)); |
66 | return 0; |
67 | } |
68 | |
69 | void |
70 | jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val) |
71 | { |
72 | if (val == 0) |
73 | pio->PXDATC = (1 << (o)); |
74 | else |
75 | pio->PXDATS = (1 << (o)); |
76 | } |
77 | |
78 | unsigned int |
79 | jz_gpio_get_pin (JZ_PIO * pio, unsigned int o) |
80 | { |
81 | return (pio->PXPIN & (1 << o)) ? 1 : 0; |
82 | } |
83 | |
84 | int |
85 | jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func) |
86 | { |
87 | switch (func) |
88 | { |
89 | case 0: |
90 | pio->PXFUNS = (1 << o); |
91 | pio->PXTRGC = (1 << o); |
92 | pio->PXSELC = (1 << o); |
93 | pio->PXPES = (1 << o); |
94 | return 1; |
95 | |
96 | case 1: |
97 | pio->PXFUNS = (1 << o); |
98 | pio->PXTRGC = (1 << o); |
99 | pio->PXSELS = (1 << o); |
100 | pio->PXPES = (1 << o); |
101 | return 1; |
102 | |
103 | case 2: |
104 | pio->PXFUNS = (1 << o); |
105 | pio->PXTRGS = (1 << o); |
106 | pio->PXSELC = (1 << o); |
107 | pio->PXPES = (1 << o); |
108 | return 1; |
109 | } |
110 | return 0; |
111 | } |
112 | |
113 | JZ_PIO * |
114 | jz_gpio_map (int port) |
115 | { |
116 | JZ_PIO *pio; |
117 | |
118 | pio = (JZ_PIO *) jz_mmap (JZ_GPIO_BASE); |
119 | pio = (JZ_PIO *) ((unsigned int) pio + port * 0x100); |
120 | |
121 | return pio; |
122 | } |
123 |
Branches:
master