Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

platform/x86: toshiba_haps: Convert ACPI driver to a platform one

In all cases in which a struct acpi_driver is used for binding a driver
to an ACPI device object, a corresponding platform device is created by
the ACPI core and that device is regarded as a proper representation of
underlying hardware. Accordingly, a struct platform_driver should be
used by driver code to bind to that device. There are multiple reasons
why drivers should not bind directly to ACPI device objects [1].

Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the Toshiba HDD Active Protection Sensor
driver from an ACPI driver to a platform one.

While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.

Note that the sysfs attributes in haps_attr_group will still be there
in the sysfs directory of the ACPI companion of the platform device
used for driver binding in case there are tools in user space expecting
them to be present there.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/2045343.PYKUYFuaPT@rafael.j.wysocki
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Rafael J. Wysocki and committed by
Ilpo Järvinen
3a96c791 32156fd2

+21 -19
+21 -19
drivers/platform/x86/toshiba_haps.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/types.h> 14 14 #include <linux/acpi.h> 15 + #include <linux/platform_device.h> 15 16 16 17 MODULE_AUTHOR("Azael Avalos <coproscefalo@gmail.com>"); 17 18 MODULE_DESCRIPTION("Toshiba HDD Active Protection Sensor"); ··· 141 140 event, 0); 142 141 } 143 142 144 - static void toshiba_haps_remove(struct acpi_device *device) 143 + static void toshiba_haps_remove(struct platform_device *pdev) 145 144 { 145 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 146 + 146 147 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, 147 148 toshiba_haps_notify); 148 149 ··· 152 149 153 150 if (toshiba_haps) 154 151 toshiba_haps = NULL; 152 + 153 + dev_set_drvdata(&device->dev, NULL); 155 154 } 156 155 157 156 /* Helper function */ ··· 180 175 return 1; 181 176 } 182 177 183 - static int toshiba_haps_add(struct acpi_device *acpi_dev) 178 + static int toshiba_haps_probe(struct platform_device *pdev) 184 179 { 180 + struct acpi_device *acpi_dev = ACPI_COMPANION(&pdev->dev); 185 181 struct toshiba_haps_dev *haps; 186 182 int ret; 187 183 ··· 194 188 195 189 pr_info("Toshiba HDD Active Protection Sensor device\n"); 196 190 197 - haps = devm_kzalloc(&acpi_dev->dev, sizeof(*haps), GFP_KERNEL); 191 + haps = devm_kzalloc(&pdev->dev, sizeof(*haps), GFP_KERNEL); 198 192 if (!haps) 199 193 return -ENOMEM; 200 194 201 195 haps->acpi_dev = acpi_dev; 202 196 haps->protection_level = 2; 203 - acpi_dev->driver_data = haps; 197 + 204 198 dev_set_drvdata(&acpi_dev->dev, haps); 199 + platform_set_drvdata(pdev, haps); 205 200 206 201 /* Set the protection level, currently at level 2 (Medium) */ 207 202 ret = toshiba_haps_protection_level(acpi_dev->handle, 2); ··· 230 223 #ifdef CONFIG_PM_SLEEP 231 224 static int toshiba_haps_suspend(struct device *device) 232 225 { 233 - struct toshiba_haps_dev *haps; 226 + struct toshiba_haps_dev *haps = dev_get_drvdata(device); 234 227 int ret; 235 - 236 - haps = acpi_driver_data(to_acpi_device(device)); 237 228 238 229 /* Deactivate the protection on suspend */ 239 230 ret = toshiba_haps_protection_level(haps->acpi_dev->handle, 0); ··· 241 236 242 237 static int toshiba_haps_resume(struct device *device) 243 238 { 244 - struct toshiba_haps_dev *haps; 239 + struct toshiba_haps_dev *haps = dev_get_drvdata(device); 245 240 int ret; 246 - 247 - haps = acpi_driver_data(to_acpi_device(device)); 248 241 249 242 /* Set the stored protection level */ 250 243 ret = toshiba_haps_protection_level(haps->acpi_dev->handle, ··· 266 263 }; 267 264 MODULE_DEVICE_TABLE(acpi, haps_device_ids); 268 265 269 - static struct acpi_driver toshiba_haps_driver = { 270 - .name = "Toshiba HAPS", 271 - .ids = haps_device_ids, 272 - .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 273 - .ops = { 274 - .add = toshiba_haps_add, 275 - .remove = toshiba_haps_remove, 266 + static struct platform_driver toshiba_haps_driver = { 267 + .probe = toshiba_haps_probe, 268 + .remove = toshiba_haps_remove, 269 + .driver = { 270 + .name = "Toshiba HAPS", 271 + .acpi_match_table = haps_device_ids, 272 + .pm = &toshiba_haps_pm, 276 273 }, 277 - .drv.pm = &toshiba_haps_pm, 278 274 }; 279 275 280 - module_acpi_driver(toshiba_haps_driver); 276 + module_platform_driver(toshiba_haps_driver);