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 void
0027 gf119_gpio_reset(struct nvkm_gpio *gpio, u8 match)
0028 {
0029     struct nvkm_device *device = gpio->subdev.device;
0030     struct nvkm_bios *bios = device->bios;
0031     u8 ver, len;
0032     u16 entry;
0033     int ent = -1;
0034 
0035     while ((entry = dcb_gpio_entry(bios, 0, ++ent, &ver, &len))) {
0036         u32 data = nvbios_rd32(bios, entry);
0037         u8  line =   (data & 0x0000003f);
0038         u8  defs = !!(data & 0x00000080);
0039         u8  func =   (data & 0x0000ff00) >> 8;
0040         u8  unk0 =   (data & 0x00ff0000) >> 16;
0041         u8  unk1 =   (data & 0x1f000000) >> 24;
0042 
0043         if ( func  == DCB_GPIO_UNUSED ||
0044             (match != DCB_GPIO_UNUSED && match != func))
0045             continue;
0046 
0047         nvkm_gpio_set(gpio, 0, func, line, defs);
0048 
0049         nvkm_mask(device, 0x00d610 + (line * 4), 0xff, unk0);
0050         if (unk1--)
0051             nvkm_mask(device, 0x00d740 + (unk1 * 4), 0xff, line);
0052     }
0053 }
0054 
0055 int
0056 gf119_gpio_drive(struct nvkm_gpio *gpio, int line, int dir, int out)
0057 {
0058     struct nvkm_device *device = gpio->subdev.device;
0059     u32 data = ((dir ^ 1) << 13) | (out << 12);
0060     nvkm_mask(device, 0x00d610 + (line * 4), 0x00003000, data);
0061     nvkm_mask(device, 0x00d604, 0x00000001, 0x00000001); /* update? */
0062     return 0;
0063 }
0064 
0065 int
0066 gf119_gpio_sense(struct nvkm_gpio *gpio, int line)
0067 {
0068     struct nvkm_device *device = gpio->subdev.device;
0069     return !!(nvkm_rd32(device, 0x00d610 + (line * 4)) & 0x00004000);
0070 }
0071 
0072 static const struct nvkm_gpio_func
0073 gf119_gpio = {
0074     .lines = 32,
0075     .intr_stat = g94_gpio_intr_stat,
0076     .intr_mask = g94_gpio_intr_mask,
0077     .drive = gf119_gpio_drive,
0078     .sense = gf119_gpio_sense,
0079     .reset = gf119_gpio_reset,
0080 };
0081 
0082 int
0083 gf119_gpio_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0084            struct nvkm_gpio **pgpio)
0085 {
0086     return nvkm_gpio_new_(&gf119_gpio, device, type, inst, pgpio);
0087 }