syscon.h 1.45 KB
Newer Older
1 2 3 4
#ifndef __SYSCON_H
#define __SYSCON_H

#include <inttypes.h>
5
#include <sys/types.h>
6 7

#include "board.h"
8
#undef PACKED /* if we already included a regs file, we'd get a warning */
9 10
#include <hw/wrc_syscon_regs.h>

11 12 13 14 15 16 17
struct SYSCON_WB {
	uint32_t RSTR;		/*Syscon Reset Register */
	uint32_t GPSR;		/*GPIO Set/Readback Register */
	uint32_t GPCR;		/*GPIO Clear Register */
	uint32_t HWFR;		/*Hardware Feature Register */
	uint32_t TCR;		/*Timer Control Register */
	uint32_t TVR;		/*Timer Counter Value Register */
18 19 20 21 22 23 24
};

/*GPIO pins*/
#define GPIO_LED_LINK SYSC_GPSR_LED_LINK
#define GPIO_LED_STAT SYSC_GPSR_LED_STAT
#define GPIO_BTN1     SYSC_GPSR_BTN1
#define GPIO_BTN2     SYSC_GPSR_BTN2
25 26 27 28 29
#define GPIO_SFP_DET  SYSC_GPSR_SFP_DET

#define WRPC_FMC_I2C  0
#define WRPC_SFP_I2C  1

30 31 32
struct s_i2c_if {
	uint32_t scl;
	uint32_t sda;
33 34
};

35
extern struct s_i2c_if i2c_if[2];
36

37
#define TICS_PER_SECOND 1000
38 39 40 41
void timer_init(uint32_t enable);
uint32_t timer_get_tics();
void timer_delay(uint32_t how_long);

42 43 44 45 46 47
/* usleep.c */
extern void usleep_init(void);
extern int usleep(useconds_t usec);



48
extern volatile struct SYSCON_WB *syscon;
49 50 51 52 53 54

/****************************
 *        GPIO
 ***************************/
static inline void gpio_out(int pin, int val)
{
55 56 57 58
	if (val)
		syscon->GPSR = pin;
	else
		syscon->GPCR = pin;
59 60 61 62
}

static inline int gpio_in(int pin)
{
63
	return syscon->GPSR & pin ? 1 : 0;
64
}
65 66 67 68 69

static inline int sysc_get_memsize()
{
	return (SYSC_HWFR_MEMSIZE_R(syscon->HWFR) + 1) * 16;
}
70

71
#endif