81 lines · c
1/*2 * Copyright 2012 Red Hat Inc.3 *4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"),6 * to deal in the Software without restriction, including without limitation7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,8 * and/or sell copies of the Software, and to permit persons to whom the9 * Software is furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR18 * 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 OR20 * OTHER DEALINGS IN THE SOFTWARE.21 *22 * Authors: Ben Skeggs23 */24#include "priv.h"25 26#include <subdev/gsp.h>27 28static void29gk104_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)30{31 struct nvkm_device *device = gpio->subdev.device;32 u32 intr0 = nvkm_rd32(device, 0x00dc00);33 u32 intr1 = nvkm_rd32(device, 0x00dc80);34 u32 stat0 = nvkm_rd32(device, 0x00dc08) & intr0;35 u32 stat1 = nvkm_rd32(device, 0x00dc88) & intr1;36 *lo = (stat1 & 0xffff0000) | (stat0 >> 16);37 *hi = (stat1 << 16) | (stat0 & 0x0000ffff);38 nvkm_wr32(device, 0x00dc00, intr0);39 nvkm_wr32(device, 0x00dc80, intr1);40}41 42static void43gk104_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)44{45 struct nvkm_device *device = gpio->subdev.device;46 u32 inte0 = nvkm_rd32(device, 0x00dc08);47 u32 inte1 = nvkm_rd32(device, 0x00dc88);48 if (type & NVKM_GPIO_LO)49 inte0 = (inte0 & ~(mask << 16)) | (data << 16);50 if (type & NVKM_GPIO_HI)51 inte0 = (inte0 & ~(mask & 0xffff)) | (data & 0xffff);52 mask >>= 16;53 data >>= 16;54 if (type & NVKM_GPIO_LO)55 inte1 = (inte1 & ~(mask << 16)) | (data << 16);56 if (type & NVKM_GPIO_HI)57 inte1 = (inte1 & ~mask) | data;58 nvkm_wr32(device, 0x00dc08, inte0);59 nvkm_wr32(device, 0x00dc88, inte1);60}61 62static const struct nvkm_gpio_func63gk104_gpio = {64 .lines = 32,65 .intr_stat = gk104_gpio_intr_stat,66 .intr_mask = gk104_gpio_intr_mask,67 .drive = gf119_gpio_drive,68 .sense = gf119_gpio_sense,69 .reset = gf119_gpio_reset,70};71 72int73gk104_gpio_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,74 struct nvkm_gpio **pgpio)75{76 if (nvkm_gsp_rm(device->gsp))77 return -ENODEV;78 79 return nvkm_gpio_new_(&gk104_gpio, device, type, inst, pgpio);80}81