static ssize_t store_led_b(struct device *dev,
		struct device_attribute *devattr,
		const char *buf, size_t count)
{
	struct max77828_rgb *max77828_rgb = dev_get_drvdata(dev);
	unsigned int brightness;
	char buff[10] = {0,};
	int cnt, ret;

	cnt = count;
	cnt = (buf[cnt-1] == '\n') ? cnt-1 : cnt;
	memcpy(buff, buf, cnt);
	buff[cnt] = '\0';
	ret = kstrtouint(buff, 0, &brightness);
	if (ret != 0) {
		dev_err(dev, "fail to get brightness.\n");
		goto out;
	}
	if (brightness != 0) {
		max77828_rgb_set(&max77828_rgb->led[BLUE], brightness);
		max77828_rgb_blink(dev, 0, 0);
	} else	{
		max77828_rgb_set(&max77828_rgb->led[BLUE], LED_OFF);
	}
out:
	return count;
}
static void max77828_rgb_reset(struct device *dev)
{
	struct max77828_rgb *max77828_rgb = dev_get_drvdata(dev);
	max77828_rgb_set(&max77828_rgb->led[RED], LED_OFF);
	max77828_rgb_set(&max77828_rgb->led[GREEN], LED_OFF);
	max77828_rgb_set(&max77828_rgb->led[BLUE], LED_OFF);
	max77828_rgb_ramp(dev, 0, 0);
}
static ssize_t store_max77828_rgb_blink(struct device *dev,
					struct device_attribute *devattr,
					const char *buf, size_t count)
{
	struct max77828_rgb *max77828_rgb = dev_get_drvdata(dev);
	int led_brightness = 0;
	int delay_on_time = 0;
	int delay_off_time = 0;
	u8 led_r_brightness = 0;
	u8 led_g_brightness = 0;
	u8 led_b_brightness = 0;
	int ret;

	ret = sscanf(buf, "0x%8x %5d %5d", &led_brightness,
					&delay_on_time, &delay_off_time);
	if (ret == 0) {
		dev_err(dev, "fail to get led_blink value.\n");
		return count;
	}

	/*Reset led*/
	max77828_rgb_reset(dev);

	led_r_brightness = (led_brightness & LED_R_MASK) >> 16;
	led_g_brightness = (led_brightness & LED_G_MASK) >> 8;
	led_b_brightness = led_brightness & LED_B_MASK;

	/* In user case, LED current is restricted to less than 2mA */
	led_r_brightness = (led_r_brightness * led_dynamic_current) / LED_MAX_CURRENT;
	led_g_brightness = (led_g_brightness * led_dynamic_current) / LED_MAX_CURRENT;
	led_b_brightness = (led_b_brightness * led_dynamic_current) / LED_MAX_CURRENT;

	if (led_r_brightness) {
		max77828_rgb_set(&max77828_rgb->led[RED], led_r_brightness);
	}
	if (led_g_brightness) {
		max77828_rgb_set(&max77828_rgb->led[GREEN], led_g_brightness);
	}
	if (led_b_brightness) {
		max77828_rgb_set(&max77828_rgb->led[BLUE], led_b_brightness);
	}
	/*Set LED blink mode*/
	max77828_rgb_blink(dev, delay_on_time, delay_off_time);

	dev_dbg(dev, "led_blink is called, Color:0x%X Brightness:%i\n",
			led_brightness, led_dynamic_current);
	return count;
}
Exemplo n.º 4
0
static ssize_t max77828_led_b(struct device *dev,
													struct device_attribute *devattr,
													const char *buf, size_t count)
{
	struct led_classdev *led_cdev = dev_get_drvdata(dev);
	struct max77828_led_data *led_data = container_of(led_cdev, struct max77828_led_data, led);

	char buff[10] = {0,};
	int cnt, ret;
	int brightness;

	cnt = count;
	cnt = (buf[cnt-1] == '\n') ? cnt-1 : cnt;
	memcpy(buff, buf, cnt);
	buff[cnt] = '\0';

	ret = kstrtoint(buff, 0, &brightness);
	if (ret != 0){
			printk("fail to get brightness.\n");
			goto out;
	}
	led_data->test_brightness = brightness;
	led_data->data->id = MAX77828_RGB_B;
	max77828_rgb_set(led_data);
out:
	return count;
}
Exemplo n.º 5
0
static void led_set(struct max77828_led_data *led_data)
{
	struct max77828_led *data = led_data->data;
	int id = data->id;
	switch(id)
	{
		case MAX77828_FLASH:
			max77828_flash_set(led_data);
			break;
		case MAX77828_TORCH:
			max77828_torch_set(led_data);
			break;
		case MAX77828_RGB_R :
		case MAX77828_RGB_G :
		case MAX77828_RGB_B :
			max77828_rgb_set(led_data);
			break;
		default:
			pr_err("(%s) : LED id is not valid\n",__func__);
			break;
	}
	return;
}
static ssize_t store_max77828_rgb_pattern(struct device *dev,
					struct device_attribute *devattr,
					const char *buf, size_t count)
{
	struct max77828_rgb *max77828_rgb = dev_get_drvdata(dev);
	unsigned int mode = 0;
	int ret;

	ret = sscanf(buf, "%1d", &mode);
	if (ret == 0) {
		dev_err(dev, "fail to get led_pattern mode.\n");
		return count;
	}

	if (mode > POWERING)
		return count;

	/* Set all LEDs Off */
	max77828_rgb_reset(dev);
	if (mode == PATTERN_OFF)
		return count;

	/* Set to low power consumption mode */
	if (led_lowpower_mode == 1)
		led_dynamic_current = 0x5;
	else
		led_dynamic_current = 0x14;

	switch (mode) {

	case CHARGING:
		max77828_rgb_set(&max77828_rgb->led[RED], led_dynamic_current);
		max77828_rgb_blink(dev, 0, 0);
		break;
	case CHARGING_ERR:
		max77828_rgb_set(&max77828_rgb->led[RED], led_dynamic_current);
		max77828_rgb_blink(dev, 600, 400);
		break;
	case MISSED_NOTI:
		max77828_rgb_set(&max77828_rgb->led[BLUE], led_dynamic_current);
		max77828_rgb_blink(dev, 600, 4900);
		break;
	case LOW_BATTERY:
		max77828_rgb_set(&max77828_rgb->led[RED], led_dynamic_current);
		max77828_rgb_blink(dev, 600, 4900);
		break;
	case FULLY_CHARGED:
		max77828_rgb_set(&max77828_rgb->led[GREEN], led_dynamic_current);
		max77828_rgb_blink(dev, 0, 0);
		break;
	case POWERING:
		max77828_rgb_set(&max77828_rgb->led[GREEN], led_dynamic_current);
		max77828_rgb_set(&max77828_rgb->led[BLUE], led_dynamic_current);
		max77828_rgb_ramp(dev, 1500, 700);
		max77828_rgb_blink(dev, 200, 2500);
		break;
	default:
		break;
	}

	return count;
}