Lines Matching +full:bus +full:- +full:frequency
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic Exynos Bus frequency driver with DEVFREQ Framework
8 * This driver support Exynos Bus frequency feature by using
14 #include <linux/devfreq-event.h>
42 * Control the devfreq-event device to get the current state of bus
45 static int exynos_bus_##ops(struct exynos_bus *bus) \
49 for (i = 0; i < bus->edev_count; i++) { \
50 if (!bus->edev[i]) \
52 ret = devfreq_event_##ops(bus->edev[i]); \
63 static int exynos_bus_get_event(struct exynos_bus *bus, in exynos_bus_get_event() argument
70 for (i = 0; i < bus->edev_count; i++) { in exynos_bus_get_event()
71 if (!bus->edev[i]) in exynos_bus_get_event()
74 ret = devfreq_event_get_event(bus->edev[i], &event_data); in exynos_bus_get_event()
84 edata->load_count = load_count; in exynos_bus_get_event()
85 edata->total_count = total_count; in exynos_bus_get_event()
91 * devfreq function for both simple-ondemand and passive governor
95 struct exynos_bus *bus = dev_get_drvdata(dev); in exynos_bus_target() local
99 /* Get correct frequency for bus. */ in exynos_bus_target()
108 /* Change voltage and frequency according to new OPP level */ in exynos_bus_target()
109 mutex_lock(&bus->lock); in exynos_bus_target()
112 bus->curr_freq = *freq; in exynos_bus_target()
114 mutex_unlock(&bus->lock); in exynos_bus_target()
122 struct exynos_bus *bus = dev_get_drvdata(dev); in exynos_bus_get_dev_status() local
126 stat->current_frequency = bus->curr_freq; in exynos_bus_get_dev_status()
128 ret = exynos_bus_get_event(bus, &edata); in exynos_bus_get_dev_status()
130 dev_err(dev, "failed to get event from devfreq-event devices\n"); in exynos_bus_get_dev_status()
131 stat->total_time = stat->busy_time = 0; in exynos_bus_get_dev_status()
135 stat->busy_time = (edata.load_count * 100) / bus->ratio; in exynos_bus_get_dev_status()
136 stat->total_time = edata.total_count; in exynos_bus_get_dev_status()
138 dev_dbg(dev, "Usage of devfreq-event : %lu/%lu\n", stat->busy_time, in exynos_bus_get_dev_status()
139 stat->total_time); in exynos_bus_get_dev_status()
142 ret = exynos_bus_set_event(bus); in exynos_bus_get_dev_status()
144 dev_err(dev, "failed to set event to devfreq-event devices\n"); in exynos_bus_get_dev_status()
153 struct exynos_bus *bus = dev_get_drvdata(dev); in exynos_bus_exit() local
156 ret = exynos_bus_disable_edev(bus); in exynos_bus_exit()
158 dev_warn(dev, "failed to disable the devfreq-event devices\n"); in exynos_bus_exit()
160 platform_device_unregister(bus->icc_pdev); in exynos_bus_exit()
163 clk_disable_unprepare(bus->clk); in exynos_bus_exit()
164 dev_pm_opp_put_regulators(bus->opp_table); in exynos_bus_exit()
165 bus->opp_table = NULL; in exynos_bus_exit()
170 struct exynos_bus *bus = dev_get_drvdata(dev); in exynos_bus_passive_exit() local
172 platform_device_unregister(bus->icc_pdev); in exynos_bus_passive_exit()
175 clk_disable_unprepare(bus->clk); in exynos_bus_passive_exit()
179 struct exynos_bus *bus) in exynos_bus_parent_parse_of() argument
181 struct device *dev = bus->dev; in exynos_bus_parent_parse_of()
193 bus->opp_table = opp_table; in exynos_bus_parent_parse_of()
196 * Get the devfreq-event devices to get the current utilization of in exynos_bus_parent_parse_of()
199 count = devfreq_event_get_edev_count(dev, "devfreq-events"); in exynos_bus_parent_parse_of()
201 dev_err(dev, "failed to get the count of devfreq-event dev\n"); in exynos_bus_parent_parse_of()
205 bus->edev_count = count; in exynos_bus_parent_parse_of()
207 size = sizeof(*bus->edev) * count; in exynos_bus_parent_parse_of()
208 bus->edev = devm_kzalloc(dev, size, GFP_KERNEL); in exynos_bus_parent_parse_of()
209 if (!bus->edev) { in exynos_bus_parent_parse_of()
210 ret = -ENOMEM; in exynos_bus_parent_parse_of()
215 bus->edev[i] = devfreq_event_get_edev_by_phandle(dev, in exynos_bus_parent_parse_of()
216 "devfreq-events", i); in exynos_bus_parent_parse_of()
217 if (IS_ERR(bus->edev[i])) { in exynos_bus_parent_parse_of()
218 ret = -EPROBE_DEFER; in exynos_bus_parent_parse_of()
225 * When measuring the utilization of each AXI bus with devfreq-event in exynos_bus_parent_parse_of()
227 * total cycle of bus during sampling rate. In result, the devfreq in exynos_bus_parent_parse_of()
228 * simple-ondemand governor might not decide to change the current in exynos_bus_parent_parse_of()
229 * frequency due to too utilization (= real cycle/total cycle). in exynos_bus_parent_parse_of()
233 if (of_property_read_u32(np, "exynos,saturation-ratio", &bus->ratio)) in exynos_bus_parent_parse_of()
234 bus->ratio = DEFAULT_SATURATION_RATIO; in exynos_bus_parent_parse_of()
239 dev_pm_opp_put_regulators(bus->opp_table); in exynos_bus_parent_parse_of()
240 bus->opp_table = NULL; in exynos_bus_parent_parse_of()
246 struct exynos_bus *bus) in exynos_bus_parse_of() argument
248 struct device *dev = bus->dev; in exynos_bus_parse_of()
253 /* Get the clock to provide each bus with source clock */ in exynos_bus_parse_of()
254 bus->clk = devm_clk_get(dev, "bus"); in exynos_bus_parse_of()
255 if (IS_ERR(bus->clk)) { in exynos_bus_parse_of()
256 dev_err(dev, "failed to get bus clock\n"); in exynos_bus_parse_of()
257 return PTR_ERR(bus->clk); in exynos_bus_parse_of()
260 ret = clk_prepare_enable(bus->clk); in exynos_bus_parse_of()
266 /* Get the freq and voltage from OPP table to scale the bus freq */ in exynos_bus_parse_of()
273 rate = clk_get_rate(bus->clk); in exynos_bus_parse_of()
281 bus->curr_freq = dev_pm_opp_get_freq(opp); in exynos_bus_parse_of()
289 clk_disable_unprepare(bus->clk); in exynos_bus_parse_of()
294 static int exynos_bus_profile_init(struct exynos_bus *bus, in exynos_bus_profile_init() argument
297 struct device *dev = bus->dev; in exynos_bus_profile_init()
302 profile->polling_ms = 50; in exynos_bus_profile_init()
303 profile->target = exynos_bus_target; in exynos_bus_profile_init()
304 profile->get_dev_status = exynos_bus_get_dev_status; in exynos_bus_profile_init()
305 profile->exit = exynos_bus_exit; in exynos_bus_profile_init()
309 return -ENOMEM; in exynos_bus_profile_init()
311 ondemand_data->upthreshold = 40; in exynos_bus_profile_init()
312 ondemand_data->downdifferential = 5; in exynos_bus_profile_init()
314 /* Add devfreq device to monitor and handle the exynos bus */ in exynos_bus_profile_init()
315 bus->devfreq = devm_devfreq_add_device(dev, profile, in exynos_bus_profile_init()
318 if (IS_ERR(bus->devfreq)) { in exynos_bus_profile_init()
320 return PTR_ERR(bus->devfreq); in exynos_bus_profile_init()
324 ret = devm_devfreq_register_opp_notifier(dev, bus->devfreq); in exynos_bus_profile_init()
331 * Enable devfreq-event to get raw data which is used to determine in exynos_bus_profile_init()
332 * current bus load. in exynos_bus_profile_init()
334 ret = exynos_bus_enable_edev(bus); in exynos_bus_profile_init()
336 dev_err(dev, "failed to enable devfreq-event devices\n"); in exynos_bus_profile_init()
340 ret = exynos_bus_set_event(bus); in exynos_bus_profile_init()
342 dev_err(dev, "failed to set event to devfreq-event devices\n"); in exynos_bus_profile_init()
349 if (exynos_bus_disable_edev(bus)) in exynos_bus_profile_init()
350 dev_warn(dev, "failed to disable the devfreq-event devices\n"); in exynos_bus_profile_init()
355 static int exynos_bus_profile_init_passive(struct exynos_bus *bus, in exynos_bus_profile_init_passive() argument
358 struct device *dev = bus->dev; in exynos_bus_profile_init_passive()
363 profile->target = exynos_bus_target; in exynos_bus_profile_init_passive()
364 profile->exit = exynos_bus_passive_exit; in exynos_bus_profile_init_passive()
369 return -EPROBE_DEFER; in exynos_bus_profile_init_passive()
373 return -ENOMEM; in exynos_bus_profile_init_passive()
375 passive_data->parent = parent_devfreq; in exynos_bus_profile_init_passive()
377 /* Add devfreq device for exynos bus with passive governor */ in exynos_bus_profile_init_passive()
378 bus->devfreq = devm_devfreq_add_device(dev, profile, DEVFREQ_GOV_PASSIVE, in exynos_bus_profile_init_passive()
380 if (IS_ERR(bus->devfreq)) { in exynos_bus_profile_init_passive()
383 return PTR_ERR(bus->devfreq); in exynos_bus_profile_init_passive()
391 struct device *dev = &pdev->dev; in exynos_bus_probe()
392 struct device_node *np = dev->of_node, *node; in exynos_bus_probe()
394 struct exynos_bus *bus; in exynos_bus_probe() local
401 return -EINVAL; in exynos_bus_probe()
404 bus = devm_kzalloc(&pdev->dev, sizeof(*bus), GFP_KERNEL); in exynos_bus_probe()
405 if (!bus) in exynos_bus_probe()
406 return -ENOMEM; in exynos_bus_probe()
407 mutex_init(&bus->lock); in exynos_bus_probe()
408 bus->dev = &pdev->dev; in exynos_bus_probe()
409 platform_set_drvdata(pdev, bus); in exynos_bus_probe()
413 return -ENOMEM; in exynos_bus_probe()
415 node = of_parse_phandle(dev->of_node, "devfreq", 0); in exynos_bus_probe()
420 ret = exynos_bus_parent_parse_of(np, bus); in exynos_bus_probe()
425 /* Parse the device-tree to get the resource information */ in exynos_bus_probe()
426 ret = exynos_bus_parse_of(np, bus); in exynos_bus_probe()
431 ret = exynos_bus_profile_init_passive(bus, profile); in exynos_bus_probe()
433 ret = exynos_bus_profile_init(bus, profile); in exynos_bus_probe()
439 if (of_get_property(dev->of_node, "#interconnect-cells", NULL)) { in exynos_bus_probe()
440 bus->icc_pdev = platform_device_register_data( in exynos_bus_probe()
441 dev, "exynos-generic-icc", in exynos_bus_probe()
444 if (IS_ERR(bus->icc_pdev)) { in exynos_bus_probe()
445 ret = PTR_ERR(bus->icc_pdev); in exynos_bus_probe()
450 max_state = bus->devfreq->profile->max_state; in exynos_bus_probe()
451 min_freq = (bus->devfreq->profile->freq_table[0] / 1000); in exynos_bus_probe()
452 max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000); in exynos_bus_probe()
453 pr_info("exynos-bus: new bus device registered: %s (%6ld KHz ~ %6ld KHz)\n", in exynos_bus_probe()
460 clk_disable_unprepare(bus->clk); in exynos_bus_probe()
462 dev_pm_opp_put_regulators(bus->opp_table); in exynos_bus_probe()
463 bus->opp_table = NULL; in exynos_bus_probe()
470 struct exynos_bus *bus = dev_get_drvdata(&pdev->dev); in exynos_bus_shutdown() local
472 devfreq_suspend_device(bus->devfreq); in exynos_bus_shutdown()
478 struct exynos_bus *bus = dev_get_drvdata(dev); in exynos_bus_resume() local
481 ret = exynos_bus_enable_edev(bus); in exynos_bus_resume()
483 dev_err(dev, "failed to enable the devfreq-event devices\n"); in exynos_bus_resume()
492 struct exynos_bus *bus = dev_get_drvdata(dev); in exynos_bus_suspend() local
495 ret = exynos_bus_disable_edev(bus); in exynos_bus_suspend()
497 dev_err(dev, "failed to disable the devfreq-event devices\n"); in exynos_bus_suspend()
510 { .compatible = "samsung,exynos-bus", },
519 .name = "exynos-bus",
526 MODULE_DESCRIPTION("Generic Exynos Bus frequency driver");