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> |
Eric Miao | faa312d | 2008-08-29 04:18:43 +0800 | [diff] [blame] | 14 | #include <linux/fb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 16 | /* Notes on locking: |
| 17 | * |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 18 | * lcd_device->ops_lock is an internal backlight lock protecting the ops |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 19 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | struct lcd_device; |
| 32 | struct fb_info; |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct lcd_properties { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 35 | /* The maximum value for contrast (read-only) */ |
| 36 | int max_contrast; |
| 37 | }; |
| 38 | |
| 39 | struct lcd_ops { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* 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 *); |
Inki Dae | d54ad83 | 2012-05-29 15:07:13 -0700 | [diff] [blame] | 43 | /* |
| 44 | * Enable or disable power to the LCD(0: on; 4: off, see FB_BLANK_XXX) |
| 45 | * and this callback would be called proir to fb driver's callback. |
| 46 | * |
| 47 | * P.S. note that if early_set_power is not NULL then early fb notifier |
| 48 | * would be registered. |
| 49 | */ |
| 50 | int (*early_set_power)(struct lcd_device *, int power); |
| 51 | /* revert the effects of the early blank event. */ |
| 52 | int (*r_early_set_power)(struct lcd_device *, int power); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* Enable or disable power to the LCD (0: on; 4: off, see FB_BLANK_XXX) */ |
| 54 | int (*set_power)(struct lcd_device *, int power); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* Get the current contrast setting (0-max_contrast) */ |
| 56 | int (*get_contrast)(struct lcd_device *); |
| 57 | /* Set LCD panel contrast */ |
| 58 | int (*set_contrast)(struct lcd_device *, int contrast); |
Eric Miao | faa312d | 2008-08-29 04:18:43 +0800 | [diff] [blame] | 59 | /* Set LCD panel mode (resolutions ...) */ |
| 60 | int (*set_mode)(struct lcd_device *, struct fb_videomode *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* Check if given framebuffer device is the one LCD is bound to; |
| 62 | 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] | 63 | int (*check_fb)(struct lcd_device *, struct fb_info *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct lcd_device { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 67 | struct lcd_properties props; |
| 68 | /* This protects the 'ops' field. If 'ops' is NULL, the driver that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | registered this device has been unloaded, and if class_get_devdata() |
| 70 | 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] | 71 | struct mutex ops_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* If this is NULL, the backing module is unloaded */ |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 73 | struct lcd_ops *ops; |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 74 | /* Serialise access to set_power method */ |
| 75 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* The framebuffer notifier block */ |
| 77 | struct notifier_block fb_notif; |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 78 | |
| 79 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
InKi Dae | ee378a5 | 2010-05-24 12:21:36 -0700 | [diff] [blame] | 82 | struct lcd_platform_data { |
| 83 | /* reset lcd panel device. */ |
| 84 | int (*reset)(struct lcd_device *ld); |
| 85 | /* on or off to lcd panel. if 'enable' is 0 then |
| 86 | lcd power off and 1, lcd power on. */ |
| 87 | int (*power_on)(struct lcd_device *ld, int enable); |
| 88 | |
| 89 | /* it indicates whether lcd panel was enabled |
| 90 | from bootloader or not. */ |
| 91 | int lcd_enabled; |
| 92 | /* it means delay for stable time when it becomes low to high |
| 93 | or high to low that is dependent on whether reset gpio is |
| 94 | low active or high active. */ |
| 95 | unsigned int reset_delay; |
| 96 | /* stable time needing to become lcd power on. */ |
| 97 | unsigned int power_on_delay; |
| 98 | /* stable time needing to become lcd power off. */ |
| 99 | unsigned int power_off_delay; |
| 100 | |
| 101 | /* it could be used for any purpose. */ |
| 102 | void *pdata; |
| 103 | }; |
| 104 | |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 105 | static inline void lcd_set_power(struct lcd_device *ld, int power) |
| 106 | { |
| 107 | mutex_lock(&ld->update_lock); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 108 | if (ld->ops && ld->ops->set_power) |
| 109 | ld->ops->set_power(ld, power); |
Richard Purdie | 28ee086 | 2007-02-08 22:25:09 +0000 | [diff] [blame] | 110 | mutex_unlock(&ld->update_lock); |
| 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | extern struct lcd_device *lcd_device_register(const char *name, |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 114 | struct device *parent, void *devdata, struct lcd_ops *ops); |
Jingoo Han | 1d0c48e | 2013-07-03 15:05:14 -0700 | [diff] [blame^] | 115 | extern struct lcd_device *devm_lcd_device_register(struct device *dev, |
| 116 | const char *name, struct device *parent, |
| 117 | void *devdata, struct lcd_ops *ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | extern void lcd_device_unregister(struct lcd_device *ld); |
Jingoo Han | 1d0c48e | 2013-07-03 15:05:14 -0700 | [diff] [blame^] | 119 | extern void devm_lcd_device_unregister(struct device *dev, |
| 120 | struct lcd_device *ld); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 122 | #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) |
| 123 | |
| 124 | static inline void * lcd_get_data(struct lcd_device *ld_dev) |
| 125 | { |
| 126 | return dev_get_drvdata(&ld_dev->dev); |
| 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | #endif |