diff options
-rw-r--r-- | drivers/mfd/Kconfig | 12 | ||||
-rw-r--r-- | drivers/mfd/Makefile | 1 | ||||
-rw-r--r-- | drivers/mfd/da9052-spi.c | 115 |
3 files changed, 128 insertions, 0 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index baced42c8572..c8322eefc865 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -332,6 +332,18 @@ config PMIC_DA9052 | |||
332 | bool | 332 | bool |
333 | select MFD_CORE | 333 | select MFD_CORE |
334 | 334 | ||
335 | config MFD_DA9052_SPI | ||
336 | bool "Support Dialog Semiconductor DA9052/53 PMIC variants with SPI" | ||
337 | select REGMAP_SPI | ||
338 | select REGMAP_IRQ | ||
339 | select PMIC_DA9052 | ||
340 | depends on SPI_MASTER=y | ||
341 | help | ||
342 | Support for the Dialog Semiconductor DA9052 PMIC | ||
343 | when controlled using SPI. This driver provides common support | ||
344 | for accessing the device, additional drivers must be enabled in | ||
345 | order to use the functionality of the device. | ||
346 | |||
335 | config MFD_DA9052_I2C | 347 | config MFD_DA9052_I2C |
336 | bool "Support Dialog Semiconductor DA9052/53 PMIC variants with I2C" | 348 | bool "Support Dialog Semiconductor DA9052/53 PMIC variants with I2C" |
337 | select REGMAP_I2C | 349 | select REGMAP_I2C |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 484f209f41e4..d5f574306c7f 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -69,6 +69,7 @@ obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o | |||
69 | obj-$(CONFIG_PMIC_DA903X) += da903x.o | 69 | obj-$(CONFIG_PMIC_DA903X) += da903x.o |
70 | 70 | ||
71 | obj-$(CONFIG_PMIC_DA9052) += da9052-core.o | 71 | obj-$(CONFIG_PMIC_DA9052) += da9052-core.o |
72 | obj-$(CONFIG_MFD_DA9052_SPI) += da9052-spi.o | ||
72 | obj-$(CONFIG_MFD_DA9052_I2C) += da9052-i2c.o | 73 | obj-$(CONFIG_MFD_DA9052_I2C) += da9052-i2c.o |
73 | 74 | ||
74 | max8925-objs := max8925-core.o max8925-i2c.o | 75 | max8925-objs := max8925-core.o max8925-i2c.o |
diff --git a/drivers/mfd/da9052-spi.c b/drivers/mfd/da9052-spi.c new file mode 100644 index 000000000000..cdbc7cad326f --- /dev/null +++ b/drivers/mfd/da9052-spi.c | |||
@@ -0,0 +1,115 @@ | |||
1 | /* | ||
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 | |||
24 | static int da9052_spi_probe(struct spi_device *spi) | ||
25 | { | ||
26 | int ret; | ||
27 | const struct spi_device_id *id = spi_get_device_id(spi); | ||
28 | struct da9052 *da9052 = kzalloc(sizeof(struct da9052), GFP_KERNEL); | ||
29 | |||
30 | if (!da9052) | ||
31 | return -ENOMEM; | ||
32 | |||
33 | spi->mode = SPI_MODE_0 | SPI_CPOL; | ||
34 | spi->bits_per_word = 8; | ||
35 | spi_setup(spi); | ||
36 | |||
37 | da9052->dev = &spi->dev; | ||
38 | da9052->chip_irq = spi->irq; | ||
39 | |||
40 | dev_set_drvdata(&spi->dev, da9052); | ||
41 | |||
42 | da9052_regmap_config.read_flag_mask = 1; | ||
43 | da9052_regmap_config.write_flag_mask = 0; | ||
44 | |||
45 | da9052->regmap = regmap_init_spi(spi, &da9052_regmap_config); | ||
46 | if (IS_ERR(da9052->regmap)) { | ||
47 | ret = PTR_ERR(da9052->regmap); | ||
48 | dev_err(&spi->dev, "Failed to allocate register map: %d\n", | ||
49 | ret); | ||
50 | goto err; | ||
51 | } | ||
52 | |||
53 | ret = da9052_device_init(da9052, id->driver_data); | ||
54 | if (ret != 0) | ||
55 | goto err; | ||
56 | |||
57 | return 0; | ||
58 | |||
59 | err: | ||
60 | kfree(da9052); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | static int da9052_spi_remove(struct spi_device *spi) | ||
65 | { | ||
66 | struct da9052 *da9052 = dev_get_drvdata(&spi->dev); | ||
67 | |||
68 | da9052_device_exit(da9052); | ||
69 | kfree(da9052); | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static 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}, | ||
79 | {} | ||
80 | }; | ||
81 | |||
82 | static struct spi_driver da9052_spi_driver = { | ||
83 | .probe = da9052_spi_probe, | ||
84 | .remove = __devexit_p(da9052_spi_remove), | ||
85 | .id_table = da9052_spi_id, | ||
86 | .driver = { | ||
87 | .name = "da9052", | ||
88 | .bus = &spi_bus_type, | ||
89 | .owner = THIS_MODULE, | ||
90 | }, | ||
91 | }; | ||
92 | |||
93 | static 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 | } | ||
105 | subsys_initcall(da9052_spi_init); | ||
106 | |||
107 | static void __exit da9052_spi_exit(void) | ||
108 | { | ||
109 | spi_unregister_driver(&da9052_spi_driver); | ||
110 | } | ||
111 | module_exit(da9052_spi_exit); | ||
112 | |||
113 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); | ||
114 | MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC"); | ||
115 | MODULE_LICENSE("GPL"); | ||