^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * am200epd.c -- Platform device for AM200 EPD kit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2008, Jaya Kumar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * License. See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This work was made possible by help and equipment support from E-Ink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Corporation. http://support.eink.com/community
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * This driver is written to be used with the Metronome display controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * on the AM200 EPD prototype kit/development kit with an E-Ink 800x600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Vizplex EPD on a Gumstix board using the Lyre interface board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "pxa25x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "gumstix.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/platform_data/video-pxafb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "generic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <video/metronomefb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static unsigned int panel_type = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct platform_device *am200_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static struct metronome_board am200_board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct pxafb_mode_info am200_fb_mode_9inch7 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .pixclock = 40000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .xres = 1200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .yres = 842,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .bpp = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .hsync_len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .left_margin = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .right_margin = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .vsync_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .upper_margin = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .lower_margin = 25,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static struct pxafb_mode_info am200_fb_mode_8inch = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .pixclock = 40000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .xres = 1088,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .yres = 791,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .bpp = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .hsync_len = 28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .left_margin = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .right_margin = 30,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .vsync_len = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .upper_margin = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .lower_margin = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static struct pxafb_mode_info am200_fb_mode_6inch = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .pixclock = 40189,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .xres = 832,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .yres = 622,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .bpp = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .hsync_len = 28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .left_margin = 34,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .right_margin = 34,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .vsync_len = 25,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .upper_margin = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .lower_margin = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static struct pxafb_mach_info am200_fb_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .modes = &am200_fb_mode_6inch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .num_modes = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .lcd_conn = LCD_TYPE_COLOR_TFT | LCD_PCLK_EDGE_FALL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) LCD_AC_BIAS_FREQ(24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* register offsets for gpio control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define LED_GPIO_PIN 51
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define STDBY_GPIO_PIN 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define RST_GPIO_PIN 49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define RDY_GPIO_PIN 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define ERR_GPIO_PIN 17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define PCBPWR_GPIO_PIN 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int gpios[] = { LED_GPIO_PIN , STDBY_GPIO_PIN , RST_GPIO_PIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) RDY_GPIO_PIN, ERR_GPIO_PIN, PCBPWR_GPIO_PIN };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static char *gpio_names[] = { "LED" , "STDBY" , "RST", "RDY", "ERR", "PCBPWR" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int am200_init_gpio_regs(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (i = 0; i < ARRAY_SIZE(gpios); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) err = gpio_request(gpios[i], gpio_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) dev_err(&am200_device->dev, "failed requesting "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) "gpio %s, err=%d\n", gpio_names[i], err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) goto err_req_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) gpio_direction_output(LED_GPIO_PIN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) gpio_direction_output(STDBY_GPIO_PIN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) gpio_direction_output(RST_GPIO_PIN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) gpio_direction_input(RDY_GPIO_PIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) gpio_direction_input(ERR_GPIO_PIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) gpio_direction_output(PCBPWR_GPIO_PIN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) err_req_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) gpio_free(gpios[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void am200_cleanup(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) free_irq(PXA_GPIO_TO_IRQ(RDY_GPIO_PIN), par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) for (i = 0; i < ARRAY_SIZE(gpios); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) gpio_free(gpios[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int am200_share_video_mem(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* rough check if this is our desired fb and not something else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if ((info->var.xres != am200_fb_info.modes->xres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) || (info->var.yres != am200_fb_info.modes->yres))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* we've now been notified that we have our new fb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) am200_board.metromem = info->screen_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) am200_board.host_fbinfo = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* try to refcount host drv since we are the consumer after this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!try_module_get(info->fbops->owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int am200_unshare_video_mem(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dev_dbg(&am200_device->dev, "ENTER %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (info != am200_board.host_fbinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) module_put(am200_board.host_fbinfo->fbops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int am200_fb_notifier_callback(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct fb_event *evdata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct fb_info *info = evdata->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dev_dbg(&am200_device->dev, "ENTER %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (event == FB_EVENT_FB_REGISTERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return am200_share_video_mem(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) else if (event == FB_EVENT_FB_UNREGISTERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return am200_unshare_video_mem(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static struct notifier_block am200_fb_notif = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .notifier_call = am200_fb_notifier_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* this gets called as part of our init. these steps must be done now so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * that we can use pxa_set_fb_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void __init am200_presetup_fb(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int padding_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int totalsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) switch (panel_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) am200_fb_info.modes = &am200_fb_mode_6inch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) am200_fb_info.modes = &am200_fb_mode_8inch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) case 97:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) am200_fb_info.modes = &am200_fb_mode_9inch7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) dev_err(&am200_device->dev, "invalid panel_type selection,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) " setting to 6\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) am200_fb_info.modes = &am200_fb_mode_6inch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* the frame buffer is divided as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) command | CRC | padding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 16kb waveform data | CRC | padding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) image data | CRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) fw = am200_fb_info.modes->xres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) fh = am200_fb_info.modes->yres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* waveform must be 16k + 2 for checksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) am200_board.wfm_size = roundup(16*1024 + 2, fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) padding_size = PAGE_SIZE + (4 * fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* total is 1 cmd , 1 wfm, padding and image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) totalsize = fw + am200_board.wfm_size + padding_size + (fw*fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* save this off because we're manipulating fw after this and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * we'll need it when we're ready to setup the framebuffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) am200_board.fw = fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) am200_board.fh = fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* the reason we do this adjustment is because we want to acquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * more framebuffer memory without imposing custom awareness on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * underlying pxafb driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) am200_fb_info.modes->yres = DIV_ROUND_UP(totalsize, fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* we divide since we told the LCD controller we're 16bpp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) am200_fb_info.modes->xres /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pxa_set_fb_info(NULL, &am200_fb_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /* this gets called by metronomefb as part of its init, in our case, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * have already completed initial framebuffer init in presetup_fb so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * can just setup the fb access pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int am200_setup_fb(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) fw = am200_board.fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) fh = am200_board.fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* metromem was set up by the notifier in share_video_mem so now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * we can use its value to calculate the other entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) par->metromem_cmd = (struct metromem_cmd *) am200_board.metromem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) par->metromem_wfm = am200_board.metromem + fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) par->metromem_img = par->metromem_wfm + am200_board.wfm_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) par->metromem_img_csum = (u16 *) (par->metromem_img + (fw * fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) par->metromem_dma = am200_board.host_fbinfo->fix.smem_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int am200_get_panel_type(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return panel_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static irqreturn_t am200_handle_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct metronomefb_par *par = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) wake_up_interruptible(&par->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int am200_setup_irq(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) ret = request_irq(PXA_GPIO_TO_IRQ(RDY_GPIO_PIN), am200_handle_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) IRQF_TRIGGER_FALLING, "AM200", info->par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) dev_err(&am200_device->dev, "request_irq failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static void am200_set_rst(struct metronomefb_par *par, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) gpio_set_value(RST_GPIO_PIN, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static void am200_set_stdby(struct metronomefb_par *par, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) gpio_set_value(STDBY_GPIO_PIN, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static int am200_wait_event(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return wait_event_timeout(par->waitq, gpio_get_value(RDY_GPIO_PIN), HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int am200_wait_event_intr(struct metronomefb_par *par)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return wait_event_interruptible_timeout(par->waitq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) gpio_get_value(RDY_GPIO_PIN), HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static struct metronome_board am200_board = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .setup_irq = am200_setup_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .setup_io = am200_init_gpio_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .setup_fb = am200_setup_fb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .set_rst = am200_set_rst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .set_stdby = am200_set_stdby,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .met_wait_event = am200_wait_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .met_wait_event_intr = am200_wait_event_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .get_panel_type = am200_get_panel_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .cleanup = am200_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static unsigned long am200_pin_config[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) GPIO51_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) GPIO49_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) GPIO48_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) GPIO32_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) GPIO17_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) GPIO16_GPIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int __init am200_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * Before anything else, we request notification for any fb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * creation events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * FIXME: This is terrible and needs to be nuked. The notifier is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * to get at the fb base address from the boot splash fb driver, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * is then passed to metronomefb. Instaed of metronomfb or this board
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * support file here figuring this out on their own.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * See also the #ifdef in fbmem.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) fb_register_client(&am200_fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) pxa2xx_mfp_config(ARRAY_AND_SIZE(am200_pin_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* request our platform independent driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) request_module("metronomefb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) am200_device = platform_device_alloc("metronomefb", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (!am200_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* the am200_board that will be seen by metronomefb is a copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) platform_device_add_data(am200_device, &am200_board,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) sizeof(am200_board));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* this _add binds metronomefb to am200. metronomefb refcounts am200 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ret = platform_device_add(am200_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) platform_device_put(am200_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) fb_unregister_client(&am200_fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) am200_presetup_fb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) module_param(panel_type, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) MODULE_PARM_DESC(panel_type, "Select the panel type: 6, 8, 97");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) MODULE_DESCRIPTION("board driver for am200 metronome epd kit");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) MODULE_AUTHOR("Jaya Kumar");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) MODULE_LICENSE("GPL");