xref: /openbmc/linux/arch/mips/lantiq/xway/vmmc.c (revision f1288bdb)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *
4  *  Copyright (C) 2012 John Crispin <john@phrozen.org>
5  */
6 
7 #include <linux/err.h>
8 #include <linux/export.h>
9 #include <linux/gpio/consumer.h>
10 #include <linux/of_platform.h>
11 #include <linux/dma-mapping.h>
12 
13 #include <lantiq_soc.h>
14 
15 static unsigned int *cp1_base;
16 
17 unsigned int *ltq_get_cp1_base(void)
18 {
19 	if (!cp1_base)
20 		panic("no cp1 base was set\n");
21 
22 	return cp1_base;
23 }
24 EXPORT_SYMBOL(ltq_get_cp1_base);
25 
26 static int vmmc_probe(struct platform_device *pdev)
27 {
28 #define CP1_SIZE       (1 << 20)
29 	struct gpio_desc *gpio;
30 	int gpio_count;
31 	dma_addr_t dma;
32 	int error;
33 
34 	cp1_base =
35 		(void *) CPHYSADDR(dma_alloc_coherent(&pdev->dev, CP1_SIZE,
36 						    &dma, GFP_KERNEL));
37 
38 	gpio_count = gpiod_count(&pdev->dev, NULL);
39 	while (gpio_count > 0) {
40 		gpio = devm_gpiod_get_index(&pdev->dev,
41 					    NULL, --gpio_count, GPIOD_OUT_HIGH);
42 		error = PTR_ERR_OR_ZERO(gpio);
43 		if (error) {
44 			dev_err(&pdev->dev,
45 				"failed to request GPIO idx %d: %d\n",
46 				gpio_count, error);
47 			continue;
48 		}
49 
50 		gpiod_set_consumer_name(gpio, "vmmc-relay");
51 	}
52 
53 	dev_info(&pdev->dev, "reserved %dMB at 0x%p", CP1_SIZE >> 20, cp1_base);
54 
55 	return 0;
56 }
57 
58 static const struct of_device_id vmmc_match[] = {
59 	{ .compatible = "lantiq,vmmc-xway" },
60 	{},
61 };
62 
63 static struct platform_driver vmmc_driver = {
64 	.probe = vmmc_probe,
65 	.driver = {
66 		.name = "lantiq,vmmc",
67 		.of_match_table = vmmc_match,
68 	},
69 };
70 builtin_platform_driver(vmmc_driver);
71