2727
2828#define TEGRA186_GPIO_INT_ROUTE_MAPPING (p , x ) (0x14 + (p) * 0x20 + (x) * 4)
2929
30+ #define TEGRA186_GPIO_VM 0x00
31+ #define TEGRA186_GPIO_VM_RW_MASK 0x03
32+ #define TEGRA186_GPIO_SCR 0x04
33+ #define TEGRA186_GPIO_SCR_PIN_SIZE 0x08
34+ #define TEGRA186_GPIO_SCR_PORT_SIZE 0x40
35+ #define TEGRA186_GPIO_SCR_SEC_WEN BIT(28)
36+ #define TEGRA186_GPIO_SCR_SEC_REN BIT(27)
37+ #define TEGRA186_GPIO_SCR_SEC_G1W BIT(9)
38+ #define TEGRA186_GPIO_SCR_SEC_G1R BIT(1)
39+ #define TEGRA186_GPIO_FULL_ACCESS (TEGRA186_GPIO_SCR_SEC_WEN | \
40+ TEGRA186_GPIO_SCR_SEC_REN | \
41+ TEGRA186_GPIO_SCR_SEC_G1R | \
42+ TEGRA186_GPIO_SCR_SEC_G1W)
43+ #define TEGRA186_GPIO_SCR_SEC_ENABLE (TEGRA186_GPIO_SCR_SEC_WEN | \
44+ TEGRA186_GPIO_SCR_SEC_REN)
45+
3046/* control registers */
3147#define TEGRA186_GPIO_ENABLE_CONFIG 0x00
3248#define TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0)
@@ -81,6 +97,7 @@ struct tegra_gpio_soc {
8197 unsigned int num_pin_ranges ;
8298 const char * pinmux ;
8399 bool has_gte ;
100+ bool has_vm_support ;
84101};
85102
86103struct tegra_gpio {
@@ -130,6 +147,58 @@ static void __iomem *tegra186_gpio_get_base(struct tegra_gpio *gpio,
130147 return gpio -> base + offset + pin * 0x20 ;
131148}
132149
150+ static void __iomem * tegra186_gpio_get_secure_base (struct tegra_gpio * gpio ,
151+ unsigned int pin )
152+ {
153+ const struct tegra_gpio_port * port ;
154+ unsigned int offset ;
155+
156+ port = tegra186_gpio_get_port (gpio , & pin );
157+ if (!port )
158+ return NULL ;
159+
160+ offset = port -> bank * 0x1000 + port -> port * TEGRA186_GPIO_SCR_PORT_SIZE ;
161+
162+ return gpio -> secure + offset + pin * TEGRA186_GPIO_SCR_PIN_SIZE ;
163+ }
164+
165+ static inline bool tegra186_gpio_is_accessible (struct tegra_gpio * gpio , unsigned int pin )
166+ {
167+ void __iomem * secure ;
168+ u32 value ;
169+
170+ secure = tegra186_gpio_get_secure_base (gpio , pin );
171+
172+ if (gpio -> soc -> has_vm_support ) {
173+ value = readl (secure + TEGRA186_GPIO_VM );
174+ if ((value & TEGRA186_GPIO_VM_RW_MASK ) != TEGRA186_GPIO_VM_RW_MASK )
175+ return false;
176+ }
177+
178+ value = __raw_readl (secure + TEGRA186_GPIO_SCR );
179+
180+ if ((value & TEGRA186_GPIO_SCR_SEC_ENABLE ) == 0 )
181+ return true;
182+
183+ if ((value & TEGRA186_GPIO_FULL_ACCESS ) == TEGRA186_GPIO_FULL_ACCESS )
184+ return true;
185+
186+ return false;
187+ }
188+
189+ static int tegra186_init_valid_mask (struct gpio_chip * chip ,
190+ unsigned long * valid_mask , unsigned int ngpios )
191+ {
192+ struct tegra_gpio * gpio = gpiochip_get_data (chip );
193+ unsigned int j ;
194+
195+ for (j = 0 ; j < ngpios ; j ++ ) {
196+ if (!tegra186_gpio_is_accessible (gpio , j ))
197+ clear_bit (j , valid_mask );
198+ }
199+ return 0 ;
200+ }
201+
133202static int tegra186_gpio_get_direction (struct gpio_chip * chip ,
134203 unsigned int offset )
135204{
@@ -816,6 +885,7 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
816885 gpio -> gpio .set = tegra186_gpio_set ;
817886 gpio -> gpio .set_config = tegra186_gpio_set_config ;
818887 gpio -> gpio .add_pin_ranges = tegra186_gpio_add_pin_ranges ;
888+ gpio -> gpio .init_valid_mask = tegra186_init_valid_mask ;
819889 if (gpio -> soc -> has_gte ) {
820890 gpio -> gpio .en_hw_timestamp = tegra186_gpio_en_hw_ts ;
821891 gpio -> gpio .dis_hw_timestamp = tegra186_gpio_dis_hw_ts ;
@@ -962,6 +1032,7 @@ static const struct tegra_gpio_soc tegra186_main_soc = {
9621032 .name = "tegra186-gpio" ,
9631033 .instance = 0 ,
9641034 .num_irqs_per_bank = 1 ,
1035+ .has_vm_support = false,
9651036};
9661037
9671038#define TEGRA186_AON_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -989,6 +1060,7 @@ static const struct tegra_gpio_soc tegra186_aon_soc = {
9891060 .name = "tegra186-gpio-aon" ,
9901061 .instance = 1 ,
9911062 .num_irqs_per_bank = 1 ,
1063+ .has_vm_support = false,
9921064};
9931065
9941066#define TEGRA194_MAIN_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -1044,6 +1116,7 @@ static const struct tegra_gpio_soc tegra194_main_soc = {
10441116 .num_pin_ranges = ARRAY_SIZE (tegra194_main_pin_ranges ),
10451117 .pin_ranges = tegra194_main_pin_ranges ,
10461118 .pinmux = "nvidia,tegra194-pinmux" ,
1119+ .has_vm_support = true,
10471120};
10481121
10491122#define TEGRA194_AON_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -1069,6 +1142,7 @@ static const struct tegra_gpio_soc tegra194_aon_soc = {
10691142 .instance = 1 ,
10701143 .num_irqs_per_bank = 8 ,
10711144 .has_gte = true,
1145+ .has_vm_support = false,
10721146};
10731147
10741148#define TEGRA234_MAIN_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -1113,6 +1187,7 @@ static const struct tegra_gpio_soc tegra234_main_soc = {
11131187 .name = "tegra234-gpio" ,
11141188 .instance = 0 ,
11151189 .num_irqs_per_bank = 8 ,
1190+ .has_vm_support = true,
11161191};
11171192
11181193#define TEGRA234_AON_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -1139,6 +1214,7 @@ static const struct tegra_gpio_soc tegra234_aon_soc = {
11391214 .instance = 1 ,
11401215 .num_irqs_per_bank = 8 ,
11411216 .has_gte = true,
1217+ .has_vm_support = false,
11421218};
11431219
11441220#define TEGRA241_MAIN_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -1169,6 +1245,7 @@ static const struct tegra_gpio_soc tegra241_main_soc = {
11691245 .name = "tegra241-gpio" ,
11701246 .instance = 0 ,
11711247 .num_irqs_per_bank = 8 ,
1248+ .has_vm_support = false,
11721249};
11731250
11741251#define TEGRA241_AON_GPIO_PORT (_name , _bank , _port , _pins ) \
@@ -1190,6 +1267,7 @@ static const struct tegra_gpio_soc tegra241_aon_soc = {
11901267 .name = "tegra241-gpio-aon" ,
11911268 .instance = 1 ,
11921269 .num_irqs_per_bank = 8 ,
1270+ .has_vm_support = false,
11931271};
11941272
11951273static const struct of_device_id tegra186_gpio_of_match [] = {
0 commit comments