gpio.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
  5. */
  6. #ifndef _ASM_GENERIC_GPIO_H_
  7. #define _ASM_GENERIC_GPIO_H_
  8. #include <dm/ofnode.h>
  9. struct ofnode_phandle_args;
  10. /*
  11. * Generic GPIO API for U-Boot
  12. *
  13. * --
  14. * NB: This is deprecated. Please use the driver model functions instead:
  15. *
  16. * - gpio_request_by_name()
  17. * - dm_gpio_get_value() etc.
  18. *
  19. * For now we need a dm_ prefix on some functions to avoid name collision.
  20. * --
  21. *
  22. * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
  23. * by the SOC/architecture.
  24. *
  25. * Each GPIO can be an input or output. If an input then its value can
  26. * be read as 0 or 1. If an output then its value can be set to 0 or 1.
  27. * If you try to write an input then the value is undefined. If you try
  28. * to read an output, barring something very unusual, you will get
  29. * back the value of the output that you previously set.
  30. *
  31. * In some cases the operation may fail, for example if the GPIO number
  32. * is out of range, or the GPIO is not available because its pin is
  33. * being used by another function. In that case, functions may return
  34. * an error value of -1.
  35. */
  36. /**
  37. * @deprecated Please use driver model instead
  38. * Request a GPIO. This should be called before any of the other functions
  39. * are used on this GPIO.
  40. *
  41. * Note: With driver model, the label is allocated so there is no need for
  42. * the caller to preserve it.
  43. *
  44. * @param gpio GPIO number
  45. * @param label User label for this GPIO
  46. * @return 0 if ok, -1 on error
  47. */
  48. int gpio_request(unsigned gpio, const char *label);
  49. /**
  50. * @deprecated Please use driver model instead
  51. * Stop using the GPIO. This function should not alter pin configuration.
  52. *
  53. * @param gpio GPIO number
  54. * @return 0 if ok, -1 on error
  55. */
  56. int gpio_free(unsigned gpio);
  57. /**
  58. * @deprecated Please use driver model instead
  59. * Make a GPIO an input.
  60. *
  61. * @param gpio GPIO number
  62. * @return 0 if ok, -1 on error
  63. */
  64. int gpio_direction_input(unsigned gpio);
  65. /**
  66. * @deprecated Please use driver model instead
  67. * Make a GPIO an output, and set its value.
  68. *
  69. * @param gpio GPIO number
  70. * @param value GPIO value (0 for low or 1 for high)
  71. * @return 0 if ok, -1 on error
  72. */
  73. int gpio_direction_output(unsigned gpio, int value);
  74. /**
  75. * @deprecated Please use driver model instead
  76. * Get a GPIO's value. This will work whether the GPIO is an input
  77. * or an output.
  78. *
  79. * @param gpio GPIO number
  80. * @return 0 if low, 1 if high, -1 on error
  81. */
  82. int gpio_get_value(unsigned gpio);
  83. /**
  84. * @deprecated Please use driver model instead
  85. * Set an output GPIO's value. The GPIO must already be an output or
  86. * this function may have no effect.
  87. *
  88. * @param gpio GPIO number
  89. * @param value GPIO value (0 for low or 1 for high)
  90. * @return 0 if ok, -1 on error
  91. */
  92. int gpio_set_value(unsigned gpio, int value);
  93. /* State of a GPIO, as reported by get_function() */
  94. enum gpio_func_t {
  95. GPIOF_INPUT = 0,
  96. GPIOF_OUTPUT,
  97. GPIOF_UNUSED, /* Not claimed */
  98. GPIOF_UNKNOWN, /* Not known */
  99. GPIOF_FUNC, /* Not used as a GPIO */
  100. GPIOF_COUNT,
  101. };
  102. struct udevice;
  103. struct gpio_desc {
  104. struct udevice *dev; /* Device, NULL for invalid GPIO */
  105. unsigned long flags;
  106. #define GPIOD_IS_OUT BIT(1) /* GPIO is an output */
  107. #define GPIOD_IS_IN BIT(2) /* GPIO is an input */
  108. #define GPIOD_ACTIVE_LOW BIT(3) /* GPIO is active when value is low */
  109. #define GPIOD_IS_OUT_ACTIVE BIT(4) /* set output active */
  110. #define GPIOD_OPEN_DRAIN BIT(5) /* GPIO is open drain type */
  111. #define GPIOD_OPEN_SOURCE BIT(6) /* GPIO is open source type */
  112. #define GPIOD_PULL_UP BIT(7) /* GPIO has pull-up enabled */
  113. #define GPIOD_PULL_DOWN BIT(8) /* GPIO has pull-down enabled */
  114. uint offset; /* GPIO offset within the device */
  115. /*
  116. * We could consider adding the GPIO label in here. Possibly we could
  117. * use this structure for internal GPIO information.
  118. */
  119. };
  120. /* helper to compute the value of the gpio output */
  121. #define GPIOD_FLAGS_OUTPUT_MASK (GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE)
  122. #define GPIOD_FLAGS_OUTPUT(flags) \
  123. (((((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_IS_OUT_ACTIVE) || \
  124. (((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_ACTIVE_LOW)))
  125. /**
  126. * dm_gpio_is_valid() - Check if a GPIO is valid
  127. *
  128. * @desc: GPIO description containing device, offset and flags,
  129. * previously returned by gpio_request_by_name()
  130. * @return true if valid, false if not
  131. */
  132. static inline bool dm_gpio_is_valid(const struct gpio_desc *desc)
  133. {
  134. return desc->dev != NULL;
  135. }
  136. /**
  137. * gpio_get_status() - get the current GPIO status as a string
  138. *
  139. * Obtain the current GPIO status as a string which can be presented to the
  140. * user. A typical string is:
  141. *
  142. * "b4: in: 1 [x] sdmmc_cd"
  143. *
  144. * which means this is GPIO bank b, offset 4, currently set to input, current
  145. * value 1, [x] means that it is requested and the owner is 'sdmmc_cd'
  146. *
  147. * TODO(sjg@chromium.org): This should use struct gpio_desc
  148. *
  149. * @dev: Device to check
  150. * @offset: Offset of device GPIO to check
  151. * @buf: Place to put string
  152. * @buffsize: Size of string including \0
  153. */
  154. int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize);
  155. /**
  156. * gpio_get_function() - get the current function for a GPIO pin
  157. *
  158. * Note this returns GPIOF_UNUSED if the GPIO is not requested.
  159. *
  160. * TODO(sjg@chromium.org): This should use struct gpio_desc
  161. *
  162. * @dev: Device to check
  163. * @offset: Offset of device GPIO to check
  164. * @namep: If non-NULL, this is set to the name given when the GPIO
  165. * was requested, or -1 if it has not been requested
  166. * @return -ENODATA if the driver returned an unknown function,
  167. * -ENODEV if the device is not active, -EINVAL if the offset is invalid.
  168. * GPIOF_UNUSED if the GPIO has not been requested. Otherwise returns the
  169. * function from enum gpio_func_t.
  170. */
  171. int gpio_get_function(struct udevice *dev, int offset, const char **namep);
  172. /**
  173. * gpio_get_raw_function() - get the current raw function for a GPIO pin
  174. *
  175. * Note this does not return GPIOF_UNUSED - it will always return the GPIO
  176. * driver's view of a pin function, even if it is not correctly set up.
  177. *
  178. * TODO(sjg@chromium.org): This should use struct gpio_desc
  179. *
  180. * @dev: Device to check
  181. * @offset: Offset of device GPIO to check
  182. * @namep: If non-NULL, this is set to the name given when the GPIO
  183. * was requested, or -1 if it has not been requested
  184. * @return -ENODATA if the driver returned an unknown function,
  185. * -ENODEV if the device is not active, -EINVAL if the offset is invalid.
  186. * Otherwise returns the function from enum gpio_func_t.
  187. */
  188. int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep);
  189. /**
  190. * gpio_requestf() - request a GPIO using a format string for the owner
  191. *
  192. * This is a helper function for gpio_request(). It allows you to provide
  193. * a printf()-format string for the GPIO owner. It calls gpio_request() with
  194. * the string that is created
  195. */
  196. int gpio_requestf(unsigned gpio, const char *fmt, ...)
  197. __attribute__ ((format (__printf__, 2, 3)));
  198. struct fdtdec_phandle_args;
  199. /**
  200. * gpio_xlate_offs_flags() - implementation for common use of dm_gpio_ops.xlate
  201. *
  202. * This routine sets the offset field to args[0] and the flags field to
  203. * GPIOD_ACTIVE_LOW if the GPIO_ACTIVE_LOW flag is present in args[1].
  204. */
  205. int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
  206. struct ofnode_phandle_args *args);
  207. /**
  208. * struct struct dm_gpio_ops - Driver model GPIO operations
  209. *
  210. * Refer to functions above for description. These function largely copy
  211. * the old API.
  212. *
  213. * This is trying to be close to Linux GPIO API. Once the U-Boot uses the
  214. * new DM GPIO API, this should be really easy to flip over to the Linux
  215. * GPIO API-alike interface.
  216. *
  217. * Also it would be useful to standardise additional functions like
  218. * pullup, slew rate and drive strength.
  219. *
  220. * gpio_request() and gpio_free() are optional - if NULL then they will
  221. * not be called.
  222. *
  223. * Note that @offset is the offset from the base GPIO of the device. So
  224. * offset 0 is the device's first GPIO and offset o-1 is the last GPIO,
  225. * where o is the number of GPIO lines controlled by the device. A device
  226. * is typically used to control a single bank of GPIOs. Within complex
  227. * SoCs there may be many banks and therefore many devices all referring
  228. * to the different IO addresses within the SoC.
  229. *
  230. * The uclass combines all GPIO devices together to provide a consistent
  231. * numbering from 0 to n-1, where n is the number of GPIOs in total across
  232. * all devices. Be careful not to confuse offset with gpio in the parameters.
  233. */
  234. struct dm_gpio_ops {
  235. int (*request)(struct udevice *dev, unsigned offset, const char *label);
  236. int (*rfree)(struct udevice *dev, unsigned int offset);
  237. int (*direction_input)(struct udevice *dev, unsigned offset);
  238. int (*direction_output)(struct udevice *dev, unsigned offset,
  239. int value);
  240. int (*get_value)(struct udevice *dev, unsigned offset);
  241. int (*set_value)(struct udevice *dev, unsigned offset, int value);
  242. /**
  243. * get_function() Get the GPIO function
  244. *
  245. * @dev: Device to check
  246. * @offset: GPIO offset within that device
  247. * @return current function - GPIOF_...
  248. */
  249. int (*get_function)(struct udevice *dev, unsigned offset);
  250. /**
  251. * xlate() - Translate phandle arguments into a GPIO description
  252. *
  253. * This function should set up the fields in desc according to the
  254. * information in the arguments. The uclass will have set up:
  255. *
  256. * @desc->dev to @dev
  257. * @desc->flags to 0
  258. * @desc->offset to 0
  259. *
  260. * This method is optional and defaults to gpio_xlate_offs_flags,
  261. * which will parse offset and the GPIO_ACTIVE_LOW flag in the first
  262. * two arguments.
  263. *
  264. * Note that @dev is passed in as a parameter to follow driver model
  265. * uclass conventions, even though it is already available as
  266. * desc->dev.
  267. *
  268. * @dev: GPIO device
  269. * @desc: Place to put GPIO description
  270. * @args: Arguments provided in description
  271. * @return 0 if OK, -ve on error
  272. */
  273. int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
  274. struct ofnode_phandle_args *args);
  275. /**
  276. * set_dir_flags() - Set GPIO dir flags
  277. *
  278. * This function should set up the GPIO configuration according to the
  279. * information provide by the direction flags bitfield.
  280. *
  281. * This method is optional.
  282. *
  283. * @dev: GPIO device
  284. * @offset: GPIO offset within that device
  285. * @flags: GPIO configuration to use
  286. * @return 0 if OK, -ve on error
  287. */
  288. int (*set_dir_flags)(struct udevice *dev, unsigned int offset,
  289. ulong flags);
  290. /**
  291. * get_dir_flags() - Get GPIO dir flags
  292. *
  293. * This function return the GPIO direction flags used.
  294. *
  295. * This method is optional.
  296. *
  297. * @dev: GPIO device
  298. * @offset: GPIO offset within that device
  299. * @flags: place to put the used direction flags by GPIO
  300. * @return 0 if OK, -ve on error
  301. */
  302. int (*get_dir_flags)(struct udevice *dev, unsigned int offset,
  303. ulong *flags);
  304. };
  305. /**
  306. * struct gpio_dev_priv - information about a device used by the uclass
  307. *
  308. * The uclass combines all active GPIO devices into a unified numbering
  309. * scheme. To do this it maintains some private information about each
  310. * device.
  311. *
  312. * To implement driver model support in your GPIO driver, add a probe
  313. * handler, and set @gpio_count and @bank_name correctly in that handler.
  314. * This tells the uclass the name of the GPIO bank and the number of GPIOs
  315. * it contains.
  316. *
  317. * @bank_name: Name of the GPIO device (e.g 'a' means GPIOs will be called
  318. * 'A0', 'A1', etc.
  319. * @gpio_count: Number of GPIOs in this device
  320. * @gpio_base: Base GPIO number for this device. For the first active device
  321. * this will be 0; the numbering for others will follow sequentially so that
  322. * @gpio_base for device 1 will equal the number of GPIOs in device 0.
  323. * @name: Array of pointers to the name for each GPIO in this bank. The
  324. * value of the pointer will be NULL if the GPIO has not been claimed.
  325. */
  326. struct gpio_dev_priv {
  327. const char *bank_name;
  328. unsigned gpio_count;
  329. unsigned gpio_base;
  330. char **name;
  331. };
  332. /* Access the GPIO operations for a device */
  333. #define gpio_get_ops(dev) ((struct dm_gpio_ops *)(dev)->driver->ops)
  334. /**
  335. * gpio_get_bank_info - Return information about a GPIO bank/device
  336. *
  337. * This looks up a device and returns both its GPIO base name and the number
  338. * of GPIOs it controls.
  339. *
  340. * @dev: Device to look up
  341. * @offset_count: Returns number of GPIOs within this bank
  342. * @return bank name of this device
  343. */
  344. const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
  345. /**
  346. * dm_gpio_lookup_name() - Look up a named GPIO and return its description
  347. *
  348. * The name of a GPIO is typically its bank name followed by a number from 0.
  349. * For example A0 is the first GPIO in bank A. Each bank is a separate driver
  350. * model device.
  351. *
  352. * @name: Name to look up
  353. * @desc: Returns description, on success
  354. * @return 0 if OK, -ve on error
  355. */
  356. int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc);
  357. /**
  358. * gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr.
  359. *
  360. * @name: Name to look up
  361. * @desc: Returns GPIO description, on success, else NULL
  362. * @return: Returns 0 if OK, else -ENODEV
  363. */
  364. int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc);
  365. /**
  366. * gpio_hog_probe_all() - probe all gpio devices with
  367. * gpio-hog subnodes.
  368. *
  369. * @return: Returns return value from device_probe()
  370. */
  371. int gpio_hog_probe_all(void);
  372. /**
  373. * gpio_lookup_name - Look up a GPIO name and return its details
  374. *
  375. * This is used to convert a named GPIO into a device, offset and GPIO
  376. * number.
  377. *
  378. * @name: GPIO name to look up
  379. * @devp: Returns pointer to device which contains this GPIO
  380. * @offsetp: Returns the offset number within this device
  381. * @gpiop: Returns the absolute GPIO number, numbered from 0
  382. */
  383. int gpio_lookup_name(const char *name, struct udevice **devp,
  384. unsigned int *offsetp, unsigned int *gpiop);
  385. /**
  386. * gpio_get_values_as_int() - Turn the values of a list of GPIOs into an int
  387. *
  388. * This puts the value of the first GPIO into bit 0, the second into bit 1,
  389. * etc. then returns the resulting integer.
  390. *
  391. * @gpio_list: List of GPIOs to collect
  392. * @return resulting integer value, or -ve on error
  393. */
  394. int gpio_get_values_as_int(const int *gpio_list);
  395. /**
  396. * dm_gpio_get_values_as_int() - Turn the values of a list of GPIOs into an int
  397. *
  398. * This puts the value of the first GPIO into bit 0, the second into bit 1,
  399. * etc. then returns the resulting integer.
  400. *
  401. * @desc_list: List of GPIOs to collect
  402. * @count: Number of GPIOs
  403. * @return resulting integer value, or -ve on error
  404. */
  405. int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count);
  406. /**
  407. * gpio_claim_vector() - claim a number of GPIOs for input
  408. *
  409. * @gpio_num_array: array of gpios to claim, terminated by -1
  410. * @fmt: format string for GPIO names, e.g. "board_id%d"
  411. * @return 0 if OK, -ve on error
  412. */
  413. int gpio_claim_vector(const int *gpio_num_array, const char *fmt);
  414. /**
  415. * gpio_request_by_name() - Locate and request a GPIO by name
  416. *
  417. * This operates by looking up the given list name in the device (device
  418. * tree property) and requesting the GPIO for use. The property must exist
  419. * in @dev's node.
  420. *
  421. * Use @flags to specify whether the GPIO should be an input or output. In
  422. * principle this can also come from the device tree binding but most
  423. * bindings don't provide this information. Specifically, when the GPIO uclass
  424. * calls the xlate() method, it can return default flags, which are then
  425. * ORed with this @flags.
  426. *
  427. * If we find that requesting the GPIO is not always needed we could add a
  428. * new function or a new GPIOD_NO_REQUEST flag.
  429. *
  430. * At present driver model has no reference counting so if one device
  431. * requests a GPIO which subsequently is unbound, the @desc->dev pointer
  432. * will be invalid. However this will only happen if the GPIO device is
  433. * unbound, not if it is removed, so this seems like a reasonable limitation
  434. * for now. There is no real use case for unbinding drivers in normal
  435. * operation.
  436. *
  437. * The device tree binding is doc/device-tree-bindings/gpio/gpio.txt in
  438. * generate terms and each specific device may add additional details in
  439. * a binding file in the same directory.
  440. *
  441. * @dev: Device requesting the GPIO
  442. * @list_name: Name of GPIO list (e.g. "board-id-gpios")
  443. * @index: Index number of the GPIO in that list use request (0=first)
  444. * @desc: Returns GPIO description information. If there is no such
  445. * GPIO, dev->dev will be NULL.
  446. * @flags: Indicates the GPIO input/output settings (GPIOD_...)
  447. * @return 0 if OK, -ENOENT if the GPIO does not exist, -EINVAL if there is
  448. * something wrong with the list, or other -ve for another error (e.g.
  449. * -EBUSY if a GPIO was already requested)
  450. */
  451. int gpio_request_by_name(struct udevice *dev, const char *list_name,
  452. int index, struct gpio_desc *desc, int flags);
  453. /**
  454. * gpio_request_list_by_name() - Request a list of GPIOs
  455. *
  456. * Reads all the GPIOs from a list and requests them. See
  457. * gpio_request_by_name() for additional details. Lists should not be
  458. * misused to hold unrelated or optional GPIOs. They should only be used
  459. * for things like parallel data lines. A zero phandle terminates the list
  460. * the list.
  461. *
  462. * This function will either succeed, and request all GPIOs in the list, or
  463. * fail and request none (it will free already-requested GPIOs in case of
  464. * an error part-way through).
  465. *
  466. * @dev: Device requesting the GPIO
  467. * @list_name: Name of GPIO list (e.g. "board-id-gpios")
  468. * @desc_list: Returns a list of GPIO description information
  469. * @max_count: Maximum number of GPIOs to return (@desc_list must be at least
  470. * this big)
  471. * @flags: Indicates the GPIO input/output settings (GPIOD_...)
  472. * @return number of GPIOs requested, or -ve on error
  473. */
  474. int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
  475. struct gpio_desc *desc_list, int max_count,
  476. int flags);
  477. /**
  478. * dm_gpio_request() - manually request a GPIO
  479. *
  480. * Note: This function should only be used for testing / debugging. Instead.
  481. * use gpio_request_by_name() to pull GPIOs from the device tree.
  482. *
  483. * @desc: GPIO description of GPIO to request (see dm_gpio_lookup_name())
  484. * @label: Label to attach to the GPIO while claimed
  485. * @return 0 if OK, -ve on error
  486. */
  487. int dm_gpio_request(struct gpio_desc *desc, const char *label);
  488. /**
  489. * gpio_get_list_count() - Returns the number of GPIOs in a list
  490. *
  491. * Counts the GPIOs in a list. See gpio_request_by_name() for additional
  492. * details.
  493. *
  494. * @dev: Device requesting the GPIO
  495. * @list_name: Name of GPIO list (e.g. "board-id-gpios")
  496. * @return number of GPIOs (0 for an empty property) or -ENOENT if the list
  497. * does not exist
  498. */
  499. int gpio_get_list_count(struct udevice *dev, const char *list_name);
  500. /**
  501. * gpio_request_by_name_nodev() - request GPIOs without a device
  502. *
  503. * This is a version of gpio_request_list_by_name() that does not use a
  504. * device. Avoid it unless the caller is not yet using driver model
  505. */
  506. int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,
  507. struct gpio_desc *desc, int flags);
  508. /**
  509. * gpio_request_list_by_name_nodev() - request GPIOs without a device
  510. *
  511. * This is a version of gpio_request_list_by_name() that does not use a
  512. * device. Avoid it unless the caller is not yet using driver model
  513. */
  514. int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
  515. struct gpio_desc *desc_list, int max_count,
  516. int flags);
  517. /**
  518. * gpio_dev_request_index() - request single GPIO from gpio device
  519. *
  520. * @dev: GPIO device
  521. * @nodename: Name of node for which gpio gets requested, used
  522. * for the gpio label name
  523. * @list_name: Name of GPIO list (e.g. "board-id-gpios")
  524. * @index: Index number of the GPIO in that list use request (0=first)
  525. * @flags: GPIOD_* flags
  526. * @dtflags: GPIO flags read from DT defined see GPIOD_*
  527. * @desc: returns GPIO descriptor filled from this function
  528. * @return: return value from gpio_request_tail()
  529. */
  530. int gpio_dev_request_index(struct udevice *dev, const char *nodename,
  531. char *list_name, int index, int flags,
  532. int dtflags, struct gpio_desc *desc);
  533. /**
  534. * dm_gpio_free() - Free a single GPIO
  535. *
  536. * This frees a single GPIOs previously returned from gpio_request_by_name().
  537. *
  538. * @dev: Device which requested the GPIO
  539. * @desc: GPIO to free
  540. * @return 0 if OK, -ve on error
  541. */
  542. int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc);
  543. /**
  544. * gpio_free_list() - Free a list of GPIOs
  545. *
  546. * This frees a list of GPIOs previously returned from
  547. * gpio_request_list_by_name().
  548. *
  549. * @dev: Device which requested the GPIOs
  550. * @desc: List of GPIOs to free
  551. * @count: Number of GPIOs in the list
  552. * @return 0 if OK, -ve on error
  553. */
  554. int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count);
  555. /**
  556. * gpio_free_list_nodev() - free GPIOs without a device
  557. *
  558. * This is a version of gpio_free_list() that does not use a
  559. * device. Avoid it unless the caller is not yet using driver model
  560. */
  561. int gpio_free_list_nodev(struct gpio_desc *desc, int count);
  562. /**
  563. * dm_gpio_get_value() - Get the value of a GPIO
  564. *
  565. * This is the driver model version of the existing gpio_get_value() function
  566. * and should be used instead of that.
  567. *
  568. * For now, these functions have a dm_ prefix since they conflict with
  569. * existing names.
  570. *
  571. * @desc: GPIO description containing device, offset and flags,
  572. * previously returned by gpio_request_by_name()
  573. * @return GPIO value (0 for inactive, 1 for active) or -ve on error
  574. */
  575. int dm_gpio_get_value(const struct gpio_desc *desc);
  576. int dm_gpio_set_value(const struct gpio_desc *desc, int value);
  577. /**
  578. * dm_gpio_set_dir() - Set the direction for a GPIO
  579. *
  580. * This sets up the direction according to the GPIO flags: desc->flags.
  581. *
  582. * @desc: GPIO description containing device, offset and flags,
  583. * previously returned by gpio_request_by_name()
  584. * @return 0 if OK, -ve on error
  585. */
  586. int dm_gpio_set_dir(struct gpio_desc *desc);
  587. /**
  588. * dm_gpio_set_dir_flags() - Set direction using description and added flags
  589. *
  590. * This sets up the direction according to the provided flags and the GPIO
  591. * description (desc->flags) which include direction information.
  592. * Note that desc->flags is updated by this function.
  593. *
  594. * @desc: GPIO description containing device, offset and flags,
  595. * previously returned by gpio_request_by_name()
  596. * @flags: New flags to use
  597. * @return 0 if OK, -ve on error, in which case desc->flags is not updated
  598. */
  599. int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags);
  600. /**
  601. * dm_gpio_get_dir_flags() - Get direction flags
  602. *
  603. * read the current direction flags
  604. *
  605. * @desc: GPIO description containing device, offset and flags,
  606. * previously returned by gpio_request_by_name()
  607. * @flags: place to put the used flags
  608. * @return 0 if OK, -ve on error, in which case desc->flags is not updated
  609. */
  610. int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags);
  611. /**
  612. * gpio_get_number() - Get the global GPIO number of a GPIO
  613. *
  614. * This should only be used for debugging or interest. It returns the number
  615. * that should be used for gpio_get_value() etc. to access this GPIO.
  616. *
  617. * @desc: GPIO description containing device, offset and flags,
  618. * previously returned by gpio_request_by_name()
  619. * @return GPIO number, or -ve if not found
  620. */
  621. int gpio_get_number(const struct gpio_desc *desc);
  622. #endif /* _ASM_GENERIC_GPIO_H_ */