blob: 17666b40b70c624029fc2a95ccebd71b10b685c6 [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{
26 int ret;
27 const struct spi_device_id *id = spi_get_device_id(spi);
Axel Lin6608a5e2012-05-11 09:29:51 +080028 struct da9052 *da9052;
Ashish Jangamcfe04472011-12-12 20:37:41 +053029
Axel Lin6608a5e2012-05-11 09:29:51 +080030 da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
Ashish Jangamcfe04472011-12-12 20:37:41 +053031 if (!da9052)
32 return -ENOMEM;
33
34 spi->mode = SPI_MODE_0 | SPI_CPOL;
35 spi->bits_per_word = 8;
36 spi_setup(spi);
37
38 da9052->dev = &spi->dev;
39 da9052->chip_irq = spi->irq;
40
Jingoo Han1b1ba092013-04-06 15:43:23 +090041 spi_set_drvdata(spi, da9052);
Ashish Jangamcfe04472011-12-12 20:37:41 +053042
43 da9052_regmap_config.read_flag_mask = 1;
44 da9052_regmap_config.write_flag_mask = 0;
45
Axel Lin6608a5e2012-05-11 09:29:51 +080046 da9052->regmap = devm_regmap_init_spi(spi, &da9052_regmap_config);
Ashish Jangamcfe04472011-12-12 20:37:41 +053047 if (IS_ERR(da9052->regmap)) {
48 ret = PTR_ERR(da9052->regmap);
49 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
50 ret);
Axel Lin6608a5e2012-05-11 09:29:51 +080051 return ret;
Ashish Jangamcfe04472011-12-12 20:37:41 +053052 }
53
54 ret = da9052_device_init(da9052, id->driver_data);
55 if (ret != 0)
Axel Lin6608a5e2012-05-11 09:29:51 +080056 return ret;
Ashish Jangamcfe04472011-12-12 20:37:41 +053057
58 return 0;
Ashish Jangamcfe04472011-12-12 20:37:41 +053059}
60
Bill Pemberton4740f732012-11-19 13:26:01 -050061static int da9052_spi_remove(struct spi_device *spi)
Ashish Jangamcfe04472011-12-12 20:37:41 +053062{
Jingoo Han1b1ba092013-04-06 15:43:23 +090063 struct da9052 *da9052 = spi_get_drvdata(spi);
Ashish Jangamcfe04472011-12-12 20:37:41 +053064
65 da9052_device_exit(da9052);
Ashish Jangamcfe04472011-12-12 20:37:41 +053066 return 0;
67}
68
69static struct spi_device_id da9052_spi_id[] = {
70 {"da9052", DA9052},
71 {"da9053-aa", DA9053_AA},
72 {"da9053-ba", DA9053_BA},
73 {"da9053-bb", DA9053_BB},
Opensource [Anthony Olech]6c049b22014-02-19 16:32:47 +000074 {"da9053-bc", DA9053_BC},
Ashish Jangamcfe04472011-12-12 20:37:41 +053075 {}
76};
77
78static struct spi_driver da9052_spi_driver = {
79 .probe = da9052_spi_probe,
Bill Pemberton84449212012-11-19 13:20:24 -050080 .remove = da9052_spi_remove,
Ashish Jangamcfe04472011-12-12 20:37:41 +053081 .id_table = da9052_spi_id,
82 .driver = {
83 .name = "da9052",
Ashish Jangamcfe04472011-12-12 20:37:41 +053084 .owner = THIS_MODULE,
85 },
86};
87
88static int __init da9052_spi_init(void)
89{
90 int ret;
91
92 ret = spi_register_driver(&da9052_spi_driver);
93 if (ret != 0) {
94 pr_err("Failed to register DA9052 SPI driver, %d\n", ret);
95 return ret;
96 }
97
98 return 0;
99}
100subsys_initcall(da9052_spi_init);
101
102static void __exit da9052_spi_exit(void)
103{
104 spi_unregister_driver(&da9052_spi_driver);
105}
106module_exit(da9052_spi_exit);
107
108MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
109MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
110MODULE_LICENSE("GPL");