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 | |
Axel Lin | e536b62 | 2012-01-11 17:27:16 +0800 | [diff] [blame] | 24 | static int __devinit da9052_spi_probe(struct spi_device *spi) |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 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) |
Axel Lin | 4d75dd6 | 2012-01-10 15:09:56 +0800 | [diff] [blame] | 55 | goto err_regmap; |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | |
Axel Lin | 4d75dd6 | 2012-01-10 15:09:56 +0800 | [diff] [blame] | 59 | err_regmap: |
| 60 | regmap_exit(da9052->regmap); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 61 | err: |
| 62 | kfree(da9052); |
| 63 | return ret; |
| 64 | } |
| 65 | |
Axel Lin | e536b62 | 2012-01-11 17:27:16 +0800 | [diff] [blame] | 66 | static int __devexit da9052_spi_remove(struct spi_device *spi) |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 67 | { |
| 68 | struct da9052 *da9052 = dev_get_drvdata(&spi->dev); |
| 69 | |
| 70 | da9052_device_exit(da9052); |
Axel Lin | 4d75dd6 | 2012-01-10 15:09:56 +0800 | [diff] [blame] | 71 | regmap_exit(da9052->regmap); |
Ashish Jangam | cfe0447 | 2011-12-12 20:37:41 +0530 | [diff] [blame] | 72 | kfree(da9052); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static struct spi_device_id da9052_spi_id[] = { |
| 78 | {"da9052", DA9052}, |
| 79 | {"da9053-aa", DA9053_AA}, |
| 80 | {"da9053-ba", DA9053_BA}, |
| 81 | {"da9053-bb", DA9053_BB}, |
| 82 | {} |
| 83 | }; |
| 84 | |
| 85 | static struct spi_driver da9052_spi_driver = { |
| 86 | .probe = da9052_spi_probe, |
| 87 | .remove = __devexit_p(da9052_spi_remove), |
| 88 | .id_table = da9052_spi_id, |
| 89 | .driver = { |
| 90 | .name = "da9052", |
| 91 | .bus = &spi_bus_type, |
| 92 | .owner = THIS_MODULE, |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | static int __init da9052_spi_init(void) |
| 97 | { |
| 98 | int ret; |
| 99 | |
| 100 | ret = spi_register_driver(&da9052_spi_driver); |
| 101 | if (ret != 0) { |
| 102 | pr_err("Failed to register DA9052 SPI driver, %d\n", ret); |
| 103 | return ret; |
| 104 | } |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | subsys_initcall(da9052_spi_init); |
| 109 | |
| 110 | static void __exit da9052_spi_exit(void) |
| 111 | { |
| 112 | spi_unregister_driver(&da9052_spi_driver); |
| 113 | } |
| 114 | module_exit(da9052_spi_exit); |
| 115 | |
| 116 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |
| 117 | MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC"); |
| 118 | MODULE_LICENSE("GPL"); |