progear_bl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_ops progearbl_ops = {
  49. .get_brightness = progearbl_get_intensity,
  50. .update_status = progearbl_set_intensity,
  51. };
  52. static int progearbl_probe(struct platform_device *pdev)
  53. {
  54. u8 temp;
  55. struct backlight_device *progear_backlight_device;
  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. pci_dev_put(pmu_dev);
  65. return -ENODEV;
  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. return PTR_ERR(progear_backlight_device);
  75. platform_set_drvdata(pdev, progear_backlight_device);
  76. progear_backlight_device->props.power = FB_BLANK_UNBLANK;
  77. progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  78. progear_backlight_device->props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
  79. progearbl_set_intensity(progear_backlight_device);
  80. return 0;
  81. }
  82. static int progearbl_remove(struct platform_device *pdev)
  83. {
  84. struct backlight_device *bd = platform_get_drvdata(pdev);
  85. backlight_device_unregister(bd);
  86. return 0;
  87. }
  88. static struct platform_driver progearbl_driver = {
  89. .probe = progearbl_probe,
  90. .remove = progearbl_remove,
  91. .driver = {
  92. .name = "progear-bl",
  93. },
  94. };
  95. static struct platform_device *progearbl_device;
  96. static int __init progearbl_init(void)
  97. {
  98. int ret = platform_driver_register(&progearbl_driver);
  99. if (!ret) {
  100. progearbl_device = platform_device_alloc("progear-bl", -1);
  101. if (!progearbl_device)
  102. return -ENOMEM;
  103. ret = platform_device_add(progearbl_device);
  104. if (ret) {
  105. platform_device_put(progearbl_device);
  106. platform_driver_unregister(&progearbl_driver);
  107. }
  108. }
  109. return ret;
  110. }
  111. static void __exit progearbl_exit(void)
  112. {
  113. pci_dev_put(pmu_dev);
  114. pci_dev_put(sb_dev);
  115. platform_device_unregister(progearbl_device);
  116. platform_driver_unregister(&progearbl_driver);
  117. }
  118. module_init(progearbl_init);
  119. module_exit(progearbl_exit);
  120. MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
  121. MODULE_DESCRIPTION("ProGear Backlight Driver");
  122. MODULE_LICENSE("GPL");