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