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 | |
Paul Mundt | 193f3c2 | 2008-07-30 02:16:12 +0900 | [diff] [blame] | 21 | #include <cpu/dac.h> |
Paul Mundt | 7639a45 | 2008-10-20 13:02:48 +0900 | [diff] [blame] | 22 | #include <mach/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; |
Jingoo Han | ff10b07 | 2012-12-17 16:00:18 -0800 | [diff] [blame] | 29 | static int current_intensity; |
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 | |
Jingoo Han | b55bb78 | 2013-04-29 16:17:42 -0700 | [diff] [blame] | 67 | #ifdef CONFIG_PM_SLEEP |
| 68 | static int hp680bl_suspend(struct device *dev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 69 | { |
Jingoo Han | b55bb78 | 2013-04-29 16:17:42 -0700 | [diff] [blame] | 70 | struct backlight_device *bd = dev_get_drvdata(dev); |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 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 | |
Jingoo Han | b55bb78 | 2013-04-29 16:17:42 -0700 | [diff] [blame] | 77 | static int hp680bl_resume(struct device *dev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 78 | { |
Jingoo Han | b55bb78 | 2013-04-29 16:17:42 -0700 | [diff] [blame] | 79 | struct backlight_device *bd = dev_get_drvdata(dev); |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 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 | } |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 85 | #endif |
| 86 | |
Jingoo Han | b55bb78 | 2013-04-29 16:17:42 -0700 | [diff] [blame] | 87 | static SIMPLE_DEV_PM_OPS(hp680bl_pm_ops, hp680bl_suspend, hp680bl_resume); |
| 88 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 89 | static int hp680bl_set_intensity(struct backlight_device *bd) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 90 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 91 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static int hp680bl_get_intensity(struct backlight_device *bd) |
| 96 | { |
| 97 | return current_intensity; |
| 98 | } |
| 99 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 100 | static const struct backlight_ops hp680bl_ops = { |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 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 | |
Bill Pemberton | 1b9e450 | 2012-11-19 13:21:46 -0500 | [diff] [blame] | 105 | static int hp680bl_probe(struct platform_device *pdev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 106 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 107 | struct backlight_properties props; |
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 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 110 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 111 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 112 | props.max_brightness = HP680_MAX_INTENSITY; |
Jingoo Han | 0561c17 | 2014-01-23 15:54:25 -0800 | [diff] [blame] | 113 | bd = devm_backlight_device_register(&pdev->dev, "hp680-bl", &pdev->dev, |
| 114 | NULL, &hp680bl_ops, &props); |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 115 | if (IS_ERR(bd)) |
| 116 | return PTR_ERR(bd); |
| 117 | |
| 118 | platform_set_drvdata(pdev, bd); |
| 119 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 120 | bd->props.brightness = HP680_DEFAULT_INTENSITY; |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 121 | hp680bl_send_intensity(bd); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 126 | static int hp680bl_remove(struct platform_device *pdev) |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 127 | { |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 128 | struct backlight_device *bd = platform_get_drvdata(pdev); |
| 129 | |
Kristoffer Ericson | eb650d6 | 2007-09-11 12:44:38 +0900 | [diff] [blame] | 130 | bd->props.brightness = 0; |
| 131 | bd->props.power = 0; |
Richard Purdie | a8db3c1 | 2007-02-08 00:33:24 +0000 | [diff] [blame] | 132 | hp680bl_send_intensity(bd); |
Henrique de Moraes Holschuh | 4437cd1 | 2006-12-08 02:40:49 -0800 | [diff] [blame] | 133 | |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 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, |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 140 | .driver = { |
| 141 | .name = "hp680-bl", |
Jingoo Han | b55bb78 | 2013-04-29 16:17:42 -0700 | [diff] [blame] | 142 | .pm = &hp680bl_pm_ops, |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 143 | }, |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 146 | static struct platform_device *hp680bl_device; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 147 | |
| 148 | static int __init hp680bl_init(void) |
| 149 | { |
| 150 | int ret; |
| 151 | |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 152 | ret = platform_driver_register(&hp680bl_driver); |
Akinobu Mita | 3bcdcc0 | 2008-11-17 15:16:20 +0000 | [diff] [blame] | 153 | if (ret) |
| 154 | return ret; |
| 155 | hp680bl_device = platform_device_register_simple("hp680-bl", -1, |
| 156 | NULL, 0); |
| 157 | if (IS_ERR(hp680bl_device)) { |
| 158 | platform_driver_unregister(&hp680bl_driver); |
| 159 | return PTR_ERR(hp680bl_device); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 160 | } |
Akinobu Mita | 3bcdcc0 | 2008-11-17 15:16:20 +0000 | [diff] [blame] | 161 | return 0; |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void __exit hp680bl_exit(void) |
| 165 | { |
Richard Purdie | 5f27a27 | 2006-03-31 02:31:50 -0800 | [diff] [blame] | 166 | platform_device_unregister(hp680bl_device); |
Jingoo Han | ff10b07 | 2012-12-17 16:00:18 -0800 | [diff] [blame] | 167 | platform_driver_unregister(&hp680bl_driver); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | module_init(hp680bl_init); |
| 171 | module_exit(hp680bl_exit); |
| 172 | |
Andriy Skulysh | 848dd26 | 2006-09-27 16:09:59 +0900 | [diff] [blame] | 173 | MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>"); |
Andriy Skulysh | 06c6f90 | 2006-02-01 03:06:53 -0800 | [diff] [blame] | 174 | MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); |
| 175 | MODULE_LICENSE("GPL"); |