ACPI: scan: Make acpi_bus_get_device() clear return pointer on error
[platform/kernel/linux-rpi.git] / drivers / mfd / da9052-spi.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * SPI access for Dialog DA9052 PMICs.
4  *
5  * Copyright(c) 2011 Dialog Semiconductor Ltd.
6  *
7  * Author: David Dajun Chen <dchen@diasemi.com>
8  */
9
10 #include <linux/device.h>
11 #include <linux/module.h>
12 #include <linux/input.h>
13 #include <linux/mfd/core.h>
14 #include <linux/spi/spi.h>
15 #include <linux/err.h>
16
17 #include <linux/mfd/da9052/da9052.h>
18
19 static int da9052_spi_probe(struct spi_device *spi)
20 {
21         struct regmap_config config;
22         int ret;
23         const struct spi_device_id *id = spi_get_device_id(spi);
24         struct da9052 *da9052;
25
26         da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
27         if (!da9052)
28                 return -ENOMEM;
29
30         spi->mode = SPI_MODE_0;
31         spi->bits_per_word = 8;
32         spi_setup(spi);
33
34         da9052->dev = &spi->dev;
35         da9052->chip_irq = spi->irq;
36
37         spi_set_drvdata(spi, da9052);
38
39         config = da9052_regmap_config;
40         config.read_flag_mask = 1;
41         config.reg_bits = 7;
42         config.pad_bits = 1;
43         config.val_bits = 8;
44         config.use_single_read = true;
45         config.use_single_write = true;
46
47         da9052->regmap = devm_regmap_init_spi(spi, &config);
48         if (IS_ERR(da9052->regmap)) {
49                 ret = PTR_ERR(da9052->regmap);
50                 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
51                         ret);
52                 return ret;
53         }
54
55         return da9052_device_init(da9052, id->driver_data);
56 }
57
58 static int da9052_spi_remove(struct spi_device *spi)
59 {
60         struct da9052 *da9052 = spi_get_drvdata(spi);
61
62         da9052_device_exit(da9052);
63         return 0;
64 }
65
66 static const struct spi_device_id da9052_spi_id[] = {
67         {"da9052", DA9052},
68         {"da9053-aa", DA9053_AA},
69         {"da9053-ba", DA9053_BA},
70         {"da9053-bb", DA9053_BB},
71         {"da9053-bc", DA9053_BC},
72         {}
73 };
74
75 static struct spi_driver da9052_spi_driver = {
76         .probe = da9052_spi_probe,
77         .remove = da9052_spi_remove,
78         .id_table = da9052_spi_id,
79         .driver = {
80                 .name = "da9052",
81         },
82 };
83
84 static int __init da9052_spi_init(void)
85 {
86         int ret;
87
88         ret = spi_register_driver(&da9052_spi_driver);
89         if (ret != 0) {
90                 pr_err("Failed to register DA9052 SPI driver, %d\n", ret);
91                 return ret;
92         }
93
94         return 0;
95 }
96 subsys_initcall(da9052_spi_init);
97
98 static void __exit da9052_spi_exit(void)
99 {
100         spi_unregister_driver(&da9052_spi_driver);
101 }
102 module_exit(da9052_spi_exit);
103
104 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
105 MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
106 MODULE_LICENSE("GPL");