012-1-clk-qcom-Add-support-for-SMD-RPM-Clocks.patch 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. From patchwork Wed Nov 2 15:56:56 2016
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. Subject: [v9,1/3] clk: qcom: Add support for SMD-RPM Clocks
  6. From: Georgi Djakov <georgi.djakov@linaro.org>
  7. X-Patchwork-Id: 9409419
  8. Message-Id: <20161102155658.32203-2-georgi.djakov@linaro.org>
  9. To: sboyd@codeaurora.org, mturquette@baylibre.com
  10. Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
  11. robh+dt@kernel.org, mark.rutland@arm.com,
  12. linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
  13. georgi.djakov@linaro.org
  14. Date: Wed, 2 Nov 2016 17:56:56 +0200
  15. This adds initial support for clocks controlled by the Resource
  16. Power Manager (RPM) processor on some Qualcomm SoCs, which use
  17. the qcom_smd_rpm driver to communicate with RPM.
  18. Such platforms are msm8916, apq8084 and msm8974.
  19. The RPM is a dedicated hardware engine for managing the shared
  20. SoC resources in order to keep the lowest power profile. It
  21. communicates with other hardware subsystems via shared memory
  22. and accepts clock requests, aggregates the requests and turns
  23. the clocks on/off or scales them on demand.
  24. This driver is based on the codeaurora.org driver:
  25. https://www.codeaurora.org/cgit/quic/la/kernel/msm-3.10/tree/drivers/clk/qcom/clock-rpm.c
  26. Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
  27. ---
  28. .../devicetree/bindings/clock/qcom,rpmcc.txt | 36 ++
  29. drivers/clk/qcom/Kconfig | 16 +
  30. drivers/clk/qcom/Makefile | 1 +
  31. drivers/clk/qcom/clk-smd-rpm.c | 571 +++++++++++++++++++++
  32. include/dt-bindings/clock/qcom,rpmcc.h | 45 ++
  33. 5 files changed, 669 insertions(+)
  34. create mode 100644 Documentation/devicetree/bindings/clock/qcom,rpmcc.txt
  35. create mode 100644 drivers/clk/qcom/clk-smd-rpm.c
  36. create mode 100644 include/dt-bindings/clock/qcom,rpmcc.h
  37. --
  38. To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
  39. the body of a message to majordomo@vger.kernel.org
  40. More majordomo info at http://vger.kernel.org/majordomo-info.html
  41. --- /dev/null
  42. +++ b/Documentation/devicetree/bindings/clock/qcom,rpmcc.txt
  43. @@ -0,0 +1,36 @@
  44. +Qualcomm RPM Clock Controller Binding
  45. +------------------------------------------------
  46. +The RPM is a dedicated hardware engine for managing the shared
  47. +SoC resources in order to keep the lowest power profile. It
  48. +communicates with other hardware subsystems via shared memory
  49. +and accepts clock requests, aggregates the requests and turns
  50. +the clocks on/off or scales them on demand.
  51. +
  52. +Required properties :
  53. +- compatible : shall contain only one of the following. The generic
  54. + compatible "qcom,rpmcc" should be also included.
  55. +
  56. + "qcom,rpmcc-msm8916", "qcom,rpmcc"
  57. +
  58. +- #clock-cells : shall contain 1
  59. +
  60. +Example:
  61. + smd {
  62. + compatible = "qcom,smd";
  63. +
  64. + rpm {
  65. + interrupts = <0 168 1>;
  66. + qcom,ipc = <&apcs 8 0>;
  67. + qcom,smd-edge = <15>;
  68. +
  69. + rpm_requests {
  70. + compatible = "qcom,rpm-msm8916";
  71. + qcom,smd-channels = "rpm_requests";
  72. +
  73. + rpmcc: clock-controller {
  74. + compatible = "qcom,rpmcc-msm8916", "qcom,rpmcc";
  75. + #clock-cells = <1>;
  76. + };
  77. + };
  78. + };
  79. + };
  80. --- a/drivers/clk/qcom/Kconfig
  81. +++ b/drivers/clk/qcom/Kconfig
  82. @@ -2,6 +2,9 @@ config QCOM_GDSC
  83. bool
  84. select PM_GENERIC_DOMAINS if PM
  85. +config QCOM_RPMCC
  86. + bool
  87. +
  88. config COMMON_CLK_QCOM
  89. tristate "Support for Qualcomm's clock controllers"
  90. depends on OF
  91. @@ -9,6 +12,19 @@ config COMMON_CLK_QCOM
  92. select REGMAP_MMIO
  93. select RESET_CONTROLLER
  94. +config QCOM_CLK_SMD_RPM
  95. + tristate "RPM over SMD based Clock Controller"
  96. + depends on COMMON_CLK_QCOM && QCOM_SMD_RPM
  97. + select QCOM_RPMCC
  98. + help
  99. + The RPM (Resource Power Manager) is a dedicated hardware engine for
  100. + managing the shared SoC resources in order to keep the lowest power
  101. + profile. It communicates with other hardware subsystems via shared
  102. + memory and accepts clock requests, aggregates the requests and turns
  103. + the clocks on/off or scales them on demand.
  104. + Say Y if you want to support the clocks exposed by the RPM on
  105. + platforms such as apq8016, apq8084, msm8974 etc.
  106. +
  107. config APQ_GCC_8084
  108. tristate "APQ8084 Global Clock Controller"
  109. select QCOM_GDSC
  110. --- a/drivers/clk/qcom/Makefile
  111. +++ b/drivers/clk/qcom/Makefile
  112. @@ -22,3 +22,4 @@ obj-$(CONFIG_MSM_LCC_8960) += lcc-msm896
  113. obj-$(CONFIG_MSM_GCC_8974) += gcc-msm8974.o
  114. obj-$(CONFIG_MSM_MMCC_8960) += mmcc-msm8960.o
  115. obj-$(CONFIG_MSM_MMCC_8974) += mmcc-msm8974.o
  116. +obj-$(CONFIG_QCOM_CLK_SMD_RPM) += clk-smd-rpm.o
  117. --- /dev/null
  118. +++ b/drivers/clk/qcom/clk-smd-rpm.c
  119. @@ -0,0 +1,571 @@
  120. +/*
  121. + * Copyright (c) 2016, Linaro Limited
  122. + * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  123. + *
  124. + * This software is licensed under the terms of the GNU General Public
  125. + * License version 2, as published by the Free Software Foundation, and
  126. + * may be copied, distributed, and modified under those terms.
  127. + *
  128. + * This program is distributed in the hope that it will be useful,
  129. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  130. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  131. + * GNU General Public License for more details.
  132. + */
  133. +
  134. +#include <linux/clk-provider.h>
  135. +#include <linux/err.h>
  136. +#include <linux/export.h>
  137. +#include <linux/init.h>
  138. +#include <linux/kernel.h>
  139. +#include <linux/module.h>
  140. +#include <linux/mutex.h>
  141. +#include <linux/of.h>
  142. +#include <linux/of_device.h>
  143. +#include <linux/platform_device.h>
  144. +#include <linux/soc/qcom/smd-rpm.h>
  145. +
  146. +#include <dt-bindings/clock/qcom,rpmcc.h>
  147. +#include <dt-bindings/mfd/qcom-rpm.h>
  148. +
  149. +#define QCOM_RPM_KEY_SOFTWARE_ENABLE 0x6e657773
  150. +#define QCOM_RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY 0x62636370
  151. +#define QCOM_RPM_SMD_KEY_RATE 0x007a484b
  152. +#define QCOM_RPM_SMD_KEY_ENABLE 0x62616e45
  153. +#define QCOM_RPM_SMD_KEY_STATE 0x54415453
  154. +#define QCOM_RPM_SCALING_ENABLE_ID 0x2
  155. +
  156. +#define __DEFINE_CLK_SMD_RPM(_platform, _name, _active, type, r_id, stat_id, \
  157. + key) \
  158. + static struct clk_smd_rpm _platform##_##_active; \
  159. + static struct clk_smd_rpm _platform##_##_name = { \
  160. + .rpm_res_type = (type), \
  161. + .rpm_clk_id = (r_id), \
  162. + .rpm_status_id = (stat_id), \
  163. + .rpm_key = (key), \
  164. + .peer = &_platform##_##_active, \
  165. + .rate = INT_MAX, \
  166. + .hw.init = &(struct clk_init_data){ \
  167. + .ops = &clk_smd_rpm_ops, \
  168. + .name = #_name, \
  169. + .parent_names = (const char *[]){ "xo_board" }, \
  170. + .num_parents = 1, \
  171. + }, \
  172. + }; \
  173. + static struct clk_smd_rpm _platform##_##_active = { \
  174. + .rpm_res_type = (type), \
  175. + .rpm_clk_id = (r_id), \
  176. + .rpm_status_id = (stat_id), \
  177. + .active_only = true, \
  178. + .rpm_key = (key), \
  179. + .peer = &_platform##_##_name, \
  180. + .rate = INT_MAX, \
  181. + .hw.init = &(struct clk_init_data){ \
  182. + .ops = &clk_smd_rpm_ops, \
  183. + .name = #_active, \
  184. + .parent_names = (const char *[]){ "xo_board" }, \
  185. + .num_parents = 1, \
  186. + }, \
  187. + }
  188. +
  189. +#define __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, r_id, \
  190. + stat_id, r, key) \
  191. + static struct clk_smd_rpm _platform##_##_active; \
  192. + static struct clk_smd_rpm _platform##_##_name = { \
  193. + .rpm_res_type = (type), \
  194. + .rpm_clk_id = (r_id), \
  195. + .rpm_status_id = (stat_id), \
  196. + .rpm_key = (key), \
  197. + .branch = true, \
  198. + .peer = &_platform##_##_active, \
  199. + .rate = (r), \
  200. + .hw.init = &(struct clk_init_data){ \
  201. + .ops = &clk_smd_rpm_branch_ops, \
  202. + .name = #_name, \
  203. + .parent_names = (const char *[]){ "xo_board" }, \
  204. + .num_parents = 1, \
  205. + }, \
  206. + }; \
  207. + static struct clk_smd_rpm _platform##_##_active = { \
  208. + .rpm_res_type = (type), \
  209. + .rpm_clk_id = (r_id), \
  210. + .rpm_status_id = (stat_id), \
  211. + .active_only = true, \
  212. + .rpm_key = (key), \
  213. + .branch = true, \
  214. + .peer = &_platform##_##_name, \
  215. + .rate = (r), \
  216. + .hw.init = &(struct clk_init_data){ \
  217. + .ops = &clk_smd_rpm_branch_ops, \
  218. + .name = #_active, \
  219. + .parent_names = (const char *[]){ "xo_board" }, \
  220. + .num_parents = 1, \
  221. + }, \
  222. + }
  223. +
  224. +#define DEFINE_CLK_SMD_RPM(_platform, _name, _active, type, r_id) \
  225. + __DEFINE_CLK_SMD_RPM(_platform, _name, _active, type, r_id, \
  226. + 0, QCOM_RPM_SMD_KEY_RATE)
  227. +
  228. +#define DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, r_id, r) \
  229. + __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, type, \
  230. + r_id, 0, r, QCOM_RPM_SMD_KEY_ENABLE)
  231. +
  232. +#define DEFINE_CLK_SMD_RPM_QDSS(_platform, _name, _active, type, r_id) \
  233. + __DEFINE_CLK_SMD_RPM(_platform, _name, _active, type, r_id, \
  234. + 0, QCOM_RPM_SMD_KEY_STATE)
  235. +
  236. +#define DEFINE_CLK_SMD_RPM_XO_BUFFER(_platform, _name, _active, r_id) \
  237. + __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, \
  238. + QCOM_SMD_RPM_CLK_BUF_A, r_id, 0, 1000, \
  239. + QCOM_RPM_KEY_SOFTWARE_ENABLE)
  240. +
  241. +#define DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(_platform, _name, _active, r_id) \
  242. + __DEFINE_CLK_SMD_RPM_BRANCH(_platform, _name, _active, \
  243. + QCOM_SMD_RPM_CLK_BUF_A, r_id, 0, 1000, \
  244. + QCOM_RPM_KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY)
  245. +
  246. +#define to_clk_smd_rpm(_hw) container_of(_hw, struct clk_smd_rpm, hw)
  247. +
  248. +struct clk_smd_rpm {
  249. + const int rpm_res_type;
  250. + const int rpm_key;
  251. + const int rpm_clk_id;
  252. + const int rpm_status_id;
  253. + const bool active_only;
  254. + bool enabled;
  255. + bool branch;
  256. + struct clk_smd_rpm *peer;
  257. + struct clk_hw hw;
  258. + unsigned long rate;
  259. + struct qcom_smd_rpm *rpm;
  260. +};
  261. +
  262. +struct clk_smd_rpm_req {
  263. + __le32 key;
  264. + __le32 nbytes;
  265. + __le32 value;
  266. +};
  267. +
  268. +struct rpm_cc {
  269. + struct qcom_rpm *rpm;
  270. + struct clk_hw_onecell_data data;
  271. + struct clk_hw *hws[];
  272. +};
  273. +
  274. +struct rpm_smd_clk_desc {
  275. + struct clk_smd_rpm **clks;
  276. + size_t num_clks;
  277. +};
  278. +
  279. +static DEFINE_MUTEX(rpm_smd_clk_lock);
  280. +
  281. +static int clk_smd_rpm_handoff(struct clk_smd_rpm *r)
  282. +{
  283. + int ret;
  284. + struct clk_smd_rpm_req req = {
  285. + .key = cpu_to_le32(r->rpm_key),
  286. + .nbytes = cpu_to_le32(sizeof(u32)),
  287. + .value = cpu_to_le32(INT_MAX),
  288. + };
  289. +
  290. + ret = qcom_rpm_smd_write(r->rpm, QCOM_SMD_RPM_ACTIVE_STATE,
  291. + r->rpm_res_type, r->rpm_clk_id, &req,
  292. + sizeof(req));
  293. + if (ret)
  294. + return ret;
  295. + ret = qcom_rpm_smd_write(r->rpm, QCOM_SMD_RPM_SLEEP_STATE,
  296. + r->rpm_res_type, r->rpm_clk_id, &req,
  297. + sizeof(req));
  298. + if (ret)
  299. + return ret;
  300. +
  301. + return 0;
  302. +}
  303. +
  304. +static int clk_smd_rpm_set_rate_active(struct clk_smd_rpm *r,
  305. + unsigned long rate)
  306. +{
  307. + struct clk_smd_rpm_req req = {
  308. + .key = cpu_to_le32(r->rpm_key),
  309. + .nbytes = cpu_to_le32(sizeof(u32)),
  310. + .value = cpu_to_le32(DIV_ROUND_UP(rate, 1000)), /* to kHz */
  311. + };
  312. +
  313. + return qcom_rpm_smd_write(r->rpm, QCOM_SMD_RPM_ACTIVE_STATE,
  314. + r->rpm_res_type, r->rpm_clk_id, &req,
  315. + sizeof(req));
  316. +}
  317. +
  318. +static int clk_smd_rpm_set_rate_sleep(struct clk_smd_rpm *r,
  319. + unsigned long rate)
  320. +{
  321. + struct clk_smd_rpm_req req = {
  322. + .key = cpu_to_le32(r->rpm_key),
  323. + .nbytes = cpu_to_le32(sizeof(u32)),
  324. + .value = cpu_to_le32(DIV_ROUND_UP(rate, 1000)), /* to kHz */
  325. + };
  326. +
  327. + return qcom_rpm_smd_write(r->rpm, QCOM_SMD_RPM_SLEEP_STATE,
  328. + r->rpm_res_type, r->rpm_clk_id, &req,
  329. + sizeof(req));
  330. +}
  331. +
  332. +static void to_active_sleep(struct clk_smd_rpm *r, unsigned long rate,
  333. + unsigned long *active, unsigned long *sleep)
  334. +{
  335. + *active = rate;
  336. +
  337. + /*
  338. + * Active-only clocks don't care what the rate is during sleep. So,
  339. + * they vote for zero.
  340. + */
  341. + if (r->active_only)
  342. + *sleep = 0;
  343. + else
  344. + *sleep = *active;
  345. +}
  346. +
  347. +static int clk_smd_rpm_prepare(struct clk_hw *hw)
  348. +{
  349. + struct clk_smd_rpm *r = to_clk_smd_rpm(hw);
  350. + struct clk_smd_rpm *peer = r->peer;
  351. + unsigned long this_rate = 0, this_sleep_rate = 0;
  352. + unsigned long peer_rate = 0, peer_sleep_rate = 0;
  353. + unsigned long active_rate, sleep_rate;
  354. + int ret = 0;
  355. +
  356. + mutex_lock(&rpm_smd_clk_lock);
  357. +
  358. + /* Don't send requests to the RPM if the rate has not been set. */
  359. + if (!r->rate)
  360. + goto out;
  361. +
  362. + to_active_sleep(r, r->rate, &this_rate, &this_sleep_rate);
  363. +
  364. + /* Take peer clock's rate into account only if it's enabled. */
  365. + if (peer->enabled)
  366. + to_active_sleep(peer, peer->rate,
  367. + &peer_rate, &peer_sleep_rate);
  368. +
  369. + active_rate = max(this_rate, peer_rate);
  370. +
  371. + if (r->branch)
  372. + active_rate = !!active_rate;
  373. +
  374. + ret = clk_smd_rpm_set_rate_active(r, active_rate);
  375. + if (ret)
  376. + goto out;
  377. +
  378. + sleep_rate = max(this_sleep_rate, peer_sleep_rate);
  379. + if (r->branch)
  380. + sleep_rate = !!sleep_rate;
  381. +
  382. + ret = clk_smd_rpm_set_rate_sleep(r, sleep_rate);
  383. + if (ret)
  384. + /* Undo the active set vote and restore it */
  385. + ret = clk_smd_rpm_set_rate_active(r, peer_rate);
  386. +
  387. +out:
  388. + if (!ret)
  389. + r->enabled = true;
  390. +
  391. + mutex_unlock(&rpm_smd_clk_lock);
  392. +
  393. + return ret;
  394. +}
  395. +
  396. +static void clk_smd_rpm_unprepare(struct clk_hw *hw)
  397. +{
  398. + struct clk_smd_rpm *r = to_clk_smd_rpm(hw);
  399. + struct clk_smd_rpm *peer = r->peer;
  400. + unsigned long peer_rate = 0, peer_sleep_rate = 0;
  401. + unsigned long active_rate, sleep_rate;
  402. + int ret;
  403. +
  404. + mutex_lock(&rpm_smd_clk_lock);
  405. +
  406. + if (!r->rate)
  407. + goto out;
  408. +
  409. + /* Take peer clock's rate into account only if it's enabled. */
  410. + if (peer->enabled)
  411. + to_active_sleep(peer, peer->rate, &peer_rate,
  412. + &peer_sleep_rate);
  413. +
  414. + active_rate = r->branch ? !!peer_rate : peer_rate;
  415. + ret = clk_smd_rpm_set_rate_active(r, active_rate);
  416. + if (ret)
  417. + goto out;
  418. +
  419. + sleep_rate = r->branch ? !!peer_sleep_rate : peer_sleep_rate;
  420. + ret = clk_smd_rpm_set_rate_sleep(r, sleep_rate);
  421. + if (ret)
  422. + goto out;
  423. +
  424. + r->enabled = false;
  425. +
  426. +out:
  427. + mutex_unlock(&rpm_smd_clk_lock);
  428. +}
  429. +
  430. +static int clk_smd_rpm_set_rate(struct clk_hw *hw, unsigned long rate,
  431. + unsigned long parent_rate)
  432. +{
  433. + struct clk_smd_rpm *r = to_clk_smd_rpm(hw);
  434. + struct clk_smd_rpm *peer = r->peer;
  435. + unsigned long active_rate, sleep_rate;
  436. + unsigned long this_rate = 0, this_sleep_rate = 0;
  437. + unsigned long peer_rate = 0, peer_sleep_rate = 0;
  438. + int ret = 0;
  439. +
  440. + mutex_lock(&rpm_smd_clk_lock);
  441. +
  442. + if (!r->enabled)
  443. + goto out;
  444. +
  445. + to_active_sleep(r, rate, &this_rate, &this_sleep_rate);
  446. +
  447. + /* Take peer clock's rate into account only if it's enabled. */
  448. + if (peer->enabled)
  449. + to_active_sleep(peer, peer->rate,
  450. + &peer_rate, &peer_sleep_rate);
  451. +
  452. + active_rate = max(this_rate, peer_rate);
  453. + ret = clk_smd_rpm_set_rate_active(r, active_rate);
  454. + if (ret)
  455. + goto out;
  456. +
  457. + sleep_rate = max(this_sleep_rate, peer_sleep_rate);
  458. + ret = clk_smd_rpm_set_rate_sleep(r, sleep_rate);
  459. + if (ret)
  460. + goto out;
  461. +
  462. + r->rate = rate;
  463. +
  464. +out:
  465. + mutex_unlock(&rpm_smd_clk_lock);
  466. +
  467. + return ret;
  468. +}
  469. +
  470. +static long clk_smd_rpm_round_rate(struct clk_hw *hw, unsigned long rate,
  471. + unsigned long *parent_rate)
  472. +{
  473. + /*
  474. + * RPM handles rate rounding and we don't have a way to
  475. + * know what the rate will be, so just return whatever
  476. + * rate is requested.
  477. + */
  478. + return rate;
  479. +}
  480. +
  481. +static unsigned long clk_smd_rpm_recalc_rate(struct clk_hw *hw,
  482. + unsigned long parent_rate)
  483. +{
  484. + struct clk_smd_rpm *r = to_clk_smd_rpm(hw);
  485. +
  486. + /*
  487. + * RPM handles rate rounding and we don't have a way to
  488. + * know what the rate will be, so just return whatever
  489. + * rate was set.
  490. + */
  491. + return r->rate;
  492. +}
  493. +
  494. +static int clk_smd_rpm_enable_scaling(struct qcom_smd_rpm *rpm)
  495. +{
  496. + int ret;
  497. + struct clk_smd_rpm_req req = {
  498. + .key = cpu_to_le32(QCOM_RPM_SMD_KEY_ENABLE),
  499. + .nbytes = cpu_to_le32(sizeof(u32)),
  500. + .value = cpu_to_le32(1),
  501. + };
  502. +
  503. + ret = qcom_rpm_smd_write(rpm, QCOM_SMD_RPM_SLEEP_STATE,
  504. + QCOM_SMD_RPM_MISC_CLK,
  505. + QCOM_RPM_SCALING_ENABLE_ID, &req, sizeof(req));
  506. + if (ret) {
  507. + pr_err("RPM clock scaling (sleep set) not enabled!\n");
  508. + return ret;
  509. + }
  510. +
  511. + ret = qcom_rpm_smd_write(rpm, QCOM_SMD_RPM_ACTIVE_STATE,
  512. + QCOM_SMD_RPM_MISC_CLK,
  513. + QCOM_RPM_SCALING_ENABLE_ID, &req, sizeof(req));
  514. + if (ret) {
  515. + pr_err("RPM clock scaling (active set) not enabled!\n");
  516. + return ret;
  517. + }
  518. +
  519. + pr_debug("%s: RPM clock scaling is enabled\n", __func__);
  520. + return 0;
  521. +}
  522. +
  523. +static const struct clk_ops clk_smd_rpm_ops = {
  524. + .prepare = clk_smd_rpm_prepare,
  525. + .unprepare = clk_smd_rpm_unprepare,
  526. + .set_rate = clk_smd_rpm_set_rate,
  527. + .round_rate = clk_smd_rpm_round_rate,
  528. + .recalc_rate = clk_smd_rpm_recalc_rate,
  529. +};
  530. +
  531. +static const struct clk_ops clk_smd_rpm_branch_ops = {
  532. + .prepare = clk_smd_rpm_prepare,
  533. + .unprepare = clk_smd_rpm_unprepare,
  534. + .round_rate = clk_smd_rpm_round_rate,
  535. + .recalc_rate = clk_smd_rpm_recalc_rate,
  536. +};
  537. +
  538. +/* msm8916 */
  539. +DEFINE_CLK_SMD_RPM(msm8916, pcnoc_clk, pcnoc_a_clk, QCOM_SMD_RPM_BUS_CLK, 0);
  540. +DEFINE_CLK_SMD_RPM(msm8916, snoc_clk, snoc_a_clk, QCOM_SMD_RPM_BUS_CLK, 1);
  541. +DEFINE_CLK_SMD_RPM(msm8916, bimc_clk, bimc_a_clk, QCOM_SMD_RPM_MEM_CLK, 0);
  542. +DEFINE_CLK_SMD_RPM_QDSS(msm8916, qdss_clk, qdss_a_clk, QCOM_SMD_RPM_MISC_CLK, 1);
  543. +DEFINE_CLK_SMD_RPM_XO_BUFFER(msm8916, bb_clk1, bb_clk1_a, 1);
  544. +DEFINE_CLK_SMD_RPM_XO_BUFFER(msm8916, bb_clk2, bb_clk2_a, 2);
  545. +DEFINE_CLK_SMD_RPM_XO_BUFFER(msm8916, rf_clk1, rf_clk1_a, 4);
  546. +DEFINE_CLK_SMD_RPM_XO_BUFFER(msm8916, rf_clk2, rf_clk2_a, 5);
  547. +DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(msm8916, bb_clk1_pin, bb_clk1_a_pin, 1);
  548. +DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(msm8916, bb_clk2_pin, bb_clk2_a_pin, 2);
  549. +DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(msm8916, rf_clk1_pin, rf_clk1_a_pin, 4);
  550. +DEFINE_CLK_SMD_RPM_XO_BUFFER_PINCTRL(msm8916, rf_clk2_pin, rf_clk2_a_pin, 5);
  551. +
  552. +static struct clk_smd_rpm *msm8916_clks[] = {
  553. + [RPM_SMD_PCNOC_CLK] = &msm8916_pcnoc_clk,
  554. + [RPM_SMD_PCNOC_A_CLK] = &msm8916_pcnoc_a_clk,
  555. + [RPM_SMD_SNOC_CLK] = &msm8916_snoc_clk,
  556. + [RPM_SMD_SNOC_A_CLK] = &msm8916_snoc_a_clk,
  557. + [RPM_SMD_BIMC_CLK] = &msm8916_bimc_clk,
  558. + [RPM_SMD_BIMC_A_CLK] = &msm8916_bimc_a_clk,
  559. + [RPM_SMD_QDSS_CLK] = &msm8916_qdss_clk,
  560. + [RPM_SMD_QDSS_A_CLK] = &msm8916_qdss_a_clk,
  561. + [RPM_SMD_BB_CLK1] = &msm8916_bb_clk1,
  562. + [RPM_SMD_BB_CLK1_A] = &msm8916_bb_clk1_a,
  563. + [RPM_SMD_BB_CLK2] = &msm8916_bb_clk2,
  564. + [RPM_SMD_BB_CLK2_A] = &msm8916_bb_clk2_a,
  565. + [RPM_SMD_RF_CLK1] = &msm8916_rf_clk1,
  566. + [RPM_SMD_RF_CLK1_A] = &msm8916_rf_clk1_a,
  567. + [RPM_SMD_RF_CLK2] = &msm8916_rf_clk2,
  568. + [RPM_SMD_RF_CLK2_A] = &msm8916_rf_clk2_a,
  569. + [RPM_SMD_BB_CLK1_PIN] = &msm8916_bb_clk1_pin,
  570. + [RPM_SMD_BB_CLK1_A_PIN] = &msm8916_bb_clk1_a_pin,
  571. + [RPM_SMD_BB_CLK2_PIN] = &msm8916_bb_clk2_pin,
  572. + [RPM_SMD_BB_CLK2_A_PIN] = &msm8916_bb_clk2_a_pin,
  573. + [RPM_SMD_RF_CLK1_PIN] = &msm8916_rf_clk1_pin,
  574. + [RPM_SMD_RF_CLK1_A_PIN] = &msm8916_rf_clk1_a_pin,
  575. + [RPM_SMD_RF_CLK2_PIN] = &msm8916_rf_clk2_pin,
  576. + [RPM_SMD_RF_CLK2_A_PIN] = &msm8916_rf_clk2_a_pin,
  577. +};
  578. +
  579. +static const struct rpm_smd_clk_desc rpm_clk_msm8916 = {
  580. + .clks = msm8916_clks,
  581. + .num_clks = ARRAY_SIZE(msm8916_clks),
  582. +};
  583. +
  584. +static const struct of_device_id rpm_smd_clk_match_table[] = {
  585. + { .compatible = "qcom,rpmcc-msm8916", .data = &rpm_clk_msm8916 },
  586. + { }
  587. +};
  588. +MODULE_DEVICE_TABLE(of, rpm_smd_clk_match_table);
  589. +
  590. +static int rpm_smd_clk_probe(struct platform_device *pdev)
  591. +{
  592. + struct clk_hw **hws;
  593. + struct rpm_cc *rcc;
  594. + struct clk_hw_onecell_data *data;
  595. + int ret;
  596. + size_t num_clks, i;
  597. + struct qcom_smd_rpm *rpm;
  598. + struct clk_smd_rpm **rpm_smd_clks;
  599. + const struct rpm_smd_clk_desc *desc;
  600. +
  601. + rpm = dev_get_drvdata(pdev->dev.parent);
  602. + if (!rpm) {
  603. + dev_err(&pdev->dev, "Unable to retrieve handle to RPM\n");
  604. + return -ENODEV;
  605. + }
  606. +
  607. + desc = of_device_get_match_data(&pdev->dev);
  608. + if (!desc)
  609. + return -EINVAL;
  610. +
  611. + rpm_smd_clks = desc->clks;
  612. + num_clks = desc->num_clks;
  613. +
  614. + rcc = devm_kzalloc(&pdev->dev, sizeof(*rcc) + sizeof(*hws) * num_clks,
  615. + GFP_KERNEL);
  616. + if (!rcc)
  617. + return -ENOMEM;
  618. +
  619. + hws = rcc->hws;
  620. + data = &rcc->data;
  621. + data->num = num_clks;
  622. +
  623. + for (i = 0; i < num_clks; i++) {
  624. + if (!rpm_smd_clks[i]) {
  625. + continue;
  626. + }
  627. +
  628. + rpm_smd_clks[i]->rpm = rpm;
  629. +
  630. + ret = clk_smd_rpm_handoff(rpm_smd_clks[i]);
  631. + if (ret)
  632. + goto err;
  633. + }
  634. +
  635. + ret = clk_smd_rpm_enable_scaling(rpm);
  636. + if (ret)
  637. + goto err;
  638. +
  639. + for (i = 0; i < num_clks; i++) {
  640. + if (!rpm_smd_clks[i]) {
  641. + data->hws[i] = ERR_PTR(-ENOENT);
  642. + continue;
  643. + }
  644. +
  645. + ret = devm_clk_hw_register(&pdev->dev, &rpm_smd_clks[i]->hw);
  646. + if (ret)
  647. + goto err;
  648. + }
  649. +
  650. + ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
  651. + data);
  652. + if (ret)
  653. + goto err;
  654. +
  655. + return 0;
  656. +err:
  657. + dev_err(&pdev->dev, "Error registering SMD clock driver (%d)\n", ret);
  658. + return ret;
  659. +}
  660. +
  661. +static int rpm_smd_clk_remove(struct platform_device *pdev)
  662. +{
  663. + of_clk_del_provider(pdev->dev.of_node);
  664. + return 0;
  665. +}
  666. +
  667. +static struct platform_driver rpm_smd_clk_driver = {
  668. + .driver = {
  669. + .name = "qcom-clk-smd-rpm",
  670. + .of_match_table = rpm_smd_clk_match_table,
  671. + },
  672. + .probe = rpm_smd_clk_probe,
  673. + .remove = rpm_smd_clk_remove,
  674. +};
  675. +
  676. +static int __init rpm_smd_clk_init(void)
  677. +{
  678. + return platform_driver_register(&rpm_smd_clk_driver);
  679. +}
  680. +core_initcall(rpm_smd_clk_init);
  681. +
  682. +static void __exit rpm_smd_clk_exit(void)
  683. +{
  684. + platform_driver_unregister(&rpm_smd_clk_driver);
  685. +}
  686. +module_exit(rpm_smd_clk_exit);
  687. +
  688. +MODULE_DESCRIPTION("Qualcomm RPM over SMD Clock Controller Driver");
  689. +MODULE_LICENSE("GPL v2");
  690. +MODULE_ALIAS("platform:qcom-clk-smd-rpm");
  691. --- /dev/null
  692. +++ b/include/dt-bindings/clock/qcom,rpmcc.h
  693. @@ -0,0 +1,45 @@
  694. +/*
  695. + * Copyright 2015 Linaro Limited
  696. + *
  697. + * This software is licensed under the terms of the GNU General Public
  698. + * License version 2, as published by the Free Software Foundation, and
  699. + * may be copied, distributed, and modified under those terms.
  700. + *
  701. + * This program is distributed in the hope that it will be useful,
  702. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  703. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  704. + * GNU General Public License for more details.
  705. + */
  706. +
  707. +#ifndef _DT_BINDINGS_CLK_MSM_RPMCC_H
  708. +#define _DT_BINDINGS_CLK_MSM_RPMCC_H
  709. +
  710. +/* msm8916 */
  711. +#define RPM_SMD_XO_CLK_SRC 0
  712. +#define RPM_SMD_XO_A_CLK_SRC 1
  713. +#define RPM_SMD_PCNOC_CLK 2
  714. +#define RPM_SMD_PCNOC_A_CLK 3
  715. +#define RPM_SMD_SNOC_CLK 4
  716. +#define RPM_SMD_SNOC_A_CLK 5
  717. +#define RPM_SMD_BIMC_CLK 6
  718. +#define RPM_SMD_BIMC_A_CLK 7
  719. +#define RPM_SMD_QDSS_CLK 8
  720. +#define RPM_SMD_QDSS_A_CLK 9
  721. +#define RPM_SMD_BB_CLK1 10
  722. +#define RPM_SMD_BB_CLK1_A 11
  723. +#define RPM_SMD_BB_CLK2 12
  724. +#define RPM_SMD_BB_CLK2_A 13
  725. +#define RPM_SMD_RF_CLK1 14
  726. +#define RPM_SMD_RF_CLK1_A 15
  727. +#define RPM_SMD_RF_CLK2 16
  728. +#define RPM_SMD_RF_CLK2_A 17
  729. +#define RPM_SMD_BB_CLK1_PIN 18
  730. +#define RPM_SMD_BB_CLK1_A_PIN 19
  731. +#define RPM_SMD_BB_CLK2_PIN 20
  732. +#define RPM_SMD_BB_CLK2_A_PIN 21
  733. +#define RPM_SMD_RF_CLK1_PIN 22
  734. +#define RPM_SMD_RF_CLK1_A_PIN 23
  735. +#define RPM_SMD_RF_CLK2_PIN 24
  736. +#define RPM_SMD_RF_CLK2_A_PIN 25
  737. +
  738. +#endif