lcd_ams_delta.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Based on drivers/video/omap/lcd_inn1510.c
  4. *
  5. * LCD panel support for the Amstrad E3 (Delta) videophone.
  6. *
  7. * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/io.h>
  12. #include <linux/delay.h>
  13. #include <linux/gpio/consumer.h>
  14. #include <linux/lcd.h>
  15. #include <linux/soc/ti/omap1-io.h>
  16. #include "omapfb.h"
  17. #define AMS_DELTA_DEFAULT_CONTRAST 112
  18. #define AMS_DELTA_MAX_CONTRAST 0x00FF
  19. #define AMS_DELTA_LCD_POWER 0x0100
  20. /* LCD class device section */
  21. static int ams_delta_lcd;
  22. static struct gpio_desc *gpiod_vblen;
  23. static struct gpio_desc *gpiod_ndisp;
  24. static int ams_delta_lcd_set_power(struct lcd_device *dev, int power)
  25. {
  26. if (power == LCD_POWER_ON) {
  27. if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER)) {
  28. omap_writeb(ams_delta_lcd & AMS_DELTA_MAX_CONTRAST,
  29. OMAP_PWL_ENABLE);
  30. omap_writeb(1, OMAP_PWL_CLK_ENABLE);
  31. ams_delta_lcd |= AMS_DELTA_LCD_POWER;
  32. }
  33. } else {
  34. if (ams_delta_lcd & AMS_DELTA_LCD_POWER) {
  35. omap_writeb(0, OMAP_PWL_ENABLE);
  36. omap_writeb(0, OMAP_PWL_CLK_ENABLE);
  37. ams_delta_lcd &= ~AMS_DELTA_LCD_POWER;
  38. }
  39. }
  40. return 0;
  41. }
  42. static int ams_delta_lcd_set_contrast(struct lcd_device *dev, int value)
  43. {
  44. if ((value >= 0) && (value <= AMS_DELTA_MAX_CONTRAST)) {
  45. omap_writeb(value, OMAP_PWL_ENABLE);
  46. ams_delta_lcd &= ~AMS_DELTA_MAX_CONTRAST;
  47. ams_delta_lcd |= value;
  48. }
  49. return 0;
  50. }
  51. #ifdef CONFIG_LCD_CLASS_DEVICE
  52. static int ams_delta_lcd_get_power(struct lcd_device *dev)
  53. {
  54. if (ams_delta_lcd & AMS_DELTA_LCD_POWER)
  55. return LCD_POWER_ON;
  56. else
  57. return LCD_POWER_OFF;
  58. }
  59. static int ams_delta_lcd_get_contrast(struct lcd_device *dev)
  60. {
  61. if (!(ams_delta_lcd & AMS_DELTA_LCD_POWER))
  62. return 0;
  63. return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
  64. }
  65. static const struct lcd_ops ams_delta_lcd_ops = {
  66. .get_power = ams_delta_lcd_get_power,
  67. .set_power = ams_delta_lcd_set_power,
  68. .get_contrast = ams_delta_lcd_get_contrast,
  69. .set_contrast = ams_delta_lcd_set_contrast,
  70. };
  71. #endif
  72. /* omapfb panel section */
  73. static int ams_delta_panel_enable(struct lcd_panel *panel)
  74. {
  75. gpiod_set_value(gpiod_ndisp, 1);
  76. gpiod_set_value(gpiod_vblen, 1);
  77. return 0;
  78. }
  79. static void ams_delta_panel_disable(struct lcd_panel *panel)
  80. {
  81. gpiod_set_value(gpiod_vblen, 0);
  82. gpiod_set_value(gpiod_ndisp, 0);
  83. }
  84. static struct lcd_panel ams_delta_panel = {
  85. .name = "ams-delta",
  86. .config = 0,
  87. .bpp = 12,
  88. .data_lines = 16,
  89. .x_res = 480,
  90. .y_res = 320,
  91. .pixel_clock = 4687,
  92. .hsw = 3,
  93. .hfp = 1,
  94. .hbp = 1,
  95. .vsw = 1,
  96. .vfp = 0,
  97. .vbp = 0,
  98. .pcd = 0,
  99. .acb = 37,
  100. .enable = ams_delta_panel_enable,
  101. .disable = ams_delta_panel_disable,
  102. };
  103. /* platform driver section */
  104. static int ams_delta_panel_probe(struct platform_device *pdev)
  105. {
  106. struct lcd_device *lcd_device = NULL;
  107. gpiod_vblen = devm_gpiod_get(&pdev->dev, "vblen", GPIOD_OUT_LOW);
  108. if (IS_ERR(gpiod_vblen))
  109. return dev_err_probe(&pdev->dev, PTR_ERR(gpiod_vblen),
  110. "VBLEN GPIO request failed\n");
  111. gpiod_ndisp = devm_gpiod_get(&pdev->dev, "ndisp", GPIOD_OUT_LOW);
  112. if (IS_ERR(gpiod_ndisp))
  113. return dev_err_probe(&pdev->dev, PTR_ERR(gpiod_ndisp),
  114. "NDISP GPIO request failed\n");
  115. #ifdef CONFIG_LCD_CLASS_DEVICE
  116. lcd_device = lcd_device_register("omapfb", &pdev->dev, NULL,
  117. &ams_delta_lcd_ops);
  118. if (IS_ERR(lcd_device)) {
  119. int ret = PTR_ERR(lcd_device);
  120. dev_err(&pdev->dev, "failed to register device\n");
  121. return ret;
  122. }
  123. platform_set_drvdata(pdev, lcd_device);
  124. lcd_device->props.max_contrast = AMS_DELTA_MAX_CONTRAST;
  125. #endif
  126. ams_delta_lcd_set_contrast(lcd_device, AMS_DELTA_DEFAULT_CONTRAST);
  127. ams_delta_lcd_set_power(lcd_device, LCD_POWER_ON);
  128. omapfb_register_panel(&ams_delta_panel);
  129. return 0;
  130. }
  131. static struct platform_driver ams_delta_panel_driver = {
  132. .probe = ams_delta_panel_probe,
  133. .driver = {
  134. .name = "lcd_ams_delta",
  135. },
  136. };
  137. module_platform_driver(ams_delta_panel_driver);
  138. MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
  139. MODULE_DESCRIPTION("LCD panel support for the Amstrad E3 (Delta) videophone");
  140. MODULE_LICENSE("GPL");