lcd_ams_delta.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Based on drivers/video/omap/lcd_inn1510.c
  3. *
  4. * LCD panel support for the Amstrad E3 (Delta) videophone.
  5. *
  6. * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/lcd.h>
  27. #include <linux/gpio.h>
  28. #include <mach/board-ams-delta.h>
  29. #include "omapfb.h"
  30. #define AMS_DELTA_DEFAULT_CONTRAST 112
  31. #define AMS_DELTA_MAX_CONTRAST 0x00FF
  32. #define AMS_DELTA_LCD_POWER 0x0100
  33. /* LCD class device section */
  34. static int ams_delta_lcd;
  35. static int ams_delta_lcd_set_power(struct lcd_device *dev, int power)
  36. {
  37. if (power == FB_BLANK_UNBLANK) {
  38. if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER)) {
  39. omap_writeb(ams_delta_lcd & AMS_DELTA_MAX_CONTRAST,
  40. OMAP_PWL_ENABLE);
  41. omap_writeb(1, OMAP_PWL_CLK_ENABLE);
  42. ams_delta_lcd |= AMS_DELTA_LCD_POWER;
  43. }
  44. } else {
  45. if (ams_delta_lcd & AMS_DELTA_LCD_POWER) {
  46. omap_writeb(0, OMAP_PWL_ENABLE);
  47. omap_writeb(0, OMAP_PWL_CLK_ENABLE);
  48. ams_delta_lcd &= ~AMS_DELTA_LCD_POWER;
  49. }
  50. }
  51. return 0;
  52. }
  53. static int ams_delta_lcd_set_contrast(struct lcd_device *dev, int value)
  54. {
  55. if ((value >= 0) && (value <= AMS_DELTA_MAX_CONTRAST)) {
  56. omap_writeb(value, OMAP_PWL_ENABLE);
  57. ams_delta_lcd &= ~AMS_DELTA_MAX_CONTRAST;
  58. ams_delta_lcd |= value;
  59. }
  60. return 0;
  61. }
  62. #ifdef CONFIG_LCD_CLASS_DEVICE
  63. static int ams_delta_lcd_get_power(struct lcd_device *dev)
  64. {
  65. if (ams_delta_lcd & AMS_DELTA_LCD_POWER)
  66. return FB_BLANK_UNBLANK;
  67. else
  68. return FB_BLANK_POWERDOWN;
  69. }
  70. static int ams_delta_lcd_get_contrast(struct lcd_device *dev)
  71. {
  72. if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER))
  73. return 0;
  74. return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
  75. }
  76. static struct lcd_ops ams_delta_lcd_ops = {
  77. .get_power = ams_delta_lcd_get_power,
  78. .set_power = ams_delta_lcd_set_power,
  79. .get_contrast = ams_delta_lcd_get_contrast,
  80. .set_contrast = ams_delta_lcd_set_contrast,
  81. };
  82. #endif
  83. /* omapfb panel section */
  84. static const struct gpio _gpios[] = {
  85. {
  86. .gpio = AMS_DELTA_GPIO_PIN_LCD_VBLEN,
  87. .flags = GPIOF_OUT_INIT_LOW,
  88. .label = "lcd_vblen",
  89. },
  90. {
  91. .gpio = AMS_DELTA_GPIO_PIN_LCD_NDISP,
  92. .flags = GPIOF_OUT_INIT_LOW,
  93. .label = "lcd_ndisp",
  94. },
  95. };
  96. static int ams_delta_panel_init(struct lcd_panel *panel,
  97. struct omapfb_device *fbdev)
  98. {
  99. return gpio_request_array(_gpios, ARRAY_SIZE(_gpios));
  100. }
  101. static void ams_delta_panel_cleanup(struct lcd_panel *panel)
  102. {
  103. gpio_free_array(_gpios, ARRAY_SIZE(_gpios));
  104. }
  105. static int ams_delta_panel_enable(struct lcd_panel *panel)
  106. {
  107. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 1);
  108. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 1);
  109. return 0;
  110. }
  111. static void ams_delta_panel_disable(struct lcd_panel *panel)
  112. {
  113. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 0);
  114. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 0);
  115. }
  116. static unsigned long ams_delta_panel_get_caps(struct lcd_panel *panel)
  117. {
  118. return 0;
  119. }
  120. static struct lcd_panel ams_delta_panel = {
  121. .name = "ams-delta",
  122. .config = 0,
  123. .bpp = 12,
  124. .data_lines = 16,
  125. .x_res = 480,
  126. .y_res = 320,
  127. .pixel_clock = 4687,
  128. .hsw = 3,
  129. .hfp = 1,
  130. .hbp = 1,
  131. .vsw = 1,
  132. .vfp = 0,
  133. .vbp = 0,
  134. .pcd = 0,
  135. .acb = 37,
  136. .init = ams_delta_panel_init,
  137. .cleanup = ams_delta_panel_cleanup,
  138. .enable = ams_delta_panel_enable,
  139. .disable = ams_delta_panel_disable,
  140. .get_caps = ams_delta_panel_get_caps,
  141. };
  142. /* platform driver section */
  143. static int ams_delta_panel_probe(struct platform_device *pdev)
  144. {
  145. struct lcd_device *lcd_device = NULL;
  146. #ifdef CONFIG_LCD_CLASS_DEVICE
  147. int ret;
  148. lcd_device = lcd_device_register("omapfb", &pdev->dev, NULL,
  149. &ams_delta_lcd_ops);
  150. if (IS_ERR(lcd_device)) {
  151. ret = PTR_ERR(lcd_device);
  152. dev_err(&pdev->dev, "failed to register device\n");
  153. return ret;
  154. }
  155. platform_set_drvdata(pdev, lcd_device);
  156. lcd_device->props.max_contrast = AMS_DELTA_MAX_CONTRAST;
  157. #endif
  158. ams_delta_lcd_set_contrast(lcd_device, AMS_DELTA_DEFAULT_CONTRAST);
  159. ams_delta_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
  160. omapfb_register_panel(&ams_delta_panel);
  161. return 0;
  162. }
  163. static int ams_delta_panel_remove(struct platform_device *pdev)
  164. {
  165. return 0;
  166. }
  167. static int ams_delta_panel_suspend(struct platform_device *pdev,
  168. pm_message_t mesg)
  169. {
  170. return 0;
  171. }
  172. static int ams_delta_panel_resume(struct platform_device *pdev)
  173. {
  174. return 0;
  175. }
  176. static struct platform_driver ams_delta_panel_driver = {
  177. .probe = ams_delta_panel_probe,
  178. .remove = ams_delta_panel_remove,
  179. .suspend = ams_delta_panel_suspend,
  180. .resume = ams_delta_panel_resume,
  181. .driver = {
  182. .name = "lcd_ams_delta",
  183. .owner = THIS_MODULE,
  184. },
  185. };
  186. module_platform_driver(ams_delta_panel_driver);