2016-04-26 21:14:25 +08:00
|
|
|
/*
|
|
|
|
* Copyright © 2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Deepak M <m.deepak at intel.com>
|
|
|
|
*/
|
|
|
|
|
2019-04-29 20:29:34 +08:00
|
|
|
#include <drm/drm_mipi_dsi.h>
|
|
|
|
#include <video/mipi_display.h>
|
|
|
|
|
|
|
|
#include "i915_drv.h"
|
2019-08-06 19:39:33 +08:00
|
|
|
#include "intel_display_types.h"
|
2016-04-26 21:14:25 +08:00
|
|
|
#include "intel_dsi.h"
|
2019-04-29 20:29:34 +08:00
|
|
|
#include "intel_dsi_dcs_backlight.h"
|
2016-04-26 21:14:25 +08:00
|
|
|
|
|
|
|
#define CONTROL_DISPLAY_BCTRL (1 << 5)
|
|
|
|
#define CONTROL_DISPLAY_DD (1 << 3)
|
|
|
|
#define CONTROL_DISPLAY_BL (1 << 2)
|
|
|
|
|
2016-04-26 21:14:26 +08:00
|
|
|
#define POWER_SAVE_OFF (0 << 0)
|
|
|
|
#define POWER_SAVE_LOW (1 << 0)
|
|
|
|
#define POWER_SAVE_MEDIUM (2 << 0)
|
|
|
|
#define POWER_SAVE_HIGH (3 << 0)
|
|
|
|
#define POWER_SAVE_OUTDOOR_MODE (4 << 0)
|
|
|
|
|
2016-04-26 21:14:25 +08:00
|
|
|
#define PANEL_PWM_MAX_VALUE 0xFF
|
|
|
|
|
2021-01-15 06:17:05 +08:00
|
|
|
static u32 dcs_get_backlight(struct intel_connector *connector, enum pipe unused)
|
2016-04-26 21:14:25 +08:00
|
|
|
{
|
2019-12-05 02:05:45 +08:00
|
|
|
struct intel_encoder *encoder = intel_attached_encoder(connector);
|
2019-12-05 02:05:43 +08:00
|
|
|
struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
|
2021-09-08 19:56:07 +08:00
|
|
|
struct intel_panel *panel = &connector->panel;
|
2016-04-26 21:14:25 +08:00
|
|
|
struct mipi_dsi_device *dsi_device;
|
2021-09-08 19:56:07 +08:00
|
|
|
u8 data[2] = {};
|
2016-04-26 21:14:25 +08:00
|
|
|
enum port port;
|
2021-09-08 19:56:07 +08:00
|
|
|
size_t len = panel->backlight.max > U8_MAX ? 2 : 1;
|
2016-04-26 21:14:25 +08:00
|
|
|
|
|
|
|
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
|
|
|
|
dsi_device = intel_dsi->dsi_hosts[port]->device;
|
|
|
|
mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_DISPLAY_BRIGHTNESS,
|
2021-09-08 19:56:07 +08:00
|
|
|
&data, len);
|
2016-04-26 21:14:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-08 19:56:07 +08:00
|
|
|
return (data[1] << 8) | data[0];
|
2016-04-26 21:14:25 +08:00
|
|
|
}
|
|
|
|
|
2017-06-12 18:21:15 +08:00
|
|
|
static void dcs_set_backlight(const struct drm_connector_state *conn_state, u32 level)
|
2016-04-26 21:14:25 +08:00
|
|
|
{
|
2019-12-05 02:05:43 +08:00
|
|
|
struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(conn_state->best_encoder));
|
2021-09-08 19:56:07 +08:00
|
|
|
struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel;
|
2016-04-26 21:14:25 +08:00
|
|
|
struct mipi_dsi_device *dsi_device;
|
2021-09-08 19:56:07 +08:00
|
|
|
u8 data[2] = {};
|
2016-04-26 21:14:25 +08:00
|
|
|
enum port port;
|
2021-09-08 19:56:07 +08:00
|
|
|
size_t len = panel->backlight.max > U8_MAX ? 2 : 1;
|
|
|
|
|
|
|
|
if (len == 1) {
|
|
|
|
data[0] = level;
|
|
|
|
} else {
|
|
|
|
data[0] = level >> 8;
|
|
|
|
data[1] = level;
|
|
|
|
}
|
2016-04-26 21:14:25 +08:00
|
|
|
|
|
|
|
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
|
|
|
|
dsi_device = intel_dsi->dsi_hosts[port]->device;
|
|
|
|
mipi_dsi_dcs_write(dsi_device, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
|
2021-09-08 19:56:07 +08:00
|
|
|
&data, len);
|
2016-04-26 21:14:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-05 06:35:57 +08:00
|
|
|
static void dcs_disable_backlight(const struct drm_connector_state *conn_state, u32 level)
|
2016-04-26 21:14:25 +08:00
|
|
|
{
|
2019-12-05 02:05:43 +08:00
|
|
|
struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(conn_state->best_encoder));
|
2016-04-26 21:14:25 +08:00
|
|
|
struct mipi_dsi_device *dsi_device;
|
|
|
|
enum port port;
|
|
|
|
|
2017-06-12 18:21:15 +08:00
|
|
|
dcs_set_backlight(conn_state, 0);
|
2016-04-26 21:14:25 +08:00
|
|
|
|
2016-04-26 21:14:26 +08:00
|
|
|
for_each_dsi_port(port, intel_dsi->dcs_cabc_ports) {
|
|
|
|
u8 cabc = POWER_SAVE_OFF;
|
|
|
|
|
|
|
|
dsi_device = intel_dsi->dsi_hosts[port]->device;
|
|
|
|
mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_POWER_SAVE,
|
|
|
|
&cabc, sizeof(cabc));
|
|
|
|
}
|
|
|
|
|
2016-04-26 21:14:25 +08:00
|
|
|
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
|
|
|
|
u8 ctrl = 0;
|
|
|
|
|
|
|
|
dsi_device = intel_dsi->dsi_hosts[port]->device;
|
|
|
|
|
|
|
|
mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_CONTROL_DISPLAY,
|
|
|
|
&ctrl, sizeof(ctrl));
|
|
|
|
|
|
|
|
ctrl &= ~CONTROL_DISPLAY_BL;
|
|
|
|
ctrl &= ~CONTROL_DISPLAY_DD;
|
|
|
|
ctrl &= ~CONTROL_DISPLAY_BCTRL;
|
|
|
|
|
|
|
|
mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
|
|
|
|
&ctrl, sizeof(ctrl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 18:21:15 +08:00
|
|
|
static void dcs_enable_backlight(const struct intel_crtc_state *crtc_state,
|
2020-12-05 06:35:57 +08:00
|
|
|
const struct drm_connector_state *conn_state, u32 level)
|
2016-04-26 21:14:25 +08:00
|
|
|
{
|
2019-12-05 02:05:43 +08:00
|
|
|
struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(conn_state->best_encoder));
|
2016-04-26 21:14:25 +08:00
|
|
|
struct mipi_dsi_device *dsi_device;
|
|
|
|
enum port port;
|
|
|
|
|
|
|
|
for_each_dsi_port(port, intel_dsi->dcs_backlight_ports) {
|
|
|
|
u8 ctrl = 0;
|
|
|
|
|
|
|
|
dsi_device = intel_dsi->dsi_hosts[port]->device;
|
|
|
|
|
|
|
|
mipi_dsi_dcs_read(dsi_device, MIPI_DCS_GET_CONTROL_DISPLAY,
|
|
|
|
&ctrl, sizeof(ctrl));
|
|
|
|
|
|
|
|
ctrl |= CONTROL_DISPLAY_BL;
|
|
|
|
ctrl |= CONTROL_DISPLAY_DD;
|
|
|
|
ctrl |= CONTROL_DISPLAY_BCTRL;
|
|
|
|
|
|
|
|
mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_CONTROL_DISPLAY,
|
|
|
|
&ctrl, sizeof(ctrl));
|
|
|
|
}
|
|
|
|
|
2016-04-26 21:14:26 +08:00
|
|
|
for_each_dsi_port(port, intel_dsi->dcs_cabc_ports) {
|
|
|
|
u8 cabc = POWER_SAVE_MEDIUM;
|
|
|
|
|
|
|
|
dsi_device = intel_dsi->dsi_hosts[port]->device;
|
|
|
|
mipi_dsi_dcs_write(dsi_device, MIPI_DCS_WRITE_POWER_SAVE,
|
|
|
|
&cabc, sizeof(cabc));
|
|
|
|
}
|
|
|
|
|
2020-12-05 06:35:57 +08:00
|
|
|
dcs_set_backlight(conn_state, level);
|
2016-04-26 21:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dcs_setup_backlight(struct intel_connector *connector,
|
|
|
|
enum pipe unused)
|
|
|
|
{
|
2021-09-08 19:56:06 +08:00
|
|
|
struct drm_device *dev = connector->base.dev;
|
|
|
|
struct drm_i915_private *dev_priv = to_i915(dev);
|
2016-04-26 21:14:25 +08:00
|
|
|
struct intel_panel *panel = &connector->panel;
|
|
|
|
|
2021-09-08 19:56:06 +08:00
|
|
|
if (dev_priv->vbt.backlight.brightness_precision_bits > 8)
|
|
|
|
panel->backlight.max = (1 << dev_priv->vbt.backlight.brightness_precision_bits) - 1;
|
|
|
|
else
|
|
|
|
panel->backlight.max = PANEL_PWM_MAX_VALUE;
|
|
|
|
|
|
|
|
panel->backlight.level = panel->backlight.max;
|
2016-04-26 21:14:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-01 05:09:45 +08:00
|
|
|
static const struct intel_panel_bl_funcs dcs_bl_funcs = {
|
|
|
|
.setup = dcs_setup_backlight,
|
|
|
|
.enable = dcs_enable_backlight,
|
|
|
|
.disable = dcs_disable_backlight,
|
|
|
|
.set = dcs_set_backlight,
|
|
|
|
.get = dcs_get_backlight,
|
|
|
|
};
|
|
|
|
|
2016-04-26 21:14:25 +08:00
|
|
|
int intel_dsi_dcs_init_backlight_funcs(struct intel_connector *intel_connector)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = intel_connector->base.dev;
|
2016-07-04 18:34:36 +08:00
|
|
|
struct drm_i915_private *dev_priv = to_i915(dev);
|
2019-12-05 02:05:45 +08:00
|
|
|
struct intel_encoder *encoder = intel_attached_encoder(intel_connector);
|
2016-04-26 21:14:25 +08:00
|
|
|
struct intel_panel *panel = &intel_connector->panel;
|
|
|
|
|
|
|
|
if (dev_priv->vbt.backlight.type != INTEL_BACKLIGHT_DSI_DCS)
|
|
|
|
return -ENODEV;
|
|
|
|
|
drm/i915/display: Make WARN* drm specific where drm_device ptr is available
drm specific WARN* calls include device information in the
backtrace, so we know what device the warnings originate from.
Covert all the calls of WARN* with device specific drm_WARN*
variants in functions where drm_device or drm_i915_private struct
pointer is readily available.
The conversion was done automatically with below coccinelle semantic
patch. checkpatch errors/warnings are fixed manually.
@rule1@
identifier func, T;
@@
func(...) {
...
struct drm_device *T = ...;
<...
(
-WARN(
+drm_WARN(T,
...)
|
-WARN_ON(
+drm_WARN_ON(T,
...)
|
-WARN_ONCE(
+drm_WARN_ONCE(T,
...)
|
-WARN_ON_ONCE(
+drm_WARN_ON_ONCE(T,
...)
)
...>
}
@rule2@
identifier func, T;
@@
func(struct drm_device *T,...) {
<...
(
-WARN(
+drm_WARN(T,
...)
|
-WARN_ON(
+drm_WARN_ON(T,
...)
|
-WARN_ONCE(
+drm_WARN_ONCE(T,
...)
|
-WARN_ON_ONCE(
+drm_WARN_ON_ONCE(T,
...)
)
...>
}
@rule3@
identifier func, T;
@@
func(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-WARN(
+drm_WARN(&T->drm,
...)
|
-WARN_ON(
+drm_WARN_ON(&T->drm,
...)
|
-WARN_ONCE(
+drm_WARN_ONCE(&T->drm,
...)
|
-WARN_ON_ONCE(
+drm_WARN_ON_ONCE(&T->drm,
...)
)
...+>
}
@rule4@
identifier func, T;
@@
func(struct drm_i915_private *T,...) {
<+...
(
-WARN(
+drm_WARN(&T->drm,
...)
|
-WARN_ON(
+drm_WARN_ON(&T->drm,
...)
|
-WARN_ONCE(
+drm_WARN_ONCE(&T->drm,
...)
|
-WARN_ON_ONCE(
+drm_WARN_ON_ONCE(&T->drm,
...)
)
...+>
}
Signed-off-by: Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200128181603.27767-20-pankaj.laxminarayan.bharadiya@intel.com
2020-01-29 02:16:01 +08:00
|
|
|
if (drm_WARN_ON(dev, encoder->type != INTEL_OUTPUT_DSI))
|
2016-04-26 21:14:25 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2020-12-01 05:09:45 +08:00
|
|
|
panel->backlight.funcs = &dcs_bl_funcs;
|
2016-04-26 21:14:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|