arizona-spi.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * arizona-spi.c -- Arizona SPI bus interface
  3. *
  4. * Copyright 2012 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.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 version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/err.h>
  13. #include <linux/module.h>
  14. #include <linux/pm_runtime.h>
  15. #include <linux/regmap.h>
  16. #include <linux/regulator/consumer.h>
  17. #include <linux/slab.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/of.h>
  20. #include <linux/mfd/arizona/core.h>
  21. #include "arizona.h"
  22. static int arizona_spi_probe(struct spi_device *spi)
  23. {
  24. const struct spi_device_id *id = spi_get_device_id(spi);
  25. struct arizona *arizona;
  26. const struct regmap_config *regmap_config = NULL;
  27. unsigned long type;
  28. int ret;
  29. if (spi->dev.of_node)
  30. type = arizona_of_get_type(&spi->dev);
  31. else
  32. type = id->driver_data;
  33. switch (type) {
  34. case WM5102:
  35. if (IS_ENABLED(CONFIG_MFD_WM5102))
  36. regmap_config = &wm5102_spi_regmap;
  37. break;
  38. case WM5110:
  39. case WM8280:
  40. if (IS_ENABLED(CONFIG_MFD_WM5110))
  41. regmap_config = &wm5110_spi_regmap;
  42. break;
  43. case WM1831:
  44. case CS47L24:
  45. if (IS_ENABLED(CONFIG_MFD_CS47L24))
  46. regmap_config = &cs47l24_spi_regmap;
  47. break;
  48. default:
  49. dev_err(&spi->dev, "Unknown device type %ld\n", type);
  50. return -EINVAL;
  51. }
  52. if (!regmap_config) {
  53. dev_err(&spi->dev,
  54. "No kernel support for device type %ld\n", type);
  55. return -EINVAL;
  56. }
  57. arizona = devm_kzalloc(&spi->dev, sizeof(*arizona), GFP_KERNEL);
  58. if (arizona == NULL)
  59. return -ENOMEM;
  60. arizona->regmap = devm_regmap_init_spi(spi, regmap_config);
  61. if (IS_ERR(arizona->regmap)) {
  62. ret = PTR_ERR(arizona->regmap);
  63. dev_err(&spi->dev, "Failed to allocate register map: %d\n",
  64. ret);
  65. return ret;
  66. }
  67. arizona->type = type;
  68. arizona->dev = &spi->dev;
  69. arizona->irq = spi->irq;
  70. return arizona_dev_init(arizona);
  71. }
  72. static int arizona_spi_remove(struct spi_device *spi)
  73. {
  74. struct arizona *arizona = spi_get_drvdata(spi);
  75. arizona_dev_exit(arizona);
  76. return 0;
  77. }
  78. static const struct spi_device_id arizona_spi_ids[] = {
  79. { "wm5102", WM5102 },
  80. { "wm5110", WM5110 },
  81. { "wm8280", WM8280 },
  82. { "wm1831", WM1831 },
  83. { "cs47l24", CS47L24 },
  84. { },
  85. };
  86. MODULE_DEVICE_TABLE(spi, arizona_spi_ids);
  87. static struct spi_driver arizona_spi_driver = {
  88. .driver = {
  89. .name = "arizona",
  90. .pm = &arizona_pm_ops,
  91. .of_match_table = of_match_ptr(arizona_of_match),
  92. },
  93. .probe = arizona_spi_probe,
  94. .remove = arizona_spi_remove,
  95. .id_table = arizona_spi_ids,
  96. };
  97. module_spi_driver(arizona_spi_driver);
  98. MODULE_DESCRIPTION("Arizona SPI bus interface");
  99. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  100. MODULE_LICENSE("GPL");