kb3886_bl.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Backlight Driver for the KB3886 Backlight
  3. *
  4. * Copyright (c) 2007-2008 Claudio Nieder
  5. *
  6. * Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mutex.h>
  18. #include <linux/fb.h>
  19. #include <linux/backlight.h>
  20. #include <linux/delay.h>
  21. #include <linux/dmi.h>
  22. #define KB3886_PARENT 0x64
  23. #define KB3886_IO 0x60
  24. #define KB3886_ADC_DAC_PWM 0xC4
  25. #define KB3886_PWM0_WRITE 0x81
  26. #define KB3886_PWM0_READ 0x41
  27. static DEFINE_MUTEX(bl_mutex);
  28. static void kb3886_bl_set_intensity(int intensity)
  29. {
  30. mutex_lock(&bl_mutex);
  31. intensity = intensity&0xff;
  32. outb(KB3886_ADC_DAC_PWM, KB3886_PARENT);
  33. usleep_range(10000, 11000);
  34. outb(KB3886_PWM0_WRITE, KB3886_IO);
  35. usleep_range(10000, 11000);
  36. outb(intensity, KB3886_IO);
  37. mutex_unlock(&bl_mutex);
  38. }
  39. struct kb3886bl_machinfo {
  40. int max_intensity;
  41. int default_intensity;
  42. int limit_mask;
  43. void (*set_bl_intensity)(int intensity);
  44. };
  45. static struct kb3886bl_machinfo kb3886_bl_machinfo = {
  46. .max_intensity = 0xff,
  47. .default_intensity = 0xa0,
  48. .limit_mask = 0x7f,
  49. .set_bl_intensity = kb3886_bl_set_intensity,
  50. };
  51. static struct platform_device kb3886bl_device = {
  52. .name = "kb3886-bl",
  53. .dev = {
  54. .platform_data = &kb3886_bl_machinfo,
  55. },
  56. .id = -1,
  57. };
  58. static struct platform_device *devices[] __initdata = {
  59. &kb3886bl_device,
  60. };
  61. /*
  62. * Back to driver
  63. */
  64. static int kb3886bl_intensity;
  65. static struct backlight_device *kb3886_backlight_device;
  66. static struct kb3886bl_machinfo *bl_machinfo;
  67. static unsigned long kb3886bl_flags;
  68. #define KB3886BL_SUSPENDED 0x01
  69. static struct dmi_system_id kb3886bl_device_table[] __initdata = {
  70. {
  71. .ident = "Sahara Touch-iT",
  72. .matches = {
  73. DMI_MATCH(DMI_SYS_VENDOR, "SDV"),
  74. DMI_MATCH(DMI_PRODUCT_NAME, "iTouch T201"),
  75. },
  76. },
  77. { }
  78. };
  79. static int kb3886bl_send_intensity(struct backlight_device *bd)
  80. {
  81. int intensity = bd->props.brightness;
  82. if (bd->props.power != FB_BLANK_UNBLANK)
  83. intensity = 0;
  84. if (bd->props.fb_blank != FB_BLANK_UNBLANK)
  85. intensity = 0;
  86. if (kb3886bl_flags & KB3886BL_SUSPENDED)
  87. intensity = 0;
  88. bl_machinfo->set_bl_intensity(intensity);
  89. kb3886bl_intensity = intensity;
  90. return 0;
  91. }
  92. #ifdef CONFIG_PM_SLEEP
  93. static int kb3886bl_suspend(struct device *dev)
  94. {
  95. struct backlight_device *bd = dev_get_drvdata(dev);
  96. kb3886bl_flags |= KB3886BL_SUSPENDED;
  97. backlight_update_status(bd);
  98. return 0;
  99. }
  100. static int kb3886bl_resume(struct device *dev)
  101. {
  102. struct backlight_device *bd = dev_get_drvdata(dev);
  103. kb3886bl_flags &= ~KB3886BL_SUSPENDED;
  104. backlight_update_status(bd);
  105. return 0;
  106. }
  107. #endif
  108. static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops, kb3886bl_suspend, kb3886bl_resume);
  109. static int kb3886bl_get_intensity(struct backlight_device *bd)
  110. {
  111. return kb3886bl_intensity;
  112. }
  113. static const struct backlight_ops kb3886bl_ops = {
  114. .get_brightness = kb3886bl_get_intensity,
  115. .update_status = kb3886bl_send_intensity,
  116. };
  117. static int kb3886bl_probe(struct platform_device *pdev)
  118. {
  119. struct backlight_properties props;
  120. struct kb3886bl_machinfo *machinfo = dev_get_platdata(&pdev->dev);
  121. bl_machinfo = machinfo;
  122. if (!machinfo->limit_mask)
  123. machinfo->limit_mask = -1;
  124. memset(&props, 0, sizeof(struct backlight_properties));
  125. props.type = BACKLIGHT_RAW;
  126. props.max_brightness = machinfo->max_intensity;
  127. kb3886_backlight_device = devm_backlight_device_register(&pdev->dev,
  128. "kb3886-bl", &pdev->dev,
  129. NULL, &kb3886bl_ops,
  130. &props);
  131. if (IS_ERR(kb3886_backlight_device))
  132. return PTR_ERR(kb3886_backlight_device);
  133. platform_set_drvdata(pdev, kb3886_backlight_device);
  134. kb3886_backlight_device->props.power = FB_BLANK_UNBLANK;
  135. kb3886_backlight_device->props.brightness = machinfo->default_intensity;
  136. backlight_update_status(kb3886_backlight_device);
  137. return 0;
  138. }
  139. static struct platform_driver kb3886bl_driver = {
  140. .probe = kb3886bl_probe,
  141. .driver = {
  142. .name = "kb3886-bl",
  143. .pm = &kb3886bl_pm_ops,
  144. },
  145. };
  146. static int __init kb3886_init(void)
  147. {
  148. if (!dmi_check_system(kb3886bl_device_table))
  149. return -ENODEV;
  150. platform_add_devices(devices, ARRAY_SIZE(devices));
  151. return platform_driver_register(&kb3886bl_driver);
  152. }
  153. static void __exit kb3886_exit(void)
  154. {
  155. platform_driver_unregister(&kb3886bl_driver);
  156. }
  157. module_init(kb3886_init);
  158. module_exit(kb3886_exit);
  159. MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
  160. MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
  161. MODULE_LICENSE("GPL");
  162. MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");