| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Generic Exynos Bus frequency driver with DEVFREQ Framework |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * This driver support Exynos Bus frequency feature by using |
|---|
| 8 | 9 | * DEVFREQ framework and is based on drivers/devfreq/exynos/exynos4_bus.c. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #include <linux/clk.h> |
|---|
| .. | .. |
|---|
| 18 | 15 | #include <linux/device.h> |
|---|
| 19 | 16 | #include <linux/export.h> |
|---|
| 20 | 17 | #include <linux/module.h> |
|---|
| 21 | | -#include <linux/of_device.h> |
|---|
| 18 | +#include <linux/of.h> |
|---|
| 22 | 19 | #include <linux/pm_opp.h> |
|---|
| 23 | 20 | #include <linux/platform_device.h> |
|---|
| 24 | 21 | #include <linux/regulator/consumer.h> |
|---|
| 25 | | -#include <linux/slab.h> |
|---|
| 26 | 22 | |
|---|
| 27 | 23 | #define DEFAULT_SATURATION_RATIO 40 |
|---|
| 28 | | -#define DEFAULT_VOLTAGE_TOLERANCE 2 |
|---|
| 29 | 24 | |
|---|
| 30 | 25 | struct exynos_bus { |
|---|
| 31 | 26 | struct device *dev; |
|---|
| .. | .. |
|---|
| 37 | 32 | |
|---|
| 38 | 33 | unsigned long curr_freq; |
|---|
| 39 | 34 | |
|---|
| 40 | | - struct regulator *regulator; |
|---|
| 35 | + struct opp_table *opp_table; |
|---|
| 41 | 36 | struct clk *clk; |
|---|
| 42 | | - unsigned int voltage_tolerance; |
|---|
| 43 | 37 | unsigned int ratio; |
|---|
| 44 | 38 | }; |
|---|
| 45 | 39 | |
|---|
| .. | .. |
|---|
| 93 | 87 | } |
|---|
| 94 | 88 | |
|---|
| 95 | 89 | /* |
|---|
| 96 | | - * Must necessary function for devfreq simple-ondemand governor |
|---|
| 90 | + * devfreq function for both simple-ondemand and passive governor |
|---|
| 97 | 91 | */ |
|---|
| 98 | 92 | static int exynos_bus_target(struct device *dev, unsigned long *freq, u32 flags) |
|---|
| 99 | 93 | { |
|---|
| 100 | 94 | struct exynos_bus *bus = dev_get_drvdata(dev); |
|---|
| 101 | 95 | struct dev_pm_opp *new_opp; |
|---|
| 102 | | - unsigned long old_freq, new_freq, new_volt, tol; |
|---|
| 103 | 96 | int ret = 0; |
|---|
| 104 | 97 | |
|---|
| 105 | | - /* Get new opp-bus instance according to new bus clock */ |
|---|
| 98 | + /* Get correct frequency for bus. */ |
|---|
| 106 | 99 | new_opp = devfreq_recommended_opp(dev, freq, flags); |
|---|
| 107 | 100 | if (IS_ERR(new_opp)) { |
|---|
| 108 | 101 | dev_err(dev, "failed to get recommended opp instance\n"); |
|---|
| 109 | 102 | return PTR_ERR(new_opp); |
|---|
| 110 | 103 | } |
|---|
| 111 | 104 | |
|---|
| 112 | | - new_freq = dev_pm_opp_get_freq(new_opp); |
|---|
| 113 | | - new_volt = dev_pm_opp_get_voltage(new_opp); |
|---|
| 114 | 105 | dev_pm_opp_put(new_opp); |
|---|
| 115 | | - |
|---|
| 116 | | - old_freq = bus->curr_freq; |
|---|
| 117 | | - |
|---|
| 118 | | - if (old_freq == new_freq) |
|---|
| 119 | | - return 0; |
|---|
| 120 | | - tol = new_volt * bus->voltage_tolerance / 100; |
|---|
| 121 | 106 | |
|---|
| 122 | 107 | /* Change voltage and frequency according to new OPP level */ |
|---|
| 123 | 108 | mutex_lock(&bus->lock); |
|---|
| 109 | + ret = dev_pm_opp_set_rate(dev, *freq); |
|---|
| 110 | + if (!ret) |
|---|
| 111 | + bus->curr_freq = *freq; |
|---|
| 124 | 112 | |
|---|
| 125 | | - if (old_freq < new_freq) { |
|---|
| 126 | | - ret = regulator_set_voltage_tol(bus->regulator, new_volt, tol); |
|---|
| 127 | | - if (ret < 0) { |
|---|
| 128 | | - dev_err(bus->dev, "failed to set voltage\n"); |
|---|
| 129 | | - goto out; |
|---|
| 130 | | - } |
|---|
| 131 | | - } |
|---|
| 132 | | - |
|---|
| 133 | | - ret = clk_set_rate(bus->clk, new_freq); |
|---|
| 134 | | - if (ret < 0) { |
|---|
| 135 | | - dev_err(dev, "failed to change clock of bus\n"); |
|---|
| 136 | | - clk_set_rate(bus->clk, old_freq); |
|---|
| 137 | | - goto out; |
|---|
| 138 | | - } |
|---|
| 139 | | - |
|---|
| 140 | | - if (old_freq > new_freq) { |
|---|
| 141 | | - ret = regulator_set_voltage_tol(bus->regulator, new_volt, tol); |
|---|
| 142 | | - if (ret < 0) { |
|---|
| 143 | | - dev_err(bus->dev, "failed to set voltage\n"); |
|---|
| 144 | | - goto out; |
|---|
| 145 | | - } |
|---|
| 146 | | - } |
|---|
| 147 | | - bus->curr_freq = new_freq; |
|---|
| 148 | | - |
|---|
| 149 | | - dev_dbg(dev, "Set the frequency of bus (%luHz -> %luHz, %luHz)\n", |
|---|
| 150 | | - old_freq, new_freq, clk_get_rate(bus->clk)); |
|---|
| 151 | | -out: |
|---|
| 152 | 113 | mutex_unlock(&bus->lock); |
|---|
| 153 | 114 | |
|---|
| 154 | 115 | return ret; |
|---|
| .. | .. |
|---|
| 165 | 126 | |
|---|
| 166 | 127 | ret = exynos_bus_get_event(bus, &edata); |
|---|
| 167 | 128 | if (ret < 0) { |
|---|
| 129 | + dev_err(dev, "failed to get event from devfreq-event devices\n"); |
|---|
| 168 | 130 | stat->total_time = stat->busy_time = 0; |
|---|
| 169 | 131 | goto err; |
|---|
| 170 | 132 | } |
|---|
| .. | .. |
|---|
| 196 | 158 | |
|---|
| 197 | 159 | dev_pm_opp_of_remove_table(dev); |
|---|
| 198 | 160 | clk_disable_unprepare(bus->clk); |
|---|
| 199 | | - if (bus->regulator) |
|---|
| 200 | | - regulator_disable(bus->regulator); |
|---|
| 201 | | -} |
|---|
| 202 | | - |
|---|
| 203 | | -/* |
|---|
| 204 | | - * Must necessary function for devfreq passive governor |
|---|
| 205 | | - */ |
|---|
| 206 | | -static int exynos_bus_passive_target(struct device *dev, unsigned long *freq, |
|---|
| 207 | | - u32 flags) |
|---|
| 208 | | -{ |
|---|
| 209 | | - struct exynos_bus *bus = dev_get_drvdata(dev); |
|---|
| 210 | | - struct dev_pm_opp *new_opp; |
|---|
| 211 | | - unsigned long old_freq, new_freq; |
|---|
| 212 | | - int ret = 0; |
|---|
| 213 | | - |
|---|
| 214 | | - /* Get new opp-bus instance according to new bus clock */ |
|---|
| 215 | | - new_opp = devfreq_recommended_opp(dev, freq, flags); |
|---|
| 216 | | - if (IS_ERR(new_opp)) { |
|---|
| 217 | | - dev_err(dev, "failed to get recommended opp instance\n"); |
|---|
| 218 | | - return PTR_ERR(new_opp); |
|---|
| 161 | + if (bus->opp_table) { |
|---|
| 162 | + dev_pm_opp_put_regulators(bus->opp_table); |
|---|
| 163 | + bus->opp_table = NULL; |
|---|
| 219 | 164 | } |
|---|
| 220 | | - |
|---|
| 221 | | - new_freq = dev_pm_opp_get_freq(new_opp); |
|---|
| 222 | | - dev_pm_opp_put(new_opp); |
|---|
| 223 | | - |
|---|
| 224 | | - old_freq = bus->curr_freq; |
|---|
| 225 | | - |
|---|
| 226 | | - if (old_freq == new_freq) |
|---|
| 227 | | - return 0; |
|---|
| 228 | | - |
|---|
| 229 | | - /* Change the frequency according to new OPP level */ |
|---|
| 230 | | - mutex_lock(&bus->lock); |
|---|
| 231 | | - |
|---|
| 232 | | - ret = clk_set_rate(bus->clk, new_freq); |
|---|
| 233 | | - if (ret < 0) { |
|---|
| 234 | | - dev_err(dev, "failed to set the clock of bus\n"); |
|---|
| 235 | | - goto out; |
|---|
| 236 | | - } |
|---|
| 237 | | - |
|---|
| 238 | | - *freq = new_freq; |
|---|
| 239 | | - bus->curr_freq = new_freq; |
|---|
| 240 | | - |
|---|
| 241 | | - dev_dbg(dev, "Set the frequency of bus (%luHz -> %luHz, %luHz)\n", |
|---|
| 242 | | - old_freq, new_freq, clk_get_rate(bus->clk)); |
|---|
| 243 | | -out: |
|---|
| 244 | | - mutex_unlock(&bus->lock); |
|---|
| 245 | | - |
|---|
| 246 | | - return ret; |
|---|
| 247 | 165 | } |
|---|
| 248 | 166 | |
|---|
| 249 | 167 | static void exynos_bus_passive_exit(struct device *dev) |
|---|
| .. | .. |
|---|
| 258 | 176 | struct exynos_bus *bus) |
|---|
| 259 | 177 | { |
|---|
| 260 | 178 | struct device *dev = bus->dev; |
|---|
| 179 | + struct opp_table *opp_table; |
|---|
| 180 | + const char *vdd = "vdd"; |
|---|
| 261 | 181 | int i, ret, count, size; |
|---|
| 262 | 182 | |
|---|
| 263 | | - /* Get the regulator to provide each bus with the power */ |
|---|
| 264 | | - bus->regulator = devm_regulator_get(dev, "vdd"); |
|---|
| 265 | | - if (IS_ERR(bus->regulator)) { |
|---|
| 266 | | - dev_err(dev, "failed to get VDD regulator\n"); |
|---|
| 267 | | - return PTR_ERR(bus->regulator); |
|---|
| 268 | | - } |
|---|
| 269 | | - |
|---|
| 270 | | - ret = regulator_enable(bus->regulator); |
|---|
| 271 | | - if (ret < 0) { |
|---|
| 272 | | - dev_err(dev, "failed to enable VDD regulator\n"); |
|---|
| 183 | + opp_table = dev_pm_opp_set_regulators(dev, &vdd, 1); |
|---|
| 184 | + if (IS_ERR(opp_table)) { |
|---|
| 185 | + ret = PTR_ERR(opp_table); |
|---|
| 186 | + dev_err(dev, "failed to set regulators %d\n", ret); |
|---|
| 273 | 187 | return ret; |
|---|
| 274 | 188 | } |
|---|
| 189 | + |
|---|
| 190 | + bus->opp_table = opp_table; |
|---|
| 275 | 191 | |
|---|
| 276 | 192 | /* |
|---|
| 277 | 193 | * Get the devfreq-event devices to get the current utilization of |
|---|
| 278 | 194 | * buses. This raw data will be used in devfreq ondemand governor. |
|---|
| 279 | 195 | */ |
|---|
| 280 | | - count = devfreq_event_get_edev_count(dev); |
|---|
| 196 | + count = devfreq_event_get_edev_count(dev, "devfreq-events"); |
|---|
| 281 | 197 | if (count < 0) { |
|---|
| 282 | 198 | dev_err(dev, "failed to get the count of devfreq-event dev\n"); |
|---|
| 283 | 199 | ret = count; |
|---|
| .. | .. |
|---|
| 293 | 209 | } |
|---|
| 294 | 210 | |
|---|
| 295 | 211 | for (i = 0; i < count; i++) { |
|---|
| 296 | | - bus->edev[i] = devfreq_event_get_edev_by_phandle(dev, i); |
|---|
| 212 | + bus->edev[i] = devfreq_event_get_edev_by_phandle(dev, |
|---|
| 213 | + "devfreq-events", i); |
|---|
| 297 | 214 | if (IS_ERR(bus->edev[i])) { |
|---|
| 298 | 215 | ret = -EPROBE_DEFER; |
|---|
| 299 | 216 | goto err_regulator; |
|---|
| .. | .. |
|---|
| 313 | 230 | if (of_property_read_u32(np, "exynos,saturation-ratio", &bus->ratio)) |
|---|
| 314 | 231 | bus->ratio = DEFAULT_SATURATION_RATIO; |
|---|
| 315 | 232 | |
|---|
| 316 | | - if (of_property_read_u32(np, "exynos,voltage-tolerance", |
|---|
| 317 | | - &bus->voltage_tolerance)) |
|---|
| 318 | | - bus->voltage_tolerance = DEFAULT_VOLTAGE_TOLERANCE; |
|---|
| 319 | | - |
|---|
| 320 | 233 | return 0; |
|---|
| 321 | 234 | |
|---|
| 322 | 235 | err_regulator: |
|---|
| 323 | | - regulator_disable(bus->regulator); |
|---|
| 236 | + dev_pm_opp_put_regulators(bus->opp_table); |
|---|
| 237 | + bus->opp_table = NULL; |
|---|
| 324 | 238 | |
|---|
| 325 | 239 | return ret; |
|---|
| 326 | 240 | } |
|---|
| .. | .. |
|---|
| 374 | 288 | return ret; |
|---|
| 375 | 289 | } |
|---|
| 376 | 290 | |
|---|
| 291 | +static int exynos_bus_profile_init(struct exynos_bus *bus, |
|---|
| 292 | + struct devfreq_dev_profile *profile) |
|---|
| 293 | +{ |
|---|
| 294 | + struct device *dev = bus->dev; |
|---|
| 295 | + struct devfreq_simple_ondemand_data *ondemand_data; |
|---|
| 296 | + int ret; |
|---|
| 297 | + |
|---|
| 298 | + /* Initialize the struct profile and governor data for parent device */ |
|---|
| 299 | + profile->polling_ms = 50; |
|---|
| 300 | + profile->target = exynos_bus_target; |
|---|
| 301 | + profile->get_dev_status = exynos_bus_get_dev_status; |
|---|
| 302 | + profile->exit = exynos_bus_exit; |
|---|
| 303 | + |
|---|
| 304 | + ondemand_data = devm_kzalloc(dev, sizeof(*ondemand_data), GFP_KERNEL); |
|---|
| 305 | + if (!ondemand_data) |
|---|
| 306 | + return -ENOMEM; |
|---|
| 307 | + |
|---|
| 308 | + ondemand_data->upthreshold = 40; |
|---|
| 309 | + ondemand_data->downdifferential = 5; |
|---|
| 310 | + |
|---|
| 311 | + /* Add devfreq device to monitor and handle the exynos bus */ |
|---|
| 312 | + bus->devfreq = devm_devfreq_add_device(dev, profile, |
|---|
| 313 | + DEVFREQ_GOV_SIMPLE_ONDEMAND, |
|---|
| 314 | + ondemand_data); |
|---|
| 315 | + if (IS_ERR(bus->devfreq)) { |
|---|
| 316 | + dev_err(dev, "failed to add devfreq device\n"); |
|---|
| 317 | + return PTR_ERR(bus->devfreq); |
|---|
| 318 | + } |
|---|
| 319 | + |
|---|
| 320 | + /* Register opp_notifier to catch the change of OPP */ |
|---|
| 321 | + ret = devm_devfreq_register_opp_notifier(dev, bus->devfreq); |
|---|
| 322 | + if (ret < 0) { |
|---|
| 323 | + dev_err(dev, "failed to register opp notifier\n"); |
|---|
| 324 | + return ret; |
|---|
| 325 | + } |
|---|
| 326 | + |
|---|
| 327 | + /* |
|---|
| 328 | + * Enable devfreq-event to get raw data which is used to determine |
|---|
| 329 | + * current bus load. |
|---|
| 330 | + */ |
|---|
| 331 | + ret = exynos_bus_enable_edev(bus); |
|---|
| 332 | + if (ret < 0) { |
|---|
| 333 | + dev_err(dev, "failed to enable devfreq-event devices\n"); |
|---|
| 334 | + return ret; |
|---|
| 335 | + } |
|---|
| 336 | + |
|---|
| 337 | + ret = exynos_bus_set_event(bus); |
|---|
| 338 | + if (ret < 0) { |
|---|
| 339 | + dev_err(dev, "failed to set event to devfreq-event devices\n"); |
|---|
| 340 | + goto err_edev; |
|---|
| 341 | + } |
|---|
| 342 | + |
|---|
| 343 | + return 0; |
|---|
| 344 | + |
|---|
| 345 | +err_edev: |
|---|
| 346 | + if (exynos_bus_disable_edev(bus)) |
|---|
| 347 | + dev_warn(dev, "failed to disable the devfreq-event devices\n"); |
|---|
| 348 | + |
|---|
| 349 | + return ret; |
|---|
| 350 | +} |
|---|
| 351 | + |
|---|
| 352 | +static int exynos_bus_profile_init_passive(struct exynos_bus *bus, |
|---|
| 353 | + struct devfreq_dev_profile *profile) |
|---|
| 354 | +{ |
|---|
| 355 | + struct device *dev = bus->dev; |
|---|
| 356 | + struct devfreq_passive_data *passive_data; |
|---|
| 357 | + struct devfreq *parent_devfreq; |
|---|
| 358 | + |
|---|
| 359 | + /* Initialize the struct profile and governor data for passive device */ |
|---|
| 360 | + profile->target = exynos_bus_target; |
|---|
| 361 | + profile->exit = exynos_bus_passive_exit; |
|---|
| 362 | + |
|---|
| 363 | + /* Get the instance of parent devfreq device */ |
|---|
| 364 | + parent_devfreq = devfreq_get_devfreq_by_phandle(dev, "devfreq", 0); |
|---|
| 365 | + if (IS_ERR(parent_devfreq)) |
|---|
| 366 | + return -EPROBE_DEFER; |
|---|
| 367 | + |
|---|
| 368 | + passive_data = devm_kzalloc(dev, sizeof(*passive_data), GFP_KERNEL); |
|---|
| 369 | + if (!passive_data) |
|---|
| 370 | + return -ENOMEM; |
|---|
| 371 | + |
|---|
| 372 | + passive_data->parent = parent_devfreq; |
|---|
| 373 | + |
|---|
| 374 | + /* Add devfreq device for exynos bus with passive governor */ |
|---|
| 375 | + bus->devfreq = devm_devfreq_add_device(dev, profile, DEVFREQ_GOV_PASSIVE, |
|---|
| 376 | + passive_data); |
|---|
| 377 | + if (IS_ERR(bus->devfreq)) { |
|---|
| 378 | + dev_err(dev, |
|---|
| 379 | + "failed to add devfreq dev with passive governor\n"); |
|---|
| 380 | + return PTR_ERR(bus->devfreq); |
|---|
| 381 | + } |
|---|
| 382 | + |
|---|
| 383 | + return 0; |
|---|
| 384 | +} |
|---|
| 385 | + |
|---|
| 377 | 386 | static int exynos_bus_probe(struct platform_device *pdev) |
|---|
| 378 | 387 | { |
|---|
| 379 | 388 | struct device *dev = &pdev->dev; |
|---|
| 380 | 389 | struct device_node *np = dev->of_node, *node; |
|---|
| 381 | 390 | struct devfreq_dev_profile *profile; |
|---|
| 382 | | - struct devfreq_simple_ondemand_data *ondemand_data; |
|---|
| 383 | | - struct devfreq_passive_data *passive_data; |
|---|
| 384 | | - struct devfreq *parent_devfreq; |
|---|
| 385 | 391 | struct exynos_bus *bus; |
|---|
| 386 | 392 | int ret, max_state; |
|---|
| 387 | 393 | unsigned long min_freq, max_freq; |
|---|
| .. | .. |
|---|
| 419 | 425 | goto err_reg; |
|---|
| 420 | 426 | |
|---|
| 421 | 427 | if (passive) |
|---|
| 422 | | - goto passive; |
|---|
| 428 | + ret = exynos_bus_profile_init_passive(bus, profile); |
|---|
| 429 | + else |
|---|
| 430 | + ret = exynos_bus_profile_init(bus, profile); |
|---|
| 423 | 431 | |
|---|
| 424 | | - /* Initialize the struct profile and governor data for parent device */ |
|---|
| 425 | | - profile->polling_ms = 50; |
|---|
| 426 | | - profile->target = exynos_bus_target; |
|---|
| 427 | | - profile->get_dev_status = exynos_bus_get_dev_status; |
|---|
| 428 | | - profile->exit = exynos_bus_exit; |
|---|
| 429 | | - |
|---|
| 430 | | - ondemand_data = devm_kzalloc(dev, sizeof(*ondemand_data), GFP_KERNEL); |
|---|
| 431 | | - if (!ondemand_data) { |
|---|
| 432 | | - ret = -ENOMEM; |
|---|
| 432 | + if (ret < 0) |
|---|
| 433 | 433 | goto err; |
|---|
| 434 | | - } |
|---|
| 435 | | - ondemand_data->upthreshold = 40; |
|---|
| 436 | | - ondemand_data->downdifferential = 5; |
|---|
| 437 | 434 | |
|---|
| 438 | | - /* Add devfreq device to monitor and handle the exynos bus */ |
|---|
| 439 | | - bus->devfreq = devm_devfreq_add_device(dev, profile, |
|---|
| 440 | | - DEVFREQ_GOV_SIMPLE_ONDEMAND, |
|---|
| 441 | | - ondemand_data); |
|---|
| 442 | | - if (IS_ERR(bus->devfreq)) { |
|---|
| 443 | | - dev_err(dev, "failed to add devfreq device\n"); |
|---|
| 444 | | - ret = PTR_ERR(bus->devfreq); |
|---|
| 445 | | - goto err; |
|---|
| 446 | | - } |
|---|
| 447 | | - |
|---|
| 448 | | - /* Register opp_notifier to catch the change of OPP */ |
|---|
| 449 | | - ret = devm_devfreq_register_opp_notifier(dev, bus->devfreq); |
|---|
| 450 | | - if (ret < 0) { |
|---|
| 451 | | - dev_err(dev, "failed to register opp notifier\n"); |
|---|
| 452 | | - goto err; |
|---|
| 453 | | - } |
|---|
| 454 | | - |
|---|
| 455 | | - /* |
|---|
| 456 | | - * Enable devfreq-event to get raw data which is used to determine |
|---|
| 457 | | - * current bus load. |
|---|
| 458 | | - */ |
|---|
| 459 | | - ret = exynos_bus_enable_edev(bus); |
|---|
| 460 | | - if (ret < 0) { |
|---|
| 461 | | - dev_err(dev, "failed to enable devfreq-event devices\n"); |
|---|
| 462 | | - goto err; |
|---|
| 463 | | - } |
|---|
| 464 | | - |
|---|
| 465 | | - ret = exynos_bus_set_event(bus); |
|---|
| 466 | | - if (ret < 0) { |
|---|
| 467 | | - dev_err(dev, "failed to set event to devfreq-event devices\n"); |
|---|
| 468 | | - goto err; |
|---|
| 469 | | - } |
|---|
| 470 | | - |
|---|
| 471 | | - goto out; |
|---|
| 472 | | -passive: |
|---|
| 473 | | - /* Initialize the struct profile and governor data for passive device */ |
|---|
| 474 | | - profile->target = exynos_bus_passive_target; |
|---|
| 475 | | - profile->exit = exynos_bus_passive_exit; |
|---|
| 476 | | - |
|---|
| 477 | | - /* Get the instance of parent devfreq device */ |
|---|
| 478 | | - parent_devfreq = devfreq_get_devfreq_by_phandle(dev, 0); |
|---|
| 479 | | - if (IS_ERR(parent_devfreq)) { |
|---|
| 480 | | - ret = -EPROBE_DEFER; |
|---|
| 481 | | - goto err; |
|---|
| 482 | | - } |
|---|
| 483 | | - |
|---|
| 484 | | - passive_data = devm_kzalloc(dev, sizeof(*passive_data), GFP_KERNEL); |
|---|
| 485 | | - if (!passive_data) { |
|---|
| 486 | | - ret = -ENOMEM; |
|---|
| 487 | | - goto err; |
|---|
| 488 | | - } |
|---|
| 489 | | - passive_data->parent = parent_devfreq; |
|---|
| 490 | | - |
|---|
| 491 | | - /* Add devfreq device for exynos bus with passive governor */ |
|---|
| 492 | | - bus->devfreq = devm_devfreq_add_device(dev, profile, DEVFREQ_GOV_PASSIVE, |
|---|
| 493 | | - passive_data); |
|---|
| 494 | | - if (IS_ERR(bus->devfreq)) { |
|---|
| 495 | | - dev_err(dev, |
|---|
| 496 | | - "failed to add devfreq dev with passive governor\n"); |
|---|
| 497 | | - ret = PTR_ERR(bus->devfreq); |
|---|
| 498 | | - goto err; |
|---|
| 499 | | - } |
|---|
| 500 | | - |
|---|
| 501 | | -out: |
|---|
| 502 | 435 | max_state = bus->devfreq->profile->max_state; |
|---|
| 503 | 436 | min_freq = (bus->devfreq->profile->freq_table[0] / 1000); |
|---|
| 504 | 437 | max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000); |
|---|
| .. | .. |
|---|
| 511 | 444 | dev_pm_opp_of_remove_table(dev); |
|---|
| 512 | 445 | clk_disable_unprepare(bus->clk); |
|---|
| 513 | 446 | err_reg: |
|---|
| 514 | | - if (!passive) |
|---|
| 515 | | - regulator_disable(bus->regulator); |
|---|
| 447 | + if (!passive) { |
|---|
| 448 | + dev_pm_opp_put_regulators(bus->opp_table); |
|---|
| 449 | + bus->opp_table = NULL; |
|---|
| 450 | + } |
|---|
| 516 | 451 | |
|---|
| 517 | 452 | return ret; |
|---|
| 453 | +} |
|---|
| 454 | + |
|---|
| 455 | +static void exynos_bus_shutdown(struct platform_device *pdev) |
|---|
| 456 | +{ |
|---|
| 457 | + struct exynos_bus *bus = dev_get_drvdata(&pdev->dev); |
|---|
| 458 | + |
|---|
| 459 | + devfreq_suspend_device(bus->devfreq); |
|---|
| 518 | 460 | } |
|---|
| 519 | 461 | |
|---|
| 520 | 462 | #ifdef CONFIG_PM_SLEEP |
|---|
| .. | .. |
|---|
| 559 | 501 | |
|---|
| 560 | 502 | static struct platform_driver exynos_bus_platdrv = { |
|---|
| 561 | 503 | .probe = exynos_bus_probe, |
|---|
| 504 | + .shutdown = exynos_bus_shutdown, |
|---|
| 562 | 505 | .driver = { |
|---|
| 563 | 506 | .name = "exynos-bus", |
|---|
| 564 | 507 | .pm = &exynos_bus_pm, |
|---|