xref: /OK3568_Linux_fs/kernel/include/linux/lcd.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * LCD Lowlevel Control Abstraction
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2003,2004 Hewlett-Packard Company
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _LINUX_LCD_H
10*4882a593Smuzhiyun #define _LINUX_LCD_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/device.h>
13*4882a593Smuzhiyun #include <linux/mutex.h>
14*4882a593Smuzhiyun #include <linux/notifier.h>
15*4882a593Smuzhiyun #include <linux/fb.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* Notes on locking:
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * lcd_device->ops_lock is an internal backlight lock protecting the ops
20*4882a593Smuzhiyun  * field and no code outside the core should need to touch it.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * Access to set_power() is serialised by the update_lock mutex since
23*4882a593Smuzhiyun  * most drivers seem to need this and historically get it wrong.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Most drivers don't need locking on their get_power() method.
26*4882a593Smuzhiyun  * If yours does, you need to implement it in the driver. You can use the
27*4882a593Smuzhiyun  * update_lock mutex if appropriate.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * Any other use of the locks below is probably wrong.
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct lcd_device;
33*4882a593Smuzhiyun struct fb_info;
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun struct lcd_properties {
36*4882a593Smuzhiyun 	/* The maximum value for contrast (read-only) */
37*4882a593Smuzhiyun 	int max_contrast;
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun struct lcd_ops {
41*4882a593Smuzhiyun 	/* Get the LCD panel power status (0: full on, 1..3: controller
42*4882a593Smuzhiyun 	   power on, flat panel power off, 4: full off), see FB_BLANK_XXX */
43*4882a593Smuzhiyun 	int (*get_power)(struct lcd_device *);
44*4882a593Smuzhiyun 	/* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
45*4882a593Smuzhiyun 	int (*set_power)(struct lcd_device *, int power);
46*4882a593Smuzhiyun 	/* Get the current contrast setting (0-max_contrast) */
47*4882a593Smuzhiyun 	int (*get_contrast)(struct lcd_device *);
48*4882a593Smuzhiyun 	/* Set LCD panel contrast */
49*4882a593Smuzhiyun         int (*set_contrast)(struct lcd_device *, int contrast);
50*4882a593Smuzhiyun 	/* Set LCD panel mode (resolutions ...) */
51*4882a593Smuzhiyun 	int (*set_mode)(struct lcd_device *, struct fb_videomode *);
52*4882a593Smuzhiyun 	/* Check if given framebuffer device is the one LCD is bound to;
53*4882a593Smuzhiyun 	   return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
54*4882a593Smuzhiyun 	int (*check_fb)(struct lcd_device *, struct fb_info *);
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun struct lcd_device {
58*4882a593Smuzhiyun 	struct lcd_properties props;
59*4882a593Smuzhiyun 	/* This protects the 'ops' field. If 'ops' is NULL, the driver that
60*4882a593Smuzhiyun 	   registered this device has been unloaded, and if class_get_devdata()
61*4882a593Smuzhiyun 	   points to something in the body of that driver, it is also invalid. */
62*4882a593Smuzhiyun 	struct mutex ops_lock;
63*4882a593Smuzhiyun 	/* If this is NULL, the backing module is unloaded */
64*4882a593Smuzhiyun 	struct lcd_ops *ops;
65*4882a593Smuzhiyun 	/* Serialise access to set_power method */
66*4882a593Smuzhiyun 	struct mutex update_lock;
67*4882a593Smuzhiyun 	/* The framebuffer notifier block */
68*4882a593Smuzhiyun 	struct notifier_block fb_notif;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	struct device dev;
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun struct lcd_platform_data {
74*4882a593Smuzhiyun 	/* reset lcd panel device. */
75*4882a593Smuzhiyun 	int (*reset)(struct lcd_device *ld);
76*4882a593Smuzhiyun 	/* on or off to lcd panel. if 'enable' is 0 then
77*4882a593Smuzhiyun 	   lcd power off and 1, lcd power on. */
78*4882a593Smuzhiyun 	int (*power_on)(struct lcd_device *ld, int enable);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	/* it indicates whether lcd panel was enabled
81*4882a593Smuzhiyun 	   from bootloader or not. */
82*4882a593Smuzhiyun 	int lcd_enabled;
83*4882a593Smuzhiyun 	/* it means delay for stable time when it becomes low to high
84*4882a593Smuzhiyun 	   or high to low that is dependent on whether reset gpio is
85*4882a593Smuzhiyun 	   low active or high active. */
86*4882a593Smuzhiyun 	unsigned int reset_delay;
87*4882a593Smuzhiyun 	/* stable time needing to become lcd power on. */
88*4882a593Smuzhiyun 	unsigned int power_on_delay;
89*4882a593Smuzhiyun 	/* stable time needing to become lcd power off. */
90*4882a593Smuzhiyun 	unsigned int power_off_delay;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	/* it could be used for any purpose. */
93*4882a593Smuzhiyun 	void *pdata;
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun 
lcd_set_power(struct lcd_device * ld,int power)96*4882a593Smuzhiyun static inline void lcd_set_power(struct lcd_device *ld, int power)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	mutex_lock(&ld->update_lock);
99*4882a593Smuzhiyun 	if (ld->ops && ld->ops->set_power)
100*4882a593Smuzhiyun 		ld->ops->set_power(ld, power);
101*4882a593Smuzhiyun 	mutex_unlock(&ld->update_lock);
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun extern struct lcd_device *lcd_device_register(const char *name,
105*4882a593Smuzhiyun 	struct device *parent, void *devdata, struct lcd_ops *ops);
106*4882a593Smuzhiyun extern struct lcd_device *devm_lcd_device_register(struct device *dev,
107*4882a593Smuzhiyun 	const char *name, struct device *parent,
108*4882a593Smuzhiyun 	void *devdata, struct lcd_ops *ops);
109*4882a593Smuzhiyun extern void lcd_device_unregister(struct lcd_device *ld);
110*4882a593Smuzhiyun extern void devm_lcd_device_unregister(struct device *dev,
111*4882a593Smuzhiyun 	struct lcd_device *ld);
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
114*4882a593Smuzhiyun 
lcd_get_data(struct lcd_device * ld_dev)115*4882a593Smuzhiyun static inline void * lcd_get_data(struct lcd_device *ld_dev)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun 	return dev_get_drvdata(&ld_dev->dev);
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun #endif
122