^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Platform UFS Host driver for Cadence controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2018 Cadence Design Systems, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Jan Kotas <jank@cadence.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "ufshcd-pltfrm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define CDNS_UFS_REG_HCLKDIV 0xFC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define CDNS_UFS_REG_PHY_XCFGD1 0x113C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define CDNS_UFS_MAX_L4_ATTRS 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct cdns_ufs_host {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * cdns_ufs_dme_attr_val - for storing L4 attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) u32 cdns_ufs_dme_attr_val[CDNS_UFS_MAX_L4_ATTRS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * cdns_ufs_get_l4_attr - get L4 attributes on local side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * @hba: per adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static void cdns_ufs_get_l4_attr(struct ufs_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct cdns_ufs_host *host = ufshcd_get_variant(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ufshcd_dme_get(hba, UIC_ARG_MIB(T_PEERDEVICEID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) &host->cdns_ufs_dme_attr_val[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ufshcd_dme_get(hba, UIC_ARG_MIB(T_PEERCPORTID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) &host->cdns_ufs_dme_attr_val[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ufshcd_dme_get(hba, UIC_ARG_MIB(T_TRAFFICCLASS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) &host->cdns_ufs_dme_attr_val[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ufshcd_dme_get(hba, UIC_ARG_MIB(T_PROTOCOLID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) &host->cdns_ufs_dme_attr_val[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ufshcd_dme_get(hba, UIC_ARG_MIB(T_CPORTFLAGS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) &host->cdns_ufs_dme_attr_val[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ufshcd_dme_get(hba, UIC_ARG_MIB(T_TXTOKENVALUE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) &host->cdns_ufs_dme_attr_val[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ufshcd_dme_get(hba, UIC_ARG_MIB(T_RXTOKENVALUE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) &host->cdns_ufs_dme_attr_val[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ufshcd_dme_get(hba, UIC_ARG_MIB(T_LOCALBUFFERSPACE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) &host->cdns_ufs_dme_attr_val[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ufshcd_dme_get(hba, UIC_ARG_MIB(T_PEERBUFFERSPACE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) &host->cdns_ufs_dme_attr_val[8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ufshcd_dme_get(hba, UIC_ARG_MIB(T_CREDITSTOSEND),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) &host->cdns_ufs_dme_attr_val[9]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ufshcd_dme_get(hba, UIC_ARG_MIB(T_CPORTMODE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) &host->cdns_ufs_dme_attr_val[10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ufshcd_dme_get(hba, UIC_ARG_MIB(T_CONNECTIONSTATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) &host->cdns_ufs_dme_attr_val[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * cdns_ufs_set_l4_attr - set L4 attributes on local side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @hba: per adapter instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void cdns_ufs_set_l4_attr(struct ufs_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct cdns_ufs_host *host = ufshcd_get_variant(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ufshcd_dme_set(hba, UIC_ARG_MIB(T_CONNECTIONSTATE), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ufshcd_dme_set(hba, UIC_ARG_MIB(T_PEERDEVICEID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) host->cdns_ufs_dme_attr_val[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ufshcd_dme_set(hba, UIC_ARG_MIB(T_PEERCPORTID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) host->cdns_ufs_dme_attr_val[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ufshcd_dme_set(hba, UIC_ARG_MIB(T_TRAFFICCLASS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) host->cdns_ufs_dme_attr_val[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ufshcd_dme_set(hba, UIC_ARG_MIB(T_PROTOCOLID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) host->cdns_ufs_dme_attr_val[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ufshcd_dme_set(hba, UIC_ARG_MIB(T_CPORTFLAGS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) host->cdns_ufs_dme_attr_val[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ufshcd_dme_set(hba, UIC_ARG_MIB(T_TXTOKENVALUE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) host->cdns_ufs_dme_attr_val[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ufshcd_dme_set(hba, UIC_ARG_MIB(T_RXTOKENVALUE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) host->cdns_ufs_dme_attr_val[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ufshcd_dme_set(hba, UIC_ARG_MIB(T_LOCALBUFFERSPACE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) host->cdns_ufs_dme_attr_val[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ufshcd_dme_set(hba, UIC_ARG_MIB(T_PEERBUFFERSPACE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) host->cdns_ufs_dme_attr_val[8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ufshcd_dme_set(hba, UIC_ARG_MIB(T_CREDITSTOSEND),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) host->cdns_ufs_dme_attr_val[9]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ufshcd_dme_set(hba, UIC_ARG_MIB(T_CPORTMODE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) host->cdns_ufs_dme_attr_val[10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ufshcd_dme_set(hba, UIC_ARG_MIB(T_CONNECTIONSTATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) host->cdns_ufs_dme_attr_val[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Sets HCLKDIV register value based on the core_clk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @hba: host controller instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * Return zero for success and non-zero for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct ufs_clk_info *clki;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct list_head *head = &hba->clk_list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned long core_clk_rate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u32 core_clk_div = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) list_for_each_entry(clki, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (IS_ERR_OR_NULL(clki->clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (!strcmp(clki->name, "core_clk"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) core_clk_rate = clk_get_rate(clki->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (!core_clk_rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) dev_err(hba->dev, "%s: unable to find core_clk rate\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) core_clk_div = core_clk_rate / USEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ufshcd_writel(hba, core_clk_div, CDNS_UFS_REG_HCLKDIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Make sure the register was updated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * UniPro layer will not work with an incorrect value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * Called before and after HCE enable bit is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * @hba: host controller instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * @status: notify stage (pre, post change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Return zero for success and non-zero for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int cdns_ufs_hce_enable_notify(struct ufs_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) enum ufs_notify_change_status status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (status != PRE_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return cdns_ufs_set_hclkdiv(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * Called around hibern8 enter/exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * @hba: host controller instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @cmd: UIC Command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * @status: notify stage (pre, post change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static void cdns_ufs_hibern8_notify(struct ufs_hba *hba, enum uic_cmd_dme cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) enum ufs_notify_change_status status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (status == PRE_CHANGE && cmd == UIC_CMD_DME_HIBER_ENTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cdns_ufs_get_l4_attr(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (status == POST_CHANGE && cmd == UIC_CMD_DME_HIBER_EXIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) cdns_ufs_set_l4_attr(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * Called before and after Link startup is carried out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @hba: host controller instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * @status: notify stage (pre, post change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Return zero for success and non-zero for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int cdns_ufs_link_startup_notify(struct ufs_hba *hba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) enum ufs_notify_change_status status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (status != PRE_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * Some UFS devices have issues if LCC is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * So we are setting PA_Local_TX_LCC_Enable to 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * before link startup which will make sure that both host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * and device TX LCC are disabled once link startup is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ufshcd_disable_host_tx_lcc(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * Disabling Autohibern8 feature in cadence UFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * to mask unexpected interrupt trigger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) hba->ahit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * cdns_ufs_init - performs additional ufs initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * @hba: host controller instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Returns status of initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int cdns_ufs_init(struct ufs_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct cdns_ufs_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct device *dev = hba->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ufshcd_set_variant(hba, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (hba->vops && hba->vops->phy_initialization)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) status = hba->vops->phy_initialization(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * cdns_ufs_m31_16nm_phy_initialization - performs m31 phy initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * @hba: host controller instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Always returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static int cdns_ufs_m31_16nm_phy_initialization(struct ufs_hba *hba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Increase RX_Advanced_Min_ActivateTime_Capability */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) data = ufshcd_readl(hba, CDNS_UFS_REG_PHY_XCFGD1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) data |= BIT(24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ufshcd_writel(hba, data, CDNS_UFS_REG_PHY_XCFGD1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static const struct ufs_hba_variant_ops cdns_ufs_pltfm_hba_vops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .name = "cdns-ufs-pltfm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .init = cdns_ufs_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .hce_enable_notify = cdns_ufs_hce_enable_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .link_startup_notify = cdns_ufs_link_startup_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .hibern8_notify = cdns_ufs_hibern8_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static const struct ufs_hba_variant_ops cdns_ufs_m31_16nm_pltfm_hba_vops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .name = "cdns-ufs-pltfm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .init = cdns_ufs_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .hce_enable_notify = cdns_ufs_hce_enable_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .link_startup_notify = cdns_ufs_link_startup_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .phy_initialization = cdns_ufs_m31_16nm_phy_initialization,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .hibern8_notify = cdns_ufs_hibern8_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static const struct of_device_id cdns_ufs_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .compatible = "cdns,ufshc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .data = &cdns_ufs_pltfm_hba_vops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .compatible = "cdns,ufshc-m31-16nm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .data = &cdns_ufs_m31_16nm_pltfm_hba_vops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) MODULE_DEVICE_TABLE(of, cdns_ufs_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * cdns_ufs_pltfrm_probe - probe routine of the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @pdev: pointer to platform device handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Return zero for success and non-zero for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static int cdns_ufs_pltfrm_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) const struct of_device_id *of_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct ufs_hba_variant_ops *vops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) of_id = of_match_node(cdns_ufs_of_match, dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) vops = (struct ufs_hba_variant_ops *)of_id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* Perform generic probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) err = ufshcd_pltfrm_init(pdev, vops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) dev_err(dev, "ufshcd_pltfrm_init() failed %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * cdns_ufs_pltfrm_remove - removes the ufs driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * @pdev: pointer to platform device handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * Always returns 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int cdns_ufs_pltfrm_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct ufs_hba *hba = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ufshcd_remove(hba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static const struct dev_pm_ops cdns_ufs_dev_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .suspend = ufshcd_pltfrm_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .resume = ufshcd_pltfrm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .runtime_suspend = ufshcd_pltfrm_runtime_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .runtime_resume = ufshcd_pltfrm_runtime_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .runtime_idle = ufshcd_pltfrm_runtime_idle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct platform_driver cdns_ufs_pltfrm_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .probe = cdns_ufs_pltfrm_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .remove = cdns_ufs_pltfrm_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .shutdown = ufshcd_pltfrm_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .name = "cdns-ufshcd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .pm = &cdns_ufs_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .of_match_table = cdns_ufs_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) module_platform_driver(cdns_ufs_pltfrm_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) MODULE_AUTHOR("Jan Kotas <jank@cadence.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_DESCRIPTION("Cadence UFS host controller platform driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) MODULE_VERSION(UFSHCD_DRIVER_VERSION);