Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zynq7000: add platformctl for setting SD card pins #465

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading