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