1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/video/backlight/platform_lcd.c
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
7 * Generic platform-device LCD power control interface.
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/lcd.h>
13 #include <linux/slab.h>
15 #include <video/platform_lcd.h>
19 struct lcd_device
*lcd
;
20 struct plat_lcd_data
*pdata
;
23 unsigned int suspended
:1;
26 static inline struct platform_lcd
*to_our_lcd(struct lcd_device
*lcd
)
28 return lcd_get_data(lcd
);
31 static int platform_lcd_get_power(struct lcd_device
*lcd
)
33 struct platform_lcd
*plcd
= to_our_lcd(lcd
);
38 static int platform_lcd_set_power(struct lcd_device
*lcd
, int power
)
40 struct platform_lcd
*plcd
= to_our_lcd(lcd
);
43 if (power
== LCD_POWER_OFF
|| plcd
->suspended
)
46 plcd
->pdata
->set_power(plcd
->pdata
, lcd_power
);
52 static bool platform_lcd_controls_device(struct lcd_device
*lcd
, struct device
*display_device
)
54 struct platform_lcd
*plcd
= to_our_lcd(lcd
);
56 return plcd
->us
->parent
== display_device
;
59 static const struct lcd_ops platform_lcd_ops
= {
60 .get_power
= platform_lcd_get_power
,
61 .set_power
= platform_lcd_set_power
,
62 .controls_device
= platform_lcd_controls_device
,
65 static int platform_lcd_probe(struct platform_device
*pdev
)
67 struct plat_lcd_data
*pdata
;
68 struct platform_lcd
*plcd
;
69 struct device
*dev
= &pdev
->dev
;
72 pdata
= dev_get_platdata(&pdev
->dev
);
74 dev_err(dev
, "no platform data supplied\n");
79 err
= pdata
->probe(pdata
);
84 plcd
= devm_kzalloc(&pdev
->dev
, sizeof(struct platform_lcd
),
91 plcd
->lcd
= devm_lcd_device_register(&pdev
->dev
, dev_name(dev
), dev
,
92 plcd
, &platform_lcd_ops
);
93 if (IS_ERR(plcd
->lcd
)) {
94 dev_err(dev
, "cannot register lcd device\n");
95 return PTR_ERR(plcd
->lcd
);
98 platform_set_drvdata(pdev
, plcd
);
99 platform_lcd_set_power(plcd
->lcd
, LCD_POWER_REDUCED
);
104 #ifdef CONFIG_PM_SLEEP
105 static int platform_lcd_suspend(struct device
*dev
)
107 struct platform_lcd
*plcd
= dev_get_drvdata(dev
);
110 platform_lcd_set_power(plcd
->lcd
, plcd
->power
);
115 static int platform_lcd_resume(struct device
*dev
)
117 struct platform_lcd
*plcd
= dev_get_drvdata(dev
);
120 platform_lcd_set_power(plcd
->lcd
, plcd
->power
);
126 static SIMPLE_DEV_PM_OPS(platform_lcd_pm_ops
, platform_lcd_suspend
,
127 platform_lcd_resume
);
129 static struct platform_driver platform_lcd_driver
= {
131 .name
= "platform-lcd",
132 .pm
= &platform_lcd_pm_ops
,
134 .probe
= platform_lcd_probe
,
137 module_platform_driver(platform_lcd_driver
);
139 MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
140 MODULE_DESCRIPTION("Generic platform-device LCD power control interface");
141 MODULE_LICENSE("GPL v2");
142 MODULE_ALIAS("platform:platform-lcd");