.. | .. |
---|
1 | | -/* |
---|
2 | | - * Copyright 2012 Freescale Semiconductor, Inc. |
---|
3 | | - * Copyright 2012 Linaro Ltd. |
---|
4 | | - * Copyright 2009 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de> |
---|
5 | | - * |
---|
6 | | - * Initial development of this code was funded by |
---|
7 | | - * Phytec Messtechnik GmbH, http://www.phytec.de |
---|
8 | | - * |
---|
9 | | - * This program is free software; you can redistribute it and/or modify |
---|
10 | | - * it under the terms of the GNU General Public License as published by |
---|
11 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
12 | | - * (at your option) any later version. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, |
---|
15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | | - * GNU General Public License for more details. |
---|
18 | | - */ |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
| 2 | +// |
---|
| 3 | +// Copyright 2012 Freescale Semiconductor, Inc. |
---|
| 4 | +// Copyright 2012 Linaro Ltd. |
---|
| 5 | +// Copyright 2009 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de> |
---|
| 6 | +// |
---|
| 7 | +// Initial development of this code was funded by |
---|
| 8 | +// Phytec Messtechnik GmbH, https://www.phytec.de |
---|
19 | 9 | |
---|
20 | 10 | #include <linux/clk.h> |
---|
21 | 11 | #include <linux/debugfs.h> |
---|
.. | .. |
---|
33 | 23 | |
---|
34 | 24 | static struct clk *audmux_clk; |
---|
35 | 25 | static void __iomem *audmux_base; |
---|
| 26 | +static u32 *regcache; |
---|
| 27 | +static u32 reg_max; |
---|
36 | 28 | |
---|
37 | 29 | #define IMX_AUDMUX_V2_PTCR(x) ((x) * 8) |
---|
38 | 30 | #define IMX_AUDMUX_V2_PDCR(x) ((x) * 8 + 4) |
---|
.. | .. |
---|
151 | 143 | char buf[20]; |
---|
152 | 144 | |
---|
153 | 145 | audmux_debugfs_root = debugfs_create_dir("audmux", NULL); |
---|
154 | | - if (!audmux_debugfs_root) { |
---|
155 | | - pr_warning("Failed to create AUDMUX debugfs root\n"); |
---|
156 | | - return; |
---|
157 | | - } |
---|
158 | 146 | |
---|
159 | 147 | for (i = 0; i < MX31_AUDMUX_PORT7_SSI_PINS_7 + 1; i++) { |
---|
160 | 148 | snprintf(buf, sizeof(buf), "ssi%lu", i); |
---|
161 | | - if (!debugfs_create_file(buf, 0444, audmux_debugfs_root, |
---|
162 | | - (void *)i, &audmux_debugfs_fops)) |
---|
163 | | - pr_warning("Failed to create AUDMUX port %lu debugfs file\n", |
---|
164 | | - i); |
---|
| 149 | + debugfs_create_file(buf, 0444, audmux_debugfs_root, |
---|
| 150 | + (void *)i, &audmux_debugfs_fops); |
---|
165 | 151 | } |
---|
166 | 152 | } |
---|
167 | 153 | |
---|
.. | .. |
---|
314 | 300 | |
---|
315 | 301 | static int imx_audmux_probe(struct platform_device *pdev) |
---|
316 | 302 | { |
---|
317 | | - struct resource *res; |
---|
318 | 303 | const struct of_device_id *of_id = |
---|
319 | 304 | of_match_device(imx_audmux_dt_ids, &pdev->dev); |
---|
320 | 305 | |
---|
321 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
322 | | - audmux_base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 306 | + audmux_base = devm_platform_ioremap_resource(pdev, 0); |
---|
323 | 307 | if (IS_ERR(audmux_base)) |
---|
324 | 308 | return PTR_ERR(audmux_base); |
---|
325 | 309 | |
---|
.. | .. |
---|
333 | 317 | if (of_id) |
---|
334 | 318 | pdev->id_entry = of_id->data; |
---|
335 | 319 | audmux_type = pdev->id_entry->driver_data; |
---|
336 | | - if (audmux_type == IMX31_AUDMUX) |
---|
| 320 | + |
---|
| 321 | + switch (audmux_type) { |
---|
| 322 | + case IMX31_AUDMUX: |
---|
337 | 323 | audmux_debugfs_init(); |
---|
| 324 | + reg_max = 14; |
---|
| 325 | + break; |
---|
| 326 | + case IMX21_AUDMUX: |
---|
| 327 | + reg_max = 6; |
---|
| 328 | + break; |
---|
| 329 | + default: |
---|
| 330 | + dev_err(&pdev->dev, "unsupported version!\n"); |
---|
| 331 | + return -EINVAL; |
---|
| 332 | + } |
---|
| 333 | + |
---|
| 334 | + regcache = devm_kzalloc(&pdev->dev, sizeof(u32) * reg_max, GFP_KERNEL); |
---|
| 335 | + if (!regcache) |
---|
| 336 | + return -ENOMEM; |
---|
338 | 337 | |
---|
339 | 338 | if (of_id) |
---|
340 | 339 | imx_audmux_parse_dt_defaults(pdev, pdev->dev.of_node); |
---|
.. | .. |
---|
350 | 349 | return 0; |
---|
351 | 350 | } |
---|
352 | 351 | |
---|
| 352 | +#ifdef CONFIG_PM_SLEEP |
---|
| 353 | +static int imx_audmux_suspend(struct device *dev) |
---|
| 354 | +{ |
---|
| 355 | + int i; |
---|
| 356 | + |
---|
| 357 | + clk_prepare_enable(audmux_clk); |
---|
| 358 | + |
---|
| 359 | + for (i = 0; i < reg_max; i++) |
---|
| 360 | + regcache[i] = readl(audmux_base + i * 4); |
---|
| 361 | + |
---|
| 362 | + clk_disable_unprepare(audmux_clk); |
---|
| 363 | + |
---|
| 364 | + return 0; |
---|
| 365 | +} |
---|
| 366 | + |
---|
| 367 | +static int imx_audmux_resume(struct device *dev) |
---|
| 368 | +{ |
---|
| 369 | + int i; |
---|
| 370 | + |
---|
| 371 | + clk_prepare_enable(audmux_clk); |
---|
| 372 | + |
---|
| 373 | + for (i = 0; i < reg_max; i++) |
---|
| 374 | + writel(regcache[i], audmux_base + i * 4); |
---|
| 375 | + |
---|
| 376 | + clk_disable_unprepare(audmux_clk); |
---|
| 377 | + |
---|
| 378 | + return 0; |
---|
| 379 | +} |
---|
| 380 | +#endif /* CONFIG_PM_SLEEP */ |
---|
| 381 | + |
---|
| 382 | +static const struct dev_pm_ops imx_audmux_pm = { |
---|
| 383 | + SET_SYSTEM_SLEEP_PM_OPS(imx_audmux_suspend, imx_audmux_resume) |
---|
| 384 | +}; |
---|
| 385 | + |
---|
353 | 386 | static struct platform_driver imx_audmux_driver = { |
---|
354 | 387 | .probe = imx_audmux_probe, |
---|
355 | 388 | .remove = imx_audmux_remove, |
---|
356 | 389 | .id_table = imx_audmux_ids, |
---|
357 | 390 | .driver = { |
---|
358 | 391 | .name = DRIVER_NAME, |
---|
| 392 | + .pm = &imx_audmux_pm, |
---|
359 | 393 | .of_match_table = imx_audmux_dt_ids, |
---|
360 | 394 | } |
---|
361 | 395 | }; |
---|