1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 *
4 * iPAQ microcontroller backlight support
5 * Author : Linus Walleij <linus.walleij@linaro.org>
6 */
7
8 #include <linux/backlight.h>
9 #include <linux/err.h>
10 #include <linux/init.h>
11 #include <linux/mfd/ipaq-micro.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14
micro_bl_update_status(struct backlight_device * bd)15 static int micro_bl_update_status(struct backlight_device *bd)
16 {
17 struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
18 int intensity = backlight_get_brightness(bd);
19 struct ipaq_micro_msg msg = {
20 .id = MSG_BACKLIGHT,
21 .tx_len = 3,
22 };
23
24 /*
25 * Message format:
26 * Byte 0: backlight instance (usually 1)
27 * Byte 1: on/off
28 * Byte 2: intensity, 0-255
29 */
30 msg.tx_data[0] = 0x01;
31 msg.tx_data[1] = intensity > 0 ? 1 : 0;
32 msg.tx_data[2] = intensity;
33 return ipaq_micro_tx_msg_sync(micro, &msg);
34 }
35
36 static const struct backlight_ops micro_bl_ops = {
37 .options = BL_CORE_SUSPENDRESUME,
38 .update_status = micro_bl_update_status,
39 };
40
41 static const struct backlight_properties micro_bl_props = {
42 .type = BACKLIGHT_RAW,
43 .max_brightness = 255,
44 .power = BACKLIGHT_POWER_ON,
45 .brightness = 64,
46 };
47
micro_backlight_probe(struct platform_device * pdev)48 static int micro_backlight_probe(struct platform_device *pdev)
49 {
50 struct backlight_device *bd;
51 struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
52
53 bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
54 &pdev->dev, micro, µ_bl_ops,
55 µ_bl_props);
56 if (IS_ERR(bd))
57 return PTR_ERR(bd);
58
59 platform_set_drvdata(pdev, bd);
60 backlight_update_status(bd);
61
62 return 0;
63 }
64
65 static struct platform_driver micro_backlight_device_driver = {
66 .driver = {
67 .name = "ipaq-micro-backlight",
68 },
69 .probe = micro_backlight_probe,
70 };
71 module_platform_driver(micro_backlight_device_driver);
72
73 MODULE_LICENSE("GPL v2");
74 MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
75 MODULE_ALIAS("platform:ipaq-micro-backlight");
76