Skip to content

Commit ca45262

Browse files
Daniil Lunevmartinkpetersen
authored andcommitted
scsi: ufs: core: Read device property for ref clock
UFS storage devices require bRefClkFreq attribute to be set to operate correctly at high speed mode. The necessary value is determined by what the SoC / board supports. The standard doesn't specify a method to query the value, so the information needs to be fed in separately. DT information feeds into setting up the clock framework, so platforms using DT can get the UFS reference clock frequency from the clock framework. A special node "ref_clk" from the clock array for the UFS controller node is used as the source for the information. On the platforms that do not use DT (e.g. Intel), the alternative mechanism to feed the intended reference clock frequency is necessary. Specifying the necessary information in DSD of the UFS controller ACPI node is an alternative mechanism proposed in this patch. Those can be accessed via firmware property facility in the kernel and in many ways simillar to querying properties defined in DT. This patch introduces a small helper function to query a predetermined ACPI supplied property of the UFS controller, and uses it to attempt retrieving reference clock value, unless that was already done by the clock infrastructure. Link: https://lore.kernel.org/r/20220715210230.1.I365d113d275117dee8fd055ce4fc7e6aebd0bce9@changeid Reviewed-by: Adrian Hunter <[email protected]> Signed-off-by: Daniil Lunev <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1e82e46 commit ca45262

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Documentation/scsi/ufs.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Universal Flash Storage
1717
3.2 UTP Transfer requests
1818
3.3 UFS error handling
1919
3.4 SCSI Error handling
20+
4. BSG Support
21+
5. UFS Reference Clock Frequency configuration
2022
2123
2224
1. Overview
@@ -193,3 +195,16 @@ UFS specifications can be found at:
193195

194196
- UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
195197
- UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf
198+
199+
5. UFS Reference Clock Frequency configuration
200+
==============================================
201+
202+
Devicetree can define a clock named "ref_clk" under the UFS controller node
203+
to specify the intended reference clock frequency for the UFS storage
204+
parts. ACPI-based system can specify the frequency using ACPI
205+
Device-Specific Data property named "ref-clk-freq". In both ways the value
206+
is interpreted as frequency in Hz and must match one of the values given in
207+
the UFS specification. UFS subsystem will attempt to read the value when
208+
executing common controller initialization. If the value is available, UFS
209+
subsytem will ensure the bRefClkFreq attribute of the UFS storage device is
210+
set accordingly and will modify it if there is a mismatch.

drivers/ufs/core/ufshcd.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8544,6 +8544,19 @@ static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
85448544
return ret;
85458545
}
85468546

8547+
static enum ufs_ref_clk_freq ufshcd_parse_ref_clk_property(struct ufs_hba *hba)
8548+
{
8549+
u32 freq;
8550+
int ret = device_property_read_u32(hba->dev, "ref-clk-freq", &freq);
8551+
8552+
if (ret) {
8553+
dev_dbg(hba->dev, "Cannnot query 'ref-clk-freq' property = %d", ret);
8554+
return REF_CLK_FREQ_INVAL;
8555+
}
8556+
8557+
return ufs_get_bref_clk_from_hz(freq);
8558+
}
8559+
85478560
static int ufshcd_init_clocks(struct ufs_hba *hba)
85488561
{
85498562
int ret = 0;
@@ -8637,6 +8650,9 @@ static int ufshcd_hba_init(struct ufs_hba *hba)
86378650
if (err)
86388651
goto out_disable_hba_vreg;
86398652

8653+
if (hba->dev_ref_clk_freq == REF_CLK_FREQ_INVAL)
8654+
hba->dev_ref_clk_freq = ufshcd_parse_ref_clk_property(hba);
8655+
86408656
err = ufshcd_setup_clocks(hba, true);
86418657
if (err)
86428658
goto out_disable_hba_vreg;

0 commit comments

Comments
 (0)