Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
kernel_linux
提交
ef8e26bb
K
kernel_linux
项目概览
OpenHarmony
/
kernel_linux
上一次同步 4 年多
通知
15
Star
8
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kernel_linux
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ef8e26bb
编写于
7月 25, 2016
作者:
T
Thierry Reding
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'for-4.8/core' into for-next
上级
bcedaba1
2b77487f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
88 addition
and
1 deletion
+88
-1
include/linux/pwm.h
include/linux/pwm.h
+88
-1
未找到文件。
include/linux/pwm.h
浏览文件 @
ef8e26bb
...
@@ -147,6 +147,94 @@ static inline void pwm_get_args(const struct pwm_device *pwm,
...
@@ -147,6 +147,94 @@ static inline void pwm_get_args(const struct pwm_device *pwm,
*
args
=
pwm
->
args
;
*
args
=
pwm
->
args
;
}
}
/**
* pwm_init_state() - prepare a new state to be applied with pwm_apply_state()
* @pwm: PWM device
* @state: state to fill with the prepared PWM state
*
* This functions prepares a state that can later be tweaked and applied
* to the PWM device with pwm_apply_state(). This is a convenient function
* that first retrieves the current PWM state and the replaces the period
* and polarity fields with the reference values defined in pwm->args.
* Once the function returns, you can adjust the ->enabled and ->duty_cycle
* fields according to your needs before calling pwm_apply_state().
*
* ->duty_cycle is initially set to zero to avoid cases where the current
* ->duty_cycle value exceed the pwm_args->period one, which would trigger
* an error if the user calls pwm_apply_state() without adjusting ->duty_cycle
* first.
*/
static
inline
void
pwm_init_state
(
const
struct
pwm_device
*
pwm
,
struct
pwm_state
*
state
)
{
struct
pwm_args
args
;
/* First get the current state. */
pwm_get_state
(
pwm
,
state
);
/* Then fill it with the reference config */
pwm_get_args
(
pwm
,
&
args
);
state
->
period
=
args
.
period
;
state
->
polarity
=
args
.
polarity
;
state
->
duty_cycle
=
0
;
}
/**
* pwm_get_relative_duty_cycle() - Get a relative duty cycle value
* @state: PWM state to extract the duty cycle from
* @scale: target scale of the relative duty cycle
*
* This functions converts the absolute duty cycle stored in @state (expressed
* in nanosecond) into a value relative to the period.
*
* For example if you want to get the duty_cycle expressed in percent, call:
*
* pwm_get_state(pwm, &state);
* duty = pwm_get_relative_duty_cycle(&state, 100);
*/
static
inline
unsigned
int
pwm_get_relative_duty_cycle
(
const
struct
pwm_state
*
state
,
unsigned
int
scale
)
{
if
(
!
state
->
period
)
return
0
;
return
DIV_ROUND_CLOSEST_ULL
((
u64
)
state
->
duty_cycle
*
scale
,
state
->
period
);
}
/**
* pwm_set_relative_duty_cycle() - Set a relative duty cycle value
* @state: PWM state to fill
* @duty_cycle: relative duty cycle value
* @scale: scale in which @duty_cycle is expressed
*
* This functions converts a relative into an absolute duty cycle (expressed
* in nanoseconds), and puts the result in state->duty_cycle.
*
* For example if you want to configure a 50% duty cycle, call:
*
* pwm_init_state(pwm, &state);
* pwm_set_relative_duty_cycle(&state, 50, 100);
* pwm_apply_state(pwm, &state);
*
* This functions returns -EINVAL if @duty_cycle and/or @scale are
* inconsistent (@scale == 0 or @duty_cycle > @scale).
*/
static
inline
int
pwm_set_relative_duty_cycle
(
struct
pwm_state
*
state
,
unsigned
int
duty_cycle
,
unsigned
int
scale
)
{
if
(
!
scale
||
duty_cycle
>
scale
)
return
-
EINVAL
;
state
->
duty_cycle
=
DIV_ROUND_CLOSEST_ULL
((
u64
)
duty_cycle
*
state
->
period
,
scale
);
return
0
;
}
/**
/**
* struct pwm_ops - PWM controller operations
* struct pwm_ops - PWM controller operations
* @request: optional hook for requesting a PWM
* @request: optional hook for requesting a PWM
...
@@ -323,7 +411,6 @@ static inline void pwm_disable(struct pwm_device *pwm)
...
@@ -323,7 +411,6 @@ static inline void pwm_disable(struct pwm_device *pwm)
pwm_apply_state
(
pwm
,
&
state
);
pwm_apply_state
(
pwm
,
&
state
);
}
}
/* PWM provider APIs */
/* PWM provider APIs */
int
pwm_set_chip_data
(
struct
pwm_device
*
pwm
,
void
*
data
);
int
pwm_set_chip_data
(
struct
pwm_device
*
pwm
,
void
*
data
);
void
*
pwm_get_chip_data
(
struct
pwm_device
*
pwm
);
void
*
pwm_get_chip_data
(
struct
pwm_device
*
pwm
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录