/arch/arm/mach-fsm/gpio.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · C · 666 lines · 577 code · 66 blank · 23 comment · 47 complexity · c347426e138d8129d8cae45038925b88 MD5 · raw file

  1. /* linux/arch/arm/mach-msm/gpio.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  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. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <asm/io.h>
  17. #include <asm/gpio.h>
  18. #include <linux/irq.h>
  19. #include <linux/module.h>
  20. #include <linux/debugfs.h>
  21. #include "gpio_chip.h"
  22. #include "gpio_hw.h"
  23. #include "proc_comm.h"
  24. #include "smd_private.h"
  25. #ifndef CONFIG_GPIOLIB
  26. enum {
  27. GPIO_DEBUG_SLEEP = 1U << 0,
  28. };
  29. static int msm_gpio_debug_mask = 0;
  30. module_param_named(debug_mask, msm_gpio_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
  31. /* private gpio_configure flags */
  32. #define MSM_GPIOF_ENABLE_INTERRUPT 0x10000000
  33. #define MSM_GPIOF_DISABLE_INTERRUPT 0x20000000
  34. #define MSM_GPIOF_ENABLE_WAKE 0x40000000
  35. #define MSM_GPIOF_DISABLE_WAKE 0x80000000
  36. static int msm_gpio_configure(struct goog_gpio_chip *chip,
  37. unsigned int gpio,
  38. unsigned long flags);
  39. static int msm_gpio_get_irq_num(struct goog_gpio_chip *chip,
  40. unsigned int gpio,
  41. unsigned int *irqp,
  42. unsigned long *irqnumflagsp);
  43. static int msm_gpio_read(struct goog_gpio_chip *chip, unsigned n);
  44. static int msm_gpio_write(struct goog_gpio_chip *chip,
  45. unsigned n,
  46. unsigned on);
  47. static int msm_gpio_read_detect_status(struct goog_gpio_chip *chip,
  48. unsigned int gpio);
  49. static int msm_gpio_clear_detect_status(struct goog_gpio_chip *chip,
  50. unsigned int gpio);
  51. struct msm_gpio_chip msm_gpio_chips[] = {
  52. {
  53. .regs = {
  54. .out = GPIO_OUT_0,
  55. .in = GPIO_IN_0,
  56. .int_status = GPIO_INT_STATUS_0,
  57. .int_clear = GPIO_INT_CLEAR_0,
  58. .int_en = GPIO_INT_EN_0,
  59. .int_edge = GPIO_INT_EDGE_0,
  60. .int_pos = GPIO_INT_POS_0,
  61. .oe = GPIO_OE_0,
  62. },
  63. .chip = {
  64. .start = 0,
  65. .end = 15,
  66. .configure = msm_gpio_configure,
  67. .get_irq_num = msm_gpio_get_irq_num,
  68. .read = msm_gpio_read,
  69. .write = msm_gpio_write,
  70. .read_detect_status = msm_gpio_read_detect_status,
  71. .clear_detect_status = msm_gpio_clear_detect_status
  72. }
  73. },
  74. {
  75. .regs = {
  76. .out = GPIO_OUT_1,
  77. .in = GPIO_IN_1,
  78. .int_status = GPIO_INT_STATUS_1,
  79. .int_clear = GPIO_INT_CLEAR_1,
  80. .int_en = GPIO_INT_EN_1,
  81. .int_edge = GPIO_INT_EDGE_1,
  82. .int_pos = GPIO_INT_POS_1,
  83. .oe = GPIO_OE_1,
  84. },
  85. .chip = {
  86. .start = 16,
  87. #if defined(CONFIG_ARCH_MSM7X30)
  88. .end = 43,
  89. #else
  90. .end = 42,
  91. #endif
  92. .configure = msm_gpio_configure,
  93. .get_irq_num = msm_gpio_get_irq_num,
  94. .read = msm_gpio_read,
  95. .write = msm_gpio_write,
  96. .read_detect_status = msm_gpio_read_detect_status,
  97. .clear_detect_status = msm_gpio_clear_detect_status
  98. }
  99. },
  100. {
  101. .regs = {
  102. .out = GPIO_OUT_2,
  103. .in = GPIO_IN_2,
  104. .int_status = GPIO_INT_STATUS_2,
  105. .int_clear = GPIO_INT_CLEAR_2,
  106. .int_en = GPIO_INT_EN_2,
  107. .int_edge = GPIO_INT_EDGE_2,
  108. .int_pos = GPIO_INT_POS_2,
  109. .oe = GPIO_OE_2,
  110. },
  111. .chip = {
  112. #if defined(CONFIG_ARCH_MSM7X30)
  113. .start = 44,
  114. #else
  115. .start = 43,
  116. #endif
  117. .end = 67,
  118. .configure = msm_gpio_configure,
  119. .get_irq_num = msm_gpio_get_irq_num,
  120. .read = msm_gpio_read,
  121. .write = msm_gpio_write,
  122. .read_detect_status = msm_gpio_read_detect_status,
  123. .clear_detect_status = msm_gpio_clear_detect_status
  124. }
  125. },
  126. {
  127. .regs = {
  128. .out = GPIO_OUT_3,
  129. .in = GPIO_IN_3,
  130. .int_status = GPIO_INT_STATUS_3,
  131. .int_clear = GPIO_INT_CLEAR_3,
  132. .int_en = GPIO_INT_EN_3,
  133. .int_edge = GPIO_INT_EDGE_3,
  134. .int_pos = GPIO_INT_POS_3,
  135. .oe = GPIO_OE_3,
  136. },
  137. .chip = {
  138. .start = 68,
  139. .end = 94,
  140. .configure = msm_gpio_configure,
  141. .get_irq_num = msm_gpio_get_irq_num,
  142. .read = msm_gpio_read,
  143. .write = msm_gpio_write,
  144. .read_detect_status = msm_gpio_read_detect_status,
  145. .clear_detect_status = msm_gpio_clear_detect_status
  146. }
  147. },
  148. {
  149. .regs = {
  150. .out = GPIO_OUT_4,
  151. .in = GPIO_IN_4,
  152. .int_status = GPIO_INT_STATUS_4,
  153. .int_clear = GPIO_INT_CLEAR_4,
  154. .int_en = GPIO_INT_EN_4,
  155. .int_edge = GPIO_INT_EDGE_4,
  156. .int_pos = GPIO_INT_POS_4,
  157. .oe = GPIO_OE_4,
  158. },
  159. .chip = {
  160. .start = 95,
  161. #if defined(CONFIG_ARCH_QSD8X50)
  162. .end = 103,
  163. #else
  164. .end = 106,
  165. #endif
  166. .configure = msm_gpio_configure,
  167. .get_irq_num = msm_gpio_get_irq_num,
  168. .read = msm_gpio_read,
  169. .write = msm_gpio_write,
  170. .read_detect_status = msm_gpio_read_detect_status,
  171. .clear_detect_status = msm_gpio_clear_detect_status
  172. }
  173. },
  174. {
  175. .regs = {
  176. .out = GPIO_OUT_5,
  177. .in = GPIO_IN_5,
  178. .int_status = GPIO_INT_STATUS_5,
  179. .int_clear = GPIO_INT_CLEAR_5,
  180. .int_en = GPIO_INT_EN_5,
  181. .int_edge = GPIO_INT_EDGE_5,
  182. .int_pos = GPIO_INT_POS_5,
  183. .oe = GPIO_OE_5,
  184. },
  185. .chip = {
  186. #if defined(CONFIG_ARCH_QSD8X50)
  187. .start = 104,
  188. .end = 121,
  189. #elif defined(CONFIG_ARCH_MSM7X30)
  190. .start = 107,
  191. .end = 133,
  192. #else
  193. .start = 107,
  194. .end = 132,
  195. #endif
  196. .configure = msm_gpio_configure,
  197. .get_irq_num = msm_gpio_get_irq_num,
  198. .read = msm_gpio_read,
  199. .write = msm_gpio_write,
  200. .read_detect_status = msm_gpio_read_detect_status,
  201. .clear_detect_status = msm_gpio_clear_detect_status
  202. }
  203. },
  204. #if defined(CONFIG_ARCH_MSM_SCORPION)
  205. {
  206. .regs = {
  207. .out = GPIO_OUT_6,
  208. .in = GPIO_IN_6,
  209. .int_status = GPIO_INT_STATUS_6,
  210. .int_clear = GPIO_INT_CLEAR_6,
  211. .int_en = GPIO_INT_EN_6,
  212. .int_edge = GPIO_INT_EDGE_6,
  213. .int_pos = GPIO_INT_POS_6,
  214. .oe = GPIO_OE_6,
  215. },
  216. .chip = {
  217. #if defined(CONFIG_ARCH_MSM7X30)
  218. .start = 134,
  219. .end = 150,
  220. #else
  221. .start = 122,
  222. .end = 152,
  223. #endif
  224. .configure = msm_gpio_configure,
  225. .get_irq_num = msm_gpio_get_irq_num,
  226. .read = msm_gpio_read,
  227. .write = msm_gpio_write,
  228. .read_detect_status = msm_gpio_read_detect_status,
  229. .clear_detect_status = msm_gpio_clear_detect_status
  230. }
  231. },
  232. {
  233. .regs = {
  234. .out = GPIO_OUT_7,
  235. .in = GPIO_IN_7,
  236. .int_status = GPIO_INT_STATUS_7,
  237. .int_clear = GPIO_INT_CLEAR_7,
  238. .int_en = GPIO_INT_EN_7,
  239. .int_edge = GPIO_INT_EDGE_7,
  240. .int_pos = GPIO_INT_POS_7,
  241. .oe = GPIO_OE_7,
  242. },
  243. .chip = {
  244. #if defined(CONFIG_ARCH_MSM7X30)
  245. .start = 151,
  246. .end = 181,
  247. #else
  248. .start = 153,
  249. .end = 164,
  250. #endif
  251. .configure = msm_gpio_configure,
  252. .get_irq_num = msm_gpio_get_irq_num,
  253. .read = msm_gpio_read,
  254. .write = msm_gpio_write,
  255. .read_detect_status = msm_gpio_read_detect_status,
  256. .clear_detect_status = msm_gpio_clear_detect_status
  257. }
  258. },
  259. #endif
  260. };
  261. static void msm_gpio_update_both_edge_detect(struct msm_gpio_chip *msm_chip)
  262. {
  263. int loop_limit = 100;
  264. unsigned pol, val, val2, intstat;
  265. do {
  266. val = readl(msm_chip->regs.in);
  267. pol = readl(msm_chip->regs.int_pos);
  268. pol = (pol & ~msm_chip->both_edge_detect) | (~val & msm_chip->both_edge_detect);
  269. writel(pol, msm_chip->regs.int_pos);
  270. intstat = readl(msm_chip->regs.int_status);
  271. val2 = readl(msm_chip->regs.in);
  272. if (((val ^ val2) & msm_chip->both_edge_detect & ~intstat) == 0)
  273. return;
  274. } while (loop_limit-- > 0);
  275. printk(KERN_ERR "msm_gpio_update_both_edge_detect, failed to reach stable state %x != %x\n", val, val2);
  276. }
  277. static int msm_gpio_write(struct goog_gpio_chip *chip, unsigned n, unsigned on)
  278. {
  279. struct msm_gpio_chip *msm_chip = container_of(chip, struct msm_gpio_chip, chip);
  280. unsigned b = 1U << (n - chip->start);
  281. unsigned v;
  282. v = readl(msm_chip->regs.out);
  283. if (on) {
  284. writel(v | b, msm_chip->regs.out);
  285. } else {
  286. writel(v & (~b), msm_chip->regs.out);
  287. }
  288. return 0;
  289. }
  290. static int msm_gpio_read(struct goog_gpio_chip *chip, unsigned n)
  291. {
  292. struct msm_gpio_chip *msm_chip = container_of(chip, struct msm_gpio_chip, chip);
  293. unsigned b = 1U << (n - chip->start);
  294. return (readl(msm_chip->regs.in) & b) ? 1 : 0;
  295. }
  296. static int msm_gpio_read_detect_status(struct goog_gpio_chip *chip,
  297. unsigned int gpio)
  298. {
  299. struct msm_gpio_chip *msm_chip = container_of(chip, struct msm_gpio_chip, chip);
  300. unsigned b = 1U << (gpio - chip->start);
  301. unsigned v;
  302. v = readl(msm_chip->regs.int_status);
  303. #if MSM_GPIO_BROKEN_INT_CLEAR
  304. v |= msm_chip->int_status_copy;
  305. #endif
  306. return (v & b) ? 1 : 0;
  307. }
  308. static int msm_gpio_clear_detect_status(struct goog_gpio_chip *chip,
  309. unsigned int gpio)
  310. {
  311. struct msm_gpio_chip *msm_chip = container_of(chip, struct msm_gpio_chip, chip);
  312. unsigned b = 1U << (gpio - chip->start);
  313. #if MSM_GPIO_BROKEN_INT_CLEAR
  314. /* Save interrupts that already triggered before we loose them. */
  315. /* Any interrupt that triggers between the read of int_status */
  316. /* and the write to int_clear will still be lost though. */
  317. msm_chip->int_status_copy |= readl(msm_chip->regs.int_status);
  318. msm_chip->int_status_copy &= ~b;
  319. #endif
  320. writel(b, msm_chip->regs.int_clear);
  321. msm_gpio_update_both_edge_detect(msm_chip);
  322. return 0;
  323. }
  324. int msm_gpio_configure(struct goog_gpio_chip *chip,
  325. unsigned int gpio,
  326. unsigned long flags)
  327. {
  328. struct msm_gpio_chip *msm_chip = container_of(chip, struct msm_gpio_chip, chip);
  329. unsigned b = 1U << (gpio - chip->start);
  330. unsigned v;
  331. if (flags & (GPIOF_OUTPUT_LOW | GPIOF_OUTPUT_HIGH))
  332. msm_gpio_write(chip, gpio, flags & GPIOF_OUTPUT_HIGH);
  333. if (flags & (GPIOF_INPUT | GPIOF_DRIVE_OUTPUT)) {
  334. v = readl(msm_chip->regs.oe);
  335. if (flags & GPIOF_DRIVE_OUTPUT) {
  336. writel(v | b, msm_chip->regs.oe);
  337. } else {
  338. writel(v & (~b), msm_chip->regs.oe);
  339. }
  340. }
  341. if (flags & (IRQF_TRIGGER_MASK | GPIOF_IRQF_TRIGGER_NONE)) {
  342. v = readl(msm_chip->regs.int_edge);
  343. if (flags & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING)) {
  344. writel(v | b, msm_chip->regs.int_edge);
  345. irq_desc[MSM_GPIO_TO_INT(gpio)].handle_irq = handle_edge_irq;
  346. } else {
  347. writel(v & (~b), msm_chip->regs.int_edge);
  348. irq_desc[MSM_GPIO_TO_INT(gpio)].handle_irq = handle_level_irq;
  349. }
  350. if ((flags & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING)) == (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING)) {
  351. msm_chip->both_edge_detect |= b;
  352. msm_gpio_update_both_edge_detect(msm_chip);
  353. } else {
  354. msm_chip->both_edge_detect &= ~b;
  355. v = readl(msm_chip->regs.int_pos);
  356. if (flags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_HIGH)) {
  357. writel(v | b, msm_chip->regs.int_pos);
  358. } else {
  359. writel(v & (~b), msm_chip->regs.int_pos);
  360. }
  361. }
  362. }
  363. /* used by msm_gpio_irq_mask and msm_gpio_irq_unmask */
  364. if (flags & (MSM_GPIOF_ENABLE_INTERRUPT | MSM_GPIOF_DISABLE_INTERRUPT)) {
  365. v = readl(msm_chip->regs.int_edge);
  366. /* level triggered interrupts are also latched */
  367. if (!(v & b))
  368. msm_gpio_clear_detect_status(chip, gpio);
  369. if (flags & MSM_GPIOF_ENABLE_INTERRUPT) {
  370. msm_chip->int_enable[0] |= b;
  371. } else {
  372. msm_chip->int_enable[0] &= ~b;
  373. }
  374. writel(msm_chip->int_enable[0], msm_chip->regs.int_en);
  375. }
  376. if (flags & (MSM_GPIOF_ENABLE_WAKE | MSM_GPIOF_DISABLE_WAKE)) {
  377. if (flags & MSM_GPIOF_ENABLE_WAKE)
  378. msm_chip->int_enable[1] |= b;
  379. else
  380. msm_chip->int_enable[1] &= ~b;
  381. }
  382. return 0;
  383. }
  384. static int msm_gpio_get_irq_num(struct goog_gpio_chip *chip,
  385. unsigned int gpio,
  386. unsigned int *irqp,
  387. unsigned long *irqnumflagsp)
  388. {
  389. *irqp = MSM_GPIO_TO_INT(gpio);
  390. if (irqnumflagsp)
  391. *irqnumflagsp = 0;
  392. return 0;
  393. }
  394. static void msm_gpio_irq_ack(unsigned int irq)
  395. {
  396. gpio_clear_detect_status(irq - NR_MSM_IRQS);
  397. }
  398. static void msm_gpio_irq_mask(unsigned int irq)
  399. {
  400. gpio_configure(irq - NR_MSM_IRQS, MSM_GPIOF_DISABLE_INTERRUPT);
  401. }
  402. static void msm_gpio_irq_unmask(unsigned int irq)
  403. {
  404. gpio_configure(irq - NR_MSM_IRQS, MSM_GPIOF_ENABLE_INTERRUPT);
  405. }
  406. static void msm_gpio_irq_disable(unsigned int irq)
  407. {
  408. struct irq_desc *desc = irq_to_desc(irq);
  409. msm_gpio_irq_mask(irq);
  410. desc->status |= IRQ_MASKED;
  411. }
  412. static void msm_gpio_irq_enable(unsigned int irq)
  413. {
  414. struct irq_desc *desc = irq_to_desc(irq);
  415. msm_gpio_irq_unmask(irq);
  416. desc->status &= ~IRQ_MASKED;
  417. }
  418. static int msm_gpio_irq_set_wake(unsigned int irq, unsigned int on)
  419. {
  420. return gpio_configure(irq - NR_MSM_IRQS, on ? MSM_GPIOF_ENABLE_WAKE : MSM_GPIOF_DISABLE_WAKE);
  421. }
  422. static int msm_gpio_irq_set_type(unsigned int irq, unsigned int flow_type)
  423. {
  424. return gpio_configure(irq - NR_MSM_IRQS, flow_type);
  425. }
  426. static void msm_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
  427. {
  428. int i, j, m;
  429. unsigned v;
  430. for (i = 0; i < ARRAY_SIZE(msm_gpio_chips); i++) {
  431. struct msm_gpio_chip *msm_chip = &msm_gpio_chips[i];
  432. v = readl(msm_chip->regs.int_status);
  433. v &= msm_chip->int_enable[0];
  434. while (v) {
  435. m = v & -v;
  436. j = fls(m) - 1;
  437. /* printk("msm_gpio_irq_handler %08x %08x bit %d gpio %d irq %d\n", v, m, j, msm_chip->chip.start + j, NR_MSM_IRQS + msm_chip->chip.start + j); */
  438. v &= ~m;
  439. generic_handle_irq(NR_MSM_IRQS + msm_chip->chip.start + j);
  440. }
  441. }
  442. desc->chip->ack(irq);
  443. }
  444. static struct irq_chip msm_gpio_irq_chip = {
  445. .name = "msmgpio",
  446. .ack = msm_gpio_irq_ack,
  447. .mask = msm_gpio_irq_mask,
  448. .unmask = msm_gpio_irq_unmask,
  449. .disable = msm_gpio_irq_disable,
  450. .enable = msm_gpio_irq_enable,
  451. .set_wake = msm_gpio_irq_set_wake,
  452. .set_type = msm_gpio_irq_set_type,
  453. };
  454. #define NUM_GPIO_SMEM_BANKS 6
  455. #define GPIO_SMEM_NUM_GROUPS 2
  456. #define GPIO_SMEM_MAX_PC_INTERRUPTS 8
  457. struct tramp_gpio_smem
  458. {
  459. uint16_t num_fired[GPIO_SMEM_NUM_GROUPS];
  460. uint16_t fired[GPIO_SMEM_NUM_GROUPS][GPIO_SMEM_MAX_PC_INTERRUPTS];
  461. uint32_t enabled[NUM_GPIO_SMEM_BANKS];
  462. uint32_t detection[NUM_GPIO_SMEM_BANKS];
  463. uint32_t polarity[NUM_GPIO_SMEM_BANKS];
  464. };
  465. static void msm_gpio_sleep_int(unsigned long arg)
  466. {
  467. int i, j;
  468. struct tramp_gpio_smem *smem_gpio;
  469. BUILD_BUG_ON(NR_GPIO_IRQS > NUM_GPIO_SMEM_BANKS * 32);
  470. smem_gpio = smem_alloc(SMEM_GPIO_INT, sizeof(*smem_gpio));
  471. if (smem_gpio == NULL)
  472. return;
  473. local_irq_disable();
  474. for(i = 0; i < GPIO_SMEM_NUM_GROUPS; i++) {
  475. int count = smem_gpio->num_fired[i];
  476. for(j = 0; j < count; j++) {
  477. /* TODO: Check mask */
  478. generic_handle_irq(MSM_GPIO_TO_INT(smem_gpio->fired[i][j]));
  479. }
  480. }
  481. local_irq_enable();
  482. }
  483. static DECLARE_TASKLET(msm_gpio_sleep_int_tasklet, msm_gpio_sleep_int, 0);
  484. void msm_gpio_enter_sleep(int from_idle)
  485. {
  486. int i;
  487. struct tramp_gpio_smem *smem_gpio;
  488. smem_gpio = smem_alloc(SMEM_GPIO_INT, sizeof(*smem_gpio));
  489. if (smem_gpio) {
  490. for (i = 0; i < ARRAY_SIZE(smem_gpio->enabled); i++) {
  491. smem_gpio->enabled[i] = 0;
  492. smem_gpio->detection[i] = 0;
  493. smem_gpio->polarity[i] = 0;
  494. }
  495. }
  496. for (i = 0; i < ARRAY_SIZE(msm_gpio_chips); i++) {
  497. writel(msm_gpio_chips[i].int_enable[!from_idle], msm_gpio_chips[i].regs.int_en);
  498. if (smem_gpio) {
  499. uint32_t tmp;
  500. int start, index, shiftl, shiftr;
  501. start = msm_gpio_chips[i].chip.start;
  502. index = start / 32;
  503. shiftl = start % 32;
  504. shiftr = 32 - shiftl;
  505. tmp = msm_gpio_chips[i].int_enable[!from_idle];
  506. smem_gpio->enabled[index] |= tmp << shiftl;
  507. smem_gpio->enabled[index+1] |= tmp >> shiftr;
  508. smem_gpio->detection[index] |= readl(msm_gpio_chips[i].regs.int_edge) << shiftl;
  509. smem_gpio->detection[index+1] |= readl(msm_gpio_chips[i].regs.int_edge) >> shiftr;
  510. smem_gpio->polarity[index] |= readl(msm_gpio_chips[i].regs.int_pos) << shiftl;
  511. smem_gpio->polarity[index+1] |= readl(msm_gpio_chips[i].regs.int_pos) >> shiftr;
  512. }
  513. }
  514. if (smem_gpio) {
  515. if (msm_gpio_debug_mask & GPIO_DEBUG_SLEEP)
  516. for (i = 0; i < ARRAY_SIZE(smem_gpio->enabled); i++) {
  517. printk("msm_gpio_enter_sleep gpio %d-%d: enable"
  518. " %08x, edge %08x, polarity %08x\n",
  519. i * 32, i * 32 + 31,
  520. smem_gpio->enabled[i],
  521. smem_gpio->detection[i],
  522. smem_gpio->polarity[i]);
  523. }
  524. for(i = 0; i < GPIO_SMEM_NUM_GROUPS; i++)
  525. smem_gpio->num_fired[i] = 0;
  526. }
  527. }
  528. void msm_gpio_exit_sleep(void)
  529. {
  530. int i;
  531. struct tramp_gpio_smem *smem_gpio;
  532. smem_gpio = smem_alloc(SMEM_GPIO_INT, sizeof(*smem_gpio));
  533. for (i = 0; i < ARRAY_SIZE(msm_gpio_chips); i++) {
  534. writel(msm_gpio_chips[i].int_enable[0], msm_gpio_chips[i].regs.int_en);
  535. }
  536. if (smem_gpio && (smem_gpio->num_fired[0] || smem_gpio->num_fired[1])) {
  537. if (msm_gpio_debug_mask & GPIO_DEBUG_SLEEP)
  538. printk(KERN_INFO "gpio: fired %x %x\n",
  539. smem_gpio->num_fired[0], smem_gpio->num_fired[1]);
  540. tasklet_schedule(&msm_gpio_sleep_int_tasklet);
  541. }
  542. }
  543. static int __init msm_init_gpio(void)
  544. {
  545. int i;
  546. for (i = NR_MSM_IRQS; i < NR_MSM_IRQS + NR_GPIO_IRQS; i++) {
  547. set_irq_chip(i, &msm_gpio_irq_chip);
  548. set_irq_handler(i, handle_edge_irq);
  549. set_irq_flags(i, IRQF_VALID);
  550. }
  551. for (i = 0; i < ARRAY_SIZE(msm_gpio_chips); i++) {
  552. writel(0, msm_gpio_chips[i].regs.int_en);
  553. register_gpio_chip(&msm_gpio_chips[i].chip);
  554. }
  555. set_irq_chained_handler(INT_GPIO_GROUP1, msm_gpio_irq_handler);
  556. set_irq_chained_handler(INT_GPIO_GROUP2, msm_gpio_irq_handler);
  557. set_irq_wake(INT_GPIO_GROUP1, 1);
  558. set_irq_wake(INT_GPIO_GROUP2, 2);
  559. return 0;
  560. }
  561. postcore_initcall(msm_init_gpio);
  562. #if defined(CONFIG_DEBUG_FS)
  563. static int msm_gpio_debug_result = 1;
  564. static int gpio_enable_set(void *data, u64 val)
  565. {
  566. msm_gpio_debug_result = gpio_tlmm_config(val, 0);
  567. return 0;
  568. }
  569. static int gpio_disable_set(void *data, u64 val)
  570. {
  571. msm_gpio_debug_result = gpio_tlmm_config(val, 1);
  572. return 0;
  573. }
  574. static int gpio_debug_get(void *data, u64 *val)
  575. {
  576. unsigned int result = msm_gpio_debug_result;
  577. msm_gpio_debug_result = 1;
  578. if (result)
  579. *val = 1;
  580. else
  581. *val = 0;
  582. return 0;
  583. }
  584. DEFINE_SIMPLE_ATTRIBUTE(gpio_enable_fops, gpio_debug_get,
  585. gpio_enable_set, "%llu\n");
  586. DEFINE_SIMPLE_ATTRIBUTE(gpio_disable_fops, gpio_debug_get,
  587. gpio_disable_set, "%llu\n");
  588. static int __init gpio_debug_init(void)
  589. {
  590. struct dentry *dent;
  591. dent = debugfs_create_dir("gpio", 0);
  592. if (IS_ERR(dent))
  593. return 0;
  594. debugfs_create_file("enable", 0644, dent, 0, &gpio_enable_fops);
  595. debugfs_create_file("disable", 0644, dent, 0, &gpio_disable_fops);
  596. return 0;
  597. }
  598. device_initcall(gpio_debug_init);
  599. #endif
  600. #endif