Lines Matching +full:power +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
3 * System Control and Power Interface(SCPI) based hwmon sensor driver
45 [POWER] = 1000000, /* (microwatts) */
53 [POWER] = 1000000, /* (microwatts) */
57 static void scpi_scale_reading(u64 *value, struct sensor_data *sensor) in scpi_scale_reading() argument
59 if (scpi_scale[sensor->info.class] != sensor->scale) { in scpi_scale_reading()
60 *value *= scpi_scale[sensor->info.class]; in scpi_scale_reading()
61 do_div(*value, sensor->scale); in scpi_scale_reading()
68 struct scpi_sensors *scpi_sensors = zone->scpi_sensors; in scpi_read_temp()
69 struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops; in scpi_read_temp()
70 struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id]; in scpi_read_temp() local
74 ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value); in scpi_read_temp()
78 scpi_scale_reading(&value, sensor); in scpi_read_temp()
89 struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops; in scpi_show_sensor()
90 struct sensor_data *sensor; in scpi_show_sensor() local
94 sensor = container_of(attr, struct sensor_data, dev_attr_input); in scpi_show_sensor()
96 ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value); in scpi_show_sensor()
100 scpi_scale_reading(&value, sensor); in scpi_show_sensor()
103 * Temperature sensor values are treated as signed values based on in scpi_show_sensor()
108 if (sensor->info.class == TEMPERATURE) in scpi_show_sensor()
117 struct sensor_data *sensor; in scpi_show_label() local
119 sensor = container_of(attr, struct sensor_data, dev_attr_label); in scpi_show_label()
121 return sprintf(buf, "%s\n", sensor->info.name); in scpi_show_label()
129 {.compatible = "arm,scpi-sensors", .data = &scpi_scale},
130 {.compatible = "amlogic,meson-gxbb-scpi-sensors", .data = &gxbb_scpi_scale},
142 struct device *hwdev, *dev = &pdev->dev; in scpi_hwmon_probe()
148 return -EPROBE_DEFER; in scpi_hwmon_probe()
150 ret = scpi_ops->sensor_get_capability(&nr_sensors); in scpi_hwmon_probe()
155 return -ENODEV; in scpi_hwmon_probe()
159 return -ENOMEM; in scpi_hwmon_probe()
161 scpi_sensors->data = devm_kcalloc(dev, nr_sensors, in scpi_hwmon_probe()
162 sizeof(*scpi_sensors->data), GFP_KERNEL); in scpi_hwmon_probe()
163 if (!scpi_sensors->data) in scpi_hwmon_probe()
164 return -ENOMEM; in scpi_hwmon_probe()
166 scpi_sensors->attrs = devm_kcalloc(dev, (nr_sensors * 2) + 1, in scpi_hwmon_probe()
167 sizeof(*scpi_sensors->attrs), GFP_KERNEL); in scpi_hwmon_probe()
168 if (!scpi_sensors->attrs) in scpi_hwmon_probe()
169 return -ENOMEM; in scpi_hwmon_probe()
171 scpi_sensors->scpi_ops = scpi_ops; in scpi_hwmon_probe()
173 scale = of_device_get_match_data(&pdev->dev); in scpi_hwmon_probe()
175 dev_err(&pdev->dev, "Unable to initialize scpi-hwmon data\n"); in scpi_hwmon_probe()
176 return -ENODEV; in scpi_hwmon_probe()
180 struct sensor_data *sensor = &scpi_sensors->data[idx]; in scpi_hwmon_probe() local
182 ret = scpi_ops->sensor_get_info(i, &sensor->info); in scpi_hwmon_probe()
186 switch (sensor->info.class) { in scpi_hwmon_probe()
188 snprintf(sensor->input, sizeof(sensor->input), in scpi_hwmon_probe()
190 snprintf(sensor->label, sizeof(sensor->input), in scpi_hwmon_probe()
195 snprintf(sensor->input, sizeof(sensor->input), in scpi_hwmon_probe()
197 snprintf(sensor->label, sizeof(sensor->input), in scpi_hwmon_probe()
202 snprintf(sensor->input, sizeof(sensor->input), in scpi_hwmon_probe()
204 snprintf(sensor->label, sizeof(sensor->input), in scpi_hwmon_probe()
208 case POWER: in scpi_hwmon_probe()
209 snprintf(sensor->input, sizeof(sensor->input), in scpi_hwmon_probe()
210 "power%d_input", num_power + 1); in scpi_hwmon_probe()
211 snprintf(sensor->label, sizeof(sensor->input), in scpi_hwmon_probe()
212 "power%d_label", num_power + 1); in scpi_hwmon_probe()
216 snprintf(sensor->input, sizeof(sensor->input), in scpi_hwmon_probe()
218 snprintf(sensor->label, sizeof(sensor->input), in scpi_hwmon_probe()
226 sensor->scale = scale[sensor->info.class]; in scpi_hwmon_probe()
228 sensor->dev_attr_input.attr.mode = 0444; in scpi_hwmon_probe()
229 sensor->dev_attr_input.show = scpi_show_sensor; in scpi_hwmon_probe()
230 sensor->dev_attr_input.attr.name = sensor->input; in scpi_hwmon_probe()
232 sensor->dev_attr_label.attr.mode = 0444; in scpi_hwmon_probe()
233 sensor->dev_attr_label.show = scpi_show_label; in scpi_hwmon_probe()
234 sensor->dev_attr_label.attr.name = sensor->label; in scpi_hwmon_probe()
236 scpi_sensors->attrs[idx << 1] = &sensor->dev_attr_input.attr; in scpi_hwmon_probe()
237 scpi_sensors->attrs[(idx << 1) + 1] = &sensor->dev_attr_label.attr; in scpi_hwmon_probe()
239 sysfs_attr_init(scpi_sensors->attrs[idx << 1]); in scpi_hwmon_probe()
240 sysfs_attr_init(scpi_sensors->attrs[(idx << 1) + 1]); in scpi_hwmon_probe()
244 scpi_sensors->group.attrs = scpi_sensors->attrs; in scpi_hwmon_probe()
245 scpi_sensors->groups[0] = &scpi_sensors->group; in scpi_hwmon_probe()
250 "scpi_sensors", scpi_sensors, scpi_sensors->groups); in scpi_hwmon_probe()
263 INIT_LIST_HEAD(&scpi_sensors->thermal_zones); in scpi_hwmon_probe()
265 struct sensor_data *sensor = &scpi_sensors->data[i]; in scpi_hwmon_probe() local
269 if (sensor->info.class != TEMPERATURE) in scpi_hwmon_probe()
274 return -ENOMEM; in scpi_hwmon_probe()
276 zone->sensor_id = i; in scpi_hwmon_probe()
277 zone->scpi_sensors = scpi_sensors; in scpi_hwmon_probe()
279 sensor->info.sensor_id, in scpi_hwmon_probe()
297 .name = "scpi-hwmon",