progear_bl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Backlight Driver for Frontpath ProGear HX1050+
  3. *
  4. * Copyright (c) 2006 Marcin Juszkiewicz
  5. *
  6. * Based on Progear LCD driver by M Schacht
  7. * <mschacht at alumni dot washington dot edu>
  8. *
  9. * Based on Sharp's Corgi Backlight Driver
  10. * Based on Backlight Driver for HP Jornada 680
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mutex.h>
  22. #include <linux/fb.h>
  23. #include <linux/backlight.h>
  24. #include <linux/pci.h>
  25. #define PMU_LPCR 0xB0
  26. #define SB_MPS1 0x61
  27. #define HW_LEVEL_MAX 0x77
  28. #define HW_LEVEL_MIN 0x4f
  29. static struct pci_dev *pmu_dev = NULL;
  30. static struct pci_dev *sb_dev = NULL;
  31. static int progearbl_set_intensity(struct backlight_device *bd)
  32. {
  33. int intensity = bd->props.brightness;
  34. if (bd->props.power != FB_BLANK_UNBLANK)
  35. intensity = 0;
  36. if (bd->props.fb_blank != FB_BLANK_UNBLANK)
  37. intensity = 0;
  38. pci_write_config_byte(pmu_dev, PMU_LPCR, intensity + HW_LEVEL_MIN);
  39. return 0;
  40. }
  41. static int progearbl_get_intensity(struct backlight_device *bd)
  42. {
  43. u8 intensity;
  44. pci_read_config_byte(pmu_dev, PMU_LPCR, &intensity);
  45. return intensity - HW_LEVEL_MIN;
  46. }
  47. static const struct backlight_ops progearbl_ops = {
  48. .get_brightness = progearbl_get_intensity,
  49. .update_status = progearbl_set_intensity,
  50. };
  51. static int progearbl_probe(struct platform_device *pdev)
  52. {
  53. u8 temp;
  54. struct backlight_device *progear_backlight_device;
  55. int ret;
  56. pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, NULL);
  57. if (!pmu_dev) {
  58. printk("ALI M7101 PMU not found.\n");
  59. return -ENODEV;
  60. }
  61. sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  62. if (!sb_dev) {
  63. printk("ALI 1533 SB not found.\n");
  64. ret = -ENODEV;
  65. goto put_pmu;
  66. }
  67. /* Set SB_MPS1 to enable brightness control. */
  68. pci_read_config_byte(sb_dev, SB_MPS1, &temp);
  69. pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20);
  70. progear_backlight_device = backlight_device_register("progear-bl",
  71. &pdev->dev, NULL,
  72. &progearbl_ops);
  73. if (IS_ERR(progear_backlight_device)) {
  74. ret = PTR_ERR(progear_backlight_device);
  75. goto put_sb;
  76. }
  77. platform_set_drvdata(pdev, progear_backlight_device);
  78. progear_backlight_device->props.power = FB_BLANK_UNBLANK;
  79. progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  80. progear_backlight_device->props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  81. progearbl_set_intensity(progear_backlight_device);
  82. return 0;
  83. put_sb:
  84. pci_dev_put(sb_dev);
  85. put_pmu:
  86. pci_dev_put(pmu_dev);
  87. return ret;
  88. }
  89. static int progearbl_remove(struct platform_device *pdev)
  90. {
  91. struct backlight_device *bd = platform_get_drvdata(pdev);
  92. backlight_device_unregister(bd);
  93. return 0;
  94. }
  95. static struct platform_driver progearbl_driver = {
  96. .probe = progearbl_probe,
  97. .remove = progearbl_remove,
  98. .driver = {
  99. .name = "progear-bl",
  100. },
  101. };
  102. static struct platform_device *progearbl_device;
  103. static int __init progearbl_init(void)
  104. {
  105. int ret = platform_driver_register(&progearbl_driver);
  106. if (ret)
  107. return ret;
  108. progearbl_device = platform_device_register_simple("progear-bl", -1,
  109. NULL, 0);
  110. if (IS_ERR(progearbl_device)) {
  111. platform_driver_unregister(&progearbl_driver);
  112. return PTR_ERR(progearbl_device);
  113. }
  114. return 0;
  115. }
  116. static void __exit progearbl_exit(void)
  117. {
  118. pci_dev_put(pmu_dev);
  119. pci_dev_put(sb_dev);
  120. platform_device_unregister(progearbl_device);
  121. platform_driver_unregister(&progearbl_driver);
  122. }
  123. module_init(progearbl_init);
  124. module_exit(progearbl_exit);
  125. MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
  126. MODULE_DESCRIPTION("ProGear Backlight Driver");
  127. MODULE_LICENSE("GPL");