@@ -804,8 +804,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
804
804
return 1 ;
805
805
}
806
806
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 )
809
808
{
810
809
struct acpi_device * adev = lookup -> info .adev ;
811
810
struct list_head res_list ;
@@ -824,8 +823,6 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
824
823
if (!lookup -> desc )
825
824
return - ENOENT ;
826
825
827
- if (info )
828
- * info = lookup -> info ;
829
826
return 0 ;
830
827
}
831
828
@@ -871,97 +868,83 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
871
868
* acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
872
869
* @adev: pointer to a ACPI device to get GPIO from
873
870
* @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
876
872
*
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
878
874
* 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.
881
877
*
882
878
* If @propname is specified the GPIO is looked using device property. In
883
879
* that case @index is used to select the GPIO entry in the property value
884
880
* (in case of multiple).
885
881
*
886
882
* 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.
890
887
*
891
888
* Note: if the GPIO resource has multiple entries in the pin list, this
892
889
* function only returns the first.
893
890
*/
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 )
898
893
{
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 ;
901
896
int ret ;
902
897
903
- memset (& lookup , 0 , sizeof (lookup ));
904
- params -> crs_entry_index = index ;
905
-
906
898
if (propname ) {
907
899
dev_dbg (& adev -> dev , "GPIO: looking up %s\n" , propname );
908
900
909
- ret = acpi_gpio_property_lookup (acpi_fwnode_handle (adev ), propname , & lookup );
901
+ ret = acpi_gpio_property_lookup (acpi_fwnode_handle (adev ), propname , lookup );
910
902
if (ret )
911
- return ERR_PTR ( ret ) ;
903
+ return ret ;
912
904
913
905
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 ),
915
907
params -> crs_entry_index , params -> line_index , params -> active_low );
916
908
} else {
917
909
dev_dbg (& adev -> dev , "GPIO: looking up %u in _CRS\n" , params -> crs_entry_index );
918
- lookup . info . adev = adev ;
910
+ info -> adev = adev ;
919
911
}
920
912
921
- ret = acpi_gpio_resource_lookup (& lookup , info );
922
- return ret ? ERR_PTR (ret ) : lookup .desc ;
913
+ return acpi_gpio_resource_lookup (lookup );
923
914
}
924
915
925
916
/**
926
917
* acpi_get_gpiod_from_data() - get a GPIO descriptor from ACPI data node
927
918
* @fwnode: pointer to an ACPI firmware node to get the GPIO information from
928
919
* @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
931
921
*
932
922
* This function uses the property-based GPIO lookup to get to the GPIO
933
923
* resource with the relevant information from a data-only ACPI firmware node
934
924
* and uses that to obtain the GPIO descriptor to return.
935
925
*
936
926
* 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.
940
931
*/
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 )
945
934
{
946
- struct acpi_gpio_lookup lookup ;
947
- struct acpi_gpio_params * params = & lookup .params ;
948
935
int ret ;
949
936
950
937
if (!is_acpi_data_node (fwnode ))
951
- return ERR_PTR ( - ENODEV ) ;
938
+ return - ENODEV ;
952
939
953
940
if (!propname )
954
- return ERR_PTR (- EINVAL );
955
-
956
- memset (& lookup , 0 , sizeof (lookup ));
957
- params -> crs_entry_index = index ;
941
+ return - EINVAL ;
958
942
959
- ret = acpi_gpio_property_lookup (fwnode , propname , & lookup );
943
+ ret = acpi_gpio_property_lookup (fwnode , propname , lookup );
960
944
if (ret )
961
- return ERR_PTR ( ret ) ;
945
+ return ret ;
962
946
963
- ret = acpi_gpio_resource_lookup (& lookup , info );
964
- return ret ? ERR_PTR (ret ) : lookup .desc ;
947
+ return acpi_gpio_resource_lookup (lookup );
965
948
}
966
949
967
950
static 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
983
966
bool can_fallback , struct acpi_gpio_info * info )
984
967
{
985
968
struct acpi_device * adev = to_acpi_device_node (fwnode );
969
+ struct acpi_gpio_lookup lookup ;
986
970
struct gpio_desc * desc ;
987
971
char propname [32 ];
972
+ int ret ;
973
+
974
+ memset (& lookup , 0 , sizeof (lookup ));
975
+ lookup .params .crs_entry_index = idx ;
988
976
989
977
/* Try first from _DSD */
990
978
for_each_gpio_property_name (propname , con_id ) {
991
979
if (adev )
992
- desc = acpi_get_gpiod_by_index (adev ,
993
- propname , idx , info );
980
+ ret = acpi_get_gpiod_by_index (adev , propname , & lookup );
994
981
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 ;
997
987
if (PTR_ERR (desc ) == - EPROBE_DEFER )
998
988
return desc ;
999
989
@@ -1002,8 +992,13 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
1002
992
}
1003
993
1004
994
/* 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
+ }
1007
1002
1008
1003
return ERR_PTR (- ENOENT );
1009
1004
}
0 commit comments