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 char *prop = get_property(bk_node, "backlight-control", NULL);
42 if (prop && strncmp(prop, type, strlen(type)) == 0)
49 int pmac_backlight_curve_lookup(struct fb_info *info, int value)
51 int level = (FB_BACKLIGHT_LEVELS - 1);
53 if (info && info->bl_dev) {
56 /* Look for biggest value */
57 for (i = 0; i < FB_BACKLIGHT_LEVELS; i++)
58 max = max((int)info->bl_curve[i], max);
60 /* Look for nearest value */
61 for (i = 0; i < FB_BACKLIGHT_LEVELS; i++) {
62 int diff = abs(info->bl_curve[i] - value);
74 static void pmac_backlight_key(int direction)
76 mutex_lock(&pmac_backlight_mutex);
78 struct backlight_properties *props;
81 down(&pmac_backlight->sem);
82 props = pmac_backlight->props;
84 brightness = props->brightness +
85 ((direction?-1:1) * (props->max_brightness / 15));
89 else if (brightness > props->max_brightness)
90 brightness = props->max_brightness;
92 props->brightness = brightness;
93 props->update_status(pmac_backlight);
95 up(&pmac_backlight->sem);
97 mutex_unlock(&pmac_backlight_mutex);
100 void pmac_backlight_key_up()
102 pmac_backlight_key(0);
105 void pmac_backlight_key_down()
107 pmac_backlight_key(1);
110 int pmac_backlight_set_legacy_brightness(int brightness)
114 mutex_lock(&pmac_backlight_mutex);
115 if (pmac_backlight) {
116 struct backlight_properties *props;
118 down(&pmac_backlight->sem);
119 props = pmac_backlight->props;
120 props->brightness = brightness *
121 (props->max_brightness + 1) /
122 (OLD_BACKLIGHT_MAX + 1);
124 if (props->brightness > props->max_brightness)
125 props->brightness = props->max_brightness;
126 else if (props->brightness < 0)
127 props->brightness = 0;
129 props->update_status(pmac_backlight);
130 up(&pmac_backlight->sem);
134 mutex_unlock(&pmac_backlight_mutex);
139 int pmac_backlight_get_legacy_brightness()
143 mutex_lock(&pmac_backlight_mutex);
144 if (pmac_backlight) {
145 struct backlight_properties *props;
147 down(&pmac_backlight->sem);
148 props = pmac_backlight->props;
150 result = props->brightness *
151 (OLD_BACKLIGHT_MAX + 1) /
152 (props->max_brightness + 1);
154 up(&pmac_backlight->sem);
156 mutex_unlock(&pmac_backlight_mutex);