Commit 3aeeb375 authored by Thierry Reding's avatar Thierry Reding

Merge branch 'for-4.11/core' into for-4.11/acpi

parents 0c744ea4 b526a314
...@@ -29,7 +29,6 @@ struct led_pwm_data { ...@@ -29,7 +29,6 @@ struct led_pwm_data {
unsigned int active_low; unsigned int active_low;
unsigned int period; unsigned int period;
int duty; int duty;
bool can_sleep;
}; };
struct led_pwm_priv { struct led_pwm_priv {
...@@ -49,8 +48,8 @@ static void __led_pwm_set(struct led_pwm_data *led_dat) ...@@ -49,8 +48,8 @@ static void __led_pwm_set(struct led_pwm_data *led_dat)
pwm_enable(led_dat->pwm); pwm_enable(led_dat->pwm);
} }
static void led_pwm_set(struct led_classdev *led_cdev, static int led_pwm_set(struct led_classdev *led_cdev,
enum led_brightness brightness) enum led_brightness brightness)
{ {
struct led_pwm_data *led_dat = struct led_pwm_data *led_dat =
container_of(led_cdev, struct led_pwm_data, cdev); container_of(led_cdev, struct led_pwm_data, cdev);
...@@ -66,12 +65,7 @@ static void led_pwm_set(struct led_classdev *led_cdev, ...@@ -66,12 +65,7 @@ static void led_pwm_set(struct led_classdev *led_cdev,
led_dat->duty = duty; led_dat->duty = duty;
__led_pwm_set(led_dat); __led_pwm_set(led_dat);
}
static int led_pwm_set_blocking(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
led_pwm_set(led_cdev, brightness);
return 0; return 0;
} }
...@@ -112,11 +106,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, ...@@ -112,11 +106,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
return ret; return ret;
} }
led_data->can_sleep = pwm_can_sleep(led_data->pwm); led_data->cdev.brightness_set_blocking = led_pwm_set;
if (!led_data->can_sleep)
led_data->cdev.brightness_set = led_pwm_set;
else
led_data->cdev.brightness_set_blocking = led_pwm_set_blocking;
/* /*
* FIXME: pwm_apply_args() should be removed when switching to the * FIXME: pwm_apply_args() should be removed when switching to the
......
...@@ -137,9 +137,14 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) ...@@ -137,9 +137,14 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
{ {
struct pwm_device *pwm; struct pwm_device *pwm;
/* check, whether the driver supports a third cell for flags */
if (pc->of_pwm_n_cells < 3) if (pc->of_pwm_n_cells < 3)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* flags in the third cell are optional */
if (args->args_count < 2)
return ERR_PTR(-EINVAL);
if (args->args[0] >= pc->npwm) if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -148,11 +153,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) ...@@ -148,11 +153,10 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
return pwm; return pwm;
pwm->args.period = args->args[1]; pwm->args.period = args->args[1];
pwm->args.polarity = PWM_POLARITY_NORMAL;
if (args->args[2] & PWM_POLARITY_INVERTED) if (args->args_count > 2 && args->args[2] & PWM_POLARITY_INVERTED)
pwm->args.polarity = PWM_POLARITY_INVERSED; pwm->args.polarity = PWM_POLARITY_INVERSED;
else
pwm->args.polarity = PWM_POLARITY_NORMAL;
return pwm; return pwm;
} }
...@@ -163,9 +167,14 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) ...@@ -163,9 +167,14 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
{ {
struct pwm_device *pwm; struct pwm_device *pwm;
/* sanity check driver support */
if (pc->of_pwm_n_cells < 2) if (pc->of_pwm_n_cells < 2)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
/* all cells are required */
if (args->args_count != pc->of_pwm_n_cells)
return ERR_PTR(-EINVAL);
if (args->args[0] >= pc->npwm) if (args->args[0] >= pc->npwm)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -663,24 +672,17 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id) ...@@ -663,24 +672,17 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id)
err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index, err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
&args); &args);
if (err) { if (err) {
pr_debug("%s(): can't parse \"pwms\" property\n", __func__); pr_err("%s(): can't parse \"pwms\" property\n", __func__);
return ERR_PTR(err); return ERR_PTR(err);
} }
pc = of_node_to_pwmchip(args.np); pc = of_node_to_pwmchip(args.np);
if (IS_ERR(pc)) { if (IS_ERR(pc)) {
pr_debug("%s(): PWM chip not found\n", __func__); pr_err("%s(): PWM chip not found\n", __func__);
pwm = ERR_CAST(pc); pwm = ERR_CAST(pc);
goto put; goto put;
} }
if (args.args_count != pc->of_pwm_n_cells) {
pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
args.np->full_name);
pwm = ERR_PTR(-EINVAL);
goto put;
}
pwm = pc->of_xlate(pc, &args); pwm = pc->of_xlate(pc, &args);
if (IS_ERR(pwm)) if (IS_ERR(pwm))
goto put; goto put;
...@@ -757,12 +759,13 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num) ...@@ -757,12 +759,13 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num)
*/ */
struct pwm_device *pwm_get(struct device *dev, const char *con_id) struct pwm_device *pwm_get(struct device *dev, const char *con_id)
{ {
struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER);
const char *dev_id = dev ? dev_name(dev) : NULL; const char *dev_id = dev ? dev_name(dev) : NULL;
struct pwm_chip *chip = NULL; struct pwm_device *pwm;
struct pwm_chip *chip;
unsigned int best = 0; unsigned int best = 0;
struct pwm_lookup *p, *chosen = NULL; struct pwm_lookup *p, *chosen = NULL;
unsigned int match; unsigned int match;
int err;
/* look up via DT first */ /* look up via DT first */
if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
...@@ -817,24 +820,35 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) ...@@ -817,24 +820,35 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
} }
} }
if (!chosen) { mutex_unlock(&pwm_lookup_lock);
pwm = ERR_PTR(-ENODEV);
goto out; if (!chosen)
} return ERR_PTR(-ENODEV);
chip = pwmchip_find_by_name(chosen->provider); chip = pwmchip_find_by_name(chosen->provider);
/*
* If the lookup entry specifies a module, load the module and retry
* the PWM chip lookup. This can be used to work around driver load
* ordering issues if driver's can't be made to properly support the
* deferred probe mechanism.
*/
if (!chip && chosen->module) {
err = request_module(chosen->module);
if (err == 0)
chip = pwmchip_find_by_name(chosen->provider);
}
if (!chip) if (!chip)
goto out; return ERR_PTR(-EPROBE_DEFER);
pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
if (IS_ERR(pwm)) if (IS_ERR(pwm))
goto out; return pwm;
pwm->args.period = chosen->period; pwm->args.period = chosen->period;
pwm->args.polarity = chosen->polarity; pwm->args.polarity = chosen->polarity;
out:
mutex_unlock(&pwm_lookup_lock);
return pwm; return pwm;
} }
EXPORT_SYMBOL_GPL(pwm_get); EXPORT_SYMBOL_GPL(pwm_get);
...@@ -960,18 +974,6 @@ void devm_pwm_put(struct device *dev, struct pwm_device *pwm) ...@@ -960,18 +974,6 @@ void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
} }
EXPORT_SYMBOL_GPL(devm_pwm_put); EXPORT_SYMBOL_GPL(devm_pwm_put);
/**
* pwm_can_sleep() - report whether PWM access will sleep
* @pwm: PWM device
*
* Returns: True if accessing the PWM can sleep, false otherwise.
*/
bool pwm_can_sleep(struct pwm_device *pwm)
{
return true;
}
EXPORT_SYMBOL_GPL(pwm_can_sleep);
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
{ {
......
...@@ -270,7 +270,6 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev) ...@@ -270,7 +270,6 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
chip->chip.npwm = 1; chip->chip.npwm = 1;
chip->chip.of_xlate = of_pwm_xlate_with_flags; chip->chip.of_xlate = of_pwm_xlate_with_flags;
chip->chip.of_pwm_n_cells = 3; chip->chip.of_pwm_n_cells = 3;
chip->chip.can_sleep = 1;
ret = pwmchip_add_with_polarity(&chip->chip, PWM_POLARITY_INVERSED); ret = pwmchip_add_with_polarity(&chip->chip, PWM_POLARITY_INVERSED);
if (ret) { if (ret) {
......
...@@ -385,7 +385,6 @@ static int atmel_pwm_probe(struct platform_device *pdev) ...@@ -385,7 +385,6 @@ static int atmel_pwm_probe(struct platform_device *pdev)
atmel_pwm->chip.base = -1; atmel_pwm->chip.base = -1;
atmel_pwm->chip.npwm = 4; atmel_pwm->chip.npwm = 4;
atmel_pwm->chip.can_sleep = true;
atmel_pwm->config = data->config; atmel_pwm->config = data->config;
atmel_pwm->updated_pwms = 0; atmel_pwm->updated_pwms = 0;
mutex_init(&atmel_pwm->isr_lock); mutex_init(&atmel_pwm->isr_lock);
......
...@@ -276,7 +276,6 @@ static int kona_pwmc_probe(struct platform_device *pdev) ...@@ -276,7 +276,6 @@ static int kona_pwmc_probe(struct platform_device *pdev)
kp->chip.npwm = 6; kp->chip.npwm = 6;
kp->chip.of_xlate = of_pwm_xlate_with_flags; kp->chip.of_xlate = of_pwm_xlate_with_flags;
kp->chip.of_pwm_n_cells = 3; kp->chip.of_pwm_n_cells = 3;
kp->chip.can_sleep = true;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
kp->base = devm_ioremap_resource(&pdev->dev, res); kp->base = devm_ioremap_resource(&pdev->dev, res);
......
...@@ -206,7 +206,6 @@ static int berlin_pwm_probe(struct platform_device *pdev) ...@@ -206,7 +206,6 @@ static int berlin_pwm_probe(struct platform_device *pdev)
pwm->chip.ops = &berlin_pwm_ops; pwm->chip.ops = &berlin_pwm_ops;
pwm->chip.base = -1; pwm->chip.base = -1;
pwm->chip.npwm = 4; pwm->chip.npwm = 4;
pwm->chip.can_sleep = true;
pwm->chip.of_xlate = of_pwm_xlate_with_flags; pwm->chip.of_xlate = of_pwm_xlate_with_flags;
pwm->chip.of_pwm_n_cells = 3; pwm->chip.of_pwm_n_cells = 3;
......
...@@ -270,7 +270,6 @@ static int brcmstb_pwm_probe(struct platform_device *pdev) ...@@ -270,7 +270,6 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
p->chip.ops = &brcmstb_pwm_ops; p->chip.ops = &brcmstb_pwm_ops;
p->chip.base = -1; p->chip.base = -1;
p->chip.npwm = 2; p->chip.npwm = 2;
p->chip.can_sleep = true;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
p->base = devm_ioremap_resource(&pdev->dev, res); p->base = devm_ioremap_resource(&pdev->dev, res);
......
...@@ -446,7 +446,6 @@ static int fsl_pwm_probe(struct platform_device *pdev) ...@@ -446,7 +446,6 @@ static int fsl_pwm_probe(struct platform_device *pdev)
fpc->chip.of_pwm_n_cells = 3; fpc->chip.of_pwm_n_cells = 3;
fpc->chip.base = -1; fpc->chip.base = -1;
fpc->chip.npwm = 8; fpc->chip.npwm = 8;
fpc->chip.can_sleep = true;
ret = pwmchip_add(&fpc->chip); ret = pwmchip_add(&fpc->chip);
if (ret < 0) { if (ret < 0) {
......
...@@ -304,7 +304,6 @@ static int imx_pwm_probe(struct platform_device *pdev) ...@@ -304,7 +304,6 @@ static int imx_pwm_probe(struct platform_device *pdev)
imx->chip.dev = &pdev->dev; imx->chip.dev = &pdev->dev;
imx->chip.base = -1; imx->chip.base = -1;
imx->chip.npwm = 1; imx->chip.npwm = 1;
imx->chip.can_sleep = true;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
imx->mmio_base = devm_ioremap_resource(&pdev->dev, r); imx->mmio_base = devm_ioremap_resource(&pdev->dev, r);
......
...@@ -278,7 +278,6 @@ static int lp3943_pwm_probe(struct platform_device *pdev) ...@@ -278,7 +278,6 @@ static int lp3943_pwm_probe(struct platform_device *pdev)
lp3943_pwm->chip.dev = &pdev->dev; lp3943_pwm->chip.dev = &pdev->dev;
lp3943_pwm->chip.ops = &lp3943_pwm_ops; lp3943_pwm->chip.ops = &lp3943_pwm_ops;
lp3943_pwm->chip.npwm = LP3943_NUM_PWMS; lp3943_pwm->chip.npwm = LP3943_NUM_PWMS;
lp3943_pwm->chip.can_sleep = true;
platform_set_drvdata(pdev, lp3943_pwm); platform_set_drvdata(pdev, lp3943_pwm);
......
...@@ -151,7 +151,7 @@ static int mxs_pwm_probe(struct platform_device *pdev) ...@@ -151,7 +151,7 @@ static int mxs_pwm_probe(struct platform_device *pdev)
mxs->chip.dev = &pdev->dev; mxs->chip.dev = &pdev->dev;
mxs->chip.ops = &mxs_pwm_ops; mxs->chip.ops = &mxs_pwm_ops;
mxs->chip.base = -1; mxs->chip.base = -1;
mxs->chip.can_sleep = true;
ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm); ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret);
......
...@@ -343,7 +343,6 @@ static int pca9685_pwm_probe(struct i2c_client *client, ...@@ -343,7 +343,6 @@ static int pca9685_pwm_probe(struct i2c_client *client,
pca->chip.dev = &client->dev; pca->chip.dev = &client->dev;
pca->chip.base = -1; pca->chip.base = -1;
pca->chip.can_sleep = true;
return pwmchip_add(&pca->chip); return pwmchip_add(&pca->chip);
} }
......
...@@ -635,7 +635,6 @@ static int sti_pwm_probe(struct platform_device *pdev) ...@@ -635,7 +635,6 @@ static int sti_pwm_probe(struct platform_device *pdev)
pc->chip.ops = &sti_pwm_ops; pc->chip.ops = &sti_pwm_ops;
pc->chip.base = -1; pc->chip.base = -1;
pc->chip.npwm = pc->cdata->pwm_num_devs; pc->chip.npwm = pc->cdata->pwm_num_devs;
pc->chip.can_sleep = true;
ret = pwmchip_add(&pc->chip); ret = pwmchip_add(&pc->chip);
if (ret < 0) { if (ret < 0) {
......
...@@ -340,7 +340,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev) ...@@ -340,7 +340,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.ops = &sun4i_pwm_ops;
pwm->chip.base = -1; pwm->chip.base = -1;
pwm->chip.npwm = pwm->data->npwm; pwm->chip.npwm = pwm->data->npwm;
pwm->chip.can_sleep = true;
pwm->chip.of_xlate = of_pwm_xlate_with_flags; pwm->chip.of_xlate = of_pwm_xlate_with_flags;
pwm->chip.of_pwm_n_cells = 3; pwm->chip.of_pwm_n_cells = 3;
......
...@@ -303,7 +303,6 @@ static int twl_pwmled_probe(struct platform_device *pdev) ...@@ -303,7 +303,6 @@ static int twl_pwmled_probe(struct platform_device *pdev)
twl->chip.dev = &pdev->dev; twl->chip.dev = &pdev->dev;
twl->chip.base = -1; twl->chip.base = -1;
twl->chip.can_sleep = true;
mutex_init(&twl->mutex); mutex_init(&twl->mutex);
......
...@@ -323,7 +323,6 @@ static int twl_pwm_probe(struct platform_device *pdev) ...@@ -323,7 +323,6 @@ static int twl_pwm_probe(struct platform_device *pdev)
twl->chip.dev = &pdev->dev; twl->chip.dev = &pdev->dev;
twl->chip.base = -1; twl->chip.base = -1;
twl->chip.npwm = 2; twl->chip.npwm = 2;
twl->chip.can_sleep = true;
mutex_init(&twl->mutex); mutex_init(&twl->mutex);
......
...@@ -284,7 +284,6 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev, ...@@ -284,7 +284,6 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
pwm->ops = &gb_pwm_ops; pwm->ops = &gb_pwm_ops;
pwm->base = -1; /* Allocate base dynamically */ pwm->base = -1; /* Allocate base dynamically */
pwm->npwm = pwmc->pwm_max + 1; pwm->npwm = pwmc->pwm_max + 1;
pwm->can_sleep = true; /* FIXME */
ret = pwmchip_add(pwm); ret = pwmchip_add(pwm);
if (ret) { if (ret) {
......
...@@ -287,8 +287,6 @@ struct pwm_ops { ...@@ -287,8 +287,6 @@ struct pwm_ops {
* @pwms: array of PWM devices allocated by the framework * @pwms: array of PWM devices allocated by the framework
* @of_xlate: request a PWM device given a device tree PWM specifier * @of_xlate: request a PWM device given a device tree PWM specifier
* @of_pwm_n_cells: number of cells expected in the device tree PWM specifier * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
* @can_sleep: must be true if the .config(), .enable() or .disable()
* operations may sleep
*/ */
struct pwm_chip { struct pwm_chip {
struct device *dev; struct device *dev;
...@@ -302,7 +300,6 @@ struct pwm_chip { ...@@ -302,7 +300,6 @@ struct pwm_chip {
struct pwm_device * (*of_xlate)(struct pwm_chip *pc, struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
const struct of_phandle_args *args); const struct of_phandle_args *args);
unsigned int of_pwm_n_cells; unsigned int of_pwm_n_cells;
bool can_sleep;
}; };
/** /**
...@@ -451,8 +448,6 @@ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id); ...@@ -451,8 +448,6 @@ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np, struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
const char *con_id); const char *con_id);
void devm_pwm_put(struct device *dev, struct pwm_device *pwm); void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
bool pwm_can_sleep(struct pwm_device *pwm);
#else #else
static inline struct pwm_device *pwm_request(int pwm_id, const char *label) static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
{ {
...@@ -566,11 +561,6 @@ static inline struct pwm_device *devm_of_pwm_get(struct device *dev, ...@@ -566,11 +561,6 @@ static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm) static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
{ {
} }
static inline bool pwm_can_sleep(struct pwm_device *pwm)
{
return false;
}
#endif #endif
static inline void pwm_apply_args(struct pwm_device *pwm) static inline void pwm_apply_args(struct pwm_device *pwm)
...@@ -613,18 +603,25 @@ struct pwm_lookup { ...@@ -613,18 +603,25 @@ struct pwm_lookup {
const char *con_id; const char *con_id;
unsigned int period; unsigned int period;
enum pwm_polarity polarity; enum pwm_polarity polarity;
const char *module; /* optional, may be NULL */
}; };
#define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \ #define PWM_LOOKUP_WITH_MODULE(_provider, _index, _dev_id, _con_id, \
{ \ _period, _polarity, _module) \
.provider = _provider, \ { \
.index = _index, \ .provider = _provider, \
.dev_id = _dev_id, \ .index = _index, \
.con_id = _con_id, \ .dev_id = _dev_id, \
.period = _period, \ .con_id = _con_id, \
.polarity = _polarity \ .period = _period, \
.polarity = _polarity, \
.module = _module, \
} }
#define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
PWM_LOOKUP_WITH_MODULE(_provider, _index, _dev_id, _con_id, _period, \
_polarity, NULL)
#if IS_ENABLED(CONFIG_PWM) #if IS_ENABLED(CONFIG_PWM)
void pwm_add_table(struct pwm_lookup *table, size_t num); void pwm_add_table(struct pwm_lookup *table, size_t num);
void pwm_remove_table(struct pwm_lookup *table, size_t num); void pwm_remove_table(struct pwm_lookup *table, size_t num);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment