Lines Matching refs:ab8500

166 static int ab8500_prcmu_write(struct ab8500 *ab8500, u16 addr, u8 data)  in ab8500_prcmu_write()  argument
172 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_write()
176 static int ab8500_prcmu_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask, in ab8500_prcmu_write_masked() argument
184 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_write_masked()
188 static int ab8500_prcmu_read(struct ab8500 *ab8500, u16 addr) in ab8500_prcmu_read() argument
195 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); in ab8500_prcmu_read()
203 struct ab8500 *ab8500; in ab8500_get_chip_id() local
207 ab8500 = dev_get_drvdata(dev->parent); in ab8500_get_chip_id()
208 return ab8500 ? (int)ab8500->chip_id : -EINVAL; in ab8500_get_chip_id()
211 static int set_register_interruptible(struct ab8500 *ab8500, u8 bank, in set_register_interruptible() argument
221 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data); in set_register_interruptible()
223 mutex_lock(&ab8500->lock); in set_register_interruptible()
225 ret = ab8500->write(ab8500, addr, data); in set_register_interruptible()
227 dev_err(ab8500->dev, "failed to write reg %#x: %d\n", in set_register_interruptible()
229 mutex_unlock(&ab8500->lock); in set_register_interruptible()
238 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_set_register() local
240 atomic_inc(&ab8500->transfer_ongoing); in ab8500_set_register()
241 ret = set_register_interruptible(ab8500, bank, reg, value); in ab8500_set_register()
242 atomic_dec(&ab8500->transfer_ongoing); in ab8500_set_register()
246 static int get_register_interruptible(struct ab8500 *ab8500, u8 bank, in get_register_interruptible() argument
252 mutex_lock(&ab8500->lock); in get_register_interruptible()
254 ret = ab8500->read(ab8500, addr); in get_register_interruptible()
256 dev_err(ab8500->dev, "failed to read reg %#x: %d\n", in get_register_interruptible()
261 mutex_unlock(&ab8500->lock); in get_register_interruptible()
262 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret); in get_register_interruptible()
271 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_get_register() local
273 atomic_inc(&ab8500->transfer_ongoing); in ab8500_get_register()
274 ret = get_register_interruptible(ab8500, bank, reg, value); in ab8500_get_register()
275 atomic_dec(&ab8500->transfer_ongoing); in ab8500_get_register()
279 static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank, in mask_and_set_register_interruptible() argument
285 mutex_lock(&ab8500->lock); in mask_and_set_register_interruptible()
287 if (ab8500->write_masked == NULL) { in mask_and_set_register_interruptible()
290 ret = ab8500->read(ab8500, addr); in mask_and_set_register_interruptible()
292 dev_err(ab8500->dev, "failed to read reg %#x: %d\n", in mask_and_set_register_interruptible()
300 ret = ab8500->write(ab8500, addr, data); in mask_and_set_register_interruptible()
302 dev_err(ab8500->dev, "failed to write reg %#x: %d\n", in mask_and_set_register_interruptible()
305 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, in mask_and_set_register_interruptible()
309 ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues); in mask_and_set_register_interruptible()
311 dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr, in mask_and_set_register_interruptible()
314 mutex_unlock(&ab8500->lock); in mask_and_set_register_interruptible()
322 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); in ab8500_mask_and_set_register() local
324 atomic_inc(&ab8500->transfer_ongoing); in ab8500_mask_and_set_register()
325 ret = mask_and_set_register_interruptible(ab8500, bank, reg, in ab8500_mask_and_set_register()
327 atomic_dec(&ab8500->transfer_ongoing); in ab8500_mask_and_set_register()
345 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_lock() local
347 mutex_lock(&ab8500->irq_lock); in ab8500_irq_lock()
348 atomic_inc(&ab8500->transfer_ongoing); in ab8500_irq_lock()
353 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_sync_unlock() local
356 for (i = 0; i < ab8500->mask_size; i++) { in ab8500_irq_sync_unlock()
357 u8 old = ab8500->oldmask[i]; in ab8500_irq_sync_unlock()
358 u8 new = ab8500->mask[i]; in ab8500_irq_sync_unlock()
368 if (ab8500->irq_reg_offset[i] == 11 && in ab8500_irq_sync_unlock()
369 is_ab8500_1p1_or_earlier(ab8500)) in ab8500_irq_sync_unlock()
372 if (ab8500->irq_reg_offset[i] < 0) in ab8500_irq_sync_unlock()
375 ab8500->oldmask[i] = new; in ab8500_irq_sync_unlock()
377 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; in ab8500_irq_sync_unlock()
378 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new); in ab8500_irq_sync_unlock()
380 atomic_dec(&ab8500->transfer_ongoing); in ab8500_irq_sync_unlock()
381 mutex_unlock(&ab8500->irq_lock); in ab8500_irq_sync_unlock()
386 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_mask() local
391 ab8500->mask[index] |= mask; in ab8500_irq_mask()
395 ab8500->mask[index + 2] |= mask; in ab8500_irq_mask()
397 ab8500->mask[index + 1] |= mask; in ab8500_irq_mask()
400 ab8500->mask[index] |= (mask << 1); in ab8500_irq_mask()
405 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); in ab8500_irq_unmask() local
412 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
417 ab8500->mask[index + 2] &= ~mask; in ab8500_irq_unmask()
420 ab8500->mask[index + 1] &= ~mask; in ab8500_irq_unmask()
424 ab8500->mask[index] &= ~(mask << 1); in ab8500_irq_unmask()
426 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
429 ab8500->mask[index] &= ~mask; in ab8500_irq_unmask()
460 static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500, in ab8500_handle_hierarchical_line() argument
465 for (i = 0; i < ab8500->mask_size; i++) in ab8500_handle_hierarchical_line()
466 if (ab8500->irq_reg_offset[i] == latch_offset) in ab8500_handle_hierarchical_line()
469 if (i >= ab8500->mask_size) { in ab8500_handle_hierarchical_line()
470 dev_err(ab8500->dev, "Register offset 0x%2x not declared\n", in ab8500_handle_hierarchical_line()
476 latch_val &= ~ab8500->mask[i]; in ab8500_handle_hierarchical_line()
496 handle_nested_irq(irq_create_mapping(ab8500->domain, line)); in ab8500_handle_hierarchical_line()
502 static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500, in ab8500_handle_hierarchical_latch() argument
514 status = get_register_interruptible(ab8500, in ab8500_handle_hierarchical_latch()
521 status = ab8500_handle_hierarchical_line(ab8500, in ab8500_handle_hierarchical_latch()
534 struct ab8500 *ab8500 = dev; in ab8500_hierarchical_irq() local
537 dev_vdbg(ab8500->dev, "interrupt\n"); in ab8500_hierarchical_irq()
540 for (i = 0; i < (ab8500->it_latchhier_num); i++) { in ab8500_hierarchical_irq()
544 status = get_register_interruptible(ab8500, AB8500_INTERRUPT, in ab8500_hierarchical_irq()
549 status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val); in ab8500_hierarchical_irq()
559 struct ab8500 *ab8500 = d->host_data; in ab8500_irq_map() local
561 if (!ab8500) in ab8500_irq_map()
564 irq_set_chip_data(virq, ab8500); in ab8500_irq_map()
578 static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np) in ab8500_irq_init() argument
582 if (is_ab8540(ab8500)) in ab8500_irq_init()
584 else if (is_ab9540(ab8500)) in ab8500_irq_init()
586 else if (is_ab8505(ab8500)) in ab8500_irq_init()
592 ab8500->domain = irq_domain_add_simple(ab8500->dev->of_node, in ab8500_irq_init()
594 &ab8500_irq_ops, ab8500); in ab8500_irq_init()
596 if (!ab8500->domain) { in ab8500_irq_init()
597 dev_err(ab8500->dev, "Failed to create irqdomain\n"); in ab8500_irq_init()
604 int ab8500_suspend(struct ab8500 *ab8500) in ab8500_suspend() argument
606 if (atomic_read(&ab8500->transfer_ongoing)) in ab8500_suspend()
885 struct ab8500 *ab8500; in show_chip_id() local
887 ab8500 = dev_get_drvdata(dev); in show_chip_id()
889 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); in show_chip_id()
908 struct ab8500 *ab8500; in show_switch_off_status() local
910 ab8500 = dev_get_drvdata(dev); in show_switch_off_status()
911 ret = get_register_interruptible(ab8500, AB8500_RTC, in show_switch_off_status()
943 struct ab8500 *ab8500; in show_turn_on_status() local
945 ab8500 = dev_get_drvdata(dev); in show_turn_on_status()
946 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, in show_turn_on_status()
958 if (is_ab9540(ab8500)) { in show_turn_on_status()
972 struct ab8500 *ab8500; in show_turn_on_status_2() local
974 ab8500 = dev_get_drvdata(dev); in show_turn_on_status_2()
975 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, in show_turn_on_status_2()
985 struct ab8500 *ab8500; in show_ab9540_dbbrstn() local
989 ab8500 = dev_get_drvdata(dev); in show_ab9540_dbbrstn()
991 ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2, in show_ab9540_dbbrstn()
1003 struct ab8500 *ab8500; in store_ab9540_dbbrstn() local
1008 ab8500 = dev_get_drvdata(dev); in store_ab9540_dbbrstn()
1022 err = mask_and_set_register_interruptible(ab8500, in store_ab9540_dbbrstn()
1026 dev_info(ab8500->dev, in store_ab9540_dbbrstn()
1097 struct ab8500 *ab8500; in ab8500_probe() local
1103 ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL); in ab8500_probe()
1104 if (!ab8500) in ab8500_probe()
1107 ab8500->dev = &pdev->dev; in ab8500_probe()
1115 ab8500->irq = resource->start; in ab8500_probe()
1117 ab8500->read = ab8500_prcmu_read; in ab8500_probe()
1118 ab8500->write = ab8500_prcmu_write; in ab8500_probe()
1119 ab8500->write_masked = ab8500_prcmu_write_masked; in ab8500_probe()
1121 mutex_init(&ab8500->lock); in ab8500_probe()
1122 mutex_init(&ab8500->irq_lock); in ab8500_probe()
1123 atomic_set(&ab8500->transfer_ongoing, 0); in ab8500_probe()
1125 platform_set_drvdata(pdev, ab8500); in ab8500_probe()
1131 ab8500->version = version; in ab8500_probe()
1133 ret = get_register_interruptible(ab8500, AB8500_MISC, in ab8500_probe()
1140 ab8500->version = value; in ab8500_probe()
1143 ret = get_register_interruptible(ab8500, AB8500_MISC, in ab8500_probe()
1148 ab8500->chip_id = value; in ab8500_probe()
1150 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n", in ab8500_probe()
1151 ab8500_version_str[ab8500->version], in ab8500_probe()
1152 ab8500->chip_id >> 4, in ab8500_probe()
1153 ab8500->chip_id & 0x0F); in ab8500_probe()
1156 if (is_ab8540(ab8500)) { in ab8500_probe()
1157 ab8500->mask_size = AB8540_NUM_IRQ_REGS; in ab8500_probe()
1158 ab8500->irq_reg_offset = ab8540_irq_regoffset; in ab8500_probe()
1159 ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM; in ab8500_probe()
1161 else if (is_ab9540(ab8500) || is_ab8505(ab8500)) { in ab8500_probe()
1162 ab8500->mask_size = AB9540_NUM_IRQ_REGS; in ab8500_probe()
1163 ab8500->irq_reg_offset = ab9540_irq_regoffset; in ab8500_probe()
1164 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM; in ab8500_probe()
1166 ab8500->mask_size = AB8500_NUM_IRQ_REGS; in ab8500_probe()
1167 ab8500->irq_reg_offset = ab8500_irq_regoffset; in ab8500_probe()
1168 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM; in ab8500_probe()
1170 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, in ab8500_probe()
1172 if (!ab8500->mask) in ab8500_probe()
1174 ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, in ab8500_probe()
1176 if (!ab8500->oldmask) in ab8500_probe()
1191 ret = get_register_interruptible(ab8500, AB8500_RTC, in ab8500_probe()
1195 dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value); in ab8500_probe()
1208 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, in ab8500_probe()
1212 dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value); in ab8500_probe()
1225 if (is_ab9540(ab8500)) { in ab8500_probe()
1226 ret = get_register_interruptible(ab8500, AB8500_CHARGER, in ab8500_probe()
1236 for (i = 0; i < ab8500->mask_size; i++) { in ab8500_probe()
1241 if (ab8500->irq_reg_offset[i] == 11 && in ab8500_probe()
1242 is_ab8500_1p1_or_earlier(ab8500)) in ab8500_probe()
1245 if (ab8500->irq_reg_offset[i] < 0) in ab8500_probe()
1248 get_register_interruptible(ab8500, AB8500_INTERRUPT, in ab8500_probe()
1249 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], in ab8500_probe()
1251 set_register_interruptible(ab8500, AB8500_INTERRUPT, in ab8500_probe()
1252 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff); in ab8500_probe()
1255 ret = abx500_register_ops(ab8500->dev, &ab8500_ops); in ab8500_probe()
1259 for (i = 0; i < ab8500->mask_size; i++) in ab8500_probe()
1260 ab8500->mask[i] = ab8500->oldmask[i] = 0xff; in ab8500_probe()
1262 ret = ab8500_irq_init(ab8500, np); in ab8500_probe()
1266 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, in ab8500_probe()
1269 "ab8500", ab8500); in ab8500_probe()
1273 if (is_ab9540(ab8500)) in ab8500_probe()
1274 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, in ab8500_probe()
1276 0, ab8500->domain); in ab8500_probe()
1277 else if (is_ab8540(ab8500)) { in ab8500_probe()
1278 ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs, in ab8500_probe()
1280 0, ab8500->domain); in ab8500_probe()
1284 if (is_ab8540_1p2_or_earlier(ab8500)) in ab8500_probe()
1285 ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut1_devs, in ab8500_probe()
1287 0, ab8500->domain); in ab8500_probe()
1289 ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut2_devs, in ab8500_probe()
1291 0, ab8500->domain); in ab8500_probe()
1292 } else if (is_ab8505(ab8500)) in ab8500_probe()
1293 ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs, in ab8500_probe()
1295 0, ab8500->domain); in ab8500_probe()
1297 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, in ab8500_probe()
1299 0, ab8500->domain); in ab8500_probe()
1305 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, in ab8500_probe()
1307 0, ab8500->domain); in ab8500_probe()
1309 dev_err(ab8500->dev, "error adding bm devices\n"); in ab8500_probe()
1312 if (((is_ab8505(ab8500) || is_ab9540(ab8500)) && in ab8500_probe()
1313 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500)) in ab8500_probe()
1314 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1317 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1320 if ((is_ab8505(ab8500) || is_ab9540(ab8500)) && in ab8500_probe()
1321 ab8500->chip_id >= AB8500_CUT2P0) in ab8500_probe()
1322 ret = sysfs_create_group(&ab8500->dev->kobj, in ab8500_probe()
1326 dev_err(ab8500->dev, "error creating sysfs entries\n"); in ab8500_probe()