net: DCB: Validate DCB_ATTR_DCB_BUFFER argument
[linux/fpc-iii.git] / drivers / mfd / da9052-spi.c
blob5faf3766a5e2082528a62fbcc13d50214e68fae9
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * SPI access for Dialog DA9052 PMICs.
5 * Copyright(c) 2011 Dialog Semiconductor Ltd.
7 * Author: David Dajun Chen <dchen@diasemi.com>
8 */
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>
17 #include <linux/mfd/da9052/da9052.h>
19 static int da9052_spi_probe(struct spi_device *spi)
21 struct regmap_config config;
22 int ret;
23 const struct spi_device_id *id = spi_get_device_id(spi);
24 struct da9052 *da9052;
26 da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
27 if (!da9052)
28 return -ENOMEM;
30 spi->mode = SPI_MODE_0;
31 spi->bits_per_word = 8;
32 spi_setup(spi);
34 da9052->dev = &spi->dev;
35 da9052->chip_irq = spi->irq;
37 spi_set_drvdata(spi, da9052);
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;
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;
55 return da9052_device_init(da9052, id->driver_data);
58 static int da9052_spi_remove(struct spi_device *spi)
60 struct da9052 *da9052 = spi_get_drvdata(spi);
62 da9052_device_exit(da9052);
63 return 0;
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},
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",
84 static int __init da9052_spi_init(void)
86 int ret;
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;
94 return 0;
96 subsys_initcall(da9052_spi_init);
98 static void __exit da9052_spi_exit(void)
100 spi_unregister_driver(&da9052_spi_driver);
102 module_exit(da9052_spi_exit);
104 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
105 MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
106 MODULE_LICENSE("GPL");