@@ -96,21 +96,21 @@ struct acpi_gpio_chip {
9696 * @adev: reference to ACPI device which consumes GPIO resource
9797 * @flags: GPIO initialization flags
9898 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
99+ * @wake_capable: wake capability as provided by ACPI
99100 * @pin_config: pin bias as provided by ACPI
100101 * @polarity: interrupt polarity as provided by ACPI
101102 * @triggering: triggering type as provided by ACPI
102- * @wake_capable: wake capability as provided by ACPI
103103 * @debounce: debounce timeout as provided by ACPI
104104 * @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
105105 */
106106struct acpi_gpio_info {
107107 struct acpi_device * adev ;
108108 enum gpiod_flags flags ;
109109 bool gpioint ;
110+ bool wake_capable ;
110111 int pin_config ;
111112 int polarity ;
112113 int triggering ;
113- bool wake_capable ;
114114 unsigned int debounce ;
115115 unsigned int quirks ;
116116};
@@ -653,12 +653,12 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
653653
654654 for (gm = adev -> driver_gpios ; gm -> name ; gm ++ )
655655 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 ;
657657
658658 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 ;
662662 args -> nargs = 3 ;
663663
664664 * quirks = gm -> quirks ;
@@ -744,16 +744,15 @@ static int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
744744
745745struct acpi_gpio_lookup {
746746 struct acpi_gpio_info info ;
747- int index ;
748- u16 pin_index ;
749- bool active_low ;
747+ struct acpi_gpio_params params ;
750748 struct gpio_desc * desc ;
751749 int n ;
752750};
753751
754752static int acpi_populate_gpio_lookup (struct acpi_resource * ares , void * data )
755753{
756754 struct acpi_gpio_lookup * lookup = data ;
755+ struct acpi_gpio_params * params = & lookup -> params ;
757756
758757 if (ares -> type != ACPI_RESOURCE_TYPE_GPIO )
759758 return 1 ;
@@ -765,12 +764,12 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
765764 u16 pin_index ;
766765
767766 if (lookup -> info .quirks & ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint )
768- lookup -> index ++ ;
767+ params -> crs_entry_index ++ ;
769768
770- if (lookup -> n ++ != lookup -> index )
769+ if (lookup -> n ++ != params -> crs_entry_index )
771770 return 1 ;
772771
773- pin_index = lookup -> pin_index ;
772+ pin_index = params -> line_index ;
774773 if (pin_index >= agpio -> pin_table_length )
775774 return 1 ;
776775
@@ -796,7 +795,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
796795 lookup -> info .polarity = agpio -> polarity ;
797796 lookup -> info .triggering = agpio -> triggering ;
798797 } else {
799- lookup -> info .polarity = lookup -> active_low ;
798+ lookup -> info .polarity = params -> active_low ;
800799 }
801800
802801 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)
805804 return 1 ;
806805}
807806
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 )
810808{
811809 struct acpi_device * adev = lookup -> info .adev ;
812810 struct list_head res_list ;
@@ -825,22 +823,21 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
825823 if (!lookup -> desc )
826824 return - ENOENT ;
827825
828- if (info )
829- * info = lookup -> info ;
830826 return 0 ;
831827}
832828
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 ,
835830 struct acpi_gpio_lookup * lookup )
836831{
837832 struct fwnode_reference_args args ;
833+ struct acpi_gpio_params * params = & lookup -> params ;
834+ unsigned int index = params -> crs_entry_index ;
838835 unsigned int quirks = 0 ;
839836 int ret ;
840837
841838 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 );
844841 if (ret ) {
845842 struct acpi_device * adev ;
846843
@@ -857,9 +854,9 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
857854 if (args .nargs != 3 )
858855 return - EPROTO ;
859856
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 ];
863860
864861 lookup -> info .adev = to_acpi_device_node (args .fwnode );
865862 lookup -> info .quirks = quirks ;
@@ -871,96 +868,83 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
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 ;
894+ struct acpi_gpio_info * info = & lookup -> info ;
895+ struct acpi_gpio_params * params = & lookup -> params ;
900896 int ret ;
901897
902- memset (& lookup , 0 , sizeof (lookup ));
903- lookup .index = index ;
904-
905898 if (propname ) {
906899 dev_dbg (& adev -> dev , "GPIO: looking up %s\n" , propname );
907900
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 );
910902 if (ret )
911- return ERR_PTR ( ret ) ;
903+ return ret ;
912904
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 );
916908 } 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 ;
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 ;
947935 int ret ;
948936
949937 if (!is_acpi_data_node (fwnode ))
950- return ERR_PTR ( - ENODEV ) ;
938+ return - ENODEV ;
951939
952940 if (!propname )
953- return ERR_PTR (- EINVAL );
954-
955- memset (& lookup , 0 , sizeof (lookup ));
956- lookup .index = index ;
941+ return - EINVAL ;
957942
958- ret = acpi_gpio_property_lookup (fwnode , propname , index , & lookup );
943+ ret = acpi_gpio_property_lookup (fwnode , propname , lookup );
959944 if (ret )
960- return ERR_PTR ( ret ) ;
945+ return ret ;
961946
962- ret = acpi_gpio_resource_lookup (& lookup , info );
963- return ret ? ERR_PTR (ret ) : lookup .desc ;
947+ return acpi_gpio_resource_lookup (lookup );
964948}
965949
966950static 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
982966 bool can_fallback , struct acpi_gpio_info * info )
983967{
984968 struct acpi_device * adev = to_acpi_device_node (fwnode );
969+ struct acpi_gpio_lookup lookup ;
985970 struct gpio_desc * desc ;
986971 char propname [32 ];
972+ int ret ;
973+
974+ memset (& lookup , 0 , sizeof (lookup ));
975+ lookup .params .crs_entry_index = idx ;
987976
988977 /* Try first from _DSD */
989978 for_each_gpio_property_name (propname , con_id ) {
990979 if (adev )
991- desc = acpi_get_gpiod_by_index (adev ,
992- propname , idx , info );
980+ ret = acpi_get_gpiod_by_index (adev , propname , & lookup );
993981 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 ;
996987 if (PTR_ERR (desc ) == - EPROBE_DEFER )
997988 return desc ;
998989
@@ -1001,8 +992,13 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
1001992 }
1002993
1003994 /* 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+ }
10061002
10071003 return ERR_PTR (- ENOENT );
10081004}
0 commit comments