lcdc_chimei_wxga.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* Copyright (c) 2011, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/pwm.h>
  14. #ifdef CONFIG_PMIC8058_PWM
  15. #include <linux/mfd/pmic8058.h>
  16. #include <linux/pmic8058-pwm.h>
  17. #endif
  18. #include <mach/gpio.h>
  19. #include "msm_fb.h"
  20. static struct pwm_device *bl_pwm;
  21. #define PWM_FREQ_HZ 210
  22. #define PWM_PERIOD_USEC (USEC_PER_SEC / PWM_FREQ_HZ)
  23. #define PWM_DUTY_LEVEL (PWM_PERIOD_USEC / PWM_LEVEL)
  24. #define PWM_LEVEL 15
  25. static struct msm_panel_common_pdata *cm_pdata;
  26. static struct platform_device *cm_fbpdev;
  27. static int led_pwm; /* pm8058 gpio 24, channel 0 */
  28. static int led_en; /* pm8058 gpio 1 */
  29. static int lvds_pwr_down; /* msm gpio 30 */
  30. static int chimei_bl_level = 1;
  31. static void lcdc_chimei_set_backlight(int level)
  32. {
  33. int ret;
  34. if (bl_pwm) {
  35. ret = pwm_config(bl_pwm, PWM_DUTY_LEVEL * level,
  36. PWM_PERIOD_USEC);
  37. if (ret) {
  38. pr_err("%s: pwm_config on pwm failed %d\n",
  39. __func__, ret);
  40. return;
  41. }
  42. ret = pwm_enable(bl_pwm);
  43. if (ret) {
  44. pr_err("%s: pwm_enable on pwm failed %d\n",
  45. __func__, ret);
  46. return;
  47. }
  48. }
  49. chimei_bl_level = level;
  50. }
  51. static int lcdc_chimei_panel_on(struct platform_device *pdev)
  52. {
  53. int ret;
  54. /* panel powered on here */
  55. ret = gpio_request(lvds_pwr_down, "lvds_pwr_down");
  56. if (ret == 0) {
  57. /* output, pull high to enable */
  58. gpio_direction_output(lvds_pwr_down, 1);
  59. } else {
  60. pr_err("%s: lvds_pwr_down=%d, gpio_request failed\n",
  61. __func__, lvds_pwr_down);
  62. }
  63. msleep(200);
  64. /* power on led pwm power >= 200 ms */
  65. if (chimei_bl_level == 0)
  66. chimei_bl_level = 1;
  67. lcdc_chimei_set_backlight(chimei_bl_level);
  68. msleep(10);
  69. ret = gpio_request(led_en, "led_en");
  70. if (ret == 0) {
  71. /* output, pull high */
  72. gpio_direction_output(led_en, 1);
  73. } else {
  74. pr_err("%s: led_en=%d, gpio_request failed\n",
  75. __func__, led_en);
  76. }
  77. return ret;
  78. }
  79. static int lcdc_chimei_panel_off(struct platform_device *pdev)
  80. {
  81. /* pull low to disable */
  82. gpio_set_value_cansleep(led_en, 0);
  83. gpio_free(led_en);
  84. msleep(10);
  85. lcdc_chimei_set_backlight(0);
  86. msleep(200);
  87. /* power off led pwm power >= 200 ms */
  88. /* pull low to shut down lvds */
  89. gpio_set_value_cansleep(lvds_pwr_down, 0);
  90. gpio_free(lvds_pwr_down);
  91. /* panel power off here */
  92. return 0;
  93. }
  94. static void lcdc_chimei_panel_backlight(struct msm_fb_data_type *mfd)
  95. {
  96. lcdc_chimei_set_backlight(mfd->bl_level);
  97. }
  98. static int __devinit chimei_probe(struct platform_device *pdev)
  99. {
  100. int rc = 0;
  101. if (pdev->id == 0) {
  102. cm_pdata = pdev->dev.platform_data;
  103. if (cm_pdata == NULL) {
  104. pr_err("%s: no PWM gpio specified\n", __func__);
  105. return 0;
  106. }
  107. led_pwm = cm_pdata->gpio_num[0];
  108. led_en = cm_pdata->gpio_num[1];
  109. lvds_pwr_down = cm_pdata->gpio_num[2];
  110. pr_info("%s: led_pwm=%d led_en=%d lvds_pwr_down=%d\n",
  111. __func__, led_pwm, led_en, lvds_pwr_down);
  112. return 0;
  113. }
  114. if (cm_pdata == NULL)
  115. return -ENODEV;
  116. bl_pwm = pwm_request(led_pwm, "backlight");
  117. if (bl_pwm == NULL || IS_ERR(bl_pwm)) {
  118. pr_err("%s pwm_request() failed\n", __func__);
  119. bl_pwm = NULL;
  120. }
  121. cm_fbpdev = msm_fb_add_device(pdev);
  122. if (!cm_fbpdev) {
  123. dev_err(&pdev->dev, "failed to add msm_fb device\n");
  124. rc = -ENODEV;
  125. goto probe_exit;
  126. }
  127. probe_exit:
  128. return rc;
  129. }
  130. static struct platform_driver this_driver = {
  131. .probe = chimei_probe,
  132. .driver = {
  133. .name = "lcdc_chimei_lvds_wxga",
  134. },
  135. };
  136. static struct msm_fb_panel_data chimei_panel_data = {
  137. .on = lcdc_chimei_panel_on,
  138. .off = lcdc_chimei_panel_off,
  139. .set_backlight = lcdc_chimei_panel_backlight,
  140. };
  141. static struct platform_device this_device = {
  142. .name = "lcdc_chimei_lvds_wxga",
  143. .id = 1,
  144. .dev = {
  145. .platform_data = &chimei_panel_data,
  146. }
  147. };
  148. static int __init lcdc_chimei_lvds_panel_init(void)
  149. {
  150. int ret;
  151. struct msm_panel_info *pinfo;
  152. if (msm_fb_detect_client("lcdc_chimei_wxga"))
  153. return 0;
  154. ret = platform_driver_register(&this_driver);
  155. if (ret)
  156. return ret;
  157. pinfo = &chimei_panel_data.panel_info;
  158. pinfo->xres = 1366;
  159. pinfo->yres = 768;
  160. MSM_FB_SINGLE_MODE_PANEL(pinfo);
  161. pinfo->type = LCDC_PANEL;
  162. pinfo->pdest = DISPLAY_1;
  163. pinfo->wait_cycle = 0;
  164. pinfo->bpp = 18;
  165. pinfo->fb_num = 2;
  166. pinfo->clk_rate = 69300000;
  167. pinfo->bl_max = PWM_LEVEL;
  168. pinfo->bl_min = 1;
  169. /*
  170. * this panel is operated by de,
  171. * vsycn and hsync are ignored
  172. */
  173. pinfo->lcdc.h_back_porch = 108;
  174. pinfo->lcdc.h_front_porch = 0;
  175. pinfo->lcdc.h_pulse_width = 1;
  176. pinfo->lcdc.v_back_porch = 0;
  177. pinfo->lcdc.v_front_porch = 16;
  178. pinfo->lcdc.v_pulse_width = 1;
  179. pinfo->lcdc.border_clr = 0;
  180. pinfo->lcdc.underflow_clr = 0xff;
  181. pinfo->lcdc.hsync_skew = 0;
  182. ret = platform_device_register(&this_device);
  183. if (ret)
  184. platform_driver_unregister(&this_driver);
  185. return ret;
  186. }
  187. module_init(lcdc_chimei_lvds_panel_init);