-/*
-* Data Type Used to Call ioctl
-*/
-struct led_config_param {
- unsigned long operation_mask; // Select operations to be performed
- unsigned long led; // LED to change update source (LED or ADSL)
- unsigned long source; // Corresponding update source (LED or ADSL)
- unsigned long blink_mask; // LEDs to set blink mode
- unsigned long blink; // Set to blink mode or normal mode
- unsigned long update_clock; // Select the source of update clock
- unsigned long fpid; // If FPI is the source of update clock, set the divider
- // else if GPT is the source, set the frequency
- unsigned long store_mode; // Set clock mode or single pulse mode for store signal
- unsigned long fpis; // FPI is the source of shift clock, set the divider
- unsigned long data_offset; // Set cycles to be inserted before data is transmitted
- unsigned long number_of_enabled_led; // Total number of LED to be enabled
- unsigned long data_mask; // LEDs to set value
- unsigned long data; // Corresponding value
- unsigned long mips0_access_mask; // LEDs to set access right
- unsigned long mips0_access; // 1: the corresponding data is output from MIPS0, 0: MIPS1
- unsigned long f_data_clock_on_rising; // 1: data clock on rising edge, 0: data clock on falling edge
-};
-
-
-extern int danube_led_set_blink(unsigned int, unsigned int);
-extern int danube_led_set_data(unsigned int, unsigned int);
-extern int danube_led_config(struct led_config_param *);
-
-#define DATA_CLOCKING_EDGE FALLING_EDGE
-#define RISING_EDGE 0
-#define FALLING_EDGE 1
-
-#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
-
-#if LED_SH_DIR
- #define LED_SH_DIR_SETUP danube_port_set_dir_out
-#else
- #define LED_SH_DIR_SETUP danube_port_clear_dir_out
-#endif
-#if LED_SH_ALTSEL0
- #define LED_SH_ALTSEL0_SETUP danube_port_set_altsel0
-#else
- #define LED_SH_ALTSEL0_SETUP danube_port_clear_altsel0
-#endif
-#if LED_SH_ALTSEL1
- #define LED_SH_ALTSEL1_SETUP danube_port_set_altsel1
-#else
- #define LED_SH_ALTSEL1_SETUP danube_port_clear_altsel1
-#endif
-#if LED_SH_OPENDRAIN
- #define LED_SH_OPENDRAIN_SETUP danube_port_set_open_drain
-#else
- #define LED_SH_OPENDRAIN_SETUP danube_port_clear_open_drain
-#endif
-
-#if LED_D_DIR
- #define LED_D_DIR_SETUP danube_port_set_dir_out
-#else
- #define LED_D_DIR_SETUP danube_port_clear_dir_out
-#endif
-#if LED_D_ALTSEL0
- #define LED_D_ALTSEL0_SETUP danube_port_set_altsel0
-#else
- #define LED_D_ALTSEL0_SETUP danube_port_clear_altsel0
-#endif
-#if LED_D_ALTSEL1
- #define LED_D_ALTSEL1_SETUP danube_port_set_altsel1
-#else
- #define LED_D_ALTSEL1_SETUP danube_port_clear_altsel1
-#endif
-#if LED_D_OPENDRAIN
- #define LED_D_OPENDRAIN_SETUP danube_port_set_open_drain
-#else
- #define LED_D_OPENDRAIN_SETUP danube_port_clear_open_drain
-#endif
-
-#if LED_ST_DIR
- #define LED_ST_DIR_SETUP danube_port_set_dir_out
-#else
- #define LED_ST_DIR_SETUP danube_port_clear_dir_out
-#endif
-#if LED_ST_ALTSEL0
- #define LED_ST_ALTSEL0_SETUP danube_port_set_altsel0
-#else
- #define LED_ST_ALTSEL0_SETUP danube_port_clear_altsel0
-#endif
-#if LED_ST_ALTSEL1
- #define LED_ST_ALTSEL1_SETUP danube_port_set_altsel1
-#else
- #define LED_ST_ALTSEL1_SETUP danube_port_clear_altsel1
-#endif
-#if LED_ST_OPENDRAIN
- #define LED_ST_OPENDRAIN_SETUP danube_port_set_open_drain
-#else
- #define LED_ST_OPENDRAIN_SETUP danube_port_clear_open_drain
-#endif
-
-#if LED_ADSL0_DIR
- #define LED_ADSL0_DIR_SETUP danube_port_set_dir_out
-#else
- #define LED_ADSL0_DIR_SETUP danube_port_clear_dir_out
-#endif
-#if LED_ADSL0_ALTSEL0
- #define LED_ADSL0_ALTSEL0_SETUP danube_port_set_altsel0
-#else
- #define LED_ADSL0_ALTSEL0_SETUP danube_port_clear_altsel0
-#endif
-#if LED_ADSL0_ALTSEL1
- #define LED_ADSL0_ALTSEL1_SETUP danube_port_set_altsel1
-#else
- #define LED_ADSL0_ALTSEL1_SETUP danube_port_clear_altsel1
-#endif
-#if LED_ADSL0_OPENDRAIN
- #define LED_ADSL0_OPENDRAIN_SETUP danube_port_set_open_drain
-#else
- #define LED_ADSL0_OPENDRAIN_SETUP danube_port_clear_open_drain
-#endif
-
-#if LED_ADSL1_DIR
- #define LED_ADSL1_DIR_SETUP danube_port_set_dir_out
-#else
- #define LED_ADSL1_DIR_SETUP danube_port_clear_dir_out
-#endif
-#if LED_ADSL1_ALTSEL0
- #define LED_ADSL1_ALTSEL0_SETUP danube_port_set_altsel0
-#else
- #define LED_ADSL1_ALTSEL0_SETUP danube_port_clear_altsel0
-#endif
-#if LED_ADSL1_ALTSEL1
- #define LED_ADSL1_ALTSEL1_SETUP danube_port_set_altsel1
-#else
- #define LED_ADSL1_ALTSEL1_SETUP danube_port_clear_altsel1
-#endif
-#if LED_ADSL1_OPENDRAIN
- #define LED_ADSL1_OPENDRAIN_SETUP danube_port_set_open_drain
-#else
- #define LED_ADSL1_OPENDRAIN_SETUP danube_port_clear_open_drain
-#endif
-
-#define SET_BITS(x, msb, lsb, value) (((x) & ~(((1 << ((msb) + 1)) - 1) ^ ((1 << (lsb)) - 1))) | (((value) & ((1 << (1 + (msb) - (lsb))) - 1)) << (lsb)))
-
-static struct semaphore led_sem;
-
-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 inline int
-update_led (void)
-{
- int i, j;
-
- /*
- * GPT2 or FPID is the clock to update LEDs automatically.
- */
- if (readl(DANUBE_LED_CON1) >> 30)
- return 0;
-
- /*
- * Check the status to prevent conflict of two consecutive update
- */
- for ( i = 100000; i != 0; i -= j / 16 )
- {
- down(&led_sem);
- if (!(readl(DANUBE_LED_CON0) & LED_CON0_SWU))
- {
- *DANUBE_LED_CON0 |= 1 << 31;
- up(&led_sem);
- return 0;
- }
- else
- up(&led_sem);
- for ( j = 0; j < 1000 * 16; j++ );
- }
-
- return -EBUSY;
-}
-
-static inline unsigned int
-set_update_source (unsigned int reg, unsigned long led, unsigned long source)
-{
- return (reg & ~((led & 0x03) << 24)) | ((source & 0x03) << 24);
-}
-
-static inline unsigned int
-set_blink_in_batch (unsigned int reg, unsigned long mask, unsigned long blink)
-{
- return (reg & (~(mask & 0x00FFFFFF) & 0x87FFFFFF)) | (blink & 0x00FFFFFF);
-}
-
-static inline unsigned int
-set_data_clock_edge (unsigned int reg, unsigned long f_on_rising_edge)
-{
- return f_on_rising_edge ? (reg & ~(1 << 26)) : (reg | (1 << 26));
-}
-
-static inline unsigned int
-set_update_clock (unsigned int reg, unsigned long clock, unsigned long fpid)
-{
- switch ( clock )
- {
- case 0:
- reg &= ~0xC0000000;
- break;
-
- case 1:
- reg = (reg & ~0xC0000000) | 0x40000000;
- break;
-
- case 2:
- reg = (reg & ~0xCF800000) | 0x80000000 | ((fpid & 0x1F) << 23);
- break;
- }
-
- return reg;
-}