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