Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 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 | |
| 11 | #include <dt-bindings/mfd/at91-usart.h> |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/mfd/core.h> |
Lee Jones | 65b80df | 2018-09-11 11:34:27 +0100 | [diff] [blame] | 15 | #include <linux/of.h> |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 16 | #include <linux/property.h> |
| 17 | |
Codrin Ciubotariu | 4c5840b | 2020-11-03 11:32:46 +0200 | [diff] [blame] | 18 | static const struct mfd_cell at91_usart_spi_subdev = |
| 19 | MFD_CELL_NAME("at91_usart_spi"); |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 20 | |
Codrin Ciubotariu | 4c5840b | 2020-11-03 11:32:46 +0200 | [diff] [blame] | 21 | static const struct mfd_cell at91_usart_serial_subdev = |
| 22 | MFD_CELL_NAME("atmel_usart_serial"); |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 23 | |
| 24 | static int at91_usart_mode_probe(struct platform_device *pdev) |
| 25 | { |
Axel Lin | c0056bf | 2019-01-31 12:32:13 +0800 | [diff] [blame] | 26 | const struct mfd_cell *cell; |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 27 | u32 opmode = AT91_USART_MODE_SERIAL; |
| 28 | |
| 29 | device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode); |
| 30 | |
| 31 | switch (opmode) { |
| 32 | case AT91_USART_MODE_SPI: |
Axel Lin | c0056bf | 2019-01-31 12:32:13 +0800 | [diff] [blame] | 33 | cell = &at91_usart_spi_subdev; |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 34 | break; |
| 35 | case AT91_USART_MODE_SERIAL: |
Axel Lin | c0056bf | 2019-01-31 12:32:13 +0800 | [diff] [blame] | 36 | cell = &at91_usart_serial_subdev; |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 37 | break; |
| 38 | default: |
| 39 | dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u\n", |
| 40 | opmode); |
| 41 | return -EINVAL; |
| 42 | } |
| 43 | |
Axel Lin | c0056bf | 2019-01-31 12:32:13 +0800 | [diff] [blame] | 44 | return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, cell, 1, |
Radu Pirea | 7d3aa34 | 2018-07-13 19:47:33 +0300 | [diff] [blame] | 45 | NULL, 0, NULL); |
| 46 | } |
| 47 | |
| 48 | static const struct of_device_id at91_usart_mode_of_match[] = { |
| 49 | { .compatible = "atmel,at91rm9200-usart" }, |
| 50 | { .compatible = "atmel,at91sam9260-usart" }, |
| 51 | { /* sentinel */ } |
| 52 | }; |
| 53 | |
| 54 | MODULE_DEVICE_TABLE(of, at91_usart_mode_of_match); |
| 55 | |
| 56 | static struct platform_driver at91_usart_mfd = { |
| 57 | .probe = at91_usart_mode_probe, |
| 58 | .driver = { |
| 59 | .name = "at91_usart_mode", |
| 60 | .of_match_table = at91_usart_mode_of_match, |
| 61 | }, |
| 62 | }; |
| 63 | |
| 64 | module_platform_driver(at91_usart_mfd); |
| 65 | |
| 66 | MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>"); |
| 67 | MODULE_DESCRIPTION("AT91 USART MFD driver"); |
| 68 | MODULE_LICENSE("GPL v2"); |