mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
* refs/heads/tmp-cfee25d: Linux 4.14.126 ALSA: seq: Cover unsubscribe_port() in list_mutex drm: don't block fb changes for async plane updates Revert "drm/nouveau: add kconfig option to turn off nouveau legacy contexts. (v3)" Revert "Bluetooth: Align minimum encryption key size for LE and BR/EDR connections" percpu: do not search past bitmap when allocating an area gpio: vf610: Do not share irq_chip usb: typec: fusb302: Check vconn is off when we start toggling ARM: exynos: Fix undefined instruction during Exynos5422 resume pwm: Fix deadlock warning when removing PWM device ARM: dts: exynos: Always enable necessary APIO_1V8 and ABB_1V8 regulators on Arndale Octa pwm: tiehrpwm: Update shadow register for disabling PWMs dmaengine: idma64: Use actual device for DMA transfers gpio: gpio-omap: add check for off wake capable gpios PCI: xilinx: Check for __get_free_pages() failure block, bfq: increase idling for weight-raised queues video: imsttfb: fix potential NULL pointer dereferences video: hgafb: fix potential NULL pointer dereference PCI: rcar: Fix 64bit MSI message address handling PCI: rcar: Fix a potential NULL pointer dereference power: supply: max14656: fix potential use-before-alloc platform/x86: intel_pmc_ipc: adding error handling PCI: rpadlpar: Fix leaked device_node references in add/remove paths ARM: dts: imx6qdl: Specify IMX6QDL_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx6ul: Specify IMX6UL_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx7d: Specify IMX7D_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ahb" clock to SDMA ARM: dts: imx53: Specify IMX5_CLK_IPG as "ahb" clock to SDMA ARM: dts: imx50: Specify IMX5_CLK_IPG as "ahb" clock to SDMA ARM: dts: imx51: Specify IMX5_CLK_IPG as "ahb" clock to SDMA soc: rockchip: Set the proper PWM for rk3288 clk: rockchip: Turn on "aclk_dmac1" for suspend on rk3288 soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher PCI: keystone: Prevent ARM32 specific code to be compiled for ARM64 platform/chrome: cros_ec_proto: check for NULL transfer function x86/PCI: Fix PCI IRQ routing table memory leak vfio: Fix WARNING "do not call blocking ops when !TASK_RUNNING" nfsd: allow fh_want_write to be called twice fuse: retrieve: cap requested size to negotiated max_write nvmem: core: fix read buffer in place ALSA: hda - Register irq handler after the chip initialization nvme-pci: unquiesce admin queue on shutdown misc: pci_endpoint_test: Fix test_reg_bar to be updated in pci_endpoint_test iommu/vt-d: Set intel_iommu_gfx_mapped correctly blk-mq: move cancel of requeue_work into blk_mq_release watchdog: fix compile time error of pretimeout governors watchdog: imx2_wdt: Fix set_timeout for big timeout values mmc: mmci: Prevent polling for busy detection in IRQ context uml: fix a boot splat wrt use of cpu_all_mask configfs: fix possible use-after-free in configfs_register_group percpu: remove spurious lock dependency between percpu and sched f2fs: fix to do sanity check on valid block count of segment f2fs: fix to avoid panic in dec_valid_block_count() f2fs: fix to clear dirty inode in error path of f2fs_iget() f2fs: fix to avoid panic in do_recover_data() ntp: Allow TAI-UTC offset to be set to zero pwm: meson: Use the spin-lock only to protect register modifications EDAC/mpc85xx: Prevent building as a module objtool: Don't use ignore flag for fake jumps drm/bridge: adv7511: Fix low refresh rate selection perf/x86/intel: Allow PEBS multi-entry in watermark mode mfd: twl6040: Fix device init errors for ACCCTL register drm/nouveau/disp/dp: respect sink limits when selecting failsafe link configuration mfd: intel-lpss: Set the device in reset state when init mfd: tps65912-spi: Add missing of table registration drivers: thermal: tsens: Don't print error message on -EPROBE_DEFER thermal: rcar_gen3_thermal: disable interrupt in .remove kernel/sys.c: prctl: fix false positive in validate_prctl_map() mm/slab.c: fix an infinite loop in leaks_show() mm/cma_debug.c: fix the break condition in cma_maxchunk_get() mm/cma.c: fix the bitmap status to show failed allocation reason mm/cma.c: fix crash on CMA allocation if bitmap allocation fails mem-hotplug: fix node spanned pages when we have a node with only ZONE_MOVABLE hugetlbfs: on restore reserve error path retain subpool reservation mm/hmm: select mmu notifier when selecting HMM ARM: prevent tracing IPI_CPU_BACKTRACE ipc: prevent lockup on alloc_msg and free_msg sysctl: return -EINVAL if val violates minmax fs/fat/file.c: issue flush after the writeback of FAT rapidio: fix a NULL pointer dereference when create_workqueue() fails BACKPORT: kheaders: Do not regenerate archive if config is not changed BACKPORT: kheaders: Move from proc to sysfs BACKPORT: Provide in-kernel headers to make extending kernel easier UPSTREAM: binder: check for overflow when alloc for security context Conflicts: arch/arm/kernel/smp.c Change-Id: I93aaeb09806bd05b4bb216aa12d7ba8007fbc3e9 Signed-off-by: Blagovest Kolenichev <bkolenichev@codeaurora.org>
475 lines
10 KiB
C
475 lines
10 KiB
C
/*
|
|
* A simple sysfs interface for the generic PWM framework
|
|
*
|
|
* Copyright (C) 2013 H Hartley Sweeten <hsweeten@visionengravers.com>
|
|
*
|
|
* Based on previous work by Lars Poeschel <poeschel@lemonage.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/err.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/kdev_t.h>
|
|
#include <linux/pwm.h>
|
|
|
|
struct pwm_export {
|
|
struct device child;
|
|
struct pwm_device *pwm;
|
|
struct mutex lock;
|
|
};
|
|
|
|
static struct pwm_export *child_to_pwm_export(struct device *child)
|
|
{
|
|
return container_of(child, struct pwm_export, child);
|
|
}
|
|
|
|
static struct pwm_device *child_to_pwm_device(struct device *child)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
|
|
return export->pwm;
|
|
}
|
|
|
|
static ssize_t period_show(struct device *child,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
const struct pwm_device *pwm = child_to_pwm_device(child);
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return sprintf(buf, "%llu\n", state.period);
|
|
}
|
|
|
|
static ssize_t period_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
struct pwm_device *pwm = export->pwm;
|
|
struct pwm_state state;
|
|
unsigned int val;
|
|
int ret;
|
|
|
|
ret = kstrtouint(buf, 0, &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mutex_lock(&export->lock);
|
|
pwm_get_state(pwm, &state);
|
|
state.period = val;
|
|
ret = pwm_apply_state(pwm, &state);
|
|
mutex_unlock(&export->lock);
|
|
|
|
return ret ? : size;
|
|
}
|
|
|
|
static ssize_t duty_cycle_show(struct device *child,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
const struct pwm_device *pwm = child_to_pwm_device(child);
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return sprintf(buf, "%llu\n", state.duty_cycle);
|
|
}
|
|
|
|
static ssize_t duty_cycle_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
struct pwm_device *pwm = export->pwm;
|
|
struct pwm_state state;
|
|
unsigned int val;
|
|
int ret;
|
|
|
|
ret = kstrtouint(buf, 0, &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mutex_lock(&export->lock);
|
|
pwm_get_state(pwm, &state);
|
|
state.duty_cycle = val;
|
|
ret = pwm_apply_state(pwm, &state);
|
|
mutex_unlock(&export->lock);
|
|
|
|
return ret ? : size;
|
|
}
|
|
|
|
static ssize_t enable_show(struct device *child,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
const struct pwm_device *pwm = child_to_pwm_device(child);
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return sprintf(buf, "%d\n", state.enabled);
|
|
}
|
|
|
|
static ssize_t enable_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
struct pwm_device *pwm = export->pwm;
|
|
struct pwm_state state;
|
|
int val, ret;
|
|
|
|
ret = kstrtoint(buf, 0, &val);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mutex_lock(&export->lock);
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
switch (val) {
|
|
case 0:
|
|
state.enabled = false;
|
|
break;
|
|
case 1:
|
|
state.enabled = true;
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
goto unlock;
|
|
}
|
|
|
|
ret = pwm_apply_state(pwm, &state);
|
|
|
|
unlock:
|
|
mutex_unlock(&export->lock);
|
|
return ret ? : size;
|
|
}
|
|
|
|
static ssize_t polarity_show(struct device *child,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
const struct pwm_device *pwm = child_to_pwm_device(child);
|
|
const char *polarity = "unknown";
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
switch (state.polarity) {
|
|
case PWM_POLARITY_NORMAL:
|
|
polarity = "normal";
|
|
break;
|
|
|
|
case PWM_POLARITY_INVERSED:
|
|
polarity = "inversed";
|
|
break;
|
|
}
|
|
|
|
return sprintf(buf, "%s\n", polarity);
|
|
}
|
|
|
|
static ssize_t polarity_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
struct pwm_device *pwm = export->pwm;
|
|
enum pwm_polarity polarity;
|
|
struct pwm_state state;
|
|
int ret;
|
|
|
|
if (sysfs_streq(buf, "normal"))
|
|
polarity = PWM_POLARITY_NORMAL;
|
|
else if (sysfs_streq(buf, "inversed"))
|
|
polarity = PWM_POLARITY_INVERSED;
|
|
else
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&export->lock);
|
|
pwm_get_state(pwm, &state);
|
|
state.polarity = polarity;
|
|
ret = pwm_apply_state(pwm, &state);
|
|
mutex_unlock(&export->lock);
|
|
|
|
return ret ? : size;
|
|
}
|
|
|
|
static ssize_t capture_show(struct device *child,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct pwm_device *pwm = child_to_pwm_device(child);
|
|
struct pwm_capture result;
|
|
int ret;
|
|
|
|
ret = pwm_capture(pwm, &result, jiffies_to_msecs(HZ));
|
|
if (ret)
|
|
return ret;
|
|
|
|
return sprintf(buf, "%llu %llu\n", result.period, result.duty_cycle);
|
|
}
|
|
|
|
static ssize_t output_type_show(struct device *child,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
const struct pwm_device *pwm = child_to_pwm_device(child);
|
|
const char *output_type = "unknown";
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
switch (state.output_type) {
|
|
case PWM_OUTPUT_FIXED:
|
|
output_type = "fixed";
|
|
break;
|
|
case PWM_OUTPUT_MODULATED:
|
|
output_type = "modulated";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", output_type);
|
|
}
|
|
|
|
static ssize_t output_type_store(struct device *child,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t size)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
struct pwm_device *pwm = export->pwm;
|
|
struct pwm_state state;
|
|
int ret = -EINVAL;
|
|
|
|
mutex_lock(&export->lock);
|
|
pwm_get_state(pwm, &state);
|
|
if (sysfs_streq(buf, "fixed"))
|
|
state.output_type = PWM_OUTPUT_FIXED;
|
|
else if (sysfs_streq(buf, "modulated"))
|
|
state.output_type = PWM_OUTPUT_MODULATED;
|
|
else
|
|
goto unlock;
|
|
|
|
ret = pwm_apply_state(pwm, &state);
|
|
unlock:
|
|
mutex_unlock(&export->lock);
|
|
|
|
return ret ? : size;
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(period);
|
|
static DEVICE_ATTR_RW(duty_cycle);
|
|
static DEVICE_ATTR_RW(enable);
|
|
static DEVICE_ATTR_RW(polarity);
|
|
static DEVICE_ATTR_RO(capture);
|
|
static DEVICE_ATTR_RW(output_type);
|
|
|
|
static struct attribute *pwm_attrs[] = {
|
|
&dev_attr_period.attr,
|
|
&dev_attr_duty_cycle.attr,
|
|
&dev_attr_enable.attr,
|
|
&dev_attr_polarity.attr,
|
|
&dev_attr_capture.attr,
|
|
&dev_attr_output_type.attr,
|
|
NULL
|
|
};
|
|
ATTRIBUTE_GROUPS(pwm);
|
|
|
|
static void pwm_export_release(struct device *child)
|
|
{
|
|
struct pwm_export *export = child_to_pwm_export(child);
|
|
|
|
kfree(export);
|
|
}
|
|
|
|
static int pwm_export_child(struct device *parent, struct pwm_device *pwm)
|
|
{
|
|
struct pwm_export *export;
|
|
int ret;
|
|
|
|
if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags))
|
|
return -EBUSY;
|
|
|
|
export = kzalloc(sizeof(*export), GFP_KERNEL);
|
|
if (!export) {
|
|
clear_bit(PWMF_EXPORTED, &pwm->flags);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
export->pwm = pwm;
|
|
mutex_init(&export->lock);
|
|
|
|
export->child.release = pwm_export_release;
|
|
export->child.parent = parent;
|
|
export->child.devt = MKDEV(0, 0);
|
|
export->child.groups = pwm_groups;
|
|
dev_set_name(&export->child, "pwm%u", pwm->hwpwm);
|
|
|
|
ret = device_register(&export->child);
|
|
if (ret) {
|
|
clear_bit(PWMF_EXPORTED, &pwm->flags);
|
|
kfree(export);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pwm_unexport_match(struct device *child, void *data)
|
|
{
|
|
return child_to_pwm_device(child) == data;
|
|
}
|
|
|
|
static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm)
|
|
{
|
|
struct device *child;
|
|
|
|
if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags))
|
|
return -ENODEV;
|
|
|
|
child = device_find_child(parent, pwm, pwm_unexport_match);
|
|
if (!child)
|
|
return -ENODEV;
|
|
|
|
/* for device_find_child() */
|
|
put_device(child);
|
|
device_unregister(child);
|
|
pwm_put(pwm);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t export_store(struct device *parent,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t len)
|
|
{
|
|
struct pwm_chip *chip = dev_get_drvdata(parent);
|
|
struct pwm_device *pwm;
|
|
unsigned int hwpwm;
|
|
int ret;
|
|
|
|
ret = kstrtouint(buf, 0, &hwpwm);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
if (hwpwm >= chip->npwm)
|
|
return -ENODEV;
|
|
|
|
pwm = pwm_request_from_chip(chip, hwpwm, "sysfs");
|
|
if (IS_ERR(pwm))
|
|
return PTR_ERR(pwm);
|
|
|
|
ret = pwm_export_child(parent, pwm);
|
|
if (ret < 0)
|
|
pwm_put(pwm);
|
|
|
|
return ret ? : len;
|
|
}
|
|
static DEVICE_ATTR_WO(export);
|
|
|
|
static ssize_t unexport_store(struct device *parent,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t len)
|
|
{
|
|
struct pwm_chip *chip = dev_get_drvdata(parent);
|
|
unsigned int hwpwm;
|
|
int ret;
|
|
|
|
ret = kstrtouint(buf, 0, &hwpwm);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
if (hwpwm >= chip->npwm)
|
|
return -ENODEV;
|
|
|
|
ret = pwm_unexport_child(parent, &chip->pwms[hwpwm]);
|
|
|
|
return ret ? : len;
|
|
}
|
|
static DEVICE_ATTR_WO(unexport);
|
|
|
|
static ssize_t npwm_show(struct device *parent, struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
const struct pwm_chip *chip = dev_get_drvdata(parent);
|
|
|
|
return sprintf(buf, "%u\n", chip->npwm);
|
|
}
|
|
static DEVICE_ATTR_RO(npwm);
|
|
|
|
static struct attribute *pwm_chip_attrs[] = {
|
|
&dev_attr_export.attr,
|
|
&dev_attr_unexport.attr,
|
|
&dev_attr_npwm.attr,
|
|
NULL,
|
|
};
|
|
ATTRIBUTE_GROUPS(pwm_chip);
|
|
|
|
static struct class pwm_class = {
|
|
.name = "pwm",
|
|
.owner = THIS_MODULE,
|
|
.dev_groups = pwm_chip_groups,
|
|
};
|
|
|
|
static int pwmchip_sysfs_match(struct device *parent, const void *data)
|
|
{
|
|
return dev_get_drvdata(parent) == data;
|
|
}
|
|
|
|
void pwmchip_sysfs_export(struct pwm_chip *chip)
|
|
{
|
|
struct device *parent;
|
|
|
|
/*
|
|
* If device_create() fails the pwm_chip is still usable by
|
|
* the kernel its just not exported.
|
|
*/
|
|
parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip,
|
|
"pwmchip%d", chip->base);
|
|
if (IS_ERR(parent)) {
|
|
dev_warn(chip->dev,
|
|
"device_create failed for pwm_chip sysfs export\n");
|
|
}
|
|
}
|
|
|
|
void pwmchip_sysfs_unexport(struct pwm_chip *chip)
|
|
{
|
|
struct device *parent;
|
|
unsigned int i;
|
|
|
|
parent = class_find_device(&pwm_class, NULL, chip,
|
|
pwmchip_sysfs_match);
|
|
if (!parent)
|
|
return;
|
|
|
|
for (i = 0; i < chip->npwm; i++) {
|
|
struct pwm_device *pwm = &chip->pwms[i];
|
|
|
|
if (test_bit(PWMF_EXPORTED, &pwm->flags))
|
|
pwm_unexport_child(parent, pwm);
|
|
}
|
|
|
|
put_device(parent);
|
|
device_unregister(parent);
|
|
}
|
|
|
|
static int __init pwm_sysfs_init(void)
|
|
{
|
|
return class_register(&pwm_class);
|
|
}
|
|
subsys_initcall(pwm_sysfs_init);
|