2.1 --- a/pkg/landfall-examples/msc_block_server/msc_block_server.cc Tue Apr 30 01:37:52 2024 +0200
2.2 +++ b/pkg/landfall-examples/msc_block_server/msc_block_server.cc Tue Apr 30 01:44:00 2024 +0200
2.3 @@ -21,6 +21,7 @@
2.4
2.5 #include <l4/devices/cpm-generic.h>
2.6 #include <l4/devices/dma-generic.h>
2.7 +#include <l4/devices/gpio-generic.h>
2.8 #include <l4/devices/memory.h>
2.9 #include <l4/devices/msc-generic.h>
2.10
2.11 @@ -104,6 +105,7 @@
2.12
2.13 static Cpm_chip *cpm;
2.14 static Dma_chip *dma;
2.15 +static Hw::Gpio_chip *gpio;
2.16 static Msc_chip *msc;
2.17
2.18 /* Obtain an abstraction for the memory card. */
2.19 @@ -116,6 +118,7 @@
2.20 char resource[strlen(machine) + 8];
2.21 l4_addr_t cpm_base = 0, cpm_base_end = 0;
2.22 l4_addr_t dma_base = 0, dma_base_end = 0;
2.23 + l4_addr_t gpio_base = 0, gpio_base_end = 0;
2.24 l4_addr_t msc_base = 0, msc_base_end = 0;
2.25 l4_addr_t msc_phys_base = 0, msc_phys_base_end = 0;
2.26 l4_uint32_t dma_irq_start = 0, dma_irq_end = 0;
2.27 @@ -149,6 +152,11 @@
2.28
2.29 dma->enable();
2.30
2.31 + sprintf(resource, "%s-gpio", machine);
2.32 +
2.33 + if (get_memory(resource, &gpio_base, &gpio_base_end) < 0)
2.34 + return NULL;
2.35 +
2.36 sprintf(resource, "%s-msc", machine);
2.37
2.38 if (get_memory_complete(resource, &msc_base, &msc_base_end,
2.39 @@ -168,6 +176,39 @@
2.40 Dma_channel *dma_channel = dma->get_channel(dma_channel_num, dma_irq);
2.41 Msc_channel *msc_channel = msc->get_channel(msc_channel_num, msc_irq, dma_channel);
2.42
2.43 + /* Configure the memory card peripheral clock.
2.44 + NOTE: This needs to be parameterised. */
2.45 +
2.46 + enum Clock_identifiers clocks[] = {Clock_msc0, Clock_msc1, Clock_msc2};
2.47 +
2.48 + /* Configure the GPIO pins.
2.49 + NOTE: This needs to be parameterised and to use a more abstract interface. */
2.50 +
2.51 + if (!strcmp(machine, "jz4780"))
2.52 + {
2.53 + cpm->set_frequency(clocks[msc_channel_num], 50000000);
2.54 + gpio = new_gpio_chip(machine, gpio_base, 4);
2.55 + gpio->config_pad(20, Hw::Gpio_chip::Function_alt, 0);
2.56 + gpio->config_pad(21, Hw::Gpio_chip::Function_alt, 0);
2.57 + gpio->config_pad(22, Hw::Gpio_chip::Function_alt, 0);
2.58 + gpio->config_pad(23, Hw::Gpio_chip::Function_alt, 0);
2.59 + gpio->config_pad(28, Hw::Gpio_chip::Function_alt, 0);
2.60 + gpio->config_pad(29, Hw::Gpio_chip::Function_alt, 0);
2.61 + }
2.62 + else if (!strcmp(machine, "x1600"))
2.63 + {
2.64 + cpm->set_frequency(clocks[msc_channel_num], 25000000);
2.65 + gpio = new_gpio_chip(machine, gpio_base, 2);
2.66 + gpio->config_pad(17, Hw::Gpio_chip::Function_alt, 1);
2.67 + gpio->config_pad(18, Hw::Gpio_chip::Function_alt, 1);
2.68 + gpio->config_pad(19, Hw::Gpio_chip::Function_alt, 1);
2.69 + gpio->config_pad(20, Hw::Gpio_chip::Function_alt, 1);
2.70 + gpio->config_pad(21, Hw::Gpio_chip::Function_alt, 1);
2.71 + gpio->config_pad(22, Hw::Gpio_chip::Function_alt, 1);
2.72 + }
2.73 +
2.74 + /* Attempt to enable the memory card peripheral. */
2.75 +
2.76 msc_channel->enable();
2.77
2.78 if (card >= msc_channel->num_cards())