Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *
0004  * iPAQ microcontroller backlight support
0005  * Author : Linus Walleij <linus.walleij@linaro.org>
0006  */
0007 
0008 #include <linux/backlight.h>
0009 #include <linux/err.h>
0010 #include <linux/fb.h>
0011 #include <linux/init.h>
0012 #include <linux/mfd/ipaq-micro.h>
0013 #include <linux/module.h>
0014 #include <linux/platform_device.h>
0015 
0016 static int micro_bl_update_status(struct backlight_device *bd)
0017 {
0018     struct ipaq_micro *micro = dev_get_drvdata(&bd->dev);
0019     int intensity = bd->props.brightness;
0020     struct ipaq_micro_msg msg = {
0021         .id = MSG_BACKLIGHT,
0022         .tx_len = 3,
0023     };
0024 
0025     if (bd->props.power != FB_BLANK_UNBLANK)
0026         intensity = 0;
0027     if (bd->props.state & (BL_CORE_FBBLANK | BL_CORE_SUSPENDED))
0028         intensity = 0;
0029 
0030     /*
0031      * Message format:
0032      * Byte 0: backlight instance (usually 1)
0033      * Byte 1: on/off
0034      * Byte 2: intensity, 0-255
0035      */
0036     msg.tx_data[0] = 0x01;
0037     msg.tx_data[1] = intensity > 0 ? 1 : 0;
0038     msg.tx_data[2] = intensity;
0039     return ipaq_micro_tx_msg_sync(micro, &msg);
0040 }
0041 
0042 static const struct backlight_ops micro_bl_ops = {
0043     .options = BL_CORE_SUSPENDRESUME,
0044     .update_status  = micro_bl_update_status,
0045 };
0046 
0047 static const struct backlight_properties micro_bl_props = {
0048     .type = BACKLIGHT_RAW,
0049     .max_brightness = 255,
0050     .power = FB_BLANK_UNBLANK,
0051     .brightness = 64,
0052 };
0053 
0054 static int micro_backlight_probe(struct platform_device *pdev)
0055 {
0056     struct backlight_device *bd;
0057     struct ipaq_micro *micro = dev_get_drvdata(pdev->dev.parent);
0058 
0059     bd = devm_backlight_device_register(&pdev->dev, "ipaq-micro-backlight",
0060                         &pdev->dev, micro, &micro_bl_ops,
0061                         &micro_bl_props);
0062     if (IS_ERR(bd))
0063         return PTR_ERR(bd);
0064 
0065     platform_set_drvdata(pdev, bd);
0066     backlight_update_status(bd);
0067 
0068     return 0;
0069 }
0070 
0071 static struct platform_driver micro_backlight_device_driver = {
0072     .driver = {
0073         .name    = "ipaq-micro-backlight",
0074     },
0075     .probe   = micro_backlight_probe,
0076 };
0077 module_platform_driver(micro_backlight_device_driver);
0078 
0079 MODULE_LICENSE("GPL v2");
0080 MODULE_DESCRIPTION("driver for iPAQ Atmel micro backlight");
0081 MODULE_ALIAS("platform:ipaq-micro-backlight");