Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 12 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/notifier.h> |
| 14 | |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 15 | /* Notes on locking: |
| 16 | * |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 17 | * lcd_device->ops_lock is an internal backlight lock protecting the ops |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | struct lcd_device; |
| 31 | struct fb_info; |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | struct lcd_properties { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 34 | /* The maximum value for contrast (read-only) */ |
| 35 | int max_contrast; |
| 36 | }; |
| 37 | |
| 38 | struct lcd_ops { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* Get the LCD panel power status (0: full on, 1..3: controller |
| 40 | power on, flat panel power off, 4: full off), see FB_BLANK_XXX */ |
| 41 | int (*get_power)(struct lcd_device *); |
| 42 | /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */ |
| 43 | int (*set_power)(struct lcd_device *, int power); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* Get the current contrast setting (0-max_contrast) */ |
| 45 | int (*get_contrast)(struct lcd_device *); |
| 46 | /* Set LCD panel contrast */ |
| 47 | int (*set_contrast)(struct lcd_device *, int contrast); |
| 48 | /* Check if given framebuffer device is the one LCD is bound to; |
| 49 | return 0 if not, !=0 if it is. If NULL, lcd always matches the fb. */ |
Ben Dooks | 0c53136 | 2008-07-23 21:31:38 -0700 | [diff] [blame] | 50 | int (*check_fb)(struct lcd_device *, struct fb_info *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct lcd_device { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 54 | struct lcd_properties props; |
| 55 | /* This protects the 'ops' field. If 'ops' is NULL, the driver that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | registered this device has been unloaded, and if class_get_devdata() |
| 57 | points to something in the body of that driver, it is also invalid. */ |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 58 | struct mutex ops_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* If this is NULL, the backing module is unloaded */ |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 60 | struct lcd_ops *ops; |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 61 | /* Serialise access to set_power method */ |
| 62 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* The framebuffer notifier block */ |
| 64 | struct notifier_block fb_notif; |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 65 | |
| 66 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 69 | static inline void lcd_set_power(struct lcd_device *ld, int power) |
| 70 | { |
| 71 | mutex_lock(&ld->update_lock); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 72 | if (ld->ops && ld->ops->set_power) |
| 73 | ld->ops->set_power(ld, power); |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 74 | mutex_unlock(&ld->update_lock); |
| 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | extern struct lcd_device *lcd_device_register(const char *name, |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 78 | struct device *parent, void *devdata, struct lcd_ops *ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | extern void lcd_device_unregister(struct lcd_device *ld); |
| 80 | |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 81 | #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) |
| 82 | |
| 83 | static inline void * lcd_get_data(struct lcd_device *ld_dev) |
| 84 | { |
| 85 | return dev_get_drvdata(&ld_dev->dev); |
| 86 | } |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | #endif |