summaryrefslogtreecommitdiffstats
path: root/arch/arm/boards/phytec-som-imx8mq/board.c
blob: 45ed9cf5ad98ce1bb9824616f3e95ca2bbd27f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2018 Christian Hemp
 */

#include <asm/memory.h>
#include <bootsource.h>
#include <environment.h>
#include <common.h>
#include <init.h>
#include <linux/sizes.h>
#include <mach/imx/bbu.h>
#include <mfd/pfuze.h>
#include <linux/regmap.h>

#include <envfs.h>

#define PFUZE100_DEVICEID	0x0
#define PFUZE100_REVID		0x3

#define PFUZE100_SW1ABMODE	0x23
#define PFUZE100_SW2MODE	0x38
#define PFUZE100_SW1CMODE	0x31
#define PFUZE100_SW3AVOL	0x3c

#define APS_PFM			0xc

static void imx8mq_setup_pmic_voltages(struct regmap *map)
{
	int offset = PFUZE100_SW1CMODE;
	int switch_num = 6;
	int val, i;

	regmap_read(map, PFUZE100_SW3AVOL, &val);

	/* ensure the correct VDD_DRAM_0V9 output voltage */
	regmap_write_bits(map, PFUZE100_SW3AVOL, 0x3f, 0x18);

	/* pfuze200 */
	regmap_read(map, PFUZE100_DEVICEID, &val);
	if (val & 0xf) {
		offset = PFUZE100_SW2MODE;
		switch_num = 4;
	}

	/* set all switches APS in normal and PFM mode in standby */
	regmap_write(map, PFUZE100_SW1ABMODE, APS_PFM);

	for (i = 0; i < switch_num - 1; i++)
		regmap_write(map, offset + i * 7, APS_PFM);
}

static int physom_imx8mq_devices_init(void)
{
	int flag_emmc = 0;
	int flag_sd = 0;

	if (!of_machine_is_compatible("phytec,imx8mq-pcl066"))
		return 0;

	barebox_set_hostname("phycore-imx8mq");

	pfuze_register_init_callback(imx8mq_setup_pmic_voltages);

	switch (bootsource_get_instance()) {
	case 0:
		flag_emmc = BBU_HANDLER_FLAG_DEFAULT;
		of_device_enable_path("/chosen/environment-emmc");
		break;
	case 1:
	default:
		flag_sd = BBU_HANDLER_FLAG_DEFAULT;
		of_device_enable_path("/chosen/environment-sd");
		break;
	}

	imx8m_bbu_internal_mmc_register_handler("eMMC", "/dev/mmc0.barebox", flag_emmc);
	imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", flag_sd);


	return 0;
}
device_initcall(physom_imx8mq_devices_init);