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