Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 1 | // 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 Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 10 | #include <misc.h> |
| 11 | #include <asm/io.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 12 | #include <linux/err.h> |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 13 | |
| 14 | struct microchip_flexcom_regs { |
| 15 | u32 cr; |
| 16 | }; |
| 17 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 18 | struct microchip_flexcom_plat { |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 19 | struct microchip_flexcom_regs *regs; |
| 20 | u32 flexcom_mode; |
| 21 | }; |
| 22 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 23 | static int microchip_flexcom_of_to_plat(struct udevice *dev) |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 24 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 25 | struct microchip_flexcom_plat *plat = dev_get_plat(dev); |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 26 | int ret; |
| 27 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 28 | plat->regs = map_physmem(dev_read_addr(dev), |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 29 | 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 | |
| 53 | static const struct udevice_id microchip_flexcom_ids[] = { |
| 54 | { .compatible = "atmel,sama5d2-flexcom" }, |
| 55 | { .compatible = "microchip,flexcom" }, |
| 56 | {} |
| 57 | }; |
| 58 | |
| 59 | U_BOOT_DRIVER(microchip_flexcom) = { |
| 60 | .name = "microchip_flexcom", |
| 61 | .id = UCLASS_MISC, |
| 62 | .of_match = microchip_flexcom_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 63 | .of_to_plat = microchip_flexcom_of_to_plat, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 64 | .plat_auto = sizeof(struct microchip_flexcom_plat), |
Eugen Hristev | 3bd5610 | 2019-10-09 09:23:39 +0000 | [diff] [blame] | 65 | }; |