Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 2 | /* |
| 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 Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 8 | */ |
| 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 Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 19 | static int da9052_spi_probe(struct spi_device *spi) |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 20 | { |
Axel Lin | e9e9d39 | 2014-08-16 21:23:40 +0800 | [diff] [blame] | 21 | struct regmap_config config; |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 22 | int ret; |
| 23 | const struct spi_device_id *id = spi_get_device_id(spi); |
Axel Lin | 6608a5e | 2012-05-11 09:29:51 +0800 | [diff] [blame] | 24 | struct da9052 *da9052; |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 25 | |
Axel Lin | 6608a5e | 2012-05-11 09:29:51 +0800 | [diff] [blame] | 26 | da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 27 | if (!da9052) |
| 28 | return -ENOMEM; |
| 29 | |
Adam Ward | 72e341c | 2015-03-04 16:13:12 +0000 | [diff] [blame] | 30 | spi->mode = SPI_MODE_0; |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 31 | spi->bits_per_word = 8; |
| 32 | spi_setup(spi); |
| 33 | |
| 34 | da9052->dev = &spi->dev; |
| 35 | da9052->chip_irq = spi->irq; |
| 36 | |
Jingoo Han | 1b1ba09 | 2013-04-06 15:43:23 +0900 | [diff] [blame] | 37 | spi_set_drvdata(spi, da9052); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 38 | |
Axel Lin | e9e9d39 | 2014-08-16 21:23:40 +0800 | [diff] [blame] | 39 | config = da9052_regmap_config; |
| 40 | config.read_flag_mask = 1; |
Adam Ward | 72e341c | 2015-03-04 16:13:12 +0000 | [diff] [blame] | 41 | config.reg_bits = 7; |
| 42 | config.pad_bits = 1; |
| 43 | config.val_bits = 8; |
David Frey | 1c96a2f | 2018-09-01 09:50:41 -0700 | [diff] [blame] | 44 | config.use_single_read = true; |
| 45 | config.use_single_write = true; |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 46 | |
Axel Lin | e9e9d39 | 2014-08-16 21:23:40 +0800 | [diff] [blame] | 47 | da9052->regmap = devm_regmap_init_spi(spi, &config); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 48 | 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 Lin | 6608a5e | 2012-05-11 09:29:51 +0800 | [diff] [blame] | 52 | return ret; |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 53 | } |
| 54 | |
Javier Martinez Canillas | ad698ea | 2015-09-29 13:26:07 +0200 | [diff] [blame] | 55 | return da9052_device_init(da9052, id->driver_data); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 56 | } |
| 57 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 58 | static int da9052_spi_remove(struct spi_device *spi) |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 59 | { |
Jingoo Han | 1b1ba09 | 2013-04-06 15:43:23 +0900 | [diff] [blame] | 60 | struct da9052 *da9052 = spi_get_drvdata(spi); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 61 | |
| 62 | da9052_device_exit(da9052); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
Arvind Yadav | 7e1372a | 2017-08-21 23:25:27 +0530 | [diff] [blame] | 66 | static const struct spi_device_id da9052_spi_id[] = { |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 67 | {"da9052", DA9052}, |
| 68 | {"da9053-aa", DA9053_AA}, |
| 69 | {"da9053-ba", DA9053_BA}, |
| 70 | {"da9053-bb", DA9053_BB}, |
Opensource [Anthony Olech] | 6c049b2 | 2014-02-19 16:32:47 +0000 | [diff] [blame] | 71 | {"da9053-bc", DA9053_BC}, |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 72 | {} |
| 73 | }; |
| 74 | |
| 75 | static struct spi_driver da9052_spi_driver = { |
| 76 | .probe = da9052_spi_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 77 | .remove = da9052_spi_remove, |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 78 | .id_table = da9052_spi_id, |
| 79 | .driver = { |
| 80 | .name = "da9052", |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 81 | }, |
| 82 | }; |
| 83 | |
| 84 | static 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 | } |
| 96 | subsys_initcall(da9052_spi_init); |
| 97 | |
| 98 | static void __exit da9052_spi_exit(void) |
| 99 | { |
| 100 | spi_unregister_driver(&da9052_spi_driver); |
| 101 | } |
| 102 | module_exit(da9052_spi_exit); |
| 103 | |
| 104 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |
| 105 | MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC"); |
| 106 | MODULE_LICENSE("GPL"); |