Blame view

drivers/mfd/at91-usart.c 1.71 KB
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  // SPDX-License-Identifier: GPL-2.0
  /*
   * Driver for AT91 USART
   *
   * Copyright (C) 2018 Microchip Technology
   *
   * Author: Radu Pirea <radu.pirea@microchip.com>
   *
   */
  
  #include <dt-bindings/mfd/at91-usart.h>
  
  #include <linux/module.h>
  #include <linux/mfd/core.h>
65b80dfff   Lee Jones   mfd: at91-usart: ...
15
  #include <linux/of.h>
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
16
  #include <linux/property.h>
10cffde4a   Axel Lin   mfd: at91-usart: ...
17
18
19
20
  static const struct mfd_cell at91_usart_spi_subdev = {
  	.name = "at91_usart_spi",
  	.of_compatible = "microchip,at91sam9g45-usart-spi",
  };
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
21

10cffde4a   Axel Lin   mfd: at91-usart: ...
22
23
24
25
  static const struct mfd_cell at91_usart_serial_subdev = {
  	.name = "atmel_usart_serial",
  	.of_compatible = "atmel,at91rm9200-usart-serial",
  };
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
26
27
28
  
  static int at91_usart_mode_probe(struct platform_device *pdev)
  {
c0056bfe4   Axel Lin   mfd: at91-usart: ...
29
  	const struct mfd_cell *cell;
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
30
31
32
33
34
35
  	u32 opmode = AT91_USART_MODE_SERIAL;
  
  	device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode);
  
  	switch (opmode) {
  	case AT91_USART_MODE_SPI:
c0056bfe4   Axel Lin   mfd: at91-usart: ...
36
  		cell = &at91_usart_spi_subdev;
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
37
38
  		break;
  	case AT91_USART_MODE_SERIAL:
c0056bfe4   Axel Lin   mfd: at91-usart: ...
39
  		cell = &at91_usart_serial_subdev;
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
40
41
42
43
44
45
46
  		break;
  	default:
  		dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u
  ",
  			opmode);
  		return -EINVAL;
  	}
c0056bfe4   Axel Lin   mfd: at91-usart: ...
47
  	return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, cell, 1,
7d3aa342c   Radu Pirea   mfd: at91-usart: ...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  			      NULL, 0, NULL);
  }
  
  static const struct of_device_id at91_usart_mode_of_match[] = {
  	{ .compatible = "atmel,at91rm9200-usart" },
  	{ .compatible = "atmel,at91sam9260-usart" },
  	{ /* sentinel */ }
  };
  
  MODULE_DEVICE_TABLE(of, at91_usart_mode_of_match);
  
  static struct platform_driver at91_usart_mfd = {
  	.probe	= at91_usart_mode_probe,
  	.driver	= {
  		.name		= "at91_usart_mode",
  		.of_match_table	= at91_usart_mode_of_match,
  	},
  };
  
  module_platform_driver(at91_usart_mfd);
  
  MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>");
  MODULE_DESCRIPTION("AT91 USART MFD driver");
  MODULE_LICENSE("GPL v2");