2011-12-12 15:07:41 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2012-11-19 18:23:04 +00:00
|
|
|
static int da9052_spi_probe(struct spi_device *spi)
|
2011-12-12 15:07:41 +00:00
|
|
|
{
|
2014-08-16 13:23:40 +00:00
|
|
|
struct regmap_config config;
|
2011-12-12 15:07:41 +00:00
|
|
|
int ret;
|
|
|
|
const struct spi_device_id *id = spi_get_device_id(spi);
|
2012-05-11 01:29:51 +00:00
|
|
|
struct da9052 *da9052;
|
2011-12-12 15:07:41 +00:00
|
|
|
|
2012-05-11 01:29:51 +00:00
|
|
|
da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
|
2011-12-12 15:07:41 +00:00
|
|
|
if (!da9052)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-03-04 16:13:12 +00:00
|
|
|
spi->mode = SPI_MODE_0;
|
2011-12-12 15:07:41 +00:00
|
|
|
spi->bits_per_word = 8;
|
|
|
|
spi_setup(spi);
|
|
|
|
|
|
|
|
da9052->dev = &spi->dev;
|
|
|
|
da9052->chip_irq = spi->irq;
|
|
|
|
|
2013-04-06 06:43:23 +00:00
|
|
|
spi_set_drvdata(spi, da9052);
|
2011-12-12 15:07:41 +00:00
|
|
|
|
2014-08-16 13:23:40 +00:00
|
|
|
config = da9052_regmap_config;
|
|
|
|
config.read_flag_mask = 1;
|
2015-03-04 16:13:12 +00:00
|
|
|
config.reg_bits = 7;
|
|
|
|
config.pad_bits = 1;
|
|
|
|
config.val_bits = 8;
|
|
|
|
config.use_single_rw = 1;
|
2011-12-12 15:07:41 +00:00
|
|
|
|
2014-08-16 13:23:40 +00:00
|
|
|
da9052->regmap = devm_regmap_init_spi(spi, &config);
|
2011-12-12 15:07:41 +00:00
|
|
|
if (IS_ERR(da9052->regmap)) {
|
|
|
|
ret = PTR_ERR(da9052->regmap);
|
|
|
|
dev_err(&spi->dev, "Failed to allocate register map: %d\n",
|
|
|
|
ret);
|
2012-05-11 01:29:51 +00:00
|
|
|
return ret;
|
2011-12-12 15:07:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 11:26:07 +00:00
|
|
|
return da9052_device_init(da9052, id->driver_data);
|
2011-12-12 15:07:41 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:01 +00:00
|
|
|
static int da9052_spi_remove(struct spi_device *spi)
|
2011-12-12 15:07:41 +00:00
|
|
|
{
|
2013-04-06 06:43:23 +00:00
|
|
|
struct da9052 *da9052 = spi_get_drvdata(spi);
|
2011-12-12 15:07:41 +00:00
|
|
|
|
|
|
|
da9052_device_exit(da9052);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-21 17:55:27 +00:00
|
|
|
static const struct spi_device_id da9052_spi_id[] = {
|
2011-12-12 15:07:41 +00:00
|
|
|
{"da9052", DA9052},
|
|
|
|
{"da9053-aa", DA9053_AA},
|
|
|
|
{"da9053-ba", DA9053_BA},
|
|
|
|
{"da9053-bb", DA9053_BB},
|
2014-02-19 16:32:47 +00:00
|
|
|
{"da9053-bc", DA9053_BC},
|
2011-12-12 15:07:41 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_driver da9052_spi_driver = {
|
|
|
|
.probe = da9052_spi_probe,
|
2012-11-19 18:20:24 +00:00
|
|
|
.remove = da9052_spi_remove,
|
2011-12-12 15:07:41 +00:00
|
|
|
.id_table = da9052_spi_id,
|
|
|
|
.driver = {
|
|
|
|
.name = "da9052",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
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\n", 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");
|