da9052-spi.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <linux/device.h>
  15. #include <linux/module.h>
  16. #include <linux/input.h>
  17. #include <linux/mfd/core.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/err.h>
  20. #include <linux/mfd/da9052/da9052.h>
  21. static int da9052_spi_probe(struct spi_device *spi)
  22. {
  23. struct regmap_config config;
  24. int ret;
  25. const struct spi_device_id *id = spi_get_device_id(spi);
  26. struct da9052 *da9052;
  27. da9052 = devm_kzalloc(&spi->dev, sizeof(struct da9052), GFP_KERNEL);
  28. if (!da9052)
  29. return -ENOMEM;
  30. spi->mode = SPI_MODE_0;
  31. spi->bits_per_word = 8;
  32. spi_setup(spi);
  33. da9052->dev = &spi->dev;
  34. da9052->chip_irq = spi->irq;
  35. spi_set_drvdata(spi, da9052);
  36. config = da9052_regmap_config;
  37. config.read_flag_mask = 1;
  38. config.reg_bits = 7;
  39. config.pad_bits = 1;
  40. config.val_bits = 8;
  41. config.use_single_rw = 1;
  42. da9052->regmap = devm_regmap_init_spi(spi, &config);
  43. if (IS_ERR(da9052->regmap)) {
  44. ret = PTR_ERR(da9052->regmap);
  45. dev_err(&spi->dev, "Failed to allocate register map: %d\n",
  46. ret);
  47. return ret;
  48. }
  49. return da9052_device_init(da9052, id->driver_data);
  50. }
  51. static int da9052_spi_remove(struct spi_device *spi)
  52. {
  53. struct da9052 *da9052 = spi_get_drvdata(spi);
  54. da9052_device_exit(da9052);
  55. return 0;
  56. }
  57. static struct spi_device_id da9052_spi_id[] = {
  58. {"da9052", DA9052},
  59. {"da9053-aa", DA9053_AA},
  60. {"da9053-ba", DA9053_BA},
  61. {"da9053-bb", DA9053_BB},
  62. {"da9053-bc", DA9053_BC},
  63. {}
  64. };
  65. static struct spi_driver da9052_spi_driver = {
  66. .probe = da9052_spi_probe,
  67. .remove = da9052_spi_remove,
  68. .id_table = da9052_spi_id,
  69. .driver = {
  70. .name = "da9052",
  71. },
  72. };
  73. static int __init da9052_spi_init(void)
  74. {
  75. int ret;
  76. ret = spi_register_driver(&da9052_spi_driver);
  77. if (ret != 0) {
  78. pr_err("Failed to register DA9052 SPI driver, %d\n", ret);
  79. return ret;
  80. }
  81. return 0;
  82. }
  83. subsys_initcall(da9052_spi_init);
  84. static void __exit da9052_spi_exit(void)
  85. {
  86. spi_unregister_driver(&da9052_spi_driver);
  87. }
  88. module_exit(da9052_spi_exit);
  89. MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
  90. MODULE_DESCRIPTION("SPI driver for Dialog DA9052 PMIC");
  91. MODULE_LICENSE("GPL");