1.1 --- a/pkg/landfall-examples/msc_block_server/msc_block_server.cc Tue Apr 30 01:37:52 2024 +0200
1.2 +++ b/pkg/landfall-examples/msc_block_server/msc_block_server.cc Tue Apr 30 01:44:00 2024 +0200
1.3 @@ -21,6 +21,7 @@
1.4
1.5 #include <l4/devices/cpm-generic.h>
1.6 #include <l4/devices/dma-generic.h>
1.7 +#include <l4/devices/gpio-generic.h>
1.8 #include <l4/devices/memory.h>
1.9 #include <l4/devices/msc-generic.h>
1.10
1.11 @@ -104,6 +105,7 @@
1.12
1.13 static Cpm_chip *cpm;
1.14 static Dma_chip *dma;
1.15 +static Hw::Gpio_chip *gpio;
1.16 static Msc_chip *msc;
1.17
1.18 /* Obtain an abstraction for the memory card. */
1.19 @@ -116,6 +118,7 @@
1.20 char resource[strlen(machine) + 8];
1.21 l4_addr_t cpm_base = 0, cpm_base_end = 0;
1.22 l4_addr_t dma_base = 0, dma_base_end = 0;
1.23 + l4_addr_t gpio_base = 0, gpio_base_end = 0;
1.24 l4_addr_t msc_base = 0, msc_base_end = 0;
1.25 l4_addr_t msc_phys_base = 0, msc_phys_base_end = 0;
1.26 l4_uint32_t dma_irq_start = 0, dma_irq_end = 0;
1.27 @@ -149,6 +152,11 @@
1.28
1.29 dma->enable();
1.30
1.31 + sprintf(resource, "%s-gpio", machine);
1.32 +
1.33 + if (get_memory(resource, &gpio_base, &gpio_base_end) < 0)
1.34 + return NULL;
1.35 +
1.36 sprintf(resource, "%s-msc", machine);
1.37
1.38 if (get_memory_complete(resource, &msc_base, &msc_base_end,
1.39 @@ -168,6 +176,39 @@
1.40 Dma_channel *dma_channel = dma->get_channel(dma_channel_num, dma_irq);
1.41 Msc_channel *msc_channel = msc->get_channel(msc_channel_num, msc_irq, dma_channel);
1.42
1.43 + /* Configure the memory card peripheral clock.
1.44 + NOTE: This needs to be parameterised. */
1.45 +
1.46 + enum Clock_identifiers clocks[] = {Clock_msc0, Clock_msc1, Clock_msc2};
1.47 +
1.48 + /* Configure the GPIO pins.
1.49 + NOTE: This needs to be parameterised and to use a more abstract interface. */
1.50 +
1.51 + if (!strcmp(machine, "jz4780"))
1.52 + {
1.53 + cpm->set_frequency(clocks[msc_channel_num], 50000000);
1.54 + gpio = new_gpio_chip(machine, gpio_base, 4);
1.55 + gpio->config_pad(20, Hw::Gpio_chip::Function_alt, 0);
1.56 + gpio->config_pad(21, Hw::Gpio_chip::Function_alt, 0);
1.57 + gpio->config_pad(22, Hw::Gpio_chip::Function_alt, 0);
1.58 + gpio->config_pad(23, Hw::Gpio_chip::Function_alt, 0);
1.59 + gpio->config_pad(28, Hw::Gpio_chip::Function_alt, 0);
1.60 + gpio->config_pad(29, Hw::Gpio_chip::Function_alt, 0);
1.61 + }
1.62 + else if (!strcmp(machine, "x1600"))
1.63 + {
1.64 + cpm->set_frequency(clocks[msc_channel_num], 25000000);
1.65 + gpio = new_gpio_chip(machine, gpio_base, 2);
1.66 + gpio->config_pad(17, Hw::Gpio_chip::Function_alt, 1);
1.67 + gpio->config_pad(18, Hw::Gpio_chip::Function_alt, 1);
1.68 + gpio->config_pad(19, Hw::Gpio_chip::Function_alt, 1);
1.69 + gpio->config_pad(20, Hw::Gpio_chip::Function_alt, 1);
1.70 + gpio->config_pad(21, Hw::Gpio_chip::Function_alt, 1);
1.71 + gpio->config_pad(22, Hw::Gpio_chip::Function_alt, 1);
1.72 + }
1.73 +
1.74 + /* Attempt to enable the memory card peripheral. */
1.75 +
1.76 msc_channel->enable();
1.77
1.78 if (card >= msc_channel->num_cards())