| |
| |
| |
| |
| |
| |
| #include <linux/refcount.h> |
| #include <linux/mutex.h> |
| #include <linux/clk.h> |
| #include <linux/device.h> |
| #include <linux/interconnect.h> |
| |
| #include "ipa.h" |
| #include "ipa_clock.h" |
| #include "ipa_modem.h" |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define IPA_CORE_CLOCK_RATE (75UL * 1000 * 1000) |
| |
| |
| #define IPA_MEMORY_AVG (80 * 1000) |
| #define IPA_MEMORY_PEAK (600 * 1000) |
| |
| #define IPA_IMEM_AVG (80 * 1000) |
| #define IPA_IMEM_PEAK (350 * 1000) |
| |
| #define IPA_CONFIG_AVG (40 * 1000) |
| #define IPA_CONFIG_PEAK (40 * 1000) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| struct ipa_clock { |
| <------>refcount_t count; |
| <------>struct mutex mutex; |
| <------>struct clk *core; |
| <------>struct icc_path *memory_path; |
| <------>struct icc_path *imem_path; |
| <------>struct icc_path *config_path; |
| }; |
| |
| static struct icc_path * |
| ipa_interconnect_init_one(struct device *dev, const char *name) |
| { |
| <------>struct icc_path *path; |
| |
| <------>path = of_icc_get(dev, name); |
| <------>if (IS_ERR(path)) |
| <------><------>dev_err(dev, "error %ld getting %s interconnect\n", |
| <------><------><------>PTR_ERR(path), name); |
| |
| <------>return path; |
| } |
| |
| |
| static int ipa_interconnect_init(struct ipa_clock *clock, struct device *dev) |
| { |
| <------>struct icc_path *path; |
| |
| <------>path = ipa_interconnect_init_one(dev, "memory"); |
| <------>if (IS_ERR(path)) |
| <------><------>goto err_return; |
| <------>clock->memory_path = path; |
| |
| <------>path = ipa_interconnect_init_one(dev, "imem"); |
| <------>if (IS_ERR(path)) |
| <------><------>goto err_memory_path_put; |
| <------>clock->imem_path = path; |
| |
| <------>path = ipa_interconnect_init_one(dev, "config"); |
| <------>if (IS_ERR(path)) |
| <------><------>goto err_imem_path_put; |
| <------>clock->config_path = path; |
| |
| <------>return 0; |
| |
| err_imem_path_put: |
| <------>icc_put(clock->imem_path); |
| err_memory_path_put: |
| <------>icc_put(clock->memory_path); |
| err_return: |
| <------>return PTR_ERR(path); |
| } |
| |
| |
| static void ipa_interconnect_exit(struct ipa_clock *clock) |
| { |
| <------>icc_put(clock->config_path); |
| <------>icc_put(clock->imem_path); |
| <------>icc_put(clock->memory_path); |
| } |
| |
| |
| static int ipa_interconnect_enable(struct ipa *ipa) |
| { |
| <------>struct ipa_clock *clock = ipa->clock; |
| <------>int ret; |
| |
| <------>ret = icc_set_bw(clock->memory_path, IPA_MEMORY_AVG, IPA_MEMORY_PEAK); |
| <------>if (ret) |
| <------><------>return ret; |
| |
| <------>ret = icc_set_bw(clock->imem_path, IPA_IMEM_AVG, IPA_IMEM_PEAK); |
| <------>if (ret) |
| <------><------>goto err_memory_path_disable; |
| |
| <------>ret = icc_set_bw(clock->config_path, IPA_CONFIG_AVG, IPA_CONFIG_PEAK); |
| <------>if (ret) |
| <------><------>goto err_imem_path_disable; |
| |
| <------>return 0; |
| |
| err_imem_path_disable: |
| <------>(void)icc_set_bw(clock->imem_path, 0, 0); |
| err_memory_path_disable: |
| <------>(void)icc_set_bw(clock->memory_path, 0, 0); |
| |
| <------>return ret; |
| } |
| |
| |
| static int ipa_interconnect_disable(struct ipa *ipa) |
| { |
| <------>struct ipa_clock *clock = ipa->clock; |
| <------>int ret; |
| |
| <------>ret = icc_set_bw(clock->memory_path, 0, 0); |
| <------>if (ret) |
| <------><------>return ret; |
| |
| <------>ret = icc_set_bw(clock->imem_path, 0, 0); |
| <------>if (ret) |
| <------><------>goto err_memory_path_reenable; |
| |
| <------>ret = icc_set_bw(clock->config_path, 0, 0); |
| <------>if (ret) |
| <------><------>goto err_imem_path_reenable; |
| |
| <------>return 0; |
| |
| err_imem_path_reenable: |
| <------>(void)icc_set_bw(clock->imem_path, IPA_IMEM_AVG, IPA_IMEM_PEAK); |
| err_memory_path_reenable: |
| <------>(void)icc_set_bw(clock->memory_path, IPA_MEMORY_AVG, IPA_MEMORY_PEAK); |
| |
| <------>return ret; |
| } |
| |
| |
| static int ipa_clock_enable(struct ipa *ipa) |
| { |
| <------>int ret; |
| |
| <------>ret = ipa_interconnect_enable(ipa); |
| <------>if (ret) |
| <------><------>return ret; |
| |
| <------>ret = clk_prepare_enable(ipa->clock->core); |
| <------>if (ret) |
| <------><------>ipa_interconnect_disable(ipa); |
| |
| <------>return ret; |
| } |
| |
| |
| static void ipa_clock_disable(struct ipa *ipa) |
| { |
| <------>clk_disable_unprepare(ipa->clock->core); |
| <------>(void)ipa_interconnect_disable(ipa); |
| } |
| |
| |
| |
| |
| |
| bool ipa_clock_get_additional(struct ipa *ipa) |
| { |
| <------>return refcount_inc_not_zero(&ipa->clock->count); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void ipa_clock_get(struct ipa *ipa) |
| { |
| <------>struct ipa_clock *clock = ipa->clock; |
| <------>int ret; |
| |
| <------> |
| <------>if (ipa_clock_get_additional(ipa)) |
| <------><------>return; |
| |
| <------> |
| <------>mutex_lock(&clock->mutex); |
| |
| <------> |
| <------>if (ipa_clock_get_additional(ipa)) |
| <------><------>goto out_mutex_unlock; |
| |
| <------>ret = ipa_clock_enable(ipa); |
| <------>if (ret) { |
| <------><------>dev_err(&ipa->pdev->dev, "error %d enabling IPA clock\n", ret); |
| <------><------>goto out_mutex_unlock; |
| <------>} |
| |
| <------>refcount_set(&clock->count, 1); |
| |
| out_mutex_unlock: |
| <------>mutex_unlock(&clock->mutex); |
| } |
| |
| |
| |
| |
| void ipa_clock_put(struct ipa *ipa) |
| { |
| <------>struct ipa_clock *clock = ipa->clock; |
| |
| <------> |
| <------>if (!refcount_dec_and_mutex_lock(&clock->count, &clock->mutex)) |
| <------><------>return; |
| |
| <------>ipa_clock_disable(ipa); |
| |
| <------>mutex_unlock(&clock->mutex); |
| } |
| |
| |
| u32 ipa_clock_rate(struct ipa *ipa) |
| { |
| <------>return ipa->clock ? (u32)clk_get_rate(ipa->clock->core) : 0; |
| } |
| |
| |
| struct ipa_clock *ipa_clock_init(struct device *dev) |
| { |
| <------>struct ipa_clock *clock; |
| <------>struct clk *clk; |
| <------>int ret; |
| |
| <------>clk = clk_get(dev, "core"); |
| <------>if (IS_ERR(clk)) { |
| <------><------>dev_err(dev, "error %ld getting core clock\n", PTR_ERR(clk)); |
| <------><------>return ERR_CAST(clk); |
| <------>} |
| |
| <------>ret = clk_set_rate(clk, IPA_CORE_CLOCK_RATE); |
| <------>if (ret) { |
| <------><------>dev_err(dev, "error %d setting core clock rate to %lu\n", |
| <------><------><------>ret, IPA_CORE_CLOCK_RATE); |
| <------><------>goto err_clk_put; |
| <------>} |
| |
| <------>clock = kzalloc(sizeof(*clock), GFP_KERNEL); |
| <------>if (!clock) { |
| <------><------>ret = -ENOMEM; |
| <------><------>goto err_clk_put; |
| <------>} |
| <------>clock->core = clk; |
| |
| <------>ret = ipa_interconnect_init(clock, dev); |
| <------>if (ret) |
| <------><------>goto err_kfree; |
| |
| <------>mutex_init(&clock->mutex); |
| <------>refcount_set(&clock->count, 0); |
| |
| <------>return clock; |
| |
| err_kfree: |
| <------>kfree(clock); |
| err_clk_put: |
| <------>clk_put(clk); |
| |
| <------>return ERR_PTR(ret); |
| } |
| |
| |
| void ipa_clock_exit(struct ipa_clock *clock) |
| { |
| <------>struct clk *clk = clock->core; |
| |
| <------>WARN_ON(refcount_read(&clock->count) != 0); |
| <------>mutex_destroy(&clock->mutex); |
| <------>ipa_interconnect_exit(clock); |
| <------>kfree(clock); |
| <------>clk_put(clk); |
| } |
| |