Lines Matching +full:clock +full:- +full:master

1 // SPDX-License-Identifier: GPL-2.0-only
3 * J-Core SPI controller driver
5 * Copyright (C) 2012-2016 Smart Energy Instruments, Inc.
36 struct spi_master *master; member
52 } while (--timeout); in jcore_spi_wait()
54 return -EBUSY; in jcore_spi_wait()
59 void __iomem *ctrl_reg = hw->base + CTRL_REG; in jcore_spi_program()
62 dev_err(hw->master->dev.parent, in jcore_spi_program()
65 writel(hw->cs_reg | hw->speed_reg, ctrl_reg); in jcore_spi_program()
70 struct jcore_spi *hw = spi_master_get_devdata(spi->master); in jcore_spi_chipsel()
71 u32 csbit = 1U << (2 * spi->chip_select); in jcore_spi_chipsel()
73 dev_dbg(hw->master->dev.parent, "chipselect %d\n", spi->chip_select); in jcore_spi_chipsel()
76 hw->cs_reg |= csbit; in jcore_spi_chipsel()
78 hw->cs_reg &= ~csbit; in jcore_spi_chipsel()
85 if (speed == hw->speed_hz) return; in jcore_spi_baudrate()
86 hw->speed_hz = speed; in jcore_spi_baudrate()
87 if (speed >= hw->clock_freq / 2) in jcore_spi_baudrate()
88 hw->speed_reg = 0; in jcore_spi_baudrate()
90 hw->speed_reg = ((hw->clock_freq / 2 / speed) - 1) << 27; in jcore_spi_baudrate()
92 dev_dbg(hw->master->dev.parent, "speed=%d reg=0x%x\n", in jcore_spi_baudrate()
93 speed, hw->speed_reg); in jcore_spi_baudrate()
96 static int jcore_spi_txrx(struct spi_master *master, struct spi_device *spi, in jcore_spi_txrx() argument
99 struct jcore_spi *hw = spi_master_get_devdata(master); in jcore_spi_txrx()
101 void __iomem *ctrl_reg = hw->base + CTRL_REG; in jcore_spi_txrx()
102 void __iomem *data_reg = hw->base + DATA_REG; in jcore_spi_txrx()
111 jcore_spi_baudrate(hw, t->speed_hz); in jcore_spi_txrx()
113 xmit = hw->cs_reg | hw->speed_reg | JCORE_SPI_CTRL_XMIT; in jcore_spi_txrx()
114 tx = t->tx_buf; in jcore_spi_txrx()
115 rx = t->rx_buf; in jcore_spi_txrx()
116 len = t->len; in jcore_spi_txrx()
132 spi_finalize_current_transfer(master); in jcore_spi_txrx()
135 return -EREMOTEIO; in jcore_spi_txrx()
142 struct device_node *node = pdev->dev.of_node; in jcore_spi_probe()
144 struct spi_master *master; in jcore_spi_probe() local
148 int err = -ENODEV; in jcore_spi_probe()
150 master = spi_alloc_master(&pdev->dev, sizeof(struct jcore_spi)); in jcore_spi_probe()
151 if (!master) in jcore_spi_probe()
154 /* Setup the master state. */ in jcore_spi_probe()
155 master->num_chipselect = 3; in jcore_spi_probe()
156 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; in jcore_spi_probe()
157 master->transfer_one = jcore_spi_txrx; in jcore_spi_probe()
158 master->set_cs = jcore_spi_chipsel; in jcore_spi_probe()
159 master->dev.of_node = node; in jcore_spi_probe()
160 master->bus_num = pdev->id; in jcore_spi_probe()
162 hw = spi_master_get_devdata(master); in jcore_spi_probe()
163 hw->master = master; in jcore_spi_probe()
170 if (!devm_request_mem_region(&pdev->dev, res->start, in jcore_spi_probe()
171 resource_size(res), pdev->name)) in jcore_spi_probe()
173 hw->base = devm_ioremap(&pdev->dev, res->start, in jcore_spi_probe()
175 if (!hw->base) in jcore_spi_probe()
179 * The SPI clock rate controlled via a configurable clock divider in jcore_spi_probe()
180 * which is applied to the reference clock. A 50 MHz reference is in jcore_spi_probe()
181 * most suitable for obtaining standard SPI clock rates, but some in jcore_spi_probe()
182 * designs may have a different reference clock, and the DT must in jcore_spi_probe()
184 * requested rate. If the clock is omitted, 50 MHz is assumed. in jcore_spi_probe()
187 clk = devm_clk_get(&pdev->dev, "ref_clk"); in jcore_spi_probe()
193 dev_warn(&pdev->dev, "could not enable ref_clk\n"); in jcore_spi_probe()
195 hw->clock_freq = clock_freq; in jcore_spi_probe()
198 hw->cs_reg = JCORE_SPI_CTRL_CS_BITS; in jcore_spi_probe()
202 err = devm_spi_register_master(&pdev->dev, master); in jcore_spi_probe()
209 err = -EBUSY; in jcore_spi_probe()
211 spi_master_put(master); in jcore_spi_probe()
231 MODULE_DESCRIPTION("J-Core SPI driver");