基于tiny4412的Linux内核移植 -- SD卡驱动移植(五)

发布时间:2023-06-21  

平台简介

开发板:tiny4412ADK + S700 + 4GB Flash

要移植的内核版本:Linux-4.4.0 (支持device tree)

u-boot版本:友善之臂自带的 U-Boot 2010.12 (为支持uImage启动,做了少许改动)

busybox版本:busybox 1.25

SD卡:Kingston SDHC 4GB

交叉编译工具链: arm-none-linux-gnueabi-gcc

      (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29))

概述

    移植SD卡比较简单,但是刚开始的时候也出现了不少问题,关键是对设备树的修改、对regulator的理解以及sdcard检测过程。

移植

    下面是tiny4412关于sd卡部分的原理图:

底板:

image

核心板:

image

从原理图可以看出,tiny4412用的MMC控制器是SDMMC2。一共用到了7个引脚(CLK、CMD、CDn、DATA0-DATA3),其中CDn的意思是当插入SD卡时,这个引脚的电平会被拉低(可以轮询这个引脚的电平转态或者通过设置这个引脚产生中断来检测sdcard状态)。在之前的移植中我们将sdhc2给disabled了:

arch/arm/boot/dts/exynos4412-tiny4412.dts:

&sdhci_2 {

    bus-width = <4>;

    pinctrl-0 = ;

    pinctrl-names = "default";

    status = "disabled";

};

其中princtrl-0后的作用是设置用到的GPIO的复用功能(一旦复用为sdcard控制器的专用引脚后,就不能作为普通的gpio使用了),这几个标号是在arch/arm/boot/dts/exynos4x12-pinctrl.dtsi中定义的:


sd2_clk: sd2-clk {

    samsung,pins = "gpk2-0";

    samsung,pin-function = <2>;

    samsung,pin-pud = <0>;

    samsung,pin-drv = <3>;

};

 

sd2_cmd: sd2-cmd {

    samsung,pins = "gpk2-1";

    samsung,pin-function = <2>;

    samsung,pin-pud = <0>;

    samsung,pin-drv = <3>;

};

 

sd2_cd: sd2-cd {

    samsung,pins = "gpk2-2";

    samsung,pin-function = <2>;

    samsung,pin-pud = <3>;

    samsung,pin-drv = <3>;

};

 

sd2_bus4: sd2-bus-width4 {

    samsung,pins = "gpk2-3", "gpk2-4", "gpk2-5", "gpk2-6";

    samsung,pin-function = <2>;

    samsung,pin-pud = <3>;

    samsung,pin-drv = <3>;

};

这样只是设置了这几个GPIO的复用功能,并不用在驱动程序中申请这几个GPIO资源,因为这几个引脚已经不是作为普通的GPIO使用了。


如果直接将sdhc2使能的话:


--- a/arch/arm/boot/dts/exynos4412-tiny4412.dts

+++ b/arch/arm/boot/dts/exynos4412-tiny4412.dts

@@ -86,7 +86,7 @@

        bus-width = <4>;

        pinctrl-0 = ;

        pinctrl-names = "default";

-       status = "disabled";

+       status = "okay";

 };

 

 &serial_0 {

内核在启动时会崩溃,信息如下:


   1: [    2.228406] sdhci: Secure Digital Host Controller Interface driver

   2: [    2.233751] sdhci: Copyright(c) Pierre Ossman

   3: [    2.238350] s3c-sdhci 12530000.sdhci: clock source 2: mmc_busclk.2 (100000000 Hz)

   4: [    2.245838] s3c-sdhci 12530000.sdhci: No vmmc regulator found

   5: [    2.251358] s3c-sdhci 12530000.sdhci: No vqmmc regulator found

   6: [    2.257480] ------------[ cut here ]------------

   7: [    2.261686] kernel BUG at drivers/mmc/host/sdhci.c:1304!

   8: [    2.266981] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM

   9: [    2.272796] Modules linked in:

  10: [    2.275836] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.4.0-gbd7378b-dirty #33

  11: [    2.283038] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)

  12: [    2.289115] task: ef078000 ti: ef080000 task.ti: ef080000

  13: [    2.294500] PC is at sdhci_do_set_ios+0x564/0x5e0

  14: [    2.299189] LR is at arm_heavy_mb+0x1c/0x38

  15: [    2.303351] pc : []    lr : []    psr: 80000093

  16: [    2.303351] sp : ef081cc8  ip : 00000200  fp : 00000001

  17: [    2.314807] r10: 00000003  r9 : ef30e800  r8 : 60000013

  18: [    2.320015] r7 : ef30e800  r6 : ef30ec98  r5 : ef30ea34  r4 : ef30eb80

  19: [    2.326525] r3 : 00000001  r2 : 75004180  r1 : 00000000  r0 : ef30eb80

  20: [    2.333036] Flags: Nzcv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none

  21: [    2.340240] Control: 10c5387d  Table: 4000404a  DAC: 00000051

  22: [    2.345969] Process swapper/0 (pid: 1, stack limit = 0xef080210)

  23: [    2.351958] Stack: (0xef081cc8 to 0xef082000)

  24: [    2.356300] 1cc0:                   00000000 ef30eb80 00000043 c02d30e8 c02d30e8 00000004

  25: [    2.364460] 1ce0: c0058b5c ef080000 ef1a6ebc c0407168 ef1a6e10 ef1a6e80 c02d30e8 c02d3114

  26: [    2.372619] 1d00: 00000004 c02d465c ef1a6e10 c0852100 c086ea10 c02d46b0 00000000 ef1a6e10

  27: [    2.380778] 1d20: c0852100 c02d54fc eeca0fa0 c00f2934 00000188 eeca0fa0 ef078000 60000013

  28: [    2.388937] 1d40: ef1a6e80 ef1a6e10 ef1a6e80 00000004 60000013 00000000 00000002 ef30ea80

  29: [    2.397096] 1d60: 00000000 c02d56c8 00000000 ef30e800 ef30ea24 60000013 ef080000 c03eff80

  30: [    2.405256] 1d80: eec0b7b8 00000000 ef078000 c0044ee8 00000100 00000200 eec0b6b4 ef30e800

  31: [    2.413415] 1da0: ef30ed2c ef30eb80 ef30e800 00000000 00000200 00000000 ef30ed18 c03f2fd8

  32: [    2.421574] 1dc0: ef30e800 c03f41ac 00000000 c0407ba4 ef264300 ef30eb80 00000808 ef30e800

  33: [    2.429733] 1de0: ef7d3488 00000000 00000000 c03f3dd4 00000000 ef30eb80 00000004 ef1a6e10

  34: [    2.437893] 1e00: ef1a6e00 ef30edec 00000001 ef264110 00000000 c0408be8 05f5e100 c087a810

  35: [    2.446052] 1e20: ef17df50 c087a8a4 5f636d6d 63737562 332e6b6c ee9d9600 00000001 ef1a6e10

  36: [    2.454211] 1e40: fffffffe fffffdfb c087a810 c087a810 00000000 c081683c c0816848 c02ce238

  37: [    2.462370] 1e60: c02ce1e8 ef1a6e10 c08d942c c088e410 00000000 c02cc634 c087a810 ef1a6e44

  38: [    2.470529] 1e80: c088e338 ef1a6e10 c087a810 ef1a6e44 c088e338 00000000 00000000 c02cc8d4

  39: [    2.478688] 1ea0: 00000000 c087a810 c02cc848 c02ca7d4 ef003274 ef17b7c0 c087a810 eebf6f00

  40: [    2.486848] 1ec0: c086ebc8 c02cbb48 c0755dc0 c087a810 c087a810 c0855520 ef267240 c089c000

  41: [    2.495007] 1ee0: c08023cc c02cd0cc c087a7fc c0855520 c0855520 c00097a0 ef15eb00 c0598680

  42: [    2.503166] 1f00: 00000025 0000c000 ef078000 60000013 efffca92 c05aba2c 000000c0 c003da88

  43: [    2.511325] 1f20: 00000001 00000003 c0746c3c c07b1804 00000000 c088c6b8 00000006 00000006

  44: [    2.519484] 1f40: c0858ec8 c0849e3c c084a108 00000006 c089c000 c089c000 c07e35b0 000000c0

  45: [    2.527643] 1f60: c081683c c07e3dec 00000006 00000006 00000000 c07e35b0 ef078000 c0042518

  46: [    2.535802] 1f80: 000000a2 00000000 c058e6c8 00000000 00000000 00000000 00000000 00000000

  47: [    2.543962] 1fa0: 00000000 c058e6d0 00000000 c0010338 00000000 00000000 00000000 00000000

  48: [    2.552121] 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

  49: [    2.560280] 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 dffffefb f5fbff7f

  50: [    2.568447] [] (sdhci_do_set_ios) from [] (sdhci_runtime_resume_host+0x60/0x114)

  51: [    2.577557] [] (sdhci_runtime_resume_host) from [] (pm_generic_runtime_resume+0x2c/0x38)

  52: [    2.587366] [] (pm_generic_runtime_resume) from [] (__rpm_callback+0x2c/0x60)

  53: [    2.596216] [] (__rpm_callback) from [] (rpm_callback+0x20/0x80)

  54: [    2.603942] [] (rpm_callback) from [] (rpm_resume+0x3ac/0x52c)

  55: [    2.611493] [] (rpm_resume) from [] (__pm_runtime_resume+0x4c/0x64)

  56: [    2.619482] [] (__pm_runtime_resume) from [] (__mmc_claim_host+0x190/0x19c)

  57: [    2.628161] [] (__mmc_claim_host) from [] (mmc_start_host+0x38/0x98)

  58: [    2.636232] [] (mmc_start_host) from [] (mmc_add_host+0x58/0x7c)

  59: [    2.643957] [] (mmc_add_host) from [] (sdhci_add_host+0x988/0xe80)

  60: [    2.651855] [] (sdhci_add_host) from [] (sdhci_s3c_probe+0x4a8/0x548)

  61: [    2.660016] [] (sdhci_s3c_probe) from [] (platform_drv_probe+0x50/0xac)

  62: [    2.668348] [] (platform_drv_probe) from [] (driver_probe_device+0x240/0x454)

  63: [    2.677200] [] (driver_probe_device) from [] (__driver_attach+0x8c/0x90)

  64: [    2.685626] [] (__driver_attach) from [] (bus_for_each_dev+0x60/0x94)

  65: [    2.693780] [] (bus_for_each_dev) from [] (bus_add_driver+0x1b8/0x26c)

  66: [    2.702025] [] (bus_add_driver) from [] (driver_register+0x78/0xf8)

  67: [    2.710012] [] (driver_register) from [] (do_one_initcall+0xbc/0x1f4)

  68: [    2.718176] [] (do_one_initcall) from [] (kernel_init_freeable+0x158/0x1f8)

  69: [    2.726855] [] (kernel_init_freeable) from [] (kernel_init+0x8/0xf0)

文章来源于:电子工程世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。

我们与500+贴片厂合作,完美满足客户的定制需求。为品牌提供定制化的推广方案、专属产品特色页,多渠道推广,SEM/SEO精准营销以及与公众号的联合推广...详细>>

利用葫芦芯平台的卓越技术服务和新产品推广能力,原厂代理能轻松打入消费物联网(IOT)、信息与通信(ICT)、汽车及新能源汽车、工业自动化及工业物联网、装备及功率电子...详细>>

充分利用其强大的电子元器件采购流量,创新性地为这些物料提供了一个全新的窗口。我们的高效数字营销技术,不仅可以助你轻松识别与连接到需求方,更能够极大地提高“闲置物料”的处理能力,通过葫芦芯平台...详细>>

我们的目标很明确:构建一个全方位的半导体产业生态系统。成为一家全球领先的半导体互联网生态公司。目前,我们已成功打造了智能汽车、智能家居、大健康医疗、机器人和材料等五大生态领域。更为重要的是...详细>>

我们深知加工与定制类服务商的价值和重要性,因此,我们倾力为您提供最顶尖的营销资源。在我们的平台上,您可以直接接触到100万的研发工程师和采购工程师,以及10万的活跃客户群体...详细>>

凭借我们强大的专业流量和尖端的互联网数字营销技术,我们承诺为原厂提供免费的产品资料推广服务。无论是最新的资讯、技术动态还是创新产品,都可以通过我们的平台迅速传达给目标客户...详细>>

我们不止于将线索转化为潜在客户。葫芦芯平台致力于形成业务闭环,从引流、宣传到最终销售,全程跟进,确保每一个potential lead都得到妥善处理,从而大幅提高转化率。不仅如此...详细>>