Lines Matching refs:ab8500

157 static int ab8500_prcmu_write(struct ab8500 *ab8500, u16 addr, u8 data)  in ab8500_prcmu_write()  argument
163 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_write()
167 static int ab8500_prcmu_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask, in ab8500_prcmu_write_masked() argument
175 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_write_masked()
179 static int ab8500_prcmu_read(struct ab8500 *ab8500, u16 addr) in ab8500_prcmu_read() argument
186 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_read()
194 struct ab8500 *ab8500; in ab8500_get_chip_id() local
198 ab8500 = dev_get_drvdata(dev->parent); in ab8500_get_chip_id()
199 return ab8500 ? (int)ab8500->chip_id : -EINVAL; in ab8500_get_chip_id()
202 static int set_register_interruptible(struct ab8500 *ab8500, u8 bank, in set_register_interruptible() argument
212 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data); in set_register_interruptible()
214 mutex_lock(&ab8500->lock); in set_register_interruptible()
216 ret = ab8500->write(ab8500, addr, data); in set_register_interruptible()
218 dev_err(ab8500->dev, "failed to write reg %#x: %d\n", in set_register_interruptible()
220 mutex_unlock(&ab8500->lock); in set_register_interruptible()
229 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_set_register() local
231 atomic_inc(&ab8500->transfer_ongoing); in ab8500_set_register()
232 ret = set_register_interruptible(ab8500, bank, reg, value); in ab8500_set_register()
233 atomic_dec(&ab8500->transfer_ongoing); in ab8500_set_register()
237 static int get_register_interruptible(struct ab8500 *ab8500, u8 bank, in get_register_interruptible() argument
243 mutex_lock(&ab8500->lock); in get_register_interruptible()
245 ret = ab8500->read(ab8500, addr); in get_register_interruptible()
247 dev_err(ab8500->dev, "failed to read reg %#x: %d\n", in get_register_interruptible()
252 mutex_unlock(&ab8500->lock); in get_register_interruptible()
253 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret); in get_register_interruptible()
262 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_get_register() local
264 atomic_inc(&ab8500->transfer_ongoing); in ab8500_get_register()
265 ret = get_register_interruptible(ab8500, bank, reg, value); in ab8500_get_register()
266 atomic_dec(&ab8500->transfer_ongoing); in ab8500_get_register()
270 static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank, in mask_and_set_register_interruptible() argument
276 mutex_lock(&ab8500->lock); in mask_and_set_register_interruptible()
278 if (ab8500->write_masked == NULL) { in mask_and_set_register_interruptible()
281 ret = ab8500->read(ab8500, addr); in mask_and_set_register_interruptible()
283 dev_err(ab8500->dev, "failed to read reg %#x: %d\n", in mask_and_set_register_interruptible()
291 ret = ab8500->write(ab8500, addr, data); in mask_and_set_register_interruptible()
293 dev_err(ab8500->dev, "failed to write reg %#x: %d\n", in mask_and_set_register_interruptible()
296 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, in mask_and_set_register_interruptible()
300 ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues); in mask_and_set_register_interruptible()
302 dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr, in mask_and_set_register_interruptible()
305 mutex_unlock(&ab8500->lock); in mask_and_set_register_interruptible()
313 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_mask_and_set_register() local
315 atomic_inc(&ab8500->transfer_ongoing); in ab8500_mask_and_set_register()
316 ret = mask_and_set_register_interruptible(ab8500, bank, reg, in ab8500_mask_and_set_register()
318 atomic_dec(&ab8500->transfer_ongoing); in ab8500_mask_and_set_register()
336 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_lock() local
338 mutex_lock(&ab8500->irq_lock); in ab8500_irq_lock()
339 atomic_inc(&ab8500->transfer_ongoing); in ab8500_irq_lock()
344 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_sync_unlock() local
347 for (i = 0; i < ab8500->mask_size; i++) { in ab8500_irq_sync_unlock()
348 u8 old = ab8500->oldmask[i]; in ab8500_irq_sync_unlock()
349 u8 new = ab8500->mask[i]; in ab8500_irq_sync_unlock()
359 if (ab8500->irq_reg_offset[i] == 11 && in ab8500_irq_sync_unlock()
360 is_ab8500_1p1_or_earlier(ab8500)) in ab8500_irq_sync_unlock()
363 if (ab8500->irq_reg_offset[i] < 0) in ab8500_irq_sync_unlock()
366 ab8500->oldmask[i] = new; in ab8500_irq_sync_unlock()
368 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; in ab8500_irq_sync_unlock()
369 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new); in ab8500_irq_sync_unlock()
371 atomic_dec(&ab8500->transfer_ongoing); in ab8500_irq_sync_unlock()
372 mutex_unlock(&ab8500->irq_lock); in ab8500_irq_sync_unlock()
377 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_mask() local
382 ab8500->mask[index] |= mask; in ab8500_irq_mask()
386 ab8500->mask[index + 2] |= mask; in ab8500_irq_mask()
388 ab8500->mask[index + 1] |= mask; in ab8500_irq_mask()
391 ab8500->mask[index] |= (mask << 1); in ab8500_irq_mask()
396 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_unmask() local
403 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
408 ab8500->mask[index + 2] &= ~mask; in ab8500_irq_unmask()
411 ab8500->mask[index + 1] &= ~mask; in ab8500_irq_unmask()
415 ab8500->mask[index] &= ~(mask << 1); in ab8500_irq_unmask()
417 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
420 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
451 static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500, in ab8500_handle_hierarchical_line() argument
456 for (i = 0; i < ab8500->mask_size; i++) in ab8500_handle_hierarchical_line()
457 if (ab8500->irq_reg_offset[i] == latch_offset) in ab8500_handle_hierarchical_line()
460 if (i >= ab8500->mask_size) { in ab8500_handle_hierarchical_line()
461 dev_err(ab8500->dev, "Register offset 0x%2x not declared\n", in ab8500_handle_hierarchical_line()
467 latch_val &= ~ab8500->mask[i]; in ab8500_handle_hierarchical_line()
487 handle_nested_irq(irq_find_mapping(ab8500->domain, line)); in ab8500_handle_hierarchical_line()
493 static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500, in ab8500_handle_hierarchical_latch() argument
505 status = get_register_interruptible(ab8500, in ab8500_handle_hierarchical_latch()
512 status = ab8500_handle_hierarchical_line(ab8500, in ab8500_handle_hierarchical_latch()
525 struct ab8500 *ab8500 = dev; in ab8500_hierarchical_irq() local
528 dev_vdbg(ab8500->dev, "interrupt\n"); in ab8500_hierarchical_irq()
531 for (i = 0; i < (ab8500->it_latchhier_num); i++) { in ab8500_hierarchical_irq()
535 status = get_register_interruptible(ab8500, AB8500_INTERRUPT, in ab8500_hierarchical_irq()
540 status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val); in ab8500_hierarchical_irq()
550 struct ab8500 *ab8500 = d->host_data; in ab8500_irq_map() local
552 if (!ab8500) in ab8500_irq_map()
555 irq_set_chip_data(virq, ab8500); in ab8500_irq_map()
569 static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np) in ab8500_irq_init() argument
573 if (is_ab8540(ab8500)) in ab8500_irq_init()
575 else if (is_ab9540(ab8500)) in ab8500_irq_init()
577 else if (is_ab8505(ab8500)) in ab8500_irq_init()
583 ab8500->domain = irq_domain_add_simple(ab8500->dev->of_node, in ab8500_irq_init()
585 &ab8500_irq_ops, ab8500); in ab8500_irq_init()
587 if (!ab8500->domain) { in ab8500_irq_init()
588 dev_err(ab8500->dev, "Failed to create irqdomain\n"); in ab8500_irq_init()
595 int ab8500_suspend(struct ab8500 *ab8500) in ab8500_suspend() argument
597 if (atomic_read(&ab8500->transfer_ongoing)) in ab8500_suspend()
812 struct ab8500 *ab8500; in chip_id_show() local
814 ab8500 = dev_get_drvdata(dev); in chip_id_show()
816 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); in chip_id_show()
835 struct ab8500 *ab8500; in switch_off_status_show() local
837 ab8500 = dev_get_drvdata(dev); in switch_off_status_show()
838 ret = get_register_interruptible(ab8500, AB8500_RTC, in switch_off_status_show()
870 struct ab8500 *ab8500; in turn_on_status_show() local
872 ab8500 = dev_get_drvdata(dev); in turn_on_status_show()
873 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, in turn_on_status_show()
885 if (is_ab9540(ab8500)) { in turn_on_status_show()
899 struct ab8500 *ab8500; in turn_on_status_2_show() local
901 ab8500 = dev_get_drvdata(dev); in turn_on_status_2_show()
902 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, in turn_on_status_2_show()
912 struct ab8500 *ab8500; in dbbrstn_show() local
916 ab8500 = dev_get_drvdata(dev); in dbbrstn_show()
918 ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2, in dbbrstn_show()
930 struct ab8500 *ab8500; in dbbrstn_store() local
935 ab8500 = dev_get_drvdata(dev); in dbbrstn_store()
949 err = mask_and_set_register_interruptible(ab8500, in dbbrstn_store()
953 dev_info(ab8500->dev, in dbbrstn_store()
1023 struct ab8500 *ab8500; in ab8500_probe() local
1029 ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL); in ab8500_probe()
1030 if (!ab8500) in ab8500_probe()
1033 ab8500->dev = &pdev->dev; in ab8500_probe()
1039 ab8500->irq = irq; in ab8500_probe()
1041 ab8500->read = ab8500_prcmu_read; in ab8500_probe()
1042 ab8500->write = ab8500_prcmu_write; in ab8500_probe()
1043 ab8500->write_masked = ab8500_prcmu_write_masked; in ab8500_probe()
1045 mutex_init(&ab8500->lock); in ab8500_probe()
1046 mutex_init(&ab8500->irq_lock); in ab8500_probe()
1047 atomic_set(&ab8500->transfer_ongoing, 0); in ab8500_probe()
1049 platform_set_drvdata(pdev, ab8500); in ab8500_probe()
1055 ab8500->version = version; in ab8500_probe()
1057 ret = get_register_interruptible(ab8500, AB8500_MISC, in ab8500_probe()
1064 ab8500->version = value; in ab8500_probe()
1067 ret = get_register_interruptible(ab8500, AB8500_MISC, in ab8500_probe()
1072 ab8500->chip_id = value; in ab8500_probe()
1074 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n", in ab8500_probe()
1075 ab8500_version_str[ab8500->version], in ab8500_probe()
1076 ab8500->chip_id >> 4, in ab8500_probe()
1077 ab8500->chip_id & 0x0F); in ab8500_probe()
1080 if (is_ab8540(ab8500)) { in ab8500_probe()
1081 ab8500->mask_size = AB8540_NUM_IRQ_REGS; in ab8500_probe()
1082 ab8500->irq_reg_offset = ab8540_irq_regoffset; in ab8500_probe()
1083 ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM; in ab8500_probe()
1085 else if (is_ab9540(ab8500) || is_ab8505(ab8500)) { in ab8500_probe()
1086 ab8500->mask_size = AB9540_NUM_IRQ_REGS; in ab8500_probe()
1087 ab8500->irq_reg_offset = ab9540_irq_regoffset; in ab8500_probe()
1088 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM; in ab8500_probe()
1090 ab8500->mask_size = AB8500_NUM_IRQ_REGS; in ab8500_probe()
1091 ab8500->irq_reg_offset = ab8500_irq_regoffset; in ab8500_probe()
1092 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM; in ab8500_probe()
1094 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, in ab8500_probe()
1096 if (!ab8500->mask) in ab8500_probe()
1098 ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, in ab8500_probe()
1100 if (!ab8500->oldmask) in ab8500_probe()
1115 ret = get_register_interruptible(ab8500, AB8500_RTC, in ab8500_probe()
1119 dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value); in ab8500_probe()
1132 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, in ab8500_probe()
1136 dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value); in ab8500_probe()
1149 if (is_ab9540(ab8500)) { in ab8500_probe()
1150 ret = get_register_interruptible(ab8500, AB8500_CHARGER, in ab8500_probe()
1160 for (i = 0; i < ab8500->mask_size; i++) { in ab8500_probe()
1165 if (ab8500->irq_reg_offset[i] == 11 && in ab8500_probe()
1166 is_ab8500_1p1_or_earlier(ab8500)) in ab8500_probe()
1169 if (ab8500->irq_reg_offset[i] < 0) in ab8500_probe()
1172 get_register_interruptible(ab8500, AB8500_INTERRUPT, in ab8500_probe()
1173 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], in ab8500_probe()
1175 set_register_interruptible(ab8500, AB8500_INTERRUPT, in ab8500_probe()
1176 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff); in ab8500_probe()
1179 ret = abx500_register_ops(ab8500->dev, &ab8500_ops); in ab8500_probe()
1183 for (i = 0; i < ab8500->mask_size; i++) in ab8500_probe()
1184 ab8500->mask[i] = ab8500->oldmask[i] = 0xff; in ab8500_probe()
1186 ret = ab8500_irq_init(ab8500, np); in ab8500_probe()
1190 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, in ab8500_probe()
1193 "ab8500", ab8500); in ab8500_probe()
1197 if (is_ab9540(ab8500)) in ab8500_probe()
1198 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, in ab8500_probe()
1200 0, ab8500->domain); in ab8500_probe()
1201 else if (is_ab8540(ab8500)) { in ab8500_probe()
1202 ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs, in ab8500_probe()
1204 0, ab8500->domain); in ab8500_probe()
1208 if (is_ab8540_1p2_or_earlier(ab8500)) in ab8500_probe()
1209 ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut1_devs, in ab8500_probe()
1211 0, ab8500->domain); in ab8500_probe()
1213 ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut2_devs, in ab8500_probe()
1215 0, ab8500->domain); in ab8500_probe()
1216 } else if (is_ab8505(ab8500)) in ab8500_probe()
1217 ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs, in ab8500_probe()
1219 0, ab8500->domain); in ab8500_probe()
1221 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, in ab8500_probe()
1223 0, ab8500->domain); in ab8500_probe()
1228 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, in ab8500_probe()
1230 0, ab8500->domain); in ab8500_probe()
1232 dev_err(ab8500->dev, "error adding bm devices\n"); in ab8500_probe()
1234 if (((is_ab8505(ab8500) || is_ab9540(ab8500)) && in ab8500_probe()
1235 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500)) in ab8500_probe()
1236 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1239 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1242 if ((is_ab8505(ab8500) || is_ab9540(ab8500)) && in ab8500_probe()
1243 ab8500->chip_id >= AB8500_CUT2P0) in ab8500_probe()
1244 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1248 dev_err(ab8500->dev, "error creating sysfs entries\n"); in ab8500_probe()