ufshcd-pci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Universal Flash Storage Host controller PCI glue driver
  4. *
  5. * Copyright (C) 2011-2013 Samsung India Software Operations
  6. *
  7. * Authors:
  8. * Santosh Yaraganavi <santosh.sy@samsung.com>
  9. * Vinayak Holikatti <h.vinayak@samsung.com>
  10. */
  11. #include <ufs/ufshcd.h>
  12. #include <linux/delay.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/pm_qos.h>
  17. #include <linux/debugfs.h>
  18. #include <linux/uuid.h>
  19. #include <linux/acpi.h>
  20. #include <linux/gpio/consumer.h>
  21. #define MAX_SUPP_MAC 64
  22. struct ufs_host {
  23. void (*late_init)(struct ufs_hba *hba);
  24. };
  25. enum intel_ufs_dsm_func_id {
  26. INTEL_DSM_FNS = 0,
  27. INTEL_DSM_RESET = 1,
  28. };
  29. struct intel_host {
  30. struct ufs_host ufs_host;
  31. u32 dsm_fns;
  32. u32 active_ltr;
  33. u32 idle_ltr;
  34. struct dentry *debugfs_root;
  35. struct gpio_desc *reset_gpio;
  36. };
  37. static const guid_t intel_dsm_guid =
  38. GUID_INIT(0x1A4832A0, 0x7D03, 0x43CA,
  39. 0xB0, 0x20, 0xF6, 0xDC, 0xD1, 0x2A, 0x19, 0x50);
  40. static bool __intel_dsm_supported(struct intel_host *host,
  41. enum intel_ufs_dsm_func_id fn)
  42. {
  43. return fn < 32 && fn >= 0 && (host->dsm_fns & (1u << fn));
  44. }
  45. #define INTEL_DSM_SUPPORTED(host, name) \
  46. __intel_dsm_supported(host, INTEL_DSM_##name)
  47. static int __intel_dsm(struct intel_host *intel_host, struct device *dev,
  48. unsigned int fn, u32 *result)
  49. {
  50. union acpi_object *obj;
  51. int err = 0;
  52. size_t len;
  53. obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(dev), &intel_dsm_guid, 0, fn, NULL,
  54. ACPI_TYPE_BUFFER);
  55. if (!obj)
  56. return -EOPNOTSUPP;
  57. if (obj->buffer.length < 1) {
  58. err = -EINVAL;
  59. goto out;
  60. }
  61. len = min_t(size_t, obj->buffer.length, 4);
  62. *result = 0;
  63. memcpy(result, obj->buffer.pointer, len);
  64. out:
  65. ACPI_FREE(obj);
  66. return err;
  67. }
  68. static int intel_dsm(struct intel_host *intel_host, struct device *dev,
  69. unsigned int fn, u32 *result)
  70. {
  71. if (!__intel_dsm_supported(intel_host, fn))
  72. return -EOPNOTSUPP;
  73. return __intel_dsm(intel_host, dev, fn, result);
  74. }
  75. static void intel_dsm_init(struct intel_host *intel_host, struct device *dev)
  76. {
  77. int err;
  78. err = __intel_dsm(intel_host, dev, INTEL_DSM_FNS, &intel_host->dsm_fns);
  79. dev_dbg(dev, "DSM fns %#x, error %d\n", intel_host->dsm_fns, err);
  80. }
  81. static int ufs_intel_hce_enable_notify(struct ufs_hba *hba,
  82. enum ufs_notify_change_status status)
  83. {
  84. /* Cannot enable ICE until after HC enable */
  85. if (status == POST_CHANGE && hba->caps & UFSHCD_CAP_CRYPTO) {
  86. u32 hce = ufshcd_readl(hba, REG_CONTROLLER_ENABLE);
  87. hce |= CRYPTO_GENERAL_ENABLE;
  88. ufshcd_writel(hba, hce, REG_CONTROLLER_ENABLE);
  89. }
  90. return 0;
  91. }
  92. static int ufs_intel_disable_lcc(struct ufs_hba *hba)
  93. {
  94. u32 attr = UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE);
  95. u32 lcc_enable = 0;
  96. ufshcd_dme_get(hba, attr, &lcc_enable);
  97. if (lcc_enable)
  98. ufshcd_disable_host_tx_lcc(hba);
  99. return 0;
  100. }
  101. static int ufs_intel_link_startup_notify(struct ufs_hba *hba,
  102. enum ufs_notify_change_status status)
  103. {
  104. int err = 0;
  105. switch (status) {
  106. case PRE_CHANGE:
  107. err = ufs_intel_disable_lcc(hba);
  108. break;
  109. case POST_CHANGE:
  110. break;
  111. default:
  112. break;
  113. }
  114. return err;
  115. }
  116. static int ufs_intel_set_lanes(struct ufs_hba *hba, u32 lanes)
  117. {
  118. struct ufs_pa_layer_attr pwr_info = hba->pwr_info;
  119. int ret;
  120. pwr_info.lane_rx = lanes;
  121. pwr_info.lane_tx = lanes;
  122. ret = ufshcd_config_pwr_mode(hba, &pwr_info);
  123. if (ret)
  124. dev_err(hba->dev, "%s: Setting %u lanes, err = %d\n",
  125. __func__, lanes, ret);
  126. return ret;
  127. }
  128. static int ufs_intel_lkf_pwr_change_notify(struct ufs_hba *hba,
  129. enum ufs_notify_change_status status,
  130. struct ufs_pa_layer_attr *dev_max_params,
  131. struct ufs_pa_layer_attr *dev_req_params)
  132. {
  133. int err = 0;
  134. switch (status) {
  135. case PRE_CHANGE:
  136. if (ufshcd_is_hs_mode(dev_max_params) &&
  137. (hba->pwr_info.lane_rx != 2 || hba->pwr_info.lane_tx != 2))
  138. ufs_intel_set_lanes(hba, 2);
  139. memcpy(dev_req_params, dev_max_params, sizeof(*dev_req_params));
  140. break;
  141. case POST_CHANGE:
  142. if (ufshcd_is_hs_mode(dev_req_params)) {
  143. u32 peer_granularity;
  144. usleep_range(1000, 1250);
  145. err = ufshcd_dme_peer_get(hba, UIC_ARG_MIB(PA_GRANULARITY),
  146. &peer_granularity);
  147. }
  148. break;
  149. default:
  150. break;
  151. }
  152. return err;
  153. }
  154. static int ufs_intel_lkf_apply_dev_quirks(struct ufs_hba *hba)
  155. {
  156. u32 granularity, peer_granularity;
  157. u32 pa_tactivate, peer_pa_tactivate;
  158. int ret;
  159. ret = ufshcd_dme_get(hba, UIC_ARG_MIB(PA_GRANULARITY), &granularity);
  160. if (ret)
  161. goto out;
  162. ret = ufshcd_dme_peer_get(hba, UIC_ARG_MIB(PA_GRANULARITY), &peer_granularity);
  163. if (ret)
  164. goto out;
  165. ret = ufshcd_dme_get(hba, UIC_ARG_MIB(PA_TACTIVATE), &pa_tactivate);
  166. if (ret)
  167. goto out;
  168. ret = ufshcd_dme_peer_get(hba, UIC_ARG_MIB(PA_TACTIVATE), &peer_pa_tactivate);
  169. if (ret)
  170. goto out;
  171. if (granularity == peer_granularity) {
  172. u32 new_peer_pa_tactivate = pa_tactivate + 2;
  173. ret = ufshcd_dme_peer_set(hba, UIC_ARG_MIB(PA_TACTIVATE), new_peer_pa_tactivate);
  174. }
  175. out:
  176. return ret;
  177. }
  178. static void ufs_intel_ctrl_uic_compl(struct ufs_hba *hba, bool enable)
  179. {
  180. u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
  181. if (enable)
  182. set |= UIC_COMMAND_COMPL;
  183. else
  184. set &= ~UIC_COMMAND_COMPL;
  185. ufshcd_writel(hba, set, REG_INTERRUPT_ENABLE);
  186. }
  187. static void ufs_intel_mtl_h8_notify(struct ufs_hba *hba,
  188. enum uic_cmd_dme cmd,
  189. enum ufs_notify_change_status status)
  190. {
  191. /*
  192. * Disable UIC COMPL INTR to prevent access to UFSHCI after
  193. * checking HCS.UPMCRS
  194. */
  195. if (status == PRE_CHANGE && cmd == UIC_CMD_DME_HIBER_ENTER)
  196. ufs_intel_ctrl_uic_compl(hba, false);
  197. if (status == POST_CHANGE && cmd == UIC_CMD_DME_HIBER_EXIT)
  198. ufs_intel_ctrl_uic_compl(hba, true);
  199. }
  200. #define INTEL_ACTIVELTR 0x804
  201. #define INTEL_IDLELTR 0x808
  202. #define INTEL_LTR_REQ BIT(15)
  203. #define INTEL_LTR_SCALE_MASK GENMASK(11, 10)
  204. #define INTEL_LTR_SCALE_1US (2 << 10)
  205. #define INTEL_LTR_SCALE_32US (3 << 10)
  206. #define INTEL_LTR_VALUE_MASK GENMASK(9, 0)
  207. static void intel_cache_ltr(struct ufs_hba *hba)
  208. {
  209. struct intel_host *host = ufshcd_get_variant(hba);
  210. host->active_ltr = readl(hba->mmio_base + INTEL_ACTIVELTR);
  211. host->idle_ltr = readl(hba->mmio_base + INTEL_IDLELTR);
  212. }
  213. static void intel_ltr_set(struct device *dev, s32 val)
  214. {
  215. struct ufs_hba *hba = dev_get_drvdata(dev);
  216. struct intel_host *host = ufshcd_get_variant(hba);
  217. u32 ltr;
  218. pm_runtime_get_sync(dev);
  219. /*
  220. * Program latency tolerance (LTR) accordingly what has been asked
  221. * by the PM QoS layer or disable it in case we were passed
  222. * negative value or PM_QOS_LATENCY_ANY.
  223. */
  224. ltr = readl(hba->mmio_base + INTEL_ACTIVELTR);
  225. if (val == PM_QOS_LATENCY_ANY || val < 0) {
  226. ltr &= ~INTEL_LTR_REQ;
  227. } else {
  228. ltr |= INTEL_LTR_REQ;
  229. ltr &= ~INTEL_LTR_SCALE_MASK;
  230. ltr &= ~INTEL_LTR_VALUE_MASK;
  231. if (val > INTEL_LTR_VALUE_MASK) {
  232. val >>= 5;
  233. if (val > INTEL_LTR_VALUE_MASK)
  234. val = INTEL_LTR_VALUE_MASK;
  235. ltr |= INTEL_LTR_SCALE_32US | val;
  236. } else {
  237. ltr |= INTEL_LTR_SCALE_1US | val;
  238. }
  239. }
  240. if (ltr == host->active_ltr)
  241. goto out;
  242. writel(ltr, hba->mmio_base + INTEL_ACTIVELTR);
  243. writel(ltr, hba->mmio_base + INTEL_IDLELTR);
  244. /* Cache the values into intel_host structure */
  245. intel_cache_ltr(hba);
  246. out:
  247. pm_runtime_put(dev);
  248. }
  249. static void intel_ltr_expose(struct device *dev)
  250. {
  251. dev->power.set_latency_tolerance = intel_ltr_set;
  252. dev_pm_qos_expose_latency_tolerance(dev);
  253. }
  254. static void intel_ltr_hide(struct device *dev)
  255. {
  256. dev_pm_qos_hide_latency_tolerance(dev);
  257. dev->power.set_latency_tolerance = NULL;
  258. }
  259. static void intel_add_debugfs(struct ufs_hba *hba)
  260. {
  261. struct dentry *dir = debugfs_create_dir(dev_name(hba->dev), NULL);
  262. struct intel_host *host = ufshcd_get_variant(hba);
  263. intel_cache_ltr(hba);
  264. host->debugfs_root = dir;
  265. debugfs_create_x32("active_ltr", 0444, dir, &host->active_ltr);
  266. debugfs_create_x32("idle_ltr", 0444, dir, &host->idle_ltr);
  267. }
  268. static void intel_remove_debugfs(struct ufs_hba *hba)
  269. {
  270. struct intel_host *host = ufshcd_get_variant(hba);
  271. debugfs_remove_recursive(host->debugfs_root);
  272. }
  273. static int ufs_intel_device_reset(struct ufs_hba *hba)
  274. {
  275. struct intel_host *host = ufshcd_get_variant(hba);
  276. if (INTEL_DSM_SUPPORTED(host, RESET)) {
  277. u32 result = 0;
  278. int err;
  279. err = intel_dsm(host, hba->dev, INTEL_DSM_RESET, &result);
  280. if (!err && !result)
  281. err = -EIO;
  282. if (err)
  283. dev_err(hba->dev, "%s: DSM error %d result %u\n",
  284. __func__, err, result);
  285. return err;
  286. }
  287. if (!host->reset_gpio)
  288. return -EOPNOTSUPP;
  289. gpiod_set_value_cansleep(host->reset_gpio, 1);
  290. usleep_range(10, 15);
  291. gpiod_set_value_cansleep(host->reset_gpio, 0);
  292. usleep_range(10, 15);
  293. return 0;
  294. }
  295. static struct gpio_desc *ufs_intel_get_reset_gpio(struct device *dev)
  296. {
  297. /* GPIO in _DSD has active low setting */
  298. return devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
  299. }
  300. static int ufs_intel_common_init(struct ufs_hba *hba)
  301. {
  302. struct intel_host *host;
  303. hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
  304. host = devm_kzalloc(hba->dev, sizeof(*host), GFP_KERNEL);
  305. if (!host)
  306. return -ENOMEM;
  307. ufshcd_set_variant(hba, host);
  308. intel_dsm_init(host, hba->dev);
  309. if (INTEL_DSM_SUPPORTED(host, RESET)) {
  310. if (hba->vops->device_reset)
  311. hba->caps |= UFSHCD_CAP_DEEPSLEEP;
  312. } else {
  313. if (hba->vops->device_reset)
  314. host->reset_gpio = ufs_intel_get_reset_gpio(hba->dev);
  315. if (IS_ERR(host->reset_gpio)) {
  316. dev_err(hba->dev, "%s: failed to get reset GPIO, error %ld\n",
  317. __func__, PTR_ERR(host->reset_gpio));
  318. host->reset_gpio = NULL;
  319. }
  320. if (host->reset_gpio) {
  321. gpiod_set_value_cansleep(host->reset_gpio, 0);
  322. hba->caps |= UFSHCD_CAP_DEEPSLEEP;
  323. }
  324. }
  325. intel_ltr_expose(hba->dev);
  326. intel_add_debugfs(hba);
  327. return 0;
  328. }
  329. static void ufs_intel_common_exit(struct ufs_hba *hba)
  330. {
  331. intel_remove_debugfs(hba);
  332. intel_ltr_hide(hba->dev);
  333. }
  334. static int ufs_intel_resume(struct ufs_hba *hba, enum ufs_pm_op op)
  335. {
  336. if (ufshcd_is_link_hibern8(hba)) {
  337. int ret = ufshcd_uic_hibern8_exit(hba);
  338. if (!ret) {
  339. ufshcd_set_link_active(hba);
  340. } else {
  341. dev_err(hba->dev, "%s: hibern8 exit failed %d\n",
  342. __func__, ret);
  343. /*
  344. * Force reset and restore. Any other actions can lead
  345. * to an unrecoverable state.
  346. */
  347. ufshcd_set_link_off(hba);
  348. }
  349. }
  350. return 0;
  351. }
  352. static int ufs_intel_ehl_init(struct ufs_hba *hba)
  353. {
  354. hba->quirks |= UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8;
  355. return ufs_intel_common_init(hba);
  356. }
  357. static void ufs_intel_lkf_late_init(struct ufs_hba *hba)
  358. {
  359. /* LKF always needs a full reset, so set PM accordingly */
  360. if (hba->caps & UFSHCD_CAP_DEEPSLEEP) {
  361. hba->spm_lvl = UFS_PM_LVL_6;
  362. hba->rpm_lvl = UFS_PM_LVL_6;
  363. } else {
  364. hba->spm_lvl = UFS_PM_LVL_5;
  365. hba->rpm_lvl = UFS_PM_LVL_5;
  366. }
  367. }
  368. static int ufs_intel_lkf_init(struct ufs_hba *hba)
  369. {
  370. struct ufs_host *ufs_host;
  371. int err;
  372. hba->nop_out_timeout = 200;
  373. hba->quirks |= UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8;
  374. hba->caps |= UFSHCD_CAP_CRYPTO;
  375. err = ufs_intel_common_init(hba);
  376. ufs_host = ufshcd_get_variant(hba);
  377. ufs_host->late_init = ufs_intel_lkf_late_init;
  378. return err;
  379. }
  380. static int ufs_intel_adl_init(struct ufs_hba *hba)
  381. {
  382. hba->nop_out_timeout = 200;
  383. hba->quirks |= UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8;
  384. hba->caps |= UFSHCD_CAP_WB_EN;
  385. return ufs_intel_common_init(hba);
  386. }
  387. static void ufs_intel_mtl_late_init(struct ufs_hba *hba)
  388. {
  389. hba->rpm_lvl = UFS_PM_LVL_2;
  390. hba->spm_lvl = UFS_PM_LVL_2;
  391. }
  392. static int ufs_intel_mtl_init(struct ufs_hba *hba)
  393. {
  394. struct ufs_host *ufs_host;
  395. int err;
  396. hba->caps |= UFSHCD_CAP_CRYPTO | UFSHCD_CAP_WB_EN;
  397. err = ufs_intel_common_init(hba);
  398. /* Get variant after it is set in ufs_intel_common_init() */
  399. ufs_host = ufshcd_get_variant(hba);
  400. ufs_host->late_init = ufs_intel_mtl_late_init;
  401. return err;
  402. }
  403. static int ufs_qemu_get_hba_mac(struct ufs_hba *hba)
  404. {
  405. return MAX_SUPP_MAC;
  406. }
  407. static int ufs_qemu_mcq_config_resource(struct ufs_hba *hba)
  408. {
  409. hba->mcq_base = hba->mmio_base + ufshcd_mcq_queue_cfg_addr(hba);
  410. return 0;
  411. }
  412. static int ufs_qemu_op_runtime_config(struct ufs_hba *hba)
  413. {
  414. struct ufshcd_mcq_opr_info_t *opr;
  415. int i;
  416. u32 sqdao = ufsmcq_readl(hba, ufshcd_mcq_cfg_offset(REG_SQDAO, 0));
  417. u32 sqisao = ufsmcq_readl(hba, ufshcd_mcq_cfg_offset(REG_SQISAO, 0));
  418. u32 cqdao = ufsmcq_readl(hba, ufshcd_mcq_cfg_offset(REG_CQDAO, 0));
  419. u32 cqisao = ufsmcq_readl(hba, ufshcd_mcq_cfg_offset(REG_CQISAO, 0));
  420. hba->mcq_opr[OPR_SQD].offset = sqdao;
  421. hba->mcq_opr[OPR_SQIS].offset = sqisao;
  422. hba->mcq_opr[OPR_CQD].offset = cqdao;
  423. hba->mcq_opr[OPR_CQIS].offset = cqisao;
  424. for (i = 0; i < OPR_MAX; i++) {
  425. opr = &hba->mcq_opr[i];
  426. opr->stride = 48;
  427. opr->base = hba->mmio_base + opr->offset;
  428. }
  429. return 0;
  430. }
  431. static struct ufs_hba_variant_ops ufs_qemu_hba_vops = {
  432. .name = "qemu-pci",
  433. .get_hba_mac = ufs_qemu_get_hba_mac,
  434. .mcq_config_resource = ufs_qemu_mcq_config_resource,
  435. .op_runtime_config = ufs_qemu_op_runtime_config,
  436. };
  437. static struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
  438. .name = "intel-pci",
  439. .init = ufs_intel_common_init,
  440. .exit = ufs_intel_common_exit,
  441. .link_startup_notify = ufs_intel_link_startup_notify,
  442. .resume = ufs_intel_resume,
  443. };
  444. static struct ufs_hba_variant_ops ufs_intel_ehl_hba_vops = {
  445. .name = "intel-pci",
  446. .init = ufs_intel_ehl_init,
  447. .exit = ufs_intel_common_exit,
  448. .link_startup_notify = ufs_intel_link_startup_notify,
  449. .resume = ufs_intel_resume,
  450. };
  451. static struct ufs_hba_variant_ops ufs_intel_lkf_hba_vops = {
  452. .name = "intel-pci",
  453. .init = ufs_intel_lkf_init,
  454. .exit = ufs_intel_common_exit,
  455. .hce_enable_notify = ufs_intel_hce_enable_notify,
  456. .link_startup_notify = ufs_intel_link_startup_notify,
  457. .pwr_change_notify = ufs_intel_lkf_pwr_change_notify,
  458. .apply_dev_quirks = ufs_intel_lkf_apply_dev_quirks,
  459. .resume = ufs_intel_resume,
  460. .device_reset = ufs_intel_device_reset,
  461. };
  462. static struct ufs_hba_variant_ops ufs_intel_adl_hba_vops = {
  463. .name = "intel-pci",
  464. .init = ufs_intel_adl_init,
  465. .exit = ufs_intel_common_exit,
  466. .link_startup_notify = ufs_intel_link_startup_notify,
  467. .resume = ufs_intel_resume,
  468. .device_reset = ufs_intel_device_reset,
  469. };
  470. static struct ufs_hba_variant_ops ufs_intel_mtl_hba_vops = {
  471. .name = "intel-pci",
  472. .init = ufs_intel_mtl_init,
  473. .exit = ufs_intel_common_exit,
  474. .hce_enable_notify = ufs_intel_hce_enable_notify,
  475. .hibern8_notify = ufs_intel_mtl_h8_notify,
  476. .link_startup_notify = ufs_intel_link_startup_notify,
  477. .resume = ufs_intel_resume,
  478. .device_reset = ufs_intel_device_reset,
  479. };
  480. #ifdef CONFIG_PM_SLEEP
  481. static int ufshcd_pci_restore(struct device *dev)
  482. {
  483. struct ufs_hba *hba = dev_get_drvdata(dev);
  484. /* Force a full reset and restore */
  485. ufshcd_set_link_off(hba);
  486. return ufshcd_system_resume(dev);
  487. }
  488. #endif
  489. /**
  490. * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
  491. * data structure memory
  492. * @pdev: pointer to PCI handle
  493. */
  494. static void ufshcd_pci_remove(struct pci_dev *pdev)
  495. {
  496. struct ufs_hba *hba = pci_get_drvdata(pdev);
  497. pm_runtime_forbid(&pdev->dev);
  498. pm_runtime_get_noresume(&pdev->dev);
  499. ufshcd_remove(hba);
  500. }
  501. /**
  502. * ufshcd_pci_probe - probe routine of the driver
  503. * @pdev: pointer to PCI device handle
  504. * @id: PCI device id
  505. *
  506. * Return: 0 on success, non-zero value on failure.
  507. */
  508. static int
  509. ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  510. {
  511. struct ufs_host *ufs_host;
  512. struct ufs_hba *hba;
  513. void __iomem *mmio_base;
  514. int err;
  515. err = pcim_enable_device(pdev);
  516. if (err) {
  517. dev_err(&pdev->dev, "pcim_enable_device failed\n");
  518. return err;
  519. }
  520. pci_set_master(pdev);
  521. err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
  522. if (err < 0) {
  523. dev_err(&pdev->dev, "request and iomap failed\n");
  524. return err;
  525. }
  526. mmio_base = pcim_iomap_table(pdev)[0];
  527. err = ufshcd_alloc_host(&pdev->dev, &hba);
  528. if (err) {
  529. dev_err(&pdev->dev, "Allocation failed\n");
  530. return err;
  531. }
  532. hba->vops = (struct ufs_hba_variant_ops *)id->driver_data;
  533. err = ufshcd_init(hba, mmio_base, pdev->irq);
  534. if (err) {
  535. dev_err(&pdev->dev, "Initialization failed\n");
  536. return err;
  537. }
  538. ufs_host = ufshcd_get_variant(hba);
  539. if (ufs_host && ufs_host->late_init)
  540. ufs_host->late_init(hba);
  541. pm_runtime_put_noidle(&pdev->dev);
  542. pm_runtime_allow(&pdev->dev);
  543. return 0;
  544. }
  545. static const struct dev_pm_ops ufshcd_pci_pm_ops = {
  546. SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
  547. #ifdef CONFIG_PM_SLEEP
  548. .suspend = ufshcd_system_suspend,
  549. .resume = ufshcd_system_resume,
  550. .freeze = ufshcd_system_suspend,
  551. .thaw = ufshcd_system_resume,
  552. .poweroff = ufshcd_system_suspend,
  553. .restore = ufshcd_pci_restore,
  554. .prepare = ufshcd_suspend_prepare,
  555. .complete = ufshcd_resume_complete,
  556. #endif
  557. };
  558. static const struct pci_device_id ufshcd_pci_tbl[] = {
  559. { PCI_VENDOR_ID_REDHAT, 0x0013, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  560. (kernel_ulong_t)&ufs_qemu_hba_vops },
  561. { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  562. { PCI_VDEVICE(INTEL, 0x9DFA), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
  563. { PCI_VDEVICE(INTEL, 0x4B41), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
  564. { PCI_VDEVICE(INTEL, 0x4B43), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
  565. { PCI_VDEVICE(INTEL, 0x98FA), (kernel_ulong_t)&ufs_intel_lkf_hba_vops },
  566. { PCI_VDEVICE(INTEL, 0x51FF), (kernel_ulong_t)&ufs_intel_adl_hba_vops },
  567. { PCI_VDEVICE(INTEL, 0x54FF), (kernel_ulong_t)&ufs_intel_adl_hba_vops },
  568. { PCI_VDEVICE(INTEL, 0x7E47), (kernel_ulong_t)&ufs_intel_mtl_hba_vops },
  569. { PCI_VDEVICE(INTEL, 0xA847), (kernel_ulong_t)&ufs_intel_mtl_hba_vops },
  570. { PCI_VDEVICE(INTEL, 0x7747), (kernel_ulong_t)&ufs_intel_mtl_hba_vops },
  571. { PCI_VDEVICE(INTEL, 0xE447), (kernel_ulong_t)&ufs_intel_mtl_hba_vops },
  572. { } /* terminate list */
  573. };
  574. MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
  575. static struct pci_driver ufshcd_pci_driver = {
  576. .name = UFSHCD,
  577. .id_table = ufshcd_pci_tbl,
  578. .probe = ufshcd_pci_probe,
  579. .remove = ufshcd_pci_remove,
  580. .driver = {
  581. .pm = &ufshcd_pci_pm_ops
  582. },
  583. };
  584. module_pci_driver(ufshcd_pci_driver);
  585. MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
  586. MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
  587. MODULE_DESCRIPTION("UFS host controller PCI glue driver");
  588. MODULE_LICENSE("GPL");