0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/backlight.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/mfd/rave-sp.h>
0014 #include <linux/platform_device.h>
0015
0016 #define RAVE_SP_BACKLIGHT_LCD_EN BIT(7)
0017
0018 static int rave_sp_backlight_update_status(struct backlight_device *bd)
0019 {
0020 const struct backlight_properties *p = &bd->props;
0021 const u8 intensity =
0022 (p->power == FB_BLANK_UNBLANK) ? p->brightness : 0;
0023 struct rave_sp *sp = dev_get_drvdata(&bd->dev);
0024 u8 cmd[] = {
0025 [0] = RAVE_SP_CMD_SET_BACKLIGHT,
0026 [1] = 0,
0027 [2] = intensity ? RAVE_SP_BACKLIGHT_LCD_EN | intensity : 0,
0028 [3] = 0,
0029 [4] = 0,
0030 };
0031
0032 return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
0033 }
0034
0035 static const struct backlight_ops rave_sp_backlight_ops = {
0036 .options = BL_CORE_SUSPENDRESUME,
0037 .update_status = rave_sp_backlight_update_status,
0038 };
0039
0040 static struct backlight_properties rave_sp_backlight_props = {
0041 .type = BACKLIGHT_PLATFORM,
0042 .max_brightness = 100,
0043 .brightness = 50,
0044 };
0045
0046 static int rave_sp_backlight_probe(struct platform_device *pdev)
0047 {
0048 struct device *dev = &pdev->dev;
0049 struct backlight_device *bd;
0050
0051 bd = devm_backlight_device_register(dev, pdev->name, dev,
0052 dev_get_drvdata(dev->parent),
0053 &rave_sp_backlight_ops,
0054 &rave_sp_backlight_props);
0055 if (IS_ERR(bd))
0056 return PTR_ERR(bd);
0057
0058
0059
0060
0061
0062
0063 if (!dev->of_node->phandle)
0064 backlight_update_status(bd);
0065
0066 return 0;
0067 }
0068
0069 static const struct of_device_id rave_sp_backlight_of_match[] = {
0070 { .compatible = "zii,rave-sp-backlight" },
0071 {}
0072 };
0073
0074 static struct platform_driver rave_sp_backlight_driver = {
0075 .probe = rave_sp_backlight_probe,
0076 .driver = {
0077 .name = KBUILD_MODNAME,
0078 .of_match_table = rave_sp_backlight_of_match,
0079 },
0080 };
0081 module_platform_driver(rave_sp_backlight_driver);
0082
0083 MODULE_DEVICE_TABLE(of, rave_sp_backlight_of_match);
0084 MODULE_LICENSE("GPL");
0085 MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
0086 MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
0087 MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
0088 MODULE_DESCRIPTION("RAVE SP Backlight driver");