Lines Matching +full:devfreq +full:- +full:event
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic Exynos Bus frequency driver with DEVFREQ Framework
9 * DEVFREQ framework and is based on drivers/devfreq/exynos/exynos4_bus.c.
13 #include <linux/devfreq.h>
14 #include <linux/devfreq-event.h>
28 struct devfreq *devfreq; member
41 * Control the devfreq-event device to get the current state of bus
48 for (i = 0; i < bus->edev_count; i++) { \
49 if (!bus->edev[i]) \
51 ret = devfreq_event_##ops(bus->edev[i]); \
69 for (i = 0; i < bus->edev_count; i++) { in exynos_bus_get_event()
70 if (!bus->edev[i]) in exynos_bus_get_event()
73 ret = devfreq_event_get_event(bus->edev[i], &event_data); in exynos_bus_get_event()
83 edata->load_count = load_count; in exynos_bus_get_event()
84 edata->total_count = total_count; in exynos_bus_get_event()
90 * devfreq function for both simple-ondemand and passive governor
108 mutex_lock(&bus->lock); in exynos_bus_target()
111 bus->curr_freq = *freq; in exynos_bus_target()
113 mutex_unlock(&bus->lock); in exynos_bus_target()
125 stat->current_frequency = bus->curr_freq; in exynos_bus_get_dev_status()
129 dev_err(dev, "failed to get event from devfreq-event devices\n"); in exynos_bus_get_dev_status()
130 stat->total_time = stat->busy_time = 0; in exynos_bus_get_dev_status()
134 stat->busy_time = (edata.load_count * 100) / bus->ratio; in exynos_bus_get_dev_status()
135 stat->total_time = edata.total_count; in exynos_bus_get_dev_status()
137 dev_dbg(dev, "Usage of devfreq-event : %lu/%lu\n", stat->busy_time, in exynos_bus_get_dev_status()
138 stat->total_time); in exynos_bus_get_dev_status()
143 dev_err(dev, "failed to set event to devfreq-event devices\n"); in exynos_bus_get_dev_status()
157 dev_warn(dev, "failed to disable the devfreq-event devices\n"); in exynos_bus_exit()
160 clk_disable_unprepare(bus->clk); in exynos_bus_exit()
161 if (bus->opp_table) { in exynos_bus_exit()
162 dev_pm_opp_put_regulators(bus->opp_table); in exynos_bus_exit()
163 bus->opp_table = NULL; in exynos_bus_exit()
172 clk_disable_unprepare(bus->clk); in exynos_bus_passive_exit()
178 struct device *dev = bus->dev; in exynos_bus_parent_parse_of()
190 bus->opp_table = opp_table; in exynos_bus_parent_parse_of()
193 * Get the devfreq-event devices to get the current utilization of in exynos_bus_parent_parse_of()
194 * buses. This raw data will be used in devfreq ondemand governor. in exynos_bus_parent_parse_of()
196 count = devfreq_event_get_edev_count(dev, "devfreq-events"); in exynos_bus_parent_parse_of()
198 dev_err(dev, "failed to get the count of devfreq-event dev\n"); in exynos_bus_parent_parse_of()
202 bus->edev_count = count; in exynos_bus_parent_parse_of()
204 size = sizeof(*bus->edev) * count; in exynos_bus_parent_parse_of()
205 bus->edev = devm_kzalloc(dev, size, GFP_KERNEL); in exynos_bus_parent_parse_of()
206 if (!bus->edev) { in exynos_bus_parent_parse_of()
207 ret = -ENOMEM; in exynos_bus_parent_parse_of()
212 bus->edev[i] = devfreq_event_get_edev_by_phandle(dev, in exynos_bus_parent_parse_of()
213 "devfreq-events", i); in exynos_bus_parent_parse_of()
214 if (IS_ERR(bus->edev[i])) { in exynos_bus_parent_parse_of()
215 ret = -EPROBE_DEFER; in exynos_bus_parent_parse_of()
222 * When measuring the utilization of each AXI bus with devfreq-event in exynos_bus_parent_parse_of()
224 * total cycle of bus during sampling rate. In result, the devfreq in exynos_bus_parent_parse_of()
225 * simple-ondemand governor might not decide to change the current in exynos_bus_parent_parse_of()
230 if (of_property_read_u32(np, "exynos,saturation-ratio", &bus->ratio)) in exynos_bus_parent_parse_of()
231 bus->ratio = DEFAULT_SATURATION_RATIO; in exynos_bus_parent_parse_of()
236 dev_pm_opp_put_regulators(bus->opp_table); in exynos_bus_parent_parse_of()
237 bus->opp_table = NULL; in exynos_bus_parent_parse_of()
245 struct device *dev = bus->dev; in exynos_bus_parse_of()
251 bus->clk = devm_clk_get(dev, "bus"); in exynos_bus_parse_of()
252 if (IS_ERR(bus->clk)) { in exynos_bus_parse_of()
254 return PTR_ERR(bus->clk); in exynos_bus_parse_of()
257 ret = clk_prepare_enable(bus->clk); in exynos_bus_parse_of()
270 rate = clk_get_rate(bus->clk); in exynos_bus_parse_of()
278 bus->curr_freq = dev_pm_opp_get_freq(opp); in exynos_bus_parse_of()
286 clk_disable_unprepare(bus->clk); in exynos_bus_parse_of()
294 struct device *dev = bus->dev; in exynos_bus_profile_init()
299 profile->polling_ms = 50; in exynos_bus_profile_init()
300 profile->target = exynos_bus_target; in exynos_bus_profile_init()
301 profile->get_dev_status = exynos_bus_get_dev_status; in exynos_bus_profile_init()
302 profile->exit = exynos_bus_exit; in exynos_bus_profile_init()
306 return -ENOMEM; in exynos_bus_profile_init()
308 ondemand_data->upthreshold = 40; in exynos_bus_profile_init()
309 ondemand_data->downdifferential = 5; in exynos_bus_profile_init()
311 /* Add devfreq device to monitor and handle the exynos bus */ in exynos_bus_profile_init()
312 bus->devfreq = devm_devfreq_add_device(dev, profile, in exynos_bus_profile_init()
315 if (IS_ERR(bus->devfreq)) { in exynos_bus_profile_init()
316 dev_err(dev, "failed to add devfreq device\n"); in exynos_bus_profile_init()
317 return PTR_ERR(bus->devfreq); in exynos_bus_profile_init()
321 ret = devm_devfreq_register_opp_notifier(dev, bus->devfreq); in exynos_bus_profile_init()
328 * Enable devfreq-event to get raw data which is used to determine in exynos_bus_profile_init()
333 dev_err(dev, "failed to enable devfreq-event devices\n"); in exynos_bus_profile_init()
339 dev_err(dev, "failed to set event to devfreq-event devices\n"); in exynos_bus_profile_init()
347 dev_warn(dev, "failed to disable the devfreq-event devices\n"); in exynos_bus_profile_init()
355 struct device *dev = bus->dev; in exynos_bus_profile_init_passive()
357 struct devfreq *parent_devfreq; in exynos_bus_profile_init_passive()
360 profile->target = exynos_bus_target; in exynos_bus_profile_init_passive()
361 profile->exit = exynos_bus_passive_exit; in exynos_bus_profile_init_passive()
363 /* Get the instance of parent devfreq device */ in exynos_bus_profile_init_passive()
364 parent_devfreq = devfreq_get_devfreq_by_phandle(dev, "devfreq", 0); in exynos_bus_profile_init_passive()
366 return -EPROBE_DEFER; in exynos_bus_profile_init_passive()
370 return -ENOMEM; in exynos_bus_profile_init_passive()
372 passive_data->parent = parent_devfreq; in exynos_bus_profile_init_passive()
374 /* Add devfreq device for exynos bus with passive governor */ in exynos_bus_profile_init_passive()
375 bus->devfreq = devm_devfreq_add_device(dev, profile, DEVFREQ_GOV_PASSIVE, in exynos_bus_profile_init_passive()
377 if (IS_ERR(bus->devfreq)) { in exynos_bus_profile_init_passive()
379 "failed to add devfreq dev with passive governor\n"); in exynos_bus_profile_init_passive()
380 return PTR_ERR(bus->devfreq); in exynos_bus_profile_init_passive()
388 struct device *dev = &pdev->dev; in exynos_bus_probe()
389 struct device_node *np = dev->of_node, *node; in exynos_bus_probe()
398 return -EINVAL; in exynos_bus_probe()
401 bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); in exynos_bus_probe()
403 return -ENOMEM; in exynos_bus_probe()
404 mutex_init(&bus->lock); in exynos_bus_probe()
405 bus->dev = &pdev->dev; in exynos_bus_probe()
410 return -ENOMEM; in exynos_bus_probe()
412 node = of_parse_phandle(dev->of_node, "devfreq", 0); in exynos_bus_probe()
422 /* Parse the device-tree to get the resource information */ in exynos_bus_probe()
435 max_state = bus->devfreq->profile->max_state; in exynos_bus_probe()
436 min_freq = (bus->devfreq->profile->freq_table[0] / 1000); in exynos_bus_probe()
437 max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000); in exynos_bus_probe()
438 pr_info("exynos-bus: new bus device registered: %s (%6ld KHz ~ %6ld KHz)\n", in exynos_bus_probe()
445 clk_disable_unprepare(bus->clk); in exynos_bus_probe()
448 dev_pm_opp_put_regulators(bus->opp_table); in exynos_bus_probe()
449 bus->opp_table = NULL; in exynos_bus_probe()
457 struct exynos_bus *bus = dev_get_drvdata(&pdev->dev); in exynos_bus_shutdown()
459 devfreq_suspend_device(bus->devfreq); in exynos_bus_shutdown()
470 dev_err(dev, "failed to enable the devfreq-event devices\n"); in exynos_bus_resume()
484 dev_err(dev, "failed to disable the devfreq-event devices\n"); in exynos_bus_suspend()
497 { .compatible = "samsung,exynos-bus", },
506 .name = "exynos-bus",