crypto: Fix clocks and DMA configuration
cover crypto: Fix clocks and DMA configuration
This patch-set ensures any clocks that are obtained by the ux500 crypto drivers are prepared for use. We also request DMA channels and configure them in the correct way using the new dmaengine API.
arch/arm/mach-ux500/board-mop500.c | 14 ++------------ drivers/crypto/ux500/cryp/cryp.h | 7 ++++++- drivers/crypto/ux500/cryp/cryp_core.c | 31 ++++++++++++++++++++++++++++++- drivers/crypto/ux500/hash/hash_alg.h | 5 ++++- drivers/crypto/ux500/hash/hash_core.c | 24 ++++++++++++++++++++++-- 5 files changed, 64 insertions(+), 17 deletions(-)
PATCH 1/8 crypto: ux500/hash - Prepare clock before enabling it
If we fail to prepare the ux500-hash clock before enabling it the platform will fail to boot. Here we insure this happens.
--- drivers/crypto/ux500/hash/hash_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/crypto/ux500/hash/hash_core.c +11 -1
@@ -1727,11 +1727,17 @@ static int ux500_hash_probe(struct platform_device *pdev) goto out_regulator; } + ret =clk_prepare (device_data->clk); +if (ret) { +dev_err (dev,"[%s] clk_prepare() failed!" , __func__); + goto out_clk; + } +/* Enable device power (and clock) */ ret =hash_enable_power (device_data, false);if (ret) {dev_err (dev,"[%s]: hash_enable_power() failed!" , __func__); - goto out_clk; + goto out_clk_unprepare; } ret =hash_check_hw (device_data);
@@ -1763,6 +1769,9 @@ static int ux500_hash_probe(struct platform_device *pdev) out_power:hash_disable_power (device_data, false); +out_clk_unprepare: +clk_unprepare (device_data->clk); + out_clk:clk_put (device_data->clk);
@@ -1827,6 +1836,7 @@ static int ux500_hash_remove(struct platform_device *pdev)dev_err (dev,"[%s]: hash_disable_power() failed" , __func__); +clk_unprepare (device_data->clk);clk_put (device_data->clk);regulator_put (device_data->regulator);
Signature · 1 line
1.7.10.4
Re: [PATCH 1/8] crypto: ux500/hash - Prepare clock before enabling it
Quoted 56 lines · Lee Jones
If we fail to prepare the ux500-hash clock before enabling it the platform will fail to boot. Here we insure this happens.
Cc Herbert Xu <[email protected]>Cc David S. Miller <[email protected]>Cc Andreas Westin <[email protected]>Cc Ulf Hansson <[email protected]>Cc linux-crypto at vger.kernel.orgAcked-by Arnd Bergmann <[email protected]>Signed-off-by Lee Jones <[email protected]>--- drivers/crypto/ux500/hash/hash_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/crypto/ux500/hash/hash_core.c +11
-2@@ -1727,11 +1727,17 @@ static int ux500_hash_probe(struct platform_device *pdev) goto out_regulator; } + ret =clk_prepare (device_data->clk); +if (ret) { +dev_err (dev,"[%s] clk_prepare() failed!" , __func__); + goto out_clk; + } +/* Enable device power (and clock) */ ret =hash_enable_power (device_data, false);if (ret) {dev_err (dev,"[%s]: hash_enable_power() failed!" , __func__); - goto out_clk; + goto out_clk_unprepare; } ret =hash_check_hw (device_data);@@ -1763,6 +1769,9 @@ static int ux500_hash_probe(struct platform_device *pdev) out_power:hash_disable_power (device_data, false); +out_clk_unprepare: +clk_unprepare (device_data->clk); + out_clk:clk_put (device_data->clk);@@ -1827,6 +1836,7 @@ static int ux500_hash_remove(struct platform_device *pdev)dev_err (dev,"[%s]: hash_disable_power() failed" , __func__); +clk_unprepare (device_data->clk);clk_put (device_data->clk);regulator_put (device_data->regulator); --
Quoted 2 lines
1.7.10.4
PATCH 2/8 crypto: ux500/hash - Set DMA configuration though dma_slave_config()
In reply to Lee JonesThe DMA controller currently takes configuration information from information passed though dma_channel_request(), but it shouldn't. Using the API, the DMA channel should only be configured during a dma_slave_config() call.
--- drivers/crypto/ux500/hash/hash_alg.h | 5 ++++- drivers/crypto/ux500/hash/hash_core.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/crypto/ux500/hash/hash_alg.h +4 -1
@@ -11,6 +11,7 @@#include <linux/bitops.h> #define HASH_BLOCK_SIZE 64 +#define HASH_DMA_FIFO 4#define HASH_DMA_ALIGN_SIZE 4#define HASH_DMA_PERFORMANCE_MIN_SIZE 1024#define HASH_BYTES_PER_WORD 4
@@ -347,7 +348,8 @@ struct hash_req_ctx {/** * struct hash_device_data - structure for a hash device. -* @base: Pointer to the hardware base address. +* @base: Pointer to virtual base address of the hash device. +* @phybase: Pointer to physical memory location of the hash device. * @list_node: For inclusion in klist. * @dev: Pointer to the device dev structure. * @ctx_lock: Spinlock for current_ctx.
@@ -361,6 +363,7 @@ struct hash_req_ctx {*/ struct hash_device_data {struct hash_register __iomem *base; +phys_addr_t phybase;struct klist_node list_node;struct device *dev;struct spinlock ctx_lock;
drivers/crypto/ux500/hash/hash_core.c +10 -0
@@ -123,6 +123,13 @@ static void hash_dma_setup_channel(struct hash_device_data *device_data, struct device *dev) {struct hash_platform_data *platform_data = dev->platform_data; +struct dma_slave_config conf = { + .direction =DMA_MEM_TO_DEV , + .dst_addr = device_data->phybase +HASH_DMA_FIFO , + .dst_addr_width =DMA_SLAVE_BUSWIDTH_2_BYTES , + .dst_maxburst =16 , + }; +dma_cap_zero (device_data->dma.mask);dma_cap_set (DMA_SLAVE , device_data->dma.mask);
@@ -132,6 +139,8 @@ static void hash_dma_setup_channel(struct hash_device_data *device_data, platform_data->dma_filter, device_data->dma.cfg_mem2hash); +dmaengine_slave_config (device_data->dma.chan_mem2hash, &conf); +init_completion (&device_data->dma.complete); }
@@ -1700,6 +1709,7 @@ static int ux500_hash_probe(struct platform_device *pdev) goto out_kfree; } + device_data->phybase = res->start; device_data->base =ioremap (res->start,resource_size (res));if (!device_data->base) { dev_err(dev, "[%s] ioremap() failed!",
Signature · 1 line
1.7.10.4
PATCH 3/8 ARM: ux500: Stop passing Hash DMA channel config information though pdata
In reply to Lee JonesDMA channel configuration information should be setup in the driver. The Ux500 Hash driver now does this, so there's no need to send it though here too.
--- arch/arm/mach-ux500/board-mop500.c | 4 ---- 1 file changed, 4 deletions(-)
arch/arm/mach-ux500/board-mop500.c +0 -4
@@ -473,11 +473,7 @@ static struct cryp_platform_data u8500_cryp1_platform_data = {static struct stedma40_chan_cfg u8500_hash_dma_cfg_tx = { .dir =STEDMA40_MEM_TO_PERIPH , .dev_type =DB8500_DMA_DEV50_HAC1_TX , - .src_info.data_width =STEDMA40_WORD_WIDTH , - .dst_info.data_width =STEDMA40_WORD_WIDTH , .mode =STEDMA40_MODE_LOGICAL , - .src_info.psize =STEDMA40_PSIZE_LOG_16 , - .dst_info.psize =STEDMA40_PSIZE_LOG_16 , };static struct hash_platform_data u8500_hash1_platform_data = {
Signature · 1 line
1.7.10.4
PATCH 4/8 crypto: ux500/cryp - Prepare clock before enabling it
In reply to Lee JonesIf we fail to prepare the ux500-cryp clock before enabling it the platform will fail to boot. Here we insure this happens.
--- drivers/crypto/ux500/cryp/cryp_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/crypto/ux500/cryp/cryp_core.c +11 -1
@@ -1459,11 +1459,17 @@ static int ux500_cryp_probe(struct platform_device *pdev) goto out_regulator; } + ret =clk_prepare (device_data->clk); +if (ret) { +dev_err (dev,"[%s]: clk_prepare() failed!" , __func__); + goto out_clk; + } +/* Enable device power (and clock) */ ret =cryp_enable_power (device_data->dev, device_data, false);if (ret) {dev_err (dev,"[%s]: cryp_enable_power() failed!" , __func__); - goto out_clk; + goto out_clk_unprepare; } cryp_error =cryp_check (device_data);
@@ -1524,6 +1530,9 @@ static int ux500_cryp_probe(struct platform_device *pdev) out_power:cryp_disable_power (device_data->dev, device_data, false); +out_clk_unprepare: +clk_unprepare (device_data->clk); + out_clk:clk_put (device_data->clk);
@@ -1594,6 +1603,7 @@ static int ux500_cryp_remove(struct platform_device *pdev)dev_err (&pdev->dev,"[%s]: cryp_disable_power() failed" , __func__); +clk_unprepare (device_data->clk);clk_put (device_data->clk);regulator_put (device_data->pwr_regulator);
Signature · 1 line
1.7.10.4
Re: [PATCH 4/8] crypto: ux500/cryp - Prepare clock before enabling it
Quoted 56 lines · Lee Jones
If we fail to prepare the ux500-cryp clock before enabling it the platform will fail to boot. Here we insure this happens.
Cc Herbert Xu <[email protected]>Cc David S. Miller <[email protected]>Cc Andreas Westin <[email protected]>Cc Ulf Hansson <[email protected]>Cc linux-crypto at vger.kernel.orgAcked-by Arnd Bergmann <[email protected]>Signed-off-by Lee Jones <[email protected]>--- drivers/crypto/ux500/cryp/cryp_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/crypto/ux500/cryp/cryp_core.c +11
-2@@ -1459,11 +1459,17 @@ static int ux500_cryp_probe(struct platform_device *pdev) goto out_regulator; } + ret =clk_prepare (device_data->clk); +if (ret) { +dev_err (dev,"[%s]: clk_prepare() failed!" , __func__); + goto out_clk; + } +/* Enable device power (and clock) */ ret =cryp_enable_power (device_data->dev, device_data, false);if (ret) {dev_err (dev,"[%s]: cryp_enable_power() failed!" , __func__); - goto out_clk; + goto out_clk_unprepare; } cryp_error =cryp_check (device_data);@@ -1524,6 +1530,9 @@ static int ux500_cryp_probe(struct platform_device *pdev) out_power:cryp_disable_power (device_data->dev, device_data, false); +out_clk_unprepare: +clk_unprepare (device_data->clk); + out_clk:clk_put (device_data->clk);@@ -1594,6 +1603,7 @@ static int ux500_cryp_remove(struct platform_device *pdev)dev_err (&pdev->dev,"[%s]: cryp_disable_power() failed" , __func__); +clk_unprepare (device_data->clk);clk_put (device_data->clk);regulator_put (device_data->pwr_regulator); --
Quoted 2 lines
1.7.10.4
PATCH 5/8 crypto: ux500/cryp - Set DMA configuration though dma_slave_config()
In reply to Lee JonesThe DMA controller currently takes configuration information from information passed though dma_channel_request(), but it shouldn't. Using the API, the DMA channel should only be configured during a dma_slave_config() call.
--- drivers/crypto/ux500/cryp/cryp.h | 7 ++++++- drivers/crypto/ux500/cryp/cryp_core.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/crypto/ux500/cryp/cryp.h +6 -1
@@ -114,6 +114,9 @@ enum cryp_status_id { };/* Cryp DMA interface */ +#define CRYP_DMA_TX_FIFO 0x08 +#define CRYP_DMA_RX_FIFO 0x10 +enum cryp_dma_req_type {CRYP_DMA_DISABLE_BOTH ,CRYP_DMA_ENABLE_IN_DATA ,
@@ -217,7 +220,8 @@ struct cryp_dma {/** * struct cryp_device_data - structure for a cryp device. -* @base: Pointer to the hardware base address. +* @base: Pointer to virtual base address of the cryp device. +* @phybase: Pointer to physical memory location of the cryp device. * @dev: Pointer to the devices dev structure. * @clk: Pointer to the device's clock control. * @pwr_regulator: Pointer to the device's power control.
@@ -232,6 +236,7 @@ struct cryp_dma {*/ struct cryp_device_data {struct cryp_register __iomem *base; +phys_addr_t phybase;struct device *dev;struct clk *clk;struct regulator *pwr_regulator;
drivers/crypto/ux500/cryp/cryp_core.c +17 -0
@@ -476,6 +476,19 @@ static int cryp_get_device_data(struct cryp_ctx *ctx,static void cryp_dma_setup_channel (struct cryp_device_data *device_data,struct device *dev) { +struct dma_slave_config mem2cryp = { + .direction =DMA_MEM_TO_DEV , + .dst_addr = device_data->phybase +CRYP_DMA_TX_FIFO , + .dst_addr_width =DMA_SLAVE_BUSWIDTH_2_BYTES , + .dst_maxburst =4 , + }; +struct dma_slave_config cryp2mem = { + .direction =DMA_DEV_TO_MEM , + .src_addr = device_data->phybase +CRYP_DMA_RX_FIFO , + .src_addr_width =DMA_SLAVE_BUSWIDTH_2_BYTES , + .src_maxburst =4 , + }; +dma_cap_zero (device_data->dma.mask);dma_cap_set (DMA_SLAVE , device_data->dma.mask);
@@ -491,6 +504,9 @@ static void cryp_dma_setup_channel(struct cryp_device_data *device_data, stedma40_filter, device_data->dma.cfg_cryp2mem); +dmaengine_slave_config (device_data->dma.chan_mem2cryp, &mem2cryp); +dmaengine_slave_config (device_data->dma.chan_cryp2mem, &cryp2mem); +init_completion (&device_data->dma.cryp_dma_complete); }
@@ -1432,6 +1448,7 @@ static int ux500_cryp_probe(struct platform_device *pdev) goto out_kfree; } + device_data->phybase = res->start; device_data->base =ioremap (res->start,resource_size (res));if (!device_data->base) {dev_err (dev,"[%s]: ioremap failed!" , __func__);
Signature · 1 line
1.7.10.4
PATCH 6/8 ARM: ux500: Stop passing Cryp DMA channel config information though pdata
In reply to Lee JonesDMA channel configuration information should be setup in the driver. The Ux500 Cryp driver now does this, so there's no need to send it though here too.
--- arch/arm/mach-ux500/board-mop500.c | 8 -------- 1 file changed, 8 deletions(-)
arch/arm/mach-ux500/board-mop500.c +0 -8
@@ -453,20 +453,12 @@ static struct cryp_platform_data u8500_cryp1_platform_data = { .mem_to_engine = { .dir = STEDMA40_MEM_TO_PERIPH, .dev_type = DB8500_DMA_DEV48_CAC1, - .src_info.data_width = STEDMA40_WORD_WIDTH, - .dst_info.data_width = STEDMA40_WORD_WIDTH, .mode = STEDMA40_MODE_LOGICAL, - .src_info.psize = STEDMA40_PSIZE_LOG_4, - .dst_info.psize = STEDMA40_PSIZE_LOG_4, }, .engine_to_mem = { .dir = STEDMA40_PERIPH_TO_MEM, .dev_type = DB8500_DMA_DEV48_CAC1, - .src_info.data_width = STEDMA40_WORD_WIDTH, - .dst_info.data_width = STEDMA40_WORD_WIDTH, .mode = STEDMA40_MODE_LOGICAL, - .src_info.psize = STEDMA40_PSIZE_LOG_4, - .dst_info.psize = STEDMA40_PSIZE_LOG_4, } };
Signature · 1 line
1.7.10.4
PATCH 7/8 crypto: ux500/[cryp|hash] - Show successful start-up in the bootlog
In reply to Lee JonesThe Cryp driver is currently silent and the Hash driver prints the name of its probe function unnecessarily. Let's just put a nice descriptive one-liner there instead.
--- drivers/crypto/ux500/cryp/cryp_core.c | 2 ++ drivers/crypto/ux500/hash/hash_core.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/crypto/ux500/cryp/cryp_core.c +2 -0
@@ -1542,6 +1542,8 @@ static int ux500_cryp_probe(struct platform_device *pdev) goto out_power; } +dev_info (dev,"successfully registered\n" ); +return 0 ; out_power:
drivers/crypto/ux500/hash/hash_core.c +1 -1
@@ -1773,7 +1773,7 @@ static int ux500_hash_probe(struct platform_device *pdev) goto out_power; } -dev_info (dev,"[%s] successfully probed\n" , __func__); +dev_info (dev,"successfully registered\n" );return 0 ; out_power:
Signature · 1 line
1.7.10.4
PATCH 8/8 ARM: ux500: Register Cyrp and Hash platform drivers on Snowball
In reply to Lee JonesThese drivers are now operational and even use the latest common clk and DMA APIs. There's no reason why we shouldn't start them up now.
--- arch/arm/mach-ux500/board-mop500.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/mach-ux500/board-mop500.c +2 -0
@@ -656,6 +656,8 @@ static void __init snowball_init_machine(void)mop500_snowball_ethernet_clock_enable (); +u8500_cryp1_hash1_init (parent); +/* This board has full regulator constraints */ regulator_has_full_constraints (); }
Signature · 1 line
1.7.10.4