progear_bl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #include <asm/uaccess.h>
  26. #define PMU_LPCR 0xB0
  27. #define SB_MPS1 0x61
  28. #define HW_LEVEL_MAX 0x77
  29. #define HW_LEVEL_MIN 0x4f
  30. static struct pci_dev *pmu_dev = NULL;
  31. static struct pci_dev *sb_dev = NULL;
  32. static int progearbl_set_intensity(struct backlight_device *bd)
  33. {
  34. int intensity = bd->props->brightness;
  35. if (bd->props->power != FB_BLANK_UNBLANK)
  36. intensity = 0;
  37. if (bd->props->fb_blank != FB_BLANK_UNBLANK)
  38. intensity = 0;
  39. pci_write_config_byte(pmu_dev, PMU_LPCR, intensity + HW_LEVEL_MIN);
  40. return 0;
  41. }
  42. static int progearbl_get_intensity(struct backlight_device *bd)
  43. {
  44. u8 intensity;
  45. pci_read_config_byte(pmu_dev, PMU_LPCR, &intensity);
  46. return intensity - HW_LEVEL_MIN;
  47. }
  48. static struct backlight_properties progearbl_data = {
  49. .owner = THIS_MODULE,
  50. .get_brightness = progearbl_get_intensity,
  51. .update_status = progearbl_set_intensity,
  52. };
  53. static int progearbl_probe(struct platform_device *pdev)
  54. {
  55. u8 temp;
  56. struct backlight_device *progear_backlight_device;
  57. pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, 0);
  58. if (!pmu_dev) {
  59. printk("ALI M7101 PMU not found.\n");
  60. return -ENODEV;
  61. }
  62. sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, 0);
  63. if (!sb_dev) {
  64. printk("ALI 1533 SB not found.\n");
  65. pci_dev_put(pmu_dev);
  66. return -ENODEV;
  67. }
  68. /* Set SB_MPS1 to enable brightness control. */
  69. pci_read_config_byte(sb_dev, SB_MPS1, &temp);
  70. pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20);
  71. progear_backlight_device = backlight_device_register("progear-bl",
  72. &pdev->dev, NULL,
  73. &progearbl_data);
  74. if (IS_ERR(progear_backlight_device))
  75. return PTR_ERR(progear_backlight_device);
  76. platform_set_drvdata(pdev, progear_backlight_device);
  77. progearbl_data.power = FB_BLANK_UNBLANK;
  78. progearbl_data.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  79. progearbl_data.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  80. progearbl_set_intensity(progear_backlight_device);
  81. return 0;
  82. }
  83. static int progearbl_remove(struct platform_device *pdev)
  84. {
  85. struct backlight_device *bd = platform_get_drvdata(pdev);
  86. backlight_device_unregister(bd);
  87. return 0;
  88. }
  89. static struct platform_driver progearbl_driver = {
  90. .probe = progearbl_probe,
  91. .remove = progearbl_remove,
  92. .driver = {
  93. .name = "progear-bl",
  94. },
  95. };
  96. static struct platform_device *progearbl_device;
  97. static int __init progearbl_init(void)
  98. {
  99. int ret = platform_driver_register(&progearbl_driver);
  100. if (!ret) {
  101. progearbl_device = platform_device_alloc("progear-bl", -1);
  102. if (!progearbl_device)
  103. return -ENOMEM;
  104. ret = platform_device_add(progearbl_device);
  105. if (ret) {
  106. platform_device_put(progearbl_device);
  107. platform_driver_unregister(&progearbl_driver);
  108. }
  109. }
  110. return ret;
  111. }
  112. static void __exit progearbl_exit(void)
  113. {
  114. pci_dev_put(pmu_dev);
  115. pci_dev_put(sb_dev);
  116. platform_device_unregister(progearbl_device);
  117. platform_driver_unregister(&progearbl_driver);
  118. }
  119. module_init(progearbl_init);
  120. module_exit(progearbl_exit);
  121. MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
  122. MODULE_DESCRIPTION("ProGear Backlight Driver");
  123. MODULE_LICENSE("GPL");