void __iomem *regs;
int irq;
struct clk *clk;
+ struct clk *gclk;
struct platform_device *pdev;
unsigned long spi_clk;
static void atmel_spi_init(struct atmel_spi *as)
{
+ u32 mr = 0;
+
spi_writel(as, CR, SPI_BIT(SWRST));
spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
if (as->fifo_size)
spi_writel(as, CR, SPI_BIT(FIFOEN));
- if (as->caps.has_wdrbt) {
- spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
- | SPI_BIT(MSTR));
- } else {
- spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
- }
+ /*
+ * If GCLK is selected as the source clock for the bit rate generation
+ * Enable the BRSRCCLK/FDIV/DIV32 bit
+ */
+ if (as->gclk)
+ mr |= SPI_BIT(FDIV);
+
+ if (as->caps.has_wdrbt)
+ mr |= SPI_BIT(WDRBT);
+
+ spi_writel(as, MR, mr | SPI_BIT(MODFDIS) | SPI_BIT(MSTR));
if (as->use_pdc)
spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
as->phybase = regs->start;
as->irq = irq;
as->clk = clk;
+ as->gclk = devm_clk_get_optional(&pdev->dev, "spi_gclk");
+ if (IS_ERR(as->gclk)) {
+ ret = PTR_ERR(as->gclk);
+ goto out_unmap_regs;
+ }
init_completion(&as->xfer_completion);
if (ret)
goto out_free_irq;
- as->spi_clk = clk_get_rate(clk);
+ /*
+ * In cases where the peripheral clock is higher,the FLEX_SPI_CSRx.SCBR
+ * exceeds the threshold (SCBR ≤ 255), the GCLK is used as the source clock
+ * for the SPCK (SPI Serial Clock) bit rate generation
+ */
+ if (as->gclk) {
+ ret = clk_prepare_enable(as->gclk);
+ if (ret)
+ goto out_disable_clk;
+ as->spi_clk = clk_get_rate(as->gclk);
+ } else {
+ as->spi_clk = clk_get_rate(clk);
+ }
as->fifo_size = 0;
if (!of_property_read_u32(pdev->dev.of_node, "atmel,fifo-size",
spi_writel(as, CR, SPI_BIT(SWRST));
spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
+ clk_disable_unprepare(as->gclk);
+out_disable_clk:
clk_disable_unprepare(clk);
out_free_irq:
out_unmap_regs:
spin_unlock_irq(&as->lock);
clk_disable_unprepare(as->clk);
+ if (as->gclk)
+ clk_disable_unprepare(as->gclk);
pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
struct atmel_spi *as = spi_controller_get_devdata(host);
clk_disable_unprepare(as->clk);
+ if (as->gclk)
+ clk_disable_unprepare(as->gclk);
pinctrl_pm_select_sleep_state(dev);
return 0;
{
struct spi_controller *host = dev_get_drvdata(dev);
struct atmel_spi *as = spi_controller_get_devdata(host);
+ int ret;
pinctrl_pm_select_default_state(dev);
- return clk_prepare_enable(as->clk);
+ ret = clk_prepare_enable(as->clk);
+ if (ret)
+ return ret;
+ if (as->gclk) {
+ ret = clk_prepare_enable(as->gclk);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
}
static int atmel_spi_suspend(struct device *dev)
ret = clk_prepare_enable(as->clk);
if (ret)
return ret;
+ if (as->gclk) {
+ ret = clk_prepare_enable(as->gclk);
+ if (ret)
+ return ret;
+ }
atmel_spi_init(as);
clk_disable_unprepare(as->clk);
+ if (as->gclk)
+ clk_disable_unprepare(as->gclk);
if (!pm_runtime_suspended(dev)) {
ret = atmel_spi_runtime_resume(dev);