From 8ca7624ab71fba2371058e03838ecf7083a0bb89 Mon Sep 17 00:00:00 2001 From: yetta_wu Date: Fri, 12 Apr 2013 23:32:12 +0800 Subject: [PATCH] display: JDI: config backlight level when kernel init 1. Remove the gpio 26 config in board-flo-pmic.c since this gpio is already config as PWM function in LK. 2. Add pwm_init function implementation. 3. Config backlight level in pm8xxx_led_probe(), and remove the pwm_request() part in panel probe function. Change-Id: I3ce71a9c792ce155bebabd80a24a8ff8fc361ae9 Signed-off-by: yetta_wu --- .../arm/mach-msm/asustek/flo/board-flo-pmic.c | 36 +++++++++++++++++- drivers/leds/leds-pm8xxx.c | 4 ++ drivers/video/msm/mipi_JDI.c | 38 ++----------------- include/linux/leds-pm8xxx.h | 1 + 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/arch/arm/mach-msm/asustek/flo/board-flo-pmic.c b/arch/arm/mach-msm/asustek/flo/board-flo-pmic.c index 9d07cb67f2b4..20dbede6fcc7 100755 --- a/arch/arm/mach-msm/asustek/flo/board-flo-pmic.c +++ b/arch/arm/mach-msm/asustek/flo/board-flo-pmic.c @@ -31,6 +31,9 @@ #include "board-flo.h" #include +#include +#include + struct pm8xxx_gpio_init { unsigned gpio; struct pm_gpio config; @@ -132,8 +135,8 @@ static struct pm8xxx_gpio_init pm8921_gpios[] __initdata = { PM8921_GPIO_OUTPUT_BUFCONF(25, 0, LOW, CMOS), /* DISP_RESET_N */ //PM8921_GPIO_OUTPUT_FUNC(26, 0, PM_GPIO_FUNC_2), /* Bl: Off, PWM mode */ //PM8921_GPIO_OUTPUT_VIN(30, 1, PM_GPIO_VIN_VPH), /* SMB349 susp line */ - /* Bl: On, PWM mode */ - PM8921_GPIO_OUTPUT_FUNC_L17(26, 1, PM_GPIO_FUNC_2), + /* Bl: On, PWM mode */ + /* remove pwm function config because bootloader have done this*/ PM8921_GPIO_OUTPUT(2, 1, HIGH), /* SLIMPORT_PWR_DWN */ PM8921_GPIO_OUTPUT(1, 0, HIGH), /* SLIMPORT_RESET_N */ PM8921_GPIO_OUTPUT_FUNC(44, 0, PM_GPIO_FUNC_2), @@ -339,11 +342,40 @@ static struct pm8xxx_led_config pm8921_led_configs[] = { }, }; +#define PWM_FREQ_HZ 300 +#define PWM_PERIOD_USEC (USEC_PER_SEC / PWM_FREQ_HZ) +#define PWM_LEVEL 255 +#define PWM_DUTY_LEVEL \ + (PWM_PERIOD_USEC / PWM_LEVEL) +#define BL_INIT_LEVEL 102 /* 255 x 40% */ + +struct pwm_device *bl_lpm; + +static void apq8064_pm8921_pwm_init(void) +{ + int ret; + pr_info("%s+\n", __func__); + + bl_lpm = pwm_request(2, "backlight"); + + ret = pwm_config(bl_lpm, PWM_DUTY_LEVEL * BL_INIT_LEVEL, + PWM_PERIOD_USEC); + if (ret) + pr_err("pwm_config on lpm failed %d\n", ret); + + ret = pwm_enable(bl_lpm); + if (ret) + pr_err("pwm enable failed for bl %d\n", BL_INIT_LEVEL); + + pr_info("%s-\n", __func__); +} + static struct pm8xxx_led_platform_data apq8064_pm8921_leds_pdata = { .led_core = &pm8921_led_core_pdata, .configs = pm8921_led_configs, .num_configs = ARRAY_SIZE(pm8921_led_configs), .use_pwm = 1, + .pwm_init = apq8064_pm8921_pwm_init, }; static struct pm8xxx_adc_amux apq8064_pm8921_adc_channels_data[] = { diff --git a/drivers/leds/leds-pm8xxx.c b/drivers/leds/leds-pm8xxx.c index 965c95566c9e..a948d30806d8 100755 --- a/drivers/leds/leds-pm8xxx.c +++ b/drivers/leds/leds-pm8xxx.c @@ -1274,6 +1274,10 @@ static int __devinit pm8xxx_led_probe(struct platform_device *pdev) } } + /* Config PWM */ + if ((pdata) && (pdata->pwm_init)) + pdata->pwm_init(); + return 0; fail_id_check: diff --git a/drivers/video/msm/mipi_JDI.c b/drivers/video/msm/mipi_JDI.c index 87f9ebed8b0d..9a38579ab55f 100644 --- a/drivers/video/msm/mipi_JDI.c +++ b/drivers/video/msm/mipi_JDI.c @@ -41,13 +41,10 @@ static int gpio_LCD_BL_EN = gpio_LCD_BL_EN_SR2; static int gpio_LCM_XRES = gpio_LCM_XRES_SR2; static bool first_cmd = true; -static bool first = true; static hw_rev hw_revision; -static unsigned gpio; -static struct pm_gpio config; static struct mipi_dsi_panel_platform_data *mipi_JDI_pdata; -static struct pwm_device *bl_lpm; +extern struct pwm_device *bl_lpm; static struct dsi_buf JDI_tx_buf; static struct dsi_buf JDI_rx_buf; @@ -256,14 +253,6 @@ static void mipi_JDI_set_backlight(struct msm_fb_data_type *mfd) pr_debug("%s: back light level %d\n", __func__, mfd->bl_level); - if (first) { - ret = pm8xxx_gpio_config(gpio, &config); - if (ret) - pr_err("%s: pm8xxx_gpio_config failed: ret=%d\n", - __func__, ret); - first = false; - } - if (bl_lpm) { if (mfd->bl_level) { if (hw_revision != 0x3) { @@ -317,14 +306,6 @@ static void mipi_JDI_set_recovery_backlight(struct msm_fb_data_type *mfd) pr_info("%s: backlight level %d\n", __func__, recovery_backlight); - if (first) { - ret = pm8xxx_gpio_config(gpio, &config); - if (ret) - pr_err("%s: pm8xxx_gpio_config failed: ret=%d\n", - __func__, ret); - first = false; - } - if (bl_lpm) { if (hw_revision != 0x3) { ret = pwm_config(bl_lpm, PWM_DUTY_LEVEL * @@ -402,11 +383,10 @@ static int __devinit mipi_JDI_lcd_probe(struct platform_device *pdev) if (mipi_JDI_pdata == NULL) { pr_err("%s.invalid platform data.\n", __func__); return -ENODEV; - } else { - bl_lpm = pwm_request(mipi_JDI_pdata->gpio[0], - "backlight"); } + /* already request bl_lpm in leds_pm8xxx.c, pm8xxx_led_probe() */ + if (bl_lpm == NULL || IS_ERR(bl_lpm)) { pr_err("%s pwm_request() failed\n", __func__); bl_lpm = NULL; @@ -423,18 +403,6 @@ static int __devinit mipi_JDI_lcd_probe(struct platform_device *pdev) gpio_LCM_XRES = gpio_LCM_XRES_SR1; } - /* set PWM config */ - gpio = gpio_PWM; - config.direction = PM_GPIO_DIR_OUT; - config.output_buffer = PM_GPIO_OUT_BUF_CMOS; - config.output_value = 0; - config.pull = PM_GPIO_PULL_NO; - config.vin_sel = PM_GPIO_VIN_L17; - config.out_strength = PM_GPIO_STRENGTH_HIGH; - config.function = PM_GPIO_FUNC_2; - config.inv_int_pol = 0; - config.disable_pin = 0; - pr_info("%s-\n", __func__); return 0; } diff --git a/include/linux/leds-pm8xxx.h b/include/linux/leds-pm8xxx.h index f6430275b5cf..07375bba8cb4 100644 --- a/include/linux/leds-pm8xxx.h +++ b/include/linux/leds-pm8xxx.h @@ -136,5 +136,6 @@ struct pm8xxx_led_platform_data { struct pm8xxx_led_config *configs; u32 num_configs; int use_pwm; + void (*pwm_init) (void); }; #endif /* __LEDS_PM8XXX_H__ */