Lines Matching +full:sg2042 +full:- +full:hwmon +full:- +full:mcu
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Sophgo power control mcu for SG2042
11 #include <linux/hwmon.h>
17 /* fixed MCU registers */
41 struct sg2042_mcu_data *mcu = seqf->private; \
43 ret = i2c_smbus_read_byte_data(mcu->client, (_reg)); \
63 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in reset_count_show() local
66 ret = i2c_smbus_read_byte_data(mcu->client, REG_RST_COUNT); in reset_count_show()
77 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in uptime_show() local
81 ret = i2c_smbus_read_i2c_block_data(mcu->client, REG_UPTIME, in uptime_show()
94 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in reset_reason_show() local
97 ret = i2c_smbus_read_byte_data(mcu->client, REG_RESET_REASON); in reset_reason_show()
108 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in repower_policy_show() local
112 ret = i2c_smbus_read_byte_data(mcu->client, REG_REPOWER_POLICY); in repower_policy_show()
130 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in repower_policy_store() local
139 return -EINVAL; in repower_policy_store()
141 ret = i2c_smbus_write_byte_data(mcu->client, in repower_policy_store()
188 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in sg2042_mcu_read() local
203 return -EOPNOTSUPP; in sg2042_mcu_read()
206 tmp = i2c_smbus_read_byte_data(mcu->client, reg); in sg2042_mcu_read()
218 struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); in sg2042_mcu_write() local
225 guard(mutex)(&mcu->mutex); in sg2042_mcu_write()
229 hyst_temp = i2c_smbus_read_byte_data(mcu->client, in sg2042_mcu_write()
238 crit_temp = i2c_smbus_read_byte_data(mcu->client, in sg2042_mcu_write()
247 return -EOPNOTSUPP; in sg2042_mcu_write()
251 * ensure hyst_temp is smaller to avoid MCU from in sg2042_mcu_write()
255 return -EINVAL; in sg2042_mcu_write()
257 return i2c_smbus_write_byte_data(mcu->client, reg, temp); in sg2042_mcu_write()
295 static void sg2042_mcu_debugfs_init(struct sg2042_mcu_data *mcu, in sg2042_mcu_debugfs_init() argument
298 mcu->debugfs = debugfs_create_dir(dev_name(dev), sgmcu_debugfs); in sg2042_mcu_debugfs_init()
300 debugfs_create_file("firmware_version", 0444, mcu->debugfs, in sg2042_mcu_debugfs_init()
301 mcu, &firmware_version_fops); in sg2042_mcu_debugfs_init()
302 debugfs_create_file("pcb_version", 0444, mcu->debugfs, mcu, in sg2042_mcu_debugfs_init()
304 debugfs_create_file("mcu_type", 0444, mcu->debugfs, mcu, in sg2042_mcu_debugfs_init()
306 debugfs_create_file("board_type", 0444, mcu->debugfs, mcu, in sg2042_mcu_debugfs_init()
312 struct device *dev = &client->dev; in sg2042_mcu_i2c_probe()
313 struct sg2042_mcu_data *mcu; in sg2042_mcu_i2c_probe() local
316 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | in sg2042_mcu_i2c_probe()
318 return -ENODEV; in sg2042_mcu_i2c_probe()
320 mcu = devm_kmalloc(dev, sizeof(*mcu), GFP_KERNEL); in sg2042_mcu_i2c_probe()
321 if (!mcu) in sg2042_mcu_i2c_probe()
322 return -ENOMEM; in sg2042_mcu_i2c_probe()
324 mutex_init(&mcu->mutex); in sg2042_mcu_i2c_probe()
325 mcu->client = client; in sg2042_mcu_i2c_probe()
327 i2c_set_clientdata(client, mcu); in sg2042_mcu_i2c_probe()
330 mcu, in sg2042_mcu_i2c_probe()
336 sg2042_mcu_debugfs_init(mcu, dev); in sg2042_mcu_i2c_probe()
343 struct sg2042_mcu_data *mcu = i2c_get_clientdata(client); in sg2042_mcu_i2c_remove() local
345 debugfs_remove_recursive(mcu->debugfs); in sg2042_mcu_i2c_remove()
349 { "sg2042-hwmon-mcu", 0 },
355 { .compatible = "sophgo,sg2042-hwmon-mcu" },
362 .name = "sg2042-mcu",
373 sgmcu_debugfs = debugfs_create_dir("sg2042-mcu", NULL); in sg2042_mcu_init()
387 MODULE_DESCRIPTION("MCU I2C driver for SG2042 soc platform");