| .. | .. |
|---|
| 27 | 27 | #include <linux/err.h> |
|---|
| 28 | 28 | #include <linux/errno.h> |
|---|
| 29 | 29 | #include <linux/list.h> |
|---|
| 30 | | -#include <linux/notifier.h> |
|---|
| 31 | 30 | |
|---|
| 32 | | -/* A hardware display blank change occurred */ |
|---|
| 33 | | -#define DRM_PANEL_EVENT_BLANK 0x01 |
|---|
| 34 | | -/* A hardware display blank early change occurred */ |
|---|
| 35 | | -#define DRM_PANEL_EARLY_EVENT_BLANK 0x02 |
|---|
| 36 | | - |
|---|
| 37 | | -enum { |
|---|
| 38 | | - /* panel: power on */ |
|---|
| 39 | | - DRM_PANEL_BLANK_UNBLANK, |
|---|
| 40 | | - /* panel: power off */ |
|---|
| 41 | | - DRM_PANEL_BLANK_POWERDOWN, |
|---|
| 42 | | -}; |
|---|
| 43 | | - |
|---|
| 44 | | -struct drm_panel_notifier { |
|---|
| 45 | | - int refresh_rate; |
|---|
| 46 | | - void *data; |
|---|
| 47 | | - uint32_t id; |
|---|
| 48 | | -}; |
|---|
| 49 | | - |
|---|
| 31 | +struct backlight_device; |
|---|
| 50 | 32 | struct device_node; |
|---|
| 51 | 33 | struct drm_connector; |
|---|
| 52 | 34 | struct drm_device; |
|---|
| 53 | 35 | struct drm_panel; |
|---|
| 54 | 36 | struct display_timing; |
|---|
| 55 | 37 | |
|---|
| 38 | +enum drm_panel_orientation; |
|---|
| 39 | + |
|---|
| 56 | 40 | /** |
|---|
| 57 | | - * @loader_protect: protect loader logo panel's power |
|---|
| 58 | 41 | * struct drm_panel_funcs - perform operations on a given panel |
|---|
| 59 | | - * @disable: disable panel (turn off back light, etc.) |
|---|
| 60 | | - * @unprepare: turn off panel |
|---|
| 61 | | - * @prepare: turn on panel and perform set up |
|---|
| 62 | | - * @enable: enable panel (turn on back light, etc.) |
|---|
| 63 | | - * @get_modes: add modes to the connector that the panel is attached to and |
|---|
| 64 | | - * return the number of modes added |
|---|
| 65 | | - * @get_timings: copy display timings into the provided array and return |
|---|
| 66 | | - * the number of display timings available |
|---|
| 67 | 42 | * |
|---|
| 68 | 43 | * The .prepare() function is typically called before the display controller |
|---|
| 69 | 44 | * starts to transmit video data. Panel drivers can use this to turn the panel |
|---|
| .. | .. |
|---|
| 87 | 62 | * |
|---|
| 88 | 63 | * To save power when no video data is transmitted, a driver can power down |
|---|
| 89 | 64 | * the panel. This is the job of the .unprepare() function. |
|---|
| 65 | + * |
|---|
| 66 | + * Backlight can be handled automatically if configured using |
|---|
| 67 | + * drm_panel_of_backlight(). Then the driver does not need to implement the |
|---|
| 68 | + * functionality to enable/disable backlight. |
|---|
| 90 | 69 | */ |
|---|
| 91 | 70 | struct drm_panel_funcs { |
|---|
| 92 | | - int (*loader_protect)(struct drm_panel *panel, bool on); |
|---|
| 93 | | - int (*disable)(struct drm_panel *panel); |
|---|
| 94 | | - int (*unprepare)(struct drm_panel *panel); |
|---|
| 71 | + /** |
|---|
| 72 | + * @prepare: |
|---|
| 73 | + * |
|---|
| 74 | + * Turn on panel and perform set up. |
|---|
| 75 | + * |
|---|
| 76 | + * This function is optional. |
|---|
| 77 | + */ |
|---|
| 95 | 78 | int (*prepare)(struct drm_panel *panel); |
|---|
| 79 | + |
|---|
| 80 | + /** |
|---|
| 81 | + * @enable: |
|---|
| 82 | + * |
|---|
| 83 | + * Enable panel (turn on back light, etc.). |
|---|
| 84 | + * |
|---|
| 85 | + * This function is optional. |
|---|
| 86 | + */ |
|---|
| 96 | 87 | int (*enable)(struct drm_panel *panel); |
|---|
| 97 | | - int (*get_modes)(struct drm_panel *panel); |
|---|
| 88 | + |
|---|
| 89 | + /** |
|---|
| 90 | + * @disable: |
|---|
| 91 | + * |
|---|
| 92 | + * Disable panel (turn off back light, etc.). |
|---|
| 93 | + * |
|---|
| 94 | + * This function is optional. |
|---|
| 95 | + */ |
|---|
| 96 | + int (*disable)(struct drm_panel *panel); |
|---|
| 97 | + |
|---|
| 98 | + /** |
|---|
| 99 | + * @unprepare: |
|---|
| 100 | + * |
|---|
| 101 | + * Turn off panel. |
|---|
| 102 | + * |
|---|
| 103 | + * This function is optional. |
|---|
| 104 | + */ |
|---|
| 105 | + int (*unprepare)(struct drm_panel *panel); |
|---|
| 106 | + |
|---|
| 107 | + /** |
|---|
| 108 | + * @get_modes: |
|---|
| 109 | + * |
|---|
| 110 | + * Add modes to the connector that the panel is attached to |
|---|
| 111 | + * and returns the number of modes added. |
|---|
| 112 | + * |
|---|
| 113 | + * This function is mandatory. |
|---|
| 114 | + */ |
|---|
| 115 | + int (*get_modes)(struct drm_panel *panel, |
|---|
| 116 | + struct drm_connector *connector); |
|---|
| 117 | + |
|---|
| 118 | + /** |
|---|
| 119 | + * @get_timings: |
|---|
| 120 | + * |
|---|
| 121 | + * Copy display timings into the provided array and return |
|---|
| 122 | + * the number of display timings available. |
|---|
| 123 | + * |
|---|
| 124 | + * This function is optional. |
|---|
| 125 | + */ |
|---|
| 98 | 126 | int (*get_timings)(struct drm_panel *panel, unsigned int num_timings, |
|---|
| 99 | 127 | struct display_timing *timings); |
|---|
| 100 | 128 | }; |
|---|
| 101 | 129 | |
|---|
| 102 | 130 | /** |
|---|
| 103 | 131 | * struct drm_panel - DRM panel object |
|---|
| 104 | | - * @drm: DRM device owning the panel |
|---|
| 105 | | - * @connector: DRM connector that the panel is attached to |
|---|
| 106 | | - * @dev: parent device of the panel |
|---|
| 107 | | - * @funcs: operations that can be performed on the panel |
|---|
| 108 | | - * @list: panel entry in registry |
|---|
| 109 | 132 | */ |
|---|
| 110 | 133 | struct drm_panel { |
|---|
| 111 | | - struct drm_device *drm; |
|---|
| 112 | | - struct drm_connector *connector; |
|---|
| 134 | + /** |
|---|
| 135 | + * @dev: |
|---|
| 136 | + * |
|---|
| 137 | + * Parent device of the panel. |
|---|
| 138 | + */ |
|---|
| 113 | 139 | struct device *dev; |
|---|
| 114 | 140 | |
|---|
| 115 | | - const struct drm_panel_funcs *funcs; |
|---|
| 116 | | - |
|---|
| 117 | | - struct list_head list; |
|---|
| 141 | + /** |
|---|
| 142 | + * @backlight: |
|---|
| 143 | + * |
|---|
| 144 | + * Backlight device, used to turn on backlight after the call |
|---|
| 145 | + * to enable(), and to turn off backlight before the call to |
|---|
| 146 | + * disable(). |
|---|
| 147 | + * backlight is set by drm_panel_of_backlight() and drivers |
|---|
| 148 | + * shall not assign it. |
|---|
| 149 | + */ |
|---|
| 150 | + struct backlight_device *backlight; |
|---|
| 118 | 151 | |
|---|
| 119 | 152 | /** |
|---|
| 120 | | - * @nh: |
|---|
| 153 | + * @funcs: |
|---|
| 121 | 154 | * |
|---|
| 122 | | - * panel notifier list head |
|---|
| 155 | + * Operations that can be performed on the panel. |
|---|
| 123 | 156 | */ |
|---|
| 124 | | - struct blocking_notifier_head nh; |
|---|
| 157 | + const struct drm_panel_funcs *funcs; |
|---|
| 158 | + |
|---|
| 159 | + /** |
|---|
| 160 | + * @connector_type: |
|---|
| 161 | + * |
|---|
| 162 | + * Type of the panel as a DRM_MODE_CONNECTOR_* value. This is used to |
|---|
| 163 | + * initialise the drm_connector corresponding to the panel with the |
|---|
| 164 | + * correct connector type. |
|---|
| 165 | + */ |
|---|
| 166 | + int connector_type; |
|---|
| 167 | + |
|---|
| 168 | + /** |
|---|
| 169 | + * @list: |
|---|
| 170 | + * |
|---|
| 171 | + * Panel entry in registry. |
|---|
| 172 | + */ |
|---|
| 173 | + struct list_head list; |
|---|
| 125 | 174 | }; |
|---|
| 126 | 175 | |
|---|
| 127 | | -static inline int drm_panel_loader_protect(struct drm_panel *panel, bool on) |
|---|
| 128 | | -{ |
|---|
| 129 | | - if (panel && panel->funcs && panel->funcs->loader_protect) |
|---|
| 130 | | - return panel->funcs->loader_protect(panel, on); |
|---|
| 176 | +void drm_panel_init(struct drm_panel *panel, struct device *dev, |
|---|
| 177 | + const struct drm_panel_funcs *funcs, |
|---|
| 178 | + int connector_type); |
|---|
| 131 | 179 | |
|---|
| 132 | | - return -EINVAL; |
|---|
| 133 | | -} |
|---|
| 134 | | - |
|---|
| 135 | | -/** |
|---|
| 136 | | - * drm_disable_unprepare - power off a panel |
|---|
| 137 | | - * @panel: DRM panel |
|---|
| 138 | | - * |
|---|
| 139 | | - * Calling this function will completely power off a panel (assert the panel's |
|---|
| 140 | | - * reset, turn off power supplies, ...). After this function has completed, it |
|---|
| 141 | | - * is usually no longer possible to communicate with the panel until another |
|---|
| 142 | | - * call to drm_panel_prepare(). |
|---|
| 143 | | - * |
|---|
| 144 | | - * Return: 0 on success or a negative error code on failure. |
|---|
| 145 | | - */ |
|---|
| 146 | | -static inline int drm_panel_unprepare(struct drm_panel *panel) |
|---|
| 147 | | -{ |
|---|
| 148 | | - if (panel && panel->funcs && panel->funcs->unprepare) |
|---|
| 149 | | - return panel->funcs->unprepare(panel); |
|---|
| 150 | | - |
|---|
| 151 | | - return panel ? -ENOSYS : -EINVAL; |
|---|
| 152 | | -} |
|---|
| 153 | | - |
|---|
| 154 | | -/** |
|---|
| 155 | | - * drm_panel_disable - disable a panel |
|---|
| 156 | | - * @panel: DRM panel |
|---|
| 157 | | - * |
|---|
| 158 | | - * This will typically turn off the panel's backlight or disable the display |
|---|
| 159 | | - * drivers. For smart panels it should still be possible to communicate with |
|---|
| 160 | | - * the integrated circuitry via any command bus after this call. |
|---|
| 161 | | - * |
|---|
| 162 | | - * Return: 0 on success or a negative error code on failure. |
|---|
| 163 | | - */ |
|---|
| 164 | | -static inline int drm_panel_disable(struct drm_panel *panel) |
|---|
| 165 | | -{ |
|---|
| 166 | | - if (panel && panel->funcs && panel->funcs->disable) |
|---|
| 167 | | - return panel->funcs->disable(panel); |
|---|
| 168 | | - |
|---|
| 169 | | - return panel ? -ENOSYS : -EINVAL; |
|---|
| 170 | | -} |
|---|
| 171 | | - |
|---|
| 172 | | -/** |
|---|
| 173 | | - * drm_panel_prepare - power on a panel |
|---|
| 174 | | - * @panel: DRM panel |
|---|
| 175 | | - * |
|---|
| 176 | | - * Calling this function will enable power and deassert any reset signals to |
|---|
| 177 | | - * the panel. After this has completed it is possible to communicate with any |
|---|
| 178 | | - * integrated circuitry via a command bus. |
|---|
| 179 | | - * |
|---|
| 180 | | - * Return: 0 on success or a negative error code on failure. |
|---|
| 181 | | - */ |
|---|
| 182 | | -static inline int drm_panel_prepare(struct drm_panel *panel) |
|---|
| 183 | | -{ |
|---|
| 184 | | - if (panel && panel->funcs && panel->funcs->prepare) |
|---|
| 185 | | - return panel->funcs->prepare(panel); |
|---|
| 186 | | - |
|---|
| 187 | | - return panel ? -ENOSYS : -EINVAL; |
|---|
| 188 | | -} |
|---|
| 189 | | - |
|---|
| 190 | | -/** |
|---|
| 191 | | - * drm_panel_enable - enable a panel |
|---|
| 192 | | - * @panel: DRM panel |
|---|
| 193 | | - * |
|---|
| 194 | | - * Calling this function will cause the panel display drivers to be turned on |
|---|
| 195 | | - * and the backlight to be enabled. Content will be visible on screen after |
|---|
| 196 | | - * this call completes. |
|---|
| 197 | | - * |
|---|
| 198 | | - * Return: 0 on success or a negative error code on failure. |
|---|
| 199 | | - */ |
|---|
| 200 | | -static inline int drm_panel_enable(struct drm_panel *panel) |
|---|
| 201 | | -{ |
|---|
| 202 | | - if (panel && panel->funcs && panel->funcs->enable) |
|---|
| 203 | | - return panel->funcs->enable(panel); |
|---|
| 204 | | - |
|---|
| 205 | | - return panel ? -ENOSYS : -EINVAL; |
|---|
| 206 | | -} |
|---|
| 207 | | - |
|---|
| 208 | | -/** |
|---|
| 209 | | - * drm_panel_get_modes - probe the available display modes of a panel |
|---|
| 210 | | - * @panel: DRM panel |
|---|
| 211 | | - * |
|---|
| 212 | | - * The modes probed from the panel are automatically added to the connector |
|---|
| 213 | | - * that the panel is attached to. |
|---|
| 214 | | - * |
|---|
| 215 | | - * Return: The number of modes available from the panel on success or a |
|---|
| 216 | | - * negative error code on failure. |
|---|
| 217 | | - */ |
|---|
| 218 | | -static inline int drm_panel_get_modes(struct drm_panel *panel) |
|---|
| 219 | | -{ |
|---|
| 220 | | - if (panel && panel->funcs && panel->funcs->get_modes) |
|---|
| 221 | | - return panel->funcs->get_modes(panel); |
|---|
| 222 | | - |
|---|
| 223 | | - return panel ? -ENOSYS : -EINVAL; |
|---|
| 224 | | -} |
|---|
| 225 | | - |
|---|
| 226 | | -void drm_panel_init(struct drm_panel *panel); |
|---|
| 227 | | - |
|---|
| 228 | | -int drm_panel_add(struct drm_panel *panel); |
|---|
| 180 | +void drm_panel_add(struct drm_panel *panel); |
|---|
| 229 | 181 | void drm_panel_remove(struct drm_panel *panel); |
|---|
| 230 | 182 | |
|---|
| 231 | | -int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector); |
|---|
| 232 | | -int drm_panel_detach(struct drm_panel *panel); |
|---|
| 183 | +int drm_panel_prepare(struct drm_panel *panel); |
|---|
| 184 | +int drm_panel_unprepare(struct drm_panel *panel); |
|---|
| 233 | 185 | |
|---|
| 234 | | -int drm_panel_notifier_register(struct drm_panel *panel, |
|---|
| 235 | | - struct notifier_block *nb); |
|---|
| 236 | | -int drm_panel_notifier_unregister(struct drm_panel *panel, |
|---|
| 237 | | - struct notifier_block *nb); |
|---|
| 238 | | -int drm_panel_notifier_call_chain(struct drm_panel *panel, |
|---|
| 239 | | - unsigned long val, void *v); |
|---|
| 186 | +int drm_panel_enable(struct drm_panel *panel); |
|---|
| 187 | +int drm_panel_disable(struct drm_panel *panel); |
|---|
| 188 | + |
|---|
| 189 | +int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector); |
|---|
| 240 | 190 | |
|---|
| 241 | 191 | #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL) |
|---|
| 242 | 192 | struct drm_panel *of_drm_find_panel(const struct device_node *np); |
|---|
| 193 | +int of_drm_get_panel_orientation(const struct device_node *np, |
|---|
| 194 | + enum drm_panel_orientation *orientation); |
|---|
| 243 | 195 | #else |
|---|
| 244 | 196 | static inline struct drm_panel *of_drm_find_panel(const struct device_node *np) |
|---|
| 245 | 197 | { |
|---|
| 246 | 198 | return ERR_PTR(-ENODEV); |
|---|
| 247 | 199 | } |
|---|
| 200 | + |
|---|
| 201 | +static inline int of_drm_get_panel_orientation(const struct device_node *np, |
|---|
| 202 | + enum drm_panel_orientation *orientation) |
|---|
| 203 | +{ |
|---|
| 204 | + return -ENODEV; |
|---|
| 205 | +} |
|---|
| 206 | +#endif |
|---|
| 207 | + |
|---|
| 208 | +#if IS_ENABLED(CONFIG_DRM_PANEL) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \ |
|---|
| 209 | + (IS_MODULE(CONFIG_DRM) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE))) |
|---|
| 210 | +int drm_panel_of_backlight(struct drm_panel *panel); |
|---|
| 211 | +#else |
|---|
| 212 | +static inline int drm_panel_of_backlight(struct drm_panel *panel) |
|---|
| 213 | +{ |
|---|
| 214 | + return 0; |
|---|
| 215 | +} |
|---|
| 248 | 216 | #endif |
|---|
| 249 | 217 | |
|---|
| 250 | 218 | #endif |
|---|