forked from Imagelibrary/rtems
arm/gp32/smc/smc.c: Fix warnings and clean up
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
/* smc.c -- s3c2400 smc disk block device implementation
|
/*
|
||||||
|
* s3c2400 smc disk block device implementation
|
||||||
Squidge's SMC Low-level access routines.
|
*
|
||||||
Inspired and derived from routines provided by Samsung Electronics M/M R&D Center & FireFly.
|
* Squidge's SMC Low-level access routines.
|
||||||
|
* Inspired and derived from routines provided by Samsung Electronics
|
||||||
*/
|
* M/M R&D Center & FireFly.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <rtems.h>
|
#include <rtems.h>
|
||||||
#include <rtems/libio.h>
|
#include <rtems/libio.h>
|
||||||
@@ -49,8 +50,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Internal SMC disk descriptor */
|
/* Internal SMC disk descriptor */
|
||||||
struct SMC_INFO
|
struct SMC_INFO {
|
||||||
{
|
|
||||||
uint8_t id[3];
|
uint8_t id[3];
|
||||||
uint32_t bytes_per_page;
|
uint32_t bytes_per_page;
|
||||||
uint32_t pages_per_block;
|
uint32_t pages_per_block;
|
||||||
@@ -112,7 +112,7 @@ static uint8_t sm_read(void)
|
|||||||
returns 1 on success, 0 on fail
|
returns 1 on success, 0 on fail
|
||||||
*/
|
*/
|
||||||
#if UNUSED
|
#if UNUSED
|
||||||
static uint8_t sm_status()
|
static static uint8_t sm_status()
|
||||||
{
|
{
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
@@ -133,9 +133,8 @@ static uint8_t sm_status()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void smc_read_id( uint8_t* buf, uint32_t length)
|
static void smc_read_id( uint8_t* buf, uint32_t length)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
sm_chip_en();
|
sm_chip_en();
|
||||||
@@ -160,7 +159,7 @@ void smc_read_id( uint8_t* buf, uint32_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* read an entire logical page of 512 bytes.*/
|
/* read an entire logical page of 512 bytes.*/
|
||||||
uint8_t smc_read_page (uint32_t lpage, uint8_t* buf)
|
static uint8_t smc_read_page (uint32_t lpage, uint8_t* buf)
|
||||||
{
|
{
|
||||||
uint32_t block, page, i;
|
uint32_t block, page, i;
|
||||||
|
|
||||||
@@ -188,15 +187,15 @@ uint8_t smc_read_page (uint32_t lpage, uint8_t* buf)
|
|||||||
sm_write( 0x00);
|
sm_write( 0x00);
|
||||||
sm_write( (uint8_t)(page >> 0));
|
sm_write( (uint8_t)(page >> 0));
|
||||||
sm_write( (uint8_t)(page >> 8));
|
sm_write( (uint8_t)(page >> 8));
|
||||||
if (smc_info.mb >= 64) sm_write( (uint8_t)(page >> 16));
|
if (smc_info.mb >= 64)
|
||||||
|
sm_write( (uint8_t)(page >> 16));
|
||||||
sm_write_dis();
|
sm_write_dis();
|
||||||
sm_ale_dis();
|
sm_ale_dis();
|
||||||
|
|
||||||
sm_busy();
|
sm_busy();
|
||||||
|
|
||||||
sm_read_en();
|
sm_read_en();
|
||||||
for (i = 0; i < 512; i++)
|
for (i = 0; i < 512; i++) {
|
||||||
{
|
|
||||||
*buf = sm_read();
|
*buf = sm_read();
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
@@ -207,11 +206,10 @@ uint8_t smc_read_page (uint32_t lpage, uint8_t* buf)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void smc_read_spare( uint32_t page, uint8_t* buf, uint8_t length)
|
static void smc_read_spare( uint32_t page, uint8_t* buf, uint8_t length)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
|
||||||
sm_chip_en();
|
sm_chip_en();
|
||||||
|
|
||||||
sm_cle_en();
|
sm_cle_en();
|
||||||
@@ -225,21 +223,23 @@ void smc_read_spare( uint32_t page, uint8_t* buf, uint8_t length)
|
|||||||
sm_write( 0x00);
|
sm_write( 0x00);
|
||||||
sm_write( (uint8_t)(page >> 0));
|
sm_write( (uint8_t)(page >> 0));
|
||||||
sm_write( (uint8_t)(page >> 8));
|
sm_write( (uint8_t)(page >> 8));
|
||||||
if (smc_info.mb >= 64) sm_write( (uint8_t)(page >> 16));
|
if (smc_info.mb >= 64)
|
||||||
|
sm_write( (uint8_t)(page >> 16));
|
||||||
sm_read_en();
|
sm_read_en();
|
||||||
sm_ale_dis();
|
sm_ale_dis();
|
||||||
|
|
||||||
sm_busy();
|
sm_busy();
|
||||||
|
|
||||||
sm_read_en();
|
sm_read_en();
|
||||||
for (i=0;i<length;i++) *(buf+i) = sm_read();
|
for (i=0;i<length;i++)
|
||||||
|
*(buf+i) = sm_read();
|
||||||
sm_read_dis();
|
sm_read_dis();
|
||||||
|
|
||||||
sm_chip_dis();
|
sm_chip_dis();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void smc_make_l2p(void)
|
static void smc_make_l2p(void)
|
||||||
{
|
{
|
||||||
uint32_t pblock, i, j, lblock, zone, count, cnt1, cnt2, cnt3;
|
uint32_t pblock, i, j, lblock, zone, count, cnt1, cnt2, cnt3;
|
||||||
uint8_t data[512];
|
uint8_t data[512];
|
||||||
@@ -248,38 +248,30 @@ void smc_make_l2p(void)
|
|||||||
cnt2 = 0;
|
cnt2 = 0;
|
||||||
cnt3 = 0;
|
cnt3 = 0;
|
||||||
|
|
||||||
for (i=0;i<0x2000;i++)
|
for (i=0;i<0x2000;i++) {
|
||||||
{
|
|
||||||
smc_l2p[i] = LBA_RESERVED;
|
smc_l2p[i] = LBA_RESERVED;
|
||||||
smc_p2l[i] = BLOCK_RESERVED;
|
smc_p2l[i] = BLOCK_RESERVED;
|
||||||
}
|
}
|
||||||
for (pblock=0;pblock<smc_info.blocks;pblock++)
|
|
||||||
{
|
for (pblock=0;pblock<smc_info.blocks;pblock++) {
|
||||||
/* read physical block - first page */
|
/* read physical block - first page */
|
||||||
smc_read_spare( pblock*smc_info.pages_per_block, (uint8_t*)&data, 16);
|
smc_read_spare( pblock*smc_info.pages_per_block, (uint8_t*)&data, 16);
|
||||||
|
|
||||||
zone = pblock >> 10; /* divide by 1024 to get zone */
|
zone = pblock >> 10; /* divide by 1024 to get zone */
|
||||||
if ((data[5] == 0xFF) && ((data[6]&0xF8) == 0x10))
|
if ((data[5] == 0xFF) && ((data[6]&0xF8) == 0x10)) {
|
||||||
{
|
|
||||||
lblock = ((((data[6]<<8)|(data[7]<<0)) >> 1) & 0x03FF) + (zone * 1000);
|
lblock = ((((data[6]<<8)|(data[7]<<0)) >> 1) & 0x03FF) + (zone * 1000);
|
||||||
smc_l2p[lblock] = pblock;
|
smc_l2p[lblock] = pblock;
|
||||||
smc_p2l[pblock] = lblock;
|
smc_p2l[pblock] = lblock;
|
||||||
cnt1++;
|
cnt1++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
count = 0;
|
count = 0;
|
||||||
for (j=0;j<16;j++)
|
for (j=0;j<16;j++) {
|
||||||
{
|
|
||||||
if (data[j] == 0xFF) count++;
|
if (data[j] == 0xFF) count++;
|
||||||
}
|
}
|
||||||
if (count == 16)
|
if (count == 16) {
|
||||||
{
|
|
||||||
smc_p2l[pblock] = BLOCK_UNUSED;
|
smc_p2l[pblock] = BLOCK_UNUSED;
|
||||||
cnt2++;
|
cnt2++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
smc_p2l[pblock] = BLOCK_RESERVED;
|
smc_p2l[pblock] = BLOCK_RESERVED;
|
||||||
cnt3++;
|
cnt3++;
|
||||||
}
|
}
|
||||||
@@ -288,7 +280,7 @@ void smc_make_l2p(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void smc_detect( uint8_t id1, uint8_t id2, uint8_t id3)
|
static void smc_detect( uint8_t id1, uint8_t id2, uint8_t id3)
|
||||||
{
|
{
|
||||||
smc_info.id[0] = id1;
|
smc_info.id[0] = id1;
|
||||||
smc_info.id[1] = id2;
|
smc_info.id[1] = id2;
|
||||||
@@ -298,13 +290,10 @@ void smc_detect( uint8_t id1, uint8_t id2, uint8_t id3)
|
|||||||
smc_info.pages_per_block = 0;
|
smc_info.pages_per_block = 0;
|
||||||
smc_info.blocks = 0;
|
smc_info.blocks = 0;
|
||||||
|
|
||||||
switch (id1)
|
switch (id1) {
|
||||||
{
|
|
||||||
case SMC_SAMSUNG_ID:
|
case SMC_SAMSUNG_ID:
|
||||||
case SMC_TOSHIBA_ID:
|
case SMC_TOSHIBA_ID: {
|
||||||
{
|
switch (id2) {
|
||||||
switch (id2)
|
|
||||||
{
|
|
||||||
case SMC_16MB : smc_info.mb = 16; break;
|
case SMC_16MB : smc_info.mb = 16; break;
|
||||||
case SMC_32MB : smc_info.mb = 32; break;
|
case SMC_32MB : smc_info.mb = 32; break;
|
||||||
case SMC_64MB : smc_info.mb = 64; break;
|
case SMC_64MB : smc_info.mb = 64; break;
|
||||||
@@ -314,8 +303,7 @@ void smc_detect( uint8_t id1, uint8_t id2, uint8_t id3)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (smc_info.mb)
|
switch (smc_info.mb) {
|
||||||
{
|
|
||||||
case 16 : smc_info.bytes_per_page = 512; smc_info.pages_per_block = 32; smc_info.blocks = 0x0400; break;
|
case 16 : smc_info.bytes_per_page = 512; smc_info.pages_per_block = 32; smc_info.blocks = 0x0400; break;
|
||||||
case 32 : smc_info.bytes_per_page = 512; smc_info.pages_per_block = 32; smc_info.blocks = 0x0800; break;
|
case 32 : smc_info.bytes_per_page = 512; smc_info.pages_per_block = 32; smc_info.blocks = 0x0800; break;
|
||||||
case 64 : smc_info.bytes_per_page = 512; smc_info.pages_per_block = 32; smc_info.blocks = 0x1000; break;
|
case 64 : smc_info.bytes_per_page = 512; smc_info.pages_per_block = 32; smc_info.blocks = 0x1000; break;
|
||||||
@@ -323,7 +311,7 @@ void smc_detect( uint8_t id1, uint8_t id2, uint8_t id3)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void smc_init( void)
|
static void smc_init( void)
|
||||||
{
|
{
|
||||||
unsigned char buf[32];
|
unsigned char buf[32];
|
||||||
int i;
|
int i;
|
||||||
@@ -368,14 +356,12 @@ int sm_ECCEncode(const uint8_t * p_buf, uint8_t * p_ecc)
|
|||||||
uint8_t* paritr_ptr;
|
uint8_t* paritr_ptr;
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; ++i, ++paritr_ptr, ++p_buf)
|
for (i = 0; i < 256; ++i, ++paritr_ptr, ++p_buf) {
|
||||||
{
|
|
||||||
paritc ^= *p_buf;
|
paritc ^= *p_buf;
|
||||||
tmp = (*p_buf & 0xf0) >> 4;
|
tmp = (*p_buf & 0xf0) >> 4;
|
||||||
tmp2 = *p_buf & 0x0f;
|
tmp2 = *p_buf & 0x0f;
|
||||||
|
|
||||||
switch (tmp)
|
switch (tmp) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
case 3:
|
case 3:
|
||||||
case 5:
|
case 5:
|
||||||
@@ -416,80 +402,64 @@ int sm_ECCEncode(const uint8_t * p_buf, uint8_t * p_ecc)
|
|||||||
parit4_1 = parit7c ^ parit6c ^ parit5c ^ parit4c;
|
parit4_1 = parit7c ^ parit6c ^ parit5c ^ parit4c;
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; ++i, ++paritr_ptr)
|
for (i = 0; i < 256; ++i, ++paritr_ptr) {
|
||||||
{
|
|
||||||
sum ^= *paritr_ptr;
|
sum ^= *paritr_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 2, paritr_ptr += 2)
|
for (i = 0; i < 256; i += 2, paritr_ptr += 2) {
|
||||||
{
|
|
||||||
parit8_2 ^= *paritr_ptr;
|
parit8_2 ^= *paritr_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 4, paritr_ptr += 4)
|
for (i = 0; i < 256; i += 4, paritr_ptr += 4) {
|
||||||
{
|
|
||||||
parit16_2 ^= *paritr_ptr;
|
parit16_2 ^= *paritr_ptr;
|
||||||
parit16_2 ^= *(paritr_ptr + 1);
|
parit16_2 ^= *(paritr_ptr + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 8, paritr_ptr += 8)
|
for (i = 0; i < 256; i += 8, paritr_ptr += 8) {
|
||||||
{
|
for (j = 0; j <= 3; ++j) {
|
||||||
for (j = 0; j <= 3; ++j)
|
|
||||||
{
|
|
||||||
parit32_2 ^= *(paritr_ptr + j);
|
parit32_2 ^= *(paritr_ptr + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 16, paritr_ptr += 16)
|
for (i = 0; i < 256; i += 16, paritr_ptr += 16) {
|
||||||
{
|
for (j = 0; j <= 7; ++j) {
|
||||||
for (j = 0; j <= 7; ++j)
|
|
||||||
{
|
|
||||||
parit64_2 ^= *(paritr_ptr + j);
|
parit64_2 ^= *(paritr_ptr + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 32, paritr_ptr += 32)
|
for (i = 0; i < 256; i += 32, paritr_ptr += 32) {
|
||||||
{
|
for (j = 0; j <= 15; ++j) {
|
||||||
for (j = 0; j <= 15; ++j)
|
|
||||||
{
|
|
||||||
parit128_2 ^= *(paritr_ptr + j);
|
parit128_2 ^= *(paritr_ptr + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 64, paritr_ptr += 64)
|
for (i = 0; i < 256; i += 64, paritr_ptr += 64) {
|
||||||
{
|
for (j = 0; j <= 31; ++j) {
|
||||||
for (j = 0; j <= 31; ++j)
|
|
||||||
{
|
|
||||||
parit256_2 ^= *(paritr_ptr + j);
|
parit256_2 ^= *(paritr_ptr + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 128, paritr_ptr += 128)
|
for (i = 0; i < 256; i += 128, paritr_ptr += 128) {
|
||||||
{
|
for (j = 0; j <= 63; ++j) {
|
||||||
for (j = 0; j <= 63; ++j)
|
|
||||||
{
|
|
||||||
parit512_2 ^= *(paritr_ptr + j);
|
parit512_2 ^= *(paritr_ptr + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paritr_ptr = paritr;
|
paritr_ptr = paritr;
|
||||||
for (i = 0; i < 256; i += 256, paritr_ptr += 256)
|
for (i = 0; i < 256; i += 256, paritr_ptr += 256) {
|
||||||
{
|
for (j = 0; j <= 127; ++j) {
|
||||||
for (j = 0; j <= 127; ++j)
|
|
||||||
{
|
|
||||||
parit1024_2 ^= *(paritr_ptr + j);
|
parit1024_2 ^= *(paritr_ptr + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sum==0)
|
if (sum==0) {
|
||||||
{
|
|
||||||
parit1024_1 = parit1024_2;
|
parit1024_1 = parit1024_2;
|
||||||
parit512_1 = parit512_2;
|
parit512_1 = parit512_2;
|
||||||
parit256_1 = parit256_2;
|
parit256_1 = parit256_2;
|
||||||
@@ -498,9 +468,7 @@ int sm_ECCEncode(const uint8_t * p_buf, uint8_t * p_ecc)
|
|||||||
parit32_1 = parit32_2;
|
parit32_1 = parit32_2;
|
||||||
parit16_1 = parit16_2;
|
parit16_1 = parit16_2;
|
||||||
parit8_1 = parit8_2;
|
parit8_1 = parit8_2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
parit1024_1 = parit1024_2 ? 0 : 1;
|
parit1024_1 = parit1024_2 ? 0 : 1;
|
||||||
parit512_1 = parit512_2 ? 0 : 1;
|
parit512_1 = parit512_2 ? 0 : 1;
|
||||||
parit256_1 = parit256_2 ? 0 : 1;
|
parit256_1 = parit256_2 ? 0 : 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user