linux/drivers/gpu/drm/nouveau/core/subdev/devinit/nv50.c
<<
>>
Prefs
   1/*
   2 * Copyright 2013 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 <subdev/bios.h>
  26#include <subdev/bios/dcb.h>
  27#include <subdev/bios/disp.h>
  28#include <subdev/bios/init.h>
  29#include <subdev/vga.h>
  30
  31#include "nv50.h"
  32
  33int
  34nv50_devinit_pll_set(struct nouveau_devinit *devinit, u32 type, u32 freq)
  35{
  36        struct nv50_devinit_priv *priv = (void *)devinit;
  37        struct nouveau_bios *bios = nouveau_bios(priv);
  38        struct nvbios_pll info;
  39        int N1, M1, N2, M2, P;
  40        int ret;
  41
  42        ret = nvbios_pll_parse(bios, type, &info);
  43        if (ret) {
  44                nv_error(devinit, "failed to retrieve pll data, %d\n", ret);
  45                return ret;
  46        }
  47
  48        ret = nv04_pll_calc(nv_subdev(devinit), &info, freq, &N1, &M1, &N2, &M2, &P);
  49        if (!ret) {
  50                nv_error(devinit, "failed pll calculation\n");
  51                return ret;
  52        }
  53
  54        switch (info.type) {
  55        case PLL_VPLL0:
  56        case PLL_VPLL1:
  57                nv_wr32(priv, info.reg + 0, 0x10000611);
  58                nv_mask(priv, info.reg + 4, 0x00ff00ff, (M1 << 16) | N1);
  59                nv_mask(priv, info.reg + 8, 0x7fff00ff, (P  << 28) |
  60                                                        (M2 << 16) | N2);
  61                break;
  62        case PLL_MEMORY:
  63                nv_mask(priv, info.reg + 0, 0x01ff0000, (P << 22) |
  64                                                        (info.bias_p << 19) |
  65                                                        (P << 16));
  66                nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
  67                break;
  68        default:
  69                nv_mask(priv, info.reg + 0, 0x00070000, (P << 16));
  70                nv_wr32(priv, info.reg + 4, (N1 << 8) | M1);
  71                break;
  72        }
  73
  74        return 0;
  75}
  76
  77static u64
  78nv50_devinit_disable(struct nouveau_devinit *devinit)
  79{
  80        struct nv50_devinit_priv *priv = (void *)devinit;
  81        u32 r001540 = nv_rd32(priv, 0x001540);
  82        u64 disable = 0ULL;
  83
  84        if (!(r001540 & 0x40000000))
  85                disable |= (1ULL << NVDEV_ENGINE_MPEG);
  86
  87        return disable;
  88}
  89
  90int
  91nv50_devinit_init(struct nouveau_object *object)
  92{
  93        struct nouveau_bios *bios = nouveau_bios(object);
  94        struct nv50_devinit_priv *priv = (void *)object;
  95        struct nvbios_outp info;
  96        struct dcb_output outp;
  97        u8  ver = 0xff, hdr, cnt, len;
  98        int ret, i = 0;
  99
 100        if (!priv->base.post) {
 101                if (!nv_rdvgac(priv, 0, 0x00) &&
 102                    !nv_rdvgac(priv, 0, 0x1a)) {
 103                        nv_info(priv, "adaptor not initialised\n");
 104                        priv->base.post = true;
 105                }
 106        }
 107
 108        ret = nouveau_devinit_init(&priv->base);
 109        if (ret)
 110                return ret;
 111
 112        /* if we ran the init tables, we have to execute the first script
 113         * pointer of each dcb entry's display encoder table in order
 114         * to properly initialise each encoder.
 115         */
 116        while (priv->base.post && dcb_outp_parse(bios, i, &ver, &hdr, &outp)) {
 117                if (nvbios_outp_match(bios, outp.hasht, outp.hashm,
 118                                     &ver, &hdr, &cnt, &len, &info)) {
 119                        struct nvbios_init init = {
 120                                .subdev = nv_subdev(priv),
 121                                .bios = bios,
 122                                .offset = info.script[0],
 123                                .outp = &outp,
 124                                .crtc = -1,
 125                                .execute = 1,
 126                        };
 127
 128                        nvbios_exec(&init);
 129                }
 130                i++;
 131        }
 132
 133        return 0;
 134}
 135
 136int
 137nv50_devinit_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
 138                  struct nouveau_oclass *oclass, void *data, u32 size,
 139                  struct nouveau_object **pobject)
 140{
 141        struct nv50_devinit_priv *priv;
 142        int ret;
 143
 144        ret = nouveau_devinit_create(parent, engine, oclass, &priv);
 145        *pobject = nv_object(priv);
 146        if (ret)
 147                return ret;
 148
 149        return 0;
 150}
 151
 152struct nouveau_oclass *
 153nv50_devinit_oclass = &(struct nouveau_devinit_impl) {
 154        .base.handle = NV_SUBDEV(DEVINIT, 0x50),
 155        .base.ofuncs = &(struct nouveau_ofuncs) {
 156                .ctor = nv50_devinit_ctor,
 157                .dtor = _nouveau_devinit_dtor,
 158                .init = nv50_devinit_init,
 159                .fini = _nouveau_devinit_fini,
 160        },
 161        .pll_set = nv50_devinit_pll_set,
 162        .disable = nv50_devinit_disable,
 163}.base;
 164