drivers/mfd/Mfd-core.c

mfd: multifunction device drivers---多功能设备驱动开发;
A product or device that has multiple functions. An example of this might be a printer that also makes copies, faxes, and scans. Another example is a CD or DVD that might contain multiple applications on the same disk; this may be a Mac and PC version of the same software or media meant to be played on more than one platform. Also called multi function product (MFP), all-in-one.

源码主要是做了一些platform_device的注册和添加删除工作。

 

[cpp]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. int mfd_add_devices(struct device *parent, int id,  
  2.             struct mfd_cell *cells, int n_devs,  
  3.             struct resource *mem_base,  
  4.             int irq_base)  
  5. {  
  6.     int i;  
  7.     int ret = 0;  
  8.     atomic_t *cnts;  
  9.   
  10.     /* initialize reference counting for all cells */  
  11.     cnts = kcalloc(n_devs, sizeof(*cnts), GFP_KERNEL);  
  12.     if (!cnts)  
  13.         return -ENOMEM;  
  14.   
  15.     for (i = 0; i < n_devs; i++) {  
  16.         atomic_set(&cnts[i], 0);  
  17.         cells[i].usage_count = &cnts[i];  
  18.         ret = mfd_add_device(parent, id, cells + i, mem_base, irq_base); 调用mfd_add_device()  
  19.         if (ret)  
  20.             break;  
  21.     }  
  22.   
  23.     if (ret)  
  24.         mfd_remove_devices(parent);  
  25.   
  26.     return ret;  
  27. }  
  28. EXPORT_SYMBOL(mfd_add_devices);  

在这个函数中,参数cells是数组,个数为参数n_devs。用户调用此函数前初始化了cells部分内容,但其中成员由本函数初始化:

 

 

[cpp]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. /* 
  2.  * This struct describes the MFD part ("cell"). 
  3.  * After registration the copy of this structure will become the platform data 
  4.  * of the resulting platform_device 
  5.  */  
  6. struct mfd_cell {  //个人理解:注册mfd_cell后等效为platform_device
  7.     const char      *name;       
  8.     int         id;                    
  9.   
  10.     /* refcounting for multiple drivers to use a single cell */  
  11.     atomic_t        *usage_count;    //本函数初始化  
  12.     int         (*enable)(struct platform_device *dev);  
  13.     int         (*disable)(struct platform_device *dev);  
  14.   
  15.     int         (*suspend)(struct platform_device *dev);  
  16.     int         (*resume)(struct platform_device *dev);  
  17.   
  18.     /* platform data passed to the sub devices drivers */  
  19.     void            *platform_data;  
  20.     size_t          pdata_size;  
  21.   
  22.     /* 
  23.      * These resources can be specified relative to the parent device. 
  24.      * For accessing hardware you should use resources from the platform dev 
  25.      */  
  26.     int         num_resources;  
  27.     const struct resource   *resources;  
  28.   
  29.     /* don't check for resource conflicts */  
  30.     bool            ignore_resource_conflicts;  
  31.   
  32.     /* 
  33.      * Disable runtime PM callbacks for this subdevice - see 
  34.      * pm_runtime_no_callbacks(). 
  35.      */  
  36.     bool            pm_runtime_no_callbacks;  
  37. };  

再来看mfd_add_device()

 

 

[cpp]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. static int mfd_add_device(struct device *parent, int id,  
  2.               const struct mfd_cell *cell,  
  3.               struct resource *mem_base,  
  4.               int irq_base)  
  5. {  
  6.     struct resource *res;  
  7.     struct platform_device *pdev;  
  8.     int ret = -ENOMEM;  
  9.     int r;  
  10.   
  11.     pdev = platform_device_alloc(cell->name, id + cell->id); //申请pdev内存并初始化name和id  
  12.     if (!pdev)  
  13.         goto fail_alloc;  
  14.   
  15.     res = kzalloc(sizeof(*res) * cell->num_resources, GFP_KERNEL);  
  16.     if (!res)  
  17.         goto fail_device;  
  18.   
  19.     pdev->dev.parent = parent;  
  20.     pdev->dev.type = &mfd_dev_type;  
  21.   
  22.     if (cell->pdata_size) {  //重新分配pdev->dev. platform_data内存并将cell->platform_data赋给它。  
  23.         ret = platform_device_add_data(pdev,  
  24.                     cell->platform_data, cell->pdata_size);  
  25.         if (ret)  
  26.             goto fail_res;  
  27.     }  
  28.   
  29.     ret = mfd_platform_add_cell(pdev, cell); //重新分配pdev->mfd_cell内存并将cell赋给它。  
  30.     if (ret)  
  31.         goto fail_res;  
  32.   
  33. //初始化cell->num_resources 个数量的res将它赋给pdev->resource  
  34.     for (r = 0; r < cell->num_resources; r++) {  
  35.         res[r].name = cell->resources[r].name;  
  36.         res[r].flags = cell->resources[r].flags;  
  37.   
  38.         /* Find out base to use */  
  39.         if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) {  
  40.             res[r].parent = mem_base;  
  41.             res[r].start = mem_base->start +    //cell中的每个内存start都要加上mem_base->start  
  42.                 cell->resources[r].start;  
  43.             res[r].end = mem_base->start +  
  44.                 cell->resources[r].end;  
  45.         } else if (cell->resources[r].flags & IORESOURCE_IRQ) {  
  46.             res[r].start = irq_base +           //每个cell中的irq都要加上irq_base。  
  47.                 cell->resources[r].start;  
  48.             res[r].end   = irq_base +  
  49.                 cell->resources[r].end;  
  50.         } else {  
  51.             res[r].parent = cell->resources[r].parent;  
  52.             res[r].start = cell->resources[r].start;  
  53.             res[r].end   = cell->resources[r].end;  
  54.         }  
  55.   
  56.         if (!cell->ignore_resource_conflicts) {  
  57.             ret = acpi_check_resource_conflict(&res[r]);  
  58.             if (ret)  
  59.                 goto fail_res;  
  60.         }  
  61.     }  
  62.   
  63.     ret = platform_device_add_resources(pdev, res, cell->num_resources);//将多个res赋给pdev  
  64.     if (ret)  
  65.         goto fail_res;  
  66.   
  67.     ret = platform_device_add(pdev); //添加一个platform_device到系统,这时在dev的驱动中会使用这些res数据。  
  68.     if (ret)  
  69.         goto fail_res;  
  70.   
  71.     if (cell->pm_runtime_no_callbacks)  
  72.         pm_runtime_no_callbacks(&pdev->dev);  
  73.   
  74.     kfree(res);  
  75.   
  76.     return 0;  
  77.   
  78. fail_res:  
  79.     kfree(res);  
  80. fail_device:  
  81.     platform_device_put(pdev);  
  82. fail_alloc:  
  83.     return ret;  
  84. }  



转载于:https://www.cnblogs.com/Ph-one/p/5785054.html

a20_hummingbird_v4.5_v1.0_csi01_2ov7670_rtl8188eus 20150918 1830 JNI.7z 无法打开USB Wifi rtl8188eus.txt 配置前后ov7670双摄像头 JNI调用读写一次之后就会出现内核出错,系统死机。 有可能与系统为android4.4有关。 无法打开USB Wifi rtl8188eus shell@wing-k70:/ $ shell@wing-k70:/ $ shell@wing-k70:/ $ shell@wing-k70:/ $ logcat -c shell@wing-k70:/ $ logcat --------- beginning of /dev/log/system I/ActivityManager( 1670): Waited long enough for: ServiceRecord{41e90e08 u0 com.android.calendar/.alerts.InitAlarmsService} --------- beginning of /dev/log/main D/dalvikvm( 1849): GC_FOR_ALLOC freed 673K, 22% free 5143K/6512K, paused 41ms, total 47ms I/ActivityManager( 1670): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.settings/.Settings} from pid 1849 D/PermissionCache( 1252): checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (3161 us) D/BluetoothAdapter( 1931): 1103979928: getState() : mService = null. Returning STATE_OFF D/libEGL ( 1931): loaded /system/lib/egl/libEGL_mali.so D/libEGL ( 1931): loaded /system/lib/egl/libGLESv1_CM_mali.so D/libEGL ( 1931): loaded /system/lib/egl/libGLESv2_mali.so D/OpenGLRenderer( 1931): Enabling debug mode 0 D/BluetoothAdapter( 1931): 1103979928: getState() : mService = null. Returning STATE_OFF I/ActivityManager( 1670): Displayed com.android.settings/.Settings: +1s78ms D/WifiService( 1670): setWifiEnabled: true pid=1931, uid=1000 D/WifiHW ( 1670): Start to insmod 8188eu.ko [ 54.805792] ****wyb arch/arm/mach-sun7i/rf/wifi_pm.c:69/wifi_pm_power()! on=1 [ 54.813855] ****wyb arch/arm/mach-sun7i/rf/wifi_pm.c:73/wifi_pm_power()! [ 54.821376] ****wyb arch/arm/mach-sun7i/rf/wifi_pm_rtl8188eu.c:197/rtl8188eu_power()! mode=1 *updown=1 [ 54.831805] ****wyb arch/arm/mach-sun7i/rf/wifi_pm_rtl8188eu.c:95/rtl8188eu_gpio_ctrl()! name=rtk_rtl8188eu_wl_dis, level=1 [ 54.844290] ****wyb arch/arm/mach-sun7i/rf/wifi_pm_rtl8188eu.c:209/rtl8188eu_power()! usb wifi power state: on [ 54.855621] ----wyb arch/arm/mach-sun7i/rf/wifi_pm_rtl8188eu.c:222/rtl8188eu_power()! D/WifiHW ( 1670): faied to read proc/net/wireless D/WifiHW ( 1670): loading wifi driver... D/WifiHW ( 1670): faied to read proc/net/wireless D/WifiHW ( 1670): loading wifi driver... I/USB3G ( 1258): event { 'add', '/devices/platform/sw-ehci.2/usb4/4-1', 'usb', '', 189, 385 } I/USB3G ( 1258): path : '/sys/devices/platform/sw-ehci.2/usb4/4-1' I/USB3G ( 1258): VID :size 5,vid_path '/sys/devices/platform/sw-ehci.2/usb4/4-1/idVendor',VID '0bda I/USB3G ( 1258): '. I/USB3G ( 1258): PID :size 5,Pid_path '/sys/devices/platform/sw-ehci.2/usb4/4-1/idProduct',PID '8179 I/USB3G ( 1258): '. I/USB3G ( 1258): cmd=source /system/xbin/usb_modeswitch.sh /system/etc/usb_modeswitch.d/0bda_8179 &, D/WifiHW ( 1670): faied to read proc/net/wireless D/WifiHW ( 1670): loading wifi driver... I/USB3G ( 1258): excute ret:0,err:No such file or directory I/USB3G ( 1258): free cmd W/ContextImpl( 1670): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1123 com.android.server.usb.UsbSettingsManager.deviceAttached:621 com.android.server.usb.UsbHostManager.usbDeviceAdded:156 com.android.server.usb.UsbHostManager.monitorUsbHostBus:-2 com.android.server.usb.UsbHostManager.access$000:38 D/Tethering( 1670): sendTetherStateChangedBroadcast 1, 0, 0 W/SocketClient( 1249): write error (Broken pipe) D/Tethering( 1670): InitialState.processMessage what=4 D/Tethering( 1670): sendTetherStateChangedBroadcast 0, 0, 0 D/WifiHW ( 1670): faied to read proc/net/wireless D/WifiHW ( 1670): loading wifi driver... D/WifiHW ( 1249): Enter: wifi_get_fw_path function, fw_type=0, D/WifiHW ( 1249): Eneter: wifi_change_fw_path, fwpath = STA. D/SoftapController( 1249): Softap fwReload - Ok D/CommandListener( 1249): Setting iface cfg D/CommandListener( 1249): Trying to bring down wlan0 D/WifiMonitor( 1670): startMonitoring(wlan0) with mConnected = false I/wpa_supplicant( 2247): Successfully initialized wpa_supplicant I/wpa_supplicant( 2247): rfkill: Cannot open RFKILL control device D/BluetoothAdapter( 1931): 1103979928: getState() : mService = null. Returning STATE_OFF I/wpa_supplicant( 2247): rfkill: Cannot open RFKILL control device D/WifiConfigStore( 1670): Loading config and enabling all networks E/WifiConfigStore( 1670): Error parsing configurationjava.io.FileNotFoundException: /data/misc/wifi/ipconfig.txt: open failed: ENOENT (No such file or directory) D/BluetoothAdapter( 1931): 1103979928: getState() : mService = null. Returning STATE_OFF E/WifiStateMachine( 1670): Failed to set device name wing_k70 E/WifiStateMachine( 1670): Failed to set manufacturer Allwinner E/WifiStateMachine( 1670): Failed to set model name AOSP on wing E/WifiStateMachine( 1670): Failed to set model number AOSP on wing E/WifiStateMachine( 1670): Failed to set serial number 582034060190a829459 E/WifiStateMachine( 1670): Failed to set WPS config methods E/WifiStateMachine( 1670): Failed to set primary device type 10-0050F204-5 D/CommandListener( 1249): Setting iface cfg D/CommandListener( 1249): Trying to bring up p2p0 D/WifiMonitor( 1670): startMonitoring(p2p0) with mConnected = true E/WifiStateMachine( 1670): Failed to set frequency band 0 [ 57.384990] init: untracked pid 2221 exited D/InitAlarmsService( 2053): Clearing and rescheduling alarms. W/SocketClient( 1249): write error (Broken pipe) D/ConnectivityService( 1670): Sampling interval elapsed, updating statistics .. D/ConnectivityService( 1670): Done. D/ConnectivityService( 1670): Setting timer for 720seconds I/MediaFocusControl( 1670): AudioFocus abandonAudioFocus() from android.media.AudioManager@41cc7828com.android.music.MediaPlaybackService$3@41cc66a8 I/ActivityManager( 1670): Start proc com.android.musicfx for broadcast com.android.musicfx/.ControlPanelReceiver: pid=2265 uid=10008 gids={50008, 3003, 3002} V/MusicFXControlPanelReceiver( 2265): onReceive V/MusicFXControlPanelReceiver( 2265): Action: android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION V/MusicFXControlPanelReceiver( 2265): Package name: com.android.music V/MusicFXControlPanelReceiver( 2265): Audio session: 8 V/MusicFXControlPanelEffect( 2265): closeSession(android.app.ReceiverRestrictedContext@41ccc508, com.android.music, 8) ^C 130|shell@wing-k70:/ $
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值