Changeset 9732


Ignore:
Timestamp:
2007-12-13T21:29:22+01:00 (9 years ago)
Author:
blogic
Message:

danube led cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/target/linux/danube/files/drivers/char/danube_led.c

    r9731 r9732  
    245245 */ 
    246246#define DANUBE_LED                      (KSEG1 + 0x1E100BB0) 
    247 #define DANUBE_LED_CON0                 ((volatile u32*)(DANUBE_LED + 0x0000)) 
    248 #define DANUBE_LED_CON1                 ((volatile u32*)(DANUBE_LED + 0x0004)) 
    249 #define DANUBE_LED_CPU0                 ((volatile u32*)(DANUBE_LED + 0x0008)) 
    250 #define DANUBE_LED_CPU1                 ((volatile u32*)(DANUBE_LED + 0x000C)) 
    251 #define DANUBE_LED_AR                   ((volatile u32*)(DANUBE_LED + 0x0010)) 
     247#define DANUBE_LED_CON0                 ((volatile unsigned int*)(DANUBE_LED + 0x0000)) 
     248#define DANUBE_LED_CON1                 ((volatile unsigned int*)(DANUBE_LED + 0x0004)) 
     249#define DANUBE_LED_CPU0                 ((volatile unsigned int*)(DANUBE_LED + 0x0008)) 
     250#define DANUBE_LED_CPU1                 ((volatile unsigned int*)(DANUBE_LED + 0x000C)) 
     251#define DANUBE_LED_AR                   ((volatile unsigned int*)(DANUBE_LED + 0x0010)) 
    252252 
    253253/* 
     
    293293#define LED_AR_DEFAULT_VALUE            0x00000000 
    294294 
    295  
    296 /* 
    297  * #################################### 
    298  * Preparation of Debug on Amazon Chip 
    299  * #################################### 
    300  */ 
    301  
    302295/* 
    303296 *  If try module on Amazon chip, prepare some tricks to prevent invalid memory write. 
     
    330323 
    331324/* 
    332  * #################################### 
    333  *             Declaration 
    334  * #################################### 
    335  */ 
    336  
    337 /* 
    338325 *  File Operations 
    339326 */ 
     
    350337 *  LED Configuration Functions 
    351338 */ 
    352 static inline u32 set_update_source(u32, unsigned long, unsigned long); 
    353 static inline u32 set_blink_in_batch(u32, unsigned long, unsigned long); 
    354 static inline u32 set_data_clock_edge(u32, unsigned long); 
    355 static inline u32 set_update_clock(u32, unsigned long, unsigned long); 
    356 static inline u32 set_store_mode(u32, unsigned long); 
    357 static inline u32 set_shift_clock(u32, unsigned long); 
    358 static inline u32 set_data_offset(u32, unsigned long); 
    359 static inline u32 set_number_of_enabled_led(u32, unsigned long); 
    360 static inline u32 set_data_in_batch(u32, unsigned long, unsigned long); 
    361 static inline u32 set_access_right(u32, unsigned long, unsigned long); 
     339static inline unsigned int set_update_source(unsigned int, unsigned long, unsigned long); 
     340static inline unsigned int set_blink_in_batch(unsigned int, unsigned long, unsigned long); 
     341static inline unsigned int set_data_clock_edge(unsigned int, unsigned long); 
     342static inline unsigned int set_update_clock(unsigned int, unsigned long, unsigned long); 
     343static inline unsigned int set_store_mode(unsigned int, unsigned long); 
     344static inline unsigned int set_shift_clock(unsigned int, unsigned long); 
     345static inline unsigned int set_data_offset(unsigned int, unsigned long); 
     346static inline unsigned int set_number_of_enabled_led(unsigned int, unsigned long); 
     347static inline unsigned int set_data_in_batch(unsigned int, unsigned long, unsigned long); 
     348static inline unsigned int set_access_right(unsigned int, unsigned long, unsigned long); 
    362349 
    363350/* 
     
    385372static inline void turn_off_led(unsigned long); 
    386373 
    387  
    388 /* 
    389  * #################################### 
    390  *            Local Variable 
    391  * #################################### 
    392  */ 
    393374 
    394375static struct semaphore led_sem; 
     
    419400 
    420401 
    421 /* 
    422  * #################################### 
    423  *           Global Variable 
    424  * #################################### 
    425  */ 
    426  
    427  
    428 /* 
    429  * #################################### 
    430  *            Local Function 
    431  * #################################### 
    432  */ 
    433  
    434 static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 
     402static int 
     403led_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 
    435404{ 
    436405    int ret = -EINVAL; 
     
    448417} 
    449418 
    450 static int led_open(struct inode *inode, struct file *file) 
     419static int 
     420led_open (struct inode *inode, struct file *file) 
    451421{ 
    452422    return 0; 
    453423} 
    454424 
    455 static int led_release(struct inode *inode, struct file *file) 
     425static int 
     426led_release (struct inode *inode, struct file *file) 
    456427{ 
    457428    return 0; 
    458429} 
    459430 
    460 /* 
    461  *  Description: 
    462  *    Update LEDs with data stored in register. 
    463  *  Input: 
    464  *    none 
    465  *  Output: 
    466  *    int --- 0:    Success 
    467  *            else: Error Code 
    468  */ 
    469 static inline int update_led(void) 
     431static inline int 
     432update_led (void) 
    470433{ 
    471434    int i, j; 
     
    497460} 
    498461 
    499 /* 
    500  *  Description: 
    501  *    Select update source for LED bit 0 and bit 1. 
    502  *  Input: 
    503  *    reg    --- u32, the original register value going to be modified. 
    504  *    led    --- unsigned long, bit 0 stands for LED 0, and bit 1 stands for 
    505  *               LED 1. If the bit is set, the source value is valid, else 
    506  *               the source value is invalid. 
    507  *    source --- unsigned long, bit 0 stands for LED 0, and bit 1 stands for 
    508  *               LED 1. If the corresponding is cleared, LED is updated with 
    509  *               value in data register, else LED is updated with ARC module. 
    510  *  Output: 
    511  *    u32    --- The updated register value. 
    512  */ 
    513 static inline u32 set_update_source(u32 reg, unsigned long led, unsigned long source) 
     462static inline unsigned int 
     463set_update_source (unsigned int reg, unsigned long led, unsigned long source) 
    514464{ 
    515465    return (reg & ~((led & 0x03) << 24)) | ((source & 0x03) << 24); 
    516466} 
    517467 
    518 /* 
    519  *  Description: 
    520  *    Define which of the LEDs should change their value based on the US pulse. 
    521  *  Input: 
    522  *    reg    --- u32, the original register value going to be modified. 
    523  *    mask   --- unsigned long, if the corresponding bit is set, the blink value 
    524  *               is valid, else the blink value is invalid. 
    525  *    blink  --- unsigned long, if the corresponding bit is set, the LED should 
    526  *               change its value based on the US pulse. 
    527  *  Output: 
    528  *    u32    --- The updated register value. 
    529  */ 
    530 static inline u32 set_blink_in_batch(u32 reg, unsigned long mask, unsigned long blink) 
     468static inline unsigned int 
     469set_blink_in_batch (unsigned int reg, unsigned long mask, unsigned long blink) 
    531470{ 
    532471    return (reg & (~(mask & 0x00FFFFFF) & 0x87FFFFFF)) | (blink & 0x00FFFFFF); 
    533472} 
    534473 
    535 static inline u32 set_data_clock_edge(u32 reg, unsigned long f_on_rising_edge) 
     474static inline unsigned int 
     475set_data_clock_edge (unsigned int reg, unsigned long f_on_rising_edge) 
    536476{ 
    537477    return f_on_rising_edge ? (reg & ~(1 << 26)) : (reg | (1 << 26)); 
    538478} 
    539479 
    540 /* 
    541  *  Description: 
    542  *    Select the clock source for US pulse. 
    543  *  Input: 
    544  *    reg    --- u32, the original register value going to be modified. 
    545  *    clock  --- unsigned long, there 3 available values: 
    546  *               0x00 - use software update bit (SWU) as source. 
    547  *               0x01 - use GPT2 as clock source. 
    548  *               0x02 - use FPI as clock source. 
    549  *    fpid   --- unsigned long, if FPI is selected as clock source, this field 
    550  *               specify the divider. Please refer to specification for detail 
    551  *               description. 
    552  *  Output: 
    553  *    u32    --- The updated register value. 
    554  */ 
    555 static inline u32 set_update_clock(u32 reg, unsigned long clock, unsigned long fpid) 
     480static inline unsigned int 
     481set_update_clock (unsigned int reg, unsigned long clock, unsigned long fpid) 
    556482{ 
    557483    switch ( clock ) 
     
    564490} 
    565491 
    566 /* 
    567  *  Description: 
    568  *    Set the behavior of the LED_ST (shift register) signal. 
    569  *  Input: 
    570  *    reg    --- u32, the original register value going to be modified. 
    571  *    mode   --- unsigned long, there 2 available values: 
    572  *               zero     - LED controller generate single pulse. 
    573  *               non-zero - LED controller generate inverted shift clock. 
    574  *  Output: 
    575  *    u32    --- The updated register value. 
    576  */ 
    577 static inline u32 set_store_mode(u32 reg, unsigned long mode) 
     492static inline unsigned int 
     493set_store_mode (unsigned int reg, unsigned long mode) 
    578494{ 
    579495    return mode ? (reg | (1 << 28)) : (reg & ~(1 << 28)); 
    580496} 
    581497 
    582 /* 
    583  *  Description: 
    584  *    Select the clock source for shift clock LED_SH. 
    585  *  Input: 
    586  *    reg    --- u32, the original register value going to be modified. 
    587  *    fpis   --- unsigned long, if FPI is selected as clock source, this field 
    588  *               specify the divider. Please refer to specification for detail 
    589  *               description. 
    590  *  Output: 
    591  *    u32    --- The updated register value. 
    592  */ 
    593 static inline u32 set_shift_clock(u32 reg, unsigned long fpis) 
     498static inline 
     499unsigned int set_shift_clock (unsigned int reg, unsigned long fpis) 
    594500{ 
    595501    return SET_BITS(reg, 21, 20, fpis); 
    596502} 
    597503 
    598 /* 
    599  *  Description: 
    600  *    Set the clock cycle offset before data is transmitted to LED_D pin. 
    601  *  Input: 
    602  *    reg    --- u32, the original register value going to be modified. 
    603  *    offset --- unsigned long, the number of clock cycles would be inserted 
    604  *               before data is transmitted to LED_D pin. Zero means no cycle 
    605  *               inserted. 
    606  *  Output: 
    607  *    u32    --- The updated register value. 
    608  */ 
    609 static inline u32 set_data_offset(u32 reg, unsigned long offset) 
     504static inline 
     505unsigned int set_data_offset (unsigned int reg, unsigned long offset) 
    610506{ 
    611507    return SET_BITS(reg, 19, 18, offset); 
    612508} 
    613509 
    614 /* 
    615  *  Description: 
    616  *    Enable or disable LEDs. 
    617  *  Input: 
    618  *    reg    --- u32, the original register value going to be modified. 
    619  *    number --- unsigned long, the number of LED to be enabled. This field 
    620  *               could 0, 8, 16 or 24. Zero means disable all LEDs. 
    621  *  Output: 
    622  *    u32    --- The updated register value. 
    623  */ 
    624 static inline u32 set_number_of_enabled_led(u32 reg, unsigned long number) 
    625 { 
    626     u32 bit_mask; 
     510static inline 
     511unsigned int set_number_of_enabled_led (unsigned int reg, unsigned long number) 
     512{ 
     513    unsigned int bit_mask; 
    627514 
    628515    bit_mask = number > 16 ? 0x07 : (number > 8 ? 0x03 : (number ? 0x01 : 0x00)); 
     
    630517} 
    631518 
    632 /* 
    633  *  Description: 
    634  *    Turn on/off LEDs. 
    635  *  Input: 
    636  *    reg    --- u32, the original register value going to be modified. 
    637  *    mask   --- unsigned long, if the corresponding bit is set, the data value 
    638  *               is valid, else the data value is invalid. 
    639  *    data   --- unsigned long, if the corresponding bit is set, the LED should 
    640  *               be on, else be off. 
    641  *  Output: 
    642  *    u32    --- The updated register value. 
    643  */ 
    644 static inline u32 set_data_in_batch(u32 reg, unsigned long mask, unsigned long data) 
     519static inline unsigned int 
     520set_data_in_batch (unsigned int reg, unsigned long mask, unsigned long data) 
    645521{ 
    646522    return (reg & ~(mask & 0x00FFFFFF)) | (data & 0x00FFFFFF); 
    647523} 
    648524 
    649 static inline u32 set_access_right(u32 reg, unsigned long mask, unsigned long ar) 
     525static inline unsigned int 
     526set_access_right (unsigned int reg, unsigned long mask, unsigned long ar) 
    650527{ 
    651528    return (reg & ~(mask & 0x00FFFFFF)) | (~ar & mask); 
    652529} 
    653530 
    654 /* 
    655  *  Description: 
    656  *    Enable LED control module. 
    657  *  Input: 
    658  *    none 
    659  *  Output: 
    660  *    none 
    661  */ 
    662 static inline void enable_led(void) 
     531static inline void 
     532enable_led (void) 
    663533{ 
    664534#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON 
     
    673543} 
    674544 
    675 /* 
    676  *  Description: 
    677  *    Disable LED control module. 
    678  *  Input: 
    679  *    none 
    680  *  Output: 
    681  *    none 
    682  */ 
    683 static inline void disable_led(void) 
     545static inline void 
     546disable_led (void) 
    684547{ 
    685548#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON 
     
    689552} 
    690553 
    691 /* 
    692  *  Description: 
    693  *    If LEDs are enabled, GPIO must be setup to enable LED pins. 
    694  *  Input: 
    695  *    none 
    696  *  Output: 
    697  *    int --- 0:    Success 
    698  *            else: Error Code 
    699  */ 
    700 static inline int setup_gpio_port(unsigned long adsl) 
     554static inline int 
     555setup_gpio_port (unsigned long adsl) 
    701556{ 
    702557#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON 
     
    787642} 
    788643 
    789 /* 
    790  *  Description: 
    791  *    If LEDs are all disabled, GPIO must be released so that other application 
    792  *    could reuse it. 
    793  *  Input: 
    794  *    none 
    795  *  Output: 
    796  *    none 
    797  */ 
    798 static inline void release_gpio_port(unsigned long adsl) 
     644static inline void 
     645release_gpio_port (unsigned long adsl) 
    799646{ 
    800647#if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON 
     
    815662} 
    816663 
    817 /* 
    818  *  Description: 
    819  *    If shifter or update select GPT as clock source, this function would be 
    820  *    invoked to setup corresponding GPT module. 
    821  *    Attention please, this function is not working since the GPTU driver is 
    822  *    not ready. 
    823  *  Input: 
    824  *    timer  --- int, index of timer. 
    825  *    freq   --- unsigned long, frequency of timer (0.001Hz). This value will be 
    826  *               rounded off to nearest possible value. 
    827  *  Output: 
    828  *    int --- 0:    Success 
    829  *            else: Error Code 
    830  */ 
    831 static inline int setup_gpt(int timer, unsigned long freq) 
     664static inline int 
     665setup_gpt (int timer, unsigned long freq) 
    832666{ 
    833667    int ret; 
    834668 
    835 #if 0 
    836     timer = TIMER(timer, 0); 
    837 #else 
    838     timer = TIMER(timer, 1);    //  2B 
    839 #endif 
    840  
    841 #if 0 
    842     ret  = set_timer(timer, freq, 1, 0, TIMER_FLAG_NO_HANDLE, 0, 0); 
    843 #else 
     669    timer = TIMER(timer, 1); 
     670 
    844671    ret  = request_timer(timer, 
    845672                           TIMER_FLAG_SYNC 
     
    853680                         0); 
    854681 
    855 #endif 
    856 //    printk("setup_gpt: timer = %d, freq = %d, return = %d\n", timer, freq, ret); 
    857682    if ( !ret ) 
    858683    { 
     
    865690} 
    866691 
    867 /* 
    868  *  Description: 
    869  *    If shifter or update select other clock source, allocated GPT must be 
    870  *    released so that other application can use it. 
    871  *    Attention please, this function is not working since the GPTU driver is 
    872  *    not ready. 
    873  *  Input: 
    874  *    none 
    875  *  Output: 
    876  *    none 
    877  */ 
    878 static inline void release_gpt(int timer) 
    879 { 
    880 #if 0 
    881     timer = TIMER(timer, 0); 
    882 #else 
     692static inline void 
     693release_gpt (int timer) 
     694{ 
    883695    timer = TIMER(timer, 1); 
    884 #endif 
    885696    stop_timer(timer); 
    886697    free_timer(timer); 
    887698} 
    888699 
    889 static inline int turn_on_led(unsigned long adsl) 
     700static inline int 
     701turn_on_led (unsigned long adsl) 
    890702{ 
    891703    int ret; 
     
    900712} 
    901713 
    902 static inline void turn_off_led(unsigned long adsl) 
     714static inline void 
     715turn_off_led (unsigned long adsl) 
    903716{ 
    904717    release_gpio_port(adsl); 
     
    907720 
    908721 
    909 /* 
    910  * #################################### 
    911  *           Global Function 
    912  * #################################### 
    913  */ 
    914  
    915 /* 
    916  *  Description: 
    917  *    Define which of the LEDs should change its value based on the US pulse. 
    918  *  Input: 
    919  *    led    --- unsigned int, index of the LED to be set. 
    920  *    blink  --- unsigned int, zero means normal mode, and non-zero means blink 
    921  *               mode. 
    922  *  Output: 
    923  *    int    --- 0:    Success 
    924  *               else: Error Code 
    925  */ 
    926 int danube_led_set_blink(unsigned int led, unsigned int blink) 
    927 { 
    928     u32 bit_mask; 
     722int 
     723danube_led_set_blink (unsigned int led, unsigned int blink) 
     724{ 
     725    unsigned int bit_mask; 
    929726 
    930727    if ( led > 23 ) 
     
    942739} 
    943740 
    944 /* 
    945  *  Description: 
    946  *    Turn on/off LED. 
    947  *  Input: 
    948  *    led    --- unsigned int, index of the LED to be set. 
    949  *    data   --- unsigned int, zero means off, and non-zero means on. 
    950  *  Output: 
    951  *    int    --- 0:    Success 
    952  *               else: Error Code 
    953  */ 
    954 int danube_led_set_data(unsigned int led, unsigned int data) 
     741int 
     742danube_led_set_data (unsigned int led, unsigned int data) 
    955743{ 
    956744    unsigned long f_update; 
    957     u32 bit_mask; 
     745    unsigned int bit_mask; 
    958746 
    959747    if ( led > 23 ) 
     
    972760} 
    973761 
    974 /* 
    975  *  Description: 
    976  *    Config LED controller. 
    977  *  Input: 
    978  *    param   --- struct led_config_param*, the members are listed below: 
    979  *                  operation_mask         - Select operations to be performed 
    980  *                  led                    - LED to change update source 
    981  *                  source                 - Corresponding update source 
    982  *                  blink_mask             - LEDs to set blink mode 
    983  *                  blink                  - Set to blink mode or normal mode 
    984  *                  update_clock           - Select the source of update clock 
    985  *                  fpid                   - If FPI is the source of update clock, set the divider 
    986  *                  store_mode             - Set clock mode or single pulse mode for store signal 
    987  *                  fpis                   - If FPI is the source of shift clock, set the divider 
    988  *                  data_offset            - Set cycles to be inserted before data is transmitted 
    989  *                  number_of_enabled_led  - Total number of LED to be enabled 
    990  *                  data_mask              - LEDs to set value 
    991  *                  data                   - Corresponding value 
    992  *                  mips0_access_mask      - LEDs to set access right 
    993  *                  mips0_access;          - 1: the corresponding data is output from MIPS0, 0: MIPS1 
    994  *                  f_data_clock_on_rising - 1: data clock on rising edge, 0: data clock on falling edge 
    995  *  Output: 
    996  *    int    --- 0:    Success 
    997  *               else: Error Code 
    998  */ 
    999 int danube_led_config(struct led_config_param* param) 
     762int 
     763danube_led_config (struct led_config_param* param) 
    1000764{ 
    1001765    int ret; 
    1002     u32 reg_con0, reg_con1, reg_cpu0, reg_ar; 
    1003     u32 clean_reg_con0, clean_reg_con1, clean_reg_cpu0, clean_reg_ar; 
    1004     u32 f_setup_gpt2; 
    1005     u32 f_software_update; 
    1006     u32 new_led_on, new_adsl_on; 
     766    unsigned int reg_con0, reg_con1, reg_cpu0, reg_ar; 
     767    unsigned int clean_reg_con0, clean_reg_con1, clean_reg_cpu0, clean_reg_ar; 
     768    unsigned int f_setup_gpt2; 
     769    unsigned int f_software_update; 
     770    unsigned int new_led_on, new_adsl_on; 
    1007771 
    1008772    if ( !param ) 
     
    1184948        if ( ret ) 
    1185949        { 
    1186 #if 1 
    1187950            printk("Setup GPIO error!\n"); 
    1188 #endif 
    1189951            goto SETUP_GPIO_ERROR; 
    1190952        } 
     
    1192954        f_led_on = 1; 
    1193955    } 
    1194  
    1195 #if 0 
    1196     if ( (reg_con0 & 0x80000000) ) 
    1197         printk("software update\n"); 
    1198 #endif 
    1199956 
    1200957    /*  Write Register  */ 
     
    1216973#endif 
    1217974 
    1218 #if 0 
    1219   #if !defined(DEBUG_ON_AMAZON) || !DEBUG_ON_AMAZON 
    1220     printk("*0xBF10201C      = 0x%08lX\n", *(unsigned long *)0xBF10201C); 
    1221     printk("*0xBE100B18      = 0x%08lX\n", *(unsigned long *)0xBE100B18); 
    1222     printk("*0xBE100B1C      = 0x%08lX\n", *(unsigned long *)0xBE100B1C); 
    1223     printk("*0xBE100B20      = 0x%08lX\n", *(unsigned long *)0xBE100B20); 
    1224     printk("*0xBE100B24      = 0x%08lX\n", *(unsigned long *)0xBE100B24); 
    1225   #endif 
    1226     printk("*DANUBE_LED_CON0 = 0x%08X\n", *DANUBE_LED_CON0); 
    1227     printk("*DANUBE_LED_CON1 = 0x%08X\n", *DANUBE_LED_CON1); 
    1228     printk("*DANUBE_LED_CPU0 = 0x%08X\n", *DANUBE_LED_CPU0); 
    1229     printk("*DANUBE_LED_CPU1 = 0x%08X\n", *DANUBE_LED_CPU1); 
    1230     printk("*DANUBE_LED_AR   = 0x%08X\n", *DANUBE_LED_AR); 
    1231 #endif 
    1232  
    1233975    up(&led_sem); 
    1234976    return 0; 
     
    1247989 
    1248990 
    1249 /* 
    1250  * #################################### 
    1251  *           Init/Cleanup API 
    1252  * #################################### 
    1253  */ 
    1254  
    1255 /* 
    1256  *  Description: 
    1257  *    register device 
    1258  *  Input: 
    1259  *    none 
    1260  *  Output: 
    1261  *    0    --- successful 
    1262  *    else --- failure, usually it is negative value of error code 
    1263  */ 
    1264 int __init danube_led_init(void) 
     991int __init 
     992danube_led_init (void) 
    1265993{ 
    1266994    int ret; 
     
    13511079} 
    13521080 
    1353 /* 
    1354  *  Description: 
    1355  *    deregister device 
    1356  *  Input: 
    1357  *    none 
    1358  *  Output: 
    1359  *    none 
    1360  */ 
    1361 void __exit danube_led_exit(void) 
     1081void __exit 
     1082danube_led_exit (void) 
    13621083{ 
    13631084    int ret; 
Note: See TracChangeset for help on using the changeset viewer.