Skip to content

Commit 403e068

Browse files
chanwoochoimyungjoo
authored andcommitted
PM / devfreq: exynos: Add support of bus frequency of sub-blocks using passive governor
This patch adds the support of bus frequency feature for sub-blocks which share the one power line. If each bus depends on the power line, each bus is not able to change the voltage by oneself. To optimize the power-consumption on runtime, some buses using the same power line should change the source clock and regulator at the same time. So, this patch uses the passive governor to support the bus frequency for all buses which sharing the one power line. For example, Exynos3250 include the two power line for AXI buses as following: : VDD_MIF : MIF (Memory Interface) provide the DMC (Dynamic Memory Controller) with the power (regulator). : VDD_INT : INT (Internal) provide the various sub-blocks with the power (regulator). Each bus is included in as follwoing block. In the case of VDD_MIF, only DMC bus use the power line. So, there is no any depencency between buese. But, in the case of VDD_INT, various buses share the one power line of VDD_INT. We need to make the depenency between buses. When using passive governor, there is no problem to support the bus frequency as DVFS for all buses. One bus should be operated as the parent bus device which gathering the current load of INT block and then decides the new frequency with some governors except of passive governor. After deciding the new frequency by the parent bus device, the rest bus devices will change the each source clock according to new frequency of the parent bus device. - MIF (Memory Interface) block : VDD_MIF |--- DMC - INT (Internal) block : VDD_INT |--- LEFTBUS (parent) |--- PERIL |--- MFC |--- G3D |--- RIGHTBUS |--- FSYS |--- LCD0 |--- PERIR |--- ISP |--- CAM Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> [tjakobi: Reported debugfs error during booting and cw00.choi fix it.] Reported-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> Acked-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
1 parent 9961331 commit 403e068

2 files changed

Lines changed: 174 additions & 46 deletions

File tree

‎drivers/devfreq/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ config ARM_EXYNOS_BUS_DEVFREQ
7878
bool "ARM EXYNOS Generic Memory Bus DEVFREQ Driver"
7979
depends on ARCH_EXYNOS
8080
select DEVFREQ_GOV_SIMPLE_ONDEMAND
81+
select DEVFREQ_GOV_PASSIVE
8182
select DEVFREQ_EVENT_EXYNOS_PPMU
8283
select PM_DEVFREQ_EVENT
8384
select PM_OPP

‎drivers/devfreq/exynos-bus.c‎

Lines changed: 173 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Generic Exynos Bus frequency driver with DEVFREQ Framework
33
*
4-
* Copyright (c) 2015 Samsung Electronics Co., Ltd.
4+
* Copyright (c) 2016 Samsung Electronics Co., Ltd.
55
* Author : Chanwoo Choi <cw00.choi@samsung.com>
66
*
77
* This driver support Exynos Bus frequency feature by using
@@ -93,7 +93,7 @@ static int exynos_bus_get_event(struct exynos_bus *bus,
9393
}
9494

9595
/*
96-
* Must necessary function for devfreq governor
96+
* Must necessary function for devfreq simple-ondemand governor
9797
*/
9898
static int exynos_bus_target(struct device *dev, unsigned long *freq, u32 flags)
9999
{
@@ -202,59 +202,81 @@ static void exynos_bus_exit(struct device *dev)
202202
regulator_disable(bus->regulator);
203203

204204
dev_pm_opp_of_remove_table(dev);
205+
clk_disable_unprepare(bus->clk);
205206
}
206207

207-
static int exynos_bus_parse_of(struct device_node *np,
208-
struct exynos_bus *bus)
208+
/*
209+
* Must necessary function for devfreq passive governor
210+
*/
211+
static int exynos_bus_passive_target(struct device *dev, unsigned long *freq,
212+
u32 flags)
209213
{
210-
struct device *dev = bus->dev;
211-
unsigned long rate;
212-
int i, ret, count, size;
214+
struct exynos_bus *bus = dev_get_drvdata(dev);
215+
struct dev_pm_opp *new_opp;
216+
unsigned long old_freq, new_freq;
217+
int ret = 0;
213218

214-
/* Get the clock to provide each bus with source clock */
215-
bus->clk = devm_clk_get(dev, "bus");
216-
if (IS_ERR(bus->clk)) {
217-
dev_err(dev, "failed to get bus clock\n");
218-
return PTR_ERR(bus->clk);
219+
/* Get new opp-bus instance according to new bus clock */
220+
rcu_read_lock();
221+
new_opp = devfreq_recommended_opp(dev, freq, flags);
222+
if (IS_ERR(new_opp)) {
223+
dev_err(dev, "failed to get recommended opp instance\n");
224+
rcu_read_unlock();
225+
return PTR_ERR(new_opp);
219226
}
220227

221-
ret = clk_prepare_enable(bus->clk);
222-
if (ret < 0) {
223-
dev_err(dev, "failed to get enable clock\n");
224-
return ret;
225-
}
228+
new_freq = dev_pm_opp_get_freq(new_opp);
229+
old_freq = dev_pm_opp_get_freq(bus->curr_opp);
230+
rcu_read_unlock();
226231

227-
/* Get the freq/voltage OPP table to scale the bus frequency */
228-
rcu_read_lock();
229-
ret = dev_pm_opp_of_add_table(dev);
232+
if (old_freq == new_freq)
233+
return 0;
234+
235+
/* Change the frequency according to new OPP level */
236+
mutex_lock(&bus->lock);
237+
238+
ret = clk_set_rate(bus->clk, new_freq);
230239
if (ret < 0) {
231-
dev_err(dev, "failed to get OPP table\n");
232-
rcu_read_unlock();
233-
goto err_clk;
240+
dev_err(dev, "failed to set the clock of bus\n");
241+
goto out;
234242
}
235243

236-
rate = clk_get_rate(bus->clk);
237-
bus->curr_opp = dev_pm_opp_find_freq_ceil(dev, &rate);
238-
if (IS_ERR(bus->curr_opp)) {
239-
dev_err(dev, "failed to find dev_pm_opp\n");
240-
rcu_read_unlock();
241-
ret = PTR_ERR(bus->curr_opp);
242-
goto err_opp;
243-
}
244-
rcu_read_unlock();
244+
*freq = new_freq;
245+
bus->curr_opp = new_opp;
246+
247+
dev_dbg(dev, "Set the frequency of bus (%lukHz -> %lukHz)\n",
248+
old_freq/1000, new_freq/1000);
249+
out:
250+
mutex_unlock(&bus->lock);
251+
252+
return ret;
253+
}
254+
255+
static void exynos_bus_passive_exit(struct device *dev)
256+
{
257+
struct exynos_bus *bus = dev_get_drvdata(dev);
258+
259+
dev_pm_opp_of_remove_table(dev);
260+
clk_disable_unprepare(bus->clk);
261+
}
262+
263+
static int exynos_bus_parent_parse_of(struct device_node *np,
264+
struct exynos_bus *bus)
265+
{
266+
struct device *dev = bus->dev;
267+
int i, ret, count, size;
245268

246269
/* Get the regulator to provide each bus with the power */
247270
bus->regulator = devm_regulator_get(dev, "vdd");
248271
if (IS_ERR(bus->regulator)) {
249272
dev_err(dev, "failed to get VDD regulator\n");
250-
ret = PTR_ERR(bus->regulator);
251-
goto err_opp;
273+
return PTR_ERR(bus->regulator);
252274
}
253275

254276
ret = regulator_enable(bus->regulator);
255277
if (ret < 0) {
256278
dev_err(dev, "failed to enable VDD regulator\n");
257-
goto err_opp;
279+
return ret;
258280
}
259281

260282
/*
@@ -305,6 +327,51 @@ static int exynos_bus_parse_of(struct device_node *np,
305327

306328
err_regulator:
307329
regulator_disable(bus->regulator);
330+
331+
return ret;
332+
}
333+
334+
static int exynos_bus_parse_of(struct device_node *np,
335+
struct exynos_bus *bus)
336+
{
337+
struct device *dev = bus->dev;
338+
unsigned long rate;
339+
int ret;
340+
341+
/* Get the clock to provide each bus with source clock */
342+
bus->clk = devm_clk_get(dev, "bus");
343+
if (IS_ERR(bus->clk)) {
344+
dev_err(dev, "failed to get bus clock\n");
345+
return PTR_ERR(bus->clk);
346+
}
347+
348+
ret = clk_prepare_enable(bus->clk);
349+
if (ret < 0) {
350+
dev_err(dev, "failed to get enable clock\n");
351+
return ret;
352+
}
353+
354+
/* Get the freq and voltage from OPP table to scale the bus freq */
355+
rcu_read_lock();
356+
ret = dev_pm_opp_of_add_table(dev);
357+
if (ret < 0) {
358+
dev_err(dev, "failed to get OPP table\n");
359+
rcu_read_unlock();
360+
goto err_clk;
361+
}
362+
363+
rate = clk_get_rate(bus->clk);
364+
bus->curr_opp = devfreq_recommended_opp(dev, &rate, 0);
365+
if (IS_ERR(bus->curr_opp)) {
366+
dev_err(dev, "failed to find dev_pm_opp\n");
367+
rcu_read_unlock();
368+
ret = PTR_ERR(bus->curr_opp);
369+
goto err_opp;
370+
}
371+
rcu_read_unlock();
372+
373+
return 0;
374+
308375
err_opp:
309376
dev_pm_opp_of_remove_table(dev);
310377
err_clk:
@@ -319,8 +386,11 @@ static int exynos_bus_probe(struct platform_device *pdev)
319386
struct device_node *np = dev->of_node;
320387
struct devfreq_dev_profile *profile;
321388
struct devfreq_simple_ondemand_data *ondemand_data;
389+
struct devfreq_passive_data *passive_data;
390+
struct devfreq *parent_devfreq;
322391
struct exynos_bus *bus;
323-
int ret;
392+
int ret, max_state;
393+
unsigned long min_freq, max_freq;
324394

325395
if (!np) {
326396
dev_err(dev, "failed to find devicetree node\n");
@@ -337,20 +407,33 @@ static int exynos_bus_probe(struct platform_device *pdev)
337407
/* Parse the device-tree to get the resource information */
338408
ret = exynos_bus_parse_of(np, bus);
339409
if (ret < 0)
340-
return ret;
410+
goto err;
341411

342-
/* Initalize the struct profile and governor data */
343412
profile = devm_kzalloc(dev, sizeof(*profile), GFP_KERNEL);
344-
if (!profile)
345-
return -ENOMEM;
413+
if (!profile) {
414+
ret = -ENOMEM;
415+
goto err;
416+
}
417+
418+
if (of_parse_phandle(dev->of_node, "devfreq", 0))
419+
goto passive;
420+
else
421+
ret = exynos_bus_parent_parse_of(np, bus);
422+
423+
if (ret < 0)
424+
goto err;
425+
426+
/* Initalize the struct profile and governor data for parent device */
346427
profile->polling_ms = 50;
347428
profile->target = exynos_bus_target;
348429
profile->get_dev_status = exynos_bus_get_dev_status;
349430
profile->exit = exynos_bus_exit;
350431

351432
ondemand_data = devm_kzalloc(dev, sizeof(*ondemand_data), GFP_KERNEL);
352-
if (!ondemand_data)
353-
return -ENOMEM;
433+
if (!ondemand_data) {
434+
ret = -ENOMEM;
435+
goto err;
436+
}
354437
ondemand_data->upthreshold = 40;
355438
ondemand_data->downdifferential = 5;
356439

@@ -359,14 +442,15 @@ static int exynos_bus_probe(struct platform_device *pdev)
359442
ondemand_data);
360443
if (IS_ERR(bus->devfreq)) {
361444
dev_err(dev, "failed to add devfreq device\n");
362-
return PTR_ERR(bus->devfreq);
445+
ret = PTR_ERR(bus->devfreq);
446+
goto err;
363447
}
364448

365449
/* Register opp_notifier to catch the change of OPP */
366450
ret = devm_devfreq_register_opp_notifier(dev, bus->devfreq);
367451
if (ret < 0) {
368452
dev_err(dev, "failed to register opp notifier\n");
369-
return ret;
453+
goto err;
370454
}
371455

372456
/*
@@ -376,16 +460,59 @@ static int exynos_bus_probe(struct platform_device *pdev)
376460
ret = exynos_bus_enable_edev(bus);
377461
if (ret < 0) {
378462
dev_err(dev, "failed to enable devfreq-event devices\n");
379-
return ret;
463+
goto err;
380464
}
381465

382466
ret = exynos_bus_set_event(bus);
383467
if (ret < 0) {
384468
dev_err(dev, "failed to set event to devfreq-event devices\n");
385-
return ret;
469+
goto err;
386470
}
387471

472+
goto out;
473+
passive:
474+
/* Initalize the struct profile and governor data for passive device */
475+
profile->target = exynos_bus_passive_target;
476+
profile->exit = exynos_bus_passive_exit;
477+
478+
/* Get the instance of parent devfreq device */
479+
parent_devfreq = devfreq_get_devfreq_by_phandle(dev, 0);
480+
if (IS_ERR(parent_devfreq)) {
481+
ret = -EPROBE_DEFER;
482+
goto err;
483+
}
484+
485+
passive_data = devm_kzalloc(dev, sizeof(*passive_data), GFP_KERNEL);
486+
if (!passive_data) {
487+
ret = -ENOMEM;
488+
goto err;
489+
}
490+
passive_data->parent = parent_devfreq;
491+
492+
/* Add devfreq device for exynos bus with passive governor */
493+
bus->devfreq = devm_devfreq_add_device(dev, profile, "passive",
494+
passive_data);
495+
if (IS_ERR(bus->devfreq)) {
496+
dev_err(dev,
497+
"failed to add devfreq dev with passive governor\n");
498+
ret = -EPROBE_DEFER;
499+
goto err;
500+
}
501+
502+
out:
503+
max_state = bus->devfreq->profile->max_state;
504+
min_freq = (bus->devfreq->profile->freq_table[0] / 1000);
505+
max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000);
506+
pr_info("exynos-bus: new bus device registered: %s (%6ld KHz ~ %6ld KHz)\n",
507+
dev_name(dev), min_freq, max_freq);
508+
388509
return 0;
510+
511+
err:
512+
dev_pm_opp_of_remove_table(dev);
513+
clk_disable_unprepare(bus->clk);
514+
515+
return ret;
389516
}
390517

391518
#ifdef CONFIG_PM_SLEEP

0 commit comments

Comments
 (0)