Lines Matching +full:on +full:- +full:chip +full:- +full:buff +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
19 #include <linux/platform_data/i2c-gpio.h>
25 #include <linux/sm501-regs.h>
135 unsigned long misct = smc501_readl(sm->regs + SM501_MISC_TIMING); in sm501_dump_clk()
136 unsigned long pm0 = smc501_readl(sm->regs + SM501_POWER_MODE_0_CLOCK); in sm501_dump_clk()
137 unsigned long pm1 = smc501_readl(sm->regs + SM501_POWER_MODE_1_CLOCK); in sm501_dump_clk()
138 unsigned long pmc = smc501_readl(sm->regs + SM501_POWER_MODE_CONTROL); in sm501_dump_clk()
163 dev_dbg(sm->dev, "MISCT=%08lx, PM0=%08lx, PM1=%08lx\n", in sm501_dump_clk()
166 dev_dbg(sm->dev, "PLL2 = %ld.%ld MHz (%ld), SDCLK0=%08lx, SDCLK1=%08lx\n", in sm501_dump_clk()
169 dev_dbg(sm->dev, "SDRAM: PM0=%ld, PM1=%ld\n", sdclk0, sdclk1); in sm501_dump_clk()
171 dev_dbg(sm->dev, "PM0[%c]: " in sm501_dump_clk()
174 (pmc & 3 ) == 0 ? '*' : '-', in sm501_dump_clk()
180 dev_dbg(sm->dev, "PM1[%c]: " in sm501_dump_clk()
183 (pmc & 3 ) == 1 ? '*' : '-', in sm501_dump_clk()
192 void __iomem *regs = sm->regs; in sm501_dump_regs()
194 dev_info(sm->dev, "System Control %08x\n", in sm501_dump_regs()
196 dev_info(sm->dev, "Misc Control %08x\n", in sm501_dump_regs()
198 dev_info(sm->dev, "GPIO Control Low %08x\n", in sm501_dump_regs()
200 dev_info(sm->dev, "GPIO Control Hi %08x\n", in sm501_dump_regs()
202 dev_info(sm->dev, "DRAM Control %08x\n", in sm501_dump_regs()
204 dev_info(sm->dev, "Arbitration Ctrl %08x\n", in sm501_dump_regs()
206 dev_info(sm->dev, "Misc Timing %08x\n", in sm501_dump_regs()
212 dev_info(sm->dev, "CurrentGate %08x\n", in sm501_dump_gate()
213 smc501_readl(sm->regs + SM501_CURRENT_GATE)); in sm501_dump_gate()
214 dev_info(sm->dev, "CurrentClock %08x\n", in sm501_dump_gate()
215 smc501_readl(sm->regs + SM501_CURRENT_CLOCK)); in sm501_dump_gate()
216 dev_info(sm->dev, "PowerModeControl %08x\n", in sm501_dump_gate()
217 smc501_readl(sm->regs + SM501_POWER_MODE_CONTROL)); in sm501_dump_gate()
233 smc501_readl(sm->regs); in sm501_sync_regs()
242 if (sm->in_suspend) in sm501_mdelay()
261 spin_lock_irqsave(&sm->reg_lock, save); in sm501_misc_control()
263 misc = smc501_readl(sm->regs + SM501_MISC_CONTROL); in sm501_misc_control()
267 smc501_writel(to, sm->regs + SM501_MISC_CONTROL); in sm501_misc_control()
270 dev_dbg(sm->dev, "MISC_CONTROL %08lx\n", misc); in sm501_misc_control()
273 spin_unlock_irqrestore(&sm->reg_lock, save); in sm501_misc_control()
294 spin_lock_irqsave(&sm->reg_lock, save); in sm501_modify_reg()
296 data = smc501_readl(sm->regs + reg); in sm501_modify_reg()
300 smc501_writel(data, sm->regs + reg); in sm501_modify_reg()
303 spin_unlock_irqrestore(&sm->reg_lock, save); in sm501_modify_reg()
312 * alters the power active gate to set specific units on or off
322 mutex_lock(&sm->clock_lock); in sm501_unit_power()
324 mode = smc501_readl(sm->regs + SM501_POWER_MODE_CONTROL); in sm501_unit_power()
325 gate = smc501_readl(sm->regs + SM501_CURRENT_GATE); in sm501_unit_power()
326 clock = smc501_readl(sm->regs + SM501_CURRENT_CLOCK); in sm501_unit_power()
330 if (unit >= ARRAY_SIZE(sm->unit_power)) { in sm501_unit_power()
335 dev_dbg(sm->dev, "%s: unit %d, cur %d, to %d\n", __func__, unit, in sm501_unit_power()
336 sm->unit_power[unit], to); in sm501_unit_power()
338 if (to == 0 && sm->unit_power[unit] == 0) { in sm501_unit_power()
339 dev_err(sm->dev, "unit %d is already shutdown\n", unit); in sm501_unit_power()
343 sm->unit_power[unit] += to ? 1 : -1; in sm501_unit_power()
344 to = sm->unit_power[unit] ? 1 : 0; in sm501_unit_power()
358 smc501_writel(gate, sm->regs + SM501_POWER_MODE_0_GATE); in sm501_unit_power()
359 smc501_writel(clock, sm->regs + SM501_POWER_MODE_0_CLOCK); in sm501_unit_power()
364 smc501_writel(gate, sm->regs + SM501_POWER_MODE_1_GATE); in sm501_unit_power()
365 smc501_writel(clock, sm->regs + SM501_POWER_MODE_1_CLOCK); in sm501_unit_power()
370 gate = -1; in sm501_unit_power()
374 smc501_writel(mode, sm->regs + SM501_POWER_MODE_CONTROL); in sm501_unit_power()
377 dev_dbg(sm->dev, "gate %08lx, clock %08lx, mode %08lx\n", in sm501_unit_power()
383 mutex_unlock(&sm->clock_lock); in sm501_unit_power()
422 diff = DIV_ROUND_CLOSEST(mclk, divider << shift) - freq; in sm501_calc_clock()
424 diff = -diff; in sm501_calc_clock()
430 clock->mclk = mclk; in sm501_calc_clock()
431 clock->divider = divider; in sm501_calc_clock()
432 clock->shift = shift; in sm501_calc_clock()
467 clock->m = m; in sm501_calc_pll()
468 clock->n = n; in sm501_calc_pll()
469 clock->k = k; in sm501_calc_pll()
476 return clock->mclk / (clock->divider << clock->shift); in sm501_calc_pll()
499 return clock->mclk / (clock->divider << clock->shift); in sm501_select_clock()
513 unsigned long mode = smc501_readl(sm->regs + SM501_POWER_MODE_CONTROL); in sm501_set_clock()
514 unsigned long gate = smc501_readl(sm->regs + SM501_CURRENT_GATE); in sm501_set_clock()
515 unsigned long clock = smc501_readl(sm->regs + SM501_CURRENT_CLOCK); in sm501_set_clock()
532 if (sm->rev >= 0xC0) { in sm501_set_clock()
533 /* SM502 -> use the programmable PLL */ in sm501_set_clock()
584 mutex_lock(&sm->clock_lock); in sm501_set_clock()
586 mode = smc501_readl(sm->regs + SM501_POWER_MODE_CONTROL); in sm501_set_clock()
587 gate = smc501_readl(sm->regs + SM501_CURRENT_GATE); in sm501_set_clock()
588 clock = smc501_readl(sm->regs + SM501_CURRENT_CLOCK); in sm501_set_clock()
597 smc501_writel(gate, sm->regs + SM501_POWER_MODE_0_GATE); in sm501_set_clock()
598 smc501_writel(clock, sm->regs + SM501_POWER_MODE_0_CLOCK); in sm501_set_clock()
603 smc501_writel(gate, sm->regs + SM501_POWER_MODE_1_GATE); in sm501_set_clock()
604 smc501_writel(clock, sm->regs + SM501_POWER_MODE_1_CLOCK); in sm501_set_clock()
609 mutex_unlock(&sm->clock_lock); in sm501_set_clock()
610 return -1; in sm501_set_clock()
613 smc501_writel(mode, sm->regs + SM501_POWER_MODE_CONTROL); in sm501_set_clock()
617 sm->regs + SM501_PROGRAMMABLE_PLL_CONTROL); in sm501_set_clock()
621 dev_dbg(sm->dev, "gate %08lx, clock %08lx, mode %08lx\n", in sm501_set_clock()
625 mutex_unlock(&sm->clock_lock); in sm501_set_clock()
649 if (sm->rev >= 0xC0) { in sm501_find_clock()
650 /* SM502 -> use the programmable PLL */ in sm501_find_clock()
696 * sub-driver
711 smdev->pdev.dev.release = sm501_device_release; in sm501_create_subdev()
713 smdev->pdev.name = name; in sm501_create_subdev()
714 smdev->pdev.id = sm->pdev_id; in sm501_create_subdev()
715 smdev->pdev.dev.parent = sm->dev; in sm501_create_subdev()
716 smdev->pdev.dev.coherent_dma_mask = 0xffffffff; in sm501_create_subdev()
719 smdev->pdev.resource = (struct resource *)(smdev+1); in sm501_create_subdev()
720 smdev->pdev.num_resources = res_count; in sm501_create_subdev()
723 smdev->pdev.dev.platform_data = (void *)(smdev+1); in sm501_create_subdev()
725 return &smdev->pdev; in sm501_create_subdev()
740 for (ptr = 0; ptr < pdev->num_resources; ptr++) { in sm501_register_device()
742 pdev->name, ptr, &pdev->resource[ptr]); in sm501_register_device()
748 dev_dbg(sm->dev, "registered %s\n", pdev->name); in sm501_register_device()
749 list_add_tail(&smdev->list, &sm->devices); in sm501_register_device()
751 dev_err(sm->dev, "error registering %s (%d)\n", in sm501_register_device()
752 pdev->name, ret); in sm501_register_device()
765 resource_size_t size) in sm501_create_subio() argument
767 res->flags = IORESOURCE_MEM; in sm501_create_subio()
768 res->parent = sm->io_res; in sm501_create_subio()
769 res->start = sm->io_res->start + offs; in sm501_create_subio()
770 res->end = res->start + size - 1; in sm501_create_subio()
781 resource_size_t size) in sm501_create_mem() argument
783 *offs -= size; /* adjust memory size */ in sm501_create_mem()
785 res->flags = IORESOURCE_MEM; in sm501_create_mem()
786 res->parent = sm->mem_res; in sm501_create_mem()
787 res->start = sm->mem_res->start + *offs; in sm501_create_mem()
788 res->end = res->start + size - 1; in sm501_create_mem()
799 res->flags = IORESOURCE_IRQ; in sm501_create_irq()
800 res->parent = NULL; in sm501_create_irq()
801 res->start = res->end = sm->irq; in sm501_create_irq()
809 pdev = sm501_create_subdev(sm, "sm501-usb", 3, 0); in sm501_register_usbhost()
811 return -ENOMEM; in sm501_register_usbhost()
813 sm501_create_subio(sm, &pdev->resource[0], 0x40000, 0x20000); in sm501_register_usbhost()
814 sm501_create_mem(sm, &pdev->resource[1], mem_avail, 256*1024); in sm501_register_usbhost()
815 sm501_create_irq(sm, &pdev->resource[2]); in sm501_register_usbhost()
824 uart_data->membase = sm->regs + offset; in sm501_setup_uart_data()
825 uart_data->mapbase = sm->io_res->start + offset; in sm501_setup_uart_data()
826 uart_data->iotype = UPIO_MEM; in sm501_setup_uart_data()
827 uart_data->irq = sm->irq; in sm501_setup_uart_data()
828 uart_data->flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ; in sm501_setup_uart_data()
829 uart_data->regshift = 2; in sm501_setup_uart_data()
830 uart_data->uartclk = (9600 * 16); in sm501_setup_uart_data()
841 return -ENOMEM; in sm501_register_uart()
843 uart_data = dev_get_platdata(&pdev->dev); in sm501_register_uart()
847 sm501_unit_power(sm->dev, SM501_GATE_UART0, 1); in sm501_register_uart()
848 sm501_modify_reg(sm->dev, SM501_IRQ_MASK, 1 << 12, 0); in sm501_register_uart()
849 sm501_modify_reg(sm->dev, SM501_GPIO63_32_CONTROL, 0x01e0, 0); in sm501_register_uart()
853 sm501_unit_power(sm->dev, SM501_GATE_UART1, 1); in sm501_register_uart()
854 sm501_modify_reg(sm->dev, SM501_IRQ_MASK, 1 << 13, 0); in sm501_register_uart()
855 sm501_modify_reg(sm->dev, SM501_GPIO63_32_CONTROL, 0x1e00, 0); in sm501_register_uart()
858 pdev->id = PLAT8250_DEV_SM501; in sm501_register_uart()
868 pdev = sm501_create_subdev(sm, "sm501-fb", 4, 0); in sm501_register_display()
870 return -ENOMEM; in sm501_register_display()
872 sm501_create_subio(sm, &pdev->resource[0], 0x80000, 0x10000); in sm501_register_display()
873 sm501_create_subio(sm, &pdev->resource[1], 0x100000, 0x50000); in sm501_register_display()
874 sm501_create_mem(sm, &pdev->resource[2], mem_avail, *mem_avail); in sm501_register_display()
875 sm501_create_irq(sm, &pdev->resource[3]); in sm501_register_display()
887 static int sm501_gpio_get(struct gpio_chip *chip, unsigned offset) in sm501_gpio_get() argument
890 struct sm501_gpio_chip *smgpio = gpiochip_get_data(chip); in sm501_gpio_get()
893 result = smc501_readl(smgpio->regbase + SM501_GPIO_DATA_LOW); in sm501_gpio_get()
906 if (smc501_readl(smchip->control) & bit) { in sm501_gpio_ensure_gpio()
907 dev_info(sm501_gpio_to_dev(smchip->ourgpio)->dev, in sm501_gpio_ensure_gpio()
910 ctrl = smc501_readl(smchip->control); in sm501_gpio_ensure_gpio()
912 smc501_writel(ctrl, smchip->control); in sm501_gpio_ensure_gpio()
914 sm501_sync_regs(sm501_gpio_to_dev(smchip->ourgpio)); in sm501_gpio_ensure_gpio()
918 static void sm501_gpio_set(struct gpio_chip *chip, unsigned offset, int value) in sm501_gpio_set() argument
921 struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); in sm501_gpio_set()
922 struct sm501_gpio *smgpio = smchip->ourgpio; in sm501_gpio_set()
924 void __iomem *regs = smchip->regbase; in sm501_gpio_set()
928 dev_dbg(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d)\n", in sm501_gpio_set()
929 __func__, chip, offset); in sm501_gpio_set()
931 spin_lock_irqsave(&smgpio->lock, save); in sm501_gpio_set()
941 spin_unlock_irqrestore(&smgpio->lock, save); in sm501_gpio_set()
944 static int sm501_gpio_input(struct gpio_chip *chip, unsigned offset) in sm501_gpio_input() argument
946 struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); in sm501_gpio_input()
947 struct sm501_gpio *smgpio = smchip->ourgpio; in sm501_gpio_input()
948 void __iomem *regs = smchip->regbase; in sm501_gpio_input()
953 dev_dbg(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d)\n", in sm501_gpio_input()
954 __func__, chip, offset); in sm501_gpio_input()
956 spin_lock_irqsave(&smgpio->lock, save); in sm501_gpio_input()
964 spin_unlock_irqrestore(&smgpio->lock, save); in sm501_gpio_input()
969 static int sm501_gpio_output(struct gpio_chip *chip, in sm501_gpio_output() argument
972 struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); in sm501_gpio_output()
973 struct sm501_gpio *smgpio = smchip->ourgpio; in sm501_gpio_output()
975 void __iomem *regs = smchip->regbase; in sm501_gpio_output()
980 dev_dbg(sm501_gpio_to_dev(smgpio)->dev, "%s(%p,%d,%d)\n", in sm501_gpio_output()
981 __func__, chip, offset, value); in sm501_gpio_output()
983 spin_lock_irqsave(&smgpio->lock, save); in sm501_gpio_output()
999 spin_unlock_irqrestore(&smgpio->lock, save); in sm501_gpio_output()
1014 struct sm501_gpio_chip *chip) in sm501_gpio_register_chip() argument
1016 struct sm501_platdata *pdata = sm->platdata; in sm501_gpio_register_chip()
1017 struct gpio_chip *gchip = &chip->gpio; in sm501_gpio_register_chip()
1018 int base = pdata->gpio_base; in sm501_gpio_register_chip()
1020 chip->gpio = gpio_chip_template; in sm501_gpio_register_chip()
1022 if (chip == &gpio->high) { in sm501_gpio_register_chip()
1025 chip->regbase = gpio->regs + SM501_GPIO_DATA_HIGH; in sm501_gpio_register_chip()
1026 chip->control = sm->regs + SM501_GPIO63_32_CONTROL; in sm501_gpio_register_chip()
1027 gchip->label = "SM501-HIGH"; in sm501_gpio_register_chip()
1029 chip->regbase = gpio->regs + SM501_GPIO_DATA_LOW; in sm501_gpio_register_chip()
1030 chip->control = sm->regs + SM501_GPIO31_0_CONTROL; in sm501_gpio_register_chip()
1031 gchip->label = "SM501-LOW"; in sm501_gpio_register_chip()
1034 gchip->base = base; in sm501_gpio_register_chip()
1035 chip->ourgpio = gpio; in sm501_gpio_register_chip()
1037 return gpiochip_add_data(gchip, chip); in sm501_gpio_register_chip()
1042 struct sm501_gpio *gpio = &sm->gpio; in sm501_register_gpio()
1043 resource_size_t iobase = sm->io_res->start + SM501_GPIO; in sm501_register_gpio()
1046 dev_dbg(sm->dev, "registering gpio block %08llx\n", in sm501_register_gpio()
1049 spin_lock_init(&gpio->lock); in sm501_register_gpio()
1051 gpio->regs_res = request_mem_region(iobase, 0x20, "sm501-gpio"); in sm501_register_gpio()
1052 if (!gpio->regs_res) { in sm501_register_gpio()
1053 dev_err(sm->dev, "gpio: failed to request region\n"); in sm501_register_gpio()
1054 return -ENXIO; in sm501_register_gpio()
1057 gpio->regs = ioremap(iobase, 0x20); in sm501_register_gpio()
1058 if (!gpio->regs) { in sm501_register_gpio()
1059 dev_err(sm->dev, "gpio: failed to remap registers\n"); in sm501_register_gpio()
1060 ret = -ENXIO; in sm501_register_gpio()
1066 ret = sm501_gpio_register_chip(sm, gpio, &gpio->low); in sm501_register_gpio()
1068 dev_err(sm->dev, "failed to add low chip\n"); in sm501_register_gpio()
1072 ret = sm501_gpio_register_chip(sm, gpio, &gpio->high); in sm501_register_gpio()
1074 dev_err(sm->dev, "failed to add high chip\n"); in sm501_register_gpio()
1078 gpio->registered = 1; in sm501_register_gpio()
1083 gpiochip_remove(&gpio->low.gpio); in sm501_register_gpio()
1086 iounmap(gpio->regs); in sm501_register_gpio()
1096 struct sm501_gpio *gpio = &sm->gpio; in sm501_gpio_remove()
1097 resource_size_t iobase = sm->io_res->start + SM501_GPIO; in sm501_gpio_remove()
1099 if (!sm->gpio.registered) in sm501_gpio_remove()
1102 gpiochip_remove(&gpio->low.gpio); in sm501_gpio_remove()
1103 gpiochip_remove(&gpio->high.gpio); in sm501_gpio_remove()
1105 iounmap(gpio->regs); in sm501_gpio_remove()
1111 return sm->gpio.registered; in sm501_gpio_isregistered()
1136 pdev = sm501_create_subdev(sm, "i2c-gpio", 0, in sm501_register_gpio_i2c_instance()
1139 return -ENOMEM; in sm501_register_gpio_i2c_instance()
1141 /* Create a gpiod lookup using gpiochip-local offsets */ in sm501_register_gpio_i2c_instance()
1142 lookup = devm_kzalloc(&pdev->dev, struct_size(lookup, table, 3), in sm501_register_gpio_i2c_instance()
1145 return -ENOMEM; in sm501_register_gpio_i2c_instance()
1147 lookup->dev_id = "i2c-gpio"; in sm501_register_gpio_i2c_instance()
1148 lookup->table[0] = (struct gpiod_lookup) in sm501_register_gpio_i2c_instance()
1149 GPIO_LOOKUP_IDX(iic->pin_sda < 32 ? "SM501-LOW" : "SM501-HIGH", in sm501_register_gpio_i2c_instance()
1150 iic->pin_sda % 32, NULL, 0, in sm501_register_gpio_i2c_instance()
1152 lookup->table[1] = (struct gpiod_lookup) in sm501_register_gpio_i2c_instance()
1153 GPIO_LOOKUP_IDX(iic->pin_scl < 32 ? "SM501-LOW" : "SM501-HIGH", in sm501_register_gpio_i2c_instance()
1154 iic->pin_scl % 32, NULL, 1, in sm501_register_gpio_i2c_instance()
1158 icd = dev_get_platdata(&pdev->dev); in sm501_register_gpio_i2c_instance()
1159 icd->timeout = iic->timeout; in sm501_register_gpio_i2c_instance()
1160 icd->udelay = iic->udelay; in sm501_register_gpio_i2c_instance()
1162 /* note, we can't use either of the pin numbers, as the i2c-gpio in sm501_register_gpio_i2c_instance()
1168 pdev->id = iic->bus_num; in sm501_register_gpio_i2c_instance()
1170 dev_info(sm->dev, "registering i2c-%d: sda=%d, scl=%d\n", in sm501_register_gpio_i2c_instance()
1171 iic->bus_num, in sm501_register_gpio_i2c_instance()
1172 iic->pin_sda, iic->pin_scl); in sm501_register_gpio_i2c_instance()
1180 struct sm501_platdata_gpio_i2c *iic = pdata->gpio_i2c; in sm501_register_gpio_i2c()
1184 for (index = 0; index < pdata->gpio_i2c_nr; index++, iic++) { in sm501_register_gpio_i2c()
1199 struct device_attribute *attr, char *buff) in dbg_regs_show() argument
1203 char *ptr = buff; in dbg_regs_show()
1208 reg, smc501_readl(sm->regs + reg)); in dbg_regs_show()
1212 return ptr - buff; in dbg_regs_show()
1222 * clear the bits which are set in r->mask, and then set
1223 * the bits set in r->set.
1232 tmp = smc501_readl(sm->regs + reg); in sm501_init_reg()
1233 tmp &= ~r->mask; in sm501_init_reg()
1234 tmp |= r->set; in sm501_init_reg()
1235 smc501_writel(tmp, sm->regs + reg); in sm501_init_reg()
1246 sm501_misc_control(sm->dev, in sm501_init_regs()
1247 init->misc_control.set, in sm501_init_regs()
1248 init->misc_control.mask); in sm501_init_regs()
1250 sm501_init_reg(sm, SM501_MISC_TIMING, &init->misc_timing); in sm501_init_regs()
1251 sm501_init_reg(sm, SM501_GPIO31_0_CONTROL, &init->gpio_low); in sm501_init_regs()
1252 sm501_init_reg(sm, SM501_GPIO63_32_CONTROL, &init->gpio_high); in sm501_init_regs()
1254 if (init->m1xclk) { in sm501_init_regs()
1255 dev_info(sm->dev, "setting M1XCLK to %ld\n", init->m1xclk); in sm501_init_regs()
1256 sm501_set_clock(sm->dev, SM501_CLOCK_M1XCLK, init->m1xclk); in sm501_init_regs()
1259 if (init->mclk) { in sm501_init_regs()
1260 dev_info(sm->dev, "setting MCLK to %ld\n", init->mclk); in sm501_init_regs()
1261 sm501_set_clock(sm->dev, SM501_CLOCK_MCLK, init->mclk); in sm501_init_regs()
1269 * there is a risk (see errata AB-5) that the SM501 will cease proper
1276 unsigned long pwrmode = smc501_readl(sm->regs + SM501_CURRENT_CLOCK); in sm501_check_clocks()
1306 mutex_init(&sm->clock_lock); in sm501_init_dev()
1307 spin_lock_init(&sm->reg_lock); in sm501_init_dev()
1309 INIT_LIST_HEAD(&sm->devices); in sm501_init_dev()
1311 devid = smc501_readl(sm->regs + SM501_DEVICEID); in sm501_init_dev()
1314 dev_err(sm->dev, "incorrect device id %08lx\n", devid); in sm501_init_dev()
1315 return -EINVAL; in sm501_init_dev()
1319 smc501_writel(0, sm->regs + SM501_IRQ_MASK); in sm501_init_dev()
1321 dramctrl = smc501_readl(sm->regs + SM501_DRAM_CONTROL); in sm501_init_dev()
1324 dev_info(sm->dev, "SM501 At %p: Version %08lx, %ld Mb, IRQ %d\n", in sm501_init_dev()
1325 sm->regs, devid, (unsigned long)mem_avail >> 20, sm->irq); in sm501_init_dev()
1327 sm->rev = devid & SM501_DEVICEID_REVMASK; in sm501_init_dev()
1331 ret = device_create_file(sm->dev, &dev_attr_dbg_regs); in sm501_init_dev()
1333 dev_err(sm->dev, "failed to create debug regs file\n"); in sm501_init_dev()
1339 pdata = sm->platdata; in sm501_init_dev()
1340 idata = pdata ? pdata->init : NULL; in sm501_init_dev()
1345 if (idata->devices & SM501_USE_USB_HOST) in sm501_init_dev()
1347 if (idata->devices & (SM501_USE_UART0 | SM501_USE_UART1)) in sm501_init_dev()
1348 sm501_register_uart(sm, idata->devices); in sm501_init_dev()
1349 if (idata->devices & SM501_USE_GPIO) in sm501_init_dev()
1353 if (pdata && pdata->gpio_i2c && pdata->gpio_i2c_nr > 0) { in sm501_init_dev()
1355 dev_err(sm->dev, "no gpio available for i2c gpio.\n"); in sm501_init_dev()
1362 dev_err(sm->dev, "M1X and M clocks sourced from different " in sm501_init_dev()
1364 return -EINVAL; in sm501_init_dev()
1380 ret = -ENOMEM; in sm501_plat_probe()
1384 sm->dev = &dev->dev; in sm501_plat_probe()
1385 sm->pdev_id = dev->id; in sm501_plat_probe()
1386 sm->platdata = dev_get_platdata(&dev->dev); in sm501_plat_probe()
1391 sm->irq = ret; in sm501_plat_probe()
1393 sm->io_res = platform_get_resource(dev, IORESOURCE_MEM, 1); in sm501_plat_probe()
1394 sm->mem_res = platform_get_resource(dev, IORESOURCE_MEM, 0); in sm501_plat_probe()
1395 if (!sm->io_res || !sm->mem_res) { in sm501_plat_probe()
1396 dev_err(&dev->dev, "failed to get IO resource\n"); in sm501_plat_probe()
1397 ret = -ENOENT; in sm501_plat_probe()
1401 sm->regs_claim = request_mem_region(sm->io_res->start, in sm501_plat_probe()
1403 if (!sm->regs_claim) { in sm501_plat_probe()
1404 dev_err(&dev->dev, "cannot claim registers\n"); in sm501_plat_probe()
1405 ret = -EBUSY; in sm501_plat_probe()
1411 sm->regs = ioremap(sm->io_res->start, resource_size(sm->io_res)); in sm501_plat_probe()
1412 if (!sm->regs) { in sm501_plat_probe()
1413 dev_err(&dev->dev, "cannot remap registers\n"); in sm501_plat_probe()
1414 ret = -EIO; in sm501_plat_probe()
1425 iounmap(sm->regs); in sm501_plat_probe()
1427 release_mem_region(sm->io_res->start, 0x100); in sm501_plat_probe()
1437 static void sm501_set_power(struct sm501_devdata *sm, int on) in sm501_set_power() argument
1439 struct sm501_platdata *pd = sm->platdata; in sm501_set_power()
1444 if (pd->get_power) { in sm501_set_power()
1445 if (pd->get_power(sm->dev) == on) { in sm501_set_power()
1446 dev_dbg(sm->dev, "is already %d\n", on); in sm501_set_power()
1451 if (pd->set_power) { in sm501_set_power()
1452 dev_dbg(sm->dev, "setting power to %d\n", on); in sm501_set_power()
1454 pd->set_power(sm->dev, on); in sm501_set_power()
1463 sm->in_suspend = 1; in sm501_plat_suspend()
1464 sm->pm_misc = smc501_readl(sm->regs + SM501_MISC_CONTROL); in sm501_plat_suspend()
1468 if (sm->platdata) { in sm501_plat_suspend()
1469 if (sm->platdata->flags & SM501_FLAG_SUSPEND_OFF) in sm501_plat_suspend()
1488 if (smc501_readl(sm->regs + SM501_MISC_CONTROL) != sm->pm_misc) { in sm501_plat_resume()
1489 dev_info(sm->dev, "SM501_MISC_CONTROL changed over sleep\n"); in sm501_plat_resume()
1490 smc501_writel(sm->pm_misc, sm->regs + SM501_MISC_CONTROL); in sm501_plat_resume()
1494 * or an external reset event on power change */ in sm501_plat_resume()
1496 if (sm->platdata && sm->platdata->init) { in sm501_plat_resume()
1497 sm501_init_regs(sm, sm->platdata->init); in sm501_plat_resume()
1506 sm->in_suspend = 0; in sm501_plat_resume()
1529 /* Errata AB-3 says that 72MHz is the fastest available
1530 * for 33MHZ PCI with proper bus-mastering operation */
1552 .gpio_base = -1,
1563 err = -ENOMEM; in sm501_pci_probe()
1568 dev->dev.platform_data = sm->platdata = &sm501_pci_platdata; in sm501_pci_probe()
1571 sm->pdev_id = 32 + dev->devfn; in sm501_pci_probe()
1577 dev_err(&dev->dev, "cannot enable device\n"); in sm501_pci_probe()
1581 sm->dev = &dev->dev; in sm501_pci_probe()
1582 sm->irq = dev->irq; in sm501_pci_probe()
1585 /* if the system is big-endian, we most probably have a in sm501_pci_probe()
1595 dev_err(&dev->dev, "region #0 is not memory?\n"); in sm501_pci_probe()
1596 err = -EINVAL; in sm501_pci_probe()
1601 dev_err(&dev->dev, "region #1 is not memory?\n"); in sm501_pci_probe()
1602 err = -EINVAL; in sm501_pci_probe()
1608 sm->io_res = &dev->resource[1]; in sm501_pci_probe()
1609 sm->mem_res = &dev->resource[0]; in sm501_pci_probe()
1611 sm->regs_claim = request_mem_region(sm->io_res->start, in sm501_pci_probe()
1613 if (!sm->regs_claim) { in sm501_pci_probe()
1614 dev_err(&dev->dev, "cannot claim registers\n"); in sm501_pci_probe()
1615 err= -EBUSY; in sm501_pci_probe()
1619 sm->regs = pci_ioremap_bar(dev, 1); in sm501_pci_probe()
1620 if (!sm->regs) { in sm501_pci_probe()
1621 dev_err(&dev->dev, "cannot remap registers\n"); in sm501_pci_probe()
1622 err = -EIO; in sm501_pci_probe()
1630 release_mem_region(sm->io_res->start, 0x100); in sm501_pci_probe()
1642 list_del(&smdev->list); in sm501_remove_sub()
1643 platform_device_unregister(&smdev->pdev); in sm501_remove_sub()
1650 list_for_each_entry_safe(smdev, tmp, &sm->devices, list) in sm501_dev_remove()
1653 device_remove_file(sm->dev, &dev_attr_dbg_regs); in sm501_dev_remove()
1663 iounmap(sm->regs); in sm501_pci_remove()
1665 release_mem_region(sm->io_res->start, 0x100); in sm501_pci_remove()
1675 iounmap(sm->regs); in sm501_plat_remove()
1677 release_mem_region(sm->io_res->start, 0x100); in sm501_plat_remove()