at91-usart.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/property.h>
  14. static struct mfd_cell at91_usart_spi_subdev = {
  15. .name = "at91_usart_spi",
  16. .of_compatible = "microchip,at91sam9g45-usart-spi",
  17. };
  18. static struct mfd_cell at91_usart_serial_subdev = {
  19. .name = "atmel_usart_serial",
  20. .of_compatible = "atmel,at91rm9200-usart-serial",
  21. };
  22. static int at91_usart_mode_probe(struct platform_device *pdev)
  23. {
  24. struct mfd_cell cell;
  25. u32 opmode = AT91_USART_MODE_SERIAL;
  26. device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode);
  27. switch (opmode) {
  28. case AT91_USART_MODE_SPI:
  29. cell = at91_usart_spi_subdev;
  30. break;
  31. case AT91_USART_MODE_SERIAL:
  32. cell = at91_usart_serial_subdev;
  33. break;
  34. default:
  35. dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u\n",
  36. opmode);
  37. return -EINVAL;
  38. }
  39. return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, &cell, 1,
  40. NULL, 0, NULL);
  41. }
  42. static const struct of_device_id at91_usart_mode_of_match[] = {
  43. { .compatible = "atmel,at91rm9200-usart" },
  44. { .compatible = "atmel,at91sam9260-usart" },
  45. { /* sentinel */ }
  46. };
  47. MODULE_DEVICE_TABLE(of, at91_usart_mode_of_match);
  48. static struct platform_driver at91_usart_mfd = {
  49. .probe = at91_usart_mode_probe,
  50. .driver = {
  51. .name = "at91_usart_mode",
  52. .of_match_table = at91_usart_mode_of_match,
  53. },
  54. };
  55. module_platform_driver(at91_usart_mfd);
  56. MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>");
  57. MODULE_DESCRIPTION("AT91 USART MFD driver");
  58. MODULE_LICENSE("GPL v2");