Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs
0023  */
0024 #include "priv.h"
0025 
0026 static void
0027 gk104_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)
0028 {
0029     struct nvkm_device *device = gpio->subdev.device;
0030     u32 intr0 = nvkm_rd32(device, 0x00dc00);
0031     u32 intr1 = nvkm_rd32(device, 0x00dc80);
0032     u32 stat0 = nvkm_rd32(device, 0x00dc08) & intr0;
0033     u32 stat1 = nvkm_rd32(device, 0x00dc88) & intr1;
0034     *lo = (stat1 & 0xffff0000) | (stat0 >> 16);
0035     *hi = (stat1 << 16) | (stat0 & 0x0000ffff);
0036     nvkm_wr32(device, 0x00dc00, intr0);
0037     nvkm_wr32(device, 0x00dc80, intr1);
0038 }
0039 
0040 static void
0041 gk104_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)
0042 {
0043     struct nvkm_device *device = gpio->subdev.device;
0044     u32 inte0 = nvkm_rd32(device, 0x00dc08);
0045     u32 inte1 = nvkm_rd32(device, 0x00dc88);
0046     if (type & NVKM_GPIO_LO)
0047         inte0 = (inte0 & ~(mask << 16)) | (data << 16);
0048     if (type & NVKM_GPIO_HI)
0049         inte0 = (inte0 & ~(mask & 0xffff)) | (data & 0xffff);
0050     mask >>= 16;
0051     data >>= 16;
0052     if (type & NVKM_GPIO_LO)
0053         inte1 = (inte1 & ~(mask << 16)) | (data << 16);
0054     if (type & NVKM_GPIO_HI)
0055         inte1 = (inte1 & ~mask) | data;
0056     nvkm_wr32(device, 0x00dc08, inte0);
0057     nvkm_wr32(device, 0x00dc88, inte1);
0058 }
0059 
0060 static const struct nvkm_gpio_func
0061 gk104_gpio = {
0062     .lines = 32,
0063     .intr_stat = gk104_gpio_intr_stat,
0064     .intr_mask = gk104_gpio_intr_mask,
0065     .drive = gf119_gpio_drive,
0066     .sense = gf119_gpio_sense,
0067     .reset = gf119_gpio_reset,
0068 };
0069 
0070 int
0071 gk104_gpio_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0072            struct nvkm_gpio **pgpio)
0073 {
0074     return nvkm_gpio_new_(&gk104_gpio, device, type, inst, pgpio);
0075 }