]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/powerpc/platforms/powermac/backlight.c
2 * Miscellaneous procedures for dealing with the PowerMac hardware.
3 * Contains support for the backlight.
5 * Copyright (C) 2000 Benjamin Herrenschmidt
6 * Copyright (C) 2006 Michael Hanselmann <linux-kernel@hansmi.ch>
10 #include <linux/kernel.h>
12 #include <linux/backlight.h>
14 #include <asm/backlight.h>
16 #define OLD_BACKLIGHT_MAX 15
18 /* Protect the pmac_backlight variable */
19 DEFINE_MUTEX(pmac_backlight_mutex
);
21 /* Main backlight storage
23 * Backlight drivers in this variable are required to have the "props"
24 * attribute set and to have an update_status function.
26 * We can only store one backlight here, but since Apple laptops have only one
27 * internal display, it doesn't matter. Other backlight drivers can be used
31 * pmac_backlight_mutex (global, main backlight)
32 * pmac_backlight->sem (backlight class)
34 struct backlight_device
*pmac_backlight
;
36 int pmac_has_backlight_type(const char *type
)
38 struct device_node
* bk_node
= find_devices("backlight");
41 const char *prop
= get_property(bk_node
,
42 "backlight-control", NULL
);
43 if (prop
&& strncmp(prop
, type
, strlen(type
)) == 0)
50 int pmac_backlight_curve_lookup(struct fb_info
*info
, int value
)
52 int level
= (FB_BACKLIGHT_LEVELS
- 1);
54 if (info
&& info
->bl_dev
) {
57 /* Look for biggest value */
58 for (i
= 0; i
< FB_BACKLIGHT_LEVELS
; i
++)
59 max
= max((int)info
->bl_curve
[i
], max
);
61 /* Look for nearest value */
62 for (i
= 0; i
< FB_BACKLIGHT_LEVELS
; i
++) {
63 int diff
= abs(info
->bl_curve
[i
] - value
);
75 static void pmac_backlight_key(int direction
)
77 mutex_lock(&pmac_backlight_mutex
);
79 struct backlight_properties
*props
;
82 down(&pmac_backlight
->sem
);
83 props
= pmac_backlight
->props
;
85 brightness
= props
->brightness
+
86 ((direction
?-1:1) * (props
->max_brightness
/ 15));
90 else if (brightness
> props
->max_brightness
)
91 brightness
= props
->max_brightness
;
93 props
->brightness
= brightness
;
94 props
->update_status(pmac_backlight
);
96 up(&pmac_backlight
->sem
);
98 mutex_unlock(&pmac_backlight_mutex
);
101 void pmac_backlight_key_up()
103 pmac_backlight_key(0);
106 void pmac_backlight_key_down()
108 pmac_backlight_key(1);
111 int pmac_backlight_set_legacy_brightness(int brightness
)
115 mutex_lock(&pmac_backlight_mutex
);
116 if (pmac_backlight
) {
117 struct backlight_properties
*props
;
119 down(&pmac_backlight
->sem
);
120 props
= pmac_backlight
->props
;
121 props
->brightness
= brightness
*
122 (props
->max_brightness
+ 1) /
123 (OLD_BACKLIGHT_MAX
+ 1);
125 if (props
->brightness
> props
->max_brightness
)
126 props
->brightness
= props
->max_brightness
;
127 else if (props
->brightness
< 0)
128 props
->brightness
= 0;
130 props
->update_status(pmac_backlight
);
131 up(&pmac_backlight
->sem
);
135 mutex_unlock(&pmac_backlight_mutex
);
140 int pmac_backlight_get_legacy_brightness()
144 mutex_lock(&pmac_backlight_mutex
);
145 if (pmac_backlight
) {
146 struct backlight_properties
*props
;
148 down(&pmac_backlight
->sem
);
149 props
= pmac_backlight
->props
;
151 result
= props
->brightness
*
152 (OLD_BACKLIGHT_MAX
+ 1) /
153 (props
->max_brightness
+ 1);
155 up(&pmac_backlight
->sem
);
157 mutex_unlock(&pmac_backlight_mutex
);