Lines Matching +full:data +full:- +full:channel
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * cgbc-hwmon - Congatec Board Controller hardware monitoring driver
26 unsigned int channel; member
89 static int cgbc_hwmon_cmd(struct cgbc_device_data *cgbc, u8 index, u8 *data) in cgbc_hwmon_cmd() argument
93 return cgbc_command(cgbc, cmd, sizeof(cmd), data, CGBC_HWMON_CMD_SENSOR_DATA_SIZE, NULL); in cgbc_hwmon_cmd()
98 struct cgbc_device_data *cgbc = hwmon->cgbc; in cgbc_hwmon_probe_sensors()
99 struct cgbc_hwmon_sensor *sensor = hwmon->sensors; in cgbc_hwmon_probe_sensors()
100 u8 data[CGBC_HWMON_CMD_SENSOR_DATA_SIZE], nb_sensors, i; in cgbc_hwmon_probe_sensors() local
103 ret = cgbc_hwmon_cmd(cgbc, 0, &data[0]); in cgbc_hwmon_probe_sensors()
107 nb_sensors = data[0]; in cgbc_hwmon_probe_sensors()
109 hwmon->sensors = devm_kzalloc(dev, sizeof(*hwmon->sensors) * nb_sensors, GFP_KERNEL); in cgbc_hwmon_probe_sensors()
110 if (!hwmon->sensors) in cgbc_hwmon_probe_sensors()
111 return -ENOMEM; in cgbc_hwmon_probe_sensors()
113 sensor = hwmon->sensors; in cgbc_hwmon_probe_sensors()
117 unsigned int channel; in cgbc_hwmon_probe_sensors() local
120 * No need to request data for the first sensor. in cgbc_hwmon_probe_sensors()
121 * We got data for the first sensor when we ask the number of sensors to the Board in cgbc_hwmon_probe_sensors()
125 ret = cgbc_hwmon_cmd(cgbc, i, &data[0]); in cgbc_hwmon_probe_sensors()
130 type = FIELD_GET(CGBC_HWMON_TYPE_MASK, data[1]); in cgbc_hwmon_probe_sensors()
131 channel = FIELD_GET(CGBC_HWMON_ID_MASK, data[1]) - 1; in cgbc_hwmon_probe_sensors()
133 if (type == CGBC_HWMON_TYPE_TEMP && channel < ARRAY_SIZE(cgbc_hwmon_labels_temp)) { in cgbc_hwmon_probe_sensors()
134 sensor->type = hwmon_temp; in cgbc_hwmon_probe_sensors()
135 sensor->label = cgbc_hwmon_labels_temp[channel]; in cgbc_hwmon_probe_sensors()
137 channel < ARRAY_SIZE(cgbc_hwmon_labels_in)) { in cgbc_hwmon_probe_sensors()
140 * Get the sensor type from cgbc_hwmon_labels_in[channel].type instead. in cgbc_hwmon_probe_sensors()
142 sensor->type = cgbc_hwmon_labels_in[channel].type; in cgbc_hwmon_probe_sensors()
143 sensor->label = cgbc_hwmon_labels_in[channel].label; in cgbc_hwmon_probe_sensors()
145 channel < ARRAY_SIZE(cgbc_hwmon_labels_fan)) { in cgbc_hwmon_probe_sensors()
146 sensor->type = hwmon_fan; in cgbc_hwmon_probe_sensors()
147 sensor->label = cgbc_hwmon_labels_fan[channel]; in cgbc_hwmon_probe_sensors()
149 dev_warn(dev, "Board Controller returned an unknown sensor (type=%d, channel=%d), ignore it", in cgbc_hwmon_probe_sensors()
150 type, channel); in cgbc_hwmon_probe_sensors()
154 sensor->active = FIELD_GET(CGBC_HWMON_ACTIVE_BIT, data[1]); in cgbc_hwmon_probe_sensors()
155 sensor->channel = channel; in cgbc_hwmon_probe_sensors()
156 sensor->index = i; in cgbc_hwmon_probe_sensors()
158 hwmon->nb_sensors++; in cgbc_hwmon_probe_sensors()
165 enum hwmon_sensor_types type, int channel) in cgbc_hwmon_find_sensor() argument
172 * The channel value (from the Board Controller point of view) shall be computed for current in cgbc_hwmon_find_sensor()
176 channel += CGBC_HWMON_NB_IN_SENSORS; in cgbc_hwmon_find_sensor()
178 for (i = 0; i < hwmon->nb_sensors; i++) { in cgbc_hwmon_find_sensor()
179 if (hwmon->sensors[i].type == type && hwmon->sensors[i].channel == channel) { in cgbc_hwmon_find_sensor()
180 sensor = &hwmon->sensors[i]; in cgbc_hwmon_find_sensor()
188 static int cgbc_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, in cgbc_hwmon_read() argument
192 struct cgbc_hwmon_sensor *sensor = cgbc_hwmon_find_sensor(hwmon, type, channel); in cgbc_hwmon_read()
193 struct cgbc_device_data *cgbc = hwmon->cgbc; in cgbc_hwmon_read()
194 u8 data[CGBC_HWMON_CMD_SENSOR_DATA_SIZE]; in cgbc_hwmon_read() local
197 ret = cgbc_hwmon_cmd(cgbc, sensor->index, &data[0]); in cgbc_hwmon_read()
201 *val = (data[3] << 8) | data[2]; in cgbc_hwmon_read()
207 if (sensor->type == hwmon_temp) in cgbc_hwmon_read()
214 int channel) in cgbc_hwmon_is_visible() argument
216 struct cgbc_hwmon_data *data = (struct cgbc_hwmon_data *)_data; in cgbc_hwmon_is_visible() local
219 sensor = cgbc_hwmon_find_sensor(data, type, channel); in cgbc_hwmon_is_visible()
223 return sensor->active ? 0444 : 0; in cgbc_hwmon_is_visible()
227 int channel, const char **str) in cgbc_hwmon_read_string() argument
230 struct cgbc_hwmon_sensor *sensor = cgbc_hwmon_find_sensor(hwmon, type, channel); in cgbc_hwmon_read_string()
232 *str = sensor->label; in cgbc_hwmon_read_string()
275 struct cgbc_device_data *cgbc = dev_get_drvdata(pdev->dev.parent); in cgbc_hwmon_probe()
276 struct device *dev = &pdev->dev; in cgbc_hwmon_probe()
277 struct cgbc_hwmon_data *data; in cgbc_hwmon_probe() local
281 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in cgbc_hwmon_probe()
282 if (!data) in cgbc_hwmon_probe()
283 return -ENOMEM; in cgbc_hwmon_probe()
285 data->cgbc = cgbc; in cgbc_hwmon_probe()
287 ret = cgbc_hwmon_probe_sensors(dev, data); in cgbc_hwmon_probe()
291 hwmon_dev = devm_hwmon_device_register_with_info(dev, "cgbc_hwmon", data, &cgbc_chip_info, in cgbc_hwmon_probe()
298 .name = "cgbc-hwmon",