gpio-tegra186.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * Copyright (c) 2016-2017 NVIDIA Corporation
  3. *
  4. * Author: Thierry Reding <treding@nvidia.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. */
  10. #include <linux/gpio/driver.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/irq.h>
  13. #include <linux/module.h>
  14. #include <linux/of_device.h>
  15. #include <linux/platform_device.h>
  16. #include <dt-bindings/gpio/tegra186-gpio.h>
  17. #define TEGRA186_GPIO_ENABLE_CONFIG 0x00
  18. #define TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0)
  19. #define TEGRA186_GPIO_ENABLE_CONFIG_OUT BIT(1)
  20. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_NONE (0x0 << 2)
  21. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL (0x1 << 2)
  22. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE (0x2 << 2)
  23. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE (0x3 << 2)
  24. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK (0x3 << 2)
  25. #define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL BIT(4)
  26. #define TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT BIT(6)
  27. #define TEGRA186_GPIO_DEBOUNCE_CONTROL 0x04
  28. #define TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD(x) ((x) & 0xff)
  29. #define TEGRA186_GPIO_INPUT 0x08
  30. #define TEGRA186_GPIO_INPUT_HIGH BIT(0)
  31. #define TEGRA186_GPIO_OUTPUT_CONTROL 0x0c
  32. #define TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED BIT(0)
  33. #define TEGRA186_GPIO_OUTPUT_VALUE 0x10
  34. #define TEGRA186_GPIO_OUTPUT_VALUE_HIGH BIT(0)
  35. #define TEGRA186_GPIO_INTERRUPT_CLEAR 0x14
  36. #define TEGRA186_GPIO_INTERRUPT_STATUS(x) (0x100 + (x) * 4)
  37. struct tegra_gpio_port {
  38. const char *name;
  39. unsigned int offset;
  40. unsigned int pins;
  41. unsigned int irq;
  42. };
  43. struct tegra_gpio_soc {
  44. const struct tegra_gpio_port *ports;
  45. unsigned int num_ports;
  46. const char *name;
  47. };
  48. struct tegra_gpio {
  49. struct gpio_chip gpio;
  50. struct irq_chip intc;
  51. unsigned int num_irq;
  52. unsigned int *irq;
  53. const struct tegra_gpio_soc *soc;
  54. void __iomem *base;
  55. };
  56. static const struct tegra_gpio_port *
  57. tegra186_gpio_get_port(struct tegra_gpio *gpio, unsigned int *pin)
  58. {
  59. unsigned int start = 0, i;
  60. for (i = 0; i < gpio->soc->num_ports; i++) {
  61. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  62. if (*pin >= start && *pin < start + port->pins) {
  63. *pin -= start;
  64. return port;
  65. }
  66. start += port->pins;
  67. }
  68. return NULL;
  69. }
  70. static void __iomem *tegra186_gpio_get_base(struct tegra_gpio *gpio,
  71. unsigned int pin)
  72. {
  73. const struct tegra_gpio_port *port;
  74. port = tegra186_gpio_get_port(gpio, &pin);
  75. if (!port)
  76. return NULL;
  77. return gpio->base + port->offset + pin * 0x20;
  78. }
  79. static int tegra186_gpio_get_direction(struct gpio_chip *chip,
  80. unsigned int offset)
  81. {
  82. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  83. void __iomem *base;
  84. u32 value;
  85. base = tegra186_gpio_get_base(gpio, offset);
  86. if (WARN_ON(base == NULL))
  87. return -ENODEV;
  88. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  89. if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
  90. return 0;
  91. return 1;
  92. }
  93. static int tegra186_gpio_direction_input(struct gpio_chip *chip,
  94. unsigned int offset)
  95. {
  96. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  97. void __iomem *base;
  98. u32 value;
  99. base = tegra186_gpio_get_base(gpio, offset);
  100. if (WARN_ON(base == NULL))
  101. return -ENODEV;
  102. value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
  103. value |= TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
  104. writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
  105. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  106. value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
  107. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_OUT;
  108. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  109. return 0;
  110. }
  111. static int tegra186_gpio_direction_output(struct gpio_chip *chip,
  112. unsigned int offset, int level)
  113. {
  114. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  115. void __iomem *base;
  116. u32 value;
  117. /* configure output level first */
  118. chip->set(chip, offset, level);
  119. base = tegra186_gpio_get_base(gpio, offset);
  120. if (WARN_ON(base == NULL))
  121. return -EINVAL;
  122. /* set the direction */
  123. value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
  124. value &= ~TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
  125. writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
  126. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  127. value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
  128. value |= TEGRA186_GPIO_ENABLE_CONFIG_OUT;
  129. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  130. return 0;
  131. }
  132. static int tegra186_gpio_get(struct gpio_chip *chip, unsigned int offset)
  133. {
  134. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  135. void __iomem *base;
  136. u32 value;
  137. base = tegra186_gpio_get_base(gpio, offset);
  138. if (WARN_ON(base == NULL))
  139. return -ENODEV;
  140. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  141. if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
  142. value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
  143. else
  144. value = readl(base + TEGRA186_GPIO_INPUT);
  145. return value & BIT(0);
  146. }
  147. static void tegra186_gpio_set(struct gpio_chip *chip, unsigned int offset,
  148. int level)
  149. {
  150. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  151. void __iomem *base;
  152. u32 value;
  153. base = tegra186_gpio_get_base(gpio, offset);
  154. if (WARN_ON(base == NULL))
  155. return;
  156. value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
  157. if (level == 0)
  158. value &= ~TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
  159. else
  160. value |= TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
  161. writel(value, base + TEGRA186_GPIO_OUTPUT_VALUE);
  162. }
  163. static int tegra186_gpio_of_xlate(struct gpio_chip *chip,
  164. const struct of_phandle_args *spec,
  165. u32 *flags)
  166. {
  167. struct tegra_gpio *gpio = gpiochip_get_data(chip);
  168. unsigned int port, pin, i, offset = 0;
  169. if (WARN_ON(chip->of_gpio_n_cells < 2))
  170. return -EINVAL;
  171. if (WARN_ON(spec->args_count < chip->of_gpio_n_cells))
  172. return -EINVAL;
  173. port = spec->args[0] / 8;
  174. pin = spec->args[0] % 8;
  175. if (port >= gpio->soc->num_ports) {
  176. dev_err(chip->parent, "invalid port number: %u\n", port);
  177. return -EINVAL;
  178. }
  179. for (i = 0; i < port; i++)
  180. offset += gpio->soc->ports[i].pins;
  181. if (flags)
  182. *flags = spec->args[1];
  183. return offset + pin;
  184. }
  185. static void tegra186_irq_ack(struct irq_data *data)
  186. {
  187. struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
  188. void __iomem *base;
  189. base = tegra186_gpio_get_base(gpio, data->hwirq);
  190. if (WARN_ON(base == NULL))
  191. return;
  192. writel(1, base + TEGRA186_GPIO_INTERRUPT_CLEAR);
  193. }
  194. static void tegra186_irq_mask(struct irq_data *data)
  195. {
  196. struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
  197. void __iomem *base;
  198. u32 value;
  199. base = tegra186_gpio_get_base(gpio, data->hwirq);
  200. if (WARN_ON(base == NULL))
  201. return;
  202. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  203. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
  204. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  205. }
  206. static void tegra186_irq_unmask(struct irq_data *data)
  207. {
  208. struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
  209. void __iomem *base;
  210. u32 value;
  211. base = tegra186_gpio_get_base(gpio, data->hwirq);
  212. if (WARN_ON(base == NULL))
  213. return;
  214. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  215. value |= TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
  216. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  217. }
  218. static int tegra186_irq_set_type(struct irq_data *data, unsigned int flow)
  219. {
  220. struct tegra_gpio *gpio = irq_data_get_irq_chip_data(data);
  221. void __iomem *base;
  222. u32 value;
  223. base = tegra186_gpio_get_base(gpio, data->hwirq);
  224. if (WARN_ON(base == NULL))
  225. return -ENODEV;
  226. value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
  227. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK;
  228. value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  229. switch (flow & IRQ_TYPE_SENSE_MASK) {
  230. case IRQ_TYPE_NONE:
  231. break;
  232. case IRQ_TYPE_EDGE_RISING:
  233. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  234. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  235. break;
  236. case IRQ_TYPE_EDGE_FALLING:
  237. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
  238. break;
  239. case IRQ_TYPE_EDGE_BOTH:
  240. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
  241. break;
  242. case IRQ_TYPE_LEVEL_HIGH:
  243. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
  244. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
  245. break;
  246. case IRQ_TYPE_LEVEL_LOW:
  247. value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
  248. break;
  249. default:
  250. return -EINVAL;
  251. }
  252. writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
  253. if ((flow & IRQ_TYPE_EDGE_BOTH) == 0)
  254. irq_set_handler_locked(data, handle_level_irq);
  255. else
  256. irq_set_handler_locked(data, handle_edge_irq);
  257. return 0;
  258. }
  259. static void tegra186_gpio_irq(struct irq_desc *desc)
  260. {
  261. struct tegra_gpio *gpio = irq_desc_get_handler_data(desc);
  262. struct irq_domain *domain = gpio->gpio.irq.domain;
  263. struct irq_chip *chip = irq_desc_get_chip(desc);
  264. unsigned int parent = irq_desc_get_irq(desc);
  265. unsigned int i, offset = 0;
  266. chained_irq_enter(chip, desc);
  267. for (i = 0; i < gpio->soc->num_ports; i++) {
  268. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  269. void __iomem *base = gpio->base + port->offset;
  270. unsigned int pin, irq;
  271. unsigned long value;
  272. /* skip ports that are not associated with this controller */
  273. if (parent != gpio->irq[port->irq])
  274. goto skip;
  275. value = readl(base + TEGRA186_GPIO_INTERRUPT_STATUS(1));
  276. for_each_set_bit(pin, &value, port->pins) {
  277. irq = irq_find_mapping(domain, offset + pin);
  278. if (WARN_ON(irq == 0))
  279. continue;
  280. generic_handle_irq(irq);
  281. }
  282. skip:
  283. offset += port->pins;
  284. }
  285. chained_irq_exit(chip, desc);
  286. }
  287. static int tegra186_gpio_irq_domain_xlate(struct irq_domain *domain,
  288. struct device_node *np,
  289. const u32 *spec, unsigned int size,
  290. unsigned long *hwirq,
  291. unsigned int *type)
  292. {
  293. struct tegra_gpio *gpio = gpiochip_get_data(domain->host_data);
  294. unsigned int port, pin, i, offset = 0;
  295. if (size < 2)
  296. return -EINVAL;
  297. port = spec[0] / 8;
  298. pin = spec[0] % 8;
  299. if (port >= gpio->soc->num_ports) {
  300. dev_err(gpio->gpio.parent, "invalid port number: %u\n", port);
  301. return -EINVAL;
  302. }
  303. for (i = 0; i < port; i++)
  304. offset += gpio->soc->ports[i].pins;
  305. *type = spec[1] & IRQ_TYPE_SENSE_MASK;
  306. *hwirq = offset + pin;
  307. return 0;
  308. }
  309. static const struct irq_domain_ops tegra186_gpio_irq_domain_ops = {
  310. .map = gpiochip_irq_map,
  311. .unmap = gpiochip_irq_unmap,
  312. .xlate = tegra186_gpio_irq_domain_xlate,
  313. };
  314. static int tegra186_gpio_probe(struct platform_device *pdev)
  315. {
  316. unsigned int i, j, offset;
  317. struct gpio_irq_chip *irq;
  318. struct tegra_gpio *gpio;
  319. struct resource *res;
  320. char **names;
  321. int err;
  322. gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
  323. if (!gpio)
  324. return -ENOMEM;
  325. gpio->soc = of_device_get_match_data(&pdev->dev);
  326. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gpio");
  327. gpio->base = devm_ioremap_resource(&pdev->dev, res);
  328. if (IS_ERR(gpio->base))
  329. return PTR_ERR(gpio->base);
  330. err = platform_irq_count(pdev);
  331. if (err < 0)
  332. return err;
  333. gpio->num_irq = err;
  334. gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq),
  335. GFP_KERNEL);
  336. if (!gpio->irq)
  337. return -ENOMEM;
  338. for (i = 0; i < gpio->num_irq; i++) {
  339. err = platform_get_irq(pdev, i);
  340. if (err < 0)
  341. return err;
  342. gpio->irq[i] = err;
  343. }
  344. gpio->gpio.label = gpio->soc->name;
  345. gpio->gpio.parent = &pdev->dev;
  346. gpio->gpio.get_direction = tegra186_gpio_get_direction;
  347. gpio->gpio.direction_input = tegra186_gpio_direction_input;
  348. gpio->gpio.direction_output = tegra186_gpio_direction_output;
  349. gpio->gpio.get = tegra186_gpio_get,
  350. gpio->gpio.set = tegra186_gpio_set;
  351. gpio->gpio.base = -1;
  352. for (i = 0; i < gpio->soc->num_ports; i++)
  353. gpio->gpio.ngpio += gpio->soc->ports[i].pins;
  354. names = devm_kcalloc(gpio->gpio.parent, gpio->gpio.ngpio,
  355. sizeof(*names), GFP_KERNEL);
  356. if (!names)
  357. return -ENOMEM;
  358. for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
  359. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  360. char *name;
  361. for (j = 0; j < port->pins; j++) {
  362. name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
  363. "P%s.%02x", port->name, j);
  364. if (!name)
  365. return -ENOMEM;
  366. names[offset + j] = name;
  367. }
  368. offset += port->pins;
  369. }
  370. gpio->gpio.names = (const char * const *)names;
  371. gpio->gpio.of_node = pdev->dev.of_node;
  372. gpio->gpio.of_gpio_n_cells = 2;
  373. gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
  374. gpio->intc.name = pdev->dev.of_node->name;
  375. gpio->intc.irq_ack = tegra186_irq_ack;
  376. gpio->intc.irq_mask = tegra186_irq_mask;
  377. gpio->intc.irq_unmask = tegra186_irq_unmask;
  378. gpio->intc.irq_set_type = tegra186_irq_set_type;
  379. irq = &gpio->gpio.irq;
  380. irq->chip = &gpio->intc;
  381. irq->domain_ops = &tegra186_gpio_irq_domain_ops;
  382. irq->handler = handle_simple_irq;
  383. irq->default_type = IRQ_TYPE_NONE;
  384. irq->parent_handler = tegra186_gpio_irq;
  385. irq->parent_handler_data = gpio;
  386. irq->num_parents = gpio->num_irq;
  387. irq->parents = gpio->irq;
  388. irq->map = devm_kcalloc(&pdev->dev, gpio->gpio.ngpio,
  389. sizeof(*irq->map), GFP_KERNEL);
  390. if (!irq->map)
  391. return -ENOMEM;
  392. for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
  393. const struct tegra_gpio_port *port = &gpio->soc->ports[i];
  394. for (j = 0; j < port->pins; j++)
  395. irq->map[offset + j] = irq->parents[port->irq];
  396. offset += port->pins;
  397. }
  398. platform_set_drvdata(pdev, gpio);
  399. err = devm_gpiochip_add_data(&pdev->dev, &gpio->gpio, gpio);
  400. if (err < 0)
  401. return err;
  402. return 0;
  403. }
  404. static int tegra186_gpio_remove(struct platform_device *pdev)
  405. {
  406. return 0;
  407. }
  408. #define TEGRA_MAIN_GPIO_PORT(port, base, count, controller) \
  409. [TEGRA_MAIN_GPIO_PORT_##port] = { \
  410. .name = #port, \
  411. .offset = base, \
  412. .pins = count, \
  413. .irq = controller, \
  414. }
  415. static const struct tegra_gpio_port tegra186_main_ports[] = {
  416. TEGRA_MAIN_GPIO_PORT( A, 0x2000, 7, 2),
  417. TEGRA_MAIN_GPIO_PORT( B, 0x3000, 7, 3),
  418. TEGRA_MAIN_GPIO_PORT( C, 0x3200, 7, 3),
  419. TEGRA_MAIN_GPIO_PORT( D, 0x3400, 6, 3),
  420. TEGRA_MAIN_GPIO_PORT( E, 0x2200, 8, 2),
  421. TEGRA_MAIN_GPIO_PORT( F, 0x2400, 6, 2),
  422. TEGRA_MAIN_GPIO_PORT( G, 0x4200, 6, 4),
  423. TEGRA_MAIN_GPIO_PORT( H, 0x1000, 7, 1),
  424. TEGRA_MAIN_GPIO_PORT( I, 0x0800, 8, 0),
  425. TEGRA_MAIN_GPIO_PORT( J, 0x5000, 8, 5),
  426. TEGRA_MAIN_GPIO_PORT( K, 0x5200, 1, 5),
  427. TEGRA_MAIN_GPIO_PORT( L, 0x1200, 8, 1),
  428. TEGRA_MAIN_GPIO_PORT( M, 0x5600, 6, 5),
  429. TEGRA_MAIN_GPIO_PORT( N, 0x0000, 7, 0),
  430. TEGRA_MAIN_GPIO_PORT( O, 0x0200, 4, 0),
  431. TEGRA_MAIN_GPIO_PORT( P, 0x4000, 7, 4),
  432. TEGRA_MAIN_GPIO_PORT( Q, 0x0400, 6, 0),
  433. TEGRA_MAIN_GPIO_PORT( R, 0x0a00, 6, 0),
  434. TEGRA_MAIN_GPIO_PORT( T, 0x0600, 4, 0),
  435. TEGRA_MAIN_GPIO_PORT( X, 0x1400, 8, 1),
  436. TEGRA_MAIN_GPIO_PORT( Y, 0x1600, 7, 1),
  437. TEGRA_MAIN_GPIO_PORT(BB, 0x2600, 2, 2),
  438. TEGRA_MAIN_GPIO_PORT(CC, 0x5400, 4, 5),
  439. };
  440. static const struct tegra_gpio_soc tegra186_main_soc = {
  441. .num_ports = ARRAY_SIZE(tegra186_main_ports),
  442. .ports = tegra186_main_ports,
  443. .name = "tegra186-gpio",
  444. };
  445. #define TEGRA_AON_GPIO_PORT(port, base, count, controller) \
  446. [TEGRA_AON_GPIO_PORT_##port] = { \
  447. .name = #port, \
  448. .offset = base, \
  449. .pins = count, \
  450. .irq = controller, \
  451. }
  452. static const struct tegra_gpio_port tegra186_aon_ports[] = {
  453. TEGRA_AON_GPIO_PORT( S, 0x0200, 5, 0),
  454. TEGRA_AON_GPIO_PORT( U, 0x0400, 6, 0),
  455. TEGRA_AON_GPIO_PORT( V, 0x0800, 8, 0),
  456. TEGRA_AON_GPIO_PORT( W, 0x0a00, 8, 0),
  457. TEGRA_AON_GPIO_PORT( Z, 0x0e00, 4, 0),
  458. TEGRA_AON_GPIO_PORT(AA, 0x0c00, 8, 0),
  459. TEGRA_AON_GPIO_PORT(EE, 0x0600, 3, 0),
  460. TEGRA_AON_GPIO_PORT(FF, 0x0000, 5, 0),
  461. };
  462. static const struct tegra_gpio_soc tegra186_aon_soc = {
  463. .num_ports = ARRAY_SIZE(tegra186_aon_ports),
  464. .ports = tegra186_aon_ports,
  465. .name = "tegra186-gpio-aon",
  466. };
  467. static const struct of_device_id tegra186_gpio_of_match[] = {
  468. {
  469. .compatible = "nvidia,tegra186-gpio",
  470. .data = &tegra186_main_soc
  471. }, {
  472. .compatible = "nvidia,tegra186-gpio-aon",
  473. .data = &tegra186_aon_soc
  474. }, {
  475. /* sentinel */
  476. }
  477. };
  478. static struct platform_driver tegra186_gpio_driver = {
  479. .driver = {
  480. .name = "tegra186-gpio",
  481. .of_match_table = tegra186_gpio_of_match,
  482. },
  483. .probe = tegra186_gpio_probe,
  484. .remove = tegra186_gpio_remove,
  485. };
  486. module_platform_driver(tegra186_gpio_driver);
  487. MODULE_DESCRIPTION("NVIDIA Tegra186 GPIO controller driver");
  488. MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
  489. MODULE_LICENSE("GPL v2");