pfc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * Pinmuxed GPIO support for SuperH.
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <linux/list.h>
  14. #include <linux/module.h>
  15. #include <linux/clk.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/irq.h>
  19. #include <linux/bitops.h>
  20. #include <linux/gpio.h>
  21. #include <linux/slab.h>
  22. #include <linux/ioport.h>
  23. static void pfc_iounmap(struct pinmux_info *pip)
  24. {
  25. int k;
  26. for (k = 0; k < pip->num_resources; k++)
  27. if (pip->window[k].virt)
  28. iounmap(pip->window[k].virt);
  29. kfree(pip->window);
  30. pip->window = NULL;
  31. }
  32. static int pfc_ioremap(struct pinmux_info *pip)
  33. {
  34. struct resource *res;
  35. int k;
  36. if (!pip->num_resources)
  37. return 0;
  38. pip->window = kzalloc(pip->num_resources * sizeof(*pip->window),
  39. GFP_NOWAIT);
  40. if (!pip->window)
  41. goto err1;
  42. for (k = 0; k < pip->num_resources; k++) {
  43. res = pip->resource + k;
  44. WARN_ON(resource_type(res) != IORESOURCE_MEM);
  45. pip->window[k].phys = res->start;
  46. pip->window[k].size = resource_size(res);
  47. pip->window[k].virt = ioremap_nocache(res->start,
  48. resource_size(res));
  49. if (!pip->window[k].virt)
  50. goto err2;
  51. }
  52. return 0;
  53. err2:
  54. pfc_iounmap(pip);
  55. err1:
  56. return -1;
  57. }
  58. static void __iomem *pfc_phys_to_virt(struct pinmux_info *pip,
  59. unsigned long address)
  60. {
  61. struct pfc_window *window;
  62. int k;
  63. /* scan through physical windows and convert address */
  64. for (k = 0; k < pip->num_resources; k++) {
  65. window = pip->window + k;
  66. if (address < window->phys)
  67. continue;
  68. if (address >= (window->phys + window->size))
  69. continue;
  70. return window->virt + (address - window->phys);
  71. }
  72. /* no windows defined, register must be 1:1 mapped virt:phys */
  73. return (void __iomem *)address;
  74. }
  75. static int enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r)
  76. {
  77. if (enum_id < r->begin)
  78. return 0;
  79. if (enum_id > r->end)
  80. return 0;
  81. return 1;
  82. }
  83. static unsigned long gpio_read_raw_reg(void __iomem *mapped_reg,
  84. unsigned long reg_width)
  85. {
  86. switch (reg_width) {
  87. case 8:
  88. return ioread8(mapped_reg);
  89. case 16:
  90. return ioread16(mapped_reg);
  91. case 32:
  92. return ioread32(mapped_reg);
  93. }
  94. BUG();
  95. return 0;
  96. }
  97. static void gpio_write_raw_reg(void __iomem *mapped_reg,
  98. unsigned long reg_width,
  99. unsigned long data)
  100. {
  101. switch (reg_width) {
  102. case 8:
  103. iowrite8(data, mapped_reg);
  104. return;
  105. case 16:
  106. iowrite16(data, mapped_reg);
  107. return;
  108. case 32:
  109. iowrite32(data, mapped_reg);
  110. return;
  111. }
  112. BUG();
  113. }
  114. static int gpio_read_bit(struct pinmux_data_reg *dr,
  115. unsigned long in_pos)
  116. {
  117. unsigned long pos;
  118. pos = dr->reg_width - (in_pos + 1);
  119. pr_debug("read_bit: addr = %lx, pos = %ld, "
  120. "r_width = %ld\n", dr->reg, pos, dr->reg_width);
  121. return (gpio_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1;
  122. }
  123. static void gpio_write_bit(struct pinmux_data_reg *dr,
  124. unsigned long in_pos, unsigned long value)
  125. {
  126. unsigned long pos;
  127. pos = dr->reg_width - (in_pos + 1);
  128. pr_debug("write_bit addr = %lx, value = %d, pos = %ld, "
  129. "r_width = %ld\n",
  130. dr->reg, !!value, pos, dr->reg_width);
  131. if (value)
  132. set_bit(pos, &dr->reg_shadow);
  133. else
  134. clear_bit(pos, &dr->reg_shadow);
  135. gpio_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow);
  136. }
  137. static int gpio_read_reg(void __iomem *mapped_reg, unsigned long reg_width,
  138. unsigned long field_width, unsigned long in_pos,
  139. unsigned long reg)
  140. {
  141. unsigned long data, mask, pos;
  142. data = 0;
  143. mask = (1 << field_width) - 1;
  144. pos = reg_width - ((in_pos + 1) * field_width);
  145. pr_debug("read_reg: addr = %lx, pos = %ld, "
  146. "r_width = %ld, f_width = %ld\n",
  147. reg, pos, reg_width, field_width);
  148. data = gpio_read_raw_reg(mapped_reg, reg_width);
  149. return (data >> pos) & mask;
  150. }
  151. static void gpio_write_reg(void __iomem *mapped_reg, unsigned long reg_width,
  152. unsigned long field_width, unsigned long in_pos,
  153. unsigned long value, unsigned long reg)
  154. {
  155. unsigned long mask, pos;
  156. mask = (1 << field_width) - 1;
  157. pos = reg_width - ((in_pos + 1) * field_width);
  158. pr_debug("write_reg addr = %lx, value = %ld, pos = %ld, "
  159. "r_width = %ld, f_width = %ld\n",
  160. reg, value, pos, reg_width, field_width);
  161. mask = ~(mask << pos);
  162. value = value << pos;
  163. switch (reg_width) {
  164. case 8:
  165. iowrite8((ioread8(mapped_reg) & mask) | value, mapped_reg);
  166. break;
  167. case 16:
  168. iowrite16((ioread16(mapped_reg) & mask) | value, mapped_reg);
  169. break;
  170. case 32:
  171. iowrite32((ioread32(mapped_reg) & mask) | value, mapped_reg);
  172. break;
  173. }
  174. }
  175. static int setup_data_reg(struct pinmux_info *gpioc, unsigned gpio)
  176. {
  177. struct pinmux_gpio *gpiop = &gpioc->gpios[gpio];
  178. struct pinmux_data_reg *data_reg;
  179. int k, n;
  180. if (!enum_in_range(gpiop->enum_id, &gpioc->data))
  181. return -1;
  182. k = 0;
  183. while (1) {
  184. data_reg = gpioc->data_regs + k;
  185. if (!data_reg->reg_width)
  186. break;
  187. data_reg->mapped_reg = pfc_phys_to_virt(gpioc, data_reg->reg);
  188. for (n = 0; n < data_reg->reg_width; n++) {
  189. if (data_reg->enum_ids[n] == gpiop->enum_id) {
  190. gpiop->flags &= ~PINMUX_FLAG_DREG;
  191. gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT);
  192. gpiop->flags &= ~PINMUX_FLAG_DBIT;
  193. gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT);
  194. return 0;
  195. }
  196. }
  197. k++;
  198. }
  199. BUG();
  200. return -1;
  201. }
  202. static void setup_data_regs(struct pinmux_info *gpioc)
  203. {
  204. struct pinmux_data_reg *drp;
  205. int k;
  206. for (k = gpioc->first_gpio; k <= gpioc->last_gpio; k++)
  207. setup_data_reg(gpioc, k);
  208. k = 0;
  209. while (1) {
  210. drp = gpioc->data_regs + k;
  211. if (!drp->reg_width)
  212. break;
  213. drp->reg_shadow = gpio_read_raw_reg(drp->mapped_reg,
  214. drp->reg_width);
  215. k++;
  216. }
  217. }
  218. static int get_data_reg(struct pinmux_info *gpioc, unsigned gpio,
  219. struct pinmux_data_reg **drp, int *bitp)
  220. {
  221. struct pinmux_gpio *gpiop = &gpioc->gpios[gpio];
  222. int k, n;
  223. if (!enum_in_range(gpiop->enum_id, &gpioc->data))
  224. return -1;
  225. k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
  226. n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
  227. *drp = gpioc->data_regs + k;
  228. *bitp = n;
  229. return 0;
  230. }
  231. static int get_config_reg(struct pinmux_info *gpioc, pinmux_enum_t enum_id,
  232. struct pinmux_cfg_reg **crp, int *indexp,
  233. unsigned long **cntp)
  234. {
  235. struct pinmux_cfg_reg *config_reg;
  236. unsigned long r_width, f_width;
  237. int k, n;
  238. k = 0;
  239. while (1) {
  240. config_reg = gpioc->cfg_regs + k;
  241. r_width = config_reg->reg_width;
  242. f_width = config_reg->field_width;
  243. if (!r_width)
  244. break;
  245. for (n = 0; n < (r_width / f_width) * (1 << f_width); n++) {
  246. if (config_reg->enum_ids[n] == enum_id) {
  247. *crp = config_reg;
  248. *indexp = n;
  249. *cntp = &config_reg->cnt[n / (1 << f_width)];
  250. return 0;
  251. }
  252. }
  253. k++;
  254. }
  255. return -1;
  256. }
  257. static int get_gpio_enum_id(struct pinmux_info *gpioc, unsigned gpio,
  258. int pos, pinmux_enum_t *enum_idp)
  259. {
  260. pinmux_enum_t enum_id = gpioc->gpios[gpio].enum_id;
  261. pinmux_enum_t *data = gpioc->gpio_data;
  262. int k;
  263. if (!enum_in_range(enum_id, &gpioc->data)) {
  264. if (!enum_in_range(enum_id, &gpioc->mark)) {
  265. pr_err("non data/mark enum_id for gpio %d\n", gpio);
  266. return -1;
  267. }
  268. }
  269. if (pos) {
  270. *enum_idp = data[pos + 1];
  271. return pos + 1;
  272. }
  273. for (k = 0; k < gpioc->gpio_data_size; k++) {
  274. if (data[k] == enum_id) {
  275. *enum_idp = data[k + 1];
  276. return k + 1;
  277. }
  278. }
  279. pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio);
  280. return -1;
  281. }
  282. static void write_config_reg(struct pinmux_info *gpioc,
  283. struct pinmux_cfg_reg *crp,
  284. int index)
  285. {
  286. unsigned long ncomb, pos, value;
  287. void __iomem *mapped_reg;
  288. ncomb = 1 << crp->field_width;
  289. pos = index / ncomb;
  290. value = index % ncomb;
  291. mapped_reg = pfc_phys_to_virt(gpioc, crp->reg);
  292. gpio_write_reg(mapped_reg, crp->reg_width, crp->field_width,
  293. pos, value, crp->reg);
  294. }
  295. static int check_config_reg(struct pinmux_info *gpioc,
  296. struct pinmux_cfg_reg *crp,
  297. int index)
  298. {
  299. unsigned long ncomb, pos, value;
  300. void __iomem *mapped_reg;
  301. ncomb = 1 << crp->field_width;
  302. pos = index / ncomb;
  303. value = index % ncomb;
  304. mapped_reg = pfc_phys_to_virt(gpioc, crp->reg);
  305. if (gpio_read_reg(mapped_reg, crp->reg_width,
  306. crp->field_width, pos, crp->reg) == value)
  307. return 0;
  308. return -1;
  309. }
  310. enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
  311. static int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio,
  312. int pinmux_type, int cfg_mode)
  313. {
  314. struct pinmux_cfg_reg *cr = NULL;
  315. pinmux_enum_t enum_id;
  316. struct pinmux_range *range;
  317. int in_range, pos, index;
  318. unsigned long *cntp;
  319. switch (pinmux_type) {
  320. case PINMUX_TYPE_FUNCTION:
  321. range = NULL;
  322. break;
  323. case PINMUX_TYPE_OUTPUT:
  324. range = &gpioc->output;
  325. break;
  326. case PINMUX_TYPE_INPUT:
  327. range = &gpioc->input;
  328. break;
  329. case PINMUX_TYPE_INPUT_PULLUP:
  330. range = &gpioc->input_pu;
  331. break;
  332. case PINMUX_TYPE_INPUT_PULLDOWN:
  333. range = &gpioc->input_pd;
  334. break;
  335. default:
  336. goto out_err;
  337. }
  338. pos = 0;
  339. enum_id = 0;
  340. index = 0;
  341. while (1) {
  342. pos = get_gpio_enum_id(gpioc, gpio, pos, &enum_id);
  343. if (pos <= 0)
  344. goto out_err;
  345. if (!enum_id)
  346. break;
  347. /* first check if this is a function enum */
  348. in_range = enum_in_range(enum_id, &gpioc->function);
  349. if (!in_range) {
  350. /* not a function enum */
  351. if (range) {
  352. /*
  353. * other range exists, so this pin is
  354. * a regular GPIO pin that now is being
  355. * bound to a specific direction.
  356. *
  357. * for this case we only allow function enums
  358. * and the enums that match the other range.
  359. */
  360. in_range = enum_in_range(enum_id, range);
  361. /*
  362. * special case pass through for fixed
  363. * input-only or output-only pins without
  364. * function enum register association.
  365. */
  366. if (in_range && enum_id == range->force)
  367. continue;
  368. } else {
  369. /*
  370. * no other range exists, so this pin
  371. * must then be of the function type.
  372. *
  373. * allow function type pins to select
  374. * any combination of function/in/out
  375. * in their MARK lists.
  376. */
  377. in_range = 1;
  378. }
  379. }
  380. if (!in_range)
  381. continue;
  382. if (get_config_reg(gpioc, enum_id, &cr, &index, &cntp) != 0)
  383. goto out_err;
  384. switch (cfg_mode) {
  385. case GPIO_CFG_DRYRUN:
  386. if (!*cntp || !check_config_reg(gpioc, cr, index))
  387. continue;
  388. break;
  389. case GPIO_CFG_REQ:
  390. write_config_reg(gpioc, cr, index);
  391. *cntp = *cntp + 1;
  392. break;
  393. case GPIO_CFG_FREE:
  394. *cntp = *cntp - 1;
  395. break;
  396. }
  397. }
  398. return 0;
  399. out_err:
  400. return -1;
  401. }
  402. static DEFINE_SPINLOCK(gpio_lock);
  403. static struct pinmux_info *chip_to_pinmux(struct gpio_chip *chip)
  404. {
  405. return container_of(chip, struct pinmux_info, chip);
  406. }
  407. static int sh_gpio_request(struct gpio_chip *chip, unsigned offset)
  408. {
  409. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  410. struct pinmux_data_reg *dummy;
  411. unsigned long flags;
  412. int i, ret, pinmux_type;
  413. ret = -EINVAL;
  414. if (!gpioc)
  415. goto err_out;
  416. spin_lock_irqsave(&gpio_lock, flags);
  417. if ((gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE) != PINMUX_TYPE_NONE)
  418. goto err_unlock;
  419. /* setup pin function here if no data is associated with pin */
  420. if (get_data_reg(gpioc, offset, &dummy, &i) != 0)
  421. pinmux_type = PINMUX_TYPE_FUNCTION;
  422. else
  423. pinmux_type = PINMUX_TYPE_GPIO;
  424. if (pinmux_type == PINMUX_TYPE_FUNCTION) {
  425. if (pinmux_config_gpio(gpioc, offset,
  426. pinmux_type,
  427. GPIO_CFG_DRYRUN) != 0)
  428. goto err_unlock;
  429. if (pinmux_config_gpio(gpioc, offset,
  430. pinmux_type,
  431. GPIO_CFG_REQ) != 0)
  432. BUG();
  433. }
  434. gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
  435. gpioc->gpios[offset].flags |= pinmux_type;
  436. ret = 0;
  437. err_unlock:
  438. spin_unlock_irqrestore(&gpio_lock, flags);
  439. err_out:
  440. return ret;
  441. }
  442. static void sh_gpio_free(struct gpio_chip *chip, unsigned offset)
  443. {
  444. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  445. unsigned long flags;
  446. int pinmux_type;
  447. if (!gpioc)
  448. return;
  449. spin_lock_irqsave(&gpio_lock, flags);
  450. pinmux_type = gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE;
  451. pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_FREE);
  452. gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
  453. gpioc->gpios[offset].flags |= PINMUX_TYPE_NONE;
  454. spin_unlock_irqrestore(&gpio_lock, flags);
  455. }
  456. static int pinmux_direction(struct pinmux_info *gpioc,
  457. unsigned gpio, int new_pinmux_type)
  458. {
  459. int pinmux_type;
  460. int ret = -EINVAL;
  461. if (!gpioc)
  462. goto err_out;
  463. pinmux_type = gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE;
  464. switch (pinmux_type) {
  465. case PINMUX_TYPE_GPIO:
  466. break;
  467. case PINMUX_TYPE_OUTPUT:
  468. case PINMUX_TYPE_INPUT:
  469. case PINMUX_TYPE_INPUT_PULLUP:
  470. case PINMUX_TYPE_INPUT_PULLDOWN:
  471. pinmux_config_gpio(gpioc, gpio, pinmux_type, GPIO_CFG_FREE);
  472. break;
  473. default:
  474. goto err_out;
  475. }
  476. if (pinmux_config_gpio(gpioc, gpio,
  477. new_pinmux_type,
  478. GPIO_CFG_DRYRUN) != 0)
  479. goto err_out;
  480. if (pinmux_config_gpio(gpioc, gpio,
  481. new_pinmux_type,
  482. GPIO_CFG_REQ) != 0)
  483. BUG();
  484. gpioc->gpios[gpio].flags &= ~PINMUX_FLAG_TYPE;
  485. gpioc->gpios[gpio].flags |= new_pinmux_type;
  486. ret = 0;
  487. err_out:
  488. return ret;
  489. }
  490. static int sh_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  491. {
  492. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  493. unsigned long flags;
  494. int ret;
  495. spin_lock_irqsave(&gpio_lock, flags);
  496. ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_INPUT);
  497. spin_unlock_irqrestore(&gpio_lock, flags);
  498. return ret;
  499. }
  500. static void sh_gpio_set_value(struct pinmux_info *gpioc,
  501. unsigned gpio, int value)
  502. {
  503. struct pinmux_data_reg *dr = NULL;
  504. int bit = 0;
  505. if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
  506. BUG();
  507. else
  508. gpio_write_bit(dr, bit, value);
  509. }
  510. static int sh_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  511. int value)
  512. {
  513. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  514. unsigned long flags;
  515. int ret;
  516. sh_gpio_set_value(gpioc, offset, value);
  517. spin_lock_irqsave(&gpio_lock, flags);
  518. ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_OUTPUT);
  519. spin_unlock_irqrestore(&gpio_lock, flags);
  520. return ret;
  521. }
  522. static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio)
  523. {
  524. struct pinmux_data_reg *dr = NULL;
  525. int bit = 0;
  526. if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
  527. return -EINVAL;
  528. return gpio_read_bit(dr, bit);
  529. }
  530. static int sh_gpio_get(struct gpio_chip *chip, unsigned offset)
  531. {
  532. return sh_gpio_get_value(chip_to_pinmux(chip), offset);
  533. }
  534. static void sh_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  535. {
  536. sh_gpio_set_value(chip_to_pinmux(chip), offset, value);
  537. }
  538. static int sh_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  539. {
  540. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  541. pinmux_enum_t enum_id;
  542. pinmux_enum_t *enum_ids;
  543. int i, k, pos;
  544. pos = 0;
  545. enum_id = 0;
  546. while (1) {
  547. pos = get_gpio_enum_id(gpioc, offset, pos, &enum_id);
  548. if (pos <= 0 || !enum_id)
  549. break;
  550. for (i = 0; i < gpioc->gpio_irq_size; i++) {
  551. enum_ids = gpioc->gpio_irq[i].enum_ids;
  552. for (k = 0; enum_ids[k]; k++) {
  553. if (enum_ids[k] == enum_id)
  554. return gpioc->gpio_irq[i].irq;
  555. }
  556. }
  557. }
  558. return -ENOSYS;
  559. }
  560. int register_pinmux(struct pinmux_info *pip)
  561. {
  562. struct gpio_chip *chip = &pip->chip;
  563. int ret;
  564. pr_info("%s handling gpio %d -> %d\n",
  565. pip->name, pip->first_gpio, pip->last_gpio);
  566. ret = pfc_ioremap(pip);
  567. if (ret < 0)
  568. return ret;
  569. setup_data_regs(pip);
  570. chip->request = sh_gpio_request;
  571. chip->free = sh_gpio_free;
  572. chip->direction_input = sh_gpio_direction_input;
  573. chip->get = sh_gpio_get;
  574. chip->direction_output = sh_gpio_direction_output;
  575. chip->set = sh_gpio_set;
  576. chip->to_irq = sh_gpio_to_irq;
  577. WARN_ON(pip->first_gpio != 0); /* needs testing */
  578. chip->label = pip->name;
  579. chip->owner = THIS_MODULE;
  580. chip->base = pip->first_gpio;
  581. chip->ngpio = (pip->last_gpio - pip->first_gpio) + 1;
  582. ret = gpiochip_add(chip);
  583. if (ret < 0)
  584. pfc_iounmap(pip);
  585. return ret;
  586. }
  587. int unregister_pinmux(struct pinmux_info *pip)
  588. {
  589. pr_info("%s deregistering\n", pip->name);
  590. pfc_iounmap(pip);
  591. return gpiochip_remove(&pip->chip);
  592. }