add mic i2s0 changes

This commit is contained in:
wangzijiao 2018-08-01 15:15:23 +08:00
parent 614ba61941
commit f745631406
31 changed files with 5807 additions and 1727 deletions

View File

@ -4,6 +4,29 @@
menu "Misc devices"
config ADAU1761
tristate "ADI ADAU1761 DSP"
default n
---help---
ADI ADAU1761 DSP.
config ADAU1761_ES1
tristate "ADI ADAU1761 DSP FOR ES1"
default n
---help---
ADI ADAU1761 DSP FOR ES1.
config ADAU1761_ES2
tristate "ADI ADAU1761 DSP FOR ES2"
default n
---help---
ADI ADAU1761 DSP FOR ES2.
config ADAU1761_R311_PV1
tristate "ADI ADAU1761 DSP FOR R311 PV1"
default n
---help---
ADI ADAU1761 DSP FOR R311 PV1.
config SENSORS_LIS3LV02D
tristate
depends on INPUT
@ -800,4 +823,5 @@ source "drivers/misc/genwqe/Kconfig"
source "drivers/misc/echo/Kconfig"
source "drivers/misc/cxl/Kconfig"
source "drivers/misc/sunxi-rf/Kconfig"
source "drivers/misc/xunfei/Kconfig"
endmenu

View File

@ -73,3 +73,8 @@ $(obj)/lkdtm_rodata_objcopy.o: $(obj)/lkdtm_rodata.o FORCE
$(call if_changed,objcopy)
obj-$(CONFIG_SUNXI_RFKILL) += sunxi-rf/
obj-$(CONFIG_ADAU1761) += adau1761.o
obj-$(CONFIG_ADAU1761_ES1) += adau1761-es1.o
obj-$(CONFIG_ADAU1761_ES2) += adau1761-es2.o
obj-$(CONFIG_ADAU1761_R311_PV1) += adau1761-r311-pv1.o
obj-y += xunfei/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
menu "Xunfei module driver"
config XUNFEI_CPLD
tristate "xunfei cpld driver"
help
Xunfei CPLD Mic sample board control interfaces. Added by wzj. 2018-07-27
endmenu

View File

@ -0,0 +1 @@
obj-$(CONFIG_XUNFEI_CPLD) += cpld/i2c_operator.o cpld/fpga_loader.o cpld/fpga_config.o cpld/cx20810.o cpld/netease_config.o

View File

@ -0,0 +1,362 @@
#include <asm/io.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/sunxi-gpio.h>
#include <linux/timer.h>
// codec init param
#include "cx20810_config.h"
#define I2C_CX20810_DRIVER_NAME "i2c_cx20810"
#define MAX_CX20810_NUM (3)
void netease_enable_clk(void);
static int gpio_adc_rst = -1;
// g_client_cx20810[0] is on adapter 0 and its address is 0x35
// g_client_cx20810[1] is on adapter 1 and its address is 0x35
// g_client_cx20810[2] is on adapter 1 and its address is 0x3B
static struct i2c_client *g_client_cx20810[MAX_CX20810_NUM];
static const unsigned short i2c_cx20810_addr[] = {0x35, 0x3B, I2C_CLIENT_END};
static const struct i2c_device_id i2c_driver_cx20810_id[] = {
{I2C_CX20810_DRIVER_NAME, 0}, {}};
// function declaration
static int cx20810_hw_init(void);
static int i2c_driver_cx20810_probe(struct i2c_client *client,
const struct i2c_device_id *id);
static int i2c_driver_cx20810_remove(struct i2c_client *client);
static int i2c_driver_cx20810_detect(struct i2c_client *client,
struct i2c_board_info *info);
static int i2c_master_send_array_to_cx20810(const struct i2c_client *client,
const char *buf, int length);
static void cx20810_init(int index, int mode);
int cx20810_set_mode(int mode, int index);
// set cx20810 work mode
int cx20810_set_mode(int mode, int index) {
printk("Timothy:cx20810.c->cx20810_set_mode(), mode = %d, index = %d\n",
mode, index);
int i;
int ret;
char *param;
int length;
switch (mode) {
case CX20810_NORMAL_MODE:
param = codec_config_param_normal_mode;
length = sizeof(codec_config_param_normal_mode);
break;
case CX20810_NORMAL_MODE_SIMPLE:
param = codec_config_param_normal_mode_simple;
length = sizeof(codec_config_param_normal_mode_simple);
break;
case CX20810_48K_16BIT_MODE:
param = codec_config_param_48k_16bit_mode;
length = sizeof(codec_config_param_48k_16bit_mode);
break;
case CX20810_96K_16BIT_MODE:
param = codec_config_param_96k_16bit_mode;
length = sizeof(codec_config_param_96k_16bit_mode);
break;
case CX20810_NIRMAL_MODE_CODEC3:
param = codec3_config_param_normal_mode;
length = sizeof(codec3_config_param_normal_mode);
break;
case CX20810_NIRMAL_MODE_CODEC3_SIMPLE:
param = codec3_config_param_normal_mode_simple;
length = sizeof(codec3_config_param_normal_mode_simple);
break;
default:
return;
break;
}
// if client is null, return
if (g_client_cx20810[index] == NULL) {
printk("Timothy:cx20810(%d) is not detected yet\n", index);
return -1;
}
ret = i2c_master_send_array_to_cx20810(g_client_cx20810[index], param,
length);
if (ret != 0) {
printk("Timothy:cx82011[%x] init error!\n",
g_client_cx20810[index]->addr);
return -1;
} else {
printk("Timothy:cx20810[%x] init ok\n", g_client_cx20810[index]->addr);
return 0;
}
}
EXPORT_SYMBOL(cx20810_set_mode);
int cx20810_write_reg(int index, int addr, int regval) {
char writedata[2] = {0};
if (index > 1) {
return -1;
}
writedata[0] = (char)addr;
writedata[1] = (char)regval;
return i2c_master_send(g_client_cx20810[index], writedata, 2);
}
EXPORT_SYMBOL(cx20810_write_reg);
int cx20810_read_reg(int index, int cmd, int *regval) {
int error = 0;
char data = 0;
if (index > 1) {
return -1;
}
error = i2c_master_send(g_client_cx20810[index], (const char *)&cmd, 1);
// write reg addr
if (1 != i2c_master_send(g_client_cx20810[index], (const char *)&cmd, 1)) {
printk(KERN_ERR " cx20810_read_reg fail1! \n");
return -1;
}
// wait
msleep(10);
// read
if (error >= 0) {
error = i2c_master_recv(g_client_cx20810[index], &data, 1);
if (error < 0) {
printk(KERN_ERR " cx20810_read_reg fail2! \n");
}
} else {
printk(KERN_ERR " cx20810_read_reg fail1! \n");
}
*regval = (int)data;
return 0;
}
EXPORT_SYMBOL(cx20810_read_reg);
// send parameters to cx20810 as master
static int i2c_master_send_array_to_cx20810(const struct i2c_client *client,
const char *buf, int length) {
printk("Timothy:cx20810.c->i2c_master_send_array_to_cx20810()\n");
int i;
int nwrite;
for (i = 0; i < (length / 2); i++) {
nwrite = i2c_master_send(client, buf + i * 2, 2);
if (nwrite != 2) {
printk("Timothy:send to cx20810 error\n");
return -1;
}
}
return 0;
}
// initial cx20810
static void cx20810_init(int index, int mode) {
printk("Timothy:cx20810.c->cx20810_init()\n");
if (cx20810_set_mode(mode, index) == 0) {
printk("Timothy:cx20810 init success\n");
} else {
printk("Timothy:cx20810 init fail\n");
}
}
static int i2c_driver_cx20810_probe(struct i2c_client *client,
const struct i2c_device_id *id) {
if (client->adapter->nr == 0 && client->addr == i2c_cx20810_addr[0]) {
g_client_cx20810[1] = client;
printk("Timothy:cx20810 (0x%x) init ok\n", client->addr);
cx20810_init(1, CX20810_NORMAL_MODE);
} else if (client->adapter->nr == 0 &&
client->addr == i2c_cx20810_addr[1]) {
g_client_cx20810[0] = client;
printk("Timothy:cx20810 (0x%x) init ok\n", client->addr);
cx20810_init(0, CX20810_NORMAL_MODE);
}
return 0;
}
static int i2c_driver_cx20810_remove(struct i2c_client *client) {
printk("Timothy:cx20810.c->i2c_driver_cx20810_remove()\n");
return 0;
}
MODULE_DEVICE_TABLE(i2c, i2c_driver_cx20810_id);
static int i2c_driver_cx20810_detect(struct i2c_client *client,
struct i2c_board_info *info) {
printk("Timothy:cx20810.c->i2c_driver_cx20810_detect()...\n");
struct i2c_adapter *p_adapter;
const char *type_name = I2C_CX20810_DRIVER_NAME;
p_adapter = client->adapter;
printk("Timothy:adapter->nr = %d\n", p_adapter->nr);
if (0 == p_adapter->nr) {
if (info->addr == i2c_cx20810_addr[0]) {
printk("Timothy:detect cx20810 (%x) on i2c adapter (%d)\n",
info->addr, p_adapter->nr);
strlcpy(info->type, type_name, I2C_NAME_SIZE);
return 0;
} else if (info->addr == i2c_cx20810_addr[1]) {
printk("Timothy:detect cx20810 (%x) on i2c adapter (%d)\n",
info->addr, p_adapter->nr);
strlcpy(info->type, type_name, I2C_NAME_SIZE);
return 0;
}
}
return ENODEV;
}
static struct i2c_driver i2c_driver_cx20810 = {
.class = I2C_CLASS_HWMON,
.probe = i2c_driver_cx20810_probe,
.remove = i2c_driver_cx20810_remove,
.id_table = i2c_driver_cx20810_id,
.driver =
{
.name = I2C_CX20810_DRIVER_NAME,
.owner = THIS_MODULE,
},
.detect = i2c_driver_cx20810_detect,
.address_list = i2c_cx20810_addr};
static int __init i2c_driver_cx20810_init(void) {
printk("Timothy:cx20810.c->i2c_driver_cx20810_init()\n");
msleep(300);
// cx20810_hw_init();
return i2c_add_driver(&i2c_driver_cx20810);
}
static void __exit i2c_driver_cx20810_exit(void) {
printk("Timothy:cx20810.c->i2c_driver_cx20810_exit()\n");
i2c_del_driver(&i2c_driver_cx20810);
}
static int __init cpld_r311_probe(struct platform_device *pdev) {
printk("Begin to set luyao asked gpios \n");
struct device_node *np = pdev->dev.of_node;
struct device *dev = &pdev->dev;
struct gpio_config cfg;
int gpionum;
gpionum = of_get_named_gpio_flags(np, "4v5_ldo_en", 0,
(enum of_gpio_flags *)&cfg);
if (gpio_is_valid(gpionum)) {
gpio_request(gpionum, "4v5_ldo_en");
gpio_direction_output(gpionum, 1);
printk("Set 4v5_ldo_en(%d) success\n", gpionum);
} else {
printk("Set 4v5_ldo_en fail\n");
}
gpionum =
of_get_named_gpio_flags(np, "3v_ldo_en", 0, (enum of_gpio_flags *)&cfg);
if (gpio_is_valid(gpionum)) {
gpio_request(gpionum, "3v_ldo_en");
gpio_direction_output(gpionum, 1);
printk("Set 3v_ldo_en(%d) success\n", gpionum);
} else {
printk("Set 3v_ldo_en fail\n");
}
gpionum = of_get_named_gpio_flags(np, "gp_adc_rst", 0,
(enum of_gpio_flags *)&cfg);
gpio_adc_rst = gpionum;
if (!gpio_is_valid(gpionum)) {
printk("get gp_adc_rst failed\n");
return -EINVAL;
} else {
printk("Get gp_adc_rst success,gpio:%d\n", gpionum);
}
devm_gpio_request(dev, gpionum, "gp_adc_rst");
gpio_direction_output(gpionum, 1);
printk("Set gp_adc_rst(%d) to 1\n", gpionum);
return 0;
}
void netease_cpld_reset(void) {
printk("Begin to reset cpld!\n");
if (gpio_is_valid(gpio_adc_rst)) {
gpio_set_value(gpio_adc_rst, 0);
msleep(100);
printk("Begin to start cpld!\n");
gpio_set_value(gpio_adc_rst, 1);
msleep(800);
printk("Finish reseting cpld!\n");
} else {
printk("Adc rst gpio is not init!\n");
}
}
static const struct of_device_id cpld_r311_ids[] = {
{.compatible = "allwinner,cpld-r311-pv1"}, {/* Sentinel */}};
static struct platform_driver cpld_r311_driver = {
.driver =
{
.owner = THIS_MODULE,
.name = "cpld",
.of_match_table = cpld_r311_ids,
},
};
static int __init cpld_r311_init(void) {
int ret = 0;
#if 0
type = script_get_item("cpld", "gp_ldo_4_5", &item);
if (SCIRPT_ITEM_VALUE_TYPE_PIO == type) {
printk("luyao:set gp_ldo_4_5\n");
printk("Gpio:%d\n", item.gpio.gpio);
gpio_request(item.gpio.gpio, NULL);
gpio_direction_output(item.gpio.gpio, 1);
gpio_set_value(item.gpio.gpio, 1);
gpio_free(item.gpio.gpio);
}
type = script_get_item("cpld", "gp_ldo_3", &item);
if (SCIRPT_ITEM_VALUE_TYPE_PIO == type) {
printk("luyao:set gp_ldo_3\n");
printk("Gpio:%d\n", item.gpio.gpio);
gpio_request(item.gpio.gpio, NULL);
gpio_direction_output(item.gpio.gpio, 1);
gpio_set_value(item.gpio.gpio, 1);
gpio_free(item.gpio.gpio);
}
#endif
printk("Begin to init cpld r311 driver!!\n");
ret = platform_driver_probe(&cpld_r311_driver, cpld_r311_probe);
printk("platform_driver_probe:%d!\n", ret);
return ret;
}
static void __exit cpld_r311_deinit(void) {}
fs_initcall_sync(cpld_r311_init);
module_exit(cpld_r311_deinit);
late_initcall_sync(i2c_driver_cx20810_init);
module_exit(i2c_driver_cx20810_exit);
MODULE_AUTHOR("Timothy");
MODULE_DESCRIPTION("I2C device cx20810 loader");
MODULE_LICENSE("GPL");

View File

@ -0,0 +1,340 @@
#ifndef CX20810_CONFIG_H_
#define CX20810_CONFIG_H_
enum
{
CX20810_NORMAL_MODE = 0,
CX20810_NORMAL_MODE_SIMPLE,
CX20810_NIRMAL_MODE_CODEC3,
CX20810_NIRMAL_MODE_CODEC3_SIMPLE,
CX20810_96K_16BIT_MODE,
CX20810_48K_16BIT_MODE,
};
const char codec_config_param_normal_mode[]=
{
0x0F,0x03, //RST
0x0F,0x03, //repeat write is let chip has more time to RST
0x0F,0x03,
0x0F,0x03,
0x0F,0x00,//release reset
0x78,0x33, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x33, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x33, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x33, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x33, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x73, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x73, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x73, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x73, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x73, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x7A,0x01,
0x01,0x01,
0xA0,0x07,//ADC bias EN
0xA7,0x07,
0xAE,0x07,
0xB5,0x07,
0xBC,0x38,// 0x28 20dB 0x34 26dB
0xBD,0x38,
0xBE,0x38,
0xBF,0x38,
0x30,0x14,//14 24bit 0a 16bit
0x31,0x07,//frame (n+1)*8 bit 32+32=64
0x32,0x07,//
0x33,0x1F,//sys width 32 clk
0x34,0x1F,
0x35,0xA2,// TX left justified i2s1+i2s2
0x36,0x00,// config for right justified ignored.
0x37,0x00,// RX left justified.
0x38,0x00,// config for right justified ignored.
0x39,0x08, // ADC12 0n DATA1.ADC34 On DATA2
0x3A,0x00,//Slot1
0x3B,0x00,//slot2
0x3C,0x00,//slot3
0x3D,0x00,//slot4
0x3E,0x1F,//slot4
0x16,0x00, // Use DC Filter for ADCs
0x80,0x03,// MCLK
0x81,0x01,// LRCLK BCLK RX Pull down
0x82,0x3F,// LRCLK BCLK RX
0x83,0x0F,// LRCLK BCLK
/*
// PLL config
0x08,0x00,// disable MCLK
0x09,0x40,// I2S TX Bit Clock
0x60,0xF8, //reset and Disable PLL1
0x61,0xDF,//
0x62,0x01,
0x63,0x01,
//{0x64,0x90},
//{0x65,0x24},
0x66,0x80,
0x67,0x02,
//{0x68,0x0},
//{0x69,0x0},
// enable PLL1
0x60,0xFB,//delay for PLL locked
0x60,0xFB,
0x60,0xFB,
0x60,0xFB,
0x60,0xFB,
0x60,0xFB,
// end PLL config
*/
0x0F,0x01, //RST,clears DSP,audio data interface values
0x0F,0x01, //repeat write is let chip has more time to RST
0x0F,0x01,
0x0F,0x01,
0x08,0x00,// disable MCLK to chip
0x0C,0x0A,// Clocks gated
0x09,0x02,
0x0F,0x00,//clear RST
//0x08,0x30,// enable MCLK to chip
//0x08,0x38,
0x08,0x20,
0x09,0x03,
0x10,0x00, // Disable all ADC clocks
0x11,0x10, // Disable all ADC and Mixer
0x10,0x1F, // Enable all ADC clocks and ADC digital
0x11,0x1F, // Enable all ADC and set 16k sample rate
0x10,0x5F, // Enable all ADC clocks, ADC digital and ADC Mic Clock Gate
};
const char codec_config_param_normal_mode_simple[]=
{
// mic pga 增益
// 4通道录音工具
0xBC,0x28,// 0x28 20dB 0x34 26dB
0xBD,0x28,
0xBE,0x28,
0xBF,0x28,
0x60,0x04,
0x66,0x00,
0x67,0x02,
//PAD配置
0x80,0x03,// MCLK 为输入
0x83,0x0F,// LRCLK BCLK 为输入脚TX1 TX2为输出脚
//0x08,0x30,// MCLK 作为输入
//0x08,0x38,// MCLK divisor 生效
0x08,0x20,// MCLK 作为输入 12.288MHz
0x09,0x03,// 选MCLK作为PLL输入源
0x0a,0x0b,
0x0a,0x8b,
0x0C,0x0A,// RT clock disable, TX clock enable, enable clock to ADC3/4
// I2S
//0x30,0x0A,// Tx sample size:16bit, Normal mode
0x30,0x14,// Tx sample size:24bit, Normal mode
0x35,0xA2,// left justified, enable I2S-1 and I2S-2
0x10,0x00,
0x11,0x00,
0x10,0x1F,
0x11,0x1F,// ADC 96k, enables all ADCs
0x16,0x00,
0x10,0x5F,
};
const char codec3_config_param_normal_mode[]=
{
// POWER
0x78,0x39, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x39, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x39, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x39, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x39, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x79, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x79, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x79, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x79, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x78,0x79, //*PLLEN = 1 ABIASEN IOBUFEN REFIMP = 11 3KR
0x7A,0x01,
0x01,0x01,
// Analog ADC Control
// MIcIn PGA A0,A7,AE,B5 [5:4] ctrl_rcm , [1] enable [3] mute [7] bypass
// 模拟部分电源
0xA0,0x07,//ADC bias EN
0xA7,0x07,
0xAE,0x07,
0xB5,0x07,
// mic pga 增益
// 4通道录音工具
0xBC,0x06,// 0x28 20dB 0x34 26dB
0xBD,0x06,
0xBE,0x0C,
0xBF,0x14,
0x60,0x04,
0x66,0x00,
0x67,0x02,
//PAD配置
0x80,0x03,// MCLK 为输入
0x83,0x0F,// LRCLK BCLK 为输入脚TX1 TX2为输出脚
//0x08,0x30,// MCLK 作为输入
//0x08,0x38,// MCLK divisor 生效
0x08,0x20,// MCLK 作为输入 12.288MHz
0x09,0x03,// 选MCLK作为PLL输入源
0x0a,0x0b,
0x0a,0x8b,
0x0C,0x0A,// RT clock disable, TX clock enable, enable clock to ADC3/4
// I2S
//0x30,0x0A,// Tx sample size:16bit, Normal mode
0x30,0x14,// Tx sample size:24bit, Normal mode
0x35,0xA2,// left justified, enable I2S-1 and I2S-2
0x10,0x00,
0x11,0x00,
0x10,0x1F,
0x11,0x1F,// ADC 96k, enables all ADCs
0x16,0x00,
0x10,0x5F,
};
const char codec3_config_param_normal_mode_simple[]=
{
// mic pga 增益
// 4通道录音工具
0xBC,0x28,// 0x28 20dB 0x34 26dB
0xBD,0x28,
0xBE,0x28,
0xBF,0x28,
0x60,0x04,
0x66,0x00,
0x67,0x02,
//PAD配置
0x80,0x03,// MCLK 为输入
0x83,0x0F,// LRCLK BCLK 为输入脚TX1 TX2为输出脚
//0x08,0x30,// MCLK 作为输入
//0x08,0x38,// MCLK divisor 生效
0x08,0x20,// MCLK 作为输入 12.288MHz
0x09,0x03,// 选MCLK作为PLL输入源
0x0a,0x0b,
0x0a,0x8b,
0x0C,0x0A,// RT clock disable, TX clock enable, enable clock to ADC3/4
// I2S
//0x30,0x0A,// Tx sample size:16bit, Normal mode
0x30,0x14,// Tx sample size:24bit, Normal mode
0x35,0xA2,// left justified, enable I2S-1 and I2S-2
0x10,0x00,
0x11,0x00,
0x10,0x1F,
0x11,0x1F,// ADC 96k, enables all ADCs
0x16,0x00,
0x10,0x5F,
};
const char codec_config_param_48k_16bit_mode[]=
{
// mic pga 增益
// 4通道录音工具
0xBC,29 << 1,// 0x28 20dB 0x34 26dB
0xBD,29 << 1,
0xBE,29 << 1,
0xBF,29 << 1,
0x60,0x04,
0x66,0x00,
0x67,0x02,
//PAD配置
0x80,0x03,// MCLK 为输入
0x83,0x0F,// LRCLK BCLK 为输入脚TX1 TX2为输出脚
//0x08,0x30,// MCLK 作为输入
//0x08,0x38,// MCLK divisor 生效
0x08,0x20,// MCLK 作为输入 12.288MHz
0x09,0x03,//选MCLK作为PLL输入源
0x0a,0x03,
0x0a,0x83,
0x0C,0x0A,// RT clock disable, TX clock enable, enable clock to ADC3/4
// I2S
0x30,0x0A,// Tx sample size:16bit, Normal mode
//0x30,0x14,// Tx sample size:24bit, Normal mode
0x35,0xA2,// left justified, enable I2S-1 and I2S-2
0x10,0x00,
0x11,0x00,
0x10,0x1F,
0x11,0x4F,// ADC 96k, enables all ADCs
0x16,0x00,
0x10,0x5F,
};
const char codec_config_param_96k_16bit_mode[]=
{
// mic pga 增益
// 4通道录音工具
0xBC,29 << 1,// 0x28 20dB 0x34 26dB
0xBD,29 << 1,
0xBE,29 << 1,
0xBF,29 << 1,
0x60,0x04,
0x66,0x00,
0x67,0x02,
//PAD配置
0x80,0x03,// MCLK 为输入
0x83,0x0F,// LRCLK BCLK 为输入脚TX1 TX2为输出脚
//0x08,0x30,// MCLK 作为输入
//0x08,0x38,// MCLK divisor 生效
0x08,0x20,// MCLK 作为输入 12.288MHz
0x09,0x03,// 选MCLK作为PLL输入源
0x0a,0x01,
0x0a,0x81,
0x0C,0x0A,// RT clock disable, TX clock enable, enable clock to ADC3/4
// I2S
0x30,0x0A,// Tx sample size:16bit, Normal mode
//0x30,0x14,// Tx sample size:24bit, Normal mode
0x35,0xA2,// left justified, enable I2S-1 and I2S-2
0x10,0x00,
0x11,0x00,
0x10,0x1F,
0x11,0x5F,// ADC 96k, enables all ADCs
0x16,0x00,
0x10,0x5F,
};
#endif /* CX20810_CONFIG_H_ */

View File

@ -0,0 +1,428 @@
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/gpio.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/sysfs.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
//#include <linux/stdlib.h>
#include <linux/stat.h>
#include <linux/string.h>
// unsigned char toupad_get_key(void);
// void tipa_set_vol(unsigned char abs_vol);
int at_8740_write(unsigned char *pbuf, unsigned int len);
int at_8740_read(unsigned char *pbuf, unsigned int len);
void at_8740_wakeup(void);
static unsigned int map_io_base;
#define D_IO_BASE map_io_base
#define D_IO_BASE_PHY (0x01c20800)
#define D_IO_LEN (0x400)
#define D_IO_A (0)
#define D_IO_B (1)
#define D_IO_C (2)
#define D_IO_D (3)
#define D_IO_E (4)
#define D_IO_F (5)
#define D_IO_G (6)
#define D_IO_H (7)
#define D_IO_I (8)
#define D_IO_CFG0(x) (D_IO_BASE + (x * 0x24) + 0x00)
#define D_IO_CFG1(x) (D_IO_BASE + (x * 0x24) + 0x04)
#define D_IO_CFG2(x) (D_IO_BASE + (x * 0x24) + 0x08)
#define D_IO_CFG3(x) (D_IO_BASE + (x * 0x24) + 0x0c)
#define D_IO_DAT(x) (D_IO_BASE + (x * 0x24) + 0x10)
#define D_IO_DRV0(x) (D_IO_BASE + (x * 0x24) + 0x14)
#define D_IO_DRV1(x) (D_IO_BASE + (x * 0x24) + 0x18)
#define D_IO_PUL0(x) (D_IO_BASE + (x * 0x24) + 0x1c)
#define D_IO_PUL1(x) (D_IO_BASE + (x * 0x24) + 0x20)
int cx20810_set_mode(int mode, int index);
typedef struct {
unsigned int opcode;
unsigned int param[3];
} t_data_unit;
enum {
eDU_RESVER = 0,
eDU_IVW_PRESET_TIME,
eDU_REC_TYPE,
eDU_IVW_POS_INFO,
eDU_MAX
};
t_data_unit database[eDU_MAX];
static int major_num;
static struct class *p_class;
static struct device *p_fpga;
static struct device *p_reg_debug;
static struct device *p_dsp_settings;
static struct device *p_au;
static struct device *p_tk;
static struct device *p_vol;
static struct device *p_vol2;
static struct device *p_8740;
static struct device *p_8740_wakeup;
static unsigned int param_config;
static struct kset *kset_vendor;
static struct kobject kobj_pa;
static ssize_t gen_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf) {
strcpy(buf, "wocao");
return strlen(buf);
}
static ssize_t gen_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count) {
int i = simple_strtol(buf, (char **)(buf + strlen(buf) - 1), 0);
printk("vol=%ddb", i);
// tipa_set_vol(2 * (24-i));
return count;
}
struct attribute gen_vol_set = {
.name = "vol_set",
.mode = S_IRWXUGO,
};
struct attribute *gen_attr_group[] = {
&gen_vol_set,
NULL,
};
static const struct sysfs_ops gen_ops = {
.show = gen_attr_show,
.store = gen_attr_store,
};
static void gen_release(struct kobject *k) {
// nothing to do
}
static struct kobj_type gen_ktype = {
.sysfs_ops = &gen_ops,
.default_attrs = gen_attr_group,
.release = gen_release,
};
static int gp_open(struct inode *pnode, struct file *pfile) {
int major = MAJOR(pnode->i_rdev);
int minor = MINOR(pnode->i_rdev);
if (minor == 0) {
pfile->private_data = (void *)p_fpga;
} else if (minor == 1) {
pfile->private_data = (void *)p_reg_debug;
} else if (minor == 2) {
pfile->private_data = (void *)p_dsp_settings;
} else if (minor == 3) {
pfile->private_data = (void *)p_au;
} else if (minor == 4) {
pfile->private_data = (void *)p_tk;
} else if (minor == 5) {
pfile->private_data = (void *)p_vol;
}
// else if(minor == 6)
// {
// pfile->private_data = (void*)p_8740;
// }
// else if(minor == 7)
// {
// pfile->private_data = (void*)p_8740_wakeup;
// }
else {
pfile->private_data = NULL;
}
return 0;
}
static int gp_close(struct inode *pnode, struct file *pfile) { return 0; }
static ssize_t gp_read(struct file *pfile, char __user *puser, size_t len,
loff_t *poff) {
if (pfile->private_data == p_fpga) {
return 0;
} else if (pfile->private_data == p_reg_debug) {
unsigned int base_addr = (unsigned int)ioremap(0x1C22400, 0x100);
unsigned int i;
for (i = 0; i <= 0x3C; i += 4) {
printk("[i2s1] addr:0x%x val:0x%x\r\n", base_addr + i,
*((unsigned int *)(base_addr + i)));
}
return len;
} else if (pfile->private_data == p_au) {
t_data_unit tmp_data;
copy_from_user((void *)&tmp_data, puser, len);
if (tmp_data.opcode < eDU_MAX) {
copy_to_user(puser, &database[tmp_data.opcode],
sizeof(t_data_unit));
return len;
} else {
return 0;
}
}
// else if(pfile->private_data == p_tk)
// {
// unsigned char tmp = toupad_get_key();
// copy_to_user(puser, &tmp, sizeof(unsigned char));
// return len;
// }
// else if(pfile->private_data == p_8740)
// {
// unsigned char * pbuf;
// pbuf = kmalloc(len, GFP_KERNEL);
// printk("8740 nread:%d\r\n", at_8740_read(pbuf, len));
// copy_to_user(puser, pbuf, len);
// kfree(pbuf);
// return len;
// }
// else if(pfile->private_data == p_8740_wakeup)
// {
// return len;
// }
return 0;
}
enum {
CX20810_NORMAL_MODE = 0,
CX20810_NORMAL_MODE_SIMPLE,
CX20810_NIRMAL_MODE_CODEC3,
CX20810_NIRMAL_MODE_CODEC3_SIMPLE,
CX20810_96K_16BIT_MODE,
CX20810_48K_16BIT_MODE,
};
static ssize_t gp_write(struct file *pfile, const char __user *puser,
size_t len, loff_t *poff) {
if (pfile->private_data == p_fpga) {
copy_from_user((void *)&param_config, puser, len);
switch (param_config) {
case 0:
printk("fpga_config:mode0\r\n");
// cx20810_set_mode(CX20810_NORMAL_MODE, 0);
// cx20810_set_mode(CX20810_NORMAL_MODE, 1);
// cx20810_set_mode(CX20810_NORMAL_MODE, 2);
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x7000000) |
// 0x1000000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 6)),
// D_IO_DAT(D_IO_D));
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x7000) |
// 0x1000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 3)),
// D_IO_DAT(D_IO_D));
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x70000) |
// 0x10000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 4)),
// D_IO_DAT(D_IO_D));
writel((readl(D_IO_CFG0(D_IO_E)) & ~0x70000) | 0x10000,
D_IO_CFG0(D_IO_E));
writel((readl(D_IO_DAT(D_IO_E)) & ~(1 << 4)), D_IO_DAT(D_IO_E));
writel((readl(D_IO_CFG0(D_IO_H)) & ~0x70000000) | 0x10000000,
D_IO_CFG0(D_IO_H));
writel((readl(D_IO_DAT(D_IO_H)) & ~(1 << 7)), D_IO_DAT(D_IO_H));
writel((readl(D_IO_CFG0(D_IO_E)) & ~0x7000) | 0x1000,
D_IO_CFG0(D_IO_E));
writel((readl(D_IO_DAT(D_IO_E)) & ~(1 << 3)), D_IO_DAT(D_IO_E));
break;
case 1:
printk("fpga_config:mode1\r\n");
cx20810_set_mode(CX20810_96K_16BIT_MODE, 1);
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x7000000) |
// 0x1000000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 6)),
// D_IO_DAT(D_IO_D));
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x7000) |
// 0x1000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) | (1 << 3)),
// D_IO_DAT(D_IO_D));
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x70000) |
// 0x10000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 4)),
// D_IO_DAT(D_IO_D));
writel((readl(D_IO_CFG0(D_IO_E)) & ~0x70000) | 0x10000,
D_IO_CFG0(D_IO_E));
writel((readl(D_IO_DAT(D_IO_E)) & ~(1 << 4)), D_IO_DAT(D_IO_E));
writel((readl(D_IO_CFG0(D_IO_H)) & ~0x70000000) | 0x10000000,
D_IO_CFG0(D_IO_H));
writel((readl(D_IO_DAT(D_IO_H)) & ~(1 << 7)), D_IO_DAT(D_IO_H));
writel((readl(D_IO_CFG0(D_IO_E)) & ~0x7000) | 0x1000,
D_IO_CFG0(D_IO_E));
writel((readl(D_IO_DAT(D_IO_E)) | (1 << 3)), D_IO_DAT(D_IO_E));
break;
case 2:
printk("fpga_config:mode2\r\n");
cx20810_set_mode(CX20810_48K_16BIT_MODE, 0);
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x7000000) |
// 0x1000000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 6)),
// D_IO_DAT(D_IO_D));
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x7000) |
// 0x1000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) & ~(1 << 3)),
// D_IO_DAT(D_IO_D));
// writel((readl(D_IO_CFG0(D_IO_D)) & ~0x70000) |
// 0x10000, D_IO_CFG0(D_IO_D));
// writel((readl(D_IO_DAT(D_IO_D)) | (1 << 4)),
// D_IO_DAT(D_IO_D));
writel((readl(D_IO_CFG0(D_IO_E)) & ~0x70000) | 0x10000,
D_IO_CFG0(D_IO_E));
writel((readl(D_IO_DAT(D_IO_E)) & ~(1 << 4)), D_IO_DAT(D_IO_E));
writel((readl(D_IO_CFG0(D_IO_H)) & ~0x70000000) | 0x10000000,
D_IO_CFG0(D_IO_H));
writel((readl(D_IO_DAT(D_IO_H)) | (1 << 7)), D_IO_DAT(D_IO_H));
writel((readl(D_IO_CFG0(D_IO_E)) & ~0x7000) | 0x1000,
D_IO_CFG0(D_IO_E));
writel((readl(D_IO_DAT(D_IO_E)) & ~(1 << 3)), D_IO_DAT(D_IO_E));
break;
default:
break;
}
return len;
} else if (pfile->private_data == p_reg_debug) {
return len;
} else if (pfile->private_data == p_dsp_settings) {
return len;
} else if (pfile->private_data == p_au) {
t_data_unit tmp_data;
copy_from_user((void *)&tmp_data, puser, len);
if (tmp_data.opcode < eDU_MAX) {
memcpy(&database[tmp_data.opcode], &tmp_data, sizeof(t_data_unit));
return len;
} else {
return 0;
}
} else if (pfile->private_data == p_vol) {
unsigned char tmp;
copy_from_user((void *)&tmp, puser, len);
// tipa_set_vol(tmp);
return len;
}
// else if(pfile->private_data == p_8740)
// {
// unsigned char * pbuf;
// pbuf = kmalloc(len, GFP_KERNEL);
// copy_from_user((void*)pbuf, puser, len);
// printk("8740 nwrite:%d\r\n", at_8740_write(pbuf, len));
// kfree(pbuf);
// return len;
// }
// else if(pfile->private_data == p_8740_wakeup)
// {
// printk("8740 wakeup\r\n");
// at_8740_wakeup();
// return len;
// }
else {
}
return 0;
}
static struct file_operations gp_fops = {
.owner = THIS_MODULE,
.open = gp_open,
.release = gp_close,
.read = gp_read,
.write = gp_write,
};
static int __init fpga_config_init(void) {
D_IO_BASE = (unsigned int)ioremap(D_IO_BASE_PHY, D_IO_LEN);
if (!D_IO_BASE) {
printk("[gen_prov] init gpio err\r\n");
return;
}
kset_vendor = kset_create_and_add("vendor", NULL, NULL);
kobj_pa.kset = kset_vendor;
kobject_init_and_add(&kobj_pa, &gen_ktype, NULL, "pa");
major_num = register_chrdev(0, "fpga_chr", &gp_fops);
if (major_num < 0) {
printk("reg_chr_err\n");
return 1;
}
p_class = class_create(THIS_MODULE, "fpga_class");
if (p_class == NULL) {
printk("class create err\n");
return 1;
}
p_fpga =
device_create(p_class, NULL, MKDEV(major_num, 0), NULL, "fpga_config");
if (p_fpga == NULL) {
printk("device_create err:fpga\n");
return 1;
}
p_reg_debug =
device_create(p_class, NULL, MKDEV(major_num, 1), NULL, "reg_debug");
if (p_reg_debug == NULL) {
printk("device_create err:reg_debug\n");
return 1;
}
p_dsp_settings =
device_create(p_class, NULL, MKDEV(major_num, 2), NULL, "dsp_settings");
if (p_dsp_settings == NULL) {
printk("device_create err:p_dsp_settings\n");
return 1;
}
p_au = device_create(p_class, NULL, MKDEV(major_num, 3), NULL, "au_base");
if (p_au == NULL) {
printk("device_create err:au_base\n");
return 1;
}
p_tk = device_create(p_class, NULL, MKDEV(major_num, 4), NULL, "touch_key");
if (p_tk == NULL) {
printk("device_create err:touch_key\n");
return 1;
}
p_vol = device_create(p_class, NULL, MKDEV(major_num, 5), NULL, "vbox_vol");
if (p_vol == NULL) {
printk("device_create err:vbox_vol\n");
return 1;
}
// p_8740 = device_create(p_class, NULL, MKDEV(major_num, 6), NULL,
// "atml_sec"); if(p_8740 == NULL)
// {
// printk("device_create err:p_8740\n");
// return 1;
// }
// p_8740_wakeup = device_create(p_class, NULL, MKDEV(major_num, 7),
// NULL, "atml_sec_wake"); if(p_8740_wakeup == NULL)
// {
// printk("device_create err:p_8740\n");
// return 1;
// }
return 0;
}
//module_init(fpga_config_init);
static void __exit fpga_config_exit(void) {}
module_exit(fpga_config_exit);
/* Module information */
MODULE_AUTHOR("feitao");
MODULE_DESCRIPTION("fpga config");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:fpga");

View File

@ -0,0 +1,267 @@
#include <asm/io.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <mach/gpio.h>
// mem define
static unsigned int map_io_base;
#define D_IO_BASE map_io_base
#define D_IO_BASE_PHY (0x01c20800)
#define D_IO_LEN (0x400)
#define D_IO_A (0)
#define D_IO_B (1)
#define D_IO_C (2)
#define D_IO_D (3)
#define D_IO_E (4)
#define D_IO_F (5)
#define D_IO_G (6)
#define D_IO_H (7)
#define D_IO_I (8)
#define D_IO_CFG0(x) (D_IO_BASE + (x * 0x24) + 0x00)
#define D_IO_CFG1(x) (D_IO_BASE + (x * 0x24) + 0x04)
#define D_IO_CFG2(x) (D_IO_BASE + (x * 0x24) + 0x08)
#define D_IO_CFG3(x) (D_IO_BASE + (x * 0x24) + 0x0c)
#define D_IO_DAT(x) (D_IO_BASE + (x * 0x24) + 0x10)
#define D_IO_DRV0(x) (D_IO_BASE + (x * 0x24) + 0x14)
#define D_IO_DRV1(x) (D_IO_BASE + (x * 0x24) + 0x18)
#define D_IO_PUL0(x) (D_IO_BASE + (x * 0x24) + 0x1c)
#define D_IO_PUL1(x) (D_IO_BASE + (x * 0x24) + 0x20)
static struct i2c_client *fpga_client = NULL;
static const struct i2c_device_id i2c_driver_fpga_id[] = {{"i2c_fpga", 0}, {}};
MODULE_DEVICE_TABLE(i2c, i2c_driver_fpga_id);
static unsigned char fpga_refresh_command[] = {0x79, 0x00, 0x00};
static unsigned char fpga_none_command[] = {0xff, 0xff, 0xff, 0xff};
static const unsigned short i2c_fpga_addr[] = {0x40, I2C_CLIENT_END};
static struct delayed_work fpga_reset_work;
static struct i2c_msg *i2c_recev_msg;
static int current_msg_pos;
static void fpga_hw_init(void) {
printk("fpga_loader.c->fpga_hw_init()\n");
if (!D_IO_BASE) {
// printk("Timothy:D_IO_BASE is not initial yet, initial it now\n");
D_IO_BASE = (unsigned int)ioremap(D_IO_BASE_PHY, D_IO_LEN);
if (!D_IO_BASE) {
printk("fpga loader hardware init io error\n");
return -1;
}
}
}
// set reset for fpga
// enable = 1:set ph7 high
// enable = 0:set ph7 low
static void set_fpga_reset(int enable) {
// printk("Timothy:fpga_loader.c->set_fpga_reset()\n");
if (1 == enable) {
writel(readl(D_IO_DAT(D_IO_H)) | (1 << 8), D_IO_DAT(D_IO_H));
} else {
writel(readl(D_IO_DAT(D_IO_H)) & ~(1 << 8), D_IO_DAT(D_IO_H));
}
}
int send_to_device(char *data, int count) {
// //printk("Timothy:fpga_loader.c->send_to_device(), count = %d\n",
//count);
int nwrite;
int i;
if (data[0] == 0) // STOP causes this, send stop
{
// printk("the data send to device is:");
// for(i = 1; i < count; i++)
// {
// printk("%x ", data[i]);
// }
// printk("\n");
nwrite = i2c_master_send(fpga_client, &data[1], count - 1);
if (nwrite != count - 1) {
// printk("Timothy:not write enough, nwrite = %d, count = %d\n",
// nwrite, count);
} else {
// //printk("Timothy:write success, count = %d\n",
//count);
}
return nwrite;
} else if (data[0] ==
1) // RESTART causes this, do not send stop, just put int in buf
{
if (current_msg_pos >= 8) {
// printk("Timothy:buf is overflow, quit");
return -2;
}
// //printk("Timothy:the data add to buf is:");
// for(i = 1; i < count; i++)
// {
// printk("%x ", data[i]);
// }
// printk("\n");
i2c_recev_msg[current_msg_pos].addr = i2c_fpga_addr[0];
i2c_recev_msg[current_msg_pos].len = count - 1;
i2c_recev_msg[current_msg_pos].buf = (unsigned char *)kzalloc(
i2c_recev_msg[current_msg_pos].len * sizeof(unsigned char),
GFP_KERNEL);
memcpy(i2c_recev_msg[current_msg_pos].buf, &data[1],
i2c_recev_msg[current_msg_pos].len);
current_msg_pos++;
return count - 1;
} else if (data[0] == 2) {
// printk("Timothy:send refresh command now\n");
nwrite = i2c_master_send(fpga_client, fpga_refresh_command, 3);
return nwrite;
} else if (data[0] == 3) {
// printk("Timothy:send none command now\n");
nwrite = i2c_master_send(fpga_client, fpga_none_command, 4);
nwrite = i2c_master_send(fpga_client, fpga_none_command, 4);
return nwrite;
} else {
// printk("Timothy:unknow flag for send");
return -1;
}
}
EXPORT_SYMBOL(send_to_device);
int receive_from_device(char *data, int count) {
// //printk("Timothy:fpga_loader.c->receive_from_device()\n");
int nread;
int i, j;
if (current_msg_pos >= 8) {
// printk("Timothy:buf is overflow, quit");
return -2;
}
i2c_recev_msg[current_msg_pos].addr = i2c_fpga_addr[0];
i2c_recev_msg[current_msg_pos].flags = I2C_M_RD | I2C_M_NO_RD_ACK;
i2c_recev_msg[current_msg_pos].len = count;
i2c_recev_msg[current_msg_pos].buf = data;
current_msg_pos++;
// //printk("Timothy:the data send before read is:");
// for(i = 0; i < current_msg_pos-1; i++)
// {
// for(j = 0; j < i2c_recev_msg[i].len; j++)
// {
// printk("%x ", i2c_recev_msg[i].buf[j]);
// }
// }
// printk("\n");
nread = i2c_transfer(fpga_client->adapter, i2c_recev_msg, current_msg_pos);
if (nread != current_msg_pos) {
// printk("Timothy:not read enough, nread = %d, current_msg_pos = %d\n",
// nread, current_msg_pos);
} else {
// //printk("Timothy:read success, current_msg_pos = %d\n",
//current_msg_pos);
}
// //printk("Timothy:the data read from i2c is:");
// for(i = 0; i < count; i++)
// {
// printk("%x, ", data[i]);
// }
// printk("\n");
for (i = 0; i < current_msg_pos - 1; i++) {
if (i2c_recev_msg[i].buf) {
kfree(i2c_recev_msg[i].buf);
i2c_recev_msg[i].buf = NULL;
}
}
current_msg_pos = 0;
return count;
}
EXPORT_SYMBOL(receive_from_device);
static int i2c_driver_fpga_probe(struct i2c_client *client,
const struct i2c_device_id *id) {
// printk("Timothy:fpga_loader.c->i2c_driver_fpga_probe()\n");
if ((client->addr == i2c_fpga_addr[0])) {
fpga_client = client;
// printk("Timothy:fpga (%x) init ok\n", client->addr);
}
return 0;
}
static int i2c_driver_fpga_remove(struct i2c_client *client) {
// printk("Timothy:fpga_loader.c->i2c_driver_fpga_remove()\n");
return 0;
}
static int i2c_driver_fpga_detect(struct i2c_client *client,
struct i2c_board_info *info) {
// printk("Timothy:fpga_loader.c->i2c_driver_fpga_detect()\n");
struct i2c_adapter *p_adapter;
const char *type_name = "i2c_fpga";
p_adapter = client->adapter;
// printk("Timothy:adapter->nr = %d\n", p_adapter->nr);
if (2 == p_adapter->nr) {
if (info->addr == i2c_fpga_addr[0]) {
// printk("Timothy:detect fpga (%x) on i2c adapter (%d)\n",
// info->addr, p_adapter->nr);
strlcpy(info->type, type_name, I2C_NAME_SIZE);
return 0;
}
}
return ENODEV;
}
static struct i2c_driver i2c_driver_fpga = {.class = I2C_CLASS_HWMON,
.probe = i2c_driver_fpga_probe,
.remove = i2c_driver_fpga_remove,
.id_table = i2c_driver_fpga_id,
.driver =
{
.name = "i2c_fpga",
.owner = THIS_MODULE,
},
.detect = i2c_driver_fpga_detect,
.address_list = i2c_fpga_addr};
static int __init i2c_driver_fpga_init(void) {
// printk("Timothy:fpga_loader.c->i2c_driver_fpga_init()\n");
fpga_hw_init();
i2c_recev_msg =
(struct i2c_msg *)kzalloc(8 * sizeof(struct i2c_msg), GFP_KERNEL);
current_msg_pos = 0;
return i2c_add_driver(&i2c_driver_fpga);
}
static void __exit i2c_driver_fpga_exit(void) {
// printk("Timothy:fpga_loader.c->i2c_driver_fpga_exit()\n");
if (i2c_recev_msg) {
kfree(i2c_recev_msg);
i2c_recev_msg = NULL;
}
current_msg_pos = 0;
i2c_del_driver(&i2c_driver_fpga);
}
module_init(i2c_driver_fpga_init);
module_exit(i2c_driver_fpga_exit);
MODULE_AUTHOR("Timothy");
MODULE_DESCRIPTION("I2C device fpga loader");
MODULE_LICENSE("GPL");

View File

@ -0,0 +1,313 @@
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/gpio.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#define GP_CLASS_NAME "i2c_operator"
#define GP_CHR_DEV_NAME "i2c_operator"
#define GP_I2C_DEV_NAME "i2c_operator_device"
struct i2c_ioctl_msg {
int i2c_index;
int reg_addr;
int reg_val;
};
#define MAGIC_NUM 'A'
#define CMD_I2C_SET _IOW(MAGIC_NUM, 0, struct i2c_ioctl_msg)
#define CMD_I2C_GET _IOR(MAGIC_NUM, 1, struct i2c_ioctl_msg)
#define CMD_MAX (1)
static unsigned int map_io_base;
#define D_IO_BASE map_io_base
#define D_IO_BASE_PHY (0x01c20800)
#define D_IO_LEN (0x400)
#define D_IO_B (1)
#define D_IO_C (2)
#define D_IO_D (3)
#define D_IO_E (4)
#define D_IO_F (5)
#define D_IO_G (6)
#define D_IO_H (7)
#define D_IO_CFG0(x) (D_IO_BASE + (x * 0x24) + 0x00)
#define D_IO_CFG1(x) (D_IO_BASE + (x * 0x24) + 0x04)
#define D_IO_CFG2(x) (D_IO_BASE + (x * 0x24) + 0x08)
#define D_IO_CFG3(x) (D_IO_BASE + (x * 0x24) + 0x0c)
#define D_IO_DAT(x) (D_IO_BASE + (x * 0x24) + 0x10)
#define D_IO_DRV0(x) (D_IO_BASE + (x * 0x24) + 0x14)
#define D_IO_DRV1(x) (D_IO_BASE + (x * 0x24) + 0x18)
#define D_IO_PUL0(x) (D_IO_BASE + (x * 0x24) + 0x1c)
#define D_IO_PUL1(x) (D_IO_BASE + (x * 0x24) + 0x20)
static struct class *p_gp_class;
static struct device *p_class_i2c;
static int major_num;
static unsigned char *i2c_msg;
int send_to_device(char *data, int count);
int receive_from_device(char *data, int count);
int cx20810_set_mode(int mode, int index);
// int led_array_set_mode(unsigned char * param, int length);
int led_array_set_enable(int enable);
int cx20810_write_reg(int index, int addr, int regval);
int cx20810_read_reg(int index, int cmd, int *regval);
enum {
I2C_DEVICE_FPGA = 0,
I2C_DEVICE_CX20810,
I2C_DEVICE_CX20810_0,
I2C_DEVICE_CX20810_1,
I2C_DEVICE_CX20810_2,
I2C_DEVICE_LED_ARRAY,
};
static void gp_hw_init(void) {
printk("i2c_operator.c->gp_hw_init()\n");
if (!D_IO_BASE) {
// printk("Timothy:D_IO_BASE is not initial yet, initial it now\n");
D_IO_BASE = (unsigned int)ioremap(D_IO_BASE_PHY, D_IO_LEN);
if (!D_IO_BASE) {
printk("led array hardware init io error\n");
return -1;
}
}
// set pe6 output and set it high to open mute led
// writel(readl(D_IO_CFG0(D_IO_E)) & (~(0x7<<24)) | (0x1<<24),
// D_IO_CFG0(D_IO_E)); writel(readl(D_IO_DAT(D_IO_E)) | 0x1<<6,
// D_IO_DAT(D_IO_E));
}
// add by Timothy
// time:2015-02-09
// start==========
// i2c设备write处理
static ssize_t gp_i2c_write_dispatch(int len) {
// //printk("Timothy:i2c_operator.c->gp_i2c_write_dispatch(), len = %d\n",
//len);
int ret = 0;
int i;
int device_index = (int)i2c_msg[0];
int length = len - sizeof(char);
// //printk("Timothy:device_index = %d\n", device_index);
// all 3 cx20810
if (I2C_DEVICE_CX20810 == device_index) {
// //printk("Timothy:operate device:cx20810\n");
for (i = 0; i < 3; i++) {
cx20810_set_mode((int)i2c_msg[1], i);
}
return 0;
}
else if (I2C_DEVICE_CX20810_0 == device_index) {
// //printk("Timothy:operate device:cx20810_0\n");
return cx20810_set_mode((int)i2c_msg[1], 0);
} else if (I2C_DEVICE_CX20810_1 == device_index) {
// //printk("Timothy:operate device:cx20810_1\n");
return cx20810_set_mode((int)i2c_msg[1], 1);
} else if (I2C_DEVICE_CX20810_2 == device_index) {
// //printk("Timothy:operate device:cx20810_2\n");
return cx20810_set_mode((int)i2c_msg[1], 2);
}
// LED
// else if(I2C_DEVICE_LED_ARRAY == device_index)
// {
// //printk("Timothy:operate device:led_array\n");
// return led_array_set_mode(&i2c_msg[1], length);
// }
// FPGA
else if (I2C_DEVICE_FPGA == device_index) {
// //printk("Timothy:operate device:FPGA, data lendth is
//%d\n", length);
ret = send_to_device((char *)&i2c_msg[1], length);
return ret;
}
return -1;
}
static int gp_i2c_read_dispatch(int len) {
// //printk("Timothy:i2c_operator.c->gp_i2c_read_dispatch()\n");
int ret = 0;
int device_index = (int)i2c_msg[0];
int length = len - sizeof(char);
// //printk("Timothy:device_index = %d\n", device_index);
if (I2C_DEVICE_FPGA == device_index) // FPGA
{
// //printk("Timothy:operate device:FPGA, data lendth is
//%d\n", length);
ret = receive_from_device((char *)&i2c_msg[1], length);
return ret;
}
return -1;
}
// end==========
static int gp_open(struct inode *pnode, struct file *pfile) {
// printk("Timothy:i2c_operator.c->gp_open()\n");
int major = MAJOR(pnode->i_rdev);
int minor = MINOR(pnode->i_rdev);
if (minor == 0) {
pfile->private_data = (void *)p_class_i2c;
// printk("Timothy:gp_open_i2c\n");
} else {
pfile->private_data = (void *)NULL;
// printk("Timothy:gp_open:unknow device\n");
}
return 0;
}
static int gp_close(struct inode *pnode, struct file *pfile) {
pfile->private_data = (void *)NULL;
printk("gp_close\n");
return 0;
}
static ssize_t gp_read(struct file *pfile, char __user *puser, size_t len,
loff_t *poff) {
int nread = 0;
int i;
// //printk("Timothy:i2c_operator.c->gp_read()\n");
if (pfile->private_data == p_class_i2c) {
// //printk("Timothy:gp_read():i2c device\n");
i2c_msg =
(unsigned char *)kzalloc(len * sizeof(unsigned char), GFP_KERNEL);
copy_from_user((void *)i2c_msg, puser, len);
nread = gp_i2c_read_dispatch(len);
// //printk("Timothy:the data will send to user is:%d\n",
//i2c_msg[1]);
copy_to_user(puser, (void *)i2c_msg, len);
kfree(i2c_msg);
}
// //printk("Timothy:return value is %d\n", nread);
return nread;
}
static ssize_t gp_write(struct file *pfile, const char __user *puser,
size_t len, loff_t *poff) {
// //printk("Timothy:i2c_operator.c->gp_write()\n");
int ret = 0;
int i;
if (pfile->private_data == p_class_i2c) {
// //printk("Timothy:gp_write():i2c device\n");
i2c_msg =
(unsigned char *)kzalloc(len * sizeof(unsigned char), GFP_KERNEL);
copy_from_user((void *)i2c_msg, puser, len);
// //printk("Timothy:the data is ");
// for(i = 0; i < len; i++)
// {
// printk("%x ", i2c_msg[i]);
// }
// printk("\n");
ret = gp_i2c_write_dispatch(len);
kfree(i2c_msg);
} else {
// //printk("Timothy:gp_write_null\n");
}
// //printk("Timothy:return value is %d\n", ret);
return ret;
}
// file operations
static long gp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {
u8 i;
int ret = 0;
struct i2c_ioctl_msg i2carg = {0};
printk("ioctl start cmd: %d arg: %lX\n", cmd, arg);
if (_IOC_TYPE(cmd) != MAGIC_NUM)
return -EINVAL;
if (_IOC_NR(cmd) > CMD_MAX)
return -EINVAL;
printk("ioctl start\n");
switch (cmd) {
case CMD_I2C_SET:
ret = copy_from_user(&i2carg, (struct i2c_ioctl_msg *)arg,
sizeof(i2carg));
if (0 == ret) {
printk("Will set i2c:%d reg:0x%x val:0x%x\n", i2carg.i2c_index,
i2carg.reg_addr, i2carg.reg_val);
} else {
printk("get user arg fail!\n");
}
cx20810_write_reg(i2carg.i2c_index, i2carg.reg_addr, i2carg.reg_val);
break;
case CMD_I2C_GET:
i2carg.reg_val = 0;
ret = copy_from_user(&i2carg, (struct i2c_ioctl_msg *)arg,
sizeof(i2carg));
cx20810_read_reg(i2carg.i2c_index, i2carg.reg_addr, &(i2carg.reg_val));
printk("Get i2c:%d reg:0x%x val:0x%x\n", i2carg.i2c_index,
i2carg.reg_addr, i2carg.reg_val);
ret = copy_to_user((void *)arg, &i2carg, sizeof(i2carg));
break;
default:
break;
}
printk("ioctl end\n");
return ret;
}
static struct file_operations gp_fops = {
.owner = THIS_MODULE,
.open = gp_open,
.release = gp_close,
.read = gp_read,
.write = gp_write,
.unlocked_ioctl = gp_ioctl,
};
static int __init i2c_operator_init(void) {
gp_hw_init();
major_num = register_chrdev(0, GP_CHR_DEV_NAME, &gp_fops);
if (major_num < 0) {
// printk("Timothy:gen_prov_reg_chr_err\n");
return 1;
}
p_gp_class = class_create(THIS_MODULE, GP_CLASS_NAME);
if (p_gp_class == NULL) {
// printk("Timothy:gen_prov:class create err\n");
}
p_class_i2c = device_create(p_gp_class, NULL, MKDEV(major_num, 0), NULL,
GP_I2C_DEV_NAME);
if (p_class_i2c == NULL) {
// printk("Timothy:gen_prov:device_create err:i2c\n");
return 1;
}
}
static void __exit i2c_operator_exit(void) {}
module_init(i2c_operator_init);
module_exit(i2c_operator_exit);
MODULE_AUTHOR("Timothy");
MODULE_DESCRIPTION("i2c operator driver");
MODULE_LICENSE("GPL");

View File

@ -0,0 +1,101 @@
#include <linux/kernel.h>
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
static struct kset *netease_keyset = NULL;
static struct kobject cpld_ko;
extern int cx20810_set_mode(int mode, int index);
extern void netease_cpld_reset(void);
enum {
CX20810_NORMAL_MODE = 0,
CX20810_NORMAL_MODE_SIMPLE,
CX20810_NIRMAL_MODE_CODEC3,
CX20810_NIRMAL_MODE_CODEC3_SIMPLE,
CX20810_96K_16BIT_MODE,
CX20810_48K_16BIT_MODE,
};
static ssize_t gen_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf) {
int count = 0;
count += sprintf(buf, "Cpld init help:\n");
count += sprintf(buf + count, "adc rst and config:echo 1 > cpld_init\n");
count += sprintf(buf + count, "adc rst:echo 2 > cpld_init\n");
count += sprintf(buf + count, "adc config:echo 3 > cpld_init\n");
return count;
}
static ssize_t gen_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count) {
long ret = -1;
kstrtol(buf, 10, &ret);
switch (ret) {
case 1:
printk("Adc rst and config\n");
netease_cpld_reset();
cx20810_set_mode(CX20810_NORMAL_MODE, 0);
cx20810_set_mode(CX20810_NORMAL_MODE, 1);
break;
case 2:
printk("Adc rst\n");
netease_cpld_reset();
break;
case 3:
printk("Adc config\n");
cx20810_set_mode(CX20810_NORMAL_MODE, 0);
cx20810_set_mode(CX20810_NORMAL_MODE, 1);
break;
default:
printk("Can not read your input cmd, need help? type cat cpld_init.");
}
printk("Do finish, Get ret:%d, count:%d, input:%s\n", ret, count, buf);
// tipa_set_vol(2 * (24-i));
return count;
}
static const struct sysfs_ops cpld_ktype_ops = {
.show = gen_attr_show,
.store = gen_attr_store,
};
struct attribute cpld_init_set = {
.name = "cpld_init",
.mode = S_IRWXUGO,
};
struct attribute *cpld_attr_group[] = {&cpld_init_set, NULL};
void cpld_release(struct kobject *kobj) {
printk("wzj:release %d\n", kobj->name);
}
static struct kobj_type cpld_ko_ktype = {
.sysfs_ops = &cpld_ktype_ops,
.default_attrs = cpld_attr_group,
.release = cpld_release,
};
static int __init netease_config_init(void) {
printk("Begin to start netease config!\n");
netease_keyset = kset_create_and_add("netease", NULL, NULL);
cpld_ko.kset = netease_keyset;
kobject_init_and_add(&cpld_ko, &cpld_ko_ktype, NULL, "cpld_control");
return 0;
}
module_init(netease_config_init);
static void __exit netease_config_exit(void) {}
module_exit(netease_config_exit);
/* Module information */
MODULE_AUTHOR("Wang zijiao");
MODULE_DESCRIPTION("Netease config!");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:netease_config");

File diff suppressed because it is too large Load Diff

View File

@ -102,6 +102,7 @@ static int sunxi_snddaudio_hw_params(struct snd_pcm_substream *substream,
/* sunxi card initialization */
static int sunxi_snddaudio_init(struct snd_soc_pcm_runtime *rtd)
{
printk("wzj:sunxi_snddaudio_init!\n");
return 0;
}
@ -356,6 +357,9 @@ cpu_node_find:
dai_link->codec_name,
dai_link->codec_dai_name);
printk("wzj: codec: %s, codec_dai: %s.\n",
dai_link->codec_name,
dai_link->codec_dai_name);
#ifdef CONFIG_SND_SUNXI_MAD
sunxi_daudio_priv.mad_bind = 0;
snd_soc_card_set_drvdata(card, &sunxi_daudio_priv);

View File

@ -0,0 +1,98 @@
##############################################
# OpenWrt Makefile for helloworld program
#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.
#
##############################################
include $(TOPDIR)/rules.mk
# Name and release number of this package
PKG_NAME:=adau1761
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(COMPILE_DIR)/$(PKG_NAME)
include $(BUILD_DIR)/package.mk
# Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/adau1761
SECTION:=utils
CATEGORY:=Allwinner
TITLE:=just test adau1761
DEPENDS:=+libpthread
endef
# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/adau1761/description
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef
# Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default. The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Configure
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS)" -Wall \
LDFLAGS="$(TARGET_LDFLAGS)" \
LIBS="-lpthread" \
all
endef
# We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one
# Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/adau1761/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/adau1761 $(1)/bin/
endef
# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,adau1761))

View File

@ -0,0 +1,16 @@
TARGET = adau1761
LIBS += -lpthread -lm -lrt
SRCS = main.c
OBJS = $(SRCS:.c=.o)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(TARGET): $(OBJS)
$(CC) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
all:$(TARGET)
clean:
rm -rf $(TARGET) *.o *.a *~

View File

@ -0,0 +1,148 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/ioctl.h>
// io commands
#define MAGIC_NUM 'A'
#define ADAU1761_CMD_VOL_SET _IOW(MAGIC_NUM, 0, int)
#define ADAU1761_CMD_VOL_GET _IOR(MAGIC_NUM, 1, int)
#define ADAU1761_CMD_AMP_MUTE_SET _IOW(MAGIC_NUM, 2, int)
#define ADAU1761_CMD_AMP_MUTE_GET _IOR(MAGIC_NUM, 3, int)
#define ADAU1761_CMD_SRC_SET _IOW(MAGIC_NUM, 4, int)
#define ADAU1761_CMD_SRC_GET _IOR(MAGIC_NUM, 5, int)
#define ADAU1761_CMD_FW_LOAD _IOW(MAGIC_NUM, 6, int)
#define ADAU1761_CMD_EQ_SET _IOW(MAGIC_NUM, 7, int)
#define ADAU1761_CMD_MAX (7)
#define MAX_VOL_STEP (20)
int main(int argc, char *argv[])
{
int fd, ret = 0;
unsigned int cmd;
unsigned long para;
char *path = "/dev/adau1761";
printf("argv1 is cmd, argv2 is para.\n");
if((atoi(argv[1]) < 0) || (atoi(argv[1]) > ADAU1761_CMD_MAX)) {
printf("argv1 is out of scope\n");
exit(1);
}
cmd = (unsigned int)atoi(argv[1]);
para = (unsigned long)atoi(argv[2]);
printf("cmd %ud, para %lu.\n", cmd, para);
fd = open(path, O_RDWR);
if(fd < 0) {
printf("open %s failed.\n", path);
} else {
printf("fd %d, cmd %ud, para %lu.\n", fd, cmd, para);
switch(cmd) {
case 0:
if((para < 0) || (para > MAX_VOL_STEP)) {
printf("argv2 is out of scope\n");
exit(2);
}
cmd = _IOW(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, para);
printf("return: %d\n", ret);
break;
case 1:
cmd = _IOR(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, (unsigned long)&para);
printf("return: %lu\n", para);
if((para < 0) || (para > MAX_VOL_STEP)) {
printf("vol is out of scope\n");
exit(3);
}
break;
case 2:
if((para < 0) || (para > 1)) {
printf("argv2 is out of scope\n");
exit(4);
}
cmd = _IOW(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, para);
printf("return: %d\n", ret);
break;
case 3:
cmd = _IOR(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, (unsigned long)&para);
printf("return: %lu\n", para);
if((para < 0) || (para > 1)) {
printf("mute is out of scope\n");
exit(5);
}
break;
case 4:
if((para < 0) || (para > 1)) {
printf("argv2 is out of scope\n");
exit(6);
}
cmd = _IOW(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, para);
printf("return: %d\n", ret);
break;
case 5:
cmd = _IOR(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, (unsigned long)&para);
printf("return: %lu\n", para);
if((para < 0) || (para > 1)) {
printf("src is out of scope\n");
exit(7);
}
break;
case 6:
cmd = _IOW(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, para);
printf("return: %d\n", ret);
break;
case 7:
if((para < 0) || (para > 2)) {
printf("argv2 is out of scope\n");
}
cmd = _IOW(MAGIC_NUM, cmd, int);
ret = ioctl(fd, cmd, para);
printf("return: %d\n", ret);
break;
default:
break;
}
}
close(fd);
return ret;
}

View File

@ -1,6 +1,6 @@
config system
option hostname TinaLinux
option timezone Asia/Shanghai
option zonename Asia/Shanghai
option timezone CST-8
option log_file /root/.lastlog
option log_size 512

Binary file not shown.

View File

@ -92,12 +92,12 @@ define Package/$(PKG_NAME)/install
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/$(PKG_NAME)/nembd/evdev/bin/netease_keytest $(1)/usr/sbin/
$(INSTALL_BIN) ./netease.init $(1)/etc/init.d/netease_services
$(INSTALL_BIN) ./neteasewifi.init $(1)/etc/init.d/netease_wifi_service
$(INSTALL_BIN) ./neteasevoice.init $(1)/etc/init.d/netease_voice_service
$(INSTALL_BIN) ./neteaseplayer.init $(1)/etc/init.d/netease_player_service
# $(INSTALL_BIN) ./neteasevoice.init $(1)/etc/init.d/netease_voice_service
# $(INSTALL_BIN) ./neteaseplayer.init $(1)/etc/init.d/netease_player_service
$(INSTALL_BIN) ./neteasemanufacture_cc.init $(1)/etc/init.d/netease_cc_manufacture_service
$(INSTALL_BIN) ./neteasemanufacture_mcu.init $(1)/etc/init.d/netease_mcu_manufacture_service
$(INSTALL_BIN) ./neteasemanufacture_rf.init $(1)/etc/init.d/netease_rf_manufacture_service
$(INSTALL_BIN) ./neteasecc.init $(1)/etc/init.d/netease_cc_service
# $(INSTALL_BIN) ./neteasecc.init $(1)/etc/init.d/netease_cc_service
$(INSTALL_BIN) ./neteasebt.init $(1)/etc/init.d/netease_bt_service
$(INSTALL_DATA) mcu/* $(1)/usr/share/golang/mcu/
$(INSTALL_DATA) vol_adc.config $(1)/usr/share/golang/

View File

@ -161,3 +161,11 @@ void setBindUser(char *user, size_t len) {
}
char *getBindUser() { return (char *)g_binduser; }
void resetAdc() {
n_debug("Begin to reset adc!\n");
char * cmd = "1";
int fd = open("/sys/netease/cpld_control/cpld_init", O_RDWR);
write(fd, cmd, strlen(cmd));
close(fd);
}

View File

@ -85,6 +85,7 @@ int getVoiceStatus();
void setVoiceConfidence(double voiceConfidence);
double getVoiceConfidence();
void resetAdc();
#ifdef __cplusplus
} /* extern "C" */
#endif /* C++ */

View File

@ -38,7 +38,7 @@ enum {
// fprintf(stderr, format, ##arg)
#ifdef NETEASE_TOAST
#define n_toast(fmt, arg...) n_printf(fmt, ##arg)
#define n_toast(fmt, arg...) printf(fmt, ##arg)
#else
#define n_toast(fmt, arg...) \
do { \
@ -46,7 +46,7 @@ enum {
#endif
#ifdef NETEASE_DEBUG
#define n_debug(fmt, arg...) n_printf(fmt, ##arg)
#define n_debug(fmt, arg...) printf(fmt, ##arg)
#else
#define n_debug(fmt, arg...) \
do { \
@ -54,7 +54,7 @@ enum {
#endif
#ifdef NETEASE_ERROR
#define n_error(fmt, arg...) n_printf(fmt, ##arg)
#define n_error(fmt, arg...) printf(fmt, ##arg)
#else
#define n_error(fmt, arg...) \
do { \

View File

@ -46,7 +46,7 @@ when who why
/* ------------------------------------------------------------------------
** Macros
** ------------------------------------------------------------------------ */
//#define BACKUP_ORIG_AUDIO
#define BACKUP_ORIG_AUDIO
//#define BACKUP_FINAL_AUDIO
/* ------------------------------------------------------------------------
@ -515,13 +515,13 @@ void main(int argc, char **argv) {
#ifdef ENABLE_OEM_DBUS
ret = Netease_dbus_oem_init(DBusMessageCb);
#else
ret = Netease_Dbus_Init(DBusMessageCb);
// ret = Netease_Dbus_Init(DBusMessageCb);
#endif
if (NETEASE_SUCCESS == ret) {
n_debug("Dbus init success\n");
} else {
n_error("Dbus init fail: %d\n", ret);
return;
// return;
}
#if USED_NETEASE_FMAE
@ -563,6 +563,10 @@ void main(int argc, char **argv) {
printf("period_size name is %d\n", recordconfig.period_size);
printf("++++++++++++++++++++++++++\n");
n_debug("Begin to init netease_voice modules!\n");
extern void listAlsaDev();
resetAdc();
listAlsaDev();
#ifdef BACKUP_ORIG_AUDIO
fd_audio_orig = open(argv[1], O_CREAT | O_APPEND | O_RDWR);
n_debug("Open file: %s, fd:%d\n", argv[1], fd_audio_orig);
@ -654,7 +658,7 @@ void main(int argc, char **argv) {
}
#ifdef ENABLE_YUNXIN
Netease_yunxin_init(&audiobypassconfig);
// Netease_yunxin_init(&audiobypassconfig);
#endif
// Netease_Dbus_Start_Sync();
@ -662,14 +666,14 @@ void main(int argc, char **argv) {
#ifdef ENABLE_OEM_DBUS
pthread_create(&tid, NULL, Netease_dbus_oem_start, NULL);
#else
pthread_create(&tid, NULL, Netease_Dbus_Start_Sync, NULL);
// pthread_create(&tid, NULL, Netease_Dbus_Start_Sync, NULL);
#endif
// Netease_yunxin_test();
while (1) {
if (strlen(getUuid()) == 0 || strlen(getYxToken()) == 0) {
n_toast("Get args frome cc\n");
Netease_dbus_initargs();
// n_toast("Get args frome cc\n");
// Netease_dbus_initargs();
usleep(1000000);
} else {
break;

View File

@ -506,6 +506,11 @@ void Netease_yunxin_cb_disconnect(const char *json_params,
NULL);
}
void listAlsaDev() {
char *dev = nrtc_alsa_available_devices(false);
n_toast("Avalible dev: %s\n", dev);
}
int Netease_yunxin_init(struct audio_bypass **bypass) {
// alsa_hd = nrtc_audio_alsa_core_create(false, 1, 16000, 16);
// if (!alsa_hd) {

View File

@ -38,7 +38,7 @@ define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/sbin/
$(INSTALL_BIN) ./voice.init $(1)/etc/init.d/voice_service
# $(INSTALL_BIN) ./voice.init $(1)/etc/init.d/voice_service
$(INSTALL_BIN) ./netease_record.sh $(1)/usr/sbin/netease_record
endef

View File

@ -140,7 +140,6 @@ static void* RecordThread(void* param)
static void record_audio_cb(const void *audio, unsigned int audio_len, int err_code)
{
if (SUCCESS == err_code){
FILE *fp = fopen(out_pcm_name, "ab+");
if (NULL == fp){
@ -150,7 +149,6 @@ static void record_audio_cb(const void *audio, unsigned int audio_len, int err_c
fwrite(audio, audio_len, 1, fp);
fclose(fp);
}
}
int start_record(struct pcm_config pcm_cfg)

View File

@ -1,3 +1,7 @@
# CONFIG_ADAU1761 is not set
# CONFIG_ADAU1761_ES1 is not set
# CONFIG_ADAU1761_ES2 is not set
CONFIG_ADAU1761_R311_PV1=y
CONFIG_ADVISE_SYSCALLS=y
# CONFIG_AF_KCM is not set
CONFIG_ALIGNMENT_TRAP=y
@ -325,6 +329,7 @@ CONFIG_FS_POSIX_ACL=y
# CONFIG_FW_CFG_SYSFS is not set
# CONFIG_FW_LOADER_USER_HELPER_FALLBACK is not set
# CONFIG_GCC_PLUGINS is not set
CONFIG_GDB_SCRIPTS=y
CONFIG_GENERIC_ALLOCATOR=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_CLOCKEVENTS=y
@ -348,6 +353,7 @@ CONFIG_GPIOLIB=y
# CONFIG_GPIO_MPC8XXX is not set
# CONFIG_GPIO_PISOSR is not set
# CONFIG_GPIO_SUNXI is not set
CONFIG_GPIO_SYSFS=y
# CONFIG_GPIO_TPIC2810 is not set
# CONFIG_GPIO_TS4900 is not set
# CONFIG_GREYBUS is not set
@ -512,6 +518,7 @@ CONFIG_MEDIA_SUBDRV_AUTOSELECT=y
CONFIG_MEDIA_SUPPORT=y
CONFIG_MEMORY_ISOLATION=y
# CONFIG_MEMORY_STATE_TIME is not set
CONFIG_MESSAGE_LOGLEVEL_DEFAULT=7
# CONFIG_MFD_ACT8945A is not set
# CONFIG_MFD_ACX00 is not set
# CONFIG_MFD_AXP20X_I2C is not set
@ -743,10 +750,11 @@ CONFIG_SND_SOC_I2C_AND_SPI=y
CONFIG_SND_SPI=y
CONFIG_SND_SUN8IW15_CODEC=y
CONFIG_SND_SUNXI_SOC=y
CONFIG_SND_SUNXI_SOC_DAUDIO=y
CONFIG_SND_SUNXI_SOC_INTER_I2S=y
CONFIG_SND_SUNXI_SOC_RWFUNC=y
CONFIG_SND_SUNXI_SOC_SUN8IW15_CODEC=y
# CONFIG_SND_SUNXI_SOC_SUNXI_DAUDIO is not set
CONFIG_SND_SUNXI_SOC_SUNXI_DAUDIO=y
# CONFIG_SND_SUNXI_SOC_SUNXI_DMIC is not set
CONFIG_SND_SUPPORT_OLD_API=y
CONFIG_SND_TIMER=y
@ -953,6 +961,7 @@ CONFIG_XFRM_SUB_POLICY=y
CONFIG_XFRM_USER=y
CONFIG_XPS=y
# CONFIG_XR_WLAN is not set
CONFIG_XUNFEI_CPLD=y
CONFIG_ZBOOT_ROM_BSS=0
CONFIG_ZBOOT_ROM_TEXT=0
CONFIG_ZLIB_INFLATE=y

View File

@ -550,7 +550,7 @@ lcd1_hue = 50
;smart_color 90:normal lcd screen 65:retina lcd screen(9.7inch)
;----------------------------------------------------------------------------------
[lcd0]
lcd_used = 1
lcd_used = 0
lcd_driver_name = "default_lcd"
lcd_backlight = 50
@ -702,13 +702,13 @@ lcdvsync = port:PD21<7><0><default><default>
;hdmi configuration
;----------------------------------------------------------------------------------
[hdmi_para]
hdmi_used = 1
hdmi_used = 0
;----------------------------------------------------------------------------------
;pwm config
;----------------------------------------------------------------------------------
[pwm0]
pwm_used = 1
pwm_used = 0
pwm_positive = port:PD23<2><0><default><default>
[pwm0_suspend]
@ -1251,12 +1251,12 @@ snddaudio0_used = 1
daudio0_used = 1
daudio_master = 4
tdm_config = 1
mclk_div = 1
clk_active = 0
mclk_div = 2
clk_active = 1
audio_format = 1
signal_inversion = 1
pcm_lrck_period = 32
;msb_lsb_first = 0
msb_lsb_first = 0
slot_width_select = 32
frametype = 1
;tx_data_mode = 1
@ -1690,6 +1690,14 @@ hold-time-ms = 0
fall-time-ms = 6
off-time-ms = 4
;--------------------------------------------------------------------------------
;digital amplifier control
;--------------------------------------------------------------------------------
[dig_amp]
compatible = "allwinner,adau1761-r311-pv1"
audio_pa_mute = port:PH07<1><default><default><0>
audio_pa_sdz = port:PH06<1><default><default><0>
[led_g]
led_name = "green"
id = 1
@ -1711,3 +1719,10 @@ rise-time-ms = 6
hold-time-ms = 0
fall-time-ms = 6
off-time-ms = 4
[cpld]
compatible = "allwinner,cpld-r311-pv1"
gp_adc_rst = port:PD21<1><1><default><1>
gp_cpld_rst = port:PL10<1><1><default><1>
4v5_ldo_en = port:PH04<1><default><default><0>
3v_ldo_en = port:PH05<1><default><default><0>

View File

@ -1365,6 +1365,7 @@ CONFIG_PACKAGE_wireless-tools=y
# CONFIG_PACKAGE_tplayerdemo is not set
# CONFIG_PACKAGE_trecorderdemo is not set
# CONFIG_PACKAGE_MtpDaemon is not set
CONFIG_PACKAGE_adau1761=y
CONFIG_PACKAGE_adb=y
# CONFIG_PACKAGE_aec-xt-demo is not set
# CONFIG_PACKAGE_benchmarks is not set
@ -1465,7 +1466,7 @@ CONFIG_PACKAGE_softap=y
# CONFIG_PACKAGE_stress-ng is not set
# CONFIG_PACKAGE_tina-upgrade is not set
# CONFIG_PACKAGE_tinacvr is not set
# CONFIG_PACKAGE_tinymp3 is not set
CONFIG_PACKAGE_tinymp3=y
# CONFIG_PACKAGE_tsc_demo is not set
# CONFIG_PACKAGE_usb-gadget is not set
CONFIG_PACKAGE_wifimanager=y
@ -2438,7 +2439,7 @@ CONFIG_PACKAGE_libjson-c=y
# CONFIG_PACKAGE_liblua is not set
# CONFIG_PACKAGE_liblz4 is not set
# CONFIG_PACKAGE_liblzo is not set
# CONFIG_PACKAGE_libmad is not set
CONFIG_PACKAGE_libmad=y
# CONFIG_PACKAGE_libmcrypt is not set
# CONFIG_PACKAGE_libmicrohttpd is not set
# CONFIG_PACKAGE_libmijia is not set
@ -2449,7 +2450,7 @@ CONFIG_PACKAGE_libjson-c=y
# CONFIG_PACKAGE_libmosquittopp is not set
# CONFIG_PACKAGE_libmount is not set
# CONFIG_PACKAGE_libmraa is not set
# CONFIG_PACKAGE_libmsc is not set
CONFIG_PACKAGE_libmsc=y
# CONFIG_PACKAGE_libmysqlclient is not set
# CONFIG_PACKAGE_libmysqlclient-r is not set
CONFIG_PACKAGE_libncurses=y
@ -2771,7 +2772,7 @@ CONFIG_TTF2_SUPPORT=y
# CONFIG_PACKAGE_KPlayerTest is not set
# CONFIG_PACKAGE_SPlayer is not set
# CONFIG_PACKAGE_SPlayer-demo is not set
CONFIG_PACKAGE_alarmer=y
# CONFIG_PACKAGE_alarmer is not set
# CONFIG_PACKAGE_blueKC is not set
# CONFIG_PACKAGE_blueKC-demo is not set
# CONFIG_PACKAGE_config_server is not set
@ -2787,7 +2788,7 @@ CONFIG_PACKAGE_libuvdbus=y
CONFIG_RES_NORMAL_MODE=y
# CONFIG_PACKAGE_log_ctrl is not set
# CONFIG_PACKAGE_mcu_ota is not set
CONFIG_PACKAGE_netease_control_center=y
# CONFIG_PACKAGE_netease_control_center is not set
# CONFIG_PACKAGE_netease_test is not set
CONFIG_PACKAGE_netease_voice=y
@ -2799,13 +2800,13 @@ CONFIG_NETEASE_MSC_SDK=y
# CONFIG_NETEASE_CAE_SDK is not set
CONFIG_XUNFEI_CAE_SDK=y
CONFIG_NETEASE_DUILITE_SDK=y
CONFIG_NETEASE_TTS_SDK=y
# CONFIG_XUNFEI_TTS_SDK is not set
# CONFIG_NETEASE_TTS_SDK is not set
CONFIG_XUNFEI_TTS_SDK=y
# CONFIG_USED_NONE is not set
CONFIG_USED_DC_SDK=y
# CONFIG_PACKAGE_ntes_record is not set
CONFIG_PACKAGE_ota=y
CONFIG_PACKAGE_pv1res=y
CONFIG_PACKAGE_ntes_record=y
# CONFIG_PACKAGE_ota is not set
# CONFIG_PACKAGE_pv1res is not set
# CONFIG_PACKAGE_rokid_test is not set
# CONFIG_PACKAGE_sraop is not set
# CONFIG_PACKAGE_wifiDemo is not set