Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Texas Instruments |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 7 | #include <linux/gpio/consumer.h> |
Sam Ravnborg | fcb5766 | 2019-07-16 08:42:15 +0200 | [diff] [blame] | 8 | #include <linux/pinctrl/consumer.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 11 | #include <video/display_timing.h> |
| 12 | #include <video/of_display_timing.h> |
| 13 | #include <video/videomode.h> |
Sam Ravnborg | fcb5766 | 2019-07-16 08:42:15 +0200 | [diff] [blame] | 14 | |
| 15 | #include <drm/drm_atomic_state_helper.h> |
| 16 | #include <drm/drm_connector.h> |
| 17 | #include <drm/drm_modeset_helper_vtables.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 18 | #include <drm/drm_probe_helper.h> |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 19 | |
| 20 | #include "tilcdc_drv.h" |
Baoyou Xie | 0fd8677 | 2016-09-08 19:08:56 +0800 | [diff] [blame] | 21 | #include "tilcdc_panel.h" |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 22 | |
| 23 | struct panel_module { |
| 24 | struct tilcdc_module base; |
| 25 | struct tilcdc_panel_info *info; |
| 26 | struct display_timings *timings; |
| 27 | struct backlight_device *backlight; |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 28 | struct gpio_desc *enable_gpio; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 29 | }; |
| 30 | #define to_panel_module(x) container_of(x, struct panel_module, base) |
| 31 | |
| 32 | |
| 33 | /* |
| 34 | * Encoder: |
| 35 | */ |
| 36 | |
| 37 | struct panel_encoder { |
| 38 | struct drm_encoder base; |
| 39 | struct panel_module *mod; |
| 40 | }; |
| 41 | #define to_panel_encoder(x) container_of(x, struct panel_encoder, base) |
| 42 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 43 | static void panel_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 44 | { |
| 45 | struct panel_encoder *panel_encoder = to_panel_encoder(encoder); |
| 46 | struct backlight_device *backlight = panel_encoder->mod->backlight; |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 47 | struct gpio_desc *gpio = panel_encoder->mod->enable_gpio; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 48 | |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 49 | if (backlight) { |
| 50 | backlight->props.power = mode == DRM_MODE_DPMS_ON ? |
| 51 | FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; |
| 52 | backlight_update_status(backlight); |
| 53 | } |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 54 | |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 55 | if (gpio) |
| 56 | gpiod_set_value_cansleep(gpio, |
| 57 | mode == DRM_MODE_DPMS_ON ? 1 : 0); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 58 | } |
| 59 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 60 | static void panel_encoder_prepare(struct drm_encoder *encoder) |
| 61 | { |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 62 | panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void panel_encoder_commit(struct drm_encoder *encoder) |
| 66 | { |
| 67 | panel_encoder_dpms(encoder, DRM_MODE_DPMS_ON); |
| 68 | } |
| 69 | |
| 70 | static void panel_encoder_mode_set(struct drm_encoder *encoder, |
| 71 | struct drm_display_mode *mode, |
| 72 | struct drm_display_mode *adjusted_mode) |
| 73 | { |
| 74 | /* nothing needed */ |
| 75 | } |
| 76 | |
| 77 | static const struct drm_encoder_funcs panel_encoder_funcs = { |
Jyri Sarha | d0ec32c | 2016-02-23 12:44:27 +0200 | [diff] [blame] | 78 | .destroy = drm_encoder_cleanup, |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = { |
| 82 | .dpms = panel_encoder_dpms, |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 83 | .prepare = panel_encoder_prepare, |
| 84 | .commit = panel_encoder_commit, |
| 85 | .mode_set = panel_encoder_mode_set, |
| 86 | }; |
| 87 | |
| 88 | static struct drm_encoder *panel_encoder_create(struct drm_device *dev, |
| 89 | struct panel_module *mod) |
| 90 | { |
| 91 | struct panel_encoder *panel_encoder; |
| 92 | struct drm_encoder *encoder; |
| 93 | int ret; |
| 94 | |
Jyri Sarha | d0ec32c | 2016-02-23 12:44:27 +0200 | [diff] [blame] | 95 | panel_encoder = devm_kzalloc(dev->dev, sizeof(*panel_encoder), |
| 96 | GFP_KERNEL); |
Markus Elfring | 3366ba3 | 2018-02-06 21:51:15 +0100 | [diff] [blame] | 97 | if (!panel_encoder) |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 98 | return NULL; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 99 | |
| 100 | panel_encoder->mod = mod; |
| 101 | |
| 102 | encoder = &panel_encoder->base; |
| 103 | encoder->possible_crtcs = 1; |
| 104 | |
| 105 | ret = drm_encoder_init(dev, encoder, &panel_encoder_funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 106 | DRM_MODE_ENCODER_LVDS, NULL); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 107 | if (ret < 0) |
| 108 | goto fail; |
| 109 | |
| 110 | drm_encoder_helper_add(encoder, &panel_encoder_helper_funcs); |
| 111 | |
| 112 | return encoder; |
| 113 | |
| 114 | fail: |
Jyri Sarha | d0ec32c | 2016-02-23 12:44:27 +0200 | [diff] [blame] | 115 | drm_encoder_cleanup(encoder); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * Connector: |
| 121 | */ |
| 122 | |
| 123 | struct panel_connector { |
| 124 | struct drm_connector base; |
| 125 | |
| 126 | struct drm_encoder *encoder; /* our connected encoder */ |
| 127 | struct panel_module *mod; |
| 128 | }; |
| 129 | #define to_panel_connector(x) container_of(x, struct panel_connector, base) |
| 130 | |
| 131 | |
| 132 | static void panel_connector_destroy(struct drm_connector *connector) |
| 133 | { |
Sachin Kamat | 62eb3e2 | 2014-07-09 17:12:57 +0530 | [diff] [blame] | 134 | drm_connector_unregister(connector); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 135 | drm_connector_cleanup(connector); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 136 | } |
| 137 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 138 | static int panel_connector_get_modes(struct drm_connector *connector) |
| 139 | { |
| 140 | struct drm_device *dev = connector->dev; |
| 141 | struct panel_connector *panel_connector = to_panel_connector(connector); |
| 142 | struct display_timings *timings = panel_connector->mod->timings; |
| 143 | int i; |
| 144 | |
| 145 | for (i = 0; i < timings->num_timings; i++) { |
| 146 | struct drm_display_mode *mode = drm_mode_create(dev); |
| 147 | struct videomode vm; |
| 148 | |
Tomi Valkeinen | 6cd2c7d | 2013-03-21 14:20:12 +0200 | [diff] [blame] | 149 | if (videomode_from_timings(timings, &vm, i)) |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 150 | break; |
| 151 | |
| 152 | drm_display_mode_from_videomode(&vm, mode); |
| 153 | |
| 154 | mode->type = DRM_MODE_TYPE_DRIVER; |
| 155 | |
| 156 | if (timings->native_mode == i) |
| 157 | mode->type |= DRM_MODE_TYPE_PREFERRED; |
| 158 | |
| 159 | drm_mode_set_name(mode); |
| 160 | drm_mode_probed_add(connector, mode); |
| 161 | } |
| 162 | |
| 163 | return i; |
| 164 | } |
| 165 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 166 | static struct drm_encoder *panel_connector_best_encoder( |
| 167 | struct drm_connector *connector) |
| 168 | { |
| 169 | struct panel_connector *panel_connector = to_panel_connector(connector); |
| 170 | return panel_connector->encoder; |
| 171 | } |
| 172 | |
| 173 | static const struct drm_connector_funcs panel_connector_funcs = { |
| 174 | .destroy = panel_connector_destroy, |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 175 | .fill_modes = drm_helper_probe_single_connector_modes, |
Jyri Sarha | 0f65d89b | 2016-04-13 18:49:29 +0300 | [diff] [blame] | 176 | .reset = drm_atomic_helper_connector_reset, |
| 177 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 178 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | static const struct drm_connector_helper_funcs panel_connector_helper_funcs = { |
| 182 | .get_modes = panel_connector_get_modes, |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 183 | .best_encoder = panel_connector_best_encoder, |
| 184 | }; |
| 185 | |
| 186 | static struct drm_connector *panel_connector_create(struct drm_device *dev, |
| 187 | struct panel_module *mod, struct drm_encoder *encoder) |
| 188 | { |
| 189 | struct panel_connector *panel_connector; |
| 190 | struct drm_connector *connector; |
| 191 | int ret; |
| 192 | |
Jyri Sarha | d0ec32c | 2016-02-23 12:44:27 +0200 | [diff] [blame] | 193 | panel_connector = devm_kzalloc(dev->dev, sizeof(*panel_connector), |
| 194 | GFP_KERNEL); |
Markus Elfring | 3366ba3 | 2018-02-06 21:51:15 +0100 | [diff] [blame] | 195 | if (!panel_connector) |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 196 | return NULL; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 197 | |
| 198 | panel_connector->encoder = encoder; |
| 199 | panel_connector->mod = mod; |
| 200 | |
| 201 | connector = &panel_connector->base; |
| 202 | |
| 203 | drm_connector_init(dev, connector, &panel_connector_funcs, |
| 204 | DRM_MODE_CONNECTOR_LVDS); |
| 205 | drm_connector_helper_add(connector, &panel_connector_helper_funcs); |
| 206 | |
| 207 | connector->interlace_allowed = 0; |
| 208 | connector->doublescan_allowed = 0; |
| 209 | |
Daniel Vetter | cde4c44 | 2018-07-09 10:40:07 +0200 | [diff] [blame] | 210 | ret = drm_connector_attach_encoder(connector, encoder); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 211 | if (ret) |
| 212 | goto fail; |
| 213 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 214 | return connector; |
| 215 | |
| 216 | fail: |
| 217 | panel_connector_destroy(connector); |
| 218 | return NULL; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Module: |
| 223 | */ |
| 224 | |
| 225 | static int panel_modeset_init(struct tilcdc_module *mod, struct drm_device *dev) |
| 226 | { |
| 227 | struct panel_module *panel_mod = to_panel_module(mod); |
| 228 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 229 | struct drm_encoder *encoder; |
| 230 | struct drm_connector *connector; |
| 231 | |
| 232 | encoder = panel_encoder_create(dev, panel_mod); |
| 233 | if (!encoder) |
| 234 | return -ENOMEM; |
| 235 | |
| 236 | connector = panel_connector_create(dev, panel_mod, encoder); |
| 237 | if (!connector) |
| 238 | return -ENOMEM; |
| 239 | |
| 240 | priv->encoders[priv->num_encoders++] = encoder; |
| 241 | priv->connectors[priv->num_connectors++] = connector; |
| 242 | |
Jyri Sarha | ee6de21 | 2016-04-13 18:45:29 +0300 | [diff] [blame] | 243 | tilcdc_crtc_set_panel_info(priv->crtc, |
| 244 | to_panel_encoder(encoder)->mod->info); |
| 245 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 249 | static const struct tilcdc_module_ops panel_module_ops = { |
| 250 | .modeset_init = panel_modeset_init, |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | /* |
| 254 | * Device: |
| 255 | */ |
| 256 | |
| 257 | /* maybe move this somewhere common if it is needed by other outputs? */ |
Sachin Kamat | 1733d01 | 2013-03-02 15:53:09 +0530 | [diff] [blame] | 258 | static struct tilcdc_panel_info *of_get_panel_info(struct device_node *np) |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 259 | { |
| 260 | struct device_node *info_np; |
| 261 | struct tilcdc_panel_info *info; |
| 262 | int ret = 0; |
| 263 | |
| 264 | if (!np) { |
| 265 | pr_err("%s: no devicenode given\n", __func__); |
| 266 | return NULL; |
| 267 | } |
| 268 | |
| 269 | info_np = of_get_child_by_name(np, "panel-info"); |
| 270 | if (!info_np) { |
| 271 | pr_err("%s: could not find panel-info node\n", __func__); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
Markus Elfring | b225e74 | 2018-02-06 22:10:11 +0100 | [diff] [blame] | 276 | if (!info) |
| 277 | goto put_node; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 278 | |
| 279 | ret |= of_property_read_u32(info_np, "ac-bias", &info->ac_bias); |
| 280 | ret |= of_property_read_u32(info_np, "ac-bias-intrpt", &info->ac_bias_intrpt); |
| 281 | ret |= of_property_read_u32(info_np, "dma-burst-sz", &info->dma_burst_sz); |
| 282 | ret |= of_property_read_u32(info_np, "bpp", &info->bpp); |
| 283 | ret |= of_property_read_u32(info_np, "fdd", &info->fdd); |
| 284 | ret |= of_property_read_u32(info_np, "sync-edge", &info->sync_edge); |
| 285 | ret |= of_property_read_u32(info_np, "sync-ctrl", &info->sync_ctrl); |
| 286 | ret |= of_property_read_u32(info_np, "raster-order", &info->raster_order); |
| 287 | ret |= of_property_read_u32(info_np, "fifo-th", &info->fifo_th); |
| 288 | |
| 289 | /* optional: */ |
| 290 | info->tft_alt_mode = of_property_read_bool(info_np, "tft-alt-mode"); |
| 291 | info->invert_pxl_clk = of_property_read_bool(info_np, "invert-pxl-clk"); |
| 292 | |
| 293 | if (ret) { |
| 294 | pr_err("%s: error reading panel-info properties\n", __func__); |
| 295 | kfree(info); |
Markus Elfring | b225e74 | 2018-02-06 22:10:11 +0100 | [diff] [blame] | 296 | info = NULL; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 297 | } |
| 298 | |
Markus Elfring | b225e74 | 2018-02-06 22:10:11 +0100 | [diff] [blame] | 299 | put_node: |
| 300 | of_node_put(info_np); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 301 | return info; |
| 302 | } |
| 303 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 304 | static int panel_probe(struct platform_device *pdev) |
| 305 | { |
Ezequiel Garcia | 18c44db | 2014-09-02 09:51:20 -0300 | [diff] [blame] | 306 | struct device_node *bl_node, *node = pdev->dev.of_node; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 307 | struct panel_module *panel_mod; |
| 308 | struct tilcdc_module *mod; |
| 309 | struct pinctrl *pinctrl; |
Ezequiel Garcia | 12778fc | 2014-09-02 09:51:21 -0300 | [diff] [blame] | 310 | int ret; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 311 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 312 | /* bail out early if no DT data: */ |
| 313 | if (!node) { |
| 314 | dev_err(&pdev->dev, "device-tree data is missing\n"); |
| 315 | return -ENXIO; |
| 316 | } |
| 317 | |
Ezequiel Garcia | 971645d | 2014-09-02 09:51:19 -0300 | [diff] [blame] | 318 | panel_mod = devm_kzalloc(&pdev->dev, sizeof(*panel_mod), GFP_KERNEL); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 319 | if (!panel_mod) |
| 320 | return -ENOMEM; |
| 321 | |
Ezequiel Garcia | 18c44db | 2014-09-02 09:51:20 -0300 | [diff] [blame] | 322 | bl_node = of_parse_phandle(node, "backlight", 0); |
| 323 | if (bl_node) { |
| 324 | panel_mod->backlight = of_find_backlight_by_node(bl_node); |
| 325 | of_node_put(bl_node); |
| 326 | |
| 327 | if (!panel_mod->backlight) |
| 328 | return -EPROBE_DEFER; |
| 329 | |
| 330 | dev_info(&pdev->dev, "found backlight\n"); |
| 331 | } |
| 332 | |
Uwe Kleine-König | 26a5bd2 | 2015-02-11 17:32:53 +0100 | [diff] [blame] | 333 | panel_mod->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", |
| 334 | GPIOD_OUT_LOW); |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 335 | if (IS_ERR(panel_mod->enable_gpio)) { |
| 336 | ret = PTR_ERR(panel_mod->enable_gpio); |
Uwe Kleine-König | 26a5bd2 | 2015-02-11 17:32:53 +0100 | [diff] [blame] | 337 | dev_err(&pdev->dev, "failed to request enable GPIO\n"); |
| 338 | goto fail_backlight; |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 339 | } |
| 340 | |
Uwe Kleine-König | 26a5bd2 | 2015-02-11 17:32:53 +0100 | [diff] [blame] | 341 | if (panel_mod->enable_gpio) |
| 342 | dev_info(&pdev->dev, "found enable GPIO\n"); |
| 343 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 344 | mod = &panel_mod->base; |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 345 | pdev->dev.platform_data = mod; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 346 | |
| 347 | tilcdc_module_init(mod, "panel", &panel_module_ops); |
| 348 | |
| 349 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); |
| 350 | if (IS_ERR(pinctrl)) |
| 351 | dev_warn(&pdev->dev, "pins are not configured\n"); |
| 352 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 353 | panel_mod->timings = of_get_display_timings(node); |
| 354 | if (!panel_mod->timings) { |
| 355 | dev_err(&pdev->dev, "could not get panel timings\n"); |
Ezequiel Garcia | 12778fc | 2014-09-02 09:51:21 -0300 | [diff] [blame] | 356 | ret = -EINVAL; |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 357 | goto fail_free; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | panel_mod->info = of_get_panel_info(node); |
| 361 | if (!panel_mod->info) { |
| 362 | dev_err(&pdev->dev, "could not get panel info\n"); |
Ezequiel Garcia | 12778fc | 2014-09-02 09:51:21 -0300 | [diff] [blame] | 363 | ret = -EINVAL; |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 364 | goto fail_timings; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 365 | } |
| 366 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 367 | return 0; |
| 368 | |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 369 | fail_timings: |
| 370 | display_timings_release(panel_mod->timings); |
| 371 | |
| 372 | fail_free: |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 373 | tilcdc_module_cleanup(mod); |
Ezequiel Garcia | d898ce0 | 2014-09-02 09:51:22 -0300 | [diff] [blame] | 374 | |
| 375 | fail_backlight: |
Ezequiel Garcia | 18c44db | 2014-09-02 09:51:20 -0300 | [diff] [blame] | 376 | if (panel_mod->backlight) |
| 377 | put_device(&panel_mod->backlight->dev); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | static int panel_remove(struct platform_device *pdev) |
| 382 | { |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 383 | struct tilcdc_module *mod = dev_get_platdata(&pdev->dev); |
| 384 | struct panel_module *panel_mod = to_panel_module(mod); |
Ezequiel Garcia | 18c44db | 2014-09-02 09:51:20 -0300 | [diff] [blame] | 385 | struct backlight_device *backlight = panel_mod->backlight; |
| 386 | |
| 387 | if (backlight) |
| 388 | put_device(&backlight->dev); |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 389 | |
| 390 | display_timings_release(panel_mod->timings); |
| 391 | |
| 392 | tilcdc_module_cleanup(mod); |
| 393 | kfree(panel_mod->info); |
Guido Martínez | 7cdcce9 | 2014-06-17 11:17:10 -0300 | [diff] [blame] | 394 | |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Arvind Yadav | 2117355 | 2017-06-28 11:08:43 +0530 | [diff] [blame] | 398 | static const struct of_device_id panel_of_match[] = { |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 399 | { .compatible = "ti,tilcdc,panel", }, |
| 400 | { }, |
| 401 | }; |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 402 | |
| 403 | struct platform_driver panel_driver = { |
| 404 | .probe = panel_probe, |
| 405 | .remove = panel_remove, |
| 406 | .driver = { |
| 407 | .owner = THIS_MODULE, |
Jyri Sarha | 7f78c3d | 2018-02-21 18:38:24 +0200 | [diff] [blame] | 408 | .name = "tilcdc-panel", |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 409 | .of_match_table = panel_of_match, |
| 410 | }, |
| 411 | }; |
| 412 | |
| 413 | int __init tilcdc_panel_init(void) |
| 414 | { |
| 415 | return platform_driver_register(&panel_driver); |
| 416 | } |
| 417 | |
| 418 | void __exit tilcdc_panel_fini(void) |
| 419 | { |
| 420 | platform_driver_unregister(&panel_driver); |
| 421 | } |