1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SPI access for Dialog DA9052 PMICs.
5 * Copyright(c) 2011 Dialog Semiconductor Ltd.
7 * Author: David Dajun Chen <dchen@diasemi.com>
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;
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);
30 spi->mode = SPI_MODE_0;
31 spi->bits_per_word = 8;
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;
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",
55 return da9052_device_init(da9052, id->driver_data);
58 static void da9052_spi_remove(struct spi_device *spi)
60 struct da9052 *da9052 = spi_get_drvdata(spi);
62 da9052_device_exit(da9052);
65 static const struct spi_device_id da9052_spi_id[] = {
67 {"da9053-aa", DA9053_AA},
68 {"da9053-ba", DA9053_BA},
69 {"da9053-bb", DA9053_BB},
70 {"da9053-bc", DA9053_BC},
74 static struct spi_driver da9052_spi_driver = {
75 .probe = da9052_spi_probe,
76 .remove = da9052_spi_remove,
77 .id_table = da9052_spi_id,
83 static int __init da9052_spi_init(void)
87 ret = spi_register_driver(&da9052_spi_driver);
89 pr_err("Failed to register DA9052 SPI driver, %d\n", ret);
95 subsys_initcall(da9052_spi_init);
97 static void __exit da9052_spi_exit(void)
99 spi_unregister_driver(&da9052_spi_driver);
101 module_exit(da9052_spi_exit);
103 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
104 MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
105 MODULE_LICENSE("GPL");