Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Backlight Driver for HP Jornada 680 |
| 3 | * |
| 4 | * Copyright (c) 2005 Andriy Skulysh |
| 5 | * |
| 6 | * Based on Sharp's Corgi Backlight Driver |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file "COPYING" in the main directory of this archive |
| 10 | * for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 16 | #include <linux/platform_device.h> |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/fb.h> |
| 19 | #include <linux/backlight.h> |
| 20 | |
| 21 | #include <asm/cpu/dac.h> |
| 22 | #include <asm/hp6xx/hp6xx.h> |
| 23 | #include <asm/hd64461/hd64461.h> |
| 24 | |
| 25 | #define HP680_MAX_INTENSITY 255 |
| 26 | #define HP680_DEFAULT_INTENSITY 10 |
| 27 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 28 | static int hp680bl_suspended; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 29 | static int current_intensity = 0; |
| 30 | static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED; |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 31 | static struct backlight_device *hp680_backlight_device; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 32 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 33 | static void hp680bl_send_intensity(struct backlight_device *bd) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 34 | { |
| 35 | unsigned long flags; |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 36 | u16 v; |
| 37 | int intensity = bd->props->brightness; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 38 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 39 | if (bd->props->power != FB_BLANK_UNBLANK) |
| 40 | intensity = 0; |
| 41 | if (bd->props->fb_blank != FB_BLANK_UNBLANK) |
| 42 | intensity = 0; |
| 43 | if (hp680bl_suspended) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 44 | intensity = 0; |
| 45 | |
| 46 | spin_lock_irqsave(&bl_lock, flags); |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 47 | if (intensity && current_intensity == 0) { |
| 48 | sh_dac_enable(DAC_LCD_BRIGHTNESS); |
| 49 | v = inw(HD64461_GPBDR); |
| 50 | v &= ~HD64461_GPBDR_LCDOFF; |
| 51 | outw(v, HD64461_GPBDR); |
| 52 | sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); |
| 53 | } else if (intensity == 0 && current_intensity != 0) { |
| 54 | sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); |
| 55 | sh_dac_disable(DAC_LCD_BRIGHTNESS); |
| 56 | v = inw(HD64461_GPBDR); |
| 57 | v |= HD64461_GPBDR_LCDOFF; |
| 58 | outw(v, HD64461_GPBDR); |
| 59 | } else if (intensity) { |
| 60 | sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 61 | } |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 62 | spin_unlock_irqrestore(&bl_lock, flags); |
| 63 | |
| 64 | current_intensity = intensity; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 67 | |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 68 | #ifdef CONFIG_PM |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 69 | static int hp680bl_suspend(struct platform_device *dev, pm_message_t state) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 70 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 71 | hp680bl_suspended = 1; |
| 72 | hp680bl_send_intensity(hp680_backlight_device); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 73 | return 0; |
| 74 | } |
| 75 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 76 | static int hp680bl_resume(struct platform_device *dev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 77 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 78 | hp680bl_suspended = 0; |
| 79 | hp680bl_send_intensity(hp680_backlight_device); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | #else |
| 83 | #define hp680bl_suspend NULL |
| 84 | #define hp680bl_resume NULL |
| 85 | #endif |
| 86 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 87 | static int hp680bl_set_intensity(struct backlight_device *bd) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 88 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 89 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static int hp680bl_get_intensity(struct backlight_device *bd) |
| 94 | { |
| 95 | return current_intensity; |
| 96 | } |
| 97 | |
| 98 | static struct backlight_properties hp680bl_data = { |
| 99 | .owner = THIS_MODULE, |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 100 | .max_brightness = HP680_MAX_INTENSITY, |
| 101 | .get_brightness = hp680bl_get_intensity, |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 102 | .update_status = hp680bl_set_intensity, |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 105 | static int __init hp680bl_probe(struct platform_device *dev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 106 | { |
| 107 | hp680_backlight_device = backlight_device_register ("hp680-bl", |
| 108 | NULL, &hp680bl_data); |
| 109 | if (IS_ERR (hp680_backlight_device)) |
| 110 | return PTR_ERR (hp680_backlight_device); |
| 111 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 112 | hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY; |
| 113 | hp680bl_send_intensity(hp680_backlight_device); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 118 | static int hp680bl_remove(struct platform_device *dev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 119 | { |
| 120 | backlight_device_unregister(hp680_backlight_device); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 125 | static struct platform_driver hp680bl_driver = { |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 126 | .probe = hp680bl_probe, |
| 127 | .remove = hp680bl_remove, |
| 128 | .suspend = hp680bl_suspend, |
| 129 | .resume = hp680bl_resume, |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 130 | .driver = { |
| 131 | .name = "hp680-bl", |
| 132 | }, |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 135 | static struct platform_device *hp680bl_device; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 136 | |
| 137 | static int __init hp680bl_init(void) |
| 138 | { |
| 139 | int ret; |
| 140 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 141 | ret = platform_driver_register(&hp680bl_driver); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 142 | if (!ret) { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 143 | hp680bl_device = platform_device_alloc("hp680-bl", -1); |
| 144 | if (!hp680bl_device) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | ret = platform_device_add(hp680bl_device); |
| 148 | |
| 149 | if (ret) { |
| 150 | platform_device_put(hp680bl_device); |
| 151 | platform_driver_unregister(&hp680bl_driver); |
| 152 | } |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 153 | } |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | static void __exit hp680bl_exit(void) |
| 158 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame^] | 159 | platform_device_unregister(hp680bl_device); |
| 160 | platform_driver_unregister(&hp680bl_driver); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | module_init(hp680bl_init); |
| 164 | module_exit(hp680bl_exit); |
| 165 | |
| 166 | MODULE_AUTHOR("Andriy Skulysh <askulysh@image.kiev.ua>"); |
| 167 | MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); |
| 168 | MODULE_LICENSE("GPL"); |