File: ipaq_micro_bl.c

package info (click to toggle)
linux 6.16.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,724,628 kB
  • sloc: ansic: 26,562,645; asm: 271,329; sh: 144,039; python: 72,469; makefile: 57,135; perl: 36,821; xml: 19,553; cpp: 5,820; yacc: 4,915; lex: 2,955; awk: 1,667; sed: 28; ruby: 25
file content (75 lines) | stat: -rw-r--r-- 1,882 bytes parent folder | download | duplicates (23)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: GPL-2.0-only
/*
 *
 * iPAQ microcontroller backlight support
 * Author : Linus Walleij <linus.walleij@linaro.org>
 */

#include <linux/backlight.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/mfd/ipaq-micro.h>
#include <linux/module.h>
#include <linux/platform_device.h>

static int micro_bl_update_status(struct backlight_device *bd)
{
	struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
	int intensity = backlight_get_brightness(bd);
	struct ipaq_micro_msg msg = {
		.id = MSG_BACKLIGHT,
		.tx_len = 3,
	};

	/*
	 * Message format:
	 * Byte 0: backlight instance (usually 1)
	 * Byte 1: on/off
	 * Byte 2: intensity, 0-255
	 */
	msg.tx_data[0] = 0x01;
	msg.tx_data[1] = intensity > 0 ? 1 : 0;
	msg.tx_data[2] = intensity;
	return ipaq_micro_tx_msg_sync(micro, &msg);
}

static const struct backlight_ops micro_bl_ops = {
	.options = BL_CORE_SUSPENDRESUME,
	.update_status  = micro_bl_update_status,
};

static const struct backlight_properties micro_bl_props = {
	.type = BACKLIGHT_RAW,
	.max_brightness = 255,
	.power = BACKLIGHT_POWER_ON,
	.brightness = 64,
};

static int micro_backlight_probe(struct platform_device *pdev)
{
	struct backlight_device *bd;
	struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);

	bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
					    &pdev->dev, micro, &micro_bl_ops,
					    &micro_bl_props);
	if (IS_ERR(bd))
		return PTR_ERR(bd);

	platform_set_drvdata(pdev, bd);
	backlight_update_status(bd);

	return 0;
}

static struct platform_driver micro_backlight_device_driver = {
	.driver = {
		.name    = "ipaq-micro-backlight",
	},
	.probe   = micro_backlight_probe,
};
module_platform_driver(micro_backlight_device_driver);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
MODULE_ALIAS("platform:ipaq-micro-backlight");