blob: 5faf3766a5e2082528a62fbcc13d50214e68fae9 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ashish Jangamcfe04472011-12-12 20:37:41 +05302/*
3 * SPI access for Dialog DA9052 PMICs.
4 *
5 * Copyright(c) 2011 Dialog Semiconductor Ltd.
6 *
7 * Author: David Dajun Chen <dchen@diasemi.com>
Ashish Jangamcfe04472011-12-12 20:37:41 +05308 */
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
Bill Pembertonf791be42012-11-19 13:23:04 -050019static int da9052_spi_probe(struct spi_device *spi)
Ashish Jangamcfe04472011-12-12 20:37:41 +053020{
Axel Line9e9d392014-08-16 21:23:40 +080021 struct regmap_config config;
Ashish Jangamcfe04472011-12-12 20:37:41 +053022 int ret;
23 const struct spi_device_id *id = spi_get_device_id(spi);
Axel Lin6608a5e2012-05-11 09:29:51 +080024 struct da9052 *da9052;
Ashish Jangamcfe04472011-12-12 20:37:41 +053025
Axel Lin6608a5e2012-05-11 09:29:51 +080026 da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
Ashish Jangamcfe04472011-12-12 20:37:41 +053027 if (!da9052)
28 return -ENOMEM;
29
Adam Ward72e341c2015-03-04 16:13:12 +000030 spi->mode = SPI_MODE_0;
Ashish Jangamcfe04472011-12-12 20:37:41 +053031 spi->bits_per_word = 8;
32 spi_setup(spi);
33
34 da9052->dev = &spi->dev;
35 da9052->chip_irq = spi->irq;
36
Jingoo Han1b1ba092013-04-06 15:43:23 +090037 spi_set_drvdata(spi, da9052);
Ashish Jangamcfe04472011-12-12 20:37:41 +053038
Axel Line9e9d392014-08-16 21:23:40 +080039 config = da9052_regmap_config;
40 config.read_flag_mask = 1;
Adam Ward72e341c2015-03-04 16:13:12 +000041 config.reg_bits = 7;
42 config.pad_bits = 1;
43 config.val_bits = 8;
David Frey1c96a2f2018-09-01 09:50:41 -070044 config.use_single_read = true;
45 config.use_single_write = true;
Ashish Jangamcfe04472011-12-12 20:37:41 +053046
Axel Line9e9d392014-08-16 21:23:40 +080047 da9052->regmap = devm_regmap_init_spi(spi, &config);
Ashish Jangamcfe04472011-12-12 20:37:41 +053048 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);
Axel Lin6608a5e2012-05-11 09:29:51 +080052 return ret;
Ashish Jangamcfe04472011-12-12 20:37:41 +053053 }
54
Javier Martinez Canillasad698ea2015-09-29 13:26:07 +020055 return da9052_device_init(da9052, id->driver_data);
Ashish Jangamcfe04472011-12-12 20:37:41 +053056}
57
Bill Pemberton4740f732012-11-19 13:26:01 -050058static int da9052_spi_remove(struct spi_device *spi)
Ashish Jangamcfe04472011-12-12 20:37:41 +053059{
Jingoo Han1b1ba092013-04-06 15:43:23 +090060 struct da9052 *da9052 = spi_get_drvdata(spi);
Ashish Jangamcfe04472011-12-12 20:37:41 +053061
62 da9052_device_exit(da9052);
Ashish Jangamcfe04472011-12-12 20:37:41 +053063 return 0;
64}
65
Arvind Yadav7e1372a2017-08-21 23:25:27 +053066static const struct spi_device_id da9052_spi_id[] = {
Ashish Jangamcfe04472011-12-12 20:37:41 +053067 {"da9052", DA9052},
68 {"da9053-aa", DA9053_AA},
69 {"da9053-ba", DA9053_BA},
70 {"da9053-bb", DA9053_BB},
Opensource [Anthony Olech]6c049b22014-02-19 16:32:47 +000071 {"da9053-bc", DA9053_BC},
Ashish Jangamcfe04472011-12-12 20:37:41 +053072 {}
73};
74
75static struct spi_driver da9052_spi_driver = {
76 .probe = da9052_spi_probe,
Bill Pemberton84449212012-11-19 13:20:24 -050077 .remove = da9052_spi_remove,
Ashish Jangamcfe04472011-12-12 20:37:41 +053078 .id_table = da9052_spi_id,
79 .driver = {
80 .name = "da9052",
Ashish Jangamcfe04472011-12-12 20:37:41 +053081 },
82};
83
84static 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}
96subsys_initcall(da9052_spi_init);
97
98static void __exit da9052_spi_exit(void)
99{
100 spi_unregister_driver(&da9052_spi_driver);
101}
102module_exit(da9052_spi_exit);
103
104MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
105MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
106MODULE_LICENSE("GPL");