Lines Matching refs:qmp

51 	struct qmp *qmp;  member
69 struct qmp { struct
87 static void qmp_kick(struct qmp *qmp) in qmp_kick() argument
89 mbox_send_message(qmp->mbox_chan, NULL); in qmp_kick()
90 mbox_client_txdone(qmp->mbox_chan, 0); in qmp_kick()
93 static bool qmp_magic_valid(struct qmp *qmp) in qmp_magic_valid() argument
95 return readl(qmp->msgram + QMP_DESC_MAGIC) == QMP_MAGIC; in qmp_magic_valid()
98 static bool qmp_link_acked(struct qmp *qmp) in qmp_link_acked() argument
100 return readl(qmp->msgram + QMP_DESC_MCORE_LINK_STATE_ACK) == QMP_STATE_UP; in qmp_link_acked()
103 static bool qmp_mcore_channel_acked(struct qmp *qmp) in qmp_mcore_channel_acked() argument
105 return readl(qmp->msgram + QMP_DESC_MCORE_CH_STATE_ACK) == QMP_STATE_UP; in qmp_mcore_channel_acked()
108 static bool qmp_ucore_channel_up(struct qmp *qmp) in qmp_ucore_channel_up() argument
110 return readl(qmp->msgram + QMP_DESC_UCORE_CH_STATE) == QMP_STATE_UP; in qmp_ucore_channel_up()
113 static int qmp_open(struct qmp *qmp) in qmp_open() argument
118 if (!qmp_magic_valid(qmp)) { in qmp_open()
119 dev_err(qmp->dev, "QMP magic doesn't match\n"); in qmp_open()
123 val = readl(qmp->msgram + QMP_DESC_VERSION); in qmp_open()
125 dev_err(qmp->dev, "unsupported QMP version %d\n", val); in qmp_open()
129 qmp->offset = readl(qmp->msgram + QMP_DESC_MCORE_MBOX_OFFSET); in qmp_open()
130 qmp->size = readl(qmp->msgram + QMP_DESC_MCORE_MBOX_SIZE); in qmp_open()
131 if (!qmp->size) { in qmp_open()
132 dev_err(qmp->dev, "invalid mailbox size\n"); in qmp_open()
137 val = readl(qmp->msgram + QMP_DESC_UCORE_LINK_STATE); in qmp_open()
138 writel(val, qmp->msgram + QMP_DESC_UCORE_LINK_STATE_ACK); in qmp_open()
141 writel(QMP_STATE_UP, qmp->msgram + QMP_DESC_MCORE_LINK_STATE); in qmp_open()
143 qmp_kick(qmp); in qmp_open()
145 ret = wait_event_timeout(qmp->event, qmp_link_acked(qmp), HZ); in qmp_open()
147 dev_err(qmp->dev, "ucore didn't ack link\n"); in qmp_open()
151 writel(QMP_STATE_UP, qmp->msgram + QMP_DESC_MCORE_CH_STATE); in qmp_open()
153 qmp_kick(qmp); in qmp_open()
155 ret = wait_event_timeout(qmp->event, qmp_ucore_channel_up(qmp), HZ); in qmp_open()
157 dev_err(qmp->dev, "ucore didn't open channel\n"); in qmp_open()
162 writel(QMP_STATE_UP, qmp->msgram + QMP_DESC_UCORE_CH_STATE_ACK); in qmp_open()
164 qmp_kick(qmp); in qmp_open()
166 ret = wait_event_timeout(qmp->event, qmp_mcore_channel_acked(qmp), HZ); in qmp_open()
168 dev_err(qmp->dev, "ucore didn't ack channel\n"); in qmp_open()
175 writel(QMP_STATE_DOWN, qmp->msgram + QMP_DESC_MCORE_CH_STATE); in qmp_open()
178 writel(QMP_STATE_DOWN, qmp->msgram + QMP_DESC_MCORE_LINK_STATE); in qmp_open()
179 qmp_kick(qmp); in qmp_open()
184 static void qmp_close(struct qmp *qmp) in qmp_close() argument
186 writel(QMP_STATE_DOWN, qmp->msgram + QMP_DESC_MCORE_CH_STATE); in qmp_close()
187 writel(QMP_STATE_DOWN, qmp->msgram + QMP_DESC_MCORE_LINK_STATE); in qmp_close()
188 qmp_kick(qmp); in qmp_close()
193 struct qmp *qmp = data; in qmp_intr() local
195 wake_up_all(&qmp->event); in qmp_intr()
200 static bool qmp_message_empty(struct qmp *qmp) in qmp_message_empty() argument
202 return readl(qmp->msgram + qmp->offset) == 0; in qmp_message_empty()
217 int qmp_send(struct qmp *qmp, const void *data, size_t len) in qmp_send() argument
222 if (WARN_ON(IS_ERR_OR_NULL(qmp) || !data)) in qmp_send()
225 if (WARN_ON(len + sizeof(u32) > qmp->size)) in qmp_send()
231 mutex_lock(&qmp->tx_lock); in qmp_send()
234 __iowrite32_copy(qmp->msgram + qmp->offset + sizeof(u32), in qmp_send()
236 writel(len, qmp->msgram + qmp->offset); in qmp_send()
239 readl(qmp->msgram + qmp->offset); in qmp_send()
240 qmp_kick(qmp); in qmp_send()
242 time_left = wait_event_interruptible_timeout(qmp->event, in qmp_send()
243 qmp_message_empty(qmp), HZ); in qmp_send()
245 dev_err(qmp->dev, "ucore did not ack channel\n"); in qmp_send()
249 writel(0, qmp->msgram + qmp->offset); in qmp_send()
254 mutex_unlock(&qmp->tx_lock); in qmp_send()
263 struct qmp *qmp = container_of(hw, struct qmp, qdss_clk); in qmp_qdss_clk_prepare() local
265 return qmp_send(qmp, buf, sizeof(buf)); in qmp_qdss_clk_prepare()
271 struct qmp *qmp = container_of(hw, struct qmp, qdss_clk); in qmp_qdss_clk_unprepare() local
273 qmp_send(qmp, buf, sizeof(buf)); in qmp_qdss_clk_unprepare()
281 static int qmp_qdss_clk_add(struct qmp *qmp) in qmp_qdss_clk_add() argument
289 qmp->qdss_clk.init = &qdss_init; in qmp_qdss_clk_add()
290 ret = clk_hw_register(qmp->dev, &qmp->qdss_clk); in qmp_qdss_clk_add()
292 dev_err(qmp->dev, "failed to register qdss clock\n"); in qmp_qdss_clk_add()
296 ret = of_clk_add_hw_provider(qmp->dev->of_node, of_clk_hw_simple_get, in qmp_qdss_clk_add()
297 &qmp->qdss_clk); in qmp_qdss_clk_add()
299 dev_err(qmp->dev, "unable to register of clk hw provider\n"); in qmp_qdss_clk_add()
300 clk_hw_unregister(&qmp->qdss_clk); in qmp_qdss_clk_add()
306 static void qmp_qdss_clk_remove(struct qmp *qmp) in qmp_qdss_clk_remove() argument
308 of_clk_del_provider(qmp->dev->of_node); in qmp_qdss_clk_remove()
309 clk_hw_unregister(&qmp->qdss_clk); in qmp_qdss_clk_remove()
347 ret = qmp_send(qmp_cdev->qmp, buf, sizeof(buf)); in qmp_cdev_set_cur_state()
361 static int qmp_cooling_device_add(struct qmp *qmp, in qmp_cooling_device_add() argument
367 qmp_cdev->qmp = qmp; in qmp_cooling_device_add()
371 (qmp->dev, node, in qmp_cooling_device_add()
376 dev_err(qmp->dev, "unable to register %s cooling device\n", in qmp_cooling_device_add()
382 static int qmp_cooling_devices_register(struct qmp *qmp) in qmp_cooling_devices_register() argument
388 np = qmp->dev->of_node; in qmp_cooling_devices_register()
390 qmp->cooling_devs = devm_kcalloc(qmp->dev, QMP_NUM_COOLING_RESOURCES, in qmp_cooling_devices_register()
391 sizeof(*qmp->cooling_devs), in qmp_cooling_devices_register()
394 if (!qmp->cooling_devs) in qmp_cooling_devices_register()
400 ret = qmp_cooling_device_add(qmp, &qmp->cooling_devs[count++], in qmp_cooling_devices_register()
407 devm_kfree(qmp->dev, qmp->cooling_devs); in qmp_cooling_devices_register()
414 (qmp->cooling_devs[count].cdev); in qmp_cooling_devices_register()
415 devm_kfree(qmp->dev, qmp->cooling_devs); in qmp_cooling_devices_register()
420 static void qmp_cooling_devices_remove(struct qmp *qmp) in qmp_cooling_devices_remove() argument
425 thermal_cooling_device_unregister(qmp->cooling_devs[i].cdev); in qmp_cooling_devices_remove()
434 struct qmp *qmp_get(struct device *dev) in qmp_get()
438 struct qmp *qmp; in qmp_get() local
452 qmp = platform_get_drvdata(pdev); in qmp_get()
454 return qmp ? qmp : ERR_PTR(-EPROBE_DEFER); in qmp_get()
462 void qmp_put(struct qmp *qmp) in qmp_put() argument
468 if (!IS_ERR_OR_NULL(qmp)) in qmp_put()
469 put_device(qmp->dev); in qmp_put()
475 struct qmp *qmp; in qmp_probe() local
479 qmp = devm_kzalloc(&pdev->dev, sizeof(*qmp), GFP_KERNEL); in qmp_probe()
480 if (!qmp) in qmp_probe()
483 qmp->dev = &pdev->dev; in qmp_probe()
484 init_waitqueue_head(&qmp->event); in qmp_probe()
485 mutex_init(&qmp->tx_lock); in qmp_probe()
487 qmp->msgram = devm_platform_ioremap_resource(pdev, 0); in qmp_probe()
488 if (IS_ERR(qmp->msgram)) in qmp_probe()
489 return PTR_ERR(qmp->msgram); in qmp_probe()
491 qmp->mbox_client.dev = &pdev->dev; in qmp_probe()
492 qmp->mbox_client.knows_txdone = true; in qmp_probe()
493 qmp->mbox_chan = mbox_request_channel(&qmp->mbox_client, 0); in qmp_probe()
494 if (IS_ERR(qmp->mbox_chan)) { in qmp_probe()
496 return PTR_ERR(qmp->mbox_chan); in qmp_probe()
501 "aoss-qmp", qmp); in qmp_probe()
507 ret = qmp_open(qmp); in qmp_probe()
511 ret = qmp_qdss_clk_add(qmp); in qmp_probe()
515 ret = qmp_cooling_devices_register(qmp); in qmp_probe()
519 platform_set_drvdata(pdev, qmp); in qmp_probe()
524 qmp_close(qmp); in qmp_probe()
526 mbox_free_channel(qmp->mbox_chan); in qmp_probe()
533 struct qmp *qmp = platform_get_drvdata(pdev); in qmp_remove() local
535 qmp_qdss_clk_remove(qmp); in qmp_remove()
536 qmp_cooling_devices_remove(qmp); in qmp_remove()
538 qmp_close(qmp); in qmp_remove()
539 mbox_free_channel(qmp->mbox_chan); in qmp_remove()