blob: 851eee8fff257836c06ed5b8b7f4ddb7d0e87e2a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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>
Richard Purdie28ee0862007-02-08 22:25:09 +000013#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/notifier.h>
Eric Miaofaa312d2008-08-29 04:18:43 +080015#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Richard Purdie28ee0862007-02-08 22:25:09 +000017/* Notes on locking:
18 *
Richard Purdie599a52d2007-02-10 23:07:48 +000019 * lcd_device->ops_lock is an internal backlight lock protecting the ops
Richard Purdie28ee0862007-02-08 22:25:09 +000020 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070032struct lcd_device;
33struct fb_info;
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035struct lcd_properties {
Richard Purdie599a52d2007-02-10 23:07:48 +000036 /* The maximum value for contrast (read-only) */
37 int max_contrast;
38};
39
40struct lcd_ops {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 /* 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 *);
Inki Daed54ad832012-05-29 15:07:13 -070044 /*
45 * Enable or disable power to the LCD(0: on; 4: off, see FB_BLANK_XXX)
46 * and this callback would be called proir to fb driver's callback.
47 *
48 * P.S. note that if early_set_power is not NULL then early fb notifier
49 * would be registered.
50 */
51 int (*early_set_power)(struct lcd_device *, int power);
52 /* revert the effects of the early blank event. */
53 int (*r_early_set_power)(struct lcd_device *, int power);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
55 int (*set_power)(struct lcd_device *, int power);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 /* Get the current contrast setting (0-max_contrast) */
57 int (*get_contrast)(struct lcd_device *);
58 /* Set LCD panel contrast */
59 int (*set_contrast)(struct lcd_device *, int contrast);
Eric Miaofaa312d2008-08-29 04:18:43 +080060 /* Set LCD panel mode (resolutions ...) */
61 int (*set_mode)(struct lcd_device *, struct fb_videomode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* Check if given framebuffer device is the one LCD is bound to;
63 return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
Ben Dooks0c531362008-07-23 21:31:38 -070064 int (*check_fb)(struct lcd_device *, struct fb_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
67struct lcd_device {
Richard Purdie599a52d2007-02-10 23:07:48 +000068 struct lcd_properties props;
69 /* This protects the 'ops' field. If 'ops' is NULL, the driver that
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 registered this device has been unloaded, and if class_get_devdata()
71 points to something in the body of that driver, it is also invalid. */
Richard Purdie599a52d2007-02-10 23:07:48 +000072 struct mutex ops_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /* If this is NULL, the backing module is unloaded */
Richard Purdie599a52d2007-02-10 23:07:48 +000074 struct lcd_ops *ops;
Richard Purdie28ee0862007-02-08 22:25:09 +000075 /* Serialise access to set_power method */
76 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /* The framebuffer notifier block */
78 struct notifier_block fb_notif;
Richard Purdie655bfd72007-07-09 12:17:24 +010079
80 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
InKi Daeee378a52010-05-24 12:21:36 -070083struct lcd_platform_data {
84 /* reset lcd panel device. */
85 int (*reset)(struct lcd_device *ld);
86 /* on or off to lcd panel. if 'enable' is 0 then
87 lcd power off and 1, lcd power on. */
88 int (*power_on)(struct lcd_device *ld, int enable);
89
90 /* it indicates whether lcd panel was enabled
91 from bootloader or not. */
92 int lcd_enabled;
93 /* it means delay for stable time when it becomes low to high
94 or high to low that is dependent on whether reset gpio is
95 low active or high active. */
96 unsigned int reset_delay;
97 /* stable time needing to become lcd power on. */
98 unsigned int power_on_delay;
99 /* stable time needing to become lcd power off. */
100 unsigned int power_off_delay;
101
102 /* it could be used for any purpose. */
103 void *pdata;
104};
105
Richard Purdie28ee0862007-02-08 22:25:09 +0000106static inline void lcd_set_power(struct lcd_device *ld, int power)
107{
108 mutex_lock(&ld->update_lock);
Richard Purdie599a52d2007-02-10 23:07:48 +0000109 if (ld->ops && ld->ops->set_power)
110 ld->ops->set_power(ld, power);
Richard Purdie28ee0862007-02-08 22:25:09 +0000111 mutex_unlock(&ld->update_lock);
112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern struct lcd_device *lcd_device_register(const char *name,
Richard Purdie655bfd72007-07-09 12:17:24 +0100115 struct device *parent, void *devdata, struct lcd_ops *ops);
Jingoo Han1d0c48e2013-07-03 15:05:14 -0700116extern struct lcd_device *devm_lcd_device_register(struct device *dev,
117 const char *name, struct device *parent,
118 void *devdata, struct lcd_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119extern void lcd_device_unregister(struct lcd_device *ld);
Jingoo Han1d0c48e2013-07-03 15:05:14 -0700120extern void devm_lcd_device_unregister(struct device *dev,
121 struct lcd_device *ld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Richard Purdie655bfd72007-07-09 12:17:24 +0100123#define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
124
125static inline void * lcd_get_data(struct lcd_device *ld_dev)
126{
127 return dev_get_drvdata(&ld_dev->dev);
128}
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131#endif