1c39f472eSBen Skeggs /* 2c39f472eSBen Skeggs * Copyright 2014 Martin Peres 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: Martin Peres 23c39f472eSBen Skeggs */ 24c39f472eSBen Skeggs #include "priv.h" 25c39f472eSBen Skeggs 26ce7b4f60SBen Skeggs struct gf100_fuse { 27630ec6c0SBen Skeggs struct nvkm_fuse base; 28c39f472eSBen Skeggs 29c39f472eSBen Skeggs spinlock_t fuse_enable_lock; 30c39f472eSBen Skeggs }; 31c39f472eSBen Skeggs 32c39f472eSBen Skeggs static u32 33630ec6c0SBen Skeggs gf100_fuse_rd32(struct nvkm_object *object, u64 addr) 34c39f472eSBen Skeggs { 35ce7b4f60SBen Skeggs struct gf100_fuse *fuse = (void *)object; 36c39f472eSBen Skeggs unsigned long flags; 37c39f472eSBen Skeggs u32 fuse_enable, unk, val; 38c39f472eSBen Skeggs 39630ec6c0SBen Skeggs /* racy if another part of nvkm start writing to these regs */ 40ce7b4f60SBen Skeggs spin_lock_irqsave(&fuse->fuse_enable_lock, flags); 41ce7b4f60SBen Skeggs fuse_enable = nv_mask(fuse, 0x22400, 0x800, 0x800); 42ce7b4f60SBen Skeggs unk = nv_mask(fuse, 0x21000, 0x1, 0x1); 43ce7b4f60SBen Skeggs val = nv_rd32(fuse, 0x21100 + addr); 44ce7b4f60SBen Skeggs nv_wr32(fuse, 0x21000, unk); 45ce7b4f60SBen Skeggs nv_wr32(fuse, 0x22400, fuse_enable); 46ce7b4f60SBen Skeggs spin_unlock_irqrestore(&fuse->fuse_enable_lock, flags); 47c39f472eSBen Skeggs return val; 48c39f472eSBen Skeggs } 49c39f472eSBen Skeggs 50c39f472eSBen Skeggs 51c39f472eSBen Skeggs static int 52630ec6c0SBen Skeggs gf100_fuse_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 53630ec6c0SBen Skeggs struct nvkm_oclass *oclass, void *data, u32 size, 54630ec6c0SBen Skeggs struct nvkm_object **pobject) 55c39f472eSBen Skeggs { 56ce7b4f60SBen Skeggs struct gf100_fuse *fuse; 57c39f472eSBen Skeggs int ret; 58c39f472eSBen Skeggs 59ce7b4f60SBen Skeggs ret = nvkm_fuse_create(parent, engine, oclass, &fuse); 60ce7b4f60SBen Skeggs *pobject = nv_object(fuse); 61c39f472eSBen Skeggs if (ret) 62c39f472eSBen Skeggs return ret; 63c39f472eSBen Skeggs 64ce7b4f60SBen Skeggs spin_lock_init(&fuse->fuse_enable_lock); 65c39f472eSBen Skeggs return 0; 66c39f472eSBen Skeggs } 67c39f472eSBen Skeggs 68630ec6c0SBen Skeggs struct nvkm_oclass 69c39f472eSBen Skeggs gf100_fuse_oclass = { 70c39f472eSBen Skeggs .handle = NV_SUBDEV(FUSE, 0xC0), 71630ec6c0SBen Skeggs .ofuncs = &(struct nvkm_ofuncs) { 72c39f472eSBen Skeggs .ctor = gf100_fuse_ctor, 73630ec6c0SBen Skeggs .dtor = _nvkm_fuse_dtor, 74630ec6c0SBen Skeggs .init = _nvkm_fuse_init, 75630ec6c0SBen Skeggs .fini = _nvkm_fuse_fini, 76c39f472eSBen Skeggs .rd32 = gf100_fuse_rd32, 77c39f472eSBen Skeggs }, 78c39f472eSBen Skeggs }; 79