Commit 3dc92594 authored by Alexander Shiyan's avatar Alexander Shiyan Committed by Mark Brown

spi: clps711x: Remove <mach/hardware.h> dependency

This patch removes <mach/hardware.h> dependency. This is performed
by replace hard coded used memory regions and interrupt to getting
these values from resources passed to the driver. For the system-wide
registers we now able to use SYSCON driver.
Signed-off-by: default avatarAlexander Shiyan <shc_work@mail.ru>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent bed890b4
...@@ -17,14 +17,21 @@ ...@@ -17,14 +17,21 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/mfd/syscon.h>
#include <linux/mfd/syscon/clps711x.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/platform_data/spi-clps711x.h> #include <linux/platform_data/spi-clps711x.h>
#include <mach/hardware.h>
#define DRIVER_NAME "spi-clps711x" #define DRIVER_NAME "spi-clps711x"
#define SYNCIO_FRMLEN(x) ((x) << 8)
#define SYNCIO_TXFRMEN (1 << 14)
struct spi_clps711x_data { struct spi_clps711x_data {
void __iomem *syncio;
struct regmap *syscon;
struct regmap *syscon1;
struct clk *spi_clk; struct clk *spi_clk;
u32 max_speed_hz; u32 max_speed_hz;
...@@ -49,31 +56,29 @@ static void spi_clps711x_setup_xfer(struct spi_device *spi, ...@@ -49,31 +56,29 @@ static void spi_clps711x_setup_xfer(struct spi_device *spi,
/* Setup SPI frequency divider */ /* Setup SPI frequency divider */
if (!xfer->speed_hz || (xfer->speed_hz >= hw->max_speed_hz)) if (!xfer->speed_hz || (xfer->speed_hz >= hw->max_speed_hz))
clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) | regmap_update_bits(hw->syscon1, SYSCON_OFFSET,
SYSCON1_ADCKSEL(3), SYSCON1); SYSCON1_ADCKSEL_MASK, SYSCON1_ADCKSEL(3));
else if (xfer->speed_hz >= (hw->max_speed_hz / 2)) else if (xfer->speed_hz >= (hw->max_speed_hz / 2))
clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) | regmap_update_bits(hw->syscon1, SYSCON_OFFSET,
SYSCON1_ADCKSEL(2), SYSCON1); SYSCON1_ADCKSEL_MASK, SYSCON1_ADCKSEL(2));
else if (xfer->speed_hz >= (hw->max_speed_hz / 8)) else if (xfer->speed_hz >= (hw->max_speed_hz / 8))
clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) | regmap_update_bits(hw->syscon1, SYSCON_OFFSET,
SYSCON1_ADCKSEL(1), SYSCON1); SYSCON1_ADCKSEL_MASK, SYSCON1_ADCKSEL(1));
else else
clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) | regmap_update_bits(hw->syscon1, SYSCON_OFFSET,
SYSCON1_ADCKSEL(0), SYSCON1); SYSCON1_ADCKSEL_MASK, SYSCON1_ADCKSEL(0));
} }
static int spi_clps711x_prepare_message(struct spi_master *master, static int spi_clps711x_prepare_message(struct spi_master *master,
struct spi_message *msg) struct spi_message *msg)
{ {
struct spi_clps711x_data *hw = spi_master_get_devdata(master);
struct spi_device *spi = msg->spi; struct spi_device *spi = msg->spi;
/* Setup edge for transfer */ /* Setup mode for transfer */
if (spi->mode & SPI_CPHA) return regmap_update_bits(hw->syscon, SYSCON_OFFSET, SYSCON3_ADCCKNSEN,
clps_writew(clps_readw(SYSCON3) | SYSCON3_ADCCKNSEN, SYSCON3); (spi->mode & SPI_CPHA) ?
else SYSCON3_ADCCKNSEN : 0);
clps_writew(clps_readw(SYSCON3) & ~SYSCON3_ADCCKNSEN, SYSCON3);
return 0;
} }
static int spi_clps711x_transfer_one(struct spi_master *master, static int spi_clps711x_transfer_one(struct spi_master *master,
...@@ -92,7 +97,8 @@ static int spi_clps711x_transfer_one(struct spi_master *master, ...@@ -92,7 +97,8 @@ static int spi_clps711x_transfer_one(struct spi_master *master,
/* Initiate transfer */ /* Initiate transfer */
data = hw->tx_buf ? *hw->tx_buf++ : 0; data = hw->tx_buf ? *hw->tx_buf++ : 0;
clps_writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, SYNCIO); writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, hw->syncio);
return 1; return 1;
} }
...@@ -103,15 +109,15 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id) ...@@ -103,15 +109,15 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id)
u8 data; u8 data;
/* Handle RX */ /* Handle RX */
data = clps_readb(SYNCIO); data = readb(hw->syncio);
if (hw->rx_buf) if (hw->rx_buf)
*hw->rx_buf++ = data; *hw->rx_buf++ = data;
/* Handle TX */ /* Handle TX */
if (--hw->len > 0) { if (--hw->len > 0) {
data = hw->tx_buf ? *hw->tx_buf++ : 0; data = hw->tx_buf ? *hw->tx_buf++ : 0;
clps_writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN,
SYNCIO); hw->syncio);
} else } else
spi_finalize_current_transfer(master); spi_finalize_current_transfer(master);
...@@ -120,10 +126,11 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id) ...@@ -120,10 +126,11 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id)
static int spi_clps711x_probe(struct platform_device *pdev) static int spi_clps711x_probe(struct platform_device *pdev)
{ {
int i, ret;
struct spi_master *master;
struct spi_clps711x_data *hw; struct spi_clps711x_data *hw;
struct spi_clps711x_pdata *pdata = dev_get_platdata(&pdev->dev); struct spi_clps711x_pdata *pdata = dev_get_platdata(&pdev->dev);
struct spi_master *master;
struct resource *res;
int i, irq, ret;
if (!pdata) { if (!pdata) {
dev_err(&pdev->dev, "No platform data supplied\n"); dev_err(&pdev->dev, "No platform data supplied\n");
...@@ -135,6 +142,10 @@ static int spi_clps711x_probe(struct platform_device *pdev) ...@@ -135,6 +142,10 @@ static int spi_clps711x_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
master = spi_alloc_master(&pdev->dev, sizeof(*hw)); master = spi_alloc_master(&pdev->dev, sizeof(*hw));
if (!master) if (!master)
return -ENOMEM; return -ENOMEM;
...@@ -176,18 +187,35 @@ static int spi_clps711x_probe(struct platform_device *pdev) ...@@ -176,18 +187,35 @@ static int spi_clps711x_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, master); platform_set_drvdata(pdev, master);
hw->syscon = syscon_regmap_lookup_by_pdevname("syscon.3");
if (IS_ERR(hw->syscon)) {
ret = PTR_ERR(hw->syscon);
goto err_out;
}
hw->syscon1 = syscon_regmap_lookup_by_pdevname("syscon.1");
if (IS_ERR(hw->syscon1)) {
ret = PTR_ERR(hw->syscon1);
goto err_out;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
hw->syncio = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(hw->syncio)) {
ret = PTR_ERR(hw->syncio);
goto err_out;
}
/* Disable extended mode due hardware problems */ /* Disable extended mode due hardware problems */
clps_writew(clps_readw(SYSCON3) & ~SYSCON3_ADCCON, SYSCON3); regmap_update_bits(hw->syscon, SYSCON_OFFSET, SYSCON3_ADCCON, 0);
/* Clear possible pending interrupt */ /* Clear possible pending interrupt */
clps_readl(SYNCIO); readl(hw->syncio);
ret = devm_request_irq(&pdev->dev, IRQ_SSEOTI, spi_clps711x_isr, 0, ret = devm_request_irq(&pdev->dev, irq, spi_clps711x_isr, 0,
dev_name(&pdev->dev), master); dev_name(&pdev->dev), master);
if (ret) { if (ret)
dev_err(&pdev->dev, "Can't request IRQ\n");
goto err_out; goto err_out;
}
ret = devm_spi_register_master(&pdev->dev, master); ret = devm_spi_register_master(&pdev->dev, master);
if (!ret) { if (!ret) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment