xref: /rk3399_rockchip-uboot/include/asm-generic/gpio.h (revision 3669e0e759118fed3d371e2427b4b47d3969bfd0)
19d2cb8e8SSimon Glass /*
29d2cb8e8SSimon Glass  * Copyright (c) 2011 The Chromium OS Authors.
35f533aebSJoe Hershberger  * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
59d2cb8e8SSimon Glass  */
69d2cb8e8SSimon Glass 
75f533aebSJoe Hershberger #ifndef _ASM_GENERIC_GPIO_H_
85f533aebSJoe Hershberger #define _ASM_GENERIC_GPIO_H_
95f533aebSJoe Hershberger 
109d2cb8e8SSimon Glass /*
119d2cb8e8SSimon Glass  * Generic GPIO API for U-Boot
129d2cb8e8SSimon Glass  *
139d2cb8e8SSimon Glass  * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
149d2cb8e8SSimon Glass  * by the SOC/architecture.
159d2cb8e8SSimon Glass  *
169d2cb8e8SSimon Glass  * Each GPIO can be an input or output. If an input then its value can
179d2cb8e8SSimon Glass  * be read as 0 or 1. If an output then its value can be set to 0 or 1.
189d2cb8e8SSimon Glass  * If you try to write an input then the value is undefined. If you try
199d2cb8e8SSimon Glass  * to read an output, barring something very unusual,  you will get
209d2cb8e8SSimon Glass  * back the value of the output that you previously set.
219d2cb8e8SSimon Glass  *
229d2cb8e8SSimon Glass  * In some cases the operation may fail, for example if the GPIO number
239d2cb8e8SSimon Glass  * is out of range, or the GPIO is not available because its pin is
249d2cb8e8SSimon Glass  * being used by another function. In that case, functions may return
259d2cb8e8SSimon Glass  * an error value of -1.
269d2cb8e8SSimon Glass  */
279d2cb8e8SSimon Glass 
289d2cb8e8SSimon Glass /**
2925ca385dSMarcel Ziswiler  * Request a GPIO. This should be called before any of the other functions
3025ca385dSMarcel Ziswiler  * are used on this GPIO.
319d2cb8e8SSimon Glass  *
32b892d127SSimon Glass  * Note: With driver model, the label is allocated so there is no need for
33b892d127SSimon Glass  * the caller to preserve it.
34b892d127SSimon Glass  *
3594740e47SNikita Kiryanov  * @param gp	GPIO number
3694740e47SNikita Kiryanov  * @param label	User label for this GPIO
379d2cb8e8SSimon Glass  * @return 0 if ok, -1 on error
389d2cb8e8SSimon Glass  */
395f533aebSJoe Hershberger int gpio_request(unsigned gpio, const char *label);
405f533aebSJoe Hershberger 
415f533aebSJoe Hershberger /**
425f533aebSJoe Hershberger  * Stop using the GPIO.  This function should not alter pin configuration.
435f533aebSJoe Hershberger  *
445f533aebSJoe Hershberger  * @param gpio	GPIO number
455f533aebSJoe Hershberger  * @return 0 if ok, -1 on error
465f533aebSJoe Hershberger  */
475f533aebSJoe Hershberger int gpio_free(unsigned gpio);
485f533aebSJoe Hershberger 
495f533aebSJoe Hershberger /**
505f533aebSJoe Hershberger  * Make a GPIO an input.
515f533aebSJoe Hershberger  *
525f533aebSJoe Hershberger  * @param gpio	GPIO number
535f533aebSJoe Hershberger  * @return 0 if ok, -1 on error
545f533aebSJoe Hershberger  */
555f533aebSJoe Hershberger int gpio_direction_input(unsigned gpio);
569d2cb8e8SSimon Glass 
579d2cb8e8SSimon Glass /**
589d2cb8e8SSimon Glass  * Make a GPIO an output, and set its value.
599d2cb8e8SSimon Glass  *
605f533aebSJoe Hershberger  * @param gpio	GPIO number
619d2cb8e8SSimon Glass  * @param value	GPIO value (0 for low or 1 for high)
629d2cb8e8SSimon Glass  * @return 0 if ok, -1 on error
639d2cb8e8SSimon Glass  */
645f533aebSJoe Hershberger int gpio_direction_output(unsigned gpio, int value);
659d2cb8e8SSimon Glass 
669d2cb8e8SSimon Glass /**
679d2cb8e8SSimon Glass  * Get a GPIO's value. This will work whether the GPIO is an input
689d2cb8e8SSimon Glass  * or an output.
699d2cb8e8SSimon Glass  *
705f533aebSJoe Hershberger  * @param gpio	GPIO number
719d2cb8e8SSimon Glass  * @return 0 if low, 1 if high, -1 on error
729d2cb8e8SSimon Glass  */
735f533aebSJoe Hershberger int gpio_get_value(unsigned gpio);
749d2cb8e8SSimon Glass 
759d2cb8e8SSimon Glass /**
765f533aebSJoe Hershberger  * Set an output GPIO's value. The GPIO must already be an output or
779d2cb8e8SSimon Glass  * this function may have no effect.
789d2cb8e8SSimon Glass  *
795f533aebSJoe Hershberger  * @param gpio	GPIO number
809d2cb8e8SSimon Glass  * @param value	GPIO value (0 for low or 1 for high)
819d2cb8e8SSimon Glass  * @return 0 if ok, -1 on error
829d2cb8e8SSimon Glass  */
835f533aebSJoe Hershberger int gpio_set_value(unsigned gpio, int value);
8496495d90SSimon Glass 
8589e64054SSimon Glass /* State of a GPIO, as reported by get_function() */
866449a506SSimon Glass enum gpio_func_t {
8796495d90SSimon Glass 	GPIOF_INPUT = 0,
8896495d90SSimon Glass 	GPIOF_OUTPUT,
8989e64054SSimon Glass 	GPIOF_UNUSED,		/* Not claimed */
9089e64054SSimon Glass 	GPIOF_UNKNOWN,		/* Not known */
9189e64054SSimon Glass 	GPIOF_FUNC,		/* Not used as a GPIO */
9289e64054SSimon Glass 
9389e64054SSimon Glass 	GPIOF_COUNT,
9496495d90SSimon Glass };
9596495d90SSimon Glass 
9654c5d08aSHeiko Schocher struct udevice;
9796495d90SSimon Glass 
98ae7123f8SSimon Glass struct gpio_desc {
99ae7123f8SSimon Glass 	struct udevice *dev;	/* Device, NULL for invalid GPIO */
100ae7123f8SSimon Glass 	unsigned long flags;
101ae7123f8SSimon Glass #define GPIOD_REQUESTED		(1 << 0)	/* Requested/claimed */
102ae7123f8SSimon Glass #define GPIOD_IS_OUT		(1 << 1)	/* GPIO is an output */
103ae7123f8SSimon Glass #define GPIOD_IS_IN		(1 << 2)	/* GPIO is an output */
104ae7123f8SSimon Glass #define GPIOD_ACTIVE_LOW	(1 << 3)	/* value has active low */
105ae7123f8SSimon Glass #define GPIOD_IS_OUT_ACTIVE	(1 << 4)	/* set output active */
106ae7123f8SSimon Glass 
107ae7123f8SSimon Glass 	uint offset;		/* GPIO offset within the device */
108ae7123f8SSimon Glass 	/*
109ae7123f8SSimon Glass 	 * We could consider adding the GPIO label in here. Possibly we could
110ae7123f8SSimon Glass 	 * use this structure for internal GPIO information.
111ae7123f8SSimon Glass 	 */
112ae7123f8SSimon Glass };
113ae7123f8SSimon Glass 
11496495d90SSimon Glass /**
115*3669e0e7SSimon Glass  * dm_gpio_is_valid() - Check if a GPIO is gpio_is_valie
116*3669e0e7SSimon Glass  *
117*3669e0e7SSimon Glass  * @desc:	GPIO description containing device, offset and flags,
118*3669e0e7SSimon Glass  *		previously returned by gpio_request_by_name()
119*3669e0e7SSimon Glass  * @return true if valid, false if not
120*3669e0e7SSimon Glass  */
121*3669e0e7SSimon Glass static inline bool dm_gpio_is_valid(struct gpio_desc *desc)
122*3669e0e7SSimon Glass {
123*3669e0e7SSimon Glass 	return desc->dev != NULL;
124*3669e0e7SSimon Glass }
125*3669e0e7SSimon Glass 
126*3669e0e7SSimon Glass /**
1270757535aSSimon Glass  * gpio_get_status() - get the current GPIO status as a string
1280757535aSSimon Glass  *
1290757535aSSimon Glass  * Obtain the current GPIO status as a string which can be presented to the
1300757535aSSimon Glass  * user. A typical string is:
1310757535aSSimon Glass  *
1320757535aSSimon Glass  * "b4:  in: 1 [x] sdmmc_cd"
1330757535aSSimon Glass  *
1340757535aSSimon Glass  * which means this is GPIO bank b, offset 4, currently set to input, current
1350757535aSSimon Glass  * value 1, [x] means that it is requested and the owner is 'sdmmc_cd'
1360757535aSSimon Glass  *
1370757535aSSimon Glass  * @dev:	Device to check
1380757535aSSimon Glass  * @offset:	Offset of device GPIO to check
1390757535aSSimon Glass  * @buf:	Place to put string
1400757535aSSimon Glass  * @buffsize:	Size of string including \0
1410757535aSSimon Glass  */
1420757535aSSimon Glass int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize);
1430757535aSSimon Glass 
1440757535aSSimon Glass /**
1456449a506SSimon Glass  * gpio_get_function() - get the current function for a GPIO pin
1466449a506SSimon Glass  *
1476449a506SSimon Glass  * Note this returns GPIOF_UNUSED if the GPIO is not requested.
1486449a506SSimon Glass  *
1496449a506SSimon Glass  * @dev:	Device to check
1506449a506SSimon Glass  * @offset:	Offset of device GPIO to check
1516449a506SSimon Glass  * @namep:	If non-NULL, this is set to the nane given when the GPIO
1526449a506SSimon Glass  *		was requested, or -1 if it has not been requested
1536449a506SSimon Glass  * @return  -ENODATA if the driver returned an unknown function,
1546449a506SSimon Glass  * -ENODEV if the device is not active, -EINVAL if the offset is invalid.
1556449a506SSimon Glass  * GPIOF_UNUSED if the GPIO has not been requested. Otherwise returns the
1566449a506SSimon Glass  * function from enum gpio_func_t.
1576449a506SSimon Glass  */
1586449a506SSimon Glass int gpio_get_function(struct udevice *dev, int offset, const char **namep);
1596449a506SSimon Glass 
1606449a506SSimon Glass /**
1616449a506SSimon Glass  * gpio_get_raw_function() - get the current raw function for a GPIO pin
1626449a506SSimon Glass  *
1636449a506SSimon Glass  * Note this does not return GPIOF_UNUSED - it will always return the GPIO
1646449a506SSimon Glass  * driver's view of a pin function, even if it is not correctly set up.
1656449a506SSimon Glass  *
1666449a506SSimon Glass  * @dev:	Device to check
1676449a506SSimon Glass  * @offset:	Offset of device GPIO to check
1686449a506SSimon Glass  * @namep:	If non-NULL, this is set to the nane given when the GPIO
1696449a506SSimon Glass  *		was requested, or -1 if it has not been requested
1706449a506SSimon Glass  * @return  -ENODATA if the driver returned an unknown function,
1716449a506SSimon Glass  * -ENODEV if the device is not active, -EINVAL if the offset is invalid.
1726449a506SSimon Glass  * Otherwise returns the function from enum gpio_func_t.
1736449a506SSimon Glass  */
1746449a506SSimon Glass int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep);
1756449a506SSimon Glass 
1766449a506SSimon Glass /**
177d44f597bSSimon Glass  * gpio_requestf() - request a GPIO using a format string for the owner
178d44f597bSSimon Glass  *
179d44f597bSSimon Glass  * This is a helper function for gpio_request(). It allows you to provide
180d44f597bSSimon Glass  * a printf()-format string for the GPIO owner. It calls gpio_request() with
181d44f597bSSimon Glass  * the string that is created
182d44f597bSSimon Glass  */
183d44f597bSSimon Glass int gpio_requestf(unsigned gpio, const char *fmt, ...)
184d44f597bSSimon Glass 		__attribute__ ((format (__printf__, 2, 3)));
185d44f597bSSimon Glass 
1860dac4d51SSimon Glass struct fdtdec_phandle_args;
1870dac4d51SSimon Glass 
188d44f597bSSimon Glass /**
18996495d90SSimon Glass  * struct struct dm_gpio_ops - Driver model GPIO operations
19096495d90SSimon Glass  *
19196495d90SSimon Glass  * Refer to functions above for description. These function largely copy
19296495d90SSimon Glass  * the old API.
19396495d90SSimon Glass  *
19496495d90SSimon Glass  * This is trying to be close to Linux GPIO API. Once the U-Boot uses the
19596495d90SSimon Glass  * new DM GPIO API, this should be really easy to flip over to the Linux
19696495d90SSimon Glass  * GPIO API-alike interface.
19796495d90SSimon Glass  *
19825ca385dSMarcel Ziswiler  * Also it would be useful to standardise additional functions like
19996495d90SSimon Glass  * pullup, slew rate and drive strength.
20096495d90SSimon Glass  *
20196495d90SSimon Glass  * gpio_request)( and gpio_free() are optional - if NULL then they will
20296495d90SSimon Glass  * not be called.
20396495d90SSimon Glass  *
20496495d90SSimon Glass  * Note that @offset is the offset from the base GPIO of the device. So
20596495d90SSimon Glass  * offset 0 is the device's first GPIO and offset o-1 is the last GPIO,
20696495d90SSimon Glass  * where o is the number of GPIO lines controlled by the device. A device
20796495d90SSimon Glass  * is typically used to control a single bank of GPIOs. Within complex
20896495d90SSimon Glass  * SoCs there may be many banks and therefore many devices all referring
20996495d90SSimon Glass  * to the different IO addresses within the SoC.
21096495d90SSimon Glass  *
21125ca385dSMarcel Ziswiler  * The uclass combines all GPIO devices together to provide a consistent
21296495d90SSimon Glass  * numbering from 0 to n-1, where n is the number of GPIOs in total across
21396495d90SSimon Glass  * all devices. Be careful not to confuse offset with gpio in the parameters.
21496495d90SSimon Glass  */
21596495d90SSimon Glass struct dm_gpio_ops {
21654c5d08aSHeiko Schocher 	int (*request)(struct udevice *dev, unsigned offset, const char *label);
21754c5d08aSHeiko Schocher 	int (*free)(struct udevice *dev, unsigned offset);
21854c5d08aSHeiko Schocher 	int (*direction_input)(struct udevice *dev, unsigned offset);
21954c5d08aSHeiko Schocher 	int (*direction_output)(struct udevice *dev, unsigned offset,
22096495d90SSimon Glass 				int value);
22154c5d08aSHeiko Schocher 	int (*get_value)(struct udevice *dev, unsigned offset);
22254c5d08aSHeiko Schocher 	int (*set_value)(struct udevice *dev, unsigned offset, int value);
22389e64054SSimon Glass 	/**
22489e64054SSimon Glass 	 * get_function() Get the GPIO function
22589e64054SSimon Glass 	 *
22689e64054SSimon Glass 	 * @dev:     Device to check
22789e64054SSimon Glass 	 * @offset:  GPIO offset within that device
22889e64054SSimon Glass 	 * @return current function - GPIOF_...
22989e64054SSimon Glass 	 */
23054c5d08aSHeiko Schocher 	int (*get_function)(struct udevice *dev, unsigned offset);
2310dac4d51SSimon Glass 
2320dac4d51SSimon Glass 	/**
2330dac4d51SSimon Glass 	 * xlate() - Translate phandle arguments into a GPIO description
2340dac4d51SSimon Glass 	 *
2350dac4d51SSimon Glass 	 * This function should set up the fields in desc according to the
2360dac4d51SSimon Glass 	 * information in the arguments. The uclass will have set up:
2370dac4d51SSimon Glass 	 *
2380dac4d51SSimon Glass 	 *   @desc->dev to @dev
2390dac4d51SSimon Glass 	 *   @desc->flags to 0
2400dac4d51SSimon Glass 	 *   @desc->offset to the value of the first argument in args, if any,
2410dac4d51SSimon Glass 	 *		otherwise -1 (which is invalid)
2420dac4d51SSimon Glass 	 *
2430dac4d51SSimon Glass 	 * This method is optional so if the above defaults suit it can be
2440dac4d51SSimon Glass 	 * omitted. Typical behaviour is to set up the GPIOD_ACTIVE_LOW flag
2450dac4d51SSimon Glass 	 * in desc->flags.
2460dac4d51SSimon Glass 	 *
2470dac4d51SSimon Glass 	 * Note that @dev is passed in as a parameter to follow driver model
2480dac4d51SSimon Glass 	 * uclass conventions, even though it is already available as
2490dac4d51SSimon Glass 	 * desc->dev.
2500dac4d51SSimon Glass 	 *
2510dac4d51SSimon Glass 	 * @dev:	GPIO device
2520dac4d51SSimon Glass 	 * @desc:	Place to put GPIO description
2530dac4d51SSimon Glass 	 * @args:	Arguments provided in descripion
2540dac4d51SSimon Glass 	 * @return 0 if OK, -ve on error
2550dac4d51SSimon Glass 	 */
2560dac4d51SSimon Glass 	int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
2570dac4d51SSimon Glass 		     struct fdtdec_phandle_args *args);
25896495d90SSimon Glass };
25996495d90SSimon Glass 
26096495d90SSimon Glass /**
26196495d90SSimon Glass  * struct gpio_dev_priv - information about a device used by the uclass
26296495d90SSimon Glass  *
26396495d90SSimon Glass  * The uclass combines all active GPIO devices into a unified numbering
26425ca385dSMarcel Ziswiler  * scheme. To do this it maintains some private information about each
26596495d90SSimon Glass  * device.
26696495d90SSimon Glass  *
26796495d90SSimon Glass  * To implement driver model support in your GPIO driver, add a probe
26896495d90SSimon Glass  * handler, and set @gpio_count and @bank_name correctly in that handler.
26996495d90SSimon Glass  * This tells the uclass the name of the GPIO bank and the number of GPIOs
27096495d90SSimon Glass  * it contains.
27196495d90SSimon Glass  *
27296495d90SSimon Glass  * @bank_name: Name of the GPIO device (e.g 'a' means GPIOs will be called
27396495d90SSimon Glass  * 'A0', 'A1', etc.
27496495d90SSimon Glass  * @gpio_count: Number of GPIOs in this device
27596495d90SSimon Glass  * @gpio_base: Base GPIO number for this device. For the first active device
27696495d90SSimon Glass  * this will be 0; the numbering for others will follow sequentially so that
27796495d90SSimon Glass  * @gpio_base for device 1 will equal the number of GPIOs in device 0.
278b892d127SSimon Glass  * @name: Array of pointers to the name for each GPIO in this bank. The
279b892d127SSimon Glass  * value of the pointer will be NULL if the GPIO has not been claimed.
28096495d90SSimon Glass  */
28196495d90SSimon Glass struct gpio_dev_priv {
28296495d90SSimon Glass 	const char *bank_name;
28396495d90SSimon Glass 	unsigned gpio_count;
28496495d90SSimon Glass 	unsigned gpio_base;
285b892d127SSimon Glass 	char **name;
28696495d90SSimon Glass };
28796495d90SSimon Glass 
28896495d90SSimon Glass /* Access the GPIO operations for a device */
28996495d90SSimon Glass #define gpio_get_ops(dev)	((struct dm_gpio_ops *)(dev)->driver->ops)
29096495d90SSimon Glass 
29196495d90SSimon Glass /**
29296495d90SSimon Glass  * gpio_get_bank_info - Return information about a GPIO bank/device
29396495d90SSimon Glass  *
29496495d90SSimon Glass  * This looks up a device and returns both its GPIO base name and the number
29596495d90SSimon Glass  * of GPIOs it controls.
29696495d90SSimon Glass  *
29796495d90SSimon Glass  * @dev: Device to look up
29896495d90SSimon Glass  * @offset_count: Returns number of GPIOs within this bank
29996495d90SSimon Glass  * @return bank name of this device
30096495d90SSimon Glass  */
30154c5d08aSHeiko Schocher const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
30296495d90SSimon Glass 
30396495d90SSimon Glass /**
30496495d90SSimon Glass  * gpio_lookup_name - Look up a GPIO name and return its details
30596495d90SSimon Glass  *
30696495d90SSimon Glass  * This is used to convert a named GPIO into a device, offset and GPIO
30796495d90SSimon Glass  * number.
30896495d90SSimon Glass  *
30996495d90SSimon Glass  * @name: GPIO name to look up
31096495d90SSimon Glass  * @devp: Returns pointer to device which contains this GPIO
31196495d90SSimon Glass  * @offsetp: Returns the offset number within this device
31296495d90SSimon Glass  * @gpiop: Returns the absolute GPIO number, numbered from 0
31396495d90SSimon Glass  */
31454c5d08aSHeiko Schocher int gpio_lookup_name(const char *name, struct udevice **devp,
31596495d90SSimon Glass 		     unsigned int *offsetp, unsigned int *gpiop);
31696495d90SSimon Glass 
317e5901c94SSimon Glass /**
318e5901c94SSimon Glass  * get_gpios() - Turn the values of a list of GPIOs into an integer
319e5901c94SSimon Glass  *
320e5901c94SSimon Glass  * This puts the value of the first GPIO into bit 0, the second into bit 1,
321e5901c94SSimon Glass  * etc. then returns the resulting integer.
322e5901c94SSimon Glass  *
323e5901c94SSimon Glass  * @gpio_list: List of GPIOs to collect
324e5901c94SSimon Glass  * @return resulting integer value
325e5901c94SSimon Glass  */
326e5901c94SSimon Glass unsigned gpio_get_values_as_int(const int *gpio_list);
3275b5ac645SJeroen Hofstee 
328*3669e0e7SSimon Glass /**
329*3669e0e7SSimon Glass  * gpio_request_by_name() - Locate and request a GPIO by name
330*3669e0e7SSimon Glass  *
331*3669e0e7SSimon Glass  * This operates by looking up the given list name in the device (device
332*3669e0e7SSimon Glass  * tree property) and requesting the GPIO for use. The property must exist
333*3669e0e7SSimon Glass  * in @dev's node.
334*3669e0e7SSimon Glass  *
335*3669e0e7SSimon Glass  * Use @flags to specify whether the GPIO should be an input or output. In
336*3669e0e7SSimon Glass  * principle this can also come from the device tree binding but most
337*3669e0e7SSimon Glass  * bindings don't provide this information. Specifically, when the GPIO uclass
338*3669e0e7SSimon Glass  * calls the xlate() method, it can return default flags, which are then
339*3669e0e7SSimon Glass  * ORed with this @flags.
340*3669e0e7SSimon Glass  *
341*3669e0e7SSimon Glass  * If we find that requesting the GPIO is not always needed we could add a
342*3669e0e7SSimon Glass  * new function or a new GPIOD_NO_REQUEST flag.
343*3669e0e7SSimon Glass  *
344*3669e0e7SSimon Glass  * At present driver model has no reference counting so if one device
345*3669e0e7SSimon Glass  * requests a GPIO which subsequently is unbound, the @desc->dev pointer
346*3669e0e7SSimon Glass  * will be invalid. However this will only happen if the GPIO device is
347*3669e0e7SSimon Glass  * unbound, not if it is removed, so this seems like a reasonable limitation
348*3669e0e7SSimon Glass  * for now. There is no real use case for unbinding drivers in normal
349*3669e0e7SSimon Glass  * operation.
350*3669e0e7SSimon Glass  *
351*3669e0e7SSimon Glass  * The device tree binding is doc/device-tree-bindings/gpio/gpio.txt in
352*3669e0e7SSimon Glass  * generate terms and each specific device may add additional details in
353*3669e0e7SSimon Glass  * a binding file in the same directory.
354*3669e0e7SSimon Glass  *
355*3669e0e7SSimon Glass  * @dev:	Device requesting the GPIO
356*3669e0e7SSimon Glass  * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
357*3669e0e7SSimon Glass  * @index:	Index number of the GPIO in that list use request (0=first)
358*3669e0e7SSimon Glass  * @desc:	Returns GPIO description information. If there is no such
359*3669e0e7SSimon Glass  *		GPIO, dev->dev will be NULL.
360*3669e0e7SSimon Glass  * @flags:	Indicates the GPIO input/output settings (GPIOD_...)
361*3669e0e7SSimon Glass  * @return 0 if OK, -ENOENT if the GPIO does not exist, -EINVAL if there is
362*3669e0e7SSimon Glass  * something wrong with the list, or other -ve for another error (e.g.
363*3669e0e7SSimon Glass  * -EBUSY if a GPIO was already requested)
364*3669e0e7SSimon Glass  */
365*3669e0e7SSimon Glass int gpio_request_by_name(struct udevice *dev, const char *list_name,
366*3669e0e7SSimon Glass 			 int index, struct gpio_desc *desc, int flags);
367*3669e0e7SSimon Glass 
368*3669e0e7SSimon Glass /**
369*3669e0e7SSimon Glass  * gpio_request_list_by_name() - Request a list of GPIOs
370*3669e0e7SSimon Glass  *
371*3669e0e7SSimon Glass  * Reads all the GPIOs from a list and requetss them. See
372*3669e0e7SSimon Glass  * gpio_request_by_name() for additional details. Lists should not be
373*3669e0e7SSimon Glass  * misused to hold unrelated or optional GPIOs. They should only be used
374*3669e0e7SSimon Glass  * for things like parallel data lines. A zero phandle terminates the list
375*3669e0e7SSimon Glass  * the list.
376*3669e0e7SSimon Glass  *
377*3669e0e7SSimon Glass  * This function will either succeed, and request all GPIOs in the list, or
378*3669e0e7SSimon Glass  * fail and request none (it will free already-requested GPIOs in case of
379*3669e0e7SSimon Glass  * an error part-way through).
380*3669e0e7SSimon Glass  *
381*3669e0e7SSimon Glass  * @dev:	Device requesting the GPIO
382*3669e0e7SSimon Glass  * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
383*3669e0e7SSimon Glass  * @desc_list:	Returns a list of GPIO description information
384*3669e0e7SSimon Glass  * @max_count:	Maximum number of GPIOs to return (@desc_list must be at least
385*3669e0e7SSimon Glass  *		this big)
386*3669e0e7SSimon Glass  * @flags:	Indicates the GPIO input/output settings (GPIOD_...)
387*3669e0e7SSimon Glass  * @return number of GPIOs requested, or -ve on error
388*3669e0e7SSimon Glass  */
389*3669e0e7SSimon Glass int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
390*3669e0e7SSimon Glass 			      struct gpio_desc *desc_list, int max_count,
391*3669e0e7SSimon Glass 			      int flags);
392*3669e0e7SSimon Glass 
393*3669e0e7SSimon Glass /**
394*3669e0e7SSimon Glass  * gpio_get_list_count() - Returns the number of GPIOs in a list
395*3669e0e7SSimon Glass  *
396*3669e0e7SSimon Glass  * Counts the GPIOs in a list. See gpio_request_by_name() for additional
397*3669e0e7SSimon Glass  * details.
398*3669e0e7SSimon Glass  *
399*3669e0e7SSimon Glass  * @dev:	Device requesting the GPIO
400*3669e0e7SSimon Glass  * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
401*3669e0e7SSimon Glass  * @return number of GPIOs (0 for an empty property) or -ENOENT if the list
402*3669e0e7SSimon Glass  * does not exist
403*3669e0e7SSimon Glass  */
404*3669e0e7SSimon Glass int gpio_get_list_count(struct udevice *dev, const char *list_name);
405*3669e0e7SSimon Glass 
406*3669e0e7SSimon Glass /**
407*3669e0e7SSimon Glass  * gpio_request_by_name_nodev() - request GPIOs without a device
408*3669e0e7SSimon Glass  *
409*3669e0e7SSimon Glass  * This is a version of gpio_request_list_by_name() that does not use a
410*3669e0e7SSimon Glass  * device. Avoid it unless the caller is not yet using driver model
411*3669e0e7SSimon Glass  */
412*3669e0e7SSimon Glass int gpio_request_by_name_nodev(const void *blob, int node,
413*3669e0e7SSimon Glass 			       const char *list_name,
414*3669e0e7SSimon Glass 			       int index, struct gpio_desc *desc, int flags);
415*3669e0e7SSimon Glass 
416*3669e0e7SSimon Glass /**
417*3669e0e7SSimon Glass  * gpio_request_list_by_name_nodev() - request GPIOs without a device
418*3669e0e7SSimon Glass  *
419*3669e0e7SSimon Glass  * This is a version of gpio_request_list_by_name() that does not use a
420*3669e0e7SSimon Glass  * device. Avoid it unless the caller is not yet using driver model
421*3669e0e7SSimon Glass  */
422*3669e0e7SSimon Glass int gpio_request_list_by_name_nodev(const void *blob, int node,
423*3669e0e7SSimon Glass 				    const char *list_name,
424*3669e0e7SSimon Glass 				    struct gpio_desc *desc_list, int max_count,
425*3669e0e7SSimon Glass 				    int flags);
426*3669e0e7SSimon Glass 
427*3669e0e7SSimon Glass /**
428*3669e0e7SSimon Glass  * dm_gpio_free() - Free a single GPIO
429*3669e0e7SSimon Glass  *
430*3669e0e7SSimon Glass  * This frees a single GPIOs previously returned from gpio_request_by_name().
431*3669e0e7SSimon Glass  *
432*3669e0e7SSimon Glass  * @dev:	Device which requested the GPIO
433*3669e0e7SSimon Glass  * @desc:	GPIO to free
434*3669e0e7SSimon Glass  * @return 0 if OK, -ve on error
435*3669e0e7SSimon Glass  */
436*3669e0e7SSimon Glass int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc);
437*3669e0e7SSimon Glass 
438*3669e0e7SSimon Glass /**
439*3669e0e7SSimon Glass  * gpio_free_list() - Free a list of GPIOs
440*3669e0e7SSimon Glass  *
441*3669e0e7SSimon Glass  * This frees a list of GPIOs previously returned from
442*3669e0e7SSimon Glass  * gpio_request_list_by_name().
443*3669e0e7SSimon Glass  *
444*3669e0e7SSimon Glass  * @dev:	Device which requested the GPIOs
445*3669e0e7SSimon Glass  * @desc:	List of GPIOs to free
446*3669e0e7SSimon Glass  * @count:	Number of GPIOs in the list
447*3669e0e7SSimon Glass  * @return 0 if OK, -ve on error
448*3669e0e7SSimon Glass  */
449*3669e0e7SSimon Glass int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count);
450*3669e0e7SSimon Glass 
451*3669e0e7SSimon Glass /**
452*3669e0e7SSimon Glass  * gpio_free_list_nodev() - free GPIOs without a device
453*3669e0e7SSimon Glass  *
454*3669e0e7SSimon Glass  * This is a version of gpio_free_list() that does not use a
455*3669e0e7SSimon Glass  * device. Avoid it unless the caller is not yet using driver model
456*3669e0e7SSimon Glass  */
457*3669e0e7SSimon Glass int gpio_free_list_nodev(struct gpio_desc *desc, int count);
458*3669e0e7SSimon Glass 
459*3669e0e7SSimon Glass /**
460*3669e0e7SSimon Glass  * dm_gpio_get_value() - Get the value of a GPIO
461*3669e0e7SSimon Glass  *
462*3669e0e7SSimon Glass  * This is the driver model version of the existing gpio_get_value() function
463*3669e0e7SSimon Glass  * and should be used instead of that.
464*3669e0e7SSimon Glass  *
465*3669e0e7SSimon Glass  * For now, these functions have a dm_ prefix since they conflict with
466*3669e0e7SSimon Glass  * existing names.
467*3669e0e7SSimon Glass  *
468*3669e0e7SSimon Glass  * @desc:	GPIO description containing device, offset and flags,
469*3669e0e7SSimon Glass  *		previously returned by gpio_request_by_name()
470*3669e0e7SSimon Glass  * @return GPIO value (0 for inactive, 1 for active) or -ve on error
471*3669e0e7SSimon Glass  */
472*3669e0e7SSimon Glass int dm_gpio_get_value(struct gpio_desc *desc);
473*3669e0e7SSimon Glass 
474*3669e0e7SSimon Glass int dm_gpio_set_value(struct gpio_desc *desc, int value);
475*3669e0e7SSimon Glass 
476*3669e0e7SSimon Glass /**
477*3669e0e7SSimon Glass  * dm_gpio_set_dir() - Set the direction for a GPIO
478*3669e0e7SSimon Glass  *
479*3669e0e7SSimon Glass  * This sets up the direction according tot the provided flags. It will do
480*3669e0e7SSimon Glass  * nothing unless the direction is actually specified.
481*3669e0e7SSimon Glass  *
482*3669e0e7SSimon Glass  * @desc:	GPIO description containing device, offset and flags,
483*3669e0e7SSimon Glass  *		previously returned by gpio_request_by_name()
484*3669e0e7SSimon Glass  * @return 0 if OK, -ve on error
485*3669e0e7SSimon Glass  */
486*3669e0e7SSimon Glass int dm_gpio_set_dir(struct gpio_desc *desc);
487*3669e0e7SSimon Glass 
488*3669e0e7SSimon Glass /**
489*3669e0e7SSimon Glass  * dm_gpio_set_dir_flags() - Set direction using specific flags
490*3669e0e7SSimon Glass  *
491*3669e0e7SSimon Glass  * This is like dm_gpio_set_dir() except that the flags value is provided
492*3669e0e7SSimon Glass  * instead of being used from desc->flags. This is needed because in many
493*3669e0e7SSimon Glass  * cases the GPIO description does not include direction information.
494*3669e0e7SSimon Glass  * Note that desc->flags is updated by this function.
495*3669e0e7SSimon Glass  *
496*3669e0e7SSimon Glass  * @desc:	GPIO description containing device, offset and flags,
497*3669e0e7SSimon Glass  *		previously returned by gpio_request_by_name()
498*3669e0e7SSimon Glass  * @flags:	New flags to use
499*3669e0e7SSimon Glass  * @return 0 if OK, -ve on error, in which case desc->flags is not updated
500*3669e0e7SSimon Glass  */
501*3669e0e7SSimon Glass int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags);
502*3669e0e7SSimon Glass 
503*3669e0e7SSimon Glass /**
504*3669e0e7SSimon Glass  * gpio_get_number() - Get the global GPIO number of a GPIO
505*3669e0e7SSimon Glass  *
506*3669e0e7SSimon Glass  * This should only be used for debugging or interest. It returns the nummber
507*3669e0e7SSimon Glass  * that should be used for gpio_get_value() etc. to access this GPIO.
508*3669e0e7SSimon Glass  *
509*3669e0e7SSimon Glass  * @desc:	GPIO description containing device, offset and flags,
510*3669e0e7SSimon Glass  *		previously returned by gpio_request_by_name()
511*3669e0e7SSimon Glass  * @return GPIO number, or -ve if not found
512*3669e0e7SSimon Glass  */
513*3669e0e7SSimon Glass int gpio_get_number(struct gpio_desc *desc);
514*3669e0e7SSimon Glass 
5155f533aebSJoe Hershberger #endif	/* _ASM_GENERIC_GPIO_H_ */
516