Lines Matching refs:c

87 static u32 txx9spi_rd(struct txx9spi *c, int reg)  in txx9spi_rd()  argument
89 return __raw_readl(c->membase + reg); in txx9spi_rd()
91 static void txx9spi_wr(struct txx9spi *c, u32 val, int reg) in txx9spi_wr() argument
93 __raw_writel(val, c->membase + reg); in txx9spi_wr()
96 static void txx9spi_cs_func(struct spi_device *spi, struct txx9spi *c, in txx9spi_cs_func() argument
103 if (c->last_chipselect >= 0) in txx9spi_cs_func()
104 gpio_set_value(c->last_chipselect, in txx9spi_cs_func()
105 !c->last_chipselect_val); in txx9spi_cs_func()
106 c->last_chipselect = spi->chip_select; in txx9spi_cs_func()
107 c->last_chipselect_val = val; in txx9spi_cs_func()
109 c->last_chipselect = -1; in txx9spi_cs_func()
118 struct txx9spi *c = spi_master_get_devdata(spi->master); in txx9spi_setup() local
130 spin_lock(&c->lock); in txx9spi_setup()
131 txx9spi_cs_func(spi, c, 0, (NSEC_PER_SEC / 2) / spi->max_speed_hz); in txx9spi_setup()
132 spin_unlock(&c->lock); in txx9spi_setup()
139 struct txx9spi *c = dev_id; in txx9spi_interrupt() local
142 txx9spi_wr(c, txx9spi_rd(c, TXx9_SPCR0) & ~TXx9_SPCR0_RBSIE, in txx9spi_interrupt()
144 wake_up(&c->waitq); in txx9spi_interrupt()
148 static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) in txx9spi_work_one() argument
162 mcr = txx9spi_rd(c, TXx9_SPMCR); in txx9spi_work_one()
171 txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, TXx9_SPMCR); in txx9spi_work_one()
172 txx9spi_wr(c, TXx9_SPCR0_SBOS in txx9spi_work_one()
191 int n = DIV_ROUND_UP(c->baseclk, speed_hz) - 1; in txx9spi_work_one()
195 txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, in txx9spi_work_one()
197 txx9spi_wr(c, (n << 8) | bits_per_word, TXx9_SPCR1); in txx9spi_work_one()
199 txx9spi_wr(c, mcr | TXx9_SPMCR_ACTIVE, TXx9_SPMCR); in txx9spi_work_one()
206 txx9spi_cs_func(spi, c, 1, cs_delay); in txx9spi_work_one()
216 while (!(txx9spi_rd(c, TXx9_SPSR) & TXx9_SPSR_SIDLE)) in txx9spi_work_one()
218 cr0 = txx9spi_rd(c, TXx9_SPCR0); in txx9spi_work_one()
223 txx9spi_wr(c, cr0, TXx9_SPCR0); in txx9spi_work_one()
230 txx9spi_wr(c, data, TXx9_SPDR); in txx9spi_work_one()
233 txx9spi_wr(c, 0, TXx9_SPDR); in txx9spi_work_one()
236 wait_event(c->waitq, in txx9spi_work_one()
237 txx9spi_rd(c, TXx9_SPSR) & TXx9_SPSR_RBSI); in txx9spi_work_one()
240 data = txx9spi_rd(c, TXx9_SPDR); in txx9spi_work_one()
262 txx9spi_cs_func(spi, c, 0, cs_delay); in txx9spi_work_one()
275 txx9spi_cs_func(spi, c, 0, cs_delay); in txx9spi_work_one()
278 txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, TXx9_SPMCR); in txx9spi_work_one()
283 struct txx9spi *c = container_of(work, struct txx9spi, work); in txx9spi_work() local
286 spin_lock_irqsave(&c->lock, flags); in txx9spi_work()
287 while (!list_empty(&c->queue)) { in txx9spi_work()
290 m = container_of(c->queue.next, struct spi_message, queue); in txx9spi_work()
292 spin_unlock_irqrestore(&c->lock, flags); in txx9spi_work()
294 txx9spi_work_one(c, m); in txx9spi_work()
296 spin_lock_irqsave(&c->lock, flags); in txx9spi_work()
298 spin_unlock_irqrestore(&c->lock, flags); in txx9spi_work()
304 struct txx9spi *c = spi_master_get_devdata(master); in txx9spi_transfer() local
316 spin_lock_irqsave(&c->lock, flags); in txx9spi_transfer()
317 list_add_tail(&m->queue, &c->queue); in txx9spi_transfer()
318 queue_work(c->workqueue, &c->work); in txx9spi_transfer()
319 spin_unlock_irqrestore(&c->lock, flags); in txx9spi_transfer()
327 struct txx9spi *c; in txx9spi_probe() local
333 master = spi_alloc_master(&dev->dev, sizeof(*c)); in txx9spi_probe()
336 c = spi_master_get_devdata(master); in txx9spi_probe()
339 INIT_WORK(&c->work, txx9spi_work); in txx9spi_probe()
340 spin_lock_init(&c->lock); in txx9spi_probe()
341 INIT_LIST_HEAD(&c->queue); in txx9spi_probe()
342 init_waitqueue_head(&c->waitq); in txx9spi_probe()
344 c->clk = devm_clk_get(&dev->dev, "spi-baseclk"); in txx9spi_probe()
345 if (IS_ERR(c->clk)) { in txx9spi_probe()
346 ret = PTR_ERR(c->clk); in txx9spi_probe()
347 c->clk = NULL; in txx9spi_probe()
350 ret = clk_enable(c->clk); in txx9spi_probe()
352 c->clk = NULL; in txx9spi_probe()
355 c->baseclk = clk_get_rate(c->clk); in txx9spi_probe()
356 master->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1); in txx9spi_probe()
357 master->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1); in txx9spi_probe()
360 c->membase = devm_ioremap_resource(&dev->dev, res); in txx9spi_probe()
361 if (IS_ERR(c->membase)) in txx9spi_probe()
365 mcr = txx9spi_rd(c, TXx9_SPMCR); in txx9spi_probe()
367 txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR, TXx9_SPMCR); in txx9spi_probe()
373 "spi_txx9", c); in txx9spi_probe()
377 c->workqueue = create_singlethread_workqueue( in txx9spi_probe()
379 if (!c->workqueue) in txx9spi_probe()
381 c->last_chipselect = -1; in txx9spi_probe()
385 (c->baseclk + 500000) / 1000000); in txx9spi_probe()
403 if (c->workqueue) in txx9spi_probe()
404 destroy_workqueue(c->workqueue); in txx9spi_probe()
405 clk_disable(c->clk); in txx9spi_probe()
413 struct txx9spi *c = spi_master_get_devdata(master); in txx9spi_remove() local
415 destroy_workqueue(c->workqueue); in txx9spi_remove()
416 clk_disable(c->clk); in txx9spi_remove()