• Home
  • Raw
  • Download

Lines Matching refs:priv

82 static inline void pic32_spi_enable(struct pic32_spi_priv *priv)  in pic32_spi_enable()  argument
84 writel(PIC32_SPI_CTRL_ON, &priv->regs->ctrl.set); in pic32_spi_enable()
87 static inline void pic32_spi_disable(struct pic32_spi_priv *priv) in pic32_spi_disable() argument
89 writel(PIC32_SPI_CTRL_ON, &priv->regs->ctrl.clr); in pic32_spi_disable()
92 static inline u32 pic32_spi_rx_fifo_level(struct pic32_spi_priv *priv) in pic32_spi_rx_fifo_level() argument
94 u32 sr = readl(&priv->regs->status.raw); in pic32_spi_rx_fifo_level()
99 static inline u32 pic32_spi_tx_fifo_level(struct pic32_spi_priv *priv) in pic32_spi_tx_fifo_level() argument
101 u32 sr = readl(&priv->regs->status.raw); in pic32_spi_tx_fifo_level()
107 static u32 pic32_tx_max(struct pic32_spi_priv *priv, int n_bytes) in pic32_tx_max() argument
111 tx_left = (priv->tx_end - priv->tx) / n_bytes; in pic32_tx_max()
112 tx_room = priv->fifo_n_word - pic32_spi_tx_fifo_level(priv); in pic32_tx_max()
114 rxtx_gap = (priv->rx_end - priv->rx) - (priv->tx_end - priv->tx); in pic32_tx_max()
116 return min3(tx_left, tx_room, (u32)(priv->fifo_n_word - rxtx_gap)); in pic32_tx_max()
120 static u32 pic32_rx_max(struct pic32_spi_priv *priv, int n_bytes) in pic32_rx_max() argument
122 u32 rx_left = (priv->rx_end - priv->rx) / n_bytes; in pic32_rx_max()
124 return min_t(u32, rx_left, pic32_spi_rx_fifo_level(priv)); in pic32_rx_max()
128 static void pic32_spi_rx_##__name(struct pic32_spi_priv *priv) \
131 u32 mx = pic32_rx_max(priv, sizeof(__type)); \
134 val = read##__bwl(&priv->regs->buf.raw); \
135 if (priv->rx_end - priv->len) \
136 *(__type *)(priv->rx) = val; \
137 priv->rx += sizeof(__type); \
141 static void pic32_spi_tx_##__name(struct pic32_spi_priv *priv) \
144 u32 mx = pic32_tx_max(priv, sizeof(__type)); \
148 if (priv->tx_end - priv->len) \
149 val = *(__type *)(priv->tx); \
150 write##__bwl(val, &priv->regs->buf.raw); \
151 priv->tx += sizeof(__type); \
158 static int pic32_spi_set_word_size(struct pic32_spi_priv *priv, in pic32_spi_set_word_size() argument
166 priv->rx_fifo = pic32_spi_rx_byte; in pic32_spi_set_word_size()
167 priv->tx_fifo = pic32_spi_tx_byte; in pic32_spi_set_word_size()
171 priv->rx_fifo = pic32_spi_rx_word; in pic32_spi_set_word_size()
172 priv->tx_fifo = pic32_spi_tx_word; in pic32_spi_set_word_size()
176 priv->rx_fifo = pic32_spi_rx_dword; in pic32_spi_set_word_size()
177 priv->tx_fifo = pic32_spi_tx_dword; in pic32_spi_set_word_size()
186 val = readl(&priv->regs->ctrl.raw); in pic32_spi_set_word_size()
189 writel(val, &priv->regs->ctrl.raw); in pic32_spi_set_word_size()
192 priv->fifo_n_word = DIV_ROUND_UP(priv->fifo_depth, wordlen / 8); in pic32_spi_set_word_size()
199 struct pic32_spi_priv *priv = dev_get_priv(slave->parent); in pic32_spi_claim_bus() local
202 pic32_spi_enable(priv); in pic32_spi_claim_bus()
209 struct pic32_spi_priv *priv = dev_get_priv(slave->parent); in pic32_spi_release_bus() local
212 pic32_spi_disable(priv); in pic32_spi_release_bus()
217 static void spi_cs_activate(struct pic32_spi_priv *priv) in spi_cs_activate() argument
219 if (!dm_gpio_is_valid(&priv->cs_gpio)) in spi_cs_activate()
222 dm_gpio_set_value(&priv->cs_gpio, 1); in spi_cs_activate()
225 static void spi_cs_deactivate(struct pic32_spi_priv *priv) in spi_cs_deactivate() argument
227 if (!dm_gpio_is_valid(&priv->cs_gpio)) in spi_cs_deactivate()
230 dm_gpio_set_value(&priv->cs_gpio, 0); in spi_cs_deactivate()
239 struct pic32_spi_priv *priv; in pic32_spi_xfer() local
244 priv = dev_get_priv(bus); in pic32_spi_xfer()
254 spi_cs_activate(priv); in pic32_spi_xfer()
257 priv->tx = tx_buf; in pic32_spi_xfer()
258 priv->rx = rx_buf; in pic32_spi_xfer()
259 priv->tx_end = priv->tx + len; in pic32_spi_xfer()
260 priv->rx_end = priv->rx + len; in pic32_spi_xfer()
261 priv->len = len; in pic32_spi_xfer()
266 priv->tx_fifo(priv); in pic32_spi_xfer()
267 priv->rx_fifo(priv); in pic32_spi_xfer()
270 if (priv->rx >= priv->rx_end) { in pic32_spi_xfer()
285 spi_cs_deactivate(priv); in pic32_spi_xfer()
292 struct pic32_spi_priv *priv = dev_get_priv(bus); in pic32_spi_set_speed() local
298 div = (priv->clk_rate / 2 / speed) - 1; in pic32_spi_set_speed()
300 writel(div, &priv->regs->baud.raw); in pic32_spi_set_speed()
302 priv->speed_hz = speed; in pic32_spi_set_speed()
309 struct pic32_spi_priv *priv = dev_get_priv(bus); in pic32_spi_set_mode() local
315 val = readl(&priv->regs->ctrl.raw); in pic32_spi_set_mode()
330 writel(val, &priv->regs->ctrl.raw); in pic32_spi_set_mode()
332 priv->mode = mode; in pic32_spi_set_mode()
339 struct pic32_spi_priv *priv = dev_get_priv(slave->parent); in pic32_spi_set_wordlen() local
341 return pic32_spi_set_word_size(priv, wordlen); in pic32_spi_set_wordlen()
344 static void pic32_spi_hw_init(struct pic32_spi_priv *priv) in pic32_spi_hw_init() argument
349 pic32_spi_disable(priv); in pic32_spi_hw_init()
351 val = readl(&priv->regs->ctrl); in pic32_spi_hw_init()
355 priv->fifo_depth = 16; in pic32_spi_hw_init()
369 writel(val, &priv->regs->ctrl); in pic32_spi_hw_init()
372 writel(PIC32_SPI_STAT_RX_OV, &priv->regs->status.clr); in pic32_spi_hw_init()
377 struct pic32_spi_priv *priv = dev_get_priv(bus); in pic32_spi_probe() local
390 priv->regs = ioremap(addr, size); in pic32_spi_probe()
391 if (!priv->regs) in pic32_spi_probe()
402 priv->clk_rate = clk_get_periph_rate(clkdev, ret); in pic32_spi_probe()
405 pic32_spi_hw_init(priv); in pic32_spi_probe()
408 pic32_spi_set_word_size(priv, SPI_DEFAULT_WORDLEN); in pic32_spi_probe()
417 &priv->cs_gpio, GPIOD_IS_OUT); in pic32_spi_probe()