]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/misc/smsc_sio1007.c
2 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <smsc_sio1007.h>
12 static inline u8
sio1007_read(int port
, int reg
)
19 static inline void sio1007_write(int port
, int reg
, int val
)
25 static inline void sio1007_clrsetbits(int port
, int reg
, u8 clr
, u8 set
)
27 sio1007_write(port
, reg
, (sio1007_read(port
, reg
) & ~clr
) | set
);
30 void sio1007_enable_serial(int port
, int num
, int iobase
, int irq
)
32 if (num
< 0 || num
> SIO1007_UART_NUM
)
35 /* enter configuration state */
38 /* power on serial port and set up its i/o base & irq */
40 sio1007_clrsetbits(port
, DEV_POWER_CTRL
, 0, UART1_POWER_ON
);
41 sio1007_clrsetbits(port
, UART1_IOBASE
, 0xfe, iobase
>> 2);
42 sio1007_clrsetbits(port
, UART_IRQ
, 0xf0, irq
<< 4);
44 sio1007_clrsetbits(port
, DEV_POWER_CTRL
, 0, UART2_POWER_ON
);
45 sio1007_clrsetbits(port
, UART2_IOBASE
, 0xfe, iobase
>> 2);
46 sio1007_clrsetbits(port
, UART_IRQ
, 0x0f, irq
);
49 /* exit configuration state */
53 void sio1007_enable_runtime(int port
, int iobase
)
55 /* enter configuration state */
58 /* set i/o base for the runtime register block */
59 sio1007_clrsetbits(port
, RTR_IOBASE_LOW
, 0, iobase
>> 4);
60 sio1007_clrsetbits(port
, RTR_IOBASE_HIGH
, 0, iobase
>> 12);
61 /* turn on address decoding for this block */
62 sio1007_clrsetbits(port
, DEV_ACTIVATE
, 0, RTR_EN
);
64 /* exit configuration state */
68 void sio1007_gpio_config(int port
, int gpio
, int dir
, int pol
, int type
)
72 if (gpio
< 0 || gpio
> SIO1007_GPIO_NUM
)
74 if (gpio
>= GPIO_NUM_PER_GROUP
) {
76 gpio
-= GPIO_NUM_PER_GROUP
;
79 /* enter configuration state */
82 /* set gpio pin direction, polority and type */
83 sio1007_clrsetbits(port
, reg
, 1 << gpio
, dir
<< gpio
);
84 sio1007_clrsetbits(port
, reg
+ 1, 1 << gpio
, pol
<< gpio
);
85 sio1007_clrsetbits(port
, reg
+ 2, 1 << gpio
, type
<< gpio
);
87 /* exit configuration state */
91 int sio1007_gpio_get_value(int port
, int gpio
)
96 if (gpio
< 0 || gpio
> SIO1007_GPIO_NUM
)
98 if (gpio
>= GPIO_NUM_PER_GROUP
) {
100 gpio
-= GPIO_NUM_PER_GROUP
;
103 val
= inb(port
+ reg
);
104 if (val
& (1 << gpio
))
110 void sio1007_gpio_set_value(int port
, int gpio
, int val
)
112 int reg
= GPIO0_DATA
;
115 if (gpio
< 0 || gpio
> SIO1007_GPIO_NUM
)
117 if (gpio
>= GPIO_NUM_PER_GROUP
) {
119 gpio
-= GPIO_NUM_PER_GROUP
;
122 data
= inb(port
+ reg
);
123 data
&= ~(1 << gpio
);
124 data
|= (val
<< gpio
);
125 outb(data
, port
+ reg
);