blob: b5de8a6856c0de07f29c10dbeaa4de67c0ac4617 [file] [log] [blame]
Ashish Jangamcfe04472011-12-12 20:37:41 +05301/*
2 * SPI access for Dialog DA9052 PMICs.
3 *
4 * Copyright(c) 2011 Dialog Semiconductor Ltd.
5 *
6 * Author: David Dajun Chen <dchen@diasemi.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 */
14
15#include <linux/device.h>
16#include <linux/module.h>
17#include <linux/input.h>
18#include <linux/mfd/core.h>
19#include <linux/spi/spi.h>
20#include <linux/err.h>
21
22#include <linux/mfd/da9052/da9052.h>
23
Bill Pembertonf791be42012-11-19 13:23:04 -050024static int da9052_spi_probe(struct spi_device *spi)
Ashish Jangamcfe04472011-12-12 20:37:41 +053025{
Axel Line9e9d392014-08-16 21:23:40 +080026 struct regmap_config config;
Ashish Jangamcfe04472011-12-12 20:37:41 +053027 int ret;
28 const struct spi_device_id *id = spi_get_device_id(spi);
Axel Lin6608a5e2012-05-11 09:29:51 +080029 struct da9052 *da9052;
Ashish Jangamcfe04472011-12-12 20:37:41 +053030
Axel Lin6608a5e2012-05-11 09:29:51 +080031 da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
Ashish Jangamcfe04472011-12-12 20:37:41 +053032 if (!da9052)
33 return -ENOMEM;
34
Adam Ward72e341c2015-03-04 16:13:12 +000035 spi->mode = SPI_MODE_0;
Ashish Jangamcfe04472011-12-12 20:37:41 +053036 spi->bits_per_word = 8;
37 spi_setup(spi);
38
39 da9052->dev = &spi->dev;
40 da9052->chip_irq = spi->irq;
41
Jingoo Han1b1ba092013-04-06 15:43:23 +090042 spi_set_drvdata(spi, da9052);
Ashish Jangamcfe04472011-12-12 20:37:41 +053043
Axel Line9e9d392014-08-16 21:23:40 +080044 config = da9052_regmap_config;
45 config.read_flag_mask = 1;
Adam Ward72e341c2015-03-04 16:13:12 +000046 config.reg_bits = 7;
47 config.pad_bits = 1;
48 config.val_bits = 8;
49 config.use_single_rw = 1;
Ashish Jangamcfe04472011-12-12 20:37:41 +053050
Axel Line9e9d392014-08-16 21:23:40 +080051 da9052->regmap = devm_regmap_init_spi(spi, &config);
Ashish Jangamcfe04472011-12-12 20:37:41 +053052 if (IS_ERR(da9052->regmap)) {
53 ret = PTR_ERR(da9052->regmap);
54 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
55 ret);
Axel Lin6608a5e2012-05-11 09:29:51 +080056 return ret;
Ashish Jangamcfe04472011-12-12 20:37:41 +053057 }
58
59 ret = da9052_device_init(da9052, id->driver_data);
60 if (ret != 0)
Axel Lin6608a5e2012-05-11 09:29:51 +080061 return ret;
Ashish Jangamcfe04472011-12-12 20:37:41 +053062
63 return 0;
Ashish Jangamcfe04472011-12-12 20:37:41 +053064}
65
Bill Pemberton4740f732012-11-19 13:26:01 -050066static int da9052_spi_remove(struct spi_device *spi)
Ashish Jangamcfe04472011-12-12 20:37:41 +053067{
Jingoo Han1b1ba092013-04-06 15:43:23 +090068 struct da9052 *da9052 = spi_get_drvdata(spi);
Ashish Jangamcfe04472011-12-12 20:37:41 +053069
70 da9052_device_exit(da9052);
Ashish Jangamcfe04472011-12-12 20:37:41 +053071 return 0;
72}
73
74static struct spi_device_id da9052_spi_id[] = {
75 {"da9052", DA9052},
76 {"da9053-aa", DA9053_AA},
77 {"da9053-ba", DA9053_BA},
78 {"da9053-bb", DA9053_BB},
Opensource [Anthony Olech]6c049b22014-02-19 16:32:47 +000079 {"da9053-bc", DA9053_BC},
Ashish Jangamcfe04472011-12-12 20:37:41 +053080 {}
81};
82
83static struct spi_driver da9052_spi_driver = {
84 .probe = da9052_spi_probe,
Bill Pemberton84449212012-11-19 13:20:24 -050085 .remove = da9052_spi_remove,
Ashish Jangamcfe04472011-12-12 20:37:41 +053086 .id_table = da9052_spi_id,
87 .driver = {
88 .name = "da9052",
Ashish Jangamcfe04472011-12-12 20:37:41 +053089 .owner = THIS_MODULE,
90 },
91};
92
93static int __init da9052_spi_init(void)
94{
95 int ret;
96
97 ret = spi_register_driver(&da9052_spi_driver);
98 if (ret != 0) {
99 pr_err("Failed to register DA9052 SPI driver, %d\n", ret);
100 return ret;
101 }
102
103 return 0;
104}
105subsys_initcall(da9052_spi_init);
106
107static void __exit da9052_spi_exit(void)
108{
109 spi_unregister_driver(&da9052_spi_driver);
110}
111module_exit(da9052_spi_exit);
112
113MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
114MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
115MODULE_LICENSE("GPL");