12ea7249fSBen Skeggs /*
22ea7249fSBen Skeggs * Copyright 2012 Red Hat Inc.
32ea7249fSBen Skeggs *
42ea7249fSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
52ea7249fSBen Skeggs * copy of this software and associated documentation files (the "Software"),
62ea7249fSBen Skeggs * to deal in the Software without restriction, including without limitation
72ea7249fSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
82ea7249fSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
92ea7249fSBen Skeggs * Software is furnished to do so, subject to the following conditions:
102ea7249fSBen Skeggs *
112ea7249fSBen Skeggs * The above copyright notice and this permission notice shall be included in
122ea7249fSBen Skeggs * all copies or substantial portions of the Software.
132ea7249fSBen Skeggs *
142ea7249fSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
152ea7249fSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
162ea7249fSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
172ea7249fSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
182ea7249fSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
192ea7249fSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
202ea7249fSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
212ea7249fSBen Skeggs *
222ea7249fSBen Skeggs * Authors: Ben Skeggs
232ea7249fSBen Skeggs */
242ea7249fSBen Skeggs #include "priv.h"
252ea7249fSBen Skeggs
262ea7249fSBen Skeggs void
gf119_gpio_reset(struct nvkm_gpio * gpio,u8 match)272ea7249fSBen Skeggs gf119_gpio_reset(struct nvkm_gpio *gpio, u8 match)
282ea7249fSBen Skeggs {
292ea7249fSBen Skeggs struct nvkm_device *device = gpio->subdev.device;
302ea7249fSBen Skeggs struct nvkm_bios *bios = device->bios;
312ea7249fSBen Skeggs u8 ver, len;
322ea7249fSBen Skeggs u16 entry;
332ea7249fSBen Skeggs int ent = -1;
342ea7249fSBen Skeggs
352ea7249fSBen Skeggs while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver, &len))) {
362ea7249fSBen Skeggs u32 data = nvbios_rd32(bios, entry);
372ea7249fSBen Skeggs u8 line = (data & 0x0000003f);
382ea7249fSBen Skeggs u8 defs = !!(data & 0x00000080);
392ea7249fSBen Skeggs u8 func = (data & 0x0000ff00) >> 8;
402ea7249fSBen Skeggs u8 unk0 = (data & 0x00ff0000) >> 16;
412ea7249fSBen Skeggs u8 unk1 = (data & 0x1f000000) >> 24;
422ea7249fSBen Skeggs
432ea7249fSBen Skeggs if ( func == DCB_GPIO_UNUSED ||
442ea7249fSBen Skeggs (match != DCB_GPIO_UNUSED && match != func))
452ea7249fSBen Skeggs continue;
462ea7249fSBen Skeggs
472ea7249fSBen Skeggs nvkm_gpio_set(gpio, 0, func, line, defs);
482ea7249fSBen Skeggs
492ea7249fSBen Skeggs nvkm_mask(device, 0x00d610 + (line * 4), 0xff, unk0);
502ea7249fSBen Skeggs if (unk1--)
512ea7249fSBen Skeggs nvkm_mask(device, 0x00d740 + (unk1 * 4), 0xff, line);
522ea7249fSBen Skeggs }
532ea7249fSBen Skeggs }
542ea7249fSBen Skeggs
552ea7249fSBen Skeggs int
gf119_gpio_drive(struct nvkm_gpio * gpio,int line,int dir,int out)562ea7249fSBen Skeggs gf119_gpio_drive(struct nvkm_gpio *gpio, int line, int dir, int out)
572ea7249fSBen Skeggs {
582ea7249fSBen Skeggs struct nvkm_device *device = gpio->subdev.device;
592ea7249fSBen Skeggs u32 data = ((dir ^ 1) << 13) | (out << 12);
602ea7249fSBen Skeggs nvkm_mask(device, 0x00d610 + (line * 4), 0x00003000, data);
612ea7249fSBen Skeggs nvkm_mask(device, 0x00d604, 0x00000001, 0x00000001); /* update? */
622ea7249fSBen Skeggs return 0;
632ea7249fSBen Skeggs }
642ea7249fSBen Skeggs
652ea7249fSBen Skeggs int
gf119_gpio_sense(struct nvkm_gpio * gpio,int line)662ea7249fSBen Skeggs gf119_gpio_sense(struct nvkm_gpio *gpio, int line)
672ea7249fSBen Skeggs {
682ea7249fSBen Skeggs struct nvkm_device *device = gpio->subdev.device;
692ea7249fSBen Skeggs return !!(nvkm_rd32(device, 0x00d610 + (line * 4)) & 0x00004000);
702ea7249fSBen Skeggs }
712ea7249fSBen Skeggs
722ea7249fSBen Skeggs static const struct nvkm_gpio_func
732ea7249fSBen Skeggs gf119_gpio = {
742ea7249fSBen Skeggs .lines = 32,
752ea7249fSBen Skeggs .intr_stat = g94_gpio_intr_stat,
762ea7249fSBen Skeggs .intr_mask = g94_gpio_intr_mask,
772ea7249fSBen Skeggs .drive = gf119_gpio_drive,
782ea7249fSBen Skeggs .sense = gf119_gpio_sense,
792ea7249fSBen Skeggs .reset = gf119_gpio_reset,
802ea7249fSBen Skeggs };
812ea7249fSBen Skeggs
822ea7249fSBen Skeggs int
gf119_gpio_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_gpio ** pgpio)83*01055c01SBen Skeggs gf119_gpio_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
84*01055c01SBen Skeggs struct nvkm_gpio **pgpio)
852ea7249fSBen Skeggs {
86*01055c01SBen Skeggs return nvkm_gpio_new_(&gf119_gpio, device, type, inst, pgpio);
872ea7249fSBen Skeggs }
88