Lines Matching refs:master
224 static bool svc_i3c_master_error(struct svc_i3c_master *master) in svc_i3c_master_error() argument
228 mstatus = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_error()
230 merrwarn = readl(master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_error()
231 writel(merrwarn, master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_error()
235 dev_dbg(master->dev, "Warning condition: MSTATUS 0x%08x, MERRWARN 0x%08x\n", in svc_i3c_master_error()
240 dev_err(master->dev, in svc_i3c_master_error()
250 static void svc_i3c_master_enable_interrupts(struct svc_i3c_master *master, u32 mask) in svc_i3c_master_enable_interrupts() argument
252 writel(mask, master->regs + SVC_I3C_MINTSET); in svc_i3c_master_enable_interrupts()
255 static void svc_i3c_master_disable_interrupts(struct svc_i3c_master *master) in svc_i3c_master_disable_interrupts() argument
257 u32 mask = readl(master->regs + SVC_I3C_MINTSET); in svc_i3c_master_disable_interrupts()
259 writel(mask, master->regs + SVC_I3C_MINTCLR); in svc_i3c_master_disable_interrupts()
262 static void svc_i3c_master_clear_merrwarn(struct svc_i3c_master *master) in svc_i3c_master_clear_merrwarn() argument
265 writel(readl(master->regs + SVC_I3C_MERRWARN), in svc_i3c_master_clear_merrwarn()
266 master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_clear_merrwarn()
269 static void svc_i3c_master_flush_fifo(struct svc_i3c_master *master) in svc_i3c_master_flush_fifo() argument
273 master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_flush_fifo()
276 static void svc_i3c_master_reset_fifo_trigger(struct svc_i3c_master *master) in svc_i3c_master_reset_fifo_trigger() argument
286 writel(reg, master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_reset_fifo_trigger()
289 static void svc_i3c_master_reset(struct svc_i3c_master *master) in svc_i3c_master_reset() argument
291 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_reset()
292 svc_i3c_master_reset_fifo_trigger(master); in svc_i3c_master_reset()
293 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_reset()
297 to_svc_i3c_master(struct i3c_master_controller *master) in to_svc_i3c_master() argument
299 return container_of(master, struct svc_i3c_master, base); in to_svc_i3c_master()
304 struct svc_i3c_master *master; in svc_i3c_master_hj_work() local
306 master = container_of(work, struct svc_i3c_master, hj_work); in svc_i3c_master_hj_work()
307 i3c_master_do_daa(&master->base); in svc_i3c_master_hj_work()
311 svc_i3c_master_dev_from_addr(struct svc_i3c_master *master, in svc_i3c_master_dev_from_addr() argument
317 if (master->addrs[i] == ibiaddr) in svc_i3c_master_dev_from_addr()
323 return master->descs[i]; in svc_i3c_master_dev_from_addr()
326 static void svc_i3c_master_emit_stop(struct svc_i3c_master *master) in svc_i3c_master_emit_stop() argument
328 writel(SVC_I3C_MCTRL_REQUEST_STOP, master->regs + SVC_I3C_MCTRL); in svc_i3c_master_emit_stop()
339 static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master, in svc_i3c_master_handle_ibi() argument
356 ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val, in svc_i3c_master_handle_ibi()
359 dev_err(master->dev, "Timeout when polling for COMPLETE\n"); in svc_i3c_master_handle_ibi()
363 while (SVC_I3C_MSTATUS_RXPEND(readl(master->regs + SVC_I3C_MSTATUS)) && in svc_i3c_master_handle_ibi()
365 mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_handle_ibi()
367 readsl(master->regs + SVC_I3C_MRDATAB, buf, count); in svc_i3c_master_handle_ibi()
372 master->ibi.tbq_slot = slot; in svc_i3c_master_handle_ibi()
377 static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, in svc_i3c_master_ack_ibi() argument
388 writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL); in svc_i3c_master_ack_ibi()
391 static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master) in svc_i3c_master_nack_ibi() argument
395 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_nack_ibi()
400 struct svc_i3c_master *master = container_of(work, struct svc_i3c_master, ibi_work); in svc_i3c_master_ibi_work() local
407 mutex_lock(&master->lock); in svc_i3c_master_ibi_work()
419 writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_ibi_work()
424 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_ibi_work()
427 ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val, in svc_i3c_master_ibi_work()
430 dev_err(master->dev, "Timeout when polling for IBIWON\n"); in svc_i3c_master_ibi_work()
431 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
435 status = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_ibi_work()
442 dev = svc_i3c_master_dev_from_addr(master, ibiaddr); in svc_i3c_master_ibi_work()
444 svc_i3c_master_nack_ibi(master); in svc_i3c_master_ibi_work()
446 svc_i3c_master_handle_ibi(master, dev); in svc_i3c_master_ibi_work()
449 svc_i3c_master_ack_ibi(master, false); in svc_i3c_master_ibi_work()
452 svc_i3c_master_nack_ibi(master); in svc_i3c_master_ibi_work()
463 if (svc_i3c_master_error(master)) { in svc_i3c_master_ibi_work()
464 if (master->ibi.tbq_slot) { in svc_i3c_master_ibi_work()
467 master->ibi.tbq_slot); in svc_i3c_master_ibi_work()
468 master->ibi.tbq_slot = NULL; in svc_i3c_master_ibi_work()
471 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
480 i3c_master_queue_ibi(dev, master->ibi.tbq_slot); in svc_i3c_master_ibi_work()
481 master->ibi.tbq_slot = NULL; in svc_i3c_master_ibi_work()
483 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
486 queue_work(master->base.wq, &master->hj_work); in svc_i3c_master_ibi_work()
494 svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); in svc_i3c_master_ibi_work()
495 mutex_unlock(&master->lock); in svc_i3c_master_ibi_work()
500 struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id; in svc_i3c_master_irq_handler() local
501 u32 active = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_irq_handler()
507 writel(SVC_I3C_MINT_SLVSTART, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_irq_handler()
509 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_irq_handler()
512 queue_work(master->base.wq, &master->ibi_work); in svc_i3c_master_irq_handler()
519 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_bus_init() local
527 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_bus_init()
529 dev_err(master->dev, in svc_i3c_master_bus_init()
536 fclk_rate = clk_get_rate(master->fclk); in svc_i3c_master_bus_init()
597 writel(reg, master->regs + SVC_I3C_MCONFIG); in svc_i3c_master_bus_init()
607 master->regs + SVC_I3C_MDYNADDR); in svc_i3c_master_bus_init()
609 ret = i3c_master_set_info(&master->base, &info); in svc_i3c_master_bus_init()
614 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_bus_init()
615 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_bus_init()
622 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_bus_cleanup() local
625 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_bus_cleanup()
627 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_bus_cleanup()
631 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_bus_cleanup()
634 writel(0, master->regs + SVC_I3C_MCONFIG); in svc_i3c_master_bus_cleanup()
636 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_bus_cleanup()
637 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_bus_cleanup()
640 static int svc_i3c_master_reserve_slot(struct svc_i3c_master *master) in svc_i3c_master_reserve_slot() argument
644 if (!(master->free_slots & GENMASK(SVC_I3C_MAX_DEVS - 1, 0))) in svc_i3c_master_reserve_slot()
647 slot = ffs(master->free_slots) - 1; in svc_i3c_master_reserve_slot()
649 master->free_slots &= ~BIT(slot); in svc_i3c_master_reserve_slot()
654 static void svc_i3c_master_release_slot(struct svc_i3c_master *master, in svc_i3c_master_release_slot() argument
657 master->free_slots |= BIT(slot); in svc_i3c_master_release_slot()
663 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_attach_i3c_dev() local
667 slot = svc_i3c_master_reserve_slot(master); in svc_i3c_master_attach_i3c_dev()
673 svc_i3c_master_release_slot(master, slot); in svc_i3c_master_attach_i3c_dev()
679 master->addrs[slot] = dev->info.dyn_addr ? dev->info.dyn_addr : in svc_i3c_master_attach_i3c_dev()
681 master->descs[slot] = dev; in svc_i3c_master_attach_i3c_dev()
692 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_reattach_i3c_dev() local
695 master->addrs[data->index] = dev->info.dyn_addr ? dev->info.dyn_addr : in svc_i3c_master_reattach_i3c_dev()
705 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_detach_i3c_dev() local
707 master->addrs[data->index] = 0; in svc_i3c_master_detach_i3c_dev()
708 svc_i3c_master_release_slot(master, data->index); in svc_i3c_master_detach_i3c_dev()
716 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_attach_i2c_dev() local
720 slot = svc_i3c_master_reserve_slot(master); in svc_i3c_master_attach_i2c_dev()
726 svc_i3c_master_release_slot(master, slot); in svc_i3c_master_attach_i2c_dev()
731 master->addrs[slot] = dev->addr; in svc_i3c_master_attach_i2c_dev()
742 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_detach_i2c_dev() local
744 svc_i3c_master_release_slot(master, data->index); in svc_i3c_master_detach_i2c_dev()
749 static int svc_i3c_master_readb(struct svc_i3c_master *master, u8 *dst, in svc_i3c_master_readb() argument
756 ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, in svc_i3c_master_readb()
763 dst[i] = readl(master->regs + SVC_I3C_MRDATAB); in svc_i3c_master_readb()
769 static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, in svc_i3c_master_do_daa_locked() argument
783 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_do_daa_locked()
789 ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, in svc_i3c_master_do_daa_locked()
805 ret = svc_i3c_master_readb(master, data, 6); in svc_i3c_master_do_daa_locked()
813 ret = svc_i3c_master_readb(master, data, 2); in svc_i3c_master_do_daa_locked()
842 svc_i3c_master_emit_stop(master); in svc_i3c_master_do_daa_locked()
851 ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, in svc_i3c_master_do_daa_locked()
861 ret = i3c_master_get_free_addr(&master->base, last_addr + 1); in svc_i3c_master_do_daa_locked()
866 dev_dbg(master->dev, "DAA: device %d assigned to 0x%02x\n", in svc_i3c_master_do_daa_locked()
869 writel(addrs[dev_nb], master->regs + SVC_I3C_MWDATAB); in svc_i3c_master_do_daa_locked()
878 static int svc_i3c_update_ibirules(struct svc_i3c_master *master) in svc_i3c_update_ibirules() argument
887 i3c_bus_for_each_i3cdev(&master->base.bus, dev) { in svc_i3c_update_ibirules()
925 writel(reg_mbyte, master->regs + SVC_I3C_IBIRULES); in svc_i3c_update_ibirules()
927 writel(reg_nobyte, master->regs + SVC_I3C_IBIRULES); in svc_i3c_update_ibirules()
934 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_do_daa() local
940 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_do_daa()
942 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_do_daa()
946 spin_lock_irqsave(&master->xferqueue.lock, flags); in svc_i3c_master_do_daa()
947 ret = svc_i3c_master_do_daa_locked(master, addrs, &dev_nb); in svc_i3c_master_do_daa()
948 spin_unlock_irqrestore(&master->xferqueue.lock, flags); in svc_i3c_master_do_daa()
950 svc_i3c_master_emit_stop(master); in svc_i3c_master_do_daa()
951 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_do_daa()
963 ret = svc_i3c_update_ibirules(master); in svc_i3c_master_do_daa()
965 dev_err(master->dev, "Cannot handle such a list of devices"); in svc_i3c_master_do_daa()
968 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_do_daa()
969 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_do_daa()
974 static int svc_i3c_master_read(struct svc_i3c_master *master, in svc_i3c_master_read() argument
984 mstatus = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_read()
989 dev_dbg(master->dev, "I3C read timeout\n"); in svc_i3c_master_read()
993 mdctrl = readl(master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_read()
996 dev_err(master->dev, "I3C receive length too long!\n"); in svc_i3c_master_read()
1000 in[offset + i] = readl(master->regs + SVC_I3C_MRDATAB); in svc_i3c_master_read()
1008 static int svc_i3c_master_write(struct svc_i3c_master *master, in svc_i3c_master_write() argument
1015 ret = readl_poll_timeout(master->regs + SVC_I3C_MDATACTRL, in svc_i3c_master_write()
1027 writel(out[offset++], master->regs + SVC_I3C_MWDATAB); in svc_i3c_master_write()
1029 writel(out[offset++], master->regs + SVC_I3C_MWDATABE); in svc_i3c_master_write()
1035 static int svc_i3c_master_xfer(struct svc_i3c_master *master, in svc_i3c_master_xfer() argument
1045 writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_xfer()
1055 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_xfer()
1057 ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, in svc_i3c_master_xfer()
1062 if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) { in svc_i3c_master_xfer()
1084 writel(SVC_I3C_MERRWARN_NACK, master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_xfer()
1114 ret = svc_i3c_master_read(master, in, xfer_len); in svc_i3c_master_xfer()
1116 ret = svc_i3c_master_write(master, out, xfer_len); in svc_i3c_master_xfer()
1123 ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, in svc_i3c_master_xfer()
1128 writel(SVC_I3C_MINT_COMPLETE, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_xfer()
1131 svc_i3c_master_emit_stop(master); in svc_i3c_master_xfer()
1134 readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, in svc_i3c_master_xfer()
1141 svc_i3c_master_emit_stop(master); in svc_i3c_master_xfer()
1142 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_xfer()
1148 svc_i3c_master_alloc_xfer(struct svc_i3c_master *master, unsigned int ncmds) in svc_i3c_master_alloc_xfer() argument
1168 static void svc_i3c_master_dequeue_xfer_locked(struct svc_i3c_master *master, in svc_i3c_master_dequeue_xfer_locked() argument
1171 if (master->xferqueue.cur == xfer) in svc_i3c_master_dequeue_xfer_locked()
1172 master->xferqueue.cur = NULL; in svc_i3c_master_dequeue_xfer_locked()
1177 static void svc_i3c_master_dequeue_xfer(struct svc_i3c_master *master, in svc_i3c_master_dequeue_xfer() argument
1182 spin_lock_irqsave(&master->xferqueue.lock, flags); in svc_i3c_master_dequeue_xfer()
1183 svc_i3c_master_dequeue_xfer_locked(master, xfer); in svc_i3c_master_dequeue_xfer()
1184 spin_unlock_irqrestore(&master->xferqueue.lock, flags); in svc_i3c_master_dequeue_xfer()
1187 static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master) in svc_i3c_master_start_xfer_locked() argument
1189 struct svc_i3c_xfer *xfer = master->xferqueue.cur; in svc_i3c_master_start_xfer_locked()
1195 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_start_xfer_locked()
1196 svc_i3c_master_flush_fifo(master); in svc_i3c_master_start_xfer_locked()
1201 ret = svc_i3c_master_xfer(master, cmd->rnw, xfer->type, in svc_i3c_master_start_xfer_locked()
1217 svc_i3c_master_dequeue_xfer_locked(master, xfer); in svc_i3c_master_start_xfer_locked()
1219 xfer = list_first_entry_or_null(&master->xferqueue.list, in svc_i3c_master_start_xfer_locked()
1225 master->xferqueue.cur = xfer; in svc_i3c_master_start_xfer_locked()
1226 svc_i3c_master_start_xfer_locked(master); in svc_i3c_master_start_xfer_locked()
1229 static void svc_i3c_master_enqueue_xfer(struct svc_i3c_master *master, in svc_i3c_master_enqueue_xfer() argument
1235 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_enqueue_xfer()
1237 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_enqueue_xfer()
1242 spin_lock_irqsave(&master->xferqueue.lock, flags); in svc_i3c_master_enqueue_xfer()
1243 if (master->xferqueue.cur) { in svc_i3c_master_enqueue_xfer()
1244 list_add_tail(&xfer->node, &master->xferqueue.list); in svc_i3c_master_enqueue_xfer()
1246 master->xferqueue.cur = xfer; in svc_i3c_master_enqueue_xfer()
1247 svc_i3c_master_start_xfer_locked(master); in svc_i3c_master_enqueue_xfer()
1249 spin_unlock_irqrestore(&master->xferqueue.lock, flags); in svc_i3c_master_enqueue_xfer()
1251 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_enqueue_xfer()
1252 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_enqueue_xfer()
1256 svc_i3c_master_supports_ccc_cmd(struct i3c_master_controller *master, in svc_i3c_master_supports_ccc_cmd() argument
1263 static int svc_i3c_master_send_bdcast_ccc_cmd(struct svc_i3c_master *master, in svc_i3c_master_send_bdcast_ccc_cmd() argument
1272 xfer = svc_i3c_master_alloc_xfer(master, 1); in svc_i3c_master_send_bdcast_ccc_cmd()
1296 mutex_lock(&master->lock); in svc_i3c_master_send_bdcast_ccc_cmd()
1297 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_send_bdcast_ccc_cmd()
1299 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_send_bdcast_ccc_cmd()
1300 mutex_unlock(&master->lock); in svc_i3c_master_send_bdcast_ccc_cmd()
1309 static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, in svc_i3c_master_send_direct_ccc_cmd() argument
1318 xfer = svc_i3c_master_alloc_xfer(master, 2); in svc_i3c_master_send_direct_ccc_cmd()
1344 mutex_lock(&master->lock); in svc_i3c_master_send_direct_ccc_cmd()
1345 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_send_direct_ccc_cmd()
1347 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_send_direct_ccc_cmd()
1348 mutex_unlock(&master->lock); in svc_i3c_master_send_direct_ccc_cmd()
1362 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_send_ccc_cmd() local
1367 ret = svc_i3c_master_send_bdcast_ccc_cmd(master, cmd); in svc_i3c_master_send_ccc_cmd()
1369 ret = svc_i3c_master_send_direct_ccc_cmd(master, cmd); in svc_i3c_master_send_ccc_cmd()
1382 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_priv_xfers() local
1387 xfer = svc_i3c_master_alloc_xfer(master, nxfers); in svc_i3c_master_priv_xfers()
1397 cmd->addr = master->addrs[data->index]; in svc_i3c_master_priv_xfers()
1406 mutex_lock(&master->lock); in svc_i3c_master_priv_xfers()
1407 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_priv_xfers()
1409 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_priv_xfers()
1410 mutex_unlock(&master->lock); in svc_i3c_master_priv_xfers()
1423 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_i2c_xfers() local
1428 xfer = svc_i3c_master_alloc_xfer(master, nxfers); in svc_i3c_master_i2c_xfers()
1437 cmd->addr = master->addrs[data->index]; in svc_i3c_master_i2c_xfers()
1446 mutex_lock(&master->lock); in svc_i3c_master_i2c_xfers()
1447 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_i2c_xfers()
1449 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_i2c_xfers()
1450 mutex_unlock(&master->lock); in svc_i3c_master_i2c_xfers()
1462 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_request_ibi() local
1468 dev_err(master->dev, "IBI max payload %d should be < %d\n", in svc_i3c_master_request_ibi()
1477 spin_lock_irqsave(&master->ibi.lock, flags); in svc_i3c_master_request_ibi()
1478 for (i = 0; i < master->ibi.num_slots; i++) { in svc_i3c_master_request_ibi()
1479 if (!master->ibi.slots[i]) { in svc_i3c_master_request_ibi()
1481 master->ibi.slots[i] = dev; in svc_i3c_master_request_ibi()
1485 spin_unlock_irqrestore(&master->ibi.lock, flags); in svc_i3c_master_request_ibi()
1487 if (i < master->ibi.num_slots) in svc_i3c_master_request_ibi()
1499 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_free_ibi() local
1503 spin_lock_irqsave(&master->ibi.lock, flags); in svc_i3c_master_free_ibi()
1504 master->ibi.slots[data->ibi] = NULL; in svc_i3c_master_free_ibi()
1506 spin_unlock_irqrestore(&master->ibi.lock, flags); in svc_i3c_master_free_ibi()
1514 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_enable_ibi() local
1517 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_enable_ibi()
1519 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_enable_ibi()
1523 svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); in svc_i3c_master_enable_ibi()
1531 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_disable_ibi() local
1534 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_disable_ibi()
1538 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_disable_ibi()
1539 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_disable_ibi()
1572 static int svc_i3c_master_prepare_clks(struct svc_i3c_master *master) in svc_i3c_master_prepare_clks() argument
1576 ret = clk_prepare_enable(master->pclk); in svc_i3c_master_prepare_clks()
1580 ret = clk_prepare_enable(master->fclk); in svc_i3c_master_prepare_clks()
1582 clk_disable_unprepare(master->pclk); in svc_i3c_master_prepare_clks()
1586 ret = clk_prepare_enable(master->sclk); in svc_i3c_master_prepare_clks()
1588 clk_disable_unprepare(master->pclk); in svc_i3c_master_prepare_clks()
1589 clk_disable_unprepare(master->fclk); in svc_i3c_master_prepare_clks()
1596 static void svc_i3c_master_unprepare_clks(struct svc_i3c_master *master) in svc_i3c_master_unprepare_clks() argument
1598 clk_disable_unprepare(master->pclk); in svc_i3c_master_unprepare_clks()
1599 clk_disable_unprepare(master->fclk); in svc_i3c_master_unprepare_clks()
1600 clk_disable_unprepare(master->sclk); in svc_i3c_master_unprepare_clks()
1606 struct svc_i3c_master *master; in svc_i3c_master_probe() local
1609 master = devm_kzalloc(dev, sizeof(*master), GFP_KERNEL); in svc_i3c_master_probe()
1610 if (!master) in svc_i3c_master_probe()
1613 master->regs = devm_platform_ioremap_resource(pdev, 0); in svc_i3c_master_probe()
1614 if (IS_ERR(master->regs)) in svc_i3c_master_probe()
1615 return PTR_ERR(master->regs); in svc_i3c_master_probe()
1617 master->pclk = devm_clk_get(dev, "pclk"); in svc_i3c_master_probe()
1618 if (IS_ERR(master->pclk)) in svc_i3c_master_probe()
1619 return PTR_ERR(master->pclk); in svc_i3c_master_probe()
1621 master->fclk = devm_clk_get(dev, "fast_clk"); in svc_i3c_master_probe()
1622 if (IS_ERR(master->fclk)) in svc_i3c_master_probe()
1623 return PTR_ERR(master->fclk); in svc_i3c_master_probe()
1625 master->sclk = devm_clk_get(dev, "slow_clk"); in svc_i3c_master_probe()
1626 if (IS_ERR(master->sclk)) in svc_i3c_master_probe()
1627 return PTR_ERR(master->sclk); in svc_i3c_master_probe()
1629 master->irq = platform_get_irq(pdev, 0); in svc_i3c_master_probe()
1630 if (master->irq < 0) in svc_i3c_master_probe()
1631 return master->irq; in svc_i3c_master_probe()
1633 master->dev = dev; in svc_i3c_master_probe()
1635 ret = svc_i3c_master_prepare_clks(master); in svc_i3c_master_probe()
1639 INIT_WORK(&master->hj_work, svc_i3c_master_hj_work); in svc_i3c_master_probe()
1640 INIT_WORK(&master->ibi_work, svc_i3c_master_ibi_work); in svc_i3c_master_probe()
1641 mutex_init(&master->lock); in svc_i3c_master_probe()
1643 ret = devm_request_irq(dev, master->irq, svc_i3c_master_irq_handler, in svc_i3c_master_probe()
1644 IRQF_NO_SUSPEND, "svc-i3c-irq", master); in svc_i3c_master_probe()
1648 master->free_slots = GENMASK(SVC_I3C_MAX_DEVS - 1, 0); in svc_i3c_master_probe()
1650 spin_lock_init(&master->xferqueue.lock); in svc_i3c_master_probe()
1651 INIT_LIST_HEAD(&master->xferqueue.list); in svc_i3c_master_probe()
1653 spin_lock_init(&master->ibi.lock); in svc_i3c_master_probe()
1654 master->ibi.num_slots = SVC_I3C_MAX_DEVS; in svc_i3c_master_probe()
1655 master->ibi.slots = devm_kcalloc(&pdev->dev, master->ibi.num_slots, in svc_i3c_master_probe()
1656 sizeof(*master->ibi.slots), in svc_i3c_master_probe()
1658 if (!master->ibi.slots) { in svc_i3c_master_probe()
1663 platform_set_drvdata(pdev, master); in svc_i3c_master_probe()
1671 svc_i3c_master_reset(master); in svc_i3c_master_probe()
1674 ret = i3c_master_register(&master->base, &pdev->dev, in svc_i3c_master_probe()
1691 svc_i3c_master_unprepare_clks(master); in svc_i3c_master_probe()
1698 struct svc_i3c_master *master = platform_get_drvdata(pdev); in svc_i3c_master_remove() local
1700 cancel_work_sync(&master->hj_work); in svc_i3c_master_remove()
1701 i3c_master_unregister(&master->base); in svc_i3c_master_remove()
1707 static void svc_i3c_save_regs(struct svc_i3c_master *master) in svc_i3c_save_regs() argument
1709 master->saved_regs.mconfig = readl(master->regs + SVC_I3C_MCONFIG); in svc_i3c_save_regs()
1710 master->saved_regs.mdynaddr = readl(master->regs + SVC_I3C_MDYNADDR); in svc_i3c_save_regs()
1713 static void svc_i3c_restore_regs(struct svc_i3c_master *master) in svc_i3c_restore_regs() argument
1715 if (readl(master->regs + SVC_I3C_MDYNADDR) != in svc_i3c_restore_regs()
1716 master->saved_regs.mdynaddr) { in svc_i3c_restore_regs()
1717 writel(master->saved_regs.mconfig, in svc_i3c_restore_regs()
1718 master->regs + SVC_I3C_MCONFIG); in svc_i3c_restore_regs()
1719 writel(master->saved_regs.mdynaddr, in svc_i3c_restore_regs()
1720 master->regs + SVC_I3C_MDYNADDR); in svc_i3c_restore_regs()
1726 struct svc_i3c_master *master = dev_get_drvdata(dev); in svc_i3c_runtime_suspend() local
1728 svc_i3c_save_regs(master); in svc_i3c_runtime_suspend()
1729 svc_i3c_master_unprepare_clks(master); in svc_i3c_runtime_suspend()
1737 struct svc_i3c_master *master = dev_get_drvdata(dev); in svc_i3c_runtime_resume() local
1740 svc_i3c_master_prepare_clks(master); in svc_i3c_runtime_resume()
1742 svc_i3c_restore_regs(master); in svc_i3c_runtime_resume()