xref: /OK3568_Linux_fs/kernel/drivers/mfd/tps65912-spi.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * SPI access driver for TI TPS65912x PMICs
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
5*4882a593Smuzhiyun  *	Andrew F. Davis <afd@ti.com>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or
8*4882a593Smuzhiyun  * modify it under the terms of the GNU General Public License version 2 as
9*4882a593Smuzhiyun  * published by the Free Software Foundation.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12*4882a593Smuzhiyun  * kind, whether expressed or implied; without even the implied warranty
13*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*4882a593Smuzhiyun  * GNU General Public License version 2 for more details.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * Based on the TPS65218 driver and the previous TPS65912 driver by
17*4882a593Smuzhiyun  * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/module.h>
21*4882a593Smuzhiyun #include <linux/regmap.h>
22*4882a593Smuzhiyun #include <linux/spi/spi.h>
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #include <linux/mfd/tps65912.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun static const struct of_device_id tps65912_spi_of_match_table[] = {
27*4882a593Smuzhiyun 	{ .compatible = "ti,tps65912", },
28*4882a593Smuzhiyun 	{ /* sentinel */ }
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, tps65912_spi_of_match_table);
31*4882a593Smuzhiyun 
tps65912_spi_probe(struct spi_device * spi)32*4882a593Smuzhiyun static int tps65912_spi_probe(struct spi_device *spi)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	struct tps65912 *tps;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	tps = devm_kzalloc(&spi->dev, sizeof(*tps), GFP_KERNEL);
37*4882a593Smuzhiyun 	if (!tps)
38*4882a593Smuzhiyun 		return -ENOMEM;
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 	spi_set_drvdata(spi, tps);
41*4882a593Smuzhiyun 	tps->dev = &spi->dev;
42*4882a593Smuzhiyun 	tps->irq = spi->irq;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	tps->regmap = devm_regmap_init_spi(spi, &tps65912_regmap_config);
45*4882a593Smuzhiyun 	if (IS_ERR(tps->regmap)) {
46*4882a593Smuzhiyun 		dev_err(tps->dev, "Failed to initialize register map\n");
47*4882a593Smuzhiyun 		return PTR_ERR(tps->regmap);
48*4882a593Smuzhiyun 	}
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	return tps65912_device_init(tps);
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
tps65912_spi_remove(struct spi_device * spi)53*4882a593Smuzhiyun static int tps65912_spi_remove(struct spi_device *spi)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	struct tps65912 *tps = spi_get_drvdata(spi);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	return tps65912_device_exit(tps);
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun static const struct spi_device_id tps65912_spi_id_table[] = {
61*4882a593Smuzhiyun 	{ "tps65912", 0 },
62*4882a593Smuzhiyun 	{ /* sentinel */ }
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun MODULE_DEVICE_TABLE(spi, tps65912_spi_id_table);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun static struct spi_driver tps65912_spi_driver = {
67*4882a593Smuzhiyun 	.driver		= {
68*4882a593Smuzhiyun 		.name	= "tps65912",
69*4882a593Smuzhiyun 		.of_match_table = tps65912_spi_of_match_table,
70*4882a593Smuzhiyun 	},
71*4882a593Smuzhiyun 	.probe		= tps65912_spi_probe,
72*4882a593Smuzhiyun 	.remove		= tps65912_spi_remove,
73*4882a593Smuzhiyun 	.id_table       = tps65912_spi_id_table,
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun module_spi_driver(tps65912_spi_driver);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
78*4882a593Smuzhiyun MODULE_DESCRIPTION("TPS65912x SPI Interface Driver");
79*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
80