1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright (C) 2010 Francisco Jerez.
3c39f472eSBen Skeggs  * All Rights Reserved.
4c39f472eSBen Skeggs  *
5c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining
6c39f472eSBen Skeggs  * a copy of this software and associated documentation files (the
7c39f472eSBen Skeggs  * "Software"), to deal in the Software without restriction, including
8c39f472eSBen Skeggs  * without limitation the rights to use, copy, modify, merge, publish,
9c39f472eSBen Skeggs  * distribute, sublicense, and/or sell copies of the Software, and to
10c39f472eSBen Skeggs  * permit persons to whom the Software is furnished to do so, subject to
11c39f472eSBen Skeggs  * the following conditions:
12c39f472eSBen Skeggs  *
13c39f472eSBen Skeggs  * The above copyright notice and this permission notice (including the
14c39f472eSBen Skeggs  * next paragraph) shall be included in all copies or substantial
15c39f472eSBen Skeggs  * portions of the Software.
16c39f472eSBen Skeggs  *
17c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18c39f472eSBen Skeggs  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19c39f472eSBen Skeggs  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20c39f472eSBen Skeggs  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21c39f472eSBen Skeggs  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22c39f472eSBen Skeggs  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23c39f472eSBen Skeggs  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24c39f472eSBen Skeggs  *
25c39f472eSBen Skeggs  */
26c39f472eSBen Skeggs #include <subdev/fb/regsnv04.h>
27c39f472eSBen Skeggs 
28c39f472eSBen Skeggs #define NV04_PFB_DEBUG_0					0x00100080
29c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_PAGE_MODE			0x00000001
30c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_REFRESH_OFF			0x00000010
31c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_REFRESH_COUNTX64		0x00003f00
32c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_REFRESH_SLOW_CLK		0x00004000
33c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_SAFE_MODE			0x00008000
34c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_ALOM_ENABLE			0x00010000
35c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_CASOE				0x00100000
36c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_CKE_INVERT			0x10000000
37c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_REFINC				0x20000000
38c39f472eSBen Skeggs #	define NV04_PFB_DEBUG_0_SAVE_POWER_OFF			0x40000000
39c39f472eSBen Skeggs #define NV04_PFB_CFG0						0x00100200
40c39f472eSBen Skeggs #	define NV04_PFB_CFG0_SCRAMBLE				0x20000000
41c39f472eSBen Skeggs #define NV04_PFB_CFG1						0x00100204
42c39f472eSBen Skeggs #define NV04_PFB_SCRAMBLE(i)                         (0x00100400 + 4 * (i))
43c39f472eSBen Skeggs 
44c39f472eSBen Skeggs #define NV10_PFB_REFCTRL					0x00100210
45c39f472eSBen Skeggs #	define NV10_PFB_REFCTRL_VALID_1				(1 << 31)
46c39f472eSBen Skeggs 
47c39f472eSBen Skeggs static inline struct io_mapping *
fbmem_init(struct nvkm_device * dev)48a8c4362bSBen Skeggs fbmem_init(struct nvkm_device *dev)
49c39f472eSBen Skeggs {
50*7e8820feSBen Skeggs 	return io_mapping_create_wc(dev->func->resource_addr(dev, 1),
51*7e8820feSBen Skeggs 				    dev->func->resource_size(dev, 1));
52c39f472eSBen Skeggs }
53c39f472eSBen Skeggs 
54c39f472eSBen Skeggs static inline void
fbmem_fini(struct io_mapping * fb)55c39f472eSBen Skeggs fbmem_fini(struct io_mapping *fb)
56c39f472eSBen Skeggs {
57c39f472eSBen Skeggs 	io_mapping_free(fb);
58c39f472eSBen Skeggs }
59c39f472eSBen Skeggs 
60c39f472eSBen Skeggs static inline u32
fbmem_peek(struct io_mapping * fb,u32 off)61c39f472eSBen Skeggs fbmem_peek(struct io_mapping *fb, u32 off)
62c39f472eSBen Skeggs {
63c39f472eSBen Skeggs 	u8 __iomem *p = io_mapping_map_atomic_wc(fb, off & PAGE_MASK);
64c39f472eSBen Skeggs 	u32 val = ioread32(p + (off & ~PAGE_MASK));
65c39f472eSBen Skeggs 	io_mapping_unmap_atomic(p);
66c39f472eSBen Skeggs 	return val;
67c39f472eSBen Skeggs }
68c39f472eSBen Skeggs 
69c39f472eSBen Skeggs static inline void
fbmem_poke(struct io_mapping * fb,u32 off,u32 val)70c39f472eSBen Skeggs fbmem_poke(struct io_mapping *fb, u32 off, u32 val)
71c39f472eSBen Skeggs {
72c39f472eSBen Skeggs 	u8 __iomem *p = io_mapping_map_atomic_wc(fb, off & PAGE_MASK);
73c39f472eSBen Skeggs 	iowrite32(val, p + (off & ~PAGE_MASK));
74c39f472eSBen Skeggs 	wmb();
75c39f472eSBen Skeggs 	io_mapping_unmap_atomic(p);
76c39f472eSBen Skeggs }
77c39f472eSBen Skeggs 
78c39f472eSBen Skeggs static inline bool
fbmem_readback(struct io_mapping * fb,u32 off,u32 val)79c39f472eSBen Skeggs fbmem_readback(struct io_mapping *fb, u32 off, u32 val)
80c39f472eSBen Skeggs {
81c39f472eSBen Skeggs 	fbmem_poke(fb, off, val);
82c39f472eSBen Skeggs 	return val == fbmem_peek(fb, off);
83c39f472eSBen Skeggs }
84