/*
 * 
 *
 *  Copyright (C) 2005 HP Labs
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

#ifndef __ASM_ARCH_GPIO_H
#define __ASM_ARCH_GPIO_H

#define MAX_GPIO_BANKS		5
#define NR_BUILTIN_GPIO		(MAX_GPIO_BANKS * 32)

#define IMX_GPIO_NR(bank, nr)		(((bank) - 1) * 32 + (nr))

#define DEBUG 1

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

#ifdef DEBUG
  #define DEBUG_INFO(fmt, args...)  fprintf(stderr, fmt, ##args) 
  #define DEBUG_ERROR(fmt, args...) fprintf(stderr, fmt"%s\t%s\t%d\n", ##args, __FILE__,__FUNCTION__,__LINE__)
#else
  #define DEBUG_INFO(fmt, args...) 
  #define DEBUG_ERROR(fmt, args...)
#endif        

#define RET_SUCCESS                 0
#define RET_FAILED                  -1
#define BUF_SIZE1                    512
#define BUF_SIZE2                    512
/* ioctl cmd */
#define	IOCTL_GPIO_LEVEL_GET	        _IOW('Q', 0x02, int)   	//get gpio state
#define	IOCTL_GPIO_LEVEL_SET            _IOR('Q', 0x03, int)	//set gpio output state
#define	IOCTL_GPIO_DIR_INPUT_SET	    _IOW('Q', 0x04, int)	//set gpio as a input
  

#define GPIO_LEVEL_LOW                  0
#define GPIO_LEVEL_HIGHT                1

typedef struct {
	char *gpio_name;
	int  gpio_index;
} GPIO_ATTR_ST;
 
typedef struct {
	int  gpio_index;
	int  gpio_level;
} IOCTL_GPIO_ARG_ST;

/*
* serial define 
*/
typedef struct {
    unsigned int lable;
	unsigned int baudrate;
} SERIAL_BAUD_ST;

typedef struct{
    unsigned int flags;
	unsigned int delay_rts_after_send;	/* delay after send (milliseconds) */
}SERIAL_RS485_CONF_ST;

typedef struct {
    char parity;
	unsigned int baud;
    unsigned int databits;
    unsigned int stopbits;
} SERIAL_ATTR_ST;

#define TIMEOUT                     1  /* read operation timeout 1s = TIMEOUT/10 */
#define MIN_LEN                     255 /* the min len datas */
#define DEV_NAME_LEN                11
#define SERIAL_ATTR_BAUD            115200
#define SERIAL_ATTR_DATABITS        8
#define SERIAL_ATTR_STOPBITS        1
#define SERIAL_ATTR_PARITY          'n'
#define SERIAL_MODE_NORMAL          0
#define SERIAL_MODE_485             1
#define DELAY_RTS_AFTER_SEND        1   /* 1ms */
#define SER_RS485_ENABLED		    1	/* 485 enable */

#define DEV_GPIO                    "/dev/qiyang_imx6_gpio"

#define	IMX_GPIO4_23	    IMX_GPIO_NR(4 , 23)
#define	IMX_GPIO4_24	    IMX_GPIO_NR(4 , 24)
#define	IMX_GPIO4_25	    IMX_GPIO_NR(4 , 25)
#define	IMX_GPIO4_26	    IMX_GPIO_NR(4 , 26)
#define	IMX_GPIO4_27	    IMX_GPIO_NR(4 , 27)
#define	IMX_GPIO4_28	    IMX_GPIO_NR(4 , 28)
#define	IMX_GPIO1_18	    IMX_GPIO_NR(1 , 18)

#define	IMX_GPIO5_4	    IMX_GPIO_NR(5 , 4)
#define	IMX_GPIO5_6	    IMX_GPIO_NR(5 , 6)

#define	IMX_GPIO5_1	    IMX_GPIO_NR(5 , 1)
#define	IMX_GPIO5_2	    IMX_GPIO_NR(5 , 2)
#define	IMX_GPIO5_7	    IMX_GPIO_NR(5 , 7)



#endif

