/* * Copyright (C) 2009 Red Hat <mjg@redhat.com> * * 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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. *
*/
/* * Authors: * Matthew Garrett <mjg@redhat.com> * * Register locations derived from NVClock by Roderick Colenbrander
*/
/* * eDP brightness callbacks need to happen under lock, since we need to * enable/disable the backlight ourselves for modesets
*/ staticint
nv50_edp_get_brightness(struct backlight_device *bd)
{ struct drm_connector *connector = dev_get_drvdata(bd->dev.parent); struct drm_device *dev = connector->dev; struct drm_crtc *crtc; struct drm_modeset_acquire_ctx ctx; int ret = 0;
drm_modeset_acquire_init(&ctx, 0);
retry:
ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx); if (ret == -EDEADLK) goto deadlock; elseif (ret < 0) goto out;
crtc = connector->state->crtc; if (!crtc) goto out;
ret = drm_modeset_lock(&crtc->mutex, &ctx); if (ret == -EDEADLK) goto deadlock; elseif (ret < 0) goto out;
/* FIXME: perform backlight probing for eDP _before_ this, this only gets called after connector * registration which happens after the initial modeset
*/ staticint
nv50_backlight_init(struct nouveau_backlight *bl, struct nouveau_connector *nv_conn, struct nouveau_encoder *nv_encoder, struct backlight_properties *props, conststruct backlight_ops **ops)
{ struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
/* * Note when this runs the connectors have not been probed yet, * so nv_conn->base.status is not set yet.
*/ if (nvif_outp_bl_get(&nv_encoder->outp) < 0 ||
drm_helper_probe_detect(&nv_conn->base, NULL, false) != connector_status_connected) return -ENODEV;
if (nv_conn->type == DCB_CONNECTOR_eDP) { int ret;
u32 current_level;
u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
u8 current_mode;
ret = drm_dp_dpcd_read(&nv_conn->aux, DP_EDP_DPCD_REV, edp_dpcd,
EDP_DISPLAY_CTL_CAP_SIZE); if (ret < 0) return ret;
/* TODO: Add support for hybrid PWM/DPCD panels */ if (drm_edp_backlight_supported(edp_dpcd) &&
(edp_dpcd[1] & DP_EDP_BACKLIGHT_AUX_ENABLE_CAP) &&
(edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_AUX_SET_CAP)) {
NV_DEBUG(drm, "DPCD backlight controls supported on %s\n",
nv_conn->base.name);
ret = drm_edp_backlight_init(&nv_conn->aux, &bl->edp_info,
0, 0, edp_dpcd,
¤t_level, ¤t_mode, false); if (ret < 0) return ret;
ret = drm_edp_backlight_enable(&nv_conn->aux, &bl->edp_info, current_level); if (ret < 0) {
NV_ERROR(drm, "Failed to enable backlight on %s: %d\n",
nv_conn->base.name, ret); return ret;
}
bl = kzalloc(sizeof(*bl), GFP_KERNEL); if (!bl) return -ENOMEM;
switch (device->info.family) { case NV_DEVICE_INFO_V0_CURIE:
ret = nv40_backlight_init(nv_encoder, &props, &ops); break; case NV_DEVICE_INFO_V0_TESLA: case NV_DEVICE_INFO_V0_FERMI: case NV_DEVICE_INFO_V0_KEPLER: case NV_DEVICE_INFO_V0_MAXWELL: case NV_DEVICE_INFO_V0_PASCAL: case NV_DEVICE_INFO_V0_VOLTA: case NV_DEVICE_INFO_V0_TURING: case NV_DEVICE_INFO_V0_AMPERE: //XXX: not confirmed
ret = nv50_backlight_init(bl, nouveau_connector(connector),
nv_encoder, &props, &ops); break; default:
ret = 0; goto fail_alloc;
}
if (ret) { if (ret == -ENODEV)
ret = 0; goto fail_alloc;
}
if (!nouveau_acpi_video_backlight_use_native()) {
NV_INFO(drm, "Skipping nv_backlight registration\n"); goto fail_alloc;
}
if (!nouveau_get_backlight_name(backlight_name, bl)) {
NV_ERROR(drm, "Failed to retrieve a unique name for the backlight interface\n"); goto fail_alloc;
}
props.type = BACKLIGHT_RAW;
bl->dev = backlight_device_register(backlight_name, connector->kdev,
nv_encoder, ops, &props); if (IS_ERR(bl->dev)) { if (bl->id >= 0)
ida_free(&bl_ida, bl->id);
ret = PTR_ERR(bl->dev); goto fail_alloc;
}
nouveau_connector(connector)->backlight = bl; if (!bl->dev->props.brightness)
bl->dev->props.brightness =
bl->dev->ops->get_brightness(bl->dev);
backlight_update_status(bl->dev);
return 0;
fail_alloc:
kfree(bl); /* * If we get here we have an internal panel, but no nv_backlight, * try registering an ACPI video backlight device instead.
*/ if (ret == 0)
nouveau_acpi_video_register_backlight();