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 void config_reg_helper(struct pinmux_info *gpioc,
  138. struct pinmux_cfg_reg *crp,
  139. unsigned long in_pos,
  140. void __iomem **mapped_regp,
  141. unsigned long *maskp,
  142. unsigned long *posp)
  143. {
  144. int k;
  145. *mapped_regp = pfc_phys_to_virt(gpioc, crp->reg);
  146. if (crp->field_width) {
  147. *maskp = (1 << crp->field_width) - 1;
  148. *posp = crp->reg_width - ((in_pos + 1) * crp->field_width);
  149. } else {
  150. *maskp = (1 << crp->var_field_width[in_pos]) - 1;
  151. *posp = crp->reg_width;
  152. for (k = 0; k <= in_pos; k++)
  153. *posp -= crp->var_field_width[k];
  154. }
  155. }
  156. static int read_config_reg(struct pinmux_info *gpioc,
  157. struct pinmux_cfg_reg *crp,
  158. unsigned long field)
  159. {
  160. void __iomem *mapped_reg;
  161. unsigned long mask, pos;
  162. config_reg_helper(gpioc, crp, field, &mapped_reg, &mask, &pos);
  163. pr_debug("read_reg: addr = %lx, field = %ld, "
  164. "r_width = %ld, f_width = %ld\n",
  165. crp->reg, field, crp->reg_width, crp->field_width);
  166. return (gpio_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask;
  167. }
  168. static void write_config_reg(struct pinmux_info *gpioc,
  169. struct pinmux_cfg_reg *crp,
  170. unsigned long field, unsigned long value)
  171. {
  172. void __iomem *mapped_reg;
  173. unsigned long mask, pos, data;
  174. config_reg_helper(gpioc, crp, field, &mapped_reg, &mask, &pos);
  175. pr_debug("write_reg addr = %lx, value = %ld, field = %ld, "
  176. "r_width = %ld, f_width = %ld\n",
  177. crp->reg, value, field, crp->reg_width, crp->field_width);
  178. mask = ~(mask << pos);
  179. value = value << pos;
  180. data = gpio_read_raw_reg(mapped_reg, crp->reg_width);
  181. data &= mask;
  182. data |= value;
  183. if (gpioc->unlock_reg)
  184. gpio_write_raw_reg(pfc_phys_to_virt(gpioc, gpioc->unlock_reg),
  185. 32, ~data);
  186. gpio_write_raw_reg(mapped_reg, crp->reg_width, data);
  187. }
  188. static int setup_data_reg(struct pinmux_info *gpioc, unsigned gpio)
  189. {
  190. struct pinmux_gpio *gpiop = &gpioc->gpios[gpio];
  191. struct pinmux_data_reg *data_reg;
  192. int k, n;
  193. if (!enum_in_range(gpiop->enum_id, &gpioc->data))
  194. return -1;
  195. k = 0;
  196. while (1) {
  197. data_reg = gpioc->data_regs + k;
  198. if (!data_reg->reg_width)
  199. break;
  200. data_reg->mapped_reg = pfc_phys_to_virt(gpioc, data_reg->reg);
  201. for (n = 0; n < data_reg->reg_width; n++) {
  202. if (data_reg->enum_ids[n] == gpiop->enum_id) {
  203. gpiop->flags &= ~PINMUX_FLAG_DREG;
  204. gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT);
  205. gpiop->flags &= ~PINMUX_FLAG_DBIT;
  206. gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT);
  207. return 0;
  208. }
  209. }
  210. k++;
  211. }
  212. BUG();
  213. return -1;
  214. }
  215. static void setup_data_regs(struct pinmux_info *gpioc)
  216. {
  217. struct pinmux_data_reg *drp;
  218. int k;
  219. for (k = gpioc->first_gpio; k <= gpioc->last_gpio; k++)
  220. setup_data_reg(gpioc, k);
  221. k = 0;
  222. while (1) {
  223. drp = gpioc->data_regs + k;
  224. if (!drp->reg_width)
  225. break;
  226. drp->reg_shadow = gpio_read_raw_reg(drp->mapped_reg,
  227. drp->reg_width);
  228. k++;
  229. }
  230. }
  231. static int get_data_reg(struct pinmux_info *gpioc, unsigned gpio,
  232. struct pinmux_data_reg **drp, int *bitp)
  233. {
  234. struct pinmux_gpio *gpiop = &gpioc->gpios[gpio];
  235. int k, n;
  236. if (!enum_in_range(gpiop->enum_id, &gpioc->data))
  237. return -1;
  238. k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
  239. n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
  240. *drp = gpioc->data_regs + k;
  241. *bitp = n;
  242. return 0;
  243. }
  244. static int get_config_reg(struct pinmux_info *gpioc, pinmux_enum_t enum_id,
  245. struct pinmux_cfg_reg **crp,
  246. int *fieldp, int *valuep,
  247. unsigned long **cntp)
  248. {
  249. struct pinmux_cfg_reg *config_reg;
  250. unsigned long r_width, f_width, curr_width, ncomb;
  251. int k, m, n, pos, bit_pos;
  252. k = 0;
  253. while (1) {
  254. config_reg = gpioc->cfg_regs + k;
  255. r_width = config_reg->reg_width;
  256. f_width = config_reg->field_width;
  257. if (!r_width)
  258. break;
  259. pos = 0;
  260. m = 0;
  261. for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) {
  262. if (f_width)
  263. curr_width = f_width;
  264. else
  265. curr_width = config_reg->var_field_width[m];
  266. ncomb = 1 << curr_width;
  267. for (n = 0; n < ncomb; n++) {
  268. if (config_reg->enum_ids[pos + n] == enum_id) {
  269. *crp = config_reg;
  270. *fieldp = m;
  271. *valuep = n;
  272. *cntp = &config_reg->cnt[m];
  273. return 0;
  274. }
  275. }
  276. pos += ncomb;
  277. m++;
  278. }
  279. k++;
  280. }
  281. return -1;
  282. }
  283. static int get_gpio_enum_id(struct pinmux_info *gpioc, unsigned gpio,
  284. int pos, pinmux_enum_t *enum_idp)
  285. {
  286. pinmux_enum_t enum_id = gpioc->gpios[gpio].enum_id;
  287. pinmux_enum_t *data = gpioc->gpio_data;
  288. int k;
  289. if (!enum_in_range(enum_id, &gpioc->data)) {
  290. if (!enum_in_range(enum_id, &gpioc->mark)) {
  291. pr_err("non data/mark enum_id for gpio %d\n", gpio);
  292. return -1;
  293. }
  294. }
  295. if (pos) {
  296. *enum_idp = data[pos + 1];
  297. return pos + 1;
  298. }
  299. for (k = 0; k < gpioc->gpio_data_size; k++) {
  300. if (data[k] == enum_id) {
  301. *enum_idp = data[k + 1];
  302. return k + 1;
  303. }
  304. }
  305. pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio);
  306. return -1;
  307. }
  308. enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
  309. static int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio,
  310. int pinmux_type, int cfg_mode)
  311. {
  312. struct pinmux_cfg_reg *cr = NULL;
  313. pinmux_enum_t enum_id;
  314. struct pinmux_range *range;
  315. int in_range, pos, field, value;
  316. unsigned long *cntp;
  317. switch (pinmux_type) {
  318. case PINMUX_TYPE_FUNCTION:
  319. range = NULL;
  320. break;
  321. case PINMUX_TYPE_OUTPUT:
  322. range = &gpioc->output;
  323. break;
  324. case PINMUX_TYPE_INPUT:
  325. range = &gpioc->input;
  326. break;
  327. case PINMUX_TYPE_INPUT_PULLUP:
  328. range = &gpioc->input_pu;
  329. break;
  330. case PINMUX_TYPE_INPUT_PULLDOWN:
  331. range = &gpioc->input_pd;
  332. break;
  333. default:
  334. goto out_err;
  335. }
  336. pos = 0;
  337. enum_id = 0;
  338. field = 0;
  339. value = 0;
  340. while (1) {
  341. pos = get_gpio_enum_id(gpioc, gpio, pos, &enum_id);
  342. if (pos <= 0)
  343. goto out_err;
  344. if (!enum_id)
  345. break;
  346. /* first check if this is a function enum */
  347. in_range = enum_in_range(enum_id, &gpioc->function);
  348. if (!in_range) {
  349. /* not a function enum */
  350. if (range) {
  351. /*
  352. * other range exists, so this pin is
  353. * a regular GPIO pin that now is being
  354. * bound to a specific direction.
  355. *
  356. * for this case we only allow function enums
  357. * and the enums that match the other range.
  358. */
  359. in_range = enum_in_range(enum_id, range);
  360. /*
  361. * special case pass through for fixed
  362. * input-only or output-only pins without
  363. * function enum register association.
  364. */
  365. if (in_range && enum_id == range->force)
  366. continue;
  367. } else {
  368. /*
  369. * no other range exists, so this pin
  370. * must then be of the function type.
  371. *
  372. * allow function type pins to select
  373. * any combination of function/in/out
  374. * in their MARK lists.
  375. */
  376. in_range = 1;
  377. }
  378. }
  379. if (!in_range)
  380. continue;
  381. if (get_config_reg(gpioc, enum_id, &cr,
  382. &field, &value, &cntp) != 0)
  383. goto out_err;
  384. switch (cfg_mode) {
  385. case GPIO_CFG_DRYRUN:
  386. if (!*cntp ||
  387. (read_config_reg(gpioc, cr, field) != value))
  388. continue;
  389. break;
  390. case GPIO_CFG_REQ:
  391. write_config_reg(gpioc, cr, field, value);
  392. *cntp = *cntp + 1;
  393. break;
  394. case GPIO_CFG_FREE:
  395. *cntp = *cntp - 1;
  396. break;
  397. }
  398. }
  399. return 0;
  400. out_err:
  401. return -1;
  402. }
  403. static DEFINE_SPINLOCK(gpio_lock);
  404. static struct pinmux_info *chip_to_pinmux(struct gpio_chip *chip)
  405. {
  406. return container_of(chip, struct pinmux_info, chip);
  407. }
  408. static int sh_gpio_request(struct gpio_chip *chip, unsigned offset)
  409. {
  410. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  411. struct pinmux_data_reg *dummy;
  412. unsigned long flags;
  413. int i, ret, pinmux_type;
  414. ret = -EINVAL;
  415. if (!gpioc)
  416. goto err_out;
  417. spin_lock_irqsave(&gpio_lock, flags);
  418. if ((gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE) != PINMUX_TYPE_NONE)
  419. goto err_unlock;
  420. /* setup pin function here if no data is associated with pin */
  421. if (get_data_reg(gpioc, offset, &dummy, &i) != 0)
  422. pinmux_type = PINMUX_TYPE_FUNCTION;
  423. else
  424. pinmux_type = PINMUX_TYPE_GPIO;
  425. if (pinmux_type == PINMUX_TYPE_FUNCTION) {
  426. if (pinmux_config_gpio(gpioc, offset,
  427. pinmux_type,
  428. GPIO_CFG_DRYRUN) != 0)
  429. goto err_unlock;
  430. if (pinmux_config_gpio(gpioc, offset,
  431. pinmux_type,
  432. GPIO_CFG_REQ) != 0)
  433. BUG();
  434. }
  435. gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
  436. gpioc->gpios[offset].flags |= pinmux_type;
  437. ret = 0;
  438. err_unlock:
  439. spin_unlock_irqrestore(&gpio_lock, flags);
  440. err_out:
  441. return ret;
  442. }
  443. static void sh_gpio_free(struct gpio_chip *chip, unsigned offset)
  444. {
  445. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  446. unsigned long flags;
  447. int pinmux_type;
  448. if (!gpioc)
  449. return;
  450. spin_lock_irqsave(&gpio_lock, flags);
  451. pinmux_type = gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE;
  452. pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_FREE);
  453. gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
  454. gpioc->gpios[offset].flags |= PINMUX_TYPE_NONE;
  455. spin_unlock_irqrestore(&gpio_lock, flags);
  456. }
  457. static int pinmux_direction(struct pinmux_info *gpioc,
  458. unsigned gpio, int new_pinmux_type)
  459. {
  460. int pinmux_type;
  461. int ret = -EINVAL;
  462. if (!gpioc)
  463. goto err_out;
  464. pinmux_type = gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE;
  465. switch (pinmux_type) {
  466. case PINMUX_TYPE_GPIO:
  467. break;
  468. case PINMUX_TYPE_OUTPUT:
  469. case PINMUX_TYPE_INPUT:
  470. case PINMUX_TYPE_INPUT_PULLUP:
  471. case PINMUX_TYPE_INPUT_PULLDOWN:
  472. pinmux_config_gpio(gpioc, gpio, pinmux_type, GPIO_CFG_FREE);
  473. break;
  474. default:
  475. goto err_out;
  476. }
  477. if (pinmux_config_gpio(gpioc, gpio,
  478. new_pinmux_type,
  479. GPIO_CFG_DRYRUN) != 0)
  480. goto err_out;
  481. if (pinmux_config_gpio(gpioc, gpio,
  482. new_pinmux_type,
  483. GPIO_CFG_REQ) != 0)
  484. BUG();
  485. gpioc->gpios[gpio].flags &= ~PINMUX_FLAG_TYPE;
  486. gpioc->gpios[gpio].flags |= new_pinmux_type;
  487. ret = 0;
  488. err_out:
  489. return ret;
  490. }
  491. static int sh_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  492. {
  493. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  494. unsigned long flags;
  495. int ret;
  496. spin_lock_irqsave(&gpio_lock, flags);
  497. ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_INPUT);
  498. spin_unlock_irqrestore(&gpio_lock, flags);
  499. return ret;
  500. }
  501. static void sh_gpio_set_value(struct pinmux_info *gpioc,
  502. unsigned gpio, int value)
  503. {
  504. struct pinmux_data_reg *dr = NULL;
  505. int bit = 0;
  506. if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
  507. BUG();
  508. else
  509. gpio_write_bit(dr, bit, value);
  510. }
  511. static int sh_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  512. int value)
  513. {
  514. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  515. unsigned long flags;
  516. int ret;
  517. sh_gpio_set_value(gpioc, offset, value);
  518. spin_lock_irqsave(&gpio_lock, flags);
  519. ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_OUTPUT);
  520. spin_unlock_irqrestore(&gpio_lock, flags);
  521. return ret;
  522. }
  523. static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio)
  524. {
  525. struct pinmux_data_reg *dr = NULL;
  526. int bit = 0;
  527. if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
  528. return -EINVAL;
  529. return gpio_read_bit(dr, bit);
  530. }
  531. static int sh_gpio_get(struct gpio_chip *chip, unsigned offset)
  532. {
  533. return sh_gpio_get_value(chip_to_pinmux(chip), offset);
  534. }
  535. static void sh_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  536. {
  537. sh_gpio_set_value(chip_to_pinmux(chip), offset, value);
  538. }
  539. static int sh_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  540. {
  541. struct pinmux_info *gpioc = chip_to_pinmux(chip);
  542. pinmux_enum_t enum_id;
  543. pinmux_enum_t *enum_ids;
  544. int i, k, pos;
  545. pos = 0;
  546. enum_id = 0;
  547. while (1) {
  548. pos = get_gpio_enum_id(gpioc, offset, pos, &enum_id);
  549. if (pos <= 0 || !enum_id)
  550. break;
  551. for (i = 0; i < gpioc->gpio_irq_size; i++) {
  552. enum_ids = gpioc->gpio_irq[i].enum_ids;
  553. for (k = 0; enum_ids[k]; k++) {
  554. if (enum_ids[k] == enum_id)
  555. return gpioc->gpio_irq[i].irq;
  556. }
  557. }
  558. }
  559. return -ENOSYS;
  560. }
  561. int register_pinmux(struct pinmux_info *pip)
  562. {
  563. struct gpio_chip *chip = &pip->chip;
  564. int ret;
  565. pr_info("%s handling gpio %d -> %d\n",
  566. pip->name, pip->first_gpio, pip->last_gpio);
  567. ret = pfc_ioremap(pip);
  568. if (ret < 0)
  569. return ret;
  570. setup_data_regs(pip);
  571. chip->request = sh_gpio_request;
  572. chip->free = sh_gpio_free;
  573. chip->direction_input = sh_gpio_direction_input;
  574. chip->get = sh_gpio_get;
  575. chip->direction_output = sh_gpio_direction_output;
  576. chip->set = sh_gpio_set;
  577. chip->to_irq = sh_gpio_to_irq;
  578. WARN_ON(pip->first_gpio != 0); /* needs testing */
  579. chip->label = pip->name;
  580. chip->owner = THIS_MODULE;
  581. chip->base = pip->first_gpio;
  582. chip->ngpio = (pip->last_gpio - pip->first_gpio) + 1;
  583. ret = gpiochip_add(chip);
  584. if (ret < 0)
  585. pfc_iounmap(pip);
  586. return ret;
  587. }
  588. int unregister_pinmux(struct pinmux_info *pip)
  589. {
  590. pr_info("%s deregistering\n", pip->name);
  591. pfc_iounmap(pip);
  592. return gpiochip_remove(&pip->chip);
  593. }