coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mt6360.c File Reference
#include <console/console.h>
#include <device/i2c_simple.h>
#include <soc/mt6360.h>
#include <stdbool.h>
Include dependency graph for mt6360.c:

Go to the source code of this file.

Macros

#define CRC8_TABLE_SIZE   256
 

Functions

static u8 crc8 (const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes)
 
static void crc8_populate_msb (u8 table[CRC8_TABLE_SIZE], u8 polynomial)
 
static int mt6360_i2c_write_byte (u8 index, u8 reg, u8 data)
 
static int mt6360_i2c_read_byte (u8 index, u8 reg, u8 *data)
 
static int mt6360_read_interface (u8 index, u8 reg, u8 *data, u8 mask, u8 shift)
 
static int mt6360_config_interface (u8 index, u8 reg, u8 data, u8 mask, u8 shift)
 
static bool is_valid_ldo (enum mt6360_regulator_id id)
 
static bool is_valid_pmic (enum mt6360_regulator_id id)
 
static void mt6360_ldo_enable (enum mt6360_regulator_id id, uint8_t enable)
 
static uint8_t mt6360_ldo_is_enabled (enum mt6360_regulator_id id)
 
static void mt6360_ldo_set_voltage (enum mt6360_regulator_id id, u32 voltage_uv)
 
static u32 mt6360_ldo_get_voltage (enum mt6360_regulator_id id)
 
static void mt6360_pmic_enable (enum mt6360_regulator_id id, uint8_t enable)
 
static uint8_t mt6360_pmic_is_enabled (enum mt6360_regulator_id id)
 
static void mt6360_pmic_set_voltage (enum mt6360_regulator_id id, u32 voltage_uv)
 
static u32 mt6360_pmic_get_voltage (enum mt6360_regulator_id id)
 
void mt6360_init (uint8_t bus)
 
void mt6360_enable (enum mt6360_regulator_id id, uint8_t enable)
 
uint8_t mt6360_is_enabled (enum mt6360_regulator_id id)
 
void mt6360_set_voltage (enum mt6360_regulator_id id, u32 voltage_uv)
 
u32 mt6360_get_voltage (enum mt6360_regulator_id id)
 

Variables

static struct mt6360_i2c_data i2c_data []
 
static const uint32_t mt6360_ldo1_vsel_table [0x10]
 
static const uint32_t mt6360_ldo3_vsel_table [0x10]
 
static const uint32_t mt6360_ldo5_vsel_table [0x10]
 
static const struct mt6360_data regulator_data [MT6360_REGULATOR_COUNT]
 
static u8 crc8_table [MT6360_INDEX_COUNT][CRC8_TABLE_SIZE]
 

Macro Definition Documentation

◆ CRC8_TABLE_SIZE

#define CRC8_TABLE_SIZE   256

Definition at line 54 of file mt6360.c.

Function Documentation

◆ crc8()

static u8 crc8 ( const u8  table[CRC8_TABLE_SIZE],
u8 pdata,
size_t  nbytes 
)
static

Definition at line 57 of file mt6360.c.

Referenced by mt6360_i2c_read_byte(), and mt6360_i2c_write_byte().

Here is the caller graph for this function:

◆ crc8_populate_msb()

static void crc8_populate_msb ( u8  table[CRC8_TABLE_SIZE],
u8  polynomial 
)
static

Definition at line 67 of file mt6360.c.

References CRC8_TABLE_SIZE.

Referenced by mt6360_init().

Here is the caller graph for this function:

◆ is_valid_ldo()

static bool is_valid_ldo ( enum mt6360_regulator_id  id)
static

◆ is_valid_pmic()

static bool is_valid_pmic ( enum mt6360_regulator_id  id)
static

◆ mt6360_config_interface()

static int mt6360_config_interface ( u8  index,
u8  reg,
u8  data,
u8  mask,
u8  shift 
)
static

Definition at line 158 of file mt6360.c.

References BIOS_ERR, mask, mt6360_i2c_read_byte(), mt6360_i2c_write_byte(), printk, and val.

Referenced by mt6360_init(), mt6360_ldo_enable(), mt6360_ldo_set_voltage(), mt6360_pmic_enable(), and mt6360_pmic_set_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_enable()

void mt6360_enable ( enum mt6360_regulator_id  id,
uint8_t  enable 
)

Definition at line 406 of file mt6360.c.

References is_valid_ldo(), is_valid_pmic(), mt6360_ldo_enable(), and mt6360_pmic_enable().

Referenced by mainboard_enable_regulator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_get_voltage()

u32 mt6360_get_voltage ( enum mt6360_regulator_id  id)

Definition at line 432 of file mt6360.c.

References is_valid_ldo(), is_valid_pmic(), mt6360_ldo_get_voltage(), and mt6360_pmic_get_voltage().

Referenced by mainboard_get_regulator_vol().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_i2c_read_byte()

static int mt6360_i2c_read_byte ( u8  index,
u8  reg,
u8 data 
)
static

Definition at line 107 of file mt6360.c.

References mt6360_i2c_data::addr, BIOS_ERR, buf, mt6360_i2c_data::bus, crc8(), crc8_table, i2c_data, i2c_read_bytes(), and printk.

Referenced by mt6360_config_interface(), and mt6360_read_interface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_i2c_write_byte()

static int mt6360_i2c_write_byte ( u8  index,
u8  reg,
u8  data 
)
static

Definition at line 82 of file mt6360.c.

References mt6360_i2c_data::addr, BIOS_ERR, mt6360_i2c_data::bus, crc8(), crc8_table, i2c_data, i2c_write_raw(), and printk.

Referenced by mt6360_config_interface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_init()

void mt6360_init ( uint8_t  bus)

Definition at line 382 of file mt6360.c.

References BIOS_DEBUG, mt6360_i2c_data::bus, crc8_populate_msb(), crc8_table, i2c_data, mt6360_config_interface(), MT6360_INDEX_LDO, MT6360_INDEX_PMIC, mt6360_read_interface(), and printk.

Referenced by mtk_msdc_configure_sdcard(), and platform_romstage_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_is_enabled()

uint8_t mt6360_is_enabled ( enum mt6360_regulator_id  id)

Definition at line 414 of file mt6360.c.

References is_valid_ldo(), is_valid_pmic(), mt6360_ldo_is_enabled(), and mt6360_pmic_is_enabled().

Referenced by mainboard_regulator_is_enabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_ldo_enable()

static void mt6360_ldo_enable ( enum mt6360_regulator_id  id,
uint8_t  enable 
)
static

Definition at line 197 of file mt6360.c.

References mt6360_data::enable_mask, mt6360_data::enable_reg, is_valid_ldo(), mt6360_config_interface(), MT6360_INDEX_LDO, mt6360_read_interface(), regulator_data, and val.

Referenced by mt6360_enable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_ldo_get_voltage()

static u32 mt6360_ldo_get_voltage ( enum mt6360_regulator_id  id)
static

Definition at line 272 of file mt6360.c.

References BIOS_ERR, is_valid_ldo(), MIN, MT6360_INDEX_LDO, mt6360_read_interface(), printk, regulator_data, val, mt6360_data::vsel_reg, and mt6360_data::vsel_table.

Referenced by mt6360_get_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_ldo_is_enabled()

static uint8_t mt6360_ldo_is_enabled ( enum mt6360_regulator_id  id)
static

Definition at line 218 of file mt6360.c.

References mt6360_data::enable_mask, mt6360_data::enable_reg, is_valid_ldo(), MT6360_INDEX_LDO, mt6360_read_interface(), regulator_data, and val.

Referenced by mt6360_is_enabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_ldo_set_voltage()

static void mt6360_ldo_set_voltage ( enum mt6360_regulator_id  id,
u32  voltage_uv 
)
static

Definition at line 234 of file mt6360.c.

References BIOS_ERR, is_valid_ldo(), MIN, mt6360_config_interface(), MT6360_INDEX_LDO, printk, regulator_data, val, mt6360_data::vsel_reg, mt6360_data::vsel_table, and mt6360_data::vsel_table_len.

Referenced by mt6360_set_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_pmic_enable()

static void mt6360_pmic_enable ( enum mt6360_regulator_id  id,
uint8_t  enable 
)
static

Definition at line 299 of file mt6360.c.

References mt6360_data::enable_mask, mt6360_data::enable_reg, is_valid_pmic(), mt6360_config_interface(), MT6360_INDEX_PMIC, mt6360_read_interface(), regulator_data, and val.

Referenced by mt6360_enable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_pmic_get_voltage()

static u32 mt6360_pmic_get_voltage ( enum mt6360_regulator_id  id)
static

Definition at line 357 of file mt6360.c.

References is_valid_pmic(), MIN, MT6360_BUCK1, MT6360_BUCK2, MT6360_INDEX_PMIC, MT6360_LDO6, MT6360_LDO7, mt6360_read_interface(), regulator_data, val, and mt6360_data::vsel_reg.

Referenced by mt6360_get_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_pmic_is_enabled()

static uint8_t mt6360_pmic_is_enabled ( enum mt6360_regulator_id  id)
static

Definition at line 320 of file mt6360.c.

References mt6360_data::enable_mask, mt6360_data::enable_reg, is_valid_pmic(), MT6360_INDEX_PMIC, mt6360_read_interface(), regulator_data, and val.

Referenced by mt6360_is_enabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_pmic_set_voltage()

static void mt6360_pmic_set_voltage ( enum mt6360_regulator_id  id,
u32  voltage_uv 
)
static

Definition at line 336 of file mt6360.c.

References is_valid_pmic(), MT6360_BUCK1, MT6360_BUCK2, mt6360_config_interface(), MT6360_INDEX_PMIC, MT6360_LDO6, MT6360_LDO7, regulator_data, val, and mt6360_data::vsel_reg.

Referenced by mt6360_set_voltage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_read_interface()

static int mt6360_read_interface ( u8  index,
u8  reg,
u8 data,
u8  mask,
u8  shift 
)
static

Definition at line 142 of file mt6360.c.

References BIOS_ERR, mask, mt6360_i2c_read_byte(), printk, and val.

Referenced by mt6360_init(), mt6360_ldo_enable(), mt6360_ldo_get_voltage(), mt6360_ldo_is_enabled(), mt6360_pmic_enable(), mt6360_pmic_get_voltage(), and mt6360_pmic_is_enabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt6360_set_voltage()

void mt6360_set_voltage ( enum mt6360_regulator_id  id,
u32  voltage_uv 
)

Definition at line 424 of file mt6360.c.

References is_valid_ldo(), is_valid_pmic(), mt6360_ldo_set_voltage(), and mt6360_pmic_set_voltage().

Referenced by mainboard_set_regulator_vol().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ crc8_table

u8 crc8_table[MT6360_INDEX_COUNT][CRC8_TABLE_SIZE]
static

Definition at line 55 of file mt6360.c.

Referenced by mt6360_i2c_read_byte(), mt6360_i2c_write_byte(), and mt6360_init().

◆ i2c_data

struct mt6360_i2c_data i2c_data[]
static
Initial value:
= {
},
},
}
@ MT6360_INDEX_PMIC
Definition: mt6360.h:23
@ MT6360_INDEX_LDO
Definition: mt6360.h:22
#define MT6360_LDO_I2C_ADDR
Definition: mt6360.h:8
#define MT6360_PMIC_I2C_ADDR
Definition: mt6360.h:9

Definition at line 1 of file mt6360.c.

Referenced by mt6360_i2c_read_byte(), mt6360_i2c_write_byte(), and mt6360_init().

◆ mt6360_ldo1_vsel_table

const uint32_t mt6360_ldo1_vsel_table[0x10]
static
Initial value:
= {
[0x4] = 1800000,
[0x5] = 2000000,
[0x6] = 2100000,
[0x7] = 2500000,
[0x8] = 2700000,
[0x9] = 2800000,
[0xA] = 2900000,
[0xB] = 3000000,
[0xC] = 3100000,
[0xD] = 3300000,
}

Definition at line 17 of file mt6360.c.

◆ mt6360_ldo3_vsel_table

const uint32_t mt6360_ldo3_vsel_table[0x10]
static
Initial value:
= {
[0x4] = 1800000,
[0xA] = 2900000,
[0xB] = 3000000,
[0xD] = 3300000,
}

Definition at line 30 of file mt6360.c.

◆ mt6360_ldo5_vsel_table

const uint32_t mt6360_ldo5_vsel_table[0x10]
static
Initial value:
= {
[0x2] = 2900000,
[0x3] = 3000000,
[0x5] = 3300000,
}

Definition at line 37 of file mt6360.c.

◆ regulator_data

const struct mt6360_data regulator_data[MT6360_REGULATOR_COUNT]
static
Initial value:
= {
[MT6360_LDO3] = MT6360_DATA(0x05, 0x40, 0x09, 0xff, mt6360_ldo3_vsel_table),
[MT6360_LDO5] = MT6360_DATA(0x0b, 0x40, 0x0f, 0xff, mt6360_ldo5_vsel_table),
[MT6360_LDO6] = MT6360_DATA(0x37, 0x40, 0x3b, 0xff, mt6360_ldo3_vsel_table),
[MT6360_LDO7] = MT6360_DATA(0x31, 0x40, 0x35, 0xff, mt6360_ldo5_vsel_table),
[MT6360_BUCK1] = MT6360_DATA(0x17, 0x40, 0x10, 0xff, mt6360_ldo1_vsel_table),
[MT6360_BUCK2] = MT6360_DATA(0x27, 0x40, 0x20, 0xff, mt6360_ldo1_vsel_table),
[MT6360_LDO1] = MT6360_DATA(0x17, 0x40, 0x1b, 0xff, mt6360_ldo1_vsel_table),
[MT6360_LDO2] = MT6360_DATA(0x11, 0x40, 0x15, 0xff, mt6360_ldo1_vsel_table),
}
static const uint32_t mt6360_ldo1_vsel_table[0x10]
Definition: mt6360.c:17
static const uint32_t mt6360_ldo3_vsel_table[0x10]
Definition: mt6360.c:30
static const uint32_t mt6360_ldo5_vsel_table[0x10]
Definition: mt6360.c:37
@ MT6360_BUCK1
Definition: mt6360.h:11
@ MT6360_LDO5
Definition: mt6360.h:8
@ MT6360_LDO3
Definition: mt6360.h:7
@ MT6360_BUCK2
Definition: mt6360.h:12
@ MT6360_LDO6
Definition: mt6360.h:9
@ MT6360_LDO7
Definition: mt6360.h:10
@ MT6360_LDO1
Definition: mt6360.h:38
@ MT6360_LDO2
Definition: mt6360.h:39
#define MT6360_DATA(_enreg, _enmask, _vreg, _vmask, _table)
Definition: mt6360.h:11

Definition at line 37 of file mt6360.c.

Referenced by mt6360_ldo_enable(), mt6360_ldo_get_voltage(), mt6360_ldo_is_enabled(), mt6360_ldo_set_voltage(), mt6360_pmic_enable(), mt6360_pmic_get_voltage(), mt6360_pmic_is_enabled(), and mt6360_pmic_set_voltage().