1 // SPDX-License-Identifier: GPL-2.0-only
2 /* OMAP SSI driver.
3  *
4  * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5  * Copyright (C) 2014 Sebastian Reichel <sre@kernel.org>
6  *
7  * Contact: Carlos Chinea <carlos.chinea@nokia.com>
8  */
9 
10 #include <linux/compiler.h>
11 #include <linux/err.h>
12 #include <linux/ioport.h>
13 #include <linux/io.h>
14 #include <linux/clk.h>
15 #include <linux/device.h>
16 #include <linux/platform_device.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/dmaengine.h>
19 #include <linux/delay.h>
20 #include <linux/hsi/ssi_protocol.h>
21 #include <linux/seq_file.h>
22 #include <linux/scatterlist.h>
23 #include <linux/interrupt.h>
24 #include <linux/spinlock.h>
25 #include <linux/debugfs.h>
26 #include <linux/pinctrl/consumer.h>
27 #include <linux/pm_runtime.h>
28 #include <linux/of_platform.h>
29 #include <linux/hsi/hsi.h>
30 #include <linux/idr.h>
31 
32 #include "omap_ssi_regs.h"
33 #include "omap_ssi.h"
34 
35 /* For automatically allocated device IDs */
36 static DEFINE_IDA(platform_omap_ssi_ida);
37 
38 #ifdef CONFIG_DEBUG_FS
39 static int ssi_regs_show(struct seq_file *m, void *p __maybe_unused)
40 {
41 	struct hsi_controller *ssi = m->private;
42 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
43 	void __iomem *sys = omap_ssi->sys;
44 
45 	pm_runtime_get_sync(ssi->device.parent);
46 	seq_printf(m, "REVISION\t: 0x%08x\n",  readl(sys + SSI_REVISION_REG));
47 	seq_printf(m, "SYSCONFIG\t: 0x%08x\n", readl(sys + SSI_SYSCONFIG_REG));
48 	seq_printf(m, "SYSSTATUS\t: 0x%08x\n", readl(sys + SSI_SYSSTATUS_REG));
49 	pm_runtime_put(ssi->device.parent);
50 
51 	return 0;
52 }
53 
54 static int ssi_gdd_regs_show(struct seq_file *m, void *p __maybe_unused)
55 {
56 	struct hsi_controller *ssi = m->private;
57 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
58 	void __iomem *gdd = omap_ssi->gdd;
59 	void __iomem *sys = omap_ssi->sys;
60 	int lch;
61 
62 	pm_runtime_get_sync(ssi->device.parent);
63 
64 	seq_printf(m, "GDD_MPU_STATUS\t: 0x%08x\n",
65 		readl(sys + SSI_GDD_MPU_IRQ_STATUS_REG));
66 	seq_printf(m, "GDD_MPU_ENABLE\t: 0x%08x\n\n",
67 		readl(sys + SSI_GDD_MPU_IRQ_ENABLE_REG));
68 	seq_printf(m, "HW_ID\t\t: 0x%08x\n",
69 				readl(gdd + SSI_GDD_HW_ID_REG));
70 	seq_printf(m, "PPORT_ID\t: 0x%08x\n",
71 				readl(gdd + SSI_GDD_PPORT_ID_REG));
72 	seq_printf(m, "MPORT_ID\t: 0x%08x\n",
73 				readl(gdd + SSI_GDD_MPORT_ID_REG));
74 	seq_printf(m, "TEST\t\t: 0x%08x\n",
75 				readl(gdd + SSI_GDD_TEST_REG));
76 	seq_printf(m, "GCR\t\t: 0x%08x\n",
77 				readl(gdd + SSI_GDD_GCR_REG));
78 
79 	for (lch = 0; lch < SSI_MAX_GDD_LCH; lch++) {
80 		seq_printf(m, "\nGDD LCH %d\n=========\n", lch);
81 		seq_printf(m, "CSDP\t\t: 0x%04x\n",
82 				readw(gdd + SSI_GDD_CSDP_REG(lch)));
83 		seq_printf(m, "CCR\t\t: 0x%04x\n",
84 				readw(gdd + SSI_GDD_CCR_REG(lch)));
85 		seq_printf(m, "CICR\t\t: 0x%04x\n",
86 				readw(gdd + SSI_GDD_CICR_REG(lch)));
87 		seq_printf(m, "CSR\t\t: 0x%04x\n",
88 				readw(gdd + SSI_GDD_CSR_REG(lch)));
89 		seq_printf(m, "CSSA\t\t: 0x%08x\n",
90 				readl(gdd + SSI_GDD_CSSA_REG(lch)));
91 		seq_printf(m, "CDSA\t\t: 0x%08x\n",
92 				readl(gdd + SSI_GDD_CDSA_REG(lch)));
93 		seq_printf(m, "CEN\t\t: 0x%04x\n",
94 				readw(gdd + SSI_GDD_CEN_REG(lch)));
95 		seq_printf(m, "CSAC\t\t: 0x%04x\n",
96 				readw(gdd + SSI_GDD_CSAC_REG(lch)));
97 		seq_printf(m, "CDAC\t\t: 0x%04x\n",
98 				readw(gdd + SSI_GDD_CDAC_REG(lch)));
99 		seq_printf(m, "CLNK_CTRL\t: 0x%04x\n",
100 				readw(gdd + SSI_GDD_CLNK_CTRL_REG(lch)));
101 	}
102 
103 	pm_runtime_put(ssi->device.parent);
104 
105 	return 0;
106 }
107 
108 DEFINE_SHOW_ATTRIBUTE(ssi_regs);
109 DEFINE_SHOW_ATTRIBUTE(ssi_gdd_regs);
110 
111 static int ssi_debug_add_ctrl(struct hsi_controller *ssi)
112 {
113 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
114 	struct dentry *dir;
115 
116 	/* SSI controller */
117 	omap_ssi->dir = debugfs_create_dir(dev_name(&ssi->device), NULL);
118 	if (!omap_ssi->dir)
119 		return -ENOMEM;
120 
121 	debugfs_create_file("regs", S_IRUGO, omap_ssi->dir, ssi,
122 								&ssi_regs_fops);
123 	/* SSI GDD (DMA) */
124 	dir = debugfs_create_dir("gdd", omap_ssi->dir);
125 	if (!dir)
126 		goto rback;
127 	debugfs_create_file("regs", S_IRUGO, dir, ssi, &ssi_gdd_regs_fops);
128 
129 	return 0;
130 rback:
131 	debugfs_remove_recursive(omap_ssi->dir);
132 
133 	return -ENOMEM;
134 }
135 
136 static void ssi_debug_remove_ctrl(struct hsi_controller *ssi)
137 {
138 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
139 
140 	debugfs_remove_recursive(omap_ssi->dir);
141 }
142 #endif /* CONFIG_DEBUG_FS */
143 
144 /*
145  * FIXME: Horrible HACK needed until we remove the useless wakeline test
146  * in the CMT. To be removed !!!!
147  */
148 void ssi_waketest(struct hsi_client *cl, unsigned int enable)
149 {
150 	struct hsi_port *port = hsi_get_port(cl);
151 	struct omap_ssi_port *omap_port = hsi_port_drvdata(port);
152 	struct hsi_controller *ssi = to_hsi_controller(port->device.parent);
153 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
154 
155 	omap_port->wktest = !!enable;
156 	if (omap_port->wktest) {
157 		pm_runtime_get_sync(ssi->device.parent);
158 		writel_relaxed(SSI_WAKE(0),
159 				omap_ssi->sys + SSI_SET_WAKE_REG(port->num));
160 	} else {
161 		writel_relaxed(SSI_WAKE(0),
162 				omap_ssi->sys +	SSI_CLEAR_WAKE_REG(port->num));
163 		pm_runtime_put(ssi->device.parent);
164 	}
165 }
166 EXPORT_SYMBOL_GPL(ssi_waketest);
167 
168 static void ssi_gdd_complete(struct hsi_controller *ssi, unsigned int lch)
169 {
170 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
171 	struct hsi_msg *msg = omap_ssi->gdd_trn[lch].msg;
172 	struct hsi_port *port = to_hsi_port(msg->cl->device.parent);
173 	struct omap_ssi_port *omap_port = hsi_port_drvdata(port);
174 	unsigned int dir;
175 	u32 csr;
176 	u32 val;
177 
178 	spin_lock(&omap_ssi->lock);
179 
180 	val = readl(omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG);
181 	val &= ~SSI_GDD_LCH(lch);
182 	writel_relaxed(val, omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG);
183 
184 	if (msg->ttype == HSI_MSG_READ) {
185 		dir = DMA_FROM_DEVICE;
186 		val = SSI_DATAAVAILABLE(msg->channel);
187 		pm_runtime_put(omap_port->pdev);
188 	} else {
189 		dir = DMA_TO_DEVICE;
190 		val = SSI_DATAACCEPT(msg->channel);
191 		/* Keep clocks reference for write pio event */
192 	}
193 	dma_unmap_sg(&ssi->device, msg->sgt.sgl, msg->sgt.nents, dir);
194 	csr = readw(omap_ssi->gdd + SSI_GDD_CSR_REG(lch));
195 	omap_ssi->gdd_trn[lch].msg = NULL; /* release GDD lch */
196 	dev_dbg(&port->device, "DMA completed ch %d ttype %d\n",
197 				msg->channel, msg->ttype);
198 	spin_unlock(&omap_ssi->lock);
199 	if (csr & SSI_CSR_TOUR) { /* Timeout error */
200 		msg->status = HSI_STATUS_ERROR;
201 		msg->actual_len = 0;
202 		spin_lock(&omap_port->lock);
203 		list_del(&msg->link); /* Dequeue msg */
204 		spin_unlock(&omap_port->lock);
205 
206 		list_add_tail(&msg->link, &omap_port->errqueue);
207 		schedule_delayed_work(&omap_port->errqueue_work, 0);
208 		return;
209 	}
210 	spin_lock(&omap_port->lock);
211 	val |= readl(omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0));
212 	writel_relaxed(val, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0));
213 	spin_unlock(&omap_port->lock);
214 
215 	msg->status = HSI_STATUS_COMPLETED;
216 	msg->actual_len = sg_dma_len(msg->sgt.sgl);
217 }
218 
219 static void ssi_gdd_tasklet(unsigned long dev)
220 {
221 	struct hsi_controller *ssi = (struct hsi_controller *)dev;
222 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
223 	void __iomem *sys = omap_ssi->sys;
224 	unsigned int lch;
225 	u32 status_reg;
226 
227 	pm_runtime_get(ssi->device.parent);
228 
229 	if (!pm_runtime_active(ssi->device.parent)) {
230 		dev_warn(ssi->device.parent, "ssi_gdd_tasklet called without runtime PM!\n");
231 		pm_runtime_put(ssi->device.parent);
232 		return;
233 	}
234 
235 	status_reg = readl(sys + SSI_GDD_MPU_IRQ_STATUS_REG);
236 	for (lch = 0; lch < SSI_MAX_GDD_LCH; lch++) {
237 		if (status_reg & SSI_GDD_LCH(lch))
238 			ssi_gdd_complete(ssi, lch);
239 	}
240 	writel_relaxed(status_reg, sys + SSI_GDD_MPU_IRQ_STATUS_REG);
241 	status_reg = readl(sys + SSI_GDD_MPU_IRQ_STATUS_REG);
242 
243 	pm_runtime_put(ssi->device.parent);
244 
245 	if (status_reg)
246 		tasklet_hi_schedule(&omap_ssi->gdd_tasklet);
247 	else
248 		enable_irq(omap_ssi->gdd_irq);
249 
250 }
251 
252 static irqreturn_t ssi_gdd_isr(int irq, void *ssi)
253 {
254 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
255 
256 	tasklet_hi_schedule(&omap_ssi->gdd_tasklet);
257 	disable_irq_nosync(irq);
258 
259 	return IRQ_HANDLED;
260 }
261 
262 static unsigned long ssi_get_clk_rate(struct hsi_controller *ssi)
263 {
264 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
265 	unsigned long rate = clk_get_rate(omap_ssi->fck);
266 	return rate;
267 }
268 
269 static int ssi_clk_event(struct notifier_block *nb, unsigned long event,
270 								void *data)
271 {
272 	struct omap_ssi_controller *omap_ssi = container_of(nb,
273 					struct omap_ssi_controller, fck_nb);
274 	struct hsi_controller *ssi = to_hsi_controller(omap_ssi->dev);
275 	struct clk_notifier_data *clk_data = data;
276 	struct omap_ssi_port *omap_port;
277 	int i;
278 
279 	switch (event) {
280 	case PRE_RATE_CHANGE:
281 		dev_dbg(&ssi->device, "pre rate change\n");
282 
283 		for (i = 0; i < ssi->num_ports; i++) {
284 			omap_port = omap_ssi->port[i];
285 
286 			if (!omap_port)
287 				continue;
288 
289 			/* Workaround for SWBREAK + CAwake down race in CMT */
290 			disable_irq(omap_port->wake_irq);
291 
292 			/* stop all ssi communication */
293 			pinctrl_pm_select_idle_state(omap_port->pdev);
294 			udelay(1); /* wait for racing frames */
295 		}
296 
297 		break;
298 	case ABORT_RATE_CHANGE:
299 		dev_dbg(&ssi->device, "abort rate change\n");
300 		fallthrough;
301 	case POST_RATE_CHANGE:
302 		dev_dbg(&ssi->device, "post rate change (%lu -> %lu)\n",
303 			clk_data->old_rate, clk_data->new_rate);
304 		omap_ssi->fck_rate = DIV_ROUND_CLOSEST(clk_data->new_rate, 1000); /* kHz */
305 
306 		for (i = 0; i < ssi->num_ports; i++) {
307 			omap_port = omap_ssi->port[i];
308 
309 			if (!omap_port)
310 				continue;
311 
312 			omap_ssi_port_update_fclk(ssi, omap_port);
313 
314 			/* resume ssi communication */
315 			pinctrl_pm_select_default_state(omap_port->pdev);
316 			enable_irq(omap_port->wake_irq);
317 		}
318 
319 		break;
320 	default:
321 		break;
322 	}
323 
324 	return NOTIFY_DONE;
325 }
326 
327 static int ssi_get_iomem(struct platform_device *pd,
328 		const char *name, void __iomem **pbase, dma_addr_t *phy)
329 {
330 	struct resource *mem;
331 	void __iomem *base;
332 	struct hsi_controller *ssi = platform_get_drvdata(pd);
333 
334 	mem = platform_get_resource_byname(pd, IORESOURCE_MEM, name);
335 	base = devm_ioremap_resource(&ssi->device, mem);
336 	if (IS_ERR(base))
337 		return PTR_ERR(base);
338 
339 	*pbase = base;
340 
341 	if (phy)
342 		*phy = mem->start;
343 
344 	return 0;
345 }
346 
347 static int ssi_add_controller(struct hsi_controller *ssi,
348 						struct platform_device *pd)
349 {
350 	struct omap_ssi_controller *omap_ssi;
351 	int err;
352 
353 	omap_ssi = devm_kzalloc(&ssi->device, sizeof(*omap_ssi), GFP_KERNEL);
354 	if (!omap_ssi)
355 		return -ENOMEM;
356 
357 	err = ida_simple_get(&platform_omap_ssi_ida, 0, 0, GFP_KERNEL);
358 	if (err < 0)
359 		return err;
360 	ssi->id = err;
361 
362 	ssi->owner = THIS_MODULE;
363 	ssi->device.parent = &pd->dev;
364 	dev_set_name(&ssi->device, "ssi%d", ssi->id);
365 	hsi_controller_set_drvdata(ssi, omap_ssi);
366 	omap_ssi->dev = &ssi->device;
367 	err = ssi_get_iomem(pd, "sys", &omap_ssi->sys, NULL);
368 	if (err < 0)
369 		goto out_err;
370 	err = ssi_get_iomem(pd, "gdd", &omap_ssi->gdd, NULL);
371 	if (err < 0)
372 		goto out_err;
373 	err = platform_get_irq_byname(pd, "gdd_mpu");
374 	if (err < 0)
375 		goto out_err;
376 	omap_ssi->gdd_irq = err;
377 	tasklet_init(&omap_ssi->gdd_tasklet, ssi_gdd_tasklet,
378 							(unsigned long)ssi);
379 	err = devm_request_irq(&ssi->device, omap_ssi->gdd_irq, ssi_gdd_isr,
380 						0, "gdd_mpu", ssi);
381 	if (err < 0) {
382 		dev_err(&ssi->device, "Request GDD IRQ %d failed (%d)",
383 							omap_ssi->gdd_irq, err);
384 		goto out_err;
385 	}
386 
387 	omap_ssi->port = devm_kcalloc(&ssi->device, ssi->num_ports,
388 				      sizeof(*omap_ssi->port), GFP_KERNEL);
389 	if (!omap_ssi->port) {
390 		err = -ENOMEM;
391 		goto out_err;
392 	}
393 
394 	omap_ssi->fck = devm_clk_get(&ssi->device, "ssi_ssr_fck");
395 	if (IS_ERR(omap_ssi->fck)) {
396 		dev_err(&pd->dev, "Could not acquire clock \"ssi_ssr_fck\": %li\n",
397 			PTR_ERR(omap_ssi->fck));
398 		err = -ENODEV;
399 		goto out_err;
400 	}
401 
402 	omap_ssi->fck_nb.notifier_call = ssi_clk_event;
403 	omap_ssi->fck_nb.priority = INT_MAX;
404 	clk_notifier_register(omap_ssi->fck, &omap_ssi->fck_nb);
405 
406 	/* TODO: find register, which can be used to detect context loss */
407 	omap_ssi->get_loss = NULL;
408 
409 	omap_ssi->max_speed = UINT_MAX;
410 	spin_lock_init(&omap_ssi->lock);
411 	err = hsi_register_controller(ssi);
412 
413 	if (err < 0)
414 		goto out_err;
415 
416 	return 0;
417 
418 out_err:
419 	ida_simple_remove(&platform_omap_ssi_ida, ssi->id);
420 	return err;
421 }
422 
423 static int ssi_hw_init(struct hsi_controller *ssi)
424 {
425 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
426 	int err;
427 
428 	err = pm_runtime_resume_and_get(ssi->device.parent);
429 	if (err < 0) {
430 		dev_err(&ssi->device, "runtime PM failed %d\n", err);
431 		return err;
432 	}
433 	/* Resetting GDD */
434 	writel_relaxed(SSI_SWRESET, omap_ssi->gdd + SSI_GDD_GRST_REG);
435 	/* Get FCK rate in kHz */
436 	omap_ssi->fck_rate = DIV_ROUND_CLOSEST(ssi_get_clk_rate(ssi), 1000);
437 	dev_dbg(&ssi->device, "SSI fck rate %lu kHz\n", omap_ssi->fck_rate);
438 
439 	writel_relaxed(SSI_CLK_AUTOGATING_ON, omap_ssi->sys + SSI_GDD_GCR_REG);
440 	omap_ssi->gdd_gcr = SSI_CLK_AUTOGATING_ON;
441 	pm_runtime_put_sync(ssi->device.parent);
442 
443 	return 0;
444 }
445 
446 static void ssi_remove_controller(struct hsi_controller *ssi)
447 {
448 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
449 	int id = ssi->id;
450 	tasklet_kill(&omap_ssi->gdd_tasklet);
451 	hsi_unregister_controller(ssi);
452 	clk_notifier_unregister(omap_ssi->fck, &omap_ssi->fck_nb);
453 	ida_simple_remove(&platform_omap_ssi_ida, id);
454 }
455 
456 static inline int ssi_of_get_available_ports_count(const struct device_node *np)
457 {
458 	struct device_node *child;
459 	int num = 0;
460 
461 	for_each_available_child_of_node(np, child)
462 		if (of_device_is_compatible(child, "ti,omap3-ssi-port"))
463 			num++;
464 
465 	return num;
466 }
467 
468 static int ssi_remove_ports(struct device *dev, void *c)
469 {
470 	struct platform_device *pdev = to_platform_device(dev);
471 
472 	if (!dev->of_node)
473 		return 0;
474 
475 	of_node_clear_flag(dev->of_node, OF_POPULATED);
476 	of_device_unregister(pdev);
477 
478 	return 0;
479 }
480 
481 static int ssi_probe(struct platform_device *pd)
482 {
483 	struct platform_device *childpdev;
484 	struct device_node *np = pd->dev.of_node;
485 	struct device_node *child;
486 	struct hsi_controller *ssi;
487 	int err;
488 	int num_ports;
489 
490 	if (!np) {
491 		dev_err(&pd->dev, "missing device tree data\n");
492 		return -EINVAL;
493 	}
494 
495 	num_ports = ssi_of_get_available_ports_count(np);
496 
497 	ssi = hsi_alloc_controller(num_ports, GFP_KERNEL);
498 	if (!ssi) {
499 		dev_err(&pd->dev, "No memory for controller\n");
500 		return -ENOMEM;
501 	}
502 
503 	platform_set_drvdata(pd, ssi);
504 
505 	err = ssi_add_controller(ssi, pd);
506 	if (err < 0) {
507 		hsi_put_controller(ssi);
508 		goto out1;
509 	}
510 
511 	pm_runtime_enable(&pd->dev);
512 
513 	err = ssi_hw_init(ssi);
514 	if (err < 0)
515 		goto out2;
516 #ifdef CONFIG_DEBUG_FS
517 	err = ssi_debug_add_ctrl(ssi);
518 	if (err < 0)
519 		goto out2;
520 #endif
521 
522 	for_each_available_child_of_node(np, child) {
523 		if (!of_device_is_compatible(child, "ti,omap3-ssi-port"))
524 			continue;
525 
526 		childpdev = of_platform_device_create(child, NULL, &pd->dev);
527 		if (!childpdev) {
528 			err = -ENODEV;
529 			dev_err(&pd->dev, "failed to create ssi controller port\n");
530 			of_node_put(child);
531 			goto out3;
532 		}
533 	}
534 
535 	dev_info(&pd->dev, "ssi controller %d initialized (%d ports)!\n",
536 		ssi->id, num_ports);
537 	return err;
538 out3:
539 	device_for_each_child(&pd->dev, NULL, ssi_remove_ports);
540 out2:
541 	ssi_remove_controller(ssi);
542 	pm_runtime_disable(&pd->dev);
543 out1:
544 	platform_set_drvdata(pd, NULL);
545 
546 	return err;
547 }
548 
549 static int ssi_remove(struct platform_device *pd)
550 {
551 	struct hsi_controller *ssi = platform_get_drvdata(pd);
552 
553 	/* cleanup of of_platform_populate() call */
554 	device_for_each_child(&pd->dev, NULL, ssi_remove_ports);
555 
556 #ifdef CONFIG_DEBUG_FS
557 	ssi_debug_remove_ctrl(ssi);
558 #endif
559 	ssi_remove_controller(ssi);
560 	platform_set_drvdata(pd, NULL);
561 
562 	pm_runtime_disable(&pd->dev);
563 
564 	return 0;
565 }
566 
567 #ifdef CONFIG_PM
568 static int omap_ssi_runtime_suspend(struct device *dev)
569 {
570 	struct hsi_controller *ssi = dev_get_drvdata(dev);
571 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
572 
573 	dev_dbg(dev, "runtime suspend!\n");
574 
575 	if (omap_ssi->get_loss)
576 		omap_ssi->loss_count =
577 				omap_ssi->get_loss(ssi->device.parent);
578 
579 	return 0;
580 }
581 
582 static int omap_ssi_runtime_resume(struct device *dev)
583 {
584 	struct hsi_controller *ssi = dev_get_drvdata(dev);
585 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
586 
587 	dev_dbg(dev, "runtime resume!\n");
588 
589 	if ((omap_ssi->get_loss) && (omap_ssi->loss_count ==
590 				omap_ssi->get_loss(ssi->device.parent)))
591 		return 0;
592 
593 	writel_relaxed(omap_ssi->gdd_gcr, omap_ssi->gdd + SSI_GDD_GCR_REG);
594 
595 	return 0;
596 }
597 
598 static const struct dev_pm_ops omap_ssi_pm_ops = {
599 	SET_RUNTIME_PM_OPS(omap_ssi_runtime_suspend, omap_ssi_runtime_resume,
600 		NULL)
601 };
602 
603 #define DEV_PM_OPS     (&omap_ssi_pm_ops)
604 #else
605 #define DEV_PM_OPS     NULL
606 #endif
607 
608 #ifdef CONFIG_OF
609 static const struct of_device_id omap_ssi_of_match[] = {
610 	{ .compatible = "ti,omap3-ssi", },
611 	{},
612 };
613 MODULE_DEVICE_TABLE(of, omap_ssi_of_match);
614 #else
615 #define omap_ssi_of_match NULL
616 #endif
617 
618 static struct platform_driver ssi_pdriver = {
619 	.probe = ssi_probe,
620 	.remove	= ssi_remove,
621 	.driver	= {
622 		.name	= "omap_ssi",
623 		.pm     = DEV_PM_OPS,
624 		.of_match_table = omap_ssi_of_match,
625 	},
626 };
627 
628 static int __init ssi_init(void) {
629 	int ret;
630 
631 	ret = platform_driver_register(&ssi_pdriver);
632 	if (ret)
633 		return ret;
634 
635 	ret = platform_driver_register(&ssi_port_pdriver);
636 	if (ret) {
637 		platform_driver_unregister(&ssi_pdriver);
638 		return ret;
639 	}
640 
641 	return 0;
642 }
643 module_init(ssi_init);
644 
645 static void __exit ssi_exit(void) {
646 	platform_driver_unregister(&ssi_port_pdriver);
647 	platform_driver_unregister(&ssi_pdriver);
648 }
649 module_exit(ssi_exit);
650 
651 MODULE_ALIAS("platform:omap_ssi");
652 MODULE_AUTHOR("Carlos Chinea <carlos.chinea@nokia.com>");
653 MODULE_AUTHOR("Sebastian Reichel <sre@kernel.org>");
654 MODULE_DESCRIPTION("Synchronous Serial Interface Driver");
655 MODULE_LICENSE("GPL v2");
656