8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
12 #include <linux/device.h>
15 #include <linux/ctype.h>
18 #include <linux/slab.h>
20 #ifdef CONFIG_PMAC_BACKLIGHT
24 static const char *
const backlight_types[] = {
30 #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
31 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
49 if (!bd->
ops->check_fb ||
50 bd->
ops->check_fb(bd, evdata->
info)) {
51 bd->
props.fb_blank = *(
int *)evdata->
data;
56 backlight_update_status(bd);
65 bd->
fb_notif.notifier_call = fb_notifier_callback;
92 envp[0] =
"SOURCE=sysfs";
95 envp[0] =
"SOURCE=hotkey";
98 envp[0] =
"SOURCE=unknown";
121 rc = kstrtoul(buf, 0, &power);
128 pr_debug(
"set power to %lu\n", power);
129 if (bd->
props.power != power) {
130 bd->
props.power = power;
131 backlight_update_status(bd);
148 static ssize_t backlight_store_brightness(
struct device *dev,
155 rc = kstrtoul(buf, 0, &brightness);
163 if (brightness > bd->
props.max_brightness)
166 pr_debug(
"set brightness to %lu\n", brightness);
168 backlight_update_status(bd);
184 return sprintf(buf,
"%s\n", backlight_types[bd->
props.type]);
187 static ssize_t backlight_show_max_brightness(
struct device *dev,
195 static ssize_t backlight_show_actual_brightness(
struct device *dev,
202 if (bd->
ops && bd->
ops->get_brightness)
203 rc =
sprintf(buf,
"%d\n", bd->
ops->get_brightness(bd));
209 static struct class *backlight_class;
218 backlight_update_status(bd);
225 static int backlight_resume(
struct device *dev)
232 backlight_update_status(bd);
239 static void bl_device_release(
struct device *dev)
246 __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power),
247 __ATTR(brightness, 0644, backlight_show_brightness,
248 backlight_store_brightness),
249 __ATTR(actual_brightness, 0444, backlight_show_actual_brightness,
251 __ATTR(max_brightness, 0444, backlight_show_max_brightness,
NULL),
268 if (bd->
ops && bd->
ops->get_brightness)
269 bd->
props.brightness = bd->
ops->get_brightness(bd);
271 backlight_generate_event(bd, reason);
295 pr_debug(
"backlight_device_register: name=%s\n", name);
304 new_bd->
dev.class = backlight_class;
305 new_bd->
dev.parent = parent;
306 new_bd->
dev.release = bl_device_release;
315 WARN(1,
"%s: invalid backlight type", name);
328 rc = backlight_register_fb(new_bd);
336 #ifdef CONFIG_PMAC_BACKLIGHT
358 #ifdef CONFIG_PMAC_BACKLIGHT
368 backlight_unregister_fb(bd);
373 static void __exit backlight_class_exit(
void)
378 static int __init backlight_class_init(
void)
381 if (IS_ERR(backlight_class)) {
382 pr_warn(
"Unable to create backlight class; errno = %ld\n",
383 PTR_ERR(backlight_class));
384 return PTR_ERR(backlight_class);
387 backlight_class->
dev_attrs = bl_device_attributes;
388 backlight_class->
suspend = backlight_suspend;
389 backlight_class->
resume = backlight_resume;