WIP FPC-III support
[linux/fpc-iii.git] / drivers / video / backlight / ipaq_micro_bl.c
blob85b16cc828789efea742a0e74ee6a9768722590b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
4 * iPAQ microcontroller backlight support
5 * Author : Linus Walleij <linus.walleij@linaro.org>
6 */
8 #include <linux/backlight.h>
9 #include <linux/err.h>
10 #include <linux/fb.h>
11 #include <linux/init.h>
12 #include <linux/mfd/ipaq-micro.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 static int micro_bl_update_status(struct backlight_device *bd)
18 struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
19 int intensity = bd->props.brightness;
20 struct ipaq_micro_msg msg = {
21 .id = MSG_BACKLIGHT,
22 .tx_len = 3,
25 if (bd->props.power != FB_BLANK_UNBLANK)
26 intensity = 0;
27 if (bd->props.state & (BL_CORE_FBBLANK | BL_CORE_SUSPENDED))
28 intensity = 0;
31 * Message format:
32 * Byte 0: backlight instance (usually 1)
33 * Byte 1: on/off
34 * Byte 2: intensity, 0-255
36 msg.tx_data[0] = 0x01;
37 msg.tx_data[1] = intensity > 0 ? 1 : 0;
38 msg.tx_data[2] = intensity;
39 return ipaq_micro_tx_msg_sync(micro, &msg);
42 static const struct backlight_ops micro_bl_ops = {
43 .options = BL_CORE_SUSPENDRESUME,
44 .update_status = micro_bl_update_status,
47 static const struct backlight_properties micro_bl_props = {
48 .type = BACKLIGHT_RAW,
49 .max_brightness = 255,
50 .power = FB_BLANK_UNBLANK,
51 .brightness = 64,
54 static int micro_backlight_probe(struct platform_device *pdev)
56 struct backlight_device *bd;
57 struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
59 bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
60 &pdev->dev, micro, &micro_bl_ops,
61 &micro_bl_props);
62 if (IS_ERR(bd))
63 return PTR_ERR(bd);
65 platform_set_drvdata(pdev, bd);
66 backlight_update_status(bd);
68 return 0;
71 static struct platform_driver micro_backlight_device_driver = {
72 .driver = {
73 .name = "ipaq-micro-backlight",
75 .probe = micro_backlight_probe,
77 module_platform_driver(micro_backlight_device_driver);
79 MODULE_LICENSE("GPL v2");
80 MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
81 MODULE_ALIAS("platform:ipaq-micro-backlight");