首页 > 系统相关 >按键 芯片jornada680 linux驱动程序

按键 芯片jornada680 linux驱动程序

时间:2024-12-01 11:31:49浏览次数:8  
标签:__ jornadakbd 驱动程序 unsigned dev jornada680 KEY linux input

/*

  • drivers/input/keyboard/jornada680_kbd.c
  • HP Jornada 620/660/680/690 scan keyboard platform driver
  • Based on hp680_keyb.c
  • Copyright © 2006 Paul Mundt
  • Copyright © 2005 Andriy Skulysh
  • Split from drivers/input/keyboard/hp600_keyb.c
  • Copyright © 2000 Yaegashi Takeshi (hp6xx kbd scan routine and translation table)
  • Copyright © 2000 Niibe Yutaka (HP620 Keyb translation table)
  • This program is free software; you can redistribute it and/or modify it
  • under the terms of the GNU General Public License version 2 as
  • published by the Free Software Foundation.
    */

#include <linux/device.h>
#include <linux/input.h>
#include <linux/input-polldev.h>
#include <linux/interrupt.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>

#include <asm/delay.h>
#include <asm/io.h>

#define PCCR 0xa4000104
#define PDCR 0xa4000106
#define PECR 0xa4000108
#define PFCR 0xa400010a
#define PCDR 0xa4000124
#define PDDR 0xa4000126
#define PEDR 0xa4000128
#define PFDR 0xa400012a
#define PGDR 0xa400012c
#define PHDR 0xa400012e
#define PJDR 0xa4000130
#define PKDR 0xa4000132
#define PLDR 0xa4000134

static const unsigned short jornada_scancodes[] = {
/* PTD1 / KEY_CAPSLOCK, KEY_MACRO, KEY_LEFTCTRL, 0, KEY_ESC, KEY_KP5, 0, 0, / 1 -> 8 /
KEY_F1, KEY_F2, KEY_F3, KEY_F8, KEY_F7, KEY_F6, KEY_F4, KEY_F5, /
9 -> 16 /
/
PTD5 / KEY_SLASH, KEY_APOSTROPHE, KEY_ENTER, 0, KEY_Z, 0, 0, 0, / 17 -> 24 /
KEY_X, KEY_C, KEY_V, KEY_DOT, KEY_COMMA, KEY_M, KEY_B, KEY_N, /
25 -> 32 /
/
PTD7 / KEY_KP2, KEY_KP6, KEY_KP3, 0, 0, 0, 0, 0, / 33 -> 40 /
KEY_F10, KEY_RO, KEY_F9, KEY_KP4, KEY_NUMLOCK, KEY_SCROLLLOCK, KEY_LEFTALT, KEY_HANJA, /
41 -> 48 /
/
PTE0 / KEY_KATAKANA, KEY_KP0, KEY_GRAVE, 0, KEY_FINANCE, 0, 0, 0, / 49 -> 56 /
KEY_KPMINUS, KEY_HIRAGANA, KEY_SPACE, KEY_KPDOT, KEY_VOLUMEUP, 249, 0, 0, /
57 -> 64 /
/
PTE1 / KEY_SEMICOLON, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, KEY_A, 0, 0, 0, / 65 -> 72 /
KEY_S, KEY_D, KEY_F, KEY_L, KEY_K, KEY_J, KEY_G, KEY_H, /
73 -> 80 /
/
PTE3 / KEY_KP8, KEY_LEFTMETA, KEY_RIGHTSHIFT, 0, KEY_TAB, 0, 0, 0, / 81 -> 88 /
0, KEY_LEFTSHIFT, KEY_KP7, KEY_KP9, KEY_KP1, KEY_F11, KEY_KPPLUS, KEY_KPASTERISK, /
89 -> 96 /
/
PTE6 / KEY_P, KEY_LEFTBRACE, KEY_BACKSPACE, 0, KEY_Q, 0, 0, 0, / 97 -> 104 /
KEY_W, KEY_E, KEY_R, KEY_O, KEY_I, KEY_U, KEY_T, KEY_Y, /
105 -> 112 /
/
PTE7 / KEY_0, KEY_MINUS, KEY_EQUAL, 0, KEY_1, 0, 0, 0, / 113 -> 120 /
KEY_2, KEY_3, KEY_4, KEY_9, KEY_8, KEY_7, KEY_5, KEY_6, /
121 -> 128 /
/
**** */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
};

#define JORNADA_SCAN_SIZE 18

struct jornadakbd {
struct input_polled_dev *poll_dev;
unsigned short keymap[ARRAY_SIZE(jornada_scancodes)];
unsigned char length;
unsigned char old_scan[JORNADA_SCAN_SIZE];
unsigned char new_scan[JORNADA_SCAN_SIZE];
};

static void jornada_parse_kbd(struct jornadakbd *jornadakbd)
{
struct input_dev *input_dev = jornadakbd->poll_dev->input;
unsigned short *keymap = jornadakbd->keymap;
unsigned int sync_me = 0;
unsigned int i, j;

for (i = 0; i < JORNADA_SCAN_SIZE; i++) {
	unsigned char new = jornadakbd->new_scan[i];
	unsigned char old = jornadakbd->old_scan[i];
	unsigned int xor = new ^ old;

	if (xor == 0)
		continue;

	for (j = 0; j < 8; j++) {
		unsigned int bit = 1 << j;
		if (xor & bit) {
			unsigned int scancode = (i << 3) + j;
			input_event(input_dev,
				    EV_MSC, MSC_SCAN, scancode);
			input_report_key(input_dev,
					 keymap[scancode],
					 !(new & bit));
			sync_me = 1;
		}
	}
}

if (sync_me)
    input_sync(input_dev);

}

static void jornada_scan_keyb(unsigned char s)
{
int i;
unsigned short ec_static, dc_static; /
= UINT16_t /
unsigned char matrix_switch[] = {
0xfd, 0xff, /
PTD1 PD(1) /
0xdf, 0xff, /
PTD5 PD(5) /
0x7f, 0xff, /
PTD7 PD(7) /
0xff, 0xfe, /
PTE0 PE(0) /
0xff, 0xfd, /
PTE1 PE(1) /
0xff, 0xf7, /
PTE3 PE(3) /
0xff, 0xbf, /
PTE6 PE(6) /
0xff, 0x7f, /
PTE7 PE(7) /
}, t = matrix_switch;
/
PD(x) :
1. 0xcc0c & (1~(1 << (2
(x)+1)))))
2. (0xf0cf & 0xfffff) /
/
PE(x) :
1. 0xcc0c & 0xffff
2. 0xf0cf & (1~(1 << (2*(x)+1))))) /
unsigned short matrix_PDE[] = {
0xcc04, 0xf0cf, /
PD(1) /
0xc40c, 0xf0cf, /
PD(5) /
0x4c0c, 0xf0cf, /
PD(7) /
0xcc0c, 0xf0cd, /
PE(0) /
0xcc0c, 0xf0c7, /
PE(1) /
0xcc0c, 0xf04f, /
PE(3) /
0xcc0c, 0xd0cf, /
PE(6) /
0xcc0c, 0x70cf, /
PE(7) */
}, *y = matrix_PDE;

/* Save these control reg bits */
dc_static = (__raw_readw(PDCR) & (~0xcc0c));
ec_static = (__raw_readw(PECR) & (~0xf0cf));

for (i = 0; i < 8; i++) {
	/* disable output for all but the one we want to scan */
	__raw_writew((dc_static | *y++), PDCR);
	__raw_writew((ec_static | *y++), PECR);
	udelay(5);

	/* Get scanline row */
	__raw_writeb(*t++, PDDR);
	__raw_writeb(*t++, PEDR);
	udelay(50);

	/* Read data */
	*s++ = __raw_readb(PCDR);
	*s++ = __raw_readb(PFDR);
}
/* Scan no lines */
__raw_writeb(0xff, PDDR);
__raw_writeb(0xff, PEDR);

/* Enable all scanlines */
__raw_writew((dc_static | (0x5555 & 0xcc0c)),PDCR);
__raw_writew((ec_static | (0x5555 & 0xf0cf)),PECR);

/* Ignore extra keys and events */
*s++ = __raw_readb(PGDR);
*s++ = __raw_readb(PHDR);

}

static void jornadakbd680_poll(struct input_polled_dev *dev)
{
struct jornadakbd *jornadakbd = dev->private;

jornada_scan_keyb(jornadakbd->new_scan);
jornada_parse_kbd(jornadakbd);
memcpy(jornadakbd->old_scan, jornadakbd->new_scan, JORNADA_SCAN_SIZE);

}

static int jornada680kbd_probe(struct platform_device *pdev)
{
struct jornadakbd *jornadakbd;
struct input_polled_dev *poll_dev;
struct input_dev *input_dev;
int i, error;

jornadakbd = devm_kzalloc(&pdev->dev, sizeof(struct jornadakbd),
			  GFP_KERNEL);
if (!jornadakbd)
	return -ENOMEM;

poll_dev = devm_input_allocate_polled_device(&pdev->dev);
if (!poll_dev) {
	dev_err(&pdev->dev, "failed to allocate polled input device\n");
	return -ENOMEM;
}

jornadakbd->poll_dev = poll_dev;

memcpy(jornadakbd->keymap, jornada_scancodes,
	sizeof(jornadakbd->keymap));

poll_dev->private = jornadakbd;
poll_dev->poll = jornadakbd680_poll;
poll_dev->poll_interval = 50; /* msec */

input_dev = poll_dev->input;
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
input_dev->name = "HP Jornada 680 keyboard";
input_dev->phys = "jornadakbd/input0";
input_dev->keycode = jornadakbd->keymap;
input_dev->keycodesize = sizeof(unsigned short);
input_dev->keycodemax = ARRAY_SIZE(jornada_scancodes);
input_dev->dev.parent = &pdev->dev;
input_dev->id.bustype = BUS_HOST;

for (i = 0; i < 128; i++)
	if (jornadakbd->keymap[i])
		__set_bit(jornadakbd->keymap[i], input_dev->keybit);
__clear_bit(KEY_RESERVED, input_dev->keybit);

input_set_capability(input_dev, EV_MSC, MSC_SCAN);

error = input_register_polled_device(jornadakbd->poll_dev);
if (error) {
	dev_err(&pdev->dev, "failed to register polled input device\n");
	return error;
}

return 0;

}

static struct platform_driver jornada680kbd_driver = {
.driver = {
.name = “jornada680_kbd”,
},
.probe = jornada680kbd_probe,
};
module_platform_driver(jornada680kbd_driver);

MODULE_AUTHOR(“xxx”);
MODULE_DESCRIPTION(“HP Jornada 620/660/680/690 Keyboard Driver”);
MODULE_LICENSE(“GPL v2”);
MODULE_ALIAS(“platform:jornada680_kbd”);

标签:__,jornadakbd,驱动程序,unsigned,dev,jornada680,KEY,linux,input
From: https://blog.csdn.net/baidu_37552881/article/details/144049788

相关文章

  • Linux提权之八大实战利器与高权限操作技巧
    文章目录LINUX提权0x01.SUID提权chmod命令Find命令(查找有SUID权限的文件)find提权nmap提权vim提权Bash提权Less或More提权nano提权CP提权awk提权0x02sudo提权0x03计划任务提权0x04内核漏洞提权0x05环境变量劫持提权0x06NFS提权0x07通配符WS提权0x08明文密码提权0x9lx......
  • Linux操作系统2-进程控制3(进程替换,exec相关函数和系统调用)
    上篇文章:Linux操作系统2-进程控制2(进程等待,waitpid系统调用,阻塞与非阻塞等待)-CSDN博客本篇代码Gitee仓库:Linux操作系统-进程的程序替换学习·d0f7bb4·橘子真甜/linux学习-Gitee.com本篇重点:进程替换目录一.什么是进程替换?二.进程替换函数常用的函数 2.1......
  • 【Linux】shell编程基础
    一、脚本的创建和执行创建一个1.sh文件vim1.sh在文件中写入以下内容:#!/bin/bash#或者写入#!/bin/sh#或者写入#!/bin/dash无论使用哪种脚本解释器,最终调用的可能是dash。检查默认的sh解释器:ls-l/bin/sh执行脚本文件./1.sh如果权限不足,可以......
  • Linux的150个常用命令汇总,运维大神不一定全部掌握!零基础入门到精通,收藏这一篇就够了
    下面是分类总结的150个命令,看一下你掌握了多少个?1文件和目录操作命令命令作用pwd显示当前所在位置cd切换目录tree以树形结构显示目录下的内容mkdir创建目录touch创建空文件ls显示目录下的内容及相关信息属性cp复制文件或目录mv移动或重命名文件rm删除文件或目录ln创建硬......
  • linux安装intel编译器2018
    加压软件/public/download/parallel_studio_2018.tgz进入目录后用./install.sh开始安装 按回车 这个选择1,然后需要输入lic激活文件路径。 安装完成后添加PATH到环境变量中1、如果是普通用户,在用户的.bashrc里面添加2、如果是root用户,在/etc/profile文件的最......
  • [Ubuntu] linux之Ubuntu18.04的下载及在虚拟机中详细安装过程(附有下载链接)
    前言ubuntu链接:https://pan.quark.cn/s/283509d0d36e提取码:dfT1链接失效(可能被官方和谐)可评论或私信我重发下载压缩包后解压!!安装路径不要有中文下载后解压得到.iso文件,不要放在有中文路径的目录下,我这里是解压放在E盘下打开虚拟机,这里使用的是VMwareWorkstation......
  • 学霸带你游戏化 Linux 防火墙 iptables、firewalld
    网络安全与流量控制的重要性在当今数字化时代,网络安全成为用户和组织关注的核心问题。对于在线游戏而言,稳定的网络连接和安全的环境是保证良好体验的基础。无论是《绝地求生》(PUBG)中的激烈战斗,还是《英雄联盟》(LeagueofLegends)的团队协作,都离不开高效的网络流量管理与安全防......
  • Linux程序员解决程序崩溃的问题
    Linux程序员解决程序崩溃的问题1.引言嘿,各位程序员小伙伴们!你们是否曾经遇到过程序突然“跑路”崩溃的情况?是不是觉得那一刻就像被一只无形的手拍在了脑门上,整个人都懵了?别担心,今天我们就来聊聊如何像侦探一样追查程序崩溃的真相,让你的代码更加坚不可摧!2.程序崩溃的常......
  • [Linux]动静态库
    动静态库静态库(.a):程序在编译链接的时候把库的代码链接到可执行文件中。程序运行的时候将不再需要静态库,但是,多个程序使用相同的静态库时,每个程序都会包含一份库的代码,可能会导致可执行文件体积较大。动态库(.so):是在程序运行时被加载的库。当一个程序链接了动态库,在程序启动时,操......
  • 《码农增刊Linus与Linux》读后感
     林纳斯的解释是,有三件事具有生命的意义。它们是你生活当中所有事情的动机。第一是生存,第二是社会秩序,第三是娱乐。生活中所有的事情都是按这个顺序发展的,娱乐之后便一无所有。其实每个人都有自己的理论,一件事做或者不做,都是自己说服自己,每一次进步,要么是推翻自己的理论,要么是......