2 * Driver for Atmel Flexcom
4 * Copyright (C) 2015 Atmel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/platform_device.h>
26 #include <linux/of_platform.h>
27 #include <linux/err.h>
29 #include <linux/clk.h>
30 #include <dt-bindings/mfd/atmel-flexcom.h>
32 /* I/O register offsets */
33 #define FLEX_MR 0x0 /* Mode Register */
34 #define FLEX_VERSION 0xfc /* Version Register */
36 /* Mode Register bit fields */
37 #define FLEX_MR_OPMODE_OFFSET (0) /* Operating Mode */
38 #define FLEX_MR_OPMODE_MASK (0x3 << FLEX_MR_OPMODE_OFFSET)
39 #define FLEX_MR_OPMODE(opmode) (((opmode) << FLEX_MR_OPMODE_OFFSET) & \
43 static int atmel_flexcom_probe(struct platform_device *pdev)
45 struct device_node *np = pdev->dev.of_node;
52 err = of_property_read_u32(np, "atmel,flexcom-mode", &opmode);
56 if (opmode < ATMEL_FLEXCOM_MODE_USART ||
57 opmode > ATMEL_FLEXCOM_MODE_TWI)
60 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
61 base = devm_ioremap_resource(&pdev->dev, res);
65 clk = devm_clk_get(&pdev->dev, NULL);
69 err = clk_prepare_enable(clk);
74 * Set the Operating Mode in the Mode Register: only the selected device
75 * is clocked. Hence, registers of the other serial devices remain
76 * inaccessible and are read as zero. Also the external I/O lines of the
77 * Flexcom are muxed to reach the selected device.
79 writel(FLEX_MR_OPMODE(opmode), base + FLEX_MR);
81 clk_disable_unprepare(clk);
83 return of_platform_populate(np, NULL, NULL, &pdev->dev);
86 static const struct of_device_id atmel_flexcom_of_match[] = {
87 { .compatible = "atmel,sama5d2-flexcom" },
90 MODULE_DEVICE_TABLE(of, atmel_flexcom_of_match);
92 static struct platform_driver atmel_flexcom_driver = {
93 .probe = atmel_flexcom_probe,
95 .name = "atmel_flexcom",
96 .of_match_table = atmel_flexcom_of_match,
100 module_platform_driver(atmel_flexcom_driver);
103 MODULE_DESCRIPTION("Atmel Flexcom MFD driver");
104 MODULE_LICENSE("GPL v2");