当前位置:   article > 正文

NanoPi NEO小试牛刀(二)_allwinner drm

allwinner drm

你好!这里是风筝的博客,

欢迎和我一起交流。


前面写了NanoPi NEO的启动过程:NanoPi NEO小试牛刀(一)
但是我发现NanoPi NEO启动Linux内核时加载的东西太多了,Linux内核是没有经过剪裁的,我们可以试着剪裁优化下:

make menuconfig ARCH=arm CROSS_COMPILE=arm-linux-
  • 1

Networking support —>Networking options—> Network packet filtering framework (Netfilter)    我不打算使用防火墙,要用到时再编译进去

Networking support—> < >CAN bus subsystem support     我不打算使用CAN总线

Networking support —> < > RF switch subsystem support     我没有RF 切换设备

Device Drivers —>< >Serial ATA and Parallel ATA drivers (libata)     SATA或PATA接口的硬盘或光驱等设备

Device Drivers —>[ ] Multiple devices driver support (RAID and LVM)     暂时没有要使用Raid (磁盘阵列)和LVM (逻辑卷管理器,添加,删除逻辑分区)的需求

Device Drivers —> <> Sound card support      暂时没有无声卡

Device Drivers —> Graphics support –>< > DRM Support for Allwinner A10 Display Engine      没有视频播放

[ ] Virtualization      不需要

把这些都取消掉,然后选择支持nfs,这个好用:
File systems —> Network File Systems     支持nfs

最后保存退出,编译出来的zImage文件就小好多了

现在可以试着写一个简单的驱动试一下效果:
led.c:

/*
 Port A(PA): 22 input/output port ? 
 Port C(PC): 19 input/output port ? 
 Port D(PD): 18 input/output port ? 
 Port E(PE) : 16 input/output port ? 
 Port F(PF) : 7 input/output port ? 
 Port G(PG) : 14 input/output port ? 
 Port L(PL) : 12 input/output port 

 PIO 0x01C20800 
 Pn_CFG0 n*0x24+0x00 Port n Configure Register 0 (n from 0 to 6)
 Pn_CFG1 n*0x24+0x04 Port n Configure Register 1 (n from 0 to 6)
 Pn_CFG2 n*0x24+0x08 Port n Configure Register 2 (n from 0 to 6)
 Pn_CFG3 n*0x24+0x0C Port n Configure Register 3 (n from 0 to 6)
 Pn_DAT n*0x24+0x10 Port n Data Register (n from 0 to 6)
 Pn_DRV0 n*0x24+0x14 Port n Multi-Driving Register 0 (n from 0 to 6)
 Pn_DRV1 n*0x24+0x18 Port n Multi-Driving Register 1 (n from 0 to 6)
 Pn_PUL0 n*0x24+0x1C Port n Pull Register 0 (n from 0 to 6)
 Pn_PUL1 n*0x24+0x20 Port n Pull Register 1 (n from 0 to 6)
*/

#include <linux/cdev.h>
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/device.h>


//#include <linux/of_address.h>
//#include <linux/of_platform.h>


static volatile unsigned long *gpacon1;
static volatile unsigned long *gpadat;//a10



/*CFG0_REG Default Value: 0x7777777
 * [30:28] Pn7_SELECT
 * [26:24] Pn6_SELECT
 * [22:20] Pn5_SELECT
 * [18:16] Pn4_SELECT
 * [14:12] Pn3_SELECT
 * [10: 8] Pn2_SELECT
 * [ 6: 4] Pn1_SELECT
 * [ 2: 0] Pn0_SELECT
 *000:Input                001:Output  111:disable
 */

/*CFG1_REG Default Value: 0x7777777
 * [30:28] Pn15_SELECT
 * [26:24] Pn14_SELECT
 * [22:20] Pn13_SELECT
 * [18:16] Pn12_SELECT
 * [14:12] Pn11_SELECT
 * [10: 8] Pn10_SELECT
 * [ 6: 4] Pn9_SELECT
 * [ 2: 0] Pn8_SELECT
 *000:Input             001:Output 
 */

/*CFG2_REG Default Value: 0x7777777
 * [22:20] Pn21_SELECT
 * [18:16] Pn20_SELECT
 * [14:12] Pn19_SELECT
 * [10: 8] Pn18_SELECT
 * [ 6: 4] Pn17_SELECT
 * [ 2: 0] Pn16_SELECT
 *000:Input              001:Output  
*/

/*Pn_DAT Default Value: 0x0
 * [21:0] if input :read pin state; if outport : pin state is same bit
*/

static int led_open(struct inode *inode, struct file *file)   
{
    printk("this is nanopi neo led \n");
    *gpacon1 |= (0x01<<(8));//PA10=Output

    return 0;
}

static ssize_t led_read(struct file * file, char __user *buf, size_t count, loff_t *off)
{
    printk("read nanopi neo led \n");
    //*gpadat &= ~(0x01<<(10));//PA10=0
    *gpadat |= (0x01<<(10));//PA10=1


    return 0;
}

static ssize_t led_write(struct file *file, const char __user *buf,size_t count, loff_t *ppos)
{
    //*gpadat

    return 0;
}


static struct file_operations led10_fops = {
    .owner  = THIS_MODULE,
    .open   = led_open,
    .read   = led_read, 
    .write  = led_write,
};

/* 1. 确定主设备号 */
static int major;
static struct cdev led10_cdev;
static struct class *cls;

static int led_drv_init(void)
{
    int res;
    struct device * led_res;
    dev_t devid;

    /* 3. 告诉内核 */
#if 0
    major = register_chrdev(0, "hello", &hello_fops); /* (major,  0), (major, 1), ..., (major, 255)都对应hello_fops */
#else /*仅仅是注册设备号*/
    if (major) {
        devid = MKDEV(major, 0);
        register_chrdev_region(devid, 1, "led_blue");  /* (major,0) 对应 pwm_fops, (major, 1~255)都不对应pwm_fops */
    } else {
        alloc_chrdev_region(&devid, 0, 1, "led_blue"); /* (major,0) 对应 pwm_fops, (major, 1~255)都不对应pwm_fops */
        major = MAJOR(devid);                     
    }

    cdev_init(&led10_cdev, &led10_fops);
    res=cdev_add(&led10_cdev, devid, 1);
    if(res)
    {
        printk("cdev_add failed\n");
        unregister_chrdev_region(MKDEV(major, 0), 1);
        return 0;
    }
#endif

    cls = class_create(THIS_MODULE, "led_blue");
    led_res = device_create(cls, (struct device *)NULL, MKDEV(major, 0), (void *)NULL, (const char *)"led_blue"); /* /dev/xxx */
    if (IS_ERR((const void *)res)) 
    {
        printk("device_create failed\n");
        return 0;
    }

    gpacon1 = ioremap(0x01C20800+0*0x24+0x04 , 0x4*4);
    gpadat  = gpacon1+3;
    if (!gpacon1)
    {
        printk("ioremap failed\n");
        return -EIO;
    }

    return 0;
}

static void led_drv_exit(void)
{
    unregister_chrdev(major, "led_blue"); // 卸载
    device_destroy(cls,MKDEV(major, 0));
    class_destroy(cls);
    iounmap(gpacon1);
}

module_init(led_drv_init);
module_exit(led_drv_exit);

MODULE_LICENSE("GPL");

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182

这就是一个简单的控制PA10管脚的程序,测试了下,可以使用。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/953921
推荐阅读
相关标签
  

闽ICP备14008679号