gpio-tegra186.c 18 KB

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