2 * Copyright 2013 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
25 #include <subdev/timer.h>
26 #include <subdev/bus.h>
29 struct nouveau_bus *pbus;
39 hwsq_cmd(struct nouveau_hwsq *hwsq, int size, u8 data[])
41 memcpy(&hwsq->c.data[hwsq->c.size], data, size * sizeof(data[0]));
46 nouveau_hwsq_init(struct nouveau_bus *pbus, struct nouveau_hwsq **phwsq)
48 struct nouveau_hwsq *hwsq;
50 hwsq = *phwsq = kmalloc(sizeof(*hwsq), GFP_KERNEL);
55 memset(hwsq->c.data, 0x7f, sizeof(hwsq->c.data));
59 return hwsq ? 0 : -ENOMEM;
63 nouveau_hwsq_fini(struct nouveau_hwsq **phwsq, bool exec)
65 struct nouveau_hwsq *hwsq = *phwsq;
68 struct nouveau_bus *pbus = hwsq->pbus;
69 hwsq->c.size = (hwsq->c.size + 4) / 4;
70 if (hwsq->c.size <= pbus->hwsq_size) {
72 ret = pbus->hwsq_exec(pbus, (u32 *)hwsq->c.data,
75 nv_error(pbus, "hwsq exec failed: %d\n", ret);
77 nv_error(pbus, "hwsq ucode too large\n");
81 for (i = 0; ret && i < hwsq->c.size; i++)
82 nv_error(pbus, "\t0x%08x\n", ((u32 *)hwsq->c.data)[i]);
91 nouveau_hwsq_wr32(struct nouveau_hwsq *hwsq, u32 addr, u32 data)
93 nv_debug(hwsq->pbus, "R[%06x] = 0x%08x\n", addr, data);
95 if (hwsq->data != data) {
96 if ((data & 0xffff0000) != (hwsq->data & 0xffff0000)) {
97 hwsq_cmd(hwsq, 5, (u8[]){ 0xe2, data, data >> 8,
98 data >> 16, data >> 24 });
100 hwsq_cmd(hwsq, 3, (u8[]){ 0x42, data, data >> 8 });
104 if ((addr & 0xffff0000) != (hwsq->addr & 0xffff0000)) {
105 hwsq_cmd(hwsq, 5, (u8[]){ 0xe0, addr, addr >> 8,
106 addr >> 16, addr >> 24 });
108 hwsq_cmd(hwsq, 3, (u8[]){ 0x40, addr, addr >> 8 });
116 nouveau_hwsq_setf(struct nouveau_hwsq *hwsq, u8 flag, int data)
118 nv_debug(hwsq->pbus, " FLAG[%02x] = %d\n", flag, data);
124 hwsq_cmd(hwsq, 1, (u8[]){ flag });
128 nouveau_hwsq_wait(struct nouveau_hwsq *hwsq, u8 flag, u8 data)
130 nv_debug(hwsq->pbus, " WAIT[%02x] = %d\n", flag, data);
131 hwsq_cmd(hwsq, 3, (u8[]){ 0x5f, flag, data });
135 nouveau_hwsq_nsec(struct nouveau_hwsq *hwsq, u32 nsec)
137 u8 shift = 0, usec = nsec / 1000;
143 nv_debug(hwsq->pbus, " DELAY = %d ns\n", nsec);
144 hwsq_cmd(hwsq, 1, (u8[]){ 0x00 | (shift << 2) | usec });