blob: 8ea42b8d9bc8570f3bf379d44bd5c97885e5df2e [file] [log] [blame]
Andriy Skulysh06c6f902006-02-01 03:06:53 -08001/*
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 Purdie5f27a272006-03-31 02:31:50 -080016#include <linux/platform_device.h>
Andriy Skulysh06c6f902006-02-01 03:06:53 -080017#include <linux/spinlock.h>
18#include <linux/fb.h>
19#include <linux/backlight.h>
20
Paul Mundt193f3c22008-07-30 02:16:12 +090021#include <cpu/dac.h>
Paul Mundt7639a452008-10-20 13:02:48 +090022#include <mach/hp6xx.h>
Andriy Skulysh848dd262006-09-27 16:09:59 +090023#include <asm/hd64461.h>
Andriy Skulysh06c6f902006-02-01 03:06:53 -080024
25#define HP680_MAX_INTENSITY 255
26#define HP680_DEFAULT_INTENSITY 10
27
Richard Purdie5f27a272006-03-31 02:31:50 -080028static int hp680bl_suspended;
Jingoo Hanff10b072012-12-17 16:00:18 -080029static int current_intensity;
Ingo Molnar34af9462006-06-27 02:53:55 -070030static DEFINE_SPINLOCK(bl_lock);
Andriy Skulysh06c6f902006-02-01 03:06:53 -080031
Richard Purdie5f27a272006-03-31 02:31:50 -080032static void hp680bl_send_intensity(struct backlight_device *bd)
Andriy Skulysh06c6f902006-02-01 03:06:53 -080033{
34 unsigned long flags;
Richard Purdie5f27a272006-03-31 02:31:50 -080035 u16 v;
Richard Purdie599a52d2007-02-10 23:07:48 +000036 int intensity = bd->props.brightness;
Andriy Skulysh06c6f902006-02-01 03:06:53 -080037
Richard Purdie599a52d2007-02-10 23:07:48 +000038 if (bd->props.power != FB_BLANK_UNBLANK)
Richard Purdie5f27a272006-03-31 02:31:50 -080039 intensity = 0;
Richard Purdie599a52d2007-02-10 23:07:48 +000040 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
Richard Purdie5f27a272006-03-31 02:31:50 -080041 intensity = 0;
42 if (hp680bl_suspended)
Andriy Skulysh06c6f902006-02-01 03:06:53 -080043 intensity = 0;
44
45 spin_lock_irqsave(&bl_lock, flags);
Richard Purdie5f27a272006-03-31 02:31:50 -080046 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 Skulysh06c6f902006-02-01 03:06:53 -080060 }
Richard Purdie5f27a272006-03-31 02:31:50 -080061 spin_unlock_irqrestore(&bl_lock, flags);
62
63 current_intensity = intensity;
Andriy Skulysh06c6f902006-02-01 03:06:53 -080064}
65
Richard Purdie5f27a272006-03-31 02:31:50 -080066
Jingoo Hanb55bb782013-04-29 16:17:42 -070067#ifdef CONFIG_PM_SLEEP
68static int hp680bl_suspend(struct device *dev)
Andriy Skulysh06c6f902006-02-01 03:06:53 -080069{
Jingoo Hanb55bb782013-04-29 16:17:42 -070070 struct backlight_device *bd = dev_get_drvdata(dev);
Richard Purdiea8db3c12007-02-08 00:33:24 +000071
Richard Purdie5f27a272006-03-31 02:31:50 -080072 hp680bl_suspended = 1;
Richard Purdiea8db3c12007-02-08 00:33:24 +000073 hp680bl_send_intensity(bd);
Andriy Skulysh06c6f902006-02-01 03:06:53 -080074 return 0;
75}
76
Jingoo Hanb55bb782013-04-29 16:17:42 -070077static int hp680bl_resume(struct device *dev)
Andriy Skulysh06c6f902006-02-01 03:06:53 -080078{
Jingoo Hanb55bb782013-04-29 16:17:42 -070079 struct backlight_device *bd = dev_get_drvdata(dev);
Richard Purdiea8db3c12007-02-08 00:33:24 +000080
Richard Purdie5f27a272006-03-31 02:31:50 -080081 hp680bl_suspended = 0;
Richard Purdiea8db3c12007-02-08 00:33:24 +000082 hp680bl_send_intensity(bd);
Andriy Skulysh06c6f902006-02-01 03:06:53 -080083 return 0;
84}
Andriy Skulysh06c6f902006-02-01 03:06:53 -080085#endif
86
Jingoo Hanb55bb782013-04-29 16:17:42 -070087static SIMPLE_DEV_PM_OPS(hp680bl_pm_ops, hp680bl_suspend, hp680bl_resume);
88
Richard Purdie5f27a272006-03-31 02:31:50 -080089static int hp680bl_set_intensity(struct backlight_device *bd)
Andriy Skulysh06c6f902006-02-01 03:06:53 -080090{
Richard Purdie5f27a272006-03-31 02:31:50 -080091 hp680bl_send_intensity(bd);
Andriy Skulysh06c6f902006-02-01 03:06:53 -080092 return 0;
93}
94
95static int hp680bl_get_intensity(struct backlight_device *bd)
96{
97 return current_intensity;
98}
99
Emese Revfy9905a432009-12-14 00:58:57 +0100100static const struct backlight_ops hp680bl_ops = {
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800101 .get_brightness = hp680bl_get_intensity,
Richard Purdie5f27a272006-03-31 02:31:50 -0800102 .update_status = hp680bl_set_intensity,
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800103};
104
Bill Pemberton1b9e4502012-11-19 13:21:46 -0500105static int hp680bl_probe(struct platform_device *pdev)
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800106{
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500107 struct backlight_properties props;
Richard Purdiea8db3c12007-02-08 00:33:24 +0000108 struct backlight_device *bd;
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800109
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500110 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700111 props.type = BACKLIGHT_RAW;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500112 props.max_brightness = HP680_MAX_INTENSITY;
Jingoo Han0561c172014-01-23 15:54:25 -0800113 bd = devm_backlight_device_register(&pdev->dev, "hp680-bl", &pdev->dev,
114 NULL, &hp680bl_ops, &props);
Richard Purdiea8db3c12007-02-08 00:33:24 +0000115 if (IS_ERR(bd))
116 return PTR_ERR(bd);
117
118 platform_set_drvdata(pdev, bd);
119
Richard Purdie599a52d2007-02-10 23:07:48 +0000120 bd->props.brightness = HP680_DEFAULT_INTENSITY;
Richard Purdiea8db3c12007-02-08 00:33:24 +0000121 hp680bl_send_intensity(bd);
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800122
123 return 0;
124}
125
Richard Purdiea8db3c12007-02-08 00:33:24 +0000126static int hp680bl_remove(struct platform_device *pdev)
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800127{
Richard Purdiea8db3c12007-02-08 00:33:24 +0000128 struct backlight_device *bd = platform_get_drvdata(pdev);
129
Kristoffer Ericsoneb650d62007-09-11 12:44:38 +0900130 bd->props.brightness = 0;
131 bd->props.power = 0;
Richard Purdiea8db3c12007-02-08 00:33:24 +0000132 hp680bl_send_intensity(bd);
Henrique de Moraes Holschuh4437cd12006-12-08 02:40:49 -0800133
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800134 return 0;
135}
136
Richard Purdie5f27a272006-03-31 02:31:50 -0800137static struct platform_driver hp680bl_driver = {
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800138 .probe = hp680bl_probe,
139 .remove = hp680bl_remove,
Richard Purdie5f27a272006-03-31 02:31:50 -0800140 .driver = {
141 .name = "hp680-bl",
Jingoo Hanb55bb782013-04-29 16:17:42 -0700142 .pm = &hp680bl_pm_ops,
Richard Purdie5f27a272006-03-31 02:31:50 -0800143 },
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800144};
145
Richard Purdie5f27a272006-03-31 02:31:50 -0800146static struct platform_device *hp680bl_device;
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800147
148static int __init hp680bl_init(void)
149{
150 int ret;
151
Richard Purdie5f27a272006-03-31 02:31:50 -0800152 ret = platform_driver_register(&hp680bl_driver);
Akinobu Mita3bcdcc02008-11-17 15:16:20 +0000153 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 Skulysh06c6f902006-02-01 03:06:53 -0800160 }
Akinobu Mita3bcdcc02008-11-17 15:16:20 +0000161 return 0;
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800162}
163
164static void __exit hp680bl_exit(void)
165{
Richard Purdie5f27a272006-03-31 02:31:50 -0800166 platform_device_unregister(hp680bl_device);
Jingoo Hanff10b072012-12-17 16:00:18 -0800167 platform_driver_unregister(&hp680bl_driver);
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800168}
169
170module_init(hp680bl_init);
171module_exit(hp680bl_exit);
172
Andriy Skulysh848dd262006-09-27 16:09:59 +0900173MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>");
Andriy Skulysh06c6f902006-02-01 03:06:53 -0800174MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
175MODULE_LICENSE("GPL");