static int BuffaloLedGetNextPhase(struct led_t *led_stat) { LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); switch(led_stat->Brighting) { case LED_ON: if((led_stat->ErrorNumber - led_stat->Brighted) > 0) return LED_PHASE_SHORT; else return LED_PHASE_LONG; break; case LED_OFF: LED_TRACE(printk("%s > led_stat->ErrorNumer=%d, led_stat->Brighted=%d\n", __FUNCTION__, led_stat->ErrorNumber, led_stat->Brighted)); if((led_stat->ErrorNumber - led_stat->Brighted) >= 10) return LED_PHASE_10; else return LED_PHASE_1; break; default: return -1; } LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); return -1; }
/************************************************************************ * Name : do_led_tled_test_case * Function : 测试A核三色灯闪烁功能 * Arguments * input : new_state - new status * output : null * * Return : 0 - ok * else - fail * Decription : 不涉及核间通信,只测试A核三色灯闪灯方案 ************************************************************************/ int do_led_tled_test_case(unsigned long new_state) { int ret = LED_ERROR; struct balong_led_device *led = NULL; led = (struct balong_led_device *)platform_get_drvdata(&balong_led_dev); if(!led) { LED_TRACE(LED_DEBUG_LEVEL(ALWAYS),"get balong led device failed.\n"); goto ERRO; } g_arg.new_state = (unsigned char)new_state; g_arg.ctl = MNTN_LED_STATUS_FLUSH; ret = do_led_threecolor_flush(); if(ret) { LED_TRACE(LED_DEBUG_LEVEL(ERROR), "[%s]three color led flush failed, ret = %d!\n", __FUNCTION__, ret); return ret; } return ret; ERRO: return ret; }
/************************************************************************ * Name : led_test_case_005 * Function : * Arguments * input : null * output : null * * Return : 0 - ok * else - fail * Decription : 测试led_id灯的呼吸模式控制功能 ************************************************************************/ int led_test_case_005(int led_id) { int ret = LED_ERROR; unsigned long full_onoff, fade_onoff = LED_BREATH_FADEONOFF_MAX; struct balong_led_device *led = NULL; led = (struct balong_led_device *)platform_get_drvdata(&balong_led_dev); if(!led) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"get balong led device failed.\n"); return LED_ERROR; } /* set brightness */ if((0 == led_id) || (1 == led_id)) { full_onoff = LED_BREATH_FULLONOFF_MAX_DR12; } else { full_onoff = LED_BREATH_FULLONOFF_MAX_DR345; } ret = led[led_id].pdata->led_breath_set(&(led[led_id].cdev), &full_onoff, &full_onoff, &fade_onoff, &fade_onoff); if(ret) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"\n[%s]ERROR:led id %d, set blink error, ret %d\n", __FUNCTION__, led_id + 1, ret); return LED_ERROR; } return LED_OK; }
/************************************************************************ * Name : led_test_case_001 * Function : * Arguments * input : led_id:0~4 * output : null * * Return : 0 - ok * else - fail * Decription : 测试id为led_id灯的亮度控制功能。 ************************************************************************/ int led_test_case_001(int led_id) { int ret = LED_ERROR; enum led_brightness brightness; struct balong_led_device *led = NULL; led = (struct balong_led_device *)platform_get_drvdata(&balong_led_dev); if(!led) { LED_TRACE(LED_DEBUG_LEVEL(ALWAYS),"get balong led device failed.\n"); return LED_ERROR; } /* test every brightness for a certain led, including two illegal brightness*/ /*lint -save -e685*/ for(brightness = LED_OFF; brightness <= LED_FULL ; brightness++) { LED_TRACE(LED_DEBUG_LEVEL(INFO),"\n[%s] ===TEST=== led id %d, brightness %d\n", __FUNCTION__, led_id, brightness); led[led_id].cdev.brightness_set(&(led[led_id].cdev), brightness); /* set brightness */ ret = led[led_id].cdev.brightness_get(&(led[led_id].cdev)); if(ret != brightness) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"\n[%s]ERROR:led id %d, brightness set %d, get %d\n", __FUNCTION__, led_id + 1, brightness, ret); return LED_ERROR; } } /*lint -restore*/ return LED_OK; }
static void BuffaloLed_BlinkStop(struct led_t *led) { LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); if (led->ErrorNumber) del_timer(&led->LedTimer); led->ErrorNumber = 0; led->Brighted = 0; led->Brighting = LED_OFF; LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); }
static void BuffaloLed_BlinkStart(struct led_t *led) { LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); led->Brighted = 0; led->Brighting = LED_OFF; init_timer(&led->LedTimer); led->LedTimer.expires = (jiffies + BUFFALO_LED_WAIT_SHORT); led->LedTimer.function = BuffaloLed_StatChange; led->LedTimer.data = (unsigned long)led; add_timer(&led->LedTimer); LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); }
/************************************************************************ *函数原型 : static int assemble_container(const char * cmd_obj) *描述 : 属性路径容器填充函数 *输入 : 无 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20131205 修改内容 : 新生成函数 *************************************************************************/ PRIVATE int assemble_container(const char * cmd_obj) { int len = 0; if(!cmd_obj) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); return BR_ERROR; } /* 置空容器 */ (void)memset(path_container, 0x0, CONTAINER_LEN);/*lint !e506*/ if(BREATH_DR_BOTTOM <= led_attr_default.led_dr || BREATH_DR01 > led_attr_default.led_dr) { printk(KERN_ERR"[*Breath-Led*] %s: PMU DR selected %d error.\n", __func__, led_attr_default.led_dr); return BR_ERROR; } /* 填充容器 */ len = snprintf(path_container, CONTAINER_LEN, container_format, led_attr_default.led_dr, cmd_obj); if(len < 0) { printk(KERN_ERR"[*Breath-Led*] %s: assemble %s failed.\n", __func__, cmd_obj); return BR_ERROR; } return BR_OK; }
/************************************************************************ *函数原型 : enum led_brightness led_dr_brightness_get(struct led_classdev *led_cdev) *描述 : 用户态操作DR灯开始闪烁的接口 *输入 : 无 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20140620 修改内容 : 新生成函数 *************************************************************************/ enum led_brightness led_dr_brightness_get(struct led_classdev *led_cdev) { if(!led_cdev) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); return (enum led_brightness)BR_ERROR; } return (enum led_brightness)led_cdev->brightness; }
/************************************************************************ *函数原型 : int change_name(struct led_classdev *led_cdev) *描述 : 将用户态操作的节点名称转换成海思注册的Balong_dr*的名称,用于访问海思注册的dr灯节点 *输入 : 用户态操作的节点信息 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20140620 修改内容 : 新生成函数 *************************************************************************/ int change_name(struct led_classdev *led_cdev) { /* reject null */ if(!led_cdev || !led_cdev->name) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); return BR_ERROR; } LED_TRACE(LED_DEBUG_LEVEL(INFO),"[%s] led name %s\n", __FUNCTION__, led_cdev->name); if(!strcmp(led_cdev->name, LED_NODE_1)) { g_dr_name = LED_NAME_1; return BR_OK; } else if(!strcmp(led_cdev->name, LED_NODE_2)) { g_dr_name = LED_NAME_2; return BR_OK; } else if(!strcmp(led_cdev->name, LED_NODE_3)) { g_dr_name = LED_NAME_3; return BR_OK; } else if(!strcmp(led_cdev->name, LED_NODE_4)) { g_dr_name = LED_NAME_4; return BR_OK; } else if(!strcmp(led_cdev->name, LED_NODE_5)) { g_dr_name = LED_NAME_5; return BR_OK; } else { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] match the led name failedn", __FUNCTION__); return BR_ERROR; } }
/******************************************************************************* * FUNC NAME: * led_softtimer_create() * Function : 创建软timer * Arguments * input : @timer - timer的定时时间 * @wake_type - timer对CPU的唤醒类型 * output : null * * Return : LED_OK - 成功;else - 失败 * Decription : null ************************************************************************/ int led_softtimer_create(unsigned int time, enum wakeup wake_type) { led_softtimer.func = (softtimer_func)led_state_check_callback; led_softtimer.para = 0; led_softtimer.timeout = time; /* 定时长度,单位ms */ led_softtimer.wake_type = wake_type; if (bsp_softtimer_create(&led_softtimer)) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s]ERROR: softtimer create failed\n", __FUNCTION__); return LED_ERROR; } bsp_softtimer_add(&led_softtimer); LED_TRACE(LED_DEBUG_LEVEL(INFO), "LED create softtimer OK\n"); return LED_OK; }
static int BuffaloLedWriteProc(struct file *filep, const char *buffer, unsigned long count, void *data) { int TmpNum=0; struct led_t *led = data; LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); TmpNum = BuffaloKatoi(buffer, count); LED_TRACE(printk("%s > TmpNum=%d\n", __FUNCTION__, TmpNum)); // if the status buffalo_led_status.alarm.ErrorNumber is 0, force on is enable. if (TmpNum == 0) { if (strncmp(buffer, "on", 2) == 0 ) { LED_TRACE(printk("%s > Calling BuffaloGpio_AlarmLedEnable\n", __FUNCTION__)); BuffaloGpio_LedEnable(led->mppNumber); } else if (strncmp(buffer, "off", 3) == 0) { LED_TRACE(printk("%s > Calling BuffaloGpio_AlarmLedDisable\n", __FUNCTION__)); BuffaloLed_BlinkStop(led); BuffaloGpio_LedDisable(led->mppNumber); } else if (strncmp(buffer, "inv", 3) == 0) { BuffaloGpio_LedInvert(led->mppNumber); } } else { if (led->ErrorNumber ==0) { if ((TmpNum > 0) && (TmpNum <= MAX_ALARM_NUM)) { led->ErrorNumber = TmpNum; BuffaloLed_BlinkStart(led); } else if (TmpNum == 0) { BuffaloLed_BlinkStop(led); } else { // Nothing to do... } } } LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); return count; }
/******************************************************************************* * FUNC NAME: * bsp_led_init() * Function : c核led初始化函数 * Arguments * input : null * output : null * * Return : LED_OK - 成功;else - 失败 * Decription : ************************************************************************/ int bsp_led_init(void) { int ret = LED_ERROR; /* 初始化上层工作状态 */ g_cur_work_state = LED_LIGHT_STATE_MAX; p_func_tled_state_get = (pFUNCPTR)led_default_callback; /* 创建软timer(不唤醒),注册回调函数 */ ret = led_softtimer_create(LED_TIME_BASE_UNIT, SOFTTIMER_NOWAKE); if(ret != LED_OK) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] softtimer create failed, ret = 0x%x\n", __FUNCTION__, ret); return ret; } LED_TRACE(LED_DEBUG_LEVEL(ALWAYS), "LED init OK\n"); return ret; }
/******************************************************************************* * FUNC NAME: * led_state_check_callback() - C核软timer回调函数 * Function : * Arguments * input : null * output : null * * Return : null * Decription : ************************************************************************/ void led_state_check_callback(void) { int ret = LED_ERROR; /* 获取上层状态 */ if (NULL != p_func_tled_state_get) { g_new_work_state = (unsigned char)((*p_func_tled_state_get)()); } else { return; } LED_TRACE(LED_DEBUG_LEVEL(INFO), "[%s]LED get new state success, new state %d\n", __FUNCTION__, g_new_work_state); /* 与当前状态进行比较,若不同,则更新当前状态并通知A核闪灯 */ if(g_cur_work_state != g_new_work_state) { ret = bsp_icc_send(ICC_CPU_APP, LED_ICC_CHN_ID, (unsigned char*)&g_new_work_state, sizeof(unsigned char)); if(ret != (int)sizeof(unsigned char)) { LED_TRACE(LED_DEBUG_LEVEL(ERROR), "[%s]icc send failed, new state %d, length %d\n", __FUNCTION__, g_new_work_state, ret); return; } LED_TRACE(LED_DEBUG_LEVEL(INFO), "[%s]icc send success, new state %d\n", __FUNCTION__, g_new_work_state); g_cur_work_state = g_new_work_state; } LED_TRACE(LED_DEBUG_LEVEL(INFO), "[%s]LED same state, skip\n", __FUNCTION__); bsp_softtimer_add(&led_softtimer); return; }
static int BuffaloLedBlinkWriteProc(struct file *filep, const char *buffer, unsigned long count, void *data) { struct led_t *led = data; if(strncmp(buffer, "on", 2) == 0 ) { BuffaloGpio_LedBlinkEnable(led->mppNumber); } else if(strncmp(buffer, "off", 3) == 0) { BuffaloGpio_LedBlinkDisable(led->mppNumber); } LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); return count; }
/************************************************************************ * Name : led_tled_test_case_016 * Function : 测试三色灯部分颜色变化功能 - 从白色到白色 * Arguments * input : @state - 工作状态 * output : null * * Return : 0 - ok * Decription : 需要测试人员观察灯的状态来判断是否测试ok ************************************************************************/ int led_tled_test_case_016(unsigned long state) { led_save_for_test(); if(state < LED_LIGHT_STATE_MAX) { return do_led_tled_test_case(state); } else { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"ERROR: invalid state %d\n", state); return LED_ERROR; } }
static int BuffaloLedReadProc(char *page, char **start, off_t offset, int length, int *eof, void *data) { LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); int len = 0; off_t begin = 0; struct led_t *led = data; if (led->mppNumber < 0) return 0; if (led->ErrorNumber == 0) { if ((~GPIO_OUT_REG) & BIT(led->mppNumber)) len = sprintf(page, "on\n"); else len = sprintf(page, "off\n"); } else { #if defined BUFFALO_LED_CONTROL_INFO_BLOCK_ENABLE if (led == &infoLed && alarmLed.ErrorNumber != 0) len = sprintf(page, "%d(Blocked)\n", led->ErrorNumber); else len = sprintf(page, "%d\n", led->ErrorNumber); #else len = sprintf(page, "%d\n", led->ErrorNumber); #endif } *start = page + (offset - begin); len -= (offset - begin); if (len > length) len = length; LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); return (len); }
/************************************************************************ * Name : led_test_case_003 * Function : * Arguments * input : null * output : null * * Return : 0 - ok * else - fail * Decription : 测试led_id灯的闪烁模式控制功能 ************************************************************************/ int led_test_case_003(int led_id) { int ret = LED_ERROR; unsigned long full_on = LED_BLINK_FULLON_MAX, full_off = LED_BLINK_PERIOD_MAX - LED_BLINK_FULLON_MAX; struct balong_led_device *led = NULL; led = (struct balong_led_device *)platform_get_drvdata(&balong_led_dev); if(!led) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"get balong led device failed.\n"); return LED_ERROR; } /* set brightness */ ret = led[led_id].cdev.blink_set(&(led[led_id].cdev), &full_on, &full_off); if(ret) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"\n[%s]ERROR:led id %d, set blink error, ret %d\n", __FUNCTION__, led_id + 1, ret); return LED_ERROR; } return LED_OK; }
/************************************************************************ * Name : led_test_case_002 * Function : * Arguments * input : null * output : null * * Return : 0 - ok * else - fail * Decription : 测试每个led灯的亮度设置 ************************************************************************/ int led_test_case_002(void) { int led_id; int ret; for(led_id = 0; led_id < LED_ID_MAX; led_id++) { ret = led_test_case_001(led_id); if(ret != LED_OK) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"\n[%s]ERROR:led id %d, ret %d\n", __FUNCTION__, led_id + 1, ret); return LED_ERROR; } } return LED_OK; }
static void BuffaloLed_StatChange(unsigned long data) { struct led_t *led = (struct led_t *)data; int NextPhase = BuffaloLedGetNextPhase(led); LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); switch(NextPhase) { case LED_PHASE_10: led->LedTimer.expires = (jiffies + BUFFALO_LED_WAIT_10); #if defined BUFFALO_LED_CONTROL_INFO_BLOCK_ENABLE if (led == &infoLed && alarmLed.ErrorNumber != 0) BuffaloGpio_LedDisable(led->mppNumber); else BuffaloGpio_LedEnable(led->mppNumber); #else BuffaloGpio_LedEnable(led->mppNumber); #endif led->Brighted += 10; led->Brighting = LED_ON; LED_TRACE(printk("%s > change to LED_PHASE_10\n", __FUNCTION__)); break; case LED_PHASE_1: led->LedTimer.expires = (jiffies + BUFFALO_LED_WAIT_1); #if defined BUFFALO_LED_CONTROL_INFO_BLOCK_ENABLE if (led == &infoLed && alarmLed.ErrorNumber != 0) BuffaloGpio_LedDisable(led->mppNumber); else BuffaloGpio_LedEnable(led->mppNumber); #else BuffaloGpio_LedEnable(led->mppNumber); #endif led->Brighted += 1; led->Brighting = LED_ON; LED_TRACE(printk("%s > change to LED_PHASE_1\n", __FUNCTION__)); break; case LED_PHASE_SHORT: led->LedTimer.expires = (jiffies + BUFFALO_LED_WAIT_SHORT); BuffaloGpio_LedDisable(led->mppNumber); led->Brighting = LED_OFF; LED_TRACE(printk("%s > change to LED_PHASE_SHORT\n", __FUNCTION__)); break; case LED_PHASE_LONG: led->LedTimer.expires = (jiffies + BUFFALO_LED_WAIT_LONG); BuffaloGpio_LedDisable(led->mppNumber); led->Brighting = LED_OFF; led->Brighted = 0; LED_TRACE(printk("%s > change to LED_PHASE_LONG\n", __FUNCTION__)); break; } add_timer(&led->LedTimer); LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); }
/************************************************************************ *函数原型 : static int assemble_container_dr(const char * cmd_obj) *描述 : 属性路径容器填充函数 *输入 : cmd_obj 需要填充的属性 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20140620 修改内容 : 新生成函数 *************************************************************************/ PRIVATE int assemble_container_dr(const char * cmd_obj) { int len = 0; if(!cmd_obj) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); return BR_ERROR; } /* 置空容器 */ (void)memset(path_container,0x0, CONTAINER_LEN);/*lint !e160 !e506*/ /* 填充容器 */ len = snprintf(path_container, CONTAINER_LEN, container_format, g_dr_name, cmd_obj); if(len < 0) { printk(KERN_ERR"[*Breath-Led*] %s: assemble %s failed.\n", __func__, cmd_obj); return BR_ERROR; } return BR_OK; }
static int BuffaloKatoi(const char *buffer, unsigned int count) { #define MAX_LENGTH 16 int i; int TmpNum=0; LED_TRACE(printk("%s > Entered\n", __FUNCTION__)); if(count > MAX_LENGTH) { LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); return -1; } LED_TRACE(printk("%s > buffer=0x%08x\n", __FUNCTION__, buffer)); LED_TRACE(printk("%s > *buffer=0x%08x\n", __FUNCTION__, *buffer)); for(i=0; i<count; i++, buffer++) { LED_TRACE(printk("%s > *buffer=0x%08x, TmpNum=%d\n", __FUNCTION__, *buffer, TmpNum)); if(*buffer>='0' && *buffer<='9') TmpNum=(TmpNum * 10) + (*buffer - '0'); } LED_TRACE(printk("%s > Leaving\n", __FUNCTION__)); return TmpNum; }
/************************************************************************ *函数原型 : int led_dr_breath_set(struct led_classdev *led_cdev, unsigned long *full_on, unsigned long *full_off, unsigned long *fade_on, unsigned long *fade_off) *描述 : 用户态操作DR灯开始呼吸的接口 *输入 : 无 *输出 : 无 *返回值 : BR_OK OR BR_ERRO *修改历史 : 1.日 期 : 20140620 修改内容 : 新生成函数 *************************************************************************/ int led_dr_breath_set(struct led_classdev *led_cdev, unsigned long *full_on, unsigned long *full_off, unsigned long *fade_on, unsigned long *fade_off) { int ret = BR_ERROR; /* argument check */ if((!led_cdev) || (!full_on) || (!full_off) || (!fade_on) || (!fade_off)) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); return BR_ERROR; } led_cdev->breath_full_on = *full_on; led_cdev->breath_full_off = *full_off; led_cdev->breath_fade_on = *fade_on; led_cdev->breath_fade_off = *fade_off; ret = change_name(led_cdev); if(BR_ERROR == ret) { return ret; } g_dr_brightness[g_dr_name - 1] = -1; /*亮度值复位*/ ret = led_dr_trigger_hold(); if(BR_ERROR == ret) { return ret; } /*应用层下发的时间参数是毫秒级的,而底层定义的参数是微秒级的,在用户态参数传入的时候需要转换*/ ret = set_led_dr_attr(BRT_ATTR_FULL_ON, (led_cdev->breath_full_on)*1000); if(BR_ERROR == ret) { return ret; } ret = set_led_dr_attr(BRT_ATTR_FULL_OFF, (led_cdev->breath_full_off)*1000); if(BR_ERROR == ret) { return ret; } ret = set_led_dr_attr(BRT_ATTR_FADE_ON, (led_cdev->breath_fade_on)*1000); if(BR_ERROR == ret) { return ret; } ret = set_led_dr_attr(BRT_ATTR_FADE_OFF, (led_cdev->breath_fade_off)*1000); if(BR_ERROR == ret) { return ret; } /*时间赋值完毕进入亮度设置*/ if ((led_cdev->breath_full_on)&&(led_cdev->breath_full_off)&&(led_cdev->breath_fade_on)&&(led_cdev->breath_fade_off)) { if ((0 == led_cdev->brightness) || (1 == led_cdev->brightness)) { if(LED_NAME_2 < g_dr_name) { ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, DR345_BRIGHTNESS_3MA); } else { ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, DR12_BRIGHTNESS_3MA); } } else { ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, led_cdev->brightness); } if(BR_ERROR == ret) { return ret; } } return BR_OK; }
/**************************************************************************** 函 数 名 : drv_led_state_func_reg 功能描述 : 本接口为提供给协议栈的钩子函数,用于获取协议栈的点灯状态。 输入参数 : 协议栈获取点灯状态函数的指针。 输出参数 : 无。 返 回 值 : 无。 注意事项 : 无。 ******************************************************************************/ void drv_led_state_func_reg (pFUNCPTR p) { LED_TRACE(LED_DEBUG_LEVEL(INFO), "LED state_func_reg, 0x%x\n", p); p_func_tled_state_get = p; }
/************************************************************************ *函数原型 : void led_dr_work(struct work_struct *work) *描述 : DR灯亮灭接口工作队列 *输入 : 无 *输出 : 无 *返回值 : 无 *修改历史 : 1.日 期 : 20140809 修改内容 : 新生成函数 *************************************************************************/ static void led_dr_work(struct work_struct *work) { int ret = BR_ERROR; unsigned long time_local = 0; int brightness = 0; struct balong_led_device *led_dat = NULL; struct led_classdev *led_cdev = NULL; mutex_lock(&led_dr_mutex); led_dat = container_of(work, struct balong_led_device, work); led_cdev = &(led_dat->cdev); brightness = led_dat->brightness; if(!led_cdev) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] arguments is NULL\n", __FUNCTION__); goto out; } ret = change_name(led_cdev); if(BR_ERROR == ret) { goto out; } if (brightness >= LED_FULL) { brightness = LED_FULL; } if(1 == brightness) { if(LED_NAME_2 < g_dr_name) { #ifdef BSP_CONFIG_BOARD_E5 brightness = DR345_BRIGHTNESS_4_5MA; #else brightness = DR345_BRIGHTNESS_3MA; #endif } else { brightness = DR12_BRIGHTNESS_3MA; } } if(g_dr_brightness[g_dr_name - 1] == brightness) /*重复设置亮度*/ { goto out; } g_dr_brightness[g_dr_name - 1] = brightness; /*亮度值更新*/ ret = led_dr_trigger_hold(); if(BR_ERROR == ret) { goto out; } /*设置灯的状态为长灭*/ if (LED_OFF == brightness) { ret = set_led_dr_attr(BRT_ATTR_FULL_ON, time_local); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_ON,time_local) failded.\n", __func__); goto out; } ret = set_led_dr_attr(BRT_ATTR_FULL_OFF, LED_LONG_TIME); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_OFF, LED_LONG_TIME) failded.\n", __func__); goto out; } } /*设置灯的状态为长亮*/ else { ret = set_led_dr_attr(BRT_ATTR_FULL_ON, LED_LONG_TIME); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_ON, LED_LONG_TIME) failded.\n", __func__); goto out; } ret = set_led_dr_attr(BRT_ATTR_FULL_OFF, time_local); if(BR_ERROR == ret) { printk(KERN_ERR"[*Breath-Led*] %s: set_led_dr_attr(BRT_ATTR_FULL_OFF, time_local) failded.\n", __func__); goto out; } } ret = set_led_dr_attr(BRT_ATTR_FADE_ON, time_local); if(BR_ERROR == ret) { goto out; } ret = set_led_dr_attr(BRT_ATTR_FADE_OFF, time_local); if(BR_ERROR == ret) { goto out; } ret = set_led_dr_attr(BRT_ATTR_BRIGHTNESS, brightness); if(BR_ERROR == ret) { goto out; } out: mutex_unlock(&led_dr_mutex); }
/*lint -e54 -e119 -e30 -e84 -e514 */ static int led_dr_probe(struct platform_device *dev) { int ret = 0; unsigned int i = 0; struct led_platform_data *pdata = dev->dev.platform_data; struct balong_led_device *led= NULL; led = (struct balong_led_device *)kzalloc(sizeof(struct balong_led_device)*ARRAY_SIZE(led_dr) , GFP_KERNEL); if(!led) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] get buffer failed\n", __FUNCTION__); goto ERRO; } for(i = 0; i < (int)ARRAY_SIZE(led_dr); i++) { led[i].pdata =(struct balong_led_platdata*)kzalloc(sizeof(struct balong_led_platdata), GFP_KERNEL); if(!led[i].pdata) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s] get pdata buffer failed\n", __FUNCTION__); goto ERRO; } led[i].cdev.name = pdata->leds[i].name; led[i].pdata->led_breath_set = led_dr_breath_set; led[i].cdev.brightness_set = led_dr_brightness_set; led[i].cdev.brightness_get = led_dr_brightness_get; led[i].cdev.blink_set = led_dr_led_blink_set; led[i].cdev.default_trigger = pdata->leds[i].default_trigger; led[i].cdev.flags = 0; INIT_WORK(&(led[i].work), led_dr_work); ret = led_classdev_register(&dev->dev, &(led[i].cdev)); if(ret) { LED_TRACE(LED_DEBUG_LEVEL(ERROR),"[%s]led%d sysfs register failed\n", __FUNCTION__,i + 1); } } platform_set_drvdata(dev, led);/*lint !e534*/ return ret; ERRO: for(i = 0; i < ARRAY_SIZE(led_dr); i++) { if(!led) { continue; } if(led[i].pdata) { kfree(led[i].pdata); led[i].pdata = NULL; } } if(led) { kfree(led); led = NULL; } LED_TRACE(LED_DEBUG_LEVEL(ALWAYS),"LED init failed\n"); return BR_ERROR; }