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