at91-usart.c 1.6 KB

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