treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441
[linux-block.git] / arch / x86 / platform / intel-mid / device_libs / platform_bt.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Bluetooth platform data initialization file
4  *
5  * (C) Copyright 2017 Intel Corporation
6  * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
7  */
8
9 #include <linux/gpio/machine.h>
10 #include <linux/pci.h>
11 #include <linux/platform_device.h>
12
13 #include <asm/cpu_device_id.h>
14 #include <asm/intel-family.h>
15 #include <asm/intel-mid.h>
16
17 struct bt_sfi_data {
18         struct device *dev;
19         const char *name;
20         int (*setup)(struct bt_sfi_data *ddata);
21 };
22
23 static struct gpiod_lookup_table tng_bt_sfi_gpio_table = {
24         .dev_id = "hci_bcm",
25         .table  = {
26                 GPIO_LOOKUP("0000:00:0c.0", -1, "device-wakeup", GPIO_ACTIVE_HIGH),
27                 GPIO_LOOKUP("0000:00:0c.0", -1, "shutdown",      GPIO_ACTIVE_HIGH),
28                 GPIO_LOOKUP("0000:00:0c.0", -1, "host-wakeup",   GPIO_ACTIVE_HIGH),
29                 { },
30         },
31 };
32
33 #define TNG_BT_SFI_GPIO_DEVICE_WAKEUP   "bt_wakeup"
34 #define TNG_BT_SFI_GPIO_SHUTDOWN        "BT-reset"
35 #define TNG_BT_SFI_GPIO_HOST_WAKEUP     "bt_uart_enable"
36
37 static int __init tng_bt_sfi_setup(struct bt_sfi_data *ddata)
38 {
39         struct gpiod_lookup_table *table = &tng_bt_sfi_gpio_table;
40         struct gpiod_lookup *lookup = table->table;
41         struct pci_dev *pdev;
42
43         /* Connected to /dev/ttyS0 */
44         pdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(4, 1));
45         if (!pdev)
46                 return -ENODEV;
47
48         ddata->dev = &pdev->dev;
49         ddata->name = table->dev_id;
50
51         lookup[0].chip_hwnum = get_gpio_by_name(TNG_BT_SFI_GPIO_DEVICE_WAKEUP);
52         lookup[1].chip_hwnum = get_gpio_by_name(TNG_BT_SFI_GPIO_SHUTDOWN);
53         lookup[2].chip_hwnum = get_gpio_by_name(TNG_BT_SFI_GPIO_HOST_WAKEUP);
54
55         gpiod_add_lookup_table(table);
56         return 0;
57 }
58
59 static struct bt_sfi_data tng_bt_sfi_data __initdata = {
60         .setup  = tng_bt_sfi_setup,
61 };
62
63 #define ICPU(model, ddata)      \
64         { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata }
65
66 static const struct x86_cpu_id bt_sfi_cpu_ids[] = {
67         ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID, tng_bt_sfi_data),
68         {}
69 };
70
71 static int __init bt_sfi_init(void)
72 {
73         struct platform_device_info info;
74         struct platform_device *pdev;
75         const struct x86_cpu_id *id;
76         struct bt_sfi_data *ddata;
77         int ret;
78
79         id = x86_match_cpu(bt_sfi_cpu_ids);
80         if (!id)
81                 return -ENODEV;
82
83         ddata = (struct bt_sfi_data *)id->driver_data;
84         if (!ddata)
85                 return -ENODEV;
86
87         ret = ddata->setup(ddata);
88         if (ret)
89                 return ret;
90
91         memset(&info, 0, sizeof(info));
92         info.fwnode     = ddata->dev->fwnode;
93         info.parent     = ddata->dev;
94         info.name       = ddata->name,
95         info.id         = PLATFORM_DEVID_NONE,
96
97         pdev = platform_device_register_full(&info);
98         if (IS_ERR(pdev))
99                 return PTR_ERR(pdev);
100
101         dev_info(ddata->dev, "Registered Bluetooth device: %s\n", ddata->name);
102         return 0;
103 }
104 device_initcall(bt_sfi_init);