Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *
0004  * Backlight driver for HP Jornada 700 series (710/720/728)
0005  * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
0006  */
0007 
0008 #include <linux/backlight.h>
0009 #include <linux/device.h>
0010 #include <linux/fb.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 
0015 #include <mach/jornada720.h>
0016 #include <mach/hardware.h>
0017 
0018 #include <video/s1d13xxxfb.h>
0019 
0020 #define BL_MAX_BRIGHT   255
0021 #define BL_DEF_BRIGHT   25
0022 
0023 static int jornada_bl_get_brightness(struct backlight_device *bd)
0024 {
0025     int ret;
0026 
0027     /* check if backlight is on */
0028     if (!(PPSR & PPC_LDD1))
0029         return 0;
0030 
0031     jornada_ssp_start();
0032 
0033     /* cmd should return txdummy */
0034     ret = jornada_ssp_byte(GETBRIGHTNESS);
0035 
0036     if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) {
0037         dev_err(&bd->dev, "get brightness timeout\n");
0038         jornada_ssp_end();
0039         return -ETIMEDOUT;
0040     }
0041 
0042     /* exchange txdummy for value */
0043     ret = jornada_ssp_byte(TXDUMMY);
0044 
0045     jornada_ssp_end();
0046 
0047     return BL_MAX_BRIGHT - ret;
0048 }
0049 
0050 static int jornada_bl_update_status(struct backlight_device *bd)
0051 {
0052     int ret = 0;
0053 
0054     jornada_ssp_start();
0055 
0056     /* If backlight is off then really turn it off */
0057     if (backlight_is_blank(bd)) {
0058         ret = jornada_ssp_byte(BRIGHTNESSOFF);
0059         if (ret != TXDUMMY) {
0060             dev_info(&bd->dev, "brightness off timeout\n");
0061             /* turn off backlight */
0062             PPSR &= ~PPC_LDD1;
0063             PPDR |= PPC_LDD1;
0064             ret = -ETIMEDOUT;
0065         }
0066     } else  /* turn on backlight */
0067         PPSR |= PPC_LDD1;
0068 
0069     /* send command to our mcu */
0070     if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
0071         dev_info(&bd->dev, "failed to set brightness\n");
0072         ret = -ETIMEDOUT;
0073         goto out;
0074     }
0075 
0076     /*
0077      * at this point we expect that the mcu has accepted
0078      * our command and is waiting for our new value
0079      * please note that maximum brightness is 255,
0080      * but due to physical layout it is equal to 0, so we simply
0081      * invert the value (MAX VALUE - NEW VALUE).
0082      */
0083     if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
0084         != TXDUMMY) {
0085         dev_err(&bd->dev, "set brightness failed\n");
0086         ret = -ETIMEDOUT;
0087     }
0088 
0089     /*
0090      * If infact we get an TXDUMMY as output we are happy and dont
0091      * make any further comments about it
0092      */
0093 out:
0094     jornada_ssp_end();
0095 
0096     return ret;
0097 }
0098 
0099 static const struct backlight_ops jornada_bl_ops = {
0100     .get_brightness = jornada_bl_get_brightness,
0101     .update_status = jornada_bl_update_status,
0102     .options = BL_CORE_SUSPENDRESUME,
0103 };
0104 
0105 static int jornada_bl_probe(struct platform_device *pdev)
0106 {
0107     struct backlight_properties props;
0108     int ret;
0109     struct backlight_device *bd;
0110 
0111     memset(&props, 0, sizeof(struct backlight_properties));
0112     props.type = BACKLIGHT_RAW;
0113     props.max_brightness = BL_MAX_BRIGHT;
0114 
0115     bd = devm_backlight_device_register(&pdev->dev, S1D_DEVICENAME,
0116                     &pdev->dev, NULL, &jornada_bl_ops,
0117                     &props);
0118     if (IS_ERR(bd)) {
0119         ret = PTR_ERR(bd);
0120         dev_err(&pdev->dev, "failed to register device, err=%x\n", ret);
0121         return ret;
0122     }
0123 
0124     bd->props.power = FB_BLANK_UNBLANK;
0125     bd->props.brightness = BL_DEF_BRIGHT;
0126     /*
0127      * note. make sure max brightness is set otherwise
0128      * you will get seemingly non-related errors when
0129      * trying to change brightness
0130      */
0131     jornada_bl_update_status(bd);
0132 
0133     platform_set_drvdata(pdev, bd);
0134     dev_info(&pdev->dev, "HP Jornada 700 series backlight driver\n");
0135 
0136     return 0;
0137 }
0138 
0139 static struct platform_driver jornada_bl_driver = {
0140     .probe      = jornada_bl_probe,
0141     .driver = {
0142         .name   = "jornada_bl",
0143     },
0144 };
0145 
0146 module_platform_driver(jornada_bl_driver);
0147 
0148 MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
0149 MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
0150 MODULE_LICENSE("GPL");