Blame view

drivers/regulator/vexpress-regulator.c 2.63 KB
c5e911add   Axel Lin   regulator: vexpre...
1
2
3
  // SPDX-License-Identifier: GPL-2.0
  //
  // Copyright (C) 2012 ARM Limited
31e54086d   Pawel Moll   regulator: Versat...
4
5
6
7
8
9
10
11
12
13
14
15
  
  #define DRVNAME "vexpress-regulator"
  #define pr_fmt(fmt) DRVNAME ": " fmt
  
  #include <linux/device.h>
  #include <linux/err.h>
  #include <linux/module.h>
  #include <linux/of_device.h>
  #include <linux/regulator/driver.h>
  #include <linux/regulator/machine.h>
  #include <linux/regulator/of_regulator.h>
  #include <linux/vexpress.h>
31e54086d   Pawel Moll   regulator: Versat...
16
17
  static int vexpress_regulator_get_voltage(struct regulator_dev *regdev)
  {
eeb1b2355   Axel Lin   regulator: vexpre...
18
19
  	unsigned int uV;
  	int err = regmap_read(regdev->regmap, 0, &uV);
31e54086d   Pawel Moll   regulator: Versat...
20
21
22
23
24
25
26
  
  	return err ? err : uV;
  }
  
  static int vexpress_regulator_set_voltage(struct regulator_dev *regdev,
  		int min_uV, int max_uV, unsigned *selector)
  {
eeb1b2355   Axel Lin   regulator: vexpre...
27
  	return regmap_write(regdev->regmap, 0, min_uV);
31e54086d   Pawel Moll   regulator: Versat...
28
  }
ab54a4d7b   Axel Lin   regulator: vexpre...
29
  static const struct regulator_ops vexpress_regulator_ops_ro = {
31e54086d   Pawel Moll   regulator: Versat...
30
31
  	.get_voltage = vexpress_regulator_get_voltage,
  };
ab54a4d7b   Axel Lin   regulator: vexpre...
32
  static const struct regulator_ops vexpress_regulator_ops = {
31e54086d   Pawel Moll   regulator: Versat...
33
34
35
36
37
38
  	.get_voltage = vexpress_regulator_get_voltage,
  	.set_voltage = vexpress_regulator_set_voltage,
  };
  
  static int vexpress_regulator_probe(struct platform_device *pdev)
  {
eeb1b2355   Axel Lin   regulator: vexpre...
39
  	struct regulator_desc *desc;
31e54086d   Pawel Moll   regulator: Versat...
40
41
  	struct regulator_init_data *init_data;
  	struct regulator_config config = { };
eeb1b2355   Axel Lin   regulator: vexpre...
42
43
  	struct regulator_dev *rdev;
  	struct regmap *regmap;
31e54086d   Pawel Moll   regulator: Versat...
44

eeb1b2355   Axel Lin   regulator: vexpre...
45
46
  	desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
  	if (!desc)
3b9334ac8   Pawel Moll   mfd: vexpress: Co...
47
  		return -ENOMEM;
31e54086d   Pawel Moll   regulator: Versat...
48

eeb1b2355   Axel Lin   regulator: vexpre...
49
50
51
  	regmap = devm_regmap_init_vexpress_config(&pdev->dev);
  	if (IS_ERR(regmap))
  		return PTR_ERR(regmap);
31e54086d   Pawel Moll   regulator: Versat...
52

eeb1b2355   Axel Lin   regulator: vexpre...
53
54
55
56
  	desc->name = dev_name(&pdev->dev);
  	desc->type = REGULATOR_VOLTAGE;
  	desc->owner = THIS_MODULE;
  	desc->continuous_voltage_range = true;
31e54086d   Pawel Moll   regulator: Versat...
57

072e78b12   Javier Martinez Canillas   regulator: of: Ad...
58
  	init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
eeb1b2355   Axel Lin   regulator: vexpre...
59
  					       desc);
3b9334ac8   Pawel Moll   mfd: vexpress: Co...
60
61
  	if (!init_data)
  		return -EINVAL;
31e54086d   Pawel Moll   regulator: Versat...
62
63
64
  
  	init_data->constraints.apply_uV = 0;
  	if (init_data->constraints.min_uV && init_data->constraints.max_uV)
eeb1b2355   Axel Lin   regulator: vexpre...
65
  		desc->ops = &vexpress_regulator_ops;
31e54086d   Pawel Moll   regulator: Versat...
66
  	else
eeb1b2355   Axel Lin   regulator: vexpre...
67
  		desc->ops = &vexpress_regulator_ops_ro;
31e54086d   Pawel Moll   regulator: Versat...
68

eeb1b2355   Axel Lin   regulator: vexpre...
69
  	config.regmap = regmap;
31e54086d   Pawel Moll   regulator: Versat...
70
71
  	config.dev = &pdev->dev;
  	config.init_data = init_data;
31e54086d   Pawel Moll   regulator: Versat...
72
  	config.of_node = pdev->dev.of_node;
eeb1b2355   Axel Lin   regulator: vexpre...
73
  	rdev = devm_regulator_register(&pdev->dev, desc, &config);
1d7c4c115   zhengbin   regulator: vexpre...
74
  	return PTR_ERR_OR_ZERO(rdev);
31e54086d   Pawel Moll   regulator: Versat...
75
  }
1439afd8d   Jingoo Han   regulator: vexpre...
76
  static const struct of_device_id vexpress_regulator_of_match[] = {
31e54086d   Pawel Moll   regulator: Versat...
77
  	{ .compatible = "arm,vexpress-volt", },
9f4e45f77   Axel Lin   regulator: vexpre...
78
  	{ }
31e54086d   Pawel Moll   regulator: Versat...
79
  };
7209fee89   Luis de Bethencourt   regulator: vexpre...
80
  MODULE_DEVICE_TABLE(of, vexpress_regulator_of_match);
31e54086d   Pawel Moll   regulator: Versat...
81
82
83
  
  static struct platform_driver vexpress_regulator_driver = {
  	.probe = vexpress_regulator_probe,
31e54086d   Pawel Moll   regulator: Versat...
84
85
  	.driver	= {
  		.name = DRVNAME,
31e54086d   Pawel Moll   regulator: Versat...
86
87
88
89
90
91
92
93
94
95
  		.of_match_table = vexpress_regulator_of_match,
  	},
  };
  
  module_platform_driver(vexpress_regulator_driver);
  
  MODULE_AUTHOR("Pawel Moll <pawel.moll@arm.com>");
  MODULE_DESCRIPTION("Versatile Express regulator");
  MODULE_LICENSE("GPL");
  MODULE_ALIAS("platform:vexpress-regulator");