jornada720_lcd.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 *ld)
  24. {
  25. return PPSR & PPC_LDD2 ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
  26. }
  27. static int jornada_lcd_get_contrast(struct lcd_device *ld)
  28. {
  29. int ret;
  30. if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
  31. return 0;
  32. jornada_ssp_start();
  33. if (jornada_ssp_byte(GETCONTRAST) == TXDUMMY) {
  34. ret = jornada_ssp_byte(TXDUMMY);
  35. goto success;
  36. }
  37. dev_err(&ld->dev, "failed to set contrast\n");
  38. ret = -ETIMEDOUT;
  39. success:
  40. jornada_ssp_end();
  41. return ret;
  42. }
  43. static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
  44. {
  45. int ret = 0;
  46. jornada_ssp_start();
  47. /* start by sending our set contrast cmd to mcu */
  48. if (jornada_ssp_byte(SETCONTRAST) == TXDUMMY) {
  49. /* if successful push the new value */
  50. if (jornada_ssp_byte(value) == TXDUMMY)
  51. goto success;
  52. }
  53. dev_err(&ld->dev, "failed to set contrast\n");
  54. ret = -ETIMEDOUT;
  55. success:
  56. jornada_ssp_end();
  57. return ret;
  58. }
  59. static int jornada_lcd_set_power(struct lcd_device *ld, int power)
  60. {
  61. if (power != FB_BLANK_UNBLANK) {
  62. PPSR &= ~PPC_LDD2;
  63. PPDR |= PPC_LDD2;
  64. } else {
  65. PPSR |= PPC_LDD2;
  66. }
  67. return 0;
  68. }
  69. static struct lcd_ops jornada_lcd_props = {
  70. .get_contrast = jornada_lcd_get_contrast,
  71. .set_contrast = jornada_lcd_set_contrast,
  72. .get_power = jornada_lcd_get_power,
  73. .set_power = jornada_lcd_set_power,
  74. };
  75. static int jornada_lcd_probe(struct platform_device *pdev)
  76. {
  77. struct lcd_device *lcd_device;
  78. int ret;
  79. lcd_device = devm_lcd_device_register(&pdev->dev, S1D_DEVICENAME,
  80. &pdev->dev, NULL, &jornada_lcd_props);
  81. if (IS_ERR(lcd_device)) {
  82. ret = PTR_ERR(lcd_device);
  83. dev_err(&pdev->dev, "failed to register device\n");
  84. return ret;
  85. }
  86. platform_set_drvdata(pdev, lcd_device);
  87. /* lets set our default values */
  88. jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
  89. jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
  90. /* give it some time to startup */
  91. msleep(100);
  92. return 0;
  93. }
  94. static struct platform_driver jornada_lcd_driver = {
  95. .probe = jornada_lcd_probe,
  96. .driver = {
  97. .name = "jornada_lcd",
  98. },
  99. };
  100. module_platform_driver(jornada_lcd_driver);
  101. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  102. MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
  103. MODULE_LICENSE("GPL");