]>
Commit | Line | Data |
---|---|---|
cfe04478 AJ |
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 | ||
f791be49 | 24 | static int da9052_spi_probe(struct spi_device *spi) |
cfe04478 AJ |
25 | { |
26 | int ret; | |
27 | const struct spi_device_id *id = spi_get_device_id(spi); | |
6608a5e2 | 28 | struct da9052 *da9052; |
cfe04478 | 29 | |
6608a5e2 | 30 | da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL); |
cfe04478 AJ |
31 | 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 | ||
41 | dev_set_drvdata(&spi->dev, da9052); | |
42 | ||
43 | da9052_regmap_config.read_flag_mask = 1; | |
44 | da9052_regmap_config.write_flag_mask = 0; | |
45 | ||
6608a5e2 | 46 | da9052->regmap = devm_regmap_init_spi(spi, &da9052_regmap_config); |
cfe04478 AJ |
47 | 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); | |
6608a5e2 | 51 | return ret; |
cfe04478 AJ |
52 | } |
53 | ||
54 | ret = da9052_device_init(da9052, id->driver_data); | |
55 | if (ret != 0) | |
6608a5e2 | 56 | return ret; |
cfe04478 AJ |
57 | |
58 | return 0; | |
cfe04478 AJ |
59 | } |
60 | ||
4740f73f | 61 | static int da9052_spi_remove(struct spi_device *spi) |
cfe04478 AJ |
62 | { |
63 | struct da9052 *da9052 = dev_get_drvdata(&spi->dev); | |
64 | ||
65 | da9052_device_exit(da9052); | |
cfe04478 AJ |
66 | return 0; |
67 | } | |
68 | ||
69 | static 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}, | |
74 | {} | |
75 | }; | |
76 | ||
77 | static struct spi_driver da9052_spi_driver = { | |
78 | .probe = da9052_spi_probe, | |
84449216 | 79 | .remove = da9052_spi_remove, |
cfe04478 AJ |
80 | .id_table = da9052_spi_id, |
81 | .driver = { | |
82 | .name = "da9052", | |
cfe04478 AJ |
83 | .owner = THIS_MODULE, |
84 | }, | |
85 | }; | |
86 | ||
87 | static int __init da9052_spi_init(void) | |
88 | { | |
89 | int ret; | |
90 | ||
91 | ret = spi_register_driver(&da9052_spi_driver); | |
92 | if (ret != 0) { | |
93 | pr_err("Failed to register DA9052 SPI driver, %d\n", ret); | |
94 | return ret; | |
95 | } | |
96 | ||
97 | return 0; | |
98 | } | |
99 | subsys_initcall(da9052_spi_init); | |
100 | ||
101 | static void __exit da9052_spi_exit(void) | |
102 | { | |
103 | spi_unregister_driver(&da9052_spi_driver); | |
104 | } | |
105 | module_exit(da9052_spi_exit); | |
106 | ||
107 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); | |
108 | MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC"); | |
109 | MODULE_LICENSE("GPL"); |