Linux Audio

Check our new training course

Loading...
v4.17
 
 1/*
 2 * This program is free software; you can redistribute it and/or modify
 3 * it under the terms of the GNU General Public License version 2 as
 4 * published by the Free Software Foundation.
 5 *
 6 * iPAQ microcontroller backlight support
 7 * Author : Linus Walleij <linus.walleij@linaro.org>
 8 */
 9
10#include <linux/backlight.h>
11#include <linux/err.h>
12#include <linux/fb.h>
13#include <linux/init.h>
14#include <linux/mfd/ipaq-micro.h>
15#include <linux/module.h>
16#include <linux/platform_device.h>
17
18static int micro_bl_update_status(struct backlight_device *bd)
19{
20	struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
21	int intensity = bd->props.brightness;
22	struct ipaq_micro_msg msg = {
23		.id = MSG_BACKLIGHT,
24		.tx_len = 3,
25	};
26
27	if (bd->props.power != FB_BLANK_UNBLANK)
28		intensity = 0;
29	if (bd->props.state & (BL_CORE_FBBLANK | BL_CORE_SUSPENDED))
30		intensity = 0;
31
32	/*
33	 * Message format:
34	 * Byte 0: backlight instance (usually 1)
35	 * Byte 1: on/off
36	 * Byte 2: intensity, 0-255
37	 */
38	msg.tx_data[0] = 0x01;
39	msg.tx_data[1] = intensity > 0 ? 1 : 0;
40	msg.tx_data[2] = intensity;
41	return ipaq_micro_tx_msg_sync(micro, &msg);
42}
43
44static const struct backlight_ops micro_bl_ops = {
45	.options = BL_CORE_SUSPENDRESUME,
46	.update_status  = micro_bl_update_status,
47};
48
49static struct backlight_properties micro_bl_props = {
50	.type = BACKLIGHT_RAW,
51	.max_brightness = 255,
52	.power = FB_BLANK_UNBLANK,
53	.brightness = 64,
54};
55
56static int micro_backlight_probe(struct platform_device *pdev)
57{
58	struct backlight_device *bd;
59	struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
60
61	bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
62					    &pdev->dev, micro, &micro_bl_ops,
63					    &micro_bl_props);
64	if (IS_ERR(bd))
65		return PTR_ERR(bd);
66
67	platform_set_drvdata(pdev, bd);
68	backlight_update_status(bd);
69
70	return 0;
71}
72
73static struct platform_driver micro_backlight_device_driver = {
74	.driver = {
75		.name    = "ipaq-micro-backlight",
76	},
77	.probe   = micro_backlight_probe,
78};
79module_platform_driver(micro_backlight_device_driver);
80
81MODULE_LICENSE("GPL v2");
82MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
83MODULE_ALIAS("platform:ipaq-micro-backlight");
v6.8
 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/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>
15
16static int micro_bl_update_status(struct backlight_device *bd)
17{
18	struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
19	int intensity = backlight_get_brightness(bd);
20	struct ipaq_micro_msg msg = {
21		.id = MSG_BACKLIGHT,
22		.tx_len = 3,
23	};
24
 
 
 
 
 
25	/*
26	 * Message format:
27	 * Byte 0: backlight instance (usually 1)
28	 * Byte 1: on/off
29	 * Byte 2: intensity, 0-255
30	 */
31	msg.tx_data[0] = 0x01;
32	msg.tx_data[1] = intensity > 0 ? 1 : 0;
33	msg.tx_data[2] = intensity;
34	return ipaq_micro_tx_msg_sync(micro, &msg);
35}
36
37static const struct backlight_ops micro_bl_ops = {
38	.options = BL_CORE_SUSPENDRESUME,
39	.update_status  = micro_bl_update_status,
40};
41
42static const struct backlight_properties micro_bl_props = {
43	.type = BACKLIGHT_RAW,
44	.max_brightness = 255,
45	.power = FB_BLANK_UNBLANK,
46	.brightness = 64,
47};
48
49static int micro_backlight_probe(struct platform_device *pdev)
50{
51	struct backlight_device *bd;
52	struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
53
54	bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
55					    &pdev->dev, micro, &micro_bl_ops,
56					    &micro_bl_props);
57	if (IS_ERR(bd))
58		return PTR_ERR(bd);
59
60	platform_set_drvdata(pdev, bd);
61	backlight_update_status(bd);
62
63	return 0;
64}
65
66static struct platform_driver micro_backlight_device_driver = {
67	.driver = {
68		.name    = "ipaq-micro-backlight",
69	},
70	.probe   = micro_backlight_probe,
71};
72module_platform_driver(micro_backlight_device_driver);
73
74MODULE_LICENSE("GPL v2");
75MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
76MODULE_ALIAS("platform:ipaq-micro-backlight");