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/hardware.h>
  29. #include <mach/board-ams-delta.h>
  30. #include "omapfb.h"
  31. #define AMS_DELTA_DEFAULT_CONTRAST 112
  32. #define AMS_DELTA_MAX_CONTRAST 0x00FF
  33. #define AMS_DELTA_LCD_POWER 0x0100
  34. /* LCD class device section */
  35. static int ams_delta_lcd;
  36. static int ams_delta_lcd_set_power(struct lcd_device *dev, int power)
  37. {
  38. if (power == FB_BLANK_UNBLANK) {
  39. if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER)) {
  40. omap_writeb(ams_delta_lcd & AMS_DELTA_MAX_CONTRAST,
  41. OMAP_PWL_ENABLE);
  42. omap_writeb(1, OMAP_PWL_CLK_ENABLE);
  43. ams_delta_lcd |= AMS_DELTA_LCD_POWER;
  44. }
  45. } else {
  46. if (ams_delta_lcd & AMS_DELTA_LCD_POWER) {
  47. omap_writeb(0, OMAP_PWL_ENABLE);
  48. omap_writeb(0, OMAP_PWL_CLK_ENABLE);
  49. ams_delta_lcd &= ~AMS_DELTA_LCD_POWER;
  50. }
  51. }
  52. return 0;
  53. }
  54. static int ams_delta_lcd_set_contrast(struct lcd_device *dev, int value)
  55. {
  56. if ((value >= 0) && (value <= AMS_DELTA_MAX_CONTRAST)) {
  57. omap_writeb(value, OMAP_PWL_ENABLE);
  58. ams_delta_lcd &= ~AMS_DELTA_MAX_CONTRAST;
  59. ams_delta_lcd |= value;
  60. }
  61. return 0;
  62. }
  63. #ifdef CONFIG_LCD_CLASS_DEVICE
  64. static int ams_delta_lcd_get_power(struct lcd_device *dev)
  65. {
  66. if (ams_delta_lcd & AMS_DELTA_LCD_POWER)
  67. return FB_BLANK_UNBLANK;
  68. else
  69. return FB_BLANK_POWERDOWN;
  70. }
  71. static int ams_delta_lcd_get_contrast(struct lcd_device *dev)
  72. {
  73. if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER))
  74. return 0;
  75. return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
  76. }
  77. static struct lcd_ops ams_delta_lcd_ops = {
  78. .get_power = ams_delta_lcd_get_power,
  79. .set_power = ams_delta_lcd_set_power,
  80. .get_contrast = ams_delta_lcd_get_contrast,
  81. .set_contrast = ams_delta_lcd_set_contrast,
  82. };
  83. #endif
  84. /* omapfb panel section */
  85. static const struct gpio _gpios[] = {
  86. {
  87. .gpio = AMS_DELTA_GPIO_PIN_LCD_VBLEN,
  88. .flags = GPIOF_OUT_INIT_LOW,
  89. .label = "lcd_vblen",
  90. },
  91. {
  92. .gpio = AMS_DELTA_GPIO_PIN_LCD_NDISP,
  93. .flags = GPIOF_OUT_INIT_LOW,
  94. .label = "lcd_ndisp",
  95. },
  96. };
  97. static int ams_delta_panel_init(struct lcd_panel *panel,
  98. struct omapfb_device *fbdev)
  99. {
  100. return gpio_request_array(_gpios, ARRAY_SIZE(_gpios));
  101. }
  102. static void ams_delta_panel_cleanup(struct lcd_panel *panel)
  103. {
  104. gpio_free_array(_gpios, ARRAY_SIZE(_gpios));
  105. }
  106. static int ams_delta_panel_enable(struct lcd_panel *panel)
  107. {
  108. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 1);
  109. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 1);
  110. return 0;
  111. }
  112. static void ams_delta_panel_disable(struct lcd_panel *panel)
  113. {
  114. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_VBLEN, 0);
  115. gpio_set_value(AMS_DELTA_GPIO_PIN_LCD_NDISP, 0);
  116. }
  117. static unsigned long ams_delta_panel_get_caps(struct lcd_panel *panel)
  118. {
  119. return 0;
  120. }
  121. static struct lcd_panel ams_delta_panel = {
  122. .name = "ams-delta",
  123. .config = 0,
  124. .bpp = 12,
  125. .data_lines = 16,
  126. .x_res = 480,
  127. .y_res = 320,
  128. .pixel_clock = 4687,
  129. .hsw = 3,
  130. .hfp = 1,
  131. .hbp = 1,
  132. .vsw = 1,
  133. .vfp = 0,
  134. .vbp = 0,
  135. .pcd = 0,
  136. .acb = 37,
  137. .init = ams_delta_panel_init,
  138. .cleanup = ams_delta_panel_cleanup,
  139. .enable = ams_delta_panel_enable,
  140. .disable = ams_delta_panel_disable,
  141. .get_caps = ams_delta_panel_get_caps,
  142. };
  143. /* platform driver section */
  144. static int ams_delta_panel_probe(struct platform_device *pdev)
  145. {
  146. struct lcd_device *lcd_device = NULL;
  147. #ifdef CONFIG_LCD_CLASS_DEVICE
  148. int ret;
  149. lcd_device = lcd_device_register("omapfb", &pdev->dev, NULL,
  150. &ams_delta_lcd_ops);
  151. if (IS_ERR(lcd_device)) {
  152. ret = PTR_ERR(lcd_device);
  153. dev_err(&pdev->dev, "failed to register device\n");
  154. return ret;
  155. }
  156. platform_set_drvdata(pdev, lcd_device);
  157. lcd_device->props.max_contrast = AMS_DELTA_MAX_CONTRAST;
  158. #endif
  159. ams_delta_lcd_set_contrast(lcd_device, AMS_DELTA_DEFAULT_CONTRAST);
  160. ams_delta_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
  161. omapfb_register_panel(&ams_delta_panel);
  162. return 0;
  163. }
  164. static int ams_delta_panel_remove(struct platform_device *pdev)
  165. {
  166. return 0;
  167. }
  168. static int ams_delta_panel_suspend(struct platform_device *pdev,
  169. pm_message_t mesg)
  170. {
  171. return 0;
  172. }
  173. static int ams_delta_panel_resume(struct platform_device *pdev)
  174. {
  175. return 0;
  176. }
  177. static struct platform_driver ams_delta_panel_driver = {
  178. .probe = ams_delta_panel_probe,
  179. .remove = ams_delta_panel_remove,
  180. .suspend = ams_delta_panel_suspend,
  181. .resume = ams_delta_panel_resume,
  182. .driver = {
  183. .name = "lcd_ams_delta",
  184. },
  185. };
  186. module_platform_driver(ams_delta_panel_driver);