-/*
- * Description:
- * Set the clock cycle offset before data is transmitted to LED_D pin.
- * Input:
- * reg --- u32, the original register value going to be modified.
- * offset --- unsigned long, the number of clock cycles would be inserted
- * before data is transmitted to LED_D pin. Zero means no cycle
- * inserted.
- * Output:
- * u32 --- The updated register value.
- */
-static inline u32 set_data_offset(u32 reg, unsigned long offset)
-{
- return SET_BITS(reg, 19, 18, offset);
-}
-
-/*
- * Description:
- * Enable or disable LEDs.
- * Input:
- * reg --- u32, the original register value going to be modified.
- * number --- unsigned long, the number of LED to be enabled. This field
- * could 0, 8, 16 or 24. Zero means disable all LEDs.
- * Output:
- * u32 --- The updated register value.
- */
-static inline u32 set_number_of_enabled_led(u32 reg, unsigned long number)
-{
- u32 bit_mask;
-
- bit_mask = number > 16 ? 0x07 : (number > 8 ? 0x03 : (number ? 0x01 : 0x00));
- return (reg & ~0x07) | bit_mask;
-}
-
-/*
- * Description:
- * Turn on/off LEDs.
- * Input:
- * reg --- u32, the original register value going to be modified.
- * mask --- unsigned long, if the corresponding bit is set, the data value
- * is valid, else the data value is invalid.
- * data --- unsigned long, if the corresponding bit is set, the LED should
- * be on, else be off.
- * Output:
- * u32 --- The updated register value.
- */
-static inline u32 set_data_in_batch(u32 reg, unsigned long mask, unsigned long data)
-{
- return (reg & ~(mask & 0x00FFFFFF)) | (data & 0x00FFFFFF);
-}
-
-static inline u32 set_access_right(u32 reg, unsigned long mask, unsigned long ar)
-{
- return (reg & ~(mask & 0x00FFFFFF)) | (~ar & mask);
-}
-
-/*
- * Description:
- * Enable LED control module.
- * Input:
- * none
- * Output:
- * none
- */
-static inline void enable_led(void)
-{
-#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON
- /* Activate LED module in PMU. */
- int i = 1000000;
-
- *(unsigned long *)0xBF10201C &= ~(1 << 11);
- while ( --i && (*(unsigned long *)0xBF102020 & (1 << 11)) );
- if ( !i )
- panic("Activating LED in PMU failed!");
-#endif
-}
-
-/*
- * Description:
- * Disable LED control module.
- * Input:
- * none
- * Output:
- * none
- */
-static inline void disable_led(void)
-{
-#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON
- /* Inactivating LED module in PMU. */
- *(unsigned long *)0xBF10201C |= 1 << 11;
-#endif
-}
-
-/*
- * Description:
- * If LEDs are enabled, GPIO must be setup to enable LED pins.
- * Input:
- * none
- * Output:
- * int --- 0: Success
- * else: Error Code
- */
-static inline int setup_gpio_port(unsigned long adsl)
-{
-#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON
- int ret = 0;
-
- #if defined(DEBUG_WRITE_REGISTER) && DEBUG_WRITE_REGISTER
- if ( adsl )
- {
- *(unsigned long *)0xBE100B18 |= 0x30;
- *(unsigned long *)0xBE100B1C |= 0x20;
- *(unsigned long *)0xBE100B1C &= ~0x10;
- *(unsigned long *)0xBE100B20 |= 0x30;
- *(unsigned long *)0xBE100B24 |= 0x30;
- }
- else
- {
- *(unsigned long *)0xBE100B18 |= 0x70;
- *(unsigned long *)0xBE100B1C |= 0x70;
- *(unsigned long *)0xBE100B20 &= ~0x70;
- *(unsigned long *)0xBE100B24 |= 0x70;
- }
- #else
-
- /*
- * Reserve all pins before config them.
- */
- if ( adsl )
- {
- ret |= port_reserve_pin(LED_ADSL0_PORT, LED_ADSL0_PIN, module_id);
- ret |= port_reserve_pin(LED_ADSL1_PORT, LED_ADSL1_PIN, module_id);
- }
- else
- {
- ret |= port_reserve_pin(LED_ST_PORT, LED_ST_PIN, module_id);
- ret |= port_reserve_pin(LED_D_PORT, LED_D_PIN, module_id);
- ret |= port_reserve_pin(LED_SH_PORT, LED_SH_PIN, module_id);
- }
- if ( ret )
- {
- release_gpio_port(adsl);
- return ret; // Should be -EBUSY
- }
-
- if ( adsl )
- {
- LED_ADSL0_ALTSEL0_SETUP(LED_ADSL0_PORT, LED_ADSL0_PIN, module_id);
- LED_ADSL0_ALTSEL1_SETUP(LED_ADSL0_PORT, LED_ADSL0_PIN, module_id);
- LED_ADSL0_DIR_SETUP(LED_ADSL0_PORT, LED_ADSL0_PIN, module_id);
- LED_ADSL0_OPENDRAIN_SETUP(LED_ADSL0_PORT, LED_ADSL0_PIN, module_id);
-
- LED_ADSL1_ALTSEL0_SETUP(LED_ADSL1_PORT, LED_ADSL1_PIN, module_id);
- LED_ADSL1_ALTSEL1_SETUP(LED_ADSL1_PORT, LED_ADSL1_PIN, module_id);
- LED_ADSL1_DIR_SETUP(LED_ADSL1_PORT, LED_ADSL1_PIN, module_id);
- LED_ADSL1_OPENDRAIN_SETUP(LED_ADSL1_PORT, LED_ADSL1_PIN, module_id);
- }
- else
- {
- /*
- * Set LED_ST
- * I don't check the return value, because I'm sure the value is valid
- * and the pins are reserved already.
- */
- LED_ST_ALTSEL0_SETUP(LED_ST_PORT, LED_ST_PIN, module_id);
- LED_ST_ALTSEL1_SETUP(LED_ST_PORT, LED_ST_PIN, module_id);
- LED_ST_DIR_SETUP(LED_ST_PORT, LED_ST_PIN, module_id);
- LED_ST_OPENDRAIN_SETUP(LED_ST_PORT, LED_ST_PIN, module_id);
-
- /*
- * Set LED_D
- */
- LED_D_ALTSEL0_SETUP(LED_D_PORT, LED_D_PIN, module_id);
- LED_D_ALTSEL1_SETUP(LED_D_PORT, LED_D_PIN, module_id);
- LED_D_DIR_SETUP(LED_D_PORT, LED_D_PIN, module_id);
- LED_D_OPENDRAIN_SETUP(LED_D_PORT, LED_D_PIN, module_id);
-
- /*
- * Set LED_SH
- */
- LED_SH_ALTSEL0_SETUP(LED_SH_PORT, LED_SH_PIN, module_id);
- LED_SH_ALTSEL1_SETUP(LED_SH_PORT, LED_SH_PIN, module_id);
- LED_SH_DIR_SETUP(LED_SH_PORT, LED_SH_PIN, module_id);
- LED_SH_OPENDRAIN_SETUP(LED_SH_PORT, LED_SH_PIN, module_id);
- }
- #endif
-#endif
-
- return 0;
-}
-
-/*
- * Description:
- * If LEDs are all disabled, GPIO must be released so that other application
- * could reuse it.
- * Input:
- * none
- * Output:
- * none
- */
-static inline void release_gpio_port(unsigned long adsl)
-{
-#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON
- #if !defined(DEBUG_WRITE_REGISTER) || !DEBUG_WRITE_REGISTER
- if ( adsl )
- {
- port_free_pin(LED_ADSL0_PORT, LED_ADSL0_PIN, module_id);
- port_free_pin(LED_ADSL1_PORT, LED_ADSL1_PIN, module_id);
- }
- else
- {
- port_free_pin(LED_ST_PORT, LED_ST_PIN, module_id);
- port_free_pin(LED_D_PORT, LED_D_PIN, module_id);
- port_free_pin(LED_SH_PORT, LED_SH_PIN, module_id);
- }
- #endif
-#endif
-}
-
-/*
- * Description:
- * If shifter or update select GPT as clock source, this function would be
- * invoked to setup corresponding GPT module.
- * Attention please, this function is not working since the GPTU driver is
- * not ready.
- * Input:
- * timer --- int, index of timer.
- * freq --- unsigned long, frequency of timer (0.001Hz). This value will be
- * rounded off to nearest possible value.
- * Output:
- * int --- 0: Success
- * else: Error Code
- */
-static inline int setup_gpt(int timer, unsigned long freq)
-{
- int ret;
-
-#if 0
- timer = TIMER(timer, 0);
-#else
- timer = TIMER(timer, 1); // 2B
-#endif
-
-#if 0
- ret = set_timer(timer, freq, 1, 0, TIMER_FLAG_NO_HANDLE, 0, 0);
-#else
- ret = request_timer(timer,
- TIMER_FLAG_SYNC
- | TIMER_FLAG_16BIT
- | TIMER_FLAG_INT_SRC
- | TIMER_FLAG_CYCLIC | TIMER_FLAG_COUNTER | TIMER_FLAG_DOWN
- | TIMER_FLAG_ANY_EDGE
- | TIMER_FLAG_NO_HANDLE,
- 8000000 / freq,
- 0,
- 0);
-
-#endif
-// printk("setup_gpt: timer = %d, freq = %d, return = %d\n", timer, freq, ret);
- if ( !ret )
- {
- ret = start_timer(timer, 0);
- if ( ret )
- free_timer(timer);
- }
-
- return ret;
-}
-
-/*
- * Description:
- * If shifter or update select other clock source, allocated GPT must be
- * released so that other application can use it.
- * Attention please, this function is not working since the GPTU driver is
- * not ready.
- * Input:
- * none
- * Output:
- * none
- */
-static inline void release_gpt(int timer)
-{
-#if 0
- timer = TIMER(timer, 0);
-#else
- timer = TIMER(timer, 1);
-#endif
- stop_timer(timer);
- free_timer(timer);
-}
-
-static inline int turn_on_led(unsigned long adsl)
-{
- int ret;
-
- ret = setup_gpio_port(adsl);
- if ( ret )
- return ret;
-
- enable_led();
-
- return 0;
-}
-
-static inline void turn_off_led(unsigned long adsl)
-{
- release_gpio_port(adsl);
- disable_led();
-}
-
-
-/*
- * ####################################
- * Global Function
- * ####################################
- */
-
-/*
- * Description:
- * Define which of the LEDs should change its value based on the US pulse.
- * Input:
- * led --- unsigned int, index of the LED to be set.
- * blink --- unsigned int, zero means normal mode, and non-zero means blink
- * mode.
- * Output:
- * int --- 0: Success
- * else: Error Code
- */
-int danube_led_set_blink(unsigned int led, unsigned int blink)