Blame view
drivers/mfd/da9052-spi.c
2.37 KB
cfe04478f
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* * SPI access for Dialog DA9052 PMICs. * * Copyright(c) 2011 Dialog Semiconductor Ltd. * * Author: David Dajun Chen <dchen@diasemi.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ #include <linux/device.h> #include <linux/module.h> #include <linux/input.h> #include <linux/mfd/core.h> #include <linux/spi/spi.h> #include <linux/err.h> #include <linux/mfd/da9052/da9052.h> |
f791be492
|
23 |
static int da9052_spi_probe(struct spi_device *spi) |
cfe04478f
|
24 25 26 |
{ int ret; const struct spi_device_id *id = spi_get_device_id(spi); |
6608a5e2d
|
27 |
struct da9052 *da9052; |
cfe04478f
|
28 |
|
6608a5e2d
|
29 |
da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL); |
cfe04478f
|
30 31 32 33 34 35 36 37 38 |
if (!da9052) return -ENOMEM; spi->mode = SPI_MODE_0 | SPI_CPOL; spi->bits_per_word = 8; spi_setup(spi); da9052->dev = &spi->dev; da9052->chip_irq = spi->irq; |
1b1ba09c3
|
39 |
spi_set_drvdata(spi, da9052); |
cfe04478f
|
40 41 42 |
da9052_regmap_config.read_flag_mask = 1; da9052_regmap_config.write_flag_mask = 0; |
6608a5e2d
|
43 |
da9052->regmap = devm_regmap_init_spi(spi, &da9052_regmap_config); |
cfe04478f
|
44 45 46 47 48 |
if (IS_ERR(da9052->regmap)) { ret = PTR_ERR(da9052->regmap); dev_err(&spi->dev, "Failed to allocate register map: %d ", ret); |
6608a5e2d
|
49 |
return ret; |
cfe04478f
|
50 51 52 53 |
} ret = da9052_device_init(da9052, id->driver_data); if (ret != 0) |
6608a5e2d
|
54 |
return ret; |
cfe04478f
|
55 56 |
return 0; |
cfe04478f
|
57 |
} |
4740f73fe
|
58 |
static int da9052_spi_remove(struct spi_device *spi) |
cfe04478f
|
59 |
{ |
1b1ba09c3
|
60 |
struct da9052 *da9052 = spi_get_drvdata(spi); |
cfe04478f
|
61 62 |
da9052_device_exit(da9052); |
cfe04478f
|
63 64 65 66 67 68 69 70 71 72 73 74 75 |
return 0; } static struct spi_device_id da9052_spi_id[] = { {"da9052", DA9052}, {"da9053-aa", DA9053_AA}, {"da9053-ba", DA9053_BA}, {"da9053-bb", DA9053_BB}, {} }; static struct spi_driver da9052_spi_driver = { .probe = da9052_spi_probe, |
84449216b
|
76 |
.remove = da9052_spi_remove, |
cfe04478f
|
77 78 79 |
.id_table = da9052_spi_id, .driver = { .name = "da9052", |
cfe04478f
|
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
.owner = THIS_MODULE, }, }; static int __init da9052_spi_init(void) { int ret; ret = spi_register_driver(&da9052_spi_driver); if (ret != 0) { pr_err("Failed to register DA9052 SPI driver, %d ", ret); return ret; } return 0; } subsys_initcall(da9052_spi_init); static void __exit da9052_spi_exit(void) { spi_unregister_driver(&da9052_spi_driver); } module_exit(da9052_spi_exit); MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC"); MODULE_LICENSE("GPL"); |