13 #define pr_fmt(fmt) "mrst: " fmt
16 #include <linux/kernel.h>
22 #include <linux/i2c.h>
25 #include <linux/input.h>
28 #include <linux/module.h>
34 #include <asm/setup.h>
36 #include <asm/hw_irq.h>
42 #include <asm/i8259.h>
45 #include <asm/reboot.h>
81 static void mrst_power_off(
void)
85 static void mrst_reboot(
void)
104 memcpy(sfi_mtimer_array, pentry, totallen);
108 pentry = sfi_mtimer_array;
109 for (totallen = 0; totallen <
sfi_mtimer_num; totallen++, pentry++) {
110 pr_debug(
"timer[%d]: paddr = 0x%08x, freq = %dHz,"
120 mp_irq.srcbusirq = pentry->
irq;
122 mp_irq.dstirq = pentry->
irq;
132 if (hint < sfi_mtimer_num) {
133 if (!sfi_mtimer_usage[hint]) {
134 pr_debug(
"hint taken for timer %d irq %d\n",\
135 hint, sfi_mtimer_array[hint].
irq);
136 sfi_mtimer_usage[hint] = 1;
137 return &sfi_mtimer_array[hint];
142 if (!sfi_mtimer_usage[i]) {
143 sfi_mtimer_usage[
i] = 1;
144 return &sfi_mtimer_array[
i];
155 if (mtmr->
irq == sfi_mtimer_array[i].irq) {
156 sfi_mtimer_usage[
i] = 0;
183 for (totallen = 0; totallen <
sfi_mrtc_num; totallen++, pentry++) {
184 pr_debug(
"RTC[%d]: paddr = 0x%08x, irq = %d\n",
198 static unsigned long __init mrst_calibrate_tsc(
void)
200 unsigned long fast_calibrate;
204 pr_debug(
"IA32 perf status is 0x%x, 0x%0x\n", lo, hi);
205 ratio = (hi >> 8) & 0x1f;
208 pr_err(
"read a zero ratio, should be incorrect!\n");
209 pr_err(
"force tsc ratio to 16 ...\n");
213 if ((lo & 0x7) == 0x7)
217 fast_calibrate = ratio * fsb;
218 pr_debug(
"read penwell tsc %lu khz\n", fast_calibrate);
224 return fast_calibrate;
229 static void __init mrst_time_init(
void)
251 static void __cpuinit mrst_arch_setup(
void)
256 pr_err(
"Unknown Intel MID CPU (%d:%d), default to Penwell\n",
263 static int mrst_i8042_detect(
void)
274 static unsigned char mrst_get_nmi_reason(
void)
288 x86_init.timers.timer_init = mrst_time_init;
293 x86_init.oem.arch_setup = mrst_arch_setup;
321 static inline int __init setup_x86_mrst_timer(
char *
arg)
326 if (
strcmp(
"apbt_only", arg) == 0)
328 else if (
strcmp(
"lapic_and_apbt", arg) == 0)
331 pr_warning(
"X86 MRST timer option %s not recognised"
332 " use x86_mrst_timer=apbt_only or lapic_and_apbt\n",
338 __setup(
"x86_mrst_timer=", setup_x86_mrst_timer);
345 static int gpio_num_entry;
363 memcpy(gpio_table, pentry, num *
sizeof(*pentry));
364 gpio_num_entry = num;
367 for (i = 0; i < num; i++, pentry++)
368 pr_debug(
"info[%2d]: controller = %16.16s, pin_name = %16.16s,"
376 static int get_gpio_by_name(
const char *
name)
383 for (i = 0; i < gpio_num_entry; i++, pentry++) {
399 void *(*get_platform_data)(
void *
info);
403 #define MRST_IRQ_OFFSET 0x100
405 static void __init *pmic_gpio_platform_data(
void *
info)
408 int gpio_base = get_gpio_by_name(
"pmic_gpio_base");
414 pmic_gpio_pdata.
gpiointr = 0xffffeff8;
416 return &pmic_gpio_pdata;
419 static void __init *max3111_platform_data(
void *
info)
422 int intr = get_gpio_by_name(
"max3111_int");
432 #define MAX7315_NUM 2
433 static void __init *max7315_platform_data(
void *info)
443 if (nr == MAX7315_NUM) {
444 pr_err(
"too many max7315s, we only support %d\n",
453 sprintf(base_pin_name,
"max7315_%d_base", nr);
454 sprintf(intr_pin_name,
"max7315_%d_int", nr);
456 strcpy(base_pin_name,
"max7315_base");
457 strcpy(intr_pin_name,
"max7315_int");
460 gpio_base = get_gpio_by_name(base_pin_name);
461 intr = get_gpio_by_name(intr_pin_name);
476 static void *tca6416_platform_data(
void *info)
485 strcpy(base_pin_name,
"tca6416_base");
486 strcpy(intr_pin_name,
"tca6416_int");
488 gpio_base = get_gpio_by_name(base_pin_name);
489 intr = get_gpio_by_name(intr_pin_name);
499 tca6416.irq_base = -1;
504 static void *mpu3050_platform_data(
void *info)
507 int intr = get_gpio_by_name(
"mpu3050_int");
516 static void __init *emc1403_platform_data(
void *info)
518 static short intr2nd_pdata;
520 int intr = get_gpio_by_name(
"thermal_int");
521 int intr2nd = get_gpio_by_name(
"thermal_alert");
523 if (intr == -1 || intr2nd == -1)
529 return &intr2nd_pdata;
532 static void __init *lis331dl_platform_data(
void *info)
534 static short intr2nd_pdata;
536 int intr = get_gpio_by_name(
"accel_int");
537 int intr2nd = get_gpio_by_name(
"accel_2");
539 if (intr == -1 || intr2nd == -1)
545 return &intr2nd_pdata;
548 static void __init *no_platform_data(
void *info)
553 static struct resource msic_resources[] = {
564 .name =
"intel_msic",
567 .platform_data = &msic_pdata,
570 .resource = msic_resources,
573 static inline bool mrst_has_msic(
void)
589 static int __init msic_init(
void)
600 intel_scu_notifier_add(&msic_scu_notifier);
621 return no_platform_data(info);
624 static void *msic_battery_platform_data(
void *info)
629 static void *msic_gpio_platform_data(
void *info)
632 int gpio = get_gpio_by_name(
"msic_gpio_base");
638 msic_pdata.gpio = &
pdata;
643 static void *msic_audio_platform_data(
void *info)
647 pdev = platform_device_register_simple(
"sst-platform", -1,
NULL, 0);
649 pr_err(
"failed to create audio platform device\n");
656 static void *msic_power_btn_platform_data(
void *info)
661 static void *msic_ocd_platform_data(
void *info)
664 int gpio = get_gpio_by_name(
"ocd_gpio");
670 msic_pdata.ocd = &
pdata;
675 static void *msic_thermal_platform_data(
void *info)
686 pdata.gpio_bridge_reset = get_gpio_by_name(
"LCMB_RXEN");
687 pdata.gpio_panel_bl_en = get_gpio_by_name(
"6S6P_BL_EN");
688 pdata.gpio_panel_vadd = get_gpio_by_name(
"EN_VREG_LCD_V3P3");
718 #define MAX_IPCDEVS 24
720 static int ipc_next_dev;
722 #define MAX_SCU_SPI 24
724 static int spi_next_dev;
726 #define MAX_SCU_I2C 24
729 static int i2c_next_dev;
734 pr_err(
"too many SCU IPC devices");
736 ipc_devs[ipc_next_dev++] = pdev;
744 pr_err(
"too many SCU SPI devices");
750 pr_err(
"failed to alloc mem for delayed spi dev %s\n",
754 memcpy(new_dev, sdev,
sizeof(*sdev));
756 spi_devs[spi_next_dev++] = new_dev;
759 static void __init intel_scu_i2c_device_register(
int bus,
765 pr_err(
"too many SCU I2C devices");
771 pr_err(
"failed to alloc mem for delayed i2c dev %s\n",
775 memcpy(new_dev, idev,
sizeof(*idev));
777 i2c_bus[i2c_next_dev] =
bus;
778 i2c_devs[i2c_next_dev++] = new_dev;
789 for (i = 0; i < ipc_next_dev; i++)
792 for (i = 0; i < spi_next_dev; i++)
795 for (i = 0; i < i2c_next_dev; i++) {
803 pr_err(
"can't create i2c device %s\n",
819 for (i = 0; i < ipc_next_dev; i++)
841 while (dev->
name[0]) {
859 pr_err(
"out of memory for SFI platform device '%s'.\n",
863 install_irq_resource(pdev, entry->
irq);
866 intel_scu_device_register(pdev);
871 const struct devs_id *dev = device_ids;
874 while (dev->
name[0]) {
884 intel_scu_spi_device_register(spi_info);
891 const struct devs_id *dev = device_ids;
894 while (dev->
name[0]) {
905 intel_scu_i2c_device_register(bus, i2c_info);
925 for (i = 0; i < num; i++, pentry++) {
928 if (irq != (
u8)0xff) {
934 irq_attr.ioapic = ioapic;
935 irq_attr.ioapic_pin =
irq;
936 irq_attr.trigger = 1;
937 irq_attr.polarity = 1;
942 switch (pentry->
type) {
944 pr_debug(
"info[%2d]: IPC bus, name = %16.16s, "
945 "irq = 0x%2x\n", i, pentry->
name, pentry->
irq);
946 sfi_handle_ipc_dev(pentry);
949 memset(&spi_info, 0,
sizeof(spi_info));
955 pr_debug(
"info[%2d]: SPI bus = %d, name = %16.16s, "
956 "irq = 0x%2x, max_freq = %d, cs = %d\n", i,
962 sfi_handle_spi_dev(&spi_info);
965 memset(&i2c_info, 0,
sizeof(i2c_info));
970 pr_debug(
"info[%2d]: I2C bus = %d, name = %16.16s, "
971 "irq = 0x%2x, addr = 0x%x\n", i, bus,
975 sfi_handle_i2c_dev(bus, &i2c_info);
986 static int __init mrst_platform_init(
void)
1013 .buttons = gpio_button,
1019 .name =
"gpio-keys",
1022 .platform_data = &mrst_gpio_keys,
1030 static int __init pb_keys_init(
void)
1033 int i, num, good = 0;
1036 for (i = 0; i < num; i++) {
1037 gb[
i].
gpio = get_gpio_by_name(gb[i].
desc);
1038 pr_debug(
"info[%2d]: name = %s, gpio = %d\n", i, gb[i].
desc, gb[i].gpio);
1039 if (gb[i].gpio == -1)