@@ -804,8 +804,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
804804 return 1 ;
805805}
806806
807- static int acpi_gpio_resource_lookup (struct acpi_gpio_lookup * lookup ,
808- struct acpi_gpio_info * info )
807+ static int acpi_gpio_resource_lookup (struct acpi_gpio_lookup * lookup )
809808{
810809 struct acpi_device * adev = lookup -> info .adev ;
811810 struct list_head res_list ;
@@ -824,8 +823,6 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
824823 if (!lookup -> desc )
825824 return - ENOENT ;
826825
827- if (info )
828- * info = lookup -> info ;
829826 return 0 ;
830827}
831828
@@ -871,97 +868,83 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
871868 * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
872869 * @adev: pointer to a ACPI device to get GPIO from
873870 * @propname: Property name of the GPIO (optional)
874- * @index: index of GpioIo/GpioInt resource (starting from %0)
875- * @info: info pointer to fill in (optional)
871+ * @lookup: pointer to struct acpi_gpio_lookup to fill in
876872 *
877- * Function goes through ACPI resources for @adev and based on @index looks
873+ * Function goes through ACPI resources for @adev and based on @lookup. index looks
878874 * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor,
879- * and returns it. @index matches GpioIo/GpioInt resources only so if there
880- * are total % 3 GPIO resources, the index goes from % 0 to % 2.
875+ * and returns it. @lookup. index matches GpioIo/GpioInt resources only so if there
876+ * are total 3 GPIO resources, the index goes from 0 to 2.
881877 *
882878 * If @propname is specified the GPIO is looked using device property. In
883879 * that case @index is used to select the GPIO entry in the property value
884880 * (in case of multiple).
885881 *
886882 * Returns:
887- * GPIO descriptor to use with Linux generic GPIO API.
888- * If the GPIO cannot be translated or there is an error an ERR_PTR is
889- * returned.
883+ * 0 on success, negative errno on failure.
884+ *
885+ * The @lookup is filled with GPIO descriptor to use with Linux generic GPIO API.
886+ * If the GPIO cannot be translated an error will be returned.
890887 *
891888 * Note: if the GPIO resource has multiple entries in the pin list, this
892889 * function only returns the first.
893890 */
894- static struct gpio_desc * acpi_get_gpiod_by_index (struct acpi_device * adev ,
895- const char * propname ,
896- int index ,
897- struct acpi_gpio_info * info )
891+ static int acpi_get_gpiod_by_index (struct acpi_device * adev , const char * propname ,
892+ struct acpi_gpio_lookup * lookup )
898893{
899- struct acpi_gpio_lookup lookup ;
900- struct acpi_gpio_params * params = & lookup . params ;
894+ struct acpi_gpio_info * info = & lookup -> info ;
895+ struct acpi_gpio_params * params = & lookup -> params ;
901896 int ret ;
902897
903- memset (& lookup , 0 , sizeof (lookup ));
904- params -> crs_entry_index = index ;
905-
906898 if (propname ) {
907899 dev_dbg (& adev -> dev , "GPIO: looking up %s\n" , propname );
908900
909- ret = acpi_gpio_property_lookup (acpi_fwnode_handle (adev ), propname , & lookup );
901+ ret = acpi_gpio_property_lookup (acpi_fwnode_handle (adev ), propname , lookup );
910902 if (ret )
911- return ERR_PTR ( ret ) ;
903+ return ret ;
912904
913905 dev_dbg (& adev -> dev , "GPIO: _DSD returned %s %u %u %u\n" ,
914- dev_name (& lookup . info . adev -> dev ),
906+ dev_name (& info -> adev -> dev ),
915907 params -> crs_entry_index , params -> line_index , params -> active_low );
916908 } else {
917909 dev_dbg (& adev -> dev , "GPIO: looking up %u in _CRS\n" , params -> crs_entry_index );
918- lookup . info . adev = adev ;
910+ info -> adev = adev ;
919911 }
920912
921- ret = acpi_gpio_resource_lookup (& lookup , info );
922- return ret ? ERR_PTR (ret ) : lookup .desc ;
913+ return acpi_gpio_resource_lookup (lookup );
923914}
924915
925916/**
926917 * acpi_get_gpiod_from_data() - get a GPIO descriptor from ACPI data node
927918 * @fwnode: pointer to an ACPI firmware node to get the GPIO information from
928919 * @propname: Property name of the GPIO
929- * @index: index of GpioIo/GpioInt resource (starting from %0)
930- * @info: info pointer to fill in (optional)
920+ * @lookup: pointer to struct acpi_gpio_lookup to fill in
931921 *
932922 * This function uses the property-based GPIO lookup to get to the GPIO
933923 * resource with the relevant information from a data-only ACPI firmware node
934924 * and uses that to obtain the GPIO descriptor to return.
935925 *
936926 * Returns:
937- * GPIO descriptor to use with Linux generic GPIO API.
938- * If the GPIO cannot be translated or there is an error an ERR_PTR is
939- * returned.
927+ * 0 on success, negative errno on failure.
928+ *
929+ * The @lookup is filled with GPIO descriptor to use with Linux generic GPIO API.
930+ * If the GPIO cannot be translated an error will be returned.
940931 */
941- static struct gpio_desc * acpi_get_gpiod_from_data (struct fwnode_handle * fwnode ,
942- const char * propname ,
943- int index ,
944- struct acpi_gpio_info * info )
932+ static int acpi_get_gpiod_from_data (struct fwnode_handle * fwnode , const char * propname ,
933+ struct acpi_gpio_lookup * lookup )
945934{
946- struct acpi_gpio_lookup lookup ;
947- struct acpi_gpio_params * params = & lookup .params ;
948935 int ret ;
949936
950937 if (!is_acpi_data_node (fwnode ))
951- return ERR_PTR ( - ENODEV ) ;
938+ return - ENODEV ;
952939
953940 if (!propname )
954- return ERR_PTR (- EINVAL );
955-
956- memset (& lookup , 0 , sizeof (lookup ));
957- params -> crs_entry_index = index ;
941+ return - EINVAL ;
958942
959- ret = acpi_gpio_property_lookup (fwnode , propname , & lookup );
943+ ret = acpi_gpio_property_lookup (fwnode , propname , lookup );
960944 if (ret )
961- return ERR_PTR ( ret ) ;
945+ return ret ;
962946
963- ret = acpi_gpio_resource_lookup (& lookup , info );
964- return ret ? ERR_PTR (ret ) : lookup .desc ;
947+ return acpi_gpio_resource_lookup (lookup );
965948}
966949
967950static bool acpi_can_fallback_to_crs (struct acpi_device * adev ,
@@ -983,17 +966,24 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
983966 bool can_fallback , struct acpi_gpio_info * info )
984967{
985968 struct acpi_device * adev = to_acpi_device_node (fwnode );
969+ struct acpi_gpio_lookup lookup ;
986970 struct gpio_desc * desc ;
987971 char propname [32 ];
972+ int ret ;
973+
974+ memset (& lookup , 0 , sizeof (lookup ));
975+ lookup .params .crs_entry_index = idx ;
988976
989977 /* Try first from _DSD */
990978 for_each_gpio_property_name (propname , con_id ) {
991979 if (adev )
992- desc = acpi_get_gpiod_by_index (adev ,
993- propname , idx , info );
980+ ret = acpi_get_gpiod_by_index (adev , propname , & lookup );
994981 else
995- desc = acpi_get_gpiod_from_data (fwnode ,
996- propname , idx , info );
982+ ret = acpi_get_gpiod_from_data (fwnode , propname , & lookup );
983+ if (ret )
984+ continue ;
985+
986+ desc = lookup .desc ;
997987 if (PTR_ERR (desc ) == - EPROBE_DEFER )
998988 return desc ;
999989
@@ -1002,8 +992,13 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
1002992 }
1003993
1004994 /* Then from plain _CRS GPIOs */
1005- if (can_fallback )
1006- return acpi_get_gpiod_by_index (adev , NULL , idx , info );
995+ if (can_fallback ) {
996+ ret = acpi_get_gpiod_by_index (adev , NULL , & lookup );
997+ if (ret )
998+ return ERR_PTR (ret );
999+
1000+ return lookup .desc ;
1001+ }
10071002
10081003 return ERR_PTR (- ENOENT );
10091004}
0 commit comments