[stage2] Remove printk, introduce UTF-8 console stdio

This commit is contained in:
TuxSH
2018-05-05 23:55:40 +02:00
parent 02217bde55
commit 8648cac77b
15 changed files with 246 additions and 149 deletions

View File

@@ -1,8 +1,9 @@
/**
* Fusée SD/MMC driver for the Switch
* ~ktemkin
* ~ktemkin
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
@@ -16,7 +17,6 @@
#include "supplies.h"
#include "pmc.h"
#include "pad_control.h"
#include "lib/printk.h"
#define TEGRA_SDMMC_BASE (0x700B0000)
#define TEGRA_SDMMC_SIZE (0x200)
@@ -231,7 +231,7 @@ enum sdmmc_command {
CMD_SEND_EXT_CSD = 8,
CMD_SEND_IF_COND = 8,
CMD_SEND_CSD = 9,
CMD_SEND_CID = 10,
CMD_SEND_CID = 10,
CMD_STOP_TRANSMISSION = 12,
CMD_READ_STATUS = 13,
CMD_BUS_TEST = 14,
@@ -348,7 +348,7 @@ enum sdmmc_csd_versions {
/**
/**
* Positions of different fields in various CSDs.
* May eventually be replaced with a bitfield struct, if we use enough of the CSDs.
*/
@@ -427,9 +427,9 @@ static void mmc_vprint(struct mmc *mmc, char *fmt, int required_loglevel, va_lis
if (sdmmc_loglevel < required_loglevel)
return;
printk("%s: ", mmc->name);
vprintk(fmt, list);
printk("\n");
printf("%s: ", mmc->name);
vprintf(fmt, list);
printf("\n");
}
@@ -661,7 +661,7 @@ static int sdmmc1_hardware_init(struct mmc *mmc)
/**
* Sets up the I/O and clocking resources necessary to use the given controller.
* Sets up the I/O and clocking resources necessary to use the given controller.
*/
static int sdmmc_setup_controller_clock_and_io(struct mmc *mmc)
{
@@ -682,7 +682,7 @@ static int sdmmc_setup_controller_clock_and_io(struct mmc *mmc)
/**
* Sets up the I/O and clocking resources necessary to use the given controller.
* Sets up the I/O and clocking resources necessary to use the given controller.
*/
static int sdmmc_enable_supplies(struct mmc *mmc)
{
@@ -732,7 +732,7 @@ static int sdmmc_set_up_clocking_parameters(struct mmc *mmc)
break;
default:
printk("ERROR: initialization not yet writen for SDMMC%d", mmc->controller);
printf("ERROR: initialization not yet writen for SDMMC%d", mmc->controller);
return ENODEV;
}
@@ -828,20 +828,20 @@ static int sdmmc_hardware_init(struct mmc *mmc)
// Clear PAD_E_INPUT_OR_E_PWRD (relevant for eMMC only)
regs->sdmemcomppadctrl &= ~(0x80000000);
// Set SDHCI_CLOCK_INT_EN
regs->clock_control |= 0x01;
// Program a timeout of 2000ms
timebase = get_time();
is_timeout = false;
// Wait for SDHCI_CLOCK_INT_STABLE to be set
while (!(regs->clock_control & 0x02) && !is_timeout) {
// Keep checking if timeout expired
is_timeout = get_time_since(timebase) > 2000000;
}
// Clock failed to stabilize
if (is_timeout) {
mmc_print(mmc, "clock never stabalized!");
@@ -856,11 +856,11 @@ static int sdmmc_hardware_init(struct mmc *mmc)
// Clear SDHCI_CTRL_SDMA and SDHCI_CTRL_ADMA2
regs->host_control &= 0xE7;
// Set the timeout to be the maximum value
regs->timeout_control &= ~(0x0F);
regs->timeout_control |= 0x0E;
// Clear SDHCI_CTRL_4BITBUS and SDHCI_CTRL_8BITBUS
regs->host_control &= 0xFD;
regs->host_control &= 0xDF;
@@ -878,7 +878,7 @@ static int sdmmc_hardware_init(struct mmc *mmc)
// Clear SDHCI_CTRL_HISPD
regs->host_control &= 0xFB;
// Clear SDHCI_CTRL_VDD_180
// Clear SDHCI_CTRL_VDD_180
regs->host_control2 &= ~(0x08);
// Set SDHCI_DIVIDER and SDHCI_DIVIDER_HI
@@ -983,7 +983,7 @@ static int sdmmc_wait_until_no_longer_busy(struct mmc *mmc)
* Blocks until the SD driver has completed issuing a command.
*
* @param mmc The MMC controller on which to wait.
* @param target_irq A bitmask that specifies the bits that
* @param target_irq A bitmask that specifies the bits that
* will make this function return success
* @param fault_conditions A bitmask that specifies the bits that
* will make this function return EFAULT.
@@ -991,7 +991,7 @@ static int sdmmc_wait_until_no_longer_busy(struct mmc *mmc)
* @return 0 on sucess, EFAULT if a fault condition occurs,
* or an error code if a transfer failure occurs
*/
static int sdmmc_wait_for_interrupt(struct mmc *mmc,
static int sdmmc_wait_for_interrupt(struct mmc *mmc,
uint32_t target_irq, uint32_t fault_conditions)
{
uint32_t timebase = get_time();
@@ -1130,7 +1130,7 @@ static int sdmmc_handle_cpu_transfer(struct mmc *mmc, uint16_t blocks, bool is_w
* @param auto_termiante True iff we should instruct the system
* to reclaim the data lines after a transaction.
*/
static void sdmmc_prepare_command_data(struct mmc *mmc, uint16_t blocks,
static void sdmmc_prepare_command_data(struct mmc *mmc, uint16_t blocks,
bool is_write, bool auto_terminate, int argument)
{
if (blocks) {
@@ -1182,7 +1182,7 @@ static void sdmmc_prepare_command_data(struct mmc *mmc, uint16_t blocks,
static void sdmmc_prepare_command_registers(struct mmc *mmc, int blocks_to_xfer,
enum sdmmc_command command, enum sdmmc_response_type response_type, enum sdmmc_response_checks checks)
{
// Populate the command number
// Populate the command number
uint16_t to_write = (command << MMC_COMMAND_NUMBER_SHIFT) | (response_type << MMC_COMMAND_RESPONSE_TYPE_SHIFT) | checks;
// If this is a "stop transmitting" command, set the abort flag.
@@ -1301,7 +1301,7 @@ static int sdmmc_handle_command_response(struct mmc *mmc,
*/
static int sdmmc_send_command(struct mmc *mmc, enum sdmmc_command command,
enum sdmmc_response_type response_type, enum sdmmc_response_checks checks,
uint32_t argument, void *response_buffer, uint16_t blocks_to_transfer,
uint32_t argument, void *response_buffer, uint16_t blocks_to_transfer,
bool is_write, bool auto_terminate, void *data_buffer)
{
uint32_t total_data_to_xfer = sdmmc_get_block_size(mmc, is_write) * blocks_to_transfer;
@@ -1480,7 +1480,7 @@ static uint32_t sdmmc_extract_csd_bits(uint32_t *csd, int start, int width)
// Sanity check our span.
if ((start + width) > 128) {
printk("MMC ERROR: invalid CSD slice!\n");
printf("MMC ERROR: invalid CSD slice!\n");
return 0xFFFFFFFF;
}
@@ -1585,7 +1585,7 @@ static int sdmmc_read_and_parse_ext_csd(struct mmc *mmc)
uint8_t ext_csd[MMC_EXT_CSD_SIZE];
// Read the single EXT CSD block.
rc = sdmmc_send_command(mmc, CMD_SEND_EXT_CSD, MMC_RESPONSE_LEN48,
rc = sdmmc_send_command(mmc, CMD_SEND_EXT_CSD, MMC_RESPONSE_LEN48,
MMC_CHECKS_ALL, 0, NULL, 1, false, true, ext_csd);
if (rc) {
mmc_print(mmc, "ERROR: failed to read the extended CSD!");
@@ -1762,7 +1762,7 @@ static int sdmmc_get_relative_address(struct mmc *mmc)
* @param mmc The MMC controller to work with.
* @return 0 on success, or an error code on failure.
*/
static int sdmmc_get_or_set_relative_address(struct mmc *mmc)
static int sdmmc_get_or_set_relative_address(struct mmc *mmc)
{
// The SD and MMC specifications handle relative address assignemnt
// differently-- delegate accordingly.
@@ -1845,7 +1845,7 @@ static int sdmmc_mmc_wait_for_card_readiness(struct mmc *mmc)
uint32_t response_masked;
// Ask the SD card to identify its state. It will respond with readiness and a capacity magic.
rc = sdmmc_send_command(mmc, CMD_SEND_OPERATING_CONDITIONS, MMC_RESPONSE_LEN48,
rc = sdmmc_send_command(mmc, CMD_SEND_OPERATING_CONDITIONS, MMC_RESPONSE_LEN48,
MMC_CHECKS_NONE, 0x40000080, response, 0, false, false, NULL);
if (rc) {
mmc_print(mmc, "ERROR: could not read the card's operating conditions!");
@@ -2044,7 +2044,7 @@ static int sdmmc_sd_card_init(struct mmc *mmc)
*
* @param mmc The device to initialize.
*/
static int sdmmc_handle_card_type_init(struct mmc *mmc)
static int sdmmc_handle_card_type_init(struct mmc *mmc)
{
int rc;
@@ -2140,7 +2140,7 @@ static int sdmmc_wait_for_card_ready(struct mmc *mmc, uint32_t timeout)
static int sdmmc_switch_mode(struct mmc *mmc, enum sdmmc_switch_access_mode mode, enum sdmmc_switch_field field, uint16_t value, uint32_t timeout)
{
// Collapse our various parameters into a single argument.
uint32_t argument =
uint32_t argument =
(mode << MMC_SWITCH_ACCESS_MODE_SHIFT) |
(field << MMC_SWITCH_FIELD_SHIFT) |
(value << MMC_SWITCH_VALUE_SHIFT);
@@ -2205,7 +2205,7 @@ static void sdmmc_initialize_defaults(struct mmc *mmc)
break;
default:
printk("ERROR: initialization not yet writen for SDMMC%d", mmc->controller);
printf("ERROR: initialization not yet writen for SDMMC%d", mmc->controller);
break;
}
}