1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-pxa/income.c
4  *
5  * Support for Income s.r.o. SH-Dmaster PXA270 SBC
6  *
7  * Copyright (C) 2010
8  * Marek Vasut <marek.vasut@gmail.com>
9  * Pavel Revak <palo@bielyvlk.sk>
10  */
11 
12 #include <linux/bitops.h>
13 #include <linux/delay.h>
14 #include <linux/gpio/machine.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/leds.h>
18 #include <linux/ioport.h>
19 #include <linux/kernel.h>
20 #include <linux/platform_device.h>
21 #include <linux/pwm.h>
22 #include <linux/pwm_backlight.h>
23 #include <linux/platform_data/i2c-pxa.h>
24 
25 #include <asm/irq.h>
26 #include <asm/mach-types.h>
27 
28 #include <linux/platform_data/mmc-pxamci.h>
29 #include <linux/platform_data/usb-ohci-pxa27x.h>
30 #include "pxa27x.h"
31 #include "pxa27x-udc.h"
32 #include <linux/platform_data/video-pxafb.h>
33 
34 #include "devices.h"
35 #include "generic.h"
36 
37 #define GPIO114_INCOME_ETH_IRQ  (114)
38 #define GPIO0_INCOME_SD_DETECT  (0)
39 #define GPIO0_INCOME_SD_RO      (1)
40 #define GPIO54_INCOME_LED_A     (54)
41 #define GPIO55_INCOME_LED_B     (55)
42 #define GPIO113_INCOME_TS_IRQ   (113)
43 
44 /******************************************************************************
45  * SD/MMC card controller
46  ******************************************************************************/
47 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
48 static struct pxamci_platform_data income_mci_platform_data = {
49 	.ocr_mask		= MMC_VDD_32_33 | MMC_VDD_33_34,
50 	.detect_delay_ms	= 200,
51 };
52 
53 static struct gpiod_lookup_table income_mci_gpio_table = {
54 	.dev_id = "pxa2xx-mci.0",
55 	.table = {
56 		/* Card detect on GPIO 0 */
57 		GPIO_LOOKUP("gpio-pxa", GPIO0_INCOME_SD_DETECT,
58 			    "cd", GPIO_ACTIVE_LOW),
59 		/* Write protect on GPIO 1 */
60 		GPIO_LOOKUP("gpio-pxa", GPIO0_INCOME_SD_RO,
61 			    "wp", GPIO_ACTIVE_LOW),
62 		{ },
63 	},
64 };
65 
income_mmc_init(void)66 static void __init income_mmc_init(void)
67 {
68 	gpiod_add_lookup_table(&income_mci_gpio_table);
69 	pxa_set_mci_info(&income_mci_platform_data);
70 }
71 #else
income_mmc_init(void)72 static inline void income_mmc_init(void) {}
73 #endif
74 
75 /******************************************************************************
76  * USB Host
77  ******************************************************************************/
78 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
79 static struct pxaohci_platform_data income_ohci_info = {
80 	.port_mode	= PMM_PERPORT_MODE,
81 	.flags		= ENABLE_PORT1 | POWER_CONTROL_LOW | POWER_SENSE_LOW,
82 };
83 
income_uhc_init(void)84 static void __init income_uhc_init(void)
85 {
86 	pxa_set_ohci_info(&income_ohci_info);
87 }
88 #else
income_uhc_init(void)89 static inline void income_uhc_init(void) {}
90 #endif
91 
92 /******************************************************************************
93  * LED
94  ******************************************************************************/
95 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
96 struct gpio_led income_gpio_leds[] = {
97 	{
98 		.name			= "income:green:leda",
99 		.default_trigger	= "none",
100 		.gpio			= GPIO54_INCOME_LED_A,
101 		.active_low		= 1,
102 	},
103 	{
104 		.name			= "income:green:ledb",
105 		.default_trigger	= "none",
106 		.gpio			= GPIO55_INCOME_LED_B,
107 		.active_low		= 1,
108 	}
109 };
110 
111 static struct gpio_led_platform_data income_gpio_led_info = {
112 	.leds		= income_gpio_leds,
113 	.num_leds	= ARRAY_SIZE(income_gpio_leds),
114 };
115 
116 static struct platform_device income_leds = {
117 	.name	= "leds-gpio",
118 	.id	= -1,
119 	.dev	= {
120 		.platform_data	= &income_gpio_led_info,
121 	}
122 };
123 
income_led_init(void)124 static void __init income_led_init(void)
125 {
126 	platform_device_register(&income_leds);
127 }
128 #else
income_led_init(void)129 static inline void income_led_init(void) {}
130 #endif
131 
132 /******************************************************************************
133  * I2C
134  ******************************************************************************/
135 #if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
136 static struct i2c_board_info __initdata income_i2c_devs[] = {
137 	{
138 		I2C_BOARD_INFO("ds1340", 0x68),
139 	}, {
140 		I2C_BOARD_INFO("lm75", 0x4f),
141 	},
142 };
143 
income_i2c_init(void)144 static void __init income_i2c_init(void)
145 {
146 	pxa_set_i2c_info(NULL);
147 	pxa27x_set_i2c_power_info(NULL);
148 	i2c_register_board_info(0, ARRAY_AND_SIZE(income_i2c_devs));
149 }
150 #else
income_i2c_init(void)151 static inline void income_i2c_init(void) {}
152 #endif
153 
154 /******************************************************************************
155  * Framebuffer
156  ******************************************************************************/
157 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
158 static struct pxafb_mode_info income_lcd_modes[] = {
159 {
160 	.pixclock	= 144700,
161 	.xres		= 320,
162 	.yres		= 240,
163 	.bpp		= 32,
164 	.depth		= 18,
165 
166 	.left_margin	= 10,
167 	.right_margin	= 10,
168 	.upper_margin	= 7,
169 	.lower_margin	= 8,
170 
171 	.hsync_len	= 20,
172 	.vsync_len	= 2,
173 
174 	.sync		= FB_SYNC_VERT_HIGH_ACT,
175 },
176 };
177 
178 static struct pxafb_mach_info income_lcd_screen = {
179 	.modes		= income_lcd_modes,
180 	.num_modes	= ARRAY_SIZE(income_lcd_modes),
181 	.lcd_conn	= LCD_COLOR_TFT_18BPP | LCD_PCLK_EDGE_FALL,
182 };
183 
income_lcd_init(void)184 static void __init income_lcd_init(void)
185 {
186 	pxa_set_fb_info(NULL, &income_lcd_screen);
187 }
188 #else
income_lcd_init(void)189 static inline void income_lcd_init(void) {}
190 #endif
191 
192 /******************************************************************************
193  * Backlight
194  ******************************************************************************/
195 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
196 static struct pwm_lookup income_pwm_lookup[] = {
197 	PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 1000000,
198 		   PWM_POLARITY_NORMAL),
199 };
200 
201 static struct platform_pwm_backlight_data income_backlight_data = {
202 	.max_brightness	= 0x3ff,
203 	.dft_brightness	= 0x1ff,
204 };
205 
206 static struct platform_device income_backlight = {
207 	.name	= "pwm-backlight",
208 	.dev	= {
209 		.parent		= &pxa27x_device_pwm0.dev,
210 		.platform_data	= &income_backlight_data,
211 	},
212 };
213 
income_pwm_init(void)214 static void __init income_pwm_init(void)
215 {
216 	pwm_add_table(income_pwm_lookup, ARRAY_SIZE(income_pwm_lookup));
217 	platform_device_register(&income_backlight);
218 }
219 #else
income_pwm_init(void)220 static inline void income_pwm_init(void) {}
221 #endif
222 
colibri_pxa270_income_boardinit(void)223 void __init colibri_pxa270_income_boardinit(void)
224 {
225 	pxa_set_ffuart_info(NULL);
226 	pxa_set_btuart_info(NULL);
227 	pxa_set_stuart_info(NULL);
228 
229 	income_mmc_init();
230 	income_uhc_init();
231 	income_led_init();
232 	income_i2c_init();
233 	income_lcd_init();
234 	income_pwm_init();
235 }
236 
237