Loading drivers/platform/x86/intel/int3472/clk_and_regulator.c +8 −46 Original line number Diff line number Diff line Loading @@ -162,9 +162,8 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472) } int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity) struct gpio_desc *gpio) { char *path = agpio->resource_source.string_ptr; struct clk_init_data init = { .ops = &skl_int3472_clock_ops, .flags = CLK_GET_RATE_NOCACHE, Loading @@ -174,26 +173,12 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, if (int3472->clock.cl) return -EBUSY; int3472->clock.ena_gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0], "int3472,clk-enable"); if (IS_ERR(int3472->clock.ena_gpio)) { ret = PTR_ERR(int3472->clock.ena_gpio); int3472->clock.ena_gpio = NULL; return dev_err_probe(int3472->dev, ret, "getting clk-enable GPIO\n"); } if (polarity == GPIO_ACTIVE_LOW) gpiod_toggle_active_low(int3472->clock.ena_gpio); /* Ensure the pin is in output mode and non-active state */ gpiod_direction_output(int3472->clock.ena_gpio, 0); int3472->clock.ena_gpio = gpio; init.name = kasprintf(GFP_KERNEL, "%s-clk", acpi_dev_name(int3472->adev)); if (!init.name) { ret = -ENOMEM; goto out_put_gpio; } if (!init.name) return -ENOMEM; int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472); Loading @@ -219,8 +204,6 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, clk_unregister(int3472->clock.clk); out_free_init_name: kfree(init.name); out_put_gpio: gpiod_put(int3472->clock.ena_gpio); return ret; } Loading @@ -232,7 +215,6 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472) clkdev_drop(int3472->clock.cl); clk_unregister(int3472->clock.clk); gpiod_put(int3472->clock.ena_gpio); } /* Loading Loading @@ -273,14 +255,13 @@ static const struct dmi_system_id skl_int3472_regulator_second_sensor[] = { }; int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio) struct gpio_desc *gpio) { char *path = agpio->resource_source.string_ptr; struct regulator_init_data init_data = { }; struct regulator_config cfg = { }; const char *second_sensor = NULL; const struct dmi_system_id *id; int i, j, ret; int i, j; id = dmi_first_match(skl_int3472_regulator_second_sensor); if (id) Loading Loading @@ -314,16 +295,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, int3472->regulator.supply_name, &int3472_gpio_regulator_ops); int3472->regulator.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0], "int3472,regulator"); if (IS_ERR(int3472->regulator.gpio)) { ret = PTR_ERR(int3472->regulator.gpio); int3472->regulator.gpio = NULL; return dev_err_probe(int3472->dev, ret, "getting regulator GPIO\n"); } /* Ensure the pin is in output mode and non-active state */ gpiod_direction_output(int3472->regulator.gpio, 0); int3472->regulator.gpio = gpio; cfg.dev = &int3472->adev->dev; cfg.init_data = &init_data; Loading @@ -332,21 +304,11 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, int3472->regulator.rdev = regulator_register(int3472->dev, &int3472->regulator.rdesc, &cfg); if (IS_ERR(int3472->regulator.rdev)) { ret = PTR_ERR(int3472->regulator.rdev); goto err_free_gpio; } return 0; err_free_gpio: gpiod_put(int3472->regulator.gpio); return ret; return PTR_ERR_OR_ZERO(int3472->regulator.rdev); } void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472) { regulator_unregister(int3472->regulator.rdev); gpiod_put(int3472->regulator.gpio); } drivers/platform/x86/intel/int3472/common.h +3 −4 Original line number Diff line number Diff line Loading @@ -117,16 +117,15 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev, const char **name_ret); int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity); struct gpio_desc *gpio); int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472); void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472); int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio); struct gpio_desc *gpio); void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472); int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity); int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio); void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472); #endif drivers/platform/x86/intel/int3472/discrete.c +79 −24 Original line number Diff line number Diff line Loading @@ -52,21 +52,15 @@ static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *i } } static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472, static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry, struct acpi_resource_gpio *agpio, const char *func, u32 polarity) { char *path = agpio->resource_source.string_ptr; struct gpiod_lookup *table_entry; struct acpi_device *adev; acpi_handle handle; acpi_status status; if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) { dev_warn(int3472->dev, "Too many GPIOs mapped\n"); return -EINVAL; } status = acpi_get_handle(NULL, path, &handle); if (ACPI_FAILURE(status)) return -EINVAL; Loading @@ -75,18 +69,62 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347 if (!adev) return -ENODEV; table_entry = &int3472->gpios.table[int3472->n_sensor_gpios]; table_entry->key = acpi_dev_name(adev); table_entry->chip_hwnum = agpio->pin_table[0]; table_entry->con_id = func; table_entry->idx = 0; table_entry->flags = polarity; return 0; } static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, const char *func, u32 polarity) { int ret; if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) { dev_warn(int3472->dev, "Too many GPIOs mapped\n"); return -EINVAL; } ret = skl_int3472_fill_gpiod_lookup(&int3472->gpios.table[int3472->n_sensor_gpios], agpio, func, polarity); if (ret) return ret; int3472->n_sensor_gpios++; return 0; } /* This should *really* only be used when there's no other way... */ static struct gpio_desc * skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, const char *func, u32 polarity) { struct gpio_desc *desc; int ret; struct gpiod_lookup_table *lookup __free(kfree) = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL); if (!lookup) return ERR_PTR(-ENOMEM); lookup->dev_id = dev_name(int3472->dev); ret = skl_int3472_fill_gpiod_lookup(&lookup->table[0], agpio, func, polarity); if (ret) return ERR_PTR(ret); gpiod_add_lookup_table(lookup); desc = devm_gpiod_get(int3472->dev, func, GPIOD_OUT_LOW); gpiod_remove_lookup_table(lookup); return desc; } static void int3472_get_func_and_polarity(u8 type, const char **func, u32 *polarity) { switch (type) { Loading Loading @@ -156,6 +194,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, struct acpi_resource_gpio *agpio; u8 active_value, pin, type; union acpi_object *obj; struct gpio_desc *gpio; const char *err_msg; const char *func; u32 polarity; Loading Loading @@ -206,22 +245,38 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, break; case INT3472_GPIO_TYPE_CLK_ENABLE: ret = skl_int3472_register_gpio_clock(int3472, agpio, polarity); case INT3472_GPIO_TYPE_PRIVACY_LED: case INT3472_GPIO_TYPE_POWER_ENABLE: gpio = skl_int3472_gpiod_get_from_temp_lookup(int3472, agpio, func, polarity); if (IS_ERR(gpio)) { ret = PTR_ERR(gpio); err_msg = "Failed to get GPIO\n"; break; } switch (type) { case INT3472_GPIO_TYPE_CLK_ENABLE: ret = skl_int3472_register_gpio_clock(int3472, gpio); if (ret) err_msg = "Failed to register clock\n"; break; case INT3472_GPIO_TYPE_PRIVACY_LED: ret = skl_int3472_register_pled(int3472, agpio, polarity); ret = skl_int3472_register_pled(int3472, gpio); if (ret) err_msg = "Failed to register LED\n"; break; case INT3472_GPIO_TYPE_POWER_ENABLE: ret = skl_int3472_register_regulator(int3472, agpio); ret = skl_int3472_register_regulator(int3472, gpio); if (ret) err_msg = "Failed to map regulator to sensor\n"; break; default: /* Never reached */ ret = -EINVAL; break; } break; default: dev_warn(int3472->dev, Loading drivers/platform/x86/intel/int3472/led.c +4 −20 Original line number Diff line number Diff line Loading @@ -16,26 +16,15 @@ static int int3472_pled_set(struct led_classdev *led_cdev, return 0; } int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity) int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio) { char *p, *path = agpio->resource_source.string_ptr; char *p; int ret; if (int3472->pled.classdev.dev) return -EBUSY; int3472->pled.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0], "int3472,privacy-led"); if (IS_ERR(int3472->pled.gpio)) return dev_err_probe(int3472->dev, PTR_ERR(int3472->pled.gpio), "getting privacy LED GPIO\n"); if (polarity == GPIO_ACTIVE_LOW) gpiod_toggle_active_low(int3472->pled.gpio); /* Ensure the pin is in output mode and non-active state */ gpiod_direction_output(int3472->pled.gpio, 0); int3472->pled.gpio = gpio; /* Generate the name, replacing the ':' in the ACPI devname with '_' */ snprintf(int3472->pled.name, sizeof(int3472->pled.name), Loading @@ -50,7 +39,7 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, ret = led_classdev_register(int3472->dev, &int3472->pled.classdev); if (ret) goto err_free_gpio; return ret; int3472->pled.lookup.provider = int3472->pled.name; int3472->pled.lookup.dev_id = int3472->sensor_name; Loading @@ -58,10 +47,6 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, led_add_lookup(&int3472->pled.lookup); return 0; err_free_gpio: gpiod_put(int3472->pled.gpio); return ret; } void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472) Loading @@ -71,5 +56,4 @@ void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472) led_remove_lookup(&int3472->pled.lookup); led_classdev_unregister(&int3472->pled.classdev); gpiod_put(int3472->pled.gpio); } Loading
drivers/platform/x86/intel/int3472/clk_and_regulator.c +8 −46 Original line number Diff line number Diff line Loading @@ -162,9 +162,8 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472) } int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity) struct gpio_desc *gpio) { char *path = agpio->resource_source.string_ptr; struct clk_init_data init = { .ops = &skl_int3472_clock_ops, .flags = CLK_GET_RATE_NOCACHE, Loading @@ -174,26 +173,12 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, if (int3472->clock.cl) return -EBUSY; int3472->clock.ena_gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0], "int3472,clk-enable"); if (IS_ERR(int3472->clock.ena_gpio)) { ret = PTR_ERR(int3472->clock.ena_gpio); int3472->clock.ena_gpio = NULL; return dev_err_probe(int3472->dev, ret, "getting clk-enable GPIO\n"); } if (polarity == GPIO_ACTIVE_LOW) gpiod_toggle_active_low(int3472->clock.ena_gpio); /* Ensure the pin is in output mode and non-active state */ gpiod_direction_output(int3472->clock.ena_gpio, 0); int3472->clock.ena_gpio = gpio; init.name = kasprintf(GFP_KERNEL, "%s-clk", acpi_dev_name(int3472->adev)); if (!init.name) { ret = -ENOMEM; goto out_put_gpio; } if (!init.name) return -ENOMEM; int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472); Loading @@ -219,8 +204,6 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, clk_unregister(int3472->clock.clk); out_free_init_name: kfree(init.name); out_put_gpio: gpiod_put(int3472->clock.ena_gpio); return ret; } Loading @@ -232,7 +215,6 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472) clkdev_drop(int3472->clock.cl); clk_unregister(int3472->clock.clk); gpiod_put(int3472->clock.ena_gpio); } /* Loading Loading @@ -273,14 +255,13 @@ static const struct dmi_system_id skl_int3472_regulator_second_sensor[] = { }; int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio) struct gpio_desc *gpio) { char *path = agpio->resource_source.string_ptr; struct regulator_init_data init_data = { }; struct regulator_config cfg = { }; const char *second_sensor = NULL; const struct dmi_system_id *id; int i, j, ret; int i, j; id = dmi_first_match(skl_int3472_regulator_second_sensor); if (id) Loading Loading @@ -314,16 +295,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, int3472->regulator.supply_name, &int3472_gpio_regulator_ops); int3472->regulator.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0], "int3472,regulator"); if (IS_ERR(int3472->regulator.gpio)) { ret = PTR_ERR(int3472->regulator.gpio); int3472->regulator.gpio = NULL; return dev_err_probe(int3472->dev, ret, "getting regulator GPIO\n"); } /* Ensure the pin is in output mode and non-active state */ gpiod_direction_output(int3472->regulator.gpio, 0); int3472->regulator.gpio = gpio; cfg.dev = &int3472->adev->dev; cfg.init_data = &init_data; Loading @@ -332,21 +304,11 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, int3472->regulator.rdev = regulator_register(int3472->dev, &int3472->regulator.rdesc, &cfg); if (IS_ERR(int3472->regulator.rdev)) { ret = PTR_ERR(int3472->regulator.rdev); goto err_free_gpio; } return 0; err_free_gpio: gpiod_put(int3472->regulator.gpio); return ret; return PTR_ERR_OR_ZERO(int3472->regulator.rdev); } void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472) { regulator_unregister(int3472->regulator.rdev); gpiod_put(int3472->regulator.gpio); }
drivers/platform/x86/intel/int3472/common.h +3 −4 Original line number Diff line number Diff line Loading @@ -117,16 +117,15 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev, const char **name_ret); int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity); struct gpio_desc *gpio); int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472); void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472); int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio); struct gpio_desc *gpio); void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472); int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity); int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio); void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472); #endif
drivers/platform/x86/intel/int3472/discrete.c +79 −24 Original line number Diff line number Diff line Loading @@ -52,21 +52,15 @@ static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *i } } static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472, static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry, struct acpi_resource_gpio *agpio, const char *func, u32 polarity) { char *path = agpio->resource_source.string_ptr; struct gpiod_lookup *table_entry; struct acpi_device *adev; acpi_handle handle; acpi_status status; if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) { dev_warn(int3472->dev, "Too many GPIOs mapped\n"); return -EINVAL; } status = acpi_get_handle(NULL, path, &handle); if (ACPI_FAILURE(status)) return -EINVAL; Loading @@ -75,18 +69,62 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347 if (!adev) return -ENODEV; table_entry = &int3472->gpios.table[int3472->n_sensor_gpios]; table_entry->key = acpi_dev_name(adev); table_entry->chip_hwnum = agpio->pin_table[0]; table_entry->con_id = func; table_entry->idx = 0; table_entry->flags = polarity; return 0; } static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, const char *func, u32 polarity) { int ret; if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) { dev_warn(int3472->dev, "Too many GPIOs mapped\n"); return -EINVAL; } ret = skl_int3472_fill_gpiod_lookup(&int3472->gpios.table[int3472->n_sensor_gpios], agpio, func, polarity); if (ret) return ret; int3472->n_sensor_gpios++; return 0; } /* This should *really* only be used when there's no other way... */ static struct gpio_desc * skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, const char *func, u32 polarity) { struct gpio_desc *desc; int ret; struct gpiod_lookup_table *lookup __free(kfree) = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL); if (!lookup) return ERR_PTR(-ENOMEM); lookup->dev_id = dev_name(int3472->dev); ret = skl_int3472_fill_gpiod_lookup(&lookup->table[0], agpio, func, polarity); if (ret) return ERR_PTR(ret); gpiod_add_lookup_table(lookup); desc = devm_gpiod_get(int3472->dev, func, GPIOD_OUT_LOW); gpiod_remove_lookup_table(lookup); return desc; } static void int3472_get_func_and_polarity(u8 type, const char **func, u32 *polarity) { switch (type) { Loading Loading @@ -156,6 +194,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, struct acpi_resource_gpio *agpio; u8 active_value, pin, type; union acpi_object *obj; struct gpio_desc *gpio; const char *err_msg; const char *func; u32 polarity; Loading Loading @@ -206,22 +245,38 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, break; case INT3472_GPIO_TYPE_CLK_ENABLE: ret = skl_int3472_register_gpio_clock(int3472, agpio, polarity); case INT3472_GPIO_TYPE_PRIVACY_LED: case INT3472_GPIO_TYPE_POWER_ENABLE: gpio = skl_int3472_gpiod_get_from_temp_lookup(int3472, agpio, func, polarity); if (IS_ERR(gpio)) { ret = PTR_ERR(gpio); err_msg = "Failed to get GPIO\n"; break; } switch (type) { case INT3472_GPIO_TYPE_CLK_ENABLE: ret = skl_int3472_register_gpio_clock(int3472, gpio); if (ret) err_msg = "Failed to register clock\n"; break; case INT3472_GPIO_TYPE_PRIVACY_LED: ret = skl_int3472_register_pled(int3472, agpio, polarity); ret = skl_int3472_register_pled(int3472, gpio); if (ret) err_msg = "Failed to register LED\n"; break; case INT3472_GPIO_TYPE_POWER_ENABLE: ret = skl_int3472_register_regulator(int3472, agpio); ret = skl_int3472_register_regulator(int3472, gpio); if (ret) err_msg = "Failed to map regulator to sensor\n"; break; default: /* Never reached */ ret = -EINVAL; break; } break; default: dev_warn(int3472->dev, Loading
drivers/platform/x86/intel/int3472/led.c +4 −20 Original line number Diff line number Diff line Loading @@ -16,26 +16,15 @@ static int int3472_pled_set(struct led_classdev *led_cdev, return 0; } int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct acpi_resource_gpio *agpio, u32 polarity) int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio) { char *p, *path = agpio->resource_source.string_ptr; char *p; int ret; if (int3472->pled.classdev.dev) return -EBUSY; int3472->pled.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0], "int3472,privacy-led"); if (IS_ERR(int3472->pled.gpio)) return dev_err_probe(int3472->dev, PTR_ERR(int3472->pled.gpio), "getting privacy LED GPIO\n"); if (polarity == GPIO_ACTIVE_LOW) gpiod_toggle_active_low(int3472->pled.gpio); /* Ensure the pin is in output mode and non-active state */ gpiod_direction_output(int3472->pled.gpio, 0); int3472->pled.gpio = gpio; /* Generate the name, replacing the ':' in the ACPI devname with '_' */ snprintf(int3472->pled.name, sizeof(int3472->pled.name), Loading @@ -50,7 +39,7 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, ret = led_classdev_register(int3472->dev, &int3472->pled.classdev); if (ret) goto err_free_gpio; return ret; int3472->pled.lookup.provider = int3472->pled.name; int3472->pled.lookup.dev_id = int3472->sensor_name; Loading @@ -58,10 +47,6 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472, led_add_lookup(&int3472->pled.lookup); return 0; err_free_gpio: gpiod_put(int3472->pled.gpio); return ret; } void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472) Loading @@ -71,5 +56,4 @@ void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472) led_remove_lookup(&int3472->pled.lookup); led_classdev_unregister(&int3472->pled.classdev); gpiod_put(int3472->pled.gpio); }