watchdog module_amba_driver

[root@centos7 linux-5.14]# ls /dev/watchdog
/dev/watchdog
[root@centos7 opensbi]#  ls  /sys/bus/amba/
devices  drivers  drivers_autoprobe  drivers_probe  uevent
[root@centos7 opensbi]#  ls  /sys/bus/amba/devices/
[root@centos7 opensbi]# 
[root@centos7 opensbi]#  ls  /sys/bus/amba/devices/
[root@centos7 opensbi]#  ls  /sys/bus/amba/
devices  drivers  drivers_autoprobe  drivers_probe  uevent
[root@centos7 opensbi]#  ls  /sys/bus/amba/devices/
[root@centos7 opensbi]#  ls  /sys/bus/amba/devices/
[root@centos7 opensbi]#  ls  /sys/bus/amba/
devices  drivers  drivers_autoprobe  drivers_probe  uevent
[root@centos7 opensbi]#  ls  /sys/bus/amba/drivers
clcd-pl11x  kmi-pl050  pl061_gpio  rtc-pl031  uart-pl011
[root@centos7 opensbi]# 
/*
 * module_amba_driver() - Helper macro for drivers that don't do anything
 * special in module init/exit.  This eliminates a lot of boilerplate.  Each
 * module may only use this macro once, and calling it replaces module_init()
 * and module_exit()
 */
#define module_amba_driver(__amba_drv) 
        module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
#define module_driver(__driver, __register, __unregister, ...) 
static int __init __driver##_init(void) 
{ 
        return __register(&(__driver) , ##__VA_ARGS__); 
} 

 ARM_AMBA

drivers/amba/Kconfig:2:config ARM_AMBA

root@ubuntu:~/linux_arm64/linux-5.14# grep ARM64  .config
CONFIG_ARM64=y
root@ubuntu:~/linux_arm64/linux-5.14# grep ARM_AMBA  .config
CONFIG_ARM_AMBA=y
drivers/amba/Makefile:2:obj-$(CONFIG_ARM_AMBA)          += bus.o
include/linux/amba/bus.h:108:#ifdef CONFIG_ARM_AMBA

drivers/amba/bus.c

EXPORT_SYMBOL(amba_driver_register);
EXPORT_SYMBOL(amba_driver_unregister);
EXPORT_SYMBOL(amba_device_register);
EXPORT_SYMBOL(amba_device_unregister);
EXPORT_SYMBOL(amba_find_device);
EXPORT_SYMBOL(amba_request_regions);
EXPORT_SYMBOL(amba_release_regions);


 

 

root@ubuntu:~/linux_arm64/linux-5.14# grep ARM_SP805_WATCHDOG .config
CONFIG_ARM_SP805_WATCHDOG=m
root@ubuntu:~/linux_arm64/linux-5.14# lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              64
On-line CPU(s) list: 0-63
Thread(s) per core:  1
Core(s) per socket:  32
Socket(s):           2
NUMA node(s):        4
Vendor ID:           ARM
Model:               2
Model name:          Cortex-A72
Stepping:            r0p2
BogoMIPS:            100.00
L1d cache:           32K
L1i cache:           48K
L2 cache:            1024K
L3 cache:            16384K
NUMA node0 CPU(s):   0-15
NUMA node1 CPU(s):   16-31
NUMA node2 CPU(s):   32-47
NUMA node3 CPU(s):   48-63
Flags:               fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
root@ubuntu:~/linux_arm64/linux-5.14# 

CONFIG_ARM_AMBA

drivers/of/platform.c:28://#ifdef CONFIG_ARM_AMBA
drivers/of/platform.c:218://#ifdef CONFIG_ARM_AMBA
drivers/of/platform.c:573://#ifdef CONFIG_ARM_AMBA
drivers/iommu/amd/iommu.c:1795:#ifdef CONFIG_ARM_AMBA
drivers/iommu/arm/arm-smmu/arm-smmu.c:2030:#ifdef CONFIG_ARM_AMBA
drivers/iommu/arm/arm-smmu/arm-smmu.c:2058:#ifdef CONFIG_ARM_AMBA
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3718:#ifdef CONFIG_ARM_AMBA
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3734:#ifdef CONFIG_ARM_AMBA
drivers/iommu/virtio-iommu.c:1088:#ifdef CONFIG_ARM_AMBA
drivers/xen/arm-device.c:146:#ifdef CONFIG_ARM_AMBA
drivers/gpu/drm/pl111/pl111_drv.c:441:#ifdef CONFIG_ARM_AMBA
drivers/acpi/internal.h:29:#ifdef CONFIG_ARM_AMBA
include/linux/amba/bus.h:108://#ifdef CONFIG_ARM_AMBA

riscv SP805

# ALPHA Architecture

# ARM Architecture

config ARM_SP805_WATCHDOG
        tristate "ARM SP805 Watchdog"
        depends on (ARM || ARM64 || COMPILE_TEST) && ARM_AMBA
        select WATCHDOG_CORE
        help
          ARM Primecell SP805 Watchdog timer. This will reboot your system when
          the timeout is reached.

[root@centos7 linux-5.14]# grep SP805  .config
CONFIG_ARM_SP805_WATCHDOG=y
[root@centos7 linux-5.14]# 
[root@centos7 linux-5.14]# make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu-   -j128
  SYNC    include/config/auto.conf.cmd
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  CC      drivers/watchdog/watchdog_core.o
  CC      drivers/watchdog/watchdog_dev.o
  CC      drivers/watchdog/sp805_wdt.o
  UPD     kernel/config_data
  GZIP    kernel/config_data.gz
  CC      kernel/configs.o
  AR      kernel/built-in.a
  AR      drivers/watchdog/built-in.a
  AR      drivers/built-in.a
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  AR      init/built-in.a
  LD      vmlinux.o
  MODPOST vmlinux.symvers
  MODINFO modules.builtin.modinfo
  GEN     modules.builtin
  LD      .tmp_vmlinux.kallsyms1
  KSYMS   .tmp_vmlinux.kallsyms1.S
  AS      .tmp_vmlinux.kallsyms1.S
  LD      .tmp_vmlinux.kallsyms2
  KSYMS   .tmp_vmlinux.kallsyms2.S
  AS      .tmp_vmlinux.kallsyms2.S
  LD      vmlinux
  SYSMAP  System.map
  MODPOST modules-only.symvers
  OBJCOPY arch/riscv/boot/Image
  GEN     Module.symvers
  GZIP    arch/riscv/boot/Image.gz
  Kernel: arch/riscv/boot/Image.gz is ready
[root@centos7 linux-5.14]# cat System.map | grep amba_driver_registe
[root@centos7 linux-5.14]# cat System.map | grep 

竟然没有

[root@centos7 linux-5.14]# cat System.map | grep sp805_wdt_probe
[root@centos7 linux-5.14]# cat System.map | grep sp805_wdt_resume
[root@centos7 linux-5.14]# 

clean 下重新编译

[root@centos7 linux-5.14]# cat System.map | grep sp805_wdt_probe
[root@centos7 linux-5.14]# cat System.map | grep sp805
ffffffff8061c276 t sp805_wdt_driver_init
ffffffff8062ae7e t sp805_wdt_driver_exit
ffffffff8080f5f8 d __initcall__kmod_sp805_wdt__324_358_sp805_wdt_driver_init6
[root@centos7 linux-5.14]# cat System.map | grep amba_driver_
[root@centos7 linux-5.14]# 

但是还是没有amba_driver_

原来是.config 和 driver/xx/Kconfig   driver/xx/Makefile 中的config_XXX不一致

 

[root@centos7 linux-5.14]# make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j128 
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  CC      drivers/amba/bus.o
drivers/amba/bus.c:343:5: error: redefinition of 'amba_driver_register'
  343 | int amba_driver_register(struct amba_driver *drv)
      |     ^~~~~~~~~~~~~~~~~~~~
In file included from drivers/amba/bus.c:16:
./include/linux/amba/bus.h:112:19: note: previous definition of 'amba_driver_register' with type 'int(struct amba_driver *)'
  112 | static inline int amba_driver_register(struct amba_driver *drv)
      |                   ^~~~~~~~~~~~~~~~~~~~
drivers/amba/bus.c:361:6: error: redefinition of 'amba_driver_unregister'
  361 | void amba_driver_unregister(struct amba_driver *drv)
      |      ^~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/amba/bus.c:16:
./include/linux/amba/bus.h:116:20: note: previous definition of 'amba_driver_unregister' with type 'void(struct amba_driver *)'
  116 | static inline void amba_driver_unregister(struct amba_driver *drv)
      |                    ^~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:271: drivers/amba/bus.o] Error 1
make[1]: *** [scripts/Makefile.build:514: drivers/amba] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1851: drivers] Error 2
[root@centos7 linux-5.14]# find ./ -name amba
./include/linux/amba
./drivers/amba
[root@centos7 linux-5.14]# vim 

更改 vim include/linux/amba/bus.h +116

[root@centos7 linux-5.14]# make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j128 
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  CC      drivers/amba/bus.o
  CC      drivers/of/platform.o
  AR      drivers/of/built-in.a
  AR      drivers/amba/built-in.a
  AR      drivers/built-in.a
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  AR      init/built-in.a
  LD      vmlinux.o
  MODPOST vmlinux.symvers
  MODINFO modules.builtin.modinfo
  GEN     modules.builtin
  LD      .tmp_vmlinux.kallsyms1
  KSYMS   .tmp_vmlinux.kallsyms1.S
  AS      .tmp_vmlinux.kallsyms1.S
  LD      .tmp_vmlinux.kallsyms2
  KSYMS   .tmp_vmlinux.kallsyms2.S
  AS      .tmp_vmlinux.kallsyms2.S
  LD      vmlinux
  SYSMAP  System.map
  MODPOST modules-only.symvers
  OBJCOPY arch/riscv/boot/Image
  GEN     Module.symvers
  GZIP    arch/riscv/boot/Image.gz
  Kernel: arch/riscv/boot/Image.gz is ready
[root@centos7 linux-5.14]# cat System.map | grep amba_driver_
ffffffff804f0d12 T amba_driver_register
ffffffff804f0d38 T amba_driver_unregister
ffffffff80f77568 r __ksymtab_amba_driver_register
ffffffff80f77580 r __ksymtab_amba_driver_unregister
ffffffff80faf548 r __kstrtabns_amba_driver_register
ffffffff80faf548 r __kstrtabns_amba_driver_unregister
ffffffff80fb98fd r __kstrtab_amba_driver_register
ffffffff80fb9912 r __kstrtab_amba_driver_unregister
[root@centos7 linux-5.14]# 
[root@centos7 linux-5.14]# cat System.map  | grep sp805_
ffffffff804ba33e t sp805_wdt_remove
ffffffff804fa280 t sp805_wdt_probe
ffffffff8061c276 t sp805_wdt_driver_init
ffffffff8062aeb6 t sp805_wdt_driver_exit
ffffffff8080f600 d __initcall__kmod_sp805_wdt__324_359_sp805_wdt_driver_init6
ffffffff80e8f4c0 d sp805_wdt_ids
ffffffff80e8f4e0 d sp805_wdt_dev_pm_ops
ffffffff812b1280 d sp805_wdt_driver

login[98]: root login on 'console'
#
# ls /sys/bus/amba/
devices drivers_autoprobe uevent
drivers drivers_probe
#
# ls /sys/bus/amba/devices/
#
# ls /sys/bus/amba/devices/
#
# ls /sys/bus/amba/devices/drivers
ls: /sys/bus/amba/devices/drivers: No such file or directory
#
# ls /sys/bus/amba/
devices drivers_autoprobe uevent
drivers drivers_probe
#
# ls /sys/bus/amba/drivers
sp805-wdt
#
# ls /sys/bus/amba/drivers/sp805-wdt/
bind uevent unbind
#
# ls /sys/bus/amba/devices/
#
# ls /dev/watchdog
ls: /dev/watchdog: No such file or directory
#
#

amba_device_create

 customize_machine

  ->of_platform_populate

    ->of_platform_bus_create

      ->of_amba_device_create

        ->of_amba_device_create
-> ……
->
call_driver_probe
-->amba_probe -->pcdrv->probe(pcdev, id) -->sp805_wdt_probe

 sp805-wdt: probe of 20030000.watchdog failed with error -2

static int call_driver_probe(struct device *dev, struct device_driver *drv)
{
        int ret = 0;

        if (dev->bus->probe)
                ret = dev->bus->probe(dev);
        else if (drv->probe)
                ret = drv->probe(dev);

        switch (ret) {
        case 0:
                break;
        case -EPROBE_DEFER:
                /* Driver requested deferred probing */
                dev_dbg(dev, "Driver %s requests probe deferral
", drv->name);
                break;
        case -ENODEV:
        case -ENXIO:
                pr_debug("%s: probe of %s rejects match %d
",
                         drv->name, dev_name(dev), ret);
                break;
        default:
                /* driver matched but the probe failed */
                pr_warn("%s: probe of %s failed with error %d
",
                        drv->name, dev_name(dev), ret);
                break;
        }

        return ret;
}

 amba_probe(struct device *dev) -->amba_get_enable_pclk-->clk_get 

调用clk_get失败了

drivers/clk/clkdev.c

struct clk *clk_get(struct device *dev, const char *con_id)
{
        const char *dev_id = dev ? dev_name(dev) : NULL;
        struct clk_hw *hw;

        if (dev && dev->of_node) {
                hw = of_clk_get_hw(dev->of_node, 0, con_id);
                if (!IS_ERR(hw) || PTR_ERR(hw) == -EPROBE_DEFER)
                        return clk_hw_create_clk(dev, hw, dev_id, con_id);
        }

        return __clk_get_sys(dev, dev_id, con_id);
}

 struct device_node *of_node; /* associated device tree node */

ARM amba总线驱动

原文地址:https://www.cnblogs.com/dream397/p/15493911.html