1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2019 Intel Corporation. All rights reserved.
4 //
5 // Author: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
6 
7 #include <sof/drivers/iomux.h>
8 #include <sof/lib/io.h>
9 #include <errno.h>
10 #include <stddef.h>
11 
12 #define IOMUX_PIN_UNCONFIGURED 0
13 
iomux_configure(struct iomux * iomux,const struct iomux_pin_config * cfg)14 int iomux_configure(struct iomux *iomux, const struct iomux_pin_config *cfg)
15 {
16 	if (iomux->pin_state[cfg->bit] != IOMUX_PIN_UNCONFIGURED)
17 		return -EBUSY;
18 
19 	io_reg_update_bits(iomux->base, cfg->mask << cfg->bit,
20 			   cfg->fn << cfg->bit);
21 
22 	iomux->pin_state[cfg->bit] = cfg->fn + 1;
23 
24 	return 0;
25 }
26 
iomux_get(unsigned int id)27 struct iomux *iomux_get(unsigned int id)
28 {
29 	return id >= n_iomux ? NULL : iomux_data + id;
30 }
31 
iomux_probe(struct iomux * iomux)32 int iomux_probe(struct iomux *iomux)
33 {
34 	unsigned int i;
35 
36 	for (i = 0; i < n_iomux; i++)
37 		if (iomux_data + i == iomux)
38 			return 0;
39 
40 	return -ENODEV;
41 }
42