Lines Matching refs:sp

49 static inline u32 ath79_spi_rr(struct ath79_spi *sp, unsigned int reg)  in ath79_spi_rr()  argument
51 return ioread32(sp->base + reg); in ath79_spi_rr()
54 static inline void ath79_spi_wr(struct ath79_spi *sp, unsigned int reg, u32 val) in ath79_spi_wr() argument
56 iowrite32(val, sp->base + reg); in ath79_spi_wr()
64 static inline void ath79_spi_delay(struct ath79_spi *sp, unsigned int nsecs) in ath79_spi_delay() argument
66 if (nsecs > sp->rrw_delay) in ath79_spi_delay()
67 ndelay(nsecs - sp->rrw_delay); in ath79_spi_delay()
72 struct ath79_spi *sp = ath79_spidev_to_sp(spi); in ath79_spi_chipselect() local
77 sp->ioc_base |= cs_bit; in ath79_spi_chipselect()
79 sp->ioc_base &= ~cs_bit; in ath79_spi_chipselect()
81 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); in ath79_spi_chipselect()
84 static void ath79_spi_enable(struct ath79_spi *sp) in ath79_spi_enable() argument
87 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO); in ath79_spi_enable()
90 sp->reg_ctrl = ath79_spi_rr(sp, AR71XX_SPI_REG_CTRL); in ath79_spi_enable()
91 sp->ioc_base = ath79_spi_rr(sp, AR71XX_SPI_REG_IOC); in ath79_spi_enable()
94 sp->ioc_base &= ~(AR71XX_SPI_IOC_DO | AR71XX_SPI_IOC_CLK); in ath79_spi_enable()
97 ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43); in ath79_spi_enable()
100 static void ath79_spi_disable(struct ath79_spi *sp) in ath79_spi_disable() argument
103 ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl); in ath79_spi_disable()
105 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0); in ath79_spi_disable()
111 struct ath79_spi *sp = ath79_spidev_to_sp(spi); in ath79_spi_txrx_mode0() local
112 u32 ioc = sp->ioc_base; in ath79_spi_txrx_mode0()
124 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out); in ath79_spi_txrx_mode0()
125 ath79_spi_delay(sp, nsecs); in ath79_spi_txrx_mode0()
126 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out | AR71XX_SPI_IOC_CLK); in ath79_spi_txrx_mode0()
127 ath79_spi_delay(sp, nsecs); in ath79_spi_txrx_mode0()
129 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out); in ath79_spi_txrx_mode0()
134 return ath79_spi_rr(sp, AR71XX_SPI_REG_RDS); in ath79_spi_txrx_mode0()
140 struct ath79_spi *sp = ath79_spidev_to_sp(mem->spi); in ath79_exec_mem_op() local
152 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0); in ath79_exec_mem_op()
154 memcpy_fromio(op->data.buf.in, sp->base + op->addr.val, op->data.nbytes); in ath79_exec_mem_op()
157 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO); in ath79_exec_mem_op()
160 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); in ath79_exec_mem_op()
172 struct ath79_spi *sp; in ath79_spi_probe() local
176 host = spi_alloc_host(&pdev->dev, sizeof(*sp)); in ath79_spi_probe()
182 sp = spi_controller_get_devdata(host); in ath79_spi_probe()
184 platform_set_drvdata(pdev, sp); in ath79_spi_probe()
192 sp->bitbang.master = host; in ath79_spi_probe()
193 sp->bitbang.chipselect = ath79_spi_chipselect; in ath79_spi_probe()
194 sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0; in ath79_spi_probe()
195 sp->bitbang.flags = SPI_CS_HIGH; in ath79_spi_probe()
197 sp->base = devm_platform_ioremap_resource(pdev, 0); in ath79_spi_probe()
198 if (IS_ERR(sp->base)) { in ath79_spi_probe()
199 ret = PTR_ERR(sp->base); in ath79_spi_probe()
203 sp->clk = devm_clk_get(&pdev->dev, "ahb"); in ath79_spi_probe()
204 if (IS_ERR(sp->clk)) { in ath79_spi_probe()
205 ret = PTR_ERR(sp->clk); in ath79_spi_probe()
209 ret = clk_prepare_enable(sp->clk); in ath79_spi_probe()
213 rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ); in ath79_spi_probe()
219 sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate; in ath79_spi_probe()
221 sp->rrw_delay); in ath79_spi_probe()
223 ath79_spi_enable(sp); in ath79_spi_probe()
224 ret = spi_bitbang_start(&sp->bitbang); in ath79_spi_probe()
231 ath79_spi_disable(sp); in ath79_spi_probe()
233 clk_disable_unprepare(sp->clk); in ath79_spi_probe()
242 struct ath79_spi *sp = platform_get_drvdata(pdev); in ath79_spi_remove() local
244 spi_bitbang_stop(&sp->bitbang); in ath79_spi_remove()
245 ath79_spi_disable(sp); in ath79_spi_remove()
246 clk_disable_unprepare(sp->clk); in ath79_spi_remove()
247 spi_controller_put(sp->bitbang.master); in ath79_spi_remove()