blob: c5ddecac755171e5e9b25d4a69855b5a0fade377 [file] [log] [blame]
Eugen Hristev3bd56102019-10-09 09:23:39 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019, Microchip Technology, Inc.
4 * Author: Eugen Hristev <eugen.hristev@microchip.com>
5 */
6
Eugen Hristev3bd56102019-10-09 09:23:39 +00007#include <dm.h>
8#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Eugen Hristev3bd56102019-10-09 09:23:39 +000010#include <misc.h>
11#include <asm/io.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070012#include <linux/err.h>
Eugen Hristev3bd56102019-10-09 09:23:39 +000013
14struct microchip_flexcom_regs {
15 u32 cr;
16};
17
Simon Glassb75b15b2020-12-03 16:55:23 -070018struct microchip_flexcom_plat {
Eugen Hristev3bd56102019-10-09 09:23:39 +000019 struct microchip_flexcom_regs *regs;
20 u32 flexcom_mode;
21};
22
Simon Glassaad29ae2020-12-03 16:55:21 -070023static int microchip_flexcom_of_to_plat(struct udevice *dev)
Eugen Hristev3bd56102019-10-09 09:23:39 +000024{
Simon Glassb75b15b2020-12-03 16:55:23 -070025 struct microchip_flexcom_plat *plat = dev_get_plat(dev);
Eugen Hristev3bd56102019-10-09 09:23:39 +000026 int ret;
27
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +090028 plat->regs = map_physmem(dev_read_addr(dev),
Eugen Hristev3bd56102019-10-09 09:23:39 +000029 sizeof(struct microchip_flexcom_regs),
30 MAP_NOCACHE);
31
32 ret = dev_read_u32(dev, "atmel,flexcom-mode", &plat->flexcom_mode);
33
34 if (IS_ERR_VALUE(ret)) {
35 debug("Missing atmel,flexcom-mode property\n");
36 return ret;
37 }
38
39 /*
40 * The mode must have only 2 bits. If any other bits are set,
41 * the value is not supported.
42 */
43 if (plat->flexcom_mode & 0xfffffffc) {
44 debug("Wrong atmel,flexcom-mode property\n");
45 return -EINVAL;
46 }
47
48 writel(plat->flexcom_mode, &plat->regs->cr);
49
50 return 0;
51}
52
53static const struct udevice_id microchip_flexcom_ids[] = {
54 { .compatible = "atmel,sama5d2-flexcom" },
55 { .compatible = "microchip,flexcom" },
56 {}
57};
58
59U_BOOT_DRIVER(microchip_flexcom) = {
60 .name = "microchip_flexcom",
61 .id = UCLASS_MISC,
62 .of_match = microchip_flexcom_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -070063 .of_to_plat = microchip_flexcom_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -070064 .plat_auto = sizeof(struct microchip_flexcom_plat),
Eugen Hristev3bd56102019-10-09 09:23:39 +000065};