jornada720_lcd.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. *
  3. * LCD driver for HP Jornada 700 series (710/720/728)
  4. * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 or any later version as published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/device.h>
  12. #include <linux/fb.h>
  13. #include <linux/kernel.h>
  14. #include <linux/lcd.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/delay.h>
  18. #include <mach/jornada720.h>
  19. #include <mach/hardware.h>
  20. #include <video/s1d13xxxfb.h>
  21. #define LCD_MAX_CONTRAST 0xff
  22. #define LCD_DEF_CONTRAST 0x80
  23. static int jornada_lcd_get_power(struct lcd_device *dev)
  24. {
  25. /* LDD2 in PPC = LCD POWER */
  26. if (PPSR & PPC_LDD2)
  27. return FB_BLANK_UNBLANK; /* PW ON */
  28. else
  29. return FB_BLANK_POWERDOWN; /* PW OFF */
  30. }
  31. static int jornada_lcd_get_contrast(struct lcd_device *dev)
  32. {
  33. int ret;
  34. if (jornada_lcd_get_power(dev) != FB_BLANK_UNBLANK)
  35. return 0;
  36. jornada_ssp_start();
  37. if (jornada_ssp_byte(GETCONTRAST) != TXDUMMY) {
  38. printk(KERN_ERR "lcd: get contrast failed\n");
  39. jornada_ssp_end();
  40. return -ETIMEDOUT;
  41. } else {
  42. ret = jornada_ssp_byte(TXDUMMY);
  43. jornada_ssp_end();
  44. return ret;
  45. }
  46. }
  47. static int jornada_lcd_set_contrast(struct lcd_device *dev, int value)
  48. {
  49. int ret;
  50. jornada_ssp_start();
  51. /* start by sending our set contrast cmd to mcu */
  52. ret = jornada_ssp_byte(SETCONTRAST);
  53. /* push the new value */
  54. if (jornada_ssp_byte(value) != TXDUMMY) {
  55. printk(KERN_ERR "lcd : set contrast failed\n");
  56. jornada_ssp_end();
  57. return -ETIMEDOUT;
  58. }
  59. /* if we get here we can assume everything went well */
  60. jornada_ssp_end();
  61. return 0;
  62. }
  63. static int jornada_lcd_set_power(struct lcd_device *dev, int power)
  64. {
  65. if (power != FB_BLANK_UNBLANK) {
  66. PPSR &= ~PPC_LDD2;
  67. PPDR |= PPC_LDD2;
  68. } else
  69. PPSR |= PPC_LDD2;
  70. return 0;
  71. }
  72. static struct lcd_ops jornada_lcd_props = {
  73. .get_contrast = jornada_lcd_get_contrast,
  74. .set_contrast = jornada_lcd_set_contrast,
  75. .get_power = jornada_lcd_get_power,
  76. .set_power = jornada_lcd_set_power,
  77. };
  78. static int jornada_lcd_probe(struct platform_device *pdev)
  79. {
  80. struct lcd_device *lcd_device;
  81. int ret;
  82. lcd_device = lcd_device_register(S1D_DEVICENAME, &pdev->dev, NULL, &jornada_lcd_props);
  83. if (IS_ERR(lcd_device)) {
  84. ret = PTR_ERR(lcd_device);
  85. printk(KERN_ERR "lcd : failed to register device\n");
  86. return ret;
  87. }
  88. platform_set_drvdata(pdev, lcd_device);
  89. /* lets set our default values */
  90. jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
  91. jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
  92. /* give it some time to startup */
  93. msleep(100);
  94. return 0;
  95. }
  96. static int jornada_lcd_remove(struct platform_device *pdev)
  97. {
  98. struct lcd_device *lcd_device = platform_get_drvdata(pdev);
  99. lcd_device_unregister(lcd_device);
  100. return 0;
  101. }
  102. static struct platform_driver jornada_lcd_driver = {
  103. .probe = jornada_lcd_probe,
  104. .remove = jornada_lcd_remove,
  105. .driver = {
  106. .name = "jornada_lcd",
  107. },
  108. };
  109. int __init jornada_lcd_init(void)
  110. {
  111. return platform_driver_register(&jornada_lcd_driver);
  112. }
  113. void __exit jornada_lcd_exit(void)
  114. {
  115. platform_driver_unregister(&jornada_lcd_driver);
  116. }
  117. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  118. MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
  119. MODULE_LICENSE("GPL");
  120. module_init(jornada_lcd_init);
  121. module_exit(jornada_lcd_exit);