0.å°å ¥ãã代ããã«
ãã®èšäºã¯äœã§ããïŒ
ãã®èšäºã¯ãããŸããŸãªãœãŒã¹ããã®æ å ±ããŸãšãããã®ã§ãããããã¥ã¡ã³ãã®äžéšãç¡æã§ç¿»èš³ãããã®ã§ãããŸããç§èªèº«ã®ã³ã¡ã³ããè¿œå ãçºçããåé¡ã®èª¬æãæ²èŒããŠããŸãã
ãã®èšäºã®å¯Ÿè±¡è
ãŸã第äžã«ãç§ã¯åå¿è åãã§ãã çµã¿èŸŒã¿Linuxãã©ãŒã©ã ã§ã¯ãããã®ããŒãã§SPIãæäœããæ¹æ³ã¯ïŒããšãã質åãèŠã€ããããšãã§ããŸãã ç§ãçããããšããã®ã¯åœŒã«ãšã£ãŠã§ãã äŸãšããŠããã¹ãSPIããã€ã¹ã§åäœããããã«èšè¿°ãããã³ãŒããæäŸããŸãã
èšäºã®æ§é
å€ãã®æ å ±ããã£ãããããã®èšäºã¯ããã€ãã®ã»ã¯ã·ã§ã³ã«åãããŠããŸãã
- SPIãšã¯äœã§ããïŒ
- Linux SPIãµãã·ã¹ãã ã®æŠèŠ
- spidevã䜿çšãããŠãŒã¶ãŒç©ºéãããã³ã«SPIãã©ã€ããŒã®éçº
- ã«ãŒãã«ã¬ãã«ã®ãããã³ã«SPIãã©ã€ããŒã®éçº
- ããã¥ã¡ã³ã
æåã®2ã€ã®æ®µèœã¯èšäºã®æåã®éšåã«å«ãŸããæ®ãã¯2çªç®ã®éšåã«å«ãŸããŸãã
æåã®ãµãã»ã¯ã·ã§ã³ã§ã¯SPIãã¹ã®åäœã«ã€ããŠèª¬æããŸããèšäºã®ãã®éšåã¯ç¹ã«Linuxã«çµã³ä»ããããŠããªããããLinuxã«èå³ããªã人ã§ãèªãããšãã§ããŸããããã®ã€ã³ã¿ãŒãã§ãŒã¹ã«é¢ããæ å ±ãååŸããã ãã§ããŸããŸããã
2çªç®ã®ãµãã»ã¯ã·ã§ã³ã§ã¯ãLinuxã§SPIã䜿çšããåºç€ãšãªãæ§é ãšã¡ã«ããºã ã«ã€ããŠèª¬æããŸã; 3çªç®ãš4çªç®ã®ããŒãã§èª¬æããå 容ãç解ããããã«èªãå¿ èŠããããŸãã
翻蚳ãè¿œå ã«èå³ããªãå Žåã¯ãããã«5çªç®ã®ã»ã¯ã·ã§ã³ã«é²ãã§ãã ãããããã§ã¯ããã®åé¡ã«é¢ããå¿ èŠãªæ å ±ããã¹ãŠå ¥æã§ããå Žæã«é¢ããæ å ±ãèŠã€ããããšãã§ããŸãã
æ§é ãŸãã¯é¢æ°ã®ååã«ãªã³ã¯ã衚瀺ãããŠããå Žåãæ°ããã¿ãã§éãããšãã§ãããããLinuxã«ãŒãã«ã®å ¬åŒããã¥ã¡ã³ãã§ãã®æ§é /é¢æ°ã®èª¬æã«çŽæ¥ã¢ã¯ã»ã¹ã§ããŸãã
ééã
ç§ã¯éè¡åž«ã§ã¯ãããŸããããã å匷ããŠããŸãã ãšã©ãŒãäžæ£ç¢ºãªç¹ãèŠã€ããå Žåã¯ããç¥ãããã ããã
1. SPIãšã¯äœã§ããïŒ
SPIãšããç¥èªã¯ããã·ãªã¢ã«ããªãã§ã©ã«ã€ã³ã¿ãŒãã§ãŒã¹ããŸãã¯ãã·ã¢èªçã§ã¯ãã·ãªã¢ã«ããªãã§ã©ã«ã€ã³ã¿ãŒãã§ãŒã¹ããæå³ããŸãã ååã¯ããèªäœãç©èªã£ãŠããŸãããã®ã€ã³ã¿ãŒãã§ã€ã¹ã¯ãããŸããŸãªåšèŸºæ©åšãæäœããããã«äœ¿çšãããŸãã ããšãã°ãããŸããŸãªDAC / ADCãããã³ã·ã§ã¡ãŒã¿ãã»ã³ãµãŒãå ¥åºåããŒããšã¯ã¹ãã³ãïŒGPIOïŒãããŸããŸãªã¡ã¢ãªãããã«ã¯ãªãŒãã£ãªã³ãŒããã¯ãã€ãŒãµãããã³ã³ãããŒã©ãªã©ã®ããè€éãªåšèŸºæ©åšã䜿çšã§ããŸãã
æè¡çãªèŠ³ç¹ããèŠããšãSPIã¯åæ4ç·åŒãã¹ã§ãã ããã¯ã2ã€ã®åæã·ããã¬ãžã¹ã¿ã®æ¥ç¶ã§ãããSPIããã€ã¹ã®äžå¿çãªèŠçŽ ã§ãã æ¥ç¶ã¯ãã¹ã¿ãŒ/ã¹ã¬ãŒãæ§æã䜿çšããŸãã ãã¹ã¿ãŒã®ã¿ãåæãã«ã¹ãçæã§ããŸãã åè·¯ã«ã¯åžžã«1ã€ã®ãã¹ã¿ãŒãããããŸããïŒè€æ°ã®ãã¹ã¿ãŒã䜿çšã§ãããªãã·ã§ã³ãããåãI2Cãã¹ãšã¯ç°ãªãïŒãã¹ã¬ãŒãã®æ°ã¯ç°ãªãå ŽåããããŸãã äžè¬çãªå Žåããã¹ã¿ãŒã®åºåã¯ã¹ã¬ãŒãã®å ¥åã«æ¥ç¶ãããéã®å Žåãã¹ã¬ãŒãã®åºåã¯ãã¹ã¿ãŒã®å ¥åã«æ¥ç¶ãããŸãã SCKåºåã«åæãã«ã¹ãé©çšãããšãããŒã¿ã¯ãã¹ã¿ãŒã«ãã£ãŠMOSIåºåããããã·ã¥ãããMISOå ¥åã§ã¹ã¬ãŒãã«ãã£ãŠãã£ããã£ãããŸãã ãããã£ãŠãã·ããã¬ãžã¹ã¿ã®å¹ ã«å¯Ÿå¿ããæ°ã®åæãã«ã¹ãéä¿¡ãããšãã¬ãžã¹ã¿å ã®ããŒã¿ãå Žæã亀æããŸãã SPIã¯åžžã«å šäºéã¢ãŒãã§åäœããŸãã ãã ãããã©ã¡ãŒã¿ãæžã蟌ããšãã«ããã€ã¹ããåä¿¡ããããŒã¿ãå¿ èŠãã©ããã¯å¥ã®åé¡ã§ãã ããã€ã¹ã«ããŒã¿ãæžã蟌ããšãã«ããã€ã¹ããåä¿¡ããããŒã¿ãã¬ããŒãžã§ããããšããããããŸãããã®å Žåããããã¯åã«ç¡èŠãããŸãããåžæã«é¢ä¿ãªãåä¿¡ããŸãã
SPIã³ã³ãããŒã©ãŒã¯éåžžãMCUãŸãã¯eMPUã®åšèŸºè£ 眮ã«ãã£ãŠå®è£ ãããŸãã ã»ãšãã©ã®ãããã§ã¯ããã¹ã¿ãŒã¢ãŒããšã¹ã¬ãŒãã¢ãŒãã®äž¡æ¹ã§åäœããŸãã ãããçŸæç¹ã§ã¯ãLinuxã¯ãã¹ã¿ãŒã¢ãŒãã®ã¿ããµããŒãããŠããŸãã
SPIããã€ã¹ãæå¹ã«ããæ¹æ³ã¯ããã€ããããŸãã
ããªããäžã®åçã§èŠããããã®æãåçŽãªãã®ïŒç¡æã®GFDLã©ã€ã»ã³ã¹ã®äžã®åçã«ã€ããŠã¯Wikipediaã«æè¬ããŸãïŒã ãã®å Žåãã¹ã¬ãŒãéžæä¿¡å·ïŒãCSïŒãé€ãããã¹ãŠã®ã¹ã¬ãŒãããã¹ã¿ãŒã«äžŠåã«æ¥ç¶ãããŸãã åã¹ã¬ãŒãã«ã¯åå¥ã®ã¹ã¬ãŒãéžæä¿¡å·ãå¿ èŠã§ãïŒå³ã§ã¯SSxãšããŠæå®ãããŠããŸãïŒã ã¹ã¬ãŒãéžæä¿¡å·ã®å Žåããã®ç®çã®ããã«ç¹å¥ã«èšèšãããSPIã³ã³ãããŒã©ãŒåºåãšããã€ã¯ãã³ã³ãããŒã©ãŒã®æ±çšå ¥åºåïŒGPIOïŒããŒãã®äž¡æ¹ã䜿çšã§ããŸãã
ããŒã¿äŒéã«ã¯2ã€ã®å°äœã䜿çšãããŸãã1ã€ã¯ã¯ããã¯ãã«ã¹ãäŸçµŠãããã1ã€ã¯åã¹ã¬ãŒãã®ã¹ã¬ãŒããéžæããããã®ä¿¡å·ã§ãã
䜿çšãããä¿¡å·ã®èª¬æïŒ
- MOSI-ãã¹ã¿ãŒåºåãã¹ã¬ãŒãå ¥åïŒãã¹ã¿ãŒåºåãã¹ã¬ãŒãå ¥åïŒã ãã®ä¿¡å·ã¯ããã¹ã¿ãŒããã¹ã¬ãŒããžã®ã·ãªã¢ã«ããŒã¿éä¿¡ãç®çãšããŠããŸãã SDOãDOãªã©ãšãåŒã°ããŸãã
- MISO-ãã¹ã¿ãŒå ¥åãã¹ã¬ãŒãåºåïŒãã¹ã¿ãŒå ¥åãã¹ã¬ãŒãåºåïŒã ãã®ä¿¡å·ã¯ãã¹ã¬ãŒããããã¹ã¿ãŒãžã®ã·ãªã¢ã«ããŒã¿éä¿¡ãç®çãšããŠããŸãã SDIãDIãªã©ãšåŒã°ããå ŽåããããŸãã
- SCK-ã·ãªã¢ã«ã¯ããã¯ã ããŒã¿è»¢éäžã®åæã«äœ¿çšãããŸãã SCLKãCLKãªã©ãšãåŒã°ããŸãã
- ãCS-ãããéžæïŒãããéžæïŒã ãã®ä¿¡å·ã«ãããã¹ã¬ãŒããã¢ã¯ãã£ãã«ãªããŸãã éåžžãããã¯éã§ããã€ãŸããäœã¬ãã«ã¯ã¢ã¯ãã£ããšèŠãªãããŸãã æã ããã¯ãSSïŒSlave Selectããã·ã¢èªã®ã奎é·ã®éžæãïŒãšåŒã°ããŸãã
ç¬ç«ããæ¥ç¶ã®ç¹æ®ãªã±ãŒã¹ã¯ãåäžã®ã¹ã¬ãŒããæã€ãªãã·ã§ã³ã§ãã ãã®å Žåãããã€ã¹ãåžžã«ã¢ã¯ãã£ãç¶æ ã«ãªãããã«ãCSä¿¡å·ãã°ã©ã³ãã«ãã«ããããšãã§ããŸãã ãã ããã¹ã¬ãŒãã¯åæåãŸãã¯ãã®ä»ã®ãµãŒãã¹ç®çã§CSä¿¡å·ã䜿çšã§ããããããããè¡ãããšã¯éåžžã«æšå¥šãããŸããã
ã¹ã¬ãŒãã®ç¬ç«ããæ¥ç¶ã®äž»ãªäžäŸ¿ã¯ãã¹ã¬ãŒãããšã«åå¥ã®ä¿¡å·ãCSãå¿ èŠãªããšã§ãã å€åœæåŠã§ããã€ãžãŒãã§ãŒã³ãïŒãã¬ãŒã©ã³ãããšç¿»èš³ã§ããïŒãšåŒã°ããã«ã¹ã±ãŒãæ¥ç¶ã¹ããŒã ã«ã¯ããã®ãããªæ¬ ç¹ããããŸããã
äžã®å³ãããããããã«ãããã§ã¯ãã¹ãŠã®ã¹ã¬ãŒãã«å ±éã®ã¹ã¬ãŒãéžæä¿¡å·ã䜿çšãããŠããŸãã åã¹ã¬ãŒãã®åºåã¯ã次ã®ã¹ã¬ãŒãã®å ¥åã«æ¥ç¶ãããŸãã æåŸã®ã¹ã¬ãŒãã®åºåã¯ãã¹ã¿ãŒã®å ¥åã«æ¥ç¶ãããŠãããããéåè·¯ã圢æããŸãã ãã®æ¥ç¶ã§ã¯ãçŽåæ¥ç¶ãããããã€ã¹ã1ã€ã®å€§ããªã·ããã¬ãžã¹ã¿ã圢æãããšä»®å®ã§ããŸãã ãããã£ãŠãå¿ èŠãªããã±ãŒãžãåéããåŸãæ¥ç¶ã®ç©ççãªé åºã«å¯Ÿå¿ããé åºã§åããã€ã¹ã®ããŒã¿ãçµã¿åãããŠããã¹ãŠã®ããã€ã¹ã«ããŒã¿ããäžåºŠã«ãæžã蟌ãããšãã§ããŸãã ãã ãã埮åŠãªç¹ã1ã€ãããŸãã ãŸãããã¹ãŠã®è¶ å°ååè·¯ããã®ã¿ã€ãã®æ¥ç¶ããµããŒãããå¿ èŠããããŸãã 第äºã«ãLinuxã«ãŒãã«ã¯ãã®ã¿ã€ãã®æ¥ç¶ããµããŒãããŠããªããããåŒãç¶ã䜿çšããå Žåã¯ãæ¢åã®ãã©ã€ããŒãå€æŽããããç¬èªã®ãã©ã€ããŒãäœæããå¿ èŠããããŸãã
SPIããã€ã¹ã«ã¯4ã€ã®åäœã¢ãŒãããããŸãã ååãšããŠãåå¿è ã®éã§æãæ··ä¹±ãåŒãèµ·ããã®ã¯åœŒãã§ãã ãããã®4ã€ã®ã¢ãŒãã¯ã2ãããã®çµã¿åããã§ãã
- CPOLïŒã¯ããã¯æ¥µæ§ïŒ-åæä¿¡å·ã®åæã¬ãã«ïŒæ¥µæ§ïŒã決å®ããŸãã
CPOL = 0ã¯ãåæä¿¡å·ãäœã¬ãã«ã§éå§ãããããç«ã¡äžãããšããžãç«ã¡äžãããç«ã¡äžãããšããžãç«ã¡äžããããšã瀺ããŸãã
CPOL = 1ãåæä¿¡å·ã¯é«ã¬ãã«ã§éå§ãããããç«ã¡äžãããšããžã¯ç«ã¡äžãããç«ã¡äžãããšããžã¯ç«ã¡äžãããŸãã - CPHAïŒã¯ããã¯ãã§ãŒãºïŒ-åæã®ãã§ãŒãºã§ãã¯ããã¯ä¿¡å·ã®ã©ã®ãšããžã§ããŒã¿ããµã³ããªã³ã°ãããã決å®ããŸãã
CPHA = 0ã¯ãç«ã¡äžãããšããžã§ãµã³ããªã³ã°ããå¿ èŠãããããšã瀺ããŸãã
CPHA = 1ã¯ãããŒã¿ãç«ã¡äžãããšããžã§ãµã³ããªã³ã°ããå¿ èŠãããããšã瀺ããŸãã
ãããã®2ãããã¯ã¢ãŒãçªå·ã圢æããŸãã CPOLã¯æäžäœãããã§ãããCPHAã¯æäžäœãããã§ãã ããã€ã¹ã®ããã¥ã¡ã³ãã«ã¢ãŒãçªå·ãæ瀺çã«ç€ºãããŠããªãå ŽåããããŸãããã¿ã€ãã³ã°å³ãããã€ã§ãç°¡åã«å€æã§ããŸãã ããŒã¿ã®ãµã³ããªã³ã°ãšã€ã³ã¹ããŒã«ã¯åžžã«ã¯ããã¯ä¿¡å·ã®å察åŽã®ãšããžã§è¡ãããããšãç解ããããšãéèŠã§ãã ããšãã°ãããã€ã¹ãã¢ãŒã0ïŒæãäžè¬çãªãªãã·ã§ã³ïŒã§åäœãããŸãããã®å Žåãã¹ã¬ãŒãããã€ã¹ã¯ã¯ããã¯ä¿¡å·ã®ç«ã¡äžãããšããžã«æ²¿ã£ãŠMOSIå ¥åããããŒã¿ããããèªã¿åãããã¹ã¿ãŒã¯ç«ã¡äžãããšããžã«æ²¿ã£ãŠMISOå ¥åã§ã¹ã¬ãŒãããããŒã¿ãèªã¿åããŸãã ããæ確ã«ããããã«ã4ã€ã®åäœã¢ãŒããã¹ãŠã®ãªã·ãã°ã©ã ã瀺ããŸãã
ãã®å³ã¯ãMOSIïŒéç·ïŒããã³SCKïŒé»ç·ïŒä¿¡å·ã瀺ããŠããŸãã ãã¹ãŠã®å Žåã«ãããŠãçªå·0x64ãéä¿¡ãããŸãã æãã瞊ç·ã¯ãããŒã¿ãµã³ããªã³ã°ã®ç¬éã瀺ããŠããŸãã ã¢ãŒã2ã«ã€ããŠèããŠã¿ãŸããæãåºããŠãã ããããCPOL = 1ããã³CPHA = 0ã§ãã ãããã£ãŠãåæä¿¡å·ã¯æåã¯é«ã¬ãã«ã§ããããµã³ããªã³ã°ã¯ç«ã¡äžãããšããžïŒãã®å Žåã¯ç«ã¡äžããïŒã§è¡ãããŸãã ç§ã®ãªã·ãã¹ã³ãŒãã«ã¯2ã€ã®ãã£ã³ãã«ãããªãããããCSããã³MISOä¿¡å·ã¯è¡šç€ºãããŸããã ãããããã®å Žåããããã¯ããŸãããããããããŸãããããšãã°ããCSä¿¡å·ã¯ãããŒã¿è»¢éå šäœãéããŠåçŽã«ãé害ãã§ãã
2. Linuxã®SPIãµãã·ã¹ãã ã®æŠèŠ
Linux SPIãã©ã€ããŒã¯2ã€ã®éšåã«åãããŠããŸãã 1ã€ã¯SPIã³ã³ãããŒã©ãŒã®ãã©ã€ããŒã§ãç¹å®ã®ã³ã³ãããŒã©ãŒã®ããŒããŠã§ã¢ãšçŽæ¥é£æºããŸãã ãã®ãããªãã©ã€ããŒã¯ãã³ã³ãããŒã©ãŒã®æ§ææ¹æ³ããµã¹ãã³ãã¢ãŒããžã®åãæ¿ãïŒãµã¹ãã³ãïŒããã³çµäºïŒåéïŒãã¡ãã»ãŒãžã®éä¿¡ãã¥ãŒïŒspi_messageãããäžã®ãã¥ãŒã«ã€ããŠïŒããã®æ¬¡ã®éä¿¡ïŒspi_transferïŒã®éžæãããã³çŽæ¥éä¿¡æã«è¡ãã¢ã¯ã·ã§ã³ã決å®ããŸãããŒãã«å¯ŸããŠãCSãä»ããŠç¹å®ã®ããã€ã¹ãã¢ã¯ãã£ãå/éã¢ã¯ãã£ãåããæ¹æ³ã決å®ãããŸãïŒcs_activate / cs_deactivateé¢æ°ïŒã ãã®èšäºã§ã¯ããã®ã¿ã€ãã®ãã©ã€ããŒã«ã€ããŠã¯èª¬æããŸããã ååãšããŠããããã¯LinuxããŒããååšããMCU / eMPUã«æ¢ã«å®è£ ãããŠãããå€éšããç®çã®ã¹ã¬ãŒãããã€ã¹ãã¢ã¯ãã£ãã«ã§ããããã«ããããã»ã¬ã¯ããã³ãŒããªã©ã®ç¹å®ã®æ©èœãå¿ èŠãªå Žåã«ã®ã¿ãããã«ç»ãå¿ èŠããããŸãããžãã¯ã ããã¯ãããšãã°GPIOããªãå Žåã«åœ¹ç«ã€ããšããããŸãã
2çªç®ã®éšåã¯ãSPIãã¹ã«æ¥ç¶ãããŠããããŸããŸãªã¹ã¬ãŒãã§åäœããããã«äœ¿çšããããããã³ã«ãã©ã€ããŒã§ãã ãããã®ãã©ã€ããŒã¯ãããããã³ã«ããšåŒã°ããŸããããã¯ãæ©åšãšçŽæ¥é£æºããã«ãã¹ã¬ãŒããšã®éã§ã®ã¿ããŸããŸãªããŒã¿ãéåä¿¡ããããã§ãã é¢å¿ã®ããã¹ã¬ãŒãã®ãµããŒããã·ã¹ãã ã«è¿œå ã§ããããããã®ã¿ã€ãã®ãã©ã€ããŒãæãé¢å¿ããããŸããããã«ã€ããŠæ€èšããŸãã
ã»ãšãã©ã®ãããã³ã«ãã©ã€ããŒã¯ã«ãŒãã«ã¢ãžã¥ãŒã«ã§ãã ããšãã°ãããã€ã¹ãSPIãä»ããŠæ¥ç¶ããããªãŒãã£ãªã³ãŒããã¯ã§ããå Žåããã©ã€ããŒã¯ALSAãæäŸããæ©èœã䜿çšããããã°ã©ã ïŒããšãã°ãmadplayïŒã¯ãããŒããŠã§ã¢ã®æ§ææ¹æ³ã«ã€ããŠå°ããèããã«ãã·ã³ãã«ããã€ã¹/ dev /ãªãŒãã£ãªãä»ããŠãããæäœã§ããŸãã©ã®ãã¹ãæ¥ç¶ãããŠãããã
ã«ãŒãã«ã¯ããã£ã©ã¯ã¿ãŒããã€ã¹ã®åœ¢åŒã®ã€ã³ã¿ãŒãã§ã€ã¹ãåãããspidevãšåŒã°ããæ±çšãããã³ã«ãã©ã€ããŒãæäŸããŸãã ããã«ãããæšæºã®readïŒïŒããã³writeïŒïŒã·ã¹ãã ã³ãŒã«ã䜿çšããŠã¹ã¬ãŒãSPIããã€ã¹ã«åäºéåŒã³åºããè¡ããåäœã¢ãŒããèšå®ããioctlïŒïŒåŒã³åºããä»ããŠå šäºéããŒã¿äº€æãå®è¡ã§ããŸãã
ãããã£ãŠãSPIããã€ã¹ã®ãããã³ã«ãã©ã€ããŒã¯2ã€ã®ã¿ã€ãã«åé¡ã§ããŸãã
- ãŠãŒã¶ãŒç©ºéã§åäœããéåžžã®ããã°ã©ã ãããããèšèªã§è¡šçŸãã察å¿ãããã£ã©ã¯ã¿ãŒããã€ã¹spidevãèªã¿æžãããããšã«ããSPIããã€ã¹ã§åäœãããŠãŒã¶ãŒç©ºéãã©ã€ããŒã
- ã«ãŒãã«ã¹ããŒã¹ã§åäœãã/ devãã£ã¬ã¯ããªã®ããã€ã¹ãã¡ã€ã«ãä»ããŠããŸãã¯sysfsã®ããã€ã¹ãã£ã¬ã¯ããªã®å±æ§ã䜿çšããŠããŠãŒã¶ãŒã¹ããŒã¹ã®ã€ã³ã¿ãŒãã§ã€ã¹ãæäŸãããã©ã€ããŒã
Linuxã¯SPIããã€ã¹ãžã®ãã¹ãŠã®åŒã³åºããåŒã³åºããŸãã SPIãããã³ã«ãã©ã€ããŒã¯ãè€æ°ã»ã°ã¡ã³ãSPIãã©ã³ã¶ã¯ã·ã§ã³ã§ããspi_messageæ§é äœã«ãã£ãŠè¡šãããã¡ãã»ãŒãžãæ瀺çãŸãã¯æé»çã«åŠçããŸãã
struct spi_message { struct list_head transfers; struct spi_device *spi; unsigned is_dma_mapped:1; void (*complete)(void *context); void *context; unsigned actual_length; int status; struct list_head queue; void *state; };
転é-ãã©ã³ã¶ã¯ã·ã§ã³ïŒè»¢éïŒã§éä¿¡ãããã»ã°ã¡ã³ãã®ãªã³ã¯ãªã¹ãã
spi-ãã®ã¡ãã»ãŒãžã眮ãããŠãããã¥ãŒå ã®spiããã€ã¹ãžã®ãã€ã³ã¿ãŒã
is_dma_maped-ãã®ãã©ã°ãtrueã®å Žåãåéä¿¡ãããã¡ãŒã«dmaããã³cpuä»®æ³ã¢ãã¬ã¹ã®äž¡æ¹ãæäŸãããŸãã
complete-ãã©ã³ã¶ã¯ã·ã§ã³ã®çµäºãéç¥ããããã«åŒã³åºãããã³ãŒã«ããã¯ã
context-ã³ãŒã«ããã¯ããåŒæ°completeïŒïŒ;
actual_length-ãã¹ãŠã®æåãã転éã§éä¿¡ããããã€ãã®ç·æ°ã
status-æåããå Žåã¯0ããšã©ãŒã®å Žåã¯errnoã®è² ã®å€ã
spi_messageæ§é 㯠ãããŒã¿è»¢éã®ã¢ãããã¯ã·ãŒã±ã³ã¹ãå®è¡ããããã«äœ¿çšãããŸããåããŒã¿è»¢éã¯ã spi_transferæ§é ã§è¡šãããŸãã åã®ã¡ãã»ãŒãžãå®å šã«éä¿¡ããããŸã§ã SPIãã¹ã䜿çšããŠå¥ã®spi_messageã¡ãã»ãŒãžãéä¿¡ã§ããªããšããæå³ã§ãéä¿¡ã·ãŒã±ã³ã¹ã¯ãã¢ãããã¯ãã§ãã äžéšã®ã·ã¹ãã ã§ã¯ããã®ãããªã·ãŒã±ã³ã¹ã®å€ãã¯ãåäžã®ããã°ã©ã ãããDMAéä¿¡ãšããŠå®è¡ã§ããŸãã ãã¹ãŠã®ã·ã¹ãã ã§ããããã®ã¡ãã»ãŒãžã¯ãã¥ãŒã«å ¥ããããä»ã®ããã€ã¹ãšã®ãã©ã³ã¶ã¯ã·ã§ã³ã®åŸã«å®äºããããšãã§ããŸãã åäžã®ã¹ã¬ãŒããžã®ãã¹ãŠã®åŒã³åºãã¯ãåžžã«FIFOã®é åºã§å®è¡ãããŸãã
struct spi_transferæ§é äœã¯ããªã³ã¯ãããã¡ãã»ãŒãžãªã¹ãå ã®åäžã®éä¿¡ãèšè¿°ããèªã¿åã/æžã蟌ã¿ãããã¡ã®ãã¢ãå®çŸ©ããŸãã
struct spi_transfer { const void *tx_buf; void *rx_buf; unsigned len; dma_addr_t tx_dma; dma_addr_t rx_dma; unsigned cs_change:1; u8 bits_per_word; u16 delay_usecs; u32 speed_hz; struct list_head transfer_list; };
tx_buf-éä¿¡ããã«ãŒãã«ã¡ã¢ãªç©ºéã®ããŒã¿ãããã¡ãžã®ãã€ã³ã¿ããŸãã¯NULLã
rx_buf-ããŒã¿ãèªã¿èŸŒãã«ãŒãã«ã¡ã¢ãªç©ºéã®ããŒã¿ãããã¡ãžã®ãã€ã³ã¿ããŸãã¯NULLã
lenã¯ãrxããã³txãããã¡ãŒã®ãµã€ãºïŒãã€ãåäœïŒã§ãã
tx_dma-spi_message.is_dma_mappedãèšå®ãããŠããå Žåã«äœ¿çšãããDMAã¢ãã¬ã¹tx_bufã
rx_dma-DMAã¢ãã¬ã¹rx_bufãspi_message.is_dma_mappedãèšå®ãããŠããå Žåã«äœ¿çšãããŸãã
speed_hz-ããã€ã¹ã®ããã©ã«ãå€ä»¥å€ã®äŒéé床ãèšå®ããŸãã ãã®å€ã0ã®å Žåãspi_deviceæ§é äœã®max_speed_hzãã£ãŒã«ãã§æå®ãããããã©ã«ãã®é床ã䜿çšãããŸãã
bits_per_word-ããã©ã«ããšã¯ç°ãªãã¯ãŒããããã®ãããæ°ãèšå®ããŸãã ãã®å€ã0ã®å Žåãspi_deviceæ§é äœã®bits_per_wordãã£ãŒã«ãã§æå®ãããããã©ã«ãå€ã䜿çšãããŸãã
delay_usecs-äŒéã®æåŸã®ããããéä¿¡ãããŠãããããã»ã¬ã¯ãã®ç¶æ ãå€æŽãããŸã§ããŸãã¯ãã¥ãŒå ã®æ¬¡ã®äŒéã®äŒéãéå§ãããŸã§ã®ãã€ã¯ãç§åäœã®ã¿ã€ã ã¢ãŠãã ãã®ãã©ã¡ãŒã¿ãŒã«ã¯çŽ°å¿ã®æ³šæãæã£ãŠãã ãããé 延ãå®è£ ãããŠããã³ã³ãããŒã©ãŒãã©ã€ããŒã®éšåã確èªããå¿ èŠããããŸãã ããšãã°ãat91ã·ãªãŒãºãããã®å Žåãå²ã蟌ã¿ãã³ãã©ã«å®è£ ãããããããã®äœ¿çšã«ã¯çµæã䌎ããŸãã
spi_transferæ§é ãåæåãããšããéåžžã«éèŠãªãã€ã³ãããããŸãããããã¯ãkmallocãkzallocãªã©ãä»ããŠDMAã§äœ¿çšå¯èœãªã¡ã¢ãªé åã«å²ãåœãŠãå¿ èŠããããŸãã ãã¹ã¿ãŒãã©ã€ããŒãdmaã䜿çšããŠããå Žåãéçã«å®£èšãããé åã䜿çšãããšã転éããããšãããšãã«ãã©ã€ããŒãã¯ã©ãã·ã¥ããŸãã
SPIãä»ããŠããŒã¿ãéä¿¡ããå Žåãèšé²ããããããæ°ã¯åžžã«èªã¿åããããããæ°ãšçãããªããŸãã ãããã³ã«ãã©ã€ããŒã¯ãåžžã«tx_bufãããã¡ãŒãŸãã¯rx_bufãããã¡ãŒãžã®ãã€ã³ã¿ãŒãæäŸããå¿ èŠããããŸãã å Žåã«ãã£ãŠã¯ãéä¿¡ããŒã¿ã®DMAã¢ãã¬ã¹ãæäŸããå ŽåããããŸãã
å転éã®ããŒã¿è»¢éã¬ãŒããšã¯ãŒããããã®ãããæ°ãåå¥ã«ç¡å¹ã«ããæ©èœã¯ãç¹å®ã®ãã©ã€ããŒã®å®è£ ãšã³ã³ãããŒã©ãŒã®ããŒããŠã§ã¢æ©èœã«äŸåããŸãã ããšãã°ãat91ã·ãªãŒãºãããã®SPIã³ã³ãããŒã©ãŒã®å Žåããã£ãŒã«ãspeed_hzããã³bits_per_wordãåå®çŸ©ããå¯èœæ§ã¯æäŸãããªããããåžžã«0ã«èšå®ããå¿ èŠããããŸããããããªããšãããŒã¿ã転éããããšãããšãã«ãšã©ãŒãçºçããŸãã
tx_bufãžã®ãã€ã³ã¿ãŒãNULLã«èšå®ãããŠããå ŽåãSPIã³ã³ãããŒã©ãŒã¯rx_bufãããã¡ãŒããã£ã±ãã«ãªããšãŒãããããã¢ãŠãããŸãã rx_bufãNULLã«èšå®ãããŠããå Žåãèªã¿åãããããŒã¿ã¯ç¡èŠãããŸãã ããã·ã¥ïŒããã³ãã£ããã£ïŒããããã€ãæ°ã¯åžžã«lenã§ãã åèªã®äžéšã®ã¿ããââãã·ã¥ããããšãããšããšã©ãŒãçºçããŸãã ïŒããšãã°ã3ãã€ããš16ããããŸãã¯20ãããã®ã¯ãŒãé·ãããã·ã¥ããããšããå Žåãæåã®ã±ãŒã¹ã§ã¯ã¯ãŒãããšã«2ãã€ãã䜿çšããã2çªç®ã§ã¯4ãã€ãã䜿çšãããŸãïŒã
éä¿¡ããããŒã¿ã¯ãåžžã«ç¹å®ã®ããŒããŠã§ã¢ãã©ãããã©ãŒã ã«åºæã®é åºã§ä¿åãããŸãã ããŒã¿ã®éä¿¡/èªã¿åãæã«ããã€ãé åºã¯SPIåºæïŒSPI_LSB_FIRSTãã©ã¡ãŒã¿ãŒãèšå®ãããŠããªãéããéåžžããã°ãšã³ãã£ã¢ã³ïŒãããã®CPUã®ããŒããŠã§ã¢åºæã®é åºã«èªåçã«å€æãããŸãã ããšãã°ãbits_per_wordãã©ã¡ãŒã¿ãŒã16ã®å Žåããããã¡ãŒã¯2Nãã€ããå æãããã®CPUã«åºæã®ãã€ãé ã§æ ŒçŽãããããããã16ãããã®é·ãã®Nã¯ãŒããå«ã¿ãŸãã
ã¯ãŒããµã€ãºã2ã®ã¹ãä¹ã§ãªãå Žåãã¡ã¢ãªå ã®ã¯ãŒãã®è¡šçŸã«ã¯è¿œå ã®ããããå«ãŸããŸãã ãããã³ã«ãã©ã€ããŒçšã«ã¡ã¢ãªã«ä¿åãããŠããåèªã¯åžžã«å³æãã§ãããããäœåãªãããã¯åžžã«é«äœãããã«ãªããŸãã
ããããããããããã«ãããäžåºŠãªã·ãã°ã©ã ã瀺ããŸãã
ãã®å Žåãtxãããã¡ãŒã«ã¯å€0xf98eãå«ãŸããèšå®å€bits_per_wordã¯ã¯ãŒãããã12ãããã«å¯Ÿå¿ããŸãã ããã€ã¹ã¯SPI_MODE_0ã§å®è¡ãããŠããŸãã å³ã§ã¯ãéãç·ãMOSIã³ã³ãããŒã©ãŒã®åºåã«å¯Ÿå¿ããé»è²ã®ç·ãSCKã«å¯Ÿå¿ããŠããŸãã ããã§ã¯ãéä¿¡äžã«0x098eã®ã¿ãéä¿¡ãããäžäœ4ãããã¯è¿œå ãšèŠãªããããããç Žæ£ãããããšãæ確ã«ããããŸãã éåžžã«åçŽãªå Žåã1ã€ã®12ãããã¯ãŒããã¡ã¢ãªã®2ãã€ããå æããã¡ã¢ãªã®ã¯ãŒããµã€ãºãšå®éã®ãµã€ãºã®å·®ã¯2 * 8-12 = 4ãããã§ãããéä¿¡äžã«ç Žæ£ãããŸãã
ãã¹ãŠã®SPI転éã¯ã察å¿ãããããã»ã¬ã¯ãã®ã¢ã¯ãã£ãåããå§ãŸããŸãã éåžžãã¹ã¬ãŒãã¯ã¡ãã»ãŒãžã®æåŸã®éä¿¡ãŸã§ã¢ã¯ãã£ãã®ãŸãŸã§ãã ãã©ã€ããŒã¯ã spi_transferæ§é äœã®cs_changeãã©ã°ã䜿çšããŠcsã®ç¶æ ãå€æŽã§ããŸãã
- éä¿¡ãã¡ãã»ãŒãžã®æåŸã§ã¯ãªãå Žåãcs_changeãã©ã°ã䜿çšããŠãã¡ãã»ãŒãžã®éäžã§ãããã»ã¬ã¯ããäžæçã«éã¢ã¯ãã£ãã«ããŸãã ã¹ã¬ãŒãã³ãã³ããå®äºããã«ã¯ããã®ãããªcsã¹ã€ãããå¿ èŠã«ãªãå ŽåããããŸãã ããã«ããã1ã€ã®spi_messageã䜿çšããŠã1ã€ã®ã¹ã¬ãŒãã®éä¿¡ã°ã«ãŒããããã«å®è¡ã§ããŸãã
- éä¿¡ãã¡ãã»ãŒãžã®æåŸã®å Žåãã¹ã¬ãŒãã¯æ¬¡ã®ã¡ãã»ãŒãžã®éä¿¡ãéå§ããããŸã§éžæããããŸãŸã«ãªããŸãã å¥ã®ããã€ã¹ãžã®ã¡ãã»ãŒãžéä¿¡ã®éå§ã«ãããçŸåšã®csãéã¢ã¯ãã£ãåãããŸãã äžéšã®ããã€ã¹ãæ©èœããã«ã¯ããã©ã³ã¶ã¯ã·ã§ã³ã¯spi_messageã¡ãã»ãŒãžãã¥ãŒã§æ§æãããŠããå¿ èŠããããŸããåŸç¶ã®ã¡ãã»ãŒãžã®å 容ã¯ã以åã®ã¡ãã»ãŒãžã®çµæã«äŸåããŸãã ãã®å Žåããã©ã³ã¶ã¯ã·ã§ã³ã¯csãéã¢ã¯ãã£ãç¶æ ã«ããããšã§å®å šã«å®äºããŸãã
spi_message ïŒããã³ãã®spi_transferã®ïŒãäžäœã¬ãã«ã«æž¡ãã³ãŒãã¯ããããã®æ§é ã®ã¡ã¢ãªã管çããŸãã æ瀺çã«å®çŸ©ãããŠããªãæ§é äœã®ãã£ãŒã«ãã¯ãã¹ãŠããŒãã«åæåããå¿ èŠããããŸãã ã¡ãã»ãŒãžïŒããã³ãã®äžã®åã ã®éä¿¡ïŒãéä¿¡ããåŸããã®ã¡ãã»ãŒãžãå®äºããããã®ã³ãŒã«ããã¯ãæ©èœãããŸã§ãåŸç¶ã®ã¡ãã»ãŒãžãç¡èŠããå¿ èŠããããŸãã
SPIã¯ãèªåããã€ã¹æ€åºã¡ã«ããºã ããµããŒãããŠããŸããã ããã«ãã»ãšãã©ã®å ŽåãSPIããã€ã¹ã¯ããããã©ã°/ã¢ã³ãã©ã°ãæäŸããªããããéåžžã¯ããŒãã«çŽæ¥ã¯ãã ä»ãããã ãã§ãã ãã®ç¹ã§ããããã®ããã€ã¹ã¯ããŒãåºæãšèŠãªãããŸãã ãã®ãããªããã€ã¹ã®ãã©ã¡ãŒã¿ãŒã¯ãããŒããã¡ã€ã«ã«ç€ºãããŠããŸãïŒarch /.../ mach-* / board-*ãC.
ããšãã°ãSK-AT91SAM9260ãããã°ããŒãã®tlv320aic23bãªãŒãã£ãªã³ãŒããã¯ã®ãã©ã¡ãŒã¿ãŒèšå®ã¯æ¬¡ã®ããã«ãªããŸãã
static struct spi_board_info ek_spi_devices[] = { { /* tlv320aic23b CODEC */ .modalias = "tlv320aic23b", .chip_select = 0, .max_speed_hz = 10 * 1000 * 1000, .bus_num = 1, .mode = SPI_MODE_1, .platform_data = &tlv320aic23b_data, }, ⊠}
modaliasã¯ãããã€ã¹ã®ä¿å®ãæ åœããã«ãŒãã«ãã©ã€ããŒã®ååã§ãïŒãã®äŸã§ã¯ããtlv320aic23bãïŒã
chip_select-察å¿ãããããã»ã¬ã¯ãã®çªå·ã
max_speed_hz-Hzåäœã®æ倧åšæ³¢æ°ã
mode-å®æ°SPI_MODE_0 ... SPI_MODE_3ã§å®çŸ©ãããSPIã¢ãŒãããããåäœã®ãorãæäœã§ãSPI_CS_HIGHãã©ã°ãè¿œå ã§ããŸãïŒãããã»ã¬ã¯ãã®ã¢ã¯ãã£ãããã€ã¬ãã«ã«èšå®ïŒãSPI_NO_CSïŒååãšããŠCSã¢ã¯ãã£ããŒã·ã§ã³ãªãã®ããŒã¿è»¢éïŒã å¯èœãªãã©ã°ã®å®å šãªãªã¹ãã¯ã spi_deviceæ§é äœã®èª¬æã«ãããŸãã
bus_num-ãã¹çªå·ïŒéåžžãMCU / eMPUã®ããŒã¿ã·ãŒãã«ããã³ã³ãããŒã©ãŒã®SPIçªå·ã«å¯Ÿå¿ïŒã
spi_board_infoæ§é ã«ã¯ãäžèšã®äŸã§åæåãããŠããªã次ã®ãã£ãŒã«ããå«ãŸããŠããŸãã
const void * platform_data-ãã®ãã£ãŒã«ãã¯ãç¹å®ã®ãã©ã€ããŒã«åºæã®ããŒã¿ãžã®ãã€ã³ã¿ãŒãæ ŒçŽããããã®ãã®ã§ãã
void * controller_data-äžéšã®ã³ã³ãããŒã©ãŒã§ã¯ãDMAãªã©ã®ããã€ã¹æ§æã«é¢ããæ å ±ãå¿ èŠã§ãã
int irq-ããã€ã¹ã®æ¥ç¶ã«äŸåããŸãã
spi_board_infoæ§é äœã®ãã¹ãŠã®ãã£ãŒã«ãã¯ã spi_deviceæ§é äœã®å¯Ÿå¿ãããã£ãŒã«ããèšå®ããŸãã
ä»ã®SPIããã€ã¹ã®ãã©ã¡ãŒã¿ãŒãèšå®ããå¿ èŠãããå Žåãåæ§ã®èŠçŽ ãé åã«è¿œå ãããŸãã
ãããã®æ§é ã«ã¯ããã©ã€ããŒãåžžã«å€æã§ããããã§ã¯ãªãæ å ±ãæ ŒçŽãããŸãã ãã©ã€ãã®ãããŒãïŒïŒæ©èœã«ãã£ãŠæ±ºå®ã§ããæ å ±ïŒããšãã°ã1ã¯ãŒããããã®ãããæ°ïŒã¯ããã®æ§é ã«ã¯å«ãŸããŸããã
ã¹ã¬ãŒãSPIããã€ã¹ãããããã©ã°ããå¯èœæ§ããŸã ããããšã«æ³šæããŠãã ããã ãã®å Žåã spi_busnum_to_masterïŒïŒé¢æ°ã䜿çšããŠãSPIãã¹çªå·ã§spi_masteræ§é äœãžã®ãã€ã³ã¿ãŒãååŸãããã¹äžã®ããã€ã¹ãå埩åŠçããŸãã ãããããã®ãããã¯ã¯ãã®èšäºã®ç¯å²å€ã§ãã
第äºéšãèªã