xref: /linux/drivers/video/backlight/ipaq_micro_bl.c (revision c95baf12f5077419db01313ab61c2aac007d40cd)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22188a988SLinus Walleij /*
32188a988SLinus Walleij  *
42188a988SLinus Walleij  * iPAQ microcontroller backlight support
52188a988SLinus Walleij  * Author : Linus Walleij <linus.walleij@linaro.org>
62188a988SLinus Walleij  */
72188a988SLinus Walleij 
82188a988SLinus Walleij #include <linux/backlight.h>
92188a988SLinus Walleij #include <linux/err.h>
102188a988SLinus Walleij #include <linux/fb.h>
112188a988SLinus Walleij #include <linux/init.h>
122188a988SLinus Walleij #include <linux/mfd/ipaq-micro.h>
132188a988SLinus Walleij #include <linux/module.h>
142188a988SLinus Walleij #include <linux/platform_device.h>
152188a988SLinus Walleij 
162188a988SLinus Walleij static int micro_bl_update_status(struct backlight_device *bd)
172188a988SLinus Walleij {
182188a988SLinus Walleij 	struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
192188a988SLinus Walleij 	int intensity = bd->props.brightness;
202188a988SLinus Walleij 	struct ipaq_micro_msg msg = {
212188a988SLinus Walleij 		.id = MSG_BACKLIGHT,
222188a988SLinus Walleij 		.tx_len = 3,
232188a988SLinus Walleij 	};
242188a988SLinus Walleij 
252188a988SLinus Walleij 	if (bd->props.power != FB_BLANK_UNBLANK)
262188a988SLinus Walleij 		intensity = 0;
272188a988SLinus Walleij 	if (bd->props.state & (BL_CORE_FBBLANK | BL_CORE_SUSPENDED))
282188a988SLinus Walleij 		intensity = 0;
292188a988SLinus Walleij 
302188a988SLinus Walleij 	/*
312188a988SLinus Walleij 	 * Message format:
322188a988SLinus Walleij 	 * Byte 0: backlight instance (usually 1)
332188a988SLinus Walleij 	 * Byte 1: on/off
342188a988SLinus Walleij 	 * Byte 2: intensity, 0-255
352188a988SLinus Walleij 	 */
362188a988SLinus Walleij 	msg.tx_data[0] = 0x01;
372188a988SLinus Walleij 	msg.tx_data[1] = intensity > 0 ? 1 : 0;
382188a988SLinus Walleij 	msg.tx_data[2] = intensity;
392188a988SLinus Walleij 	return ipaq_micro_tx_msg_sync(micro, &msg);
402188a988SLinus Walleij }
412188a988SLinus Walleij 
422188a988SLinus Walleij static const struct backlight_ops micro_bl_ops = {
432188a988SLinus Walleij 	.options = BL_CORE_SUSPENDRESUME,
442188a988SLinus Walleij 	.update_status  = micro_bl_update_status,
452188a988SLinus Walleij };
462188a988SLinus Walleij 
47*7050a7c3SNishka Dasgupta static const struct backlight_properties micro_bl_props = {
482188a988SLinus Walleij 	.type = BACKLIGHT_RAW,
492188a988SLinus Walleij 	.max_brightness = 255,
502188a988SLinus Walleij 	.power = FB_BLANK_UNBLANK,
512188a988SLinus Walleij 	.brightness = 64,
522188a988SLinus Walleij };
532188a988SLinus Walleij 
542188a988SLinus Walleij static int micro_backlight_probe(struct platform_device *pdev)
552188a988SLinus Walleij {
562188a988SLinus Walleij 	struct backlight_device *bd;
572188a988SLinus Walleij 	struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
582188a988SLinus Walleij 
592188a988SLinus Walleij 	bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
602188a988SLinus Walleij 					    &pdev->dev, micro, &micro_bl_ops,
612188a988SLinus Walleij 					    &micro_bl_props);
622188a988SLinus Walleij 	if (IS_ERR(bd))
632188a988SLinus Walleij 		return PTR_ERR(bd);
642188a988SLinus Walleij 
652188a988SLinus Walleij 	platform_set_drvdata(pdev, bd);
662188a988SLinus Walleij 	backlight_update_status(bd);
672188a988SLinus Walleij 
682188a988SLinus Walleij 	return 0;
692188a988SLinus Walleij }
702188a988SLinus Walleij 
7187464cdbSWei Yongjun static struct platform_driver micro_backlight_device_driver = {
722188a988SLinus Walleij 	.driver = {
732188a988SLinus Walleij 		.name    = "ipaq-micro-backlight",
742188a988SLinus Walleij 	},
752188a988SLinus Walleij 	.probe   = micro_backlight_probe,
762188a988SLinus Walleij };
772188a988SLinus Walleij module_platform_driver(micro_backlight_device_driver);
782188a988SLinus Walleij 
792188a988SLinus Walleij MODULE_LICENSE("GPL v2");
802188a988SLinus Walleij MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
812188a988SLinus Walleij MODULE_ALIAS("platform:ipaq-micro-backlight");
82