Lines Matching +full:iio +full:- +full:consumer
1 // SPDX-License-Identifier: GPL-2.0+
3 * Renesas R-Car GyroADC driver
17 #include <linux/regulator/consumer.h>
22 #include <linux/iio/iio.h>
23 #include <linux/iio/sysfs.h>
24 #include <linux/iio/trigger.h>
26 #define DRIVER_NAME "rcar-gyroadc"
77 const unsigned long clk_mhz = clk_get_rate(priv->clk) / 1000000; in rcar_gyroadc_hw_init()
79 (priv->mode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) ? 10 : 5; in rcar_gyroadc_hw_init()
83 * According to the R-Car Gen2 datasheet Rev. 1.01, Sept 08 2014, in rcar_gyroadc_hw_init()
84 * page 77-7, clock length must be even number. If it's odd number, in rcar_gyroadc_hw_init()
91 writel(0, priv->regs + RCAR_GYROADC_START_STOP); in rcar_gyroadc_hw_init()
94 if (priv->model == RCAR_GYROADC_MODEL_R8A7792) in rcar_gyroadc_hw_init()
95 writel(0, priv->regs + RCAR_GYROADC_INTENR); in rcar_gyroadc_hw_init()
98 writel(priv->mode, priv->regs + RCAR_GYROADC_MODE_SELECT); in rcar_gyroadc_hw_init()
99 writel(clk_len, priv->regs + RCAR_GYROADC_CLOCK_LENGTH); in rcar_gyroadc_hw_init()
100 writel(clk_mhz * 1250, priv->regs + RCAR_GYROADC_1_25MS_LENGTH); in rcar_gyroadc_hw_init()
107 priv->regs + RCAR_GYROADC_START_STOP); in rcar_gyroadc_hw_start()
121 writel(0, priv->regs + RCAR_GYROADC_START_STOP); in rcar_gyroadc_hw_stop()
164 struct device *dev = priv->dev; in rcar_gyroadc_set_power()
179 struct regulator *consumer; in rcar_gyroadc_read_raw() local
180 unsigned int datareg = RCAR_GYROADC_REALTIME_DATA(chan->channel); in rcar_gyroadc_read_raw()
188 if (priv->mode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) in rcar_gyroadc_read_raw()
189 consumer = priv->vref[0]; in rcar_gyroadc_read_raw()
191 consumer = priv->vref[chan->channel]; in rcar_gyroadc_read_raw()
195 if (chan->type != IIO_VOLTAGE) in rcar_gyroadc_read_raw()
196 return -EINVAL; in rcar_gyroadc_read_raw()
199 if (!consumer) in rcar_gyroadc_read_raw()
200 return -EINVAL; in rcar_gyroadc_read_raw()
212 *val = readl(priv->regs + datareg); in rcar_gyroadc_read_raw()
213 *val &= BIT(priv->sample_width) - 1; in rcar_gyroadc_read_raw()
223 if (!consumer) in rcar_gyroadc_read_raw()
224 return -EINVAL; in rcar_gyroadc_read_raw()
226 vref = regulator_get_voltage(consumer); in rcar_gyroadc_read_raw()
228 *val2 = 1 << priv->sample_width; in rcar_gyroadc_read_raw()
236 return -EINVAL; in rcar_gyroadc_read_raw()
248 return -EINVAL; in rcar_gyroadc_reg_access()
251 return -EINVAL; in rcar_gyroadc_reg_access()
254 if (priv->model == RCAR_GYROADC_MODEL_R8A7792) in rcar_gyroadc_reg_access()
258 return -EINVAL; in rcar_gyroadc_reg_access()
260 *readval = readl(priv->regs + reg); in rcar_gyroadc_reg_access()
272 /* R-Car compatible GyroADC */
273 .compatible = "renesas,rcar-gyroadc",
276 /* R-Car V2H specialty with interrupt registers. */
277 .compatible = "renesas,r8a7792-gyroadc",
319 struct device *dev = priv->dev; in rcar_gyroadc_parse_subdevs()
320 struct device_node *np = dev->of_node; in rcar_gyroadc_parse_subdevs()
323 unsigned int adcmode = -1, childmode; in rcar_gyroadc_parse_subdevs()
336 childmode = (uintptr_t)of_id->data; in rcar_gyroadc_parse_subdevs()
354 return -EINVAL; in rcar_gyroadc_parse_subdevs()
379 return -EINVAL; in rcar_gyroadc_parse_subdevs()
388 return -EINVAL; in rcar_gyroadc_parse_subdevs()
392 dev->of_node = child; in rcar_gyroadc_parse_subdevs()
394 dev->of_node = np; in rcar_gyroadc_parse_subdevs()
401 priv->vref[reg] = vref; in rcar_gyroadc_parse_subdevs()
410 priv->num_channels = num_channels; in rcar_gyroadc_parse_subdevs()
411 priv->mode = childmode; in rcar_gyroadc_parse_subdevs()
412 priv->sample_width = sample_width; in rcar_gyroadc_parse_subdevs()
414 indio_dev->channels = channels; in rcar_gyroadc_parse_subdevs()
415 indio_dev->num_channels = num_channels; in rcar_gyroadc_parse_subdevs()
429 return -EINVAL; in rcar_gyroadc_parse_subdevs()
440 for (i = 0; i < priv->num_channels; i++) { in rcar_gyroadc_deinit_supplies()
441 if (!priv->vref[i]) in rcar_gyroadc_deinit_supplies()
444 regulator_disable(priv->vref[i]); in rcar_gyroadc_deinit_supplies()
451 struct device *dev = priv->dev; in rcar_gyroadc_init_supplies()
455 for (i = 0; i < priv->num_channels; i++) { in rcar_gyroadc_init_supplies()
456 if (!priv->vref[i]) in rcar_gyroadc_init_supplies()
459 ret = regulator_enable(priv->vref[i]); in rcar_gyroadc_init_supplies()
476 struct device *dev = &pdev->dev; in rcar_gyroadc_probe()
483 return -ENOMEM; in rcar_gyroadc_probe()
486 priv->dev = dev; in rcar_gyroadc_probe()
488 priv->regs = devm_platform_ioremap_resource(pdev, 0); in rcar_gyroadc_probe()
489 if (IS_ERR(priv->regs)) in rcar_gyroadc_probe()
490 return PTR_ERR(priv->regs); in rcar_gyroadc_probe()
492 priv->clk = devm_clk_get(dev, "fck"); in rcar_gyroadc_probe()
493 if (IS_ERR(priv->clk)) in rcar_gyroadc_probe()
494 return dev_err_probe(dev, PTR_ERR(priv->clk), in rcar_gyroadc_probe()
505 priv->model = (uintptr_t)of_device_get_match_data(&pdev->dev); in rcar_gyroadc_probe()
509 indio_dev->name = DRIVER_NAME; in rcar_gyroadc_probe()
510 indio_dev->info = &rcar_gyroadc_iio_info; in rcar_gyroadc_probe()
511 indio_dev->modes = INDIO_DIRECT_MODE; in rcar_gyroadc_probe()
513 ret = clk_prepare_enable(priv->clk); in rcar_gyroadc_probe()
532 dev_err(dev, "Couldn't register IIO device.\n"); in rcar_gyroadc_probe()
546 clk_disable_unprepare(priv->clk); in rcar_gyroadc_probe()
557 struct device *dev = priv->dev; in rcar_gyroadc_remove()
565 clk_disable_unprepare(priv->clk); in rcar_gyroadc_remove()
606 MODULE_DESCRIPTION("Renesas R-Car GyroADC driver");