cam_compat.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/dma-mapping.h>
  7. #include <linux/dma-buf.h>
  8. #include <linux/of_address.h>
  9. #include <linux/slab.h>
  10. #include <soc/qcom/rpmh.h>
  11. #include "cam_compat.h"
  12. #include "cam_debug_util.h"
  13. #include "cam_cpas_api.h"
  14. #include "camera_main.h"
  15. #include "cam_eeprom_dev.h"
  16. #include "cam_eeprom_core.h"
  17. #if IS_ENABLED(CONFIG_USE_RPMH_DRV_API)
  18. #define CAM_RSC_DRV_IDENTIFIER "cam_rsc"
  19. const struct device *cam_cpas_get_rsc_dev_for_drv(uint32_t index)
  20. {
  21. const struct device *rsc_dev;
  22. rsc_dev = rpmh_get_device(CAM_RSC_DRV_IDENTIFIER, index);
  23. if (!rsc_dev) {
  24. CAM_ERR(CAM_CPAS, "Invalid dev for index: %u", index);
  25. return NULL;
  26. }
  27. return rsc_dev;
  28. }
  29. int cam_cpas_start_drv_for_dev(const struct device *dev)
  30. {
  31. int rc = 0;
  32. if (!dev) {
  33. CAM_ERR(CAM_CPAS, "Invalid dev for DRV enable");
  34. return -EINVAL;
  35. }
  36. rc = rpmh_drv_start(dev);
  37. if (rc) {
  38. CAM_ERR(CAM_CPAS, "[%s] Failed in DRV start", dev_name(dev));
  39. return rc;
  40. }
  41. return rc;
  42. }
  43. int cam_cpas_stop_drv_for_dev(const struct device *dev)
  44. {
  45. int rc = 0;
  46. if (!dev) {
  47. CAM_ERR(CAM_CPAS, "Invalid dev for DRV disable");
  48. return -EINVAL;
  49. }
  50. rc = rpmh_drv_stop(dev);
  51. if (rc) {
  52. CAM_ERR(CAM_CPAS, "[%s] Failed in DRV stop", dev_name(dev));
  53. return rc;
  54. }
  55. return rc;
  56. }
  57. int cam_cpas_drv_channel_switch_for_dev(const struct device *dev)
  58. {
  59. int rc = 0;
  60. if (!dev) {
  61. CAM_ERR(CAM_CPAS, "Invalid dev for DRV channel switch");
  62. return -EINVAL;
  63. }
  64. rc = rpmh_write_sleep_and_wake_no_child(dev);
  65. if (rc) {
  66. CAM_ERR(CAM_CPAS, "[%s] Failed in DRV channel switch", dev_name(dev));
  67. return rc;
  68. }
  69. return rc;
  70. }
  71. #else
  72. const struct device *cam_cpas_get_rsc_dev_for_drv(uint32_t index)
  73. {
  74. return NULL;
  75. }
  76. int cam_cpas_start_drv_for_dev(const struct device *dev)
  77. {
  78. return 0;
  79. }
  80. int cam_cpas_stop_drv_for_dev(const struct device *dev)
  81. {
  82. return 0;
  83. }
  84. int cam_cpas_drv_channel_switch_for_dev(const struct device *dev)
  85. {
  86. return 0;
  87. }
  88. #endif
  89. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
  90. int cam_reserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length)
  91. {
  92. int rc = 0;
  93. struct device_node *of_node;
  94. struct device_node *mem_node;
  95. struct resource res;
  96. of_node = (icp_fw->fw_dev)->of_node;
  97. mem_node = of_parse_phandle(of_node, "memory-region", 0);
  98. if (!mem_node) {
  99. rc = -ENOMEM;
  100. CAM_ERR(CAM_SMMU, "FW memory carveout not found");
  101. goto end;
  102. }
  103. rc = of_address_to_resource(mem_node, 0, &res);
  104. of_node_put(mem_node);
  105. if (rc < 0) {
  106. CAM_ERR(CAM_SMMU, "Unable to get start of FW mem carveout");
  107. goto end;
  108. }
  109. icp_fw->fw_hdl = res.start;
  110. icp_fw->fw_kva = ioremap_wc(icp_fw->fw_hdl, fw_length);
  111. if (!icp_fw->fw_kva) {
  112. CAM_ERR(CAM_SMMU, "Failed to map the FW.");
  113. rc = -ENOMEM;
  114. goto end;
  115. }
  116. memset_io(icp_fw->fw_kva, 0, fw_length);
  117. end:
  118. return rc;
  119. }
  120. void cam_unreserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length)
  121. {
  122. iounmap(icp_fw->fw_kva);
  123. }
  124. int cam_ife_notify_safe_lut_scm(bool safe_trigger)
  125. {
  126. const uint32_t smmu_se_ife = 0;
  127. uint32_t camera_hw_version, rc = 0;
  128. rc = cam_cpas_get_cpas_hw_version(&camera_hw_version);
  129. if (!rc && qcom_scm_smmu_notify_secure_lut(smmu_se_ife, safe_trigger)) {
  130. switch (camera_hw_version) {
  131. case CAM_CPAS_TITAN_170_V100:
  132. case CAM_CPAS_TITAN_170_V110:
  133. case CAM_CPAS_TITAN_175_V100:
  134. CAM_ERR(CAM_ISP, "scm call to enable safe failed");
  135. rc = -EINVAL;
  136. break;
  137. default:
  138. break;
  139. }
  140. }
  141. return rc;
  142. }
  143. int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev,
  144. bool protect, int32_t offset)
  145. {
  146. int rc = 0;
  147. if (offset >= CSIPHY_MAX_INSTANCES_PER_PHY) {
  148. CAM_ERR(CAM_CSIPHY, "Invalid CSIPHY offset");
  149. rc = -EINVAL;
  150. } else if (qcom_scm_camera_protect_phy_lanes(protect,
  151. csiphy_dev->csiphy_info[offset].csiphy_cpas_cp_reg_mask)) {
  152. CAM_ERR(CAM_CSIPHY, "SCM call to hypervisor failed");
  153. rc = -EINVAL;
  154. }
  155. return rc;
  156. }
  157. void cam_cpastop_scm_write(struct cam_cpas_hw_errata_wa *errata_wa)
  158. {
  159. int reg_val;
  160. qcom_scm_io_readl(errata_wa->data.reg_info.offset, &reg_val);
  161. reg_val |= errata_wa->data.reg_info.value;
  162. qcom_scm_io_writel(errata_wa->data.reg_info.offset, reg_val);
  163. }
  164. static int camera_platform_compare_dev(struct device *dev, const void *data)
  165. {
  166. return platform_bus_type.match(dev, (struct device_driver *) data);
  167. }
  168. static int camera_i2c_compare_dev(struct device *dev, const void *data)
  169. {
  170. return i2c_bus_type.match(dev, (struct device_driver *) data);
  171. }
  172. #else
  173. int cam_reserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length)
  174. {
  175. int rc = 0;
  176. icp_fw->fw_kva = dma_alloc_coherent(icp_fw->fw_dev, fw_length,
  177. &icp_fw->fw_hdl, GFP_KERNEL);
  178. if (!icp_fw->fw_kva) {
  179. CAM_ERR(CAM_SMMU, "FW memory alloc failed");
  180. rc = -ENOMEM;
  181. }
  182. return rc;
  183. }
  184. void cam_unreserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length)
  185. {
  186. dma_free_coherent(icp_fw->fw_dev, fw_length, icp_fw->fw_kva,
  187. icp_fw->fw_hdl);
  188. }
  189. int cam_ife_notify_safe_lut_scm(bool safe_trigger)
  190. {
  191. const uint32_t smmu_se_ife = 0;
  192. uint32_t camera_hw_version, rc = 0;
  193. struct scm_desc description = {
  194. .arginfo = SCM_ARGS(2, SCM_VAL, SCM_VAL),
  195. .args[0] = smmu_se_ife,
  196. .args[1] = safe_trigger,
  197. };
  198. rc = cam_cpas_get_cpas_hw_version(&camera_hw_version);
  199. if (!rc && scm_call2(SCM_SIP_FNID(0x15, 0x3), &description)) {
  200. switch (camera_hw_version) {
  201. case CAM_CPAS_TITAN_170_V100:
  202. case CAM_CPAS_TITAN_170_V110:
  203. case CAM_CPAS_TITAN_175_V100:
  204. CAM_ERR(CAM_ISP, "scm call to enable safe failed");
  205. rc = -EINVAL;
  206. break;
  207. default:
  208. break;
  209. }
  210. }
  211. return rc;
  212. }
  213. int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev,
  214. bool protect, int32_t offset)
  215. {
  216. int rc = 0;
  217. struct scm_desc description = {
  218. .arginfo = SCM_ARGS(2, SCM_VAL, SCM_VAL),
  219. .args[0] = protect,
  220. .args[1] = csiphy_dev->csiphy_info[offset]
  221. .csiphy_cpas_cp_reg_mask,
  222. };
  223. if (offset >= CSIPHY_MAX_INSTANCES_PER_PHY) {
  224. CAM_ERR(CAM_CSIPHY, "Invalid CSIPHY offset");
  225. rc = -EINVAL;
  226. } else if (scm_call2(SCM_SIP_FNID(0x18, 0x7), &description)) {
  227. CAM_ERR(CAM_CSIPHY, "SCM call to hypervisor failed");
  228. rc = -EINVAL;
  229. }
  230. return rc;
  231. }
  232. void cam_cpastop_scm_write(struct cam_cpas_hw_errata_wa *errata_wa)
  233. {
  234. int reg_val;
  235. reg_val = scm_io_read(errata_wa->data.reg_info.offset);
  236. reg_val |= errata_wa->data.reg_info.value;
  237. scm_io_write(errata_wa->data.reg_info.offset, reg_val);
  238. }
  239. static int camera_platform_compare_dev(struct device *dev, void *data)
  240. {
  241. return platform_bus_type.match(dev, (struct device_driver *) data);
  242. }
  243. static int camera_i2c_compare_dev(struct device *dev, void *data)
  244. {
  245. return i2c_bus_type.match(dev, (struct device_driver *) data);
  246. }
  247. #endif
  248. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
  249. void cam_free_clear(const void * ptr)
  250. {
  251. kfree_sensitive(ptr);
  252. }
  253. #else
  254. void cam_free_clear(const void * ptr)
  255. {
  256. kzfree(ptr);
  257. }
  258. #endif
  259. /* Callback to compare device from match list before adding as component */
  260. static inline int camera_component_compare_dev(struct device *dev, void *data)
  261. {
  262. return dev == data;
  263. }
  264. /* Add component matches to list for master of aggregate driver */
  265. int camera_component_match_add_drivers(struct device *master_dev,
  266. struct component_match **match_list)
  267. {
  268. int i, rc = 0;
  269. struct platform_device *pdev = NULL;
  270. struct i2c_client *client = NULL;
  271. struct device *start_dev = NULL, *match_dev = NULL;
  272. if (!master_dev || !match_list) {
  273. CAM_ERR(CAM_UTIL, "Invalid parameters for component match add");
  274. rc = -EINVAL;
  275. goto end;
  276. }
  277. for (i = 0; i < ARRAY_SIZE(cam_component_platform_drivers); i++) {
  278. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
  279. struct device_driver const *drv =
  280. &cam_component_platform_drivers[i]->driver;
  281. const void *drv_ptr = (const void *)drv;
  282. #else
  283. struct device_driver *drv = &cam_component_platform_drivers[i]->driver;
  284. void *drv_ptr = (void *)drv;
  285. #endif
  286. start_dev = NULL;
  287. while ((match_dev = bus_find_device(&platform_bus_type,
  288. start_dev, drv_ptr, &camera_platform_compare_dev))) {
  289. put_device(start_dev);
  290. pdev = to_platform_device(match_dev);
  291. CAM_DBG(CAM_UTIL, "Adding matched component:%s", pdev->name);
  292. component_match_add(master_dev, match_list,
  293. camera_component_compare_dev, match_dev);
  294. start_dev = match_dev;
  295. }
  296. put_device(start_dev);
  297. }
  298. for (i = 0; i < ARRAY_SIZE(cam_component_i2c_drivers); i++) {
  299. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
  300. struct device_driver const *drv =
  301. &cam_component_i2c_drivers[i]->driver;
  302. const void *drv_ptr = (const void *)drv;
  303. #else
  304. struct device_driver *drv = &cam_component_i2c_drivers[i]->driver;
  305. void *drv_ptr = (void *)drv;
  306. #endif
  307. start_dev = NULL;
  308. while ((match_dev = bus_find_device(&i2c_bus_type,
  309. start_dev, drv_ptr, &camera_i2c_compare_dev))) {
  310. put_device(start_dev);
  311. client = to_i2c_client(match_dev);
  312. CAM_DBG(CAM_UTIL, "Adding matched component:%s", client->name);
  313. component_match_add(master_dev, match_list,
  314. camera_component_compare_dev, match_dev);
  315. start_dev = match_dev;
  316. }
  317. put_device(start_dev);
  318. }
  319. end:
  320. return rc;
  321. }
  322. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
  323. #include <linux/qcom-iommu-util.h>
  324. void cam_check_iommu_faults(struct iommu_domain *domain,
  325. struct cam_smmu_pf_info *pf_info)
  326. {
  327. struct qcom_iommu_fault_ids fault_ids = {0, 0, 0};
  328. if (qcom_iommu_get_fault_ids(domain, &fault_ids))
  329. CAM_ERR(CAM_SMMU, "Cannot get smmu fault ids");
  330. else
  331. CAM_ERR(CAM_SMMU, "smmu fault ids bid:%d pid:%d mid:%d",
  332. fault_ids.bid, fault_ids.pid, fault_ids.mid);
  333. pf_info->bid = fault_ids.bid;
  334. pf_info->pid = fault_ids.pid;
  335. pf_info->mid = fault_ids.mid;
  336. }
  337. #else
  338. void cam_check_iommu_faults(struct iommu_domain *domain,
  339. struct cam_smmu_pf_info *pf_info)
  340. {
  341. struct iommu_fault_ids fault_ids = {0, 0, 0};
  342. if (iommu_get_fault_ids(domain, &fault_ids))
  343. CAM_ERR(CAM_SMMU, "Error: Can not get smmu fault ids");
  344. CAM_ERR(CAM_SMMU, "smmu fault ids bid:%d pid:%d mid:%d",
  345. fault_ids.bid, fault_ids.pid, fault_ids.mid);
  346. pf_info->bid = fault_ids.bid;
  347. pf_info->pid = fault_ids.pid;
  348. pf_info->mid = fault_ids.mid;
  349. }
  350. #endif
  351. static int inline cam_subdev_list_cmp(struct cam_subdev *entry_1, struct cam_subdev *entry_2)
  352. {
  353. if (entry_1->close_seq_prior > entry_2->close_seq_prior)
  354. return 1;
  355. else if (entry_1->close_seq_prior < entry_2->close_seq_prior)
  356. return -1;
  357. else
  358. return 0;
  359. }
  360. #if (KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE)
  361. int cam_compat_util_get_dmabuf_va(struct dma_buf *dmabuf, uintptr_t *vaddr)
  362. {
  363. struct iosys_map mapping;
  364. int error_code = dma_buf_vmap(dmabuf, &mapping);
  365. if (error_code) {
  366. *vaddr = 0;
  367. } else {
  368. *vaddr = (mapping.is_iomem) ?
  369. (uintptr_t)mapping.vaddr_iomem : (uintptr_t)mapping.vaddr;
  370. CAM_DBG(CAM_MEM,
  371. "dmabuf=%p, *vaddr=%p, is_iomem=%d, vaddr_iomem=%p, vaddr=%p",
  372. dmabuf, *vaddr, mapping.is_iomem, mapping.vaddr_iomem, mapping.vaddr);
  373. }
  374. return error_code;
  375. }
  376. void cam_compat_util_put_dmabuf_va(struct dma_buf *dmabuf, void *vaddr)
  377. {
  378. struct iosys_map mapping = IOSYS_MAP_INIT_VADDR(vaddr);
  379. dma_buf_vunmap(dmabuf, &mapping);
  380. }
  381. #elif (KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE)
  382. int cam_compat_util_get_dmabuf_va(struct dma_buf *dmabuf, uintptr_t *vaddr)
  383. {
  384. struct dma_buf_map mapping;
  385. int error_code = dma_buf_vmap(dmabuf, &mapping);
  386. if (error_code) {
  387. *vaddr = 0;
  388. } else {
  389. *vaddr = (mapping.is_iomem) ?
  390. (uintptr_t)mapping.vaddr_iomem : (uintptr_t)mapping.vaddr;
  391. CAM_DBG(CAM_MEM,
  392. "dmabuf=%p, *vaddr=%p, is_iomem=%d, vaddr_iomem=%p, vaddr=%p",
  393. dmabuf, *vaddr, mapping.is_iomem, mapping.vaddr_iomem, mapping.vaddr);
  394. }
  395. return error_code;
  396. }
  397. void cam_compat_util_put_dmabuf_va(struct dma_buf *dmabuf, void *vaddr)
  398. {
  399. struct dma_buf_map mapping = DMA_BUF_MAP_INIT_VADDR(vaddr);
  400. dma_buf_vunmap(dmabuf, &mapping);
  401. }
  402. #else
  403. int cam_compat_util_get_dmabuf_va(struct dma_buf *dmabuf, uintptr_t *vaddr)
  404. {
  405. int error_code = 0;
  406. void *addr = dma_buf_vmap(dmabuf);
  407. if (!addr) {
  408. *vaddr = 0;
  409. error_code = -ENOSPC;
  410. } else {
  411. *vaddr = (uintptr_t)addr;
  412. }
  413. return error_code;
  414. }
  415. void cam_compat_util_put_dmabuf_va(struct dma_buf *dmabuf, void *vaddr)
  416. {
  417. dma_buf_vunmap(dmabuf, vaddr);
  418. }
  419. #endif
  420. #if (KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE)
  421. void cam_smmu_util_iommu_custom(struct device *dev,
  422. dma_addr_t discard_start, size_t discard_length)
  423. {
  424. }
  425. int cam_req_mgr_ordered_list_cmp(void *priv,
  426. const struct list_head *head_1, const struct list_head *head_2)
  427. {
  428. return cam_subdev_list_cmp(list_entry(head_1, struct cam_subdev, list),
  429. list_entry(head_2, struct cam_subdev, list));
  430. }
  431. void cam_i3c_driver_remove(struct i3c_device *client)
  432. {
  433. CAM_DBG(CAM_SENSOR, "I3C remove invoked for %s",
  434. (client ? dev_name(&client->dev) : "none"));
  435. }
  436. #else
  437. void cam_smmu_util_iommu_custom(struct device *dev,
  438. dma_addr_t discard_start, size_t discard_length)
  439. {
  440. iommu_dma_enable_best_fit_algo(dev);
  441. if (discard_start)
  442. iommu_dma_reserve_iova(dev, discard_start, discard_length);
  443. return;
  444. }
  445. int cam_req_mgr_ordered_list_cmp(void *priv,
  446. struct list_head *head_1, struct list_head *head_2)
  447. {
  448. return cam_subdev_list_cmp(list_entry(head_1, struct cam_subdev, list),
  449. list_entry(head_2, struct cam_subdev, list));
  450. }
  451. int cam_i3c_driver_remove(struct i3c_device *client)
  452. {
  453. CAM_DBG(CAM_SENSOR, "I3C remove invoked for %s",
  454. (client ? dev_name(&client->dev) : "none"));
  455. return 0;
  456. }
  457. #endif
  458. #if (KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE && \
  459. KERNEL_VERSION(5, 18, 0) > LINUX_VERSION_CODE)
  460. long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name)
  461. {
  462. long ret = 0;
  463. ret = dma_buf_set_name(dmabuf, name);
  464. return ret;
  465. }
  466. #else
  467. long cam_dma_buf_set_name(struct dma_buf *dmabuf, const char *name)
  468. {
  469. return 0;
  470. }
  471. #endif
  472. #if KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE
  473. void cam_eeprom_spi_driver_remove(struct spi_device *sdev)
  474. {
  475. struct v4l2_subdev *sd = spi_get_drvdata(sdev);
  476. struct cam_eeprom_ctrl_t *e_ctrl;
  477. struct cam_eeprom_soc_private *soc_private;
  478. struct cam_hw_soc_info *soc_info;
  479. if (!sd) {
  480. CAM_ERR(CAM_EEPROM, "Subdevice is NULL");
  481. return;
  482. }
  483. e_ctrl = (struct cam_eeprom_ctrl_t *)v4l2_get_subdevdata(sd);
  484. if (!e_ctrl) {
  485. CAM_ERR(CAM_EEPROM, "eeprom device is NULL");
  486. return;
  487. }
  488. soc_info = &e_ctrl->soc_info;
  489. mutex_lock(&(e_ctrl->eeprom_mutex));
  490. cam_eeprom_shutdown(e_ctrl);
  491. mutex_unlock(&(e_ctrl->eeprom_mutex));
  492. mutex_destroy(&(e_ctrl->eeprom_mutex));
  493. cam_unregister_subdev(&(e_ctrl->v4l2_dev_str));
  494. kfree(e_ctrl->io_master_info.spi_client);
  495. e_ctrl->io_master_info.spi_client = NULL;
  496. soc_private =
  497. (struct cam_eeprom_soc_private *)e_ctrl->soc_info.soc_private;
  498. if (soc_private) {
  499. kfree(soc_private->power_info.gpio_num_info);
  500. soc_private->power_info.gpio_num_info = NULL;
  501. kfree(soc_private);
  502. soc_private = NULL;
  503. }
  504. v4l2_set_subdevdata(&e_ctrl->v4l2_dev_str.sd, NULL);
  505. kfree(e_ctrl);
  506. }
  507. int cam_compat_util_get_irq(struct cam_hw_soc_info *soc_info)
  508. {
  509. int rc = 0;
  510. soc_info->irq_num = platform_get_irq(soc_info->pdev, 0);
  511. if (soc_info->irq_num < 0) {
  512. rc = soc_info->irq_num;
  513. return rc;
  514. }
  515. return rc;
  516. }
  517. #else
  518. int cam_eeprom_spi_driver_remove(struct spi_device *sdev)
  519. {
  520. struct v4l2_subdev *sd = spi_get_drvdata(sdev);
  521. struct cam_eeprom_ctrl_t *e_ctrl;
  522. struct cam_eeprom_soc_private *soc_private;
  523. struct cam_hw_soc_info *soc_info;
  524. if (!sd) {
  525. CAM_ERR(CAM_EEPROM, "Subdevice is NULL");
  526. return -EINVAL;
  527. }
  528. e_ctrl = (struct cam_eeprom_ctrl_t *)v4l2_get_subdevdata(sd);
  529. if (!e_ctrl) {
  530. CAM_ERR(CAM_EEPROM, "eeprom device is NULL");
  531. return -EINVAL;
  532. }
  533. soc_info = &e_ctrl->soc_info;
  534. mutex_lock(&(e_ctrl->eeprom_mutex));
  535. cam_eeprom_shutdown(e_ctrl);
  536. mutex_unlock(&(e_ctrl->eeprom_mutex));
  537. mutex_destroy(&(e_ctrl->eeprom_mutex));
  538. cam_unregister_subdev(&(e_ctrl->v4l2_dev_str));
  539. kfree(e_ctrl->io_master_info.spi_client);
  540. e_ctrl->io_master_info.spi_client = NULL;
  541. soc_private =
  542. (struct cam_eeprom_soc_private *)e_ctrl->soc_info.soc_private;
  543. if (soc_private) {
  544. kfree(soc_private->power_info.gpio_num_info);
  545. soc_private->power_info.gpio_num_info = NULL;
  546. kfree(soc_private);
  547. soc_private = NULL;
  548. }
  549. v4l2_set_subdevdata(&e_ctrl->v4l2_dev_str.sd, NULL);
  550. kfree(e_ctrl);
  551. return 0;
  552. }
  553. int cam_compat_util_get_irq(struct cam_hw_soc_info *soc_info)
  554. {
  555. int rc = 0;
  556. soc_info->irq_line =
  557. platform_get_resource_byname(soc_info->pdev,
  558. IORESOURCE_IRQ, soc_info->irq_name);
  559. if (!soc_info->irq_line) {
  560. rc = -ENODEV;
  561. return rc;
  562. }
  563. soc_info->irq_num = soc_info->irq_line->start;
  564. return rc;
  565. }
  566. #endif