| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd |
|---|
| 3 | 4 | * Author: |
|---|
| 4 | 5 | * Mark Yao <mark.yao@rock-chips.com> |
|---|
| 5 | 6 | * Sandy Huang <hjc@rock-chips.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This software is licensed under the terms of the GNU General Public |
|---|
| 8 | | - * License version 2, as published by the Free Software Foundation, and |
|---|
| 9 | | - * may be copied, distributed, and modified under those terms. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | 7 | */ |
|---|
| 16 | | - |
|---|
| 17 | | -#include <drm/drm_atomic_helper.h> |
|---|
| 18 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 19 | | -#include <drm/drm_panel.h> |
|---|
| 20 | | -#include <drm/drm_of.h> |
|---|
| 21 | 8 | |
|---|
| 22 | 9 | #include <linux/component.h> |
|---|
| 23 | 10 | #include <linux/mfd/syscon.h> |
|---|
| 24 | | -#include <linux/of_device.h> |
|---|
| 25 | 11 | #include <linux/of_graph.h> |
|---|
| 26 | | -#include <linux/regmap.h> |
|---|
| 27 | 12 | #include <linux/phy/phy.h> |
|---|
| 13 | +#include <linux/of_platform.h> |
|---|
| 14 | +#include <linux/regmap.h> |
|---|
| 15 | +#include <drm/drm_atomic_helper.h> |
|---|
| 16 | +#include <drm/drm_bridge.h> |
|---|
| 17 | +#include <drm/drm_of.h> |
|---|
| 18 | +#include <drm/drm_panel.h> |
|---|
| 19 | +#include <drm/drm_probe_helper.h> |
|---|
| 20 | +#include <drm/drm_simple_kms_helper.h> |
|---|
| 21 | + |
|---|
| 28 | 22 | #include <uapi/linux/videodev2.h> |
|---|
| 29 | 23 | |
|---|
| 30 | 24 | #include "rockchip_drm_drv.h" |
|---|
| .. | .. |
|---|
| 66 | 60 | #define RK3368_LVDS_MODE_EN(x) HIWORD_UPDATE(x, 12, 12) |
|---|
| 67 | 61 | #define RK3368_LVDS_MSBSEL(x) HIWORD_UPDATE(x, 11, 11) |
|---|
| 68 | 62 | #define RK3368_LVDS_P2S_EN(x) HIWORD_UPDATE(x, 6, 6) |
|---|
| 63 | + |
|---|
| 64 | +#define RK3562_GRF_VO_CON0 0x05d0 |
|---|
| 65 | +#define RK3562_GRF_VO_CON1 0x05d4 |
|---|
| 69 | 66 | |
|---|
| 70 | 67 | #define RK3568_GRF_VO_CON0 0x0360 |
|---|
| 71 | 68 | #define RK3568_LVDS1_SELECT(x) HIWORD_UPDATE(x, 13, 12) |
|---|
| .. | .. |
|---|
| 109 | 106 | enum lvds_format format; |
|---|
| 110 | 107 | bool data_swap; |
|---|
| 111 | 108 | bool dual_channel; |
|---|
| 109 | + bool phy_enabled; |
|---|
| 112 | 110 | enum drm_lvds_dual_link_pixels pixel_order; |
|---|
| 113 | 111 | |
|---|
| 114 | 112 | struct rockchip_lvds *primary; |
|---|
| .. | .. |
|---|
| 164 | 162 | struct rockchip_lvds *lvds = connector_to_lvds(connector); |
|---|
| 165 | 163 | struct drm_panel *panel = lvds->panel; |
|---|
| 166 | 164 | |
|---|
| 167 | | - return drm_panel_get_modes(panel); |
|---|
| 165 | + return drm_panel_get_modes(panel, connector); |
|---|
| 168 | 166 | } |
|---|
| 169 | 167 | |
|---|
| 170 | 168 | static const |
|---|
| .. | .. |
|---|
| 186 | 184 | bus_format = info->bus_formats[0]; |
|---|
| 187 | 185 | |
|---|
| 188 | 186 | switch (bus_format) { |
|---|
| 189 | | - case MEDIA_BUS_FMT_RGB666_1X7X3_JEIDA: /* jeida-18 */ |
|---|
| 190 | | - lvds->format = LVDS_6BIT_MODE; |
|---|
| 191 | | - break; |
|---|
| 192 | 187 | case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA: /* jeida-24 */ |
|---|
| 193 | 188 | lvds->format = LVDS_8BIT_MODE_FORMAT_2; |
|---|
| 194 | 189 | break; |
|---|
| .. | .. |
|---|
| 237 | 232 | s->output_type = DRM_MODE_CONNECTOR_LVDS; |
|---|
| 238 | 233 | s->bus_flags = info->bus_flags; |
|---|
| 239 | 234 | s->tv_state = &conn_state->tv; |
|---|
| 240 | | - s->eotf = TRADITIONAL_GAMMA_SDR; |
|---|
| 235 | + s->eotf = HDMI_EOTF_TRADITIONAL_GAMMA_SDR; |
|---|
| 241 | 236 | s->color_space = V4L2_COLORSPACE_DEFAULT; |
|---|
| 242 | 237 | |
|---|
| 243 | 238 | switch (lvds->pixel_order) { |
|---|
| .. | .. |
|---|
| 250 | 245 | s->output_flags |= ROCKCHIP_OUTPUT_DATA_SWAP; |
|---|
| 251 | 246 | s->output_if |= VOP_OUTPUT_IF_LVDS1 | VOP_OUTPUT_IF_LVDS0; |
|---|
| 252 | 247 | break; |
|---|
| 248 | +/* |
|---|
| 249 | + * Fix me: To do it with a GKI compatible version. |
|---|
| 250 | + */ |
|---|
| 251 | +#if 0 |
|---|
| 253 | 252 | case DRM_LVDS_DUAL_LINK_LEFT_RIGHT_PIXELS: |
|---|
| 254 | 253 | s->output_flags |= ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE; |
|---|
| 255 | 254 | s->output_if |= VOP_OUTPUT_IF_LVDS1 | VOP_OUTPUT_IF_LVDS0; |
|---|
| .. | .. |
|---|
| 259 | 258 | s->output_flags |= ROCKCHIP_OUTPUT_DATA_SWAP; |
|---|
| 260 | 259 | s->output_if |= VOP_OUTPUT_IF_LVDS1 | VOP_OUTPUT_IF_LVDS0; |
|---|
| 261 | 260 | break; |
|---|
| 261 | +#endif |
|---|
| 262 | 262 | default: |
|---|
| 263 | 263 | if (lvds->id) |
|---|
| 264 | 264 | s->output_if |= VOP_OUTPUT_IF_LVDS1; |
|---|
| .. | .. |
|---|
| 277 | 277 | if (lvds->funcs->enable) |
|---|
| 278 | 278 | lvds->funcs->enable(lvds); |
|---|
| 279 | 279 | |
|---|
| 280 | | - ret = phy_set_mode(lvds->phy, PHY_MODE_VIDEO_LVDS); |
|---|
| 280 | + ret = phy_set_mode(lvds->phy, PHY_MODE_LVDS); |
|---|
| 281 | 281 | if (ret) { |
|---|
| 282 | 282 | DRM_DEV_ERROR(lvds->dev, "failed to set phy mode: %d\n", ret); |
|---|
| 283 | 283 | return; |
|---|
| 284 | 284 | } |
|---|
| 285 | 285 | |
|---|
| 286 | | - phy_power_on(lvds->phy); |
|---|
| 286 | + if (lvds->phy && !lvds->phy_enabled) { |
|---|
| 287 | + phy_power_on(lvds->phy); |
|---|
| 288 | + lvds->phy_enabled = true; |
|---|
| 289 | + } |
|---|
| 287 | 290 | |
|---|
| 288 | 291 | if (lvds->secondary) |
|---|
| 289 | 292 | rockchip_lvds_enable(lvds->secondary); |
|---|
| .. | .. |
|---|
| 294 | 297 | if (lvds->funcs->disable) |
|---|
| 295 | 298 | lvds->funcs->disable(lvds); |
|---|
| 296 | 299 | |
|---|
| 297 | | - phy_power_off(lvds->phy); |
|---|
| 300 | + if (lvds->phy && lvds->phy_enabled) { |
|---|
| 301 | + phy_power_off(lvds->phy); |
|---|
| 302 | + lvds->phy_enabled = false; |
|---|
| 303 | + } |
|---|
| 298 | 304 | |
|---|
| 299 | 305 | if (lvds->secondary) |
|---|
| 300 | 306 | rockchip_lvds_disable(lvds->secondary); |
|---|
| .. | .. |
|---|
| 328 | 334 | struct rockchip_lvds *lvds = encoder_to_lvds(encoder); |
|---|
| 329 | 335 | |
|---|
| 330 | 336 | if (lvds->panel) |
|---|
| 331 | | - return drm_panel_loader_protect(lvds->panel, on); |
|---|
| 337 | + panel_simple_loader_protect(lvds->panel); |
|---|
| 338 | + |
|---|
| 339 | + |
|---|
| 340 | + if (on) { |
|---|
| 341 | + phy_init(lvds->phy); |
|---|
| 342 | + if (lvds->phy) { |
|---|
| 343 | + lvds->phy->power_count++; |
|---|
| 344 | + lvds->phy_enabled = true; |
|---|
| 345 | + } |
|---|
| 346 | + } else { |
|---|
| 347 | + phy_exit(lvds->phy); |
|---|
| 348 | + if (lvds->phy) { |
|---|
| 349 | + lvds->phy->power_count--; |
|---|
| 350 | + lvds->phy_enabled = false; |
|---|
| 351 | + } |
|---|
| 352 | + } |
|---|
| 332 | 353 | |
|---|
| 333 | 354 | return 0; |
|---|
| 334 | 355 | } |
|---|
| .. | .. |
|---|
| 339 | 360 | .disable = rockchip_lvds_encoder_disable, |
|---|
| 340 | 361 | .atomic_check = rockchip_lvds_encoder_atomic_check, |
|---|
| 341 | 362 | .atomic_mode_set = rockchip_lvds_encoder_atomic_mode_set, |
|---|
| 342 | | - .loader_protect = rockchip_lvds_encoder_loader_protect, |
|---|
| 343 | 363 | }; |
|---|
| 344 | 364 | |
|---|
| 345 | 365 | static const struct drm_encoder_funcs rockchip_lvds_encoder_funcs = { |
|---|
| 346 | 366 | .destroy = drm_encoder_cleanup, |
|---|
| 347 | 367 | }; |
|---|
| 348 | 368 | |
|---|
| 349 | | -static int rockchip_lvds_match_by_id(struct device *dev, void *data) |
|---|
| 369 | +static int rockchip_lvds_match_by_id(struct device *dev, const void *data) |
|---|
| 350 | 370 | { |
|---|
| 351 | 371 | struct rockchip_lvds *lvds = dev_get_drvdata(dev); |
|---|
| 352 | | - unsigned int *id = data; |
|---|
| 372 | + unsigned int *id = (unsigned int *)data; |
|---|
| 353 | 373 | |
|---|
| 354 | 374 | return lvds->id == *id; |
|---|
| 355 | 375 | } |
|---|
| 356 | 376 | |
|---|
| 357 | 377 | static struct rockchip_lvds *rockchip_lvds_find_by_id(struct device_driver *drv, |
|---|
| 358 | | - unsigned int id) |
|---|
| 378 | + unsigned int id) |
|---|
| 359 | 379 | { |
|---|
| 360 | 380 | struct device *dev; |
|---|
| 361 | 381 | |
|---|
| .. | .. |
|---|
| 386 | 406 | if (ret) |
|---|
| 387 | 407 | return ret; |
|---|
| 388 | 408 | |
|---|
| 389 | | - encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, |
|---|
| 390 | | - dev->of_node); |
|---|
| 409 | + encoder->possible_crtcs = rockchip_drm_of_find_possible_crtcs(drm_dev, |
|---|
| 410 | + dev->of_node); |
|---|
| 391 | 411 | |
|---|
| 392 | 412 | ret = drm_encoder_init(drm_dev, encoder, &rockchip_lvds_encoder_funcs, |
|---|
| 393 | 413 | DRM_MODE_ENCODER_LVDS, NULL); |
|---|
| .. | .. |
|---|
| 421 | 441 | goto err_free_connector; |
|---|
| 422 | 442 | } |
|---|
| 423 | 443 | |
|---|
| 424 | | - ret = drm_panel_attach(lvds->panel, connector); |
|---|
| 425 | | - if (ret < 0) { |
|---|
| 426 | | - DRM_DEV_ERROR(lvds->dev, |
|---|
| 427 | | - "failed to attach panel: %d\n", ret); |
|---|
| 428 | | - goto err_free_connector; |
|---|
| 429 | | - } |
|---|
| 430 | 444 | lvds->sub_dev.connector = &lvds->connector; |
|---|
| 431 | 445 | lvds->sub_dev.of_node = lvds->dev->of_node; |
|---|
| 446 | + lvds->sub_dev.loader_protect = rockchip_lvds_encoder_loader_protect; |
|---|
| 432 | 447 | rockchip_drm_register_sub_dev(&lvds->sub_dev); |
|---|
| 433 | 448 | drm_object_attach_property(&connector->base, private->connector_id_prop, 0); |
|---|
| 434 | 449 | } else { |
|---|
| 435 | | - ret = drm_bridge_attach(encoder, lvds->bridge, NULL); |
|---|
| 450 | + ret = drm_bridge_attach(encoder, lvds->bridge, NULL, 0); |
|---|
| 436 | 451 | if (ret) { |
|---|
| 437 | 452 | DRM_DEV_ERROR(lvds->dev, |
|---|
| 438 | 453 | "failed to attach bridge: %d\n", ret); |
|---|
| .. | .. |
|---|
| 456 | 471 | |
|---|
| 457 | 472 | if (lvds->sub_dev.connector) |
|---|
| 458 | 473 | rockchip_drm_unregister_sub_dev(&lvds->sub_dev); |
|---|
| 459 | | - if (lvds->panel) { |
|---|
| 460 | | - drm_panel_detach(lvds->panel); |
|---|
| 474 | + if (lvds->panel) |
|---|
| 461 | 475 | drm_connector_cleanup(&lvds->connector); |
|---|
| 462 | | - } |
|---|
| 463 | 476 | |
|---|
| 464 | 477 | if (lvds->encoder.dev) |
|---|
| 465 | 478 | drm_encoder_cleanup(&lvds->encoder); |
|---|
| .. | .. |
|---|
| 658 | 671 | return 0; |
|---|
| 659 | 672 | } |
|---|
| 660 | 673 | |
|---|
| 674 | +static void rk3562_lvds_enable(struct rockchip_lvds *lvds) |
|---|
| 675 | +{ |
|---|
| 676 | + regmap_write(lvds->grf, RK3562_GRF_VO_CON1, |
|---|
| 677 | + RK3568_LVDS0_MODE_EN(1) | RK3568_LVDS0_P2S_EN(1) | |
|---|
| 678 | + RK3568_LVDS0_DCLK_INV_SEL(1)); |
|---|
| 679 | + regmap_write(lvds->grf, RK3562_GRF_VO_CON0, |
|---|
| 680 | + RK3568_LVDS0_SELECT(lvds->format) | RK3568_LVDS0_MSBSEL(1)); |
|---|
| 681 | +} |
|---|
| 682 | + |
|---|
| 683 | +static void rk3562_lvds_disable(struct rockchip_lvds *lvds) |
|---|
| 684 | +{ |
|---|
| 685 | + regmap_write(lvds->grf, RK3562_GRF_VO_CON1, RK3568_LVDS0_MODE_EN(0)); |
|---|
| 686 | +} |
|---|
| 687 | + |
|---|
| 688 | +static const struct rockchip_lvds_funcs rk3562_lvds_funcs = { |
|---|
| 689 | + .enable = rk3562_lvds_enable, |
|---|
| 690 | + .disable = rk3562_lvds_disable, |
|---|
| 691 | +}; |
|---|
| 692 | + |
|---|
| 661 | 693 | static void rk3568_lvds_enable(struct rockchip_lvds *lvds) |
|---|
| 662 | 694 | { |
|---|
| 663 | 695 | regmap_write(lvds->grf, RK3568_GRF_VO_CON2, |
|---|
| .. | .. |
|---|
| 682 | 714 | { .compatible = "rockchip,rk3126-lvds", .data = &rk3126_lvds_funcs }, |
|---|
| 683 | 715 | { .compatible = "rockchip,rk3288-lvds", .data = &rk3288_lvds_funcs }, |
|---|
| 684 | 716 | { .compatible = "rockchip,rk3368-lvds", .data = &rk3368_lvds_funcs }, |
|---|
| 717 | + { .compatible = "rockchip,rk3562-lvds", .data = &rk3562_lvds_funcs }, |
|---|
| 685 | 718 | { .compatible = "rockchip,rk3568-lvds", .data = &rk3568_lvds_funcs }, |
|---|
| 686 | 719 | {} |
|---|
| 687 | 720 | }; |
|---|