at91-usart.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for AT91 USART
  4. *
  5. * Copyright (C) 2018 Microchip Technology
  6. *
  7. * Author: Radu Pirea <radu.pirea@microchip.com>
  8. *
  9. */
  10. #include <dt-bindings/mfd/at91-usart.h>
  11. #include <linux/module.h>
  12. #include <linux/mfd/core.h>
  13. #include <linux/of.h>
  14. #include <linux/property.h>
  15. static const struct mfd_cell at91_usart_spi_subdev = {
  16. .name = "at91_usart_spi",
  17. .of_compatible = "microchip,at91sam9g45-usart-spi",
  18. };
  19. static const struct mfd_cell at91_usart_serial_subdev = {
  20. .name = "atmel_usart_serial",
  21. .of_compatible = "atmel,at91rm9200-usart-serial",
  22. };
  23. static int at91_usart_mode_probe(struct platform_device *pdev)
  24. {
  25. const struct mfd_cell *cell;
  26. u32 opmode = AT91_USART_MODE_SERIAL;
  27. device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode);
  28. switch (opmode) {
  29. case AT91_USART_MODE_SPI:
  30. cell = &at91_usart_spi_subdev;
  31. break;
  32. case AT91_USART_MODE_SERIAL:
  33. cell = &at91_usart_serial_subdev;
  34. break;
  35. default:
  36. dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u\n",
  37. opmode);
  38. return -EINVAL;
  39. }
  40. return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, cell, 1,
  41. NULL, 0, NULL);
  42. }
  43. static const struct of_device_id at91_usart_mode_of_match[] = {
  44. { .compatible = "atmel,at91rm9200-usart" },
  45. { .compatible = "atmel,at91sam9260-usart" },
  46. { /* sentinel */ }
  47. };
  48. MODULE_DEVICE_TABLE(of, at91_usart_mode_of_match);
  49. static struct platform_driver at91_usart_mfd = {
  50. .probe = at91_usart_mode_probe,
  51. .driver = {
  52. .name = "at91_usart_mode",
  53. .of_match_table = at91_usart_mode_of_match,
  54. },
  55. };
  56. module_platform_driver(at91_usart_mfd);
  57. MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>");
  58. MODULE_DESCRIPTION("AT91 USART MFD driver");
  59. MODULE_LICENSE("GPL v2");