Skip to content

Commit 3f0925b

Browse files
Lee Jonesthierryreding
authored andcommitted
pwm: sti: Initialise PWM capture device data
Each PWM capture device is allocated a structure to hold its own state. During a capture the device may be partaking in one of 3 phases. Initial (rising) phase change, a subsequent (falling) phase change indicating end of the duty-cycle phase and finally a final (rising) phase change indicating the end of the period. The timer value snapshot each event is held in a variable of the same name, and the phase number (0, 1, 2) is contained in the index variable. Other device specific information, such as GPIO pin, the IRQ wait queue and locking is also contained in the structure. This patch initialises this structure for each of the available devices. Signed-off-by: Lee Jones <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent d66a928 commit 3f0925b

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

drivers/pwm/pwm-sti.c

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
*/
1212

1313
#include <linux/clk.h>
14+
#include <linux/interrupt.h>
1415
#include <linux/math64.h>
1516
#include <linux/mfd/syscon.h>
1617
#include <linux/module.h>
1718
#include <linux/of.h>
1819
#include <linux/platform_device.h>
1920
#include <linux/pwm.h>
2021
#include <linux/regmap.h>
22+
#include <linux/sched.h>
2123
#include <linux/slab.h>
2224
#include <linux/time.h>
25+
#include <linux/wait.h>
2326

2427
#define PWM_OUT_VAL(x) (0x00 + (4 * (x))) /* Device's Duty Cycle register */
2528
#define PWM_CPT_VAL(x) (0x10 + (4 * (x))) /* Capture value */
@@ -64,9 +67,17 @@ enum sti_cpt_edge {
6467
CPT_EDGE_BOTH,
6568
};
6669

70+
struct sti_cpt_ddata {
71+
u32 snapshot[3];
72+
unsigned int index;
73+
struct mutex lock;
74+
wait_queue_head_t wait;
75+
};
76+
6777
struct sti_pwm_compat_data {
6878
const struct reg_field *reg_fields;
69-
unsigned int num_devs;
79+
unsigned int pwm_num_devs;
80+
unsigned int cpt_num_devs;
7081
unsigned int max_pwm_cnt;
7182
unsigned int max_prescale;
7283
};
@@ -307,10 +318,15 @@ static int sti_pwm_probe_dt(struct sti_pwm_chip *pc)
307318
struct device_node *np = dev->of_node;
308319
struct sti_pwm_compat_data *cdata = pc->cdata;
309320
u32 num_devs;
321+
int ret;
310322

311-
of_property_read_u32(np, "st,pwm-num-chan", &num_devs);
312-
if (num_devs)
313-
cdata->num_devs = num_devs;
323+
ret = of_property_read_u32(np, "st,pwm-num-chan", &num_devs);
324+
if (!ret)
325+
cdata->pwm_num_devs = num_devs;
326+
327+
ret = of_property_read_u32(np, "st,capture-num-chan", &num_devs);
328+
if (!ret)
329+
cdata->cpt_num_devs = num_devs;
314330

315331
reg_fields = cdata->reg_fields;
316332

@@ -350,6 +366,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
350366
struct sti_pwm_compat_data *cdata;
351367
struct sti_pwm_chip *pc;
352368
struct resource *res;
369+
unsigned int i;
353370
int ret;
354371

355372
pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL);
@@ -378,7 +395,8 @@ static int sti_pwm_probe(struct platform_device *pdev)
378395
cdata->reg_fields = &sti_pwm_regfields[0];
379396
cdata->max_prescale = 0xff;
380397
cdata->max_pwm_cnt = 255;
381-
cdata->num_devs = 1;
398+
cdata->pwm_num_devs = 1;
399+
cdata->cpt_num_devs = 0;
382400

383401
pc->cdata = cdata;
384402
pc->dev = dev;
@@ -416,7 +434,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
416434
pc->chip.dev = dev;
417435
pc->chip.ops = &sti_pwm_ops;
418436
pc->chip.base = -1;
419-
pc->chip.npwm = pc->cdata->num_devs;
437+
pc->chip.npwm = pc->cdata->pwm_num_devs;
420438
pc->chip.can_sleep = true;
421439

422440
ret = pwmchip_add(&pc->chip);
@@ -426,6 +444,19 @@ static int sti_pwm_probe(struct platform_device *pdev)
426444
return ret;
427445
}
428446

447+
for (i = 0; i < cdata->cpt_num_devs; i++) {
448+
struct sti_cpt_ddata *ddata;
449+
450+
ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
451+
if (!ddata)
452+
return -ENOMEM;
453+
454+
init_waitqueue_head(&ddata->wait);
455+
mutex_init(&ddata->lock);
456+
457+
pwm_set_chip_data(&pc->chip.pwms[i], ddata);
458+
}
459+
429460
platform_set_drvdata(pdev, pc);
430461

431462
return 0;
@@ -436,7 +467,7 @@ static int sti_pwm_remove(struct platform_device *pdev)
436467
struct sti_pwm_chip *pc = platform_get_drvdata(pdev);
437468
unsigned int i;
438469

439-
for (i = 0; i < pc->cdata->num_devs; i++)
470+
for (i = 0; i < pc->cdata->pwm_num_devs; i++)
440471
pwm_disable(&pc->chip.pwms[i]);
441472

442473
clk_unprepare(pc->pwm_clk);

0 commit comments

Comments
 (0)