@@ -96,21 +96,21 @@ struct acpi_gpio_chip {
96
96
* @adev: reference to ACPI device which consumes GPIO resource
97
97
* @flags: GPIO initialization flags
98
98
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
99
+ * @wake_capable: wake capability as provided by ACPI
99
100
* @pin_config: pin bias as provided by ACPI
100
101
* @polarity: interrupt polarity as provided by ACPI
101
102
* @triggering: triggering type as provided by ACPI
102
- * @wake_capable: wake capability as provided by ACPI
103
103
* @debounce: debounce timeout as provided by ACPI
104
104
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
105
105
*/
106
106
struct acpi_gpio_info {
107
107
struct acpi_device * adev ;
108
108
enum gpiod_flags flags ;
109
109
bool gpioint ;
110
+ bool wake_capable ;
110
111
int pin_config ;
111
112
int polarity ;
112
113
int triggering ;
113
- bool wake_capable ;
114
114
unsigned int debounce ;
115
115
unsigned int quirks ;
116
116
};
@@ -653,12 +653,12 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
653
653
654
654
for (gm = adev -> driver_gpios ; gm -> name ; gm ++ )
655
655
if (!strcmp (name , gm -> name ) && gm -> data && index < gm -> size ) {
656
- const struct acpi_gpio_params * par = gm -> data + index ;
656
+ const struct acpi_gpio_params * params = gm -> data + index ;
657
657
658
658
args -> fwnode = acpi_fwnode_handle (adev );
659
- args -> args [0 ] = par -> crs_entry_index ;
660
- args -> args [1 ] = par -> line_index ;
661
- args -> args [2 ] = par -> active_low ;
659
+ args -> args [0 ] = params -> crs_entry_index ;
660
+ args -> args [1 ] = params -> line_index ;
661
+ args -> args [2 ] = params -> active_low ;
662
662
args -> nargs = 3 ;
663
663
664
664
* quirks = gm -> quirks ;
@@ -744,16 +744,15 @@ static int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
744
744
745
745
struct acpi_gpio_lookup {
746
746
struct acpi_gpio_info info ;
747
- int index ;
748
- u16 pin_index ;
749
- bool active_low ;
747
+ struct acpi_gpio_params params ;
750
748
struct gpio_desc * desc ;
751
749
int n ;
752
750
};
753
751
754
752
static int acpi_populate_gpio_lookup (struct acpi_resource * ares , void * data )
755
753
{
756
754
struct acpi_gpio_lookup * lookup = data ;
755
+ struct acpi_gpio_params * params = & lookup -> params ;
757
756
758
757
if (ares -> type != ACPI_RESOURCE_TYPE_GPIO )
759
758
return 1 ;
@@ -765,12 +764,12 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
765
764
u16 pin_index ;
766
765
767
766
if (lookup -> info .quirks & ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint )
768
- lookup -> index ++ ;
767
+ params -> crs_entry_index ++ ;
769
768
770
- if (lookup -> n ++ != lookup -> index )
769
+ if (lookup -> n ++ != params -> crs_entry_index )
771
770
return 1 ;
772
771
773
- pin_index = lookup -> pin_index ;
772
+ pin_index = params -> line_index ;
774
773
if (pin_index >= agpio -> pin_table_length )
775
774
return 1 ;
776
775
@@ -796,7 +795,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
796
795
lookup -> info .polarity = agpio -> polarity ;
797
796
lookup -> info .triggering = agpio -> triggering ;
798
797
} else {
799
- lookup -> info .polarity = lookup -> active_low ;
798
+ lookup -> info .polarity = params -> active_low ;
800
799
}
801
800
802
801
lookup -> info .flags = acpi_gpio_to_gpiod_flags (agpio , lookup -> info .polarity );
@@ -805,8 +804,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
805
804
return 1 ;
806
805
}
807
806
808
- static int acpi_gpio_resource_lookup (struct acpi_gpio_lookup * lookup ,
809
- struct acpi_gpio_info * info )
807
+ static int acpi_gpio_resource_lookup (struct acpi_gpio_lookup * lookup )
810
808
{
811
809
struct acpi_device * adev = lookup -> info .adev ;
812
810
struct list_head res_list ;
@@ -825,22 +823,21 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
825
823
if (!lookup -> desc )
826
824
return - ENOENT ;
827
825
828
- if (info )
829
- * info = lookup -> info ;
830
826
return 0 ;
831
827
}
832
828
833
- static int acpi_gpio_property_lookup (struct fwnode_handle * fwnode ,
834
- const char * propname , int index ,
829
+ static int acpi_gpio_property_lookup (struct fwnode_handle * fwnode , const char * propname ,
835
830
struct acpi_gpio_lookup * lookup )
836
831
{
837
832
struct fwnode_reference_args args ;
833
+ struct acpi_gpio_params * params = & lookup -> params ;
834
+ unsigned int index = params -> crs_entry_index ;
838
835
unsigned int quirks = 0 ;
839
836
int ret ;
840
837
841
838
memset (& args , 0 , sizeof (args ));
842
- ret = __acpi_node_get_property_reference ( fwnode , propname , index , 3 ,
843
- & args );
839
+
840
+ ret = __acpi_node_get_property_reference ( fwnode , propname , index , 3 , & args );
844
841
if (ret ) {
845
842
struct acpi_device * adev ;
846
843
@@ -857,9 +854,9 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
857
854
if (args .nargs != 3 )
858
855
return - EPROTO ;
859
856
860
- lookup -> index = args .args [0 ];
861
- lookup -> pin_index = args .args [1 ];
862
- lookup -> active_low = !!args .args [2 ];
857
+ params -> crs_entry_index = args .args [0 ];
858
+ params -> line_index = args .args [1 ];
859
+ params -> active_low = !!args .args [2 ];
863
860
864
861
lookup -> info .adev = to_acpi_device_node (args .fwnode );
865
862
lookup -> info .quirks = quirks ;
@@ -871,96 +868,83 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
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 ;
894
+ struct acpi_gpio_info * info = & lookup -> info ;
895
+ struct acpi_gpio_params * params = & lookup -> params ;
900
896
int ret ;
901
897
902
- memset (& lookup , 0 , sizeof (lookup ));
903
- lookup .index = index ;
904
-
905
898
if (propname ) {
906
899
dev_dbg (& adev -> dev , "GPIO: looking up %s\n" , propname );
907
900
908
- ret = acpi_gpio_property_lookup (acpi_fwnode_handle (adev ),
909
- propname , index , & 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
- dev_dbg (& adev -> dev , "GPIO: _DSD returned %s %d %u %u\n" ,
914
- dev_name (& lookup . info . adev -> dev ), lookup . index ,
915
- lookup . pin_index , lookup . active_low );
905
+ dev_dbg (& adev -> dev , "GPIO: _DSD returned %s %u %u %u\n" ,
906
+ dev_name (& info -> adev -> dev ),
907
+ params -> crs_entry_index , params -> line_index , params -> active_low );
916
908
} else {
917
- dev_dbg (& adev -> dev , "GPIO: looking up %d in _CRS\n" , index );
918
- lookup . info . adev = adev ;
909
+ dev_dbg (& adev -> dev , "GPIO: looking up %u in _CRS\n" , params -> crs_entry_index );
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
935
int ret ;
948
936
949
937
if (!is_acpi_data_node (fwnode ))
950
- return ERR_PTR ( - ENODEV ) ;
938
+ return - ENODEV ;
951
939
952
940
if (!propname )
953
- return ERR_PTR (- EINVAL );
954
-
955
- memset (& lookup , 0 , sizeof (lookup ));
956
- lookup .index = index ;
941
+ return - EINVAL ;
957
942
958
- ret = acpi_gpio_property_lookup (fwnode , propname , index , & lookup );
943
+ ret = acpi_gpio_property_lookup (fwnode , propname , lookup );
959
944
if (ret )
960
- return ERR_PTR ( ret ) ;
945
+ return ret ;
961
946
962
- ret = acpi_gpio_resource_lookup (& lookup , info );
963
- return ret ? ERR_PTR (ret ) : lookup .desc ;
947
+ return acpi_gpio_resource_lookup (lookup );
964
948
}
965
949
966
950
static bool acpi_can_fallback_to_crs (struct acpi_device * adev ,
@@ -982,17 +966,24 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
982
966
bool can_fallback , struct acpi_gpio_info * info )
983
967
{
984
968
struct acpi_device * adev = to_acpi_device_node (fwnode );
969
+ struct acpi_gpio_lookup lookup ;
985
970
struct gpio_desc * desc ;
986
971
char propname [32 ];
972
+ int ret ;
973
+
974
+ memset (& lookup , 0 , sizeof (lookup ));
975
+ lookup .params .crs_entry_index = idx ;
987
976
988
977
/* Try first from _DSD */
989
978
for_each_gpio_property_name (propname , con_id ) {
990
979
if (adev )
991
- desc = acpi_get_gpiod_by_index (adev ,
992
- propname , idx , info );
980
+ ret = acpi_get_gpiod_by_index (adev , propname , & lookup );
993
981
else
994
- desc = acpi_get_gpiod_from_data (fwnode ,
995
- propname , idx , info );
982
+ ret = acpi_get_gpiod_from_data (fwnode , propname , & lookup );
983
+ if (ret )
984
+ continue ;
985
+
986
+ desc = lookup .desc ;
996
987
if (PTR_ERR (desc ) == - EPROBE_DEFER )
997
988
return desc ;
998
989
@@ -1001,8 +992,13 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
1001
992
}
1002
993
1003
994
/* Then from plain _CRS GPIOs */
1004
- if (can_fallback )
1005
- 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
+ }
1006
1002
1007
1003
return ERR_PTR (- ENOENT );
1008
1004
}
0 commit comments