cr_bllcd.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright (c) Intel Corp. 2007.
  3. * All Rights Reserved.
  4. *
  5. * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
  6. * develop this driver.
  7. *
  8. * This file is part of the Carillo Ranch video subsystem driver.
  9. * The Carillo Ranch video subsystem driver is free software;
  10. * you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * The Carillo Ranch video subsystem driver is distributed
  16. * in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this driver; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Authors:
  26. * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
  27. * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/init.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/mutex.h>
  34. #include <linux/fb.h>
  35. #include <linux/backlight.h>
  36. #include <linux/lcd.h>
  37. #include <linux/pci.h>
  38. #include <linux/slab.h>
  39. /* The LVDS- and panel power controls sits on the
  40. * GPIO port of the ISA bridge.
  41. */
  42. #define CRVML_DEVICE_LPC 0x27B8
  43. #define CRVML_REG_GPIOBAR 0x48
  44. #define CRVML_REG_GPIOEN 0x4C
  45. #define CRVML_GPIOEN_BIT (1 << 4)
  46. #define CRVML_PANEL_PORT 0x38
  47. #define CRVML_LVDS_ON 0x00000001
  48. #define CRVML_PANEL_ON 0x00000002
  49. #define CRVML_BACKLIGHT_OFF 0x00000004
  50. /* The PLL Clock register sits on Host bridge */
  51. #define CRVML_DEVICE_MCH 0x5001
  52. #define CRVML_REG_MCHBAR 0x44
  53. #define CRVML_REG_MCHEN 0x54
  54. #define CRVML_MCHEN_BIT (1 << 28)
  55. #define CRVML_MCHMAP_SIZE 4096
  56. #define CRVML_REG_CLOCK 0xc3c
  57. #define CRVML_CLOCK_SHIFT 8
  58. #define CRVML_CLOCK_MASK 0x00000f00
  59. static struct pci_dev *lpc_dev;
  60. static u32 gpio_bar;
  61. struct cr_panel {
  62. struct backlight_device *cr_backlight_device;
  63. struct lcd_device *cr_lcd_device;
  64. };
  65. static int cr_backlight_set_intensity(struct backlight_device *bd)
  66. {
  67. int intensity = bd->props.brightness;
  68. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  69. u32 cur = inl(addr);
  70. if (bd->props.power == FB_BLANK_UNBLANK)
  71. intensity = FB_BLANK_UNBLANK;
  72. if (bd->props.fb_blank == FB_BLANK_UNBLANK)
  73. intensity = FB_BLANK_UNBLANK;
  74. if (bd->props.power == FB_BLANK_POWERDOWN)
  75. intensity = FB_BLANK_POWERDOWN;
  76. if (bd->props.fb_blank == FB_BLANK_POWERDOWN)
  77. intensity = FB_BLANK_POWERDOWN;
  78. if (intensity == FB_BLANK_UNBLANK) { /* FULL ON */
  79. cur &= ~CRVML_BACKLIGHT_OFF;
  80. outl(cur, addr);
  81. } else if (intensity == FB_BLANK_POWERDOWN) { /* OFF */
  82. cur |= CRVML_BACKLIGHT_OFF;
  83. outl(cur, addr);
  84. } /* anything else, don't bother */
  85. return 0;
  86. }
  87. static int cr_backlight_get_intensity(struct backlight_device *bd)
  88. {
  89. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  90. u32 cur = inl(addr);
  91. u8 intensity;
  92. if (cur & CRVML_BACKLIGHT_OFF)
  93. intensity = FB_BLANK_POWERDOWN;
  94. else
  95. intensity = FB_BLANK_UNBLANK;
  96. return intensity;
  97. }
  98. static const struct backlight_ops cr_backlight_ops = {
  99. .get_brightness = cr_backlight_get_intensity,
  100. .update_status = cr_backlight_set_intensity,
  101. };
  102. static void cr_panel_on(void)
  103. {
  104. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  105. u32 cur = inl(addr);
  106. if (!(cur & CRVML_PANEL_ON)) {
  107. /* Make sure LVDS controller is down. */
  108. if (cur & 0x00000001) {
  109. cur &= ~CRVML_LVDS_ON;
  110. outl(cur, addr);
  111. }
  112. /* Power up Panel */
  113. schedule_timeout(HZ / 10);
  114. cur |= CRVML_PANEL_ON;
  115. outl(cur, addr);
  116. }
  117. /* Power up LVDS controller */
  118. if (!(cur & CRVML_LVDS_ON)) {
  119. schedule_timeout(HZ / 10);
  120. outl(cur | CRVML_LVDS_ON, addr);
  121. }
  122. }
  123. static void cr_panel_off(void)
  124. {
  125. u32 addr = gpio_bar + CRVML_PANEL_PORT;
  126. u32 cur = inl(addr);
  127. /* Power down LVDS controller first to avoid high currents */
  128. if (cur & CRVML_LVDS_ON) {
  129. cur &= ~CRVML_LVDS_ON;
  130. outl(cur, addr);
  131. }
  132. if (cur & CRVML_PANEL_ON) {
  133. schedule_timeout(HZ / 10);
  134. outl(cur & ~CRVML_PANEL_ON, addr);
  135. }
  136. }
  137. static int cr_lcd_set_power(struct lcd_device *ld, int power)
  138. {
  139. if (power == FB_BLANK_UNBLANK)
  140. cr_panel_on();
  141. if (power == FB_BLANK_POWERDOWN)
  142. cr_panel_off();
  143. return 0;
  144. }
  145. static struct lcd_ops cr_lcd_ops = {
  146. .set_power = cr_lcd_set_power,
  147. };
  148. static int cr_backlight_probe(struct platform_device *pdev)
  149. {
  150. struct backlight_properties props;
  151. struct backlight_device *bdp;
  152. struct lcd_device *ldp;
  153. struct cr_panel *crp;
  154. u8 dev_en;
  155. lpc_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
  156. CRVML_DEVICE_LPC, NULL);
  157. if (!lpc_dev) {
  158. printk("INTEL CARILLO RANCH LPC not found.\n");
  159. return -ENODEV;
  160. }
  161. pci_read_config_byte(lpc_dev, CRVML_REG_GPIOEN, &dev_en);
  162. if (!(dev_en & CRVML_GPIOEN_BIT)) {
  163. printk(KERN_ERR
  164. "Carillo Ranch GPIO device was not enabled.\n");
  165. pci_dev_put(lpc_dev);
  166. return -ENODEV;
  167. }
  168. memset(&props, 0, sizeof(struct backlight_properties));
  169. props.type = BACKLIGHT_RAW;
  170. bdp = backlight_device_register("cr-backlight", &pdev->dev, NULL,
  171. &cr_backlight_ops, &props);
  172. if (IS_ERR(bdp)) {
  173. pci_dev_put(lpc_dev);
  174. return PTR_ERR(bdp);
  175. }
  176. ldp = lcd_device_register("cr-lcd", &pdev->dev, NULL, &cr_lcd_ops);
  177. if (IS_ERR(ldp)) {
  178. backlight_device_unregister(bdp);
  179. pci_dev_put(lpc_dev);
  180. return PTR_ERR(ldp);
  181. }
  182. pci_read_config_dword(lpc_dev, CRVML_REG_GPIOBAR,
  183. &gpio_bar);
  184. gpio_bar &= ~0x3F;
  185. crp = kzalloc(sizeof(*crp), GFP_KERNEL);
  186. if (!crp) {
  187. lcd_device_unregister(ldp);
  188. backlight_device_unregister(bdp);
  189. pci_dev_put(lpc_dev);
  190. return -ENOMEM;
  191. }
  192. crp->cr_backlight_device = bdp;
  193. crp->cr_lcd_device = ldp;
  194. crp->cr_backlight_device->props.power = FB_BLANK_UNBLANK;
  195. crp->cr_backlight_device->props.brightness = 0;
  196. cr_backlight_set_intensity(crp->cr_backlight_device);
  197. cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_UNBLANK);
  198. platform_set_drvdata(pdev, crp);
  199. return 0;
  200. }
  201. static int cr_backlight_remove(struct platform_device *pdev)
  202. {
  203. struct cr_panel *crp = platform_get_drvdata(pdev);
  204. crp->cr_backlight_device->props.power = FB_BLANK_POWERDOWN;
  205. crp->cr_backlight_device->props.brightness = 0;
  206. crp->cr_backlight_device->props.max_brightness = 0;
  207. cr_backlight_set_intensity(crp->cr_backlight_device);
  208. cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN);
  209. backlight_device_unregister(crp->cr_backlight_device);
  210. lcd_device_unregister(crp->cr_lcd_device);
  211. pci_dev_put(lpc_dev);
  212. kfree(crp);
  213. return 0;
  214. }
  215. static struct platform_driver cr_backlight_driver = {
  216. .probe = cr_backlight_probe,
  217. .remove = cr_backlight_remove,
  218. .driver = {
  219. .name = "cr_backlight",
  220. },
  221. };
  222. static struct platform_device *crp;
  223. static int __init cr_backlight_init(void)
  224. {
  225. int ret = platform_driver_register(&cr_backlight_driver);
  226. if (ret)
  227. return ret;
  228. crp = platform_device_register_simple("cr_backlight", -1, NULL, 0);
  229. if (IS_ERR(crp)) {
  230. platform_driver_unregister(&cr_backlight_driver);
  231. return PTR_ERR(crp);
  232. }
  233. printk("Carillo Ranch Backlight Driver Initialized.\n");
  234. return 0;
  235. }
  236. static void __exit cr_backlight_exit(void)
  237. {
  238. platform_device_unregister(crp);
  239. platform_driver_unregister(&cr_backlight_driver);
  240. }
  241. module_init(cr_backlight_init);
  242. module_exit(cr_backlight_exit);
  243. MODULE_AUTHOR("Tungsten Graphics Inc.");
  244. MODULE_DESCRIPTION("Carillo Ranch Backlight Driver");
  245. MODULE_LICENSE("GPL");