1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * platform_bcm43xx.c: bcm43xx platform data initialization file
4 *
5 * (C) Copyright 2016 Intel Corporation
6 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
7 */
8
9 #include <linux/gpio/machine.h>
10 #include <linux/platform_device.h>
11 #include <linux/regulator/machine.h>
12 #include <linux/regulator/fixed.h>
13 #include <linux/sfi.h>
14
15 #include <asm/intel-mid.h>
16
17 #define WLAN_SFI_GPIO_IRQ_NAME "WLAN-interrupt"
18 #define WLAN_SFI_GPIO_ENABLE_NAME "WLAN-enable"
19
20 #define WLAN_DEV_NAME "0000:00:01.3"
21
22 static struct regulator_consumer_supply bcm43xx_vmmc_supply = {
23 .dev_name = WLAN_DEV_NAME,
24 .supply = "vmmc",
25 };
26
27 static struct regulator_init_data bcm43xx_vmmc_data = {
28 .constraints = {
29 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
30 },
31 .num_consumer_supplies = 1,
32 .consumer_supplies = &bcm43xx_vmmc_supply,
33 };
34
35 static struct fixed_voltage_config bcm43xx_vmmc = {
36 .supply_name = "bcm43xx-vmmc-regulator",
37 /*
38 * Announce 2.0V here to be compatible with SDIO specification. The
39 * real voltage and signaling are still 1.8V.
40 */
41 .microvolts = 2000000, /* 1.8V */
42 .startup_delay = 250 * 1000, /* 250ms */
43 .enabled_at_boot = 0, /* disabled at boot */
44 .init_data = &bcm43xx_vmmc_data,
45 };
46
47 static struct platform_device bcm43xx_vmmc_regulator = {
48 .name = "reg-fixed-voltage",
49 .id = PLATFORM_DEVID_AUTO,
50 .dev = {
51 .platform_data = &bcm43xx_vmmc,
52 },
53 };
54
55 static struct gpiod_lookup_table bcm43xx_vmmc_gpio_table = {
56 .dev_id = "reg-fixed-voltage.0",
57 .table = {
58 GPIO_LOOKUP("0000:00:0c.0", -1, NULL, GPIO_ACTIVE_LOW),
59 {}
60 },
61 };
62
bcm43xx_regulator_register(void)63 static int __init bcm43xx_regulator_register(void)
64 {
65 struct gpiod_lookup_table *table = &bcm43xx_vmmc_gpio_table;
66 struct gpiod_lookup *lookup = table->table;
67 int ret;
68
69 lookup[0].chip_hwnum = get_gpio_by_name(WLAN_SFI_GPIO_ENABLE_NAME);
70 gpiod_add_lookup_table(table);
71
72 ret = platform_device_register(&bcm43xx_vmmc_regulator);
73 if (ret) {
74 pr_err("%s: vmmc regulator register failed\n", __func__);
75 return ret;
76 }
77
78 return 0;
79 }
80
bcm43xx_platform_data(void * info)81 static void __init *bcm43xx_platform_data(void *info)
82 {
83 int ret;
84
85 ret = bcm43xx_regulator_register();
86 if (ret)
87 return NULL;
88
89 pr_info("Using generic wifi platform data\n");
90
91 /* For now it's empty */
92 return NULL;
93 }
94
95 static const struct devs_id bcm43xx_clk_vmmc_dev_id __initconst = {
96 .name = "bcm43xx_clk_vmmc",
97 .type = SFI_DEV_TYPE_SD,
98 .get_platform_data = &bcm43xx_platform_data,
99 };
100
101 sfi_device(bcm43xx_clk_vmmc_dev_id);
102