lvds_chimei_wxga.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Copyright (c) 2012, 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 "msm_fb.h"
  13. #include <linux/pwm.h>
  14. #include <linux/mfd/pm8xxx/pm8921.h>
  15. #define LVDS_CHIMEI_PWM_FREQ_HZ 300
  16. #define LVDS_CHIMEI_PWM_PERIOD_USEC (USEC_PER_SEC / LVDS_CHIMEI_PWM_FREQ_HZ)
  17. #define LVDS_CHIMEI_PWM_LEVEL 255
  18. #define LVDS_CHIMEI_PWM_DUTY_LEVEL \
  19. (LVDS_CHIMEI_PWM_PERIOD_USEC / LVDS_CHIMEI_PWM_LEVEL)
  20. static struct lvds_panel_platform_data *cm_pdata;
  21. static struct platform_device *cm_fbpdev;
  22. static struct pwm_device *bl_lpm;
  23. static int lvds_chimei_panel_on(struct platform_device *pdev)
  24. {
  25. return 0;
  26. }
  27. static int lvds_chimei_panel_off(struct platform_device *pdev)
  28. {
  29. return 0;
  30. }
  31. static void lvds_chimei_set_backlight(struct msm_fb_data_type *mfd)
  32. {
  33. int ret;
  34. pr_debug("%s: back light level %d\n", __func__, mfd->bl_level);
  35. if (bl_lpm) {
  36. ret = pwm_config(bl_lpm, LVDS_CHIMEI_PWM_DUTY_LEVEL *
  37. mfd->bl_level, LVDS_CHIMEI_PWM_PERIOD_USEC);
  38. if (ret) {
  39. pr_err("pwm_config on lpm failed %d\n", ret);
  40. return;
  41. }
  42. if (mfd->bl_level) {
  43. ret = pwm_enable(bl_lpm);
  44. if (ret)
  45. pr_err("pwm enable/disable on lpm failed"
  46. "for bl %d\n", mfd->bl_level);
  47. } else {
  48. pwm_disable(bl_lpm);
  49. }
  50. }
  51. }
  52. static int __devinit lvds_chimei_probe(struct platform_device *pdev)
  53. {
  54. int rc = 0;
  55. if (pdev->id == 0) {
  56. cm_pdata = pdev->dev.platform_data;
  57. if (cm_pdata == NULL)
  58. pr_err("%s: no PWM gpio specified\n", __func__);
  59. return 0;
  60. }
  61. if (cm_pdata != NULL)
  62. bl_lpm = pwm_request(cm_pdata->gpio[0],
  63. "backlight");
  64. if (bl_lpm == NULL || IS_ERR(bl_lpm)) {
  65. pr_err("%s pwm_request() failed\n", __func__);
  66. bl_lpm = NULL;
  67. }
  68. pr_debug("bl_lpm = %p lpm = %d\n", bl_lpm,
  69. cm_pdata->gpio[0]);
  70. cm_fbpdev = msm_fb_add_device(pdev);
  71. if (!cm_fbpdev) {
  72. dev_err(&pdev->dev, "failed to add msm_fb device\n");
  73. rc = -ENODEV;
  74. goto probe_exit;
  75. }
  76. probe_exit:
  77. return rc;
  78. }
  79. static struct platform_driver this_driver = {
  80. .probe = lvds_chimei_probe,
  81. .driver = {
  82. .name = "lvds_chimei_wxga",
  83. },
  84. };
  85. static struct msm_fb_panel_data lvds_chimei_panel_data = {
  86. .on = lvds_chimei_panel_on,
  87. .off = lvds_chimei_panel_off,
  88. .set_backlight = lvds_chimei_set_backlight,
  89. };
  90. static struct platform_device this_device = {
  91. .name = "lvds_chimei_wxga",
  92. .id = 1,
  93. .dev = {
  94. .platform_data = &lvds_chimei_panel_data,
  95. }
  96. };
  97. static int __init lvds_chimei_wxga_init(void)
  98. {
  99. int ret;
  100. struct msm_panel_info *pinfo;
  101. if (msm_fb_detect_client("lvds_chimei_wxga"))
  102. return 0;
  103. ret = platform_driver_register(&this_driver);
  104. if (ret)
  105. return ret;
  106. pinfo = &lvds_chimei_panel_data.panel_info;
  107. pinfo->xres = 1366;
  108. pinfo->yres = 768;
  109. MSM_FB_SINGLE_MODE_PANEL(pinfo);
  110. pinfo->type = LVDS_PANEL;
  111. pinfo->pdest = DISPLAY_1;
  112. pinfo->wait_cycle = 0;
  113. pinfo->bpp = 24;
  114. pinfo->fb_num = 2;
  115. pinfo->clk_rate = 79400000;
  116. pinfo->bl_max = 255;
  117. pinfo->bl_min = 1;
  118. /*
  119. * this panel is operated by de,
  120. * vsycn and hsync are ignored
  121. */
  122. pinfo->lcdc.h_back_porch = 0;
  123. pinfo->lcdc.h_front_porch = 194;
  124. pinfo->lcdc.h_pulse_width = 40;
  125. pinfo->lcdc.v_back_porch = 0;
  126. pinfo->lcdc.v_front_porch = 38;
  127. pinfo->lcdc.v_pulse_width = 20;
  128. pinfo->lcdc.underflow_clr = 0xff;
  129. pinfo->lcdc.hsync_skew = 0;
  130. pinfo->lvds.channel_mode = LVDS_SINGLE_CHANNEL_MODE;
  131. /* Set border color, padding only for reducing active display region */
  132. pinfo->lcdc.border_clr = 0x0;
  133. pinfo->lcdc.xres_pad = 0;
  134. pinfo->lcdc.yres_pad = 0;
  135. ret = platform_device_register(&this_device);
  136. if (ret)
  137. platform_driver_unregister(&this_driver);
  138. return ret;
  139. }
  140. module_init(lvds_chimei_wxga_init);