2016-03-16 02:47:55 +08:00
|
|
|
/* pinmux_dev_qmsi.c - QMSI pinmux dev driver */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-03-16 02:47:55 +08:00
|
|
|
*/
|
2016-05-03 07:24:53 +08:00
|
|
|
|
|
|
|
#include <errno.h>
|
2016-03-16 02:47:55 +08:00
|
|
|
#include <pinmux.h>
|
|
|
|
|
|
|
|
#include "qm_pinmux.h"
|
|
|
|
|
2016-05-03 07:24:53 +08:00
|
|
|
#define MASK_2_BITS 0x3
|
|
|
|
|
2016-03-16 02:47:55 +08:00
|
|
|
static int pinmux_dev_set(struct device *dev, uint32_t pin,
|
2016-05-03 07:24:53 +08:00
|
|
|
uint32_t func)
|
2016-03-16 02:47:55 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
return qm_pmux_select(pin, func) == 0 ? 0 : -EIO;
|
2016-03-16 02:47:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pinmux_dev_get(struct device *dev, uint32_t pin,
|
2016-05-03 07:24:53 +08:00
|
|
|
uint32_t *func)
|
2016-03-16 02:47:55 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2016-05-03 07:24:53 +08:00
|
|
|
/*
|
|
|
|
* pinmux control registers are 32-bit wide, but each pin requires
|
|
|
|
* 2 bits to set the mode (A, B, C, or D). As such we only get 16
|
|
|
|
* pins per register.
|
|
|
|
*/
|
|
|
|
uint32_t reg_offset = pin >> 4;
|
|
|
|
|
|
|
|
/* The pin offset within the register */
|
|
|
|
uint32_t pin_no = pin % 16;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now figure out what is the full address for the register
|
|
|
|
* we are looking for.
|
|
|
|
*/
|
|
|
|
volatile uint32_t *mux_register = &QM_SCSS_PMUX->pmux_sel[reg_offset];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MASK_2_BITS (the value of which is 3) is used because there are
|
|
|
|
* 2 bits for the mode of each pin.
|
|
|
|
*/
|
|
|
|
uint32_t pin_mask = MASK_2_BITS << (pin_no << 1);
|
|
|
|
uint32_t mode_mask = *mux_register & pin_mask;
|
|
|
|
uint32_t mode = mode_mask >> (pin_no << 1);
|
|
|
|
|
|
|
|
*func = mode;
|
|
|
|
|
|
|
|
return 0;
|
2016-03-16 02:47:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pinmux_dev_pullup(struct device *dev, uint32_t pin,
|
2016-05-03 07:24:53 +08:00
|
|
|
uint8_t func)
|
2016-03-16 02:47:55 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
return qm_pmux_pullup_en(pin, func) == 0 ? 0 : -EIO;
|
2016-03-16 02:47:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pinmux_dev_input(struct device *dev, uint32_t pin,
|
2016-05-03 07:24:53 +08:00
|
|
|
uint8_t func)
|
2016-03-16 02:47:55 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2016-05-18 19:09:16 +08:00
|
|
|
return qm_pmux_input_en(pin, func) == 0 ? 0 : -EIO;
|
2016-03-16 02:47:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pinmux_driver_api api_funcs = {
|
|
|
|
.set = pinmux_dev_set,
|
|
|
|
.get = pinmux_dev_get,
|
|
|
|
.pullup = pinmux_dev_pullup,
|
|
|
|
.input = pinmux_dev_input
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pinmux_dev_initialize(struct device *port)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-15 00:28:33 +08:00
|
|
|
DEVICE_AND_API_INIT(pmux_dev, CONFIG_PINMUX_DEV_NAME,
|
2016-05-03 07:24:53 +08:00
|
|
|
&pinmux_dev_initialize, NULL, NULL,
|
2016-11-09 03:06:55 +08:00
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
2016-04-15 00:28:33 +08:00
|
|
|
&api_funcs);
|