Skip to content

Commit

Permalink
zynq7000: add platformctl for setting SD card pins
Browse files Browse the repository at this point in the history
JIRA: RTOS-630
  • Loading branch information
jmaksymowicz committed Oct 20, 2023
1 parent 9edeea5 commit 25a18c8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
39 changes: 39 additions & 0 deletions hal/armv7a/zynq7000/zynq.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,37 @@ static void zynq_softRst(void)
}


static int _zynq_setSDWpCd(char dev, unsigned char wpPin, unsigned char cdPin)
{
if ((dev != 0) && (dev != 1)) {
return -1;
}

if ((cdPin > 63) || (wpPin > 63)) {
return -1;
}

_zynq_slcrUnlock();
*(zynq_common.slcr + slcr_sd0_wp_cd_sel + dev) = ((u32)cdPin << 16) | (wpPin);
_zynq_slcrLock();
return 0;
}


static int _zynq_getSDWpCd(char dev, unsigned char *wpPin, unsigned char *cdPin)
{
u32 val = 0;
if ((dev != 0) && (dev != 1)) {
return -1;
}

val = *(zynq_common.slcr + slcr_sd0_wp_cd_sel + dev);
*wpPin = val & 0x3f;
*cdPin = (val >> 16) & 0x3f;
return 0;
}


void hal_cpuReboot(void)
{
zynq_softRst();
Expand Down Expand Up @@ -597,6 +628,14 @@ int hal_platformctl(void *ptr)
zynq_softRst();
break;

case pctl_sdwpcd:
if (data->action == pctl_set) {
ret = _zynq_setSDWpCd(data->SDWpCd.dev, data->SDWpCd.wpPin, data->SDWpCd.cdPin);
}
else { /* data->action == pctl_get */
ret = _zynq_getSDWpCd(data->SDWpCd.dev, &data->SDWpCd.wpPin, &data->SDWpCd.cdPin);
}

default:
break;
}
Expand Down
11 changes: 10 additions & 1 deletion include/arch/zynq7000.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef _PHOENIX_ARCH_ZYNQ7000_H_
#define _PHOENIX_ARCH_ZYNQ7000_H_

/* clang-format off */

/* AMBA peripherals */
enum {
Expand Down Expand Up @@ -52,8 +53,10 @@ enum {

typedef struct {
enum { pctl_set = 0, pctl_get } action;
enum { pctl_ambaclock = 0, pctl_devclock, pctl_mioclock, pctl_mio, pctl_devreset, pctl_reboot } type;
enum { pctl_ambaclock = 0, pctl_devclock, pctl_mioclock,
pctl_mio, pctl_devreset, pctl_reboot, pctl_sdwpcd } type;

/* clang-format on */
union {
struct {
int dev;
Expand Down Expand Up @@ -99,6 +102,12 @@ typedef struct {
unsigned int magic;
unsigned int reason;
} reboot;

struct {
char dev;
unsigned char wpPin;
unsigned char cdPin;
} SDWpCd;
};
} __attribute__((packed)) platformctl_t;

Expand Down

0 comments on commit 25a18c8

Please sign in to comment.