Exemple #1
0
static int __devinit pm8xxx_led_probe(struct platform_device *pdev)
{
	const struct pm8xxx_led_platform_data *pdata = pdev->dev.platform_data;
	struct pm8xxx_led_configure *curr_led;
	struct pm8xxx_led_data *led, *led_dat;
	int i, j, ret = -ENOMEM;

	if (pdata == NULL) {
		LED_ERR("platform data not supplied\n");
		return -EINVAL;
	}

	led = kcalloc(pdata->num_leds + 1, sizeof(*led), GFP_KERNEL);
	if (led == NULL) {
		LED_ERR("failed to alloc memory\n");
		return -ENOMEM;
	}
	wake_lock_init(&pmic_led_wake_lock, WAKE_LOCK_SUSPEND, "pmic_led");
	g_led_work_queue = create_workqueue("pm8xxx-led");
	if (g_led_work_queue == NULL) {
		LED_ERR("failed to create workqueue\n");
		goto err_create_work_queue;
	}

	for (i = 0; i < pdata->num_leds; i++) {
		curr_led			= &pdata->leds[i];
		led_dat				= &led[i];
		led_dat->cdev.name		= curr_led->name;
		led_dat->id     		= curr_led->flags;
		led_dat->bank			= curr_led->flags;
		led_dat->function_flags		= curr_led->function_flags;
		led_dat->start_index		= curr_led->start_index;
		led_dat->duty_time_ms		= curr_led->duty_time_ms;
		led_dat->period_us		= curr_led->period_us;
		led_dat->duites_size		= curr_led->duites_size;
		led_dat->lut_flag		= curr_led->lut_flag;
		led_dat->out_current		= curr_led->out_current;
		led_dat->duties			= &(curr_led->duties[0]);
		led_dat->led_sync		= curr_led->led_sync;
		led_dat->pwm_led 		= pwm_request(led_dat->bank, led_dat->cdev.name);
		led_dat->lpm_power      = curr_led->lpm_power;
		if (curr_led->duties[1]) {
			for (j = 0; j < 64; j++)
				dutys_array[j] = *(led_dat->duties + j);
		}

		if( curr_led->pwm_coefficient > 0 )
			led_dat->pwm_coefficient	= curr_led->pwm_coefficient;
		else
			led_dat->pwm_coefficient	= 100;

		if (curr_led->blink_duty_per_2sec > 0)
			led_dat->blink_duty_per_2sec = curr_led->blink_duty_per_2sec;
		else
			led_dat->blink_duty_per_2sec = 64000;

		switch (led_dat->id) {
		case PM8XXX_ID_GPIO24:
		case PM8XXX_ID_GPIO25:
		case PM8XXX_ID_GPIO26:
			led_dat->cdev.brightness_set = pm8xxx_led_gpio_set;
			if (curr_led->gpio_status_switch != NULL)
				led_dat->gpio_status_switch = curr_led->gpio_status_switch;
			break;
		case PM8XXX_ID_LED_0:
		case PM8XXX_ID_LED_1:
		case PM8XXX_ID_LED_2:
			led_dat->cdev.brightness_set    = pm8xxx_led_current_set;
			if (led_dat->function_flags & LED_PWM_FUNCTION) {
				led_dat->reg		= pm8xxxx_led_pwm_mode(led_dat->id);
				INIT_DELAYED_WORK(&led[i].fade_delayed_work, led_fade_do_work);
			} else
				led_dat->reg		= PM8XXX_LED_MODE_MANUAL;
			break;
		case PM8XXX_ID_LED_KB_LIGHT:
			break;
		}
		led_dat->cdev.brightness	= LED_OFF;
		led_dat->dev			= &pdev->dev;

		ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
		if (ret) {
			LED_ERR("unable to register led %d,ret=%d\n", led_dat->id, ret);
			goto err_register_led_cdev;
		}
		// blink buttons
		if (led_dat->id == PM8XXX_ID_LED_0) {
			// storing buttons light dev for blinking
			led_cdev_buttons = &led_dat->cdev;
			ret = device_create_file(led_dat->cdev.dev, &dev_attr_blink_buttons);
			if (ret < 0) {
				LED_ERR("%s: Failed to create %d attr blink_buttons\n", __func__, i);
				goto err_register_attr_currents;
			}
		}
		// blink buttons end

		if (led_dat->id >= PM8XXX_ID_LED_2 && led_dat->id <= PM8XXX_ID_LED_0) {
			ret = device_create_file(led_dat->cdev.dev, &dev_attr_currents);
			if (ret < 0) {
				LED_ERR("%s: Failed to create %d attr currents\n", __func__, i);
				goto err_register_attr_currents;
			}
		}

		if (led_dat->id >= PM8XXX_ID_LED_2 && led_dat->id <= PM8XXX_ID_LED_0) {
			ret = device_create_file(led_dat->cdev.dev, &dev_attr_lut_coefficient);
			if (ret < 0) {
				LED_ERR("%s: Failed to create %d attr lut_coefficient\n", __func__, i);
				goto err_register_attr_lut_coefficient;
			}
		}

		if ((led_dat->id <= PM8XXX_ID_GPIO26) || (led_dat->id <= PM8XXX_ID_LED_2) ||
		    (led_dat->id <= PM8XXX_ID_LED_1)) {
			ret = device_create_file(led_dat->cdev.dev, &dev_attr_pwm_coefficient);
			if (ret < 0) {
				LED_ERR("%s: Failed to create %d attr pwm_coefficient\n", __func__, i);
				goto err_register_attr_pwm_coefficient;
			}
		}
		if (led_dat->function_flags & LED_BLINK_FUNCTION) {
			INIT_DELAYED_WORK(&led[i].blink_delayed_work, led_blink_do_work);
			ret = device_create_file(led_dat->cdev.dev, &dev_attr_blink);
			if (ret < 0) {
				LED_ERR("%s: Failed to create %d attr blink\n", __func__, i);
				goto err_register_attr_blink;
			}

			ret = device_create_file(led_dat->cdev.dev, &dev_attr_off_timer);
			if (ret < 0) {
				LED_ERR("%s: Failed to create %d attr off timer\n", __func__, i);
				goto err_register_attr_off_timer;
			}
			alarm_init(&led[i].led_alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, led_alarm_handler);
			INIT_WORK(&led[i].led_work, led_work_func); 
		}

		if (!strcmp(led_dat->cdev.name, "button-backlight")) {
			for_key_led_data = led_dat;
		}
		if (!strcmp(led_dat->cdev.name, "green-back")) {
			LED_INFO("%s: green-back, 000 probe, led_dat = %x\n", __func__, (unsigned int)led_dat);
			green_back_led_data = led_dat;
		}
		if (!strcmp(led_dat->cdev.name, "amber-back")) {
			LED_INFO("%s: amber-back\n", __func__);
			amber_back_led_data = led_dat;
		}

	}

	pm8xxx_leds = led;

	platform_set_drvdata(pdev, led);

	return 0;

err_register_attr_off_timer:
	if (i > 0) {
		for (i = i - 1; i >= 0; i--) {
			if (led[i].function_flags & LED_BLINK_FUNCTION)
				device_remove_file(led[i].cdev.dev, &dev_attr_off_timer);
		}
	}
	i = pdata->num_leds;
err_register_attr_blink:
	if (i > 0) {
		for (i = i - 1; i >= 0; i--) {
			if (led[i].function_flags & LED_BLINK_FUNCTION)
				device_remove_file(led[i].cdev.dev, &dev_attr_blink);
		}
	}
	i = pdata->num_leds;
err_register_attr_pwm_coefficient:
	if (i > 0) {
		for (i = i - 1; i >= 0; i--) {
			if (led[i].function_flags <= PM8XXX_ID_GPIO26)
				device_remove_file(led[i].cdev.dev, &dev_attr_pwm_coefficient);
		}
	}
	i = pdata->num_leds;
err_register_attr_lut_coefficient:
	if (i > 0) {
		for (i = i - 1; i >= 0; i--) {
			if (led[i].function_flags >= PM8XXX_ID_LED_2 && led[i].function_flags <= PM8XXX_ID_LED_0)
				device_remove_file(led[i].cdev.dev, &dev_attr_lut_coefficient);
		}
	}
	i = pdata->num_leds;

err_register_attr_currents:
	if (i > 0) {
		for (i = i - 1; i >= 0; i--) {
			if (led[i].function_flags >= PM8XXX_ID_LED_2 && led[i].function_flags <= PM8XXX_ID_LED_0)
				device_remove_file(led[i].cdev.dev, &dev_attr_currents);
		}
	}
	i = pdata->num_leds;
err_register_led_cdev:
	if (i > 0) {
		for (i = i - 1; i >= 0; i--) {
			pwm_free(led[i].pwm_led);
			led_classdev_unregister(&led[i].cdev);
		}
	}
	destroy_workqueue(g_led_work_queue);
err_create_work_queue:
	kfree(led);
	wake_lock_destroy(&pmic_led_wake_lock);
	return ret;
}
Exemple #2
0
static int pwm_beeper_probe(struct platform_device *pdev)
{
	unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev);
	struct pwm_beeper *beeper;
	int error;

	beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
	if (!beeper)
		return -ENOMEM;

	beeper->pwm = pwm_get(&pdev->dev, NULL);
	if (IS_ERR(beeper->pwm)) {
		dev_dbg(&pdev->dev, "unable to request PWM, trying legacy API\n");
		beeper->pwm = pwm_request(pwm_id, "pwm beeper");
	}

	if (IS_ERR(beeper->pwm)) {
		error = PTR_ERR(beeper->pwm);
		dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error);
		goto err_free;
	}

	beeper->input = input_allocate_device();
	if (!beeper->input) {
		dev_err(&pdev->dev, "Failed to allocate input device\n");
		error = -ENOMEM;
		goto err_pwm_free;
	}
	beeper->input->dev.parent = &pdev->dev;

	beeper->input->name = "pwm-beeper";
	beeper->input->phys = "pwm/input0";
	beeper->input->id.bustype = BUS_HOST;
	beeper->input->id.vendor = 0x001f;
	beeper->input->id.product = 0x0001;
	beeper->input->id.version = 0x0100;

	beeper->input->evbit[0] = BIT(EV_SND);
	beeper->input->sndbit[0] = BIT(SND_TONE) | BIT(SND_BELL);

	beeper->input->event = pwm_beeper_event;

	input_set_drvdata(beeper->input, beeper);

	error = input_register_device(beeper->input);
	if (error) {
		dev_err(&pdev->dev, "Failed to register input device: %d\n", error);
		goto err_input_free;
	}

	platform_set_drvdata(pdev, beeper);

	return 0;

err_input_free:
	input_free_device(beeper->input);
err_pwm_free:
	pwm_free(beeper->pwm);
err_free:
	kfree(beeper);

	return error;
}
static int pwm_backlight_probe(struct platform_device *pdev)
{
	struct backlight_properties props;
	struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
	struct backlight_device *bl;
	struct pwm_bl_data *pb;
	int ret;

	if (!data) {
		dev_err(&pdev->dev, "failed to find platform data\n");
		return -EINVAL;
	}

	if (data->init) {
		ret = data->init(&pdev->dev);
		if (ret < 0)
			return ret;
	}

	pb = kzalloc(sizeof(*pb), GFP_KERNEL);
	if (!pb) {
		dev_err(&pdev->dev, "no memory for state\n");
		ret = -ENOMEM;
		goto err_alloc;
	}

	pb->period = data->pwm_period_ns;
	pb->notify = data->notify;
	pb->notify_after = data->notify_after;
	pb->check_fb = data->check_fb;
	pb->lth_brightness = data->lth_brightness *
		(data->pwm_period_ns / data->max_brightness);
	pb->dev = &pdev->dev;

	pb->pwm = pwm_request(data->pwm_id, "backlight");
	if (IS_ERR(pb->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM for backlight\n");
		ret = PTR_ERR(pb->pwm);
		goto err_pwm;
	} else
		dev_dbg(&pdev->dev, "got pwm for backlight\n");

	memset(&props, 0, sizeof(struct backlight_properties));
	props.type = BACKLIGHT_RAW;
	props.max_brightness = data->max_brightness;
	bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb,
				       &pwm_backlight_ops, &props);
	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		ret = PTR_ERR(bl);
		goto err_bl;
	}

	bl->props.brightness = data->dft_brightness;
	backlight_update_status(bl);

	platform_set_drvdata(pdev, bl);
	return 0;

err_bl:
	pwm_free(pb->pwm);
err_pwm:
	kfree(pb);
err_alloc:
	if (data->exit)
		data->exit(&pdev->dev);
	return ret;
}
Exemple #4
0
int backlight_pwm_gpio_config(void)
{
    int rc;
	struct pm8058_gpio backlight_drv = 
	{
		.direction      = PM_GPIO_DIR_OUT,
		.output_buffer  = PM_GPIO_OUT_BUF_CMOS,
		.output_value   = 0,
		.pull           = PM_GPIO_PULL_NO,
		.vin_sel        = 0,
		.out_strength   = PM_GPIO_STRENGTH_HIGH,
		.function       = PM_GPIO_FUNC_2,
		.inv_int_pol 	= 1,
	};
	/* U8800 use PM_GPIO25 as backlight's PWM,but U8820 use PM_GPIO26 */
    if(machine_is_msm7x30_u8800())
	{
        rc = pm8058_gpio_config( 24, &backlight_drv);
    }
    else if(machine_is_msm7x30_u8820()) 
    {
    	rc = pm8058_gpio_config( 25, &backlight_drv);
    }
	else
	{
    	rc = -1;
	}
	
    if (rc) 
	{
		pr_err("%s LCD backlight GPIO config failed\n", __func__);
		return rc;
	}
    return 0;
}
#ifndef CONFIG_HUAWEI_LEDS_PMIC
void touchkey_setbacklight(int level)
{
    if(machine_is_msm7x30_u8800()) 
	{
		pmic_set_led_intensity(LED_KEYPAD, level);
	}

    if(machine_is_msm7x30_u8820())
    {   
		/*if the machine is U8820 use the mpp6 for touchkey backlight*/
        pmic_set_mpp6_led_intensity(level);
    }

}
#endif
void pwm_set_backlight (struct msm_fb_data_type * mfd)
{
	int bl_level = mfd->bl_level;
	/*config PM GPIO25 as PWM and request PWM*/
	if(TRUE == first_set_bl)
	{
	    backlight_pwm_gpio_config();
		/* U8800 use PM_GPIO25 as backlight's PWM,but U8820 use PM_GPIO26 */
		if(machine_is_msm7x30_u8800() )
		{
			bl_pwm = pwm_request(PM_GPIO25_PWM_ID, "backlight");
		}
		else if(machine_is_msm7x30_u8820())
		{
			bl_pwm = pwm_request(PM_GPIO26_PWM_ID, "backlight");
		}
		else
		{
			bl_pwm = NULL;
		}
		
	    if (NULL == bl_pwm || IS_ERR(bl_pwm)) 
		{
	    	pr_err("%s: pwm_request() failed\n", __func__);
	    	bl_pwm = NULL;
	    }
	    first_set_bl = FALSE;

	}
	if (bl_pwm) 
	{
		/* keep duty 10% < level < 90% */
		if (bl_level)
		{
			bl_level = ((bl_level * PWM_LEVEL_ADJUST) / PWM_LEVEL + ADD_VALUE); 
			if (bl_level < BL_MIN_LEVEL)
			{
				bl_level = BL_MIN_LEVEL;
			}
		}
		pwm_config(bl_pwm, PWM_DUTY_LEVEL*bl_level/NSEC_PER_USEC, PWM_PERIOD/NSEC_PER_USEC);
		pwm_enable(bl_pwm);
	}
#ifndef CONFIG_HUAWEI_LEDS_PMIC
	touchkey_setbacklight(!!bl_level);
#endif

}
static int __devinit pm8xxx_vib_probe(struct platform_device *pdev)

{
	const struct pm8xxx_vibrator_pwm_platform_data *pdata =
						pdev->dev.platform_data;
	struct pm8xxx_vib_pwm *vib;
	int rc;
	VIB_PWM_INFO("%s+\n", __func__);

	if (!pdata)
		return -EINVAL;
	if (pdata->duty_us > pdata->PERIOD_US  ||
			 pdata->duty_us < 0)
		return -EINVAL;
	vib = kzalloc(sizeof(*vib), GFP_KERNEL);
	if (!vib)
		return -ENOMEM;
	vib->pdata	= pdata;
	vib->vdd_gpio	= pdata->vdd_gpio;
	vib->ena_gpio	= pdata->ena_gpio;
	vib->dev	= &pdev->dev;
	spin_lock_init(&vib->lock);
	INIT_WORK(&vib->work, pm8xxx_vib_update);
	hrtimer_init(&vib->vib_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	vib->vib_timer.function = pm8xxx_vib_timer_func;
	vib->timed_dev.name = "vibrator";
	vib->timed_dev.get_time = pm8xxx_vib_get_time;
	vib->timed_dev.enable = pm8xxx_vib_enable;
	vib->pwm_vib = pwm_request(vib->pdata->bank, vib->timed_dev.name);
	if (vib->pwm_vib < 0){
		rc = -ENOMEM;
		VIB_PWM_ERR("%s, pwm_request fail\n", __func__);
		goto err_pwm_request;
	}

	rc = gpio_request(vib->ena_gpio, "TI_AMP_ena");
	if (rc) {
		rc = -ENOMEM;
		VIB_PWM_ERR("%s, gpio_request ena fail\n", __func__);
		goto err_ena_gpio_request;
	}
	rc= gpio_request(vib->vdd_gpio, "TI_AMP_vdd");
	if(rc) {
		rc = -ENOMEM;
		VIB_PWM_ERR("%s, gpio_request vdd fail\n", __func__);
		goto err_vdd_gpio_request;
	}
	rc = timed_output_dev_register(&vib->timed_dev);
	if (rc < 0)
		goto err_read_vib;
	rc = device_create_file(vib->timed_dev.dev, &dev_attr_dutys);
	if (rc < 0) {
		VIB_PWM_ERR("%s, create duty sysfs fail: dutys\n", __func__);
	}
	rc = device_create_file(vib->timed_dev.dev, &dev_attr_function_switch);
	if (rc < 0) {
		VIB_PWM_ERR("%s, create duty sysfs fail: function_switch\n", __func__);
	}

	platform_set_drvdata(pdev, vib);
	duty_us= vib->pdata->duty_us;
	period_us=vib->pdata->PERIOD_US;
	VIB_PWM_INFO("%s-\n", __func__);
	return 0;
err_vdd_gpio_request:
	gpio_free(vib->vdd_gpio);
err_ena_gpio_request:
	gpio_free(vib->ena_gpio);
err_pwm_request:
	pwm_free(vib->pwm_vib);
err_read_vib:
	kfree(vib);
	return rc;
}
Exemple #6
0
static int pwm_backlight_probe(struct platform_device *pdev)
{
	struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
	struct backlight_device *bl;
	struct pwm_bl_data *pb;
	int ret;

	if (!data) {
		dev_err(&pdev->dev, "failed to find platform data\n");
		return -EINVAL;
	}

	if (data->init) {
		ret = data->init(&pdev->dev);
		if (ret < 0)
			return ret;
	}

	pb = kzalloc(sizeof(*pb), GFP_KERNEL);
	if (!pb) {
		dev_err(&pdev->dev, "no memory for state\n");
		ret = -ENOMEM;
		goto err_alloc;
	}

#if 0 /* ktj 2011-1-25 */
	pb->period = data->pwm_period_ns / 3;
#else
	pb->period = data->pwm_period_ns;
#endif
	pb->notify = data->notify;

	pb->pwm = pwm_request(data->pwm_id, "backlight");
	if (IS_ERR(pb->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM for backlight\n");
		ret = PTR_ERR(pb->pwm);
		goto err_pwm;
	} else
		dev_dbg(&pdev->dev, "got pwm for backlight\n");

	bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev,
			pb, &pwm_backlight_ops);
	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		ret = PTR_ERR(bl);
		goto err_bl;
	}

	bl->props.max_brightness = data->max_brightness;
	bl->props.brightness = data->dft_brightness;
	backlight_update_status(bl);

	platform_set_drvdata(pdev, bl);

#if defined(CONFIG_MX100)   
    backlight = bl; /* ktj */ 
#endif

	return 0;

err_bl:
	pwm_free(pb->pwm);
err_pwm:
	kfree(pb);
err_alloc:
	if (data->exit)
		data->exit(&pdev->dev);
	return ret;
}
Exemple #7
0
static void pwm_init(void)
{
	pwm_dev = pwm_request(0, "myPWM");
}
Exemple #8
0
static int __devinit vibrator_probe(struct platform_device *pdev)
{
	struct max8997_dev *max8997 = dev_get_drvdata(pdev->dev.parent);
	struct max8997_platform_data *max8997_pdata
		= dev_get_platdata(max8997->dev);
	struct max8997_motor_data *pdata = max8997_pdata->motor;
	struct vibrator_drvdata *ddata;
	int error = 0;

	ddata = kzalloc(sizeof(struct vibrator_drvdata), GFP_KERNEL);
	if (NULL == ddata) {
		pr_err("[VIB] Failed to alloc memory\n");
		error = -ENOMEM;
		goto err_free_mem;
	}

	if (pdata->init_hw)
		pdata->init_hw();

	ddata->pdata = pdata;
	ddata->dev.name = "vibrator";
	ddata->dev.get_time = vibrator_get_time;
	ddata->dev.enable = vibrator_enable;
	ddata->client = max8997->hmotor;

	platform_set_drvdata(pdev, ddata);

	hrtimer_init(&ddata->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	ddata->timer.function = vibrator_timer_func;
	INIT_WORK(&ddata->work, vibrator_work);
	spin_lock_init(&ddata->lock);

	ddata->pwm = pwm_request(pdata->pwm_id, "vibrator");
	if (IS_ERR(ddata->pwm)) {
		pr_err("[VIB] Failed to request pwm.\n");
		error = -EFAULT;
		goto err_pwm_request;
	}
	pwm_config(ddata->pwm,
		ddata->pdata->period/2, ddata->pdata->period);

	vibetonz_clk_on(&pdev->dev, true);

	ddata->regulator = regulator_get(NULL, "vmotor");
	if (IS_ERR(ddata->regulator)) {
		pr_err("[VIB] Failed to get vmoter regulator.\n");
		error = -EFAULT;
		goto err_regulator_get;
	}

	error = timed_output_dev_register(&ddata->dev);
	if (error < 0) {
		pr_err("[VIB] Failed to register timed_output : %d\n", error);
		error = -EFAULT;
		goto err_timed_output_register;
	}

#ifdef CONFIG_VIBETONZ
	g_data = ddata;
#endif

	return 0;

err_timed_output_register:
	timed_output_dev_unregister(&ddata->dev);
err_regulator_get:
	regulator_put(ddata->regulator);
err_pwm_request:
	pwm_free(ddata->pwm);
err_free_mem:
	kfree(ddata);
	return error;
}
Exemple #9
0
static int max77693_haptic_probe(struct platform_device *pdev)
{
	int error = 0;
	struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent);
	struct max77693_platform_data *max77693_pdata
		= dev_get_platdata(max77693->dev);
	struct max77693_haptic_platform_data *pdata
		= max77693_pdata->haptic_data;
	struct max77693_haptic_data *hap_data;

	pr_debug("[VIB] ++ %s\n", __func__);
	 if (pdata == NULL) {
		pr_err("%s: no pdata\n", __func__);
		return -ENODEV;
	}

	hap_data = kzalloc(sizeof(struct max77693_haptic_data), GFP_KERNEL);
	if (!hap_data)
		return -ENOMEM;

	platform_set_drvdata(pdev, hap_data);
	g_hap_data = hap_data;
	hap_data->max77693 = max77693;
	hap_data->i2c = max77693->haptic;
	hap_data->pmic_i2c = max77693->i2c;
	hap_data->pdata = pdata;

	hap_data->workqueue = create_singlethread_workqueue("hap_work");
	INIT_WORK(&(hap_data->work), haptic_work);
	spin_lock_init(&(hap_data->lock));

	hap_data->pwm = pwm_request(hap_data->pdata->pwm_id, "vibrator");
	if (IS_ERR(hap_data->pwm)) {
		pr_err("[VIB] Failed to request pwm\n");
		error = -EFAULT;
		goto err_pwm_request;
	}
	pwm_config(hap_data->pwm, pdata->period / 2, pdata->period);

	vibetonz_clk_on(&pdev->dev, true);

	if (pdata->init_hw)
		pdata->init_hw();

	hap_data->regulator
		= regulator_get(NULL, pdata->regulator_name);

	if (IS_ERR(hap_data->regulator)) {
		pr_err("[VIB] Failed to get vmoter regulator.\n");
		error = -EFAULT;
		goto err_regulator_get;
	}

	/* hrtimer init */
	hrtimer_init(&hap_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	hap_data->timer.function = haptic_timer_func;

	/* timed_output_dev init*/
	hap_data->tout_dev.name = "vibrator";
	hap_data->tout_dev.get_time = haptic_get_time;
	hap_data->tout_dev.enable = haptic_enable;

#ifdef CONFIG_ANDROID_TIMED_OUTPUT
	error = timed_output_dev_register(&hap_data->tout_dev);
	if (error < 0) {
		pr_err("[VIB] Failed to register timed_output : %d\n", error);
		error = -EFAULT;
		goto err_timed_output_register;
	}
#endif
	printk(KERN_DEBUG "[VIB] timed_output device is registrated\n");
	pr_debug("[VIB] -- %s\n", __func__);

	return error;

err_timed_output_register:
	regulator_put(hap_data->regulator);
err_regulator_get:
	pwm_free(hap_data->pwm);
err_pwm_request:
	kfree(hap_data);
	g_hap_data = NULL;
	return error;
}
Exemple #10
0
static __devinit int max77665_haptic_probe(struct platform_device *pdev)
{
	struct max77665_dev *iodev = dev_get_drvdata(pdev->dev.parent);
	struct max77665_platform_data *max77665_pdata
		= dev_get_platdata(iodev->dev);
	struct max77665_haptic_platform_data *pdata
		= max77665_pdata->haptic_pdata;
	struct haptic_data *chip;
	u8 config = 0;
	int ret = 0;

	dev_info(&pdev->dev, "%s : MAX77665 Haptic Driver Loading\n", __func__);

	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
	if (!chip)
		return -ENOMEM;

	chip->dev = &pdev->dev;
	chip->client = iodev->haptic;
	chip->pmic = iodev->i2c;
	chip->period = pdata->pwm_period;
	chip->duty = pdata->pwm_duty;
	chip->motor_status = MOTOR_NORMAL;

	hrtimer_init(&chip->timer, CLOCK_MONOTONIC,
			HRTIMER_MODE_REL);
	chip->timer.function = motor_timer_func;

	mutex_init(&chip->haptic_mutex);
	INIT_WORK(&chip->motor_work, motor_work_func);
	INIT_DELAYED_WORK(&chip->disable_work, motor_disable_work_func);
	chip->motor_queue = create_singlethread_workqueue("motor");
	chip->pwm = pwm_request(pdata->pwm_channel_id, "vibrator");
	if (IS_ERR(chip->pwm)) {
		pr_err("[VIB] Failed to request pwm\n");
		ret = -EFAULT;
		goto err_pwm;
	}
	pwm_config(chip->pwm, chip->period / 2, chip->period);

	/* max77693_haptic_init */
	if (pdata->type == MAX77665_HAPTIC_LRA)
		config |= 1<<7;
	if (pdata->mode == MAX77665_INTERNAL_MODE)
		config |= 1<<5;
	config |= pdata->pwm_divisor;
	ret = max77665_write_reg(chip->client,
				 MAX77665_HAPTIC_REG_CONFIG2, config);
	/* init done */
#if !defined(CONFIG_MACH_M040) && !defined(CONFIG_MACH_M41)
	/*comment the function call for better performance*/
	haptic_clk_on(chip->dev, true);
#endif
	chip->name = "vibrator";
	chip->max_timeout = MAX_TIMEOUT;
	chip->tdev.name = chip->name;
	chip->tdev.get_time = haptic_get_time;
	chip->tdev.enable = haptic_enable;
	ret = timed_output_dev_register(&chip->tdev);
	if (ret < 0) {
		pr_err("[VIB] Failed to register timed_output : %d\n", ret);
		ret = -EFAULT;
		goto err_timed_output;
	}	

	platform_set_drvdata(pdev, chip);

	return 0;

err_timed_output:
	pwm_free(chip->pwm);
err_pwm:
	INIT_WORK(&chip->motor_work, NULL);
	kfree(chip);
	return ret;
}
static int pwm_backlight_probe(struct platform_device *pdev)
{
	struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
	struct platform_pwm_backlight_data defdata;
	struct backlight_properties props;
	struct backlight_device *bl;
	struct pwm_bl_data *pb;
	unsigned int max;
	int ret;

	if (!data) {
		ret = pwm_backlight_parse_dt(&pdev->dev, &defdata);
		if (ret < 0) {
			dev_err(&pdev->dev, "failed to find platform data\n");
			return ret;
		}

		data = &defdata;
	}

	if (data->init) {
		ret = data->init(&pdev->dev);
		if (ret < 0)
			return ret;
	}

	pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL);
	if (!pb) {
		dev_err(&pdev->dev, "no memory for state\n");
		ret = -ENOMEM;
		goto err_alloc;
	}

	if (data->levels) {
		max = data->levels[data->max_brightness];
		pb->levels = data->levels;
	} else
		max = data->max_brightness;

	pb->notify = data->notify;
	pb->notify_after = data->notify_after;
	pb->check_fb = data->check_fb;
	pb->exit = data->exit;
	pb->dev = &pdev->dev;

	pb->pwm = devm_pwm_get(&pdev->dev, NULL);
	if (IS_ERR(pb->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");

		pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
		if (IS_ERR(pb->pwm)) {
			dev_err(&pdev->dev, "unable to request legacy PWM\n");
			ret = PTR_ERR(pb->pwm);
			goto err_alloc;
		}
	}

	dev_dbg(&pdev->dev, "got pwm for backlight\n");

	/*
	 * The DT case will set the pwm_period_ns field to 0 and store the
	 * period, parsed from the DT, in the PWM device. For the non-DT case,
	 * set the period from platform data.
	 */
	if (data->pwm_period_ns > 0)
		pwm_set_period(pb->pwm, data->pwm_period_ns);

	pb->period = pwm_get_period(pb->pwm);
	pb->lth_brightness = data->lth_brightness * (pb->period / max);

	memset(&props, 0, sizeof(struct backlight_properties));
	props.type = BACKLIGHT_RAW;
	props.max_brightness = data->max_brightness;
	bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb,
				       &pwm_backlight_ops, &props);
	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		ret = PTR_ERR(bl);
		goto err_alloc;
	}

	if (data->dft_brightness > data->max_brightness) {
		dev_warn(&pdev->dev,
			 "invalid default brightness level: %u, using %u\n",
			 data->dft_brightness, data->max_brightness);
		data->dft_brightness = data->max_brightness;
	}

	bl->props.brightness = data->dft_brightness;
	backlight_update_status(bl);

	platform_set_drvdata(pdev, bl);
	return 0;

err_alloc:
	if (data->exit)
		data->exit(&pdev->dev);
	return ret;
}
Exemple #12
0
static int max8997_haptic_probe(struct platform_device *pdev)
{
    struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
    const struct max8997_platform_data *pdata =
        dev_get_platdata(iodev->dev);
    const struct max8997_haptic_platform_data *haptic_pdata = NULL;
    struct max8997_haptic *chip;
    struct input_dev *input_dev;
    int error;

    if (pdata)
        haptic_pdata = pdata->haptic_pdata;

    if (!haptic_pdata) {
        dev_err(&pdev->dev, "no haptic platform data\n");
        return -EINVAL;
    }

    chip = kzalloc(sizeof(struct max8997_haptic), GFP_KERNEL);
    input_dev = input_allocate_device();
    if (!chip || !input_dev) {
        dev_err(&pdev->dev, "unable to allocate memory\n");
        error = -ENOMEM;
        goto err_free_mem;
    }

    INIT_WORK(&chip->work, max8997_haptic_play_effect_work);
    mutex_init(&chip->mutex);

    chip->client = iodev->haptic;
    chip->dev = &pdev->dev;
    chip->input_dev = input_dev;
    chip->pwm_period = haptic_pdata->pwm_period;
    chip->type = haptic_pdata->type;
    chip->mode = haptic_pdata->mode;
    chip->pwm_divisor = haptic_pdata->pwm_divisor;

    switch (chip->mode) {
    case MAX8997_INTERNAL_MODE:
        chip->internal_mode_pattern =
            haptic_pdata->internal_mode_pattern;
        chip->pattern_cycle = haptic_pdata->pattern_cycle;
        chip->pattern_signal_period =
            haptic_pdata->pattern_signal_period;
        break;

    case MAX8997_EXTERNAL_MODE:
        chip->pwm = pwm_request(haptic_pdata->pwm_channel_id,
                                "max8997-haptic");
        if (IS_ERR(chip->pwm)) {
            error = PTR_ERR(chip->pwm);
            dev_err(&pdev->dev,
                    "unable to request PWM for haptic, error: %d\n",
                    error);
            goto err_free_mem;
        }
        break;

    default:
        dev_err(&pdev->dev,
                "Invalid chip mode specified (%d)\n", chip->mode);
        error = -EINVAL;
        goto err_free_mem;
    }

    chip->regulator = regulator_get(&pdev->dev, "inmotor");
    if (IS_ERR(chip->regulator)) {
        error = PTR_ERR(chip->regulator);
        dev_err(&pdev->dev,
                "unable to get regulator, error: %d\n",
                error);
        goto err_free_pwm;
    }

    input_dev->name = "max8997-haptic";
    input_dev->id.version = 1;
    input_dev->dev.parent = &pdev->dev;
    input_dev->close = max8997_haptic_close;
    input_set_drvdata(input_dev, chip);
    input_set_capability(input_dev, EV_FF, FF_RUMBLE);

    error = input_ff_create_memless(input_dev, NULL,
                                    max8997_haptic_play_effect);
    if (error) {
        dev_err(&pdev->dev,
                "unable to create FF device, error: %d\n",
                error);
        goto err_put_regulator;
    }

    error = input_register_device(input_dev);
    if (error) {
        dev_err(&pdev->dev,
                "unable to register input device, error: %d\n",
                error);
        goto err_destroy_ff;
    }

    platform_set_drvdata(pdev, chip);
    return 0;

err_destroy_ff:
    input_ff_destroy(input_dev);
err_put_regulator:
    regulator_put(chip->regulator);
err_free_pwm:
    if (chip->mode == MAX8997_EXTERNAL_MODE)
        pwm_free(chip->pwm);
err_free_mem:
    input_free_device(input_dev);
    kfree(chip);

    return error;
}
static int __init pwm_regulator_probe(struct platform_device *pdev)
{
	struct pwm_platform_data *pdata = pdev->dev.platform_data;
	struct pwm_regulator_board *pwm_pdev;
	struct of_regulator_match *pwm_reg_matches = NULL;
	struct regulator_init_data *reg_data;
	struct regulator_config config = { };
	const char *rail_name = NULL;
	struct regulator_dev *pwm_rdev;
	int ret, i = 0;
	struct regulator *dc;

	pwm_pdev = devm_kzalloc(&pdev->dev, sizeof(*pwm_pdev),
					GFP_KERNEL);
	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata),
					GFP_KERNEL);

	if (pdev->dev.of_node)
		pwm_pdev = pwm_regulator_parse_dt(pdev, &pwm_reg_matches);

	if (!pwm_pdev) {
		dev_err(&pdev->dev, "Platform data not found\n");
		return -EINVAL;
	}

	if (!pwm_pdev->pwm_init_vol)
		pdata->pwm_voltage = 1100000;	/* default 1.1v*/
	else
		pdata->pwm_voltage = pwm_pdev->pwm_init_vol;

	if (!pwm_pdev->pwm_max_vol)
		pdata->max_uV = 1400000;
	else
		pdata->max_uV = pwm_pdev->pwm_max_vol;

	if (!pwm_pdev->pwm_min_vol)
		pdata->min_uV = 1000000;
	else
		pdata->min_uV = pwm_pdev->pwm_min_vol;

	if (pwm_pdev->pwm_suspend_vol < pwm_pdev->pwm_min_vol)
		pdata->suspend_voltage = pwm_pdev->pwm_min_vol;
	else if (pwm_pdev->pwm_suspend_vol > pwm_pdev->pwm_max_vol)
		pdata->suspend_voltage = pwm_pdev->pwm_max_vol;
	else
		pdata->suspend_voltage = pwm_pdev->pwm_suspend_vol;

	pdata->pwm_voltage_map = pwm_pdev->pwm_voltage_map;
	pdata->pwm_id = pwm_pdev->pwm_id;
	pdata->coefficient = pwm_pdev->pwm_coefficient;
	pdata->pwm_vol_map_count = pwm_pdev->pwm_vol_map_count;

	pdata->pwm = devm_pwm_get(&pdev->dev, NULL);
	if (IS_ERR(pdata->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");

		pdata->pwm = pwm_request(pdata->pwm_id, "pwm-regulator");
		if (IS_ERR(pdata->pwm)) {
			dev_err(&pdev->dev, "unable to request legacy PWM\n");
			ret = PTR_ERR(pdata->pwm);
			goto err;
		}
	}
	if (pdata->pwm_period_ns > 0)
		pwm_set_period(pdata->pwm, pdata->pwm_period_ns);

	pdata->period = pwm_get_period(pdata->pwm);

	mutex_init(&pdata->mutex_pwm);

	if (pwm_pdev) {
		pdata->num_regulators = pwm_pdev->num_regulators;
		pdata->rdev = kcalloc(pdata->num_regulators, sizeof(struct regulator_dev *), GFP_KERNEL);
		if (!pdata->rdev) {
			return -ENOMEM;
		}
		/* Instantiate the regulators */
		for (i = 0; i < pdata->num_regulators; i++) {
		reg_data = pwm_pdev->pwm_init_data[i];
		if (!reg_data)
			continue;
		config.dev = &pdev->dev;
		config.driver_data = pdata;
		if (&pdev->dev.of_node)
			config.of_node = pwm_pdev->of_node[i];
		if (reg_data && reg_data->constraints.name)
				rail_name = reg_data->constraints.name;
			else
				rail_name = regulators[i].name;
			reg_data->supply_regulator = rail_name;

		config.init_data = reg_data;

		pwm_rdev = regulator_register(&regulators[i], &config);
		if (IS_ERR(pwm_rdev)) {
			printk("failed to register %d regulator\n", i);
		goto err;
		}
		pdata->rdev[i] = pwm_rdev;

		/*********set pwm vol by defult***********/
		dc = regulator_get(NULL, rail_name);
		regulator_set_voltage(dc, pdata->pwm_voltage, pdata->pwm_voltage);
		regulator_put(dc);
		/**************************************/
		}
	}
	return 0;
err:
	printk("%s:error\n", __func__);
	return ret;

}
static int pwm_backlight_probe(struct platform_device *pdev)
{
	struct backlight_properties props;
	struct platform_pwm_backlight_data *data = NULL;
	struct backlight_device *bl;
	struct pwm_bl_data *pb;
	const char *pwm_request_label = NULL;
	int ret;
	int bl_delay_on = 0;
	printk("[BACKLIGHT] %s : %d\n", __func__, __LINE__);
	if (pdev->dev.platform_data)
		data = pdev->dev.platform_data;

	else if (pdev->dev.of_node) {
		u32 val;
		data = kzalloc(sizeof(struct platform_pwm_backlight_data),
				GFP_KERNEL);
		if (!data)
			return -ENOMEM;

		if (of_property_read_u32(pdev->dev.of_node, "pwm-id", &val)) {
			ret = -EINVAL;
			goto err_read;
		}
		data->pwm_id = val;

		if (of_property_read_u32(pdev->dev.of_node,
				"max-brightness", &val)) {
			ret = -EINVAL;
			goto err_read;
		}
		data->max_brightness = val;

		if (of_property_read_u32(pdev->dev.of_node,
				"dft-brightness", &val)) {
			ret = -EINVAL;
			goto err_read;
		}
		data->dft_brightness = val;

		if (of_property_read_u32(pdev->dev.of_node,
				"polarity", &val)) {
			ret = -EINVAL;
			goto err_read;
		}
		data->polarity = val;

		if (of_property_read_u32(pdev->dev.of_node,
				"pwm-period-ns", &val)) {
			ret = -EINVAL;
			goto err_read;
		}
		data->pwm_period_ns = val;

		if (of_property_read_string(pdev->dev.of_node,
			"pwm-request-label", &pwm_request_label)) {
			ret = -EINVAL;
			goto err_read;
		}

		if (of_property_read_u32(pdev->dev.of_node,
				"bl-on-delay", &val)) {
			bl_delay_on = 0;
		} else
			bl_delay_on = val;

		if (of_property_read_u32(pdev->dev.of_node,
				"pwm_pin_name", &val)) {
			pwm_pin = -1;
		} else
			pwm_pin = val;

		if (of_property_read_u32(pdev->dev.of_node,
				"pwm_pin_reboot_func", &val)) {
			pwm_pin_reboot_func = -1;
		} else
			pwm_pin_reboot_func = val;

		pdev->dev.platform_data = data;

	}
	if (!data) {
		dev_err(&pdev->dev, "failed to find platform data\n");
		return -EINVAL;
	}

	if (data->init) {
		ret = data->init(&pdev->dev);
		if (ret < 0)
			return ret;
	}

	pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL);
	if (!pb) {
		dev_err(&pdev->dev, "no memory for state\n");
		ret = -ENOMEM;
		goto err_alloc;
	}

	pb->period = data->pwm_period_ns;

	pb->notify = data->notify;
	pb->notify_after = data->notify_after;
	pb->check_fb = data->check_fb;
	pb->lth_brightness = data->lth_brightness *
		(data->pwm_period_ns / data->max_brightness);
	pb->dev = &pdev->dev;
	if (pdev->dev.of_node)
		pb->pwm = pwm_request(data->pwm_id, pwm_request_label);
	else
		pb->pwm = pwm_request(data->pwm_id, "backlight");

	if (IS_ERR(pb->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM for backlight\n");
		ret = PTR_ERR(pb->pwm);
		goto err_alloc;
	} else
		dev_dbg(&pdev->dev, "got pwm for backlight\n");

	memset(&props, 0, sizeof(struct backlight_properties));
	props.type = BACKLIGHT_RAW;
	props.max_brightness = data->max_brightness;
	//bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb,
	//			       &pwm_backlight_ops, &props);

	bl = backlight_device_register("panel", &pdev->dev, pb,
				       &pwm_backlight_ops, &props);

	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		ret = PTR_ERR(bl);
		goto err_bl;
	}

	bl->props.brightness = data->dft_brightness;
	pwm_set_polarity(pb->pwm, data->polarity);

	pr_info("pwm_backlight_probe bl-delay-on %d\r\n", bl_delay_on);
	pr_info("pwm_backlight_probe pwm_pin  %d\r\n", pwm_pin);
	pr_info("pwm_backlight_probe pwm_pin_reboot_func %d\r\n", pwm_pin_reboot_func);

	if (bl_delay_on == 0)
		backlight_update_status(bl);
	else {
		INIT_DELAYED_WORK(&(pb->bl_delay_on_work), bl_delay_on_func);
		schedule_delayed_work(&(pb->bl_delay_on_work),
			msecs_to_jiffies(bl_delay_on));
	}

	platform_set_drvdata(pdev, bl);
#ifdef CONFIG_BACKLIGHT_USE_EARLYSUSPEND
	pb->bd_early_suspend.suspend = backlight_driver_early_suspend;
	pb->bd_early_suspend.resume = backlight_driver_late_resume;
	pb->bd_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN;
	register_early_suspend(&pb->bd_early_suspend);
#endif

	printk("[BACKLIGHT] %s : %d\n", __func__, __LINE__);
	return 0;

err_bl:
	pwm_free(pb->pwm);
err_alloc:
	if (data->exit)
		data->exit(&pdev->dev);
err_read:
	if (pdev->dev.of_node)
		kfree(data);
	return ret;
}
Exemple #15
0
static int pm8058_led_probe(struct platform_device *pdev)
{
	struct pm8058_led_platform_data *pdata;
	struct pm8058_led_data *ldata;
	int i, ret;

	ret = -ENOMEM;

	pdata = pdev->dev.platform_data;

	if (pdata == NULL) {
		LED_ERR_LOG("%s: platform data is NULL\n", __func__);
		return -ENODEV;
	}

	if (!pdata->num_leds) {
		LED_ERR_LOG("%s: LED num is 0\n", __func__);
		return 0;
	}

	ldata = kzalloc(sizeof(struct pm8058_led_data)
			* pdata->num_leds, GFP_KERNEL);
	if (ldata == NULL) {
		ret = -ENOMEM;
		LED_ERR_LOG("%s: failed on allocate ldata\n", __func__);
		goto err_exit;
	}

	dev_set_drvdata(&pdev->dev, ldata);

	wake_lock_init(&pmic_led_wake_lock, WAKE_LOCK_SUSPEND, "pmic_led");

	g_led_work_queue = create_workqueue("led");
	if (!g_led_work_queue)
		goto err_create_work_queue;

	for (i = 0; i < 64; i++)
		duties[i] = pdata->duties[i];

	for (i = 0; i < pdata->num_leds; i++) {
		ldata[i].led_config = pdata->led_config + i;
		ldata[i].ldev.name = pdata->led_config[i].name;
		ldata[i].bank = pdata->led_config[i].bank;
		ldata[i].flags =  pdata->led_config[i].flags;
		ldata[i].pwm_size =  pdata->led_config[i].pwm_size;
		ldata[i].clk =  pdata->led_config[i].clk;
		ldata[i].pre_div =  pdata->led_config[i].pre_div;
		ldata[i].pre_div_exp =  pdata->led_config[i].pre_div_exp;
		ldata[i].pwm_value =  pdata->led_config[i].pwm_value;
		ldata[i].period_us =  pdata->led_config[i].period_us;
		ldata[i].start_index =  pdata->led_config[i].start_index;
		ldata[i].duites_size =  pdata->led_config[i].duites_size;
		ldata[i].duty_time_ms =  pdata->led_config[i].duty_time_ms;
		ldata[i].lut_flag =  pdata->led_config[i].lut_flag;
		ldata[i].out_current =  pdata->led_config[i].out_current;
		switch (pdata->led_config[i].type) {
		case PM8058_LED_CURRENT:
			if (ldata[i].flags & PM8058_LED_BLINK_EN)
				INIT_DELAYED_WORK(&ldata[i].led_delayed_work,
						  led_blink_do_work);
			else
				INIT_DELAYED_WORK(&ldata[i].led_delayed_work,
						  pwm_lut_delayed_fade_out);
			ldata[i].pwm_led = pwm_request(ldata[i].bank,
						ldata[i].ldev.name);
			ldata[i].ldev.brightness_set =
					pm8058_drvx_led_brightness_set;
			break;
		case PM8058_LED_RGB:
			INIT_DELAYED_WORK(&ldata[i].led_delayed_work,
					  led_blink_do_work);
		case PM8058_LED_PWM:
			ldata[i].pwm_led = pwm_request(ldata[i].bank,
						       ldata[i].ldev.name);
			ldata[i].ldev.brightness_set =
					pm8058_pwm_led_brightness_set;
			break;
		case PM8058_LED_DRVX:
			if (ldata[i].flags & PM8058_LED_BLINK_EN)
				INIT_DELAYED_WORK(&ldata[i].led_delayed_work,
						  led_blink_do_work);
			else
				INIT_DELAYED_WORK(&ldata[i].led_delayed_work,
						  pwm_lut_delayed_fade_out);
			ldata[i].pwm_led = pwm_request(ldata[i].bank,
						ldata[i].ldev.name);
			ldata[i].ldev.brightness_set =
					pm8058_drvx_led_brightness_set;
			break;
		}

		ret = led_classdev_register(&pdev->dev, &ldata[i].ldev);
		if (ret < 0) {
			LED_ERR_LOG("%s: failed on led_classdev_register [%s]\n",
				__func__, ldata[i].ldev.name);
			goto err_register_led_cdev;
		}
	}

	for (i = 0; i < pdata->num_leds; i++) {
		if (pdata->led_config[i].type == PM8058_LED_RGB ||
		    ldata[i].flags & PM8058_LED_BLINK_EN) {
			ret = device_create_file(ldata[i].ldev.dev,
						 &dev_attr_blink);
			if (ret < 0) {
				LED_ERR_LOG("%s: Failed to create attr blink"
				       " [%d]\n", __func__, i);
				goto err_register_attr_blink;
			}
		}
	}

	for (i = 0; i < pdata->num_leds; i++) {
		if (pdata->led_config[i].type == PM8058_LED_RGB ||
		    ldata[i].flags & PM8058_LED_BLINK_EN) {
			ret = device_create_file(ldata[i].ldev.dev,
						 &dev_attr_off_timer);
			if (ret < 0) {
				LED_ERR_LOG("%s: Failed to create attr off timer"
				       " [%d]\n", __func__, i);
				goto err_register_attr_off_timer;
			}
			INIT_WORK(&ldata[i].led_work, led_work_func);
			alarm_init(&ldata[i].led_alarm,
				   ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
				   led_alarm_handler);
		}
	}

	for (i = 0; i < pdata->num_leds; i++) {
		if (ldata[i].bank < 3)
			continue;
		ret = device_create_file(ldata[i].ldev.dev, &dev_attr_currents);
		if (ret < 0) {
			LED_ERR_LOG("%s: Failed to create attr blink [%d]\n",
			       __func__, i);
			goto err_register_attr_currents;
		}
	}

#ifdef CONFIG_TOUCHSCREEN_CYPRESS_SWEEP2WAKE
	if (!strcmp(pdata->led_config[2].name, "button-backlight")) {
		sweep2wake_setleddev(&ldata[2].ldev);
		printk(KERN_INFO "[sweep2wake]: set led device %s, bank %d\n", pdata->led_config[2].name, ldata[2].bank);
	}
#endif

	return 0;

err_register_attr_currents:
	for (i--; i >= 0; i--) {
		if (ldata[i].bank < 3)
			continue;
		device_remove_file(ldata[i].ldev.dev, &dev_attr_currents);
	}
	i = pdata->num_leds;

err_register_attr_off_timer:
	for (i--; i >= 0; i--) {
		if (pdata->led_config[i].type == PM8058_LED_RGB ||
		    ldata[i].flags & PM8058_LED_BLINK_EN) {
			device_remove_file(ldata[i].ldev.dev,
					   &dev_attr_off_timer);
		}
	}
	i = pdata->num_leds;

err_register_attr_blink:
	for (i--; i >= 0; i--) {
		if (pdata->led_config[i].type == PM8058_LED_RGB ||
		    ldata[i].flags & PM8058_LED_BLINK_EN) {
			device_remove_file(ldata[i].ldev.dev, &dev_attr_blink);
		}
	}
	i = pdata->num_leds;

err_register_led_cdev:
	for (i--; i >= 0; i--) {
		switch (pdata->led_config[i].type) {
		case PM8058_LED_RGB:
		case PM8058_LED_PWM:
		case PM8058_LED_DRVX:
			pwm_free(ldata[i].pwm_led);
			break;
		}
		led_classdev_unregister(&ldata[i].ldev);
	}
	destroy_workqueue(g_led_work_queue);

err_create_work_queue:
	kfree(ldata);

err_exit:
	wake_lock_destroy(&pmic_led_wake_lock);
	return ret;
}
Exemple #16
0
static int __init star_vib_probe(struct platform_device *pdev )
{
	struct pwm_vib_platform_data*	pdata;
//	struct pwm_device*	pwm;
	int		err;

	printk("vib: %s,%s,%d\n", __FILE__, __FUNCTION__, __LINE__);

	pvib	=	kzalloc(sizeof(struct pwm_vib_data), GFP_KERNEL);
	if (!pvib) {
		dev_err(&pdev->dev, "no memory for state\n");
		err	=	-ENOMEM;
		goto	err_alloc;
	}

	pdata	=	pdev->dev.platform_data;
	if(pdata){
		pvib->dev			=	&pdev->dev;
		pvib->gpio_enable	=	pdata->enable;
		pvib->duty			=	pdata->duty_ns;
		pvib->period		=	pdata->period_ns;
		pvib->power			=	pdata->power;
	} else {
		err	=   -EBUSY;
		goto    err_exit;
	}

	if(pvib->power)
		pvib->power("vcc_motor_3v0", 1);

	gpio_request(pdata->enable, "vib_enable");
	gpio_direction_output(pdata->enable, 1);
	gpio_set_value(pdata->enable, 0);
	
	pvib->pwm	=	pwm_request(pdata->pwm_id, "vibrator");
	if (IS_ERR(pvib->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM for vibrator\n");
		err	=	PTR_ERR(pvib->pwm);
		goto	err_pwm;
	}
	else
		dev_dbg(&pdev->dev, "got pwm for vibrator\n");

	hrtimer_init(&pvib->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	pvib->timer.function	=	star_vib_timeout;

	platform_set_drvdata(pdev, pvib);

	// sysfs setup
	if (sysfs_create_group(&pvib->dev->kobj, &star_vib_group)) {
		dev_err(&pdev->dev, "failed to create sys filesystem\n");
		err	=	-ENOSYS;
		goto	err_sysfs;
	}

	pwm_config(pvib->pwm, pvib->duty, pvib->period);
	pwm_enable(pvib->pwm);

	printk("vibrator probe success\n");

	#if VIB_DEBUG 
	printk("testing vibrator\n");
	// hrtimer_start(&pvib->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
	hrtimer_start(&pvib->timer, ktime_set(0, 500 * 1000 * 1000), HRTIMER_MODE_REL);
	STAR_VIB_ENABLE();
	#endif

	return	0;

err_sysfs:
	pwm_free(pvib->pwm);
err_pwm:
err_alloc:
err_exit:
	return	err;
}
Exemple #17
0
static int __devinit tl2796_probe(struct spi_device *spi)
{
	struct s5p_lcd *lcd;
	int ret;

	lcd = kzalloc(sizeof(*lcd), GFP_KERNEL);
	if (!lcd) {
		pr_err("failed to allocate for lcd\n");
		ret = -ENOMEM;
		goto err_alloc;
	}
	mutex_init(&lcd->lock);

	spi->bits_per_word = 8;
	if (spi_setup(spi)) {
		pr_err("failed to setup spi\n");
		ret = -EINVAL;
		goto err_setup;
	}

	lcd->g_spi = spi;
	lcd->dev = &spi->dev;
	lcd->bl = 255;

	if (!spi->dev.platform_data) {
		dev_err(lcd->dev, "failed to get platform data\n");
		ret = -EINVAL;
		goto err_setup;
	}
//	lcd->data = (struct s5p_panel_data *)spi->dev.platform_data;

        //determinate of LCD type 
        lcd->lcd_type = get_lcdtype();

	ret = gpio_request(GPIO_LCD_BL_PWM, "lcd_bl_pwm");
	if (ret < 0) {
		dev_err(lcd->dev, "unable to request gpio for backlight\n");	
		return ret;
	}
	s3c_gpio_cfgpin(GPIO_LCD_BL_PWM,  (0x2 << 0));

	lcd->backlight_pwm_dev = pwm_request(0, "backlight-pwm");

	if (IS_ERR(lcd->backlight_pwm_dev)) {
		dev_err(lcd->dev, "unable to request PWM for backlight\n");		
	} else
		dev_err(lcd->dev, "got pwm for backlight\n");
		
	pwm_config(lcd->backlight_pwm_dev, (bl_freq_count*70)/100, bl_freq_count);	
	pwm_enable(lcd->backlight_pwm_dev);


	lcd->bl_dev = backlight_device_register("s5p_bl",
			&spi->dev, lcd, &s5p_bl_ops, NULL);

	if (!lcd->bl_dev) {
		dev_err(lcd->dev, "failed to register backlight\n");
		ret = -EINVAL;
		goto err_setup;
	}

	lcd->bl_dev->props.max_brightness = 255;


	lcd->lcd_dev = lcd_device_register("s5p_lcd",	&spi->dev, lcd, &s5p_lcd_ops);
	if (!lcd->lcd_dev) 
	{
		dev_err(lcd->dev, "failed to register lcd\n");
		ret = -EINVAL;
		goto err_setup_lcd;
	}

			
	// Class and device file creation 
	printk(KERN_ERR "ldi_class create\n");

	lcd->ldi_class = class_create(THIS_MODULE, "ldi_class");
	if (IS_ERR(lcd->ldi_class))
		pr_err("Failed to create class(ldi_class)!\n");
	
	lcd->ldi_dev = device_create(lcd->ldi_class, &spi->dev, 0, lcd, "ldi_dev");
	if (IS_ERR(lcd->ldi_dev))
		pr_err("Failed to create device(ldi_dev)!\n");

	if (!lcd->ldi_dev) {
		dev_err(lcd->dev, "failed to register device(ldi_dev)\n");
		ret = -EINVAL;
		goto err_setup_ldi;
	}

	
	if (device_create_file(lcd->ldi_dev, &dev_attr_update_brightness_cmd) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_update_brightness_cmd.attr.name);



	spi_set_drvdata(spi, lcd);

	tl2796_ldi_enable(lcd);

#ifdef CONFIG_FB_S3C_MDNIE
	init_mdnie_class();  //set mDNIe UI mode, Outdoormode
#endif


#ifdef CONFIG_HAS_EARLYSUSPEND
	lcd->early_suspend.suspend = tl2796_early_suspend;
	lcd->early_suspend.resume = tl2796_late_resume;
	lcd->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB - 1;
	register_early_suspend(&lcd->early_suspend);
#endif
	gprintk("tl2796_probe successfully probed\n", __func__);

	return 0;

err_setup_ldi:
	lcd_device_unregister(lcd->lcd_dev);

err_setup_lcd:
	backlight_device_unregister(lcd->bl_dev);

err_setup:
	mutex_destroy(&lcd->lock);
	kfree(lcd);

err_alloc:
	return ret;
}
Exemple #18
0
static int pwm_backlight_probe(struct platform_device *pdev)
{
	struct backlight_properties props;
	struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
	struct backlight_device *bl;
	struct pwm_bl_data *pb;
	struct edp_manager *battery_manager = NULL;
	int ret;

	if (!data) {
		dev_err(&pdev->dev, "failed to find platform data\n");
		return -EINVAL;
	}

	if (data->init) {
		ret = data->init(&pdev->dev);
		if (ret < 0)
			return ret;
	}

	pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL);
	if (!pb) {
		dev_err(&pdev->dev, "no memory for state\n");
		ret = -ENOMEM;
		goto err_alloc;
	}

	pb->period = data->pwm_period_ns;
	pb->notify = data->notify;
	pb->get_brightness = data->get_brightness;
	pb->notify_after = data->notify_after;
	pb->dft_brightness = data->dft_brightness;
	pb->check_fb = data->check_fb;
	pb->lth_brightness = data->lth_brightness *
		(data->pwm_period_ns / data->max_brightness);
	pb->dev = &pdev->dev;
	pb->display_init = data->init;
	pb->pwm_gpio = data->pwm_gpio;
	pb->edp_brightness_states = data->edp_brightness;

	ret = sysfs_create_group(&pdev->dev.kobj, &bowser_bl_attr_group);
	if (ret) {
		dev_err(&pdev->dev, "error creating sysfs entries\n");
		goto err_alloc;
	}

	pb->pwm = pwm_request(data->pwm_id, "backlight");
	if (IS_ERR(pb->pwm)) {
		dev_err(&pdev->dev, "unable to request PWM for backlight\n");
		ret = PTR_ERR(pb->pwm);
		goto err_alloc;
	} else
		dev_dbg(&pdev->dev, "got pwm for backlight\n");

	memset(&props, 0, sizeof(struct backlight_properties));
	props.type = BACKLIGHT_RAW;
	props.max_brightness = data->max_brightness;

	if (gpio_request(DSI_PANEL_BL_EN, "panel backlight") < 0) {
		printk(KERN_ERR "failed to request backlight enable gpio\n");
		goto err_alloc;
	}

	if (gpio_is_valid(pb->pwm_gpio)) {
		ret = gpio_request(pb->pwm_gpio, "disp_bl");
		if (ret)
			dev_err(&pdev->dev, "backlight gpio request failed\n");
	}

	bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb,
				       &pwm_backlight_ops, &props);
	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		ret = PTR_ERR(bl);
		goto err_bl;
	}

	pb->tegra_pwm_bl_edp_client = devm_kzalloc(&pdev->dev,
			sizeof(struct edp_client), GFP_KERNEL);
	if (IS_ERR_OR_NULL(pb->tegra_pwm_bl_edp_client)) {
		dev_err(&pdev->dev, "could not allocate edp client\n");
		return PTR_ERR(pb->tegra_pwm_bl_edp_client);
	}
	strncpy(pb->tegra_pwm_bl_edp_client->name,
			"backlight", EDP_NAME_LEN - 1);
	pb->tegra_pwm_bl_edp_client->name[EDP_NAME_LEN - 1] = '\0';
	pb->tegra_pwm_bl_edp_client->states = data->edp_states;
	pb->tegra_pwm_bl_edp_client->num_states = TEGRA_PWM_BL_EDP_NUM_STATES;
	pb->tegra_pwm_bl_edp_client->e0_index = TEGRA_PWM_BL_EDP_ZERO;
	pb->tegra_pwm_bl_edp_client->private_data = bl;
	pb->tegra_pwm_bl_edp_client->priority = EDP_MAX_PRIO + 2;
	pb->tegra_pwm_bl_edp_client->throttle = pwm_backlight_edpcb;
	pb->tegra_pwm_bl_edp_client->notify_promotion = pwm_backlight_edpcb;

	battery_manager = edp_get_manager("battery");
	if (!battery_manager) {
		dev_err(&pdev->dev, "unable to get edp manager\n");
	} else {
		ret = edp_register_client(battery_manager,
					pb->tegra_pwm_bl_edp_client);
		if (ret) {
			dev_err(&pdev->dev, "unable to register edp client\n");
		} else {
			ret = edp_update_client_request(
					pb->tegra_pwm_bl_edp_client,
						TEGRA_PWM_BL_EDP_ZERO, NULL);
			if (ret) {
				dev_err(&pdev->dev,
					"unable to set E0 EDP state\n");
				edp_unregister_client(
					pb->tegra_pwm_bl_edp_client);
			} else {
				goto edp_success;
			}
		}
	}

	devm_kfree(&pdev->dev, pb->tegra_pwm_bl_edp_client);
	pb->tegra_pwm_bl_edp_client = NULL;

edp_success:

	bl->props.brightness = data->dft_brightness;
	backlight_update_status(bl);

	if (gpio_is_valid(pb->pwm_gpio))
		gpio_free(pb->pwm_gpio);

	platform_set_drvdata(pdev, bl);
	return 0;

err_bl:
	pwm_free(pb->pwm);
err_alloc:
	if (data->exit)
		data->exit(&pdev->dev);
	return ret;
}