cam_cpas_soc.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/device.h>
  6. #include <linux/of.h>
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/slab.h>
  11. #include <dt-bindings/msm-camera.h>
  12. #include "cam_cpas_api.h"
  13. #include "cam_cpas_hw_intf.h"
  14. #include "cam_cpas_hw.h"
  15. #include "cam_cpas_soc.h"
  16. static uint cpas_dump;
  17. module_param(cpas_dump, uint, 0644);
  18. void cam_cpas_dump_axi_vote_info(
  19. const struct cam_cpas_client *cpas_client,
  20. const char *identifier,
  21. struct cam_axi_vote *axi_vote)
  22. {
  23. int i;
  24. if (!cpas_dump)
  25. return;
  26. if (!axi_vote || (axi_vote->num_paths >
  27. CAM_CPAS_MAX_PATHS_PER_CLIENT)) {
  28. CAM_ERR(CAM_PERF, "Invalid num_paths %d",
  29. axi_vote ? axi_vote->num_paths : -1);
  30. return;
  31. }
  32. for (i = 0; i < axi_vote->num_paths; i++) {
  33. CAM_INFO(CAM_PERF,
  34. "Client [%s][%d] : [%s], Path=[%d] [%d], camnoc[%llu], mnoc_ab[%llu], mnoc_ib[%llu]",
  35. cpas_client->data.identifier, cpas_client->data.cell_index,
  36. identifier,
  37. axi_vote->axi_path[i].path_data_type,
  38. axi_vote->axi_path[i].transac_type,
  39. axi_vote->axi_path[i].camnoc_bw,
  40. axi_vote->axi_path[i].mnoc_ab_bw,
  41. axi_vote->axi_path[i].mnoc_ib_bw);
  42. }
  43. }
  44. void cam_cpas_util_debug_parse_data(
  45. struct cam_cpas_private_soc *soc_private)
  46. {
  47. int i, j;
  48. struct cam_cpas_tree_node *curr_node = NULL;
  49. if (!cpas_dump)
  50. return;
  51. for (i = 0; i < CAM_CPAS_MAX_TREE_NODES; i++) {
  52. if (!soc_private->tree_node[i])
  53. break;
  54. curr_node = soc_private->tree_node[i];
  55. CAM_INFO(CAM_CPAS,
  56. "NODE cell_idx: %d, level: %d, name: %s, axi_port_idx: %d, merge_type: %d, parent_name: %s camnoc_max_needed: %d",
  57. curr_node->cell_idx, curr_node->level_idx,
  58. curr_node->node_name, curr_node->axi_port_idx,
  59. curr_node->merge_type, curr_node->parent_node ?
  60. curr_node->parent_node->node_name : "no parent",
  61. curr_node->camnoc_max_needed);
  62. if (curr_node->level_idx)
  63. continue;
  64. CAM_INFO(CAM_CPAS, "path_type: %d, transac_type: %s",
  65. curr_node->path_data_type,
  66. cam_cpas_axi_util_trans_type_to_string(
  67. curr_node->path_trans_type));
  68. for (j = 0; j < CAM_CPAS_PATH_DATA_MAX; j++) {
  69. CAM_INFO(CAM_CPAS, "Constituent path: %d",
  70. curr_node->constituent_paths[j] ? j : -1);
  71. }
  72. }
  73. CAM_INFO(CAM_CPAS, "NUMBER OF NODES PARSED: %d", i);
  74. }
  75. int cam_cpas_node_tree_cleanup(struct cam_cpas *cpas_core,
  76. struct cam_cpas_private_soc *soc_private)
  77. {
  78. int i = 0;
  79. for (i = 0; i < CAM_CPAS_MAX_TREE_NODES; i++) {
  80. if (soc_private->tree_node[i]) {
  81. of_node_put(soc_private->tree_node[i]->tree_dev_node);
  82. kfree(soc_private->tree_node[i]);
  83. soc_private->tree_node[i] = NULL;
  84. }
  85. }
  86. for (i = 0; i < CAM_CPAS_MAX_TREE_LEVELS; i++) {
  87. if (soc_private->level_node[i]) {
  88. of_node_put(soc_private->level_node[i]);
  89. soc_private->level_node[i] = NULL;
  90. }
  91. }
  92. if (soc_private->camera_bus_node) {
  93. of_node_put(soc_private->camera_bus_node);
  94. soc_private->camera_bus_node = NULL;
  95. }
  96. mutex_destroy(&cpas_core->tree_lock);
  97. return 0;
  98. }
  99. static int cam_cpas_util_path_type_to_idx(uint32_t *path_data_type)
  100. {
  101. if (*path_data_type >= CAM_CPAS_PATH_DATA_CONSO_OFFSET) {
  102. *path_data_type = CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT +
  103. (*path_data_type % CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT);
  104. }
  105. else {
  106. *path_data_type %= CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT;
  107. }
  108. if (*path_data_type >= CAM_CPAS_PATH_DATA_MAX) {
  109. CAM_ERR(CAM_CPAS, "index Invalid: %u", *path_data_type);
  110. return -EINVAL;
  111. }
  112. return 0;
  113. }
  114. static int cam_cpas_update_camnoc_node(struct cam_cpas *cpas_core,
  115. struct device_node *curr_node,
  116. struct cam_cpas_tree_node *cpas_node_ptr,
  117. int *camnoc_idx)
  118. {
  119. struct device_node *camnoc_node;
  120. int rc;
  121. camnoc_node = of_find_node_by_name(curr_node,
  122. "qcom,axi-port-camnoc");
  123. if (camnoc_node) {
  124. if (*camnoc_idx >=
  125. CAM_CPAS_MAX_AXI_PORTS) {
  126. CAM_ERR(CAM_CPAS, "CAMNOC axi index overshoot %d",
  127. *camnoc_idx);
  128. return -EINVAL;
  129. }
  130. cpas_core->camnoc_axi_port[*camnoc_idx]
  131. .axi_port_node = camnoc_node;
  132. rc = of_property_read_string(
  133. curr_node,
  134. "qcom,axi-port-name",
  135. &cpas_core->camnoc_axi_port[*camnoc_idx]
  136. .axi_port_name);
  137. if (rc) {
  138. CAM_ERR(CAM_CPAS,
  139. "fail to read camnoc-port-name rc=%d",
  140. rc);
  141. return rc;
  142. }
  143. cpas_node_ptr->camnoc_axi_port_idx = *camnoc_idx;
  144. cpas_core->num_camnoc_axi_ports++;
  145. (*camnoc_idx)++;
  146. }
  147. return 0;
  148. }
  149. static int cam_cpas_parse_node_tree(struct cam_cpas *cpas_core,
  150. struct device_node *of_node, struct cam_cpas_private_soc *soc_private)
  151. {
  152. struct device_node *camera_bus_node;
  153. struct device_node *level_node;
  154. struct device_node *curr_node;
  155. struct device_node *parent_node;
  156. struct device_node *mnoc_node;
  157. int mnoc_idx = 0, camnoc_idx = 0, level_idx = 0;
  158. uint32_t path_idx;
  159. bool camnoc_max_needed = false;
  160. struct cam_cpas_tree_node *curr_node_ptr = NULL;
  161. struct cam_cpas_client *curr_client = NULL;
  162. const char *client_name = NULL;
  163. uint32_t client_idx = 0, cell_idx = 0;
  164. uint8_t niu_idx = 0;
  165. int rc = 0, count = 0, i;
  166. camera_bus_node = of_get_child_by_name(of_node, "camera-bus-nodes");
  167. if (!camera_bus_node) {
  168. CAM_ERR(CAM_CPAS, "Camera Bus node not found in cpas DT node");
  169. return -EINVAL;
  170. }
  171. soc_private->camera_bus_node = camera_bus_node;
  172. for_each_available_child_of_node(camera_bus_node, level_node) {
  173. rc = of_property_read_u32(level_node, "level-index",
  174. &level_idx);
  175. if (rc) {
  176. CAM_ERR(CAM_CPAS, "Error reading level idx rc: %d", rc);
  177. return rc;
  178. }
  179. if (level_idx >= CAM_CPAS_MAX_TREE_LEVELS) {
  180. CAM_ERR(CAM_CPAS, "Invalid level idx: %d", level_idx);
  181. return -EINVAL;
  182. }
  183. soc_private->level_node[level_idx] = level_node;
  184. }
  185. if (soc_private->enable_smart_qos)
  186. soc_private->smart_qos_info->num_rt_wr_nius = 0;
  187. for (level_idx = (CAM_CPAS_MAX_TREE_LEVELS - 1); level_idx >= 0;
  188. level_idx--) {
  189. level_node = soc_private->level_node[level_idx];
  190. if (!level_node)
  191. continue;
  192. CAM_DBG(CAM_CPAS, "Parsing level %d nodes", level_idx);
  193. camnoc_max_needed = of_property_read_bool(level_node,
  194. "camnoc-max-needed");
  195. for_each_available_child_of_node(level_node, curr_node) {
  196. curr_node_ptr =
  197. kzalloc(sizeof(struct cam_cpas_tree_node),
  198. GFP_KERNEL);
  199. if (!curr_node_ptr)
  200. return -ENOMEM;
  201. curr_node_ptr->tree_dev_node = curr_node;
  202. rc = of_property_read_u32(curr_node, "cell-index",
  203. &curr_node_ptr->cell_idx);
  204. if (rc) {
  205. CAM_ERR(CAM_CPAS, "Node index not found");
  206. return rc;
  207. }
  208. CAM_DBG(CAM_CPAS, "Parsing Node with cell index %d",
  209. curr_node_ptr->cell_idx);
  210. if (curr_node_ptr->cell_idx >=
  211. CAM_CPAS_MAX_TREE_NODES) {
  212. CAM_ERR(CAM_CPAS, "Invalid cell idx: %d",
  213. curr_node_ptr->cell_idx);
  214. return -EINVAL;
  215. }
  216. soc_private->tree_node[curr_node_ptr->cell_idx] =
  217. curr_node_ptr;
  218. curr_node_ptr->level_idx = level_idx;
  219. rc = of_property_read_string(curr_node, "node-name",
  220. &curr_node_ptr->node_name);
  221. if (rc) {
  222. CAM_ERR(CAM_CPAS,
  223. "failed to read node-name rc=%d",
  224. rc);
  225. return rc;
  226. }
  227. if (soc_private->enable_smart_qos &&
  228. (level_idx == 1) &&
  229. of_property_read_bool(curr_node, "rt-wr-niu")) {
  230. rc = of_property_read_u32(curr_node,
  231. "priority-lut-low-offset",
  232. &curr_node_ptr->pri_lut_low_offset);
  233. if (rc) {
  234. CAM_ERR(CAM_CPAS,
  235. "Invalid priority offset rc %d",
  236. rc);
  237. return rc;
  238. }
  239. rc = of_property_read_u32(curr_node, "niu-size",
  240. &curr_node_ptr->niu_size);
  241. if (rc || !curr_node_ptr->niu_size) {
  242. CAM_ERR(CAM_CPAS,
  243. "Invalid niu size rc %d", rc);
  244. return rc;
  245. }
  246. niu_idx = soc_private->smart_qos_info->num_rt_wr_nius;
  247. if (niu_idx >= CAM_CPAS_MAX_RT_WR_NIU_NODES) {
  248. CAM_ERR(CAM_CPAS,
  249. "Invalid number of level1 nodes %d",
  250. soc_private->smart_qos_info->num_rt_wr_nius);
  251. return -EINVAL;
  252. }
  253. soc_private->smart_qos_info->rt_wr_niu_node[niu_idx] =
  254. curr_node_ptr;
  255. soc_private->smart_qos_info->num_rt_wr_nius++;
  256. CAM_DBG(CAM_CPAS,
  257. "level1[%d] : Node %s idx %d priority offset 0x%x, NIU size %dKB",
  258. niu_idx,
  259. curr_node_ptr->node_name, curr_node_ptr->cell_idx,
  260. curr_node_ptr->pri_lut_low_offset, curr_node_ptr->niu_size);
  261. }
  262. curr_node_ptr->camnoc_max_needed = camnoc_max_needed;
  263. rc = of_property_read_u32(curr_node, "bus-width-factor",
  264. &curr_node_ptr->bus_width_factor);
  265. if (rc)
  266. curr_node_ptr->bus_width_factor = 1;
  267. rc = of_property_read_u32(curr_node,
  268. "traffic-merge-type",
  269. &curr_node_ptr->merge_type);
  270. curr_node_ptr->axi_port_idx = -1;
  271. mnoc_node = of_get_child_by_name(curr_node,
  272. "qcom,axi-port-mnoc");
  273. if (mnoc_node) {
  274. if (mnoc_idx >= CAM_CPAS_MAX_AXI_PORTS) {
  275. CAM_ERR(CAM_CPAS,
  276. "Invalid mnoc index: %d",
  277. mnoc_idx);
  278. return -EINVAL;
  279. }
  280. cpas_core->axi_port[mnoc_idx].axi_port_node
  281. = mnoc_node;
  282. if (soc_private->bus_icc_based) {
  283. struct of_phandle_args src_args = {0},
  284. dst_args = {0};
  285. rc = of_property_read_string(mnoc_node,
  286. "interconnect-names",
  287. &cpas_core->axi_port[mnoc_idx]
  288. .bus_client.common_data.name);
  289. if (rc) {
  290. CAM_ERR(CAM_CPAS,
  291. "failed to read interconnect-names rc=%d",
  292. rc);
  293. return rc;
  294. }
  295. rc = of_parse_phandle_with_args(
  296. mnoc_node, "interconnects",
  297. "#interconnect-cells", 0,
  298. &src_args);
  299. if (rc) {
  300. CAM_ERR(CAM_CPAS,
  301. "failed to read axi bus src info rc=%d",
  302. rc);
  303. return -EINVAL;
  304. }
  305. of_node_put(src_args.np);
  306. if (src_args.args_count != 1) {
  307. CAM_ERR(CAM_CPAS,
  308. "Invalid number of axi src args: %d",
  309. src_args.args_count);
  310. return -EINVAL;
  311. }
  312. cpas_core->axi_port[mnoc_idx].bus_client
  313. .common_data.src_id = src_args.args[0];
  314. rc = of_parse_phandle_with_args(
  315. mnoc_node, "interconnects",
  316. "#interconnect-cells", 1,
  317. &dst_args);
  318. if (rc) {
  319. CAM_ERR(CAM_CPAS,
  320. "failed to read axi bus dst info rc=%d",
  321. rc);
  322. return -EINVAL;
  323. }
  324. of_node_put(dst_args.np);
  325. if (dst_args.args_count != 1) {
  326. CAM_ERR(CAM_CPAS,
  327. "Invalid number of axi dst args: %d",
  328. dst_args.args_count);
  329. return -EINVAL;
  330. }
  331. cpas_core->axi_port[mnoc_idx].bus_client
  332. .common_data.dst_id = dst_args.args[0];
  333. cpas_core->axi_port[mnoc_idx].bus_client
  334. .common_data.num_usecases = 2;
  335. } else {
  336. rc = of_property_read_string(
  337. curr_node, "qcom,axi-port-name",
  338. &cpas_core->axi_port[mnoc_idx]
  339. .bus_client.common_data.name);
  340. if (rc) {
  341. CAM_ERR(CAM_CPAS,
  342. "failed to read mnoc-port-name rc=%d",
  343. rc);
  344. return rc;
  345. }
  346. }
  347. cpas_core->axi_port[mnoc_idx].axi_port_name =
  348. cpas_core->axi_port[mnoc_idx]
  349. .bus_client.common_data.name;
  350. cpas_core->axi_port
  351. [mnoc_idx].ib_bw_voting_needed
  352. = of_property_read_bool(curr_node,
  353. "ib-bw-voting-needed");
  354. cpas_core->axi_port
  355. [mnoc_idx].is_rt
  356. = of_property_read_bool(curr_node,
  357. "rt-axi-port");
  358. curr_node_ptr->axi_port_idx = mnoc_idx;
  359. mnoc_idx++;
  360. cpas_core->num_axi_ports++;
  361. }
  362. if (!soc_private->control_camnoc_axi_clk) {
  363. rc = cam_cpas_update_camnoc_node(
  364. cpas_core, curr_node, curr_node_ptr,
  365. &camnoc_idx);
  366. if (rc) {
  367. CAM_ERR(CAM_CPAS,
  368. "Parse Camnoc port fail");
  369. return rc;
  370. }
  371. }
  372. rc = of_property_read_string(curr_node,
  373. "client-name", &client_name);
  374. if (!rc) {
  375. rc = of_property_read_u32(curr_node,
  376. "traffic-data", &curr_node_ptr->path_data_type);
  377. if (rc) {
  378. CAM_ERR(CAM_CPAS,
  379. "Path Data type not found");
  380. return rc;
  381. }
  382. rc = cam_cpas_util_path_type_to_idx(
  383. &curr_node_ptr->path_data_type);
  384. if (rc) {
  385. CAM_ERR(CAM_CPAS, "Incorrect path type for client: %s",
  386. client_name);
  387. return rc;
  388. }
  389. rc = of_property_read_u32(curr_node,
  390. "traffic-transaction-type",
  391. &curr_node_ptr->path_trans_type);
  392. if (rc) {
  393. CAM_ERR(CAM_CPAS,
  394. "Path Transac type not found");
  395. return rc;
  396. }
  397. if (curr_node_ptr->path_trans_type >=
  398. CAM_CPAS_TRANSACTION_MAX) {
  399. CAM_ERR(CAM_CPAS,
  400. "Invalid transac type: %d",
  401. curr_node_ptr->path_trans_type);
  402. return -EINVAL;
  403. }
  404. count = of_property_count_u32_elems(curr_node,
  405. "constituent-paths");
  406. for (i = 0; i < count; i++) {
  407. rc = of_property_read_u32_index(
  408. curr_node, "constituent-paths",
  409. i, &path_idx);
  410. if (rc) {
  411. CAM_ERR(CAM_CPAS,
  412. "No constituent path at %d", i);
  413. return rc;
  414. }
  415. rc = cam_cpas_util_path_type_to_idx(
  416. &path_idx);
  417. if (rc)
  418. return rc;
  419. curr_node_ptr->constituent_paths
  420. [path_idx] = true;
  421. }
  422. rc = cam_common_util_get_string_index(
  423. soc_private->client_name,
  424. soc_private->num_clients,
  425. client_name, &client_idx);
  426. if (rc) {
  427. CAM_ERR(CAM_CPAS,
  428. "client name not found in list: %s",
  429. client_name);
  430. return rc;
  431. }
  432. if (client_idx >= CAM_CPAS_MAX_CLIENTS)
  433. return -EINVAL;
  434. curr_client =
  435. cpas_core->cpas_client[client_idx];
  436. curr_client->tree_node_valid = true;
  437. curr_client->tree_node
  438. [curr_node_ptr->path_data_type]
  439. [curr_node_ptr->path_trans_type] =
  440. curr_node_ptr;
  441. CAM_DBG(CAM_CPAS,
  442. "CLIENT NODE ADDED: %d %d %s",
  443. curr_node_ptr->path_data_type,
  444. curr_node_ptr->path_trans_type,
  445. client_name);
  446. }
  447. parent_node = of_parse_phandle(curr_node,
  448. "parent-node", 0);
  449. if (parent_node) {
  450. of_property_read_u32(parent_node, "cell-index",
  451. &cell_idx);
  452. curr_node_ptr->parent_node =
  453. soc_private->tree_node[cell_idx];
  454. } else {
  455. CAM_DBG(CAM_CPAS,
  456. "no parent node at this level");
  457. }
  458. }
  459. }
  460. mutex_init(&cpas_core->tree_lock);
  461. cam_cpas_util_debug_parse_data(soc_private);
  462. return 0;
  463. }
  464. int cam_cpas_get_hw_features(struct platform_device *pdev,
  465. struct cam_cpas_private_soc *soc_private)
  466. {
  467. struct device_node *of_node;
  468. void *fuse;
  469. uint32_t fuse_addr, fuse_mask, fuse_shift;
  470. uint32_t val = 0, fuse_val = 0, feature;
  471. uint32_t enable_type = 0, hw_map = 0;
  472. int count = 0, i = 0, j = 0, num_feature = 0, num_fuse = 0;
  473. struct cam_cpas_feature_info *feature_info;
  474. of_node = pdev->dev.of_node;
  475. count = of_property_count_u32_elems(of_node, "cam_hw_fuse");
  476. CAM_DBG(CAM_CPAS, "fuse info elements count %d", count);
  477. if (count <= 0) {
  478. CAM_INFO(CAM_CPAS, "No or invalid fuse entries count: %d",
  479. count);
  480. goto end;
  481. } else if (count%5 != 0) {
  482. CAM_INFO(CAM_CPAS, "fuse entries should be multiple of 5 %d",
  483. count);
  484. goto end;
  485. }
  486. for (i = 0; (i + 5) <= count; i = i + 5) {
  487. of_property_read_u32_index(of_node, "cam_hw_fuse", i,
  488. &feature);
  489. of_property_read_u32_index(of_node, "cam_hw_fuse", i + 1,
  490. &fuse_addr);
  491. of_property_read_u32_index(of_node, "cam_hw_fuse", i + 2,
  492. &fuse_mask);
  493. of_property_read_u32_index(of_node, "cam_hw_fuse", i + 3,
  494. &enable_type);
  495. of_property_read_u32_index(of_node, "cam_hw_fuse", i + 4,
  496. &hw_map);
  497. val = ffs(fuse_mask);
  498. if (val == 0) {
  499. CAM_ERR(CAM_CPAS, "fuse_mask not valid 0x%x",
  500. fuse_mask);
  501. fuse_shift = 0;
  502. } else {
  503. fuse_shift = val - 1;
  504. }
  505. CAM_INFO(CAM_CPAS,
  506. "feature 0x%x addr 0x%x, mask 0x%x, shift 0x%x type 0x%x hw_map 0x%x",
  507. feature, fuse_addr, fuse_mask, fuse_shift, enable_type,
  508. hw_map);
  509. fuse = ioremap(fuse_addr, 4);
  510. if (fuse) {
  511. fuse_val = cam_io_r(fuse);
  512. for (j = 0; (j < num_fuse) && (j < CAM_CPAS_FUSES_MAX);
  513. j++) {
  514. if (soc_private->fuse_info.fuse_val[j].fuse_id
  515. == fuse_addr)
  516. break;
  517. }
  518. if (j >= CAM_CPAS_FUSES_MAX) {
  519. CAM_ERR(CAM_CPAS,
  520. "fuse_info array overflow! %d", j);
  521. goto end;
  522. }
  523. if (j == num_fuse) {
  524. soc_private->fuse_info.fuse_val[j].fuse_id =
  525. fuse_addr;
  526. soc_private->fuse_info.fuse_val[j].fuse_val =
  527. fuse_val;
  528. CAM_INFO(CAM_CPAS,
  529. "fuse_addr 0x%x, fuse_val %x",
  530. fuse_addr, fuse_val);
  531. num_fuse++;
  532. }
  533. } else {
  534. /* if fuse ioremap is failed, disable the feature */
  535. CAM_ERR(CAM_CPAS,
  536. "fuse register io remap failed fuse_addr:0x%x feature0x%x ",
  537. fuse_addr, feature);
  538. if (enable_type == CAM_CPAS_FEATURE_TYPE_ENABLE ||
  539. enable_type == CAM_CPAS_FEATURE_TYPE_DISABLE)
  540. fuse_val = (enable_type) ? ~fuse_mask :
  541. fuse_mask;
  542. else
  543. fuse_val = 0;
  544. }
  545. if (num_feature >= CAM_CPAS_MAX_FUSE_FEATURE) {
  546. CAM_ERR(CAM_CPAS, "feature_info array overflow %d",
  547. num_feature);
  548. goto end;
  549. }
  550. soc_private->feature_info[num_feature].feature =
  551. feature;
  552. soc_private->feature_info[num_feature].hw_map = hw_map;
  553. soc_private->feature_info[num_feature].type = enable_type;
  554. feature_info = &soc_private->feature_info[num_feature];
  555. if (enable_type != CAM_CPAS_FEATURE_TYPE_VALUE) {
  556. if (enable_type == CAM_CPAS_FEATURE_TYPE_ENABLE) {
  557. /*
  558. * fuse is for enable feature
  559. * if fust bit is set means feature is enabled
  560. * or HW is enabled
  561. */
  562. if (fuse_val & fuse_mask)
  563. feature_info->enable = true;
  564. else
  565. feature_info->enable = false;
  566. } else if (enable_type ==
  567. CAM_CPAS_FEATURE_TYPE_DISABLE){
  568. /*
  569. * fuse is for disable feature
  570. * if fust bit is set means feature is disabled
  571. * or HW is disabled
  572. */
  573. if (fuse_val & fuse_mask)
  574. feature_info->enable = false;
  575. else
  576. feature_info->enable = true;
  577. } else {
  578. CAM_ERR(CAM_CPAS,
  579. "Feature type not valid, type: %d",
  580. enable_type);
  581. goto end;
  582. }
  583. CAM_INFO(CAM_CPAS,
  584. "feature 0x%x enable=%d hw_map=0x%x",
  585. feature_info->feature, feature_info->enable,
  586. feature_info->hw_map);
  587. } else {
  588. feature_info->value =
  589. (fuse_val & fuse_mask) >> fuse_shift;
  590. CAM_INFO(CAM_CPAS,
  591. "feature 0x%x value=0x%x hw_map=0x%x",
  592. feature_info->feature, feature_info->value,
  593. feature_info->hw_map);
  594. }
  595. num_feature++;
  596. iounmap(fuse);
  597. }
  598. end:
  599. soc_private->fuse_info.num_fuses = num_fuse;
  600. soc_private->num_feature_info = num_feature;
  601. return 0;
  602. }
  603. static inline enum cam_sys_cache_config_types cam_cpas_find_type_from_string(
  604. const char *cache_name)
  605. {
  606. if (strcmp(cache_name, "small-1") == 0)
  607. return CAM_LLCC_SMALL_1;
  608. else if (strcmp(cache_name, "small-2") == 0)
  609. return CAM_LLCC_SMALL_2;
  610. else
  611. return CAM_LLCC_MAX;
  612. }
  613. static int cam_cpas_parse_sys_cache_uids(
  614. struct device_node *of_node,
  615. struct cam_cpas_private_soc *soc_private)
  616. {
  617. enum cam_sys_cache_config_types type = CAM_LLCC_MAX;
  618. int num_caches, i, rc;
  619. uint32_t scid;
  620. soc_private->llcc_info = NULL;
  621. soc_private->num_caches = 0;
  622. num_caches = of_property_count_strings(of_node, "sys-cache-names");
  623. if (num_caches <= 0) {
  624. CAM_DBG(CAM_CPAS, "no cache-names found");
  625. return 0;
  626. }
  627. if (num_caches > CAM_LLCC_MAX) {
  628. CAM_ERR(CAM_CPAS,
  629. "invalid number of cache-names found: 0x%x",
  630. num_caches);
  631. return -EINVAL;
  632. }
  633. soc_private->llcc_info = kcalloc(num_caches,
  634. sizeof(struct cam_sys_cache_info), GFP_KERNEL);
  635. if (!soc_private->llcc_info)
  636. return -ENOMEM;
  637. for (i = 0; i < num_caches; i++) {
  638. rc = of_property_read_string_index(of_node, "sys-cache-names", i,
  639. &soc_private->llcc_info[i].name);
  640. if (rc) {
  641. CAM_ERR(CAM_CPAS, "failed to read cache-names at %d", i);
  642. goto end;
  643. }
  644. type = cam_cpas_find_type_from_string(
  645. soc_private->llcc_info[i].name);
  646. if (type == CAM_LLCC_MAX) {
  647. CAM_ERR(CAM_CPAS, "Unsupported cache found: %s",
  648. soc_private->llcc_info[i].name);
  649. rc = -EINVAL;
  650. goto end;
  651. }
  652. soc_private->llcc_info[i].type = type;
  653. rc = of_property_read_u32_index(of_node,
  654. "sys-cache-uids", i,
  655. &soc_private->llcc_info[i].uid);
  656. if (rc < 0) {
  657. CAM_ERR(CAM_CPAS,
  658. "unable to read sys cache uid at index %d", i);
  659. goto end;
  660. }
  661. soc_private->llcc_info[i].slic_desc =
  662. llcc_slice_getd(soc_private->llcc_info[i].uid);
  663. if (IS_ERR_OR_NULL(soc_private->llcc_info[i].slic_desc)) {
  664. CAM_ERR(CAM_CPAS,
  665. "Failed to get slice desc for uid %u",
  666. soc_private->llcc_info[i].uid);
  667. rc = -EINVAL;
  668. goto end;
  669. }
  670. scid = llcc_get_slice_id(soc_private->llcc_info[i].slic_desc);
  671. soc_private->llcc_info[i].scid = scid;
  672. soc_private->llcc_info[i].size =
  673. llcc_get_slice_size(soc_private->llcc_info[i].slic_desc);
  674. soc_private->num_caches++;
  675. CAM_DBG(CAM_CPAS,
  676. "Cache: %s uid: %u scid: %d size: %zukb",
  677. soc_private->llcc_info[i].name,
  678. soc_private->llcc_info[i].uid, scid,
  679. soc_private->llcc_info[i].size);
  680. }
  681. return 0;
  682. end:
  683. kfree(soc_private->llcc_info);
  684. soc_private->llcc_info = NULL;
  685. return rc;
  686. }
  687. int cam_cpas_get_custom_dt_info(struct cam_hw_info *cpas_hw,
  688. struct platform_device *pdev, struct cam_cpas_private_soc *soc_private)
  689. {
  690. struct device_node *of_node;
  691. struct of_phandle_args src_args = {0}, dst_args = {0};
  692. int count = 0, i = 0, rc = 0, num_bw_values = 0, num_levels = 0;
  693. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  694. if (!soc_private || !pdev) {
  695. CAM_ERR(CAM_CPAS, "invalid input arg %pK %pK",
  696. soc_private, pdev);
  697. return -EINVAL;
  698. }
  699. of_node = pdev->dev.of_node;
  700. rc = of_property_read_string(of_node, "arch-compat",
  701. &soc_private->arch_compat);
  702. if (rc) {
  703. CAM_ERR(CAM_CPAS, "device %s failed to read arch-compat",
  704. pdev->name);
  705. return rc;
  706. }
  707. cam_cpas_get_hw_features(pdev, soc_private);
  708. soc_private->camnoc_axi_min_ib_bw = 0;
  709. rc = of_property_read_u64(of_node,
  710. "camnoc-axi-min-ib-bw",
  711. &soc_private->camnoc_axi_min_ib_bw);
  712. if (rc == -EOVERFLOW) {
  713. soc_private->camnoc_axi_min_ib_bw = 0;
  714. rc = of_property_read_u32(of_node,
  715. "camnoc-axi-min-ib-bw",
  716. (u32 *)&soc_private->camnoc_axi_min_ib_bw);
  717. }
  718. if (rc) {
  719. CAM_DBG(CAM_CPAS,
  720. "failed to read camnoc-axi-min-ib-bw rc:%d", rc);
  721. soc_private->camnoc_axi_min_ib_bw =
  722. CAM_CPAS_AXI_MIN_CAMNOC_IB_BW;
  723. }
  724. CAM_DBG(CAM_CPAS, "camnoc-axi-min-ib-bw = %llu",
  725. soc_private->camnoc_axi_min_ib_bw);
  726. soc_private->client_id_based = of_property_read_bool(of_node,
  727. "client-id-based");
  728. soc_private->bus_icc_based = of_property_read_bool(of_node,
  729. "interconnects");
  730. if (soc_private->bus_icc_based) {
  731. rc = of_property_read_string(of_node, "interconnect-names",
  732. &cpas_core->ahb_bus_client.common_data.name);
  733. if (rc) {
  734. CAM_ERR(CAM_CPAS,
  735. "device %s failed to read interconnect-names",
  736. pdev->name);
  737. return rc;
  738. }
  739. rc = of_parse_phandle_with_args(of_node, "interconnects",
  740. "#interconnect-cells", 0, &src_args);
  741. if (rc) {
  742. CAM_ERR(CAM_CPAS,
  743. "device %s failed to read ahb bus src info",
  744. pdev->name);
  745. return rc;
  746. }
  747. of_node_put(src_args.np);
  748. if (src_args.args_count != 1) {
  749. CAM_ERR(CAM_CPAS,
  750. "Invalid number of ahb src args: %d",
  751. src_args.args_count);
  752. return -EINVAL;
  753. }
  754. cpas_core->ahb_bus_client.common_data.src_id = src_args.args[0];
  755. rc = of_parse_phandle_with_args(of_node, "interconnects",
  756. "#interconnect-cells", 1, &dst_args);
  757. if (rc) {
  758. CAM_ERR(CAM_CPAS,
  759. "device %s failed to read ahb bus dst info",
  760. pdev->name);
  761. return rc;
  762. }
  763. of_node_put(dst_args.np);
  764. if (dst_args.args_count != 1) {
  765. CAM_ERR(CAM_CPAS,
  766. "Invalid number of ahb dst args: %d",
  767. dst_args.args_count);
  768. return -EINVAL;
  769. }
  770. cpas_core->ahb_bus_client.common_data.dst_id = dst_args.args[0];
  771. rc = of_property_read_u32(of_node, "cam-ahb-num-cases",
  772. &cpas_core->ahb_bus_client.common_data.num_usecases);
  773. if (rc) {
  774. CAM_ERR(CAM_CPAS,
  775. "device %s failed to read ahb num usecases",
  776. pdev->name);
  777. return rc;
  778. }
  779. if (cpas_core->ahb_bus_client.common_data.num_usecases >
  780. CAM_SOC_BUS_MAX_NUM_USECASES) {
  781. CAM_ERR(CAM_UTIL, "Invalid number of usecases: %d",
  782. cpas_core->ahb_bus_client.common_data
  783. .num_usecases);
  784. return -EINVAL;
  785. }
  786. num_bw_values = of_property_count_u32_elems(of_node,
  787. "cam-ahb-bw-KBps");
  788. if (num_bw_values <= 0) {
  789. CAM_ERR(CAM_UTIL, "Error counting ahb bw values");
  790. return -EINVAL;
  791. }
  792. CAM_DBG(CAM_CPAS, "AHB: num bw values %d", num_bw_values);
  793. num_levels = (num_bw_values / 2);
  794. if (num_levels !=
  795. cpas_core->ahb_bus_client.common_data.num_usecases) {
  796. CAM_ERR(CAM_UTIL, "Invalid number of levels: %d",
  797. num_bw_values/2);
  798. return -EINVAL;
  799. }
  800. for (i = 0; i < num_levels; i++) {
  801. rc = of_property_read_u32_index(of_node,
  802. "cam-ahb-bw-KBps",
  803. (i * 2),
  804. (uint32_t *) &cpas_core->ahb_bus_client
  805. .common_data.bw_pair[i].ab);
  806. if (rc) {
  807. CAM_ERR(CAM_UTIL,
  808. "Error reading ab bw value, rc=%d",
  809. rc);
  810. return rc;
  811. }
  812. rc = of_property_read_u32_index(of_node,
  813. "cam-ahb-bw-KBps",
  814. ((i * 2) + 1),
  815. (uint32_t *) &cpas_core->ahb_bus_client
  816. .common_data.bw_pair[i].ib);
  817. if (rc) {
  818. CAM_ERR(CAM_UTIL,
  819. "Error reading ib bw value, rc=%d",
  820. rc);
  821. return rc;
  822. }
  823. CAM_DBG(CAM_CPAS,
  824. "AHB: Level: %d, ab_value %llu, ib_value: %llu",
  825. i, cpas_core->ahb_bus_client.common_data
  826. .bw_pair[i].ab, cpas_core->ahb_bus_client
  827. .common_data.bw_pair[i].ib);
  828. }
  829. }
  830. count = of_property_count_strings(of_node, "client-names");
  831. if (count <= 0) {
  832. CAM_ERR(CAM_CPAS, "no client-names found");
  833. count = 0;
  834. return -EINVAL;
  835. } else if (count > CAM_CPAS_MAX_CLIENTS) {
  836. CAM_ERR(CAM_CPAS, "Number of clients %d greater than max %d",
  837. count, CAM_CPAS_MAX_CLIENTS);
  838. count = 0;
  839. return -EINVAL;
  840. }
  841. soc_private->num_clients = count;
  842. CAM_DBG(CAM_CPAS,
  843. "arch-compat=%s, client_id_based = %d, num_clients=%d",
  844. soc_private->arch_compat, soc_private->client_id_based,
  845. soc_private->num_clients);
  846. for (i = 0; i < soc_private->num_clients; i++) {
  847. rc = of_property_read_string_index(of_node,
  848. "client-names", i, &soc_private->client_name[i]);
  849. if (rc) {
  850. CAM_ERR(CAM_CPAS, "no client-name at cnt=%d", i);
  851. return -EINVAL;
  852. }
  853. cpas_core->cpas_client[i] =
  854. kzalloc(sizeof(struct cam_cpas_client), GFP_KERNEL);
  855. if (!cpas_core->cpas_client[i]) {
  856. rc = -ENOMEM;
  857. goto cleanup_clients;
  858. }
  859. CAM_DBG(CAM_CPAS, "Client[%d] : %s", i,
  860. soc_private->client_name[i]);
  861. }
  862. soc_private->control_camnoc_axi_clk = of_property_read_bool(of_node,
  863. "control-camnoc-axi-clk");
  864. if (soc_private->control_camnoc_axi_clk == true) {
  865. rc = of_property_read_u32(of_node, "camnoc-bus-width",
  866. &soc_private->camnoc_bus_width);
  867. if (rc || (soc_private->camnoc_bus_width == 0)) {
  868. CAM_ERR(CAM_CPAS, "Bus width not found rc=%d, %d",
  869. rc, soc_private->camnoc_bus_width);
  870. goto cleanup_clients;
  871. }
  872. rc = of_property_read_u32(of_node,
  873. "camnoc-axi-clk-bw-margin-perc",
  874. &soc_private->camnoc_axi_clk_bw_margin);
  875. if (rc) {
  876. /* this is not fatal, overwrite rc */
  877. rc = 0;
  878. soc_private->camnoc_axi_clk_bw_margin = 0;
  879. }
  880. }
  881. CAM_DBG(CAM_CPAS,
  882. "control_camnoc_axi_clk=%d, width=%d, margin=%d",
  883. soc_private->control_camnoc_axi_clk,
  884. soc_private->camnoc_bus_width,
  885. soc_private->camnoc_axi_clk_bw_margin);
  886. count = of_property_count_u32_elems(of_node, "vdd-corners");
  887. if ((count > 0) && (count <= CAM_REGULATOR_LEVEL_MAX) &&
  888. (of_property_count_strings(of_node, "vdd-corner-ahb-mapping") ==
  889. count)) {
  890. const char *ahb_string;
  891. for (i = 0; i < count; i++) {
  892. rc = of_property_read_u32_index(of_node, "vdd-corners",
  893. i, &soc_private->vdd_ahb[i].vdd_corner);
  894. if (rc) {
  895. CAM_ERR(CAM_CPAS,
  896. "vdd-corners failed at index=%d", i);
  897. rc = -ENODEV;
  898. goto cleanup_clients;
  899. }
  900. rc = of_property_read_string_index(of_node,
  901. "vdd-corner-ahb-mapping", i, &ahb_string);
  902. if (rc) {
  903. CAM_ERR(CAM_CPAS,
  904. "no ahb-mapping at index=%d", i);
  905. rc = -ENODEV;
  906. goto cleanup_clients;
  907. }
  908. rc = cam_soc_util_get_level_from_string(ahb_string,
  909. &soc_private->vdd_ahb[i].ahb_level);
  910. if (rc) {
  911. CAM_ERR(CAM_CPAS,
  912. "invalid ahb-string at index=%d", i);
  913. rc = -EINVAL;
  914. goto cleanup_clients;
  915. }
  916. CAM_DBG(CAM_CPAS,
  917. "Vdd-AHB mapping [%d] : [%d] [%s] [%d]", i,
  918. soc_private->vdd_ahb[i].vdd_corner,
  919. ahb_string, soc_private->vdd_ahb[i].ahb_level);
  920. }
  921. soc_private->num_vdd_ahb_mapping = count;
  922. }
  923. soc_private->enable_smart_qos = of_property_read_bool(of_node,
  924. "enable-smart-qos");
  925. if (soc_private->enable_smart_qos) {
  926. uint32_t value1, value2;
  927. soc_private->smart_qos_info = kzalloc(sizeof(struct cam_cpas_smart_qos_info),
  928. GFP_KERNEL);
  929. if (!soc_private->smart_qos_info) {
  930. rc = -ENOMEM;
  931. goto cleanup_clients;
  932. }
  933. /*
  934. * If enabled, we expect min and max priority values,
  935. * so treat as fatal error if not available.
  936. */
  937. rc = of_property_read_u32(of_node, "rt-wr-priority-min",
  938. &value1);
  939. if (rc) {
  940. CAM_ERR(CAM_CPAS, "Invalid min Qos priority rc %d", rc);
  941. goto cleanup_clients;
  942. }
  943. rc = of_property_read_u32(of_node, "rt-wr-priority-max",
  944. &value2);
  945. if (rc) {
  946. CAM_ERR(CAM_CPAS, "Invalid min Qos priority rc %d", rc);
  947. goto cleanup_clients;
  948. }
  949. soc_private->smart_qos_info->rt_wr_priority_min = (uint8_t)value1;
  950. soc_private->smart_qos_info->rt_wr_priority_max = (uint8_t)value2;
  951. CAM_DBG(CAM_CPAS,
  952. "SmartQoS enabled, rt_wr_priority_min=%u, rt_wr_priority_max=%u",
  953. (uint32_t)soc_private->smart_qos_info->rt_wr_priority_min,
  954. (uint32_t)soc_private->smart_qos_info->rt_wr_priority_max);
  955. } else {
  956. CAM_DBG(CAM_CPAS, "SmartQoS not enabled, use static settings");
  957. soc_private->smart_qos_info = NULL;
  958. }
  959. rc = cam_cpas_parse_node_tree(cpas_core, of_node, soc_private);
  960. if (rc) {
  961. CAM_ERR(CAM_CPAS, "Node tree parsing failed rc: %d", rc);
  962. goto cleanup_tree;
  963. }
  964. /* If SmartQoS is enabled, we expect few tags in dtsi, validate */
  965. if (soc_private->enable_smart_qos) {
  966. int port_idx;
  967. bool rt_port_exists = false;
  968. if ((soc_private->smart_qos_info->num_rt_wr_nius == 0) ||
  969. (soc_private->smart_qos_info->num_rt_wr_nius >
  970. CAM_CPAS_MAX_RT_WR_NIU_NODES)) {
  971. CAM_ERR(CAM_CPAS, "Invalid number of level1 nodes %d",
  972. soc_private->smart_qos_info->num_rt_wr_nius);
  973. rc = -EINVAL;
  974. goto cleanup_tree;
  975. }
  976. for (port_idx = 0; port_idx < cpas_core->num_axi_ports;
  977. port_idx++) {
  978. CAM_DBG(CAM_CPAS, "[%d] : Port[%s] is_rt=%d",
  979. port_idx, cpas_core->axi_port[port_idx].axi_port_name,
  980. cpas_core->axi_port[port_idx].is_rt);
  981. if (cpas_core->axi_port[port_idx].is_rt) {
  982. rt_port_exists = true;
  983. break;
  984. }
  985. }
  986. if (!rt_port_exists) {
  987. CAM_ERR(CAM_CPAS,
  988. "RT AXI port not tagged, num ports %d",
  989. cpas_core->num_axi_ports);
  990. rc = -EINVAL;
  991. goto cleanup_tree;
  992. }
  993. }
  994. /* Optional rpmh bcm info */
  995. count = of_property_count_u32_elems(of_node, "rpmh-bcm-info");
  996. /*
  997. * We expect count=5(CAM_RPMH_BCM_INFO_MAX) if valid rpmh bcm info
  998. * is available.
  999. * 0 - Total number of BCMs
  1000. * 1 - First BCM FE (front-end) register offset.
  1001. * These represent requested clk plan by sw
  1002. * 2 - First BCM BE (back-end) register offset.
  1003. * These represent actual clk plan at hw
  1004. * 3 - DDR BCM index
  1005. * 4 - MMNOC BCM index
  1006. */
  1007. if (count == CAM_RPMH_BCM_INFO_MAX) {
  1008. for (i = 0; i < count; i++) {
  1009. rc = of_property_read_u32_index(of_node,
  1010. "rpmh-bcm-info", i, &soc_private->rpmh_info[i]);
  1011. if (rc) {
  1012. CAM_ERR(CAM_CPAS,
  1013. "Incorrect rpmh info at %d, count=%d",
  1014. i, count);
  1015. break;
  1016. }
  1017. CAM_DBG(CAM_CPAS, "RPMH BCM Info [%d]=0x%x",
  1018. i, soc_private->rpmh_info[i]);
  1019. }
  1020. if (rc)
  1021. soc_private->rpmh_info[CAM_RPMH_NUMBER_OF_BCMS] = 0;
  1022. } else {
  1023. CAM_DBG(CAM_CPAS, "RPMH BCM info not available in DT, count=%d",
  1024. count);
  1025. }
  1026. /* check cache info */
  1027. rc = cam_cpas_parse_sys_cache_uids(of_node, soc_private);
  1028. if (rc)
  1029. goto cache_parse_fail;
  1030. return 0;
  1031. cache_parse_fail:
  1032. soc_private->rpmh_info[CAM_RPMH_NUMBER_OF_BCMS] = 0;
  1033. cleanup_tree:
  1034. cam_cpas_node_tree_cleanup(cpas_core, soc_private);
  1035. cleanup_clients:
  1036. cam_cpas_util_client_cleanup(cpas_hw);
  1037. return rc;
  1038. }
  1039. int cam_cpas_soc_init_resources(struct cam_hw_soc_info *soc_info,
  1040. irq_handler_t irq_handler, struct cam_hw_info *cpas_hw)
  1041. {
  1042. int rc = 0;
  1043. rc = cam_soc_util_get_dt_properties(soc_info);
  1044. if (rc) {
  1045. CAM_ERR(CAM_CPAS, "failed in get_dt_properties, rc=%d", rc);
  1046. return rc;
  1047. }
  1048. if (soc_info->irq_line && !irq_handler) {
  1049. CAM_ERR(CAM_CPAS, "Invalid IRQ handler");
  1050. return -EINVAL;
  1051. }
  1052. rc = cam_soc_util_request_platform_resource(soc_info, irq_handler,
  1053. cpas_hw);
  1054. if (rc) {
  1055. CAM_ERR(CAM_CPAS, "failed in request_platform_resource, rc=%d",
  1056. rc);
  1057. return rc;
  1058. }
  1059. soc_info->soc_private = kzalloc(sizeof(struct cam_cpas_private_soc),
  1060. GFP_KERNEL);
  1061. if (!soc_info->soc_private) {
  1062. rc = -ENOMEM;
  1063. goto release_res;
  1064. }
  1065. rc = cam_cpas_get_custom_dt_info(cpas_hw, soc_info->pdev,
  1066. soc_info->soc_private);
  1067. if (rc) {
  1068. CAM_ERR(CAM_CPAS, "failed in get_custom_info, rc=%d", rc);
  1069. goto free_soc_private;
  1070. }
  1071. return rc;
  1072. free_soc_private:
  1073. kfree(soc_info->soc_private);
  1074. release_res:
  1075. cam_soc_util_release_platform_resource(soc_info);
  1076. return rc;
  1077. }
  1078. int cam_cpas_soc_deinit_resources(struct cam_hw_soc_info *soc_info)
  1079. {
  1080. int rc, i;
  1081. struct cam_cpas_private_soc *soc_private = soc_info->soc_private;
  1082. for (i = 0; i < soc_private->num_caches; i++)
  1083. llcc_slice_putd(soc_private->llcc_info[i].slic_desc);
  1084. rc = cam_soc_util_release_platform_resource(soc_info);
  1085. if (rc)
  1086. CAM_ERR(CAM_CPAS, "release platform failed, rc=%d", rc);
  1087. kfree(soc_private->llcc_info);
  1088. kfree(soc_private->smart_qos_info);
  1089. kfree(soc_info->soc_private);
  1090. soc_info->soc_private = NULL;
  1091. return rc;
  1092. }
  1093. int cam_cpas_soc_enable_resources(struct cam_hw_soc_info *soc_info,
  1094. enum cam_vote_level default_level)
  1095. {
  1096. int rc = 0;
  1097. rc = cam_soc_util_enable_platform_resource(soc_info, true,
  1098. default_level, true);
  1099. if (rc)
  1100. CAM_ERR(CAM_CPAS, "enable platform resource failed, rc=%d", rc);
  1101. return rc;
  1102. }
  1103. int cam_cpas_soc_disable_resources(struct cam_hw_soc_info *soc_info,
  1104. bool disable_clocks, bool disable_irq)
  1105. {
  1106. int rc = 0;
  1107. rc = cam_soc_util_disable_platform_resource(soc_info,
  1108. disable_clocks, disable_irq);
  1109. if (rc)
  1110. CAM_ERR(CAM_CPAS, "disable platform failed, rc=%d", rc);
  1111. return rc;
  1112. }
  1113. int cam_cpas_soc_disable_irq(struct cam_hw_soc_info *soc_info)
  1114. {
  1115. int rc = 0;
  1116. rc = cam_soc_util_irq_disable(soc_info);
  1117. if (rc)
  1118. CAM_ERR(CAM_CPAS, "disable irq failed, rc=%d", rc);
  1119. return rc;
  1120. }