Exemplo n.º 1
0
static void qpnp_led_config(struct qpnp_led_data *led)
{
	pm8x41_wled_reg_write(RGB_LED_SRC_SEL(led->base),
		RGB_LED_SOURCE_VPH_PWR);
	pm8x41_wled_reg_write(LPG_PATTERN_CONFIG(led->lpg_base), 0x00);
	pm8x41_wled_reg_write(LPG_PWM_SIZE_CLK(led->lpg_base),
		PWM_6BIT_1KHZ_CLK);
	pm8x41_wled_reg_write(LPG_PWM_FREQ_PREDIV_CLK(led->lpg_base),
		PWM_FREQ);
	pm8x41_wled_reg_write(LPG_PWM_TYPE_CONFIG(led->lpg_base), 0x00);
	pm8x41_wled_reg_write(PWM_VALUE_LSB(led->lpg_base), 0x20);
	pm8x41_wled_reg_write(PWM_VALUE_MSB(led->lpg_base), 0x00);
	pm8x41_wled_reg_write(PWM_SYNC(led->lpg_base), 0x01);
	pm8x41_wled_reg_write(LPG_ENABLE_CONTROL(led->lpg_base),
		RGB_LED_ENABLE_PWM);
}
Exemplo n.º 2
0
static int __devinit qpnp_rgb_init(struct qpnp_led_data *led)
{
	int rc, start_idx, idx_len;

	rc = qpnp_led_masked_write(led, RGB_LED_SRC_SEL(led->base),
		RGB_LED_SRC_MASK, RGB_LED_SOURCE_VPH_PWR);
	if (rc) {
		dev_err(&led->spmi_dev->dev,
			"Failed to write led source select register\n");
		return rc;
	}

	if (led->rgb_cfg->pwm_channel != -1) {
		led->rgb_cfg->pwm_dev =
			pwm_request(led->rgb_cfg->pwm_channel,
						led->cdev.name);

		if (IS_ERR_OR_NULL(led->rgb_cfg->pwm_dev)) {
			dev_err(&led->spmi_dev->dev,
				"could not acquire PWM Channel %d, " \
				"error %ld\n",
				led->rgb_cfg->pwm_channel,
				PTR_ERR(led->rgb_cfg->pwm_dev));
			led->rgb_cfg->pwm_dev = NULL;
			return -ENODEV;
		}

		if (led->rgb_cfg->mode == RGB_MODE_LPG) {
			start_idx =
			led->rgb_cfg->duty_cycles->start_idx;
			idx_len =
			led->rgb_cfg->duty_cycles->num_duty_pcts;

			if (idx_len >= PWM_LUT_MAX_SIZE &&
					start_idx) {
				dev_err(&led->spmi_dev->dev,
					"Wrong LUT size or index\n");
				return -EINVAL;
			}
			if ((start_idx + idx_len) >
					PWM_LUT_MAX_SIZE) {
				dev_err(&led->spmi_dev->dev,
					"Exceed LUT limit\n");
				return -EINVAL;
			}
			rc = pwm_lut_config(led->rgb_cfg->pwm_dev,
				led->rgb_cfg->pwm_period_us,
				led->rgb_cfg->duty_cycles->duty_pcts,
				led->rgb_cfg->lut_params);
			if (rc < 0) {
				dev_err(&led->spmi_dev->dev, "Failed to " \
					"configure pwm LUT\n");
				return rc;
			}
		}
	} else {
		dev_err(&led->spmi_dev->dev,
			"Invalid PWM channel\n");
		return -EINVAL;
	}

	/* Initialize led for use in auto trickle charging mode */
	rc = qpnp_led_masked_write(led, RGB_LED_ATC_CTL(led->base),
		led->rgb_cfg->enable, led->rgb_cfg->enable);

	return 0;
}