Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * LCD Lowlevel Control Abstraction
0004  *
0005  * Copyright (C) 2003,2004 Hewlett-Packard Company
0006  *
0007  */
0008 
0009 #ifndef _LINUX_LCD_H
0010 #define _LINUX_LCD_H
0011 
0012 #include <linux/device.h>
0013 #include <linux/mutex.h>
0014 #include <linux/notifier.h>
0015 #include <linux/fb.h>
0016 
0017 /* Notes on locking:
0018  *
0019  * lcd_device->ops_lock is an internal backlight lock protecting the ops
0020  * field and no code outside the core should need to touch it.
0021  *
0022  * Access to set_power() is serialised by the update_lock mutex since
0023  * most drivers seem to need this and historically get it wrong.
0024  *
0025  * Most drivers don't need locking on their get_power() method.
0026  * If yours does, you need to implement it in the driver. You can use the
0027  * update_lock mutex if appropriate.
0028  *
0029  * Any other use of the locks below is probably wrong.
0030  */
0031 
0032 struct lcd_device;
0033 struct fb_info;
0034 
0035 struct lcd_properties {
0036     /* The maximum value for contrast (read-only) */
0037     int max_contrast;
0038 };
0039 
0040 struct lcd_ops {
0041     /* Get the LCD panel power status (0: full on, 1..3: controller
0042        power on, flat panel power off, 4: full off), see FB_BLANK_XXX */
0043     int (*get_power)(struct lcd_device *);
0044     /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
0045     int (*set_power)(struct lcd_device *, int power);
0046     /* Get the current contrast setting (0-max_contrast) */
0047     int (*get_contrast)(struct lcd_device *);
0048     /* Set LCD panel contrast */
0049         int (*set_contrast)(struct lcd_device *, int contrast);
0050     /* Set LCD panel mode (resolutions ...) */
0051     int (*set_mode)(struct lcd_device *, struct fb_videomode *);
0052     /* Check if given framebuffer device is the one LCD is bound to;
0053        return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
0054     int (*check_fb)(struct lcd_device *, struct fb_info *);
0055 };
0056 
0057 struct lcd_device {
0058     struct lcd_properties props;
0059     /* This protects the 'ops' field. If 'ops' is NULL, the driver that
0060        registered this device has been unloaded, and if class_get_devdata()
0061        points to something in the body of that driver, it is also invalid. */
0062     struct mutex ops_lock;
0063     /* If this is NULL, the backing module is unloaded */
0064     struct lcd_ops *ops;
0065     /* Serialise access to set_power method */
0066     struct mutex update_lock;
0067     /* The framebuffer notifier block */
0068     struct notifier_block fb_notif;
0069 
0070     struct device dev;
0071 };
0072 
0073 struct lcd_platform_data {
0074     /* reset lcd panel device. */
0075     int (*reset)(struct lcd_device *ld);
0076     /* on or off to lcd panel. if 'enable' is 0 then
0077        lcd power off and 1, lcd power on. */
0078     int (*power_on)(struct lcd_device *ld, int enable);
0079 
0080     /* it indicates whether lcd panel was enabled
0081        from bootloader or not. */
0082     int lcd_enabled;
0083     /* it means delay for stable time when it becomes low to high
0084        or high to low that is dependent on whether reset gpio is
0085        low active or high active. */
0086     unsigned int reset_delay;
0087     /* stable time needing to become lcd power on. */
0088     unsigned int power_on_delay;
0089     /* stable time needing to become lcd power off. */
0090     unsigned int power_off_delay;
0091 
0092     /* it could be used for any purpose. */
0093     void *pdata;
0094 };
0095 
0096 static inline void lcd_set_power(struct lcd_device *ld, int power)
0097 {
0098     mutex_lock(&ld->update_lock);
0099     if (ld->ops && ld->ops->set_power)
0100         ld->ops->set_power(ld, power);
0101     mutex_unlock(&ld->update_lock);
0102 }
0103 
0104 extern struct lcd_device *lcd_device_register(const char *name,
0105     struct device *parent, void *devdata, struct lcd_ops *ops);
0106 extern struct lcd_device *devm_lcd_device_register(struct device *dev,
0107     const char *name, struct device *parent,
0108     void *devdata, struct lcd_ops *ops);
0109 extern void lcd_device_unregister(struct lcd_device *ld);
0110 extern void devm_lcd_device_unregister(struct device *dev,
0111     struct lcd_device *ld);
0112 
0113 #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
0114 
0115 static inline void * lcd_get_data(struct lcd_device *ld_dev)
0116 {
0117     return dev_get_drvdata(&ld_dev->dev);
0118 }
0119 
0120 
0121 #endif