blob: c67fecafff909ccb2c7dc1084de264d2192c845c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * LCD Lowlevel Control Abstraction
3 *
4 * Copyright (C) 2003,2004 Hewlett-Packard Company
5 *
6 */
7
8#ifndef _LINUX_LCD_H
9#define _LINUX_LCD_H
10
11#include <linux/device.h>
Richard Purdie28ee0862007-02-08 22:25:09 +000012#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/notifier.h>
Eric Miaofaa312d2008-08-29 04:18:43 +080014#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Richard Purdie28ee0862007-02-08 22:25:09 +000016/* Notes on locking:
17 *
Richard Purdie599a52d2007-02-10 23:07:48 +000018 * lcd_device->ops_lock is an internal backlight lock protecting the ops
Richard Purdie28ee0862007-02-08 22:25:09 +000019 * field and no code outside the core should need to touch it.
20 *
21 * Access to set_power() is serialised by the update_lock mutex since
22 * most drivers seem to need this and historically get it wrong.
23 *
24 * Most drivers don't need locking on their get_power() method.
25 * If yours does, you need to implement it in the driver. You can use the
26 * update_lock mutex if appropriate.
27 *
28 * Any other use of the locks below is probably wrong.
29 */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031struct lcd_device;
32struct fb_info;
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034struct lcd_properties {
Richard Purdie599a52d2007-02-10 23:07:48 +000035 /* The maximum value for contrast (read-only) */
36 int max_contrast;
37};
38
39struct lcd_ops {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 /* Get the LCD panel power status (0: full on, 1..3: controller
41 power on, flat panel power off, 4: full off), see FB_BLANK_XXX */
42 int (*get_power)(struct lcd_device *);
43 /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
44 int (*set_power)(struct lcd_device *, int power);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 /* Get the current contrast setting (0-max_contrast) */
46 int (*get_contrast)(struct lcd_device *);
47 /* Set LCD panel contrast */
48 int (*set_contrast)(struct lcd_device *, int contrast);
Eric Miaofaa312d2008-08-29 04:18:43 +080049 /* Set LCD panel mode (resolutions ...) */
50 int (*set_mode)(struct lcd_device *, struct fb_videomode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 /* Check if given framebuffer device is the one LCD is bound to;
52 return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
Ben Dooks0c531362008-07-23 21:31:38 -070053 int (*check_fb)(struct lcd_device *, struct fb_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
56struct lcd_device {
Richard Purdie599a52d2007-02-10 23:07:48 +000057 struct lcd_properties props;
58 /* This protects the 'ops' field. If 'ops' is NULL, the driver that
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 registered this device has been unloaded, and if class_get_devdata()
60 points to something in the body of that driver, it is also invalid. */
Richard Purdie599a52d2007-02-10 23:07:48 +000061 struct mutex ops_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* If this is NULL, the backing module is unloaded */
Richard Purdie599a52d2007-02-10 23:07:48 +000063 struct lcd_ops *ops;
Richard Purdie28ee0862007-02-08 22:25:09 +000064 /* Serialise access to set_power method */
65 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /* The framebuffer notifier block */
67 struct notifier_block fb_notif;
Richard Purdie655bfd72007-07-09 12:17:24 +010068
69 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
Richard Purdie28ee0862007-02-08 22:25:09 +000072static inline void lcd_set_power(struct lcd_device *ld, int power)
73{
74 mutex_lock(&ld->update_lock);
Richard Purdie599a52d2007-02-10 23:07:48 +000075 if (ld->ops && ld->ops->set_power)
76 ld->ops->set_power(ld, power);
Richard Purdie28ee0862007-02-08 22:25:09 +000077 mutex_unlock(&ld->update_lock);
78}
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern struct lcd_device *lcd_device_register(const char *name,
Richard Purdie655bfd72007-07-09 12:17:24 +010081 struct device *parent, void *devdata, struct lcd_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern void lcd_device_unregister(struct lcd_device *ld);
83
Richard Purdie655bfd72007-07-09 12:17:24 +010084#define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
85
86static inline void * lcd_get_data(struct lcd_device *ld_dev)
87{
88 return dev_get_drvdata(&ld_dev->dev);
89}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#endif