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 <subdev/bios.h>
0025 #include <subdev/bios/gpio.h>
0026 #include <subdev/bios/xpio.h>
0027 
0028 static u16
0029 dcb_xpiod_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
0030 {
0031     u16 data = dcb_gpio_table(bios, ver, hdr, cnt, len);
0032     if (data && *ver >= 0x40 && *hdr >= 0x06) {
0033         u16 xpio = nvbios_rd16(bios, data + 0x04);
0034         if (xpio) {
0035             *ver = nvbios_rd08(bios, data + 0x00);
0036             *hdr = nvbios_rd08(bios, data + 0x01);
0037             *cnt = nvbios_rd08(bios, data + 0x02);
0038             *len = nvbios_rd08(bios, data + 0x03);
0039             return xpio;
0040         }
0041     }
0042     return 0x0000;
0043 }
0044 
0045 u16
0046 dcb_xpio_table(struct nvkm_bios *bios, u8 idx,
0047            u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
0048 {
0049     u16 data = dcb_xpiod_table(bios, ver, hdr, cnt, len);
0050     if (data && idx < *cnt) {
0051         u16 xpio = nvbios_rd16(bios, data + *hdr + (idx * *len));
0052         if (xpio) {
0053             *ver = nvbios_rd08(bios, data + 0x00);
0054             *hdr = nvbios_rd08(bios, data + 0x01);
0055             *cnt = nvbios_rd08(bios, data + 0x02);
0056             *len = nvbios_rd08(bios, data + 0x03);
0057             return xpio;
0058         }
0059     }
0060     return 0x0000;
0061 }
0062 
0063 u16
0064 dcb_xpio_parse(struct nvkm_bios *bios, u8 idx,
0065            u8 *ver, u8 *hdr, u8 *cnt, u8 *len, struct nvbios_xpio *info)
0066 {
0067     u16 data = dcb_xpio_table(bios, idx, ver, hdr, cnt, len);
0068     if (data && *len >= 6) {
0069         info->type = nvbios_rd08(bios, data + 0x04);
0070         info->addr = nvbios_rd08(bios, data + 0x05);
0071         info->flags = nvbios_rd08(bios, data + 0x06);
0072     }
0073     return 0x0000;
0074 }