Commit 3272244c authored by Al Viro's avatar Al Viro Committed by Linus Torvalds

[PATCH] m68k: switch mac/misc.c to direct use of appropriate cuda/pmu/maciisi requests

kill ADBREQ_RAW use, replace adb_read_time(), etc.  with per-type variants,
eliminated remapping from pmu ones, fix the ifdefs (PMU->PMU68K)
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Cc: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b4290a23
...@@ -39,72 +39,163 @@ ...@@ -39,72 +39,163 @@
extern struct mac_booter_data mac_bi_data; extern struct mac_booter_data mac_bi_data;
static void (*rom_reset)(void); static void (*rom_reset)(void);
#ifdef CONFIG_ADB #ifdef CONFIG_ADB_CUDA
/* static long cuda_read_time(void)
* Return the current time as the number of seconds since January 1, 1904.
*/
static long adb_read_time(void)
{ {
volatile struct adb_request req; struct adb_request req;
long time; long time;
adb_request((struct adb_request *) &req, NULL, if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
ADBREQ_RAW|ADBREQ_SYNC, return 0;
2, CUDA_PACKET, CUDA_GET_TIME); while (!req.complete)
cuda_poll();
time = (req.reply[3] << 24) | (req.reply[4] << 16) time = (req.reply[3] << 24) | (req.reply[4] << 16)
| (req.reply[5] << 8) | req.reply[6]; | (req.reply[5] << 8) | req.reply[6];
return time - RTC_OFFSET; return time - RTC_OFFSET;
} }
/* static void cuda_write_time(long data)
* Set the current system time {
*/ struct adb_request req;
data += RTC_OFFSET;
if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
(data >> 24) & 0xFF, (data >> 16) & 0xFF,
(data >> 8) & 0xFF, data & 0xFF) < 0)
return;
while (!req.complete)
cuda_poll();
}
static void adb_write_time(long data) static __u8 cuda_read_pram(int offset)
{ {
volatile struct adb_request req; struct adb_request req;
if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
(offset >> 8) & 0xFF, offset & 0xFF) < 0)
return 0;
while (!req.complete)
cuda_poll();
return req.reply[3];
}
data += RTC_OFFSET; static void cuda_write_pram(int offset, __u8 data)
{
struct adb_request req;
if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
(offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
return;
while (!req.complete)
cuda_poll();
}
#else
#define cuda_read_time() 0
#define cuda_write_time(n)
#define cuda_read_pram NULL
#define cuda_write_pram NULL
#endif
#ifdef CONFIG_ADB_PMU68K
static long pmu_read_time(void)
{
struct adb_request req;
long time;
if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
return 0;
while (!req.complete)
pmu_poll();
adb_request((struct adb_request *) &req, NULL, time = (req.reply[0] << 24) | (req.reply[1] << 16)
ADBREQ_RAW|ADBREQ_SYNC, | (req.reply[2] << 8) | req.reply[3];
6, CUDA_PACKET, CUDA_SET_TIME, return time - RTC_OFFSET;
}
static void pmu_write_time(long data)
{
struct adb_request req;
data += RTC_OFFSET;
if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
(data >> 24) & 0xFF, (data >> 16) & 0xFF, (data >> 24) & 0xFF, (data >> 16) & 0xFF,
(data >> 8) & 0xFF, data & 0xFF); (data >> 8) & 0xFF, data & 0xFF) < 0)
return;
while (!req.complete)
pmu_poll();
} }
/* static __u8 pmu_read_pram(int offset)
* Get a byte from the NVRAM {
*/ struct adb_request req;
if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM,
(offset >> 8) & 0xFF, offset & 0xFF) < 0)
return 0;
while (!req.complete)
pmu_poll();
return req.reply[3];
}
static __u8 adb_read_pram(int offset) static void pmu_write_pram(int offset, __u8 data)
{ {
volatile struct adb_request req; struct adb_request req;
if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM,
(offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
return;
while (!req.complete)
pmu_poll();
}
#else
#define pmu_read_time() 0
#define pmu_write_time(n)
#define pmu_read_pram NULL
#define pmu_write_pram NULL
#endif
adb_request((struct adb_request *) &req, NULL, #ifdef CONFIG_ADB_MACIISI
ADBREQ_RAW|ADBREQ_SYNC, extern int maciisi_request(struct adb_request *req,
4, CUDA_PACKET, CUDA_GET_PRAM, void (*done)(struct adb_request *), int nbytes, ...);
(offset >> 8) & 0xFF, offset & 0xFF);
return req.reply[3]; static long maciisi_read_time(void)
{
struct adb_request req;
long time;
if (maciisi_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME))
return 0;
time = (req.reply[3] << 24) | (req.reply[4] << 16)
| (req.reply[5] << 8) | req.reply[6];
return time - RTC_OFFSET;
} }
/* static void maciisi_write_time(long data)
* Write a byte to the NVRAM {
*/ struct adb_request req;
data += RTC_OFFSET;
maciisi_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
(data >> 24) & 0xFF, (data >> 16) & 0xFF,
(data >> 8) & 0xFF, data & 0xFF);
}
static void adb_write_pram(int offset, __u8 data) static __u8 maciisi_read_pram(int offset)
{ {
volatile struct adb_request req; struct adb_request req;
if (maciisi_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
(offset >> 8) & 0xFF, offset & 0xFF))
return 0;
return req.reply[3];
}
adb_request((struct adb_request *) &req, NULL, static void maciisi_write_pram(int offset, __u8 data)
ADBREQ_RAW|ADBREQ_SYNC, {
5, CUDA_PACKET, CUDA_SET_PRAM, struct adb_request req;
(offset >> 8) & 0xFF, offset & 0xFF, maciisi_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
data); (offset >> 8) & 0xFF, offset & 0xFF, data);
} }
#endif /* CONFIG_ADB */ #else
#define maciisi_read_time() 0
#define maciisi_write_time(n)
#define maciisi_read_pram NULL
#define maciisi_write_pram NULL
#endif
/* /*
* VIA PRAM/RTC access routines * VIA PRAM/RTC access routines
...@@ -305,42 +396,55 @@ static void oss_shutdown(void) ...@@ -305,42 +396,55 @@ static void oss_shutdown(void)
static void cuda_restart(void) static void cuda_restart(void)
{ {
adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, struct adb_request req;
2, CUDA_PACKET, CUDA_RESET_SYSTEM); if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0)
return;
while (!req.complete)
cuda_poll();
} }
static void cuda_shutdown(void) static void cuda_shutdown(void)
{ {
adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, struct adb_request req;
2, CUDA_PACKET, CUDA_POWERDOWN); if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0)
return;
while (!req.complete)
cuda_poll();
} }
#endif /* CONFIG_ADB_CUDA */ #endif /* CONFIG_ADB_CUDA */
#ifdef CONFIG_ADB_PMU #ifdef CONFIG_ADB_PMU68K
void pmu_restart(void) void pmu_restart(void)
{ {
adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, struct adb_request req;
3, PMU_PACKET, PMU_SET_INTR_MASK, if (pmu_request(&req, NULL,
PMU_INT_ADB|PMU_INT_TICK); 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0)
return;
adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, while (!req.complete)
2, PMU_PACKET, PMU_RESET); pmu_poll();
if (pmu_request(&req, NULL, 1, PMU_RESET) < 0)
return;
while (!req.complete)
pmu_poll();
} }
void pmu_shutdown(void) void pmu_shutdown(void)
{ {
adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, struct adb_request req;
3, PMU_PACKET, PMU_SET_INTR_MASK, if (pmu_request(&req, NULL,
PMU_INT_ADB|PMU_INT_TICK); 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0)
return;
adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, while (!req.complete)
6, PMU_PACKET, PMU_SHUTDOWN, pmu_poll();
'M', 'A', 'T', 'T'); if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0)
return;
while (!req.complete)
pmu_poll();
} }
#endif /* CONFIG_ADB_PMU */ #endif
/* /*
*------------------------------------------------------------------- *-------------------------------------------------------------------
...@@ -351,21 +455,22 @@ void pmu_shutdown(void) ...@@ -351,21 +455,22 @@ void pmu_shutdown(void)
void mac_pram_read(int offset, __u8 *buffer, int len) void mac_pram_read(int offset, __u8 *buffer, int len)
{ {
__u8 (*func)(int) = NULL; __u8 (*func)(int);
int i; int i;
if (macintosh_config->adb_type == MAC_ADB_IISI || switch(macintosh_config->adb_type) {
macintosh_config->adb_type == MAC_ADB_PB1 || case MAC_ADB_IISI:
macintosh_config->adb_type == MAC_ADB_PB2 || func = maciisi_read_pram; break;
macintosh_config->adb_type == MAC_ADB_CUDA) { case MAC_ADB_PB1:
#ifdef CONFIG_ADB case MAC_ADB_PB2:
func = adb_read_pram; func = pmu_read_pram; break;
#else case MAC_ADB_CUDA:
return; func = cuda_read_pram; break;
#endif default:
} else {
func = via_read_pram; func = via_read_pram;
} }
if (!func)
return;
for (i = 0 ; i < len ; i++) { for (i = 0 ; i < len ; i++) {
buffer[i] = (*func)(offset++); buffer[i] = (*func)(offset++);
} }
...@@ -373,21 +478,22 @@ void mac_pram_read(int offset, __u8 *buffer, int len) ...@@ -373,21 +478,22 @@ void mac_pram_read(int offset, __u8 *buffer, int len)
void mac_pram_write(int offset, __u8 *buffer, int len) void mac_pram_write(int offset, __u8 *buffer, int len)
{ {
void (*func)(int, __u8) = NULL; void (*func)(int, __u8);
int i; int i;
if (macintosh_config->adb_type == MAC_ADB_IISI || switch(macintosh_config->adb_type) {
macintosh_config->adb_type == MAC_ADB_PB1 || case MAC_ADB_IISI:
macintosh_config->adb_type == MAC_ADB_PB2 || func = maciisi_write_pram; break;
macintosh_config->adb_type == MAC_ADB_CUDA) { case MAC_ADB_PB1:
#ifdef CONFIG_ADB case MAC_ADB_PB2:
func = adb_write_pram; func = pmu_write_pram; break;
#else case MAC_ADB_CUDA:
return; func = cuda_write_pram; break;
#endif default:
} else {
func = via_write_pram; func = via_write_pram;
} }
if (!func)
return;
for (i = 0 ; i < len ; i++) { for (i = 0 ; i < len ; i++) {
(*func)(offset++, buffer[i]); (*func)(offset++, buffer[i]);
} }
...@@ -408,7 +514,7 @@ void mac_poweroff(void) ...@@ -408,7 +514,7 @@ void mac_poweroff(void)
} else if (macintosh_config->adb_type == MAC_ADB_CUDA) { } else if (macintosh_config->adb_type == MAC_ADB_CUDA) {
cuda_shutdown(); cuda_shutdown();
#endif #endif
#ifdef CONFIG_ADB_PMU #ifdef CONFIG_ADB_PMU68K
} else if (macintosh_config->adb_type == MAC_ADB_PB1 } else if (macintosh_config->adb_type == MAC_ADB_PB1
|| macintosh_config->adb_type == MAC_ADB_PB2) { || macintosh_config->adb_type == MAC_ADB_PB2) {
pmu_shutdown(); pmu_shutdown();
...@@ -448,7 +554,7 @@ void mac_reset(void) ...@@ -448,7 +554,7 @@ void mac_reset(void)
} else if (macintosh_config->adb_type == MAC_ADB_CUDA) { } else if (macintosh_config->adb_type == MAC_ADB_CUDA) {
cuda_restart(); cuda_restart();
#endif #endif
#ifdef CONFIG_ADB_PMU #ifdef CONFIG_ADB_PMU68K
} else if (macintosh_config->adb_type == MAC_ADB_PB1 } else if (macintosh_config->adb_type == MAC_ADB_PB1
|| macintosh_config->adb_type == MAC_ADB_PB2) { || macintosh_config->adb_type == MAC_ADB_PB2) {
pmu_restart(); pmu_restart();
...@@ -588,20 +694,22 @@ int mac_hwclk(int op, struct rtc_time *t) ...@@ -588,20 +694,22 @@ int mac_hwclk(int op, struct rtc_time *t)
unsigned long now; unsigned long now;
if (!op) { /* read */ if (!op) { /* read */
if (macintosh_config->adb_type == MAC_ADB_II) { switch (macintosh_config->adb_type) {
case MAC_ADB_II:
case MAC_ADB_IOP:
now = via_read_time(); now = via_read_time();
} else break;
#ifdef CONFIG_ADB case MAC_ADB_IISI:
if ((macintosh_config->adb_type == MAC_ADB_IISI) || now = maciisi_read_time();
(macintosh_config->adb_type == MAC_ADB_PB1) || break;
(macintosh_config->adb_type == MAC_ADB_PB2) || case MAC_ADB_PB1:
(macintosh_config->adb_type == MAC_ADB_CUDA)) { case MAC_ADB_PB2:
now = adb_read_time(); now = pmu_read_time();
} else break;
#endif case MAC_ADB_CUDA:
if (macintosh_config->adb_type == MAC_ADB_IOP) { now = cuda_read_time();
now = via_read_time(); break;
} else { default:
now = 0; now = 0;
} }
...@@ -619,15 +727,20 @@ int mac_hwclk(int op, struct rtc_time *t) ...@@ -619,15 +727,20 @@ int mac_hwclk(int op, struct rtc_time *t)
now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec); t->tm_hour, t->tm_min, t->tm_sec);
if (macintosh_config->adb_type == MAC_ADB_II) { switch (macintosh_config->adb_type) {
via_write_time(now); case MAC_ADB_II:
} else if ((macintosh_config->adb_type == MAC_ADB_IISI) || case MAC_ADB_IOP:
(macintosh_config->adb_type == MAC_ADB_PB1) ||
(macintosh_config->adb_type == MAC_ADB_PB2) ||
(macintosh_config->adb_type == MAC_ADB_CUDA)) {
adb_write_time(now);
} else if (macintosh_config->adb_type == MAC_ADB_IOP) {
via_write_time(now); via_write_time(now);
break;
case MAC_ADB_CUDA:
cuda_write_time(now);
break;
case MAC_ADB_PB1:
case MAC_ADB_PB2:
pmu_write_time(now);
break;
case MAC_ADB_IISI:
maciisi_write_time(now);
} }
#endif #endif
} }
......
...@@ -294,6 +294,24 @@ static void maciisi_sync(struct adb_request *req) ...@@ -294,6 +294,24 @@ static void maciisi_sync(struct adb_request *req)
printk(KERN_ERR "maciisi_send_request: poll timed out!\n"); printk(KERN_ERR "maciisi_send_request: poll timed out!\n");
} }
int
maciisi_request(struct adb_request *req, void (*done)(struct adb_request *),
int nbytes, ...)
{
va_list list;
int i;
req->nbytes = nbytes;
req->done = done;
req->reply_expected = 0;
va_start(list, nbytes);
for (i = 0; i < nbytes; i++)
req->data[i++] = va_arg(list, int);
va_end(list);
return maciisi_send_request(req, 1);
}
/* Enqueue a request, and run the queue if possible */ /* Enqueue a request, and run the queue if possible */
static int static int
maciisi_write(struct adb_request* req) maciisi_write(struct adb_request* req)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment