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