Lines Matching refs:hwmon

86 	struct mlx5_hwmon *hwmon = dev_get_drvdata(dev);  in mlx5_hwmon_read()  local
93 err = mlx5_hwmon_query_mtmp(hwmon->mdev, hwmon->temp_channel_desc[channel].sensor_index, in mlx5_hwmon_read()
116 struct mlx5_hwmon *hwmon = dev_get_drvdata(dev); in mlx5_hwmon_write() local
121 return mlx5_hwmon_reset_max_temp(hwmon->mdev, in mlx5_hwmon_write()
122 hwmon->temp_channel_desc[channel].sensor_index); in mlx5_hwmon_write()
147 struct mlx5_hwmon *hwmon = dev_get_drvdata(dev); in mlx5_hwmon_read_string() local
152 *str = (const char *)hwmon->temp_channel_desc[channel].sensor_name; in mlx5_hwmon_read_string()
163 static int mlx5_hwmon_init_channels_names(struct mlx5_hwmon *hwmon) in mlx5_hwmon_init_channels_names() argument
167 for (i = 0; i < hwmon->asic_platform_scount + hwmon->module_scount; i++) { in mlx5_hwmon_init_channels_names()
172 err = mlx5_hwmon_query_mtmp(hwmon->mdev, hwmon->temp_channel_desc[i].sensor_index, in mlx5_hwmon_init_channels_names()
179 snprintf(hwmon->temp_channel_desc[i].sensor_name, in mlx5_hwmon_init_channels_names()
180 sizeof(hwmon->temp_channel_desc[i].sensor_name), "sensor%u", in mlx5_hwmon_init_channels_names()
181 hwmon->temp_channel_desc[i].sensor_index); in mlx5_hwmon_init_channels_names()
185 memcpy(&hwmon->temp_channel_desc[i].sensor_name, sensor_name, in mlx5_hwmon_init_channels_names()
207 static int mlx5_hwmon_init_sensors_indexes(struct mlx5_hwmon *hwmon, u64 sensor_map) in mlx5_hwmon_init_sensors_indexes() argument
217 hwmon->temp_channel_desc[i].sensor_index = bit_pos; in mlx5_hwmon_init_sensors_indexes()
221 if (hwmon->module_scount) in mlx5_hwmon_init_sensors_indexes()
222 err = mlx5_hwmon_get_module_sensor_index(hwmon->mdev, in mlx5_hwmon_init_sensors_indexes()
223 &hwmon->temp_channel_desc[i].sensor_index); in mlx5_hwmon_init_sensors_indexes()
228 static void mlx5_hwmon_channel_info_init(struct mlx5_hwmon *hwmon) in mlx5_hwmon_channel_info_init() argument
232 hwmon->channel_info[0] = &hwmon->chip_info; in mlx5_hwmon_channel_info_init()
233 hwmon->channel_info[1] = &hwmon->temp_info; in mlx5_hwmon_channel_info_init()
235 hwmon->chip_channel_config[0] = HWMON_C_REGISTER_TZ; in mlx5_hwmon_channel_info_init()
236 hwmon->chip_info.config = (const u32 *)hwmon->chip_channel_config; in mlx5_hwmon_channel_info_init()
237 hwmon->chip_info.type = hwmon_chip; in mlx5_hwmon_channel_info_init()
239 for (i = 0; i < hwmon->asic_platform_scount + hwmon->module_scount; i++) in mlx5_hwmon_channel_info_init()
240 hwmon->temp_channel_config[i] = HWMON_T_INPUT | HWMON_T_HIGHEST | HWMON_T_CRIT | in mlx5_hwmon_channel_info_init()
243 hwmon->temp_info.config = (const u32 *)hwmon->temp_channel_config; in mlx5_hwmon_channel_info_init()
244 hwmon->temp_info.type = hwmon_temp; in mlx5_hwmon_channel_info_init()
284 static void mlx5_hwmon_free(struct mlx5_hwmon *hwmon) in mlx5_hwmon_free() argument
286 if (!hwmon) in mlx5_hwmon_free()
289 kfree(hwmon->temp_channel_config); in mlx5_hwmon_free()
290 kfree(hwmon->temp_channel_desc); in mlx5_hwmon_free()
291 kfree(hwmon); in mlx5_hwmon_free()
296 struct mlx5_hwmon *hwmon; in mlx5_hwmon_alloc() local
301 hwmon = kzalloc(sizeof(*mdev->hwmon), GFP_KERNEL); in mlx5_hwmon_alloc()
302 if (!hwmon) in mlx5_hwmon_alloc()
305 err = mlx5_hwmon_get_sensors_count(mdev, &hwmon->asic_platform_scount); in mlx5_hwmon_alloc()
314 hwmon->module_scount = mon_cap ? 1 : 0; in mlx5_hwmon_alloc()
315 sensors_count = hwmon->asic_platform_scount + hwmon->module_scount; in mlx5_hwmon_alloc()
316 hwmon->temp_channel_desc = kcalloc(sensors_count, sizeof(*hwmon->temp_channel_desc), in mlx5_hwmon_alloc()
318 if (!hwmon->temp_channel_desc) { in mlx5_hwmon_alloc()
324 hwmon->temp_channel_config = kcalloc(sensors_count + 1, sizeof(*hwmon->temp_channel_config), in mlx5_hwmon_alloc()
326 if (!hwmon->temp_channel_config) { in mlx5_hwmon_alloc()
331 hwmon->mdev = mdev; in mlx5_hwmon_alloc()
333 return hwmon; in mlx5_hwmon_alloc()
336 kfree(hwmon->temp_channel_desc); in mlx5_hwmon_alloc()
338 kfree(hwmon); in mlx5_hwmon_alloc()
342 static int mlx5_hwmon_dev_init(struct mlx5_hwmon *hwmon) in mlx5_hwmon_dev_init() argument
349 err = mlx5_core_access_reg(hwmon->mdev, mtcap_in, sizeof(mtcap_in), in mlx5_hwmon_dev_init()
355 mlx5_hwmon_channel_info_init(hwmon); in mlx5_hwmon_dev_init()
356 mlx5_hwmon_init_sensors_indexes(hwmon, MLX5_GET64(mtcap_reg, mtcap_out, sensor_map)); in mlx5_hwmon_dev_init()
357 err = mlx5_hwmon_init_channels_names(hwmon); in mlx5_hwmon_dev_init()
361 for (i = 0; i < hwmon->asic_platform_scount + hwmon->module_scount; i++) { in mlx5_hwmon_dev_init()
362 err = mlx5_hwmon_enable_max_temp(hwmon->mdev, in mlx5_hwmon_dev_init()
363 hwmon->temp_channel_desc[i].sensor_index); in mlx5_hwmon_dev_init()
368 hwmon->chip.ops = &mlx5_hwmon_ops; in mlx5_hwmon_dev_init()
369 hwmon->chip.info = (const struct hwmon_channel_info **)hwmon->channel_info; in mlx5_hwmon_dev_init()
377 struct mlx5_hwmon *hwmon; in mlx5_hwmon_dev_register() local
383 hwmon = mlx5_hwmon_alloc(mdev); in mlx5_hwmon_dev_register()
384 if (IS_ERR(hwmon)) in mlx5_hwmon_dev_register()
385 return PTR_ERR(hwmon); in mlx5_hwmon_dev_register()
387 err = mlx5_hwmon_dev_init(hwmon); in mlx5_hwmon_dev_register()
391 hwmon->hwmon_dev = hwmon_device_register_with_info(dev, "mlx5", in mlx5_hwmon_dev_register()
392 hwmon, in mlx5_hwmon_dev_register()
393 &hwmon->chip, in mlx5_hwmon_dev_register()
395 if (IS_ERR(hwmon->hwmon_dev)) { in mlx5_hwmon_dev_register()
396 err = PTR_ERR(hwmon->hwmon_dev); in mlx5_hwmon_dev_register()
400 mdev->hwmon = hwmon; in mlx5_hwmon_dev_register()
404 mlx5_hwmon_free(hwmon); in mlx5_hwmon_dev_register()
410 struct mlx5_hwmon *hwmon = mdev->hwmon; in mlx5_hwmon_dev_unregister() local
412 if (!hwmon) in mlx5_hwmon_dev_unregister()
415 hwmon_device_unregister(hwmon->hwmon_dev); in mlx5_hwmon_dev_unregister()
416 mlx5_hwmon_free(hwmon); in mlx5_hwmon_dev_unregister()
417 mdev->hwmon = NULL; in mlx5_hwmon_dev_unregister()