* [PATCH 1/3] spi: sh-hspi: convert to using core message queue
[not found] ` <87obrz8qgg.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
@ 2012-03-14 9:47 ` Kuninori Morimoto
2012-03-14 9:48 ` [PATCH 2/3] spi: sh-hspi: control spi clock more correctly Kuninori Morimoto
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2012-03-14 9:47 UTC (permalink / raw)
To: Grant Likely
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
Kuninori Morimoto
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
---
drivers/spi/spi-sh-hspi.c | 152 ++++++++++++++++----------------------------
1 files changed, 55 insertions(+), 97 deletions(-)
diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
index 8356ec8..4290673 100644
--- a/drivers/spi/spi-sh-hspi.c
+++ b/drivers/spi/spi-sh-hspi.c
@@ -27,7 +27,6 @@
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/list.h>
-#include <linux/workqueue.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
@@ -50,11 +49,7 @@
struct hspi_priv {
void __iomem *addr;
struct spi_master *master;
- struct list_head queue;
- struct workqueue_struct *workqueue;
- struct work_struct ws;
struct device *dev;
- spinlock_t lock;
};
/*
@@ -148,88 +143,82 @@ static int hspi_pop(struct hspi_priv *hspi, struct spi_message *msg,
return 0;
}
-static void hspi_work(struct work_struct *work)
+/*
+ * spi master function
+ */
+static int hspi_prepare_transfer(struct spi_master *master)
{
- struct hspi_priv *hspi = container_of(work, struct hspi_priv, ws);
- struct sh_hspi_info *info = hspi2info(hspi);
- struct spi_message *msg;
- struct spi_transfer *t;
- unsigned long flags;
- u32 data;
- int ret;
-
- dev_dbg(hspi->dev, "%s\n", __func__);
+ struct hspi_priv *hspi = spi_master_get_devdata(master);
- /************************ pm enable ************************/
pm_runtime_get_sync(hspi->dev);
+ return 0;
+}
- /* setup first of all in under pm_runtime */
- data = SH_HSPI_CLK_DIVC(info->flags);
+static int hspi_unprepare_transfer(struct spi_master *master)
+{
+ struct hspi_priv *hspi = spi_master_get_devdata(master);
- if (info->flags & SH_HSPI_FBS)
- data |= 1 << 7;
- if (info->flags & SH_HSPI_CLKP_HIGH)
- data |= 1 << 6;
- if (info->flags & SH_HSPI_IDIV_DIV128)
- data |= 1 << 5;
+ pm_runtime_put_sync(hspi->dev);
+ return 0;
+}
- hspi_write(hspi, SPCR, data);
- hspi_write(hspi, SPSR, 0x0);
- hspi_write(hspi, SPSCR, 0x1); /* master mode */
+static int hspi_transfer_one_message(struct spi_master *master,
+ struct spi_message *msg)
+{
+ struct hspi_priv *hspi = spi_master_get_devdata(master);
+ struct spi_transfer *t;
+ int ret;
- while (1) {
- msg = NULL;
+ dev_dbg(hspi->dev, "%s\n", __func__);
- /************************ spin lock ************************/
- spin_lock_irqsave(&hspi->lock, flags);
- if (!list_empty(&hspi->queue)) {
- msg = list_entry(hspi->queue.next,
- struct spi_message, queue);
- list_del_init(&msg->queue);
+ ret = 0;
+ list_for_each_entry(t, &msg->transfers, transfer_list) {
+ if (t->tx_buf) {
+ ret = hspi_push(hspi, msg, t);
+ if (ret < 0)
+ goto error;
}
- spin_unlock_irqrestore(&hspi->lock, flags);
- /************************ spin unlock ************************/
- if (!msg)
- break;
-
- ret = 0;
- list_for_each_entry(t, &msg->transfers, transfer_list) {
- if (t->tx_buf) {
- ret = hspi_push(hspi, msg, t);
- if (ret < 0)
- goto error;
- }
- if (t->rx_buf) {
- ret = hspi_pop(hspi, msg, t);
- if (ret < 0)
- goto error;
- }
- msg->actual_length += t->len;
+ if (t->rx_buf) {
+ ret = hspi_pop(hspi, msg, t);
+ if (ret < 0)
+ goto error;
}
-error:
- msg->status = ret;
- msg->complete(msg->context);
+ msg->actual_length += t->len;
}
+error:
- pm_runtime_put_sync(hspi->dev);
- /************************ pm disable ************************/
+ msg->status = ret;
+ spi_finalize_current_message(master);
- return;
+ return ret;
}
-/*
- * spi master function
- */
static int hspi_setup(struct spi_device *spi)
{
struct hspi_priv *hspi = spi_master_get_devdata(spi->master);
struct device *dev = hspi->dev;
+ struct sh_hspi_info *info = hspi2info(hspi);
+ u32 data;
if (8 != spi->bits_per_word) {
dev_err(dev, "bits_per_word should be 8\n");
return -EIO;
}
+ /* setup first of all in under pm_runtime */
+ data = SH_HSPI_CLK_DIVC(info->flags);
+
+ if (info->flags & SH_HSPI_FBS)
+ data |= 1 << 7;
+ if (info->flags & SH_HSPI_CLKP_HIGH)
+ data |= 1 << 6;
+ if (info->flags & SH_HSPI_IDIV_DIV128)
+ data |= 1 << 5;
+
+ hspi_write(hspi, SPCR, data);
+ hspi_write(hspi, SPSR, 0x0);
+ hspi_write(hspi, SPSCR, 0x1); /* master mode */
+
dev_dbg(dev, "%s setup\n", spi->modalias);
return 0;
@@ -243,26 +232,6 @@ static void hspi_cleanup(struct spi_device *spi)
dev_dbg(dev, "%s cleanup\n", spi->modalias);
}
-static int hspi_transfer(struct spi_device *spi, struct spi_message *msg)
-{
- struct hspi_priv *hspi = spi_master_get_devdata(spi->master);
- unsigned long flags;
-
- /************************ spin lock ************************/
- spin_lock_irqsave(&hspi->lock, flags);
-
- msg->actual_length = 0;
- msg->status = -EINPROGRESS;
- list_add_tail(&msg->queue, &hspi->queue);
-
- spin_unlock_irqrestore(&hspi->lock, flags);
- /************************ spin unlock ************************/
-
- queue_work(hspi->workqueue, &hspi->ws);
-
- return 0;
-}
-
static int __devinit hspi_probe(struct platform_device *pdev)
{
struct resource *res;
@@ -296,27 +265,19 @@ static int __devinit hspi_probe(struct platform_device *pdev)
ret = -ENOMEM;
goto error1;
}
- hspi->workqueue = create_singlethread_workqueue(dev_name(&pdev->dev));
- if (!hspi->workqueue) {
- dev_err(&pdev->dev, "create workqueue error\n");
- ret = -EBUSY;
- goto error2;
- }
-
- spin_lock_init(&hspi->lock);
- INIT_LIST_HEAD(&hspi->queue);
- INIT_WORK(&hspi->ws, hspi_work);
master->num_chipselect = 1;
master->bus_num = pdev->id;
master->setup = hspi_setup;
- master->transfer = hspi_transfer;
master->cleanup = hspi_cleanup;
master->mode_bits = SPI_CPOL | SPI_CPHA;
+ master->prepare_transfer_hardware = hspi_prepare_transfer;
+ master->transfer_one_message = hspi_transfer_one_message;
+ master->unprepare_transfer_hardware = hspi_unprepare_transfer;
ret = spi_register_master(master);
if (ret < 0) {
dev_err(&pdev->dev, "spi_register_master error.\n");
- goto error3;
+ goto error2;
}
pm_runtime_enable(&pdev->dev);
@@ -325,8 +286,6 @@ static int __devinit hspi_probe(struct platform_device *pdev)
return 0;
- error3:
- destroy_workqueue(hspi->workqueue);
error2:
devm_iounmap(hspi->dev, hspi->addr);
error1:
@@ -342,7 +301,6 @@ static int __devexit hspi_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
spi_unregister_master(hspi->master);
- destroy_workqueue(hspi->workqueue);
devm_iounmap(hspi->dev, hspi->addr);
return 0;
--
1.7.5.4
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] spi: sh-hspi: control spi clock more correctly
[not found] ` <87obrz8qgg.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2012-03-14 9:47 ` [PATCH 1/3] spi: sh-hspi: convert to using core message queue Kuninori Morimoto
@ 2012-03-14 9:48 ` Kuninori Morimoto
2012-03-14 9:48 ` [PATCH 3/3] spi: sh-hspi: modify write/read method Kuninori Morimoto
2012-03-15 9:42 ` [PATCH 0/3] spi: sh-hspi: convert to using core message queue and fixup Grant Likely
3 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2012-03-14 9:48 UTC (permalink / raw)
To: Grant Likely
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
Kuninori Morimoto
Current sh-hspi had used platform-specific speed.
This patch remove it, and use spi_transfer specific speed.
It removes unnecessary flags from struct sh_hspi_info,
but struct sh_hspi_info is still exist, since sh-hspi needs
platform info in the future.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
---
drivers/spi/spi-sh-hspi.c | 86 +++++++++++++++++++++++++++++++++++--------
include/linux/spi/sh_hspi.h | 11 -----
2 files changed, 70 insertions(+), 27 deletions(-)
diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
index 4290673..5784734 100644
--- a/drivers/spi/spi-sh-hspi.c
+++ b/drivers/spi/spi-sh-hspi.c
@@ -22,6 +22,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
+#include <linux/clk.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/timer.h>
@@ -50,6 +52,7 @@ struct hspi_priv {
void __iomem *addr;
struct spi_master *master;
struct device *dev;
+ struct clk *clk;
};
/*
@@ -162,6 +165,59 @@ static int hspi_unprepare_transfer(struct spi_master *master)
return 0;
}
+static void hspi_hw_setup(struct hspi_priv *hspi,
+ struct spi_message *msg,
+ struct spi_transfer *t)
+{
+ struct spi_device *spi = msg->spi;
+ struct device *dev = hspi->dev;
+ u32 target_rate;
+ u32 spcr, idiv_clk;
+ u32 rate, best_rate, min, tmp;
+
+ target_rate = t ? t->speed_hz : 0;
+ if (!target_rate)
+ target_rate = spi->max_speed_hz;
+
+ /*
+ * find best IDIV/CLKCx settings
+ */
+ min = ~0;
+ best_rate = 0;
+ spcr = 0;
+ for (idiv_clk = 0x00; idiv_clk <= 0x3F; idiv_clk++) {
+ rate = clk_get_rate(hspi->clk);
+
+ /* IDIV calculation */
+ if (idiv_clk & (1 << 5))
+ rate /= 128;
+ else
+ rate /= 16;
+
+ /* CLKCx calculation */
+ rate /= (((idiv_clk & 0x1F) + 1) * 2) ;
+
+ /* save best settings */
+ tmp = abs(target_rate - rate);
+ if (tmp < min) {
+ min = tmp;
+ spcr = idiv_clk;
+ best_rate = rate;
+ }
+ }
+
+ if (spi->mode & SPI_CPHA)
+ spcr |= 1 << 7;
+ if (spi->mode & SPI_CPOL)
+ spcr |= 1 << 6;
+
+ dev_dbg(dev, "speed %d/%d\n", target_rate, best_rate);
+
+ hspi_write(hspi, SPCR, spcr);
+ hspi_write(hspi, SPSR, 0x0);
+ hspi_write(hspi, SPSCR, 0x1); /* master mode */
+}
+
static int hspi_transfer_one_message(struct spi_master *master,
struct spi_message *msg)
{
@@ -173,6 +229,8 @@ static int hspi_transfer_one_message(struct spi_master *master,
ret = 0;
list_for_each_entry(t, &msg->transfers, transfer_list) {
+ hspi_hw_setup(hspi, msg, t);
+
if (t->tx_buf) {
ret = hspi_push(hspi, msg, t);
if (ret < 0)
@@ -197,28 +255,12 @@ static int hspi_setup(struct spi_device *spi)
{
struct hspi_priv *hspi = spi_master_get_devdata(spi->master);
struct device *dev = hspi->dev;
- struct sh_hspi_info *info = hspi2info(hspi);
- u32 data;
if (8 != spi->bits_per_word) {
dev_err(dev, "bits_per_word should be 8\n");
return -EIO;
}
- /* setup first of all in under pm_runtime */
- data = SH_HSPI_CLK_DIVC(info->flags);
-
- if (info->flags & SH_HSPI_FBS)
- data |= 1 << 7;
- if (info->flags & SH_HSPI_CLKP_HIGH)
- data |= 1 << 6;
- if (info->flags & SH_HSPI_IDIV_DIV128)
- data |= 1 << 5;
-
- hspi_write(hspi, SPCR, data);
- hspi_write(hspi, SPSR, 0x0);
- hspi_write(hspi, SPSCR, 0x1); /* master mode */
-
dev_dbg(dev, "%s setup\n", spi->modalias);
return 0;
@@ -237,6 +279,7 @@ static int __devinit hspi_probe(struct platform_device *pdev)
struct resource *res;
struct spi_master *master;
struct hspi_priv *hspi;
+ struct clk *clk;
int ret;
/* get base addr */
@@ -252,12 +295,20 @@ static int __devinit hspi_probe(struct platform_device *pdev)
return -ENOMEM;
}
+ clk = clk_get(NULL, "shyway_clk");
+ if (!clk) {
+ dev_err(&pdev->dev, "shyway_clk is required\n");
+ ret = -EINVAL;
+ goto error0;
+ }
+
hspi = spi_master_get_devdata(master);
dev_set_drvdata(&pdev->dev, hspi);
/* init hspi */
hspi->master = master;
hspi->dev = &pdev->dev;
+ hspi->clk = clk;
hspi->addr = devm_ioremap(hspi->dev,
res->start, resource_size(res));
if (!hspi->addr) {
@@ -289,6 +340,8 @@ static int __devinit hspi_probe(struct platform_device *pdev)
error2:
devm_iounmap(hspi->dev, hspi->addr);
error1:
+ clk_put(clk);
+ error0:
spi_master_put(master);
return ret;
@@ -300,6 +353,7 @@ static int __devexit hspi_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
+ clk_put(hspi->clk);
spi_unregister_master(hspi->master);
devm_iounmap(hspi->dev, hspi->addr);
diff --git a/include/linux/spi/sh_hspi.h b/include/linux/spi/sh_hspi.h
index 956d112..a1121f8 100644
--- a/include/linux/spi/sh_hspi.h
+++ b/include/linux/spi/sh_hspi.h
@@ -17,18 +17,7 @@
#ifndef SH_HSPI_H
#define SH_HSPI_H
-/*
- * flags
- *
- *
- */
-#define SH_HSPI_CLK_DIVC(d) (d & 0xFF)
-
-#define SH_HSPI_FBS (1 << 8)
-#define SH_HSPI_CLKP_HIGH (1 << 9) /* default LOW */
-#define SH_HSPI_IDIV_DIV128 (1 << 10) /* default div16 */
struct sh_hspi_info {
- u32 flags;
};
#endif
--
1.7.5.4
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] spi: sh-hspi: modify write/read method
[not found] ` <87obrz8qgg.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2012-03-14 9:47 ` [PATCH 1/3] spi: sh-hspi: convert to using core message queue Kuninori Morimoto
2012-03-14 9:48 ` [PATCH 2/3] spi: sh-hspi: control spi clock more correctly Kuninori Morimoto
@ 2012-03-14 9:48 ` Kuninori Morimoto
2012-03-15 9:42 ` [PATCH 0/3] spi: sh-hspi: convert to using core message queue and fixup Grant Likely
3 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2012-03-14 9:48 UTC (permalink / raw)
To: Grant Likely
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
Kuninori Morimoto
Current sh-hspi had wrong write/read method which was not linux standard.
If spi_transfer requests tx[2], rx[2] len=2,
then, driver should run tx[0], rx[0], tx[1], rx[1].
But current sh-hspi runs tx[0], tx[1], rx[0], rx[1].
This patch fixes it up.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
---
drivers/spi/spi-sh-hspi.c | 93 ++++++++++++---------------------------------
1 files changed, 24 insertions(+), 69 deletions(-)
diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
index 5784734..934138c 100644
--- a/drivers/spi/spi-sh-hspi.c
+++ b/drivers/spi/spi-sh-hspi.c
@@ -86,66 +86,6 @@ static int hspi_status_check_timeout(struct hspi_priv *hspi, u32 mask, u32 val)
return -ETIMEDOUT;
}
-static int hspi_push(struct hspi_priv *hspi, struct spi_message *msg,
- struct spi_transfer *t)
-{
- int i, ret;
- u8 *data = (u8 *)t->tx_buf;
-
- /*
- * FIXME
- * very simple, but polling transfer
- */
- for (i = 0; i < t->len; i++) {
- /* wait remains */
- ret = hspi_status_check_timeout(hspi, 0x1, 0x0);
- if (ret < 0)
- return ret;
-
- hspi_write(hspi, SPTBR, (u32)data[i]);
-
- /* wait recive */
- ret = hspi_status_check_timeout(hspi, 0x4, 0x4);
- if (ret < 0)
- return ret;
-
- /* dummy read */
- hspi_read(hspi, SPRBR);
- }
-
- return 0;
-}
-
-static int hspi_pop(struct hspi_priv *hspi, struct spi_message *msg,
- struct spi_transfer *t)
-{
- int i, ret;
- u8 *data = (u8 *)t->rx_buf;
-
- /*
- * FIXME
- * very simple, but polling receive
- */
- for (i = 0; i < t->len; i++) {
- /* wait remains */
- ret = hspi_status_check_timeout(hspi, 0x1, 0);
- if (ret < 0)
- return ret;
-
- /* dummy write */
- hspi_write(hspi, SPTBR, 0x0);
-
- /* wait recive */
- ret = hspi_status_check_timeout(hspi, 0x4, 0x4);
- if (ret < 0)
- return ret;
-
- data[i] = (u8)hspi_read(hspi, SPRBR);
- }
-
- return 0;
-}
-
/*
* spi master function
*/
@@ -223,7 +163,9 @@ static int hspi_transfer_one_message(struct spi_master *master,
{
struct hspi_priv *hspi = spi_master_get_devdata(master);
struct spi_transfer *t;
- int ret;
+ u32 tx;
+ u32 rx;
+ int ret, i;
dev_dbg(hspi->dev, "%s\n", __func__);
@@ -231,19 +173,32 @@ static int hspi_transfer_one_message(struct spi_master *master,
list_for_each_entry(t, &msg->transfers, transfer_list) {
hspi_hw_setup(hspi, msg, t);
- if (t->tx_buf) {
- ret = hspi_push(hspi, msg, t);
+ for (i = 0; i < t->len; i++) {
+
+ /* wait remains */
+ ret = hspi_status_check_timeout(hspi, 0x1, 0);
if (ret < 0)
- goto error;
- }
- if (t->rx_buf) {
- ret = hspi_pop(hspi, msg, t);
+ break;
+
+ tx = 0;
+ if (t->tx_buf)
+ tx = (u32)((u8 *)t->tx_buf)[i];
+
+ hspi_write(hspi, SPTBR, tx);
+
+ /* wait recive */
+ ret = hspi_status_check_timeout(hspi, 0x4, 0x4);
if (ret < 0)
- goto error;
+ break;
+
+ rx = hspi_read(hspi, SPRBR);
+ if (t->rx_buf)
+ ((u8 *)t->rx_buf)[i] = (u8)rx;
+
}
+
msg->actual_length += t->len;
}
-error:
msg->status = ret;
spi_finalize_current_message(master);
--
1.7.5.4
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] spi: sh-hspi: convert to using core message queue and fixup
[not found] ` <87obrz8qgg.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
` (2 preceding siblings ...)
2012-03-14 9:48 ` [PATCH 3/3] spi: sh-hspi: modify write/read method Kuninori Morimoto
@ 2012-03-15 9:42 ` Grant Likely
3 siblings, 0 replies; 5+ messages in thread
From: Grant Likely @ 2012-03-15 9:42 UTC (permalink / raw)
To: Kuninori Morimoto
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
Kuninori Morimoto
On Wed, 14 Mar 2012 02:47:00 -0700 (PDT), Kuninori Morimoto <kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org> wrote:
>
> Hi Grant
>
> These are sh-hspi update patch set
>
> Kuninori Morimoto (3):
> spi: sh-hspi: convert to using core message queue
> spi: sh-hspi: control spi clock more correctly
> spi: sh-hspi: modify write/read method
>
> These are for spi/next branch
Applied all three, thanks.
g.
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
^ permalink raw reply [flat|nested] 5+ messages in thread