-/*
- * Chip Specific Head File
- */
-#include <asm/danube/port.h>
-
-#include <asm/danube/danube_led.h>
-#include <asm/danube/danube_gptu.h>
-
-
-/*
- * ####################################
- * Definition
- * ####################################
- */
-
-#define DEBUG_ON_AMAZON 0
-
-#define DATA_CLOCKING_EDGE FALLING_EDGE
-
-#define BOARD_TYPE REFERENCE_BOARD
-
-#define DEBUG_WRITE_REGISTER 0
-
-#define RISING_EDGE 0
-#define FALLING_EDGE 1
-
-#define EVALUATION_BOARD 0
-#define REFERENCE_BOARD 1
-
-/*
- * GPIO Driver Function Wrapping
- */
-#define port_reserve_pin danube_port_reserve_pin
-#define port_free_pin danube_port_free_pin
-#define port_set_altsel0 danube_port_set_altsel0
-#define port_clear_altsel0 danube_port_clear_altsel0
-#define port_set_altsel1 danube_port_set_altsel1
-#define port_clear_altsel1 danube_port_clear_altsel1
-#define port_set_dir_out danube_port_set_dir_out
-#define port_clear_dir_out danube_port_clear_dir_out
-#define port_set_open_drain danube_port_set_open_drain
-#define port_clear_open_drain danube_port_clear_open_drain
-
-/*
- * GPIO Port Used By LED
- */
-#define LED_SH_PORT 0
-#define LED_SH_PIN 4
-#define LED_SH_DIR 1
-#define LED_SH_ALTSEL0 1
-#define LED_SH_ALTSEL1 0
-#define LED_SH_OPENDRAIN 1
-#define LED_D_PORT 0
-#define LED_D_PIN 5
-#define LED_D_DIR 1
-#define LED_D_ALTSEL0 1
-#define LED_D_ALTSEL1 0
-#define LED_D_OPENDRAIN 1
-#define LED_ST_PORT 0
-#define LED_ST_PIN 6
-#define LED_ST_DIR 1
-#define LED_ST_ALTSEL0 1
-#define LED_ST_ALTSEL1 0
-#define LED_ST_OPENDRAIN 1
-
-#define LED_ADSL0_PORT 0
-#define LED_ADSL0_PIN 4
-#define LED_ADSL0_DIR 1
-#define LED_ADSL0_ALTSEL0 0
-#define LED_ADSL0_ALTSEL1 1
-#define LED_ADSL0_OPENDRAIN 1
-#define LED_ADSL1_PORT 0
-#define LED_ADSL1_PIN 5
-#define LED_ADSL1_DIR 1
-#define LED_ADSL1_ALTSEL0 1
-#define LED_ADSL1_ALTSEL1 1
-#define LED_ADSL1_OPENDRAIN 1
-
-#if (LED_SH_PORT == LED_ADSL0_PORT && LED_SH_PIN == LED_ADSL0_PIN) \
- || (LED_D_PORT == LED_ADSL0_PORT && LED_D_PIN == LED_ADSL0_PIN) \
- || (LED_ST_PORT == LED_ADSL0_PORT && LED_ST_PIN == LED_ADSL0_PIN) \
- || (LED_SH_PORT == LED_ADSL1_PORT && LED_SH_PIN == LED_ADSL1_PIN) \
- || (LED_D_PORT == LED_ADSL1_PORT && LED_D_PIN == LED_ADSL1_PIN) \
- || (LED_ST_PORT == LED_ADSL1_PORT && LED_ST_PIN == LED_ADSL1_PIN)
- #define ADSL_LED_IS_EXCLUSIVE 1
-#else
- #define ADSL_LED_IS_EXCLUSIVE 0
-#endif
-
-/*
- * Define GPIO Functions
- */
-#if LED_SH_DIR
- #define LED_SH_DIR_SETUP port_set_dir_out
-#else
- #define LED_SH_DIR_SETUP port_clear_dir_out
-#endif
-#if LED_SH_ALTSEL0
- #define LED_SH_ALTSEL0_SETUP port_set_altsel0
-#else
- #define LED_SH_ALTSEL0_SETUP port_clear_altsel0
-#endif
-#if LED_SH_ALTSEL1
- #define LED_SH_ALTSEL1_SETUP port_set_altsel1
-#else
- #define LED_SH_ALTSEL1_SETUP port_clear_altsel1
-#endif
-#if LED_SH_OPENDRAIN
- #define LED_SH_OPENDRAIN_SETUP port_set_open_drain
-#else
- #define LED_SH_OPENDRAIN_SETUP port_clear_open_drain
-#endif
-
-#if LED_D_DIR
- #define LED_D_DIR_SETUP port_set_dir_out
-#else
- #define LED_D_DIR_SETUP port_clear_dir_out
-#endif
-#if LED_D_ALTSEL0
- #define LED_D_ALTSEL0_SETUP port_set_altsel0
-#else
- #define LED_D_ALTSEL0_SETUP port_clear_altsel0
-#endif
-#if LED_D_ALTSEL1
- #define LED_D_ALTSEL1_SETUP port_set_altsel1
-#else
- #define LED_D_ALTSEL1_SETUP port_clear_altsel1
-#endif
-#if LED_D_OPENDRAIN
- #define LED_D_OPENDRAIN_SETUP port_set_open_drain
-#else
- #define LED_D_OPENDRAIN_SETUP port_clear_open_drain
-#endif
-
-#if LED_ST_DIR
- #define LED_ST_DIR_SETUP port_set_dir_out
-#else
- #define LED_ST_DIR_SETUP port_clear_dir_out
-#endif
-#if LED_ST_ALTSEL0
- #define LED_ST_ALTSEL0_SETUP port_set_altsel0
-#else
- #define LED_ST_ALTSEL0_SETUP port_clear_altsel0
-#endif
-#if LED_ST_ALTSEL1
- #define LED_ST_ALTSEL1_SETUP port_set_altsel1
-#else
- #define LED_ST_ALTSEL1_SETUP port_clear_altsel1
-#endif
-#if LED_ST_OPENDRAIN
- #define LED_ST_OPENDRAIN_SETUP port_set_open_drain
-#else
- #define LED_ST_OPENDRAIN_SETUP port_clear_open_drain
-#endif
-
-#if LED_ADSL0_DIR
- #define LED_ADSL0_DIR_SETUP port_set_dir_out
-#else
- #define LED_ADSL0_DIR_SETUP port_clear_dir_out
-#endif
-#if LED_ADSL0_ALTSEL0
- #define LED_ADSL0_ALTSEL0_SETUP port_set_altsel0
-#else
- #define LED_ADSL0_ALTSEL0_SETUP port_clear_altsel0
-#endif
-#if LED_ADSL0_ALTSEL1
- #define LED_ADSL0_ALTSEL1_SETUP port_set_altsel1
-#else
- #define LED_ADSL0_ALTSEL1_SETUP port_clear_altsel1
-#endif
-#if LED_ADSL0_OPENDRAIN
- #define LED_ADSL0_OPENDRAIN_SETUP port_set_open_drain
-#else
- #define LED_ADSL0_OPENDRAIN_SETUP port_clear_open_drain
-#endif
-
-#if LED_ADSL1_DIR
- #define LED_ADSL1_DIR_SETUP port_set_dir_out
-#else
- #define LED_ADSL1_DIR_SETUP port_clear_dir_out
-#endif
-#if LED_ADSL1_ALTSEL0
- #define LED_ADSL1_ALTSEL0_SETUP port_set_altsel0
-#else
- #define LED_ADSL1_ALTSEL0_SETUP port_clear_altsel0
-#endif
-#if LED_ADSL1_ALTSEL1
- #define LED_ADSL1_ALTSEL1_SETUP port_set_altsel1
-#else
- #define LED_ADSL1_ALTSEL1_SETUP port_clear_altsel1
-#endif
-#if LED_ADSL1_OPENDRAIN
- #define LED_ADSL1_OPENDRAIN_SETUP port_set_open_drain
-#else
- #define LED_ADSL1_OPENDRAIN_SETUP port_clear_open_drain
-#endif
-
-/*
- * LED Device Minor Number
- */
-#if !defined(LED_MINOR)
- #define LED_MINOR 151 // This number is written in Linux kernel document "devices.txt"
-#endif // !defined(LED_MINOR)
-
-/*
- * Bits Operation
- */
-#define GET_BITS(x, msb, lsb) (((x) & ((1 << ((msb) + 1)) - 1)) >> (lsb))
-#define SET_BITS(x, msb, lsb, value) (((x) & ~(((1 << ((msb) + 1)) - 1) ^ ((1 << (lsb)) - 1))) | (((value) & ((1 << (1 + (msb) - (lsb))) - 1)) << (lsb)))
-
-/*
- * LED Registers Mapping
- */
-#define DANUBE_LED (KSEG1 + 0x1E100BB0)
-#define DANUBE_LED_CON0 ((volatile unsigned int*)(DANUBE_LED + 0x0000))
-#define DANUBE_LED_CON1 ((volatile unsigned int*)(DANUBE_LED + 0x0004))
-#define DANUBE_LED_CPU0 ((volatile unsigned int*)(DANUBE_LED + 0x0008))
-#define DANUBE_LED_CPU1 ((volatile unsigned int*)(DANUBE_LED + 0x000C))
-#define DANUBE_LED_AR ((volatile unsigned int*)(DANUBE_LED + 0x0010))
-
-/*
- * LED Control 0 Register
- */
-#define LED_CON0_SWU (*DANUBE_LED_CON0 & (1 << 31))
-#define LED_CON0_FALLING_EDGE (*DANUBE_LED_CON0 & (1 << 26))
-#define LED_CON0_AD1 (*DANUBE_LED_CON0 & (1 << 25))
-#define LED_CON0_AD0 (*DANUBE_LED_CON0 & (1 << 24))
-#define LED_CON0_LBn(n) (*DANUBE_LED_CON0 & (1 << n))
-#define LED_CON0_DEFAULT_VALUE (0x80000000 | (DATA_CLOCKING_EDGE << 26))
-
-/*
- * LED Control 1 Register
- */
-#define LED_CON1_US (*DANUBE_LED_CON1 >> 30)
-#define LED_CON1_SCS (*DANUBE_LED_CON1 & (1 << 28))
-#define LED_CON1_FPID GET_BITS(*DANUBE_LED_CON1, 27, 23)
-#define LED_CON1_FPIS GET_BITS(*DANUBE_LED_CON1, 21, 20)
-#define LED_CON1_DO GET_BITS(*DANUBE_LED_CON1, 19, 18)
-#define LED_CON1_G2 (*DANUBE_LED_CON1 & (1 << 2))
-#define LED_CON1_G1 (*DANUBE_LED_CON1 & (1 << 1))
-#define LED_CON1_G0 (*DANUBE_LED_CON1 & 0x01)
-#define LED_CON1_G (*DANUBE_LED_CON1 & 0x07)
-#define LED_CON1_DEFAULT_VALUE 0x00000000
-
-/*
- * LED Data Output CPU 0 Register
- */
-#define LED_CPU0_Ln(n) (*DANUBE_LED_CPU0 & (1 << n))
-#define LED_LED_CPU0_DEFAULT_VALUE 0x00000000
-
-/*
- * LED Data Output CPU 1 Register
- */
-#define LED_CPU1_Ln(n) (*DANUBE_LED_CPU1 & (1 << n))
-#define LED_LED_CPU1_DEFAULT_VALUE 0x00000000
-
-/*
- * LED Data Output Access Rights Register
- */
-#define LED_AR_Ln(n) (*DANUBE_LED_AR & (1 << n))
-#define LED_AR_DEFAULT_VALUE 0x00000000
-
-/*
- * If try module on Amazon chip, prepare some tricks to prevent invalid memory write.
- */
-#if defined(DEBUG_ON_AMAZON) && DEBUG_ON_AMAZON
- char g_pFakeRegisters[0x50];
-
- #undef DEBUG_WRITE_REGISTER
-
- #undef DANUBE_LED
- #define DANUBE_LED g_pFakeRegisters
-
- #undef port_reserve_pin
- #undef port_free_pin
- #undef port_set_altsel0
- #undef port_clear_altsel0
- #undef port_set_altsel1
- #undef port_clear_altsel1
- #undef port_set_dir_out
-
- #define port_reserve_pin amazon_port_reserve_pin
- #define port_free_pin amazon_port_free_pin
- #define port_set_altsel0 amazon_port_set_altsel0
- #define port_clear_altsel0 amazon_port_clear_altsel0
- #define port_set_altsel1 amazon_port_set_altsel1
- #define port_clear_altsel1 amazon_port_clear_altsel1
- #define port_set_dir_out amazon_port_set_dir_out
-#endif // defined(DEBUG_ON_AMAZON) && DEBUG_ON_AMAZON
-
-
-/*
- * File Operations
- */
-static int led_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
-static int led_open(struct inode *, struct file *);
-static int led_release(struct inode *, struct file *);
-
-/*
- * Software Update LED
- */
-static inline int update_led(void);
-
-/*
- * LED Configuration Functions
- */
-static inline unsigned int set_update_source(unsigned int, unsigned long, unsigned long);
-static inline unsigned int set_blink_in_batch(unsigned int, unsigned long, unsigned long);
-static inline unsigned int set_data_clock_edge(unsigned int, unsigned long);
-static inline unsigned int set_update_clock(unsigned int, unsigned long, unsigned long);
-static inline unsigned int set_store_mode(unsigned int, unsigned long);
-static inline unsigned int set_shift_clock(unsigned int, unsigned long);
-static inline unsigned int set_data_offset(unsigned int, unsigned long);
-static inline unsigned int set_number_of_enabled_led(unsigned int, unsigned long);
-static inline unsigned int set_data_in_batch(unsigned int, unsigned long, unsigned long);
-static inline unsigned int set_access_right(unsigned int, unsigned long, unsigned long);
-
-/*
- * PMU Operation
- */
-static inline void enable_led(void);
-static inline void disable_led(void);
-
-/*
- * GPIO Setup & Release
- */
-static inline int setup_gpio_port(unsigned long);
-static inline void release_gpio_port(unsigned long);
-
-/*
- * GPT Setup & Release
- */
-static inline int setup_gpt(int, unsigned long);
-static inline void release_gpt(int);
-
-/*
- * Turn On/Off LED
- */
-static inline int turn_on_led(unsigned long);
-static inline void turn_off_led(unsigned long);
-
-
-static struct semaphore led_sem;
-
-static struct file_operations led_fops = {
- owner: THIS_MODULE,
- ioctl: led_ioctl,
- open: led_open,
- release: led_release
-};
-
-static struct miscdevice led_miscdev = {
- LED_MINOR,
- "led",
- &led_fops,
- NULL,
- NULL,
- NULL
-};
-
-static unsigned long gpt_on = 0;
-static unsigned long gpt_freq = 0;
-
-static unsigned long adsl_on = 0;
-static unsigned long f_led_on = 0;
-
-static int module_id;
-
-
-static int
-led_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
- int ret = -EINVAL;
- struct led_config_param param;
-
- switch ( cmd )
- {
- case LED_CONFIG:
- copy_from_user(¶m, (char*)arg, sizeof(param));
- ret = danube_led_config(¶m);
- break;
- }
-
- return ret;
-}
-
-static int
-led_open (struct inode *inode, struct file *file)
-{
- return 0;
-}