|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
| 2 | +/* |
| 3 | + * Platform driver for the Embedded Controller (EC) of Ayaneo devices. Handles |
| 4 | + * hwmon (fan speed, fan control), battery charge limits, and magic module |
| 5 | + * control (connected modules, controller disconnection). |
| 6 | + * |
| 7 | + * Copyright (C) 2025 Antheas Kapenekakis <lkml@antheas.dev> |
| 8 | + */ |
| 9 | + |
| 10 | +#include <linux/dmi.h> |
| 11 | +#include <linux/err.h> |
| 12 | +#include <linux/init.h> |
| 13 | +#include <linux/kernel.h> |
| 14 | +#include <linux/module.h> |
| 15 | +#include <linux/platform_device.h> |
| 16 | + |
| 17 | +struct ayaneo_ec_quirk { |
| 18 | +}; |
| 19 | + |
| 20 | +struct ayaneo_ec_platform_data { |
| 21 | + struct platform_device *pdev; |
| 22 | + struct ayaneo_ec_quirk *quirks; |
| 23 | +}; |
| 24 | + |
| 25 | +static const struct ayaneo_ec_quirk quirk_ayaneo3 = { |
| 26 | +}; |
| 27 | + |
| 28 | +static const struct dmi_system_id dmi_table[] = { |
| 29 | + { |
| 30 | + .matches = { |
| 31 | + DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"), |
| 32 | + DMI_EXACT_MATCH(DMI_BOARD_NAME, "AYANEO 3"), |
| 33 | + }, |
| 34 | + .driver_data = (void *)&quirk_ayaneo3, |
| 35 | + }, |
| 36 | + {}, |
| 37 | +}; |
| 38 | + |
| 39 | +static int ayaneo_ec_probe(struct platform_device *pdev) |
| 40 | +{ |
| 41 | + const struct dmi_system_id *dmi_entry; |
| 42 | + struct ayaneo_ec_platform_data *data; |
| 43 | + |
| 44 | + dmi_entry = dmi_first_match(dmi_table); |
| 45 | + if (!dmi_entry) |
| 46 | + return -ENODEV; |
| 47 | + |
| 48 | + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
| 49 | + if (!data) |
| 50 | + return -ENOMEM; |
| 51 | + |
| 52 | + data->pdev = pdev; |
| 53 | + data->quirks = dmi_entry->driver_data; |
| 54 | + platform_set_drvdata(pdev, data); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +static struct platform_driver ayaneo_platform_driver = { |
| 60 | + .driver = { |
| 61 | + .name = "ayaneo-ec", |
| 62 | + }, |
| 63 | + .probe = ayaneo_ec_probe, |
| 64 | +}; |
| 65 | + |
| 66 | +static struct platform_device *ayaneo_platform_device; |
| 67 | + |
| 68 | +static int __init ayaneo_ec_init(void) |
| 69 | +{ |
| 70 | + ayaneo_platform_device = |
| 71 | + platform_create_bundle(&ayaneo_platform_driver, |
| 72 | + ayaneo_ec_probe, NULL, 0, NULL, 0); |
| 73 | + |
| 74 | + return PTR_ERR_OR_ZERO(ayaneo_platform_device); |
| 75 | +} |
| 76 | + |
| 77 | +static void __exit ayaneo_ec_exit(void) |
| 78 | +{ |
| 79 | + platform_device_unregister(ayaneo_platform_device); |
| 80 | + platform_driver_unregister(&ayaneo_platform_driver); |
| 81 | +} |
| 82 | + |
| 83 | +MODULE_DEVICE_TABLE(dmi, dmi_table); |
| 84 | + |
| 85 | +module_init(ayaneo_ec_init); |
| 86 | +module_exit(ayaneo_ec_exit); |
| 87 | + |
| 88 | +MODULE_AUTHOR("Antheas Kapenekakis <lkml@antheas.dev>"); |
| 89 | +MODULE_DESCRIPTION("Ayaneo Embedded Controller (EC) platform features"); |
| 90 | +MODULE_LICENSE("GPL"); |
0 commit comments