gpio-tegra186.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2022 NVIDIA Corporation
  4. *
  5. * Author: Thierry Reding <treding@nvidia.com>
  6. * Dipen Patel <dpatel@nvidia.com>
  7. */
  8. #include <linux/gpio/driver.h>
  9. #include <linux/hte.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/irq.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/property.h>
  16. #include <linux/seq_file.h>
  17. #include <dt-bindings/gpio/tegra186-gpio.h>
  18. #include <dt-bindings/gpio/tegra194-gpio.h>
  19. #include <dt-bindings/gpio/tegra234-gpio.h>
  20. #include <dt-bindings/gpio/tegra241-gpio.h>
  21. /* security registers */
  22. #define TEGRA186_GPIO_CTL_SCR 0x0c
  23. #define TEGRA186_GPIO_CTL_SCR_SEC_WEN BIT(28)
  24. #define TEGRA186_GPIO_CTL_SCR_SEC_REN BIT(27)
  25. #define TEGRA186_GPIO_INT_ROUTE_MAPPING(p, x) (0x14 + (p) * 0x20 + (x) * 4)
  26. #define TEGRA186_GPIO_VM 0x00
  27. #define TEGRA186_GPIO_VM_RW_MASK 0x03
  28. #define TEGRA186_GPIO_SCR 0x04
  29. #define TEGRA186_GPIO_SCR_PIN_SIZE 0x08
  30. #define TEGRA186_GPIO_SCR_PORT_SIZE 0x40
  31. #define TEGRA186_GPIO_SCR_SEC_WEN BIT(28)
  32. #define TEGRA186_GPIO_SCR_SEC_REN BIT(27)
  33. #define TEGRA186_GPIO_SCR_SEC_G1W BIT(9)
  34. #define TEGRA186_GPIO_SCR_SEC_G1R BIT(1)
  35. /* control registers */
  36. #define TEGRA186_GPIO_ENABLE_CONFIG 0x00
  37. #define TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0)
  38. #define TEGRA186_GPIO_ENABLE_CONFIG_OUT BIT(1)
  39. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_NONE (0x0 << 2)
  40. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL (0x1 << 2)
  41. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE (0x2 << 2)
  42. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE (0x3 << 2)
  43. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK (0x3 << 2)
  44. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL BIT(4)
  45. #define TEGRA186_GPIO_ENABLE_CONFIG_DEBOUNCE BIT(5)
  46. #define TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT BIT(6)
  47. #define TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC BIT(7)
  48. #define TEGRA186_GPIO_DEBOUNCE_CONTROL 0x04
  49. #define TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD(x) ((x) & 0xff)
  50. #define TEGRA186_GPIO_INPUT 0x08
  51. #define TEGRA186_GPIO_INPUT_HIGH BIT(0)
  52. #define TEGRA186_GPIO_OUTPUT_CONTROL 0x0c
  53. #define TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED BIT(0)
  54. #define TEGRA186_GPIO_OUTPUT_VALUE 0x10
  55. #define TEGRA186_GPIO_OUTPUT_VALUE_HIGH BIT(0)
  56. #define TEGRA186_GPIO_INTERRUPT_CLEAR 0x14
  57. #define TEGRA186_GPIO_INTERRUPT_STATUS(x) (0x100 + (x) * 4)
  58. struct tegra_gpio_port {
  59. const char *name;
  60. unsigned int bank;
  61. unsigned int port;
  62. unsigned int pins;
  63. };
  64. struct tegra186_pin_range {
  65. unsigned int offset;
  66. const char *group;
  67. };
  68. struct tegra_gpio_soc {
  69. const struct tegra_gpio_port *ports;
  70. unsigned int num_ports;
  71. const char *name;
  72. unsigned int instance;
  73. unsigned int num_irqs_per_bank;
  74. const struct tegra186_pin_range *pin_ranges;
  75. unsigned int num_pin_ranges;
  76. const char *pinmux;
  77. bool has_gte;
  78. bool has_vm_support;
  79. };
  80. struct tegra_gpio {
  81. struct gpio_chip gpio;
  82. unsigned int num_irq;
  83. unsigned int *irq;
  84. const struct tegra_gpio_soc *soc;
  85. unsigned int num_irqs_per_bank;
  86. unsigned int num_banks;
  87. void __iomem *secure;
  88. void __iomem *base;
  89. };
  90. static const struct tegra_gpio_port *
  91. tegra186_gpio_get_port(struct tegra_gpio *gpio, unsigned int *pin)
  92. {
  93. unsigned int start = 0, i;
  94. for (i = 0; i < gpio->soc->num_ports; i++) {
  95. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  96. if (*pin >= start && *pin < start + port->pins) {
  97. *pin -= start;
  98. return port;
  99. }
  100. start += port->pins;
  101. }
  102. return NULL;
  103. }
  104. static void __iomem *tegra186_gpio_get_base(struct tegra_gpio *gpio,
  105. unsigned int pin)
  106. {
  107. const struct tegra_gpio_port *port;
  108. unsigned int offset;
  109. port = tegra186_gpio_get_port(gpio, &pin);
  110. if (!port)
  111. return NULL;
  112. offset = port->bank * 0x1000 + port->port * 0x200;
  113. return gpio->base + offset + pin * 0x20;
  114. }
  115. static void __iomem *tegra186_gpio_get_secure_base(struct tegra_gpio *gpio,
  116. unsigned int pin)
  117. {
  118. const struct tegra_gpio_port *port;
  119. unsigned int offset;
  120. port = tegra186_gpio_get_port(gpio, &pin);
  121. if (!port)
  122. return NULL;
  123. offset = port->bank * 0x1000 + port->port * TEGRA186_GPIO_SCR_PORT_SIZE;
  124. return gpio->secure + offset + pin * TEGRA186_GPIO_SCR_PIN_SIZE;
  125. }
  126. static inline bool tegra186_gpio_is_accessible(struct tegra_gpio *gpio, unsigned int pin)
  127. {
  128. void __iomem *secure;
  129. u32 value;
  130. secure = tegra186_gpio_get_secure_base(gpio, pin);
  131. if (gpio->soc->has_vm_support) {
  132. value = readl(secure + TEGRA186_GPIO_VM);
  133. if ((value & TEGRA186_GPIO_VM_RW_MASK) != TEGRA186_GPIO_VM_RW_MASK)
  134. return false;
  135. }
  136. value = __raw_readl(secure + TEGRA186_GPIO_SCR);
  137. /*
  138. * When SCR_SEC_[R|W]EN is unset, then we have full read/write access to all the
  139. * registers for given GPIO pin.
  140. * When SCR_SEC[R|W]EN is set, then there is need to further check the accompanying
  141. * SCR_SEC_G1[R|W] bit to determine read/write access to all the registers for given
  142. * GPIO pin.
  143. */
  144. if (((value & TEGRA186_GPIO_SCR_SEC_REN) == 0 ||
  145. ((value & TEGRA186_GPIO_SCR_SEC_REN) && (value & TEGRA186_GPIO_SCR_SEC_G1R))) &&
  146. ((value & TEGRA186_GPIO_SCR_SEC_WEN) == 0 ||
  147. ((value & TEGRA186_GPIO_SCR_SEC_WEN) && (value & TEGRA186_GPIO_SCR_SEC_G1W))))
  148. return true;
  149. return false;
  150. }
  151. static int tegra186_init_valid_mask(struct gpio_chip *chip,
  152. unsigned long *valid_mask, unsigned int ngpios)
  153. {
  154. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  155. unsigned int j;
  156. for (j = 0; j < ngpios; j++) {
  157. if (!tegra186_gpio_is_accessible(gpio, j))
  158. clear_bit(j, valid_mask);
  159. }
  160. return 0;
  161. }
  162. static int tegra186_gpio_get_direction(struct gpio_chip *chip,
  163. unsigned int offset)
  164. {
  165. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  166. void __iomem *base;
  167. u32 value;
  168. base = tegra186_gpio_get_base(gpio, offset);
  169. if (WARN_ON(base == NULL))
  170. return -ENODEV;
  171. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  172. if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
  173. return GPIO_LINE_DIRECTION_OUT;
  174. return GPIO_LINE_DIRECTION_IN;
  175. }
  176. static int tegra186_gpio_direction_input(struct gpio_chip *chip,
  177. unsigned int offset)
  178. {
  179. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  180. void __iomem *base;
  181. u32 value;
  182. base = tegra186_gpio_get_base(gpio, offset);
  183. if (WARN_ON(base == NULL))
  184. return -ENODEV;
  185. value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
  186. value |= TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
  187. writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
  188. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  189. value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
  190. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_OUT;
  191. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  192. return 0;
  193. }
  194. static int tegra186_gpio_direction_output(struct gpio_chip *chip,
  195. unsigned int offset, int level)
  196. {
  197. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  198. void __iomem *base;
  199. u32 value;
  200. /* configure output level first */
  201. chip->set(chip, offset, level);
  202. base = tegra186_gpio_get_base(gpio, offset);
  203. if (WARN_ON(base == NULL))
  204. return -EINVAL;
  205. /* set the direction */
  206. value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
  207. value &= ~TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
  208. writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
  209. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  210. value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
  211. value |= TEGRA186_GPIO_ENABLE_CONFIG_OUT;
  212. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  213. return 0;
  214. }
  215. #define HTE_BOTH_EDGES (HTE_RISING_EDGE_TS | HTE_FALLING_EDGE_TS)
  216. static int tegra186_gpio_en_hw_ts(struct gpio_chip *gc, u32 offset,
  217. unsigned long flags)
  218. {
  219. struct tegra_gpio *gpio;
  220. void __iomem *base;
  221. int value;
  222. if (!gc)
  223. return -EINVAL;
  224. gpio = gpiochip_get_data(gc);
  225. if (!gpio)
  226. return -ENODEV;
  227. base = tegra186_gpio_get_base(gpio, offset);
  228. if (WARN_ON(base == NULL))
  229. return -EINVAL;
  230. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  231. value |= TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC;
  232. if (flags == HTE_BOTH_EDGES) {
  233. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
  234. } else if (flags == HTE_RISING_EDGE_TS) {
  235. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  236. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  237. } else if (flags == HTE_FALLING_EDGE_TS) {
  238. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  239. }
  240. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  241. return 0;
  242. }
  243. static int tegra186_gpio_dis_hw_ts(struct gpio_chip *gc, u32 offset,
  244. unsigned long flags)
  245. {
  246. struct tegra_gpio *gpio;
  247. void __iomem *base;
  248. int value;
  249. if (!gc)
  250. return -EINVAL;
  251. gpio = gpiochip_get_data(gc);
  252. if (!gpio)
  253. return -ENODEV;
  254. base = tegra186_gpio_get_base(gpio, offset);
  255. if (WARN_ON(base == NULL))
  256. return -EINVAL;
  257. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  258. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC;
  259. if (flags == HTE_BOTH_EDGES) {
  260. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
  261. } else if (flags == HTE_RISING_EDGE_TS) {
  262. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  263. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  264. } else if (flags == HTE_FALLING_EDGE_TS) {
  265. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  266. }
  267. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  268. return 0;
  269. }
  270. static int tegra186_gpio_get(struct gpio_chip *chip, unsigned int offset)
  271. {
  272. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  273. void __iomem *base;
  274. u32 value;
  275. base = tegra186_gpio_get_base(gpio, offset);
  276. if (WARN_ON(base == NULL))
  277. return -ENODEV;
  278. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  279. if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
  280. value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
  281. else
  282. value = readl(base + TEGRA186_GPIO_INPUT);
  283. return value & BIT(0);
  284. }
  285. static void tegra186_gpio_set(struct gpio_chip *chip, unsigned int offset,
  286. int level)
  287. {
  288. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  289. void __iomem *base;
  290. u32 value;
  291. base = tegra186_gpio_get_base(gpio, offset);
  292. if (WARN_ON(base == NULL))
  293. return;
  294. value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
  295. if (level == 0)
  296. value &= ~TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
  297. else
  298. value |= TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
  299. writel(value, base + TEGRA186_GPIO_OUTPUT_VALUE);
  300. }
  301. static int tegra186_gpio_set_config(struct gpio_chip *chip,
  302. unsigned int offset,
  303. unsigned long config)
  304. {
  305. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  306. u32 debounce, value;
  307. void __iomem *base;
  308. base = tegra186_gpio_get_base(gpio, offset);
  309. if (base == NULL)
  310. return -ENXIO;
  311. if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
  312. return -ENOTSUPP;
  313. debounce = pinconf_to_config_argument(config);
  314. /*
  315. * The Tegra186 GPIO controller supports a maximum of 255 ms debounce
  316. * time.
  317. */
  318. if (debounce > 255000)
  319. return -EINVAL;
  320. debounce = DIV_ROUND_UP(debounce, USEC_PER_MSEC);
  321. value = TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD(debounce);
  322. writel(value, base + TEGRA186_GPIO_DEBOUNCE_CONTROL);
  323. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  324. value |= TEGRA186_GPIO_ENABLE_CONFIG_DEBOUNCE;
  325. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  326. return 0;
  327. }
  328. static int tegra186_gpio_add_pin_ranges(struct gpio_chip *chip)
  329. {
  330. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  331. struct pinctrl_dev *pctldev;
  332. struct device_node *np;
  333. unsigned int i, j;
  334. int err;
  335. if (!gpio->soc->pinmux || gpio->soc->num_pin_ranges == 0)
  336. return 0;
  337. np = of_find_compatible_node(NULL, NULL, gpio->soc->pinmux);
  338. if (!np)
  339. return -ENODEV;
  340. pctldev = of_pinctrl_get(np);
  341. of_node_put(np);
  342. if (!pctldev)
  343. return -EPROBE_DEFER;
  344. for (i = 0; i < gpio->soc->num_pin_ranges; i++) {
  345. unsigned int pin = gpio->soc->pin_ranges[i].offset, port;
  346. const char *group = gpio->soc->pin_ranges[i].group;
  347. port = pin / 8;
  348. pin = pin % 8;
  349. if (port >= gpio->soc->num_ports) {
  350. dev_warn(chip->parent, "invalid port %u for %s\n",
  351. port, group);
  352. continue;
  353. }
  354. for (j = 0; j < port; j++)
  355. pin += gpio->soc->ports[j].pins;
  356. err = gpiochip_add_pingroup_range(chip, pctldev, pin, group);
  357. if (err < 0)
  358. return err;
  359. }
  360. return 0;
  361. }
  362. static int tegra186_gpio_of_xlate(struct gpio_chip *chip,
  363. const struct of_phandle_args *spec,
  364. u32 *flags)
  365. {
  366. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  367. unsigned int port, pin, i, offset = 0;
  368. if (WARN_ON(chip->of_gpio_n_cells < 2))
  369. return -EINVAL;
  370. if (WARN_ON(spec->args_count < chip->of_gpio_n_cells))
  371. return -EINVAL;
  372. port = spec->args[0] / 8;
  373. pin = spec->args[0] % 8;
  374. if (port >= gpio->soc->num_ports) {
  375. dev_err(chip->parent, "invalid port number: %u\n", port);
  376. return -EINVAL;
  377. }
  378. for (i = 0; i < port; i++)
  379. offset += gpio->soc->ports[i].pins;
  380. if (flags)
  381. *flags = spec->args[1];
  382. return offset + pin;
  383. }
  384. #define to_tegra_gpio(x) container_of((x), struct tegra_gpio, gpio)
  385. static void tegra186_irq_ack(struct irq_data *data)
  386. {
  387. struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
  388. struct tegra_gpio *gpio = to_tegra_gpio(gc);
  389. void __iomem *base;
  390. base = tegra186_gpio_get_base(gpio, data->hwirq);
  391. if (WARN_ON(base == NULL))
  392. return;
  393. writel(1, base + TEGRA186_GPIO_INTERRUPT_CLEAR);
  394. }
  395. static void tegra186_irq_mask(struct irq_data *data)
  396. {
  397. struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
  398. struct tegra_gpio *gpio = to_tegra_gpio(gc);
  399. void __iomem *base;
  400. u32 value;
  401. base = tegra186_gpio_get_base(gpio, data->hwirq);
  402. if (WARN_ON(base == NULL))
  403. return;
  404. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  405. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
  406. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  407. gpiochip_disable_irq(&gpio->gpio, data->hwirq);
  408. }
  409. static void tegra186_irq_unmask(struct irq_data *data)
  410. {
  411. struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
  412. struct tegra_gpio *gpio = to_tegra_gpio(gc);
  413. void __iomem *base;
  414. u32 value;
  415. base = tegra186_gpio_get_base(gpio, data->hwirq);
  416. if (WARN_ON(base == NULL))
  417. return;
  418. gpiochip_enable_irq(&gpio->gpio, data->hwirq);
  419. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  420. value |= TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
  421. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  422. }
  423. static int tegra186_irq_set_type(struct irq_data *data, unsigned int type)
  424. {
  425. struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
  426. struct tegra_gpio *gpio = to_tegra_gpio(gc);
  427. void __iomem *base;
  428. u32 value;
  429. base = tegra186_gpio_get_base(gpio, data->hwirq);
  430. if (WARN_ON(base == NULL))
  431. return -ENODEV;
  432. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  433. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK;
  434. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  435. switch (type & IRQ_TYPE_SENSE_MASK) {
  436. case IRQ_TYPE_NONE:
  437. break;
  438. case IRQ_TYPE_EDGE_RISING:
  439. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  440. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  441. break;
  442. case IRQ_TYPE_EDGE_FALLING:
  443. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  444. break;
  445. case IRQ_TYPE_EDGE_BOTH:
  446. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
  447. break;
  448. case IRQ_TYPE_LEVEL_HIGH:
  449. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
  450. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  451. break;
  452. case IRQ_TYPE_LEVEL_LOW:
  453. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
  454. break;
  455. default:
  456. return -EINVAL;
  457. }
  458. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  459. if ((type & IRQ_TYPE_EDGE_BOTH) == 0)
  460. irq_set_handler_locked(data, handle_level_irq);
  461. else
  462. irq_set_handler_locked(data, handle_edge_irq);
  463. if (data->parent_data)
  464. return irq_chip_set_type_parent(data, type);
  465. return 0;
  466. }
  467. static int tegra186_irq_set_wake(struct irq_data *data, unsigned int on)
  468. {
  469. if (data->parent_data)
  470. return irq_chip_set_wake_parent(data, on);
  471. return 0;
  472. }
  473. static void tegra186_irq_print_chip(struct irq_data *data, struct seq_file *p)
  474. {
  475. struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
  476. seq_printf(p, dev_name(gc->parent));
  477. }
  478. static const struct irq_chip tegra186_gpio_irq_chip = {
  479. .irq_ack = tegra186_irq_ack,
  480. .irq_mask = tegra186_irq_mask,
  481. .irq_unmask = tegra186_irq_unmask,
  482. .irq_set_type = tegra186_irq_set_type,
  483. .irq_set_wake = tegra186_irq_set_wake,
  484. .irq_print_chip = tegra186_irq_print_chip,
  485. .flags = IRQCHIP_IMMUTABLE,
  486. GPIOCHIP_IRQ_RESOURCE_HELPERS,
  487. };
  488. static void tegra186_gpio_irq(struct irq_desc *desc)
  489. {
  490. struct tegra_gpio *gpio = irq_desc_get_handler_data(desc);
  491. struct irq_domain *domain = gpio->gpio.irq.domain;
  492. struct irq_chip *chip = irq_desc_get_chip(desc);
  493. unsigned int parent = irq_desc_get_irq(desc);
  494. unsigned int i, j, offset = 0;
  495. chained_irq_enter(chip, desc);
  496. for (i = 0; i < gpio->soc->num_ports; i++) {
  497. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  498. unsigned int pin;
  499. unsigned long value;
  500. void __iomem *base;
  501. base = gpio->base + port->bank * 0x1000 + port->port * 0x200;
  502. /* skip ports that are not associated with this bank */
  503. for (j = 0; j < gpio->num_irqs_per_bank; j++) {
  504. if (parent == gpio->irq[port->bank * gpio->num_irqs_per_bank + j])
  505. break;
  506. }
  507. if (j == gpio->num_irqs_per_bank)
  508. goto skip;
  509. value = readl(base + TEGRA186_GPIO_INTERRUPT_STATUS(1));
  510. for_each_set_bit(pin, &value, port->pins) {
  511. int ret = generic_handle_domain_irq(domain, offset + pin);
  512. WARN_RATELIMIT(ret, "hwirq = %d", offset + pin);
  513. }
  514. skip:
  515. offset += port->pins;
  516. }
  517. chained_irq_exit(chip, desc);
  518. }
  519. static int tegra186_gpio_irq_domain_translate(struct irq_domain *domain,
  520. struct irq_fwspec *fwspec,
  521. unsigned long *hwirq,
  522. unsigned int *type)
  523. {
  524. struct tegra_gpio *gpio = gpiochip_get_data(domain->host_data);
  525. unsigned int port, pin, i, offset = 0;
  526. if (WARN_ON(gpio->gpio.of_gpio_n_cells < 2))
  527. return -EINVAL;
  528. if (WARN_ON(fwspec->param_count < gpio->gpio.of_gpio_n_cells))
  529. return -EINVAL;
  530. port = fwspec->param[0] / 8;
  531. pin = fwspec->param[0] % 8;
  532. if (port >= gpio->soc->num_ports)
  533. return -EINVAL;
  534. for (i = 0; i < port; i++)
  535. offset += gpio->soc->ports[i].pins;
  536. *type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
  537. *hwirq = offset + pin;
  538. return 0;
  539. }
  540. static int tegra186_gpio_populate_parent_fwspec(struct gpio_chip *chip,
  541. union gpio_irq_fwspec *gfwspec,
  542. unsigned int parent_hwirq,
  543. unsigned int parent_type)
  544. {
  545. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  546. struct irq_fwspec *fwspec = &gfwspec->fwspec;
  547. fwspec->fwnode = chip->irq.parent_domain->fwnode;
  548. fwspec->param_count = 3;
  549. fwspec->param[0] = gpio->soc->instance;
  550. fwspec->param[1] = parent_hwirq;
  551. fwspec->param[2] = parent_type;
  552. return 0;
  553. }
  554. static int tegra186_gpio_child_to_parent_hwirq(struct gpio_chip *chip,
  555. unsigned int hwirq,
  556. unsigned int type,
  557. unsigned int *parent_hwirq,
  558. unsigned int *parent_type)
  559. {
  560. *parent_hwirq = chip->irq.child_offset_to_irq(chip, hwirq);
  561. *parent_type = type;
  562. return 0;
  563. }
  564. static unsigned int tegra186_gpio_child_offset_to_irq(struct gpio_chip *chip,
  565. unsigned int offset)
  566. {
  567. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  568. unsigned int i;
  569. for (i = 0; i < gpio->soc->num_ports; i++) {
  570. if (offset < gpio->soc->ports[i].pins)
  571. break;
  572. offset -= gpio->soc->ports[i].pins;
  573. }
  574. return offset + i * 8;
  575. }
  576. static const struct of_device_id tegra186_pmc_of_match[] = {
  577. { .compatible = "nvidia,tegra186-pmc" },
  578. { .compatible = "nvidia,tegra194-pmc" },
  579. { .compatible = "nvidia,tegra234-pmc" },
  580. { /* sentinel */ }
  581. };
  582. static void tegra186_gpio_init_route_mapping(struct tegra_gpio *gpio)
  583. {
  584. struct device *dev = gpio->gpio.parent;
  585. unsigned int i;
  586. u32 value;
  587. for (i = 0; i < gpio->soc->num_ports; i++) {
  588. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  589. unsigned int offset, p = port->port;
  590. void __iomem *base;
  591. base = gpio->secure + port->bank * 0x1000 + 0x800;
  592. value = readl(base + TEGRA186_GPIO_CTL_SCR);
  593. /*
  594. * For controllers that haven't been locked down yet, make
  595. * sure to program the default interrupt route mapping.
  596. */
  597. if ((value & TEGRA186_GPIO_CTL_SCR_SEC_REN) == 0 &&
  598. (value & TEGRA186_GPIO_CTL_SCR_SEC_WEN) == 0) {
  599. /*
  600. * On Tegra194 and later, each pin can be routed to one or more
  601. * interrupts.
  602. */
  603. dev_dbg(dev, "programming default interrupt routing for port %s\n",
  604. port->name);
  605. offset = TEGRA186_GPIO_INT_ROUTE_MAPPING(p, 0);
  606. /*
  607. * By default we only want to route GPIO pins to IRQ 0. This works
  608. * only under the assumption that we're running as the host kernel
  609. * and hence all GPIO pins are owned by Linux.
  610. *
  611. * For cases where Linux is the guest OS, the hypervisor will have
  612. * to configure the interrupt routing and pass only the valid
  613. * interrupts via device tree.
  614. */
  615. value = readl(base + offset);
  616. value = BIT(port->pins) - 1;
  617. writel(value, base + offset);
  618. }
  619. }
  620. }
  621. static unsigned int tegra186_gpio_irqs_per_bank(struct tegra_gpio *gpio)
  622. {
  623. struct device *dev = gpio->gpio.parent;
  624. if (gpio->num_irq > gpio->num_banks) {
  625. if (gpio->num_irq % gpio->num_banks != 0)
  626. goto error;
  627. }
  628. if (gpio->num_irq < gpio->num_banks)
  629. goto error;
  630. gpio->num_irqs_per_bank = gpio->num_irq / gpio->num_banks;
  631. if (gpio->num_irqs_per_bank > gpio->soc->num_irqs_per_bank)
  632. goto error;
  633. return 0;
  634. error:
  635. dev_err(dev, "invalid number of interrupts (%u) for %u banks\n",
  636. gpio->num_irq, gpio->num_banks);
  637. return -EINVAL;
  638. }
  639. static int tegra186_gpio_probe(struct platform_device *pdev)
  640. {
  641. unsigned int i, j, offset;
  642. struct gpio_irq_chip *irq;
  643. struct tegra_gpio *gpio;
  644. struct device_node *np;
  645. struct resource *res;
  646. char **names;
  647. int err;
  648. gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
  649. if (!gpio)
  650. return -ENOMEM;
  651. gpio->soc = device_get_match_data(&pdev->dev);
  652. gpio->gpio.label = gpio->soc->name;
  653. gpio->gpio.parent = &pdev->dev;
  654. /* count the number of banks in the controller */
  655. for (i = 0; i < gpio->soc->num_ports; i++)
  656. if (gpio->soc->ports[i].bank > gpio->num_banks)
  657. gpio->num_banks = gpio->soc->ports[i].bank;
  658. gpio->num_banks++;
  659. /* get register apertures */
  660. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "security");
  661. if (!res)
  662. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  663. gpio->secure = devm_ioremap_resource(&pdev->dev, res);
  664. if (IS_ERR(gpio->secure))
  665. return PTR_ERR(gpio->secure);
  666. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gpio");
  667. if (!res)
  668. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  669. gpio->base = devm_ioremap_resource(&pdev->dev, res);
  670. if (IS_ERR(gpio->base))
  671. return PTR_ERR(gpio->base);
  672. err = platform_irq_count(pdev);
  673. if (err < 0)
  674. return err;
  675. gpio->num_irq = err;
  676. err = tegra186_gpio_irqs_per_bank(gpio);
  677. if (err < 0)
  678. return err;
  679. gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq),
  680. GFP_KERNEL);
  681. if (!gpio->irq)
  682. return -ENOMEM;
  683. for (i = 0; i < gpio->num_irq; i++) {
  684. err = platform_get_irq(pdev, i);
  685. if (err < 0)
  686. return err;
  687. gpio->irq[i] = err;
  688. }
  689. gpio->gpio.request = gpiochip_generic_request;
  690. gpio->gpio.free = gpiochip_generic_free;
  691. gpio->gpio.get_direction = tegra186_gpio_get_direction;
  692. gpio->gpio.direction_input = tegra186_gpio_direction_input;
  693. gpio->gpio.direction_output = tegra186_gpio_direction_output;
  694. gpio->gpio.get = tegra186_gpio_get;
  695. gpio->gpio.set = tegra186_gpio_set;
  696. gpio->gpio.set_config = tegra186_gpio_set_config;
  697. gpio->gpio.add_pin_ranges = tegra186_gpio_add_pin_ranges;
  698. gpio->gpio.init_valid_mask = tegra186_init_valid_mask;
  699. if (gpio->soc->has_gte) {
  700. gpio->gpio.en_hw_timestamp = tegra186_gpio_en_hw_ts;
  701. gpio->gpio.dis_hw_timestamp = tegra186_gpio_dis_hw_ts;
  702. }
  703. gpio->gpio.base = -1;
  704. for (i = 0; i < gpio->soc->num_ports; i++)
  705. gpio->gpio.ngpio += gpio->soc->ports[i].pins;
  706. names = devm_kcalloc(gpio->gpio.parent, gpio->gpio.ngpio,
  707. sizeof(*names), GFP_KERNEL);
  708. if (!names)
  709. return -ENOMEM;
  710. for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
  711. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  712. char *name;
  713. for (j = 0; j < port->pins; j++) {
  714. name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
  715. "P%s.%02x", port->name, j);
  716. if (!name)
  717. return -ENOMEM;
  718. names[offset + j] = name;
  719. }
  720. offset += port->pins;
  721. }
  722. gpio->gpio.names = (const char * const *)names;
  723. #if defined(CONFIG_OF_GPIO)
  724. gpio->gpio.of_gpio_n_cells = 2;
  725. gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
  726. #endif /* CONFIG_OF_GPIO */
  727. irq = &gpio->gpio.irq;
  728. gpio_irq_chip_set_chip(irq, &tegra186_gpio_irq_chip);
  729. irq->fwnode = dev_fwnode(&pdev->dev);
  730. irq->child_to_parent_hwirq = tegra186_gpio_child_to_parent_hwirq;
  731. irq->populate_parent_alloc_arg = tegra186_gpio_populate_parent_fwspec;
  732. irq->child_offset_to_irq = tegra186_gpio_child_offset_to_irq;
  733. irq->child_irq_domain_ops.translate = tegra186_gpio_irq_domain_translate;
  734. irq->handler = handle_simple_irq;
  735. irq->default_type = IRQ_TYPE_NONE;
  736. irq->parent_handler = tegra186_gpio_irq;
  737. irq->parent_handler_data = gpio;
  738. irq->num_parents = gpio->num_irq;
  739. /*
  740. * To simplify things, use a single interrupt per bank for now. Some
  741. * chips support up to 8 interrupts per bank, which can be useful to
  742. * distribute the load and decrease the processing latency for GPIOs
  743. * but it also requires a more complicated interrupt routing than we
  744. * currently program.
  745. */
  746. if (gpio->num_irqs_per_bank > 1) {
  747. irq->parents = devm_kcalloc(&pdev->dev, gpio->num_banks,
  748. sizeof(*irq->parents), GFP_KERNEL);
  749. if (!irq->parents)
  750. return -ENOMEM;
  751. for (i = 0; i < gpio->num_banks; i++)
  752. irq->parents[i] = gpio->irq[i * gpio->num_irqs_per_bank];
  753. irq->num_parents = gpio->num_banks;
  754. } else {
  755. irq->num_parents = gpio->num_irq;
  756. irq->parents = gpio->irq;
  757. }
  758. if (gpio->soc->num_irqs_per_bank > 1)
  759. tegra186_gpio_init_route_mapping(gpio);
  760. np = of_find_matching_node(NULL, tegra186_pmc_of_match);
  761. if (np) {
  762. if (of_device_is_available(np)) {
  763. irq->parent_domain = irq_find_host(np);
  764. of_node_put(np);
  765. if (!irq->parent_domain)
  766. return -EPROBE_DEFER;
  767. } else {
  768. of_node_put(np);
  769. }
  770. }
  771. irq->map = devm_kcalloc(&pdev->dev, gpio->gpio.ngpio,
  772. sizeof(*irq->map), GFP_KERNEL);
  773. if (!irq->map)
  774. return -ENOMEM;
  775. for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
  776. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  777. for (j = 0; j < port->pins; j++)
  778. irq->map[offset + j] = irq->parents[port->bank];
  779. offset += port->pins;
  780. }
  781. return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio, gpio);
  782. }
  783. #define TEGRA186_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \
  784. [TEGRA186_MAIN_GPIO_PORT_##_name] = { \
  785. .name = #_name, \
  786. .bank = _bank, \
  787. .port = _port, \
  788. .pins = _pins, \
  789. }
  790. static const struct tegra_gpio_port tegra186_main_ports[] = {
  791. TEGRA186_MAIN_GPIO_PORT( A, 2, 0, 7),
  792. TEGRA186_MAIN_GPIO_PORT( B, 3, 0, 7),
  793. TEGRA186_MAIN_GPIO_PORT( C, 3, 1, 7),
  794. TEGRA186_MAIN_GPIO_PORT( D, 3, 2, 6),
  795. TEGRA186_MAIN_GPIO_PORT( E, 2, 1, 8),
  796. TEGRA186_MAIN_GPIO_PORT( F, 2, 2, 6),
  797. TEGRA186_MAIN_GPIO_PORT( G, 4, 1, 6),
  798. TEGRA186_MAIN_GPIO_PORT( H, 1, 0, 7),
  799. TEGRA186_MAIN_GPIO_PORT( I, 0, 4, 8),
  800. TEGRA186_MAIN_GPIO_PORT( J, 5, 0, 8),
  801. TEGRA186_MAIN_GPIO_PORT( K, 5, 1, 1),
  802. TEGRA186_MAIN_GPIO_PORT( L, 1, 1, 8),
  803. TEGRA186_MAIN_GPIO_PORT( M, 5, 3, 6),
  804. TEGRA186_MAIN_GPIO_PORT( N, 0, 0, 7),
  805. TEGRA186_MAIN_GPIO_PORT( O, 0, 1, 4),
  806. TEGRA186_MAIN_GPIO_PORT( P, 4, 0, 7),
  807. TEGRA186_MAIN_GPIO_PORT( Q, 0, 2, 6),
  808. TEGRA186_MAIN_GPIO_PORT( R, 0, 5, 6),
  809. TEGRA186_MAIN_GPIO_PORT( T, 0, 3, 4),
  810. TEGRA186_MAIN_GPIO_PORT( X, 1, 2, 8),
  811. TEGRA186_MAIN_GPIO_PORT( Y, 1, 3, 7),
  812. TEGRA186_MAIN_GPIO_PORT(BB, 2, 3, 2),
  813. TEGRA186_MAIN_GPIO_PORT(CC, 5, 2, 4),
  814. };
  815. static const struct tegra_gpio_soc tegra186_main_soc = {
  816. .num_ports = ARRAY_SIZE(tegra186_main_ports),
  817. .ports = tegra186_main_ports,
  818. .name = "tegra186-gpio",
  819. .instance = 0,
  820. .num_irqs_per_bank = 1,
  821. .has_vm_support = false,
  822. };
  823. #define TEGRA186_AON_GPIO_PORT(_name, _bank, _port, _pins) \
  824. [TEGRA186_AON_GPIO_PORT_##_name] = { \
  825. .name = #_name, \
  826. .bank = _bank, \
  827. .port = _port, \
  828. .pins = _pins, \
  829. }
  830. static const struct tegra_gpio_port tegra186_aon_ports[] = {
  831. TEGRA186_AON_GPIO_PORT( S, 0, 1, 5),
  832. TEGRA186_AON_GPIO_PORT( U, 0, 2, 6),
  833. TEGRA186_AON_GPIO_PORT( V, 0, 4, 8),
  834. TEGRA186_AON_GPIO_PORT( W, 0, 5, 8),
  835. TEGRA186_AON_GPIO_PORT( Z, 0, 7, 4),
  836. TEGRA186_AON_GPIO_PORT(AA, 0, 6, 8),
  837. TEGRA186_AON_GPIO_PORT(EE, 0, 3, 3),
  838. TEGRA186_AON_GPIO_PORT(FF, 0, 0, 5),
  839. };
  840. static const struct tegra_gpio_soc tegra186_aon_soc = {
  841. .num_ports = ARRAY_SIZE(tegra186_aon_ports),
  842. .ports = tegra186_aon_ports,
  843. .name = "tegra186-gpio-aon",
  844. .instance = 1,
  845. .num_irqs_per_bank = 1,
  846. .has_vm_support = false,
  847. };
  848. #define TEGRA194_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \
  849. [TEGRA194_MAIN_GPIO_PORT_##_name] = { \
  850. .name = #_name, \
  851. .bank = _bank, \
  852. .port = _port, \
  853. .pins = _pins, \
  854. }
  855. static const struct tegra_gpio_port tegra194_main_ports[] = {
  856. TEGRA194_MAIN_GPIO_PORT( A, 1, 2, 8),
  857. TEGRA194_MAIN_GPIO_PORT( B, 4, 7, 2),
  858. TEGRA194_MAIN_GPIO_PORT( C, 4, 3, 8),
  859. TEGRA194_MAIN_GPIO_PORT( D, 4, 4, 4),
  860. TEGRA194_MAIN_GPIO_PORT( E, 4, 5, 8),
  861. TEGRA194_MAIN_GPIO_PORT( F, 4, 6, 6),
  862. TEGRA194_MAIN_GPIO_PORT( G, 4, 0, 8),
  863. TEGRA194_MAIN_GPIO_PORT( H, 4, 1, 8),
  864. TEGRA194_MAIN_GPIO_PORT( I, 4, 2, 5),
  865. TEGRA194_MAIN_GPIO_PORT( J, 5, 1, 6),
  866. TEGRA194_MAIN_GPIO_PORT( K, 3, 0, 8),
  867. TEGRA194_MAIN_GPIO_PORT( L, 3, 1, 4),
  868. TEGRA194_MAIN_GPIO_PORT( M, 2, 3, 8),
  869. TEGRA194_MAIN_GPIO_PORT( N, 2, 4, 3),
  870. TEGRA194_MAIN_GPIO_PORT( O, 5, 0, 6),
  871. TEGRA194_MAIN_GPIO_PORT( P, 2, 5, 8),
  872. TEGRA194_MAIN_GPIO_PORT( Q, 2, 6, 8),
  873. TEGRA194_MAIN_GPIO_PORT( R, 2, 7, 6),
  874. TEGRA194_MAIN_GPIO_PORT( S, 3, 3, 8),
  875. TEGRA194_MAIN_GPIO_PORT( T, 3, 4, 8),
  876. TEGRA194_MAIN_GPIO_PORT( U, 3, 5, 1),
  877. TEGRA194_MAIN_GPIO_PORT( V, 1, 0, 8),
  878. TEGRA194_MAIN_GPIO_PORT( W, 1, 1, 2),
  879. TEGRA194_MAIN_GPIO_PORT( X, 2, 0, 8),
  880. TEGRA194_MAIN_GPIO_PORT( Y, 2, 1, 8),
  881. TEGRA194_MAIN_GPIO_PORT( Z, 2, 2, 8),
  882. TEGRA194_MAIN_GPIO_PORT(FF, 3, 2, 2),
  883. TEGRA194_MAIN_GPIO_PORT(GG, 0, 0, 2)
  884. };
  885. static const struct tegra186_pin_range tegra194_main_pin_ranges[] = {
  886. { TEGRA194_MAIN_GPIO(GG, 0), "pex_l5_clkreq_n_pgg0" },
  887. { TEGRA194_MAIN_GPIO(GG, 1), "pex_l5_rst_n_pgg1" },
  888. };
  889. static const struct tegra_gpio_soc tegra194_main_soc = {
  890. .num_ports = ARRAY_SIZE(tegra194_main_ports),
  891. .ports = tegra194_main_ports,
  892. .name = "tegra194-gpio",
  893. .instance = 0,
  894. .num_irqs_per_bank = 8,
  895. .num_pin_ranges = ARRAY_SIZE(tegra194_main_pin_ranges),
  896. .pin_ranges = tegra194_main_pin_ranges,
  897. .pinmux = "nvidia,tegra194-pinmux",
  898. .has_vm_support = true,
  899. };
  900. #define TEGRA194_AON_GPIO_PORT(_name, _bank, _port, _pins) \
  901. [TEGRA194_AON_GPIO_PORT_##_name] = { \
  902. .name = #_name, \
  903. .bank = _bank, \
  904. .port = _port, \
  905. .pins = _pins, \
  906. }
  907. static const struct tegra_gpio_port tegra194_aon_ports[] = {
  908. TEGRA194_AON_GPIO_PORT(AA, 0, 3, 8),
  909. TEGRA194_AON_GPIO_PORT(BB, 0, 4, 4),
  910. TEGRA194_AON_GPIO_PORT(CC, 0, 1, 8),
  911. TEGRA194_AON_GPIO_PORT(DD, 0, 2, 3),
  912. TEGRA194_AON_GPIO_PORT(EE, 0, 0, 7)
  913. };
  914. static const struct tegra_gpio_soc tegra194_aon_soc = {
  915. .num_ports = ARRAY_SIZE(tegra194_aon_ports),
  916. .ports = tegra194_aon_ports,
  917. .name = "tegra194-gpio-aon",
  918. .instance = 1,
  919. .num_irqs_per_bank = 8,
  920. .has_gte = true,
  921. .has_vm_support = false,
  922. };
  923. #define TEGRA234_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \
  924. [TEGRA234_MAIN_GPIO_PORT_##_name] = { \
  925. .name = #_name, \
  926. .bank = _bank, \
  927. .port = _port, \
  928. .pins = _pins, \
  929. }
  930. static const struct tegra_gpio_port tegra234_main_ports[] = {
  931. TEGRA234_MAIN_GPIO_PORT( A, 0, 0, 8),
  932. TEGRA234_MAIN_GPIO_PORT( B, 0, 3, 1),
  933. TEGRA234_MAIN_GPIO_PORT( C, 5, 1, 8),
  934. TEGRA234_MAIN_GPIO_PORT( D, 5, 2, 4),
  935. TEGRA234_MAIN_GPIO_PORT( E, 5, 3, 8),
  936. TEGRA234_MAIN_GPIO_PORT( F, 5, 4, 6),
  937. TEGRA234_MAIN_GPIO_PORT( G, 4, 0, 8),
  938. TEGRA234_MAIN_GPIO_PORT( H, 4, 1, 8),
  939. TEGRA234_MAIN_GPIO_PORT( I, 4, 2, 7),
  940. TEGRA234_MAIN_GPIO_PORT( J, 5, 0, 6),
  941. TEGRA234_MAIN_GPIO_PORT( K, 3, 0, 8),
  942. TEGRA234_MAIN_GPIO_PORT( L, 3, 1, 4),
  943. TEGRA234_MAIN_GPIO_PORT( M, 2, 0, 8),
  944. TEGRA234_MAIN_GPIO_PORT( N, 2, 1, 8),
  945. TEGRA234_MAIN_GPIO_PORT( P, 2, 2, 8),
  946. TEGRA234_MAIN_GPIO_PORT( Q, 2, 3, 8),
  947. TEGRA234_MAIN_GPIO_PORT( R, 2, 4, 6),
  948. TEGRA234_MAIN_GPIO_PORT( X, 1, 0, 8),
  949. TEGRA234_MAIN_GPIO_PORT( Y, 1, 1, 8),
  950. TEGRA234_MAIN_GPIO_PORT( Z, 1, 2, 8),
  951. TEGRA234_MAIN_GPIO_PORT(AC, 0, 1, 8),
  952. TEGRA234_MAIN_GPIO_PORT(AD, 0, 2, 4),
  953. TEGRA234_MAIN_GPIO_PORT(AE, 3, 3, 2),
  954. TEGRA234_MAIN_GPIO_PORT(AF, 3, 4, 4),
  955. TEGRA234_MAIN_GPIO_PORT(AG, 3, 2, 8),
  956. };
  957. static const struct tegra_gpio_soc tegra234_main_soc = {
  958. .num_ports = ARRAY_SIZE(tegra234_main_ports),
  959. .ports = tegra234_main_ports,
  960. .name = "tegra234-gpio",
  961. .instance = 0,
  962. .num_irqs_per_bank = 8,
  963. .has_vm_support = true,
  964. };
  965. #define TEGRA234_AON_GPIO_PORT(_name, _bank, _port, _pins) \
  966. [TEGRA234_AON_GPIO_PORT_##_name] = { \
  967. .name = #_name, \
  968. .bank = _bank, \
  969. .port = _port, \
  970. .pins = _pins, \
  971. }
  972. static const struct tegra_gpio_port tegra234_aon_ports[] = {
  973. TEGRA234_AON_GPIO_PORT(AA, 0, 4, 8),
  974. TEGRA234_AON_GPIO_PORT(BB, 0, 5, 4),
  975. TEGRA234_AON_GPIO_PORT(CC, 0, 2, 8),
  976. TEGRA234_AON_GPIO_PORT(DD, 0, 3, 3),
  977. TEGRA234_AON_GPIO_PORT(EE, 0, 0, 8),
  978. TEGRA234_AON_GPIO_PORT(GG, 0, 1, 1),
  979. };
  980. static const struct tegra_gpio_soc tegra234_aon_soc = {
  981. .num_ports = ARRAY_SIZE(tegra234_aon_ports),
  982. .ports = tegra234_aon_ports,
  983. .name = "tegra234-gpio-aon",
  984. .instance = 1,
  985. .num_irqs_per_bank = 8,
  986. .has_gte = true,
  987. .has_vm_support = false,
  988. };
  989. #define TEGRA241_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \
  990. [TEGRA241_MAIN_GPIO_PORT_##_name] = { \
  991. .name = #_name, \
  992. .bank = _bank, \
  993. .port = _port, \
  994. .pins = _pins, \
  995. }
  996. static const struct tegra_gpio_port tegra241_main_ports[] = {
  997. TEGRA241_MAIN_GPIO_PORT(A, 0, 0, 8),
  998. TEGRA241_MAIN_GPIO_PORT(B, 0, 1, 8),
  999. TEGRA241_MAIN_GPIO_PORT(C, 0, 2, 2),
  1000. TEGRA241_MAIN_GPIO_PORT(D, 0, 3, 6),
  1001. TEGRA241_MAIN_GPIO_PORT(E, 0, 4, 8),
  1002. TEGRA241_MAIN_GPIO_PORT(F, 1, 0, 8),
  1003. TEGRA241_MAIN_GPIO_PORT(G, 1, 1, 8),
  1004. TEGRA241_MAIN_GPIO_PORT(H, 1, 2, 8),
  1005. TEGRA241_MAIN_GPIO_PORT(J, 1, 3, 8),
  1006. TEGRA241_MAIN_GPIO_PORT(K, 1, 4, 4),
  1007. TEGRA241_MAIN_GPIO_PORT(L, 1, 5, 6),
  1008. };
  1009. static const struct tegra_gpio_soc tegra241_main_soc = {
  1010. .num_ports = ARRAY_SIZE(tegra241_main_ports),
  1011. .ports = tegra241_main_ports,
  1012. .name = "tegra241-gpio",
  1013. .instance = 0,
  1014. .num_irqs_per_bank = 8,
  1015. .has_vm_support = false,
  1016. };
  1017. #define TEGRA241_AON_GPIO_PORT(_name, _bank, _port, _pins) \
  1018. [TEGRA241_AON_GPIO_PORT_##_name] = { \
  1019. .name = #_name, \
  1020. .bank = _bank, \
  1021. .port = _port, \
  1022. .pins = _pins, \
  1023. }
  1024. static const struct tegra_gpio_port tegra241_aon_ports[] = {
  1025. TEGRA241_AON_GPIO_PORT(AA, 0, 0, 8),
  1026. TEGRA241_AON_GPIO_PORT(BB, 0, 0, 4),
  1027. };
  1028. static const struct tegra_gpio_soc tegra241_aon_soc = {
  1029. .num_ports = ARRAY_SIZE(tegra241_aon_ports),
  1030. .ports = tegra241_aon_ports,
  1031. .name = "tegra241-gpio-aon",
  1032. .instance = 1,
  1033. .num_irqs_per_bank = 8,
  1034. .has_vm_support = false,
  1035. };
  1036. static const struct of_device_id tegra186_gpio_of_match[] = {
  1037. {
  1038. .compatible = "nvidia,tegra186-gpio",
  1039. .data = &tegra186_main_soc
  1040. }, {
  1041. .compatible = "nvidia,tegra186-gpio-aon",
  1042. .data = &tegra186_aon_soc
  1043. }, {
  1044. .compatible = "nvidia,tegra194-gpio",
  1045. .data = &tegra194_main_soc
  1046. }, {
  1047. .compatible = "nvidia,tegra194-gpio-aon",
  1048. .data = &tegra194_aon_soc
  1049. }, {
  1050. .compatible = "nvidia,tegra234-gpio",
  1051. .data = &tegra234_main_soc
  1052. }, {
  1053. .compatible = "nvidia,tegra234-gpio-aon",
  1054. .data = &tegra234_aon_soc
  1055. }, {
  1056. /* sentinel */
  1057. }
  1058. };
  1059. MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
  1060. static const struct acpi_device_id tegra186_gpio_acpi_match[] = {
  1061. { .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
  1062. { .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
  1063. { .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
  1064. { .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
  1065. { .id = "NVDA0508", .driver_data = (kernel_ulong_t)&tegra241_main_soc },
  1066. { .id = "NVDA0608", .driver_data = (kernel_ulong_t)&tegra241_aon_soc },
  1067. {}
  1068. };
  1069. MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
  1070. static struct platform_driver tegra186_gpio_driver = {
  1071. .driver = {
  1072. .name = "tegra186-gpio",
  1073. .of_match_table = tegra186_gpio_of_match,
  1074. .acpi_match_table = tegra186_gpio_acpi_match,
  1075. },
  1076. .probe = tegra186_gpio_probe,
  1077. };
  1078. module_platform_driver(tegra186_gpio_driver);
  1079. MODULE_DESCRIPTION("NVIDIA Tegra186 GPIO controller driver");
  1080. MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
  1081. MODULE_LICENSE("GPL v2");