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> |
Kristoffer Ericson | 1aea7e0 | 2006-10-31 11:47:27 +0900 | [diff] [blame] | 22 | #include <asm/hp6xx.h> |
Andriy Skulysh | 848dd26 | 2006-09-27 16:09:59 +0900 | [diff] [blame] | 23 | #include <asm/hd64461.h> |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 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; |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 30 | static DEFINE_SPINLOCK(bl_lock); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 31 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 32 | static void hp680bl_send_intensity(struct backlight_device *bd) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 33 | { |
| 34 | unsigned long flags; |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 35 | u16 v; |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame^] | 36 | int intensity = bd->props.brightness; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 37 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame^] | 38 | if (bd->props.power != FB_BLANK_UNBLANK) |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 39 | intensity = 0; |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame^] | 40 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 41 | intensity = 0; |
| 42 | if (hp680bl_suspended) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 43 | intensity = 0; |
| 44 | |
| 45 | spin_lock_irqsave(&bl_lock, flags); |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 46 | if (intensity && current_intensity == 0) { |
| 47 | sh_dac_enable(DAC_LCD_BRIGHTNESS); |
| 48 | v = inw(HD64461_GPBDR); |
| 49 | v &= ~HD64461_GPBDR_LCDOFF; |
| 50 | outw(v, HD64461_GPBDR); |
| 51 | sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); |
| 52 | } else if (intensity == 0 && current_intensity != 0) { |
| 53 | sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); |
| 54 | sh_dac_disable(DAC_LCD_BRIGHTNESS); |
| 55 | v = inw(HD64461_GPBDR); |
| 56 | v |= HD64461_GPBDR_LCDOFF; |
| 57 | outw(v, HD64461_GPBDR); |
| 58 | } else if (intensity) { |
| 59 | sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 60 | } |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 61 | spin_unlock_irqrestore(&bl_lock, flags); |
| 62 | |
| 63 | current_intensity = intensity; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 66 | |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 67 | #ifdef CONFIG_PM |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 68 | static int hp680bl_suspend(struct platform_device *pdev, pm_message_t state) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 69 | { |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 70 | struct backlight_device *bd = platform_get_drvdata(pdev); |
| 71 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 72 | hp680bl_suspended = 1; |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 73 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 77 | static int hp680bl_resume(struct platform_device *pdev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 78 | { |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 79 | struct backlight_device *bd = platform_get_drvdata(pdev); |
| 80 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 81 | hp680bl_suspended = 0; |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 82 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | #else |
| 86 | #define hp680bl_suspend NULL |
| 87 | #define hp680bl_resume NULL |
| 88 | #endif |
| 89 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 90 | static int hp680bl_set_intensity(struct backlight_device *bd) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 91 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 92 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static int hp680bl_get_intensity(struct backlight_device *bd) |
| 97 | { |
| 98 | return current_intensity; |
| 99 | } |
| 100 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame^] | 101 | static struct backlight_ops hp680bl_ops = { |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 102 | .get_brightness = hp680bl_get_intensity, |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 103 | .update_status = hp680bl_set_intensity, |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 106 | static int __init hp680bl_probe(struct platform_device *pdev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 107 | { |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 108 | struct backlight_device *bd; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 109 | |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 110 | bd = backlight_device_register ("hp680-bl", &pdev->dev, NULL, |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame^] | 111 | &hp680bl_ops); |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 112 | if (IS_ERR(bd)) |
| 113 | return PTR_ERR(bd); |
| 114 | |
| 115 | platform_set_drvdata(pdev, bd); |
| 116 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame^] | 117 | bd->props.max_brightness = HP680_MAX_INTENSITY; |
| 118 | bd->props.brightness = HP680_DEFAULT_INTENSITY; |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 119 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 124 | static int hp680bl_remove(struct platform_device *pdev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 125 | { |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 126 | struct backlight_device *bd = platform_get_drvdata(pdev); |
| 127 | |
Henrique de Moraes Holschuh | 4437cd1 | 2006-12-08 02:40:49 -0800 | [diff] [blame] | 128 | hp680bl_data.brightness = 0; |
| 129 | hp680bl_data.power = 0; |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 130 | hp680bl_send_intensity(bd); |
Henrique de Moraes Holschuh | 4437cd1 | 2006-12-08 02:40:49 -0800 | [diff] [blame] | 131 | |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 132 | backlight_device_unregister(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 137 | static struct platform_driver hp680bl_driver = { |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 138 | .probe = hp680bl_probe, |
| 139 | .remove = hp680bl_remove, |
| 140 | .suspend = hp680bl_suspend, |
| 141 | .resume = hp680bl_resume, |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 142 | .driver = { |
| 143 | .name = "hp680-bl", |
| 144 | }, |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 145 | }; |
| 146 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 147 | static struct platform_device *hp680bl_device; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 148 | |
| 149 | static int __init hp680bl_init(void) |
| 150 | { |
| 151 | int ret; |
| 152 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 153 | ret = platform_driver_register(&hp680bl_driver); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 154 | if (!ret) { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 155 | hp680bl_device = platform_device_alloc("hp680-bl", -1); |
| 156 | if (!hp680bl_device) |
| 157 | return -ENOMEM; |
| 158 | |
| 159 | ret = platform_device_add(hp680bl_device); |
| 160 | |
| 161 | if (ret) { |
| 162 | platform_device_put(hp680bl_device); |
| 163 | platform_driver_unregister(&hp680bl_driver); |
| 164 | } |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 165 | } |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | static void __exit hp680bl_exit(void) |
| 170 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 171 | platform_device_unregister(hp680bl_device); |
| 172 | platform_driver_unregister(&hp680bl_driver); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | module_init(hp680bl_init); |
| 176 | module_exit(hp680bl_exit); |
| 177 | |
Andriy Skulysh | 848dd26 | 2006-09-27 16:09:59 +0900 | [diff] [blame] | 178 | MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>"); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 179 | MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); |
| 180 | MODULE_LICENSE("GPL"); |