Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2021 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 #include "priv.h"
0023 
0024 static void
0025 ga102_gpio_reset(struct nvkm_gpio *gpio, u8 match)
0026 {
0027     struct nvkm_device *device = gpio->subdev.device;
0028     struct nvkm_bios *bios = device->bios;
0029     u8 ver, len;
0030     u16 entry;
0031     int ent = -1;
0032 
0033     while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver, &len))) {
0034         u32 data = nvbios_rd32(bios, entry);
0035         u8  line =   (data & 0x0000003f);
0036         u8  defs = !!(data & 0x00000080);
0037         u8  func =   (data & 0x0000ff00) >> 8;
0038         u8  unk0 =   (data & 0x00ff0000) >> 16;
0039         u8  unk1 =   (data & 0x1f000000) >> 24;
0040 
0041         if ( func  == DCB_GPIO_UNUSED ||
0042             (match != DCB_GPIO_UNUSED && match != func))
0043             continue;
0044 
0045         nvkm_gpio_set(gpio, 0, func, line, defs);
0046 
0047         nvkm_mask(device, 0x021200 + (line * 4), 0xff, unk0);
0048         if (unk1--)
0049             nvkm_mask(device, 0x00d740 + (unk1 * 4), 0xff, line);
0050     }
0051 }
0052 
0053 static int
0054 ga102_gpio_drive(struct nvkm_gpio *gpio, int line, int dir, int out)
0055 {
0056     struct nvkm_device *device = gpio->subdev.device;
0057     u32 data = ((dir ^ 1) << 13) | (out << 12);
0058     nvkm_mask(device, 0x021200 + (line * 4), 0x00003000, data);
0059     nvkm_mask(device, 0x00d604, 0x00000001, 0x00000001); /* update? */
0060     return 0;
0061 }
0062 
0063 static int
0064 ga102_gpio_sense(struct nvkm_gpio *gpio, int line)
0065 {
0066     struct nvkm_device *device = gpio->subdev.device;
0067     return !!(nvkm_rd32(device, 0x021200 + (line * 4)) & 0x00004000);
0068 }
0069 
0070 static void
0071 ga102_gpio_intr_stat(struct nvkm_gpio *gpio, u32 *hi, u32 *lo)
0072 {
0073     struct nvkm_device *device = gpio->subdev.device;
0074     u32 intr0 = nvkm_rd32(device, 0x021640);
0075     u32 intr1 = nvkm_rd32(device, 0x02164c);
0076     u32 stat0 = nvkm_rd32(device, 0x021648) & intr0;
0077     u32 stat1 = nvkm_rd32(device, 0x021654) & intr1;
0078     *lo = (stat1 & 0xffff0000) | (stat0 >> 16);
0079     *hi = (stat1 << 16) | (stat0 & 0x0000ffff);
0080     nvkm_wr32(device, 0x021640, intr0);
0081     nvkm_wr32(device, 0x02164c, intr1);
0082 }
0083 
0084 static void
0085 ga102_gpio_intr_mask(struct nvkm_gpio *gpio, u32 type, u32 mask, u32 data)
0086 {
0087     struct nvkm_device *device = gpio->subdev.device;
0088     u32 inte0 = nvkm_rd32(device, 0x021648);
0089     u32 inte1 = nvkm_rd32(device, 0x021654);
0090     if (type & NVKM_GPIO_LO)
0091         inte0 = (inte0 & ~(mask << 16)) | (data << 16);
0092     if (type & NVKM_GPIO_HI)
0093         inte0 = (inte0 & ~(mask & 0xffff)) | (data & 0xffff);
0094     mask >>= 16;
0095     data >>= 16;
0096     if (type & NVKM_GPIO_LO)
0097         inte1 = (inte1 & ~(mask << 16)) | (data << 16);
0098     if (type & NVKM_GPIO_HI)
0099         inte1 = (inte1 & ~mask) | data;
0100     nvkm_wr32(device, 0x021648, inte0);
0101     nvkm_wr32(device, 0x021654, inte1);
0102 }
0103 
0104 static const struct nvkm_gpio_func
0105 ga102_gpio = {
0106     .lines = 32,
0107     .intr_stat = ga102_gpio_intr_stat,
0108     .intr_mask = ga102_gpio_intr_mask,
0109     .drive = ga102_gpio_drive,
0110     .sense = ga102_gpio_sense,
0111     .reset = ga102_gpio_reset,
0112 };
0113 
0114 int
0115 ga102_gpio_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0116            struct nvkm_gpio **pgpio)
0117 {
0118     return nvkm_gpio_new_(&ga102_gpio, device, type, inst, pgpio);
0119 }