2 * Raspberry Pi GPIO support
6 #include "../port/lib.h"
7 #include "../port/error.h"
13 #define GPIOREGS (VIRTIO+0x200000)
45 static u32int *regs = (u32int*)GPIOREGS;
48 gpiosel(uint pin, int func)
50 int shift = (pin % 10) * 3;
51 u32int *reg = ®s[Fsel0 + pin/10];
53 *reg = (*reg & ~(FuncMask<<shift)) | (func<<shift);
57 gpiopull(uint pin, int func)
61 if(regs[PUPPDN3] == 0x6770696f){
62 /* BCM2835, BCM2836, BCM2837 */
63 u32int mask = 1 << (pin % 32);
64 reg = ®s[PUDclk0 + pin/32];
72 int shift = 2*(pin % 16);
73 static u32int map[PudMask+1] = {0x00,0x02,0x01};
74 reg = ®s[PUPPDN0 + pin/16];
75 *reg = (*reg & ~(3<<shift)) | (map[func] << shift);
88 gpiopull(pin, Pullup);
92 gpiopulldown(uint pin)
94 gpiopull(pin, Pulldown);
98 gpioout(uint pin, int set)
100 regs[(set? Set0: Clr0) + pin/32] = 1 << (pin % 32);
106 return (regs[Lev0 + pin/32] & (1 << (pin % 32))) != 0;
110 gpioselevent(uint pin, int falling, int enable)
112 u32int *reg = ®s[(falling? Fedge0: Redge0) + pin/32];
113 *reg = (*reg & ~(1<<pin)) | ((enable != 0)<<pin);
117 gpiogetevent(uint pin)
121 reg = ®s[Evds0 + pin/32];
122 val = *reg & (1 << (pin % 32));
132 memset(&seg, 0, sizeof seg);
133 seg.attr = SG_PHYSICAL;
135 seg.pa = (GPIOREGS - soc.virtio) + soc.physio;