kb3886_bl.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. msleep(10);
  34. outb(KB3886_PWM0_WRITE, KB3886_IO);
  35. msleep(10);
  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 __initdata kb3886bl_device_table[] = {
  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
  93. static int kb3886bl_suspend(struct platform_device *pdev, pm_message_t state)
  94. {
  95. struct backlight_device *bd = platform_get_drvdata(pdev);
  96. kb3886bl_flags |= KB3886BL_SUSPENDED;
  97. backlight_update_status(bd);
  98. return 0;
  99. }
  100. static int kb3886bl_resume(struct platform_device *pdev)
  101. {
  102. struct backlight_device *bd = platform_get_drvdata(pdev);
  103. kb3886bl_flags &= ~KB3886BL_SUSPENDED;
  104. backlight_update_status(bd);
  105. return 0;
  106. }
  107. #else
  108. #define kb3886bl_suspend NULL
  109. #define kb3886bl_resume NULL
  110. #endif
  111. static int kb3886bl_get_intensity(struct backlight_device *bd)
  112. {
  113. return kb3886bl_intensity;
  114. }
  115. static struct backlight_ops kb3886bl_ops = {
  116. .get_brightness = kb3886bl_get_intensity,
  117. .update_status = kb3886bl_send_intensity,
  118. };
  119. static int kb3886bl_probe(struct platform_device *pdev)
  120. {
  121. struct kb3886bl_machinfo *machinfo = pdev->dev.platform_data;
  122. bl_machinfo = machinfo;
  123. if (!machinfo->limit_mask)
  124. machinfo->limit_mask = -1;
  125. kb3886_backlight_device = backlight_device_register("kb3886-bl",
  126. &pdev->dev, NULL, &kb3886bl_ops);
  127. if (IS_ERR(kb3886_backlight_device))
  128. return PTR_ERR(kb3886_backlight_device);
  129. platform_set_drvdata(pdev, kb3886_backlight_device);
  130. kb3886_backlight_device->props.max_brightness = machinfo->max_intensity;
  131. kb3886_backlight_device->props.power = FB_BLANK_UNBLANK;
  132. kb3886_backlight_device->props.brightness = machinfo->default_intensity;
  133. backlight_update_status(kb3886_backlight_device);
  134. return 0;
  135. }
  136. static int kb3886bl_remove(struct platform_device *pdev)
  137. {
  138. struct backlight_device *bd = platform_get_drvdata(pdev);
  139. backlight_device_unregister(bd);
  140. return 0;
  141. }
  142. static struct platform_driver kb3886bl_driver = {
  143. .probe = kb3886bl_probe,
  144. .remove = kb3886bl_remove,
  145. .suspend = kb3886bl_suspend,
  146. .resume = kb3886bl_resume,
  147. .driver = {
  148. .name = "kb3886-bl",
  149. },
  150. };
  151. static int __init kb3886_init(void)
  152. {
  153. if (!dmi_check_system(kb3886bl_device_table))
  154. return -ENODEV;
  155. platform_add_devices(devices, ARRAY_SIZE(devices));
  156. return platform_driver_register(&kb3886bl_driver);
  157. }
  158. static void __exit kb3886_exit(void)
  159. {
  160. platform_driver_unregister(&kb3886bl_driver);
  161. }
  162. module_init(kb3886_init);
  163. module_exit(kb3886_exit);
  164. MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
  165. MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
  166. MODULE_LICENSE("GPL");
  167. MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");