@@ -52,21 +52,15 @@ static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *i
5252 }
5353}
5454
55- static int skl_int3472_map_gpio_to_sensor (struct int3472_discrete_device * int3472 ,
56- struct acpi_resource_gpio * agpio ,
57- const char * func , u32 polarity )
55+ static int skl_int3472_fill_gpiod_lookup (struct gpiod_lookup * table_entry ,
56+ struct acpi_resource_gpio * agpio ,
57+ const char * func , u32 polarity )
5858{
5959 char * path = agpio -> resource_source .string_ptr ;
60- struct gpiod_lookup * table_entry ;
6160 struct acpi_device * adev ;
6261 acpi_handle handle ;
6362 acpi_status status ;
6463
65- if (int3472 -> n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS ) {
66- dev_warn (int3472 -> dev , "Too many GPIOs mapped\n" );
67- return - EINVAL ;
68- }
69-
7064 status = acpi_get_handle (NULL , path , & handle );
7165 if (ACPI_FAILURE (status ))
7266 return - EINVAL ;
@@ -75,18 +69,62 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
7569 if (!adev )
7670 return - ENODEV ;
7771
78- table_entry = & int3472 -> gpios .table [int3472 -> n_sensor_gpios ];
7972 table_entry -> key = acpi_dev_name (adev );
8073 table_entry -> chip_hwnum = agpio -> pin_table [0 ];
8174 table_entry -> con_id = func ;
8275 table_entry -> idx = 0 ;
8376 table_entry -> flags = polarity ;
8477
78+ return 0 ;
79+ }
80+
81+ static int skl_int3472_map_gpio_to_sensor (struct int3472_discrete_device * int3472 ,
82+ struct acpi_resource_gpio * agpio ,
83+ const char * func , u32 polarity )
84+ {
85+ int ret ;
86+
87+ if (int3472 -> n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS ) {
88+ dev_warn (int3472 -> dev , "Too many GPIOs mapped\n" );
89+ return - EINVAL ;
90+ }
91+
92+ ret = skl_int3472_fill_gpiod_lookup (& int3472 -> gpios .table [int3472 -> n_sensor_gpios ],
93+ agpio , func , polarity );
94+ if (ret )
95+ return ret ;
96+
8597 int3472 -> n_sensor_gpios ++ ;
8698
8799 return 0 ;
88100}
89101
102+ /* This should *really* only be used when there's no other way... */
103+ static struct gpio_desc *
104+ skl_int3472_gpiod_get_from_temp_lookup (struct int3472_discrete_device * int3472 ,
105+ struct acpi_resource_gpio * agpio ,
106+ const char * func , u32 polarity )
107+ {
108+ struct gpio_desc * desc ;
109+ int ret ;
110+
111+ struct gpiod_lookup_table * lookup __free (kfree ) =
112+ kzalloc (struct_size (lookup , table , 2 ), GFP_KERNEL );
113+ if (!lookup )
114+ return ERR_PTR (- ENOMEM );
115+
116+ lookup -> dev_id = dev_name (int3472 -> dev );
117+ ret = skl_int3472_fill_gpiod_lookup (& lookup -> table [0 ], agpio , func , polarity );
118+ if (ret )
119+ return ERR_PTR (ret );
120+
121+ gpiod_add_lookup_table (lookup );
122+ desc = devm_gpiod_get (int3472 -> dev , func , GPIOD_OUT_LOW );
123+ gpiod_remove_lookup_table (lookup );
124+
125+ return desc ;
126+ }
127+
90128static void int3472_get_func_and_polarity (u8 type , const char * * func , u32 * polarity )
91129{
92130 switch (type ) {
@@ -156,6 +194,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
156194 struct acpi_resource_gpio * agpio ;
157195 u8 active_value , pin , type ;
158196 union acpi_object * obj ;
197+ struct gpio_desc * gpio ;
159198 const char * err_msg ;
160199 const char * func ;
161200 u32 polarity ;
@@ -206,22 +245,38 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
206245
207246 break ;
208247 case INT3472_GPIO_TYPE_CLK_ENABLE :
209- ret = skl_int3472_register_gpio_clock (int3472 , agpio , polarity );
210- if (ret )
211- err_msg = "Failed to register clock\n" ;
212-
213- break ;
214248 case INT3472_GPIO_TYPE_PRIVACY_LED :
215- ret = skl_int3472_register_pled (int3472 , agpio , polarity );
216- if (ret )
217- err_msg = "Failed to register LED\n" ;
218-
219- break ;
220249 case INT3472_GPIO_TYPE_POWER_ENABLE :
221- ret = skl_int3472_register_regulator (int3472 , agpio );
222- if (ret )
223- err_msg = "Failed to map regulator to sensor\n" ;
224-
250+ gpio = skl_int3472_gpiod_get_from_temp_lookup (int3472 , agpio , func , polarity );
251+ if (IS_ERR (gpio )) {
252+ ret = PTR_ERR (gpio );
253+ err_msg = "Failed to get GPIO\n" ;
254+ break ;
255+ }
256+
257+ switch (type ) {
258+ case INT3472_GPIO_TYPE_CLK_ENABLE :
259+ ret = skl_int3472_register_gpio_clock (int3472 , gpio );
260+ if (ret )
261+ err_msg = "Failed to register clock\n" ;
262+
263+ break ;
264+ case INT3472_GPIO_TYPE_PRIVACY_LED :
265+ ret = skl_int3472_register_pled (int3472 , gpio );
266+ if (ret )
267+ err_msg = "Failed to register LED\n" ;
268+
269+ break ;
270+ case INT3472_GPIO_TYPE_POWER_ENABLE :
271+ ret = skl_int3472_register_regulator (int3472 , gpio );
272+ if (ret )
273+ err_msg = "Failed to map regulator to sensor\n" ;
274+
275+ break ;
276+ default : /* Never reached */
277+ ret = - EINVAL ;
278+ break ;
279+ }
225280 break ;
226281 default :
227282 dev_warn (int3472 -> dev ,
0 commit comments