2020-06-06 04:05:19 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-02-26 20:34:45 +08:00
|
|
|
/*
|
|
|
|
* Universal Flash Storage Host controller Platform bus based glue driver
|
|
|
|
* Copyright (C) 2011-2013 Samsung India Software Operations
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Santosh Yaraganavi <santosh.sy@samsung.com>
|
|
|
|
* Vinayak Holikatti <h.vinayak@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/platform_device.h>
|
2013-07-30 03:06:00 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2014-09-25 20:32:21 +08:00
|
|
|
#include <linux/of.h>
|
2013-02-26 20:34:45 +08:00
|
|
|
|
2013-06-27 12:31:54 +08:00
|
|
|
#include "ufshcd.h"
|
2015-10-28 19:15:49 +08:00
|
|
|
#include "ufshcd-pltfrm.h"
|
2019-03-16 13:04:41 +08:00
|
|
|
#include "unipro.h"
|
2014-09-25 20:32:21 +08:00
|
|
|
|
2016-03-10 23:37:05 +08:00
|
|
|
#define UFSHCD_DEFAULT_LANES_PER_DIRECTION 2
|
|
|
|
|
2014-09-25 20:32:23 +08:00
|
|
|
static int ufshcd_parse_clock_info(struct ufs_hba *hba)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int cnt;
|
|
|
|
int i;
|
|
|
|
struct device *dev = hba->dev;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
char *name;
|
|
|
|
u32 *clkfreq = NULL;
|
|
|
|
struct ufs_clk_info *clki;
|
2014-09-25 20:32:33 +08:00
|
|
|
int len = 0;
|
|
|
|
size_t sz = 0;
|
2014-09-25 20:32:23 +08:00
|
|
|
|
|
|
|
if (!np)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
cnt = of_property_count_strings(np, "clock-names");
|
|
|
|
if (!cnt || (cnt == -EINVAL)) {
|
|
|
|
dev_info(dev, "%s: Unable to find clocks, assuming enabled\n",
|
|
|
|
__func__);
|
|
|
|
} else if (cnt < 0) {
|
|
|
|
dev_err(dev, "%s: count clock strings failed, err %d\n",
|
|
|
|
__func__, cnt);
|
|
|
|
ret = cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt <= 0)
|
|
|
|
goto out;
|
|
|
|
|
2014-09-25 20:32:33 +08:00
|
|
|
if (!of_get_property(np, "freq-table-hz", &len)) {
|
|
|
|
dev_info(dev, "freq-table-hz property not specified\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sz = len / sizeof(*clkfreq);
|
|
|
|
if (sz != 2 * cnt) {
|
|
|
|
dev_err(dev, "%s len mismatch\n", "freq-table-hz");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
clkfreq = devm_kcalloc(dev, sz, sizeof(*clkfreq),
|
|
|
|
GFP_KERNEL);
|
2014-09-25 20:32:23 +08:00
|
|
|
if (!clkfreq) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-09-25 20:32:33 +08:00
|
|
|
ret = of_property_read_u32_array(np, "freq-table-hz",
|
|
|
|
clkfreq, sz);
|
2014-09-25 20:32:23 +08:00
|
|
|
if (ret && (ret != -EINVAL)) {
|
2014-09-25 20:32:33 +08:00
|
|
|
dev_err(dev, "%s: error reading array %d\n",
|
|
|
|
"freq-table-hz", ret);
|
2014-10-23 18:25:17 +08:00
|
|
|
return ret;
|
2014-09-25 20:32:23 +08:00
|
|
|
}
|
|
|
|
|
2014-09-25 20:32:33 +08:00
|
|
|
for (i = 0; i < sz; i += 2) {
|
2014-09-25 20:32:23 +08:00
|
|
|
ret = of_property_read_string_index(np,
|
2014-09-25 20:32:33 +08:00
|
|
|
"clock-names", i/2, (const char **)&name);
|
2014-09-25 20:32:23 +08:00
|
|
|
if (ret)
|
2014-10-23 18:25:17 +08:00
|
|
|
goto out;
|
2014-09-25 20:32:23 +08:00
|
|
|
|
|
|
|
clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
|
|
|
|
if (!clki) {
|
|
|
|
ret = -ENOMEM;
|
2014-10-23 18:25:17 +08:00
|
|
|
goto out;
|
2014-09-25 20:32:23 +08:00
|
|
|
}
|
|
|
|
|
2014-09-25 20:32:33 +08:00
|
|
|
clki->min_freq = clkfreq[i];
|
|
|
|
clki->max_freq = clkfreq[i+1];
|
2014-09-25 20:32:23 +08:00
|
|
|
clki->name = kstrdup(name, GFP_KERNEL);
|
2020-11-26 10:01:00 +08:00
|
|
|
if (!strcmp(name, "ref_clk"))
|
|
|
|
clki->keep_link_active = true;
|
2014-09-25 20:32:33 +08:00
|
|
|
dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz",
|
|
|
|
clki->min_freq, clki->max_freq, clki->name);
|
2014-09-25 20:32:23 +08:00
|
|
|
list_add_tail(&clki->list, &hba->clk_list_head);
|
|
|
|
}
|
2014-09-25 20:32:33 +08:00
|
|
|
out:
|
2014-09-25 20:32:23 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-25 20:32:22 +08:00
|
|
|
#define MAX_PROP_SIZE 32
|
|
|
|
static int ufshcd_populate_vreg(struct device *dev, const char *name,
|
|
|
|
struct ufs_vreg **out_vreg)
|
|
|
|
{
|
|
|
|
char prop_name[MAX_PROP_SIZE];
|
|
|
|
struct ufs_vreg *vreg = NULL;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
|
|
|
|
if (!np) {
|
|
|
|
dev_err(dev, "%s: non DT initialization\n", __func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", name);
|
|
|
|
if (!of_parse_phandle(np, prop_name, 0)) {
|
|
|
|
dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n",
|
|
|
|
__func__, prop_name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
|
2014-10-23 18:25:15 +08:00
|
|
|
if (!vreg)
|
|
|
|
return -ENOMEM;
|
2014-09-25 20:32:22 +08:00
|
|
|
|
|
|
|
vreg->name = kstrdup(name, GFP_KERNEL);
|
|
|
|
|
|
|
|
snprintf(prop_name, MAX_PROP_SIZE, "%s-max-microamp", name);
|
scsi: ufs: Change "<name>-max-microamp" to non-mandatory property
In dt-bindings for ufs, "<name>-max-microamp" property indicates current
limit and is mandatory if "<name>-fixed-regulator" is not defined on a
specified regulator.
However, in some platforms, regulators without "<name>-fixed-regulator"
property may not need to define their current limit because they may want
to define voltage range only for proper voltage switching in different
power modes, especially for vcc, vccq or vccq2.
Currently missing "<name>-max-microamp" property in device tree will lead
initialization to fail, thus such limitation shall be resolved to tolerate
this kind of regulators.
After resolving this, regulators without "<name>-max-microamp" property
will have undefined "max current" value, i.e., zero value in "max_uA" field
in struct ufs_vreg. Because we do bypass current switching operation (by
regulator_set_load) in case of undefined current limit, this patch shall be
safe.
Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Acked-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2019-03-28 17:16:26 +08:00
|
|
|
if (of_property_read_u32(np, prop_name, &vreg->max_uA)) {
|
|
|
|
dev_info(dev, "%s: unable to find %s\n", __func__, prop_name);
|
|
|
|
vreg->max_uA = 0;
|
2014-09-25 20:32:22 +08:00
|
|
|
}
|
|
|
|
out:
|
2021-03-10 16:27:41 +08:00
|
|
|
*out_vreg = vreg;
|
|
|
|
return 0;
|
2014-09-25 20:32:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ufshcd_parse_regulator_info - get regulator info from device tree
|
|
|
|
* @hba: per adapter instance
|
|
|
|
*
|
|
|
|
* Get regulator info from device tree for vcc, vccq, vccq2 power supplies.
|
|
|
|
* If any of the supplies are not defined it is assumed that they are always-on
|
|
|
|
* and hence return zero. If the property is defined but parsing is failed
|
|
|
|
* then return corresponding error.
|
|
|
|
*/
|
|
|
|
static int ufshcd_parse_regulator_info(struct ufs_hba *hba)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct device *dev = hba->dev;
|
|
|
|
struct ufs_vreg_info *info = &hba->vreg_info;
|
|
|
|
|
2014-09-25 20:32:24 +08:00
|
|
|
err = ufshcd_populate_vreg(dev, "vdd-hba", &info->vdd_hba);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2014-09-25 20:32:22 +08:00
|
|
|
err = ufshcd_populate_vreg(dev, "vcc", &info->vcc);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = ufshcd_populate_vreg(dev, "vccq", &info->vccq);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = ufshcd_populate_vreg(dev, "vccq2", &info->vccq2);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:15:49 +08:00
|
|
|
void ufshcd_pltfrm_shutdown(struct platform_device *pdev)
|
2014-09-25 20:32:30 +08:00
|
|
|
{
|
|
|
|
ufshcd_shutdown((struct ufs_hba *)platform_get_drvdata(pdev));
|
|
|
|
}
|
2015-10-28 19:15:49 +08:00
|
|
|
EXPORT_SYMBOL_GPL(ufshcd_pltfrm_shutdown);
|
2014-09-25 20:32:30 +08:00
|
|
|
|
2016-03-10 23:37:05 +08:00
|
|
|
static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba)
|
|
|
|
{
|
|
|
|
struct device *dev = hba->dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(dev->of_node, "lanes-per-direction",
|
|
|
|
&hba->lanes_per_direction);
|
|
|
|
if (ret) {
|
|
|
|
dev_dbg(hba->dev,
|
|
|
|
"%s: failed to read lanes-per-direction, ret=%d\n",
|
|
|
|
__func__, ret);
|
|
|
|
hba->lanes_per_direction = UFSHCD_DEFAULT_LANES_PER_DIRECTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 13:04:41 +08:00
|
|
|
/**
|
|
|
|
* ufshcd_get_pwr_dev_param - get finally agreed attributes for
|
|
|
|
* power mode change
|
|
|
|
* @pltfrm_param: pointer to platform parameters
|
|
|
|
* @dev_max: pointer to device attributes
|
|
|
|
* @agreed_pwr: returned agreed attributes
|
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero value on failure
|
|
|
|
*/
|
|
|
|
int ufshcd_get_pwr_dev_param(struct ufs_dev_params *pltfrm_param,
|
|
|
|
struct ufs_pa_layer_attr *dev_max,
|
|
|
|
struct ufs_pa_layer_attr *agreed_pwr)
|
|
|
|
{
|
|
|
|
int min_pltfrm_gear;
|
|
|
|
int min_dev_gear;
|
|
|
|
bool is_dev_sup_hs = false;
|
|
|
|
bool is_pltfrm_max_hs = false;
|
|
|
|
|
|
|
|
if (dev_max->pwr_rx == FAST_MODE)
|
|
|
|
is_dev_sup_hs = true;
|
|
|
|
|
|
|
|
if (pltfrm_param->desired_working_mode == UFS_HS_MODE) {
|
|
|
|
is_pltfrm_max_hs = true;
|
|
|
|
min_pltfrm_gear = min_t(u32, pltfrm_param->hs_rx_gear,
|
|
|
|
pltfrm_param->hs_tx_gear);
|
|
|
|
} else {
|
|
|
|
min_pltfrm_gear = min_t(u32, pltfrm_param->pwm_rx_gear,
|
|
|
|
pltfrm_param->pwm_tx_gear);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* device doesn't support HS but
|
|
|
|
* pltfrm_param->desired_working_mode is HS,
|
|
|
|
* thus device and pltfrm_param don't agree
|
|
|
|
*/
|
|
|
|
if (!is_dev_sup_hs && is_pltfrm_max_hs) {
|
|
|
|
pr_info("%s: device doesn't support HS\n",
|
|
|
|
__func__);
|
|
|
|
return -ENOTSUPP;
|
|
|
|
} else if (is_dev_sup_hs && is_pltfrm_max_hs) {
|
|
|
|
/*
|
|
|
|
* since device supports HS, it supports FAST_MODE.
|
|
|
|
* since pltfrm_param->desired_working_mode is also HS
|
|
|
|
* then final decision (FAST/FASTAUTO) is done according
|
|
|
|
* to pltfrm_params as it is the restricting factor
|
|
|
|
*/
|
|
|
|
agreed_pwr->pwr_rx = pltfrm_param->rx_pwr_hs;
|
|
|
|
agreed_pwr->pwr_tx = agreed_pwr->pwr_rx;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* here pltfrm_param->desired_working_mode is PWM.
|
|
|
|
* it doesn't matter whether device supports HS or PWM,
|
|
|
|
* in both cases pltfrm_param->desired_working_mode will
|
|
|
|
* determine the mode
|
|
|
|
*/
|
|
|
|
agreed_pwr->pwr_rx = pltfrm_param->rx_pwr_pwm;
|
|
|
|
agreed_pwr->pwr_tx = agreed_pwr->pwr_rx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we would like tx to work in the minimum number of lanes
|
|
|
|
* between device capability and vendor preferences.
|
|
|
|
* the same decision will be made for rx
|
|
|
|
*/
|
|
|
|
agreed_pwr->lane_tx = min_t(u32, dev_max->lane_tx,
|
|
|
|
pltfrm_param->tx_lanes);
|
|
|
|
agreed_pwr->lane_rx = min_t(u32, dev_max->lane_rx,
|
|
|
|
pltfrm_param->rx_lanes);
|
|
|
|
|
|
|
|
/* device maximum gear is the minimum between device rx and tx gears */
|
|
|
|
min_dev_gear = min_t(u32, dev_max->gear_rx, dev_max->gear_tx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if both device capabilities and vendor pre-defined preferences are
|
|
|
|
* both HS or both PWM then set the minimum gear to be the chosen
|
|
|
|
* working gear.
|
|
|
|
* if one is PWM and one is HS then the one that is PWM get to decide
|
|
|
|
* what is the gear, as it is the one that also decided previously what
|
|
|
|
* pwr the device will be configured to.
|
|
|
|
*/
|
|
|
|
if ((is_dev_sup_hs && is_pltfrm_max_hs) ||
|
|
|
|
(!is_dev_sup_hs && !is_pltfrm_max_hs)) {
|
|
|
|
agreed_pwr->gear_rx =
|
|
|
|
min_t(u32, min_dev_gear, min_pltfrm_gear);
|
|
|
|
} else if (!is_dev_sup_hs) {
|
|
|
|
agreed_pwr->gear_rx = min_dev_gear;
|
|
|
|
} else {
|
|
|
|
agreed_pwr->gear_rx = min_pltfrm_gear;
|
|
|
|
}
|
|
|
|
agreed_pwr->gear_tx = agreed_pwr->gear_rx;
|
|
|
|
|
|
|
|
agreed_pwr->hs_rate = pltfrm_param->hs_rate;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(ufshcd_get_pwr_dev_param);
|
|
|
|
|
2020-11-16 14:50:47 +08:00
|
|
|
void ufshcd_init_pwr_dev_param(struct ufs_dev_params *dev_param)
|
|
|
|
{
|
|
|
|
dev_param->tx_lanes = 2;
|
|
|
|
dev_param->rx_lanes = 2;
|
|
|
|
dev_param->hs_rx_gear = UFS_HS_G3;
|
|
|
|
dev_param->hs_tx_gear = UFS_HS_G3;
|
|
|
|
dev_param->pwm_rx_gear = UFS_PWM_G4;
|
|
|
|
dev_param->pwm_tx_gear = UFS_PWM_G4;
|
|
|
|
dev_param->rx_pwr_pwm = SLOW_MODE;
|
|
|
|
dev_param->tx_pwr_pwm = SLOW_MODE;
|
|
|
|
dev_param->rx_pwr_hs = FAST_MODE;
|
|
|
|
dev_param->tx_pwr_hs = FAST_MODE;
|
|
|
|
dev_param->hs_rate = PA_HS_MODE_B;
|
|
|
|
dev_param->desired_working_mode = UFS_HS_MODE;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(ufshcd_init_pwr_dev_param);
|
|
|
|
|
2013-02-26 20:34:45 +08:00
|
|
|
/**
|
2015-10-28 19:15:49 +08:00
|
|
|
* ufshcd_pltfrm_init - probe routine of the driver
|
2013-02-26 20:34:45 +08:00
|
|
|
* @pdev: pointer to Platform device handle
|
2015-10-28 19:15:49 +08:00
|
|
|
* @vops: pointer to variant ops
|
2013-02-26 20:34:45 +08:00
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero value on failure
|
|
|
|
*/
|
2015-10-28 19:15:49 +08:00
|
|
|
int ufshcd_pltfrm_init(struct platform_device *pdev,
|
2019-03-05 03:39:11 +08:00
|
|
|
const struct ufs_hba_variant_ops *vops)
|
2013-02-26 20:34:45 +08:00
|
|
|
{
|
|
|
|
struct ufs_hba *hba;
|
|
|
|
void __iomem *mmio_base;
|
2013-06-27 12:31:54 +08:00
|
|
|
int irq, err;
|
2013-02-26 20:34:45 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
|
2019-09-04 21:03:48 +08:00
|
|
|
mmio_base = devm_platform_ioremap_resource(pdev, 0);
|
2017-03-14 20:19:36 +08:00
|
|
|
if (IS_ERR(mmio_base)) {
|
|
|
|
err = PTR_ERR(mmio_base);
|
2013-06-27 12:31:54 +08:00
|
|
|
goto out;
|
2013-02-26 20:34:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-27 12:31:54 +08:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0) {
|
2021-03-30 04:50:58 +08:00
|
|
|
err = irq;
|
2013-06-27 12:31:54 +08:00
|
|
|
goto out;
|
2013-02-26 20:34:45 +08:00
|
|
|
}
|
|
|
|
|
2014-09-25 20:32:21 +08:00
|
|
|
err = ufshcd_alloc_host(dev, &hba);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "Allocation failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:15:49 +08:00
|
|
|
hba->vops = vops;
|
2014-09-25 20:32:21 +08:00
|
|
|
|
2014-09-25 20:32:23 +08:00
|
|
|
err = ufshcd_parse_clock_info(hba);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "%s: clock parse failed %d\n",
|
|
|
|
__func__, err);
|
2015-10-28 19:15:49 +08:00
|
|
|
goto dealloc_host;
|
2014-09-25 20:32:23 +08:00
|
|
|
}
|
2014-09-25 20:32:22 +08:00
|
|
|
err = ufshcd_parse_regulator_info(hba);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "%s: regulator init failed %d\n",
|
|
|
|
__func__, err);
|
2015-10-28 19:15:49 +08:00
|
|
|
goto dealloc_host;
|
2014-09-25 20:32:22 +08:00
|
|
|
}
|
|
|
|
|
2016-03-10 23:37:05 +08:00
|
|
|
ufshcd_init_lanes_per_dir(hba);
|
|
|
|
|
2014-09-25 20:32:21 +08:00
|
|
|
err = ufshcd_init(hba, mmio_base, irq);
|
2013-02-26 20:34:45 +08:00
|
|
|
if (err) {
|
2015-11-29 00:33:56 +08:00
|
|
|
dev_err(dev, "Initialization failed\n");
|
2019-06-12 23:19:05 +08:00
|
|
|
goto dealloc_host;
|
2013-02-26 20:34:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, hba);
|
|
|
|
|
2019-06-12 23:19:05 +08:00
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
|
2013-07-30 03:06:00 +08:00
|
|
|
return 0;
|
|
|
|
|
2015-10-28 19:15:49 +08:00
|
|
|
dealloc_host:
|
|
|
|
ufshcd_dealloc_host(hba);
|
2013-06-27 12:31:54 +08:00
|
|
|
out:
|
2013-02-26 20:34:45 +08:00
|
|
|
return err;
|
|
|
|
}
|
2015-10-28 19:15:49 +08:00
|
|
|
EXPORT_SYMBOL_GPL(ufshcd_pltfrm_init);
|
2013-02-26 20:34:45 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
|
|
|
|
MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
|
2016-05-11 19:21:25 +08:00
|
|
|
MODULE_DESCRIPTION("UFS host controller Platform bus based glue driver");
|
2013-02-26 20:34:45 +08:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(UFSHCD_DRIVER_VERSION);
|