linux-ti335x-psp 3.1: enable support for beaglebone cape EEPROM based detection
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.1 / 0032-am335x-add-support-for-7-LCD-cape-fix-DVI-entries.patch
1 From cdd84fe3886d332e9e706940af2516559da92349 Mon Sep 17 00:00:00 2001
2 From: Koen Kooi <koen@dominion.thruhere.net>
3 Date: Thu, 5 Jan 2012 12:03:20 +0100
4 Subject: [PATCH 32/35] am335x: add support for 7" LCD cape, fix DVI entries
6 Using the EEPROMs!
8 Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
9 ---
10  arch/arm/mach-omap2/board-am335xevm.c |  216 ++++++++++++++++++++++++++++++---
11  arch/arm/mach-omap2/mux33xx.c         |    2 +-
12  2 files changed, 199 insertions(+), 19 deletions(-)
14 diff --git a/arch/arm/mach-omap2/board-am335xevm.c b/arch/arm/mach-omap2/board-am335xevm.c
15 index 116089f..6c19334 100644
16 --- a/arch/arm/mach-omap2/board-am335xevm.c
17 +++ b/arch/arm/mach-omap2/board-am335xevm.c
18 @@ -146,6 +146,36 @@ struct da8xx_lcdc_platform_data TFC_S9700RTWV35TR_01B_pdata = {
19         .type                   = "TFC_S9700RTWV35TR_01B",
20  };
21  
22 +static const struct display_panel bbtoys7_panel = {
23 +       WVGA,
24 +       16,
25 +       16,
26 +       COLOR_ACTIVE,
27 +};
28 +
29 +static struct lcd_ctrl_config bbtoys7_cfg = {
30 +       &bbtoys7_panel,
31 +       .ac_bias                = 255,
32 +       .ac_bias_intrpt         = 0,
33 +       .dma_burst_sz           = 16,
34 +       .bpp                    = 16,
35 +       .fdd                    = 0x80,
36 +       .tft_alt_mode           = 0,
37 +       .stn_565_mode           = 0,
38 +       .mono_8bit_mode         = 0,
39 +       .invert_line_clock      = 1,
40 +       .invert_frm_clock       = 1,
41 +       .sync_edge              = 0,
42 +       .sync_ctrl              = 1,
43 +       .raster_order           = 0,
44 +};
45 +
46 +struct da8xx_lcdc_platform_data bbtoys7_pdata = {
47 +       .manu_name              = "ThreeFive",
48 +       .controller_data        = &bbtoys7_cfg,
49 +       .type                   = "TFC_S9700RTWV35TR_01B",
50 +};
51 +
52  static const struct display_panel dvi_panel = {
53         WVGA,
54         16,
55 @@ -345,9 +375,34 @@ struct am335x_evm_eeprom_config {
56  static struct am335x_evm_eeprom_config config;
57  static bool daughter_brd_detected;
58  
59 +struct beaglebone_cape_eeprom_config {
60 +       u32     header;
61 +       char  format_revision[2];
62 +       char    name[32];
63 +       char    version[4];
64 +       char    manufacturer[16];
65 +       char    partnumber[16];
66 +       u16  numpins;
67 +       char    serial[12];
68 +       u8      muxdata[170];
69 +       u16  current_3v3;
70 +       u16  current_vdd5v;
71 +       u16  current_sys5v;
72 +       u16  dc;
73 +};
74 +
75 +static struct beaglebone_cape_eeprom_config cape_config;
76 +static bool beaglebone_cape_detected;
77 +
78 +/* keep track of ADC pin usage */
79 +static int capecount = 0;
80 +static bool beaglebone_tsadcpins_free = 1;
81 +
82 +
83  #define GP_EVM_REV_IS_1_0A             0x1
84  #define GP_EVM_REV_IS_1_1A             0x2
85  #define GP_EVM_REV_IS_UNKNOWN          0xFF
86 +#define GP_EVM_ACTUALLY_BEAGLEBONE  0xBB
87  static unsigned int gp_evm_revision = GP_EVM_REV_IS_UNKNOWN;
88  
89  #define EEPROM_MAC_ADDRESS_OFFSET      60 /* 4+8+4+12+32 */
90 @@ -422,7 +477,7 @@ static struct pinmux_config lcdc_pin_mux[] = {
91         {NULL, 0},
92  };
93  
94 -/* Module pin mux for DVI board */
95 +/* Module pin mux for Beagleboardtoys DVI cape */
96  static struct pinmux_config dvi_pin_mux[] = {
97         {"lcd_data0.lcd_data0",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
98          | AM33XX_PULL_DISA},
99 @@ -459,13 +514,56 @@ static struct pinmux_config dvi_pin_mux[] = {
100         {"lcd_vsync.lcd_vsync",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
101         {"lcd_hsync.lcd_hsync",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
102         {"lcd_pclk.lcd_pclk",           OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
103 -       {"lcd_ac_bias_en.lcd_ac_bias_en", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT}, //DVIEN
104 +       {"lcd_ac_bias_en.lcd_ac_bias_en", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
105         {"gpmc_a2.rgmii2_td3", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // USR0 LED
106         {"gpmc_a3.rgmii2_td2", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // USR1 LED
107         {"gpmc_ad7.gpmc_ad7", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // DVI PDn
108         {NULL, 0},
109  };
110  
111 +/* Module pin mux for Beagleboardtoys 7" LCD cape */
112 +static struct pinmux_config bbtoys7_pin_mux[] = {
113 +       {"lcd_data0.lcd_data0",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
114 +               | AM33XX_PULL_DISA},
115 +       {"lcd_data1.lcd_data1",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
116 +               | AM33XX_PULL_DISA},
117 +       {"lcd_data2.lcd_data2",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
118 +               | AM33XX_PULL_DISA},
119 +       {"lcd_data3.lcd_data3",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
120 +               | AM33XX_PULL_DISA},
121 +       {"lcd_data4.lcd_data4",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
122 +               | AM33XX_PULL_DISA},
123 +       {"lcd_data5.lcd_data5",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
124 +               | AM33XX_PULL_DISA},
125 +       {"lcd_data6.lcd_data6",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
126 +               | AM33XX_PULL_DISA},
127 +       {"lcd_data7.lcd_data7",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
128 +               | AM33XX_PULL_DISA},
129 +       {"lcd_data8.lcd_data8",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
130 +               | AM33XX_PULL_DISA},
131 +       {"lcd_data9.lcd_data9",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
132 +               | AM33XX_PULL_DISA},
133 +       {"lcd_data10.lcd_data10",       OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
134 +               | AM33XX_PULL_DISA},
135 +       {"lcd_data11.lcd_data11",       OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
136 +               | AM33XX_PULL_DISA},
137 +       {"lcd_data12.lcd_data12",       OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
138 +               | AM33XX_PULL_DISA},
139 +       {"lcd_data13.lcd_data13",       OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
140 +               | AM33XX_PULL_DISA},
141 +       {"lcd_data14.lcd_data14",       OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
142 +               | AM33XX_PULL_DISA},
143 +       {"lcd_data15.lcd_data15",       OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT
144 +               | AM33XX_PULL_DISA},
145 +       {"lcd_vsync.lcd_vsync",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
146 +       {"lcd_hsync.lcd_hsync",         OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
147 +       {"lcd_pclk.lcd_pclk",           OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
148 +       {"lcd_ac_bias_en.lcd_ac_bias_en", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT}, 
149 +       {"gpmc_a2.gpio1_18", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // Backlight
150 +       {"ecap0_in_pwm0_out.gpio0_7", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // AVDD_EN
151 +       {NULL, 0},
152 +};
154  static struct pinmux_config tsc_pin_mux[] = {
155         {"ain0.ain0",           OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
156         {"ain1.ain1",           OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
157 @@ -771,16 +869,6 @@ static struct gpio_led gpio_leds[] = {
158                 .name           = "beaglebone::usr3",
159                 .gpio           = BEAGLEBONE_USR4_LED,
160         },
161 -       {
162 -               .name                   = "dvi::usr0",
163 -               .default_trigger        = "heartbeat",
164 -               .gpio                   = BEAGLEBONEDVI_USR0_LED,
165 -       },
166 -       {
167 -               .name           = "dvi::usr1",
168 -               .default_trigger        = "mmc0",
169 -               .gpio           = BEAGLEBONEDVI_USR1_LED,
170 -       },
171  };
172  
173  static struct gpio_led_platform_data gpio_led_info = {
174 @@ -905,6 +993,31 @@ static void lcdc_init(int evm_id, int profile)
175         return;
176  }
177  
178 +#define BEAGLEBONE_LCD_AVDD_EN GPIO_TO_PIN(0, 7)
179 +#define BEAGLEBONE_LCD_BL GPIO_TO_PIN(1, 18)
181 +static void bbtoys7lcd_init(int evm_id, int profile)
182 +{
183 +       setup_pin_mux(bbtoys7_pin_mux);
185 +       // we are being stupid and setting pixclock from here instead of da8xx-fb.c
186 +       if (conf_disp_pll(300000000)) {
187 +               pr_info("Failed to set pixclock to 300000000, not attempting to"
188 +                               "register LCD cape\n");
189 +               return;
190 +       }
191 +       
192 +       if (am33xx_register_lcdc(&bbtoys7_pdata))
193 +               pr_info("Failed to register Beagleboardtoys 7\" LCD cape device\n");
194 +       
195 +       gpio_request(BEAGLEBONE_LCD_BL, "BONE_LCD_BL");
196 +       gpio_direction_output(BEAGLEBONE_LCD_BL, 1);
197 +       gpio_request(BEAGLEBONE_LCD_AVDD_EN, "BONE_LCD_AVDD_EN");
198 +       gpio_direction_output(BEAGLEBONE_LCD_AVDD_EN, 1);
200 +       return;
201 +}
203  #define BEAGLEBONEDVI_PDn  GPIO_TO_PIN(1, 7)
204  
205  static void dvi_init(int evm_id, int profile)
206 @@ -921,7 +1034,7 @@ static void dvi_init(int evm_id, int profile)
207         }
208         
209         if (am33xx_register_lcdc(&dvi_pdata))
210 -               pr_info("Failed to register BeagleBoardToys DVI adapter\n");
211 +               pr_info("Failed to register BeagleBoardToys DVI cape\n");
212         return;
213  }
214  
215 @@ -932,10 +1045,15 @@ static void tsc_init(int evm_id, int profile)
216         if (gp_evm_revision == GP_EVM_REV_IS_1_1A) {
217                 am335x_touchscreen_data.analog_input = 1;
218                 pr_info("TSC connected to beta GP EVM\n");
219 -       } else {
220 +       }
221 +       if (gp_evm_revision == GP_EVM_REV_IS_1_1A) {
222                 am335x_touchscreen_data.analog_input = 0;
223                 pr_info("TSC connected to alpha GP EVM\n");
224         }
225 +       if( gp_evm_revision == GP_EVM_ACTUALLY_BEAGLEBONE) {
226 +               am335x_touchscreen_data.analog_input = 1;
227 +               pr_info("TSC connected to BeagleBone\n");;      
228 +       }
229         setup_pin_mux(tsc_pin_mux);
230         err = platform_device_register(&tsc_device);
231         if (err)
232 @@ -1148,11 +1266,76 @@ static struct i2c_board_info beaglebone_i2c_boardinfo2[] = {
233         },
234  };
235  
236 +static void beaglebone_cape_setup(struct memory_accessor *mem_acc, void *context)
237 +{
238 +       capecount++;
239 +       int ret;
240 +       char tmp[32];
241 +       char name[32];
242 +       char manufacturer[32];
244 +       /* get cape specific data */
245 +       ret = mem_acc->read(mem_acc, (char *)&cape_config, 0, sizeof(cape_config));
246 +       if (ret != sizeof(cape_config)) {
247 +               pr_warning("BeagleBone cape EEPROM: could not read eeprom at address 0x%x\n", capecount + 0x53);
248 +               if ((capecount > 3) && (beaglebone_tsadcpins_free == 1)) {
249 +                       pr_info("BeagleBone cape: exporting ADC pins to sysfs\n");
250 +                       bone_tsc_init(0,0);
251 +                       beaglebone_tsadcpins_free = 0;
252 +               }
253 +               return;
254 +       }
256 +       if (cape_config.header != AM335X_EEPROM_HEADER) {
257 +               pr_warning("BeagleBone Cape EEPROM: wrong header 0x%x, expected 0x%x\n",
258 +                       cape_config.header, AM335X_EEPROM_HEADER);
259 +               goto out;
260 +       }
262 +       pr_info("BeagleBone cape EEPROM: found eeprom at address 0x%x\n", capecount + 0x53);
263 +       snprintf(name, sizeof(cape_config.name) + 1, "%s", cape_config.name);
264 +       snprintf(manufacturer, sizeof(cape_config.manufacturer) + 1, "%s", cape_config.manufacturer);
265 +       pr_info("BeagleBone cape: %s %s\n", manufacturer, name);
266 +       snprintf(tmp, sizeof(cape_config.partnumber) + 1, "%s", cape_config.partnumber);
267 +       pr_info("BeagleBone cape partnumber: %s\n", tmp);   
269 +       if (!strncmp("DVI01", cape_config.partnumber, 5)) {
270 +                       pr_info("BeagleBone cape: initializing DVI cape\n");
271 +                       dvi_init(0,0);
272 +       }
273 +       if (!strncmp("LCD01", cape_config.partnumber, 5)) {
274 +               pr_info("BeagleBone cape: initializing LCD cape\n");
275 +               bbtoys7lcd_init(0,0);
276 +               pr_info("BeagleBone cape: initializing LCD cape touchscreen\n");
277 +               tsc_init(0,0);
278 +               beaglebone_tsadcpins_free = 0;
279 +       }
280 +       
281 +       
282 +       if ((capecount > 3) && (beaglebone_tsadcpins_free == 1)) {
283 +               pr_info("BeagleBone cape: exporting ADC pins to sysfs\n");
284 +               bone_tsc_init(0,0);
285 +               beaglebone_tsadcpins_free = 0;
286 +       }
287 +       
288 +       return;
289 +out:
290 +       /*
291 +        * If the EEPROM hasn't been programed or an incorrect header
292 +        * or board name are read, assume this is an old beaglebone board
293 +        * (< Rev A3)
294 +        */
295 +       pr_err("Could not detect BeagleBone cape properly\n");
296 +       beaglebone_cape_detected = false;
298 +}
300  static struct at24_platform_data cape_eeprom_info = {
301          .byte_len       = (256*1024) / 8,
302          .page_size      = 64,
303          .flags          = AT24_FLAG_ADDR16,
304          .context        = (void *)NULL,
305 +               .setup            = beaglebone_cape_setup,
306  };
307  
308  static struct i2c_board_info __initdata cape_i2c_boardinfo[] = {
309 @@ -1587,26 +1770,22 @@ static struct evm_dev_cfg ip_phn_evm_dev_cfg[] = {
310  /* Beaglebone < Rev A3 */
311  static struct evm_dev_cfg beaglebone_old_dev_cfg[] = {
312         {rmii1_init,    DEV_ON_BASEBOARD, PROFILE_NONE},
313 -       {dvi_init,      DEV_ON_BASEBOARD, PROFILE_ALL},
314         {usb0_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
315         {usb1_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
316         {i2c2_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
317         {mmc0_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
318         {boneleds_init, DEV_ON_BASEBOARD, PROFILE_ALL},
319 -       {bone_tsc_init,         DEV_ON_BASEBOARD, PROFILE_ALL},
320         {NULL, 0, 0},
321  };
322  
323  /* Beaglebone Rev A3 and after */
324  static struct evm_dev_cfg beaglebone_dev_cfg[] = {
325         {mii1_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
326 -       {dvi_init,      DEV_ON_BASEBOARD, PROFILE_ALL},
327         {usb0_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
328         {usb1_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
329         {i2c2_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
330         {mmc0_init,     DEV_ON_BASEBOARD, PROFILE_NONE},
331         {boneleds_init, DEV_ON_BASEBOARD, PROFILE_ALL},
332 -       {bone_tsc_init,         DEV_ON_BASEBOARD, PROFILE_ALL},
333         {NULL, 0, 0},
334  };
335  
336 @@ -1689,6 +1868,7 @@ static void setup_beaglebone_old(void)
337  static void setup_beaglebone(void)
338  {
339         pr_info("The board is a AM335x Beaglebone.\n");
340 +       gp_evm_revision = GP_EVM_ACTUALLY_BEAGLEBONE;
341  
342         /* Beagle Bone has Micro-SD slot which doesn't have Write Protect pin */
343         am335x_mmc[0].gpio_wp = -EINVAL;
344 diff --git a/arch/arm/mach-omap2/mux33xx.c b/arch/arm/mach-omap2/mux33xx.c
345 index 35986ca..da08e2e 100644
346 --- a/arch/arm/mach-omap2/mux33xx.c
347 +++ b/arch/arm/mach-omap2/mux33xx.c
348 @@ -85,7 +85,7 @@ static struct omap_mux __initdata am33xx_muxmodes[] = {
349                 NULL, NULL, NULL, NULL),
350         _AM33XX_MUXENTRY(GPMC_A2, 0,
351                 "gpmc_a2", "mii2_txd3", "rgmii2_td3", "mmc2_dat1",
352 -               NULL, NULL, NULL, NULL),
353 +               NULL, NULL, NULL, "gpio1_18"),
354         _AM33XX_MUXENTRY(GPMC_A3, 0,
355                 "gpmc_a3", "mii2_txd2", "rgmii2_td2", "mmc2_dat2",
356                 NULL, NULL, NULL, NULL),
357 -- 
358 1.7.2.5