scsi: ufs: Add support for clock and regulator initializaiton
Subsystems (4)
cover scsi: ufs: Add support for clock and regulator initializaiton
UFS HCI specificaiton allows the hardware vendors to have vendor specific configurations using a dedicated register space. Most of these register configurations are unique to each controller. The generic UFSHCD exports a set of useful vendor operations that can be used to configure the host controller. In addition, the vendor specific operations can also be used to control the power supply of controller and Uni-Pro h/w blocks.
This patchset adds support for vendor specific initialization, regulator and clock initialization based on device-tree properties.
Sujit Reddy Thumma (3):
scsi: ufs: Allow vendor specific initialization
scsi: ufs: Add regulator enable support
scsi: ufs: Add clock initialization support
.../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 31 ++ drivers/scsi/ufs/ufs.h | 23 + drivers/scsi/ufs/ufshcd-pci.c | 8 +- drivers/scsi/ufs/ufshcd-pltfrm.c | 176 ++++++++- drivers/scsi/ufs/ufshcd.c | 433 ++++++++++++++++++-- drivers/scsi/ufs/ufshcd.h | 55 +++- 6 files changed, 689 insertions(+), 37 deletions(-)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation.
PATCH 1/3 scsi: ufs: Allow vendor specific initialization
Some vendor specific controller versions might need to configure vendor specific - registers, clocks, voltage regulators etc. to initialize the host controller UTP layer and Uni-Pro stack. Provide some common initialization operations that can be used to configure vendor specifics. The methods can be extended in future, for example, for power mode transitions.
The operations are vendor/board specific and hence determined with the help of compatible property in device tree.
--- drivers/scsi/ufs/ufshcd-pci.c | 8 ++- drivers/scsi/ufs/ufshcd-pltfrm.c | 23 +++++- drivers/scsi/ufs/ufshcd.c | 157 ++++++++++++++++++++++++++++++-------- drivers/scsi/ufs/ufshcd.h | 34 ++++++++- 4 files changed, 185 insertions(+), 37 deletions(-)
drivers/scsi/ufs/ufshcd-pci.c +7 -1
@@ -191,7 +191,13 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return err; } - err =ufshcd_init (&pdev->dev, &hba, mmio_base, pdev->irq); + err =ufshcd_alloc_host (&pdev->dev, &hba); +if (err) { +dev_err (&pdev->dev,"Allocation failed\n" ); + goto out_iounmap + } + + err =ufshcd_init (hba, mmio_base, pdev->irq);if (err) {dev_err (&pdev->dev,"Initialization failed\n" );return err;
drivers/scsi/ufs/ufshcd-pltfrm.c +22 -1
@@ -35,9 +35,22 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> +#include <linux/of.h> #include "ufshcd.h" +static const struct of_device_id ufs_of_match[]; +static struct ufs_hba_variant_ops *get_variant_ops (struct device *dev) +{ +if (dev->of_node) { +const struct of_device_id *match; + match =of_match_node (ufs_of_match, dev->of_node); +return (struct ufs_hba_variant_ops *)match->data; + } + +return NULL ; +} +#ifdef CONFIG_PM /** * ufshcd_pltfrm_suspend - suspend power management function
@@ -150,10 +163,18 @@ static int ufshcd_pltfrm_probe(struct platform_device *pdev) goto out; } + err =ufshcd_alloc_host (dev, &hba); +if (err) { +dev_err (&pdev->dev,"Allocation failed\n" ); + goto out; + } + + hba->vops =get_variant_ops (&pdev->dev); +pm_runtime_set_active (&pdev->dev);pm_runtime_enable (&pdev->dev); - err =ufshcd_init (dev, &hba, mmio_base, irq); + err =ufshcd_init (hba, mmio_base, irq);if (err) {dev_err (dev,"Intialization failed\n" ); goto out_disable_rpm;
drivers/scsi/ufs/ufshcd.c +124 -33
258 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +32 -2
@@ -68,6 +68,8 @@#define UFSHCD "ufshcd"#define UFSHCD_DRIVER_VERSION "0.2" +struct ufs_hba ; +enum dev_cmd_type {DEV_CMD_TYPE_NOP =0x0 ,DEV_CMD_TYPE_QUERY =0x1 ,
@@ -152,6 +154,30 @@ struct ufs_dev_cmd {struct ufs_query query; }; +#define PRE_CHANGE 0 +#define POST_CHANGE 1 +/** +* struct ufs_hba_variant_ops - variant specific callbacks +* @name: variant name +* @init: called when the driver is initialized +* @exit: called to cleanup everything done in init +* @setup_clocks: called before touching any of the controller registers +* @setup_regulators: called before accessing the host controller +* @hce_enable_notify: called before and after HCE enable bit is set to allow +* variant specific Uni-Pro initialization. +* @link_startup_notify: called before and after Link startup is carried out +* to allow variant specific Uni-Pro initialization. +*/ +struct ufs_hba_variant_ops { +const char *name; +int (*init)(struct ufs_hba *); +void (*exit)(struct ufs_hba *); +int (*setup_clocks)(struct ufs_hba *,bool ); +int (*setup_regulators)(struct ufs_hba *,bool ); +int (*hce_enable_notify)(struct ufs_hba *,bool ); +int (*link_startup_notify)(struct ufs_hba *,bool ); +}; +/** * struct ufs_hba - per adapter private structure * @mmio_base: UFSHCI base register address
@@ -171,6 +197,8 @@ struct ufs_dev_cmd {* @nutrs: Transfer Request Queue depth supported by controller * @nutmrs: Task Management Queue depth supported by controller * @ufs_version: UFS Version to which controller complies +* @vops: pointer to variant specific operations +* @priv: pointer to variant specific private data * @irq: Irq number of the controller * @active_uic_cmd: handle of active UIC command * @uic_cmd_mutex: mutex for uic command
@@ -217,6 +245,8 @@ struct ufs_hba {int nutrs;int nutmrs;u32 ufs_version; +struct ufs_hba_variant_ops *vops; +void *priv;unsigned int irq;struct uic_command *active_uic_cmd;
@@ -253,8 +283,8 @@ struct ufs_hba {#define ufshcd_readl (hba, reg) \ readl((hba)->mmio_base + (reg)) -int ufshcd_init (struct device *,struct ufs_hba ** ,void __iomem * , -unsigned int ); +int ufshcd_alloc_host (struct device *,struct ufs_hba **); +int ufshcd_init (struct ufs_hba * ,void __iomem * ,unsigned int );void ufshcd_remove (struct ufs_hba *);/**
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation.
Re: [PATCH 1/3] scsi: ufs: Allow vendor specific initialization
On Tue, Aug 13, 2013 at 04:30:18PM +0530, Sujit Reddy Thumma wrote:
[..]
drivers/scsi/ufs/ufshcd-pci.c ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 197
Quoted 13 lines
drivers/scsi/ufs/ufshcd-pci.c +4
-1@@ -191,7 +191,13 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return err; } - err =ufshcd_init (&pdev->dev, &hba, mmio_base, pdev->irq); + err =ufshcd_alloc_host (&pdev->dev, &hba); +if (err) { +dev_err (&pdev->dev,"Allocation failed\n" ); + goto out_iounmap
You seem to be missing a semicolon here.
Also, which tree were these patches generated against? They fail to apply at least on the last few 3.11-rc's.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH 1/3] scsi: ufs: Allow vendor specific initialization
Quoted 10 lines · Josh Cartwright
On Tue, Aug 13, 2013 at 04:30:18PM +0530, Sujit Reddy Thumma wrote:
[..]Quoted 8 lines
drivers/scsi/ufs/ufshcd-pci.c +0
-0@@ -191,7 +191,13 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return err; }
Quoted 7 lines
drivers/scsi/ufs/ufshcd-pci.c ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 197
Quoted 5 lines
drivers/scsi/ufs/ufshcd-pci.c +4
-1- err =ufshcd_init (&pdev->dev, &hba, mmio_base, pdev->irq); + err =ufshcd_alloc_host (&pdev->dev, &hba); +if (err) { +dev_err (&pdev->dev,"Allocation failed\n" ); + goto out_iounmapYou seem to be missing a semicolon here.
I should have compiled the with pci config enabled :)
Quoted 3 lines
Also, which tree were these patches generated against? They fail to apply at least on the last few 3.11-rc's.
I have rebased on top of scsi-misc branch along with few UFS patches that aren't merged ([PATCH 0/9] scsi:ufs: query, bkops support and other fixes + [PATCH V5 0/4] scsi: ufs: Improve UFS error handling
patch series).
Signature · 2 lines
Regards, Sujit
PATCH 2/3 scsi: ufs: Add regulator enable support
In reply to Sujit Reddy ThummaUFS devices are powered by at most three external power supplies -
- VCC - The flash memory core power supply, 2.7V to 3.6V or 1.70V to 1.95V
- VCCQ - The controller and I/O power supply, 1.1V to 1.3V
- VCCQ2 - Secondary controller and/or I/O power supply, 1.65V to 1.95V
For some devices VCCQ or VCCQ2 are optional as they can be generated using internal LDO inside the UFS device.
Add DT bindings for voltage regulators that can be controlled from host driver.
--- .../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 18 ++ drivers/scsi/ufs/ufs.h | 23 +++ drivers/scsi/ufs/ufshcd-pltfrm.c | 89 +++++++++ drivers/scsi/ufs/ufshcd.c | 194 +++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 3 + 5 files changed, 325 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +18 -0
@@ -8,9 +8,27 @@ Required properties: - interrupts : <interrupt mapping for UFS host controller IRQ> - reg : <registers mapping> +Optional properties: +- vcc-supply : phandle to VCC supply regulator node +- vccq-supply : phandle to VCCQ supply regulator node +- vccq2-supply : phandle to VCCQ2 supply regulator node +- vcc-max-microamp : specifies max. load that can be drawn from vcc supply +- vccq-max-microamp : specifies max. load that can be drawn from vccq supply +- vccq2-max-microamp : specifies max. load that can be drawn from vccq2 supply + +Note: If above properties are not defined it can be assumed that the supply +regulators are always on. + Example: ufshc@0xfc598000 { compatible = "jedec,ufs-1.1"; reg = <0xfc598000 0x800>; interrupts = <0 28 0>; + + vcc-supply = <&xxx_reg1>; + vccq-supply = <&xxx_reg2>; + vccq2-supply = <&xxx_reg3>; + vcc-max-microamp = 500000; + vccq-max-microamp = 200000; + vccq2-max-microamp = 200000; };
drivers/scsi/ufs/ufs.h +23 -0
@@ -325,4 +325,27 @@ struct ufs_query_res { struct utp_upiu_query upiu_res; }; +#define UFS_VREG_VCC_MIN 2700000/* uV */ +#define UFS_VREG_VCC_MAX 3600000/* uV */ +#define UFS_VREG_VCCQ_MIN 1150000/* uV */ +#define UFS_VREG_VCCQ_MAX 1300000/* uV */ +#define UFS_VREG_VCCQ2_MIN 1700000/* uV */ +#define UFS_VREG_VCCQ2_MAX 1950000/* uV */ + +struct ufs_vreg { +struct regulator *reg; +const char *name; +bool enabled; +int min_uV; +int max_uV; +int min_uA; +int max_uA; +}; + +struct ufs_vreg_info { +struct ufs_vreg *vcc; +struct ufs_vreg *vccq; +struct ufs_vreg *vccq2; +}; +#endif /* End of Header */
drivers/scsi/ufs/ufshcd-pltfrm.c +89 -0
101 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.c +192 -2
218 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +3 -0
@@ -61,6 +61,7 @@#include <scsi/scsi_tcq.h> #include <scsi/scsi_dbg.h> #include <scsi/scsi_eh.h> +#include <linux/regulator/consumer.h> #include "ufs.h" #include "ufshci.h"
@@ -218,6 +219,7 @@ struct ufs_hba_variant_ops {* @saved_uic_err: sticky UIC error mask * @dev_cmd: ufs device management command information * @auto_bkops_enabled: to track whether bkops is enabled in device +* @vreg_info: UFS device voltage regulator information */ struct ufs_hba {void __iomem *mmio_base;
@@ -276,6 +278,7 @@ struct ufs_hba {struct ufs_dev_cmd dev_cmd;bool auto_bkops_enabled; +struct ufs_vreg_info vreg_info; };#define ufshcd_writel (hba, val, reg) \
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation.
PATCH 3/3 scsi: ufs: Add clock initialization support
In reply to Sujit Reddy ThummaAdd generic clock initialization support for UFSHCD platform driver. The clock info is read from device tree using standard clock bindings. A generic max-clock-frequency-hz property is defined to save information on maximum operating clock frequency the h/w supports.
--- .../devicetree/bindings/ufs/ufshcd-pltfrm.txt | 15 +++- drivers/scsi/ufs/ufshcd-pltfrm.c | 64 ++++++++++++++ drivers/scsi/ufs/ufshcd.c | 90 +++++++++++++++++++- drivers/scsi/ufs/ufshcd.h | 18 ++++ 4 files changed, 184 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +14 -1
@@ -16,8 +16,17 @@ Optional properties: - vccq-max-microamp : specifies max. load that can be drawn from vccq supply - vccq2-max-microamp : specifies max. load that can be drawn from vccq2 supply +- clocks : List of phandle and clock specifier pairs +- clock-names : List of clock input name strings sorted in the same + order as the clocks property. +- max-clock-frequency-hz : List of maximum operating frequency stored in the same + order as the clocks property. If this property is not + defined or a value in the array is "0" then it is assumed + that the frequency is set by the parent clock or a + fixed rate clock source. + Note: If above properties are not defined it can be assumed that the supply -regulators are always on. +regulators or clocks are always on. Example: ufshc@0xfc598000 {
@@ -31,4 +40,8 @@ Example: vcc-max-microamp = 500000; vccq-max-microamp = 200000; vccq2-max-microamp = 200000; + + clocks = <&core 0>, <&ref 0>, <&iface 0>; + clock-names = "core_clk", "ref_clk", "iface_clk"; + max-clock-frequency-hz = <100000000 19200000 0>; };
drivers/scsi/ufs/ufshcd-pltfrm.c +64 -0
82 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.c +88 -2
120 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +18 -0
@@ -155,6 +155,22 @@ struct ufs_dev_cmd {struct ufs_query query; }; +/** +* struct ufs_clk_info - UFS clock related info +* @list: list headed by hba->clk_list_head +* @clk: clock node +* @name: clock name +* @max_freq: maximum frequency supported by the clock +* @enabled: variable to check against multiple enable/disable +*/ +struct ufs_clk_info { +struct list_head list; +struct clk *clk; +const char *name; +u32 max_freq; +bool enabled; +}; +#define PRE_CHANGE 0#define POST_CHANGE 1/**
@@ -220,6 +236,7 @@ struct ufs_hba_variant_ops {* @dev_cmd: ufs device management command information * @auto_bkops_enabled: to track whether bkops is enabled in device * @vreg_info: UFS device voltage regulator information +* @clk_list_head: UFS host controller clocks list node head */ struct ufs_hba {void __iomem *mmio_base;
@@ -279,6 +296,7 @@ struct ufs_hba {bool auto_bkops_enabled;struct ufs_vreg_info vreg_info; +struct list_head clk_list_head; };#define ufshcd_writel (hba, val, reg) \
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation.