Lines Matching +full:ast2400 +full:- +full:adc

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Aspeed AST2400/2500 ADC
9 #include <linux/clk-provider.h>
96 of_device_get_match_data(data->dev); in aspeed_adc_read_raw()
100 *val = readw(data->base + chan->address); in aspeed_adc_read_raw()
104 *val = model_data->vref_voltage; in aspeed_adc_read_raw()
109 *val = clk_get_rate(data->clk_scaler->clk) / in aspeed_adc_read_raw()
114 return -EINVAL; in aspeed_adc_read_raw()
124 of_device_get_match_data(data->dev); in aspeed_adc_write_raw()
128 if (val < model_data->min_sampling_rate || in aspeed_adc_write_raw()
129 val > model_data->max_sampling_rate) in aspeed_adc_write_raw()
130 return -EINVAL; in aspeed_adc_write_raw()
132 clk_set_rate(data->clk_scaler->clk, in aspeed_adc_write_raw()
144 return -EPERM; in aspeed_adc_write_raw()
147 return -EINVAL; in aspeed_adc_write_raw()
158 return -EINVAL; in aspeed_adc_reg_access()
160 *readval = readl(data->base + reg); in aspeed_adc_reg_access()
180 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*data)); in aspeed_adc_probe()
182 return -ENOMEM; in aspeed_adc_probe()
185 data->dev = &pdev->dev; in aspeed_adc_probe()
188 data->base = devm_platform_ioremap_resource(pdev, 0); in aspeed_adc_probe()
189 if (IS_ERR(data->base)) in aspeed_adc_probe()
190 return PTR_ERR(data->base); in aspeed_adc_probe()
192 /* Register ADC clock prescaler with source specified by device tree. */ in aspeed_adc_probe()
193 spin_lock_init(&data->clk_lock); in aspeed_adc_probe()
194 clk_parent_name = of_clk_get_parent_name(pdev->dev.of_node, 0); in aspeed_adc_probe()
196 data->clk_prescaler = clk_hw_register_divider( in aspeed_adc_probe()
197 &pdev->dev, "prescaler", clk_parent_name, 0, in aspeed_adc_probe()
198 data->base + ASPEED_REG_CLOCK_CONTROL, in aspeed_adc_probe()
199 17, 15, 0, &data->clk_lock); in aspeed_adc_probe()
200 if (IS_ERR(data->clk_prescaler)) in aspeed_adc_probe()
201 return PTR_ERR(data->clk_prescaler); in aspeed_adc_probe()
204 * Register ADC clock scaler downstream from the prescaler. Allow rate in aspeed_adc_probe()
207 data->clk_scaler = clk_hw_register_divider( in aspeed_adc_probe()
208 &pdev->dev, "scaler", "prescaler", in aspeed_adc_probe()
210 data->base + ASPEED_REG_CLOCK_CONTROL, in aspeed_adc_probe()
211 0, 10, 0, &data->clk_lock); in aspeed_adc_probe()
212 if (IS_ERR(data->clk_scaler)) { in aspeed_adc_probe()
213 ret = PTR_ERR(data->clk_scaler); in aspeed_adc_probe()
217 data->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); in aspeed_adc_probe()
218 if (IS_ERR(data->rst)) { in aspeed_adc_probe()
219 dev_err(&pdev->dev, in aspeed_adc_probe()
221 ret = PTR_ERR(data->rst); in aspeed_adc_probe()
224 reset_control_deassert(data->rst); in aspeed_adc_probe()
226 model_data = of_device_get_match_data(&pdev->dev); in aspeed_adc_probe()
228 if (model_data->wait_init_sequence) { in aspeed_adc_probe()
231 data->base + ASPEED_REG_ENGINE_CONTROL); in aspeed_adc_probe()
234 ret = readl_poll_timeout(data->base + ASPEED_REG_ENGINE_CONTROL, in aspeed_adc_probe()
245 ret = clk_prepare_enable(data->clk_scaler->clk); in aspeed_adc_probe()
252 data->base + ASPEED_REG_ENGINE_CONTROL); in aspeed_adc_probe()
254 model_data = of_device_get_match_data(&pdev->dev); in aspeed_adc_probe()
255 indio_dev->name = model_data->model_name; in aspeed_adc_probe()
256 indio_dev->info = &aspeed_adc_iio_info; in aspeed_adc_probe()
257 indio_dev->modes = INDIO_DIRECT_MODE; in aspeed_adc_probe()
258 indio_dev->channels = aspeed_adc_iio_channels; in aspeed_adc_probe()
259 indio_dev->num_channels = ARRAY_SIZE(aspeed_adc_iio_channels); in aspeed_adc_probe()
269 data->base + ASPEED_REG_ENGINE_CONTROL); in aspeed_adc_probe()
270 clk_disable_unprepare(data->clk_scaler->clk); in aspeed_adc_probe()
273 reset_control_assert(data->rst); in aspeed_adc_probe()
275 clk_hw_unregister_divider(data->clk_scaler); in aspeed_adc_probe()
277 clk_hw_unregister_divider(data->clk_prescaler); in aspeed_adc_probe()
288 data->base + ASPEED_REG_ENGINE_CONTROL); in aspeed_adc_remove()
289 clk_disable_unprepare(data->clk_scaler->clk); in aspeed_adc_remove()
290 reset_control_assert(data->rst); in aspeed_adc_remove()
291 clk_hw_unregister_divider(data->clk_scaler); in aspeed_adc_remove()
292 clk_hw_unregister_divider(data->clk_prescaler); in aspeed_adc_remove()
298 .model_name = "ast2400-adc",
305 .model_name = "ast2500-adc",
313 { .compatible = "aspeed,ast2400-adc", .data = &ast2400_model_data },
314 { .compatible = "aspeed,ast2500-adc", .data = &ast2500_model_data },
331 MODULE_DESCRIPTION("Aspeed AST2400/2500 ADC Driver");