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