nand_chip에대해...몇일전에 질문올렸었는데요...

jodmani1의 이미지

몇일전에 nand_chip에 대해 질문올렸었습니다....

소스를 비교해보며 몇가지 틀린부분을 고쳤습니다.(맞는지모르겠지만..ㅡㅡ;)
eccmode는 enum형 으로 선언되어 nand_chip구조체에 들어가있고
그외 data_buf같은 것들은 그냥 선언해 주었습니다....
헌데.....밑에 내용을 잘모르겠습니다.

//============2.6.11 nand.h============

/* Select the chip by setting nCE to low */
#define NAND_CTL_SETNCE 1
/* Deselect the chip by setting nCE to high */
#define NAND_CTL_CLRNCE 2
/* Select the command latch by setting CLE to high */
#define NAND_CTL_SETCLE 3
/* Deselect the command latch by setting CLE to low */
#define NAND_CTL_CLRCLE 4
/* Select the address latch by setting ALE to high */
#define NAND_CTL_SETALE 5
/* Deselect the address latch by setting ALE to low */
#define NAND_CTL_CLRALE 6
/* Set write protection by setting WP to high. Not used! */
#define NAND_CTL_SETWP 7
/* Clear write protection by setting WP to low. Not used! */
#define NAND_CTL_CLRWP 8

==============2.6.18 nand.h======================
/* Select the chip by setting nCE to low */
#define NAND_NCE 0x01
/* Select the command latch by setting CLE to high */
#define NAND_CLE 0x02
/* Select the address latch by setting ALE to high */
#define NAND_ALE 0x04

#define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
#define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
#define NAND_CTRL_CHANGE 0x80

2.6.11버전에서는 Deselect하는 부분이 define되어잇지만
2.6.18버전에서는 Deselect하는 부분이 없이 그밑에 |연산을 하는 매크로가 있습니다
#define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
#define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
이매크로가 Deselect 를 하는부분인가요??

dipole의 이미지

보시는 것처럼 Deselect 하는 부분과 CLE, ALE 콘트롤하는 부분이 함께 들어가 있습니다
실제 NAND 칩의 스펙상 CLE/ALE 신호가 인가될때에만 CE 가 활성화 되어 있으면 됩니다
아마 예전코드는 CE 인가하고 CLE/ALE 제어하고 CE 놔주고 뭐 그렇게 했었을 겁니다

너는 누구냐?

jodmani1의 이미지

먼저 답변감사드립니다~~
그렇다면 CLE/ALE 신호가 인가될때에만 CE 가 활성화 되어 있으면 된다면
NAND_CTRL_CLE 값이
1일경우는 nCE가 활성화
2일경우에는 CLE 비활성화
3일경우에는 CLE 활성화

NAND_CTRL_ALE 값이
4일경우에는 ALE 비활성화
5일경우에는 ALE 활성화
이렇다는 것이지요??

#define NAND_CTRL_CHANGE 0x80 이것은
만약 NAND_CTRL_CLE = 3이고
int ctrl = (NAND_CTRL_CLE | NAND_CTRL_CHANGE );이라면
CLE를 활성화로 바꿔라..... 뭐이런뜻인가요??
NAND_CTRL_CHANGE매크로가 그런것인가요??

dipole의 이미지

말씀하신 것이 대충 맞을 겁니다만... 그것은 물리적인 예가 아닌 소프트 코딩상에서의 의미입니다
물리적으로 nCE 는 선택일때가 LOW,
ALE/CLE 의 경우 선택일때가 HIGH 입니다
물론 보드구성에 맞게 포팅하시면 됩니다

아키텍쳐에 맞게 구성하시면 되는데 2.6.18 이라면
cmd_ctrl 포인터에 구성하신 보드에 맞는 ALE/CLE 콘트롤 관련 함수를 구성해 주시면 됩니다
예제는 drivers/mtd/nand 디렉토리에 보시면 여러가지 포팅예제를 쉽게 찾으실수 있습니다

너는 누구냐?

jodmani1의 이미지

답변감사합니다^^;

말씀하신대로 drivers/mtd/nand디렉토리에있는 여러 파일들을 찾아봤는데요..
제가 바꾸려하는 것은.....
static void jjong_hwcontrol0(struct mtd_info *mtd, int cmd){
if (&priv->mtd != mtd){ printk("not valid mtd\n"); return; }

switch (cmd){
case NAND_CTL_SETCLE:
nand_ctrl0 |= NAND0_CLE;
writeb(nand_ctrl0, priv->cmds_virt);
break;
case NAND_CTL_CLRCLE:
nand_ctrl0 &= ~NAND0_CLE;
writeb(nand_ctrl0, priv->cmds_virt);
break;
case NAND_CTL_SETALE:
nand_ctrl0 |= NAND0_ALE;
writeb(nand_ctrl0, priv->cmds_virt);
break;
case NAND_CTL_CLRALE:
nand_ctrl0 &= ~NAND0_ALE;
writeb(nand_ctrl0, priv->cmds_virt);
...............

이러한 코드를 2.6.18에있는
#define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
#define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
#define NAND_CTRL_CHANGE 0x80

위매크로로 수정하려고합니다....
비교하려고 찾아봤는데....대부분의 예제를 보면
함수에서 넘겨받는 매개변수 3개더군요;;;;

저는 void (*hwcontrol)(struct mtd_info *mtd, int cmd);

이함수 포인터에 위의 함수를 주소를 가르키게 하는 것인데....
platform_nand->hwcontrol = jjong_hwcontrol0

위 jjong_hwcontrol0함수에서 cmd값을 비교해서
writeb로 데이타를 써넣잖아요;;

아래는 drivers/mtd/nand에 있는 파일의 코드중 일부입니다.

static void spia_hwcontrol(struct mtd_info *mtd, int cmd)
{
struct nand_chip *chip = mtd->priv;

if (ctrl & NAND_CTRL_CHANGE) {
void __iomem *addr = spia_io_base + spia_pedr;
unsigned char bits;

bits = (ctrl & NAND_CNE) << 2;
bits |= (ctrl & NAND_CLE | NAND_ALE) >> 1;
writeb((readb(addr) & ~0x7) | bits, addr);
}
drivers/mtd/nand 대부분의 코들이 (물론 위경우를 제외하고는 매개변수가 3개인함수들이지만요...)
cmd를 비교하지않습니다......
spia_hwcontrol함수에서의 ctrl 변수는 선언된곳이 없고 ctag로 따라가보니...조이스틱 관련으로 나오는데....포인터변수ㅡㅡ;
그냥 jjong_hwcontrol0함수에서처럼 switch(cmd)로비교해도될런지...
질문이 넘길어졌네요..ㅜㅜ

dipole의 이미지

무엇을 해야 하느냐가 가장 중요합니다

mtd 에서 요구하는 것은 chip selection, ALE/CLE 제어
IO_ADDR 메모리 포인터입니다

select_chip 에 하드웨어적으로 여러개의 nand 인터페이스가 붙을수 있으므로
원하는 nand 플래쉬를 선택할수 있는 코드를 넣으시면 되고 없으면 포인팅을 안하시면 됩니다

IO_ADDR_R 와 IO_ADDR_W 에 관련된 메모리 포인터를 넣어 주시면 되구요

cmd_ctrl 에는 CLE/ALE 제어 관련된 코드를 넣어 주시면 됩니다
cmd 에 따라서 제어를 할것이냐 말것이냐는 cmd 가 무엇을 의미하는지 파악해야 합니다
cmd 의 인자는 CLE/ALE 중 무엇을 어떻게 제어 할것이냐를 의미합니다

static void cmd_control(struct mtd_info *mtd, int dat, unsigned int ctrl)
{
register struct nand_chip *this = mtd->priv;
register unsigned long NAND_IO_ADDR = (unsigned long)this->IO_ADDR_W;

if(ctrl == NAND_CMD_NONE)
return;

if(ctrl & NAND_CLE) {
writeb(dat, NAND_IO_ADDR + NAND_CMD );
}

if(ctrl & NAND_ALE) {
writeb(dat, NAND_IO_ADDR + NAND_ADDR);
}
}

저희 보드에 포팅된 코드입니다
select_chip 를 해주는 부분은 하드웨어적으로 되어 있으니 논외구요
위 코드는 cmd_ctrl 에 들어가는 함수입니다
위코드는 하드웨어 특성에 따라 다를수 있습니다만 간단하게 CLE 제어냐 ALE 제어냐에 따라 동작하는 코드만 있습니다
저희 하드웨어는 ALE/CLE 엑세스시에 CE 가 자동으로 인가가 되도록 구성이 되어 있기 때문에 위에서 처럼 간단합니다

실제 nand_base 파일에는 여러가지 경우를 고려한 함수들이 있지만 chip_select 함수와 cmd_ctrl 함수를 직접 구성해
주신다면 실제 동작하는 함수들은 위의 정도만 처리해도 충분합니다

점심시간이네요 맛난 밥먹으러 고고~

너는 누구냐?

jodmani1의 이미지

친절한 답변감사드려요^^
많은 도움이 됐습니다.^^
감사합니다.~~

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.