Blame view

drivers/mfd/da9052-spi.c 2.24 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
2
3
4
5
6
7
  /*
   * SPI access for Dialog DA9052 PMICs.
   *
   * Copyright(c) 2011 Dialog Semiconductor Ltd.
   *
   * Author: David Dajun Chen <dchen@diasemi.com>
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
8
9
10
11
12
13
14
15
16
17
   */
  
  #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   Bill Pemberton   mfd: remove use o...
18
  static int da9052_spi_probe(struct spi_device *spi)
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
19
  {
e9e9d3973   Axel Lin   mfd: da9052: Avoi...
20
  	struct regmap_config config;
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
21
22
  	int ret;
  	const struct spi_device_id *id = spi_get_device_id(spi);
6608a5e2d   Axel Lin   mfd: Convert da90...
23
  	struct da9052 *da9052;
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
24

6608a5e2d   Axel Lin   mfd: Convert da90...
25
  	da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
26
27
  	if (!da9052)
  		return -ENOMEM;
72e341c48   Adam Ward   mfd: da9052: Fix ...
28
  	spi->mode = SPI_MODE_0;
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
29
30
31
32
33
  	spi->bits_per_word = 8;
  	spi_setup(spi);
  
  	da9052->dev = &spi->dev;
  	da9052->chip_irq = spi->irq;
1b1ba09c3   Jingoo Han   mfd: da9052: Use ...
34
  	spi_set_drvdata(spi, da9052);
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
35

e9e9d3973   Axel Lin   mfd: da9052: Avoi...
36
37
  	config = da9052_regmap_config;
  	config.read_flag_mask = 1;
72e341c48   Adam Ward   mfd: da9052: Fix ...
38
39
40
  	config.reg_bits = 7;
  	config.pad_bits = 1;
  	config.val_bits = 8;
1c96a2f67   David Frey   regmap: split up ...
41
42
  	config.use_single_read = true;
  	config.use_single_write = true;
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
43

e9e9d3973   Axel Lin   mfd: da9052: Avoi...
44
  	da9052->regmap = devm_regmap_init_spi(spi, &config);
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
45
46
47
48
49
  	if (IS_ERR(da9052->regmap)) {
  		ret = PTR_ERR(da9052->regmap);
  		dev_err(&spi->dev, "Failed to allocate register map: %d
  ",
  			ret);
6608a5e2d   Axel Lin   mfd: Convert da90...
50
  		return ret;
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
51
  	}
ad698ea42   Javier Martinez Canillas   mfd: da9052: Simp...
52
  	return da9052_device_init(da9052, id->driver_data);
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
53
  }
4740f73fe   Bill Pemberton   mfd: remove use o...
54
  static int da9052_spi_remove(struct spi_device *spi)
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
55
  {
1b1ba09c3   Jingoo Han   mfd: da9052: Use ...
56
  	struct da9052 *da9052 = spi_get_drvdata(spi);
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
57
58
  
  	da9052_device_exit(da9052);
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
59
60
  	return 0;
  }
7e1372a4c   Arvind Yadav   mfd: da9052: Cons...
61
  static const struct spi_device_id da9052_spi_id[] = {
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
62
63
64
65
  	{"da9052", DA9052},
  	{"da9053-aa", DA9053_AA},
  	{"da9053-ba", DA9053_BA},
  	{"da9053-bb", DA9053_BB},
6c049b2ac   Opensource [Anthony Olech]   mfd: da9052: Add ...
66
  	{"da9053-bc", DA9053_BC},
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
67
68
69
70
71
  	{}
  };
  
  static struct spi_driver da9052_spi_driver = {
  	.probe = da9052_spi_probe,
84449216b   Bill Pemberton   mfd: remove use o...
72
  	.remove = da9052_spi_remove,
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
73
74
75
  	.id_table = da9052_spi_id,
  	.driver = {
  		.name = "da9052",
cfe04478f   Ashish Jangam   MFD: DA9052/53 MF...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  	},
  };
  
  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");