summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/fiiom3k
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-06-05 00:12:01 +0100
committerAidan MacDonald <amachronic@protonmail.com>2021-06-06 11:06:14 +0000
commite85bc74b307365e9a7b4adab51d646638db12fbd (patch)
treec45ba9079344b5cc0ea48a77b6aa77aacd71cdc5 /firmware/target/mips/ingenic_x1000/fiiom3k
parent695d1701cdd1bb4539f652c2204f7787097b2715 (diff)
downloadrockbox-e85bc74b307365e9a7b4adab51d646638db12fbd.tar.gz
rockbox-e85bc74b307365e9a7b4adab51d646638db12fbd.zip
x1000: GPIO refactor
The GPIO API was pretty clunky and pin settings were decentralized, making it hard to see what was happening and making GPIO stuff look like a mess, frankly. Instead of passing clunky (port, pin) pairs everywhere, GPIOs are now identified with a single int. The extra overhead should be minimal as GPIO configuration is generally not on a performance-critical path. Pin assignments are now mostly consolidated in gpio-target.h and put in various tables so gpio_init() can assign most pins at boot time. Most drivers no longer need to touch GPIOs and basic pin I/O stuff can happen without config since pins are put into the right state. IRQ pins still need to be configured manually before use. Change-Id: Ic5326284b0b2a2f613e9e76a41cb50e24af3aa47
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k')
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c2
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c16
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/gpio-target.h26
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c25
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c4
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c2
6 files changed, 50 insertions, 25 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
index 542d1745dc..8528b803f7 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
@@ -87,5 +87,5 @@ void audiohw_set_power_mode(int mode)
87 87
88void ak4376_set_pdn_pin(int level) 88void ak4376_set_pdn_pin(int level)
89{ 89{
90 gpio_config(GPIO_A, 1 << 16, GPIO_OUTPUT(level ? 1 : 0)); 90 gpio_set_level(GPIO_AK4376_POWER, level ? 1 : 0);
91} 91}
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
index efc652c84f..47b5e3d6dc 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
@@ -35,8 +35,6 @@
35# include "font.h" 35# include "font.h"
36#endif 36#endif
37 37
38#define FT_RST_PIN (1 << 15)
39#define FT_INT_PIN (1 << 12)
40#define ft_interrupt GPIOB12 38#define ft_interrupt GPIOB12
41 39
42/* Touch event types */ 40/* Touch event types */
@@ -389,11 +387,13 @@ static void ft_init(void)
389 i2c_x1000_set_freq(FT6x06_BUS, I2C_FREQ_400K); 387 i2c_x1000_set_freq(FT6x06_BUS, I2C_FREQ_400K);
390 388
391 /* Reset chip */ 389 /* Reset chip */
392 gpio_config(GPIO_B, FT_RST_PIN|FT_INT_PIN, GPIO_OUTPUT(0)); 390 gpio_set_level(GPIO_FT6x06_RESET, 0);
393 mdelay(5); 391 mdelay(5);
394 gpio_out_level(GPIO_B, FT_RST_PIN, 1); 392 gpio_set_level(GPIO_FT6x06_RESET, 1);
395 gpio_config(GPIO_B, FT_INT_PIN, GPIO_IRQ_EDGE(0)); 393
396 gpio_enable_irq(GPIO_B, FT_INT_PIN); 394 /* Configure the interrupt pin */
395 gpio_set_function(GPIO_FT6x06_INTERRUPT, GPIOF_IRQ_EDGE(0));
396 gpio_enable_irq(GPIO_FT6x06_INTERRUPT);
397} 397}
398 398
399void touchpad_set_sensitivity(int level) 399void touchpad_set_sensitivity(int level)
@@ -454,10 +454,6 @@ static void hp_detect_init(void)
454/* Rockbox interface */ 454/* Rockbox interface */
455void button_init_device(void) 455void button_init_device(void)
456{ 456{
457 /* Configure physical button GPIOs */
458 gpio_config(GPIO_A, (1 << 17) | (1 << 19), GPIO_INPUT);
459 gpio_config(GPIO_B, (1 << 28) | (1 << 31), GPIO_INPUT);
460
461 /* Initialize touchpad */ 457 /* Initialize touchpad */
462 ft_init(); 458 ft_init();
463 459
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/gpio-target.h b/firmware/target/mips/ingenic_x1000/fiiom3k/gpio-target.h
new file mode 100644
index 0000000000..f580cd9167
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/gpio-target.h
@@ -0,0 +1,26 @@
1/* Name Port Pins Function */
2DEFINE_PINGROUP(LCD_DATA, GPIO_A, 0xffff << 0, GPIOF_DEVICE(1))
3DEFINE_PINGROUP(LCD_CONTROL, GPIO_B, 0x1a << 16, GPIOF_DEVICE(1))
4DEFINE_PINGROUP(MSC0, GPIO_A, 0x3f << 20, GPIOF_DEVICE(1))
5DEFINE_PINGROUP(SFC, GPIO_A, 0x3f << 26, GPIOF_DEVICE(1))
6DEFINE_PINGROUP(I2S, GPIO_B, 0x1f << 0, GPIOF_DEVICE(1))
7DEFINE_PINGROUP(DMIC, GPIO_B, 3 << 21, GPIOF_DEVICE(0))
8DEFINE_PINGROUP(I2C0, GPIO_B, 3 << 23, GPIOF_DEVICE(0))
9DEFINE_PINGROUP(I2C1, GPIO_C, 3 << 26, GPIOF_DEVICE(0))
10DEFINE_PINGROUP(I2C2, GPIO_D, 3 << 0, GPIOF_DEVICE(1))
11
12/* Name Pin Function */
13DEFINE_GPIO(AK4376_POWER, GPIO_PA(16), GPIOF_OUTPUT(0))
14DEFINE_GPIO(BTN_PLAY, GPIO_PA(17), GPIOF_INPUT)
15DEFINE_GPIO(BTN_VOL_UP, GPIO_PA(19), GPIOF_INPUT)
16DEFINE_GPIO(MSC0_CD, GPIO_PB(6), GPIOF_INPUT)
17DEFINE_GPIO(USB_ID, GPIO_PB(7), GPIOF_INPUT)
18DEFINE_GPIO(AXP_IRQ, GPIO_PB(10), GPIOF_INPUT)
19DEFINE_GPIO(USB_DETECT, GPIO_PB(11), GPIOF_INPUT)
20DEFINE_GPIO(FT6x06_INTERRUPT, GPIO_PB(12), GPIOF_INPUT)
21DEFINE_GPIO(FT6x06_RESET, GPIO_PB(15), GPIOF_OUTPUT(0))
22DEFINE_GPIO(LCD_RD, GPIO_PB(16), GPIOF_OUTPUT(1))
23DEFINE_GPIO(LCD_CE, GPIO_PB(18), GPIOF_OUTPUT(1))
24DEFINE_GPIO(USB_DRVVBUS, GPIO_PB(25), GPIOF_OUTPUT(0))
25DEFINE_GPIO(BTN_VOL_DOWN, GPIO_PB(28), GPIOF_INPUT)
26DEFINE_GPIO(BTN_POWER, GPIO_PB(31), GPIOF_INPUT)
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c
index 96f794d7df..29e72286ff 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c
@@ -25,9 +25,6 @@
25#include "gpio-x1000.h" 25#include "gpio-x1000.h"
26#include "system.h" 26#include "system.h"
27 27
28#define CS_PIN (1 << 18)
29#define RD_PIN (1 << 16)
30
31static const uint32_t fiio_lcd_cmd_enable[] = { 28static const uint32_t fiio_lcd_cmd_enable[] = {
32 /* Software reset */ 29 /* Software reset */
33 LCD_INSTR_CMD, 0x01, 30 LCD_INSTR_CMD, 0x01,
@@ -169,17 +166,27 @@ const struct lcd_tgt_config lcd_tgt_config = {
169void lcd_tgt_enable(bool enable) 166void lcd_tgt_enable(bool enable)
170{ 167{
171 if(enable) { 168 if(enable) {
172 gpio_config(GPIO_A, 0xffff, GPIO_DEVICE(1)); 169 /* reset controller, probably */
173 gpio_config(GPIO_B, 0x1f << 16, GPIO_DEVICE(1)); 170 gpio_set_level(GPIO_LCD_CE, 1);
174 gpio_config(GPIO_B, CS_PIN|RD_PIN, GPIO_OUTPUT(1)); 171 gpio_set_level(GPIO_LCD_RD, 1);
175 mdelay(5); 172 mdelay(5);
176 gpio_out_level(GPIO_B, CS_PIN, 0); 173 gpio_set_level(GPIO_LCD_CE, 0);
174
175 /* set the clock whatever it is... */
177 lcd_set_clock(X1000_CLK_SCLK_A, 30000000); 176 lcd_set_clock(X1000_CLK_SCLK_A, 30000000);
177
178 /* program the initial configuration */
178 lcd_exec_commands(&fiio_lcd_cmd_enable[0]); 179 lcd_exec_commands(&fiio_lcd_cmd_enable[0]);
179 } else { 180 } else {
181 /* go to sleep mode first */
180 lcd_exec_commands(&fiio_lcd_cmd_sleep[0]); 182 lcd_exec_commands(&fiio_lcd_cmd_sleep[0]);
181 mdelay(115); /* ensure we wait a total of 120ms before power off */ 183
182 gpio_config(GPIO_B, CS_PIN|RD_PIN, 0); 184 /* ensure we wait a total of 120ms before power off */
185 mdelay(115);
186
187 /* this is intended to power off the panel but I'm not sure it does */
188 gpio_set_level(GPIO_LCD_CE, 0);
189 gpio_set_level(GPIO_LCD_RD, 0);
183 } 190 }
184} 191}
185 192
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
index a7f6165980..6b1ad2dbb5 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
@@ -28,7 +28,6 @@
28#endif 28#endif
29#include "axp-pmu.h" 29#include "axp-pmu.h"
30#include "i2c-x1000.h" 30#include "i2c-x1000.h"
31#include "gpio-x1000.h"
32 31
33const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = 32const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
34{ 33{
@@ -53,9 +52,6 @@ const unsigned short percent_to_volt_charge[11] =
53 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 52 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
54}; 53};
55 54
56#define AXP_IRQ_PORT GPIO_B
57#define AXP_IRQ_PIN (1 << 10)
58
59void power_init(void) 55void power_init(void)
60{ 56{
61 /* Initialize driver */ 57 /* Initialize driver */
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c
index efea5aa323..85ce4da8f6 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c
@@ -116,7 +116,7 @@ int spl_get_boot_option(void)
116 const int max_iter_count = 30; 116 const int max_iter_count = 30;
117 117
118 /* Configure the button GPIOs as inputs */ 118 /* Configure the button GPIOs as inputs */
119 gpio_config(GPIO_A, pinmask, GPIO_INPUT); 119 gpioz_configure(GPIO_A, pinmask, GPIOF_INPUT);
120 120
121 /* Poll the pins for a short duration to detect a keypress */ 121 /* Poll the pins for a short duration to detect a keypress */
122 do { 122 do {