forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/fsl/imx-audmux.c
....@@ -1,21 +1,11 @@
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
199
2010 #include <linux/clk.h>
2111 #include <linux/debugfs.h>
....@@ -33,6 +23,8 @@
3323
3424 static struct clk *audmux_clk;
3525 static void __iomem *audmux_base;
26
+static u32 *regcache;
27
+static u32 reg_max;
3628
3729 #define IMX_AUDMUX_V2_PTCR(x) ((x) * 8)
3830 #define IMX_AUDMUX_V2_PDCR(x) ((x) * 8 + 4)
....@@ -151,17 +143,11 @@
151143 char buf[20];
152144
153145 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
- }
158146
159147 for (i = 0; i < MX31_AUDMUX_PORT7_SSI_PINS_7 + 1; i++) {
160148 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);
165151 }
166152 }
167153
....@@ -314,12 +300,10 @@
314300
315301 static int imx_audmux_probe(struct platform_device *pdev)
316302 {
317
- struct resource *res;
318303 const struct of_device_id *of_id =
319304 of_match_device(imx_audmux_dt_ids, &pdev->dev);
320305
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);
323307 if (IS_ERR(audmux_base))
324308 return PTR_ERR(audmux_base);
325309
....@@ -333,8 +317,23 @@
333317 if (of_id)
334318 pdev->id_entry = of_id->data;
335319 audmux_type = pdev->id_entry->driver_data;
336
- if (audmux_type == IMX31_AUDMUX)
320
+
321
+ switch (audmux_type) {
322
+ case IMX31_AUDMUX:
337323 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;
338337
339338 if (of_id)
340339 imx_audmux_parse_dt_defaults(pdev, pdev->dev.of_node);
....@@ -350,12 +349,47 @@
350349 return 0;
351350 }
352351
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
+
353386 static struct platform_driver imx_audmux_driver = {
354387 .probe = imx_audmux_probe,
355388 .remove = imx_audmux_remove,
356389 .id_table = imx_audmux_ids,
357390 .driver = {
358391 .name = DRIVER_NAME,
392
+ .pm = &imx_audmux_pm,
359393 .of_match_table = imx_audmux_dt_ids,
360394 }
361395 };