Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OS
U-Boot.Mirror
提交
aad813a3
U
U-Boot.Mirror
项目概览
OS
/
U-Boot.Mirror
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
U-Boot.Mirror
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aad813a3
编写于
1月 17, 2011
作者:
W
Wolfgang Denk
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
git://git.denx.de/u-boot-i2c
上级
245eb900
5dec49ca
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
94 addition
and
22 deletion
+94
-22
README
README
+4
-0
drivers/gpio/pca953x.c
drivers/gpio/pca953x.c
+90
-22
未找到文件。
README
浏览文件 @
aad813a3
...
...
@@ -746,6 +746,10 @@ The following options need to be configured:
CONFIG_PCA953X - use NXP's PCA953X series I2C GPIO
CONFIG_PCA953X_INFO - enable pca953x info command
The CONFIG_SYS_I2C_PCA953X_WIDTH option specifies a list of
chip-ngpio pairs that tell the PCA953X driver the number of
pins supported by a particular chip.
Note that if the GPIO device uses I2C, then the I2C interface
must also be configured. See I2C Support, below.
...
...
drivers/gpio/pca953x.c
浏览文件 @
aad813a3
...
...
@@ -17,8 +17,8 @@
*/
/*
* Driver for NXP's 4
and 8 bit I2C gpio expanders (eg pca9537, pca9557, etc)
*
TODO: support additional devices with more than 8-bits GPIO
* Driver for NXP's 4
, 8 and 16 bit I2C gpio expanders (eg pca9537, pca9557,
*
pca9539, etc)
*/
#include <common.h>
...
...
@@ -38,20 +38,81 @@ enum {
PCA953X_CMD_INVERT
,
};
#ifdef CONFIG_SYS_I2C_PCA953X_WIDTH
struct
pca953x_chip_ngpio
{
uint8_t
chip
;
uint8_t
ngpio
;
};
static
struct
pca953x_chip_ngpio
pca953x_chip_ngpios
[]
=
CONFIG_SYS_I2C_PCA953X_WIDTH
;
#define NUM_CHIP_GPIOS (sizeof(pca953x_chip_ngpios) / \
sizeof(struct pca953x_chip_ngpio))
/*
* Determine the number of GPIO pins supported. If we don't know we assume
* 8 pins.
*/
static
int
pca953x_ngpio
(
uint8_t
chip
)
{
int
i
;
for
(
i
=
0
;
i
<
NUM_CHIP_GPIOS
;
i
++
)
if
(
pca953x_chip_ngpios
[
i
].
chip
==
chip
)
return
pca953x_chip_ngpios
[
i
].
ngpio
;
return
8
;
}
#else
static
int
pca953x_ngpio
(
uint8_t
chip
)
{
return
8
;
}
#endif
/*
* Modify masked bits in register
*/
static
int
pca953x_reg_write
(
uint8_t
chip
,
uint
addr
,
uint
mask
,
uint
data
)
{
uint8_t
val
;
uint8_t
valb
;
uint16_t
valw
;
if
(
i2c_read
(
chip
,
addr
,
1
,
&
val
,
1
))
return
-
1
;
if
(
pca953x_ngpio
(
chip
)
<=
8
)
{
if
(
i2c_read
(
chip
,
addr
,
1
,
&
valb
,
1
))
return
-
1
;
valb
&=
~
mask
;
valb
|=
data
;
return
i2c_write
(
chip
,
addr
,
1
,
&
valb
,
1
);
}
else
{
if
(
i2c_read
(
chip
,
addr
<<
1
,
1
,
(
u8
*
)
&
valw
,
2
))
return
-
1
;
val
&=
~
mask
;
val
|=
data
;
valw
&=
~
mask
;
valw
|=
data
;
return
i2c_write
(
chip
,
addr
,
1
,
&
val
,
1
);
return
i2c_write
(
chip
,
addr
<<
1
,
1
,
(
u8
*
)
&
valw
,
2
);
}
}
static
int
pca953x_reg_read
(
uint8_t
chip
,
uint
addr
,
uint
*
data
)
{
uint8_t
valb
;
uint16_t
valw
;
if
(
pca953x_ngpio
(
chip
)
<=
8
)
{
if
(
i2c_read
(
chip
,
addr
,
1
,
&
valb
,
1
))
return
-
1
;
*
data
=
(
int
)
valb
;
}
else
{
if
(
i2c_read
(
chip
,
addr
<<
1
,
1
,
(
u8
*
)
&
valw
,
2
))
return
-
1
;
*
data
=
(
int
)
valw
;
}
return
0
;
}
/*
...
...
@@ -86,9 +147,9 @@ int pca953x_set_dir(uint8_t chip, uint mask, uint data)
*/
int
pca953x_get_val
(
uint8_t
chip
)
{
uint
8_t
val
;
uint
val
;
if
(
i2c_read
(
chip
,
0
,
1
,
&
val
,
1
)
)
if
(
pca953x_reg_read
(
chip
,
PCA953X_IN
,
&
val
)
<
0
)
return
-
1
;
return
(
int
)
val
;
...
...
@@ -102,37 +163,44 @@ int pca953x_get_val(uint8_t chip)
static
int
pca953x_info
(
uint8_t
chip
)
{
int
i
;
uint8_t
data
;
uint
data
;
int
nr_gpio
=
pca953x_ngpio
(
chip
);
int
msb
=
nr_gpio
-
1
;
printf
(
"pca953x@ 0x%x:
\n\n
"
,
chip
);
printf
(
"gpio pins: 76543210
\n
"
);
printf
(
"-------------------
\n
"
);
printf
(
"pca953x@ 0x%x (%d pins):
\n\n
"
,
chip
,
nr_gpio
);
printf
(
"gpio pins: "
);
for
(
i
=
msb
;
i
>=
0
;
i
--
)
printf
(
"%x"
,
i
);
printf
(
"
\n
"
);
for
(
i
=
11
+
nr_gpio
;
i
>
0
;
i
--
)
printf
(
"-"
);
printf
(
"
\n
"
);
if
(
i2c_read
(
chip
,
PCA953X_CONF
,
1
,
&
data
,
1
)
)
if
(
pca953x_reg_read
(
chip
,
PCA953X_CONF
,
&
data
)
<
0
)
return
-
1
;
printf
(
"conf: "
);
for
(
i
=
7
;
i
>=
0
;
i
--
)
for
(
i
=
msb
;
i
>=
0
;
i
--
)
printf
(
"%c"
,
data
&
(
1
<<
i
)
?
'i'
:
'o'
);
printf
(
"
\n
"
);
if
(
i2c_read
(
chip
,
PCA953X_POL
,
1
,
&
data
,
1
)
)
if
(
pca953x_reg_read
(
chip
,
PCA953X_POL
,
&
data
)
<
0
)
return
-
1
;
printf
(
"invert: "
);
for
(
i
=
7
;
i
>=
0
;
i
--
)
for
(
i
=
msb
;
i
>=
0
;
i
--
)
printf
(
"%c"
,
data
&
(
1
<<
i
)
?
'1'
:
'0'
);
printf
(
"
\n
"
);
if
(
i2c_read
(
chip
,
PCA953X_IN
,
1
,
&
data
,
1
)
)
if
(
pca953x_reg_read
(
chip
,
PCA953X_IN
,
&
data
)
<
0
)
return
-
1
;
printf
(
"input: "
);
for
(
i
=
7
;
i
>=
0
;
i
--
)
for
(
i
=
msb
;
i
>=
0
;
i
--
)
printf
(
"%c"
,
data
&
(
1
<<
i
)
?
'1'
:
'0'
);
printf
(
"
\n
"
);
if
(
i2c_read
(
chip
,
PCA953X_OUT
,
1
,
&
data
,
1
)
)
if
(
pca953x_reg_read
(
chip
,
PCA953X_OUT
,
&
data
)
<
0
)
return
-
1
;
printf
(
"output: "
);
for
(
i
=
7
;
i
>=
0
;
i
--
)
for
(
i
=
msb
;
i
>=
0
;
i
--
)
printf
(
"%c"
,
data
&
(
1
<<
i
)
?
'1'
:
'0'
);
printf
(
"
\n
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录