blob: 34e0196fb97f013e0025c986647d3e3b724387da [file] [log] [blame]
Lee Leahy32471722015-04-20 15:20:28 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Intel Corp.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Lee Leahy32471722015-04-20 15:20:28 -070014 */
15
16#include <console/console.h>
17#include <soc/gpio.h>
18
19/*
20 * Return family number and internal pad number in that community by pad number
21 * and which community it is in.
22 */
23uint16_t gpio_family_number(uint8_t community, uint8_t pad)
24{
25 /*
26 * Refer to BSW BIOS Writers Guide, Table "Family Number".
27 * BSW has 4 GPIO communities. Each community has up to 7 families and
28 * each family contains a range of Pad numbers. The number in the array
29 * is the maximum no. of that range.
30 * For example: East community, family 0, Pad 0~11.
31 */
32 static const uint8_t community_base[GPIO_COMMUNITY_COUNT]
33 [GPIO_FAMILIES_MAX_PER_COMM + 1] = {
34 {0, 8, 16, 24, 32, 40, 48, 56}, /* Southwest */
35 {0, 9, 22, 34, 46, 59, 59, 59}, /* North */
36 {0, 12, 24, 24, 24, 24, 24, 24}, /* East */
37 {0, 8, 20, 26, 34, 44, 55, 55} /* Southeast */
38 };
39 const uint8_t *base;
40 uint8_t i;
41
42 /* Validate the pad number */
43 if (pad > community_base[community][7])
44 die("Pad number is out of range!");
45
46 /* Locate the family number for the pad */
47 base = &community_base[community][0];
48 for (i = 0; i < 7; i++) {
49 if ((pad >= base[0]) && (pad < base[1]))
50 break;
51 base++;
52 }
53
54 /* Family number in high byte and inner pad number in lowest byte */
55 return (i << 8) + pad - *base;
56}
57
58/*
59 * Return pad configuration register offset by pad number and which community
60 * it is in.
61 */
62uint32_t *gpio_pad_config_reg(uint8_t community, uint8_t pad)
63{
64 uint16_t fpad;
65 uint32_t *pad_config_reg;
66
67 /* Get the GPIO family number */
68 fpad = gpio_family_number(community, pad);
69
70 /*
71 * Refer to BSW BIOS Writers Guide, Table "Per Pad Memory Space
72 * Registers Addresses" for the Pad configuration register calculation.
73 */
74 pad_config_reg = (uint32_t *)(COMMUNITY_BASE(community) + 0x4400 +
75 (0x400 * (fpad >> 8)) + (8 * (fpad & 0xff)));
76
77 return pad_config_reg;
78}
79
80int get_gpio(int community_base, int pad0_offset)
81{
82 return (read32((void *)(community_base + pad0_offset))) & PAD_RX_BIT;
83}