1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright 2013 Red Hat Inc.
3c39f472eSBen Skeggs  *
4c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs  * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs  *
11c39f472eSBen Skeggs  * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs  * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs  *
14c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17c39f472eSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs  *
22c39f472eSBen Skeggs  * Authors: Ben Skeggs
23c39f472eSBen Skeggs  */
24d36a99d2SBen Skeggs #include "ramnv40.h"
25c39f472eSBen Skeggs 
26d36a99d2SBen Skeggs int
nv49_ram_new(struct nvkm_fb * fb,struct nvkm_ram ** pram)27d36a99d2SBen Skeggs nv49_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
28c39f472eSBen Skeggs {
296758745bSBen Skeggs 	struct nvkm_device *device = fb->subdev.device;
30d36a99d2SBen Skeggs 	u32  size = nvkm_rd32(device, 0x10020c) & 0xff000000;
316758745bSBen Skeggs 	u32 fb914 = nvkm_rd32(device, 0x100914);
32d36a99d2SBen Skeggs 	enum nvkm_ram_type type = NVKM_RAM_TYPE_UNKNOWN;
33c39f472eSBen Skeggs 	int ret;
34c39f472eSBen Skeggs 
35b1e4553cSBen Skeggs 	switch (fb914 & 0x00000003) {
36d36a99d2SBen Skeggs 	case 0x00000000: type = NVKM_RAM_TYPE_DDR1 ; break;
37d36a99d2SBen Skeggs 	case 0x00000001: type = NVKM_RAM_TYPE_DDR2 ; break;
38d36a99d2SBen Skeggs 	case 0x00000002: type = NVKM_RAM_TYPE_GDDR3; break;
39c39f472eSBen Skeggs 	case 0x00000003: break;
40c39f472eSBen Skeggs 	}
41c39f472eSBen Skeggs 
42af793b8cSBen Skeggs 	ret = nv40_ram_new_(fb, type, size, pram);
43d36a99d2SBen Skeggs 	if (ret)
44d36a99d2SBen Skeggs 		return ret;
45d36a99d2SBen Skeggs 
46d36a99d2SBen Skeggs 	(*pram)->parts = (nvkm_rd32(device, 0x100200) & 0x00000003) + 1;
47c39f472eSBen Skeggs 	return 0;
48c39f472eSBen Skeggs }
49