我正在为通过 LPC(ISA 样式总线)通信的芯片编写内核 hwmon 驱动程序模块。到目前为止我有以下代码
umode_t qnap_ec_is_visible(const void* data, enum hwmon_sensor_types type, u32 attr, int channel)
{
}
int qnap_ec_read(struct device* dev, enum hwmon_sensor_types type, u32 attr, int channel, long* val)
{
}
int qnap_ec_write(struct device* dev, enum hwmon_sensor_types type, u32 attr, int channel, long val)
{
}
static const struct hwmon_ops qnap_ec_ops = {
.is_visible = qnap_ec_is_visible,
.read = qnap_ec_read,
.write = qnap_ec_write
};
static const struct hwmon_channel_info *qnap_ec_channel_info[] = {
HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT),
HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
NULL
};
static const struct hwmon_chip_info qnap_ec_chip_info = {
.ops = &qnap_ec_ops,
.info = qnap_ec_channel_info
};
static int qnap_ec_probe(struct platform_device* platform_dev)
{
struct device* dev;
dev = devm_hwmon_device_register_with_info(&platform_dev->dev, "qnap_ec_hwmon", NULL,
&qnap_ec_chip_info, NULL);
return PTR_ERR_OR_ZERO(dev);
}
static const struct of_device_id qnap_ec_of_match[] = {
{ .compatible = "???" },
{}
};
MODULE_DEVICE_TABLE(of, qnap_ec_of_match);
static struct platform_driver qnap_ec_driver = {
.driver = {
.name = "qnap_ec_hwmon",
.of_match_table = qnap_ec_of_match
},
.probe = qnap_ec_probe
};
module_platform_driver(qnap_ec_driver);
但是我很确定这种方法(使用设备 ID 并让内核在系统上找到该设备 ID 时调用探测函数)不适用于 LPC 总线上的某些东西。也通过 LPC 总线通信的 IT87 驱动程序使用 __init/__exit 函数进入驱动程序,但是,该驱动程序非常大,可能不是简单驱动程序模块的理想示例。是否有任何示例可以说明如何为 LPC 设备编写基本的(即:没有真正的功能只是骨架)内核 hwmon 驱动程序?有些事情我找不到答案,例如,如果我使用 __init/__exit 函数,我是否仍然可以使用 devm_hwmon_device_register_with_info 函数注册驱动程序,或者我是否需要使用另一种方法(例如 it87 驱动程序使用platform_driver_register 函数,但我'