Lines Matching full:master

3  * Silvaco dual-role I3C master driver
14 #include <linux/i3c/master.h>
24 /* Master Mode Registers */
162 * struct svc_i3c_master - Silvaco I3C Master structure
163 * @base: I3C master controller
185 * @lock: Transfer lock, protect between IBI work thread and callbacks from master
223 * @index: Index in the master tables corresponding to this device
224 * @ibi: IBI slot index in the master structure
233 static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask) in is_events_enabled() argument
235 return !!(master->enabled_events & mask); in is_events_enabled()
238 static bool svc_i3c_master_error(struct svc_i3c_master *master) in svc_i3c_master_error() argument
242 mstatus = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_error()
244 merrwarn = readl(master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_error()
245 writel(merrwarn, master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_error()
249 dev_dbg(master->dev, "Warning condition: MSTATUS 0x%08x, MERRWARN 0x%08x\n", in svc_i3c_master_error()
254 dev_err(master->dev, in svc_i3c_master_error()
264 static void svc_i3c_master_enable_interrupts(struct svc_i3c_master *master, u32 mask) in svc_i3c_master_enable_interrupts() argument
266 writel(mask, master->regs + SVC_I3C_MINTSET); in svc_i3c_master_enable_interrupts()
269 static void svc_i3c_master_disable_interrupts(struct svc_i3c_master *master) in svc_i3c_master_disable_interrupts() argument
271 u32 mask = readl(master->regs + SVC_I3C_MINTSET); in svc_i3c_master_disable_interrupts()
273 writel(mask, master->regs + SVC_I3C_MINTCLR); in svc_i3c_master_disable_interrupts()
276 static void svc_i3c_master_clear_merrwarn(struct svc_i3c_master *master) in svc_i3c_master_clear_merrwarn() argument
279 writel(readl(master->regs + SVC_I3C_MERRWARN), in svc_i3c_master_clear_merrwarn()
280 master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_clear_merrwarn()
283 static void svc_i3c_master_flush_fifo(struct svc_i3c_master *master) in svc_i3c_master_flush_fifo() argument
287 master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_flush_fifo()
290 static void svc_i3c_master_reset_fifo_trigger(struct svc_i3c_master *master) in svc_i3c_master_reset_fifo_trigger() argument
300 writel(reg, master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_reset_fifo_trigger()
303 static void svc_i3c_master_reset(struct svc_i3c_master *master) in svc_i3c_master_reset() argument
305 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_reset()
306 svc_i3c_master_reset_fifo_trigger(master); in svc_i3c_master_reset()
307 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_reset()
311 to_svc_i3c_master(struct i3c_master_controller *master) in to_svc_i3c_master() argument
313 return container_of(master, struct svc_i3c_master, base); in to_svc_i3c_master()
318 struct svc_i3c_master *master; in svc_i3c_master_hj_work() local
320 master = container_of(work, struct svc_i3c_master, hj_work); in svc_i3c_master_hj_work()
321 i3c_master_do_daa(&master->base); in svc_i3c_master_hj_work()
325 svc_i3c_master_dev_from_addr(struct svc_i3c_master *master, in svc_i3c_master_dev_from_addr() argument
331 if (master->addrs[i] == ibiaddr) in svc_i3c_master_dev_from_addr()
337 return master->descs[i]; in svc_i3c_master_dev_from_addr()
340 static void svc_i3c_master_emit_stop(struct svc_i3c_master *master) in svc_i3c_master_emit_stop() argument
342 writel(SVC_I3C_MCTRL_REQUEST_STOP, master->regs + SVC_I3C_MCTRL); in svc_i3c_master_emit_stop()
353 static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master, in svc_i3c_master_handle_ibi() argument
370 ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val, in svc_i3c_master_handle_ibi()
373 dev_err(master->dev, "Timeout when polling for COMPLETE\n"); in svc_i3c_master_handle_ibi()
377 while (SVC_I3C_MSTATUS_RXPEND(readl(master->regs + SVC_I3C_MSTATUS)) && in svc_i3c_master_handle_ibi()
379 mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_handle_ibi()
381 readsl(master->regs + SVC_I3C_MRDATAB, buf, count); in svc_i3c_master_handle_ibi()
386 master->ibi.tbq_slot = slot; in svc_i3c_master_handle_ibi()
391 static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, in svc_i3c_master_ack_ibi() argument
402 writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL); in svc_i3c_master_ack_ibi()
405 static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master) in svc_i3c_master_nack_ibi() argument
409 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_nack_ibi()
414 struct svc_i3c_master *master = container_of(work, struct svc_i3c_master, ibi_work); in svc_i3c_master_ibi_work() local
421 mutex_lock(&master->lock); in svc_i3c_master_ibi_work()
433 writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_ibi_work()
438 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_ibi_work()
441 ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val, in svc_i3c_master_ibi_work()
444 dev_err(master->dev, "Timeout when polling for IBIWON\n"); in svc_i3c_master_ibi_work()
445 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
449 status = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_ibi_work()
456 dev = svc_i3c_master_dev_from_addr(master, ibiaddr); in svc_i3c_master_ibi_work()
457 if (!dev || !is_events_enabled(master, SVC_I3C_EVENT_IBI)) in svc_i3c_master_ibi_work()
458 svc_i3c_master_nack_ibi(master); in svc_i3c_master_ibi_work()
460 svc_i3c_master_handle_ibi(master, dev); in svc_i3c_master_ibi_work()
463 if (is_events_enabled(master, SVC_I3C_EVENT_HOTJOIN)) in svc_i3c_master_ibi_work()
464 svc_i3c_master_ack_ibi(master, false); in svc_i3c_master_ibi_work()
466 svc_i3c_master_nack_ibi(master); in svc_i3c_master_ibi_work()
469 svc_i3c_master_nack_ibi(master); in svc_i3c_master_ibi_work()
480 if (svc_i3c_master_error(master)) { in svc_i3c_master_ibi_work()
481 if (master->ibi.tbq_slot) { in svc_i3c_master_ibi_work()
484 master->ibi.tbq_slot); in svc_i3c_master_ibi_work()
485 master->ibi.tbq_slot = NULL; in svc_i3c_master_ibi_work()
488 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
497 i3c_master_queue_ibi(dev, master->ibi.tbq_slot); in svc_i3c_master_ibi_work()
498 master->ibi.tbq_slot = NULL; in svc_i3c_master_ibi_work()
500 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
503 svc_i3c_master_emit_stop(master); in svc_i3c_master_ibi_work()
504 if (is_events_enabled(master, SVC_I3C_EVENT_HOTJOIN)) in svc_i3c_master_ibi_work()
505 queue_work(master->base.wq, &master->hj_work); in svc_i3c_master_ibi_work()
513 svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); in svc_i3c_master_ibi_work()
514 mutex_unlock(&master->lock); in svc_i3c_master_ibi_work()
519 struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id; in svc_i3c_master_irq_handler() local
520 u32 active = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_irq_handler()
526 writel(SVC_I3C_MINT_SLVSTART, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_irq_handler()
528 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_irq_handler()
531 queue_work(master->base.wq, &master->ibi_work); in svc_i3c_master_irq_handler()
539 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_set_speed() local
540 struct i3c_bus *bus = i3c_master_get_bus(&master->base); in svc_i3c_master_set_speed()
545 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_set_speed()
547 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_set_speed()
553 fclk_rate = clk_get_rate(master->fclk); in svc_i3c_master_set_speed()
564 mconfig = master->mctrl_config; in svc_i3c_master_set_speed()
570 writel(mconfig, master->regs + SVC_I3C_MCONFIG); in svc_i3c_master_set_speed()
573 writel(master->mctrl_config, master->regs + SVC_I3C_MCONFIG); in svc_i3c_master_set_speed()
578 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_set_speed()
579 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_set_speed()
586 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_bus_init() local
595 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_bus_init()
597 dev_err(master->dev, in svc_i3c_master_bus_init()
598 "<%s> cannot resume i3c bus master, err: %d\n", in svc_i3c_master_bus_init()
604 fclk_rate = clk_get_rate(master->fclk); in svc_i3c_master_bus_init()
675 writel(reg, master->regs + SVC_I3C_MCONFIG); in svc_i3c_master_bus_init()
677 master->mctrl_config = reg; in svc_i3c_master_bus_init()
678 /* Master core's registration */ in svc_i3c_master_bus_init()
686 master->regs + SVC_I3C_MDYNADDR); in svc_i3c_master_bus_init()
688 ret = i3c_master_set_info(&master->base, &info); in svc_i3c_master_bus_init()
693 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_bus_init()
694 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_bus_init()
701 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_bus_cleanup() local
704 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_bus_cleanup()
706 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_bus_cleanup()
710 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_bus_cleanup()
712 /* Disable master */ in svc_i3c_master_bus_cleanup()
713 writel(0, master->regs + SVC_I3C_MCONFIG); in svc_i3c_master_bus_cleanup()
715 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_bus_cleanup()
716 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_bus_cleanup()
719 static int svc_i3c_master_reserve_slot(struct svc_i3c_master *master) in svc_i3c_master_reserve_slot() argument
723 if (!(master->free_slots & GENMASK(SVC_I3C_MAX_DEVS - 1, 0))) in svc_i3c_master_reserve_slot()
726 slot = ffs(master->free_slots) - 1; in svc_i3c_master_reserve_slot()
728 master->free_slots &= ~BIT(slot); in svc_i3c_master_reserve_slot()
733 static void svc_i3c_master_release_slot(struct svc_i3c_master *master, in svc_i3c_master_release_slot() argument
736 master->free_slots |= BIT(slot); in svc_i3c_master_release_slot()
742 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_attach_i3c_dev() local
746 slot = svc_i3c_master_reserve_slot(master); in svc_i3c_master_attach_i3c_dev()
752 svc_i3c_master_release_slot(master, slot); in svc_i3c_master_attach_i3c_dev()
758 master->addrs[slot] = dev->info.dyn_addr ? dev->info.dyn_addr : in svc_i3c_master_attach_i3c_dev()
760 master->descs[slot] = dev; in svc_i3c_master_attach_i3c_dev()
771 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_reattach_i3c_dev() local
774 master->addrs[data->index] = dev->info.dyn_addr ? dev->info.dyn_addr : in svc_i3c_master_reattach_i3c_dev()
784 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_detach_i3c_dev() local
786 master->addrs[data->index] = 0; in svc_i3c_master_detach_i3c_dev()
787 svc_i3c_master_release_slot(master, data->index); in svc_i3c_master_detach_i3c_dev()
795 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_attach_i2c_dev() local
799 slot = svc_i3c_master_reserve_slot(master); in svc_i3c_master_attach_i2c_dev()
805 svc_i3c_master_release_slot(master, slot); in svc_i3c_master_attach_i2c_dev()
810 master->addrs[slot] = dev->addr; in svc_i3c_master_attach_i2c_dev()
821 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_detach_i2c_dev() local
823 svc_i3c_master_release_slot(master, data->index); in svc_i3c_master_detach_i2c_dev()
828 static int svc_i3c_master_readb(struct svc_i3c_master *master, u8 *dst, in svc_i3c_master_readb() argument
835 ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, in svc_i3c_master_readb()
842 dst[i] = readl(master->regs + SVC_I3C_MRDATAB); in svc_i3c_master_readb()
848 static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, in svc_i3c_master_do_daa_locked() argument
875 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_do_daa_locked()
881 ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, in svc_i3c_master_do_daa_locked()
897 ret = svc_i3c_master_readb(master, data, 6); in svc_i3c_master_do_daa_locked()
905 ret = svc_i3c_master_readb(master, data, 2); in svc_i3c_master_do_daa_locked()
947 svc_i3c_master_emit_stop(master); in svc_i3c_master_do_daa_locked()
956 ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, in svc_i3c_master_do_daa_locked()
966 ret = i3c_master_get_free_addr(&master->base, last_addr + 1); in svc_i3c_master_do_daa_locked()
971 dev_dbg(master->dev, "DAA: device %d assigned to 0x%02x\n", in svc_i3c_master_do_daa_locked()
974 writel(addrs[dev_nb], master->regs + SVC_I3C_MWDATAB); in svc_i3c_master_do_daa_locked()
979 svc_i3c_master_emit_stop(master); in svc_i3c_master_do_daa_locked()
983 static int svc_i3c_update_ibirules(struct svc_i3c_master *master) in svc_i3c_update_ibirules() argument
992 i3c_bus_for_each_i3cdev(&master->base.bus, dev) { in svc_i3c_update_ibirules()
1030 writel(reg_mbyte, master->regs + SVC_I3C_IBIRULES); in svc_i3c_update_ibirules()
1032 writel(reg_nobyte, master->regs + SVC_I3C_IBIRULES); in svc_i3c_update_ibirules()
1039 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_do_daa() local
1045 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_do_daa()
1047 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_do_daa()
1051 spin_lock_irqsave(&master->xferqueue.lock, flags); in svc_i3c_master_do_daa()
1052 ret = svc_i3c_master_do_daa_locked(master, addrs, &dev_nb); in svc_i3c_master_do_daa()
1053 spin_unlock_irqrestore(&master->xferqueue.lock, flags); in svc_i3c_master_do_daa()
1055 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_do_daa()
1067 ret = svc_i3c_update_ibirules(master); in svc_i3c_master_do_daa()
1069 dev_err(master->dev, "Cannot handle such a list of devices"); in svc_i3c_master_do_daa()
1072 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_do_daa()
1073 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_do_daa()
1078 static int svc_i3c_master_read(struct svc_i3c_master *master, in svc_i3c_master_read() argument
1088 mstatus = readl(master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_read()
1093 dev_dbg(master->dev, "I3C read timeout\n"); in svc_i3c_master_read()
1097 mdctrl = readl(master->regs + SVC_I3C_MDATACTRL); in svc_i3c_master_read()
1100 dev_err(master->dev, "I3C receive length too long!\n"); in svc_i3c_master_read()
1104 in[offset + i] = readl(master->regs + SVC_I3C_MRDATAB); in svc_i3c_master_read()
1112 static int svc_i3c_master_write(struct svc_i3c_master *master, in svc_i3c_master_write() argument
1119 ret = readl_poll_timeout(master->regs + SVC_I3C_MDATACTRL, in svc_i3c_master_write()
1131 writel(out[offset++], master->regs + SVC_I3C_MWDATAB); in svc_i3c_master_write()
1133 writel(out[offset++], master->regs + SVC_I3C_MWDATABE); in svc_i3c_master_write()
1139 static int svc_i3c_master_xfer(struct svc_i3c_master *master, in svc_i3c_master_xfer() argument
1149 writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_xfer()
1159 master->regs + SVC_I3C_MCTRL); in svc_i3c_master_xfer()
1161 ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, in svc_i3c_master_xfer()
1166 if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) { in svc_i3c_master_xfer()
1188 writel(SVC_I3C_MERRWARN_NACK, master->regs + SVC_I3C_MERRWARN); in svc_i3c_master_xfer()
1218 ret = svc_i3c_master_read(master, in, xfer_len); in svc_i3c_master_xfer()
1220 ret = svc_i3c_master_write(master, out, xfer_len); in svc_i3c_master_xfer()
1227 ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, in svc_i3c_master_xfer()
1232 writel(SVC_I3C_MINT_COMPLETE, master->regs + SVC_I3C_MSTATUS); in svc_i3c_master_xfer()
1235 svc_i3c_master_emit_stop(master); in svc_i3c_master_xfer()
1238 readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, in svc_i3c_master_xfer()
1245 svc_i3c_master_emit_stop(master); in svc_i3c_master_xfer()
1246 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_xfer()
1252 svc_i3c_master_alloc_xfer(struct svc_i3c_master *master, unsigned int ncmds) in svc_i3c_master_alloc_xfer() argument
1272 static void svc_i3c_master_dequeue_xfer_locked(struct svc_i3c_master *master, in svc_i3c_master_dequeue_xfer_locked() argument
1275 if (master->xferqueue.cur == xfer) in svc_i3c_master_dequeue_xfer_locked()
1276 master->xferqueue.cur = NULL; in svc_i3c_master_dequeue_xfer_locked()
1281 static void svc_i3c_master_dequeue_xfer(struct svc_i3c_master *master, in svc_i3c_master_dequeue_xfer() argument
1286 spin_lock_irqsave(&master->xferqueue.lock, flags); in svc_i3c_master_dequeue_xfer()
1287 svc_i3c_master_dequeue_xfer_locked(master, xfer); in svc_i3c_master_dequeue_xfer()
1288 spin_unlock_irqrestore(&master->xferqueue.lock, flags); in svc_i3c_master_dequeue_xfer()
1291 static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master) in svc_i3c_master_start_xfer_locked() argument
1293 struct svc_i3c_xfer *xfer = master->xferqueue.cur; in svc_i3c_master_start_xfer_locked()
1299 svc_i3c_master_clear_merrwarn(master); in svc_i3c_master_start_xfer_locked()
1300 svc_i3c_master_flush_fifo(master); in svc_i3c_master_start_xfer_locked()
1305 ret = svc_i3c_master_xfer(master, cmd->rnw, xfer->type, in svc_i3c_master_start_xfer_locked()
1321 svc_i3c_master_dequeue_xfer_locked(master, xfer); in svc_i3c_master_start_xfer_locked()
1323 xfer = list_first_entry_or_null(&master->xferqueue.list, in svc_i3c_master_start_xfer_locked()
1329 master->xferqueue.cur = xfer; in svc_i3c_master_start_xfer_locked()
1330 svc_i3c_master_start_xfer_locked(master); in svc_i3c_master_start_xfer_locked()
1333 static void svc_i3c_master_enqueue_xfer(struct svc_i3c_master *master, in svc_i3c_master_enqueue_xfer() argument
1339 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_enqueue_xfer()
1341 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_enqueue_xfer()
1346 spin_lock_irqsave(&master->xferqueue.lock, flags); in svc_i3c_master_enqueue_xfer()
1347 if (master->xferqueue.cur) { in svc_i3c_master_enqueue_xfer()
1348 list_add_tail(&xfer->node, &master->xferqueue.list); in svc_i3c_master_enqueue_xfer()
1350 master->xferqueue.cur = xfer; in svc_i3c_master_enqueue_xfer()
1351 svc_i3c_master_start_xfer_locked(master); in svc_i3c_master_enqueue_xfer()
1353 spin_unlock_irqrestore(&master->xferqueue.lock, flags); in svc_i3c_master_enqueue_xfer()
1355 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_enqueue_xfer()
1356 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_enqueue_xfer()
1360 svc_i3c_master_supports_ccc_cmd(struct i3c_master_controller *master, in svc_i3c_master_supports_ccc_cmd() argument
1367 static int svc_i3c_master_send_bdcast_ccc_cmd(struct svc_i3c_master *master, in svc_i3c_master_send_bdcast_ccc_cmd() argument
1376 xfer = svc_i3c_master_alloc_xfer(master, 1); in svc_i3c_master_send_bdcast_ccc_cmd()
1400 mutex_lock(&master->lock); in svc_i3c_master_send_bdcast_ccc_cmd()
1401 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_send_bdcast_ccc_cmd()
1403 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_send_bdcast_ccc_cmd()
1404 mutex_unlock(&master->lock); in svc_i3c_master_send_bdcast_ccc_cmd()
1413 static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, in svc_i3c_master_send_direct_ccc_cmd() argument
1422 xfer = svc_i3c_master_alloc_xfer(master, 2); in svc_i3c_master_send_direct_ccc_cmd()
1448 mutex_lock(&master->lock); in svc_i3c_master_send_direct_ccc_cmd()
1449 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_send_direct_ccc_cmd()
1451 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_send_direct_ccc_cmd()
1452 mutex_unlock(&master->lock); in svc_i3c_master_send_direct_ccc_cmd()
1466 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_send_ccc_cmd() local
1471 ret = svc_i3c_master_send_bdcast_ccc_cmd(master, cmd); in svc_i3c_master_send_ccc_cmd()
1473 ret = svc_i3c_master_send_direct_ccc_cmd(master, cmd); in svc_i3c_master_send_ccc_cmd()
1486 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_priv_xfers() local
1491 xfer = svc_i3c_master_alloc_xfer(master, nxfers); in svc_i3c_master_priv_xfers()
1501 cmd->addr = master->addrs[data->index]; in svc_i3c_master_priv_xfers()
1510 mutex_lock(&master->lock); in svc_i3c_master_priv_xfers()
1511 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_priv_xfers()
1513 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_priv_xfers()
1514 mutex_unlock(&master->lock); in svc_i3c_master_priv_xfers()
1527 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_i2c_xfers() local
1532 xfer = svc_i3c_master_alloc_xfer(master, nxfers); in svc_i3c_master_i2c_xfers()
1541 cmd->addr = master->addrs[data->index]; in svc_i3c_master_i2c_xfers()
1550 mutex_lock(&master->lock); in svc_i3c_master_i2c_xfers()
1551 svc_i3c_master_enqueue_xfer(master, xfer); in svc_i3c_master_i2c_xfers()
1553 svc_i3c_master_dequeue_xfer(master, xfer); in svc_i3c_master_i2c_xfers()
1554 mutex_unlock(&master->lock); in svc_i3c_master_i2c_xfers()
1566 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_request_ibi() local
1572 dev_err(master->dev, "IBI max payload %d should be < %d\n", in svc_i3c_master_request_ibi()
1581 spin_lock_irqsave(&master->ibi.lock, flags); in svc_i3c_master_request_ibi()
1582 for (i = 0; i < master->ibi.num_slots; i++) { in svc_i3c_master_request_ibi()
1583 if (!master->ibi.slots[i]) { in svc_i3c_master_request_ibi()
1585 master->ibi.slots[i] = dev; in svc_i3c_master_request_ibi()
1589 spin_unlock_irqrestore(&master->ibi.lock, flags); in svc_i3c_master_request_ibi()
1591 if (i < master->ibi.num_slots) in svc_i3c_master_request_ibi()
1603 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_free_ibi() local
1607 spin_lock_irqsave(&master->ibi.lock, flags); in svc_i3c_master_free_ibi()
1608 master->ibi.slots[data->ibi] = NULL; in svc_i3c_master_free_ibi()
1610 spin_unlock_irqrestore(&master->ibi.lock, flags); in svc_i3c_master_free_ibi()
1618 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_enable_ibi() local
1621 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_enable_ibi()
1623 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_enable_ibi()
1627 master->enabled_events |= SVC_I3C_EVENT_IBI; in svc_i3c_master_enable_ibi()
1628 svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); in svc_i3c_master_enable_ibi()
1636 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_disable_ibi() local
1639 master->enabled_events &= ~SVC_I3C_EVENT_IBI; in svc_i3c_master_disable_ibi()
1640 if (!master->enabled_events) in svc_i3c_master_disable_ibi()
1641 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_disable_ibi()
1645 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_disable_ibi()
1646 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_disable_ibi()
1653 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_enable_hotjoin() local
1656 ret = pm_runtime_resume_and_get(master->dev); in svc_i3c_master_enable_hotjoin()
1658 dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); in svc_i3c_master_enable_hotjoin()
1662 master->enabled_events |= SVC_I3C_EVENT_HOTJOIN; in svc_i3c_master_enable_hotjoin()
1664 svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); in svc_i3c_master_enable_hotjoin()
1671 struct svc_i3c_master *master = to_svc_i3c_master(m); in svc_i3c_master_disable_hotjoin() local
1673 master->enabled_events &= ~SVC_I3C_EVENT_HOTJOIN; in svc_i3c_master_disable_hotjoin()
1675 if (!master->enabled_events) in svc_i3c_master_disable_hotjoin()
1676 svc_i3c_master_disable_interrupts(master); in svc_i3c_master_disable_hotjoin()
1678 pm_runtime_mark_last_busy(master->dev); in svc_i3c_master_disable_hotjoin()
1679 pm_runtime_put_autosuspend(master->dev); in svc_i3c_master_disable_hotjoin()
1715 static int svc_i3c_master_prepare_clks(struct svc_i3c_master *master) in svc_i3c_master_prepare_clks() argument
1719 ret = clk_prepare_enable(master->pclk); in svc_i3c_master_prepare_clks()
1723 ret = clk_prepare_enable(master->fclk); in svc_i3c_master_prepare_clks()
1725 clk_disable_unprepare(master->pclk); in svc_i3c_master_prepare_clks()
1729 ret = clk_prepare_enable(master->sclk); in svc_i3c_master_prepare_clks()
1731 clk_disable_unprepare(master->pclk); in svc_i3c_master_prepare_clks()
1732 clk_disable_unprepare(master->fclk); in svc_i3c_master_prepare_clks()
1739 static void svc_i3c_master_unprepare_clks(struct svc_i3c_master *master) in svc_i3c_master_unprepare_clks() argument
1741 clk_disable_unprepare(master->pclk); in svc_i3c_master_unprepare_clks()
1742 clk_disable_unprepare(master->fclk); in svc_i3c_master_unprepare_clks()
1743 clk_disable_unprepare(master->sclk); in svc_i3c_master_unprepare_clks()
1749 struct svc_i3c_master *master; in svc_i3c_master_probe() local
1752 master = devm_kzalloc(dev, sizeof(*master), GFP_KERNEL); in svc_i3c_master_probe()
1753 if (!master) in svc_i3c_master_probe()
1756 master->regs = devm_platform_ioremap_resource(pdev, 0); in svc_i3c_master_probe()
1757 if (IS_ERR(master->regs)) in svc_i3c_master_probe()
1758 return PTR_ERR(master->regs); in svc_i3c_master_probe()
1760 master->pclk = devm_clk_get(dev, "pclk"); in svc_i3c_master_probe()
1761 if (IS_ERR(master->pclk)) in svc_i3c_master_probe()
1762 return PTR_ERR(master->pclk); in svc_i3c_master_probe()
1764 master->fclk = devm_clk_get(dev, "fast_clk"); in svc_i3c_master_probe()
1765 if (IS_ERR(master->fclk)) in svc_i3c_master_probe()
1766 return PTR_ERR(master->fclk); in svc_i3c_master_probe()
1768 master->sclk = devm_clk_get(dev, "slow_clk"); in svc_i3c_master_probe()
1769 if (IS_ERR(master->sclk)) in svc_i3c_master_probe()
1770 return PTR_ERR(master->sclk); in svc_i3c_master_probe()
1772 master->irq = platform_get_irq(pdev, 0); in svc_i3c_master_probe()
1773 if (master->irq < 0) in svc_i3c_master_probe()
1774 return master->irq; in svc_i3c_master_probe()
1776 master->dev = dev; in svc_i3c_master_probe()
1778 ret = svc_i3c_master_prepare_clks(master); in svc_i3c_master_probe()
1782 INIT_WORK(&master->hj_work, svc_i3c_master_hj_work); in svc_i3c_master_probe()
1783 INIT_WORK(&master->ibi_work, svc_i3c_master_ibi_work); in svc_i3c_master_probe()
1784 mutex_init(&master->lock); in svc_i3c_master_probe()
1786 ret = devm_request_irq(dev, master->irq, svc_i3c_master_irq_handler, in svc_i3c_master_probe()
1787 IRQF_NO_SUSPEND, "svc-i3c-irq", master); in svc_i3c_master_probe()
1791 master->free_slots = GENMASK(SVC_I3C_MAX_DEVS - 1, 0); in svc_i3c_master_probe()
1793 spin_lock_init(&master->xferqueue.lock); in svc_i3c_master_probe()
1794 INIT_LIST_HEAD(&master->xferqueue.list); in svc_i3c_master_probe()
1796 spin_lock_init(&master->ibi.lock); in svc_i3c_master_probe()
1797 master->ibi.num_slots = SVC_I3C_MAX_DEVS; in svc_i3c_master_probe()
1798 master->ibi.slots = devm_kcalloc(&pdev->dev, master->ibi.num_slots, in svc_i3c_master_probe()
1799 sizeof(*master->ibi.slots), in svc_i3c_master_probe()
1801 if (!master->ibi.slots) { in svc_i3c_master_probe()
1806 platform_set_drvdata(pdev, master); in svc_i3c_master_probe()
1814 svc_i3c_master_reset(master); in svc_i3c_master_probe()
1816 /* Register the master */ in svc_i3c_master_probe()
1817 ret = i3c_master_register(&master->base, &pdev->dev, in svc_i3c_master_probe()
1834 svc_i3c_master_unprepare_clks(master); in svc_i3c_master_probe()
1841 struct svc_i3c_master *master = platform_get_drvdata(pdev); in svc_i3c_master_remove() local
1843 cancel_work_sync(&master->hj_work); in svc_i3c_master_remove()
1844 i3c_master_unregister(&master->base); in svc_i3c_master_remove()
1850 static void svc_i3c_save_regs(struct svc_i3c_master *master) in svc_i3c_save_regs() argument
1852 master->saved_regs.mconfig = readl(master->regs + SVC_I3C_MCONFIG); in svc_i3c_save_regs()
1853 master->saved_regs.mdynaddr = readl(master->regs + SVC_I3C_MDYNADDR); in svc_i3c_save_regs()
1856 static void svc_i3c_restore_regs(struct svc_i3c_master *master) in svc_i3c_restore_regs() argument
1858 if (readl(master->regs + SVC_I3C_MDYNADDR) != in svc_i3c_restore_regs()
1859 master->saved_regs.mdynaddr) { in svc_i3c_restore_regs()
1860 writel(master->saved_regs.mconfig, in svc_i3c_restore_regs()
1861 master->regs + SVC_I3C_MCONFIG); in svc_i3c_restore_regs()
1862 writel(master->saved_regs.mdynaddr, in svc_i3c_restore_regs()
1863 master->regs + SVC_I3C_MDYNADDR); in svc_i3c_restore_regs()
1869 struct svc_i3c_master *master = dev_get_drvdata(dev); in svc_i3c_runtime_suspend() local
1871 svc_i3c_save_regs(master); in svc_i3c_runtime_suspend()
1872 svc_i3c_master_unprepare_clks(master); in svc_i3c_runtime_suspend()
1880 struct svc_i3c_master *master = dev_get_drvdata(dev); in svc_i3c_runtime_resume() local
1883 svc_i3c_master_prepare_clks(master); in svc_i3c_runtime_resume()
1885 svc_i3c_restore_regs(master); in svc_i3c_runtime_resume()
1898 { .compatible = "silvaco,i3c-master-v1"},
1907 .name = "silvaco-i3c-master",
1916 MODULE_DESCRIPTION("Silvaco dual-role I3C master driver");