blob: bfbf6552eb5158e2427032eb2ab6cea4e98073ea [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>
14
Richard Purdie28ee0862007-02-08 22:25:09 +000015/* Notes on locking:
16 *
17 * lcd_device->sem is an internal backlight lock protecting the props
18 * field and no code outside the core should need to touch it.
19 *
20 * Access to set_power() is serialised by the update_lock mutex since
21 * most drivers seem to need this and historically get it wrong.
22 *
23 * Most drivers don't need locking on their get_power() method.
24 * If yours does, you need to implement it in the driver. You can use the
25 * update_lock mutex if appropriate.
26 *
27 * Any other use of the locks below is probably wrong.
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030struct lcd_device;
31struct fb_info;
32
33/* This structure defines all the properties of a LCD flat panel. */
34struct lcd_properties {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 /* Get the LCD panel power status (0: full on, 1..3: controller
36 power on, flat panel power off, 4: full off), see FB_BLANK_XXX */
37 int (*get_power)(struct lcd_device *);
38 /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */
39 int (*set_power)(struct lcd_device *, int power);
40 /* The maximum value for contrast (read-only) */
41 int max_contrast;
42 /* Get the current contrast setting (0-max_contrast) */
43 int (*get_contrast)(struct lcd_device *);
44 /* Set LCD panel contrast */
45 int (*set_contrast)(struct lcd_device *, int contrast);
46 /* Check if given framebuffer device is the one LCD is bound to;
47 return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */
48 int (*check_fb)(struct fb_info *);
49};
50
51struct lcd_device {
52 /* This protects the 'props' field. If 'props' is NULL, the driver that
53 registered this device has been unloaded, and if class_get_devdata()
54 points to something in the body of that driver, it is also invalid. */
55 struct semaphore sem;
56 /* If this is NULL, the backing module is unloaded */
57 struct lcd_properties *props;
Richard Purdie28ee0862007-02-08 22:25:09 +000058 /* Serialise access to set_power method */
59 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 /* The framebuffer notifier block */
61 struct notifier_block fb_notif;
62 /* The class device structure */
63 struct class_device class_dev;
64};
65
Richard Purdie28ee0862007-02-08 22:25:09 +000066static inline void lcd_set_power(struct lcd_device *ld, int power)
67{
68 mutex_lock(&ld->update_lock);
69 if (ld->props && ld->props->set_power)
70 ld->props->set_power(ld, power);
71 mutex_unlock(&ld->update_lock);
72}
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern struct lcd_device *lcd_device_register(const char *name,
75 void *devdata, struct lcd_properties *lp);
76extern void lcd_device_unregister(struct lcd_device *ld);
77
78#define to_lcd_device(obj) container_of(obj, struct lcd_device, class_dev)
79
80#endif