linux/drivers/gpu/drm/nouveau/core/engine/disp/piornv50.c
<<
>>
Prefs
   1/*
   2 * Copyright 2012 Red Hat Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 * Authors: Ben Skeggs
  23 */
  24
  25#include <core/os.h>
  26#include <core/class.h>
  27
  28#include <subdev/bios.h>
  29#include <subdev/bios/dcb.h>
  30#include <subdev/timer.h>
  31#include <subdev/i2c.h>
  32
  33#include "nv50.h"
  34
  35/******************************************************************************
  36 * DisplayPort
  37 *****************************************************************************/
  38static struct nouveau_i2c_port *
  39nv50_pior_dp_find(struct nouveau_disp *disp, struct dcb_output *outp)
  40{
  41        struct nouveau_i2c *i2c = nouveau_i2c(disp);
  42        return i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(outp->extdev));
  43}
  44
  45static int
  46nv50_pior_dp_pattern(struct nouveau_disp *disp, struct dcb_output *outp,
  47                     int head, int pattern)
  48{
  49        struct nouveau_i2c_port *port;
  50        int ret = -EINVAL;
  51
  52        port = nv50_pior_dp_find(disp, outp);
  53        if (port) {
  54                if (port->func->pattern)
  55                        ret = port->func->pattern(port, pattern);
  56                else
  57                        ret = 0;
  58        }
  59
  60        return ret;
  61}
  62
  63static int
  64nv50_pior_dp_lnk_ctl(struct nouveau_disp *disp, struct dcb_output *outp,
  65                     int head, int lane_nr, int link_bw, bool enh)
  66{
  67        struct nouveau_i2c_port *port;
  68        int ret = -EINVAL;
  69
  70        port = nv50_pior_dp_find(disp, outp);
  71        if (port && port->func->lnk_ctl)
  72                ret = port->func->lnk_ctl(port, lane_nr, link_bw, enh);
  73
  74        return ret;
  75}
  76
  77static int
  78nv50_pior_dp_drv_ctl(struct nouveau_disp *disp, struct dcb_output *outp,
  79                     int head, int lane, int vsw, int pre)
  80{
  81        struct nouveau_i2c_port *port;
  82        int ret = -EINVAL;
  83
  84        port = nv50_pior_dp_find(disp, outp);
  85        if (port) {
  86                if (port->func->drv_ctl)
  87                        ret = port->func->drv_ctl(port, lane, vsw, pre);
  88                else
  89                        ret = 0;
  90        }
  91
  92        return ret;
  93}
  94
  95const struct nouveau_dp_func
  96nv50_pior_dp_func = {
  97        .pattern = nv50_pior_dp_pattern,
  98        .lnk_ctl = nv50_pior_dp_lnk_ctl,
  99        .drv_ctl = nv50_pior_dp_drv_ctl,
 100};
 101
 102/******************************************************************************
 103 * General PIOR handling
 104 *****************************************************************************/
 105int
 106nv50_pior_power(struct nv50_disp_priv *priv, int or, u32 data)
 107{
 108        const u32 stat = data & NV50_DISP_PIOR_PWR_STATE;
 109        const u32 soff = (or * 0x800);
 110        nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
 111        nv_mask(priv, 0x61e004 + soff, 0x80000101, 0x80000000 | stat);
 112        nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
 113        return 0;
 114}
 115
 116int
 117nv50_pior_mthd(struct nouveau_object *object, u32 mthd, void *args, u32 size)
 118{
 119        struct nv50_disp_priv *priv = (void *)object->engine;
 120        const u8 type = (mthd & NV50_DISP_PIOR_MTHD_TYPE) >> 12;
 121        const u8 or   = (mthd & NV50_DISP_PIOR_MTHD_OR);
 122        u32 *data = args;
 123        int ret;
 124
 125        if (size < sizeof(u32))
 126                return -EINVAL;
 127
 128        mthd &= ~NV50_DISP_PIOR_MTHD_TYPE;
 129        mthd &= ~NV50_DISP_PIOR_MTHD_OR;
 130        switch (mthd) {
 131        case NV50_DISP_PIOR_PWR:
 132                ret = priv->pior.power(priv, or, data[0]);
 133                priv->pior.type[or] = type;
 134                break;
 135        default:
 136                return -EINVAL;
 137        }
 138
 139        return ret;
 140}
 141